0byt3m1n1
Path:
/
home
/
k74ns2xygros
/
www
/
globetech
/
cms
/
admin
/
[
Home
]
File: addsubadmin.php
<?php session_start(); error_reporting(0); $admin_cid = $_SESSION['admin_cid']; include "../assets/config.php"; //require_once 'database.php'; $user = new User(); $zone = $user->getzone(); $noofzones = sizeof($zone); //$edds = $user->getedds(); $companys = $user->getcompany(); $company_roles = $user->get_company_roles(); include '../assets/head.php'; include '../assets/admin_nav.php'; ?> <?php if (isset($_POST['add_admin'])) { // echo 'yes'.$_POST['role']; if (isset($_POST['change_loc']) && empty($_POST['zone'])) { $error = "Please select Zone to change location."; } else if (isset($_POST['change_loc']) && empty($_POST['s_engineer'])) { $error = "Please select Superitendent Engineer to change location."; } else if (isset($_POST['change_loc']) && empty($_POST['ex_engineer'])) { $error = "Please select Executive Engineer to change location."; } else if (isset($_POST['change_loc']) && empty($_POST['electry_city'])) { $error = "Please select Substation to change location."; } else if (empty($_POST['role'])) { $error = "Please select Role for new admin."; } else if (empty($_POST['companys'])) { $error = "Please select Company for new admin."; } else if (empty($_POST['edds'])) { $error = "Please select Executive Engg. for new admin."; } else { $emp_id = $_POST['emp_id']; $emp_no = $_POST['emp_no']; $voucher_max_amount = $_POST['voucher_max_amount']; if($voucher_max_amount==''){ $voucher_max_amount='0.00'; } //print_r($_FILE) /* ============================= File Upload ====================================== */ if (isset($_FILES['fileToUpload']) && !empty($_FILES['fileToUpload']['name'])) { // $target_dir = "../uploads/"; $target_dir = '../uploads' . '/' . date('Y/m/'); // # create directory if not exists IN admin_files/ directory // if (!is_dir($target_dir)) { // mkdir($target_dir, 0755); // } or // #Check if directory exists if not create it // if (!is_dir($target_dir)) { // mkdir($target_dir); // } $tags = explode('/', $target_dir); // explode the full path $mkDir = ""; foreach ($tags as $folder) { $mkDir = $mkDir . $folder . "/"; // make one directory join one other for the nest directory to make // echo '"' . $mkDir . '"<br/>'; // this will show the directory created each time if (!is_dir($mkDir)) { // check if directory exist or not mkdir($mkDir, 0777); // if not exist then make the directory } } $target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]); $target_file1 = $target_dir . date('dmYHis') . $emp_no . '.jpg'; $target_file1 = str_replace(' ', '+', $target_file1); $uploadOk = 1; $imageFileType = strtolower(pathinfo($target_file, PATHINFO_EXTENSION)); // Check if image images is a actual image or fake image global $errtext; $check = getimagesize($_FILES["fileToUpload"]["tmp_name"]); if ($check !== false) { "File is an image - " . $check["mime"] . "."; $uploadOk = 1; } else { $errtext = "File is not an image."; $uploadOk = 0; } // Check images size if ($_FILES["fileToUpload"]["size"] > 300000) { echo $errtext = "Sorry, your image size is larger than 300 KB."; $uploadOk = 0; } // Allow certain images formats if ($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" && $imageFileType != "gif" && $imageFileType != "JPG" && $imageFileType != "PNG" && $imageFileType != "JPEG" && $imageFileType != "GIF") { echo $errtext = "Sorry, only JPG, JPEG, PNG & GIF imagess are allowed."; $uploadOk = 0; } if (file_exists($target_file)) { chmod($target_file, 0755); //Change the file permissions if allowed unlink($target_file); //remove the file } // Check if $uploadOk is set to 0 by an error if ($uploadOk == 0) { echo "Sorry, your images was not uploaded due to " . $errtext; // if everything is ok, try to upload images } else { if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file1)) { $fileToUpload = $target_file1; $errtext = "The images " . basename($_FILES["fileToUpload"]["name"]) . " has been uploaded."; $x = 'ok'; } else { echo $errtext = "Sorry, there was an error uploading your images."; } } } else { $x = 'ok'; } if ($x == 'ok') { $role = json_encode($_POST['role']); $edds = json_encode($_POST['edds']); $companys = json_encode($_POST['companys']); $enc_password = md5($_POST['password']); $sql = "INSERT INTO `sub_admin` (`name`, `admin_emp_no`, `user_name`, `password`, `sign` , `role`, `edds`, `companys`, `voucher_max_amount`, `emp_id`) VALUES ('" . $_POST['name'] . "', '" . $_POST['emp_no'] . "', '" . $_POST['user_name'] . "', '$enc_password','$target_file1' ,'$role' ,'$edds' ,'$companys' ,'$voucher_max_amount', '$emp_id')"; if ($user->insert($sql) > 0) { // if (in_array(6, $_POST['role'])) { if (isset($_POST['change_loc'])) { $update_query = "UPDATE `employee` SET `zone`='" . $_POST['zone'] . "',`s_engineer`='" . $_POST['s_engineer'] . "',`ex_engineer`='" . $_POST['ex_engineer'] . "',`electrycity_zone`='" . $_POST['electry_city'] . "' WHERE `cid`='$emp_id'"; $user->update_query($update_query); } $success = "New Admin Added Successfully."; } else { $error = "Something went wrong! " . mysqli_error($user->conn); } } else { $error = $errtext; } } } ?> <html> <head> <script> if (window.history.replaceState) { window.history.replaceState(null, null, window.location.href); } </script> <title>Add New Admin</title> <!--<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>--> <script src="../vendors/jquery/dist/jquery.min.js"></script> <script src="../js/myjs/ajax.js" type="text/javascript"></script> <style> .form-horizontal .checkbox-inline{ margin-left: auto; } </style> </head> <body> <div class="right_col" role="main" style="padding-top: 10px;text-transform: uppercase"> <div class="row"> <div class="col-md-10 col-md-offset-1 col-sm-10 col-md-offset-1 col-xs-12"> <div class="x_panel"> <div class="x_title"> <h2>Add New Admin <small></small></h2> <div class="clearfix"></div> </div> <div class="x_content"> <br> <form class="form-horizontal" method="post" enctype="multipart/form-data" onsubmit="return validate()"> <?php if ($error != ''): ?> <div class="form-group"> <div class="alert alert-danger alert-dismissible"> <a href="#" class="close" data-dismiss="alert" aria-label="close">×</a> <strong>Error!</strong> <?= $error; ?> </div> </div> <?php $error = ''; endif; ?> <?php if ($success != ''): ?> <div class="form-group"> <div class="alert alert-success alert-dismissible"> <a href="#" class="close" data-dismiss="alert" aria-label="close">×</a> <strong>Success!</strong> <?= $success; ?> </div> </div> <?php $success = ''; endif; ?> <div class="row"> <div class="form-group col-md-6 col-sm-6 col-xs-6"> <label class="control-label">Employee ID/MOBILE NO </label> <div class="form-input"> <input type="text" class="form-control" name="emp_no" onblur="show_emp_details(this.value)" onkeyup="show_emp_details(this.value)" placeholder="Enter Admin Employee Id or Mobile No." required> </div> </div> <div class="form-group col-md-6 col-sm-6 col-xs-6"> <label class="control-label"> Password </label> <div class="form-input"> <input type="text" class="form-control" name="password" placeholder="Set login password " required> </div> </div> </div> <div class="row" id="admin_det"> </div> <div class="row"> <div class="form-group col-md-6 col-sm-6 col-xs-6"> <label class="control-label">Select Roles </label> <div class="form-input role checkbox-group required"> <?php $i = 1; foreach ($company_roles as $value) { ?> <div class="col-md-3 col-sm-3 col-xs-3"> <label class="checkbox-inline"> <input type="checkbox" value="<?php echo $value['id']; ?>" name="role[]" <?php if ($value['id'] == '14') { ?>id="voucher_check"<?php } ?>> <?php echo $value['role_name']; ?> </label> <?php if (fmod($i, 5) == 0) { // echo '<br><br>'; // echo '<br>'; } echo '</div>'; $i++; } ?> </div> </div> <div id="voucher_div" class="form-group col-md-6 col-sm-6 col-xs-6"> </div> </div> <div class="row"> <div class="form-group col-md-6 col-sm-6 col-xs-6"> <label class="control-label"> Upload Sign </label> <div class="form-input"> <input type="file" class="form-control" name="fileToUpload" required=""> </div> </div> </div> <div class="row"> <div class="form-group col-md-6 col-sm-6 col-xs-6"> <label class="control-label"> Change Location </label> <input type="checkbox" id="change_loc" name="change_loc"> </div> </div> <div class="row" id="update_loc" style="display: none;"> <!--<span id="update_loc">--> <div class="form-group col-md-6 col-sm-6 col-xs-6"> <label class="control-label">Select Zone </label> <div class="form-input"> <select id="zone" name="zone" class="zone form-dropdown form-control" style="text-transform:uppercase"> <option value="">--Select Zone--</option> <?php foreach ($zone as $row) { ?> <option value="<?php echo $row['zone_name']; ?>"><?php echo $row['zone_name']; ?></option> <?php } ?> </select></div> </div> <div class="form-group col-md-6 col-sm-6 col-xs-6"> <label class="control-label">SUPERINTENDING ENGINEER </label> <div class="form-input"> <select id="s_engineer" name="s_engineer" class="s_engineer form-dropdown form-control" style="text-transform:uppercase"> <option value="">--SELECT SUPERINTENDING ENGINEER--</option> </select></div> </div> <div class="form-group col-md-6 col-sm-6 col-xs-6"> <label class="control-label">EXECUTIVE ENGINEER </label> <div class="form-input"> <select id="ex_engineer" name="ex_engineer" class="ex_engineer form-dropdown form-control" style="text-transform:uppercase"> <option value="">--SELECT EXECUTIVE ENGINEER--</option> </select></div> </div> <div class="form-group col-md-6 col-sm-6 col-xs-6"> <label class="control-label">WORKING SUBSTATION * </label> <div class="form-input"> <select id="electry_city" name="electry_city" class="electry_city form-dropdown form-control" style="text-transform:uppercase"> <option value="">--Select Electric Sub Station--</option> </select></div> </div> <!--</span>--> </div> <div class="row"> <div class="form-group col-md-6 col-sm-6 col-xs-6"> <label class="control-label"> Working Company </label> <div class="form-input companys checkbox-group required"> <?php foreach ($companys as $value) { ?> <label class="checkbox-inline"> <input type="checkbox" value="<?php echo $value['ep_id']; ?>" name="companys[]"> <?php echo $value['ep_name']; ?> </label> <br> <?php } ?> </div> </div> <div class="form-group col-md-6 col-sm-6 col-xs-6"> <label class="control-label"> Admin For Executive Engg. </label> <div class="form-input edds checkbox-group required"> <?php // foreach ($edds as $value) { ?> <!-- <label class="checkbox-inline"> <input type="checkbox" value="<?php echo $value['ex_id']; ?>" name="edds[]"> <?php echo $value['ex_name']; ?> </label> <br>--> <?php // } ?> </div> </div> </div> <div class="form-group"> <div class="ln_solid"> </div> <div class="col-md-12 col-sm-12 col-xs-12 text-center"> <button type="reset" class="btn btn-danger">Cancel</button> <button type="submit" name="add_admin" id="add_admin" class="btn btn-success">Add Admin</button> <!--<input type="submit" name="add_admin" class="btn btn-success" value="Add Admin">--> <!--<input type="submit" value="submit" onclick="return foo();" />--> </div> </div> </form> </div> </div> </div> </div> </div> </body> <?php include '../assets/foot.php'; ?> <script> function checkAll(checked_value) { // var checkboxes = document.getElementsByTagName('input'); var checkboxes = document.getElementsByName('edds[]'); if (checked_value) { for (var i = 0; i < checkboxes.length; i++) { if (checkboxes[i].type == 'checkbox') { checkboxes[i].checked = true; } } } else { for (var i = 0; i < checkboxes.length; i++) { // console.log(i) if (checkboxes[i].type == 'checkbox') { checkboxes[i].checked = false; } } } } function validate() { if ($('div.role.checkbox-group.required :checkbox:checked').length <= 0) { alert('Please select Role for new admin.'); return false; } if ($('div.companys.checkbox-group.required :checkbox:checked').length <= 0) { alert('Please select Company for new admin.'); return false; } if ($('div.edds.checkbox-group.required :checkbox:checked').length <= 0) { alert('Please select Executive Engg. for new admin.'); return false; } return true; } $(".companys").on('change', 'input[type=checkbox]', function () { var selected_company = []; $('.companys input[type="checkbox"]:checked').each(function () { // selected.push($(this).attr('name')); selected_company.push($(this).val()); }); // alert(selected_company); $.ajax({ url: "ajax_result.php", type: "GET", data: {"type": "get_edds", "id": selected_company}, success: function (data) { $(".edds").html(data); } }); }); $(function () { $('input[type="text"]').keyup(function () { this.value = this.value.toUpperCase(); }); $('input[name="whatsapp_api_key"]').keyup(function () { this.value = this.value.toLowerCase(); }); $('textarea').keyup(function () { this.value = this.value.toUpperCase(); }); }); $(document).ready(function () { $('#select').toggle(); $(document).click(function (e) { $('#select').attr('size', 0); }); $('#change_loc').change(function () { if (this.checked) { // document.getElementById("update_loc").innerHTML += '<div class="form-group col-md-6 col-sm-6 col-xs-6"> <label class="control-label">Select Zone </label> <div class="form-input"> <select id="zone" name="zone" class="zone form-dropdown form-control" style="text-transform:uppercase" required=""> <option selected="selected" disabled>--Select Zone--</option> <?php foreach ($zone as $row) { ?> <option value="<?php echo $row['zone_name']; ?>"><?php echo $row['zone_name']; ?></option> <?php } ?> </select></div> </div>'; // document.getElementById("update_loc").innerHTML += '<div class="form-group col-md-6 col-sm-6 col-xs-6"> <label class="control-label">SUPERINTENDING ENGINEER </label> <div class="form-input"> <select id="s_engineer" name="s_engineer" class="s_engineer form-dropdown form-control" style="text-transform:uppercase" required=""> <option selected="selected" disabled>--SELECT SUPERINTENDING ENGINEER--</option> </select></div> </div>'; // document.getElementById("update_loc").innerHTML += '<div class="form-group col-md-6 col-sm-6 col-xs-6"> <label class="control-label">EXECUTIVE ENGINEER </label> <div class="form-input"> <select id="ex_engineer" name="ex_engineer" class="ex_engineer form-dropdown form-control" style="text-transform:uppercase" required=""> <option selected="selected" disabled>--SELECT EXECUTIVE ENGINEER--</option> </select></div> </div>'; // document.getElementById("update_loc").innerHTML += '<div class="form-group col-md-6 col-sm-6 col-xs-6"> <label class="control-label">WORKING SUBSTATION * </label> <div class="form-input"> <select id="electry_city" name="electry_city" class="electry_city form-dropdown form-control" style="text-transform:uppercase" required=""> <option selected="selected" disabled>--Select Electric Sub Station--</option> </select></div> </div>'; $('#update_loc').show(); // $('#update_loc').css('display', 'block'); $('#zone').attr('required', true); $('#s_engineer').attr('required', true); $('#ex_engineer').attr('required', true); $('#electry_city').attr('required', true); } else { // $('#update_loc').html(''); $('#update_loc').hide(); // $('#update_loc').css('display', 'none'); $('#zone').attr('required', false); $('#s_engineer').attr('required', false); $('#ex_engineer').attr('required', false); $('#electry_city').attr('required', false); } }); $('#voucher_check').change(function () { if (this.checked) { $('#voucher_div').html('<label class="control-label">Enter Max Amount </label> <div class="form-input" style="width: 50%;"> <input type="number" id="voucher_max_amount" name="voucher_max_amount" class="form-control" placeholder="Enter Voucher Max Amount" value="0.00" required=""></div>'); } else { $('#voucher_div').html(''); } }); }); </script> <script type="text/javascript"> $(document).ready(function () { $("#zone").change(function () { // $('#zone').attr('size', 0); // $('.s_engineer').attr('size', 4); var id = $(this).val(); // alert(id); var dataString = 'id=' + id; $(".s_engineer").find('option').remove(); $(".ex_engineer").find('option').remove(); $(".electry_city").find('option').remove(); $.ajax({ type: "POST", url: "../get_s_engineer.php", data: dataString, cache: false, success: function (html) { $(".s_engineer").html(html); } }); }); $(".s_engineer").change(function () { // $('.s_engineer').attr('size', 0); // $('.ex_engineer').attr('size', 4); var id = $(this).val(); // alert(id) var dataString = 'id=' + id; $(".electry_city").find('option').remove(); $(".ex_engineer").find('option').remove(); $.ajax({ type: "POST", url: "../get_ex_engineer.php", data: dataString, cache: false, success: function (html) { // alert(html); $(".ex_engineer").html(html); } }); }); $(".ex_engineer").change(function () { // $('.ex_engineer').attr('size', 0); // $('.electry_city').attr('size', 4); var id = $(this).val(); var dataString = 'id=' + id; $(".electry_city").find('option').remove(); $.ajax({ type: "POST", url: "../get_electry_city.php", data: dataString, cache: false, success: function (html) { // alert(html); $(".electry_city").html(html); } }); }); $(".electry_city").change(function () { $('.electry_city').attr('size', 0); }); }); </script>