JezK
Edit File: addclass_and_section.php
<?php session_start(); include("session_check.php"); include("adm_operations.php"); include("header.php"); $operations=new adm_operations(); include('school_timeout.php'); $prev_class=$operations->getallClassesforOrder($_SESSION['child']['log_school_id'],$_SESSION['child']['choosen_academic_id']); $pcount=count($prev_class); $setjun=0; $set=1; if(isset($_POST['addcns'])) { $schid=$_SESSION['child']['log_school_id']; $acdid=$_SESSION['child']['choosen_academic_id']; $category=$_POST['category']; $prevclass=$_POST['pcls']; $classname=$_POST['classname']; $sections=$_POST['sections']; $junior=$_POST['junior']; $me=$_SESSION['child']['auth_id']; $response=$operations->addclassandsection($me,$schid,$category,$prevclass,$classname,$sections,$junior,$acdid); if($response=='100') echo "<script>window.location.replace('classnsection_manage.php');</script>"; else if($response=='102') echo "<script>alert('Class Name already exists');</script>"; else if($response=='103') echo "<script>alert('Sorry, you cannot make ".$_POST['pcls']." as your Previous Class as it is already occupied');</script>"; } ?> <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" maxlength="30" class="form-control" id="fks'+cnt+'" 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 removelastadded(rm) { var sections=document.getElementsByName("sections[]"); var remov=sections.length; if(remov==1) { } else { $('#section'+rm).remove(); } } function checkclassadd() { var xj=document.getElementById('prevcls').value; 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; //clname=clname.trim(); var sections=document.getElementsByName("sections[]"); var jrmost=document.getElementById('juniormost').checked; $('#pcls').val(xj); $('#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,j=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); } </script> <script> $(document).ready(function(){ $("#addcns").prop("disabled", false); }); </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:40px;"> <i class=" glyphicon glyphicon-plus " title ="Add Academic Year" style="font-size: 16px;"></i> Add 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;" <?php if($prev_class==0) echo "disabled";?>>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%;"> <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"); foreach($arr as $key=>$val) if($_POST['category']==$key) 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> </div> <div class="col-md-7"> <input type="hidden" name="pcls" id="pcls" value="<?php if($_POST['pcls']) echo $_POST['pcls'];?>"> <select class="form-control" name="prevcls" id="prevcls" style="height:29px; font-size:12px;" tabindex="2" onchange="assignaname(this)" disabled> <option value='0' >--Select Prev Class--</option> <?php if($prev_class!='0') foreach($prev_class as $row) { //if($_POST['prevcls']==$row[class_id]) //echo "<option value='".$row[class_id]."' selected>".$row[class_name]."</option>"; if($set==$pcount) echo "<option value='".$row[class_id]."' selected>".$row[class_name]."</option>"; else echo "<option value='".$row[class_id]."'>".$row[class_name]."</option>"; if($row['junior_status']=='1') $setjun=1; $set++; } ?> </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="3" value="<?php echo $_POST['classname'];?>"> <!-- 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> <?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].'"> <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=1; $start='<div id="secadd">'; $end='</div>'; foreach($_POST['sections'] as $sec) { if($i<1) { echo '<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;">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].'"> <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-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].'"> </div> </div> <div class="col-md-2"> <a onclick="removelastadded('.$r.')"><i class=" glyphicon glyphicon-remove-circle" title ="Add More Sections " style="font-size: 14px;margin-top:10px;color:#01aee6;"></i></a> </div> </div>'; $i++; } $r++; } echo $start.''.$variable.''.$end; } } else 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="4"> <!-- if there is an error--> <div class="col-md-11" id="err_sections" style="color:#990000;margin-left:-15px;"></div> <!--- end error--> </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>'; ?> <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 "> <input type="checkbox" name="junior" value="1" id="juniormost" onclick="primarystatuschange()" tabindex="7" <?php if($setjun==1) echo "disabled";?>>This Class is the Junior most<br> <!-- if there is an error--> <div class="col-md-12" 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="addcns" disabled="disabled" id="addcns"style="font-family:Arial, Helvetica, sans-serif;font-style:normal;font-size:13px; margin:10px;" onclick="return checkclassadd();" tabindex="5">Add </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();" tabindex="6">Cancel </button> </div> </div> </form>