/b2b/core/admin/controller/goods/ctl.gtype.php
PHP | 297 lines | 251 code | 29 blank | 17 comment | 34 complexity | ef0f4e8dbc05115c6d2a7f6378f8ac24 MD5 | raw file
- <?php
- /**
- * ctl_gtype
- *
- * @uses adminPage
- * @package
- * @version $Id: ctl.gtype.php 1928 2008-04-25 02:13:05Z alex $
- * @copyright 2003-2007 ShopEx
- * @author Wanglei <flaboy@zovatech.com>
- * @license Commercial
- */
- include_once('objectPage.php');
- class ctl_gtype extends objectPage{
-
- var $name='????';
- var $workground = 'goods';
- var $object = 'goods/gtype';
- var $actionView = 'product/gtype/finder_action.html';
- var $allowImport = true;
- var $allowExport = false;
- var $ioType = 'gtype';
-
- var $disableGridEditCols = "is_def,setting,schema_id";
- var $disableColumnEditCols = "is_def,setting,schema_id";
- var $disableGridShowCols = "is_def,setting,schema_id";
-
- var $actions= array(
- 'toEdit'=>'??',
- 'getXml'=>'??'
- );
-
- function index(){
- parent::index(array('params'=>array('is_def'=>'false')));
- }
-
- function newType(){
- $this->path[] = array('text'=>'????');
- $objGschema = $this->system->loadModel('goods/schema');
- $aSchema = $objGschema->getList();
- foreach($aSchema as $k=>$item){
- if($item['is_def']){
- unset($aSchema[$k]);
- }
- }
- $this->pagedata['schemas'] = &$aSchema;
- $this->title=__('new goods type');
- $this->page('product/gtype/newType.html');
- }
-
- function toAdd($schema, $tag){
- if($tag == 'commit'){
- $_SESSION['gtype']['setting'] = $_POST['setting'];
- $_SESSION['gtype']['is_physical'] = $_POST['is_physical'];
- $this->editType();
- }else{
- unset($_SESSION['gtype']);
- $_SESSION['gtype']['schema_id'] = $schema;
- $objGschema = $this->system->loadModel('goods/schema');
- $objGschema->dialog($schema);
- }
- }
-
- function toEdit($typeid){
- if($typeid){
- $gtype = $this->system->loadModel('goods/gtype');
- $aType = $gtype->getTypeDetail($typeid, true);
- $_SESSION['gtype'] = $aType;
- $_POST['setting'] = $aType['setting'];
- $_POST['is_physical'] = $aType['is_physical'];
- }
-
- $objGschema = $this->system->loadModel('goods/schema');
- $objGschema->dialog($aType['schema_id']);
- }
-
- function editType(){
- $this->path[] = array('text'=>'????');
-
- $aType = $_SESSION['gtype'];
- $this->pagedata['gtype'] = $aType;
- $brand = $this->system->loadModel('goods/brand');
- foreach($brand->getAll() as $rows){
- $aTmpList[$rows['brand_id']] = $rows['brand_name'];
- }
- $this->pagedata['brands'] = $aTmpList;
- $this->page('product/gtype/workpage.html');
- }
-
- function toSave(){
- if (empty($_POST['name'])){
- $this->begin('index.php?ctl=goods/gtype&act=newType');
- trigger_error('????????',E_USER_ERROR);
- $this->end();
- }
- if(count($_POST['props']['name']) > 30){
- $this->begin('index.php?ctl=goods/gtype&act=newType');
- trigger_error('????????30?',E_USER_ERROR);
- $this->end();
- }
- $this->begin('index.php?ctl=goods/gtype&act=index');
- $objGtype = $this->system->loadModel('goods/gtype');
- if(isset($_SESSION['gtype']['is_physical'])) $_POST['is_physical'] = $_SESSION['gtype']['is_physical'];
- if(isset($_SESSION['gtype']['schema_id'])) $_POST['schema_id'] = $_SESSION['gtype']['schema_id'];
- if(isset($_SESSION['gtype']['setting'])) $_POST['setting'] = $_SESSION['gtype']['setting'];
- if(isset($_SESSION['gtype']['dly_func'])) $_POST['dly_func'] = $_SESSION['gtype']['dly_func'];
- if(isset($_SESSION['gtype']['ret_func'])) $_POST['ret_func'] = $_SESSION['gtype']['ret_func'];
- if(isset($_SESSION['gtype']['reship'])) $_POST['reship'] = $_SESSION['gtype']['reship'];
- if(isset($_SESSION['gtype']['disabled'])) $_POST['disabled'] = $_SESSION['gtype']['disabled'];
- if(isset($_SESSION['gtype']['is_def'])) $_POST['is_def'] = $_SESSION['gtype']['is_def'];
- //???????? by zhoulei 2011-10-12
- $aType = $_SESSION['gtype']['props'];
- $bType = $_POST['props']['name'];
- //??????key+1
- foreach($bType as $k=>$v){
- $bType[$k+1] = $v;
- }
- unset($bType[0]);
- $updateKey = $tempKey = $updatestr = array();
- foreach ($aType as $ak=>$av){
- $bk = array_search($av['name'],$bType);
- //???
- if ($bk === false){
- $updateKey[] = $ak;
- }elseif(in_array($_POST['props']['type'][$bk-1],array(0,1))){
- $updateKey[] = $ak;
- }else{//???
- $tempKey[] = $ak;
- $bind[$ak] = $bk-1;
- }
- }
- $num = count($bType);
- //?????????p_1??
- foreach ($tempKey as $k=>$tk){
- if($objGtype->getTypeSearch($aType[$tk]['type'],$aType[$tk]['search']) != $_POST['props']['type'][$bind[$tk]]){
- $updatestr[] = ' p_'.($k+1).' = NULL ';
- }else{
- $updatestr[] = ' p_'.($k+1).' = p_'.$tk.' ';
- }
- }
- //??????? ???????
- if($num < count($aType)){
- $max_key = count($aType);
- for($i=0;$i<count($updateKey);$i++){
- $updatestr[] = ' p_'.($max_key-$i).' = NULL ';
- }
- }
- $type_id = $_POST['type_id'];
- //??????
- if($updatestr){
- $objGtype->setGoodsProp($updatestr,$type_id);
- }
-
- $this->end($objGtype->toSave($_POST), '????');
- }
-
- function delete(){
- $this->begin('index.php?ctl=goods/gtype&act=index');
- $objType = $this->system->loadModel('goods/gtype');
- if(is_array($_REQUEST['type_id'])){
- foreach($_REQUEST['type_id'] as $id){
- $objType->toRemove($id);
- }
- }else{
- $count = 0;
- $objType->disabledMark = 'recycle';
- $type = $objType->getList('type_id','',0,-1,$count);
- if($count > 0){
- foreach($type as $v){
- $objType->toRemove($v['type_id']);
- }
- }
- }
- $objType->checkDefined();
- $this->end_only(true);
- echo '????';
- }
-
- function recycle(){
- $objType = $this->system->loadModel('goods/gtype');
- $varGoto = 1;
- foreach($_REQUEST['type_id'] as $type_id){
- if(!$objType->checkDelete($type_id, $result)){
- if($result == 1){
- echo __('??????????????????');
- }
- if($result == 2){
- echo __('?????????????????');
- }
- $varGoto = 0;
- break;
- }
- }
- if($varGoto){
- parent::recycle();
- $objType = $this->system->loadModel('goods/gtype');
- $objType->checkDefined();
- }
- }
-
- function fetchProtoTypes($link,$querystring=''){
- header('Content-Type: text/html;charset=utf-8');
- $network = $this->system->network();
- $network->read_timeout = 15;
- $network->_fp_timeout = 10;
- $cert = $this->system->getConf('certificate.id');
- $token = $this->system->getConf('certificate.token');
- $sc = md5('goostypefeed'.$cert.$token);
- if($network->fetch('http://feed.shopex.cn/goodstype/'.$link.'?certificate='.$cert.'&sc='.$sc.($querystring?'&'.$querystring:''))&&strstr($network->results,'shopexfeed')){
- echo $network->results;
- }else{
- echo '<div style="width:300px;height:80px;"><BR><BR>??????????????????????????<BR>?????...</div><div style="clear:both">';
- }
- }
-
- function getXml($id){
- $o = $this->system->loadModel('goods/gtype');
- $xml = $this->system->loadModel('utility/xml');
- $xmlpart = $xml->array2xml($o->getTypeObj($id,$name),'goodstype',false);
-
-
- $charset = $this->system->loadModel('utility/charset');
- download($name.'.typ',$xmlpart);
- }
-
- function saveSpec(){
- $this->begin('index.php?ctl=goods/gtype&act=index');
- $objType = $this->system->loadModel('goods/gtype');
- $this->end($objType->saveSpec($_POST['type_id'], $_POST['specs']), '????');
- }
-
- function checkTypeNameExists(){
- $o = $this->system->loadModel('goods/gtype');
- if($o->getList('type_id',array('name'=>$_POST['gtypename']))){
- echo '<script>alert("???????????????");</script>';
- }else{
- echo '<script>alert("?????????????????");</script>';
- }
- }
-
- function fetchSave(){
- $this->begin('index.php?ctl=goods/gtype&act=index',array(300001=>'index.php?ctl=goods/gtype&act=fetchProtoTypes&p[0]=gtype.php&p[1]=id='.$_POST['param_id']));
- $xml = $this->system->loadModel('utility/xml');
- $arr = $xml->xml2array(stripslashes($_POST['xml']));
- $gtype = $arr['goodstype'];
- $gtype['name'] = $_POST['gtypename'];
- $o = $this->system->loadModel('goods/gtype');
- $this->end($o->fetchSave($gtype), __('??????'));
- }
-
- function filterActions ($row){
- $return = $this->actions;
- // $return['editType'] = array('target'=>"{update:'main',fm:'addnew'}");
- $return['getXml'] = array('link'=>'index.php?ctl=goods/gtype&act=getXml&p[0]='.$row['type_id'],'target'=>'download');
- return $return;
- }
-
- function import(){
- $dataio = &$this->system->loadModel('system/dataio');
- $dataio->privateImport = true;
- $this->pagedata['importer'] = $dataio->importer($this->ioType);
- $this->pagedata['ctl'] = 'goods/gtype';
- $this->pagedata['optionsView'] = $this->importOptions;
- $this->page('finder/import.html');
- }
-
- function importer(){
- $this->begin('index.php?ctl=goods/gtype&act=index');
- $dataio = $this->system->loadModel('system/dataio');
- $gtype = $this->system->loadModel('goods/gtype');
- if(substr($_FILES['upload']['name'],-4)!='.typ'){
- trigger_error(__('??????'),E_USER_ERROR);
- exit;
- }
-
- $content = file_get_contents($_FILES['upload']['tmp_name']);
-
-
- if(substr($content,0,3)=="\xEF\xBB\xBF")
- $content = substr($content,3);
- $data = $dataio->import_rows($_POST['type'],$content);
-
-
- $imported = false;
- foreach($data as $type){
- if($type['name']){
- $type['name'] = $type['name'].time();
- $gtype->fetchSave($type);
- $imported = true;
- }
- }
- if($imported){
- $this->end(true,__('????????,???????????'));
- }else{
- trigger_error(__('????????????????????'),E_USER_ERROR);
- }
- }
- }