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']; 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; $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; } </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=" glyphicon glyphicon-pencil " title ="Edit Teacher" style="font-size: 16px;"></i> Edit Teacher </div> </div> <form class="form-horizontal" style="margin-top:30px; margin-left:-100px;" 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 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;">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;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;">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;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;">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;margin-left:-15px;"></div> <!--- end error--> </div> </div> </div> <input type="hidden" name="staffid" value="<? echo $staff['staff_id'];?>"> <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;">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;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;">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" 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;margin-left:-15px;"></div> <!--- end error--> </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"></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";?> <?php if($_SESSION['child']['current_academic_id']!=$_SESSION['child']['choosen_academic_id']) echo 'disabled';?>>Allow access to <?php echo $appdetails['app_name'];?> Teacher App<br> </div> </div> </div> <div class="class" id="stimg"> <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; ">Image</b><span style="color:#FF0000; margin:2px;"></span> </div> <div class="col-md-5"> <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" onclick="$('#nonteach_pic').click()" style="color:#fff;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' src='<?php if($staff[staff_pic]=='') echo '//placehold.it/200x200';else echo 'uploads/'.$staff[staff_pic];?>' style="" 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-default 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-default 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="http://cdnjs.cloudflare.com/ajax/libs/jquery/1.8.3/jquery.min.js"> </script> <script type="text/javascript" src="http://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 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>