flowAction.php 47 KB

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