JezK
Edit File: editclass_and_section.php
<?php session_start(); include("session_check.php"); include("adm_operations.php"); $operations=new adm_operations(); include('school_timeout.php'); if(isset($_POST['editcns'])) { $schid=$_SESSION['child']['log_school_id']; $clsid=$_POST['clsid']; $acdid=$_SESSION['child']['choosen_academic_id']; $category=$_POST['category']; $prevclass=$_POST['pcls']; $classname=$_POST['classname']; $sections=$_POST['sections']; $sectionids=$_POST['sectionids']; $junior=$_POST['jm']; $me=$_SESSION['child']['auth_id']; $removethem=$_POST['rmids']; $response=$operations->editclassandsection($me,$clsid,$schid,$category,$prevclass,$classname,$sections,$sectionids,$junior,$acdid,$removethem); if($response=='100') echo "<script>window.location.replace('classnsection_manage.php');</script>"; //header("Location:classnsection_manage.php"); else if($response=='102') echo "<script>alert('Class Name already exists');</script>"; else if($response=='103') echo "<script>alert('You can not make ".$_POST['pcls']." as your Previous Class as it is already occupied');</script>"; } $class_details=$operations->getClassDetailsByID($_GET['cls_ref']); $prev_class=$operations->getallClassesforOrder($_SESSION['child']['log_school_id'],$_SESSION['child']['choosen_academic_id']); $setjun=0; //print_r($class_details); include("header.php"); ?> <style> #juniormost { margin-top:-2px; margin-left:2px; margin-right:5px; } </style> <script language="javascript"> var cnt=1; function addnewfield() { var sections=document.getElementsByName("sections[]"); //var cnt=sections.length; cnt++; var a='<div class="class" id="section'+cnt+'"><div class="form-group col-md-6" style="margin-bottom:1.0%; clear:both;"><div class="col-md-4 col-md-offset-1 text-right"><b style="color:#666666;"></b><span style="color:#FF0000; margin:2px; ">*</span></div><div class="col-md-7"><input type="text" id="fks'+cnt+'" class="form-control" maxlength="30" name="sections[]" style="height:29px;font-size:13px;" tabindex="6"></div></div><div class="col-md-2"><a onclick="removelastadded('+cnt+')"><i class=" glyphicon glyphicon-remove-circle" title ="Add More Sections " style="font-size: 14px;margin-top:10px;color:#01aee6;"></i></a></div></div>'; var b=$('#secadd').append(a); document.getElementById('fks'+cnt).focus(); } function primarystatuschange() { if($('#juniormost').is(':checked')) { $('#prevcls').val('0'); $('#prevcls').attr('disabled',true); } else { $('#prevcls').attr('disabled',false); } } function checkclassadd() { var repeat=0; var vr1=0; var xsections=[]; var reg=/^[a-zA-Z0-9][a-zA-Z0-9_\- ]*$/; var cat=document.getElementById('category').value; var prev=document.getElementById('prevcls').value; var clname=document.getElementById('classname').value; var sections=document.getElementsByName("sections[]"); var jrmost=document.getElementById('juniormost').checked; $('#err_category').text(''); $('#err_classname').text(''); $('#err_sections').text(''); $('#err_jnr').text(''); if(cat==0) { $('#err_category').text("Please select Class Category"); document.getElementById('category').focus(); return false; } else if(clname=='') { $('#err_classname').text("Please enter Class Name"); document.getElementById('classname').focus(); return false; } else if(!reg.test(clname)) { $('#err_classname').text("Please enter a valid Class Name"); document.getElementById('classname').focus(); return false; } for(var i =0,j=0; i < sections.length; i++) { if(sections[i].value=='') vr1=1; xsections[j]=sections[i]; j++; } if(vr1!=0) { if(sections[0].value=='') { $('#err_sections').text('Please enter Section Name'); return false; } else { $('#err_sections').text('Please enter the missing Section Name'); return false; } } for(var i =0; i < sections.length; i++) { if(!reg.test(sections[i].value)) { if(i==0) { $('#err_sections').text('Please enter a valid Section Name'); return false; } else { $('#err_sections').text('Please enter a valid Name for each Section'); return false; } } } for(var i = 0; i < sections.length; i++) { for(var j=0;j< xsections.length; j++) { if(((xsections[j].value).trim()).toUpperCase()==((sections[i].value).trim()).toUpperCase()) repeat++; if(repeat>1) { $('#err_sections').text('Please enter unique name for each Section'); return false; } } repeat=0; } if(!(jrmost) && prev==0) { $('#err_jnr').text('Select previous class or make sure that this is Junior Most'); return false; } } function canceladd() { window.location.href="classnsection_manage.php"; } function assignaname(sel) { x=sel.options[sel.selectedIndex].text; $('#pcls').val(x); } function removelastadded(rm) { var rms=0; var sections=document.getElementsByName("sections[]"); var remov=sections.length; if(remov==1) { } else { var sr=document.getElementById('scid'+rm); if(confirm("Do you want to delete the section ?")) { if(sr!=null) { var r=sr.value; rms=$('#rmids').val(); rms=rms+'_'+r; $.post('getdthesec.php',{keyid:r},function(data){ if(data=='fail') { alert("You can not delete the Section as some data is associated with it"); } else { $('#rmids').val(rms); $('#section'+rm).remove(); } }); } else { $('#section'+rm).remove(); } } } } </script> <script> // Keep all submit buttons from working $('input:submit').live('click', function () { return false; }); // After everything loads, remove the restriction $(window).load(function(){ $('input:submit').die(); }); </script> <body style="overflow-x: hidden;"> <div class="row" style="margin-top:30px;"> <div class="col-md-9" style="font:Arial, Helvetica, sans-serif;font-style:normal;font-size:14px; color:#000000; font-size:1.4em;margin-left:25px;"> <i class=" glyphicon glyphicon-pencil" title ="Edit Academic Year" style="font-size: 16px;"></i> Edit Class & Section </div> <div class="col-md-2 text-center"> <button type="button" onClick="location.href='add_juniormost.php'" class="btn btn-default" style="margin-right:20px;font-family: Arial, Helvetica, sans-serif; font-size:14px;padding:4px 10px;">Change Junior Most Class</button> </div> </div> <form class="form-horizontal" method="post" style="margin-top:30px;"> <div class="box-body" style="background-color:#fff; padding: 10px; font-family:Arial, Helvetica, sans-serif; font-size:13px; "> <div class="clear"> <div class="form-group col-md-6" style="margin-bottom:1.0%;"> <input type="hidden" name="clsid" value="<?php echo $_GET['cls_ref'];?>"> <input type="hidden" name="jm" value="<?php echo $class_details['junior_status'];?>"> <div class="col-md-4 col-md-offset-1 text-right"><b style="color:#666666; ">Select Category </b><span style="color:#FF0000;margin-left:-2px;">*</span> </div> <div class="col-md-7"> <select class="form-control" name="category" id="category" style="height:29px; font-size:12px;" tabindex="1" > <?php $arr=array("Select Category","Junior","Primary","Higher Secondary","Senior Secondary"); if(isset($_POST['category'])) { foreach($arr as $key=>$val) if($key==$_POST['category']) echo "<option value='".$key."' selected>".$val."</option>"; else echo "<option value='".$key."'>".$val."</option>"; } else { foreach($arr as $key=>$val) if($key==$class_details['class_cat_id']) echo "<option value='".$key."' selected>".$val."</option>"; else echo "<option value='".$key."'>".$val."</option>"; } ?> </select> <!-- if there is an error--> <div class="col-md-10" id="err_category" style="color:#990000;margin-left:-15px;"></div> <!--- end error--> </div> </div> </div> <div class="clear"> <div class="form-group col-md-6" style="margin-bottom:1.0%;"> <div class="col-md-4 col-md-offset-1 text-right"><b style="color:#666666;">Select Previous Class</b><span style="color:#FF0000; margin-left:4px;"> </span> <input type="hidden" name="pcls" id="pcls" value="<?php if(isset($_POST['pcls'])) echo $_POST['pcls'];else echo $class_details['class_order'];?>"> </div> <div class="col-md-7"> <?php if($prev_class!='0') if($class_details['junior_status']=='1') { echo '<select class="form-control" name="prevcls" id="prevcls" style="height:29px; font-size:12px;" tabindex="2" disabled>'; echo "<option value='0' selected>--Select Prevous Class--</option>"; foreach($prev_class as $row) { echo "<option value='".$row['class_id']."'>".$row['class_name']."</option>"; if($row['junior_status']=='1') $setjun=1; } } else { echo '<select class="form-control" name="prevcls" id="prevcls" style="height:29px; font-size:12px;" tabindex="3" onchange="assignaname(this)" disabled>'; echo "<option value='0'>--Select Prevous Class--</option>"; if(isset($_POST['prevcls'])) { foreach($prev_class as $row) { if($row['junior_status']=='1') $setjun=1; if($row['class_id']==$_POST['prevcls']) echo "<option value='".$row['class_id']."' selected >".$row['class_name']."</option>"; else echo "<option value='".$row['class_id']."'>".$row['class_name']."</option>"; } } else { foreach($prev_class as $row) { if($row['junior_status']=='1') $setjun=1; if($row['class_id']==$class_details['class_order']) echo "<option value='".$row['class_id']."' selected >".$row['class_name']."</option>"; else echo "<option value='".$row['class_id']."'>".$row['class_name']."</option>"; } } } echo '</select>'; ?> <!-- if there is an error--> <div class="col-md-10" id="err_prevcls" style="color:#990000;margin-left:-15px;"></div> <!--- end error--> </div> </div> </div> <div class="class"> <div class="form-group col-md-6" style="margin-bottom:1.0%; clear:both;"> <div class="col-md-4 col-md-offset-1 text-right"><b style="color:#666666;">Class Name </b><span style="color:#FF0000;margin-left:-2px;">*</span> </div> <div class="col-md-7"> <input type="text" name="classname" id="classname" maxlength="50" class="form-control" style="height:29px;font-size:13px;" tabindex="4" value="<?php if(isset($_POST['classname'])) echo $_POST['classname'];else echo $class_details[class_name];?>"> <!-- if there is an error--> <div class="col-md-10" id="err_classname" style="color:#990000;margin-left:-15px;"></div> <!--- end error--> </div> </div> </div> <input type="hidden" name="rmids" id="rmids" value="<?php if(isset($_POST['rmids'])) echo $_POST['rmids'];?>"> <?php if(isset($_POST['sections'])) { if(count($_POST['sections'])==1) { echo '<div class="class"> <div class="form-group col-md-6" style="margin-bottom:1.0%; clear:both;"> <div class="col-md-4 col-md-offset-1 text-right"><b style="color:#666666;">Section Name </b><span style="color:#FF0000;margin-left:-2px;">*</span> </div> <div class="col-md-7"> <input type="text" class="form-control" maxlength="30" name="sections[]" style="height:29px;font-size:13px;" tabindex="6" value="'.$_POST[sections][0].'"> <input type="hidden" class="form-control" name="sectionids[]" style="height:29px;font-size:13px;" tabindex="6" value="'.$_POST[sec_id][0].'"> <div class="col-md-11" id="err_sections" style="color:#990000;margin-left:-15px;"></div> </div> </div> <div class="col-md-2"> <a onclick="addnewfield()"><i class=" glyphicon glyphicon-plus" title ="Add More Sections " style="font-size: 14px;margin-top:10px; margin-left:2px;color:#01aee6;"></i></a> </div> </div> <div id="secadd"> </div>'; } else { $i=0; $r=2; $start='<div id="secadd">'; $end='</div>'; foreach($_POST['sections'] as $sec) { if($i<1) { echo '<div class="class"> <div class="form-group col-md-6" style="margin-bottom:1.0%; clear:both;"> <div class="col-md-4 col-md-offset-1 text-right"><b style="color:#666666;">Section Name </b><span style="color:#FF0000;margin-left:-2px;">*</span> </div> <div class="col-md-7"> <input type="text" class="form-control" maxlength="30" name="sections[]" style="height:29px;font-size:13px;" tabindex="6" value="'.$_POST[sections][$i].'"> <input type="hidden" class="form-control" name="sectionids[]" style="height:29px;font-size:13px;" tabindex="6" value="'.$_POST[sectionids][$i].'"> <div class="col-md-11" id="err_sections" style="color:#990000;margin-left:-15px;"></div> </div> </div> <div class="col-md-2"> <a onclick="addnewfield()"><i class=" glyphicon glyphicon-plus" title ="Add More Sections " style="font-size: 14px;margin-top:10px; margin-left:2px;color:#01aee6;"></i></a> </div> </div>'; $i++; } else { $variable.='<div class="class" id="section'.$r.'"> <div class="form-group col-md-6" style="margin-bottom:1.0%; clear:both;"> <div class="col-md-4 col-md-offset-1 text-right"> <b style="color:#666666;"> </b><span style="color:#FF0000; margin:2px; ">*</span> </div> <div class="col-md-7"> <input type="text" class="form-control" maxlength="30" name="sections[]" style="height:29px;font-size:13px;" tabindex="6" value="'.$_POST[sections][$i].'"> <input type="hidden" class="form-control" id="scid'.$r.'" name="sectionids[]" style="height:29px;font-size:13px;" tabindex="6" value="'.$_POST[sectionids][$i].'"> </div> </div> <div class="col-md-2"><a onclick="removelastadded('.$r.')"><i class=" glyphicon glyphicon-remove-circle" title ="Remove Section " style="font-size: 14px;margin-top:10px;color:#01aee6;"></i></a></div> </div>'; $i++; $r++; } } echo $start.''.$variable.''.$end; } } else { if(count($class_details['sections'])==1) { echo '<div class="class"> <div class="form-group col-md-6" style="margin-bottom:1.0%; clear:both;"> <div class="col-md-4 col-md-offset-1 text-right"><b style="color:#666666;">Section Name </b><span style="color:#FF0000;margin-left:-2px;">*</span> </div> <div class="col-md-7"> <input type="hidden" class="form-control" name="sectionids[]" style="height:29px;font-size:13px;" tabindex="6" value="'.$class_details[sections][0][sec_id].'"> <input type="text" class="form-control" maxlength="30" name="sections[]" style="height:29px;font-size:13px;" tabindex="6" value="'.$class_details[sections][0][sec_name].'"> <div class="col-md-11" id="err_sections" style="color:#990000;margin-left:-15px;"></div> </div> </div> <div class="col-md-2"> <a onclick="addnewfield()"><i class=" glyphicon glyphicon-plus" title ="Add More Sections " style="font-size: 14px;margin-top:10px; margin-left:2px;color:#01aee6;"></i></a> </div> </div> <div id="secadd"> </div>'; } else { $i=0; $r=2; $start='<div id="secadd">'; $end='</div>'; foreach($class_details['sections'] as $sec) { if($i<1) { echo '<div class="class"> <div class="form-group col-md-6" style="margin-bottom:1.0%; clear:both;"> <div class="col-md-4 col-md-offset-1 text-right"><b style="color:#666666;">Section Name </b><span style="color:#FF0000;margin-left:-2px;">*</span> </div> <div class="col-md-7"> <input type="hidden" class="form-control" name="sectionids[]" style="height:29px;font-size:13px;" tabindex="6" value="'.$sec[sec_id].'"> <input type="text" class="form-control" maxlength="30" name="sections[]" style="height:29px;font-size:13px;" tabindex="6" value="'.$sec[sec_name].'"> <div class="col-md-11" id="err_sections" style="color:#990000;margin-left:-15px;"></div> </div> </div> <div class="col-md-2"> <a onclick="addnewfield()"><i class=" glyphicon glyphicon-plus" title ="Add More Sections " style="font-size: 14px;margin-top:10px; margin-left:2px;color:#01aee6;"></i></a> </div> </div>'; $i++; } else { $variable.='<div class="class" id="section'.$r.'"> <div class="form-group col-md-6" style="margin-bottom:1.0%; clear:both;"> <div class="col-md-4 col-md-offset-1 text-right"> <b style="color:#666666;"> </b><span style="color:#FF0000; margin:2px; ">*</span> </div> <div class="col-md-7"> <input type="hidden" class="form-control" id="scid'.$r.'" name="sectionids[]" style="height:29px;font-size:13px;" tabindex="6" value="'.$sec[sec_id].'"> <input type="text" class="form-control" maxlength="30" name="sections[]" style="height:29px;font-size:13px;" tabindex="6" value="'.$sec[sec_name].'"> </div> </div> <div class="col-md-2"><a onclick="removelastadded('.$r.')"><i class=" glyphicon glyphicon-remove-circle" title ="Remove Section" style="font-size: 14px;margin-top:10px;color:#01aee6;"></i></a></div> </div>'; $i++; } $r++; } echo $start.''.$variable.''.$end; } } ?> <div class="class"> <div class="form-group col-md-6" style="margin-bottom:1.0%; clear:both;"> <div class="col-md-4 col-md-offset-1 text-right"> </div> <div class=" col-md-7 "> <?php if($class_details['junior_status']=='1') echo '<input type="checkbox" name="junior" value="1" id="juniormost" onclick="primarystatuschange()" tabindex="7" checked disabled>This Class is the Junior most<br>'; else if($setjun==1) echo '<input type="checkbox" name="junior" value="1" id="juniormost" onclick="primarystatuschange()" tabindex="7" disabled>This Class is the Junior most<br>'; else echo '<input type="checkbox" name="junior" value="1" id="juniormost" onclick="primarystatuschange()" tabindex="7" >This Class is the Junior most<br>'; ?> <!-- if there is an error--> <div class="col-md-7" id="err_jnr" style="color:#990000;margin-left:-15px;"></div> <!--- end error--> </div> </div> </div> </div><!-- /.col --> </div><!-- /.row --> <div class="form-group"> <div class="col-md-8" align="center"> <button type="submit" class="btn btn-default custom-button-width .navbar-right btnclr" name="editcns" onclick="return checkclassadd();" style="font-family:Arial, Helvetica, sans-serif;font-style:normal;font-size:13px; margin:10px; ">Update</button> <button type="button" class="btn btn-default custom-button-width .navbar-right btnclr" name="cancelcns" style="font-family:Arial, Helvetica, sans-serif;font-style:normal;font-size:13px; margin:10px;" onclick="return canceladd();">Cancel </button> </div> </div> </form>