flowAction.php 49 KB

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