webmainAction.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541
  1. <?php
  2. /**
  3. 网址管理后台控制处理
  4. */
  5. require(ROOT_PATH.'/include/Action.php');
  6. class Action extends mainAction
  7. {
  8. public $adminid = 0;
  9. public $adminuser = '';
  10. public $adminname = '';
  11. public $admintoken = '';
  12. public $companyid = 0;
  13. public $loadci = 0;
  14. public $flow;
  15. protected $ajaxbool = 'false';
  16. public function getlogin($lx=0)
  17. {
  18. $this->ajaxbool = $this->rock->jm->gettoken('ajaxbool', 'false');
  19. $this->adminid = (int)$this->getsession('adminid',0);
  20. $this->adminuser = $this->getsession('adminuser');
  21. $this->adminname = $this->getsession('adminname');
  22. $this->admintoken = $this->getsession('admintoken');
  23. $this->companyid = $this->getsession('companyid');
  24. $this->setNowUser($this->adminid, $this->adminname, $this->adminuser);
  25. $agid = $this->rock->get('agentid');
  26. if($agid!='')$this->rock->savesession(array('wxqyagentid' => $agid));
  27. $platsign= $this->rock->get('platsign');
  28. if($platsign!='')$this->rock->savesession(array('platsign' => $platsign));
  29. if($lx==0)$this->logincheck();
  30. }
  31. public function setNowUser($uid, $uname, $user='')
  32. {
  33. $this->rock->adminid = $uid;
  34. $this->rock->adminname = $uname;
  35. $this->rock->adminuser = $user;
  36. }
  37. //免登录验证,用于订阅报表的
  38. private function loginsubscribe()
  39. {
  40. $subscribe_key = $this->post('subscribe_key');
  41. $subscribe_post = $this->post('subscribe_post');
  42. if(isempt($subscribe_key) || isempt($subscribe_post))return false;
  43. $url = $this->rock->nowurl();
  44. $time = time(); $time1 = $time+1;
  45. $keyarr = array(md5($url.$time.$subscribe_post),md5($url.$time1.$subscribe_post));
  46. if(!in_array($subscribe_key, $keyarr))return false;
  47. $opkey = $this->option->getval('subscribe_key');
  48. if(!in_array($opkey, $keyarr))return false;
  49. $adminid = (int)$this->post('subscribe_adminid','0');
  50. $this->setNowUser($adminid,'');
  51. return true;
  52. }
  53. protected function loginnot($ismo=false)
  54. {
  55. if($this->loginsubscribe())return;//免验证
  56. $uid = (int)$this->getsession('adminid',0);
  57. if($uid==0){
  58. $lurl = '?m=login';
  59. if($this->rock->ismobile() || $ismo)$lurl='?d=we&m=login';
  60. if(ENTRANCE != 'index')$lurl = 'index.php'.$lurl.'';
  61. $backurl = $this->rock->jm->base64encode($this->rock->nowurl());
  62. if($backurl!='' && M!='index')$lurl = $lurl.'&backurl='.$backurl.'';
  63. if(!isajax())$this->rock->location($lurl); //不是ajax跳转到登录页面
  64. echo '没有登录,去<a href="'.$lurl.'">[登录]</a>';
  65. exit();
  66. }
  67. }
  68. protected function logincheck()
  69. {
  70. $this->loginnot();
  71. }
  72. public function initProject()
  73. {
  74. $this->getlogin();
  75. if($this->rock->get('ajaxbool')=='true')return;
  76. $this->smartydata['adminid'] = $this->adminid;
  77. $this->smartydata['adminuser'] = $this->adminuser;
  78. $this->smartydata['adminname'] = $this->adminname;
  79. $this->smartydata['logintime'] = $this->getsession('logintime');
  80. $cenghei = (int)$this->get('cenghei','0');
  81. if($cenghei==0)$cenghei = $this->getsession('cenghei','0');
  82. $this->assign('cenghei', $cenghei);
  83. $this->rock->savesession(array('cenghei' => $cenghei));
  84. }
  85. private function iszclogin()
  86. {
  87. if($this->loginsubscribe())return;//免验证
  88. $token = $this->admintoken;
  89. if(isempt($token))exit('sorry1');
  90. $lastt = date('Y-m-d H:i:s',time()-24*3600);
  91. $rs = m('logintoken')->getone("`uid`='$this->adminid' and `token`='$token' and `online`=1 and `moddt`>='$lastt'",'`moddt`');
  92. if(!$rs)$this->backmsg('登录失效,请重新登录');
  93. }
  94. public function backmsg($msg='', $demsg='保存成功', $da=array())
  95. {
  96. backmsg($msg,$demsg,$da);
  97. }
  98. public function limitRows($table,$fields='*',$wherea='1=1',$order='',$arr=array())
  99. {
  100. $where = $this->request('where');
  101. $keywhere = $this->request('keywhere');
  102. if(!isempt($where)){
  103. $where = $this->jm->uncrypt($this->rock->iconvsql($where));
  104. $where = $this->db->filterstr($this->rock->covexec($where));
  105. }
  106. if(!isempt($keywhere)){
  107. $keywhere = $this->jm->uncrypt($this->rock->iconvsql($keywhere));
  108. $keywhere = $this->db->filterstr($this->rock->covexec($keywhere));
  109. }
  110. $wherea .= " $where $keywhere";
  111. $order = $this->getOrder($order);
  112. $group = '';
  113. if(isset($arr['group']) && !isempt($arr['group']))$group="GROUP BY ".$arr['group']." ";
  114. $limitall = false;
  115. if(isset($arr['all']))$limitall= $arr['all'];
  116. if(isset($arr['sou'])){
  117. $wherea = str_replace($arr['sou'],$arr['rep'],$wherea);
  118. $order = str_replace($arr['sou'],$arr['rep'],$order);
  119. }
  120. $sql = "select[SQL_CALC] $fields from $table where $wherea $group $order ";
  121. $total = 0;
  122. if($group!=''){
  123. $sql = str_replace('[SQL_CALC]', ' SQL_CALC_FOUND_ROWS', $sql);
  124. }else{
  125. $sql = str_replace('[SQL_CALC]','',$sql);
  126. $total = $this->db->rows($table, $wherea);
  127. }
  128. if(!$limitall)$sql.=' '.$this->getLimit();
  129. $rows = $this->db->getall($sql);
  130. if($group!='')$total = $this->db->found_rows();
  131. if(!is_array($rows))$rows = array();
  132. return array(
  133. 'total' => $total,
  134. 'rows' => $rows,
  135. 'sql' => $this->db->nowsql
  136. );
  137. }
  138. public function getLimit()
  139. {
  140. $start = (int)$this->rock->post('start',0);
  141. $limit = (int)$this->rock->post('limit',15);
  142. $str = '';
  143. if($limit > 0)$str =" limit $start,$limit";
  144. return $str;
  145. }
  146. public function getOrder($order='')
  147. {
  148. $sort = $this->rock->iconvsql($this->post('sort'),1);
  149. $dir = strtolower($this->post('dir'));
  150. $highorder = $this->rock->iconvsql($this->post('highorder'));
  151. $asort = '';
  152. if($sort != '' && $dir !=''){
  153. if(!contain('ascdesc',$dir))$dir='desc';
  154. $sorta = $sort;
  155. $asort=' '.$sorta.' '.$dir.'';
  156. }
  157. if($asort != '')$order = $asort;
  158. if($highorder != '')$order = $highorder;
  159. if($order != '')$order=" order by $order ";
  160. return $order;
  161. }
  162. public function publicdelAjax()
  163. {
  164. $this->iszclogin();
  165. $id = c('check')->onlynumber($this->rock->post('id'));
  166. $table = $this->rock->iconvsql($this->rock->post('table','',1),1);
  167. $modenum= $this->rock->post('modenum');
  168. if(getconfig('systype')=='demo')$this->showreturn('', '演示数据禁止删除', 201);
  169. if($id=='')$this->showreturn('', 'sorry', 201);
  170. $isadmin= (int)$this->getsession('isadmin');
  171. $deltba = array('todo','option','menu','wouser');
  172. if($modenum==''){
  173. if($isadmin != 1 && $table!='todo')$this->showreturn('','只有管理员才能操作' , 201);
  174. if(substr($table,0,5)=='flow_' || in_array($table, $deltba)){
  175. $flow_element = m($table)->getone($id);
  176. m($table)->delete("`id` in($id)");
  177. //自动生成摘要显示
  178. // if ($table == 'flow_element') {
  179. // $this->save_summarx($flow_element['mid']);
  180. // }
  181. }else{
  182. $this->showreturn('','未设置删除权限' , 201);
  183. }
  184. }else{
  185. $aid = explode(',', $id);
  186. foreach($aid as $mid){
  187. $msg = m('flow')->deletebill($modenum, $mid, '');
  188. if($msg != 'ok')$this->showreturn('', $msg, 201);
  189. }
  190. }
  191. $this->showreturn('');
  192. }
  193. public function publicstoreAjax()
  194. {
  195. $this->iszclogin();
  196. $table = $this->rock->xssrepstr($this->rock->iconvsql($this->request('tablename_abc','',1),1));
  197. $fields = '*';
  198. $group = '';
  199. $order = $this->rock->iconvsql($this->request('defaultorder'));
  200. $aftera = $this->request('storeafteraction');
  201. $modenum = $this->post('modenum');
  202. $atype = $this->post('atype');
  203. $execldown = $this->request('execldown');
  204. $this->loadci = (int)$this->request('loadci');
  205. $where = '1=1 ';
  206. $beforea = $this->request('storebeforeaction');
  207. $tables = $this->T($table);
  208. if($modenum != ''){
  209. $this->flow = m('flow')->initflow($modenum);
  210. $nas = $this->flow->billwhere($this->adminid, $atype);
  211. $_wehs = $nas['where'];
  212. if(!isempt($nas['order']))$order = $nas['order'];
  213. if(!isempt($nas['fields']))$fields = $nas['fields'];
  214. if(!isempt($this->rock->arrvalue($nas, 'group')))$group = $nas['group'];
  215. if($_wehs!='')$where .= ' '.$_wehs.' ';
  216. $_tabsk = $nas['table'];
  217. if(contain($_tabsk,' ')){
  218. $tables = $_tabsk;
  219. }else{
  220. $table = $_tabsk;
  221. $tables = $this->T($table);
  222. }
  223. }
  224. if($beforea != ''){
  225. if(method_exists($this, $beforea)){
  226. $nas = $this->$beforea($table);
  227. if(is_array($nas)){
  228. if(isset($nas['where']))$where .= $nas['where'];
  229. if(isset($nas['order']))$order = $nas['order'];
  230. if(isset($nas['fields']))$fields = $nas['fields'];
  231. if(isset($nas['table']))$tables = $nas['table'];
  232. if(isset($nas['group']))$group = $nas['group'];
  233. }else{
  234. $where .= $nas;
  235. }
  236. }
  237. }
  238. if($tables==PREFIX)exit('无效的访问');
  239. $arr = $this->limitRows($tables, $fields, $where, $order, array(
  240. 'group' => $group
  241. ));
  242. $total = $arr['total'];
  243. $rows = $arr['rows'];
  244. $bacarr = array(
  245. 'totalCount'=> $total,
  246. 'rows' => $rows
  247. );
  248. if(method_exists($this, $aftera)){
  249. $narr = $this->$aftera($table, $rows);
  250. if(is_array($narr)){
  251. foreach($narr as $kv=>$vv)$bacarr[$kv]=$vv;
  252. }
  253. }
  254. if($this->flow){
  255. $rows = $bacarr['rows'];
  256. foreach($rows as $k=>$rs){
  257. if(isset($rs['status'])){
  258. $rs['statustext'] = $this->flow->getstatus($rs,'','',1);
  259. if($rs['status']==5)$rs['ishui'] = 1;
  260. }
  261. $rows[$k] = $this->flow->flowrsreplace($rs,2);
  262. }
  263. $bacarr['rows'] = $this->flow->daochusubtable($rows);
  264. }
  265. if($execldown == 'true'){
  266. $this->exceldown($bacarr);
  267. return;
  268. }
  269. $this->returnjson($bacarr);
  270. }
  271. /**
  272. * 验证签名
  273. */
  274. public function checksignature($table)
  275. {
  276. if(!getconfig('checksign'))return true;//不验证
  277. $sign = $this->post('sys_signature');
  278. $time = $this->post('sys_timeature');
  279. $signs= md5($this->rock->nowurl().$table.$time.'_'.$this->adminid);
  280. return ($sign==$signs);
  281. }
  282. /**
  283. * 公共保存页面
  284. */
  285. public function publicsaveAjax()
  286. {
  287. $this->iszclogin();
  288. $msg = '';
  289. $success= false;
  290. $table = $this->rock->xssrepstr($this->rock->iconvsql($this->post('tablename_postabc','',1),1));
  291. $id = (int)$this->post('id');
  292. $oldrs = false;
  293. if(isempt($table))return returnerror('错误表名');
  294. if(!$this->checksignature($this->post('tablename_postabc')))return returnerror('无效请求');
  295. $db = m($table);
  296. $where = "`id`='$id'";
  297. if($id==0)$where='';
  298. $modenum = $this->post('sysmodenumabc');
  299. $flow = null;
  300. $msgerrortpl = $this->post('msgerrortpl');
  301. $aftersavea = $this->post('aftersaveaction', 'publicaftersave');
  302. $beforesavea = $this->post('beforesaveaction', 'publicbeforesave');
  303. $submditfi = $this->rock->jm->base64decode($this->post('submitfields_postabc'));
  304. $editrecord = $this->post('editrecord_postabc'); //是否保存修改记录
  305. $fileid = $this->post('fileid', '0');
  306. $isturn = (int)$this->post('isturn_postabc', '1');
  307. $int_type = ','.$this->post('int_filestype').',';
  308. $md5_type = ','.$this->post('md5_filestype').',';
  309. if(isempt($submditfi))return returnerror('无效字段');
  310. if($modenum!='')$flow = m('flow')->initflow($modenum);
  311. $fields = explode(',', $submditfi);
  312. $uaarr = array();
  313. foreach($fields as $field){
  314. $field = $this->rock->xssrepstr($field);
  315. $val = $this->post(''.$field.'');
  316. $type = $this->post(''.$field.'_fieldstype');
  317. $boa = true;
  318. if($this->contain($int_type, ','.$field.',')){
  319. $val = (int)$val;
  320. }
  321. if($this->contain($md5_type, ','.$field.',')){
  322. if($val=='')$boa=false;
  323. $val = md5($val);
  324. }
  325. if($boa)$uaarr[$field]=$val;
  326. }
  327. $otherfields = $this->post('otherfields');
  328. $addotherfields = $this->post('add_otherfields');
  329. $editotherfields = $this->post('edit_otherfields');
  330. if($id == 0)$otherfields.=','.$addotherfields.'';
  331. if($id > 0)$otherfields.=','.$editotherfields.'';
  332. if($otherfields != ''){
  333. $otherfields = str_replace(array('{now}','{date}','{admin}','{adminid}'),array($this->now,date('Y-m-d'),$this->adminname,$this->adminid),$otherfields);
  334. $fiarsse = explode(',', $otherfields);
  335. foreach($fiarsse as $ffes){
  336. if($ffes!=''){
  337. $ssare = explode('=', $ffes);
  338. $lea = substr($ssare[1],0,1);
  339. if($lea == '['){
  340. $uaarr[$ssare[0]]=$uaarr[substr($ssare[1],1,-1)];
  341. }else{
  342. $uaarr[$ssare[0]]=$ssare[1];
  343. }
  344. }
  345. }
  346. }
  347. $ss = '';
  348. if(!$this->isempt($beforesavea)){
  349. if(method_exists($this, $beforesavea)){
  350. $befa = $this->$beforesavea($table, $uaarr, $id);
  351. if(is_string($befa)){
  352. $ss = $befa;
  353. }else{
  354. if(isset($befa['msg']))$ss=$befa['msg'];
  355. if(isset($befa['rows'])){
  356. foreach($befa['rows'] as $bk=>$bv)$uaarr[$bk]=$bv;
  357. }
  358. }
  359. }
  360. }
  361. $msg = $ss;
  362. $idadd = false;
  363. if($msg == ''){
  364. if($id>0 && $editrecord=='true')$oldrs = $db->getone($id);
  365. $sbo = $db->record($uaarr, $where);
  366. if($sbo){
  367. $msg = '处理成功';
  368. $success= true;
  369. $summarx_type = 'edit';
  370. if($id == 0){
  371. $summarx_type = 'insert';
  372. $id = $this->db->insert_id();
  373. $idadd = true;
  374. }
  375. //自动生成摘要显示
  376. if ($table == 'flow_element') {
  377. $flow_element = $db->getone($id);
  378. $this->save_summarx($flow_element['mid'], $id, $summarx_type);
  379. }
  380. if($fileid !='0')m('file')->addfile($fileid,$table,$id, $modenum);
  381. if(!$this->isempt($aftersavea)){
  382. if(method_exists($this, $aftersavea)){
  383. $this->$aftersavea($table, $uaarr, $id, $idadd);
  384. }
  385. }
  386. //保存修改记录
  387. if($oldrs && $flow!=null){
  388. $newrs = $db->getone($id);
  389. m('edit')->recordstr($flow->fieldsarr,$flow->mtable, $id, $oldrs, $newrs, 2);
  390. }
  391. }else{
  392. $msg = 'mysqlerr:'.$this->db->lasterror();
  393. }
  394. }
  395. if($msg=='')$msg='处理失败';
  396. $arr = array('success'=>$success,'msg'=>$msg,'id'=>$id);
  397. echo json_encode($arr);
  398. }
  399. public function publicsavevalueAjax()
  400. {
  401. $this->iszclogin();
  402. $table = $this->rock->xssrepstr($this->rock->iconvsql($this->post('tablename','',1),1));
  403. if(!$this->checksignature($this->post('tablename')))return '无效请求';
  404. $noupf = array('pass','user');
  405. $id = c('check')->onlynumber($this->post('id', '0'));
  406. $fields = $this->post('fieldname');
  407. if(in_array(strtolower($fields), $noupf))return 'error';
  408. $value = $this->post('value');
  409. $where = "`id` in($id)";
  410. m($table)->record(array($fields=>$value), $where);
  411. $fiesa = $this->rock->request('fieldsafteraction');
  412. if($fiesa!=''){
  413. if(method_exists($this, $fiesa)){
  414. $this->$fiesa($table, $fields, $value, $id);
  415. }
  416. }
  417. echo 'success';
  418. }
  419. public function exceldown($arr)
  420. {
  421. $fields = explode(',', $this->post('excelfields','',1));
  422. $header = explode(',', $this->post('excelheader','',1));
  423. $title = $this->post('exceltitle','',1);
  424. $rows = $arr['rows'];
  425. $exceltype = $this->post('exceltype','xls'); //保存文件类型
  426. if(!in_array($exceltype, array('doc','html')))$exceltype = 'xls';
  427. $headArr = array();
  428. for($i=0; $i<count($fields); $i++){
  429. $headArr[$fields[$i]] = $header[$i];
  430. }
  431. $url = c('html')->execltable($title, $headArr, $rows, $exceltype);
  432. $this->returnjson(array(
  433. 'url' => $url,
  434. 'totalCount'=> $arr['totalCount'],
  435. 'downCount' => count($rows)
  436. ));
  437. }
  438. public function getoptionAjax()
  439. {
  440. $num = $this->get('num');
  441. $arr = m('option')->getdata($num);
  442. echo json_encode($arr);
  443. }
  444. public function filejsbase()
  445. {
  446. $url = getconfig('rockfile_url');
  447. if(!$url)return '';
  448. return '<script src="'.$url.'?m=filejs&key='.getconfig('rockfile_key').'&a=base&optid='.$this->adminid.'&optname='.$this->jm->base64encode($this->adminname).'"></script>'.chr(10).'';
  449. }
  450. //自动生成摘要显示(flow_set表summarx字段)
  451. public function save_summarx($mid, $id, $summarx_type)
  452. {
  453. $flow_set = m('flow_set')->getone($mid);
  454. if (!$flow_set['summarx']) { //如果摘要为空全部生成
  455. $flow_element = m('flow_element')->getall('`mid`=' . $mid, '*', '`sort` asc');
  456. $summarx = "'";
  457. $summarx .= $flow_set['name'];
  458. foreach ($flow_element as $key => $val) {
  459. $summarx .= "\r\n" . $val['name'] . ":{" . $val['fields'] . "}";
  460. }
  461. $summarx = $summarx . "'";
  462. m('flow_set')->update('`summarx`=' . $summarx, $mid);
  463. } else { //已有摘要
  464. //如果是新增字段,则新增摘要;如果是更新字段,不做处理
  465. if ($summarx_type == 'insert') {
  466. $flow_element = m('flow_element')->getone($id);
  467. $summarx = "'";
  468. $summarx .= $flow_set['summarx'];
  469. $summarx .= "\r\n" . $flow_element['name'] . ":{" . $flow_element['fields'] . "}";
  470. $summarx = $summarx . "'";
  471. m('flow_set')->update('`summarx`=' . $summarx, $mid);
  472. }
  473. }
  474. }
  475. }
  476. class ActionNot extends Action
  477. {
  478. public function publicsavevalueAjax(){}
  479. public function publicsaveAjax(){}
  480. public function publicdelAjax(){}
  481. public function publicstoreAjax(){}
  482. public function publictreestoreAjax(){}
  483. public function getoptionAjax(){}
  484. protected function logincheck(){}
  485. /**
  486. * 手机端/单据详情页判断有没有登录就根据cookie登录
  487. */
  488. protected function mweblogin($lx=0, $ismo=false)
  489. {
  490. $uid = m('login')->autologin((int)$this->get('adminid','0'), $this->get('token'));
  491. if($uid==0){
  492. $this->loginnot($ismo);
  493. }else{
  494. $this->initProject(); //登录成功
  495. }
  496. $this->adminid = $uid;
  497. return $uid;
  498. }
  499. }