[phpBB Debug] PHP Warning: in file [ROOT]/includes/crs/crs_misc_functions.php on line 37: mime_content_type(): Empty filename or path Zen Cart 源代码 products_to_categories.php
<?php
/**
* @package admin
* @copyright Copyright 2003-2013 Zen Cart Development Team
* @copyright Portions Copyright 2003 osCommerce
* @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
* @version GIT: $Id: Author: Ian Wilson Thu Oct 24 21:13:46 2013 +0100 Modified in v1.5.2 $ */
// do not proceed unless categories are different
if ($copy_from_linked == $copy_to_linked) {
$messageStack->add_session(WARNING_DUPLICATE_PRODUCTS_TO_CATEGORY_LINKED, 'warning');
zen_redirect(zen_href_link(FILENAME_PRODUCTS_TO_CATEGORIES, 'products_filter=' . $products_filter . '¤t_category_id=' . $current_category_id));
}
$check_category_from = $db->Execute("select products_id from " . TABLE_PRODUCTS_TO_CATEGORIES . " where categories_id='" . $copy_from_linked . "' limit 1");
$check_category_to = $db->Execute("select products_id from " . TABLE_PRODUCTS_TO_CATEGORIES . " where categories_id='" . $copy_to_linked . "' limit 1");
// check if from is valid category
if ($check_category_from->RecordCount() < 1) {
$zv_invalid_copy_linked = 'true';
$zv_complete_message_linked .= WARNING_COPY_ALL_PRODUCTS_TO_CATEGORY_FROM_LINKED . $copy_from_linked . ' ';
} else {
$zv_complete_message_linked .= SUCCESS_COPY_ALL_PRODUCTS_TO_CATEGORY_FROM_LINKED . $copy_from_linked . ' ';
}
// check if to is valid category
if ($check_category_to->RecordCount() < 1) {
if (zen_childs_in_category_count($copy_to_linked) > 0) {
$zv_invalid_copy_linked = 'true';
$zv_complete_message_linked .= WARNING_COPY_ALL_PRODUCTS_TO_CATEGORY_TO_LINKED . $copy_to_linked . ' ';
}
$zv_complete_message_linked .= WARNING_COPY_ALL_PRODUCTS_TO_CATEGORY_TO_LINKED_MISSING . $copy_to_linked . ' ';
} else {
$zv_complete_message_linked .= SUCCESS_COPY_ALL_PRODUCTS_TO_CATEGORY_TO_LINKED . $copy_to_linked . ' ';
}
///////////////////////////////////////////////////////////////
// if either category was invalid nothing processes below
///////////////////////////////////////////////////////////////
// get products to be linked from
$products_to_categories_from_linked = $db->Execute("select products_id from " . TABLE_PRODUCTS_TO_CATEGORIES . " where categories_id='" . $copy_from_linked . "'");
while (!$products_to_categories_from_linked->EOF) {
$add_links_array[] = array('products_id' => $products_to_categories_from_linked->fields['products_id']);
$products_to_categories_from_linked->MoveNext();
}
// get products already in category to be linked to
$products_to_categories_to_linked = $db->Execute("select products_id from " . TABLE_PRODUCTS_TO_CATEGORIES . " where categories_id='" . $copy_to_linked . "'");
while (!$products_to_categories_to_linked->EOF) {
$remove_links_array[] = array('products_id' => $products_to_categories_to_linked->fields['products_id']);
$products_to_categories_to_linked->MoveNext();
}
// cannot count added/removed due to the nature of the how these are done
// $cnt_added = 0;
// remove elements in $remove_links_array that are in $add_links_array
for ($i=0, $n=sizeof($add_links_array); $i<$n; $i++) {
$good = 'true';
for ($j=0, $nn=sizeof($remove_links_array); $j<$nn; $j++) {
if ($add_links_array[$i]['products_id'] == $remove_links_array[$j]['products_id']) {
$good = 'false';
break;
}
}
// build final of good products
if ($good == 'true') {
$make_links_result[] = array('products_id' => $add_links_array[$i]['products_id']);
}
}
// do not proceed unless categories are different
if ($remove_from_linked == $remove_to_linked) {
$messageStack->add_session(WARNING_DUPLICATE_PRODUCTS_TO_CATEGORY_LINKED, 'warning');
zen_redirect(zen_href_link(FILENAME_PRODUCTS_TO_CATEGORIES, 'products_filter=' . $products_filter . '¤t_category_id=' . $current_category_id));
}
$check_category_from = $db->Execute("select products_id from " . TABLE_PRODUCTS_TO_CATEGORIES . " where categories_id='" . $remove_from_linked . "' limit 1");
$check_category_to = $db->Execute("select products_id from " . TABLE_PRODUCTS_TO_CATEGORIES . " where categories_id='" . $remove_to_linked . "' limit 1");
// check if from is valid category
if ($check_category_from->RecordCount() < 1) {
$zv_invalid_remove_linked = 'true';
$zv_complete_message_linked .= WARNING_REMOVE_ALL_PRODUCTS_TO_CATEGORY_FROM_LINKED . $remove_from_linked . ' ';
} else {
$zv_complete_message_linked .= SUCCESS_REMOVE_ALL_PRODUCTS_TO_CATEGORY_FROM_LINKED . $remove_from_linked . ' ';
}
// check if to is valid category
if ($check_category_to->RecordCount() < 1) {
$zv_invalid_remove_linked = 'true';
$zv_complete_message_linked .= WARNING_REMOVE_ALL_PRODUCTS_TO_CATEGORY_TO_LINKED . $remove_to_linked . ' ';
} else {
$zv_complete_message_linked .= SUCCESS_REMOVE_ALL_PRODUCTS_TO_CATEGORY_TO_LINKED . $remove_to_linked . ' ';
}
///////////////////////////////////////////////////////////////
// if either category was invalid nothing processes below
///////////////////////////////////////////////////////////////
// get products to be removed as added linked from
$products_to_categories_from_linked = $db->Execute("select ptoc.products_id, p.master_categories_id from " . TABLE_PRODUCTS_TO_CATEGORIES . " ptoc left join " . TABLE_PRODUCTS . " p on ptoc.products_id=p.products_id where ptoc.categories_id='" . $remove_from_linked . "'");
while (!$products_to_categories_from_linked->EOF) {
if ($products_to_categories_from_linked->fields['master_categories_id'] == $remove_to_linked) {
//die('THIS IS THE MASTER CATEGORIES ID!! ' . $remove_to_linked . '<br>');
//break;
$master_categories_id_stop[] = array('products_id' => $products_to_categories_from_linked->fields['products_id'],
'master_categories_id' => $products_to_categories_from_linked->fields['master_categories_id']);
}
$add_links_array[] = array('products_id' => $products_to_categories_from_linked->fields['products_id'],
'master_categories_id' => $products_to_categories_from_linked->fields['master_categories_id']);
$products_to_categories_from_linked->MoveNext();
}
// get products already in category to be removed as linked to
$products_to_categories_to_linked = $db->Execute("select products_id from " . TABLE_PRODUCTS_TO_CATEGORIES . " where categories_id='" . $remove_to_linked . "'");
while (!$products_to_categories_to_linked->EOF) {
$remove_links_array[] = array('products_id' => $products_to_categories_to_linked->fields['products_id']);
$products_to_categories_to_linked->MoveNext();
}
// $cnt_removed = 0;
// remove elements in $remove_links_array that are in $add_links_array
for ($i=0, $n=sizeof($add_links_array); $i<$n; $i++) {
$good = 'true';
for ($j=0, $nn=sizeof($remove_links_array); $j<$nn; $j++) {
if ($add_links_array[$i]['products_id'] == $remove_links_array[$j]['products_id']) {
$good = 'true';
break;
}
}
// build final of good products
if ($good == 'true') {
$make_links_result[] = array('products_id' => $add_links_array[$i]['products_id']);
}
}
for ($i=0, $n=sizeof($make_links_result); $i<$n; $i++) {
// $cnt_removed++;
$remove_product = $make_links_result[$i]['products_id'];
$sql = "delete from " . TABLE_PRODUCTS_TO_CATEGORIES . " where products_id='" . $remove_product . "' and categories_id='" . $remove_to_linked . "'";
$db->Execute($sql);
}
///////////////////////////////////////////////////////////////
// if either category was invalid nothing processes below
///////////////////////////////////////////////////////////////
$reset_master_categories_id = $db->Execute("select p.products_id, p.master_categories_id, ptoc.categories_id from " . TABLE_PRODUCTS . " p left join " . TABLE_PRODUCTS_TO_CATEGORIES . " ptoc on ptoc.products_id= p.products_id and ptoc.categories_id='" . $reset_from_master . "' where ptoc.categories_id='" . $reset_from_master . "'");
while (!$reset_master_categories_id->EOF) {
$db->Execute("update " . TABLE_PRODUCTS . " set master_categories_id='" . (int)$reset_from_master . "' where products_id='" . $reset_master_categories_id->fields['products_id'] . "'");
// reset products_price_sorter for searches etc.
zen_update_products_price_sorter($reset_master_categories_id->fields['products_id']);
$reset_master_categories_id->MoveNext();
}
// set the linked products master_categories_id product(s)
for ($i=0, $n=sizeof($_POST['categories_add']); $i<$n; $i++) {
// is current master_categories_id in the list?
if ($zv_check_master_categories_id == 'true' and $_POST['categories_add'][$i] == $current_master_categories_id->fields['master_categories_id']) {
$zv_check_master_categories_id = 'true';
// array is set above to master category
} else {
$new_categories_sort_array[] = (int)$_POST['categories_add'][$i];
}
}
// remove existing products_to_categories for current product
$db->Execute("delete from " . TABLE_PRODUCTS_TO_CATEGORIES . " where products_id='" . $products_filter . "'");
$reset_master_categories_id = '';
$old_master_categories_id = $current_master_categories_id;
// add products to categories in order of master_categories_id first then others
$verify_current_category_id = false;
for ($i=0, $n=sizeof($new_categories_sort_array); $i<$n; $i++) {
// is current master_categories_id in the list?
if ($new_categories_sort_array[$i] <= 0) {
die('I WOULD NOT ADD ' . $new_categories_sort_array[$i] . '<br>');
} else {
if ($current_category_id == $new_categories_sort_array[$i]) {
$verify_current_category_id = true;
}
$db->Execute("insert into " . TABLE_PRODUCTS_TO_CATEGORIES . "
(products_id, categories_id)
values (" . $products_filter . ", " . (int)$new_categories_sort_array[$i] . ")");
if ($reset_master_categories_id == '') {
$reset_master_categories_id = $new_categories_sort_array[$i];
}
if ($old_master_categories_id == $new_categories_sort_array[$i]) {
$reset_master_categories_id = $new_categories_sort_array[$i];
}
}
}
// reset master_categories_id in products table
if ($zv_check_master_categories_id == 'true') {
// make sure master_categories_id is set to current master_categories_id
$db->Execute("update " . TABLE_PRODUCTS . " set master_categories_id='" . (int)$current_master_categories_id . "' where products_id='" . $products_filter . "'");
} else {
// reset master_categories_id to current_category_id because it was unselected
$db->Execute("update " . TABLE_PRODUCTS . " set master_categories_id='" . (int)$reset_master_categories_id . "' where products_id='" . $products_filter . "'");
}
// recalculate price based on new master_categories_id
zen_update_products_price_sorter($products_filter);
// if product was removed from current categories_id stay in same category
if (!$verify_current_category_id) {
zen_redirect(zen_href_link(FILENAME_PRODUCTS_TO_CATEGORIES, 'current_category_id=' . $current_category_id));
} else {
zen_redirect(zen_href_link(FILENAME_PRODUCTS_TO_CATEGORIES, 'products_filter=' . $products_filter . '¤t_category_id=' . $current_category_id));
}
break;