PageRenderTime 26ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/Quản lý website bán áo đồng phục PHP/lamao/admins/modules/user_group.php

https://gitlab.com/phamngsinh/baitaplon_sinhvien
PHP | 496 lines | 486 code | 6 blank | 4 comment | 29 complexity | 4d9bcaf9c3e3fc2a6b4cc6769fc23ca7 MD5 | raw file
  1. <?php if (substr_count($_SERVER['PHP_SELF'],'/user_group.php')>0) die ("You can't access this file directly..."); ?>
  2. <?php
  3. if ($_SESSION['usergroup']<4)
  4. {
  5. ?>
  6. <script type=text/javascript>
  7. function del_group()
  8. {
  9. if (confirm('Ban dang chon xoa nhom user ! Xin xac nhan bang cach click\n\n OK [= CO] CANCEL [= KHONG] !'))
  10. if (confirm('Ban co chac la ban muon xoa nhom nay khong ?'))
  11. if (confirm('Xin xac nhan lai lan cuoi !'))
  12. {
  13. //document.group4del.action='delete';
  14. document.group4del.submit();
  15. }
  16. }
  17. function del_user()
  18. {
  19. var isvalid=false
  20. for (var counter=0; counter < datatbl.length; counter++)
  21. {
  22. if (datatbl.elements[counter].checked == true)
  23. {
  24. isvalid=true;
  25. }
  26. }
  27. if (isvalid==true)
  28. {
  29. if (confirm('<?php echo $strDelete; ?> ?!!'))
  30. {
  31. if (confirm("<?php echo $strConfirm.' '.$strAgain; ?> !!!"))
  32. {
  33. document.datatbl.submit();
  34. }
  35. }
  36. }
  37. else
  38. alert('Bạn phải chọn ít nhất một thông tin')
  39. }
  40. function setdisplay(frmname, act)
  41. {
  42. if (eval(frmname + '.style.display')=='none')
  43. eval(frmname + '.style.display="";');
  44. else
  45. eval(frmname + '.style.display="none";');
  46. switch(act)
  47. {
  48. case 'new':
  49. eval('document.' + frmname + '.group_name.value="";');
  50. eval('document.' + frmname + '.icon.value="";');
  51. eval('document.' + frmname + '.action.value="new";');
  52. break;
  53. case 'edit':
  54. eval('document.' + frmname + '.group.value=document.exist_value.gid.value;');
  55. eval('document.' + frmname + '.group_name.value=document.exist_value.gdesc.value;');
  56. eval('document.' + frmname + '.action.value="edit";');
  57. break;
  58. }
  59. }
  60. </script>
  61. <table width="95%" border="0" cellpadding="0" cellspacing="0" background="images/tablebg.gif">
  62. <!-- Show available user group -->
  63. <tr>
  64. <td height="40" colspan="3" align="center" valign="middle">
  65. <?php
  66. //Get list of available user group
  67. $allow_edit=false;
  68. $view='select * from user_groups';
  69. switch ($_SESSION['usergroup'])
  70. {
  71. case 1:
  72. case 2:
  73. $view.=' where id >= "'.$_SESSION['usergroup'].'"';
  74. break;
  75. default:
  76. $view.=' where id not in (\'1\',\'2\')';
  77. break;
  78. }
  79. $view.=' order by description ASC';
  80. //echo $view;
  81. $doview=mysql_query($view,$link);
  82. if ($doview and mysql_num_rows($doview)>0)
  83. {
  84. $return_rows=mysql_num_rows($doview);
  85. $id_array=array($return_rows);
  86. $desc_array=array($return_rows);
  87. $icon_array=array($return_rows);
  88. $i=0;
  89. while ($result=mysql_fetch_array($doview))
  90. {
  91. $id_array[$i]=$result['id'];
  92. $desc_array[$i]=$result['description'];
  93. $icon_array[$i]=$result['icon'];
  94. if (isset($_POST['group']) && $id_array[$i]==$_POST['group'])
  95. {
  96. $cur_group=$desc_array[$i];
  97. $cur_icon=$icon_array[$i];
  98. }
  99. $i++;
  100. }
  101. }
  102. ?>
  103. <table width="100%" height="30" border="0" cellpadding="2" cellspacing="2">
  104. <tr>
  105. <td bgcolor="#E1E1E1">&nbsp;</td>
  106. <td width="300" onClick="" style="border: 1px solid #E1E1E1">
  107. <form name="viewgroup" style="margin: 0;" method="post" action="">
  108. <p class="buttontext"><?php echo $strSelect.' '.$strGroup; ?>
  109. <select name="group" style="margin: 0 0 0 0">
  110. <?php
  111. $j=0;
  112. while (isset($id_array[$j]))
  113. {
  114. echo '<option value="'.$id_array[$j].'"';
  115. echo '>';
  116. echo $desc_array[$j].'</option>';
  117. $j++;
  118. }
  119. ?>
  120. </select>
  121. &nbsp;<input type="button" onClick="javascript: document.viewgroup.submit();" style="background-color: #F7F7F7; font-color: #FFFFFF;" value=" <?php echo $strView; ?> " onMouseOver="changebd(this,'#336699')" onMouseOut="undobd(this)">
  122. </p></form></td>
  123. <!--
  124. <td width="70" onClick="javascript: document.viewgroup.submit();" style="cursor: hand; border: 1px solid #E1E1E1" onMouseOver="changebd(this,'#336699')" onMouseOut="undobd(this)">
  125. <p class="buttontext"><img align="absmiddle" src="images/view.gif" width="22" height="22">
  126. &nbsp;&nbsp;Xem</p></td>
  127. -->
  128. <?php
  129. if ($_SESSION['usergroup']==1)
  130. {
  131. $allow_edit=true;
  132. $allow_delete=true;
  133. ?>
  134. <!--
  135. <td width="80" onClick="setdisplay('new_group','new');" style="cursor: hand; border: 1px solid #E1E1E1" onMouseOver="changebd(this,'#336699')" onMouseOut="undobd(this)">
  136. <p class="buttontext"><img align="absmiddle" src="images/filenew.gif" width="22" height="22">
  137. &nbsp;&nbsp;<?php echo $strCreatNew; ?></p></td>
  138. -->
  139. <?php
  140. if (isset($_POST['group']))
  141. {
  142. $getvalue='select * from user_groups where id="'.$_POST['group'].'" limit 0,1';
  143. $doget=mysql_query($getvalue,$link);
  144. if ($doget && mysql_num_rows($doget)==1)
  145. {
  146. $value=mysql_fetch_array($doget);
  147. echo '<form name="exist_value" style="display: none">';
  148. echo '<input type="hidden" name="gdesc" value="'.$value['description'].'">';
  149. echo '<input type="hidden" name="gicon" value="'.$value['icon'].'">';
  150. echo '<input type="hidden" name="gid" value="'.$_POST['group'].'">';
  151. echo '</form>';
  152. }
  153. ?>
  154. <td width="70" onClick="setdisplay('new_group','edit');" style="cursor: hand; border: 1px solid #E1E1E1" onMouseOver="changebd(this,'#336699')" onMouseOut="undobd(this)">
  155. <p class="buttontext"><img align="absmiddle" src="images/edit.gif" width="22" height="22">
  156. &nbsp;&nbsp;<?php echo $strEdit; ?></p></td>
  157. <?php
  158. if (isset($value['type']) and $value['type']!='default')
  159. {
  160. $allow_delete=true;
  161. ?>
  162. <!--
  163. <td width="70" onClick="del_group();" style="cursor: hand; border: 1px solid #E1E1E1" onMouseOver="changebd(this,'#336699')" onMouseOut="undobd(this)">
  164. <form style="display: none" name="group4del" method="post" action="">
  165. <input type="hidden" name="group" value="<?php echo $_POST['group']; ?>">
  166. <input type="hidden" name="action" value="delete">
  167. </form>
  168. <p class="buttontext"><img align="absmiddle" src="images/cancel.gif" width="22" height="22">
  169. &nbsp;&nbsp;<?php echo $strDelete; ?></p></td>
  170. -->
  171. <?php
  172. }
  173. }
  174. }
  175. else
  176. {
  177. ?>
  178. <td width="400" style="cursor: hand; border: 1px solid #E1E1E1" onMouseOver="changebd(this,'#336699')" onMouseOut="undobd(this)">
  179. <p class="buttontext">&nbsp;&nbsp;<?php echo $strErr['201']; ?></p></td>
  180. <?php
  181. }
  182. ?>
  183. <td bgcolor="#E1E1E1">&nbsp;</td>
  184. </tr>
  185. </table>
  186. </td>
  187. </tr>
  188. <!-- End show all available user group-->
  189. <!-- Main window -->
  190. <tr><td align="center" valign="top" colspan="3">
  191. <?php
  192. if (isset($_POST['action']))
  193. {
  194. $imgpath='icons';
  195. $error=0;
  196. $msg='';
  197. $action=$_POST['action'];
  198. if (isset($_FILES['icon']))
  199. {
  200. $iname=$_FILES['icon']['name'];
  201. $itemp=$_FILES['icon']['tmp_name'];
  202. }
  203. $gtype='custom';
  204. switch ($action)
  205. {
  206. case 'new':
  207. if (checkdata('user_groups','description',$_POST['group_name'])==0)
  208. {
  209. $msg.='Tạo nhóm mới: <br>';
  210. $query='insert into user_groups(description,icon,type) values("'.$_POST['group_name'].'","'.$iname.'","'.$gtype.'")';
  211. }
  212. else
  213. {
  214. set_error($strErr['106']);
  215. }
  216. break;
  217. case 'edit':
  218. if (checkdata('user_groups','id',$_POST['group'])==1)
  219. {
  220. $msg.='Cập nhật thông tin nhóm : ';
  221. if ($cur_icon!='')
  222. $msg.= '<img src="icons/'.$cur_icon.'" width="22" height="22" border="0" align="absmiddle">';
  223. $msg.= ' <font color="#FF5500">'.$cur_group.'</font><br>';
  224. $query='update user_groups set description="'.$_POST['group_name'].'"';
  225. if ($iname!='')
  226. $query.=', icon="'.$iname.'"';
  227. $query.=' where id="'.$_POST['group'].'"';
  228. }
  229. else
  230. {
  231. set_error($strErr['107']);
  232. }
  233. break;
  234. case 'delete':
  235. if (checkdata('user_groups','id',$_POST['group'])==1)
  236. {
  237. $msg.='Xóa thông tin nhóm : ';
  238. if ($cur_icon!='')
  239. $msg.= '<img src="icons/'.$cur_icon.'" width="22" height="22" border="0" align="absmiddle">';
  240. $msg.= ' <font color="#FF5500">'.$cur_group.'</font><br>';
  241. $query='delete from user_groups ';
  242. $query.=' where id="'.$_POST['group'].'" and type!="default"';
  243. }
  244. else
  245. {
  246. set_error($strErr['107']);
  247. }
  248. break;
  249. case 'deleteuser':
  250. $IDs='';
  251. if (isset($_REQUEST['total_rows']))
  252. {
  253. //echo 'Total rows : '.$_REQUEST['total_rows'];
  254. $counter=0;
  255. for ($i=1;$i<=$_REQUEST['total_rows'];$i++)
  256. {
  257. if (isset($_REQUEST['chkbox'.$i]) and $_REQUEST['chkbox'.$i]!='')
  258. {
  259. $counter++;
  260. if ($counter>1)
  261. $IDs.=',';
  262. $IDs.=$_REQUEST['chkbox'.$i];
  263. }
  264. }
  265. //echo 'Selected : '.$IDs;
  266. if ($counter>0)
  267. $allow_delete=true;
  268. }
  269. $msg.='Xóa user : ';
  270. $query='delete from users';
  271. $query.=' where id in ('.$IDs.') and id!="1"';
  272. //echo $query;
  273. break;
  274. }
  275. if (isset($query))
  276. {
  277. if (mysql_query($query,$link))
  278. {
  279. $msg.='Thông tin được cập nhật thành công !<br><br>';
  280. if (isset($_FILES['icon']) && $_FILES['icon']!='')
  281. {
  282. $checkimg=validateimage('upload','icon',$imgpath);
  283. if ($checkimg=='ok')
  284. {
  285. if (@move_uploaded_file($itemp,$imgpath.'\\'.$iname))
  286. {
  287. $msg.='File(s) uploaded successfully !';
  288. }
  289. else
  290. {
  291. $msg.='Can not upload file(s) !';
  292. }
  293. }
  294. else
  295. {
  296. set_error($checkimg);
  297. }
  298. }
  299. }
  300. else
  301. {
  302. set_error($strErr['108']);
  303. }
  304. }
  305. else
  306. {
  307. $msg.='<br>Không thể cập nhật thông tin !<br>';
  308. }
  309. $msg.='<script>';
  310. $msg.='setTimeout(\'window.location.replace("?module=user_group")\',3000);';
  311. $msg.='</script>';
  312. echo '<p class="bigtitle"><br>'.$msg.'</p>';
  313. //echo $action;
  314. }
  315. ?>
  316. <br>
  317. <form name="new_group" method="post" action="" style="display: none" enctype="multipart/form-data">
  318. <input type="hidden" name="module" value="user_group">
  319. <input type="hidden" name="action" value="">
  320. <input type="hidden" name="group" value="">
  321. <script language="JavaScript">
  322. function view(groupid)
  323. {
  324. document.viewgroup.group.value=groupid;
  325. document.viewgroup.submit();
  326. }
  327. function viewrec(id)
  328. {
  329. document.viewuser.userID.value=id;
  330. document.viewuser.submit();
  331. }
  332. </script>
  333. <table width="50%" border="0" cellspacing="0" cellpadding="0" style="border: solid 1px #336699">
  334. <tr>
  335. <td width="30%" colspan="3" bgcolor="#FFCC33">
  336. <p class="bigtitle">:: <?php echo $strCreatNew.' / '.$strEdit.' '.$strGroup; ?> ::</p></td>
  337. </tr>
  338. <tr>
  339. <td width="30%"><p class="formtitle"><?php echo $strName; ?></p></td>
  340. <td width="5%">&nbsp;</td>
  341. <td width="65%"><input type="text" class="mediuminput" name="group_name"></td>
  342. </tr>
  343. <tr>
  344. <td width="30%"><p class="formtitle">Icon</p></td>
  345. <td width="5%">&nbsp;</td>
  346. <td width="65%"><input name="icon" type="file" class="mediuminput" id="icon"></td>
  347. </tr>
  348. <tr>
  349. <td width="30%" colspan="3">
  350. <p class="bigtitle">
  351. <input type="submit" class="submit" value="&nbsp;&nbsp;Tạo&nbsp;&nbsp;">
  352. &nbsp;&nbsp;&nbsp;
  353. <input type="submit" class="reset" value="Reset">
  354. </p></td>
  355. </tr>
  356. </table>
  357. </form>
  358. </td></tr>
  359. <tr align="center" valign="top">
  360. <td colspan="3" align="center" valign="top">
  361. <table width="100%" cellspacing="0" cellpadding="0" border="0">
  362. <?php
  363. if (isset($_POST['group']))
  364. {
  365. ?>
  366. <tr>
  367. <td><p class="grouptitle"><?php echo $strGroup; ?>
  368. <?php
  369. if (isset($cur_group))
  370. {
  371. if (isset($cur_icon) && $cur_icon!='')
  372. echo '<img src="icons/'.$cur_icon.'" width="22" height="22" border="0" align="absmiddle">';
  373. echo ' <font color="#FF5500">'.$cur_group.'</font>';
  374. $members=mysql_fetch_array(mysql_query('select count(*) from users where groupof="'.$_POST['group'].'"',$link));
  375. echo ' <font size="1px">('.$members[0].' '.$strMember.' )</font></p>';
  376. }
  377. ?>
  378. </td>
  379. </tr>
  380. <tr>
  381. <td width="100%">
  382. <table width="100%" height="30" border="0" cellpadding="2" cellspacing="2">
  383. <tr>
  384. <?php
  385. if ($_SESSION['usergroup']==1)
  386. {
  387. $allow_edit=true;
  388. ?>
  389. <td width="90" onClick="window.location='?module=creat_user';" style="cursor: hand; border: 1px solid #E1E1E1" onMouseOver="changebd(this,'#336699')" onMouseOut="undobd(this)">
  390. <p class="buttontext"><img align="absmiddle" src="images/filenew.gif" width="22" height="22">
  391. &nbsp;&nbsp;<?php echo $strCreatNew; ?></p>
  392. </td>
  393. <!--
  394. <td width="120" onClick="setdisplay('edit');" style="cursor: hand; border: 1px solid #E1E1E1" onMouseOver="changebd(this,'#336699')" onMouseOut="undobd(this)">
  395. <p class="buttontext"><img align="absmiddle" src="images/move_user.gif" width="22" height="22">
  396. &nbsp;&nbsp;<?php echo $strChangeCat; ?></p>
  397. </td>
  398. -->
  399. <?php
  400. if ($allow_delete==true)
  401. {
  402. ?>
  403. <td width="70" onClick="del_user();" style="cursor: hand; border: 1px solid #E1E1E1" onMouseOver="changebd(this,'#336699')" onMouseOut="undobd(this)">
  404. <p class="buttontext"><img align="absmiddle" src="images/cancel.gif" width="22" height="22"> &nbsp;&nbsp;<?php echo $strDelete; ?></p>
  405. </td>
  406. <?php
  407. }
  408. }
  409. else
  410. {
  411. ?>
  412. <td width="400" style="cursor: hand; border: 1px solid #E1E1E1" onMouseOver="changebd(this,'#336699')" onMouseOut="undobd(this)">
  413. <p class="buttontext">&nbsp;&nbsp;Bạn chưa được phép xem thông tin này !</p>
  414. </td>
  415. <?php
  416. }
  417. ?>
  418. <td bgcolor="#E1E1E1">&nbsp;</td>
  419. </tr>
  420. </table></td>
  421. </tr>
  422. <?php
  423. $title=array('<input name="cbxSelectAll" type="checkbox" onclick="javascript: checkAll(this.form);">','ID',$strUserName,
  424. $strRealName,$strBirthDay,
  425. $strGender,$strAddress,$strPhone,
  426. );
  427. $var_array=array('id','id','username',
  428. 'realname','birthday',
  429. 'genre','address','phone',
  430. );
  431. $dimension=array(25,30,150,
  432. 200,90,
  433. 50,300,120,
  434. 200,200,300,120,
  435. 250,120,120,
  436. 50,70,50);
  437. ?>
  438. <tr>
  439. <td align="center" valign="top" style="padding: 3 0 3 0">
  440. <!-- Data Table -->
  441. <?php
  442. $group=$_POST['group'];
  443. $view='select * from users';
  444. $view.=' where groupof="'.$group.'"';
  445. $view.=' order by id ASC';
  446. //echo $view;
  447. show_datatbl($view,'datatbl','','dataTable',$title,$dimension,$var_array);
  448. ?>
  449. <!-- End Data Table -->
  450. </td>
  451. </tr>
  452. <?php
  453. ?>
  454. <tr><td align="center" valign="top">
  455. <?php show_filter('dataTable',$title,$var_array); ?>
  456. </td></tr>
  457. <?php
  458. }
  459. else
  460. {
  461. }
  462. ?>
  463. </table>
  464. <?php
  465. if ($allow_edit==true)
  466. {
  467. ?>
  468. <SCRIPT language="JavaScript">
  469. var frmvalidator = new Validator("new_group");
  470. frmvalidator.addValidation("group_name","req","Nhom User khong the ko co ten !");
  471. </script>
  472. <?php
  473. }
  474. ?>
  475. </td>
  476. </tr>
  477. </table>
  478. <?php
  479. }
  480. else
  481. {
  482. ?>
  483. <p class="bigtitle"><?php echo $strErr['201']; ?></p>
  484. <?php
  485. }
  486. ?>