JezK
Edit File: add_teacher.php
<?php session_start(); include("session_check.php"); include('adm_operations.php'); include("header.php"); $operations = new adm_operations(); $appdetails = $operations->gettingAppDetails(); $valid_exts = array('jpeg', 'jpg', 'png'); include('school_timeout.php'); if (isset($_POST['staffsubmit'])) { // echo $_POST['addapp'];exit; $tname = $_POST['tname']; $temail = $_POST['temail']; $tmobile = $_POST['tmobile']; $taddress = $_POST['taddress']; $tdob = $_POST['tdob']; //if($_FILES["nonteach_pic"]["name"]) //{ //$t = $_FILES["nonteach_pic"]["tmp_name"]; //$n = $_FILES["nonteach_pic"]["name"]; //$p=strtotime(date('d-m-Y H:i:s')); //$k=substr(str_shuffle($p),0,5); //$tfname=$k.$n; //if(move_uploaded_file($t, "uploads/".$tfname)) //{ //$attachment_file=$tfname; //} //} //echo $attachment_file; //exit; if ($_SESSION['child']['current_academic_id'] != $_SESSION['child']['choosen_academic_id']){ $tapp = 2; } else if (isset($_POST['addapp'])){ $tapp = 1; } else { $tapp = 2; } $acdid = $_SESSION['child']['choosen_academic_id']; // print_r($tapp);exit; $teacher = $operations->add_teacher_to_school($_SESSION['child']['auth_id'], $_SESSION['child']['log_school_id'], $tname, $tmobile, $temail, $taddress, $tdob, $acdid, $tapp); // print_r($teacher);exit; if ($teacher != 101) { 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($teacher, $files); } } // echo 'jkjjkj';exit; 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 fa-plus " title="Add Teacher" style="font-size: 20px;"></i> Add Teacher </div> </div> <form class="form-horizontal col-md-11 offset-md-1 " enctype="multipart/form-data" style="margin-top:30px; " 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 justify-content-center col-md-6" style="margin-bottom:1.0%; clear:both;"> <div class="col-md-4 text-md-end px-2"> <b style="color:#666666;">Name </b> <span style="color:#FF0000;margin-left:-2px;">*</span> </div> <div class="col-md-7 "> <input type="text" class="form-control" id="tname" name="tname" style="height:29px;font-size:13px;" tabindex="1" value="<?php echo $_POST['tname']; ?>" maxlength="50"> <!-- 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 justify-content-center col-md-6" style="margin-bottom:1.0%; clear:both;"> <div class="col-md-4 text-md-end px-2"> <b style="color:#666666;">Address </b> <span style="color:#FF0000;margin-left:-2px;">*</span> </div> <div class="col-md-7"> <textarea class="form-control" rows="3" id="taddress" name="taddress" style="font-size:13px;" tabindex="2" maxlength="100"><?php echo $_POST['taddress']; ?></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 justify-content-center col-md-6" style="margin-bottom:1.0%; clear:both;"> <div class="col-md-4 text-md-end px-2"> <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" name="tmobile" maxlength="10" style="height:29px;font-size:13px;" tabindex="3" value="<?php echo $_POST['tmobile']; ?>" 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> <div class="class"> <div class="form-group row justify-content-center col-md-6" style="margin-bottom:1.0%; clear:both;"> <div class="col-md-4 text-md-end px-2"> <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 echo $_POST['temail']; ?>" 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 justify-content-center col-md-6" style="margin-bottom:1.0%; clear:both;"> <div class="col-md-4 text-md-end px-2"> <b style="color:#666666;">Birth Date</b> <span style="color:#FF0000;margin-left:-2px;">*</span> </div> <div class="col-md-7"> <div id="datetimepicker" class="input-append date"> <input type="text" class="form-control" id="tdob" name="tdob" style="height:30px; font-size:13px; width:215px!important;" tabindex="5" value="<?php echo $_POST['tdob']; ?>"> <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 justify-content-center col-md-6" style="margin-bottom:1.0%; clear:both;"> <div class="col-md-4 text-md-end px-2"> </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 justify-content-center col-md-6" style="margin-bottom:1.0%; clear:both;"> <div class="col-md-4 text-md-end px-2"> <b style="color:#666666; ">Image</b><span style="color:#FF0000; margin:2px;"></span> </div> <div class="col-md-6 d-flex "> <input type="text" class="form-control col-md-6" name="file_name1" id="file_name1" 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' src='//placehold.it/200x200' style=" width:100px;height:100px;" id="imgsr" /> </div> </div> </div> <div class="form-group"> <div class="col-md-8" align="center"> <button type="submit" name="staffsubmit" onclick="return checkteacherfields()" 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; ">Add</button> <button type="button" class="btn btn-outline-secondary custom-button-width .navbar-right btnclr" tabindex="8" style="font-family:Arial, Helvetica, sans-serif;font-style:normal;font-size:13px; margin:10px;" onclick="addcancel()">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="https://cdn.jsdelivr.net/npm/@popperjs/core@2.11.6/dist/umd/popper.min.js" integrity="sha384-oBqDVmMz9ATKxIep9tiCxS/Z9fNfEXiDAYTujMAeBAsjFuCZSmKbSSUnQlmh/jp3" crossorigin="anonymous"></script> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha2/dist/js/bootstrap.min.js" integrity="sha384-heAjqF+bCxXpCWLa6Zhcp4fu20XoNIA98ecBC1YkdXhszjoejr5y9Q77hIrv8R9i" crossorigin="anonymous"></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="http://tarruda.github.com/bootstrap-datetimepicker/assets/js/bootstrap-datetimepicker.min.js"> </script> --> <!-- <script type="text/javascript" src="http://tarruda.github.com/bootstrap-datetimepicker/assets/js/bootstrap-datetimepicker.pt-BR.js"> </script> --> <script type="text/javascript"> $('#datetimepicker').datetimepicker({ format: 'dd/MM/yyyy', pickTime: false }).on('changeDate', function() { $(this).datetimepicker('hide'); }); </script> <script type="text/javascript"> $('#datetimepicker1').datetimepicker({ 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 arrStartDate = tdob.split("/"); var sDate = new Date(arrStartDate[2], arrStartDate[1], arrStartDate[0]); 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 addcancel() { 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>