PageRenderTime 41ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/b2b/core/model/admin/mdl.adminroles.php

http://phpfor.googlecode.com/
PHP | 223 lines | 164 code | 21 blank | 38 comment | 17 complexity | 72d8e9b72eea8195d2a6572fefbd129a MD5 | raw file
  1. <?php
  2. require_once('shopObject.php');
  3. class mdl_adminroles extends shopObject{
  4. var $idColumn = 'role_id'; //??id??
  5. var $textColumn = 'role_name';
  6. var $defaultCols = 'role_name,role_memo';
  7. var $adminCtl = 'trading/delivery_centers';
  8. var $defaultOrder = array('role_id','desc');
  9. var $tableName = 'sdb_admin_roles';
  10. function getAllActions(){
  11. return array(
  12. '1'=>'??',
  13. '2'=>'??',
  14. '3'=>'??',
  15. '4'=>'????',
  16. '5'=>'????',
  17. '6'=>'????',
  18. '7'=>'????',
  19. '8'=>'???',
  20. '9'=>'????',
  21. '10'=>'???',
  22. );
  23. }
  24. function rolemap(){
  25. return array(
  26. 'goods'=>1,
  27. 'order'=>2,
  28. 'member'=>3,
  29. 'sale'=>4,
  30. 'site'=>5,
  31. 'analytics'=>6,
  32. 'setting'=>7,
  33. 'tools'=>8,
  34. 'distribution'=>9,
  35. 'advance'=>10
  36. );
  37. }
  38. function getColumns(){
  39. return array(
  40. 'role_id'=>array('label'=>'??id','class'=>'span-2'),
  41. 'role_name'=>array('label'=>'????','class'=>'span-4','required'=>1),
  42. 'role_memo'=>array('label'=>'????','class'=>'span-5'),
  43. );
  44. }
  45. function instance($role_id){
  46. $role = parent::instance($role_id);
  47. if($role){
  48. $rows = $this->db->select('select * from sdb_lnk_acts where role_id='.intval($role_id));
  49. foreach($rows as $r){
  50. $role['actions'][] = $r['action_id'];
  51. }
  52. }
  53. //print_r($role);exit;
  54. return $role;
  55. }
  56. /**
  57. * ??????
  58. * @parmar $data ??
  59. * @author yanglish
  60. **/
  61. function update($data,$filter){
  62. $c = parent::update($data,$filter);
  63. if($filter['role_id']){
  64. $role_id = array();
  65. foreach($this->getList('role_id',$filter) as $r){
  66. $role_id[] = $r['role_id'];
  67. }
  68. }else{
  69. $role_id = $filter['role_id'];
  70. }
  71. if(count($role_id)==1){
  72. if ($data['actions']){
  73. //print_r($data['actions']);exit;
  74. $new_date_array = $this->add_new_list($data['actions']);
  75. foreach ($new_date_array as $key => $val){
  76. $action .= $val.",";
  77. }
  78. $action = array_unique(explode(",",rtrim($action,",")));
  79. $new_data = $action;
  80. }else{
  81. $new_data =array();
  82. }
  83. foreach($new_data as $k_key => $k_val){
  84. $delactions[] = "'{$k_val}'";
  85. }
  86. $this->db->exec("delete from sdb_lnk_acts where role_id=".intval($role_id[0]));
  87. if(count($new_data)>0){
  88. $p_action = $this->pro_list($new_data);
  89. //??????????,????????
  90. if (!empty($p_action)){
  91. $new_data = array_merge($p_action,$new_data);
  92. }
  93. $sql = 'REPLACE INTO `sdb_lnk_acts` (`role_id`,`action_id`) VALUES ';
  94. foreach($new_data as $action_id){
  95. $actions[] = "('{$role_id[0]}','$action_id')";
  96. }
  97. $sql .= implode($actions,',').';';
  98. $this->db->exec($sql);
  99. }
  100. }else{
  101. }
  102. return $c;
  103. }
  104. /**
  105. * ????
  106. * @parmar $data ??
  107. * @author yanglish
  108. **/
  109. function insert($data){
  110. //print_r("1111");exit;
  111. $role_id = parent::insert($data);
  112. if($role_id && is_array($data['actions'])){
  113. $new_date = $this->add_new_list($data['actions']);
  114. $sql = 'REPLACE INTO `sdb_lnk_acts` (`role_id`,`action_id`) VALUES ';
  115. foreach($new_date as $key => $val){
  116. $action .= $val.",";
  117. }
  118. $action = explode(",",rtrim($action,","));
  119. $p_action = $this->pro_list($action);
  120. //??????????,????????
  121. if (!empty($p_action)){
  122. $action = array_merge($p_action,$action);
  123. }
  124. foreach ($action as $a_key => $a_val){
  125. $new_action[] = "('$role_id','$a_val')";
  126. }
  127. $sql .= implode($new_action,',').';';
  128. $a = $this->db->exec($sql);
  129. }
  130. return $role_id;
  131. }
  132. /**
  133. * ??????????
  134. * @parmar $List ??
  135. * @author yanglish
  136. **/
  137. function add_new_list($list){
  138. include_once('adminSctl.php');
  139. //error_log(print_r($list,true),3,"d:/2.txt");exit;
  140. $ctl_array = $this->sctl_list($act_config);
  141. foreach ($list as $l_key => $l_val){
  142. if (isset($ctl_array[$l_val])){
  143. $action[] = $ctl_array[$l_val]['binding'];
  144. }
  145. }
  146. //error_log(print_r($action,true),3,"d:/2.txt");exit;
  147. return $action;
  148. }
  149. /**
  150. * ??????
  151. * @parmar $List ??
  152. * @author yanglish
  153. **/
  154. function sctl_list($list){
  155. foreach ($list as $l_key =>$l_val){
  156. if (empty($l_val['name'])){
  157. unset($list[$l_key]);
  158. }else{
  159. foreach ($l_val['op'] as $ll_k => $ll_v){
  160. if (empty($ll_v['name'])){
  161. unset($list[$l_key]['op'][$ll_k]);
  162. }
  163. }
  164. $new_list[] = $list[$l_key]['op'];
  165. }
  166. }
  167. $all_val=array();
  168. foreach ($new_list as $t_k => $t_v){
  169. $all_val=$all_val+$t_v;
  170. }
  171. return $all_val;
  172. }
  173. /**
  174. * ???????????/????/????/???? ?????????
  175. * ?????????????????????????? ?????????? hanxuefei 2010-12-24 18:28
  176. * @parmar $List ??
  177. * @author yanglish
  178. **/
  179. function pro_list($list){
  180. $new_list = array();
  181. if (array_search("goods/product-edit-price",$list) && array_search("goods/product-edit-info",$list) && array_search("goods/product-recycle",$list) && array_search("goods/product-edit-repertory",$list)){
  182. $new_list = array('goods/product-editMode','goods/product-batchEdit','goods/product-renTag','goods/product-delTag','goods/product-tagmgr','goods/product-newTag','goods/product-setTag','goods/product-saveBatchEdit','goods/product-prefilter','goods/product-saveValue','goods/product-saveColSet','goods/product-goodsAlert','goods/product-show','goods/product-virtualcat','goods/product-filter','goods/product-nospec','goods/product-getWholeSaleList','goods/product-clone_goods_img','goods/product-update','goods/product-toRemove','goods/product-enable','goods/product-disable','goods/product-sendNotify','goods/product-setOrder','goods/product-ratelist','goods/product-checkItem','goods/product-editItem','goods/product-getGoodsSpec','goods/product-view_src_img','goods/product-newPic','goods/product-removePic','goods/product-taobaocsv','goods/product-export_taobao_img','goods/product-updateSupplierData','goods/product-batchEdit','goods/product-singleBatchEdit','goods/product-batchImage','goods/product-nextImage','goods/product-apply_wholesale','goods/product-do_apply_wholesale','goods/product-check_bn_repeate','goods/product-nextSaveBatchEdit','goods/product-nextSaveBatchEable','goods/product-import','goods/product-importer');
  183. }
  184. return $new_list;
  185. }
  186. /**
  187. * ??????
  188. * @parmar $List ??
  189. * @author yanglish
  190. **/
  191. function deladmin($list){
  192. $sSql = 'DELETE FROM sdb_lnk_acts WHERE';
  193. $sql = 'DELETE FROM sdb_admin_roles WHERE';
  194. if(count($list)>0){
  195. $sSql .= ' role_id IN ('.implode(',',$list).')';
  196. $sql .= ' role_id IN ('.implode(',',$list).')';
  197. $this->db->exec($sql);
  198. return $this->db->exec($sSql);
  199. }
  200. return false;
  201. }
  202. }