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

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

http://phpfor.googlecode.com/
PHP | 297 lines | 251 code | 29 blank | 17 comment | 34 complexity | ef0f4e8dbc05115c6d2a7f6378f8ac24 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 $name='????';
  15. var $workground = 'goods';
  16. var $object = 'goods/gtype';
  17. var $actionView = 'product/gtype/finder_action.html';
  18. var $allowImport = true;
  19. var $allowExport = false;
  20. var $ioType = 'gtype';
  21. var $disableGridEditCols = "is_def,setting,schema_id";
  22. var $disableColumnEditCols = "is_def,setting,schema_id";
  23. var $disableGridShowCols = "is_def,setting,schema_id";
  24. var $actions= array(
  25. 'toEdit'=>'??',
  26. 'getXml'=>'??'
  27. );
  28. function index(){
  29. parent::index(array('params'=>array('is_def'=>'false')));
  30. }
  31. function newType(){
  32. $this->path[] = array('text'=>'????');
  33. $objGschema = $this->system->loadModel('goods/schema');
  34. $aSchema = $objGschema->getList();
  35. foreach($aSchema as $k=>$item){
  36. if($item['is_def']){
  37. unset($aSchema[$k]);
  38. }
  39. }
  40. $this->pagedata['schemas'] = &$aSchema;
  41. $this->title=__('new goods type');
  42. $this->page('product/gtype/newType.html');
  43. }
  44. function toAdd($schema, $tag){
  45. if($tag == 'commit'){
  46. $_SESSION['gtype']['setting'] = $_POST['setting'];
  47. $_SESSION['gtype']['is_physical'] = $_POST['is_physical'];
  48. $this->editType();
  49. }else{
  50. unset($_SESSION['gtype']);
  51. $_SESSION['gtype']['schema_id'] = $schema;
  52. $objGschema = $this->system->loadModel('goods/schema');
  53. $objGschema->dialog($schema);
  54. }
  55. }
  56. function toEdit($typeid){
  57. if($typeid){
  58. $gtype = $this->system->loadModel('goods/gtype');
  59. $aType = $gtype->getTypeDetail($typeid, true);
  60. $_SESSION['gtype'] = $aType;
  61. $_POST['setting'] = $aType['setting'];
  62. $_POST['is_physical'] = $aType['is_physical'];
  63. }
  64. $objGschema = $this->system->loadModel('goods/schema');
  65. $objGschema->dialog($aType['schema_id']);
  66. }
  67. function editType(){
  68. $this->path[] = array('text'=>'????');
  69. $aType = $_SESSION['gtype'];
  70. $this->pagedata['gtype'] = $aType;
  71. $brand = $this->system->loadModel('goods/brand');
  72. foreach($brand->getAll() as $rows){
  73. $aTmpList[$rows['brand_id']] = $rows['brand_name'];
  74. }
  75. $this->pagedata['brands'] = $aTmpList;
  76. $this->page('product/gtype/workpage.html');
  77. }
  78. function toSave(){
  79. if (empty($_POST['name'])){
  80. $this->begin('index.php?ctl=goods/gtype&act=newType');
  81. trigger_error('????????',E_USER_ERROR);
  82. $this->end();
  83. }
  84. if(count($_POST['props']['name']) > 30){
  85. $this->begin('index.php?ctl=goods/gtype&act=newType');
  86. trigger_error('????????30?',E_USER_ERROR);
  87. $this->end();
  88. }
  89. $this->begin('index.php?ctl=goods/gtype&act=index');
  90. $objGtype = $this->system->loadModel('goods/gtype');
  91. if(isset($_SESSION['gtype']['is_physical'])) $_POST['is_physical'] = $_SESSION['gtype']['is_physical'];
  92. if(isset($_SESSION['gtype']['schema_id'])) $_POST['schema_id'] = $_SESSION['gtype']['schema_id'];
  93. if(isset($_SESSION['gtype']['setting'])) $_POST['setting'] = $_SESSION['gtype']['setting'];
  94. if(isset($_SESSION['gtype']['dly_func'])) $_POST['dly_func'] = $_SESSION['gtype']['dly_func'];
  95. if(isset($_SESSION['gtype']['ret_func'])) $_POST['ret_func'] = $_SESSION['gtype']['ret_func'];
  96. if(isset($_SESSION['gtype']['reship'])) $_POST['reship'] = $_SESSION['gtype']['reship'];
  97. if(isset($_SESSION['gtype']['disabled'])) $_POST['disabled'] = $_SESSION['gtype']['disabled'];
  98. if(isset($_SESSION['gtype']['is_def'])) $_POST['is_def'] = $_SESSION['gtype']['is_def'];
  99. //???????? by zhoulei 2011-10-12
  100. $aType = $_SESSION['gtype']['props'];
  101. $bType = $_POST['props']['name'];
  102. //??????key+1
  103. foreach($bType as $k=>$v){
  104. $bType[$k+1] = $v;
  105. }
  106. unset($bType[0]);
  107. $updateKey = $tempKey = $updatestr = array();
  108. foreach ($aType as $ak=>$av){
  109. $bk = array_search($av['name'],$bType);
  110. //???
  111. if ($bk === false){
  112. $updateKey[] = $ak;
  113. }elseif(in_array($_POST['props']['type'][$bk-1],array(0,1))){
  114. $updateKey[] = $ak;
  115. }else{//???
  116. $tempKey[] = $ak;
  117. $bind[$ak] = $bk-1;
  118. }
  119. }
  120. $num = count($bType);
  121. //?????????p_1??
  122. foreach ($tempKey as $k=>$tk){
  123. if($objGtype->getTypeSearch($aType[$tk]['type'],$aType[$tk]['search']) != $_POST['props']['type'][$bind[$tk]]){
  124. $updatestr[] = ' p_'.($k+1).' = NULL ';
  125. }else{
  126. $updatestr[] = ' p_'.($k+1).' = p_'.$tk.' ';
  127. }
  128. }
  129. //??????? ???????
  130. if($num < count($aType)){
  131. $max_key = count($aType);
  132. for($i=0;$i<count($updateKey);$i++){
  133. $updatestr[] = ' p_'.($max_key-$i).' = NULL ';
  134. }
  135. }
  136. $type_id = $_POST['type_id'];
  137. //??????
  138. if($updatestr){
  139. $objGtype->setGoodsProp($updatestr,$type_id);
  140. }
  141. $this->end($objGtype->toSave($_POST), '????');
  142. }
  143. function delete(){
  144. $this->begin('index.php?ctl=goods/gtype&act=index');
  145. $objType = $this->system->loadModel('goods/gtype');
  146. if(is_array($_REQUEST['type_id'])){
  147. foreach($_REQUEST['type_id'] as $id){
  148. $objType->toRemove($id);
  149. }
  150. }else{
  151. $count = 0;
  152. $objType->disabledMark = 'recycle';
  153. $type = $objType->getList('type_id','',0,-1,$count);
  154. if($count > 0){
  155. foreach($type as $v){
  156. $objType->toRemove($v['type_id']);
  157. }
  158. }
  159. }
  160. $objType->checkDefined();
  161. $this->end_only(true);
  162. echo '????';
  163. }
  164. function recycle(){
  165. $objType = $this->system->loadModel('goods/gtype');
  166. $varGoto = 1;
  167. foreach($_REQUEST['type_id'] as $type_id){
  168. if(!$objType->checkDelete($type_id, $result)){
  169. if($result == 1){
  170. echo __('??????????????????');
  171. }
  172. if($result == 2){
  173. echo __('?????????????????');
  174. }
  175. $varGoto = 0;
  176. break;
  177. }
  178. }
  179. if($varGoto){
  180. parent::recycle();
  181. $objType = $this->system->loadModel('goods/gtype');
  182. $objType->checkDefined();
  183. }
  184. }
  185. function fetchProtoTypes($link,$querystring=''){
  186. header('Content-Type: text/html;charset=utf-8');
  187. $network = $this->system->network();
  188. $network->read_timeout = 15;
  189. $network->_fp_timeout = 10;
  190. $cert = $this->system->getConf('certificate.id');
  191. $token = $this->system->getConf('certificate.token');
  192. $sc = md5('goostypefeed'.$cert.$token);
  193. if($network->fetch('http://feed.shopex.cn/goodstype/'.$link.'?certificate='.$cert.'&sc='.$sc.($querystring?'&'.$querystring:''))&&strstr($network->results,'shopexfeed')){
  194. echo $network->results;
  195. }else{
  196. echo '<div style="width:300px;height:80px;"><BR><BR>??????????????????????????<BR>?????...</div><div style="clear:both">';
  197. }
  198. }
  199. function getXml($id){
  200. $o = $this->system->loadModel('goods/gtype');
  201. $xml = $this->system->loadModel('utility/xml');
  202. $xmlpart = $xml->array2xml($o->getTypeObj($id,$name),'goodstype',false);
  203. $charset = $this->system->loadModel('utility/charset');
  204. download($name.'.typ',$xmlpart);
  205. }
  206. function saveSpec(){
  207. $this->begin('index.php?ctl=goods/gtype&act=index');
  208. $objType = $this->system->loadModel('goods/gtype');
  209. $this->end($objType->saveSpec($_POST['type_id'], $_POST['specs']), '????');
  210. }
  211. function checkTypeNameExists(){
  212. $o = $this->system->loadModel('goods/gtype');
  213. if($o->getList('type_id',array('name'=>$_POST['gtypename']))){
  214. echo '<script>alert("???????????????");</script>';
  215. }else{
  216. echo '<script>alert("?????????????????");</script>';
  217. }
  218. }
  219. function fetchSave(){
  220. $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']));
  221. $xml = $this->system->loadModel('utility/xml');
  222. $arr = $xml->xml2array(stripslashes($_POST['xml']));
  223. $gtype = $arr['goodstype'];
  224. $gtype['name'] = $_POST['gtypename'];
  225. $o = $this->system->loadModel('goods/gtype');
  226. $this->end($o->fetchSave($gtype), __('??????'));
  227. }
  228. function filterActions ($row){
  229. $return = $this->actions;
  230. // $return['editType'] = array('target'=>"{update:'main',fm:'addnew'}");
  231. $return['getXml'] = array('link'=>'index.php?ctl=goods/gtype&act=getXml&p[0]='.$row['type_id'],'target'=>'download');
  232. return $return;
  233. }
  234. function import(){
  235. $dataio = &$this->system->loadModel('system/dataio');
  236. $dataio->privateImport = true;
  237. $this->pagedata['importer'] = $dataio->importer($this->ioType);
  238. $this->pagedata['ctl'] = 'goods/gtype';
  239. $this->pagedata['optionsView'] = $this->importOptions;
  240. $this->page('finder/import.html');
  241. }
  242. function importer(){
  243. $this->begin('index.php?ctl=goods/gtype&act=index');
  244. $dataio = $this->system->loadModel('system/dataio');
  245. $gtype = $this->system->loadModel('goods/gtype');
  246. if(substr($_FILES['upload']['name'],-4)!='.typ'){
  247. trigger_error(__('??????'),E_USER_ERROR);
  248. exit;
  249. }
  250. $content = file_get_contents($_FILES['upload']['tmp_name']);
  251. if(substr($content,0,3)=="\xEF\xBB\xBF")
  252. $content = substr($content,3);
  253. $data = $dataio->import_rows($_POST['type'],$content);
  254. $imported = false;
  255. foreach($data as $type){
  256. if($type['name']){
  257. $type['name'] = $type['name'].time();
  258. $gtype->fetchSave($type);
  259. $imported = true;
  260. }
  261. }
  262. if($imported){
  263. $this->end(true,__('????????,???????????'));
  264. }else{
  265. trigger_error(__('????????????????????'),E_USER_ERROR);
  266. }
  267. }
  268. }