flowAction.php 50 KB

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