flowAction.php 50 KB

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