query($sql); $product_id = $nexusdb->insert_id; return $product_id; } function nexus_product_update($product_id, $update_arr) { global $nexus_cfg, $nexusdb; $update_clause = ""; reset($update_arr); while (list($key, $val) = each($update_arr)) { $update_clause .= (($update_clause=="")?"":", ") . sprintf("`%s` = '%s' ", mysql_real_escape_string(trim($key)), mysql_real_escape_string(trim($val))); } $sql = "UPDATE `%s` SET %s, `last_modified` = NOW() WHERE `product_id` = %d "; $sql = sprintf($sql, $nexus_cfg["table"]["product"], $update_clause, $product_id); $num_rows_affected = $nexusdb->query($sql); return $num_rows_affected; } function nexus_product_delete($product_id) { global $nexus_cfg, $nexusdb; $product_row = nexus_product_get_row($product_id); // delete files if (trim($product_row->im_zh) != "") { @unlink($_SERVER["DOCUMENT_ROOT"] . $product_row->im_zh); } if (trim($product_row->im_cn) != "") { @unlink($_SERVER["DOCUMENT_ROOT"] . $product_row->im_cn); } if (trim($product_row->im_en) != "") { @unlink($_SERVER["DOCUMENT_ROOT"] . $product_row->im_en); } $product_dir = sprintf($nexus_cfg["path"]["uploaded_product"]."/", ($product_id % 10), $product_id); if (is_dir($product_dir)) { @unlink($product_dir); } // delete db record $sql = "DELETE FROM `%s` WHERE `product_id` = %d "; $sql = sprintf($sql, $nexus_cfg["table"]["product"], $product_id); $nexusdb->query($sql); // delete the photos nexus_product_photo_delete_by_product($product_id); // delete the category relation nexus_product_properties_category_save_relation($product_id, array()); // delete the vip relation nexus_product_properties_vip_save_relation($product_id, array()); // delete the eshop relation nexus_product_properties_eshop_save_relation($product_id, array()); return; } function nexus_product_get_row($id) { global $nexus_cfg, $nexusdb; settype($id, "integer"); if ($id < 1) { return false; } $sql = "SELECT * FROM `%s` WHERE `product_id` = %d "; $sql = sprintf($sql, $nexus_cfg["table"]["product"], mysql_real_escape_string(trim($id))); $products = $nexusdb->get_results($sql); if (count($products) < 1) { return false; } return $products[0]; } function nexus_product_get_list($search_info, &$total, &$result, $order_clause, $page=0, $page_size=0) { global $nexus_cfg, $nexusdb; $total = 0; $result = array(); $where_clause = ""; if (is_array($search_info) && count($search_info) > 0) { if (isset($search_info["keyword"])) { $keyword = mysql_real_escape_string(trim($search_info["keyword"])); if ($keyword != "") { $where_clause .= sprintf(" (`title_zh` LIKE '%%%s%%' OR `title_en` LIKE '%%%s%%' OR `title_cn` LIKE '%%%s%%' ) ", $keyword, $keyword, $keyword); } unset($search_info["keyword"]); } reset($search_info); while (list($key, $val) = each($search_info)) { $where_clause .= (($where_clause=="")?"":" AND ") . sprintf("`%s` = '%s' ", mysql_real_escape_string(trim($key)), mysql_real_escape_string(trim($val))) ; } } if ($where_clause != "") { $where_clause = sprintf("WHERE %s", $where_clause); } $sql = "SELECT COUNT(*) AS total FROM `%s` %s"; $sql = sprintf($sql, $nexus_cfg["table"]["product"], $where_clause); $product_total = $nexusdb->get_results($sql); if (count($product_total) < 1) { return false; } $product_total_row = $product_total[0]; $total = $product_total_row->total; if ($order_clause == "") { $order_clause = "ORDER BY order_id ASC, create_time DESC "; } $limit_clause = ""; if ($page_size > 0) { $offset = ($page - 1) * $page_size; $limit_clause = sprintf("LIMIT %d, %d", $offset, $page_size); } $sql = "SELECT * FROM `%s` %s %s %s"; $sql = sprintf($sql, $nexus_cfg["table"]["product"], $where_clause, $order_clause, $limit_clause); $result = $nexusdb->get_results($sql); } function nexus_product_upload_file($product_id, $file_type, $file_info, $existing_file='') { global $nexus_cfg, $_SERVER; $upload_path = ''; if (file_exists($file_info['tmp_name'])) { if ($existing_file != "") { $uploaded_upload_path = $_SERVER['DOCUMENT_ROOT'] . $existing_file; if (file_exists($uploaded_upload_path)) { unlink($uploaded_upload_path); } } $target_path = sprintf($nexus_cfg["path"]["uploaded_product"]."/", ($product_id%10), $product_id); $new_file_path = $target_path . basename($file_info['name']); // check directory if (!is_dir($target_path)) { mkdir($target_path); } $new_file_info = pathinfo(basename($file_info["name"])); while (file_exists($new_file_path)) { $new_file_path = sprintf("%s%s_%s.%s", $target_path, $file_type, unique(), $new_file_info["extension"]); } if (move_uploaded_file($file_info['tmp_name'], $new_file_path)) { $upload_path = str_replace($_SERVER['DOCUMENT_ROOT'], '', $new_file_path); } } return $upload_path; } ?>