/Quản lý website quảng cáo PHP/admin/content_category.php
PHP | 148 lines | 139 code | 9 blank | 0 comment | 20 complexity | dedb3cc11887970cf2242887ac263b98 MD5 | raw file
- <? $errMsg =''?>
- <?
- switch ($_GET['action']){
- case 'del' :
- $id = $_GET['id'];
- $r = getRecord("tbl_content_category","id=".$id);
- $resultParent = mysql_query("select id from tbl_content_category where parent='".$id."'",$conn);
- if (mysql_num_rows($resultParent) <= 0){
- @$result = mysql_query("delete from tbl_content_category where id='".$id."'",$conn);
- if ($result){
- if(file_exists('../'.$r['image'])) @unlink('../'.$r['image']);
- if(file_exists('../'.$r['image_large'])) @unlink('../'.$r['image_large']);
- $errMsg = "Đã xóa thành công.";
- }else $errMsg = "Không thể xóa dữ liệu !";
- }else{
- $errMsg = "Đang có danh mục sử dụng. Bạn không thể xóa !";
- }
- break;
- }
-
- if (isset($_POST['btnDel'])){
- $cntDel=0;
- $cntNotDel=0;
- $cntParentExist=0;
- if($_POST['chk']!=''){
- foreach ($_POST['chk'] as $id){
- $r = getRecord("tbl_content_category","id=".$id);
- $resultParent = mysql_query("select id from tbl_content_category where parent='".$id."'",$conn);
- if (mysql_num_rows($resultParent) <= 0){
- @$result = mysql_query("delete from tbl_content_category where id='".$id."'",$conn);
- if ($result){
- if(file_exists('../'.$r['image'])) @unlink('../'.$r['image']);
- if(file_exists('../'.$r['image_large'])) @unlink('../'.$r['image_large']);
- $cntDel++;
- }else $cntNotDel++;
- }else{
- $cntParentExist++;
- }
- }
- $errMsg = "Đã xóa ".$cntDel." phần tử.<br><br>";
- $errMsg .= $cntNotDel>0 ? "Không thể xóa ".$cntNotDel." phần tử.<br>" : '';
- $errMsg .= $cntParentExist>0 ? "Đang có danh mục con sử dụng ".$cntParentExist." phần tử." : '';
- }else{
- $errMsg = "Hãy chọn trước khi xóa !";
- }
- }
-
- $page = $_GET["page"];
- $p=0;
- if ($page!='') $p=$page;
- $where="1=1";
- if ($_REQUEST['cat']!='') $where="parent=".$_REQUEST['cat']?>
- <form method="POST" action="./?act=content_category" name="frmForm" enctype="multipart/form-data">
- <input type="hidden" name="page" value="<?=$page?>">
- <?
- $pageindex = createPage(countRecord("tbl_content_category",$where),"./?act=content_category&cat=".$_REQUEST['cat']."&page=",$MAXPAGE,$page)?>
-
- <? if ($_REQUEST['code']==1) $errMsg = 'Cập nhật thành công.'?>
-
- <table cellspacing="0" cellpadding="0" width="100%">
-
- <tr>
- <td class="smallfont">Trang : <?=$pageindex?></td>
- <td height="30" align="right" class="smallfont">
- <?=comboCategory('ddCat',getArrayCategory('tbl_content_category'),'smallfont',$_REQUEST['cat'],1)?>
- <input type="button" value="Chuyển" class="button" onClick="window.location='./?act=content_category&cat='+ddCat.value">
- </td>
- </tr>
- </table>
-
- <table border="1" cellpadding="2" bordercolor="#C9C9C9" width="100%">
- <tr>
- <th width="20" class="title"><input type="checkbox" name="chkall" onClick="chkallClick(this);"></th>
- <th width="20" class="title"></th>
- <th width="20" class="title"></th>
- <th width="20" class="title"><a class="title" href="<?=getLinkSort(1)?>">ID</a></th>
- <th class="title"><a class="title" href="<?=getLinkSort(2)?>">Mã</a></th>
- <th class="title"><a class="title" href="<?=getLinkSort(3)?>">Tên danh mục</a></th>
- <th width="100" class="title"><a class="title" href="<?=getLinkSort(4)?>">Thuộc danh mục</a></th>
- <th class="title"><a class="title" href="<?=getLinkSort(5)?>">Tiêu đề</a></th>
- <th width="40" class="title"><a class="title" href="<?=getLinkSort(6)?>">Mô tả ngắn</a></th>
- <th width="40" class="title"><a class="title" href="<?=getLinkSort(7)?>">Mô tả chi tiết</a></th>
- <th width="20" class="title"><a class="title" href="<?=getLinkSort(8)?>">Hình nhỏ</a></th>
- <th width="20" class="title"><a class="title" href="<?=getLinkSort(9)?>">Hình lớn</a></th>
- <th width="50" class="title"><a class="title" href="<?=getLinkSort(10)?>">Thứ tự sắp xếp</a></th>
- <th width="50" class="title"><a class="title" href="<?=getLinkSort(11)?>">Không hiển thị</a></th>
- <th width="90" class="title"><a class="title" href="<?=getLinkSort(12)?>">Ngày tạo lập</a></th>
- <th width="90" class="title"><a class="title" href="<?=getLinkSort(13)?>">Lần hiệu chỉnh trước</a></th>
- <th width="20" class="title"><a class="title" href="<?=getLinkSort(14)?>">Ngôn ngữ</a></th>
- </tr>
-
- <?
- $sortby="order by date_added";
- if ($_REQUEST['sortby']!='') $sortby="order by ".(int)$_REQUEST['sortby'];
- $direction=($_REQUEST['direction']==''||$_REQUEST['direction']=='0'?"desc":"");
-
- $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;
- $result=mysql_query($sql,$conn);
- $i=0;
- while($row=mysql_fetch_array($result)){
- $parent = getRecord('tbl_content_category','id = '.$row['parent']);
- $color = $i++%2 ? "#d5d5d5" : "#e5e5e5"?>
-
- <tr>
- <td align="center" bgcolor="<?=$color?>" class="smallfont">
- <input type="checkbox" name="chk[]" value="<?=$row['id']?>"></td>
- <td bgcolor="<?=$color?>" class="smallfont" align="center">
- <a href="./?act=content_category_m&cat=<?=$_REQUEST['cat']?>&page=<?=$_REQUEST['page']?>&id=<?=$row['id']?>">Sửa</a>
- </td>
- <td bgcolor="<?=$color?>" class="smallfont" align="center">
- <a
- onClick="return confirm('Bạn có chắc chắn muốn xóa ?');"
- href="./?act=content_category&action=del&page=<?=$_REQUEST['page']?>&id=<?=$row['id']?>"
- >Xóa</a>
- </td>
- <td bgcolor="<?=$color?>" class="smallfont" align="center"><?=$row['id']?></td>
- <td bgcolor="<?=$color?>" class="smallfont"><?=$row['code']?></td>
- <td bgcolor="<?=$color?>" class="smallfont"><?=$row['name']?></td>
- <td bgcolor="<?=$color?>" class="smallfont"><?=$parent['name']?></td>
- <td bgcolor="<?=$color?>" class="smallfont"><?=$row['subject']!=''?'...':' '?></td>
- <td bgcolor="<?=$color?>" class="smallfont" align="center"><?=$row['detail_short']!=''?'...':' '?></td>
- <td bgcolor="<?=$color?>" class="smallfont" align="center"><?=$row['detail']!=''?'...':' '?></td>
- <td bgcolor="<?=$color?>" class="smallfont" align="center"><?=$row['image']!=''?'...':' '?></td>
- <td bgcolor="<?=$color?>" class="smallfont" align="center"><?=$row['image_large']!=''?'...':' '?></td>
- <td bgcolor="<?=$color?>" class="smallfont" align="center"><?=$row['sort']?></td>
- <td bgcolor="<?=$color?>" class="smallfont" align="center"><?=$row['status']?></td>
- <td bgcolor="<?=$color?>" class="smallfont" align="center"><?=$row['dateAdd']?></td>
- <td bgcolor="<?=$color?>" class="smallfont" align="center"><?=$row['dateModify']?></td>
- <td bgcolor="<?=$color?>" class="smallfont" align="center"><?=$row['lang']?></td>
- </tr>
- <?
- }
- ?>
- </table>
- <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">
- <input type="hidden" name="act" value="content_category">
- </form>
- <script language="JavaScript">
- function chkallClick(o) {
- var form = document.frmForm;
- for (var i = 0; i < form.elements.length; i++) {
- if (form.elements[i].type == "checkbox" && form.elements[i].name!="chkall") {
- form.elements[i].checked = document.frmForm.chkall.checked;
- }
- }
- }
- </script>
- <? if($errMsg!=''){echo '<p align=center class="err">'.$errMsg.'<br></p>';}?>