JezK
Edit File: add_user.php
<?php include("session_check.php"); include("adm_operations.php"); $operations=new adm_operations(); include("header.php"); if(!isset($_GET['stf_cat'])) { $records='not'; //$operations->getmyschoolstaff($_SESSION['child']['log_school_id'],1); } else { $records=$operations->getmyschoolstaff($_SESSION['child']['log_school_id'],$_SESSION['child']['choosen_academic_id'],$_GET['stf_cat']); } if(isset($_POST['chgpriv'])) { if(isset($_POST['users'])) { foreach($_POST['users'] as $userp) { $v=$userp.'usrpriv'; //if(isset($_POST[$v])) if(isset($userp)) { $savepriv=$operations->saveuserprivileges($_SESSION['child']['auth_id'],$userp,$_POST[$v]); } } echo '<script>location.replace("schooladmin_usermanagement.php");</script>'; } } $access=$operations->getvalidModuleaccess($_SESSION['child']['log_school_id']); ///////////////////////////////LOCAL FUNCTION/////////////////////////////////// function privilegesprocess($autref,$allow,$privileges) { $mods=''; $one=''; $two=''; $three=''; $four=''; $five=''; $six=''; $checknames=$autref."usrpriv[]"; if(!empty($privileges)) { //$pr=array_intersect($allow, $privileges); for($i=0;$i<count($privileges);$i++) { if($privileges[$i] == 1) $one="checked"; if($privileges[$i] == 2) $two="checked"; if($privileges[$i] == 3) $three="checked"; if($privileges[$i] == 4) $four= "checked"; if($privileges[$i] == 5) $five= "checked"; if($privileges[$i] == 6) $six="checked"; } if(in_array(1,$allow)) $mods.='<input type="checkbox" '.$one.' name="'.$checknames.'" value="1" style="margin-top:-4px;"> Attendance<br>'; if(in_array(2,$allow)) $mods.='<input type="checkbox" '.$two.' name="'.$checknames.'" value="2" style="margin-top:-4px;"> Diary<br>'; if(in_array(3,$allow)) $mods.='<input type="checkbox" '.$three.' name="'.$checknames.'" value="3" style="margin-top:-4px;"> Notice Board<br>'; if(in_array(4,$allow)) $mods.='<input type="checkbox" '.$four.' name="'.$checknames.'" value="4" style="margin-top:-4px;"> Examinations<br>'; if(in_array(5,$allow)) $mods.='<input type="checkbox" '.$five.' name="'.$checknames.'" value="5" style="margin-top:-4px;"> Transport<br>'; if(in_array(6,$allow)) $mods.='<input type="checkbox" '.$six.' name="'.$checknames.'" value="6" style="margin-top:-4px;"> Fee Payment'; } else { if(in_array(1,$allow)) $mods.='<input type="checkbox" name="'.$checknames.'" value="1" tabindex="8" style="margin-top:-4px;"> Attendance<br>'; if(in_array(2,$allow)) $mods.='<input type="checkbox" name="'.$checknames.'" value="2" tabindex="9" style="margin-top:-4px;"> Diary <br>'; if(in_array(3,$allow)) $mods.='<input type="checkbox" name="'.$checknames.'" value="3" tabindex="10" style="margin-top:-4px;"> Notice Board<br>'; if(in_array(4,$allow)) $mods.='<input type="checkbox" name="'.$checknames.'" value="4" tabindex="11" style="margin-top:-4px;"> Examinations<br>'; if(in_array(5,$allow)) $mods.='<input type="checkbox" name="'.$checknames.'" value="5" tabindex="12" style="margin-top:-4px;"> Transport<br>'; if(in_array(6,$allow)) $mods.='<input type="checkbox" name="'.$checknames.'" value="6" tabindex="13" style="margin-top:-4px;"> Fee Payment'; } return $mods; } //////////////////////////////////////////////////////////////////////////////// ?> <style> .table-condensed>thead>tr>th, .table-condensed>tbody>tr>th, .table-condensed>tfoot>tr>th, .table-condensed>thead>tr>td, .table-condensed>tbody>tr>td, .table-condensed>tfoot>tr>td { padding: 3px; } select { width: 62px !important; background-color: #FFF; border: 1px solid #CCC; } #nav { margin: auto; width:638px !important; padding-left:0; padding-right:0; list-style: none; background: #18b88d; } #nav li { display:inline-block; margin:0 auto; text-align:center; } #nav li a { display: inline-block; padding: 7px 0; text-align:center; text-decoration: none; color: #FFFFFF; margin:auto; } #nav li:hover, li:active { background: rgb(54, 120, 102); width:90px; } #nav li.selected { background: rgb(54, 120, 102); } </style> <body style="overflow-x: hidden;"> <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;"> <i class=" glyphicon glyphicon-plus" title ="Add User" style="font-size: 16px;"></i> Add/Update User </div> </div> <br> <div class="menuu"> <ul id="nav" class="margn_auto"> <li class="selected" style="border-right:1px solid #FFFFFF;width:214px; text-align:center;margin-left:-3px;font-family:Arial, Helvetica, sans-serif;font-style:normal; font-size:14px;"> <a href="schooladmin_usermanagement.php"><img src="images/user_school-admin-white.png" title ="Users for School Admin" style="margin-right:5px;"/>Users for School Admin</a> </li> <li style=" border-right:1px solid #FFFFFF;width:215px; text-align:center; margin-left:-3px; font-family:Arial, Helvetica, sans-serif;font-style:normal; font-size:14px;"> <a href="teacherapp_usermanagement.php"><img src="images/user_teacher-app-white.png" title ="Users for Teacher App" style="margin-right:5px;"/>Users for Teacher App</a> </li> <li style="width:210px; text-align:center; margin-left:-3px; font-family:Arial, Helvetica, sans-serif;font-style:normal; font-size:14px;"> <a href="driverapp_usermanagement.php"><img src="images/user_driver-app-white.png" title ="Users for Driver App" style="margin-right:5px;"/>Users for Driver App</a> </li> </ul> </div> <form method="post"> <div class="box-body" style="background-color:#fff; padding: 10px; font-family:Arial, Helvetica, sans-serif; font-size:13px;"> <div class="clear"> <div class="form-group col-md-6" style="margin-bottom:1.0%;margin-left:-36px;"> <div class="col-md-4" style="margin-left:20px;"> <b style="color:#666666;">Category</b><span style="color:#FF0000; margin:2px;">*</span> </div> <div class="col-md-7" style="margin-left:-131px;"> <select class="form-control" id="schoolstaff" name="schoolstaff" style="height:29px; width:200px!important;font-size:12px;" tabindex="2" onchange="get_this_category(this.value);"> <?php $arr=array("Select Category","Teacher","Driver","Admin Staff","Maid","Other"); foreach($arr as $key=>$val) if($key==$_GET['stf_cat']) echo "<option value='".$key."' selected>".$val."</option>"; else echo "<option value='".$key."'>".$val."</option>"; ?> </select> <!-- if there is an error--> <div class="col-md-10" id="err_cat" style="color:#990000;margin-left:-15px;"></div> <!--- end error--> </div> </div> </div> </div> <div class="row" style="margin-left:10px;margin-right:10px;"> <div class="col-md-12 centered" style="font-family: Arial, Helvetica, sans-serif;margin-top:30px;"> <table id="myTable" class="table table-condensed table-hover" style="margin-top:-10px;"> <thead> <tr class="info"> <th class="col-md-1 text-center"> <!--<input type="checkbox" class="check" style=" margin-top:-3px;margin-left:4px;">-->Sl.No </th> <th>Staff Name</th> <th>Phone Number</th> <th>Email</th> <th>Privileges</th> </tr> </thead> <tbody> <?php $x=1; if($records!='not') foreach($records as $record) { echo ' <tr> <td class="col-sm-1 text-center" style=" font-size:14px; "><input type="checkbox" name="users[]" value="'.$record[staff_id].'" id="'.$x.'"> '.$x.'</td> <td style=" font-size:14px;">'.$record[staff_name].'</td> <td style=" font-size:14px; ">'.$record[staff_mobile].'</td> <td style=" font-size:14px; ">'.$record[staff_email].'</td> <td>'; if($access!=0) { $myprivilege=$operations->getthisuserPrivileges($record[auth_ref]); if($myprivilege!=0) { $array1=explode(',',rtrim($myprivilege,',')); $f=privilegesprocess($record[staff_id],$access,$array1); echo $f; } else { $array1=array(); $f=privilegesprocess($record[staff_id],$access,$array1); echo $f; } //echo '<input type="hidden" name="users[]" value="'.$record[auth_ref].'" id="'.$x.'">'; }?> </td> </tr> <?php $x++; } ?> </tbody> </table> </div> </div> <div class="form-group"> <div class="col-md-12" align="center"> <button type="submit" name="chgpriv" 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;" onclick="return checkselection();">Add/Update</button> <button type="button" name="canceluser" 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="canceladd();">Cancel</button> </div> </div> </form> <script type="text/javascript" language="javascript" src="Excel/media/js/jquery.js"></script> <script type="text/javascript" language="javascript" src="Excel/media/js/jquery.dataTables.js"></script> <script type="text/javascript" language="javascript" src="Excel/js/dataTables.tableTools.js"></script> <script type="text/javascript" language="javascript" src="Excel/examples/resources/syntax/shCore.js"></script> <script type="text/javascript" language="javascript" src="Excel/examples/resources/demo.js"></script> <script type="text/javascript" language="javascript" class="init"></script> <script> $(document).ready(function(){ $('#myTable').dataTable(); }); function get_this_category(val) { $("#err_cat").text(""); if(val==0) { $("#err_cat").text("Please select the Category"); $("#err_cat").show(); } else { window.location.href="add_user.php?stf_cat="+val; } } function getprivileges(val) { var prvs=document.getElementsByName('users[]'); var vr1=0; for(var i = 0; i < prvs.length; i++) { if(prvs[i].checked) vr1++; } if(vr1==1) { $.post('privilege_ajax.php',{id4privilege:val},function(data){ //var k=data.split('$'); //if(k[1]=='1') $('#cur_priv').html(''); $('#cur_priv').html(data); }); } else { $("input[name='usrpriv[]']").prop('checked', false); } } function checkselection() { $('#err_cat').text(""); if($('#schoolstaff').val()==0) { $('#err_cat').text("Please select Category"); $('#err_cat').show(); return false; } var a=document.getElementsByName('users[]'); var vr1=0; for(var i = 0; i < a.length; i++) { prev=0; if(a[i].checked) { vr1++; z=a[i].value; b=document.getElementsByName(z+"usrpriv[]"); for(j=0;j< b.length;j++) { if(b[j].checked) { prev=1; } } if(prev==0) { alert('Please select atleast one Privilege'); return false; } } } if(vr1==0) { alert('Atleast one user should be selected'); return false; } } function checkboxselection() { var a=document.getElementsByName('users[]'); for(var i = 0; i < a.length; i++) { z=a[i].value; b=document.getElementsByName(z+"usrpriv[]"); for(j=0;j< b.length;j++) { //if(b[j].checked) no privilege has been selected for any one //alert('yes'); } } } function canceladd() { window.location.href="schooladmin_usermanagement.php"; } </script> </body> </html>