deptAction.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <?php
  2. class deptClassAction extends Action
  3. {
  4. private $allid,$rows;
  5. public function defaultAction()
  6. {
  7. }
  8. public function dataAjax()
  9. {
  10. $carr = m('admin')->getcompanyinfo(0,5);
  11. $this->allid= $carr['companyallid'];
  12. $this->rows = array();
  13. $this->getdept(0, 1);
  14. $errmsg = '';
  15. if(ISMORECOM){
  16. foreach($this->rows as $k1=>$rs1){
  17. if($rs1['companyname']=='' && $rs1['level']==2){
  18. $this->rows[$k1]['trbgcolor']='red';
  19. $errmsg = '1';
  20. }
  21. }
  22. if($errmsg=='1')$errmsg='红色行必须选择所属单位,请编辑';
  23. }
  24. echo json_encode(array(
  25. 'totalCount'=> 0,
  26. 'rows' => $this->rows,
  27. 'carr' => $carr,
  28. 'errmsg' => $errmsg
  29. ));
  30. }
  31. private function getdept($pid, $oi)
  32. {
  33. $db = m('dept');
  34. $menu = $db->getall("`pid`='$pid' order by `sort`",'*');
  35. foreach($menu as $k=>$rs){
  36. $comid = $rs['companyid'];
  37. //开启单位模式只能看到自己单位下的组织结构
  38. if(!in_array($comid, $this->allid) && $this->adminid>1 && getconfig('companymode'))continue;
  39. $companyname = '';
  40. if($comid>0 && getconfig('companymode'))$companyname = m('company')->getmou('name', $comid);
  41. $rs['companyname'] = $companyname;
  42. $sid = $rs['id'];
  43. $rs['level'] = $oi;
  44. $rs['stotal'] = $db->rows("`pid`='$sid'");
  45. $this->rows[] = $rs;
  46. $this->getdept($sid, $oi+1);
  47. }
  48. }
  49. public function publicbeforesave($table, $cans, $id)
  50. {
  51. $pid = (int)$cans['pid'];
  52. if($pid<=0 && $id != 1)return '上级ID必须大于0';
  53. if($pid!=0 && $id == 1)return '顶级禁止修改上级ID';
  54. if($pid!=0 && m($table)->rows('id='.$pid.'')==0)return '上级ID不存在';
  55. return '';
  56. }
  57. public function publicaftersave($table, $cans, $id)
  58. {
  59. $name = $cans['name'];
  60. $db = m('admin');
  61. $db->update("deptname='$name'", "`deptid`=$id");
  62. $db->updateinfo("and instr(a.`deptpath`,'[$id]')>0");
  63. }
  64. public function deptuserdataAjax()
  65. {
  66. $type = $this->request('changetype');
  67. $val = $this->request('value');
  68. $pid = 0;
  69. $rows = $this->getdeptmain($pid, $type, ','.$val.',');
  70. echo json_encode($rows);
  71. }
  72. private function getdeptmain($pid, $type, $val)
  73. {
  74. $sql = $this->stringformat('select `id`,`name` from `?0` where `pid`=?1 order by `sort`', array($this->T('dept'), $pid));
  75. $arr = $this->db->getall($sql);
  76. $rows = array();
  77. foreach($arr as $k=>$rs){
  78. $children = $this->getdeptmain($rs['id'], $type, $val);
  79. $uchek = $this->contain($type, 'check');
  80. $expanded = false;
  81. if($this->contain($type, 'user')){
  82. $sql = $this->stringformat('select `id`,`name`,`sex`,`ranking`,`deptname` from `?0` where `deptid`=?1 and `status`=1 order by `sort`', array($this->T('admin'), $rs['id']));
  83. $usarr = $this->db->getall($sql);
  84. foreach($usarr as $k1=>$urs){
  85. $usarr[$k1]['leaf'] = true;
  86. $usarr[$k1]['uid'] = $urs['id'];
  87. $usarr[$k1]['id'] = 'u'.$urs['id'];
  88. $usarr[$k1]['type'] = 'u';
  89. $usarr[$k1]['icons'] = 'user';
  90. if($uchek){
  91. $bo = false;
  92. if($this->contain($type, 'dept')){
  93. $bo = $this->contain($val, $usarr[$k1]['id']);
  94. }else{
  95. $bo = $this->contain($val, $usarr[$k1]['uid']);
  96. }
  97. $usarr[$k1]['checked']=$bo;
  98. if(!$expanded)$expanded = $bo;
  99. }
  100. }
  101. $children= array_merge($children, $usarr);
  102. }
  103. if($pid==0)$expanded = true;
  104. $ars['children']= $children;
  105. $ars['name'] = $rs['name'];
  106. $ars['id'] = 'd'.$rs['id'];
  107. $ars['did'] = $rs['id'];
  108. $ars['type'] = 'd';
  109. $ars['expanded'] = $expanded;
  110. if($this->contain($type, 'dept')){
  111. if($uchek){
  112. $bo = false;
  113. if($this->contain($type, 'user')){
  114. $bo = $this->contain($val, $ars['id']);
  115. }else{
  116. $bo = $this->contain($val, $ars['did']);
  117. }
  118. $ars['checked']=$bo;
  119. }
  120. }
  121. $rows[] = $ars;
  122. }
  123. return $rows;
  124. }
  125. public function deptuserjsonAjax()
  126. {
  127. $udarr = m('dept')->getdeptuserdata(1);
  128. $bool = false;
  129. if(!ISMORECOM && !$udarr['uarr'] && $udarr['isall']){
  130. $udarrs = c('cache')->get('deptuserjson');
  131. if($udarrs)$udarr = $udarrs;
  132. $bool = true;
  133. }
  134. $userarr = $udarr['uarr'];
  135. $deptarr = $udarr['darr'];
  136. $grouparr = $udarr['garr'];
  137. $arr['deptjson'] = json_encode($deptarr);
  138. $arr['userjson'] = json_encode($userarr);
  139. $arr['groupjson'] = json_encode($grouparr);
  140. $arr['iscache'] = getconfig('usercache');
  141. if(!ISMORECOM && $udarr['isall'] && !$bool)c('cache')->set('deptuserjson', $udarr);
  142. $this->showreturn($arr);
  143. }
  144. }
粤ICP备19079148号