viewModel.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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. //返回禁看处理记录sql条件
  83. public function jkcljlwhere($mid, $uid=0, $ufid='')
  84. {
  85. $this->getursss($mid, $uid);
  86. return $this->getsswhere(8,$ufid);
  87. }
  88. //返回禁看查阅记录sql条件
  89. public function jkcyjlwhere($mid, $uid=0, $ufid='')
  90. {
  91. $this->getursss($mid, $uid);
  92. return $this->getsswhere(9,$ufid);
  93. }
  94. //$type类型0查看,1新增 $ufid 用户ID $glx0返回类型
  95. private function getsswhere($type, $ufid='', $glx=0)
  96. {
  97. $mid = $this->modeid;
  98. $where = $this->addb->getjoinstr('receid', $this->urs);
  99. if($ufid=='')$ufid = 'uid';
  100. $uid = arrvalue($this->urs, 'id','0');;
  101. $companyid = arrvalue($this->urs, 'companyid','0');
  102. $rows = $this->getall('`modeid`='.$mid.' and `type`='.$type.' and `status`=1 '.$where.'','wherestr,whereid,fieldstr');
  103. $wehs = array();
  104. $count = $this->db->count;
  105. if($type==1 || $type==4 || $type==5){
  106. return $count>0;
  107. }
  108. $qomss = ($glx==0)?'':'{asqom}';
  109. if($type== 0 && $count==0 && $this->isflow>0){
  110. $rows[] = array(
  111. 'wherestr'=>$this->rock->jm->base64encode('`uid`={uid}'),
  112. 'whereid'=>0,
  113. 'fieldstr'=>''
  114. );
  115. }
  116. foreach($rows as $k=>$rs){
  117. $sw = $this->rock->jm->base64decode($rs['wherestr']);
  118. if($sw=='{receid}'){
  119. $sw = $this->addb->getjoinstr('receid', $this->urs, 1);
  120. }
  121. //我所有下属的下属
  122. if($sw=='{allsuper}'){
  123. $sw = "`$ufid` in(select `id` from `[Q]admin` where instr(`superpath`,'[$uid]')>0)";
  124. }
  125. //我的直属下属
  126. if($sw=='{super}'){
  127. $sw1= $this->rock->dbinstr('superid',$uid);
  128. $sw = "`$ufid` in(select `id` from `[Q]admin` where $sw1)";
  129. }
  130. //同一个部门下人员
  131. if($sw=='{dept}' && !isempt($this->urs['deptid'])){
  132. $sw = "`$ufid` in(select `id` from `[Q]admin` where `deptid`=".$this->urs['deptid'].")";
  133. }
  134. //同一个部门下人员(包括子部门)
  135. if($sw=='{deptall}' && !isempt($this->urs['deptid'])){
  136. $sw = "`$ufid` in(select `id` from `[Q]admin` where instr(`deptpath`,'[".$this->urs['deptid']."]')>0)";
  137. }
  138. //同一个单位
  139. if($sw=='{company}'){
  140. $sw = "`$ufid` in(select `id` from `[Q]admin` where `companyid`=".$companyid.")";
  141. }
  142. //所有数据
  143. if($sw=='all'){
  144. if($type==6){
  145. $rows[$k]['wherestr'] = '';
  146. continue;
  147. }
  148. return ' and 1=1';
  149. }
  150. if(!isempt($sw)){
  151. $sw = $this->whereobj->getstrwhere($sw, $uid, $ufid);
  152. $sw = str_replace('{asqom}', $qomss, $sw);
  153. $rows[$k]['wherestr'] = '('.$sw.')';
  154. }
  155. $whereid = (int)$rs['whereid'];
  156. if($whereid>0){
  157. $sww = $this->whereobj->getwherestr($whereid, $uid, $ufid, 1);
  158. if($sww!=''){
  159. if(!isempt($sw))$sw.=' and';
  160. $sw.= ' '.$sww;
  161. $rows[$k]['wherestr2'] = '('.$sww.')';
  162. }
  163. }
  164. if(!isempt($sw))$wehs[] = '('.$sw.')';
  165. }
  166. if($type==6)return $rows;//禁看类型字段
  167. $s = join(' or ', $wehs);
  168. if($s!=''){
  169. $s = ' and ('.$s.')';
  170. }else{
  171. $s = ' and 1=2';
  172. }
  173. return $s;
  174. }
  175. //读取记录
  176. public function getjilu($uid, $type=7)
  177. {
  178. $where = $this->addb->getjoinstr('receid', $uid);
  179. $rows = $this->getall("`status`=1 and `type`='$type' $where ");
  180. return $rows;
  181. }
  182. ////返回流程监控权限sql条件
  183. public function jiankongwhere($mid, $uid=0, $ufid='')
  184. {
  185. $this->getursss($mid, $uid);
  186. return $this->getsswhere(7, $ufid);
  187. }
  188. }
粤ICP备19079148号