Your IP : 216.73.216.34


Current Path : /home/zqegovsj/www/us3.supplierlist.com/member/master/
Upload File :
Current File : /home/zqegovsj/www/us3.supplierlist.com/member/master/productedit.php

<?php 
$inc_path = "../../haibo/en/";$ua_sm_compile_dir = "newmember/";
require($inc_path."global.php");
require("session.php");$tb_prefix= $_SESSION['Version']."_";
//ini_set('display_errors','On');
//error_reporting(E_ALL);
if($_SESSION['Version']=="en")setvar("imgpath", "../../upload/".$_SESSION['MemberName']."/");else setvar("imgpath", "../../".$_SESSION['Version']."/upload/".$_SESSION['MemberName']."/");
uaCheckPermission(2);
//新加库存
$kucun=array('code'=>0,'data'=>array());
if($_GET['kucun_list']){
	$sql="select a.*,b.name as size,c.name as color from ".$_SESSION['Version']."_sku as a left join ".$_SESSION['Version']."_sizes as b on a.sku_size_id =b.id left join ".$_SESSION['Version']."_colors as c on a.sku_color_id =c.id where a.sku_prod_id=".$_POST['pid'];
	$res= $g_db->GetAll($sql);
	$kucun['data']=$res;
	echo json_encode($kucun);die;
}elseif($_GET['kucun_add']){
	$size=explode(',',$_POST['size']);
	$color=explode(',',$_POST['color']);
	foreach($size as $k=>$v){
		foreach($color as $m=>$n){
			$sql="select * from `".$_SESSION['Version']."_sku` where sku_prod_id=".$_POST['pid']." and sku_size_id='".$v."' and sku_color_id='".$n."'";
			$res= $g_db->GetAll($sql);
			if($res)continue;
			$sql="INSERT INTO `".$_SESSION['Version']."_sku` (
				`id` ,
				`member_id` ,
				`sku_prod_id` ,
				`sku_size_id`,
				`sku_color_id`,
				`sku_qty`,
				`update` 
				)
				VALUES (
				NULL , '".$_SESSION['MemberID']."', '".$_POST['pid']."','".$v."','".$n."','".$_POST['qty']."',now()
				)";
			$g_db->Query($sql);
		}
	}
	echo json_encode($kucun);die;
}elseif($_GET['kucun_edit']){
	$sql="update `".$_SESSION['Version']."_sku` set sku_qty=".$_POST['qty']." where id=".$_POST['id'];
	$g_db->Query($sql);
	echo json_encode($kucun);die;
}elseif($_GET['kucun_del']){
	$sql="delete from `".$_SESSION['Version']."_sku` where id=".$_POST['id'];
	$g_db->Query($sql);
	echo json_encode($kucun);die;
}



$sql="select firstname from members where id=".$_SESSION['MemberID'];
	$res= $g_db->GetAll($sql);
if(strstr($res[0][0],'shop')!=''){setvar("checked",2);}
uses("trade","member","producttype","product","industry","setting","company");
$setting = new Settings();
$company = new Companies();
$industry = new Industries();
$member = new Members();
$product = new Products();
$producttype = new Producttypes();
$trade = new Trades();
$tpl_file = "product_edit";
$conditions = "  member_id=".$_SESSION['MemberID'];
$company_id = $company->field("id", "member_id=".$_SESSION['MemberID']);
$conditions.=" and level=0";

	$ts = $producttype->findAll($producttype->common_cols,$conditions," cpt_range asc");

	 $count1=$producttype->findAll('count(*)',"1=1"," id DESC");
        $count2=$producttype->findAll('count(*)',$conditions," id DESC");

for($i=0;$i<$count2[0][0];$i++)
{ 

    $a[$i]= $producttype->findAll($producttype->common_cols,"level='".$ts[$i][0]."'"," cpt_range asc");  
	
	 $ct=$producttype->findAll('count(*)',"level='".$ts[$i][0]."'"," id asc");
  if($i==0){$typeres[0]=$ts[0];
	 for($j=0;$j<$ct[0][0];$j++){
		
		$typeres[$j+1]=$a[$i][$j];
		 }if($ts[1]!=''){$typeres[$ct[0][0]+1]=$ts[1];$x=$ct[0][0]+1;}
	 }else{
		 for($j=0;$j<$ct[0][0];$j++){
		$typeres[$x+1+$j]=$a[$i][$j];
		 }
		  $x+=$ct[0][0]+1;
		  if($x==$count1[0][0])break;
	if($ts[$i+1]!='')$typeres[$x]=$ts[$i+1];
		 }
}
foreach($typeres as $k=>$v){
	if($v['Level']){
		$typeres[$k]['child']=array();
		$res=$producttype->findAll($producttype->common_cols,"member_id = ".$_SESSION['MemberID']." and level='".$v['ID']."'","`cpt_range` ASC 
",0,500); 
		if(count($res)){
			$typeres[$k]['child']=$res;
		}

	}
}
$list = $typeres;
if(count($typeres)==0){flash("./tip.php","./producttype.php","Please add a category");
	
	}
$conditions = " and member_id=".$_SESSION['MemberID'];
$data=array();
$sql="select * from ".$_SESSION['Version']."_sizes where member_id=".$_SESSION['MemberID'];
$data['sizes'] = array_values($g_db->GetAll($sql));
$sql="select * from ".$_SESSION['Version']."_colors where member_id=".$_SESSION['MemberID'];
$data['colors'] = array_values($g_db->GetAll($sql));
setvar("sizes",$data['sizes']);	
setvar("colors",$data['colors']);	
if($_GET['all']==1){
	echo json_encode($data);
	exit;
}elseif($_GET['all']==2){
	$sql="INSERT INTO `".$_SESSION['Version']."_sizes` (
				`id` ,
				`member_id` ,
				`company_id` ,
				`product_id` ,
				`name` ,
				`created` 
				)
				VALUES (
				NULL , '".$_SESSION['MemberID']."', '".$company_id."', '0', '".$_GET['name']."', now()
				)";
	$g_db->Query($sql);
	echo '{}';
	exit;
}elseif($_GET['all']==3){
	$sql="DELETE FROM `".$_SESSION['Version']."_sizes` WHERE `id` = '".$_GET['id']."'";
	$g_db->Query($sql);
	echo '{}';
	exit;
}elseif($_GET['all']==4){
	$sql="INSERT INTO `".$_SESSION['Version']."_colors` (
				`id` ,
				`member_id` ,
				`company_id` ,
				`product_id` ,
				`name` ,
				`created` 
				)
				VALUES (
				NULL , '".$_SESSION['MemberID']."', '".$company_id."', '0', '".$_GET['name']."', now()
				)";
	$g_db->Query($sql);
	echo '{}';
	exit;
}elseif($_GET['all']==5){
	$sql="DELETE FROM `".$_SESSION['Version']."_colors` WHERE `id` = '".$_GET['id']."'";
	$g_db->Query($sql);
	echo '{}';
	exit;
}
if (($_GET['action']=="mod") && (!empty($_GET['id']))) {
	$sql="select * from ".$_SESSION['Version']."_keywords where member_id=".$_SESSION['MemberID']." and product_id=".$_GET['id'];
	$res = $g_db->GetAll($sql);
	setvar("keywords",$res);
	
	
	$sql = "select a.*,b.name as color,c.name as size from ".$_SESSION['Version']."_sku as a left join ".$tb_prefix."colors as b on b.id=a.sku_color_id left join ".$tb_prefix."sizes as c on c.id=a.sku_size_id where a.sku_prod_id = ".$_GET['id']." and a.member_id = ".$_SESSION['MemberID']." order by a.id  ASC";


	$res = $g_db->GetArray($sql);
	setvar("skulist",$res);
	
	$sql="select * from ".$_SESSION['Version']."_sizes where member_id=".$_SESSION['MemberID']." and product_id=".$_GET['id'];
	
	
	
	
	
	$productinfo = $product->read(null,$_GET['id'],null,$conditions);
	
	
	
	if (empty($productinfo)) {
		gotoUrl("./tip.php?id=1005");
	}else {
		$current_industry = $industry->searchParentIndustry($productinfo['ProductIndustryId']);
		if (is_array($current_industry)) {
			$search_industry_ids = implode(",",$current_industry);
			setvar("CurrentIndustry",$g_db->GetArray("select name AS IndustryName from ".$industry->getTable(true)." where id in (".$search_industry_ids.")"));
		}
		$sql="select id,name,level from ".$_SESSION['Version']."_producttypes where id = '".$productinfo['ProductProducttypeId']."'";
	
	$res=$g_db->GetAll($sql);
	setvar("b","product.php?action=list&sid=".$res[0][0]);
	
setvar("bb",$res[0][1]);
	$sql="select id,name from ".$_SESSION['Version']."_producttypes where id = '".$res[0][2]."'";
	
	$res=$g_db->GetAll($sql);
	if($res!=''){
setvar("c","product.php?action=list&sid=".$res[0][0]);
setvar("cc",$res[0][1]);}
		$productinfo['ProductMore']=stripslashes($productinfo['ProductMore']);
		$productinfo['ProductMore']=html_entity_decode($productinfo['ProductMore']);
		$productinfo['ProductFeatures']=stripslashes($productinfo['ProductFeatures']);
		$productinfo['ProductFeatures']=html_entity_decode($productinfo['ProductFeatures']);
	
		setvar("ProductInfo",$productinfo);
	}
}else{$productinfo['ProductMore']=html_entity_decode($productinfo['ProductMore']);
$productinfo['ProductFeatures']=html_entity_decode($productinfo['ProductFeatures']);
 }

if (isset($_POST['action'])) {
	if($_POST['action']=="product_edit"){
		/*
        uses("access");
		$access = new Accesses();
		$vals = array();
		$now_product_amount = $product->findCount("member_id=".$_SESSION['MemberID']);
		$max_product_amount = intval($access->field("max_product","membertype_id=".$ua_user['user_type']));
		$check_product_update = intval($access->field("check_product_update","membertype_id=".$ua_user['user_type']));
	
		
		
		if ($max_product_amount!=0 && $now_product_amount>=$max_product_amount && (empty($pid))) {
			$msg = $cfg['room']['mx_prod_day'];
			flash("./tip.php","./product.php",$msg,0);
		}
		*/
		$pid = intval($_POST['id']);
		if (!empty($_FILES['pic']['name'])) {
			require(LIB_PATH.'controllers/upload.inc.php');
			$f = $_FILES['pic'];
			require(LIB_PATH.'controllers/GDImage.inc.php');
			ini_set("memory_limit", "32M");
			$check_path = uaCheckMediaPath('..'.DS.'..'.DS.$_SESSION['MemberName'].DS.$_SESSION['Version'].DS.$_SESSION['MemberName'].DS."products".DS);
			$file_ext = fileext($f['name']);
			if($_SESSION['Version']=='en'){$p_name=$_POST['prod_name'];
$p_name = str_replace(" ","",$p_name);
$p_name = str_replace("&","",$p_name);
$p_name = str_replace(",","",$p_name);
$p_name = str_replace("/","",$p_name);
$p_name = str_replace(".","",$p_name);
$p_name = str_replace("%","",$p_name);
$p_name = str_replace("(","",$p_name);
$p_name = str_replace(")","",$p_name);
$p_name = str_replace("#","",$p_name);
$p_name = str_replace("@","",$p_name);
$p_name = str_replace("*","",$p_name);
$p_name = str_replace("=","",$p_name);
$p_name = str_replace(":","",$p_name);
$p_name = str_replace("-","",$p_name);
$p_name = str_replace("_","",$p_name);
$p_name = str_replace("!","",$p_name);
$p_name = str_replace("?","",$p_name);
$p_name = str_replace("\'","",$p_name);
$p_name = str_replace("\"","",$p_name);
$p_name = str_replace("'","",$p_name);
$p_name = str_replace("+","",$p_name);
$p_name = str_replace("'","",$p_name);
$p_name = str_replace("`","",$p_name);
$p_name = str_replace("$","",$p_name);
$p_name = str_replace("[","",$p_name);
$p_name = str_replace("]","",$p_name);
$p_name = str_replace("“","",$p_name);
$p_name = str_replace("”","",$p_name);
$p_name = str_replace(",","",$p_name);
$p_name=strtolower($p_name);

$this_product_pic = $_SESSION['MemberID']."_".$p_name."_".$time_stamp.$file_ext;}
				else $this_product_pic = $_SESSION['MemberID']."_".$pid."_".$time_stamp.$file_ext;
			$u = new upload($f['name']);
			if($u->checkImage()){
				$uploade_file = move_uploaded_file($f['tmp_name'],$check_path.$this_product_pic);
			}else{
				flash("./tip.php","./product.php", $cfg['room']['pic_upload_error'],0);
			}
			if(!$uploade_file){
				flash("./tip.php","./product.php",$cfg['room']['pic_upload_false'],0);
			}else {
				$sql = "select * FROM ".$_SESSION['Version']."_companies 
WHERE member_id= ".$_SESSION['MemberID']
;
$res = $g_db->GetArray($sql);
    $shuiyin=$res[0];
	shuiyin($shuiyin['is_shuiyin'],$shuiyin['text_size'],$shuiyin['text_color'],$shuiyin['x_position'],$shuiyin['y_position'],$shuiyin['text_content'],$shuiyin['align_img'],$shuiyin['vlign_img'],$shuiyin['touming_img'],'../../'.$_SESSION['MemberName'].'/'.$_SESSION['Version'].'/'.$_SESSION['MemberName'].'/'."company/big/".$shuiyin['shuiyin_img'],$check_path.$this_product_pic);
				$oldfile = substr($check_path,0,-7).$_POST['oldimgname'];
				$oldfile = str_replace("\\","/",$oldfile);
				@unlink($oldfile);
				$oldsmallfile = substr($check_path,0,-11)."small".DS.$_POST['oldimgname'];
				@unlink(str_replace("\\","/",$oldsmallfile));
			}
			$image = new GDImage2($check_path,uaCheckMediaPath('..'.DS.'..'.DS.$_SESSION['MemberName'].DS.$_SESSION['Version'].DS.$_SESSION['MemberName'].DS."products".DS,"small".DS));
			$image2 = new GDImage2($check_path,uaCheckMediaPath('..'.DS.'..'.DS.$_SESSION['MemberName'].DS.$_SESSION['Version'].DS.$_SESSION['MemberName'].DS."products".DS,"middle".DS));
			$sql = "select width_pic,height_pic from members
WHERE id=".$_SESSION['MemberID'];

$res = $g_db->GetArray($sql);
			$arr=getimagesize($check_path.$this_product_pic);
			if($arr[0]>=$arr[1]){
			$image->makeThumb($this_product_pic,300,'',$res[0]['width_pic'],$res[0]['height_pic']);
			
			$image2->makeThumb($this_product_pic,300);}else{$image->makeThumb($this_product_pic,300,'',$res[0]['width_pic'],$res[0]['height_pic']);
			
			$image2->makeThumb($this_product_pic,300);}
			$set_watermark = $setting->field("ab","aa='watermark'");
			if($set_watermark && empty($pid)){
				$water_text = $setting->field("ab","aa='watertext'");
				$water_color = $setting->field("ab","aa='watercolor'");
				if (empty($water_text)) {
					$water_text = URL;
				}
				require($inc_path .APP_NAME. 'include/inc.imageWaterMark.php');
				imageWaterMark($check_path.$this_product_pic,8,"",$water_text,5,$water_color);
			}
		}
		if(!empty($this_product_pic)) {	
			if($_REQUEST['id']){
				$sql="select picture from ".$_SESSION['Version']."_products where id='".$_REQUEST['id']."'";
				$rr = $g_db->GetAll($sql);
				foreach($rr as $k=>$v){
					if($_SESSION['Version']=="en") {
			@unlink('../../upload/'.$_SESSION['MemberName'].'/upload/small/'.$v['picture']);
			@unlink('../../upload/'.$_SESSION['MemberName'].'/upload/middle/'.$v['picture']);
			@unlink('../../upload/'.$_SESSION['MemberName'].'/upload/big/'.$v['picture']);
			} else {
			@unlink('../../'.$_SESSION['Version'].'/upload/'.$_SESSION['MemberName'].'/upload/small/'.$v['picture']);
			@unlink('../../'.$_SESSION['Version'].'/upload/'.$_SESSION['MemberName'].'/upload/middle/'.$v['picture']);
			@unlink('../../'.$_SESSION['Version'].'/upload/'.$_SESSION['MemberName'].'/upload/big/'.$v['picture']);
				
			}
				}
			}
			
			
			$vals['picture'] = $this_product_pic;
		}

		$industryid = 0;

		if ($_POST['cindustry']) {
			$industryid = $_POST['cindustry'];
		}else if($_POST['bindustry']){
			$industryid = $_POST['bindustry'];
		}else if($_POST['aindustry']){
			$industryid = $_POST['aindustry'];
		}
		if($industryid)
		$vals['industry_id'] = $industryid;
		$vals['name'] = stripslashes(trim($_POST['prod_name']));
		if($_SESSION['Version']=='en'){
			$vals['name2'] = stripslashes(trim($_POST['prod_name']));
		}
$vals['beizu_price'] = stripslashes(trim($_POST['beizu_price']));
		$vals['beizu_youtube'] = stripslashes(trim($_POST['beizu_youtube']));
		$vals['status']=$_POST['status'];
		$vals['sn'] = stripslashes(trim($_POST['prod_sn']));
		$vals['spec'] = stripslashes(trim($_POST['scale']));
		$vals['packing_content'] = stripslashes(trim($_POST['package']));
		$vals['price'] = stripslashes(trim($_POST['price']));
		$vals['now_price'] = stripslashes(trim($_POST['now_price']));
		$vals['member2_price'] = stripslashes(trim($_POST['member2_price']));
		$vals['member_price'] = stripslashes(trim($_POST['member_price']));
		$vals['produce_area'] = stripslashes(trim($_POST['fromwhere']));
		$vals['content'] = stripslashes($_POST['content']);
		$vals['more'] = htmlspecialchars($_POST['more']);
		$vals['features'] = htmlspecialchars($_POST['features']);
		$vals['producttype_id'] = $_POST['product_type'];
		if($_POST['kid']){
			$sort_arr = implode(",", $_POST['kid']);
			$sql="DELETE FROM `".$_SESSION['Version']."_keywords` WHERE `id` in (".$sort_arr.")";
			$res = $g_db->Query($sql);
		}
		
		
		
        $a=array(); $a=$_POST['prodKeyword'];
	


	
	}
		
		array_walk($vals,"uatrim");
		if(!empty($vals['keywords'])){
			$keyword->importKeys($vals['keywords'], $pid, 4);
		}
		if (empty($company_id)) {
			flash("./tip.php","./company.php", $cfg['room']['re_complete_corp'],0);
		}
		if($_POST['sid']){
			$vals['sizes']=implode(",", $_POST['sid']);
		}
		if($_POST['cid']){
			$vals['colors']=implode(",", $_POST['cid']);
		}
		
		if (!empty($pid)) {
			//print_r($vals);echo $pid;var_dump($conditions);die;
			$result = $product->save($vals, "update", $pid, null, $conditions);
			for($i=1;$i<=count($a);$i++)
				{
						if($a[$i]!='')
					{
					
					$a[$i]=$a[$i];
$ak[$i]=$a[$i];
$ak[$i] = str_replace("&","",$ak[$i]);
$ak[$i] = str_replace(",","",$ak[$i]);
$ak[$i] = str_replace("/","",$ak[$i]);
$ak[$i] = str_replace(".","",$ak[$i]);
$ak[$i] = str_replace("%","",$ak[$i]);
$ak[$i] = str_replace("(","",$ak[$i]);
$ak[$i] = str_replace(")","",$ak[$i]);
$ak[$i] = str_replace("#","",$ak[$i]);
$ak[$i] = str_replace("@","",$ak[$i]);
$ak[$i] = str_replace("*","",$ak[$i]);
$ak[$i] = str_replace("=","",$ak[$i]);
$ak[$i] = str_replace(":","",$ak[$i]);
$ak[$i] = str_replace("-","",$ak[$i]);
$ak[$i] = str_replace("_","",$ak[$i]);
$ak[$i] = str_replace("!","",$ak[$i]);
$ak[$i] = str_replace("?","",$ak[$i]);
$ak[$i] = str_replace("\'","",$ak[$i]);
$ak[$i] = str_replace("\"","",$ak[$i]);
$ak[$i] = str_replace("'","",$ak[$i]);
$ak[$i] = str_replace("+","",$ak[$i]);
$ak[$i] = str_replace("'","",$ak[$i]);
$ak[$i] = str_replace("`","",$ak[$i]);
$ak[$i] = str_replace("$","",$ak[$i]);
$ak[$i] = str_replace("[","",$ak[$i]);
$ak[$i] = str_replace("]","",$ak[$i]);
$ak[$i] = str_replace("“","",$ak[$i]);
$ak[$i] = str_replace("”","",$ak[$i]);
$ak[$i] = str_replace(" ","-",$ak[$i]);


				$sql="INSERT INTO `".$_SESSION['Version']."_keywords` (
				`id` ,
				`member_id` ,
				`company_id` ,
				`product_id` ,
				`name` ,
				`name2` ,
				`name3` ,
				`created` 
				)
				VALUES (
				NULL , '".$_SESSION['MemberID']."', '".$company_id."', '".$pid."', '".trim($a[$i])."', '".trim($a[$i])."', '".trim($ak[$i])."', now()
				)";
				$res = $g_db->Query($sql);}}
				$val=array();
		$val['member_id']=$_SESSION['MemberID'];
		$val['company_id']=$company_id;
		$val['product_id']=$pid;
foreach($_POST['selectphoto'] as $k=>$v){
	
		if(strpos($v, 'products/big/') !== false) { 
	copy("../../".$_SESSION['MemberName']."/".$_SESSION['Version']."/".$_SESSION['MemberName']."/".$v,"../../".$_SESSION['MemberName']."/".$_SESSION['Version']."/".$_SESSION['MemberName']."/".str_replace('products/big/','more_imgs/big/',$v));
		copy("../../".$_SESSION['MemberName']."/".$_SESSION['Version']."/".$_SESSION['MemberName']."/".str_replace('/big/','/small/',$v),"../../".$_SESSION['MemberName']."/".$_SESSION['Version']."/".$_SESSION['MemberName']."/".str_replace('/big/','/small/',str_replace('products/big/','more_imgs/big/',$v)));
		
} 
$val['img']=str_replace('more_imgs/big/','',str_replace('products/big/','',$v));
		$result = $member->save($val,'','',$tb_prefix."img");
		}
$val=array();
				 $a=array(); 
				 
				 if($_POST['prodsize']){
					$a=$_POST['prodsize'];
				}
				for($i=1;$i<=count($a);$i++)
				{
						if($a[$i]!='')
					{
					
				$sql="INSERT INTO `".$_SESSION['Version']."_sizes` (
				`id` ,
				`member_id` ,
				`company_id` ,
				`product_id` ,
				`name` ,
				`created` 
				)
				VALUES (
				NULL , '".$_SESSION['MemberID']."', '".$company_id."', '".$pid."', '".$a[$i]."', now()
				)";
				$res = $g_db->Query($sql);}}
				 $a=array(); 
				 if($_POST['prodcolor']){
					$a=$_POST['prodcolor'];
				}
				for($i=1;$i<=count($a);$i++)
				{
						if($a[$i]!='')
					{
					
				$sql="INSERT INTO `".$_SESSION['Version']."_colors` (
				`id` ,
				`member_id` ,
				`company_id` ,
				`product_id` ,
				`name` ,
				`created` 
				)
				VALUES (
				NULL , '".$_SESSION['MemberID']."', '".$company_id."', '".$pid."', '".$a[$i]."', now()
				)";
				$res = $g_db->Query($sql);
				}}
		}else {
			if(isset($_SESSION['freemember_back'])){
				$free_sql="select id from ".$_SESSION['Version']."_products where member_id=".$_SESSION['MemberID'];
				$result=$g_db->GetAll($free_sql);
				if(count($result)>=10)die("您还是免费会员,只能添加10个产品,请联系我们升级为高级会员");
				}
			$vals['member_id'] = $_SESSION['MemberID'];
			$vals['company_id'] = $company_id;
			$vals['created'] = $time_stamp;
			
			if($checked==1){
				
				$vals['content'].='<table cellspacing="1" cellpadding="1" width="200" align="left" border="1">
    <tbody>
        <tr>
            <td>
            <pre>
产品描述:</pre>
            </td>
            <td>
            <pre>
产品属性:</pre>
            </td>
        </tr>
        <tr>
            <td>'.$_POST['content1'].' </td>
            <td>
'.$_POST['content2'].' </td>
        </tr>
		  <tr>
            <td>
            <pre>
洗涤说明:</pre>
            </td>
            <td>
            <pre>
产品尺码表:</pre>
            </td>
        </tr>
        <tr>
            <td>
'.$_POST['content3'].' </td>
            <td>
'.$_POST['content4'].' </td>
        </tr>
    </tbody>
</table>
<p>&nbsp;</p>';
				}
			
	
			$result = $product->save($vals);
	$_POST['prod_name']=trim($_POST['prod_name']);
	$_POST['product_type']=$_POST['product_type'];
			$sql="select id from ".$_SESSION['Version']."_products where name = '".$_POST['prod_name']."' and producttype_id ='".$_POST['product_type']."' and member_id='".$_SESSION['MemberID']."'and sn='".trim($_POST['prod_sn'])."' order by id DESC limit 0,1";

			$r = $g_db->GetAll($sql);
			
	
			$conditions = " and member_id = ".$_SESSION['MemberID'];
		$sql="select ep_range from ".$_SESSION['Version']."_products where member_id='".$_SESSION['MemberID']."' order by ep_range DESC 
 limit 0,1";
 $rr = $g_db->GetAll($sql);
		$record['ep_range'] = $rr[0][0]+1;
		$result = $product->save($record,"update",$r[0][0], null, $conditions);
			for($i=1;$i<=count($a);$i++)
				{
					if($a[$i]!='')
					{
$a[$i]=$a[$i];
$ak[$i]=$a[$i];
$ak[$i] = str_replace("&","",$ak[$i]);
$ak[$i] = str_replace(",","",$ak[$i]);
$ak[$i] = str_replace("/","",$ak[$i]);
$ak[$i] = str_replace(".","",$ak[$i]);
$ak[$i] = str_replace("%","",$ak[$i]);
$ak[$i] = str_replace("(","",$ak[$i]);
$ak[$i] = str_replace(")","",$ak[$i]);
$ak[$i] = str_replace("#","",$ak[$i]);
$ak[$i] = str_replace("@","",$ak[$i]);
$ak[$i] = str_replace("*","",$ak[$i]);
$ak[$i] = str_replace("=","",$ak[$i]);
$ak[$i] = str_replace(":","",$ak[$i]);
$ak[$i] = str_replace("-","",$ak[$i]);
$ak[$i] = str_replace("_","",$ak[$i]);
$ak[$i] = str_replace("!","",$ak[$i]);
$ak[$i] = str_replace("?","",$ak[$i]);
$ak[$i] = str_replace("\'","",$ak[$i]);
$ak[$i] = str_replace("\"","",$ak[$i]);
$ak[$i] = str_replace("'","",$ak[$i]);
$ak[$i] = str_replace("+","",$ak[$i]);
$ak[$i] = str_replace("'","",$ak[$i]);
$ak[$i] = str_replace("`","",$ak[$i]);
$ak[$i] = str_replace("$","",$ak[$i]);
$ak[$i] = str_replace("[","",$ak[$i]);
$ak[$i] = str_replace("]","",$ak[$i]);
$ak[$i] = str_replace("“","",$ak[$i]);
$ak[$i] = str_replace("”","",$ak[$i]);
$ak[$i] = str_replace(" ","-",$ak[$i]);
	
				$sql="INSERT INTO `".$_SESSION['Version']."_keywords` (
				`id` ,
				`member_id` ,
				`company_id` ,
				`product_id` ,
				`name` ,
				`name2` ,
				`name3` ,
				`created` 
				)
				VALUES (
				NULL , '".$_SESSION['MemberID']."', '".$company_id."', '".$r[0][0]."', '".trim($a[$i])."', '".trim($a[$i])."', '".trim($ak[$i])."', now()
				)";
				$res = $g_db->Query($sql);
					}
				
				}
				
				$val=array();
		$val['member_id']=$_SESSION['MemberID'];
		$val['company_id']=$company_id;
		$val['product_id']=$r[0][0];
foreach($_POST['selectphoto'] as $k=>$v){

	if(strpos($v, 'products/big/') !== false) { 
	copy("../../".$_SESSION['MemberName']."/".$_SESSION['Version']."/".$_SESSION['MemberName']."/".$v,"../../".$_SESSION['MemberName']."/".$_SESSION['Version']."/".$_SESSION['MemberName']."/".str_replace('products/big/','more_imgs/big/',$v));
		copy("../../".$_SESSION['MemberName']."/".$_SESSION['Version']."/".$_SESSION['MemberName']."/".str_replace('/big/','/small/',$v),"../../".$_SESSION['MemberName']."/".$_SESSION['Version']."/".$_SESSION['MemberName']."/".str_replace('/big/','/small/',str_replace('products/big/','more_imgs/big/',$v)));
		
} 
$val['img']=str_replace('more_imgs/big/','',str_replace('products/big/','',$v));

		
		$result = $member->save($val,'','',$tb_prefix."img");
		}
$val=array();
				
				 $a=array(); 
				if($_POST['prodsize']){
					$a=$_POST['prodsize'];
				}
				
				for($i=1;$i<=count($a);$i++)
				{
					if($a[$i]!='')
					{
				$sql="INSERT INTO `".$_SESSION['Version']."_sizes` (
				`id` ,
				`member_id` ,
				`company_id` ,
				`product_id` ,
				`name` ,
				`created` 
				)
				VALUES (
				NULL , '".$_SESSION['MemberID']."', '".$company_id."', '".$r[0][0]."', '".$a[$i]."', now()
				)";
				$res = $g_db->Query($sql);
					}
				
				}
				 $a=array(); 
				 if($_POST['prodcolor']){
					$a=$_POST['prodcolor'];
				}
			
				for($i=1;$i<=count($a);$i++)
				{
					if($a[$i]!='')
					{
				$sql="INSERT INTO `".$_SESSION['Version']."_colors` (
				`id` ,
				`member_id` ,
				`company_id` ,
				`product_id` ,
				`name` ,
				`created` 
				)
				VALUES (
				NULL , '".$_SESSION['MemberID']."', '".$company_id."', '".$r[0][0]."', '".trim($a[$i])."', now()

				)";
				$res = $g_db->Query($sql);
					}
				
				}
				
		}
		
		if ($result) {
			$message_info = $cfg['room']['action_complete'];
			if(!empty($pid))flash("./tip.php",'./productedit.php?action=mod%26id='.$pid,$message_info);
			else flash("./tip.php",'./productedit.php?action=mod%26id='.$r[0][0],$message_info);
		}else {
			flash("./tip.php","./product.php",$message_info,0);
		}
	}


setvar("ProductSorts",$product->product_sorts);
setvar("ProductTypes",$list);

$conditions = "member_id = ".$_SESSION['MemberID'];

if($secid!=''){
$sql = "select * from ".$_SESSION['Version']."_img where section_id = '".$secid."' and member_id = ".$_SESSION['MemberID']." order by img_range  DESC 
";

}else{
$sql = "select * from ".$_SESSION['Version']."_img where product_id = '".$_GET['id']."' and member_id = ".$_SESSION['MemberID']." order by img_range  DESC 
";}
setvar("s",$secid);
setvar("pi",$_GET['id']);
setvar("statuscheck",$product->product_sorts);
if($_GET['id']){
	$res = $g_db->GetArray($sql);
}else{
	$res=array();
}

setvar("imglist",$res);
if($secid!=''){
$sql = "select * from ".$_SESSION['Version']."_newsection where id = ".$secid." and member_id = ".$_SESSION['MemberID']."  
";
$res = $g_db->GetArray($sql);

setvar("sn",$res[0]);
}elseif($_GET['id']){
$sql = "select * from ".$_SESSION['Version']."_products where id = '".$_GET['id']."' and member_id = ".$_SESSION['MemberID']." 
";

$res = $g_db->GetArray($sql);

setvar("pd",$res[0]);
}
setvar("i",4);
setvar("is_index",$_SESSION['is_index']);
$count=0;
		$photo=array();
$sql="select id,name from ".$_SESSION['Version']."_producttypes where level=0 and  member_id=".$_SESSION['MemberID']." order by cpt_range asc";
$res = $g_db->GetAll($sql);
foreach($res as $k=>$v){

	$sql="select id,name,level from ".$_SESSION['Version']."_producttypes where level=".$v['id']." order by cpt_range asc";
	$result = $g_db->GetAll($sql);
	
		$res[$k]['include']=$result;
		foreach($res[$k]['include'] as $m=>$n){
	
	
	$sql="select id,name,picture from ".$tb_prefix."products where producttype_id=".$n['id']." and member_id=".$_SESSION['MemberID'];

$product=$g_db->GetAll($sql);
$res[$k]['include'][$m]['include']=$product;

foreach($product as $r=>$t){
	$photo[$count]['name']=str_replace("'","\\'","products/big/".$t['picture']);
	$photo[$count]['product']=$t['id'];
	$photo[$count]['producttype']=$n['id'];
	$photo[$count]['producttypetype']=$v['id'];
	$count++;
	$sql="select img from ".$tb_prefix."img where product_id=".$t['id']." and member_id=".$_SESSION['MemberID'];
	$img=$g_db->GetAll($sql);
	foreach($img as $z=>$x){
			$photo[$count]['name']=str_replace("'","\\'","more_imgs/big/".$x['img']);
			$photo[$count]['product']=$t['id'];
	        $photo[$count]['producttype']=$n['id'];
	        $photo[$count]['producttypetype']=$v['id'];
			$count++;
		
		}

	}
	

		}
}

	setvar("post_img",$res);

	setvar("post_img2",$photo);
		setvar("post_img3",$photo);
	setvar("counter",1);
include("head.php");template("newmember/".$tpl_file);
?>