JezK
Edit File: add_nonteaching.php
<?php session_start(); include("session_check.php"); include("header.php"); include_once("adm_operations2.php"); ini_set("memory_limit", "512M"); $nonteach = new adm_operations2(); $valid_exts = array('jpeg', 'jpg', 'png'); if (isset($_POST['addnt'])) { $result = $nonteach->create_nonteach_staff($_POST, $_SESSION); if ($result == 'exists') { 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>"; } else if ($result == ERR204) { echo 1234; echo "<script>location.replace('nonteaching.php');</script>"; } else { 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); $nonteach->uploadmypic($result, $files); } } echo "<script>location.replace('nonteaching.php');</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> .upload { /* background-color: #E1E1E1; */ width: 86px; /* margin: -51px 0px 0px 150px; */ height: 30px; text-align: center; font-size: 14px; padding: 5px 5px; color: #555555; border-radius: 4px; cursor: pointer; } /* @media screen and (min-width: 1366px) { margin-left: -4px; } */ </style> <script> function inputvalidations() { $('#err_type').text(''); $('#err_name').text(''); $('#err_father_name').text(''); $('#err_address').text(''); $('#err_mobile').text(''); $('#err_licensenumber').text(''); $('#err_issuing_authority').text(''); $('#err_email').text(''); $('#err_pic').text(''); var staff_type = document.getElementById('staff_type').value; var staff_name = (document.getElementById('staff_name').value).trim(); var staff_person = (document.getElementById('staff_person').value).trim(); var staff_address = (document.getElementById('staff_address').value).trim(); var staff_number = (document.getElementById('staff_number').value).trim(); var staff_email = (document.getElementById('email_id').value).trim(); var regex = /^[a-zA-Z0-9 ]*$/; var regex2 = /^[0-9]*$/; var emreg = /^[a-zA-Z0-9._\-]+@[a-zA-Z0-9.\-]+\.[a-zA-Z]{2,6}$/; var charallow = /^[A-Za-z0-9\n_@.,#;:\/\- ]*$/; if (staff_type == 2) { var staff_licence = (document.getElementById('staff_licence').value).trim(); var staff_issuing = (document.getElementById('issuing_authority').value).trim(); var pic = document.getElementById('nonteach_pic').value; } if (staff_type == '') { document.getElementById('staff_type').focus(); $('#err_type').text('Please enter Staff Type'); $('#err_type').show(); return false; } else if (staff_name == '') { document.getElementById('staff_name').focus(); $('#err_name').text('Please enter Staff Name'); $('#err_name').show(); return false; } else if (!regex.test(staff_name)) { document.getElementById('staff_name').focus(); $('#err_name').text('Please enter a valid Staff Name'); $('#err_name').show(); return false; } else if (staff_person == '') { document.getElementById('staff_person').focus(); $('#err_father_name').text('Please enter Father/Spouse Name'); $('#err_father_name').show(); return false; } else if (!regex.test(staff_person)) { document.getElementById('staff_person').focus(); $('#err_father_name').text('Please enter a valid Father/Spouse Name'); $('#err_father_name').show(); return false; } else if (staff_address == '') { document.getElementById('staff_address').focus(); $('#err_address').text('Please enter Staff Address'); $('#err_address').show(); return false; } else if (!charallow.test(staff_address)) { document.getElementById('staff_address').focus(); $('#err_address').text('Please enter a valid Staff Address'); $('#err_address').show(); return false; } else if (staff_number == '') { document.getElementById('staff_number').focus(); $('#err_mobile').text('Please enter Mobile Number'); $('#err_mobile').show(); return false; } else if (!regex2.test(staff_number)) { document.getElementById('staff_number').focus(); $('#err_mobile').text('Please enter a valid Mobile Number'); $('#err_mobile').show(); return false; } else if (staff_number.length != 10) { document.getElementById('staff_number').focus(); $('#err_mobile').text('Please enter a valid Mobile Number'); $('#err_mobile').show(); return false; } else if (staff_email == '') { document.getElementById('email_id').focus(); $('#err_email').text('Please enter Email'); $('#err_email').show(); return false; } else if (!emreg.test(staff_email)) { document.getElementById('email_id').focus(); $('#err_email').text('Please enter a valid Email'); $('#err_email').show(); return false; } else if (staff_licence == '' && staff_type == 2) { document.getElementById('staff_licence').focus(); $('#err_licensenumber').text('Please enter License Number'); $('#err_licensenumber').show(); return false; } else if (!charallow.test(staff_licence) && staff_type == 2) { document.getElementById('staff_licence').focus(); $('#err_licensenumber').text('Please enter a valid License Number'); $('#err_licensenumber').show(); return false; } else if (staff_issuing == '' && staff_type == 2) { document.getElementById('issuing_authority').focus(); $('#err_issuing_authority').text('Please enter License Issuing Authority'); $('#err_issuing_authority').show(); return false; } else if (!regex.test(staff_issuing) && staff_type == 2) { document.getElementById('issuing_authority').focus(); $('#err_issuing_authority').text('Please enter a valid License Issuing Authority'); $('#err_issuing_authority').show(); return false; } /*else { input = document.getElementById('nonteach_pic'); file = input.files[0]; if(file.size>400000) alert('please upload image less than 400kb'); }*/ } </script> <body style="overflow-x: hidden;"> <div class="row" style="margin-top: 30px; margin-left:20px;margin-top:30px;"> <div class="col-md-9 text-left" style="font:Arial, Helvetica, sans-serif;font-style:normal;font-size:24px; margin-left:20px;"> <i class=" fa fa-plus" title="Add Staff" style="font-size: 20px;"></i> Add Staff </div> <form class="form-horizontal col-md-11 offset-md-1" enctype="multipart/form-data" name="non_teanfrm" id="non_teachfrm" 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 col-md-6" style="margin-bottom:1.0%; clear:both;"> <div class="col-md-4 text-md-end"> <b style="color:#666666; ">Type</b><span style="color:#FF0000; margin:2px;">*</span> </div> <div class="col-md-7"> <select class="form-select" onchange="check_type(this.value)" id="staff_type" name="staff_type" style="height:29px; font-size:12px;margin-left: 3%;" tabindex="1"> <option selected="selected" value=''>--Select type--</option> <option value='2' <?php if ($_POST['staff_type'] == 2) echo "selected"; ?>>Driver</option> <option value='3' <?php if ($_POST['staff_type'] == 3) echo "selected"; ?>>Admin Staff</option> <option value='4' <?php if ($_POST['staff_type'] == 4) echo "selected"; ?>>Maid</option> <option value='5' <?php if ($_POST['staff_type'] == 5) echo "selected"; ?>>Others</option> </select> <!-- if there is an error--> <div class="col-md-10" id="err_type" style="color:#990000;margin-left:-2px;"></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 text-md-end"> <b style="color:#666666;">Name </b><span style="color:#FF0000; margin:2px; ">*</span> </div> <div class="col-md-7"> <input type="text" class="form-control" value="<?php echo $_POST['staff_name'] ?>" id="staff_name" name="staff_name" style="height:29px;font-size:13px;margin-left:10px;" tabindex="2" placeholder=" Full Name" maxlength="50"> <!-- if there is an error--> <div class="col-md-10" id="err_name" style="color:#990000;margin-left:-3px;"></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 text-md-end"> <b style="color:#666666;">Father/Spouse Name</b><span style="color:#FF0000; margin:2px; ">*</span> </div> <div class="col-md-7"> <input type="text" class="form-control" id="staff_person" value="<?php echo $_POST['staff_person'] ?>" name="staff_person" style="height:29px;font-size:13px;margin-left:10px;" tabindex="3" maxlength="50"> <!-- if there is an error--> <div class="col-md-10" id="err_father_name" style="color:#990000;margin-left:-3px;"></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 text-md-end"> <b style="color:#666666;">Address </b><span style="color:#FF0000; margin:2px; ">*</span> </div> <div class="col-md-7"> <textarea class="form-control" rows="3" name="staff_address" id="staff_address" style="font-size:13px;margin-left:10px;" tabindex="4" maxlength="100"><?php echo $_POST['staff_address'] ?></textarea> <!-- if there is an error--> <div class="col-md-10" id="err_address" style="color:#990000;margin-left:-3px;"></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 text-md-end "> <b style="color:#666666;">Mobile Number</b><span style="color:#FF0000; margin:2px; ">*</span> </div> <div class="col-md-7"> <input type="text" class="form-control" id="staff_number" value="<?php echo $_POST['staff_number'] ?>" name="staff_number" style="height:29px;font-size:13px;margin-left:10px;" tabindex="5" maxlength="10" placeholder="10 digit Mobile Number"> <!-- if there is an error--> <div class="col-md-10" id="err_mobile" style="color:#990000;margin-left:-3px;"></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 text-md-end"> <b style="color:#666666;">Email</b><span style="color:#FF0000; margin:2px; ">*</span> </div> <div class="col-md-7"> <input type="text" class="form-control" value="<?php echo $_POST['email_id'] ?>" id="email_id" name="email_id" style="height:29px;font-size:13px;margin-left:10px;" tabindex="6" maxlength="50"> <!-- if there is an error--> <div class="col-md-10" id="err_email" style="color:#990000;margin-left:-3px;"></div> <!--- end error--> </div> </div> </div> <div id="driver_details" name="driver_details" style="display:none;"> <div class="class"> <div class="form-group row col-md-6" style="margin-bottom:1.0%; clear:both;"> <div class="col-md-4 text-md-end"> <b style="color:#666666;">License Number</b><span style="color:#FF0000; margin:2px; ">*</span> </div> <div class="col-md-7"> <input type="text" class="form-control" value="<?php echo $_POST['staff_licence'] ?>" id="staff_licence" name="staff_licence" style="height:29px;font-size:13px;margin-left:10px;" tabindex="7" maxlength="15"> <!-- if there is an error--> <div class="col-md-10" id="err_licensenumber" style="color:#990000;margin-left:-3px;"></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 text-md-end"> <b style="color:#666666; ">License Issuing Authority</b><span style="color:#FF0000; margin:2px;">*</span> </div> <div class="col-md-7"> <input type="text" class="form-control" value="<?php echo $_POST['issuing_authority'] ?>" id="issuing_authority" name="issuing_authority" style="height:29px;font-size:13px;margin-left:10px;" tabindex="7" maxlength="50"> <!-- if there is an error--> <div class="col-md-10" id="err_issuing_authority" style="color:#990000;margin-left:-3px;"></div> <!--- end error--> </div> </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 text-md-end"> <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" name="file_name1" id="file_name1" style="height:30px;width:165px;margin-left:6%;" readonly> <div class="upload btn btn-success" onclick="$('#nonteach_pic').click()" style="color:#fff;width:67px;">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"> <input type="submit" class="btn btn-outline-secondary custom-button-width .navbar-right btnclr" name="addnt" tabindex="10" style="font-family:Arial, Helvetica, sans-serif;font-style:normal;font-size:13px; margin:10px; " onclick="return inputvalidations();" value="Add"> <button type="button" class="btn btn-outline-secondary custom-button-width .navbar-right btnclr" onclick="getback()" tabindex="17" style="font-family:Arial, Helvetica, sans-serif;font-style:normal;font-size:13px; margin:10px; ">Cancel</button> </div> </div> </div> </form> </div> <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 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 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> <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'); }); if ($('#staff_type').val() == 2) { document.getElementById('driver_details').style.display = "block"; } function check_type(val) { if (val == 2) { document.getElementById('driver_details').style.display = "block"; } else { document.getElementById('driver_details').style.display = "none"; } } function getback() { window.location.href = "nonteaching.php"; } function getnameit() { x = $('#nonteach_pic').val(); $('#file_name1').val(x); } $('#nonteach_pic').change(function(event) { alert(); 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> </body> </html>