/new88li/core/admin/controller/goods/ctl.gtype.php
PHP | 263 lines | 227 code | 26 blank | 10 comment | 35 complexity | 05e2ff9a73a6193a58c6de238641b6fa 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 $workground = 'goods';
- var $object = 'goods/gtype';
- var $finder_action_tpl = 'product/gtype/finder_action.html';
- var $allowImport = true;
- var $finder_default_cols = '_cmd,name,is_physical';
- var $allowExport = false;
- var $ioType = 'gtype';
- var $filter=array('schema_id'=>'custom');
- var $filterUnable = true;
- function index(){
- parent::index(array('params'=>array('is_def'=>'false')));
- }
- function finder_pager(){
- $_POST['is_def']='false';
- parent::finder_pager();
- }
- function save_cell_value($id,$key){
- if( $key == 'name' ){
- $otype = $this->system->loadModel('goods/gtype');
- if($otype->checkTypeByName( $_POST['data'] ) ){
- $otype->nameSave($id, $_POST['data'] );
- parent::save_cell_value($id,$key);
- }
- }
- }
- 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'];
- if ( $_SESSION['gtype']['alias'] == 'a:1:{i:0;s:0:"";}' ){
- unset($_SESSION['gtype']['alias']);
- }
- $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();
- }
- $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'];
- $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);
- }
- $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');
- $net = &$this->system->loadModel('utility/http_client');
- $cert = $this->system->getConf('certificate.id');
- $token = $this->system->getConf('certificate.token');
- $sc = md5('goostypefeed'.$cert.$token);
- $url = 'http://feed.shopex.cn/goodstype/'.$link.'?certificate='.$cert.'&sc='.$sc.($querystring?'&'.$querystring:'');
- $net->http_ver = '1.0';
- $result = $net->get($url);
- if($result && false!==substr($result,'shopexfeed')){
- echo $result;
- }else{
- echo '<div style="width:300px;height:80px;"><BR><BR>'.__('??????????????????????????<BR>?????...????').$net->responseCode.'</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');
- $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 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');
- $map = $xml->xml2arrayValues($_POST['xml']);
- $gtype = $this->xml2arrayXin($_POST['xml']);
- $gtype['name'] = $_POST['gtypename'];
- $o = &$this->system->loadModel('goods/gtype');
- $this->end($o->fetchSave($gtype), __('??????'));
- }
- 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 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 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);
- }
- }
- function typeTransformCheck($type){
- $oGtype = $this->system->loadModel('goods/gtype');
- $_POST['goods']['spec_desc'] = unserialize(urldecode($_POST['goods']['spec_desc']));
- if($type == 'cat'){
- $oCat = $this->system->loadModel('goods/productCat');
- $aTmp = $oCat->getFieldById($_POST['goods']['cat_id'],array('type_id'));
- $_POST['goods']['type_id'] = $aTmp['type_id'];
- }
- if( $oGtype->typeTransformCheck($_POST['oldTypeId'],$_POST['goods']['type_id'],$_POST['goods']) ){
- echo '1';
- }else{
- $errorMsg = ' ';
- foreach( $oGtype->specTransformError as $sv ){
- $errorMsg .= $sv['spec_name'].' (';
- $errorMsg .= implode('?',array_values($sv['spec_value']));
- $errorMsg .= ') ';
- }
- echo '????'.$errorMsg.'??????';
- }
- }
- }