products.php
来自「全新且完善的强大网上商店系统」· PHP 代码 · 共 504 行 · 第 1/2 页
PHP
504 行
<?php
/*
[SOOBIC!] admin/products.php
Version: 1.5
Author: Soolan (soolan@qq.com)
Copyright: soolan (www.soobic.com)
Last Modified: 2005/4/16 10:00
*/
if(!defined('IN_SOOBIC')) {
exit('Access Denied');
}
cpheader();
include ($soobic."./admin/languages/".$language."/categories.php");
if(!$allowsetproduct){
cpmsg("对不起,您的管理权限受限,不能进行此操作。");
}
//echo "<pre>";print_r($HTTP_POST_VARS);
//$action = (isset($HTTP_GET_VARS['action']) ? $HTTP_GET_VARS['action'] : (isset($HTTP_POST_VARS['action']) ? $HTTP_POST_VARS['action'] : ''));
if ($action) {
switch($action){
case 'setflag':
if ( ($HTTP_GET_VARS['flag'] == '0') || ($HTTP_GET_VARS['flag'] == '1') ) {
if (isset($HTTP_GET_VARS['pID'])) {
if ($HTTP_GET_VARS['flag'] == '1') {
$db->query("update $table_products set products_status = '1', products_last_modified = now() where products_id = '" . (int)$HTTP_GET_VARS['pID']. "'");
} elseif ($HTTP_GET_VARS['flag'] == '0') {
$db->query("update $table_products set products_status = '0', products_last_modified = now() where products_id = '" . (int)$HTTP_GET_VARS['pID']. "'");
}
}
}
tep_redirect(tep_href_link('admincp.php', 'act=catalog&cPath=' . $HTTP_GET_VARS['cPath'] . '&pID=' . $HTTP_GET_VARS['pID']));
break;
case 'new_product':
case 'edit_product':
if (isset($HTTP_POST_VARS['edit_x']) || isset($HTTP_POST_VARS['edit_y'])) {
$action = 'new_product';
} else {
if (tep_not_null($pID)) $products_id = $pID;
$products_date_available = (date('Y-m-d',time()) < $products_date_available) ? $products_date_available : 'null';
if ($action == 'new_product') {
$sql_data_array = array(
'products_quantity' => $products_quantity,
'products_price' => $products_price,
'products_date_available' => $products_date_available,
'products_weight' => $products_weight,
'products_status' => $products_status,
'products_tax_class_id' => $products_tax_class_id,
'manufacturers_id' => $manufacturers_id,
'products_date_added' => $timestamp,
//'categories_id' => (int)$current_category_id,
'products_model' => $products_products_model);
tep_db_perform($table_products, $sql_data_array);
$products_id = $db->insert_id();
$db->query("insert into $table_products_to_categories (products_id, categories_id) values ('" . (int)$products_id . "', '" . (int)$current_category_id . "')");
} elseif ($action == 'edit_product') {
$db->query("update $table_products
set products_quantity='$products_quantity',
products_model='$products_model',
products_price='$products_price',
products_date_available='".$products_date_available."',
products_weight='$products_weight',
products_status='$products_status',
products_tax_class_id='$products_tax_class_id',
manufacturers_id='$manufacturers_id',
products_last_modified='".$timestamp."'
where products_id = '" . (int)$products_id . "'");
}
$products_image = new upload('products_image',$soobic.'./upload/images/products');
if ($products_image->parse($timestamp)) {
$product_image_query = $db->query("select products_image from $table_products where products_id = '" . (int)$products_id . "'");
$product_image = $db->fetch_array($product_image_query);
if (file_exists($soobic.'./upload/images/products/'. $product_image['products_image'])) {
if($action=='edit_product'){
$product_image_num_query = $db->query("select count(*) from $table_products where products_image='".$product_image['products_image']."' and products_id != '" . (int)$products_id . "'");
$product_image_num = $db->result($product_image_num_query,0);
if($product_image_num==0){
@unlink($soobic.'./upload/images/products/'. $product_image['products_image']);
if(!file_exists($soobic.'./upload/images/products/small_'. $product_image['products_image'])){
$src=eregi_replace(strrchr($soobic.'./upload/images/products/small_'. $product_image['products_image'],'.'),'.jpg',$soobic.'./upload/images/products/small_'. $product_image['products_image']);
@unlink($src);
}
@unlink($soobic.'./upload/images/products/small_'. $product_image['products_image']);
}
}
}
$products_image->save(SMALL_IMAGE_WIDTH,SMALL_IMAGE_HEIGHT);
$db->query("update $table_products set products_image = '" . safe_input($products_image->filename) . "' where products_id = '" . (int)$products_id . "'");
}
$languages = tep_get_languages();
for ($i=0, $n=sizeof($languages); $i<$n; $i++) {
$language_id = $languages[$i]['id'];
$sql_data_array = array('products_name' => $products_name[$language_id],
'products_description' => $products_description[$language_id],
'products_url' => $products_url[$language_id]);
if ($action == 'new_product') {
$insert_sql_data = array('products_id' => $products_id,
'language_id' => $language_id);
$sql_data_array = array_merge($sql_data_array, $insert_sql_data);
tep_db_perform($table_products_description, $sql_data_array);
} elseif ($action == 'edit_product') {
$db->query("update $table_products_description
set products_name='$products_name[$language_id]',
products_description='".safe_input($products_description[$language_id])."',
products_url='$products_url[$language_id]'
where products_id = '" . (int)$products_id . "' and language_id = '" . (int)$language_id . "'");
}
}
}
cpmsg("Lansen! 商品操作成功。",tep_href_link('admincp.php','act=catalog&cPath='.$cPath.'pID='.$products_id));
break;
case 'copy':
if (isset($products_id) && isset($categories_id)) {
if ($HTTP_POST_VARS['copy_as'] == 'link') {
if ($categories_id != $current_category_id) {
//echo $table_products_to_cagegories;exit;
$check_query = $db->query("select count(*) as total from $table_products_to_categories where products_id = '" . (int)$products_id . "' and categories_id = '" . (int)$categories_id . "'");
$check = $db->fetch_array($check_query);
if ($check['total'] < '1') {
$db->query("insert into $table_products_to_categories (products_id, categories_id) values ('" . (int)$products_id . "', '" . (int)$categories_id . "')");
}
} else {
$messageStack->add_session('category',ERROR_CANNOT_LINK_TO_SAME_CATEGORY);
}
} elseif ($HTTP_POST_VARS['copy_as'] == 'duplicate') {
$product_query = $db->query("select products_quantity, products_model, products_image, products_price, products_date_available, products_weight, products_tax_class_id, manufacturers_id from $table_products where products_id = '" . (int)$products_id . "'");
$product = $db->fetch_array($product_query);
$db->query("insert into $table_products (products_quantity, products_model,products_image, products_price, products_date_added, products_date_available, products_weight, products_status, products_tax_class_id, manufacturers_id) values ('" . ($product['products_quantity']) . "', '" . ($product['products_model']) . "', '" . ($product['products_image']) . "', '" . ($product['products_price']) . "', now(), '" . ($product['products_date_available']) . "', '" . ($product['products_weight']) . "', '0', '" . (int)$product['products_tax_class_id'] . "', '" . (int)$product['manufacturers_id'] . "')");
$dup_products_id = $db->insert_id();
$description_query = $db->query("select language_id, products_name, products_description, products_url from $table_products_description where products_id = '" . (int)$products_id . "'");
while ($description = $db->fetch_array($description_query)) {
$db->query("insert into $table_products_description (products_id, language_id, products_name, products_description, products_url, products_viewed) values ('" . (int)$dup_products_id . "', '" . (int)$description['language_id'] . "', '" . ($description['products_name']) . "', '" . ($description['products_description']) . "', '" . ($description['products_url']) . "', '0')");
}
$db->query("insert into $table_products_to_categories (products_id, categories_id) values ('" . (int)$dup_products_id . "', '" . (int)$categories_id . "')");
$products_id = $dup_products_id;
}
}
tep_redirect(tep_href_link('admincp.php', 'act=catalog&cPath=' . $categories_id . '&pID=' . $products_id));
break;
case 'delete_product':
$product_id = $products_id;
if (isset($products_id) && isset($product_categories) && is_array($product_categories)) {
for ($i=0, $n=sizeof($product_categories); $i<$n; $i++) {
$db->query("delete from $table_products_to_categories where products_id = '" . (int)$product_id . "' and categories_id = '" . (int)$product_categories[$i] . "'");
}
$product_categories_query = $db->query("select count(*) as total from $table_products_to_categories where products_id = '" . (int)$product_id . "'");
$product_categories = $db->fetch_array($product_categories_query);
if ($product_categories['total'] == '0') {
tep_remove_product($product_id);
}
}
cpmsg("Lansen! 商品删除成功。",tep_href_link('admincp.php','act=catalog&cPath='.$cPath.'&cID='.$categories_id));
break;
case 'move_product':
$products_id = ($pID);
$new_parent_id = ($move_to_category_id);
$duplicate_check_query = $db->query("select count(*) as total from $table_products_to_categories where products_id = '" . (int)$products_id . "' and categories_id = '" . (int)$new_parent_id . "'");
$duplicate_check = $db->fetch_array($duplicate_check_query);
if ($duplicate_check['total'] < 1) $db->query("update $table_products_to_categories set categories_id = '" . (int)$new_parent_id . "' where products_id = '" . (int)$products_id . "' and categories_id = '" . (int)$current_category_id . "'");
tep_redirect(tep_href_link('admincp.php', 'act=catalog&cPath=' . $new_parent_id . '&pID=' . $products_id));
break;
default:
}
}elseif($type){
switch($type){
case 'copy_product':
$product_query = $db->query("select pd.products_name, p.products_id, p.categories_id from $table_products p left join $table_categories c on c.categories_id=p.categories_id, $table_products_description pd where p.products_id = '" . (int)$HTTP_GET_VARS['pID'] . "' and p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "'");
$product = $db->fetch_array($product_query);
@extract($product);
?>
<form method="post" name="copy_to" action="<?=tep_href_link('admincp.php','act=products&action=copy&cPath='.$cPath)?>">
<?=tep_draw_hidden_field('products_id', $products_id)?>
<table border="0" cellspacing="<?=BORDERWIDTH?>" cellpadding="<?=TABLESPACE?>" width="<?=TABLEWIDTH?>" class="tableout" align="center">
<tr class="header"><td colspan="2"><?=TEXT_INFO_COPY_TO_INTRO?></td></tr>
<tr bgcolor="<?=ALTBG1?>"><td><?=TEXT_INFO_CURRENT_CATEGORIES?></td><td><b><?=tep_output_generated_category_path($products_id, 'product')?></b></td></tr>
<tr bgcolor="<?=ALTBG1?>"><td><?=TEXT_CATEGORIES?></td><td><?=tep_draw_pull_down_menu('categories_id', tep_get_category_tree(), $current_category_id)?></b></td></tr>
<tr bgcolor="<?=ALTBG1?>"><td><?=TEXT_HOW_TO_COPY?></td><td><?=tep_draw_radio_field('copy_as', 'link', true)?><?=TEXT_COPY_AS_LINK?><?=tep_draw_radio_field('copy_as', 'duplicate')?><?=TEXT_COPY_AS_DUPLICATE?>
</td></tr></table>
<br><center><?=tep_image_submit('button_copy.gif', IMAGE_COPY)?> <a href="<?=tep_href_link('admincp.php', 'act=catalog&cPath=' . $cPath . '&pID=' . $products_id)?>"><?=tep_image_button('button_cancel.gif', IMAGE_CANCEL)?></a></center>
</form>
<br>
<?
break;
case 'new_product':
$parameters = array('products_name' => '',
'products_description' => '',
'products_url' => '',
'products_id' => '',
'products_quantity' => '',
'products_model' => '',
'products_image' => '',
'products_price' => '',
'products_weight' => '',
'products_date_added' => '',
'products_last_modified' => '',
'products_date_available' => '',
'products_status' => '',
'products_tax_class_id' => '',
'manufacturers_id' => '');
@extract($parameters);
if (isset($HTTP_GET_VARS['pID'])) {
$product_query = $db->query("select pd.products_name, pd.products_description, pd.products_url, p.products_id, p.products_quantity, p.products_model, p.products_image, p.products_price, p.products_weight, p.products_date_added, p.products_last_modified, date_format(p.products_date_available, '%Y-%m-%d') as products_date_available, p.products_status, p.products_tax_class_id, p.manufacturers_id from $table_products p, $table_products_description pd where p.products_id = '" . (int)$HTTP_GET_VARS['pID'] . "' and p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "'");
$product = $db->fetch_array($product_query);
@extract($product);
}
//$product_query = $db->query("select categories_name from $table_products p, $table_products_description pd where p.products_id = '" . (int)$HTTP_GET_VARS['pID'] . "' and p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "'");
//$product = $db->fetch_array($product_query);
$manufacturers_array = array(array('id' => '', 'text' => TEXT_NONE));
$manufacturers_query = $db->query("select manufacturers_id, manufacturers_name from $table_manufacturers order by manufacturers_name");
while ($manufacturers = $db->fetch_array($manufacturers_query)) {
$manufacturers_array[] = array('id' => $manufacturers['manufacturers_id'],
'text' => $manufacturers['manufacturers_name']);
}
$tax_class_array = array(array('id' => '0', 'text' => TEXT_NONE));
$tax_class_query = $db->query("select tax_class_id, tax_class_title from $table_tax_class order by tax_class_title");
while ($tax_class = $db->fetch_array($tax_class_query)) {
$tax_class_array[] = array('id' => $tax_class['tax_class_id'],
'text' => $tax_class['tax_class_title']);
}
$languages = tep_get_languages();
if (!isset($pInfo_products_status)) $pInfo_products_status = '1';
switch ($pInfo_products_status) {
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?