webmainAction.php 16 KB

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