flowAction.php 50 KB

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