PageRenderTime 48ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/new88li/core/admin/controller/goods/ctl.gtype.php

http://phpfor.googlecode.com/
PHP | 263 lines | 227 code | 26 blank | 10 comment | 35 complexity | 05e2ff9a73a6193a58c6de238641b6fa MD5 | raw file
  1. <?php
  2. /**
  3. * ctl_gtype
  4. *
  5. * @uses adminPage
  6. * @package
  7. * @version $Id: ctl.gtype.php 1928 2008-04-25 02:13:05Z alex $
  8. * @copyright 2003-2007 ShopEx
  9. * @author Wanglei <flaboy@zovatech.com>
  10. * @license Commercial
  11. */
  12. include_once('objectPage.php');
  13. class ctl_gtype extends objectPage{
  14. var $workground = 'goods';
  15. var $object = 'goods/gtype';
  16. var $finder_action_tpl = 'product/gtype/finder_action.html';
  17. var $allowImport = true;
  18. var $finder_default_cols = '_cmd,name,is_physical';
  19. var $allowExport = false;
  20. var $ioType = 'gtype';
  21. var $filter=array('schema_id'=>'custom');
  22. var $filterUnable = true;
  23. function index(){
  24. parent::index(array('params'=>array('is_def'=>'false')));
  25. }
  26. function finder_pager(){
  27. $_POST['is_def']='false';
  28. parent::finder_pager();
  29. }
  30. function save_cell_value($id,$key){
  31. if( $key == 'name' ){
  32. $otype = $this->system->loadModel('goods/gtype');
  33. if($otype->checkTypeByName( $_POST['data'] ) ){
  34. $otype->nameSave($id, $_POST['data'] );
  35. parent::save_cell_value($id,$key);
  36. }
  37. }
  38. }
  39. function newType(){
  40. $this->path[] = array('text'=>__('????'));
  41. $objGschema = &$this->system->loadModel('goods/schema');
  42. $aSchema = $objGschema->getList();
  43. foreach($aSchema as $k=>$item){
  44. if($item['is_def']){
  45. unset($aSchema[$k]);
  46. }
  47. }
  48. $this->pagedata['schemas'] = &$aSchema;
  49. $this->title=__('new goods type');
  50. $this->page('product/gtype/newType.html');
  51. }
  52. function toAdd($schema, $tag){
  53. if($tag == 'commit'){
  54. $_SESSION['gtype']['setting'] = $_POST['setting'];
  55. $_SESSION['gtype']['is_physical'] = $_POST['is_physical'];
  56. if ( $_SESSION['gtype']['alias'] == 'a:1:{i:0;s:0:"";}' ){
  57. unset($_SESSION['gtype']['alias']);
  58. }
  59. $this->editType();
  60. }else{
  61. unset($_SESSION['gtype']);
  62. $_SESSION['gtype']['schema_id'] = $schema;
  63. $objGschema = &$this->system->loadModel('goods/schema');
  64. $objGschema->dialog($schema);
  65. }
  66. }
  67. function toEdit($typeid){
  68. if($typeid){
  69. $gtype = &$this->system->loadModel('goods/gtype');
  70. $aType = $gtype->getTypeDetail($typeid, true);
  71. $_SESSION['gtype'] = $aType;
  72. $_POST['setting'] = $aType['setting'];
  73. $_POST['is_physical'] = $aType['is_physical'];
  74. }
  75. $objGschema = &$this->system->loadModel('goods/schema');
  76. $objGschema->dialog($aType['schema_id']);
  77. }
  78. function editType(){
  79. $this->path[] = array('text'=>__('????'));
  80. $aType = $_SESSION['gtype'];
  81. $this->pagedata['gtype'] = $aType;
  82. $brand = &$this->system->loadModel('goods/brand');
  83. foreach($brand->getAll() as $rows){
  84. $aTmpList[$rows['brand_id']] = $rows['brand_name'];
  85. }
  86. $this->pagedata['brands'] = $aTmpList;
  87. $this->page('product/gtype/workpage.html');
  88. }
  89. function toSave(){
  90. if (empty($_POST['name'])){
  91. $this->begin('index.php?ctl=goods/gtype&act=newType');
  92. trigger_error(__('????????'),E_USER_ERROR);
  93. $this->end();
  94. }
  95. $this->begin('index.php?ctl=goods/gtype&act=index');
  96. $objGtype = &$this->system->loadModel('goods/gtype');
  97. if(isset($_SESSION['gtype']['is_physical'])) $_POST['is_physical'] = $_SESSION['gtype']['is_physical'];
  98. if(isset($_SESSION['gtype']['schema_id'])) $_POST['schema_id'] = $_SESSION['gtype']['schema_id'];
  99. if(isset($_SESSION['gtype']['setting'])) $_POST['setting'] = $_SESSION['gtype']['setting'];
  100. if(isset($_SESSION['gtype']['dly_func'])) $_POST['dly_func'] = $_SESSION['gtype']['dly_func'];
  101. if(isset($_SESSION['gtype']['ret_func'])) $_POST['ret_func'] = $_SESSION['gtype']['ret_func'];
  102. if(isset($_SESSION['gtype']['reship'])) $_POST['reship'] = $_SESSION['gtype']['reship'];
  103. if(isset($_SESSION['gtype']['disabled'])) $_POST['disabled'] = $_SESSION['gtype']['disabled'];
  104. if(isset($_SESSION['gtype']['is_def'])) $_POST['is_def'] = $_SESSION['gtype']['is_def'];
  105. $this->end($objGtype->toSave($_POST), __('????'));
  106. }
  107. function delete(){
  108. $this->begin('index.php?ctl=goods/gtype&act=index');
  109. $objType = &$this->system->loadModel('goods/gtype');
  110. if(is_array($_REQUEST['type_id']))
  111. foreach($_REQUEST['type_id'] as $id){
  112. $objType->toRemove($id);
  113. }
  114. $objType->checkDefined();
  115. $this->end_only(true);
  116. echo __('????');
  117. }
  118. function recycle(){
  119. $objType = &$this->system->loadModel('goods/gtype');
  120. $varGoto = 1;
  121. foreach($_REQUEST['type_id'] as $type_id){
  122. if(!$objType->checkDelete($type_id, $result)){
  123. if($result == 1){
  124. echo __('??????????????????');
  125. }
  126. if($result == 2){
  127. echo __('?????????????????');
  128. }
  129. $varGoto = 0;
  130. break;
  131. }
  132. }
  133. if($varGoto){
  134. parent::recycle();
  135. $objType = &$this->system->loadModel('goods/gtype');
  136. $objType->checkDefined();
  137. }
  138. }
  139. function fetchProtoTypes($link,$querystring=''){
  140. header('Content-Type: text/html;charset=utf-8');
  141. $net = &$this->system->loadModel('utility/http_client');
  142. $cert = $this->system->getConf('certificate.id');
  143. $token = $this->system->getConf('certificate.token');
  144. $sc = md5('goostypefeed'.$cert.$token);
  145. $url = 'http://feed.shopex.cn/goodstype/'.$link.'?certificate='.$cert.'&sc='.$sc.($querystring?'&'.$querystring:'');
  146. $net->http_ver = '1.0';
  147. $result = $net->get($url);
  148. if($result && false!==substr($result,'shopexfeed')){
  149. echo $result;
  150. }else{
  151. echo '<div style="width:300px;height:80px;"><BR><BR>'.__('??????????????????????????<BR>?????...????').$net->responseCode.'</div><div style="clear:both">';
  152. }
  153. }
  154. function getXml($id){
  155. $o = &$this->system->loadModel('goods/gtype');
  156. $xml = &$this->system->loadModel('utility/xml');
  157. $xmlpart = $xml->array2xml($o->getTypeObj($id,$name),'goodstype');
  158. $charset = &$this->system->loadModel('utility/charset');
  159. download($name.'.typ',$xmlpart);
  160. }
  161. function saveSpec(){
  162. $this->begin('index.php?ctl=goods/gtype&act=index');
  163. $objType = &$this->system->loadModel('goods/gtype');
  164. $this->end($objType->saveSpec($_POST['type_id'], $_POST['specs']), __('????'));
  165. }
  166. function fetchSave(){
  167. $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']));
  168. $xml = &$this->system->loadModel('utility/xml');
  169. $map = $xml->xml2arrayValues($_POST['xml']);
  170. $gtype = $this->xml2arrayXin($_POST['xml']);
  171. $gtype['name'] = $_POST['gtypename'];
  172. $o = &$this->system->loadModel('goods/gtype');
  173. $this->end($o->fetchSave($gtype), __('??????'));
  174. }
  175. function import(){
  176. $dataio = &$this->system->loadModel('system/dataio');
  177. $dataio->privateImport = true;
  178. $this->pagedata['importer'] = $dataio->importer($this->ioType);
  179. $this->pagedata['ctl'] = 'goods/gtype';
  180. $this->pagedata['optionsView'] = $this->importOptions;
  181. $this->page('finder/import.html');
  182. }
  183. function checkTypeNameExists(){
  184. $o = $this->system->loadModel('goods/gtype');
  185. if($o->getList('type_id',array('name'=>$_POST['gtypename']))){
  186. echo '<script>alert("???????????????");</script>';
  187. }else{
  188. echo '<script>alert("?????????????????");</script>';
  189. }
  190. }
  191. function importer(){
  192. $this->begin('index.php?ctl=goods/gtype&act=index');
  193. $dataio = &$this->system->loadModel('system/dataio');
  194. $gtype = &$this->system->loadModel('goods/gtype');
  195. if(substr($_FILES['upload']['name'],-4)!='.typ'){
  196. trigger_error(__('??????'),E_USER_ERROR);
  197. exit;
  198. }
  199. $content = file_get_contents($_FILES['upload']['tmp_name']);
  200. if(substr($content,0,3)=="\xEF\xBB\xBF")
  201. $content = substr($content,3);
  202. $data = $dataio->import_rows($_POST['type'],$content);
  203. $imported = false;
  204. foreach($data as $type){
  205. if($type['name']){
  206. $type['name'] = $type['name'].time();
  207. $gtype->fetchSave($type);
  208. $imported = true;
  209. }
  210. }
  211. if($imported){
  212. $this->end(true,__('????????,???????????'));
  213. }else{
  214. trigger_error(__('????????????????????'),E_USER_ERROR);
  215. }
  216. }
  217. function typeTransformCheck($type){
  218. $oGtype = $this->system->loadModel('goods/gtype');
  219. $_POST['goods']['spec_desc'] = unserialize(urldecode($_POST['goods']['spec_desc']));
  220. if($type == 'cat'){
  221. $oCat = $this->system->loadModel('goods/productCat');
  222. $aTmp = $oCat->getFieldById($_POST['goods']['cat_id'],array('type_id'));
  223. $_POST['goods']['type_id'] = $aTmp['type_id'];
  224. }
  225. if( $oGtype->typeTransformCheck($_POST['oldTypeId'],$_POST['goods']['type_id'],$_POST['goods']) ){
  226. echo '1';
  227. }else{
  228. $errorMsg = ' ';
  229. foreach( $oGtype->specTransformError as $sv ){
  230. $errorMsg .= $sv['spec_name'].' (';
  231. $errorMsg .= implode('?',array_values($sv['spec_value']));
  232. $errorMsg .= ') ';
  233. }
  234. echo '????'.$errorMsg.'??????';
  235. }
  236. }
  237. }