<?php
/**
* ECSHOP 商品管理程序
* ============================================================================
* 版权所有 2005-2009 上海商派网络科技有限公司,并保留所有权利。
* 网站地址: http://www.ecshop.com;
* ----------------------------------------------------------------------------
* 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和
* 使用;不允许对程序代码以任何形式任何目的的再发布。
* ============================================================================
* $Author: liubo $
* $Id: goods.php 16881 2009-12-14 09:19:16Z liubo $
*/
define('IN_ECS', true);
require(dirname(__FILE__) . '/includes/init.php');
require_once(ROOT_PATH . '/' . ADMIN_PATH . '/includes/lib_goods.php');
include_once(ROOT_PATH . '/includes/cls_image.php');
$image = new cls_image($_CFG['bgcolor']);
$exc = new exchange($ecs->table('goods'), $db, 'goods_id', 'goods_name');
/*------------------------------------------------------ */
//-- 商品列表,商品回收站
/*------------------------------------------------------ */
function getgoods_ida($tbbb) {
$sql = "select AUTO_INCREMENT from information_schema.TABLES where TABLE_NAME = '".$tbbb."'";
return $db->query($sql);
}
if ($_REQUEST['act'] == 'list' || $_REQUEST['act'] == 'trash')
{
admin_priv('goods_manage');
$cat_id = empty($_REQUEST['cat_id']) ? 0 : intval($_REQUEST['cat_id']);
$code = empty($_REQUEST['extension_code']) ? '' : trim($_REQUEST['extension_code']);
$suppliers_id = isset($_REQUEST['suppliers_id']) ? (empty($_REQUEST['suppliers_id']) ? '' : trim($_REQUEST['suppliers_id'])) : '';
$is_on_sale = isset($_REQUEST['is_on_sale']) ? ((empty($_REQUEST['is_on_sale']) && $_REQUEST['is_on_sale'] === 0) ? '' : trim($_REQUEST['is_on_sale'])) : '';
$handler_list = array();
$handler_list['virtual_card'][] = array('url'=>'virtual_card.php?act=card', 'title'=>$_LANG['card'], 'img'=>'icon_send_bonus.gif');
$handler_list['virtual_card'][] = array('url'=>'virtual_card.php?act=replenish', 'title'=>$_LANG['replenish'], 'img'=>'icon_add.gif');
$handler_list['virtual_card'][] = array('url'=>'virtual_card.php?act=batch_card_add', 'title'=>$_LANG['batch_card_add'], 'img'=>'icon_output.gif');
if ($_REQUEST['act'] == 'list' && isset($handler_list[$code]))
{
$smarty->assign('add_handler', $handler_list[$code]);
}
/* 供货商名 */
$suppliers_list_name = suppliers_list_name();
$suppliers_exists = 1;
if (empty($suppliers_list_name))
{
$suppliers_exists = 0;
}
$smarty->assign('is_on_sale', $is_on_sale);
$smarty->assign('suppliers_id', $suppliers_id);
$smarty->assign('suppliers_exists', $suppliers_exists);
$smarty->assign('suppliers_list_name', $suppliers_list_name);
unset($suppliers_list_name, $suppliers_exists);
/* 模板赋值 */
$goods_ur = array('' => $_LANG['01_goods_list'], 'virtual_card'=>$_LANG['50_virtual_card_list']);
$ur_here = ($_REQUEST['act'] == 'list') ? $goods_ur[$code] : $_LANG['11_goods_trash'];
$smarty->assign('ur_here', $ur_here);
$action_link = ($_REQUEST['act'] == 'list') ? add_link($code) : array('href' => 'goods.php?act=list', 'text' => $_LANG['01_goods_list']);
$smarty->assign('action_link', $action_link);
$smarty->assign('code', $code);
$smarty->assign('cat_list', cat_list(0, $cat_id));
$smarty->assign('brand_list', get_brand_list());
$smarty->assign('intro_list', get_intro_list());
$smarty->assign('lang', $_LANG);
$smarty->assign('list_type', $_REQUEST['act'] == 'list' ? 'goods' : 'trash');
$smarty->assign('use_storage', empty($_CFG['use_storage']) ? 0 : 1);
$suppliers_list = suppliers_list_info(' is_check = 1 ');
$suppliers_list_count = count($suppliers_list);
$smarty->assign('suppliers_list', ($suppliers_list_count == 0 ? 0 : $suppliers_list)); // 取供货商列表
$goods_list = goods_list($_REQUEST['act'] == 'list' ? 0 : 1, ($_REQUEST['act'] == 'list') ? (($code == '') ? 1 : 0) : -1);
$smarty->assign('goods_list', $goods_list['goods']);
$smarty->assign('filter', $goods_list['filter']);
$smarty->assign('record_count', $goods_list['record_count']);
$smarty->assign('page_count', $goods_list['page_count']);
$smarty->assign('full_page', 1);
/* 排序标记 */
$sort_flag = sort_flag($goods_list['filter']);
$smarty->assign($sort_flag['tag'], $sort_flag['img']);
/* 显示商品列表页面 */
assign_query_info();
$htm_file = ($_REQUEST['act'] == 'list') ?
'goods_list.htm' : (($_REQUEST['act'] == 'trash') ? 'goods_trash.htm' : 'group_list.htm');
$smarty->display($htm_file);
}
/*------------------------------------------------------ */
//-- 添加新商品 编辑商品
/*------------------------------------------------------ */
elseif ($_REQUEST['act'] == 'add' || $_REQUEST['act'] == 'edit' || $_REQUEST['act'] == 'copy')
{
include_once(ROOT_PATH . 'includes/fckeditor/fckeditor.php'); // 包含 html editor 类文件
$is_add = $_REQUEST['act'] == 'add'; // 添加还是编辑的标识
$is_copy = $_REQUEST['act'] == 'copy'; //是否复制
$code = empty($_REQUEST['extension_code']) ? '' : trim($_REQUEST['extension_code']);
if ($code == 'virual_card')
{
admin_priv('virualcard'); // 检查权限
}
else
{
admin_priv('goods_manage'); // 检查权限
}
if ($_REQUEST['act'] == 'edit'){
$smarty->assign('goods_ida', $_REQUEST['goods_id']);//自定义批量上传图片ID赋值
}
elseif ($_REQUEST['act'] == 'add' || $_REQUEST['act'] == 'copy'){
$sql = "show create table ".$ecs->table('goods'); //hj_reset_password 为表名
$query = mysql_query($sql);
$arr = mysql_fetch_array($query);
$b = strstr($arr[1],'AUTO_INCREMENT='); //获取子字符串,包含AUTO_INCREMENT=5 DEFAULT CHARSET=utf8 )
$result = intval(substr($b,15)); //substr()从字符串第16个位置获取字符串,再对获取后的字符串进行int类型转换
//echo 'AUTO_INCREMENT的值' .$result; //输出结果:即为下一次插入数据时的ID值
$smarty->assign('goods_ida', $result);//自定义批量上传图片ID赋值
}
/* 供货商名 */
$suppliers_list_name = suppliers_list_name();
$suppliers_exists = 1;
if (empty($suppliers_list_name))
{
$suppliers_exists = 0;
}
$smarty->assign('suppliers_exists', $suppliers_exists);
$smarty->assign('suppliers_list_name', $suppliers_list_name);
unset($suppliers_list_name, $suppliers_exists);
/* 如果是安全模式,检查目录是否存在 */
if (ini_get('safe_mode') == 1 && (!file_exists('../' . IMAGE_DIR . '/'.date('Ym')) || !is_dir('../' . IMAGE_DIR . '/'.date('Ym'))))
{
if (@!mkdir('../' . IMAGE_DIR . '/'.date('Ym'), 0777))
{
$warning = sprintf($_LANG['safe_mode_warning'], '../' . IMAGE_DIR . '/'.date('Ym'));
$smarty->assign('warning', $warning);
}
}
/* 如果目录存在但不可写,提示用户 */
elseif (file_exists('../' . IMAGE_DIR . '/'.date('Ym')) && file_mode_info('../' . IMAGE_DIR . '/'.date('Ym')) < 2)
{
$warning = sprintf($_LANG['not_writable_warning'], '../' . IMAGE_DIR . '/'.date('Ym'));
$smarty->assign('warning', $warning);
}
/* 取得商品信息 */
if ($is_add)
{
/* 默认值 */
$last_choose = array(0, 0);
if (!empty($_COOKIE['ECSCP']['last_choose']))
{
$last_choose = explode('|', $_COOKIE['ECSCP']['last_choose']);
}
$goods = array(
'goods_id'