<?php
require_once '../../library/config.php';
require_once '../library/functions.php';
require_once '../library/logged.php';
require_once '../../library/validation.php';

$sql_lang = mysql_query('SELECT `first_language` FROM `general_setting` WHERE `id` = 1');
$row_lang = mysql_fetch_assoc($sql_lang);

if ($row_lang['first_language'] == 1){
	//eng
	$subcat_name = 'subcat_name';
} elseif ($row_lang['first_language'] == 2){
	//tc
	$subcat_name = 'cp_subcat_name';
} elseif ($row_lang['first_language'] == 3){
	//sc
	$subcat_name = 'sp_subcat_name';
}

if($_POST['p_cat_id']){
	$p_cat_id = isNumber(trim($_POST['p_cat_id']));
	$id = isNumber(trim($_POST['p_id']));
	mysql_query("UPDATE `product_list` SET `p_cat_id` = '$p_cat_id' WHERE `p_id` = '$id'", $connePaper);
		
	$sql=mysql_query("select * from subcate WHERE match_cat_id =$p_cat_id");
	$row =  mysql_fetch_assoc($sql);
	if ($row){
		echo '<option value="NULL" selected>不需副分類</option>';
		do {
			echo '<option value="'.$row['subcat_id'].'">'.$row[$subcat_name].'</option>';
		} while ($row =  mysql_fetch_assoc($sql));
	} else {
		echo '<option>沒有副分類,請建立</option>';
	}
}

if($_POST['p_subcat_id']){
	$p_subcat_id = isNumber(trim($_POST['p_subcat_id']));
	$id = isNumber(trim($_POST['p_id']));
	mysql_query("UPDATE `product_list` SET `p_subcat_id` = '$p_subcat_id' WHERE `p_id` = '$id'", $connePaper);
}
mysql_close($connePaper);
?>
<b style="color:red;" id="this_info_<?php echo $id;?>">更新成功!!</b>
<script type="text/javascript">
	setTimeout(function(){$('#this_info_<?php echo $id;?>').fadeOut(500)}, 2000);
</script>