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

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

https://gitlab.com/phamngsinh/baitaplon_sinhvien
PHP | 148 lines | 139 code | 9 blank | 0 comment | 20 complexity | dedb3cc11887970cf2242887ac263b98 MD5 | raw file
  1. <? $errMsg =''?>
  2. <?
  3. switch ($_GET['action']){
  4. case 'del' :
  5. $id = $_GET['id'];
  6. $r = getRecord("tbl_content_category","id=".$id);
  7. $resultParent = mysql_query("select id from tbl_content_category where parent='".$id."'",$conn);
  8. if (mysql_num_rows($resultParent) <= 0){
  9. @$result = mysql_query("delete from tbl_content_category where id='".$id."'",$conn);
  10. if ($result){
  11. if(file_exists('../'.$r['image'])) @unlink('../'.$r['image']);
  12. if(file_exists('../'.$r['image_large'])) @unlink('../'.$r['image_large']);
  13. $errMsg = "Đã xóa thành công.";
  14. }else $errMsg = "Không thể xóa dữ liệu !";
  15. }else{
  16. $errMsg = "Đang có danh mục sử dụng. Bạn không thể xóa !";
  17. }
  18. break;
  19. }
  20. if (isset($_POST['btnDel'])){
  21. $cntDel=0;
  22. $cntNotDel=0;
  23. $cntParentExist=0;
  24. if($_POST['chk']!=''){
  25. foreach ($_POST['chk'] as $id){
  26. $r = getRecord("tbl_content_category","id=".$id);
  27. $resultParent = mysql_query("select id from tbl_content_category where parent='".$id."'",$conn);
  28. if (mysql_num_rows($resultParent) <= 0){
  29. @$result = mysql_query("delete from tbl_content_category where id='".$id."'",$conn);
  30. if ($result){
  31. if(file_exists('../'.$r['image'])) @unlink('../'.$r['image']);
  32. if(file_exists('../'.$r['image_large'])) @unlink('../'.$r['image_large']);
  33. $cntDel++;
  34. }else $cntNotDel++;
  35. }else{
  36. $cntParentExist++;
  37. }
  38. }
  39. $errMsg = "Đã xóa ".$cntDel." phần tử.<br><br>";
  40. $errMsg .= $cntNotDel>0 ? "Không thể xóa ".$cntNotDel." phần tử.<br>" : '';
  41. $errMsg .= $cntParentExist>0 ? "Đang có danh mục con sử dụng ".$cntParentExist." phần tử." : '';
  42. }else{
  43. $errMsg = "Hãy chọn trước khi xóa !";
  44. }
  45. }
  46. $page = $_GET["page"];
  47. $p=0;
  48. if ($page!='') $p=$page;
  49. $where="1=1";
  50. if ($_REQUEST['cat']!='') $where="parent=".$_REQUEST['cat']?>
  51. <form method="POST" action="./?act=content_category" name="frmForm" enctype="multipart/form-data">
  52. <input type="hidden" name="page" value="<?=$page?>">
  53. <?
  54. $pageindex = createPage(countRecord("tbl_content_category",$where),"./?act=content_category&cat=".$_REQUEST['cat']."&page=",$MAXPAGE,$page)?>
  55. <? if ($_REQUEST['code']==1) $errMsg = 'Cập nhật thành công.'?>
  56. <table cellspacing="0" cellpadding="0" width="100%">
  57. <tr>
  58. <td class="smallfont">Trang : <?=$pageindex?></td>
  59. <td height="30" align="right" class="smallfont">
  60. <?=comboCategory('ddCat',getArrayCategory('tbl_content_category'),'smallfont',$_REQUEST['cat'],1)?>
  61. <input type="button" value="Chuyển" class="button" onClick="window.location='./?act=content_category&cat='+ddCat.value">
  62. </td>
  63. </tr>
  64. </table>
  65. <table border="1" cellpadding="2" bordercolor="#C9C9C9" width="100%">
  66. <tr>
  67. <th width="20" class="title"><input type="checkbox" name="chkall" onClick="chkallClick(this);"></th>
  68. <th width="20" class="title"></th>
  69. <th width="20" class="title"></th>
  70. <th width="20" class="title"><a class="title" href="<?=getLinkSort(1)?>">ID</a></th>
  71. <th class="title"><a class="title" href="<?=getLinkSort(2)?>"></a></th>
  72. <th class="title"><a class="title" href="<?=getLinkSort(3)?>">Tên danh mục</a></th>
  73. <th width="100" class="title"><a class="title" href="<?=getLinkSort(4)?>">Thuộc danh mục</a></th>
  74. <th class="title"><a class="title" href="<?=getLinkSort(5)?>">Tiêu đề</a></th>
  75. <th width="40" class="title"><a class="title" href="<?=getLinkSort(6)?>"> tả ngắn</a></th>
  76. <th width="40" class="title"><a class="title" href="<?=getLinkSort(7)?>"> tả chi tiết</a></th>
  77. <th width="20" class="title"><a class="title" href="<?=getLinkSort(8)?>">Hình nhỏ</a></th>
  78. <th width="20" class="title"><a class="title" href="<?=getLinkSort(9)?>">Hình lớn</a></th>
  79. <th width="50" class="title"><a class="title" href="<?=getLinkSort(10)?>">Thứ tự sắp xếp</a></th>
  80. <th width="50" class="title"><a class="title" href="<?=getLinkSort(11)?>">Không hiển thị</a></th>
  81. <th width="90" class="title"><a class="title" href="<?=getLinkSort(12)?>">Ngày tạo lập</a></th>
  82. <th width="90" class="title"><a class="title" href="<?=getLinkSort(13)?>">Lần hiệu chỉnh trước</a></th>
  83. <th width="20" class="title"><a class="title" href="<?=getLinkSort(14)?>">Ngôn ngữ</a></th>
  84. </tr>
  85. <?
  86. $sortby="order by date_added";
  87. if ($_REQUEST['sortby']!='') $sortby="order by ".(int)$_REQUEST['sortby'];
  88. $direction=($_REQUEST['direction']==''||$_REQUEST['direction']=='0'?"desc":"");
  89. $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 tbl_content_category where parent<>0 and $where $sortby $direction limit ".($p*$MAXPAGE).",".$MAXPAGE;
  90. $result=mysql_query($sql,$conn);
  91. $i=0;
  92. while($row=mysql_fetch_array($result)){
  93. $parent = getRecord('tbl_content_category','id = '.$row['parent']);
  94. $color = $i++%2 ? "#d5d5d5" : "#e5e5e5"?>
  95. <tr>
  96. <td align="center" bgcolor="<?=$color?>" class="smallfont">
  97. <input type="checkbox" name="chk[]" value="<?=$row['id']?>"></td>
  98. <td bgcolor="<?=$color?>" class="smallfont" align="center">
  99. <a href="./?act=content_category_m&cat=<?=$_REQUEST['cat']?>&page=<?=$_REQUEST['page']?>&id=<?=$row['id']?>">Sửa</a>
  100. </td>
  101. <td bgcolor="<?=$color?>" class="smallfont" align="center">
  102. <a
  103. onClick="return confirm('Bạn có chắc chắn muốn xóa ?');"
  104. href="./?act=content_category&action=del&page=<?=$_REQUEST['page']?>&id=<?=$row['id']?>"
  105. >Xóa</a>
  106. </td>
  107. <td bgcolor="<?=$color?>" class="smallfont" align="center"><?=$row['id']?></td>
  108. <td bgcolor="<?=$color?>" class="smallfont"><?=$row['code']?></td>
  109. <td bgcolor="<?=$color?>" class="smallfont"><?=$row['name']?></td>
  110. <td bgcolor="<?=$color?>" class="smallfont"><?=$parent['name']?></td>
  111. <td bgcolor="<?=$color?>" class="smallfont"><?=$row['subject']!=''?'...':'&nbsp;'?></td>
  112. <td bgcolor="<?=$color?>" class="smallfont" align="center"><?=$row['detail_short']!=''?'...':'&nbsp;'?></td>
  113. <td bgcolor="<?=$color?>" class="smallfont" align="center"><?=$row['detail']!=''?'...':'&nbsp;'?></td>
  114. <td bgcolor="<?=$color?>" class="smallfont" align="center"><?=$row['image']!=''?'...':'&nbsp;'?></td>
  115. <td bgcolor="<?=$color?>" class="smallfont" align="center"><?=$row['image_large']!=''?'...':'&nbsp;'?></td>
  116. <td bgcolor="<?=$color?>" class="smallfont" align="center"><?=$row['sort']?></td>
  117. <td bgcolor="<?=$color?>" class="smallfont" align="center"><?=$row['status']?></td>
  118. <td bgcolor="<?=$color?>" class="smallfont" align="center"><?=$row['dateAdd']?></td>
  119. <td bgcolor="<?=$color?>" class="smallfont" align="center"><?=$row['dateModify']?></td>
  120. <td bgcolor="<?=$color?>" class="smallfont" align="center"><?=$row['lang']?></td>
  121. </tr>
  122. <?
  123. }
  124. ?>
  125. </table>
  126. <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">
  127. <input type="hidden" name="act" value="content_category">
  128. </form>
  129. <script language="JavaScript">
  130. function chkallClick(o) {
  131. var form = document.frmForm;
  132. for (var i = 0; i < form.elements.length; i++) {
  133. if (form.elements[i].type == "checkbox" && form.elements[i].name!="chkall") {
  134. form.elements[i].checked = document.frmForm.chkall.checked;
  135. }
  136. }
  137. }
  138. </script>
  139. <? if($errMsg!=''){echo '<p align=center class="err">'.$errMsg.'<br></p>';}?>