viewModel.php 5.0 KB

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