JezK
Edit File: add_juniormost.php
<?php session_start(); include("session_check.php"); include("adm_operations.php"); $operations = new adm_operations(); include('school_timeout.php'); $prev_class = $operations->getallClassesforOrder($_SESSION['child']['log_school_id'], $_SESSION['child']['choosen_academic_id']); if ($prev_class != 0) foreach ($prev_class as $row) { if ($row['junior_status'] == '1') { $cur_jun = $row[class_name]; $cur_cat = $row[class_category_id]; } } if (isset($_POST['clsjradd'])) { $schid = $_SESSION['child']['log_school_id']; $acdid = $_SESSION['child']['choosen_academic_id']; $category = $_POST['category']; $classname = $_POST['classname']; $sections = $_POST['sections']; $me = $_SESSION['child']['auth_id']; $response = $operations->addjuniorclassandsection($me, $schid, $category, $classname, $sections, $acdid); if ($response == '100') { //echo "<script>alert('Class added successfully');</script>"; //echo "<script>window.location.replace('classnsection_manage.php')</script>"; header("Location:classnsection_manage.php"); } else { echo "<script>alert('Class Name already exists');</script>"; } } include("header.php"); ?> <body style="overflow-x: hidden;"> <div class="row" style="margin-top: 30px;"> <div class="col-md-9 text-left" style="font:Arial, Helvetica, sans-serif;font-style:normal;font-size:24px; margin-left:25px;"> <img src="images/change-class-icon(1).png" title=" Change Junior Most Class" style="font-size: 20px;"></i> Change Junior Most Class </div> </div> <form class="form-horizontal" style="margin-left:47px; margin-top:35px;" method="post"> <div class="class"> <div class="form-group row col-md-6" style="margin-bottom:1.0%; clear:both;"> <div class="col-md-4 offset-md-1 text-md-end"> <b style="color:#666666; font-family:Arial, Helvetica, sans-serif; font-size:13px;">Current Junior Class</b> <span style="color:#FF0000; margin:2px; "></span> </div> <div class="col-md-7"> <input type="text" class="form-control" style="height:29px;font-size:13px;" tabindex="1" value="<?php echo $cur_jun; ?>" disabled> <p style="font-family:Arial, Helvetica, sans-serif;font-style:italic;font-size:10px;">(will become "Next Class" to the new Junior Class)</p> </div> </div> </div> <div class="class"> <div class="form-group row col-md-6" style="margin-bottom:1.0%;clear:both"> <div class="col-md-4 offset-md-1 text-md-end"> <b style="color:#666666;font-family:Arial, Helvetica, sans-serif; font-size:13px; ">Select Category</b> <span style="color:#FF0000;margin-left:-2px;">*</span> </div> <div class="col-md-7"> <select class="form-select" 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']) && $key == $_POST['category']) { foreach ($arr as $key => $val) if ($key == $cur_cat) echo "<option value='" . $key . "' selected>" . $val . "</option>"; else echo "<option value='" . $key . "'>" . $val . "</option>"; } else { foreach ($arr as $key => $val) if ($key == $cur_cat) 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;"></div> <!--- end error--> </div> </div> </div> <div class="class"> <div class="form-group row col-md-6" style="margin-bottom:1.0%; clear:both;"> <div class="col-md-4 offset-md-1 text-md-end"> <b style="color:#666666;font-family:Arial, Helvetica, sans-serif; font-size:13px;">New Junior Most Class</b> <span style="color:#FF0000; margin:2px;margin-left:-2px;">*</span> </div> <div class="col-md-7"> <input type="text" name="classname" maxlength="50" class="form-control" id="classname" style="height:29px;font-size:13px;" tabindex="2" value="<?php if (isset($_POST['classname'])) echo $_POST['classname']; ?>"> <!-- if there is an error--> <div class="col-md-10" id="err_classname" style="color:#990000;"></div> <!--- end error--> </div> </div> </div> <?php if (isset($_POST['sections'])) { if (count($_POST['sections']) == 1) { echo '<div class="class row"> <div class="form-group row col-md-6" style="margin-bottom:1.0%; clear:both;"> <div class="col-md-4 offset-md-1 text-md-end"><b style="color:#666666;font-size:13px;">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-10" id="err_sections" style="color:#990000;"></div> </div> </div> <div class="col-md-2"> <a onclick="addnewfield()"><i class="fa-solid fa-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 row" id="section' . $r . '"> <div class="form-group row col-md-6" style="margin-bottom:1.0%; clear:both;"> <div class="col-md-4 offset-md-1 text-md-end"><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-10" id="err_sections" style="color:#990000;"></div> </div> </div> <div class="col-md-2"> <a><i class=" fa fa-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 row col-md-6" style="margin-bottom:1.0%; clear:both;"> <div class="col-md-4 offset-md-1 text-md-end"> <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>'; $i++; } $r++; } echo $start . '' . $variable . '' . $end; } } else echo '<div class="class row"> <div class="form-group row col-md-6" style="margin-bottom:1.0%; clear:both;"> <div class="col-md-4 offset-md-1 text-md-end"> <b style="color:#666666;font-size:13px;">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-10" id="err_sections" style="color:#990000;"></div> <!--- end error--> </div> </div> <div class="col-md-2"> <a onclick="addnewfield()"><i class=" fa-solid fa-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="form-group"> <div class="col-md-12"> <div class="col-md-8" align="center"> <button type="submit" name="clsjradd" class="btn btn-outline-secondary custom-button-width .navbar-right btnclr" disabled="disabled" id="clsjradd" tabindex="4" style="font-family:Arial, Helvetica, sans-serif;font-style:normal;font-size:13px; margin:20px; " onclick="return checkclassadd();">Update</button> <button type="button" name="cncel" class="btn btn-outline-secondary custom-button-width .navbar-right btnclr" tabindex="5" style="font-family:Arial, Helvetica, sans-serif;font-style:normal;font-size:13px; margin:20px; " onclick="return canceladd();">Cancel</button> </div> </div> </div> </form> <script> $(document).ready(function() { $("#clsjradd").prop("disabled", false); }); </script> <script> var cnt = 1; function addnewfield() { var sections = document.getElementsByName("sections[]"); //var cnt=sections.length; cnt++; var a = '<div class="class row" id="section' + cnt + '"><div class="form-group row col-md-6" style="margin-bottom:1.0%; clear:both;"><div class="col-md-5 text-md-end"><b style="color:#666666;"></b><span style="color:#FF0000; margin:2px; ">*</span></div><div class="col-md-7"><input type="text" class="form-control" id="fks' + cnt + '" name="sections[]" maxlength="30" style="height:29px;font-size:13px;" tabindex="6"></div></div><div class="col-md-2"><a onclick="removelastadded(' + cnt + ')"><i class=" fa-solid fa-circle-xmark" 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 removelastadded(rm) { var sections = document.getElementsByName("sections[]"); var remov = sections.length; if (remov == 1) {} else { $('#section' + rm).remove(); } } function checkclassadd() { var repeat = 0; var vr1 = 0; var xsections = []; var reg = /^[A-Za-z\d\-_\s]+$/i; var cat = document.getElementById('category').value; var clname = document.getElementById('classname').value; clname = clname.trim(); var sections = document.getElementsByName("sections[]"); $('#err_category').text(''); $('#err_classname').text(''); $('#err_sections').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[0].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"; } </script> </body> </html>