upgradeAction.php 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876
  1. <?php
  2. /**
  3. * 来自:信呼开发团队
  4. * 作者:磐石(rainrock)
  5. * 网址:http://www.rockoa.com/
  6. * 系统文件
  7. */
  8. class upgradeClassAction extends Action
  9. {
  10. public $keyss;
  11. public function initAction()
  12. {
  13. $this->keyss = $this->option->getval('systemnum');
  14. if (isempt($this->keyss)) {
  15. $rnd = md5(str_shuffle('abcedfghijk') . rand(1000, 9999));
  16. $this->option->setval('systemnum', $rnd);
  17. $this->keyss = $rnd;
  18. }
  19. }
  20. public function dataAjax()
  21. {
  22. $xinhu = c('xinhu');
  23. $db = m('chargems');
  24. $wet = $xinhu->getwebsite();
  25. $barr = $xinhu->getdata('mode', array('sysnum' => $this->keyss, 'saasmode' => getconfig('saasmode'), 'bsste' => $this->option->getval('auther_aukey')));
  26. if ($barr['code'] != 200) exit($barr['msg']);
  27. $rows = array();
  28. $wodekey = $this->jm->getRandkey();
  29. foreach ($barr['data'] as $k => $rs) {
  30. $id = $rs['id'];
  31. $state = 0;
  32. $key = '';
  33. $ors = $db->getone("`type`=0 and `mid`='$id'");
  34. if ($ors) {
  35. $state = 1;
  36. if ($rs['updatedt'] > $ors['updatedt']) $state = 2;
  37. $key = $ors['key'];
  38. }
  39. $view = '<a href="' . $wet . 'view_' . $rs['num'] . '.html" target="_blank" class="a">介绍</a>';
  40. if ($state == 0 && $rs['price'] > 1) $view .= ',<a href="' . $wet . 'view_' . $rs['num'] . '.html" target="_blank" style="color:red">去购买</a>';
  41. $rows[] = array('id' => $id, 'name' => $rs['name'], 'price' => $rs['price'], 'isaz' => $rs['isaz'], 'explain' => $rs['explain'], 'updatedt' => $rs['updatedt'], 'key' => $key, 'view' => $view, 'opt' => $state);
  42. if ($k == 0) {
  43. $wodekey = $rs['wodekey'];
  44. if (arrvalue($rs, 'sdxe') == '1') $this->option->update('`value`=null', 'pid=-101');
  45. }
  46. }
  47. $arr['rows'] = $rows;
  48. $arr['wodekey'] = $wodekey;
  49. $this->returnjson($arr);
  50. }
  51. public function shengjianAjax()
  52. {
  53. $id = $this->post('id');
  54. $key = $this->post('key');
  55. if (!isempt($key) && $this->rock->isjm($key)) $key = $this->jm->uncrypt($key);
  56. $barr = c('xinhu')->getdata('getinstallfile', array('id' => $id, 'sysnum' => $this->keyss, 'key' => $key));
  57. if ($barr['code'] != 200) showreturn('', $barr['msg'], 201);
  58. $data = $barr['data'];
  59. $mrs = $data['rs'];
  60. $rows = $data['rows'];
  61. $uparr = array();
  62. $huira = $this->gethuiarr($id);
  63. $morrs = $this->getmodeuprs($rows);
  64. foreach ($rows as $k => $rs) {
  65. $file = $rs['filepath'];
  66. $bo = true;
  67. if (file_exists($file)) {
  68. $_size = filesize($file);
  69. if ($_size == $rs['filesize']) $bo = false;
  70. }
  71. if ($rs['isup'] == 1) $bo = true;
  72. if (isset($huira[$rs['id']])) $bo = false;
  73. if (in_array($file, $morrs)) $bo = false;
  74. if ($bo) {
  75. $uparr[] = $rs;
  76. }
  77. }
  78. if (!$uparr) {
  79. $this->upsueecc($id, $mrs['updatedt'], $key);
  80. }
  81. showreturn($uparr);
  82. }
  83. private function upsueecc($id, $updatedt, $key)
  84. {
  85. $where = "`type`=0 and `mid`='$id'";
  86. $db = m('chargems');
  87. if ($db->rows($where) == 0) $where = '';
  88. $db->record(array('type' => 0, 'mid' => $id, 'modeid' => $id, 'updatedt' => $updatedt, 'optdt' => $this->now, 'key' => $this->jm->encrypt($key)), $where);
  89. }
  90. private function upsueeccmids($modeid, $mid, $updatedt, $type = 1)
  91. {
  92. $where = "`type`='$type' and `mid`='$mid'";
  93. $db = m('chargems');
  94. if ($db->rows($where) == 0) $where = '';
  95. $db->record(array('type' => $type, 'mid' => $mid, 'modeid' => $modeid, 'updatedt' => $updatedt, 'optdt' => $this->now,), $where);
  96. }
  97. private function getmodeuprs($frows)
  98. {
  99. $rows = m('flow_set')->getall('1=1', '`num`,`status`,`isup`');
  100. $hurs = array();
  101. $nomok = array();
  102. $huwj = getconfig('noupgrademode');
  103. if ($huwj) $nomok = explode(',', $huwj);
  104. foreach ($rows as $k => $rs) {
  105. $num = $rs['num'];
  106. if ($rs['isup'] == '0') {
  107. $nomok[] = $num;
  108. }
  109. }
  110. foreach ($nomok as $num) {
  111. $hurs[] = '' . P . '/flow/input/inputjs/mode_' . $num . '.js';
  112. $hurs[] = '' . P . '/flow/input/mode_' . $num . 'Action.php';
  113. $hurs[] = '' . P . '/flow/page/input_' . $num . '.html';
  114. $hurs[] = '' . P . '/flow/page/view_' . $num . '_0.html';
  115. $hurs[] = '' . P . '/flow/page/view_' . $num . '_1.html';
  116. $hurs[] = '' . P . '/flow/page/view_' . $num . '_2.html';
  117. $hurs[] = '' . P . '/flow/page/viewpage_' . $num . '.html';
  118. $hurs[] = '' . P . '/flow/page/viewpage_' . $num . '_0.html';
  119. $hurs[] = '' . P . '/flow/page/viewpage_' . $num . '_1.html';
  120. $hurs[] = '' . P . '/flow/page/rock_page_' . $num . '.php';
  121. $hurs[] = '' . P . '/model/flow/' . $num . 'Model.php';
  122. }
  123. return $hurs;
  124. }
  125. public function shengjianssAjax()
  126. {
  127. $mid = (int)$this->post('id');
  128. $fileid = (int)$this->post('fileid');
  129. $key = $this->post('key');
  130. if (!isempt($key) && $this->rock->isjm($key)) $key = $this->jm->uncrypt($key);
  131. $oi = $this->post('oii');
  132. $len = $this->post('lens');
  133. $updatedt = $this->post('updatedt');
  134. $upbo = true;
  135. $ors = m('chargems')->getone("`type`=1 and `mid`='$fileid'");
  136. if ($ors && $updatedt <= $ors['optdt']) $upbo = false;
  137. if (isempt($updatedt)) $upbo = true;
  138. if ($upbo) {
  139. $barr = c('xinhu')->getdata('getinstallfileid', array('fid' => $fileid, 'sysnum' => $this->keyss, 'key' => $key, 'ban' => $this->post('ban')));
  140. if ($barr['code'] != 200) exit($barr['msg']);
  141. $data = $barr['data'];
  142. $type = $data['type'];
  143. $filepath = $data['filepath'];
  144. $fcont = $this->jm->base64decode($data['content']);
  145. if ($fcont != '') {
  146. if ($type == 1) {
  147. $bmsg = m('beifen')->updatefabric($fcont);
  148. $this->upsueeccmids($mid, $fileid, $updatedt, 1);
  149. }
  150. if ($type == 9) {
  151. $this->rock->createdir($filepath);
  152. $this->beifenfile($filepath);
  153. @$bo = file_put_contents($filepath, $fcont);
  154. if (!$bo) exit('无法写入:' . $filepath . '');
  155. }
  156. if ($type == 10) {
  157. $this->rock->createdir($filepath);
  158. @file_put_contents($filepath, $fcont);
  159. $sqarr = explode('ROCKSPLIT', $fcont);
  160. $lastid = '0';
  161. $sidw1 = '@id=';
  162. foreach ($sqarr as $_sql1) if ($_sql1) {
  163. if (contain($_sql1, $sidw1)) {
  164. $lastid = '0';
  165. $_asa = explode($sidw1, $_sql1);
  166. $_ors = $this->db->getall($_asa[1]);
  167. if ($_ors) $lastid = $_ors[0]['id'];
  168. continue;
  169. }
  170. if ($_sql1 == 'LASTID') {
  171. $lastid = $this->db->insert_id();
  172. if (isempt($lastid)) $lastid = '0';
  173. } else {
  174. if (contain($_sql1, '{lastid}')) {
  175. if ($lastid != '0') $this->db->query(str_replace('{lastid}', $lastid, $_sql1), false);
  176. } else {
  177. $this->db->query($_sql1, false);
  178. }
  179. }
  180. }
  181. }
  182. }
  183. $udt = $data['updatedt'];
  184. } else {
  185. $udt = $this->now;
  186. }
  187. if ($oi + 1 == $len) {
  188. $this->upsueecc($mid, $udt, $key);
  189. }
  190. echo 'ok';
  191. }
  192. private function beifenfile($path)
  193. {
  194. if (!file_exists($path)) return;
  195. $wz = strripos($path, '/');
  196. $dir = '';
  197. if ($wz === false) {
  198. $file = $path;
  199. } else {
  200. $dir = substr($path, 0, $wz);
  201. $file = substr($path, $wz + 1);
  202. }
  203. $dir = str_replace('/', '-', $dir);
  204. $nfile = '' . $dir . '' . date('YmdHis') . '@' . $file . '';
  205. $topath = '' . UPDIR . '/logs/' . date('Y-m') . '/' . $nfile . '';
  206. $this->rock->createdir($topath);
  207. @copy($path, $topath);
  208. }
  209. private function shengjifile($frs, $key, $modeid)
  210. {
  211. $fid = $frs['id'];
  212. $where = "`type`=1 and `mid`='$fid'";
  213. $db = m('chargems');
  214. $ors = $db->getone($where);
  215. if ($ors) {
  216. if ($frs['updatedt'] <= $ors['optdt']) return;
  217. } else {
  218. $where = '';
  219. }
  220. $barr = c('xinhu')->getdata('getfileinstall', array('id' => $fid, 'sysnum' => $this->keyss, 'key' => $key));
  221. if ($barr['code'] != 200) exit($barr['msg']);
  222. $fcont = $this->jm->base64decode($barr['data']);
  223. if (isempt($fcont)) return;
  224. $mkdir = '' . UPDIR . '/' . date('Y-m');
  225. if ($frs['type'] == 0) {
  226. if (!is_dir($mkdir)) mkdir($mkdir);
  227. $filemy = $mkdir . '/install' . time() . rand(1000, 9999) . '.zip';
  228. file_put_contents($filemy, $fcont);
  229. $bmsg = c('zip')->unzip($filemy, './');
  230. unlink($filemy);
  231. if ($bmsg != 'ok') exit($bmsg);
  232. }
  233. if ($frs['type'] == 1) {
  234. $bmsg = m('beifen')->updatefabric($fcont);
  235. if ($bmsg != 'ok') exit($bmsg);
  236. }
  237. $db->record(array('type' => 1, 'mid' => $fid, 'modeid' => $modeid, 'updatedt' => $frs['updatedt'], 'optdt' => $this->now,), $where);
  238. }
  239. public function tontbudataAjax()
  240. {
  241. $lx = (int)$this->get('lx');
  242. $snum = $this->get('snum');
  243. $barr = c('xinhu')->getdata('getaneydata', array('lx' => $lx, 'snum' => $snum, 'ban' => $this->post('ban')));
  244. if ($barr['code'] != 200) exit($barr['msg']);
  245. $data = $barr['data'];
  246. if (URL == 'http://127.0.0.1/app/xinhu/') exit('本地测试完成');
  247. $msgr = '';
  248. if ($lx == 0) $this->tonbbumenu($data['menu']);
  249. if ($lx == 1) $msgr = $this->tonbbumode($data['mode']);
  250. if ($lx == 4) $this->tonbbumodewq($data['mode']);
  251. if ($lx == 2) $this->tonbbuying($data['yydata']);
  252. if ($lx == 3) $this->tonbbutask($data['task']);
  253. if ($lx == 5) $msgr = $this->tonbbumode($data['mode'], $snum);
  254. echo '同步完成' . $msgr . '';
  255. }
  256. private function tonbbumenu($data)
  257. {
  258. $db = m('menu');
  259. $caid = '0';
  260. foreach ($data as $k => $rs) {
  261. $id = $rs['id'];
  262. if ($db->rows('id=' . $id . '') > 0) {
  263. unset($rs['status']);
  264. unset($rs['ispir']);
  265. unset($rs['ishs']);
  266. if (isempt($rs['num'])) unset($rs['num']);
  267. if (isempt($rs['color'])) unset($rs['color']);
  268. if (isempt($rs['icons'])) unset($rs['icons']);
  269. $db->update($rs, 'id=' . $id . '');
  270. } else {
  271. $db->insert($rs);
  272. }
  273. $caid .= ',' . $id . '';
  274. }
  275. $db->update('status=0', 'id not in(' . $caid . ')');
  276. }
  277. private function tonbbumenuss($data, $pid, $npid, $db)
  278. {
  279. foreach ($data as $k => $rs) {
  280. if ($rs['pid'] == $pid) {
  281. $name = $rs['name'];
  282. $id = $rs['id'];
  283. $where1 = " and `name`='$name'";
  284. if (!isempt($rs['url'])) $where1 = " and (`name`='$name' or `url`='" . $rs['url'] . "')";
  285. $where = "`pid`='$npid' $where1";
  286. $yid = (int)$db->getmou('id', $where);
  287. unset($rs['id']);
  288. $rs['optdt'] = $this->rock->now;
  289. if ($yid == 0) {
  290. $rs['pid'] = $npid;
  291. $this->addci++;
  292. $yid = $db->insert($rs);
  293. } else {
  294. $this->eddci++;
  295. unset($rs['status']);
  296. unset($rs['ispir']);
  297. unset($rs['ishs']);
  298. if (isempt($rs['num'])) unset($rs['num']);
  299. if (isempt($rs['color'])) unset($rs['color']);
  300. if (isempt($rs['icons'])) unset($rs['icons']);
  301. $db->update($rs, $yid);
  302. }
  303. $npid1 = $yid;
  304. $this->tonbbumenuss($data, $id, $npid1, $db);
  305. }
  306. }
  307. }
  308. private function tonbbumode($data, $snum = '')
  309. {
  310. $zcis = 0;
  311. $db = m('flow_set');
  312. $db1 = m('flow_element');
  313. $db2 = m('flow_menu');
  314. $db3 = m('flow_extent');
  315. $db5 = m('flow_course');
  316. $db6 = m('flow_where');
  317. $db7 = m('flow_todo');
  318. $iszdbo = false;
  319. if (!isempt($snum)) $iszdbo = true;
  320. foreach ($data as $num => $arr) {
  321. if ($iszdbo && $num != $snum) continue;
  322. $moders = $db->getone("`num`='$num'", '`id`,`isup`,`name`');
  323. $modeid = 0;
  324. $isup = 1;
  325. if ($moders) {
  326. $modeid = (int)$moders['id'];
  327. $isup = (int)$moders['isup'];
  328. if ($isup == 0) {
  329. if ($num == $snum) exit('此[' . $snum . '.' . $moders['name'] . ']模块未开启同步更新');
  330. continue;
  331. }
  332. }
  333. $flow_set = $arr['flow_set'];
  334. if (isset($flow_set['id'])) unset($flow_set['id']);
  335. $isadd = false;
  336. if ($modeid == 0) {
  337. $modeid = $db->insert($flow_set);
  338. $isadd = true;
  339. } else {
  340. if ($iszdbo) {
  341. unset($flow_set['name']);
  342. unset($flow_set['pctx']);
  343. unset($flow_set['mctx']);
  344. unset($flow_set['wxtx']);
  345. unset($flow_set['emtx']);
  346. unset($flow_set['receid']);
  347. unset($flow_set['recename']);
  348. unset($flow_set['status']);
  349. $db->update($flow_set, $modeid);
  350. } else {
  351. $db->update(array('where' => $flow_set['where'], 'sort' => $flow_set['sort'], 'type' => $flow_set['type'], 'summary' => $flow_set['summary'], 'summarx' => $flow_set['summarx'], 'tables' => $flow_set['tables'], 'names' => $flow_set['names'], 'isscl' => $flow_set['isscl'], 'statusstr' => $flow_set['statusstr']), $modeid);
  352. }
  353. }
  354. $flow_where = $arr['flow_where'];
  355. $sid6 = '0';
  356. foreach ($flow_where as $k6 => $rs6) {
  357. $rs6['setid'] = $modeid;
  358. if (isset($rs6['id'])) unset($rs6['id']);
  359. $num = $rs6['num'];
  360. if (isempt($num)) continue;
  361. $where = "`setid`='$modeid' and `num`='$num'";
  362. if ($db6->rows($where) == 0) {
  363. $db6->insert($rs6);
  364. } else {
  365. $db6->update($rs6, $where);
  366. }
  367. }
  368. $flow_element = $arr['flow_element'];
  369. $sid1s = '0';
  370. foreach ($flow_element as $k1 => $rs1) {
  371. $rs1['mid'] = $modeid;
  372. if (isset($rs1['id'])) unset($rs1['id']);
  373. $where = "`mid`='$modeid' and `fields`='" . $rs1['fields'] . "' and `iszb`='" . $rs1['iszb'] . "'";
  374. if ($db1->rows($where) == 0) {
  375. $sid1 = $db1->insert($rs1);
  376. } else {
  377. unset($rs1['name']);
  378. $db1->update($rs1, $where);
  379. $sid1 = $db1->getmou('id', $where);
  380. }
  381. $sid1s .= ',' . $sid1 . '';
  382. }
  383. if ($iszdbo) {
  384. $db1->delete("`mid`='$modeid' and `id` not in($sid1s)");
  385. }
  386. $flow_extent = $arr['flow_extent'];
  387. foreach ($flow_extent as $k3 => $rs3) {
  388. $rs3['modeid'] = $modeid;
  389. $sid = $rs3['id'];
  390. if ($db3->rows('id=' . $sid . '') > 0) {
  391. $db3->update($rs3, 'id=' . $sid . '');
  392. } else {
  393. $db3->insert($rs3);
  394. }
  395. }
  396. $flow_menu = $arr['flow_menu'];
  397. if ($flow_menu) {
  398. $sids = '0';
  399. foreach ($flow_menu as $k2 => $rs2) {
  400. $rs2['setid'] = $modeid;
  401. $sid = $rs2['id'];
  402. if ($db2->rows('id=' . $sid . '') > 0) {
  403. $sids .= ',' . $sid . '';
  404. $db2->update($rs2, 'id=' . $sid . '');
  405. } else {
  406. $db2->insert($rs2);
  407. $sids .= ',' . $this->db->insert_id() . '';
  408. }
  409. }
  410. $db2->delete("`setid`='$modeid' and `id` not in($sids)");
  411. }
  412. if (isset($arr['flow_course'])) {
  413. if ($db5->rows('setid=' . $modeid . '') == 0) {
  414. $flow_course = $arr['flow_course'];
  415. foreach ($flow_course as $k5 => $rs5) {
  416. if (isset($rs5['id'])) unset($rs5['id']);
  417. $rs5['setid'] = $modeid;
  418. if (isset($rs5['children'])) unset($rs5['children']);
  419. $db5->insert($rs5);
  420. }
  421. }
  422. }
  423. if (isset($arr['flow_todo'])) {
  424. $flow_todo = $arr['flow_todo'];
  425. $sids7 = '0';
  426. foreach ($flow_todo as $k7 => $rs7) {
  427. if (isset($rs7['id'])) unset($rs7['id']);
  428. $rs7['setid'] = $modeid;
  429. $where = "`setid`='$modeid' and `name`='" . $rs7['name'] . "'";
  430. if ($db7->rows($where) == 0) {
  431. $sid7 = $db7->insert($rs7);
  432. } else {
  433. $db7->update($rs7, $where);
  434. $sid7 = $db7->getmou('id', $where);
  435. }
  436. $sids7 .= ',' . $sid7 . '';
  437. }
  438. }
  439. $zcis++;
  440. }
  441. return '共' . $zcis . '个模块';
  442. }
  443. private function tonbbumodewq($data)
  444. {
  445. $db = m('flow_set');
  446. $this->initstalltable('flow_set');
  447. $this->initstalltable('flow_element');
  448. $this->initstalltable('flow_menu');
  449. $this->initstalltable('flow_extent');
  450. $this->initstalltable('flow_course');
  451. $this->initstalltable('flow_where');
  452. $this->initstalltable('flow_todo');
  453. foreach ($data as $num => $arr) {
  454. $flow_set = $arr['flow_set'];
  455. $flow_element = $arr['flow_element'];
  456. $flow_menu = $arr['flow_menu'];
  457. $flow_extent = $arr['flow_extent'];
  458. $flow_course = $arr['flow_course'];
  459. $flow_where = $arr['flow_where'];
  460. $flow_todo = $arr['flow_todo'];
  461. $db->insert($flow_set);
  462. $this->insertdata($flow_element, 'flow_element');
  463. $this->insertdata($flow_menu, 'flow_menu');
  464. $this->insertdata($flow_extent, 'flow_extent');
  465. $this->insertdata($flow_course, 'flow_course');
  466. $this->insertdata($flow_where, 'flow_where');
  467. $this->insertdata($flow_todo, 'flow_todo');
  468. }
  469. }
  470. private function initstalltable($table)
  471. {
  472. $sql1 = "delete from `[Q]" . $table . "`";
  473. $sql2 = "alter table `[Q]" . $table . "` AUTO_INCREMENT=1";
  474. $this->db->query($sql1, false);
  475. $this->db->query($sql2, false);
  476. }
  477. private function insertdata($data, $table)
  478. {
  479. $db = m($table);
  480. if ($data) foreach ($data as $k => $rs) {
  481. $db->insert($rs);
  482. }
  483. }
  484. private function tonbbuying($data)
  485. {
  486. $db = m('im_group');
  487. $dbs = m('im_menu');
  488. foreach ($data as $k => $yydata) {
  489. $rs = $yydata['data'];
  490. $menu = $yydata['menu'];
  491. $name = $rs['name'];
  492. unset($rs['id']);
  493. $where = "`name`='$name' and `type`=2";
  494. if (!isempt($rs['num'])) $where = "`num`='" . $rs['num'] . "' and `type`=2";
  495. if ($db->rows($where) == 0) {
  496. $mid = $db->insert($rs);
  497. $this->addyymenu($menu, $dbs, $mid, 0);
  498. } else {
  499. $mid = (int)$db->getmou('id', $where);
  500. $db->update(array('face' => $rs['face'], 'url' => $rs['url'], 'types' => $rs['types'], 'sort' => $rs['sort'], 'urlpc' => $rs['urlpc'], 'urlm' => $rs['urlm'], 'yylx' => $rs['yylx'], 'name' => $rs['name'], 'iconfont' => $rs['iconfont'], 'iconcolor' => $rs['iconcolor'], 'explain' => $rs['explain'],), $where);
  501. $this->addyymenu($menu, $dbs, $mid, 0);
  502. }
  503. }
  504. }
  505. private function addyymenu($menu, $dbs, $mid, $pid)
  506. {
  507. $ssid = '0';
  508. foreach ($menu as $k1 => $rs1) {
  509. unset($rs1['id']);
  510. $menusub = false;
  511. if (isset($rs1['menusub'])) {
  512. $menusub = $rs1['menusub'];
  513. unset($rs1['menusub']);
  514. }
  515. $rs1['mid'] = $mid;
  516. $rs1['pid'] = $pid;
  517. $where = "`name`='" . $rs1['name'] . "' and `pid`='$pid' and `mid`='$mid'";
  518. $sid = (int)$dbs->getmou('id', $where);
  519. if ($sid == 0) {
  520. $where = '';
  521. }
  522. $dbs->record($rs1, $where);
  523. if ($sid == 0) $sid = $this->db->insert_id();
  524. if ($menusub) $this->addyymenu($menusub, $dbs, $mid, $sid);
  525. $ssid .= ',' . $sid . '';
  526. }
  527. $dbs->delete("pid='$pid' and `mid`='$mid' and `id` not in($ssid)");
  528. }
  529. private function tonbbutask($data)
  530. {
  531. $db = m('task');
  532. foreach ($data as $k => $rs) {
  533. $where = "`url`='" . $rs['url'] . "'";
  534. $sid = (int)$db->getmou('id', $where);
  535. if ($sid == 0) {
  536. $where = '';
  537. } else {
  538. unset($rs['todoid']);
  539. unset($rs['todoname']);
  540. }
  541. unset($rs['id']);
  542. unset($rs['state']);
  543. unset($rs['lastdt']);
  544. $db->record($rs, $where);
  545. }
  546. }
  547. public function delmodelAjax()
  548. {
  549. $id = (int)$this->post('id');
  550. m('chargems')->delete("`modeid`='$id' and `type` in(0,1) and `modeid`>0");
  551. $this->showreturn('');
  552. }
  553. public function datadubiAjax()
  554. {
  555. $id = (int)$this->get('id');
  556. $barr = c('xinhu')->getdata('getinstallfile', array('id' => $id, 'sysnum' => $this->keyss));
  557. if ($barr['code'] != 200) showreturn('', $barr['msg'], 201);
  558. $data = $barr['data'];
  559. $mrs = $data['rs'];
  560. $rows = $data['rows'];
  561. $uparr = array();
  562. $morrs = $this->getmodeuprs($rows);
  563. foreach ($rows as $k => $rs) {
  564. $file = $rs['filepath'];
  565. $bo = true;
  566. $zt = 'add';
  567. if (file_exists($file)) {
  568. $_size = filesize($file);
  569. if ($_size == $rs['filesize']) $bo = false;
  570. $zt = 'edit';
  571. }
  572. if ($rs['type'] == 1) $zt = '';
  573. if ($rs['isup'] == 1) $bo = true;
  574. $rs['ting'] = 0;
  575. if (in_array($file, $morrs)) $rs['ting'] = 1;
  576. if ($bo) {
  577. $rs['zt'] = $zt;
  578. $uparr[] = $rs;
  579. }
  580. }
  581. $huira = $this->gethuiarr($id);
  582. $sarr1 = $sarr2 = array();
  583. $strh = '';
  584. foreach ($uparr as $k => $rs1) {
  585. $ishui = 0;
  586. if (isset($huira[$rs1['id']])) $ishui = 1;
  587. if ($rs1['ting'] == 1) $ishui = 1;
  588. $uparr[$k]['ishui'] = $ishui;
  589. if ($ishui == 1) {
  590. $sarr2[] = $uparr[$k];
  591. } else {
  592. $sarr1[] = $uparr[$k];
  593. }
  594. }
  595. $this->returnjson(array('strh' => $strh, 'rows' => array_merge($sarr1, $sarr2)));
  596. }
  597. private function gethuiarr($id)
  598. {
  599. $hurs = m('chargems')->getall("`modeid`='$id' and `type`=2", 'mid');
  600. $huira = array();
  601. foreach ($hurs as $k2 => $rs2) $huira[$rs2['mid']] = 1;
  602. return $huira;
  603. }
  604. public function hullueAjax()
  605. {
  606. $id = (int)$this->post('id');
  607. $lx = (int)$this->post('lx');
  608. $sid = $this->post('sid');
  609. $db = m('chargems');
  610. $db->delete("`modeid`='$id' and `mid` in($sid) and `type`=2");
  611. $sad = explode(',', $sid);
  612. if ($lx == 0) foreach ($sad as $sids) {
  613. $db->insert(array('optdt' => $this->now, 'type' => 2, 'mid' => $sids, 'modeid' => $id));
  614. }
  615. echo 'ok';
  616. }
  617. public function otherdataAjax()
  618. {
  619. $rows = array();
  620. $barr = c('xinhuapi')->getdata('other', 'data', array('page' => (int)$this->get('page', '1'), 'limit' => (int)$this->get('limit', '15'),));
  621. if (!$barr['success']) return $barr['msg'];
  622. $data = $barr['data'];
  623. $rows = $data['rows'];
  624. if ($rows) {
  625. $anzrr = m('chargems')->getall('`type`=3');
  626. $anzra = array();
  627. foreach ($anzrr as $k => $rs) $anzra[$rs['modeid']] = $rs['updatedt'];
  628. foreach ($rows as $k => $rs) {
  629. $anzt = 0;
  630. if (isset($anzra[$rs['id']])) {
  631. $dtsd = $anzra[$rs['id']];
  632. if ($rs['updatedt'] > $dtsd) {
  633. $anzt = 2;
  634. } else {
  635. $anzt = 1;
  636. }
  637. }
  638. $rows[$k]['anzt'] = $anzt;
  639. }
  640. $data['rows'] = $rows;
  641. }
  642. return $data;
  643. }
  644. public function otherinstallAjax()
  645. {
  646. $id = (int)$this->get('id', '0');
  647. if (getconfig('systype') == 'demo') return returnerror('演示不要操作');
  648. $barr = c('xinhuapi')->getdata('other', 'instcheck', array('id' => $id,));
  649. if (!$barr['success']) return $barr;
  650. $da = $barr['data'];
  651. return returnsuccess(array('msg' => '安装完成', 'name' => $da['name'], 'path' => '' . $id . '',));
  652. }
  653. public function loadinstallinfoAjax()
  654. {
  655. if (getconfig('systype') == 'demo') return returnerror('演示不要操作');
  656. if ($this->adminid != 1) return returnerror('不是管理员不要操作');
  657. $nwsp = $this->get('path');
  658. if (!$nwsp) {
  659. $nwsp = '';
  660. } else {
  661. $nwsp = $this->jm->base64decode($nwsp);
  662. }
  663. if (isempt($nwsp)) return returnerror('无效安装');
  664. if (is_numeric($nwsp)) {
  665. $barr = c('xinhuapi')->getdata('other', 'instinfo', array('id' => $nwsp,));
  666. if (!$barr['success']) return $barr;
  667. $farr = $barr['data']['farr'];
  668. $filesize = $barr['data']['filesize'];
  669. } else {
  670. if (!getconfig('rockinzip')) return returnerror('系统未开启此功能');
  671. $farr = c('zip')->zipget($nwsp);
  672. if (!is_array($farr)) return returnerror($farr);
  673. $filesize = filesize($nwsp);
  674. }
  675. $path = '' . UPDIR . '/logs/' . md5($nwsp) . '';
  676. $filestr = '';
  677. $agentstr = '';
  678. $tablestr = '';
  679. $menustr = '';
  680. foreach ($farr as $k => $rs) {
  681. $_pluj = $rs['filepath'];
  682. $spath = $path . '/' . $_pluj;
  683. $conts = $rs['filecontent'];
  684. if (!contain($_pluj, 'installconfig')) {
  685. $filestr .= '' . $_pluj . '<br>';
  686. $fileext = substr($_pluj, -3);
  687. if ($fileext == 'jpg' || $fileext == 'png' || $fileext == 'gif') {
  688. if ($conts) $this->rock->createtxt($spath, base64_decode($conts));
  689. }
  690. } else {
  691. $this->rock->createtxt($spath, base64_decode($conts));
  692. }
  693. }
  694. $confpath = $path . '/installconfig/xinhuoa_config.php';
  695. if (!file_exists($confpath)) return '无效安装包' . $confpath . '';
  696. $conf = require($confpath);
  697. $modepath = $path . '/installconfig/xinhuoa_data.json';
  698. $mysqlpath = $path . '/installconfig/xinhuoa_mysql.json';
  699. $modestr = '';
  700. $menuarr = array();
  701. if (file_exists($modepath)) {
  702. $dsta = json_decode(file_get_contents($modepath), true);
  703. if (isset($dsta['mode'])) foreach ($dsta['mode'] as $bh => $info) {
  704. $modestr .= '' . $info['flow_set']['name'] . '(' . $bh . ') ';
  705. }
  706. if (isset($dsta['menu'])) foreach ($dsta['menu'] as $cd => $cdrs) {
  707. if ($cd > 0) $menustr .= '<div style="margin:5px 0px" class="blank1"></div>';
  708. $menustr .= '<input class="btn btn-default btn-xs" click="xuancaid,' . $cdrs['id'] . '" type="button" value="选上级菜单"><br>' . $cdrs['name'] . '(' . $cdrs['url'] . ')';
  709. $menuarr[$cdrs['id']] = '-1';
  710. if (isset($cdrs['children'])) foreach ($cdrs['children'] as $cd1 => $cdrs1) {
  711. $menustr .= '<br>&nbsp;┣' . $cdrs1['name'] . '(' . $cdrs1['url'] . ') ';
  712. if (isset($cdrs1['children'])) foreach ($cdrs1['children'] as $cd2 => $cdrs2) {
  713. $menustr .= '<br>&nbsp;&nbsp;┣' . $cdrs2['name'] . '(' . $cdrs2['url'] . ') ';
  714. }
  715. }
  716. }
  717. if (isset($dsta['yydata'])) foreach ($dsta['yydata'] as $yb => $ybrs) {
  718. $agentstr .= '<img src="' . $path . '/' . $ybrs['data']['face'] . '" align="absmiddle" width="20px" height="20px">' . $ybrs['data']['name'] . ' ';
  719. }
  720. }
  721. if (file_exists($mysqlpath)) {
  722. $dstd = json_decode(file_get_contents($mysqlpath), true);
  723. foreach ($dstd as $dbs => $nse) {
  724. $tablestr .= ',' . $dbs . '';
  725. }
  726. }
  727. if ($tablestr) $tablestr = substr($tablestr, 1);
  728. $conf['modestr'] = $modestr;
  729. $conf['filestr'] = $filestr;
  730. $conf['tablestr'] = $tablestr;
  731. $conf['menustr'] = $menustr;
  732. $conf['agentstr'] = $agentstr;
  733. $conf['menuarr'] = $menuarr;
  734. $conf['pathstr'] = $this->jm->base64encode($nwsp);
  735. $conf['filesizecn'] = $this->rock->formatsize($filesize);
  736. return returnsuccess($conf);
  737. }
  738. public function getmenuAjax()
  739. {
  740. $glx = (int)$this->get('glx', '0');
  741. if ($glx == 0) $arr[] = array('name' => '顶级', 'value' => '0');
  742. $db = m('menu');
  743. $rows = $db->getall('`pid`=0 and `status`=1', 'id,name', 'sort');
  744. foreach ($rows as $k => $rs) {
  745. $arr[] = array('name' => $rs['name'], 'value' => $rs['id'], 'subname' => $rs['id']);
  746. $rows1 = $db->getall('`pid`=' . $rs['id'] . ' and `status`=1', 'id,name', 'sort');
  747. foreach ($rows1 as $k1 => $rs1) {
  748. $arr[] = array('name' => $rs1['name'], 'value' => $rs1['id'], 'padding' => 24, 'subname' => $rs1['id']);
  749. if ($glx == 1) {
  750. $rows2 = $db->getall('`pid`=' . $rs1['id'] . ' and `status`=1', 'id,name', 'sort');
  751. foreach ($rows2 as $k2 => $rs2) {
  752. $arr[] = array('name' => $rs2['name'], 'value' => $rs2['id'], 'padding' => 48, 'subname' => $rs2['id']);
  753. }
  754. }
  755. }
  756. }
  757. return $arr;
  758. }
  759. public function getyydataAjax()
  760. {
  761. $arr = array();
  762. $db = m('im_group');
  763. $rows = $db->getall('`type`=2 and `valid`=1', 'id,name,types,face', 'sort');
  764. foreach ($rows as $k => $rs) {
  765. $arr[] = array('name' => $rs['name'], 'value' => $rs['id'], 'iconsimg' => $rs['face'], 'subname' => $rs['types']);
  766. }
  767. return $arr;
  768. }
  769. public function newinstallinfoAjax()
  770. {
  771. if (getconfig('systype') == 'demo') return '演示不要操作';
  772. if ($this->adminid != 1) return '不是管理员不要操作';
  773. $nwsp = $this->jm->base64decode($this->get('path'));
  774. if (is_numeric($nwsp)) {
  775. $barr = c('xinhuapi')->getdata('other', 'instfile', array('id' => $nwsp,));
  776. if (!$barr['success']) return $barr;
  777. $farr = $barr['data']['farr'];
  778. } else {
  779. if (!getconfig('rockinzip')) return '系统未开启此功能';
  780. $farr = c('zip')->zipget($nwsp);
  781. if (!is_array($farr)) return $farr;
  782. }
  783. $path = '' . UPDIR . '/logs/' . md5($nwsp) . '';
  784. $confpath = $path . '/installconfig/xinhuoa_config.php';
  785. if (!file_exists($confpath)) return '无效安装包';
  786. $conf = require($confpath);
  787. $modepath = $path . '/installconfig/xinhuoa_data.json';
  788. $mysqlpath = $path . '/installconfig/xinhuoa_mysql.json';
  789. if (file_exists($mysqlpath)) {
  790. $bmsg = m('beifen')->updatefabric(file_get_contents($mysqlpath), 1);
  791. if ($bmsg != 'ok') return $bmsg;
  792. }
  793. if (file_exists($modepath)) {
  794. $dsta = json_decode(file_get_contents($modepath), true);
  795. if (isset($dsta['menu'])) foreach ($dsta['menu'] as $cd => $cdrs) {
  796. $pid = $this->get('menupid' . $cdrs['id'] . '', '-1');
  797. if ($pid != '-1') {
  798. $where = "`name`='" . $cdrs['name'] . "'";
  799. if (!isempt($cdrs['url'])) $where .= " and `url`='" . $cdrs['url'] . "'";
  800. if (!isempt($cdrs['num'])) $where .= " and `num`='" . $cdrs['num'] . "'";
  801. if (m('menu')->rows($where) == 0) $this->saveshangiji('menu', $cdrs, $pid, 'pid');
  802. }
  803. }
  804. if (isset($dsta['yydata'])) $this->tonbbuying($dsta['yydata']);
  805. if (isset($dsta['mode'])) $this->tonbbumode($dsta['mode']);
  806. }
  807. foreach ($farr as $k => $rs) {
  808. $_pluj = $rs['filepath'];
  809. $spath = $path . '/' . $_pluj;
  810. if (!contain($_pluj, 'installconfig')) {
  811. $bo = $this->rock->createtxt($_pluj, base64_decode($rs['filecontent']));
  812. if (!$bo) return '无法写入:' . $_pluj . '';
  813. }
  814. if (file_exists($spath)) unlink($spath);
  815. }
  816. if (is_numeric($nwsp)) {
  817. $this->upsueeccmids($nwsp, $nwsp, $this->now, 3);
  818. } else {
  819. @unlink($nwsp);
  820. }
  821. m('log')->addlog('模块插件安装', '名称:' . $conf['name'] . ',作者:' . $conf['zuozhe'] . ',版本:' . $conf['ver'] . '');
  822. return 'ok';
  823. }
  824. private function saveshangiji($tab, $da, $pid, $pfid)
  825. {
  826. unset($da['id']);
  827. $da[$pfid] = $pid;
  828. $children = false;
  829. if (isset($da['children'])) {
  830. $children = $da['children'];
  831. unset($da['children']);
  832. }
  833. $nid = m($tab)->insert($da);
  834. if ($nid && $children) foreach ($children as $k => $rs) {
  835. $this->saveshangiji($tab, $rs, $nid, $pfid);
  836. }
  837. }
  838. public function delotherAjax()
  839. {
  840. $id = (int)$this->post('id');
  841. m('chargems')->delete("`modeid`='$id' and `type`=3");
  842. $this->showreturn('');
  843. }
  844. }