flowAction.php 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616
  1. <?php
  2. class flowClassAction extends Action
  3. {
  4. public function loaddataAjax()
  5. {
  6. $id = (int)$this->get('id');
  7. $data = m('flow_set')->getone($id);
  8. $arr = array(
  9. 'data' => $data
  10. );
  11. echo json_encode($arr);
  12. }
  13. public function modeafter($table, $rows)
  14. {
  15. return array(
  16. 'qian' => PREFIX
  17. );
  18. }
  19. public function modebefore($table)
  20. {
  21. $where = '';
  22. $key = $this->post('key');
  23. if(!isempt($key)){
  24. $where = "and (`type`='$key' or `name` like '%$key%' or `table` like '$key%' or `num` like '$key%' or `sericnum` like '$key%')";
  25. }
  26. return $where;
  27. }
  28. public function getcompanydataAjax()
  29. {
  30. $rows = array();
  31. $msg = '';
  32. if(!getconfig('platdwnum')){
  33. $msg = '当前不是SAAS模式不需要操作';
  34. }else{
  35. if(!COMPANYNUM){
  36. $rows = m('company')->getall('`iscreate`=1','id,name');
  37. if(!$rows)$msg='没有创建过任何单位';
  38. }else{
  39. $msg = '请在管理模式下操作';
  40. }
  41. }
  42. return returnsuccess($rows, $msg);
  43. }
  44. public function flowwheresave_before($table,$das)
  45. {
  46. $str = m('where')->checkwhere($das['setid'], $das['wheresstr']);
  47. if($str)return $str;
  48. }
  49. public function flowmenusave_before($table,$das)
  50. {
  51. $str = m('where')->checkwhere($das['setid'], $das['wherestr']);
  52. if($str)return $str;
  53. }
  54. private function getwherelist($setid)
  55. {
  56. return m('flow_where')->getall('setid='.$setid.'','id,name','sort');
  57. }
  58. public function loaddatacourseAjax()
  59. {
  60. $id = (int)$this->get('id');
  61. $setid = (int)$this->get('setid');
  62. $data = m('flow_course')->getone($id);
  63. $arr = array(
  64. 'data' => $data,
  65. 'wherelist' => $this->getwherelist($setid),
  66. 'statusstr' => m('flow_set')->getmou('statusstr', $setid)
  67. );
  68. echo json_encode($arr);
  69. }
  70. public function loaddatawhereAjax()
  71. {
  72. $id = (int)$this->get('id');
  73. $data = m('flow_where')->getone($id);
  74. $arr = array(
  75. 'data' => $data,
  76. );
  77. echo json_encode($arr);
  78. }
  79. public function flowsetsavebefore($table, $cans)
  80. {
  81. $tab = $cans['table'];
  82. $tabs= trim($cans['tables']);
  83. $names= trim($cans['names']);
  84. $name= $this->rock->xssrepstr($cans['name']);
  85. $num = strtolower($cans['num']);
  86. $cobj= c('check');
  87. if(!$cobj->iszgen($tab))return '表名格式不对';
  88. if($cobj->isnumber($num))return '编号不能为数字';
  89. if(strlen($num)<4)return '编号至少要4位';
  90. if($cobj->isincn($num))return '编号不能包含中文';
  91. if(contain($num,'-'))return '编号不能有-';
  92. if($cans['isflow']>0 && isempt($cans['sericnum'])) return '有流程必须有写编号规则,请参考其他模块填写';
  93. $rows['num']= $this->rock->xssrepstr($num);
  94. $rows['name']= $name;
  95. if(!isempt($tabs)){
  96. if($cobj->isincn($tabs))return '多行子表名不能包含中文';
  97. $tabsa = explode(',', $tabs);
  98. $namea = explode(',', $names);
  99. foreach($tabsa as $k1=>$tabsas){
  100. if(isempt($tabsas))return '多行子表名('.$tabs.')不规范';
  101. if(isempt(arrvalue($namea, $k1)))return '第'.($k1+1).'个多行子表名称必须填写';
  102. }
  103. }
  104. $rows['tables']= $tabs;
  105. return array(
  106. 'rows' => $rows
  107. );
  108. }
  109. private function setsubtsta($tabs, $alltabls, $tab, $slxbo, $ssm)
  110. {
  111. if(isempt($tabs))return;
  112. if(!in_array(''.PREFIX.''.$tabs.'', $alltabls)){
  113. $sql = "CREATE TABLE `[Q]".$tabs."` (
  114. `id` int(11) NOT NULL AUTO_INCREMENT,
  115. `mid` int(11) DEFAULT '0' COMMENT '对应主表".$tab.".id',
  116. `sort` int(11) DEFAULT '0' COMMENT '排序号',
  117. `comid` smallint(6) DEFAULT '0' COMMENT '对应单位id',
  118. PRIMARY KEY (`id`),KEY `mid` (`mid`)
  119. ) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;";
  120. $bo = $this->db->query($sql);
  121. }else{
  122. $fields = $this->db->getallfields(''.PREFIX.''.$tabs.'');
  123. $str = '';
  124. if(!in_array('mid', $fields))$str.=",add `mid` int(11) DEFAULT '0' COMMENT '对应主表".$tab.".id'";
  125. if(!in_array('sort', $fields))$str.=",add `sort` int(11) DEFAULT '0' COMMENT '排序号'";
  126. if(!in_array('comid', $fields))$str.=",add `comid` smallint(6) DEFAULT '0' COMMENT '对应单位id'";
  127. if($slxbo && !in_array('sslx', $fields)){
  128. $ssma = explode(',', $ssm);
  129. $ss1 = '';
  130. foreach($ssma as $k=>$ssmas)$ss1.=','.$k.''.$ssmas.'';
  131. if($ss1!='')$ss1 = substr($ss1, 1);
  132. $str.=",add `sslx` tinyint(1) DEFAULT '0' COMMENT '".$ss1."'";
  133. }
  134. if($str!=''){
  135. $sql = 'alter table `'.PREFIX.''.$tabs.'` '.substr($str,1).'';
  136. $this->db->query($sql);
  137. }
  138. }
  139. }
  140. public function flowsetsaveafter($table, $cans)
  141. {
  142. $isflow = $cans['isflow'];
  143. $name = $cans['name'];
  144. $tab = $cans['table'];
  145. $tabs = $cans['tables'];
  146. $alltabls = array();
  147. //创建保存多行子表
  148. if(!isempt($tabs)){
  149. $alltabls = $this->db->getalltable();
  150. $tabsa = explode(',', $tabs);
  151. $addsts = array();
  152. foreach($tabsa as $tabsas){
  153. $this->setsubtsta($tabsas, $alltabls, $tab, in_array($tabsas, $addsts), $cans['names']);
  154. $alltabls[] = ''.PREFIX.''.$tabsas.'';
  155. $addsts[] = $tabsas;
  156. }
  157. }
  158. if(isempt($tab))return;
  159. if(!$alltabls)$alltabls = $this->db->getalltable();
  160. if($isflow==0){
  161. if(!in_array(''.PREFIX.''.$tab.'', $alltabls)){
  162. $sql = "CREATE TABLE `[Q]".$tab."` (`id` int(11) NOT NULL AUTO_INCREMENT,`comid` smallint(6) DEFAULT '0' COMMENT '对应单位id',`uid` int(11) DEFAULT '0',`optid` int(11) DEFAULT '0' COMMENT '操作人id',`optname` varchar(20) DEFAULT NULL COMMENT '操作人',`optdt` datetime DEFAULT NULL COMMENT '操作时间',PRIMARY KEY (`id`))ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COMMENT='$name';";
  163. $bo = $this->db->query($sql);
  164. }else{
  165. $fields = $this->db->getallfields(''.PREFIX.''.$tab.'');
  166. $str = '';
  167. if(!in_array('comid', $fields) && !in_array('companyid', $fields))$str.=",add `comid` smallint(6) DEFAULT '0' COMMENT '对应单位id'";
  168. if($str!=''){
  169. $sql = 'alter table `'.PREFIX.''.$tab.'` '.substr($str,1).'';
  170. $this->db->query($sql);
  171. }
  172. }
  173. return;
  174. }
  175. if(!in_array(''.PREFIX.''.$tab.'', $alltabls)){
  176. $sql = "CREATE TABLE `[Q]".$tab."` (
  177. `id` int(11) NOT NULL AUTO_INCREMENT,
  178. `uid` int(11) DEFAULT '0',
  179. `optdt` datetime DEFAULT NULL COMMENT '操作时间',
  180. `optid` int(11) DEFAULT '0',
  181. `optname` varchar(20) DEFAULT NULL COMMENT '操作人',
  182. `applydt` date DEFAULT NULL COMMENT '申请日期',
  183. `explain` varchar(500) DEFAULT NULL COMMENT '说明',
  184. `status` tinyint(1) DEFAULT '1' COMMENT '状态',
  185. `isturn` tinyint(1) DEFAULT '1' COMMENT '是否提交',
  186. `comid` smallint(6) DEFAULT '0' COMMENT '对应单位id',
  187. PRIMARY KEY (`id`)
  188. ) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COMMENT='$name';";
  189. $bo = $this->db->query($sql);
  190. }else{
  191. $fields = $this->db->getallfields(''.PREFIX.''.$tab.'');
  192. $str = '';
  193. if(!in_array('uid', $fields))$str.=",add `uid` int(11) DEFAULT '0'";
  194. if(!in_array('optdt', $fields))$str.=",add `optdt` datetime DEFAULT NULL COMMENT '操作时间'";
  195. if(!in_array('optid', $fields))$str.=",add `optid` int(11) DEFAULT '0'";
  196. if(!in_array('optname', $fields))$str.=",add `optname` varchar(20) DEFAULT NULL COMMENT '操作人'";
  197. if(!in_array('applydt', $fields))$str.=",add `applydt` date DEFAULT NULL COMMENT '申请日期'";
  198. if(!in_array('explain', $fields))$str.=",add `explain` varchar(500) DEFAULT NULL COMMENT '说明'";
  199. if(!in_array('status', $fields))$str.=",add `status` tinyint(1) DEFAULT '1' COMMENT '状态'";
  200. if(!in_array('isturn', $fields))$str.=",add `isturn` tinyint(1) DEFAULT '1' COMMENT '是否提交'";
  201. if(!in_array('comid', $fields) && !in_array('companyid', $fields))$str.=",add `comid` smallint(6) DEFAULT '0' COMMENT '对应单位id'";
  202. if($str!=''){
  203. $sql = 'alter table `'.PREFIX.''.$tab.'` '.substr($str,1).'';
  204. $this->db->query($sql);
  205. }
  206. }
  207. }
  208. public function elementafter($table, $rows)
  209. {
  210. $moders = m('flow_set')->getone($this->mid);
  211. $farrs = array();
  212. if($this->mid>0){
  213. $tass = $moders['table'];
  214. $tasss = $moders['tables'];
  215. $farr = $this->db->gettablefields('[Q]'.$tass.'');
  216. $farrs[]= array('id'=>'','name'=>'————↓以下主表('.$tass.')的字段————');
  217. foreach($farr as $k=>$rs){
  218. $farrs[]= array('id'=>$rs['name'],'name'=>'['.$rs['name'].']'.$rs['explain'].'');
  219. }
  220. if(!isempt($tasss)){
  221. $tasssa = explode(',', $tasss);
  222. foreach($tasssa as $k=>$tasss){
  223. $farr = $this->db->gettablefields('[Q]'.$tasss.'');
  224. $farrs[]= array('id'=>'','name'=>'————↓以下第'.($k+1).'个多行子表('.$tasss.')的字段————');
  225. foreach($farr as $k=>$rs){
  226. $farrs[]= array('id'=>$rs['name'],'name'=>'['.$rs['name'].']'.$rs['explain'].'');
  227. }
  228. }
  229. }
  230. }
  231. return array(
  232. 'flowarr'=>$this->getmodearr(),
  233. 'moders'=>$moders,
  234. 'fieldsarr' => $farrs,
  235. 'fieldstypearr'=> $this->option->getdata('flowinputtype')
  236. );
  237. }
  238. public $mid;
  239. public function elementbefore($table)
  240. {
  241. $mid = (int)$this->post('mid');
  242. $this->mid = $mid;
  243. return array(
  244. 'where' => 'and `mid`='.$mid.'',
  245. 'order' => 'iszb,sort,id'
  246. );
  247. }
  248. //模块多模版
  249. public function modetpl_before($table)
  250. {
  251. $mid = (int)$this->post('mid');
  252. $this->mid = $mid;
  253. return array(
  254. 'where' => 'and `setid`='.$mid.'',
  255. 'order' => 'sort,id'
  256. );
  257. }
  258. public function modetpl_after($table, $rows)
  259. {
  260. return array(
  261. 'flowarr'=>$this->getmodearr(' and `istpl`=1')
  262. );
  263. }
  264. public function modetpledit_before($table)
  265. {
  266. $mid = (int)$this->post('mid');
  267. $this->mid = $mid;
  268. return array(
  269. 'where' => 'and `mid`='.$mid.' and `iszb`=0',
  270. 'order' => 'sort,id'
  271. );
  272. }
  273. public function modetpledit_after($table, $rows)
  274. {
  275. $sid = (int)$this->post('sid');
  276. $data = false;
  277. $fieldsluru = $fieldsbitian = '';
  278. if($sid>0){
  279. $data = m('flow_modetpl')->getone($sid);
  280. $fieldsluru = $data['fieldsluru'];
  281. $fieldsbitian = $data['fieldsbitian'];
  282. foreach($rows as $k=>$rs){
  283. if(!isempt($fieldsluru)){
  284. $islu = 0;
  285. if(contain(','.$fieldsluru.',',','.$rs['fields'].','))$islu=1;
  286. $rows[$k]['islu'] = $islu;
  287. }
  288. if(!isempt($fieldsbitian)){
  289. $isbt = 0;
  290. if(contain(','.$fieldsbitian.',',','.$rs['fields'].','))$isbt=1;
  291. $rows[$k]['isbt'] = $isbt;
  292. }
  293. }
  294. }
  295. return array(
  296. 'data' => $data,
  297. 'rows' => $rows,
  298. );
  299. }
  300. public function modetpl_savefieldsbefore($table, $cans)
  301. {
  302. $tplnum = $cans['tplnum'];
  303. if(c('check')->isincn($tplnum))return '编号不能包含中文';
  304. $id = (int)$this->post('id');
  305. if(m($table)->rows("`tplnum`='$tplnum' and `id`<>'$id'")>0)return '编号已经存在';
  306. }
  307. public function modetpl_savefieldsafter($table, $cans)
  308. {
  309. $mid = $cans['setid'];
  310. $tab = m('mode')->getmou('`table`',$mid);
  311. if(!isempt($tab)){
  312. $fields = $this->db->getallfields(''.PREFIX.''.$tab.'');
  313. $str = '';
  314. if(!in_array('mtplid', $fields))$str.=",add `mtplid` int(11) DEFAULT '0' COMMENT '对应多模版flow_modetpl.id'";
  315. if($str!=''){
  316. $sql = 'alter table `'.PREFIX.''.$tab.'` '.substr($str,1).'';
  317. $this->db->query($sql);
  318. }
  319. }
  320. }
  321. //单据操作菜单
  322. public function flowmenubefore($table)
  323. {
  324. $mid = (int)$this->post('mid');
  325. $this->mid = $mid;
  326. return 'and `setid`='.$mid.'';
  327. }
  328. public function flowmenuafter($table, $rows)
  329. {
  330. return array(
  331. 'flowarr'=>$this->getmodearr()
  332. );
  333. }
  334. //条件where
  335. public function flowwhereafter($table, $rows)
  336. {
  337. return array(
  338. 'flowarr'=> $this->getmodearr()
  339. );
  340. }
  341. public function flowwherebefore($table)
  342. {
  343. return array(
  344. 'table' => '`[Q]'.$table.'` a left join `[Q]flow_set` b on a.setid=b.id',
  345. 'fields'=> 'a.*,b.num as modenum,b.name as modename'
  346. );
  347. }
  348. //单据通知设置
  349. public function flowtodobefore($table)
  350. {
  351. $mid = (int)$this->post('mid');
  352. $this->mid = $mid;
  353. $where = '';
  354. if($mid>0)$where = 'and `setid`='.$mid.'';
  355. return array(
  356. 'where' => $where,
  357. 'table' => '`[Q]'.$table.'` a left join `[Q]flow_set` b on a.setid=b.id',
  358. 'fields'=> 'a.*,b.name as modename'
  359. );
  360. }
  361. public function flowtodoafter($table, $rows)
  362. {
  363. $fielslist = m('flow_element')->getrows("mid='$this->mid' and iszb=0 and islu=1",'fields,name','sort');
  364. foreach($fielslist as &$v){
  365. $v['name'] = ''.$v['fields'].'.'.$v['name'].'';
  366. }
  367. $courselist = m('flow_course')->getrows("setid='$this->mid' and `status`=1",'id,name','pid,sort');
  368. foreach($courselist as &$v1){
  369. $v1['name'] = ''.$v1['id'].'.'.$v1['name'].'';
  370. }
  371. $dbss = m('remind');
  372. foreach($rows as $k=>$rs){
  373. $whereid = '';
  374. if($rs['whereid']>'0')$whereid = $this->db->getmou('[Q]flow_where','name', $rs['whereid']);
  375. $rows[$k]['whereidstr'] = $whereid;
  376. if($rs['botask']=='1'){
  377. $rows[$k]['remindrs'] = $dbss->getremindrs('flow_todo', $rs['id']);
  378. }
  379. }
  380. return array(
  381. 'flowarr' => $this->getmodearr(),
  382. 'wherelist' => $this->getwherelist($this->mid),
  383. 'fielslist' => $fielslist,
  384. 'courselist' => $courselist,
  385. 'rows' => $rows
  386. );
  387. }
  388. private function getmodearr($whe='')
  389. {
  390. return m('mode')->getmodearr($whe);
  391. }
  392. public function inputzsAction()
  393. {
  394. $setid = $this->get('setid');
  395. $atype = (int)$this->get('atype','0');
  396. $rs = m('flow_set')->getone("`id`='$setid'");
  397. if(!$rs)exit('sorry!');
  398. $this->smartydata['rs'] = $rs;
  399. $atypea = array('PC端','手机端','PC端打印');
  400. $this->title = $rs['name'].'_'.$atypea[$atype].'展示页面设置';
  401. $fleftarr = m('flow_element')->getrows("`mid`='$setid' and `iszb`=0",'`fields`,`name`','`iszb`,`sort`');
  402. $modenum = $rs['num'];
  403. $fleft[]= array('base_name', '申请人',0);
  404. $fleft[]= array('base_deptname', '申请部门',0);
  405. $fleft[]= array('base_sericnum', '单号',0);
  406. $fleft[] = array('file_content', '相关文件',0);
  407. $iszb = 0;
  408. foreach($fleftarr as $k=>$brs){
  409. $fleft[]= array($brs['fields'], $brs['name'], $iszb);
  410. }
  411. if(!isempt($rs['tables'])){
  412. $tablea = explode(',', $rs['tables']);
  413. $namesa = explode(',', $rs['names']);
  414. $fleft[]= array('', '<font color=#ff6600>↓多行子表</font>', 0);
  415. foreach($tablea as $k=>$rs1){
  416. $fleft[]= array('subdata'.$k.'', $namesa[$k], 0);
  417. }
  418. }
  419. if($rs['isflow']>0){
  420. $fleft[]= array('', '<font color=#ff6600>↓流程审核步骤</font>', 0);
  421. $rows = m('flow_course')->getrows('setid='.$setid.' and `status`=1','id,name','pid,sort');
  422. foreach($rows as $k=>$rs){
  423. $fleft[]= array('course'.$rs['id'].'_all', ''.$rs['name'].'处理意见', 0);
  424. $fleft[]= array('course'.$rs['id'].'_name', ''.$rs['name'].'处理人', 0);
  425. $fleft[]= array('course'.$rs['id'].'_zt', ''.$rs['name'].'处理状态', 0);
  426. $fleft[]= array('course'.$rs['id'].'_dt', ''.$rs['name'].'处理时间', 0);
  427. $fleft[]= array('course'.$rs['id'].'_sm', ''.$rs['name'].'处理说明', 0);
  428. }
  429. }
  430. $this->smartydata['fleft'] = $fleft;
  431. $this->smartydata['atype'] = $atype;
  432. $path = ''.P.'/flow/page/view_'.$modenum.'_'.$atype.'.html';
  433. $bianhao = $modenum;
  434. if(COMPANYNUM){
  435. $path1 = ''.P.'/flow/page/view_'.$modenum.'_'.COMPANYNUM.'_'.$atype.'.html';
  436. if(file_exists($path1)){
  437. $path = $path1;
  438. $bianhao.='_'.COMPANYNUM.'';
  439. }
  440. }
  441. $content = '';
  442. if(file_exists($path)){
  443. $content = file_get_contents($path);
  444. }
  445. $this->smartydata['content'] = $content;
  446. $this->smartydata['bianhao'] = $bianhao;
  447. }
  448. public $setinputid = 0;
  449. public function inputAction()
  450. {
  451. $setid = (int)$this->get('setid','0');
  452. if($this->setinputid>0)$setid = $this->setinputid;
  453. $atype = $this->get('atype');
  454. $rs = m('flow_set')->getone("`id`='$setid'");
  455. if(!$rs)exit('sorry!');
  456. $rs['zibiaoshu'] = count(explode(',', (string)$rs['tables']));
  457. $this->smartydata['rs'] = $rs;
  458. $this->title = $rs['name'].'_录入页面设置';
  459. $fleftarr = m('flow_element')->getrows("`mid`='$setid'",'*','`iszb`,`sort`');
  460. $modenum = $rs['num'];
  461. $fleft[]= array('base_name', '申请人',0);
  462. $fleft[]= array('base_deptname', '申请部门',0);
  463. $fleft[]= array('base_sericnum', '单号',0);
  464. $fleft[] = array('file_content', '相关文件',0);
  465. $iszb = 0;
  466. foreach($fleftarr as $k=>$brs){
  467. $bt='';
  468. if($brs['isbt']==1)$bt='*';
  469. $iszbs = $brs['iszb'];
  470. if($iszbs>0&&$iszb != $iszbs){
  471. $fleft[]= array('', '<font color=#ff6600>—第'.$iszbs.'个多行子表—</font>', $iszbs);
  472. $fleft[]= array('xuhao', '序号', $iszbs);
  473. }
  474. $iszb = $iszbs;
  475. $fleft[]= array($brs['fields'], $bt.$brs['name'], $iszb);
  476. }
  477. $this->smartydata['fleft'] = $fleft;
  478. $bianhao = $modenum;
  479. $path = ''.P.'/flow/page/input_'.$modenum.'.html';
  480. if(COMPANYNUM){
  481. $path1 = ''.P.'/flow/page/input_'.$modenum.'_'.COMPANYNUM.'.html';
  482. if(file_exists($path1)){
  483. $bianhao.='_'.COMPANYNUM.'';
  484. $path = $path1;
  485. }
  486. }
  487. $content = '';
  488. if(file_exists($path)){
  489. $content = file_get_contents($path);
  490. }
  491. $this->smartydata['bianhao'] = $bianhao;
  492. $this->smartydata['content'] = $content;
  493. $apaths = ''.P.'/flow/input/inputjs/mode_'.$modenum.'.js';
  494. if(!file_exists($apaths)){
  495. $stra='//流程模块【'.$modenum.'.'.$rs['name'].'】下录入页面自定义js页面,初始函数
  496. function initbodys(){
  497. }';
  498. $this->rock->createtxt($apaths, $stra);
  499. }
  500. $apaths = ''.P.'/flow/input/mode_'.$modenum.'Action.php';
  501. $apath = ''.ROOT_PATH.'/'.$apaths.'';
  502. if(!file_exists($apath)){
  503. $stra = '<?php
  504. /**
  505. * 此文件是流程模块【'.$modenum.'.'.$rs['name'].'】对应控制器接口文件。
  506. */
  507. class mode_'.$modenum.'ClassAction extends inputAction{
  508. /**
  509. * 重写函数:保存前处理,主要用于判断是否可以保存
  510. * $table String 对应表名
  511. * $arr Array 表单参数
  512. * $id Int 对应表上记录Id 0添加时,大于0修改时
  513. * $addbo Boolean 是否添加时
  514. * return array(\'msg\'=>\'错误提示内容\',\'rows\'=> array()) 可返回空字符串,或者数组 rows 是可同时保存到数据库上数组
  515. */
  516. protected function savebefore($table, $arr, $id, $addbo){
  517. }
  518. /**
  519. * 重写函数:保存后处理,主要保存其他表数据
  520. * $table String 对应表名
  521. * $arr Array 表单参数
  522. * $id Int 对应表上记录Id
  523. * $addbo Boolean 是否添加时
  524. */
  525. protected function saveafter($table, $arr, $id, $addbo){
  526. }
  527. }
  528. ';
  529. $this->rock->createtxt($apaths, $stra);
  530. }
  531. if(!file_exists($apath))echo '<div style="background:red;color:white;padding:10px">无法创建文件:'.$apaths.',会导致录入数据无法保存,请手动创建!代码内容如下:</div><div style="background:#caeccb">&lt;?php<br>class mode_'.$modenum.'ClassAction extends inputAction<br>{<br>}</div>';
  532. }
  533. private function geuolvstr($str)
  534. {
  535. $str = str_replace(array('<?php','$_POST','exec','system') ,'', $str);
  536. return $str;
  537. }
  538. private function geuolvstra($str)
  539. {
  540. $str = str_replace(array('../','.','/') ,'', $str);
  541. return $str;
  542. }
  543. public function pagesaveAjax()
  544. {
  545. $content = $this->geuolvstr($this->post('content'));
  546. $num = $this->geuolvstra($this->post('num'));
  547. if(m('flow_set')->rows("`num`='$num'")==0)return;
  548. $path = ''.P.'/flow/page/input_'.$num.'.html';
  549. if(COMPANYNUM)$path = ''.P.'/flow/page/input_'.$num.'_'.COMPANYNUM.'.html';
  550. $bo = $this->rock->createtxt($path, $content);
  551. if(!$bo){
  552. echo '无法写入文件:'.$path.'';
  553. }else{
  554. echo 'success';
  555. }
  556. }
  557. public function viewsaveAjax()
  558. {
  559. $content = $this->geuolvstr($this->post('content'));
  560. $num = $this->geuolvstra($this->post('num'));
  561. if(m('flow_set')->rows("`num`='$num'")==0)return;
  562. $atype = (int)$this->post('atype','0');
  563. $path = ''.P.'/flow/page/view_'.$num.'_'.$atype.'.html';
  564. if(COMPANYNUM){
  565. $path = ''.P.'/flow/page/view_'.$num.'_'.COMPANYNUM.'_'.$atype.'.html';
  566. }
  567. if(isempt($content)){
  568. @unlink($path);
  569. return 'success';
  570. }
  571. $bo = $this->rock->createtxt($path, $content);
  572. if(!$bo){
  573. echo '无法写入文件:'.$path.'';
  574. }else{
  575. echo 'success';
  576. }
  577. }
  578. public function getinputAjax()
  579. {
  580. $num = $this->post('num');
  581. $path = ''.P.'/flow/page/input_'.$num.'.html';
  582. $cont = '';
  583. if(file_exists($path)){
  584. $cont = file_get_contents($path);
  585. $cont = str_replace('*','', $cont);
  586. }
  587. echo $cont;
  588. }
  589. public function getsubtableAjax()
  590. {
  591. $iszb = (int)$this->post('iszb');
  592. $hang = (int)$this->post('hang');
  593. $modeid = (int)$this->post('modeid');
  594. $str = m('input')->getsubtable($modeid, $iszb, $hang);
  595. if($str=='')$this->backmsg('没有设置第'.$iszb.'个多行子表');
  596. $this->backmsg('','ok', $str);
  597. }
  598. //一键布局录入页
  599. public $yinruonearr = false;
  600. public function yinruoneAjax()
  601. {
  602. if($this->yinruonearr){
  603. $modeid = $this->yinruonearr['modeid'];
  604. $xgwj = (int)arrvalue($this->yinruonearr, 'xgwj');
  605. $base = (int)arrvalue($this->yinruonearr, 'base');
  606. }else{
  607. $modeid = (int)$this->post('modeid');
  608. $xgwj = (int)$this->post('xgwj');
  609. $base = (int)$this->post('base');
  610. }
  611. $mrs = m('mode')->getone($modeid);
  612. $rowsa = m('flow_element')->getall('mid='.$modeid.' and `iszb`=0 and `islu`=1','*','sort,id');
  613. $yczd = '';
  614. $rows = array();
  615. $fzuar = array();
  616. foreach($rowsa as $k1=>$rs1){
  617. if($rs1['fieldstype']=='hidden' || $rs1['fieldstype']=='fixed'){
  618. $yczd.='{'.$rs1['fields'].'}';
  619. }else{
  620. $rows[] = $rs1;
  621. $ftype = arrvalue($rs1, 'ftype');
  622. if(isempt($ftype))$ftype = 'defv';
  623. if(!isset($fzuar[$ftype]))$fzuar[$ftype] = array();
  624. $fzuar[$ftype][]= $rs1;
  625. }
  626. }
  627. $xichu = 0;
  628. $s = '';
  629. foreach($fzuar as $fl=>$fstra){
  630. $xichu++;
  631. if($xichu>1){
  632. $s.='</tbody></table>';
  633. }
  634. if($fl!='defv'){
  635. $s.='<br><div><b>'.$fl.'</b></div>';
  636. }
  637. $str1 = $this->yubustsin($fstra, $yczd);
  638. $s.=$str1;
  639. $yczd = '';
  640. }
  641. $tables = $mrs['tables'];
  642. if(!isempt($tables)){
  643. $tablesa = explode(',', $tables);
  644. $tablesn = explode(',', $mrs['names']);
  645. foreach($tablesa as $k=>$tab){
  646. $str = m('input')->getsubtable($modeid, $k+1, 1);
  647. $s.='<tr ><td class="ys2" style="background-color:#CCCCCC;" colspan="4"><strong>'.arrvalue($tablesn, $k).'</strong></td></tr>';
  648. $s.='<tr><td class="ys0" colspan="4">'.$str.'</td></tr>';
  649. }
  650. }
  651. if($xgwj==1)$s.='<td height="34" align="right" class="ys1">^file_content^</td><td colspan="3" class="ys2"> {file_content}</td>';
  652. if($base==1)$s.='<tr><td height="34" align="right" class="ys1">^base_name^</td><td class="ys2" >{base_name}</td><td align="right" class="ys1" >^base_deptname^</td><td class="ys2" >{base_deptname}</td></tr>';
  653. $s.='</tbody></table>';
  654. return $s;
  655. }
  656. public function yubustsin($rows, $yczd)
  657. {
  658. $zhang = array('textarea','htmlediter','uploadfile','uploadimg','changedeptusercheck');
  659. $s = '<table width="100%" border="0"><tbody><tr class="autoyijianview">';
  660. $xuo = 0;
  661. $zlen= count($rows)-1;
  662. foreach($rows as $k=>$rs){
  663. $xuo++;
  664. $name = '^'.$rs['fields'].'^';
  665. if($rs['isbt']=='1')$name='*'.$name.'';
  666. if(in_array($rs['fieldstype'], $zhang) || contain($rs['attr'],'maxhang')){
  667. if($xuo==2)$s.='<td height="34" align="right" class="ys1"></td><td class="ys2"></td></tr><tr>';
  668. $s.='<td height="34" align="right" class="ys1">'.$name.'</td><td colspan="3" class="ys2">{'.$rs['fields'].'}'.$yczd.'</td>';
  669. if($xuo==1)$xuo=2;
  670. }else{
  671. $s.='<td height="34" width="15%" align="right" class="ys1">'.$name.'</td><td width="35%" class="ys2">{'.$rs['fields'].'}'.$yczd.'</td>';
  672. }
  673. $yczd='';
  674. if($xuo==2){
  675. $s.='</tr>';
  676. if($k<$zlen)$s.='<tr>';
  677. $xuo=0;
  678. }
  679. if($xuo==1 && $k==$zlen){
  680. $s.='<td height="34" align="right" class="ys1"></td><td class="ys2"></td></tr>';
  681. }
  682. }
  683. return $s;
  684. }
  685. public function getmodearrAjax()
  686. {
  687. $arr = $this->getmodearr();
  688. $this->backmsg('','ok', $arr);
  689. }
  690. public function viewshowbefore($table)
  691. {
  692. $this->modeid = (int)$this->post('modeid');
  693. if($this->modeid==0){
  694. return 'and 1=2';
  695. }
  696. $this->moders = m('flow_set')->getone($this->modeid);
  697. $this->isflow = $this->moders['isflow'];
  698. $table = $this->moders['table'];
  699. $where = $this->moders['where'];
  700. if(!isempt($where)){
  701. $where = $this->rock->covexec($where);
  702. $where = "and $where";
  703. }
  704. return array(
  705. 'table' => '[Q]'.$table,
  706. 'where' => $where
  707. );
  708. }
  709. public function viewshowafter($table, $rows)
  710. {
  711. $arr = array();
  712. if($rows){
  713. $flow = m('flow')->initflow($this->moders['num']);
  714. $mbil = m('flowbill');
  715. foreach($rows as $k=>$rs){
  716. $zt = '';
  717. if(isset($rs['status']))$zt = $rs['status'];
  718. $narr['id'] = $rs['id'];
  719. $narr['ishui'] = ($zt=='5')?1:0;
  720. $narr['optname'] = arrvalue($rs,'optname');
  721. $narr['modenum'] = $this->moders['num'];
  722. $narr['modename'] = $this->moders['name'];
  723. $narr['table'] = $this->moders['table'];
  724. $narr['optdt'] = arrvalue($rs,'optdt');
  725. $nors = $flow->flowrsreplace($rs, 2);
  726. $narr['summary'] = $this->rock->reparr($this->moders['summary'], $nors);
  727. $otehsr = '';
  728. if($flow->isflow>0){
  729. $billrs = $flow->billmodel->getone("`table`='$flow->mtable' and `mid`='".$rs['id']."'");
  730. $otehsr = arrvalue($billrs, 'nowcheckname');
  731. }
  732. $narr['status'] = $flow->getstatus($rs,'',$otehsr,1);
  733. $narr['chushu'] = $flow->flogmodel->rows("`table`='".$flow->mtable."' and `mid`='".$rs['id']."'");
  734. $arr[] = $narr;
  735. }
  736. }
  737. return array('rows'=>$arr);
  738. }
  739. public function viewlogshowbefore($table)
  740. {
  741. $where = "and `table`='".$this->post('num')."' and `mid`='".$this->post('mid')."'";
  742. return array(
  743. 'where' => $where
  744. );
  745. }
  746. //删除单据,用户=1不需要权限判断
  747. public function delmodeshujuAjax()
  748. {
  749. $this->modeid = (int)$this->post('modeid');
  750. $mid = (int)$this->post('mid');
  751. $modenum = $this->post('modenum');
  752. if($this->modeid>0){
  753. $this->moders = m('flow_set')->getone($this->modeid);
  754. if(!$this->moders)backmsg('sorry!');
  755. $modenum = $this->moders['num'];
  756. }
  757. if(isempt($modenum))backmsg('操作有误');
  758. $msg = m('flow')->deletebill($modenum, $mid, '', $this->adminid!=1);
  759. if($msg=='ok')$msg='';
  760. backmsg($msg);
  761. }
  762. //元素保存之前判断
  763. public function elemensavefieldsbefore($table, $cans, $id)
  764. {
  765. $iszb = (int)$cans['iszb'];
  766. $fields = $cans['fields'];
  767. $type = $cans['fieldstype'];
  768. $data = $cans['data'];
  769. if(c('check')->isincn($fields))return '对应字段不能有汉字';
  770. if(c('check')->isnumber($fields))return '对应字段不能是数字';
  771. if($type=='selectdatafalse' || $type=='selectdatatrue'){
  772. if(isempt($data))return '此类型数据源必须设置如写:'.$fields.'store';
  773. if(contain(','.$data.',',',id,'))return '数据源不能包含,id';
  774. }
  775. $mid = $cans['mid'];
  776. $this->mmoders = m('flow_set')->getone($mid);
  777. $tablessa = explode(',', $this->mmoders['tables']);
  778. if($iszb>0){
  779. $tabsss = $this->rock->arrvalue($tablessa, $iszb-1);
  780. if(isempt($tabsss))return '模块没有设置第'.$iszb.'个多行子表';
  781. }
  782. if(m($table)->rows("`mid`='$mid' and `iszb`='$iszb' and `fields`='$fields' and `id`<>'$id'")>0){
  783. return '字段['.$fields.']已存在了';
  784. }
  785. }
  786. //保存字段判断,自动创建字段
  787. public function elemensavefields($table, $cans)
  788. {
  789. $fields = $cans['fields'];
  790. $name = $cans['name'];
  791. $mid = $cans['mid'];
  792. $type = $cans['fieldstype'];
  793. $lens = $cans['lens'];
  794. $dev = $cans['dev'];
  795. $data = $cans['data'];
  796. $iszb = (int)$cans['iszb'];
  797. $this->xiaoshu = (int)arrvalue($cans,'xiaoshu','-1');
  798. $mrs = $this->mmoders;
  799. $tables = $mrs['table'];
  800. if($iszb>0){
  801. $tables = '';
  802. $tablessa = explode(',', $mrs['tables']);
  803. if(isset($tablessa[$iszb-1]))$tables = $tablessa[$iszb-1];
  804. }
  805. $fiesss = substr($fields,0,5);
  806. if($fiesss == 'base_' || $fiesss == 'temp_')return;
  807. if(!isempt($tables) && $cans['islu']==1){
  808. $_fieldsa = $this->db->gettablefields('[Q]'.$tables.'');$allfields = array();
  809. foreach($_fieldsa as $k2=>$rs2)$allfields[$rs2['name']] = $rs2;
  810. $this->createfields($allfields, $tables, $fields, $type, $lens, $dev, $name);
  811. if(substr($type,0,6)=='change' && !isempt($data)){
  812. if($type=='changeuser' || $type=='changedept'){
  813. $type='number';
  814. }
  815. $this->createfields($allfields, $tables, $data, $type, $lens, '', $name.'的ID');
  816. }
  817. }
  818. }
  819. //创建字段
  820. private function createfields($allfields, $tables, $fields, $type, $lens, $dev, $name)
  821. {
  822. if(isempt($lens))$lens='0';
  823. $lens = (int)$lens;
  824. if(!isset($allfields[$fields])){
  825. $str = "ALTER TABLE `[Q]".$tables."` ADD `$fields` ";
  826. if($type=='date' || $type=='datetime' || $type=='time'){
  827. $str .= ' '.$type.'';
  828. }else if($type=='number'){
  829. if($this->xiaoshu>0){
  830. if($lens<6)$lens = 6;
  831. $str .= ' decimal('.$lens.', '.$this->xiaoshu.')';
  832. }else if($lens>6){
  833. $str .= ' int('.$lens.')';
  834. }else{
  835. $str .= ' smallint(6)';
  836. }
  837. }else if($type=='checkbox'){
  838. $str .= ' tinyint(1)';
  839. }else if($type=='textarea'){
  840. $str .= ' varchar(2000)';
  841. }else{
  842. if($lens=='0')$lens='50';
  843. $str .= ' varchar('.$lens.')';
  844. }
  845. if(!isempt($dev) && !contain($dev,'{'))$str.= " DEFAULT '$dev'";
  846. $str.= " COMMENT '$name'";
  847. $this->db->query($str);
  848. }else{
  849. $farr = $allfields[$fields];
  850. $ustr = '';
  851. $len = (int)$farr['lens'];
  852. $xslen1 = (int)arrvalue($farr,'xslen1','0');
  853. $xslen2 = (int)arrvalue($farr,'xslen2','0');
  854. if($farr['type']=='varchar'){
  855. if($lens>$len)$ustr='varchar('.$lens.')';
  856. }
  857. if($farr['type']=='smallint' || $farr['type']=='int'){
  858. if($lens>6 && $lens>$len)$ustr='int('.$lens.')';
  859. }
  860. if($farr['type']=='decimal'){
  861. if($lens>$xslen1)$ustr= 'decimal('.$lens.', '.$xslen2.')';
  862. }
  863. if($type=='date' || $type=='datetime'){
  864. if($farr['type']!=$type){
  865. $ustr= ''.$type.'';
  866. }
  867. }
  868. if($type=='number'){
  869. if($lens<6)$lens = $xslen1;
  870. if($lens<6)$lens = 6;
  871. if($this->xiaoshu>0){
  872. $ustr= 'decimal('.$lens.', '.$this->xiaoshu.')';
  873. }
  874. }
  875. if($ustr!=''){
  876. if(!isempt($dev) && !contain($dev,'{'))$ustr.= " DEFAULT '$dev'";
  877. $ustr= "ALTER TABLE `[Q]".$tables."` MODIFY column `$fields` ".$ustr." COMMENT '$name'";
  878. $this->db->query($ustr);
  879. }
  880. }
  881. }
  882. public function reloadpipeiAjax()
  883. {
  884. $mid = (int)$this->post('mid');
  885. $whe = '';
  886. if($mid>0)$whe=' and id='.$mid.'';
  887. echo m('flow')->repipei($whe);
  888. }
  889. public function setwherelistafter($table, $rows)
  890. {
  891. $dbs = m('flow_where');
  892. foreach($rows as $k=>$rs){
  893. $shu = $dbs->rows("`setid`='".$rs['id']."'");
  894. if($shu>0)$rows[$k]['shu'] = $shu;
  895. }
  896. return array('rows'=>$rows);
  897. }
  898. public function setcourselistafter($table, $rows)
  899. {
  900. $dbs = m('flow_course');
  901. foreach($rows as $k=>$rs){
  902. $shu = $dbs->rows("`setid`='".$rs['id']."'");
  903. if($shu>0)$rows[$k]['shu'] = $shu;
  904. }
  905. return array('rows'=>$rows);
  906. }
  907. public function setcourselistbefore($table)
  908. {
  909. $where = '';
  910. $key = $this->post('key');
  911. if(!isempt($key)){
  912. $where = "and (`type`='$key' or `name` like '%$key%' or `table` like '$key%' or `num` like '$key%' or `sericnum` like '$key%')";
  913. }
  914. return $where;
  915. }
  916. //删除模块
  917. public function delmodeAjax()
  918. {
  919. $id = (int)$this->post('id','0');
  920. return $this->delmode($id, true);
  921. }
  922. private function delmode($id, $dm=false)
  923. {
  924. if($this->getsession('isadmin')!='1')return '非管理员不能操作';
  925. $mrs = m('flow_set')->getone($id);
  926. if(!$mrs)return '模块不存在';
  927. $num = $mrs['num'];
  928. if($num!='demo' && $mrs['type']=='系统')return '系统类型模块不能删除清空';
  929. $flow = m('flow')->initflow($num);
  930. $table = $mrs['table'];
  931. $where = $mrs['where'];
  932. if(!isempt($where)){
  933. $where = $this->rock->covexec($where);
  934. $where = "and $where";
  935. }else{
  936. $where = '';
  937. }
  938. $rows = m($table)->getrows('1=1 '.$where.'');
  939. foreach($rows as $k=>$rs){
  940. $ssid = $rs['id'];
  941. $flow->loaddata($ssid, false);
  942. $flow->deletebill('清空模块数据', false);
  943. }
  944. $name = $mrs['name'];
  945. if($dm){
  946. m('flow_set')->delete("`id`='$id'");
  947. m('flow_course')->delete("`setid`='$id'");
  948. m('flow_element')->delete("`mid`='$id'");
  949. m('flow_extent')->delete("`modeid`='$id'");
  950. m('flow_where')->delete("`setid`='$id'");
  951. m('flow_menu')->delete("`setid`='$id'");
  952. m('flow_todo')->delete("`setid`='$id'");
  953. m('flow_todos')->delete("`modenum`='$num'");
  954. m('log')->addlog('模块','删除模块['.$name.']');
  955. }else{
  956. m('log')->addlog('模块','清空模块['.$name.']的数据');
  957. }
  958. $this->db->query("alter table `[Q]$table` AUTO_INCREMENT=1");
  959. return 'ok';
  960. }
  961. //清空模块上数据
  962. public function clearallmodeAjax()
  963. {
  964. $id = (int)$this->post('id','0');
  965. return $this->delmode($id, false);
  966. }
  967. //刷新序号
  968. public function rexuhaoAjax()
  969. {
  970. $mid = (int)$this->get('modeid');
  971. $db = m('flow_element');
  972. $rows = $db->getall('mid='.$mid.' and iszb=0','id','sort asc,id asc');
  973. foreach($rows as $k=>$rs)$db->update('sort='.$k.'',$rs['id']);
  974. $rows = $db->getall('mid='.$mid.' and iszb=1','id','sort asc,id asc');
  975. foreach($rows as $k=>$rs)$db->update('sort='.$k.'',$rs['id']);
  976. $rows = $db->getall('mid='.$mid.' and iszb=2','id','sort asc,id asc');
  977. foreach($rows as $k=>$rs)$db->update('sort='.$k.'',$rs['id']);
  978. $rows = $db->getall('mid='.$mid.' and iszb=3','id','sort asc,id asc');
  979. foreach($rows as $k=>$rs)$db->update('sort='.$k.'',$rs['id']);
  980. }
  981. public function flowcourselistbefore($rows)
  982. {
  983. return array('order'=>'pid,sort');
  984. }
  985. //流程步骤显示
  986. public function flowcourselistafter($table, $rows)
  987. {
  988. $arr = array();$pid = -1;$maxpid = -1;
  989. foreach($rows as $k=>$rs){
  990. if($rs['pid'] != $pid){
  991. $recename = $this->rock->arrvalue($rs, 'recename');
  992. if(isempt($recename))$recename = '全体人员';
  993. $arr[] = array(
  994. 'name' => '流程'.($rs['pid']+1).',适用:'.$recename.'',
  995. 'level' => 1,
  996. 'stotal'=> 1,
  997. 'status'=> 1,
  998. 'iszf' => 0,
  999. 'id' => $rs['id'],
  1000. 'pid' => $rs['pid'],
  1001. 'sort' => 0,
  1002. 'recename' => '',
  1003. );
  1004. }
  1005. $rs['level'] = 2;
  1006. $rs['stotal'] = 0;
  1007. $arr[] = $rs;
  1008. $pid = $rs['pid'];
  1009. $maxpid = $pid;
  1010. }
  1011. return array(
  1012. 'rows' => $arr,
  1013. 'maxpid' => $maxpid+1,
  1014. );
  1015. }
  1016. //生成列表页面
  1017. public function changeliebAjax()
  1018. {
  1019. $modeid = (int)$this->post('modeid');
  1020. $path = m('mode')->createlistpage($modeid);
  1021. if($path=='')$path = '无法生成,可能没权限写入'.P.'/flow/page目录';
  1022. echo $path;
  1023. }
  1024. //生成所有
  1025. public function allcreateAjax()
  1026. {
  1027. $dbs = m('mode');
  1028. $rows = $dbs->getall("`status`=1");
  1029. $oi = 0;
  1030. $msg = '';
  1031. foreach($rows as $k=>$rs){
  1032. $path = $dbs->createlistpage($rs,1);
  1033. if($path=='none')continue;
  1034. if($path==''){
  1035. if($path=='')$msg = '无法生成,可能没权限写入'.P.'/flow/page目录';
  1036. break;
  1037. }else{
  1038. $oi++;
  1039. }
  1040. }
  1041. if($msg=='')$msg='已生成'.$oi.'个模块,可到'.P.'/flow/page下查看';
  1042. echo $msg;
  1043. }
  1044. public function savecolunmsAjax()
  1045. {
  1046. $num = $this->post('num');
  1047. $modeid = (int)$this->post('modeid');
  1048. $str = $this->post('str');
  1049. $this->option->setval($num.'@'.(-1*$modeid-1000), $str,'模块列定义');
  1050. $path = m('mode')->createlistpage($modeid);
  1051. $msg = 'ok';
  1052. //if($path=='')$msg='已保存,但无法从新生成列表页,自定义列将不能生效';
  1053. echo $msg;
  1054. }
  1055. //选择人员组
  1056. public function getcnameAjax()
  1057. {
  1058. $arr = array();
  1059. $rows = m('flow_cname')->getall("`pid`=0 and `num` is not null",'num,name','`sort`');
  1060. foreach($rows as $k=>$rs)$arr[] = array('name'=>$rs['name'],'value'=>$rs['num']);
  1061. return $arr;
  1062. }
  1063. //图形的流程管理
  1064. public function courseflowinitAjax()
  1065. {
  1066. $setid = (int)$this->get('setid','0');
  1067. return m('flowcourse')->getCoursedata($setid);
  1068. }
  1069. public function courseflowdelAjax()
  1070. {
  1071. $id = (int)$this->get('id','0');
  1072. m('flowcourse')->delete($id);
  1073. }
  1074. public function coursesavebefore($table, $arr)
  1075. {
  1076. $mid = (int)arrvalue($arr,'mid','0');
  1077. $setid = (int)arrvalue($arr,'setid','0');
  1078. $nid = (int)arrvalue($arr,'nid','0');
  1079. if($mid>0 && m($table)->rows("`setid`='$setid' and `id`='$mid'")==0)return '上级步骤ID['.$mid.']不存在';
  1080. if($nid>0 && m($table)->rows("`setid`='$setid' and `id`='$nid'")==0)return '下级步骤ID['.$nid.']不存在';
  1081. $str = m('where')->checkwhere($setid, $arr['where']);
  1082. if($str)return $str;
  1083. }
  1084. public function getfieldsAjax()
  1085. {
  1086. $setid = (int)$this->get('setid','0');
  1087. $rows = m('flow_element')->getrows('`mid`='.$setid.' and `iszb`=0','name,fields,data,fieldstype','`sort`');
  1088. $arr = array();
  1089. foreach($rows as $k=>$rs){
  1090. //$arr[] = array(
  1091. // 'name' => $rs['name'].'('.$rs['fields'].')',
  1092. // 'value' => $rs['fields'],
  1093. //);
  1094. $fieldstype = $rs['fieldstype'];
  1095. if(in_array($fieldstype, array('changeuser','changeusercheck')) && !isempt($rs['data'])){
  1096. $arr[] = array(
  1097. 'name' => $rs['name'].'('.$rs['data'].')',
  1098. 'value' => $rs['data'],
  1099. );
  1100. }
  1101. }
  1102. return $arr;
  1103. }
  1104. public function savebeforecname($table, $arr, $id)
  1105. {
  1106. $num = $arr['num'];
  1107. $to = m('flowcname')->rows("`id`<>'$id' and `num`='$num'");
  1108. if($to>0)return '编号['.$num.']已存在';
  1109. }
  1110. /**
  1111. * 复制模块
  1112. */
  1113. public function copymodeAjax()
  1114. {
  1115. $id = (int)$this->post('id','0');
  1116. $bhnu = strtolower(trim($this->post('name')));
  1117. if(isempt($bhnu))return '新模块编号不能为空';
  1118. if(is_numeric($bhnu))return '模块编号不能用数字';
  1119. if(strlen($bhnu)<4)return '编号至少要4位';
  1120. if(c('check')->isincn($bhnu))return '编号不能包含中文';
  1121. $dbs = m('mode');
  1122. if($dbs->rows("`num`='$bhnu'")>0)return '模块编号['.$bhnu.']已存在';
  1123. $mrs = $dbs->getone($id);
  1124. if(!$mrs)return '模块不存在';
  1125. $ars = $mrs;
  1126. $name = $mrs['name'].'复制';
  1127. $biaom = $bhnu;
  1128. $obha = $mrs['num'];
  1129. unset($ars['id']);
  1130. $ars['name'] = $name;
  1131. $ars['num'] = $bhnu;
  1132. $ars['table']= $biaom;
  1133. $tablea[] = $mrs['table'];
  1134. $tables = '';
  1135. if(!isempt($ars['tables'])){
  1136. $staba = explode(',', $ars['tables']);
  1137. foreach($staba as $kz=>$zb1){
  1138. $tables.=','.$biaom.'zb'.($kz+1).'';
  1139. if(!in_array($zb1, $tablea))$tablea[]=$zb1;
  1140. }
  1141. $tables = substr($tables, 1);
  1142. }
  1143. $ars['tables'] = $tables;
  1144. $modeid = $dbs->insert($ars);
  1145. //复制表
  1146. foreach($tablea as $kz=>$tabs){
  1147. $sqla = $this->db->getall('show create table `[Q]'.$tabs.'`');
  1148. $createsql = $sqla[0]['Create Table'];
  1149. $biaom1 = ''.PREFIX.''.$biaom.'';
  1150. if($kz>0)$biaom1 = ''.PREFIX.''.$biaom.'zb'.$kz.'';
  1151. $createsql = str_replace('`'.PREFIX.''.$tabs.'`','`'.$biaom1.'`',$createsql);
  1152. $this->db->query($createsql);
  1153. $this->db->query('alter table `'.$biaom1.'` AUTO_INCREMENT=1');
  1154. }
  1155. //复制表单元素
  1156. $db1 = m('flow_element');
  1157. $rows = $db1->getall('mid='.$id.'');
  1158. foreach($rows as $k1=>$rs1){
  1159. $rs2 = $rs1;
  1160. unset($rs2['id']);
  1161. $rs2['mid'] = $modeid;
  1162. $db1->insert($rs2);
  1163. }
  1164. //复制相关布局文件
  1165. $hurs = $this->getfiles();
  1166. foreach($hurs as $k=>$file){
  1167. $from = str_replace('{bh}',$obha,$file);
  1168. $to = str_replace('{bh}',$bhnu,$file);
  1169. if(file_exists($from)){
  1170. if($k<=1){
  1171. $fstr = file_get_contents($from);
  1172. if($k==0)$fstr = str_replace('flow_'.$obha.'ClassModel','flow_'.$bhnu.'ClassModel',$fstr);
  1173. if($k==1)$fstr = str_replace('mode_'.$obha.'ClassAction','mode_'.$bhnu.'ClassAction',$fstr);
  1174. $this->rock->createtxt($to, $fstr);
  1175. }else{
  1176. @copy($from, $to);
  1177. }
  1178. }
  1179. }
  1180. echo 'ok';
  1181. }
  1182. public function getfiles()
  1183. {
  1184. $hurs[] = ''.P.'/model/flow/{bh}Model.php'; //模块接口文件
  1185. $hurs[] = ''.P.'/flow/input/mode_{bh}Action.php'; //模块控制器
  1186. $hurs[] = ''.P.'/flow/input/inputjs/mode_{bh}.js'; //模块录入js文件
  1187. $hurs[] = ''.P.'/flow/page/input_{bh}.html'; //PC录入模版
  1188. $hurs[] = ''.P.'/flow/page/view_{bh}_0.html'; //PC展示模版
  1189. $hurs[] = ''.P.'/flow/page/view_{bh}_1.html'; //手机展示模版
  1190. $hurs[] = ''.P.'/flow/page/view_{bh}_2.html'; //打印布局
  1191. $hurs[] = ''.P.'/flow/page/viewpage_{bh}.html'; //子模版展示
  1192. $hurs[] = ''.P.'/flow/page/viewpage_{bh}_0.html';//子模版PC展示
  1193. $hurs[] = ''.P.'/flow/page/viewpage_{bh}_1.html';//子模版手机展示
  1194. return $hurs;
  1195. }
  1196. public function loadmodeinfoAjax()
  1197. {
  1198. if(getconfig('systype')=='demo')return returnerror('演示不要操作');
  1199. if(!getconfig('rockinzip'))return returnerror('系统未开启此功能');
  1200. $sid = $this->get('sid');
  1201. $rows = m('flow_set')->getall('`id` in('.$sid.')','*','sort asc');
  1202. $ids = '';
  1203. $mname= '';
  1204. $table= '';
  1205. $file = '';
  1206. $hurs = $this->getfiles();
  1207. $hurs[] = ''.P.'/flow/page/rock_page_{bh}.php';
  1208. foreach($rows as $k=>$rs){
  1209. $ids.=','.$rs['id'].'';
  1210. $table.=','.$rs['table'].'';
  1211. if(!isempt($rs['tables']))$table.=','.$rs['tables'].'';
  1212. $mname.=''.$rs['name'].'('.$rs['num'].') &nbsp;';
  1213. foreach($hurs as $k=>$wj){
  1214. $wjs = str_replace('{bh}',$rs['num'],$wj);
  1215. if(file_exists($wjs))$file.=','.$wjs.'';
  1216. }
  1217. }
  1218. if($ids)$ids = substr($ids,1);
  1219. if($table)$table = substr($table,1);
  1220. if($file)$file = substr($file,1);
  1221. $barr['mode'] = $ids;
  1222. $barr['mname'] = $mname;
  1223. $barr['table'] = $table;
  1224. $barr['file'] = $file;
  1225. return returnsuccess($barr);
  1226. }
  1227. public function loadoteinAjax()
  1228. {
  1229. if(getconfig('systype')=='demo')return returnerror('演示不要操作');
  1230. if(!getconfig('rockinzip'))return returnerror('系统未开启此功能');
  1231. $lx = $this->post('lx');
  1232. $sid = $this->post('sid');
  1233. $barr = array();
  1234. $stsa = explode(',', $sid);
  1235. if($lx==1){
  1236. $alltabls = $this->db->getalltable();
  1237. foreach($stsa as $tab){
  1238. if(!in_array(''.PREFIX.$tab.'', $alltabls))return returnerror(''.$tab.'表不存在');
  1239. }
  1240. $barr['table'] = $sid;
  1241. }
  1242. if($lx==2){
  1243. foreach($stsa as $tab)if(!file_exists($tab))return returnerror(''.$tab.'文件不存在');
  1244. $barr['file'] = $sid;
  1245. }
  1246. if($lx==3){
  1247. $rows = m('menu')->getall('`id` in('.$sid.') and `status`=1');
  1248. $ids = '';
  1249. $mname= '';
  1250. foreach($rows as $k=>$rs){
  1251. $ids.=','.$rs['id'].'';
  1252. $mname.=''.$rs['name'].'('.$rs['url'].') &nbsp;';
  1253. }
  1254. if($ids){
  1255. $barr['menu'] = substr($ids,1);
  1256. $barr['menu_str'] = $mname;
  1257. }
  1258. }
  1259. if($lx==4){
  1260. $rows = m('im_group')->getall('`id` in('.$sid.') and `valid`=1 and `type`=2');
  1261. $ids = '';
  1262. $mname= '';
  1263. $fstr = '';
  1264. foreach($rows as $k=>$rs){
  1265. $ids.=','.$rs['id'].'';
  1266. $mname.='<img src="'.$rs['face'].'" align="absmiddle" width="20px" height="20px">'.$rs['name'].' &nbsp;';
  1267. $fstr.=','.$rs['face'].'';
  1268. $fled = 'webmain/we/ying/yingyong/'.$rs['num'].'.html';
  1269. if(file_exists($fled))$fstr.=','.$fled.'';
  1270. $fled = 'webmain/we/ying/yingyong/'.$rs['num'].'.js';
  1271. if(file_exists($fled))$fstr.=','.$fled.'';
  1272. $fled = 'webmain/we/ying/yingyong/ying_'.$rs['num'].'Class.php';
  1273. if(file_exists($fled))$fstr.=','.$fled.'';
  1274. $fled = 'webmain/model/agent/'.$rs['num'].'Model.php';
  1275. if(file_exists($fled))$fstr.=','.$fled.'';
  1276. }
  1277. if($ids){
  1278. $barr['agent'] = substr($ids,1);
  1279. $barr['agent_str'] = $mname;
  1280. }
  1281. if($fstr)$barr['file'] = substr($fstr,1);
  1282. }
  1283. return returnsuccess($barr);
  1284. }
  1285. public function createinstseAjax()
  1286. {
  1287. if(!class_exists('ZipArchive'))return returnerror('没有zip扩展无法使用');
  1288. if(getconfig('systype')=='demo')return returnerror('演示不要操作');
  1289. if(!getconfig('rockinzip'))return returnerror('系统未开启此功能');
  1290. $name = $this->post('name');
  1291. if(!$name)$name=TITLE.'_生成包';
  1292. $signstr = '';
  1293. $str = "<?php
  1294. //安装包的配置文件
  1295. return array(
  1296. 'name' => '$name', //名称
  1297. 'ver' => '".$this->post('ver')."', //版本
  1298. 'minver'=>'".VERSION."',
  1299. 'zuozhe' => '".$this->post('zuozhe')."', //作者
  1300. 'explain' => '".$this->post('explain')."', //说明
  1301. 'updatedt'=> '$this->now', //时间
  1302. 'signstr' => '$signstr', //这个是签名
  1303. );";
  1304. $path = ''.UPDIR.'/logs/xhazbao_'.time().'';
  1305. $this->rock->createtxt(''.$path.'/installconfig/xinhuoa_config.php', $str);
  1306. //复制文件
  1307. $file = $this->post('file');
  1308. if($file){
  1309. $filea = explode(',', $file);
  1310. foreach($filea as $fid1){
  1311. if(file_exists($fid1)){
  1312. $this->rock->createdir($path.'/'.$fid1);
  1313. copy(ROOT_PATH.'/'.$fid1, ROOT_PATH.'/'.$path.'/'.$fid1);
  1314. }
  1315. }
  1316. }
  1317. $data = array();
  1318. $modeid = $this->post('mode');
  1319. $menuid = $this->post('menu');
  1320. $tabless = $this->post('table');
  1321. $agentid = $this->post('agent');
  1322. if($menuid){
  1323. $rows = $this->db->getall("select * from `[Q]menu` where id in($menuid)");
  1324. $data['menu'] = $this->shangxiajich($rows,'pid');
  1325. }
  1326. if($modeid){
  1327. //创建模块文件
  1328. $mode = $this->db->getall("select * from `[Q]flow_set` where `id` in($modeid)");
  1329. $cdata= array();
  1330. foreach($mode as $k=>$rs){
  1331. $id = $rs['id'];
  1332. //元素
  1333. $flow_element = $this->db->getall("select * from `[Q]flow_element` where mid='$id'");
  1334. //权限
  1335. $flow_extent = $this->db->getall("select * from `[Q]flow_extent` where modeid='$id'");
  1336. //单据操作菜单
  1337. $flow_menu = $this->db->getall("select * from `[Q]flow_menu` where setid='$id'");
  1338. //模块条件
  1339. $flow_where = $this->db->getall("select * from `[Q]flow_where` where setid='$id'");
  1340. //审核步骤,有上下级关系
  1341. $flow_courses = $this->db->getall("select * from `[Q]flow_course` where setid='$id'");
  1342. $flow_course = $this->shangxiajich($flow_courses,'mid');
  1343. //单据通知设置
  1344. $flow_todo = $this->db->getall("select * from `[Q]flow_todo` where setid='$id'");
  1345. //unset($rs['id']);
  1346. if($rs['isflow']>2)$rs['isflow']='1';
  1347. $cdata[$rs['num']] = array(
  1348. 'flow_set' => $rs,
  1349. 'flow_element' => $flow_element,
  1350. 'flow_extent' => $flow_extent,
  1351. 'flow_menu' => $flow_menu,
  1352. 'flow_where' => $flow_where,
  1353. 'flow_course' => $flow_course,
  1354. 'flow_todo' => $flow_todo,
  1355. );
  1356. }
  1357. $data['mode'] = $cdata;
  1358. }
  1359. //应用的数据
  1360. if($agentid){
  1361. $yyrows = $this->db->getall("select * from `[Q]im_group` where valid=1 and type=2 and id in($agentid)");
  1362. $yydata = array();
  1363. foreach($yyrows as $k=>$rs){
  1364. $menu = $this->db->getall("select * from `[Q]im_menu` where mid='".$rs['id']."'");
  1365. $yydata[] = array(
  1366. 'data' => $rs,
  1367. 'menu' => $this->shangxiajich($menu,'pid', 'menusub')
  1368. );
  1369. }
  1370. $data['yydata']= $yydata;
  1371. }
  1372. if($data){
  1373. $this->rock->createtxt($path.'/installconfig/xinhuoa_data.json', json_encode($data));
  1374. }
  1375. //数据库
  1376. if($tabless){
  1377. $data = array();
  1378. $yaotable = explode(',', $tabless);
  1379. foreach($yaotable as $tabs){
  1380. $fields = $this->db->gettablefields(PREFIX.$tabs);
  1381. $shwdat = array(
  1382. 'fields' => $fields,
  1383. );
  1384. $sqla = $this->db->getall('show create table `'.PREFIX.$tabs.'`');
  1385. $createsql = $sqla[0]['Create Table'];
  1386. $crse = explode('ENGINE', $createsql);
  1387. $createsql = $crse[0].'ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8';
  1388. $shwdat['createsql'] = str_replace('`'.PREFIX.$tabs.'`','`[Q]'.$tabs.'`', $createsql);
  1389. $data[$tabs] = $shwdat;
  1390. }
  1391. if($data)$this->rock->createtxt($path.'/installconfig/xinhuoa_mysql.json', json_encode($data));
  1392. }
  1393. $topath = UPDIR.'/logs/xinhuoa_install_'.time().'.zip';
  1394. $this->rock->createtxt($topath, '');
  1395. c('zip')->packzip($path, $topath);
  1396. return returnsuccess('生成成功,点我<a href="'.$topath.'">下载</a>。');
  1397. }
  1398. //上下级处理
  1399. public function shangxiajich($rows, $fid, $ds='children')
  1400. {
  1401. $this->rsxiada = array();
  1402. $sarrr = array();
  1403. foreach($rows as $k=>$rs){
  1404. $children = $this->shangxiajichs($rows, $fid, $rs['id']);
  1405. if($children)$rs[$ds] = $children;
  1406. $sarrr[]= $rs;
  1407. }
  1408. $barr = array();
  1409. foreach($sarrr as $k=>$rs){
  1410. if(!isset($this->rsxiada[$rs['id']]))$barr[] = $rs;
  1411. }
  1412. return $barr;
  1413. }
  1414. public function shangxiajichs($rows, $fid, $pid)
  1415. {
  1416. $arr = array();
  1417. foreach($rows as $k=>$rs){
  1418. if($rs[$fid]==$pid){
  1419. $this->rsxiada[$rs['id']] = $rs['id'];
  1420. $children = $this->shangxiajichs($rows, $fid, $rs['id']);
  1421. if($children)$rs['children'] = $children;
  1422. $arr[] = $rs;
  1423. }
  1424. }
  1425. return $arr;
  1426. }
  1427. }
粤ICP备19079148号