categories.php

来自「全新且完善的强大网上商店系统」· PHP 代码 · 共 385 行 · 第 1/2 页

PHP
385
字号
<?php
/*
  [SOOBIC!] admin/categories.php 

	Version: 1.5
	Author: Soolan (soolan@qq.com)
	Copyright: soolan (www.soobic.com)
	Last Modified: 2005/4/3 10:00

*/
if(!defined('IN_SOOBIC')) {
        exit('Access Denied');
}

cpheader();


include ($soobic."./admin/languages/".$language."/categories.php");

if(!$allowsetproduct){
    cpmsg("对不起,您的管理权限受限,不能进行此操作。");
}

$action = (isset($HTTP_GET_VARS['action']) ? $HTTP_GET_VARS['action'] : (isset($HTTP_POST_VARS['action']) ? $HTTP_POST_VARS['action'] : ''));
if ($action) {
  switch($action){
     case 'new_category':
				if (isset($HTTP_POST_VARS['categories_id'])) $categories_id = stripslashes($HTTP_POST_VARS['categories_id']);
        $sort_order = stripslashes($HTTP_POST_VARS['sort_order']);
        
        $db->query("insert into $table_categories (parent_id,sort_order,date_added) values ('$current_category_id','$sort_order',now())");
        $categories_id = $db->insert_id();

        $languages = tep_get_languages();
        for ($i=0, $n=sizeof($languages); $i<$n; $i++) {
          $categories_name_array = $HTTP_POST_VARS['categories_name'];
          $language_id = $languages[$i]['id'];
          $categories_name=stripslashes($categories_name_array[$language_id]);
					$db->query("insert into $table_categories_description (categories_name,categories_id,language_id) values ('$categories_name','$categories_id','$language_id')");
        }
        $categories_image = new upload('categories_image',$soobic.'./upload/images/category');
        if ($categories_image->parse($timestamp)) {
            $categories_image->save();
						$db->query("update $table_categories set categories_image = '" . addslashes($categories_image->filename) . "' where categories_id = '" . (int)$categories_id . "'");
        }
        updatecache('categories');
        cpmsg("Lansen! 分类添加成功。",tep_href_link('admincp.php','act=catalog&cPath='.$cPath.'&cID='.$categories_id)); 
     break;
     case 'delete_category_confirm': 
        $categories = tep_get_category_tree($categories_id, '', '0', '', true);
				$products = array();
        $products_delete = array();
        
        for ($i=0, $n=sizeof($categories); $i<$n; $i++) {
            $product_ids_query = $db->query("select products_id from $table_products_to_categories where categories_id = '" . (int)$categories[$i]['id'] . "'");
            while ($product_ids = $db->fetch_array($product_ids_query)) {
              $products[$product_ids['products_id']]['categories'][] = $categories[$i]['id'];
            }
        }
				
				reset($products);
        while (list($key, $value) = each($products)) {
            $category_ids = '';
            for ($i=0, $n=sizeof($value['categories']); $i<$n; $i++) {
              $category_ids .= "'" . (int)$value['categories'][$i] . "', ";
            }
            $category_ids = substr($category_ids, 0, -2);
            $check_query = $db->query("select count(*) as total from $table_products_to_categories where products_id = '" . (int)$key . "' and categories_id not in (" . $category_ids . ")");
            $check = $db->fetch_array($check_query);
            if ($check['total'] < '1') {
              $products_delete[$key] = $key;
            }
        }
				tep_set_time_limit(0);
			  for ($i=0, $n=sizeof($categories); $i<$n; $i++) {
            tep_remove_category($categories[$i]['id']);
        }

        reset($products_delete);
        while (list($product_id) = each($products_delete)){
            tep_remove_product($key);
        }

		    updatecache("categories");
		    cpmsg("Lansen! 分类删除成功。",tep_href_link('admincp.php','act=catalog&cPath='.$cPath.'&cID='.$categories_id)); 
     break;
     case 'change_category': 
		    if (isset($HTTP_POST_VARS['categories_id'])) $categories_id = stripslashes($HTTP_POST_VARS['categories_id']);
        $sort_order = stripslashes($HTTP_POST_VARS['sort_order']);
        $datetime=date("Y-m-d h:i:s",time());
				$db->query("update $table_categories set last_modified ='$datetime',sort_order='$sort_order' where categories_id = '" . (int)$categories_id . "'");
        $languages = tep_get_languages();
				for ($i=0, $n=sizeof($languages); $i<$n; $i++) {
          $categories_name_array = $HTTP_POST_VARS['categories_name'];
          $language_id = $languages[$i]['id'];
          $categories_name=stripslashes($categories_name_array[$language_id]);
					$db->query("update $table_categories_description set categories_name='$categories_name' where categories_id ='".(int)$categories_id."' and language_id = '".(int)$languages[$i]['id']."'");
        }

        $categories_image = new upload('categories_image',$soobic.'./upload/images/category/');
        if ($categories_image->parse($timestamp) || ($delete && $delete=='1') ) {
            $query = $db->query("select categories_image from $table_categories where categories_id = '" . (int)$categories_id . "'");
            $cat_image = $db->fetch_array($query);
            if (file_exists($soobic.'./upload/images/category/'. $cat_image['categories_image'])) {
                @unlink($soobic.'./upload/images/category/'. $cat_image['categories_image']);
            }
					  $image_filename=$categories_image->save() ? $categories_image->filename : '';
						$db->query("update $table_categories set categories_image = '" . $image_filename . "' where categories_id = '" . (int)$categories_id . "'");
        }
        updatecache('categories');
        cpmsg("Lansen! 分类更新成功。",tep_href_link('admincp.php','act=catalog&cPath='.$cPath.'&cID='.$categories_id)); 
		 break;
     case 'move_category_confirm':
        //echo "<pre>";
        //print_r($HTTP_POST_VARS);
				if (isset($HTTP_POST_VARS['categories_id']) && ($HTTP_POST_VARS['categories_id'] != $HTTP_POST_VARS['move_to_category_id'])) {
           $categories_id = $categories_id;
           $new_parent_id = $move_to_category_id;

           $path = explode('_', tep_get_generated_category_path_ids($new_parent_id));

           if (in_array($categories_id, $path)) {
               $messageStack->add_session('category',ERROR_CANNOT_MOVE_CATEGORY_TO_PARENT);
               tep_redirect(tep_href_link('admincp.php','act=catalog&cPath=' . $cPath . '&cID=' . $categories_id));
           } else {
               $db->query("update $table_categories set parent_id = '" . (int)$new_parent_id . "', last_modified = now() where categories_id = '" . (int)$categories_id . "'");
               tep_redirect(tep_href_link('admincp.php','act=catalog&cPath=' . $new_parent_id . '&cID=' . $categories_id));
           }
        }else{
            $messageStack->add_session('category',ERROR_CANNOT_MOVE_CATEGORY_TO_SELF);
						tep_redirect(tep_href_link('admincp.php','act=catalog&cPath=' . $cPath . '&cID=' . $categories_id));
        }

     break;
     default:
  }
}elseif($type){
  switch($type){
     case 'new_category':
        $category_inputs_string = '';
				$languages = tep_get_languages();
        for ($i = 0, $n = sizeof($languages); $i < $n; $i++) {
          $category_inputs_string .= '<br><img src="'.IMGDIR.'/'. $languages[$i]['directory'] .'/'. $languages[$i]['image'].'" border="0" alt="'.$languages[$i]['name'].'"> &nbsp;<input type="text" size="30" name="categories_name[' . $languages[$i]['id'] . ']">';
        }
?>        
<form method="post" action="<?=tep_href_link('admincp.php','act=catalog&cPath='.$cPath)?>" enctype="multipart/form-data">
<input type="hidden" name="action" value="new_category">
<table cellspacing="0" cellpadding="0" border="0" width="80%" align="center">
<tr><td bgcolor="<?=BORDERCOLOR?>">
<table  border="0" cellspacing="1" cellpadding="6" width="95%" class="tableout" align="center">
<tr class="header"><td colspan="7"><?=TEXT_INFO_HEADING_NEW_CATEGORY;?></td></tr>

<tr align="center" bgcolor="<?=ALTBG1?>"><td width="40%" align="right"><?=TEXT_CATEGORIES_NAME;?></td>
<td align="left"><?=$category_inputs_string;?></td>
</tr>
<tr align="center" bgcolor="<?=ALTBG2?>"><td align="right"><?=TEXT_CATEGORIES_IMAGE;?></td>
<td align="left"><input type="file" name="categories_image"></td>
</tr>
<tr align="center" bgcolor="<?=ALTBG2?>"><td align="right"><?=TEXT_SORT_ORDER;?></td>
<td align="left"><input type="text" size="2" name="sort_order"></td>
</tr>

</table></td></tr></table>
<br><center><?=$warning?>
<input type="submit" name="submit" value="<?=SUBMIT?>">&nbsp;
</center></form><br><br>
<?
     break;
     case 'delete_category':
        $categories_query = $db->query("select c.categories_id, cd.categories_name from $table_categories c, $table_categories_description cd where c.categories_id = '" . (int)$cID. "' and c.categories_id = cd.categories_id and cd.language_id = '" . (int)$languages_id . "' order by c.sort_order, cd.categories_name");
        $categories = $db->fetch_array($categories_query);
        @extract($categories);
        
				$childs_count=tep_childs_in_category_count($cID);
        $products_in_category_count=tep_products_in_category_count($cID);
?>
<br>
<table  border="0" cellspacing="1" cellpadding="6" width="95%" class="tableout" align="center">
<tr class="header" ><td colspan="2"><?=SPECIALS_NOTICE?></td></tr>
<tr bgcolor="<?=ALTBG1?>"><td width="60%"><li><?=TEXT_DELETE_CATEGORY_INTRO;?></td><td><b><?=$categories_name?></b></td></tr>
<?if($childs_count){?><tr bgcolor="<?=ALTBG1?>"><td colspan="2"><li><?=sprintf(TEXT_DELETE_WARNING_CHILDS, $childs_count)?></td></tr><?}?>
<?if($products_in_category_count){?><tr bgcolor="<?=ALTBG1?>"><td colspan="2"><li><?=sprintf(TEXT_DELETE_WARNING_PRODUCTS,$products_in_category_count)?></td></tr><?}?>
</table>
<br>

<form method="post" name="categories" action="<?=tep_href_link('admincp.php', 'act=catalog&action=delete_category_confirm&cPath='.$cPath)?>">
<input type="hidden" name="categories_id" value="<?=$categories_id;?>">
<br><center>
<?=tep_image_submit('button_delete.gif', IMAGE_DELETE)?> <a href="<?=tep_href_link('admincp.php', 'act=catalog&cPath=' . $cPath . '&cID=' . $categories_id)?>"><?=tep_image_button('button_cancel.gif', IMAGE_CANCEL)?></a>
</center></form><br><br>
<?				
     break;
     case 'change_category':

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?