JezK
Edit File: edit_teacher.php
<?php session_start(); include("session_check.php"); include('adm_operations.php'); include("header.php"); $operations = new adm_operations(); include('school_timeout.php'); $staff = $operations->get_teacher_details($_GET['staff_id']); $appdetails = $operations->gettingAppDetails(); $valid_exts = array('jpeg', 'jpg', 'png'); if (isset($_POST['editstaff'])) { $tname = $_POST['tname']; $temail = $_POST['temail']; $tmobile = $_POST['tmobile']; $taddress = $_POST['taddress']; $tdob = $_POST['tdob']; $teach_id = $_POST['staffid']; $bfore = $_POST['taa']; $acdid = $_SESSION['child']['choosen_academic_id']; // print_r($_POST);exit; if ($_FILES['nonteach_pic']['name'] != '') { $ext = strtolower(pathinfo($_FILES['nonteach_pic']['name'], PATHINFO_EXTENSION)); if (in_array($ext, $valid_exts)) { $url = 'uploads/image' . date('mdhis') . '.jpg'; $files = basename($url); $filename = compress_image($_FILES["nonteach_pic"]["tmp_name"], $url, 70); //$operations->uploadmypic($teach_id,$files); } } if ($_SESSION['child']['current_academic_id'] != $_SESSION['child']['choosen_academic_id']) { $tapp = 2; } else if (isset($_POST['addapp'])){ $tapp = 1; } else { $tapp = 0; } // echo $tapp;exit; $teacher = $operations->edit_teacher_in_school($_SESSION['child']['auth_id'], $_SESSION['child']['log_school_id'], $teach_id, $tname, $tmobile, $temail, $taddress, $tdob, $tapp, $bfore, $acdid, $files); if ($teacher == '100') { echo "<script>location.replace('teacher_management.php')</script>"; } else { echo "<script>alert('The mobile number provided is already in use by another school/staff. Please provide a different mobile number and then try again')</script>"; } } function compress_image($source_url, $destination_url, $quality) { $info = getimagesize($source_url); if ($info['mime'] == 'image/jpeg') $image = imagecreatefromjpeg($source_url); elseif ($info['mime'] == 'image/gif') $image = imagecreatefromgif($source_url); elseif ($info['mime'] == 'image/png') $image = imagecreatefrompng($source_url); imagejpeg($image, $destination_url, $quality); return $destination_url; } ?> <style> #addapp { margin-top: -2px; margin-left: 2px; margin-right: 5px; } body { overflow-x: hidden; } .upload { /* background-color: #E1E1E1; */ width: 86px; /* margin: -30px 0px 0px 150px; */ height: 30px; text-align: center; font-size: 14px; padding: 5px 5px; color: #555555; border-radius: 4px; cursor: pointer; } </style> <div class="row" style="margin-top:30px;"> <div class="col-md-3 text-center" style="font:Arial, Helvetica, sans-serif;font-style:normal;font-size:14px; color:#000000; font-size:1.4em;margin-left:-35px;"> <i class="fa-solid fa-pencil " title="Edit Teacher" style="font-size: 16px;"></i> Edit Teacher </div> </div> <form class="form-horizontal" style="margin-top:30px; " enctype="multipart/form-data" method="post"> <div class="box-body" style="background-color:#fff; padding: 10px; font-family:Arial, Helvetica, sans-serif; font-size:13px; "> <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;">Name </b> <span style="color:#FF0000; margin-left:-2px; ">*</span> </div> <div class="col-md-7"> <input type="hidden" name="taa" value="<?= $staff['access_status']; ?>"> <input type="text" class="form-control" id="tname" name="tname" style="height:29px;font-size:13px;" maxlength="50" tabindex="1" value="<?php if (isset($_POST['tname'])) echo $_POST['tname']; else echo $staff['staff_name']; ?>"> <!-- if there is an error--> <div class="col-md-10" id="err_tname" 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;">Address </b> <span style="color:#FF0000; margin-left:-2px; ">*</span> </div> <div class="col-md-7"> <textarea class="form-control" id="taddress" name="taddress" rows="3" style="font-size:13px;" tabindex="2" maxlength="100"><?php if (isset($_POST['taddress'])) echo $_POST['taddress']; else echo $staff['staff_address']; ?></textarea> <!-- if there is an error--> <div class="col-md-10" id="err_taddress" 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;">Phone Number</b> <span style="color:#FF0000; margin-left:-2px; ">*</span> </div> <div class="col-md-7"> <input type="text" class="form-control" id="tmobile" maxlength="10" name="tmobile" style="height:29px;font-size:13px;" tabindex="3" value="<?php if (isset($_POST['tmobile'])) echo $_POST['tmobile']; else echo $staff['staff_mobile']; ?>" placeholder="10 digit Mobile Number"> <!-- if there is an error--> <div class="col-md-10" id="err_tmobile" style="color:#990000;"></div> <!--- end error--> </div> </div> </div> <input type="hidden" name="staffid" value="<?php echo $staff['staff_id']; ?>"> <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;">Email</b> <span style="color:#FF0000; margin-left:-2px; ">*</span> </div> <div class="col-md-7"> <input type="text" class="form-control" id="temail" name="temail" style="height:29px;font-size:13px;" tabindex="4" value="<?php if (isset($_POST['temail'])) echo $_POST['temail']; else echo $staff['staff_email']; ?>" maxlength="50"> <!-- if there is an error--> <div class="col-md-10" id="err_temail" 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;">Birth Date</b> <span style="color:#FF0000; margin-left:-2px; ">*</span> </div> <div class="col-md-7 "> <div class="input-group date d-flex" id="datetimepicker"> <input type="text" class="form-control" id="tdob" name="tdob" value="<?php if (isset($_POST['tdob'])) echo $_POST['tdob']; else echo $staff['date_of_birth']; ?>" style="font-size:13px; " tabindex="5"> <span class="input-group-append"> <span class="input-group-text bg-light d-block " style="text-align:center;"> <i class="fa fa-calendar-alt"></i> </span> </span> </div> <!-- <div id="datetimepicker" class="input-append date"> <input type="text" id="tdob" name="tdob" value="<?php if (isset($_POST['tdob'])) echo $_POST['tdob']; else echo $staff['date_of_birth']; ?>" style="height:30px; font-size:13px; width:278px!important;" tabindex="5"> <span class="add-on" style="height:30px;"> <i data-time-icon="icon-time" data-date-icon="icon-calendar"></i> </span> </div> --> <!-- if there is an error--> <div class="col-md-10" id="err_tdob" style="color:#990000;"></div> <!--- end error--> </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"></div> <div class=" col-md-7 "> <input type="checkbox" name="addapp" id="addapp" tabindex="6" <?php if (isset($_POST['addapp'])) echo "checked"; else if ($staff['access_status'] == '1') echo "checked"; ?>>Allow access to <?php echo $appdetails['app_name']; ?> Teacher App<br> </div> </div> </div> <div class="class" id="stimg"> <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; ">Image</b><span style="color:#FF0000; margin:2px;"></span> </div> <div class="col-md-5 d-flex"> <input type="text" class="form-control" name="file_name1" id="file_name1" value="<?php echo $staff[staff_pic] ?>" style="height:30px; width:126px;margin-left:6%;" readonly> <div class="upload btn btn-success col-md-6" onclick="$('#nonteach_pic').click()" style="color:#fff;height:30px;width:67px;margin-left:-6px;">Browse</div> <input type="file" name="nonteach_pic" id="nonteach_pic" class="img" style="display:none;" onchange="getnameit()"> <!-- if there is an error--> <div class="col-md-10" id="err_pic" style="color:#990000;margin-left:-3px;"></div> <!--- end error--> </div> <div class="col-md-2"> <img class='img-circle rounded' style=" width:100px;height:100px;" src='<?php if ($staff[staff_pic] == '') echo '//placehold.it/200x200'; else echo 'uploads/' . $staff[staff_pic]; ?>' id="imgsr" /> </div> </div> </div> <div class="form-group"> <div class="col-md-8" align="center"> <button type="submit" name="editstaff" onclick="return checkteacherfields();" class="btn btn-outline-secondary custom-button-width .navbar-right btnclr" tabindex="6" style="font-family:Arial, Helvetica, sans-serif;font-style:normal;font-size:13px; margin:10px; ">Update</button> <button type="button" class="btn btn-outline-secondary custom-button-width .navbar-right btnclr" tabindex="7" style="font-family:Arial, Helvetica, sans-serif;font-style:normal;font-size:13px; margin:10px;" onclick="updatecancel();">Cancel</button> </div> </div> </div> </div> </form> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> <!-- <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script> --> <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.8.3/jquery.min.js"> </script> <script type="text/javascript" src="https://netdna.bootstrapcdn.com/twitter-bootstrap/2.2.2/js/bootstrap.min.js"> </script> <script type="text/javascript" src="https://tarruda.github.com/bootstrap-datetimepicker/assets/js/bootstrap-datetimepicker.min.js"> </script> <script type="text/javascript" src="https://tarruda.github.com/bootstrap-datetimepicker/assets/js/bootstrap-datetimepicker.pt-BR.js"> </script> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-datepicker@1.9.0/dist/css/bootstrap-datepicker.min.css"> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.9.0/js/bootstrap-datepicker.min.js"></script> <script type="text/javascript"> $('#datetimepicker').datepicker({ format: 'dd/mm/yyyy', pickTime: false }).on('changeDate', function() { $(this).datetimepicker('hide'); }); </script> <script type="text/javascript"> $('#datetimepicker1').datepicker({ format: 'dd/mm/yyyy', pickTime: false }).on('changeDate', function() { $(this).datetimepicker('hide'); }); </script> <script> function checkteacherfields() { var tname = document.getElementById('tname').value; var taddress = document.getElementById('taddress').value; var tphone = document.getElementById('tmobile').value; var temail = document.getElementById('temail').value; var tdob = document.getElementById('tdob').value; var regex = /^[a-zA-Z0-9 ]*$/; var regex1 = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$/; var regex2 = /^[0-9]*$/; var sDate = new Date(tdob); re = /^\d{1,2}\/\d{1,2}\/\d{4}$/; var charallow = /^[ A-Za-z0-9\n_@.,#;:\/\-]*$/; $('#err_tname').text(''); $('#err_taddress').text(''); $('#err_tmobile').text(''); $('#err_temail').text(''); $('#err_tdob').text(''); if (tname == '') { $('#err_tname').text('Please enter Teacher Name'); document.getElementById('tname').focus(); return false; } else if (!regex.test(tname)) { $('#err_tname').text('Please enter a valid Teacher Name'); document.getElementById('tname').focus(); return false; } else if (taddress == '') { $('#err_taddress').text('Please enter Address'); document.getElementById('taddress').focus(); return false; } else if (!charallow.test(taddress)) { $('#err_taddress').text('Please enter a valid Address'); document.getElementById('taddress').focus(); return false; } else if (tphone == '') { $('#err_tmobile').text('Please enter Phone Number'); document.getElementById('tmobile').focus(); return false; } else if (!regex2.test(tphone)) { $('#err_tmobile').text('Please enter a valid Phone Number'); document.getElementById('tmobile').focus(); return false; } else if (tphone.length != 10) { $('#err_tmobile').text('Please enter a valid Phone Number'); document.getElementById('tmobile').focus(); return false; } else if (temail == '') { $('#err_temail').text('Please enter Email Address'); document.getElementById('temail').focus(); return false; } else if (!regex1.test(temail)) { $('#err_temail').text('Please enter a valid Email Address'); document.getElementById('temail').focus(); return false; } else if (tdob == '') { $('#err_tdob').text('Please enter Birth Date'); document.getElementById('tdob').focus(); return false; } /*else if(!sDate.match(re)) { $('#err_tdob').text("Invalid Date"); document.getElementById('tdob').focus(); return false; }*/ } function updatecancel() { window.location.href = "teacher_management.php"; } function getnameit() { x = $('#nonteach_pic').val(); $('#file_name1').val(x); } $('#nonteach_pic').change(function(event) { var tmppath = URL.createObjectURL(event.target.files[0]); if (tmppath == null) { $('#imgsr').prop('src', '//placehold.it/200x200'); } else { $("#imgsr").fadeIn("fast").attr('src', URL.createObjectURL(event.target.files[0])); } }); </script> </div> </body> </html>