PageRenderTime 32ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/aoliz/core/model/admin/mdl.operator.php

http://phpfor.googlecode.com/
PHP | 200 lines | 160 code | 22 blank | 18 comment | 20 complexity | 9646a72e0f97d56dd84bb5347ecf39df MD5 | raw file
  1. <?php
  2. /**
  3. * mdl_operator
  4. *
  5. * @uses modelFactory
  6. * @package
  7. * @version $Id: mdl.operator.php 1985 2008-04-28 06:36:02Z flaboy $
  8. * @copyright 2003-2007 ShopEx
  9. * @author Likunpeng <leoleegood@zovatech.com>
  10. * @license Commercial
  11. */
  12. include_once('shopObject.php');
  13. class mdl_operator extends shopObject{
  14. var $idColumn = 'op_id';
  15. var $textColumn = 'username';
  16. var $defaultCols = 'username,name,lastlogin,department,status,logincount,roles';
  17. var $adminCtl = 'admin/operator';
  18. var $defaultOrder = array('op_id', 'DESC');
  19. var $tableName = 'sdb_operators';
  20. function getColumns(){
  21. $ret = array('_cmd'=>array('label'=>__('??'),'width'=>75,'html'=>'admin/finder_command.html'),'roles'=>array('label'=>__('??'),'sql'=>'op_id','width'=>270,'readonly'=>1));
  22. return array_merge($ret,parent::getColumns());
  23. }
  24. function modifier_roles(&$rows){
  25. $role_list = $this->db->select('select l.op_id,r.role_name
  26. from sdb_lnk_roles l
  27. left join sdb_admin_roles r on r.role_id=l.role_id
  28. where l.op_id in('.implode(',',$rows).') and r.disabled!="true"');
  29. $rst = array();
  30. foreach($role_list as $r){
  31. $rst[$r['op_id']][] = $r['role_name'];
  32. }
  33. foreach($rows as $k=>$r){
  34. $rows[$k] = is_array($rst[$k])?(implode(',',$rst[$k])):'';
  35. }
  36. }
  37. function delete($filter,$current_op_id=false){
  38. if(method_exists($this,'pre_delete')){
  39. $this->pre_delete($filter);
  40. }
  41. if(method_exists($this,'post_delete')){
  42. $this->post_delete($filter);
  43. }
  44. $this->disabledMark = 'normal';
  45. $sql = 'delete from '.$this->tableName.' where '.$this->_filter($filter);
  46. if($current_op_id){
  47. $sql.=' and op_id != '.intval($current_op_id);
  48. }
  49. if($this->db->exec($sql)){
  50. if($this->db->affect_row()){
  51. return $this->db->affect_row();
  52. }else{
  53. return true;
  54. }
  55. }else{
  56. return false;
  57. }
  58. }
  59. function getUsedRoles($op_id){
  60. $rows = $this->db->select('select role_id from sdb_lnk_roles where op_id='.intval($op_id));
  61. foreach($rows as $r){
  62. $rtn[$r['role_id']] = $r['role_id'];
  63. }
  64. return $rtn;
  65. }
  66. function update($data,$filter){
  67. if(isset($data['userpass'])){
  68. $data['userpass'] = md5($data['userpass']);
  69. }
  70. $c = parent::update($data,$filter);
  71. if(!isset($data['roles'])){
  72. return $c;
  73. }
  74. if($filter['op_id']){
  75. $op_id = array();
  76. foreach($this->getList('op_id',$filter) as $r){
  77. $op_id[] = $r['op_id'];
  78. }
  79. }else{
  80. $op_id = $filter['op_id'];
  81. }
  82. if(count($op_id)==1){
  83. $rows = $this->db->select('select role_id from sdb_lnk_roles where op_id in ('.implode(',',$op_id).')');
  84. $in_db = array();
  85. foreach($rows as $r){
  86. $in_db[] = $r['role_id'];
  87. }
  88. $to_add = array_diff($data['roles'],$in_db);
  89. $to_del = array_diff($in_db,$data['roles']);
  90. if(count($to_add)>0){
  91. $sql = 'INSERT INTO `sdb_lnk_roles` (`op_id`,`role_id`) VALUES ';
  92. foreach($to_add as $role_id){
  93. $actions[] = "({$op_id[0]},$role_id)";
  94. }
  95. $sql .= implode($actions,',').';';
  96. $a = $this->db->exec($sql);
  97. }
  98. if(count($to_del)>0){
  99. $this->db->exec('delete from sdb_lnk_roles where role_id in ('.implode(',',$to_del).') and op_id='.intval($op_id[0]));
  100. }
  101. }else{
  102. }
  103. return $c;
  104. }
  105. function insert($data){
  106. $data['userpass'] = md5(trim($data['userpass']));
  107. $op_id = parent::insert($data);
  108. if($op_id && is_array($data['roles']) && isset($data['roles'][0])){
  109. $sql = 'INSERT INTO `sdb_lnk_roles` (`op_id`,`role_id`) VALUES ';
  110. foreach($data['roles'] as $role_id){
  111. $roles[] = "($op_id,$role_id)";
  112. }
  113. $sql .= implode($roles,',').';';
  114. $a = $this->db->exec($sql);
  115. }
  116. return $op_id;
  117. }
  118. function tryLogin($aValue,$issuper=false){
  119. if($aValue['passwd']=='+_-_-_+'){
  120. $aValue['passwd']='';
  121. }
  122. $sql = "SELECT * FROM sdb_operators WHERE username = ".$this->db->quote($aValue['usrname'])." AND userpass = '".md5($aValue['passwd'])."' AND disabled='false'";
  123. if($issuper){
  124. $sql.=" AND super='1'";
  125. }
  126. return $this->db->selectrow($sql);
  127. }
  128. /**
  129. * toUpdateSelf
  130. *
  131. * @param mixed $aValue,$aSetting
  132. * @access public
  133. * @return array
  134. */
  135. //+
  136. function toUpdateSelf($aValue,$aSetting){
  137. $aSetting['lang'] = $aValue['language'];
  138. $aSetting['timezone'] = $aValue['timezone'];
  139. $aValue['config'] = $aSetting;
  140. if(isset($aValue['userpass'])){
  141. $aValue['userpass'] = md5($aValue['userpass']);
  142. }
  143. $aRs = $this->db->query("SELECT * FROM sdb_operators WHERE op_id=".$aValue['op_id']);
  144. $sSql = $this->db->GetUpdateSql($aRs,$aValue);
  145. return !$sSql || $this->db->exec($sSql);
  146. }
  147. function check_role($op_id,$workground){
  148. if(!$workground)return true;
  149. $role = &$this->system->loadModel('admin/adminroles');
  150. $opt = $role->rolemap();
  151. $r = $this->db->selectrow('SELECT a.action_id
  152. FROM sdb_lnk_roles s
  153. INNER JOIN sdb_lnk_acts a ON a.role_id=s.role_id
  154. where op_id='.intval($op_id).' and action_id='.intval($opt[$workground]));
  155. return $r;
  156. }
  157. function &getActions($op_id){
  158. if(!isset($this->actmap[$op_id])){
  159. $allow_wground = array();
  160. $sql = 'SELECT distinct(a.action_id)
  161. FROM sdb_lnk_roles s
  162. INNER JOIN sdb_admin_roles r ON r.role_id=s.role_id AND r.disabled!="true"
  163. LEFT JOIN sdb_lnk_acts a ON a.role_id=r.role_id
  164. where s.op_id='.intval($op_id);
  165. foreach($this->db->select($sql) as $r){
  166. $allow_wground[$r['action_id']] = $r['action_id'];
  167. }
  168. $this->actmap[$op_id] = &$allow_wground;
  169. }
  170. return $this->actmap[$op_id];
  171. }
  172. function setLogInfo($data,$op_id){
  173. $rs=$this->db->exec('select lastlogin,logincount from sdb_operators where op_id='.intval($op_id));
  174. $sSql=$this->db->getUpdateSql($rs,$data);
  175. $this->db->exec($sSql);
  176. }
  177. }
  178. ?>