viewModel.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. <?php
  2. class viewClassModel extends Model
  3. {
  4. private $modeid = 0;
  5. private $isflow = 0;
  6. private $ursarr = array();
  7. private $addb,$whereobj,$urs,$modrs;
  8. public function initModel()
  9. {
  10. $this->settable('flow_extent');
  11. $this->addb = m('admin');
  12. $this->whereobj = m('where');
  13. }
  14. private function getursss($mid, $uid=0)
  15. {
  16. if($uid==0)$uid = $this->adminid;
  17. if(isset($this->ursarr[$uid])){
  18. $this->urs = $this->ursarr[$uid];
  19. }else{
  20. $this->urs = $this->db->getone('[Q]admin',$uid);
  21. $this->ursarr[$uid] = $this->urs;
  22. }
  23. if(is_array($mid)){
  24. $this->modrs = $mid;
  25. }else{
  26. $this->modrs = $this->db->getone('[Q]flow_set'," (`id`='$mid' or `num`='$mid')");
  27. }
  28. if($this->modrs){
  29. $this->modeid = $this->modrs['id'];
  30. $this->isflow = $this->modrs['isflow'];
  31. }
  32. }
  33. //返回可查看条件
  34. public function viewwhere($mid, $uid=0, $ufid='', $glx=0)
  35. {
  36. $this->getursss($mid, $uid);
  37. return $this->getsswhere(0, $ufid, $glx);
  38. }
  39. //获取禁看字段的权限
  40. public function viewjinfields($mid, $uid=0, $ufid='')
  41. {
  42. $this->getursss($mid, $uid);
  43. $rows = $this->getsswhere(6, $ufid);
  44. return $rows;
  45. }
  46. //是否有新增权限
  47. public function isadd($mid, $uid=0)
  48. {
  49. $this->getursss($mid, $uid);
  50. $bo = false;
  51. $type = $this->urs['type'];
  52. if($type==1)return true; //管理员有添加
  53. $bo = $this->getsswhere(1);
  54. return $bo;
  55. }
  56. //是否有导入权限
  57. public function isdaoru($mid, $uid=0)
  58. {
  59. $this->getursss($mid, $uid);
  60. $bo = $this->getsswhere(4);
  61. return $bo;
  62. }
  63. //是否有导出权限
  64. public function isdaochu($mid, $uid=0)
  65. {
  66. $this->getursss($mid, $uid);
  67. $bo = $this->getsswhere(5);
  68. return $bo;
  69. }
  70. //返回编辑数据权限sql条件
  71. public function editwhere($mid, $uid=0, $ufid='')
  72. {
  73. $this->getursss($mid, $uid);
  74. return $this->getsswhere(2,$ufid);
  75. }
  76. //返回删除数据权限sql条件
  77. public function deletewhere($mid, $uid=0, $ufid='')
  78. {
  79. $this->getursss($mid, $uid);
  80. return $this->getsswhere(3,$ufid);
  81. }
  82. //$type类型0查看,1新增 $ufid 用户ID $glx0返回类型
  83. private function getsswhere($type, $ufid='', $glx=0)
  84. {
  85. $mid = $this->modeid;
  86. $where = $this->addb->getjoinstr('receid', $this->urs);
  87. if($ufid=='')$ufid = 'uid';
  88. $uid = $this->urs['id'];
  89. $companyid = arrvalue($this->urs, 'companyid','0');
  90. $rows = $this->getall('`modeid`='.$mid.' and `type`='.$type.' and `status`=1 '.$where.'','wherestr,whereid,fieldstr');
  91. $wehs = array();
  92. $count = $this->db->count;
  93. if($type==1 || $type==4 || $type==5){
  94. return $count>0;
  95. }
  96. $qomss = ($glx==0)?'':'{asqom}';
  97. if($type== 0 && $count==0 && $this->isflow>0){
  98. $rows[] = array(
  99. 'wherestr'=>$this->rock->jm->base64encode('`uid`={uid}'),
  100. 'whereid'=>0,
  101. 'fieldstr'=>''
  102. );
  103. }
  104. foreach($rows as $k=>$rs){
  105. $sw = $this->rock->jm->base64decode($rs['wherestr']);
  106. if($sw=='{receid}'){
  107. $sw = $this->addb->getjoinstr('receid', $this->urs, 1);
  108. }
  109. //我所有下属的下属
  110. if($sw=='{allsuper}'){
  111. $sw = "`$ufid` in(select `id` from `[Q]admin` where instr(`superpath`,'[$uid]')>0)";
  112. }
  113. //我的直属下属
  114. if($sw=='{super}'){
  115. $sw1= $this->rock->dbinstr('superid',$uid);
  116. $sw = "`$ufid` in(select `id` from `[Q]admin` where $sw1)";
  117. }
  118. //同一个部门下人员
  119. if($sw=='{dept}' && !isempt($this->urs['deptid'])){
  120. $sw = "`$ufid` in(select `id` from `[Q]admin` where `deptid`=".$this->urs['deptid'].")";
  121. }
  122. //同一个部门下人员(包括子部门)
  123. if($sw=='{deptall}' && !isempt($this->urs['deptid'])){
  124. $sw = "`$ufid` in(select `id` from `[Q]admin` where instr(`deptpath`,'[".$this->urs['deptid']."]')>0)";
  125. }
  126. //同一个单位
  127. if($sw=='{company}'){
  128. $sw = "`$ufid` in(select `id` from `[Q]admin` where `companyid`=".$companyid.")";
  129. }
  130. //所有数据
  131. if($sw=='all'){
  132. if($type==6){
  133. $rows[$k]['wherestr'] = '';
  134. continue;
  135. }
  136. return ' and 1=1';
  137. }
  138. if(!isempt($sw)){
  139. $sw = $this->whereobj->getstrwhere($sw, $uid, $ufid);
  140. $sw = str_replace('{asqom}', $qomss, $sw);
  141. $rows[$k]['wherestr'] = '('.$sw.')';
  142. }
  143. $whereid = (int)$rs['whereid'];
  144. if($whereid>0){
  145. $sww = $this->whereobj->getwherestr($whereid, $uid, $ufid, 1);
  146. if($sww!=''){
  147. if(!isempt($sw))$sw.=' and';
  148. $sw.= ' '.$sww;
  149. $rows[$k]['wherestr2'] = '('.$sww.')';
  150. }
  151. }
  152. if(!isempt($sw))$wehs[] = '('.$sw.')';
  153. }
  154. if($type==6)return $rows;//禁看类型字段
  155. $s = join(' or ', $wehs);
  156. if($s!=''){
  157. $s = ' and ('.$s.')';
  158. }else{
  159. $s = ' and 1=2';
  160. }
  161. return $s;
  162. }
  163. //读取记录
  164. public function getjilu($uid, $type=7)
  165. {
  166. $where = $this->addb->getjoinstr('receid', $uid);
  167. $rows = $this->getall("`status`=1 and `type`='$type' $where ");
  168. return $rows;
  169. }
  170. ////返回流程监控权限sql条件
  171. public function jiankongwhere($mid, $uid=0, $ufid='')
  172. {
  173. $this->getursss($mid, $uid);
  174. return $this->getsswhere(7, $ufid);
  175. }
  176. }
粤ICP备19079148号