<?php
session_start();
require_once "../init.php";
require_once "../authority.inc.php";

$uppath=isset($_REQUEST["upPath"])?$_REQUEST["upPath"]."/":"/ueditor/php/upload/image";   




$formName=isset($_REQUEST["formName"])?$_REQUEST["formName"]:"form";          //回传到上页面编辑框所在Form的Name
$editName=isset($_REQUEST["editName"])?$_REQUEST["editName"]:"pic";              //回传到上页面编辑框的Name
//示例
$Productpp=$_POST['Productpp'];
$IDProduct = $_POST['IDProduct'];
$productid = $_POST['productid'];
$ParentID = $_POST['ParentID'];
$Type = $_POST['Type'];
$ProductName = $_POST['ProductName'];
$price = $_POST['price'];
$lang =  $_POST['lang'];
$ActionClass = "HostImpl";
$show_index = $_POST['show_index'];
$ProductIntro = $_POST['ProductIntro'];
$txtDetail = $_POST['txtDetail'];
$OldIDProduct = $_POST['OldIDProduct'];
$renew_price = $_POST['renew_price'];
$product_new_name = $_POST['product_new_name'];
$product_new_info = $_POST['product_new_info'];
$pics = json_encode($_POST['pics']);
$picinfo =   JSON($_POST['picinfo']);

$PParentID =  $_POST['PParentID'];
$alink = json_encode($_POST['alink']);
$OldLogo = $_POST['OldLogo'];
$DelOldLogo = $_POST['DelOldLogo'];
if($IDProduct){
	$proInfo = $proType->GetProduct($IDProduct);
	
}






if($product_new_name)
{
	foreach($product_new_name as $key => $info)
	{
		$new_info = iconv("GBK", "UTF-8", trim($info)) ;
		if($new_info != null)
		{
			$new_arr[$new_info] = iconv("GBK", "UTF-8", trim($product_new_info[$key]));

	
		}
	}
}

$product_info = addslashes(json_encode($new_arr));


?>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>增加产品类别</title>

<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<LINK rel="Bookmark" href="/favicon.ico" >
<LINK rel="Shortcut Icon" href="/favicon.ico" />
<!--[if lt IE 9]>
<script type="text/javascript" src="../lib/html5.js"></script>
<script type="text/javascript" src="../lib/respond.min.js"></script>
<script type="text/javascript" src="../lib/PIE_IE678.js"></script>
<![endif]-->
<link rel="stylesheet" type="text/css" href="/admin/static/h-ui/css/H-ui.min.css" />
<link rel="stylesheet" type="text/css" href="/admin/static/h-ui.admin/css/H-ui.admin.css" />
<link rel="stylesheet" type="text/css" href="/admin/lib/Hui-iconfont/1.0.7/iconfont.css" />
<link rel="stylesheet" type="text/css" href="/admin/lib/icheck/icheck.css" />
<link rel="stylesheet" type="text/css" href="/admin/static/h-ui.admin/skin/default/skin.css" id="skin" />
<link rel="stylesheet" type="text/css" href="/admin/static/h-ui.admin/css/style.css" />

<!--[if IE 6]>
<script type="text/javascript" src="../static/h-ui.admin/js/DD_belatedPNG_0.0.8a-min.js" ></script>
<script>DD_belatedPNG.fix('*');</script>
<![endif]-->

<LINK href="../share/style.css" rel="stylesheet">
<script src="../share/global.js"></script>

</head>
<body>
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 产品管理 <span class="c-gray en">&gt;</span> 发布产品 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>

<div class="page-container">
<? include "nav.inc.php"?>

<table width="100%" border="0" cellpadding="1" cellspacing="1">
  <tr>
    <td></td>
  </tr>
  <tr>
    <td height="3" bgcolor="#555555"></td>
  </tr>
  <tr>
    <td height="300" valign="top" align="center">
	<?php


//转换根目录的路径
if(strpos($uppath,"/")==0) {
      $i=0;
      $thpath=$_SERVER["SCRIPT_NAME"];
      $thpath=substr($thpath,1,strlen($thpath));
      while(strripos($thpath,"/")!==false){
          $thpath=substr($thpath,strpos($thpath,"/")+1,strlen($thpath));
          $i=++$i;        
      }

$pp="";
      for($j=0;$j<$i;++$j){
          $pp .="../";
      }

      $uppaths=$pp.substr($uppath,1,strlen($thpath));
}
$filename=date("y-m");
if(is_dir($uppaths."/image/".$filename)!=TRUE) mkdir($uppaths."/image/".$filename,0777);
// if(is_dir($filename."/".$ctime)!=TRUE) mkdir($filename."/".$ctime,0777);

$f = $_FILES['file1'];

$dest = $uppaths."/image/".$filename."/".date("ymd")."_".$f['name'];//设置文件名为日期加上文件名避免重复上传目录



if($f['name']){
$dest1 = $uppath.$filename."/".date("ymd")."_".$f['name'];//设置文件名为日期加上文件名避免重复
}
elseif($DelOldLogo)
{
if($OldLogo){
		  $delpath = "../..$OldLogo";
		  @unlink($delpath);
		  $plus .= "Logo='',";
		  $_POST[Logo]='';
	   }
$dest1="";
}
else
{
$dest1=$OldLogo;
}
$r = move_uploaded_file($f['tmp_name'],$dest);
if($f['size']>0){
  $delpath = "../..$OldLogo";
		  @unlink($delpath);
      echo    "<script>window.opener.document.".$formName.".".$editName.".value='".$dest1."'</script>";
}




	foreach($price as $item) {
		if(is_numeric($item)) {
			$Price.=$item.",";
		} else {
			break;
		}
	}
	if(substr($Price,-1,1)==","){
		$len = strlen($Price)-1;
		$Price = substr($Price,0,$len);
	}

	foreach($renew_price as $item) {
		if(is_numeric($item)) {
			$Renew_Price.=$item.",";
		} else {
			break;
		}
	}
	if(substr($Renew_Price,-1,1)==","){
		$len = strlen($Renew_Price)-1;
		$Renew_Price = substr($Renew_Price,0,$len);
	}
	

	if($OldIDProduct>=1) $sql = "update products set ";
	else $sql = "insert into products set ";
	$sql .= "lang='$lang',pic='$dest1',pics='$pics',picinfo='$picinfo',alink='$alink',Type='$Type',ParentID='$ParentID',";
	$sql .= "ProductName='$ProductName',Renew_Price='$Renew_Price',Price='$Price',";
	$sql .= "ActionClass='$ActionClass',AutoDo='0',ProductIntro='$ProductIntro',txtDetail='$txtDetail',product_info='$product_info',Productpp='$Productpp',";
	$sql .= "show_index='$show_index',dtCreate=now()";
	if($OldIDProduct>=1) $sql .= " where IDProduct='$OldIDProduct'";
	$DB->query($sql);
	//删除序列缓存文件,以便前台访问时重新设置序列缓存文件
	$sfile = "../../serialize/products.cache";
	@unlink($sfile);


	echo "<br><br><br>产品 $ProductName 保存成功";
	echo "<br><br><br>您必须 <a href='cache.php?action=clear&actionname=清空缓存'>[清空网站缓存]</a>才能令您刚作的修改生效,请点击这里<a href='cache.php?action=clear&actionname=清空缓存'>[清空网站缓存]</a>";
	echo "<br><br><br><a href='pro_class.php'>[返回列表]</a>";

	?>
    </td>
  </tr>



</table>



</div>
<? 
$DB->close();
include "../share/bottom.php"?>
</body>
</html>
