webmainAction.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498
  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. m($table)->delete("`id` in($id)");
  176. }else{
  177. $this->showreturn('','未设置删除权限' , 201);
  178. }
  179. }else{
  180. $aid = explode(',', $id);
  181. foreach($aid as $mid){
  182. $msg = m('flow')->deletebill($modenum, $mid, '');
  183. if($msg != 'ok')$this->showreturn('', $msg, 201);
  184. }
  185. }
  186. $this->showreturn('');
  187. }
  188. public function publicstoreAjax()
  189. {
  190. $this->iszclogin();
  191. $table = $this->rock->xssrepstr($this->rock->iconvsql($this->request('tablename_abc','',1),1));
  192. $fields = '*';
  193. $group = '';
  194. $order = $this->rock->iconvsql($this->request('defaultorder'));
  195. $aftera = $this->request('storeafteraction');
  196. $modenum = $this->post('modenum');
  197. $atype = $this->post('atype');
  198. $execldown = $this->request('execldown');
  199. $this->loadci = (int)$this->request('loadci');
  200. $where = '1=1 ';
  201. $beforea = $this->request('storebeforeaction');
  202. $tables = $this->T($table);
  203. if($modenum != ''){
  204. $this->flow = m('flow')->initflow($modenum);
  205. $nas = $this->flow->billwhere($this->adminid, $atype);
  206. $_wehs = $nas['where'];
  207. if(!isempt($nas['order']))$order = $nas['order'];
  208. if(!isempt($nas['fields']))$fields = $nas['fields'];
  209. if(!isempt($this->rock->arrvalue($nas, 'group')))$group = $nas['group'];
  210. if($_wehs!='')$where .= ' '.$_wehs.' ';
  211. $_tabsk = $nas['table'];
  212. if(contain($_tabsk,' ')){
  213. $tables = $_tabsk;
  214. }else{
  215. $table = $_tabsk;
  216. $tables = $this->T($table);
  217. }
  218. }
  219. if($beforea != ''){
  220. if(method_exists($this, $beforea)){
  221. $nas = $this->$beforea($table);
  222. if(is_array($nas)){
  223. if(isset($nas['where']))$where .= $nas['where'];
  224. if(isset($nas['order']))$order = $nas['order'];
  225. if(isset($nas['fields']))$fields = $nas['fields'];
  226. if(isset($nas['table']))$tables = $nas['table'];
  227. if(isset($nas['group']))$group = $nas['group'];
  228. }else{
  229. $where .= $nas;
  230. }
  231. }
  232. }
  233. if($tables==PREFIX)exit('无效的访问');
  234. $arr = $this->limitRows($tables, $fields, $where, $order, array(
  235. 'group' => $group
  236. ));
  237. $total = $arr['total'];
  238. $rows = $arr['rows'];
  239. $bacarr = array(
  240. 'totalCount'=> $total,
  241. 'rows' => $rows
  242. );
  243. if(method_exists($this, $aftera)){
  244. $narr = $this->$aftera($table, $rows);
  245. if(is_array($narr)){
  246. foreach($narr as $kv=>$vv)$bacarr[$kv]=$vv;
  247. }
  248. }
  249. if($this->flow){
  250. $rows = $bacarr['rows'];
  251. foreach($rows as $k=>$rs){
  252. if(isset($rs['status'])){
  253. $rs['statustext'] = $this->flow->getstatus($rs,'','',1);
  254. if($rs['status']==5)$rs['ishui'] = 1;
  255. }
  256. $rows[$k] = $this->flow->flowrsreplace($rs,2);
  257. }
  258. $bacarr['rows'] = $this->flow->daochusubtable($rows);
  259. }
  260. if($execldown == 'true'){
  261. $this->exceldown($bacarr);
  262. return;
  263. }
  264. $this->returnjson($bacarr);
  265. }
  266. /**
  267. * 验证签名
  268. */
  269. public function checksignature($table)
  270. {
  271. if(!getconfig('checksign'))return true;//不验证
  272. $sign = $this->post('sys_signature');
  273. $time = $this->post('sys_timeature');
  274. $signs= md5($this->rock->nowurl().$table.$time.'_'.$this->adminid);
  275. return ($sign==$signs);
  276. }
  277. /**
  278. * 公共保存页面
  279. */
  280. public function publicsaveAjax()
  281. {
  282. $this->iszclogin();
  283. $msg = '';
  284. $success= false;
  285. $table = $this->rock->xssrepstr($this->rock->iconvsql($this->post('tablename_postabc','',1),1));
  286. $id = (int)$this->post('id');
  287. $oldrs = false;
  288. if(isempt($table))return returnerror('错误表名');
  289. if(!$this->checksignature($this->post('tablename_postabc')))return returnerror('无效请求');
  290. $db = m($table);
  291. $where = "`id`='$id'";
  292. if($id==0)$where='';
  293. $modenum = $this->post('sysmodenumabc');
  294. $flow = null;
  295. $msgerrortpl = $this->post('msgerrortpl');
  296. $aftersavea = $this->post('aftersaveaction', 'publicaftersave');
  297. $beforesavea = $this->post('beforesaveaction', 'publicbeforesave');
  298. $submditfi = $this->rock->jm->base64decode($this->post('submitfields_postabc'));
  299. $editrecord = $this->post('editrecord_postabc'); //是否保存修改记录
  300. $fileid = $this->post('fileid', '0');
  301. $isturn = (int)$this->post('isturn_postabc', '1');
  302. $int_type = ','.$this->post('int_filestype').',';
  303. $md5_type = ','.$this->post('md5_filestype').',';
  304. if(isempt($submditfi))return returnerror('无效字段');
  305. if($modenum!='')$flow = m('flow')->initflow($modenum);
  306. $fields = explode(',', $submditfi);
  307. $uaarr = array();
  308. foreach($fields as $field){
  309. $field = $this->rock->xssrepstr($field);
  310. $val = $this->post(''.$field.'');
  311. $type = $this->post(''.$field.'_fieldstype');
  312. $boa = true;
  313. if($this->contain($int_type, ','.$field.',')){
  314. $val = (int)$val;
  315. }
  316. if($this->contain($md5_type, ','.$field.',')){
  317. if($val=='')$boa=false;
  318. $val = md5($val);
  319. }
  320. if($boa)$uaarr[$field]=$val;
  321. }
  322. $otherfields = $this->post('otherfields');
  323. $addotherfields = $this->post('add_otherfields');
  324. $editotherfields = $this->post('edit_otherfields');
  325. if($id == 0)$otherfields.=','.$addotherfields.'';
  326. if($id > 0)$otherfields.=','.$editotherfields.'';
  327. if($otherfields != ''){
  328. $otherfields = str_replace(array('{now}','{date}','{admin}','{adminid}'),array($this->now,date('Y-m-d'),$this->adminname,$this->adminid),$otherfields);
  329. if(contain($otherfields,'{companyid}'))$otherfields = str_replace('{companyid}',m('admin')->getcompanyid(),$otherfields);
  330. $fiarsse = explode(',', $otherfields);
  331. foreach($fiarsse as $ffes){
  332. if($ffes!=''){
  333. $ssare = explode('=', $ffes);
  334. $lea = substr($ssare[1],0,1);
  335. if($lea == '['){
  336. $uaarr[$ssare[0]]=$uaarr[substr($ssare[1],1,-1)];
  337. }else{
  338. $uaarr[$ssare[0]]=$ssare[1];
  339. }
  340. }
  341. }
  342. }
  343. $ss = '';
  344. if(!$this->isempt($beforesavea)){
  345. if(method_exists($this, $beforesavea)){
  346. $befa = $this->$beforesavea($table, $uaarr, $id);
  347. if(is_string($befa)){
  348. $ss = $befa;
  349. }else{
  350. if(isset($befa['msg']))$ss=$befa['msg'];
  351. if(isset($befa['rows'])){
  352. foreach($befa['rows'] as $bk=>$bv)$uaarr[$bk]=$bv;
  353. }
  354. }
  355. }
  356. }
  357. $msg = $ss;
  358. $idadd = false;
  359. if($msg == ''){
  360. if($id>0 && $editrecord=='true')$oldrs = $db->getone($id);
  361. $sbo = $db->record($uaarr, $where);
  362. if($sbo){
  363. $msg = '处理成功';
  364. $success= true;
  365. if($id == 0){
  366. $id = $this->db->insert_id();
  367. $idadd = true;
  368. }
  369. if($fileid !='0')m('file')->addfile($fileid,$table,$id, $modenum);
  370. if(!$this->isempt($aftersavea)){
  371. if(method_exists($this, $aftersavea)){
  372. $this->$aftersavea($table, $uaarr, $id, $idadd);
  373. }
  374. }
  375. //保存修改记录
  376. if($oldrs && $flow!=null){
  377. $newrs = $db->getone($id);
  378. m('edit')->recordstr($flow->fieldsarr,$flow->mtable, $id, $oldrs, $newrs, 2);
  379. }
  380. }else{
  381. $msg = 'mysqlerr:'.$this->db->lasterror();
  382. }
  383. }
  384. if($msg=='')$msg='处理失败';
  385. $arr = array('success'=>$success,'msg'=>$msg,'id'=>$id);
  386. echo json_encode($arr);
  387. }
  388. public function publicsavevalueAjax()
  389. {
  390. $this->iszclogin();
  391. $table = $this->rock->xssrepstr($this->rock->iconvsql($this->post('tablename','',1),1));
  392. if(!$this->checksignature($this->post('tablename')))return '无效请求';
  393. $noupf = array('pass','user');
  394. $id = c('check')->onlynumber($this->post('id', '0'));
  395. $fields = $this->post('fieldname');
  396. if(in_array(strtolower($fields), $noupf))return 'error';
  397. $value = $this->post('value');
  398. $where = "`id` in($id)";
  399. m($table)->record(array($fields=>$value), $where);
  400. $fiesa = $this->rock->request('fieldsafteraction');
  401. if($fiesa!=''){
  402. if(method_exists($this, $fiesa)){
  403. $this->$fiesa($table, $fields, $value, $id);
  404. }
  405. }
  406. echo 'success';
  407. }
  408. public function exceldown($arr)
  409. {
  410. $fields = explode(',', $this->post('excelfields','',1));
  411. $header = explode(',', $this->post('excelheader','',1));
  412. $title = $this->post('exceltitle','',1);
  413. $rows = $arr['rows'];
  414. $exceltype = $this->post('exceltype','xls'); //保存文件类型
  415. if(!in_array($exceltype, array('doc','html')))$exceltype = 'xls';
  416. $headArr = array();
  417. for($i=0; $i<count($fields); $i++){
  418. $headArr[$fields[$i]] = $header[$i];
  419. }
  420. $url = c('html')->execltable($title, $headArr, $rows, $exceltype);
  421. $this->returnjson(array(
  422. 'url' => $url,
  423. 'totalCount'=> $arr['totalCount'],
  424. 'downCount' => count($rows)
  425. ));
  426. }
  427. public function getoptionAjax()
  428. {
  429. $num = $this->get('num');
  430. $arr = m('option')->getdata($num);
  431. echo json_encode($arr);
  432. }
  433. public function filejsbase()
  434. {
  435. $url = getconfig('rockfile_url');
  436. if(!$url)return '';
  437. return '<script src="'.$url.'?m=filejs&key='.getconfig('rockfile_key').'&a=base&optid='.$this->adminid.'&optname='.$this->jm->base64encode($this->adminname).'"></script>'.chr(10).'';
  438. }
  439. }
  440. class ActionNot extends Action
  441. {
  442. public function publicsavevalueAjax(){}
  443. public function publicsaveAjax(){}
  444. public function publicdelAjax(){}
  445. public function publicstoreAjax(){}
  446. public function publictreestoreAjax(){}
  447. public function getoptionAjax(){}
  448. protected function logincheck(){}
  449. /**
  450. * 手机端/单据详情页判断有没有登录就根据cookie登录
  451. */
  452. protected function mweblogin($lx=0, $ismo=false)
  453. {
  454. $uid = m('login')->autologin((int)$this->get('adminid','0'), $this->get('token'));
  455. if($uid==0){
  456. $this->loginnot($ismo);
  457. }else{
  458. $this->initProject(); //登录成功
  459. }
  460. $this->adminid = $uid;
  461. return $uid;
  462. }
  463. }
粤ICP备19079148号