<?php 
require("global.php");
require("./inc/functions_sort.php");

if ($action == 'updatecategoriesid') {

		if ($cbdelete==1)
		{
				foreach($cat as $products_id=>$categories_id) {
					$id_in=check_ids($updatecheck,$products_id);
					if ($id_in==1){
						$DB->query("delete from products_to_categories  WHERE products_id = '" .intval($products_id). "' ");	
						$DB->query("delete from products_description  WHERE products_id = '" .intval($products_id). "' ");	
						$DB->query("delete from products  WHERE products_id = '" .intval($products_id). "' ");	
					}
				}
				redirect("删除完成!", "cat.php?action=$actact&page=$page");
		}
		else
		{	
				foreach($cat as $products_id=>$categories_id) {
					$id_in=check_ids($updatecheck,$products_id);
					if ($id_in==1){
						$DB->query("update products_to_categories SET categories_id = '" .intval($categories_id). "' WHERE products_id = '" .intval($products_id). "' limit 1");	
					}
				}
				redirect("更新完成!", "cat.php?action=$actact&page=$page");
		}

}
else
{
	
echo "<!doctype html public \"-//W3C//DTD HTML 4.01 Transitional//EN\">";
echo "<html ".HTML_PARAMS.">";
echo "<head>";
echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=".CHARSET."\">";
echo "<title>".TITLE."</title>";
echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"../includes/stylesheet.css\">";
echo "<script language=\"javascript\" src=\"includes/general.js\"></script>";
echo "</head>";
echo "<body marginwidth=\"0\" marginheight=\"0\" topmargin=\"0\" bottommargin=\"0\" leftmargin=\"0\" rightmargin=\"0\" bgcolor=\"#FFFFFF\" onload=\"SetFocus();\">";
echo "<div id=\"spiffycalendar\" class=\"text\"></div>";
require(DIR_FS_ADMIN.'inlcudes/header.php');
//<!-- header_eof //-->

//<!-- body //-->
	tableheader();
	$cpforms->formheader(array("title" => "全部产品",
							   "name"  => "products"));	
	$cpforms->maketd(array("产品名", "分类", "复制","产品"));
	

	$sql = "SELECT p.products_id, pd.products_name,p.code FROM products p LEFT JOIN products_description pd ON p.products_id = pd.products_id WHERE pd.language_id = 4 ORDER BY p.products_id";
	$split_page = new split_page($sql, $page, "cat.php?action=products_all", 18);

	$result = $DB->query($split_page->query);
	while ($p = $DB->fetch_array($result)) {
		//$selectid = $p['categories_id'];
		//get categories id;
		$categories_id=0;
		$cat_sql= "select * from products_to_categories where products_id = '" .(int)$p['products_id']. "'";
		$cat_result = $DB->query($cat_sql);	
		while ($cc = $DB->fetch_array($cat_result)) {
				 $categories_id =  $cc['categories_id'];
		}

//		echo "cccccid=====".$categories_id;
		$sort_string = "";
		$sort_string = get_sort_select_c($categories_id,0,1);
//		$sort_string = get_sort_select();
		$select_string = "<select name=\"cat[$p[products_id]]\">";
		$select_string .= "<option value=\"0\">根分类</option>\n";
		$select_string .= $sort_string;
		$select_string .= "</select>";
		$cpforms->maketd(array("<input type='checkbox' name='updatecheck[]' value='".$p['products_id']."'  checked>  "."(".$p['code'].")".$p['products_name'], $select_string, "<a href=\"cat.php?action=copycat&products_id=$p[products_id]\"><font color=\"#000000\">复制</font></a>","<a href=\"deleteproduct.php?products_id=$p[products_id]&productcode=$p[code]&action=$action&page=$page\"> <img hspace=\"2\" width=\"16\" height=\"16\" src=\"./images/b_drop.png\" alt=\"删除\" title=\"删除\" border=\"0\" ></a>"));
	}
	$cpforms->page_info(array("total_record"  => $split_page->total_record,
							  "page_view_num" => $split_page->page_view_num,
							  "multi_page"    => $split_page->multi_page));

	$cpforms->makehidden(array("name"  => "action",
							   "value" => "updatecategoriesid"));

	$cpforms->formfooter();

	tablefooter();
//<!-- body_eof //-->

//<!-- footer //-->
require('../inlcudes/footer.php');
//<!-- footer_eof //-->
echo "<br>";
echo "</body>";
echo "</html>";
require('../inlcudes/application_bottom.php');

}
cpfooter();
?>