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

/Quản lý website quảng cáo PHP/admin/home_product.php

https://gitlab.com/phamngsinh/baitaplon_sinhvien
PHP | 202 lines | 88 code | 114 blank | 0 comment | 14 complexity | 2b43973896271fcf5ca7af9bbeef4d58 MD5 | raw file
  1. <? // Config
  2. $tableCategoryConfig = 'tbl_product';
  3. $tableConfig = 'tbl_product_new';
  4. $actConfig = 'home_product';
  5. ?>
  6. <? $errMsg =''?>
  7. <?
  8. switch ($_GET['action']){
  9. case 'del' :
  10. $id = $_GET['id'];
  11. @$result = mysql_query("delete from ".$tableConfig." where id='".$id."'",$conn);
  12. if ($result) $errMsg = 'Đã xóa thành công.';
  13. else $errMsg = 'Không thể xóa dữ liệu !';
  14. break;
  15. }
  16. if (isset($_POST['btnDel'])) {
  17. $cnt=0;
  18. if($_POST['chk']!=''){
  19. foreach ($_POST['chk'] as $id){
  20. @$result = mysql_query("delete from ".$tableConfig." where id='".$id."'",$conn);
  21. if ($result) $cnt++;
  22. }
  23. $errMsg = 'Ðã xóa '.$cnt.' phần tử.';
  24. }else{
  25. $errMsg = 'Hãy chọn trước khi xóa !';
  26. }
  27. }
  28. $page = $_GET['page'];
  29. $p=0;
  30. if ($page!='') $p=$page;
  31. $where='1=1'?>
  32. <form method="POST" action="./" name="frmForm" enctype="multipart/form-data">
  33. <input type=hidden name="page" value="<?=$page?>">
  34. <input type="hidden" name="act" value="<?=$actConfig?>">
  35. <?
  36. $pageindex = createPage(countRecord($tableConfig,$where),"./?act=".$actConfig."&cat=".$_REQUEST['cat']."&page=",$MAXPAGE,$page)?>
  37. <? if ($_REQUEST['code']==1) $errMsg = 'Cập nhật thành công.'?>
  38. <table cellspacing="0" cellpadding="0" width="100%">
  39. <tr><td height="30" class="smallfont">Trang : <?=$pageindex?></td></tr>
  40. </table>
  41. <table border="1" cellpadding="2" style="border-collapse: collapse" bordercolor="#C9C9C9" width="100%">
  42. <tr>
  43. <th width="25" class="title"><input type="checkbox" name="chkall" onClick="chkallClick(this);"></th>
  44. <th width="211" class="title"><a class="title" href="<?=getLinkSort(2)?>">Tên S&#7843;n ph&#7849;m</a></th>
  45. <th width="172" class="title"><a class="title" href="<?=getLinkSort(3)?>">Thứ tự sắp xếp</a></th>
  46. <th width="101" class="title"><a class="title" href="<?=getLinkSort(4)?>">Không hiển thị</a></th>
  47. <th width="155" class="title"><a class="title" href="<?=getLinkSort(5)?>">Ngày tạo lập</a></th>
  48. <th width="169" class="title"><a class="title" href="<?=getLinkSort(6)?>">Lần hiệu chỉnh trước</a></th>
  49. <th width="82" class="title"><a class="title" href="<?=getLinkSort(7)?>">Ngôn ngữ</a></th>
  50. </tr>
  51. <?
  52. $sortby = 'order by date_added';
  53. if ($_REQUEST['sortby']!='') $sortby='order by '.(int)$_REQUEST['sortby'];
  54. $direction=($_REQUEST['direction']==''||$_REQUEST['direction']=='0'?'desc':'');
  55. $sql="select *,DATE_FORMAT(date_added,'%d/%m/%Y %h:%i') as dateAdd,DATE_FORMAT(last_modified,'%d/%m/%Y %h:%i') as dateModify from $tableConfig where $where $sortby $direction limit ".($p*$MAXPAGE).",".$MAXPAGE;
  56. $result=mysql_query($sql,$conn);
  57. $i=0;
  58. while($row=mysql_fetch_array($result)){
  59. $pro = getRecord($tableCategoryConfig,'id='.$row['product_id']);
  60. $color = $i++%2 ? '#d5d5d5' : '#e5e5e5'?>
  61. <tr>
  62. <td bgcolor="<?=$color?>" class="smallfont" align="center">
  63. <input type="checkbox" name="chk[]" value="<?=$row['id']?>">
  64. </td>
  65. <td bgcolor="<?=$color?>" class="smallfont" align="center"><?=$pro['name']?></td>
  66. <td bgcolor="<?=$color?>" class="smallfont" align="center"><?=$row['sort']?></td>
  67. <td bgcolor="<?=$color?>" class="smallfont" align="center"><?=$row['status']?></td>
  68. <td bgcolor="<?=$color?>" class="smallfont" align="center"><?=$row['dateAdd']?></td>
  69. <td bgcolor="<?=$color?>" class="smallfont" align="center"><?=$row['dateModify']?></td>
  70. <td bgcolor="<?=$color?>" class="smallfont" align="center"><?=$row['lang']?></td>
  71. </tr>
  72. <?
  73. }
  74. ?>
  75. </table>
  76. <input type="submit" value="Xóa chọn" name="btnDel" onclick="return confirm('Bạn có chắc chắn muốn xóa ?');" class="button">
  77. </form>
  78. <script language="JavaScript">
  79. function chkallClick(o) {
  80. var form = document.frmForm;
  81. for (var i = 0; i < form.elements.length; i++) {
  82. if (form.elements[i].type == "checkbox" && form.elements[i].name!="chkall") {
  83. form.elements[i].checked = document.frmForm.chkall.checked;
  84. }
  85. }
  86. }
  87. </script>
  88. <? if($errMsg!=''){echo '<p align=center class="err">'.$errMsg.'<br></p>';}?>