employee.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. <?php
  2. include "conn.php";
  3. checkLogin("信息管理");
  4. $act = $_GET['act'] ?? '';
  5. // Handle all actions that might need header redirects first
  6. if($act == "save") {
  7. $isEdit = false;
  8. $id = $_POST['id'] ?? '';
  9. if($id != '' && is_numeric($id)) {
  10. $isEdit = true;
  11. }
  12. $em_user = textEncode($_POST['em_user']);
  13. $em_password = textEncode($_POST['em_password']);
  14. $re_password = textEncode($_POST['re_password']);
  15. $em_role = $_POST['em_role'];
  16. $em_code = textEncode($_POST['em_code']);
  17. $em_email = textEncode($_POST['em_email']);
  18. $em_tel = textEncode($_POST['em_tel']);
  19. $em_permission_role_id = $_POST['em_permission_role_id'];
  20. $nullPwd = false;
  21. if(empty($em_password)) {
  22. $nullPwd = true;
  23. }
  24. if($em_password != $re_password) {
  25. echo "<script>alert('两次密码输入不一致');history.back();</script>";
  26. exit;
  27. }
  28. if($isEdit) {
  29. $query = "SELECT * FROM employee WHERE id=$id";
  30. $result = $conn->query($query);
  31. if($result->num_rows > 0) {
  32. $password_sql = $nullPwd ? "" : ",em_password='".md5($em_password)."'";
  33. $sql = "UPDATE employee SET em_user='$em_user'$password_sql,em_role=$em_role,
  34. em_code='$em_code',em_email='$em_email',em_tel='$em_tel',em_permission_role_id=$em_permission_role_id WHERE id=$id";
  35. $conn->query($sql);
  36. }
  37. $page = $_GET['Page'] ?? '';
  38. $keys = urlencode($_GET['Keys'] ?? '');
  39. $ord = urlencode($_GET['Ord'] ?? '');
  40. header("Location: ?keys=$keys&Ord=$ord&Page=$page");
  41. exit;
  42. } else {
  43. if($nullPwd) {
  44. $em_password = "MTB".$em_code;
  45. }
  46. $sql = "INSERT INTO employee(em_user,em_password,em_role,em_code,em_email,em_tel,em_permission_role_id)
  47. VALUES('$em_user','".md5($em_password)."',$em_role,'$em_code','$em_email','$em_tel',$em_permission_role_id)";
  48. $conn->query($sql);
  49. header("Location: ?");
  50. exit;
  51. }
  52. }
  53. if($act == "postchk") {
  54. $keys = urlencode($_GET['Keys'] ?? '');
  55. $ord = urlencode($_GET['Ord'] ?? '');
  56. $page = $_GET['Page'] ?? '';
  57. $chkact = $_POST['chkact'] ?? '';
  58. if(isset($_POST['chkbox']) && is_array($_POST['chkbox'])) {
  59. $sqlStr = "DELETE FROM employee WHERE id IN (" . implode(',', $_POST['chkbox']) . ")";
  60. $conn->query($sqlStr);
  61. }
  62. header("Location: ?Keys=$keys&Ord=$ord&Page=$page");
  63. exit;
  64. }
  65. // Now start HTML output
  66. ?>
  67. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  68. <html xmlns="http://www.w3.org/1999/xhtml">
  69. <head>
  70. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  71. <title>管理区域</title>
  72. <link rel="stylesheet" href="css/common.css" type="text/css" />
  73. <script language="javascript" src="js/jquery-1.7.2.min.js"></script>
  74. <script type="text/javascript" src="js/js.js"></script>
  75. <script type="text/javascript" src="xheditor-1.1.9/xheditor-1.1.9-zh-cn.min.js"></script>
  76. </head>
  77. <body>
  78. <div id="man_zone">
  79. <?php
  80. if($act == "add" || $act == "edit") {
  81. $id = $_GET['id'] ?? '';
  82. $isEdit = false;
  83. if($id != '' && is_numeric($id)) {
  84. $isEdit = true;
  85. }
  86. if($isEdit) {
  87. $query = "SELECT * FROM employee WHERE id=$id";
  88. $result = $conn->query($query);
  89. if($result->num_rows > 0) {
  90. $row = $result->fetch_assoc();
  91. $em_user = textUncode($row['em_user']);
  92. $em_role = $row['em_role'];
  93. $em_code = textUncode($row['em_code']);
  94. $em_email = textUncode($row['em_email']);
  95. $em_tel = textUncode($row['em_tel']);
  96. $em_permission_role_id = $row['em_permission_role_id'];
  97. } else {
  98. $isEdit = false;
  99. }
  100. }
  101. $page = $_GET['Page'] ?? '';
  102. $keys = urlencode($_GET['Keys'] ?? '');
  103. $ord = urlencode($_GET['Ord'] ?? '');
  104. $hrefstr = "?keys=$keys&Ord=$ord&Page=$page";
  105. ?>
  106. <form name="form1" method="post" action="<?php echo $hrefstr; ?>&act=save" onSubmit="return subform2();">
  107. <table width="100%" border="0" cellpadding="3" cellspacing="1" class="table1">
  108. <tbody>
  109. <tr>
  110. <th width="8%">用户名</th>
  111. <td><input type="text" id="em_user" name="em_user" value="<?php echo $em_user ?? ''; ?>" required class="txt-short" />
  112. <input type="hidden" name="id" value="<?php echo $id; ?>" /></td>
  113. </tr>
  114. <tr>
  115. <th width="8%">密码</th>
  116. <td><input type="password" id="em_password" name="em_password" value="" class="txt-short"/></td>
  117. </tr>
  118. <tr>
  119. <th width="8%">重复密码</th>
  120. <td><input type="password" id="re_password" name="re_password" value="" class="txt-short"/></td>
  121. </tr>
  122. <tr>
  123. <th width="8%">工号</th>
  124. <td><input type="text" id="em_code" name="em_code" value="<?php echo $em_code ?? ''; ?>" class="txt1" /></td>
  125. </tr>
  126. <tr>
  127. <th width="8%">该用户上级</th>
  128. <td><select name="em_role">
  129. <option value="0">无</option>
  130. <?php
  131. $query = "SELECT id,em_user FROM employee WHERE em_role=0";
  132. $result = $conn->query($query);
  133. while($row = $result->fetch_assoc()) {
  134. $selected = ($row['id'] == ($em_role ?? '')) ? ' selected="selected"' : '';
  135. echo "<option value=\"{$row['id']}\"$selected>{$row['em_user']}</option>";
  136. }
  137. ?>
  138. </select>
  139. </td>
  140. </tr>
  141. <tr>
  142. <th width="8%">权限角色</th>
  143. <td>
  144. <select name="em_permission_role_id">
  145. <option value="0" <?php echo (isset($em_permission_role_id) && $em_permission_role_id == 0) ? 'selected' : ''; ?>>0 * 普通</option>
  146. <option value="2" <?php echo (isset($em_permission_role_id) && $em_permission_role_id == 2) ? 'selected' : ''; ?>>2 * 组长</option>
  147. <option value="3" <?php echo (isset($em_permission_role_id) && $em_permission_role_id == 3) ? 'selected' : ''; ?>>3 * 组员</option>
  148. <option value="4" <?php echo (isset($em_permission_role_id) && $em_permission_role_id == 4) ? 'selected' : ''; ?>>4 * 分公司</option>
  149. <option value="1" <?php echo (isset($em_permission_role_id) && $em_permission_role_id == 1) ? 'selected' : ''; ?>>1 * 管理员</option>
  150. </select>
  151. </td>
  152. </tr>
  153. <tr>
  154. <th width="8%">邮箱</th>
  155. <td><input type="text" id="em_email" name="em_email" value="<?php echo $em_email ?? ''; ?>" class="txt1" /></td>
  156. </tr>
  157. <tr>
  158. <th width="8%">手机</th>
  159. <td><input type="text" id="em_tel" name="em_tel" value="<?php echo $em_tel ?? ''; ?>" class="txt1" /></td>
  160. </tr>
  161. <tr>
  162. <th></th>
  163. <td>
  164. <input type="submit" name="save" id="save" value="确定" class="btn1" />
  165. <input type="reset" name="save" id="save" value="重置" class="btn1" />
  166. <input type="button" value="返回" class="btn1" onClick="location.href='<?php echo $hrefstr; ?>'" />
  167. </td>
  168. </tr>
  169. </tbody>
  170. </table>
  171. </form>
  172. </div>
  173. </body>
  174. </html>
  175. <?php
  176. exit;
  177. }
  178. $keys = $_GET['Keys'] ?? '';
  179. $keyscode = textEncode($keys);
  180. $ord = $_GET['Ord'] ?? '';
  181. $page = $_GET['Page'] ?? '';
  182. $query = "SELECT id,em_user,em_code,em_role FROM employee
  183. WHERE em_user LIKE '%$keyscode%' OR em_code LIKE '%$keyscode%'
  184. ORDER BY Id DESC";
  185. $result = $conn->query($query);
  186. $keys = urlencode($keys);
  187. $ord = urlencode($ord);
  188. $hrefstr = "?keys=$keys";
  189. ?>
  190. <form id="form1" method="post" action="?act=postchk&Keys=<?php echo $keys; ?>&Ord=<?php echo $ord; ?>&Page=<?php echo $page; ?>" onSubmit="return false">
  191. <table width="100%" border="0" cellpadding="3" cellspacing="1" class="table1">
  192. <thead>
  193. <tr>
  194. <th width="4%"><input type="checkbox" name="chkall" id="chkall" onClick="chkboxall(this,'chkbox')" /></th>
  195. <th width="6%">序号</th>
  196. <th>姓名</th>
  197. <th>工号</th>
  198. <th>角色</th>
  199. <th>操作</th>
  200. </tr>
  201. </thead>
  202. <tbody>
  203. <?php
  204. if($result->num_rows > 0) {
  205. $pageSize = 13;
  206. $totalRows = $result->num_rows;
  207. $totalPages = ceil($totalRows / $pageSize);
  208. if($page == '') $page = 1;
  209. if($page == 'end') $page = $totalPages;
  210. if(!is_numeric($page) || $page < 1) $page = 1;
  211. $page = (int)$page;
  212. if($page > $totalPages) $page = $totalPages;
  213. $offset = ($page - 1) * $pageSize;
  214. $query .= " LIMIT $offset, $pageSize";
  215. $result = $conn->query($query);
  216. $tempNum = $offset;
  217. while($row = $result->fetch_assoc()) {
  218. $tempNum++;
  219. ?>
  220. <tr onMouseOver="this.style.background='#F7FCFF'" onMouseOut="this.style.background='#FFFFFF'">
  221. <td align="center"><input type="checkbox" name="chkbox[]" value="<?php echo $row['id']; ?>" /></td>
  222. <td align="center"><?php echo $tempNum; ?></td>
  223. <td align="center"><?php echo $row['em_user']; ?></td>
  224. <td align="center"><?php echo $row['em_code']; ?></td>
  225. <td align="center"><?php echo $row['em_role'] == 0 ? '组长' : '组员'; ?></td>
  226. <th><a class="ico_edit" href="?act=edit&Keys=<?php echo $keys; ?>&Ord=<?php echo $ord; ?>&Page=<?php echo $page; ?>&id=<?php echo $row['id']; ?>">修改</a></th>
  227. </tr>
  228. <?php
  229. }
  230. } else {
  231. if($keys == '') {
  232. echo '<tr><td align="center" colspan="6">Sorry,当前暂无信息</td></tr>';
  233. } else {
  234. echo '<tr><td align="center" colspan="6"><a href="?">Sorry,没有找到"'.$keyscode.'"相关的信息,点击返回</a></td></tr>';
  235. }
  236. }
  237. ?>
  238. </tbody>
  239. <tfoot>
  240. <tr>
  241. <td colspan="6">
  242. <div class="showpagebox">
  243. <?php
  244. if($totalPages > 1) {
  245. $pageName = "?Keys=$keys&Ord=$ord&";
  246. $pageLen = 3;
  247. if($page > 1) {
  248. echo "<a href=\"{$pageName}Page=1\">首页</a>";
  249. echo "<a href=\"{$pageName}Page=".($page-1)."\">上一页</a>";
  250. }
  251. if($pageLen * 2 + 1 >= $totalPages) {
  252. $startPage = 1;
  253. $endPage = $totalPages;
  254. } else {
  255. if($page <= $pageLen + 1) {
  256. $startPage = 1;
  257. $endPage = $pageLen * 2 + 1;
  258. } else {
  259. $startPage = $page - $pageLen;
  260. $endPage = $page + $pageLen;
  261. }
  262. if($page + $pageLen > $totalPages) {
  263. $startPage = $totalPages - $pageLen * 2;
  264. $endPage = $totalPages;
  265. }
  266. }
  267. for($i = $startPage; $i <= $endPage; $i++) {
  268. if($i == $page) {
  269. echo "<a class=\"current\">$i</a>";
  270. } else {
  271. echo "<a href=\"{$pageName}Page=$i\">$i</a>";
  272. }
  273. }
  274. if($page < $totalPages) {
  275. if($totalPages - $page > $pageLen) {
  276. echo "<a href=\"{$pageName}Page=$totalPages\">...$totalPages</a>";
  277. }
  278. echo "<a href=\"{$pageName}Page=".($page+1)."\">下一页</a>";
  279. echo "<a href=\"{$pageName}Page=$totalPages\">尾页</a>";
  280. }
  281. echo "<input type=\"text\" id=\"Pagego\" value=\"$page\" onFocus=\"if(this.value == '$page'){this.value='';}\" onBlur=\"if(this.value == ''){this.value='$page';}\" onKeyUp=\"this.value=this.value.replace(/\D/g,'')\" onKeyDown=\"if(event.keyCode==13){location.href='{$pageName}Page='+document.getElementById('Pagego').value}\" />";
  282. }
  283. ?>
  284. </div>
  285. <div class="searchbox">
  286. <input type="text" id="keys" value="<?php echo $keyscode == '' ? '请输入搜索关键词' : $keyscode; ?>"
  287. onFocus="if(this.value == '<?php echo $keyscode == '' ? '请输入搜索关键词' : $keyscode; ?>'){this.value='';}"
  288. onBlur="if(this.value == ''){this.value='<?php echo $keyscode == '' ? '请输入搜索关键词' : $keyscode; ?>';}"
  289. onKeyDown="if(event.keyCode==13){location.href='?Keys='+encodeURIComponent(document.getElementById('keys').value)}" />
  290. <input type="button" id="searchgo" value="go" onClick="location.href='?Keys='+encodeURIComponent(document.getElementById('keys').value)" />
  291. </div>
  292. <div class="postchkbox">
  293. <select id="chkact" name="chkact">
  294. <option value="1">显示</option>
  295. <option value="0">隐藏</option>
  296. <option value="-1">删除</option>
  297. </select>
  298. <input type="button" value="执行" onClick="postchk(1)" class="btn1" />
  299. <input type="button" value="新增" onClick="location.href='?act=add'" class="btn1" />
  300. </div>
  301. </td>
  302. </tr>
  303. </tfoot>
  304. </table>
  305. </form>
  306. </div>
  307. </body>
  308. </html>