control.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733
  1. <?php
  2. /**
  3. * The control file of admin module of ZenTaoPMS.
  4. *
  5. * @copyright Copyright 2009-2023 禅道软件(青岛)有限公司(ZenTao Software (Qingdao) Co., Ltd. www.cnezsoft.com)
  6. * @license ZPL(http://zpl.pub/page/zplv12.html) or AGPL(https://www.gnu.org/licenses/agpl-3.0.en.html)
  7. * @author Chunsheng Wang <chunsheng@cnezsoft.com>
  8. * @package admin
  9. * @version $Id: control.php 4460 2013-02-26 02:28:02Z chencongzhi520@gmail.com $
  10. * @link https://www.zentao.net
  11. */
  12. class admin extends control
  13. {
  14. /**
  15. *
  16. * @access public
  17. * @return void
  18. */
  19. public function index()
  20. {
  21. set_time_limit(0);
  22. /* 设置导航信息。*/
  23. /* Set the nav. */
  24. $this->admin->setMenu();
  25. /* 处理社区登记。*/
  26. /* Process community registration. */
  27. $community = zget($this->config->global, 'community', '');
  28. if(!$community || $community == 'na')
  29. {
  30. $this->view->bind = false;
  31. $this->view->ignore = $community == 'na';
  32. }
  33. else
  34. {
  35. $this->view->bind = true;
  36. $this->view->ignore = false;
  37. }
  38. $this->view->title = $this->lang->admin->common;
  39. $this->view->zentaoData = $this->adminZen->getZentaoData();
  40. $this->view->dateUsed = $this->admin->genDateUsed();
  41. $this->view->hasInternet = $this->admin->checkInternet();
  42. $this->display();
  43. }
  44. /**
  45. * 获取禅道官网数据。
  46. * Get zentao.net data by api.
  47. *
  48. * @access public
  49. * @return void
  50. */
  51. public function ajaxSetZentaoData()
  52. {
  53. session_write_close();
  54. if(helper::isIntranet()) return $this->send(array('result' => 'ignore'));
  55. if($this->admin->checkInternet())
  56. {
  57. $lastSyncDate = !empty($this->config->zentaoWebsite->lastSyncDate) ? $this->config->zentaoWebsite->lastSyncDate : '';
  58. $nextWeek = date('Y-m-d', strtotime('-7 days'));
  59. $needSync = empty($lastSyncDate) || $lastSyncDate <= $nextWeek;
  60. $zentaoData = $this->adminZen->getZentaoData();
  61. if($needSync || empty($zentaoData->plugins)) $this->adminZen->syncExtensions('plugin', 6);
  62. if($needSync || empty($zentaoData->patches)) $this->adminZen->syncExtensions('patch', 5);
  63. if($needSync || empty($zentaoData->dynamics)) $this->adminZen->syncDynamics(3);
  64. if($needSync || empty($zentaoData->classes)) $this->adminZen->syncPublicClasses(3);
  65. if($needSync) $this->loadModel('setting')->setItem('system.common.zentaoWebsite.lastSyncDate', date('Y-m-d'));
  66. }
  67. return $this->send(array('result' => 'success'));
  68. }
  69. /**
  70. * 系统安全设置。
  71. * System security Settings.
  72. *
  73. * @access public
  74. * @return void
  75. */
  76. public function safe()
  77. {
  78. if($_POST)
  79. {
  80. $data = form::data()->get();
  81. $this->loadModel('setting')->setItems('system.common.safe', $data);
  82. return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'load' => true));
  83. }
  84. $this->view->title = $this->lang->admin->safe->common . $this->lang->hyphen . $this->lang->admin->safe->set;
  85. $this->view->gdInfo = function_exists('gd_info') ? gd_info() : array();
  86. $this->display();
  87. }
  88. /**
  89. * 弱口令扫描。
  90. * Check weak user.
  91. *
  92. * @access public
  93. * @return void
  94. */
  95. public function checkWeak()
  96. {
  97. $this->view->title = $this->lang->admin->safe->common . $this->lang->hyphen . $this->lang->admin->safe->checkWeak;
  98. $this->view->weakUsers = $this->loadModel('user')->getWeakUsers();
  99. $this->display();
  100. }
  101. /**
  102. * ZDOO集成。
  103. * Config sso for ranzhi.
  104. *
  105. * @access public
  106. * @return void
  107. */
  108. public function sso()
  109. {
  110. if(!empty($_POST))
  111. {
  112. $data = form::data()->get();
  113. if(!$data->turnon) $data->redirect = $data->turnon;
  114. $this->loadModel('setting')->setItems('system.sso', $data);
  115. if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError()));
  116. return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'load' => inlink('sso')));
  117. }
  118. $this->loadModel('sso');
  119. if(!isset($this->config->sso)) $this->config->sso = new stdclass();
  120. $this->view->title = $this->lang->admin->sso;
  121. $this->view->turnon = isset($this->config->sso->turnon) ? $this->config->sso->turnon : 1;
  122. $this->view->redirect = isset($this->config->sso->redirect) ? $this->config->sso->redirect : 0;
  123. $this->view->addr = isset($this->config->sso->addr) ? $this->config->sso->addr : '';
  124. $this->view->key = isset($this->config->sso->key) ? $this->config->sso->key : '';
  125. $this->view->code = isset($this->config->sso->code) ? $this->config->sso->code : '';
  126. $this->display();
  127. }
  128. /**
  129. * 系统功能配置。
  130. * Set closed features config.
  131. *
  132. * @access public
  133. * @return void
  134. */
  135. public function setModule()
  136. {
  137. $this->loadModel('setting');
  138. $this->loadModel('project');
  139. if($_POST)
  140. {
  141. $data = form::data()->get();
  142. $closedFeatures = array();
  143. foreach($this->config->featureGroup as $group => $features)
  144. {
  145. foreach($features as $feature)
  146. {
  147. $code = $group . ucfirst($feature);
  148. if(empty($data->module[$code])) $closedFeatures[] = $code;
  149. }
  150. }
  151. foreach($closedFeatures as $closedFeature)
  152. {
  153. if(in_array($closedFeature, array('productER', 'productUR')))
  154. {
  155. $this->project->unlinkStoryByType(0, $closedFeature == 'productER' ? 'epic' : 'requirement');
  156. }
  157. /* 关闭项目变更后将交付物解冻。*/
  158. if($closedFeature == 'projectChange')
  159. {
  160. $deliverableReviewPairs = $this->admin->getDeliverableReviewPairs();
  161. if(!empty($deliverableReviewPairs)) $this->loadModel('deliverable')->setFrozen(array_filter($deliverableReviewPairs), '', 'all');
  162. }
  163. }
  164. $enableER = $this->config->edition == 'ipd' ? 1 : zget($data->module, 'productER', 0);
  165. $URAndSR = $this->config->edition == 'ipd' ? 1 : zget($data->module, 'productUR', 0);
  166. $this->setting->setItem('system.common.closedFeatures', implode(',', $closedFeatures));
  167. $this->setting->setItem('system.common.global.scoreStatus', zget($data->module, 'myScore', 0));
  168. $this->setting->setItem('system.custom.enableER', $enableER);
  169. $this->setting->setItem('system.custom.URAndSR', $URAndSR);
  170. $this->setting->setItem('system.common.setCode', in_array('otherSetCode', $closedFeatures) ? 0 : 1);
  171. $this->loadModel('custom')->processMeasrecordCron();
  172. $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'callback' => '$.apps.updateAppsMenu(true);loadCurrentPage();'));
  173. }
  174. $closedFeatures = $this->setting->getItem('owner=system&module=common&section=&key=closedFeatures');
  175. if(empty($this->config->setCode) && strpos(",{$closedFeatures},", ',otherSetCode,') === false) $closedFeatures .= ',otherSetCode';
  176. $this->view->title = $this->lang->admin->setModuleIndex;
  177. $this->view->closedFeatures = $closedFeatures;
  178. $this->view->useScore = $this->setting->getItem('owner=system&module=common&global&key=scoreStatus');
  179. $this->view->disabledFeatures = $this->setting->getItem('owner=system&module=common&section=&key=disabledFeatures');
  180. $this->display();
  181. }
  182. /**
  183. * 认证邮箱。
  184. * Certify ztEmail.
  185. *
  186. * @param string $email
  187. * @access public
  188. * @return void
  189. */
  190. public function certifyZtEmail($email = '')
  191. {
  192. if($_POST)
  193. {
  194. $response = $this->adminZen->certifyByAPI('mail');
  195. $response = json_decode($response);
  196. if($response->result == 'fail') return print(js::alert($response->message));
  197. return print(js::locate($this->createLink('mail', 'ztCloud'), 'parent'));
  198. }
  199. $this->view->title = $this->lang->admin->certifyEmail;
  200. $this->view->email = helper::safe64Decode($email);
  201. $this->display();
  202. }
  203. /**
  204. * 认证手机。
  205. * Certify ztMobile.
  206. *
  207. * @param string $mobile
  208. * @access public
  209. * @return void
  210. */
  211. public function certifyZtMobile($mobile = '')
  212. {
  213. if($_POST)
  214. {
  215. $response = $this->adminZen->certifyByAPI('mobile');
  216. $response = json_decode($response);
  217. if($response->result == 'fail') return print(js::alert($response->message));
  218. return print(js::locate($this->createLink('mail', 'ztCloud'), 'parent'));
  219. }
  220. $this->view->title = $this->lang->admin->certifyMobile;
  221. $this->view->mobile = helper::safe64Decode($mobile);
  222. $this->display();
  223. }
  224. /**
  225. * 认证公司。
  226. * Set ztCompany.
  227. *
  228. * @param string $fields
  229. * @access public
  230. * @return void
  231. */
  232. public function ztCompany($fields = 'company')
  233. {
  234. if($_POST)
  235. {
  236. $response = $this->adminZen->setCompanyByAPI();
  237. $response = json_decode($response);
  238. if($response->result == 'fail') return print(js::alert($response->message));
  239. return print(js::locate($this->createLink('mail', 'ztCloud'), 'parent'));
  240. }
  241. $this->view->title = $this->lang->admin->ztCompany;
  242. $this->view->fields = explode(',', $fields);
  243. $this->display();
  244. }
  245. /**
  246. * 获取验证码。
  247. * Get the verification code.
  248. *
  249. * @param string $type mobile|email
  250. * @access public
  251. * @return void
  252. */
  253. public function ajaxSendCode($type)
  254. {
  255. return print($this->adminZen->sendCodeByAPI($type));
  256. }
  257. /**
  258. * 设置日志保存天数。
  259. * Set save days of log.
  260. *
  261. * @access public
  262. * @return void
  263. */
  264. public function log()
  265. {
  266. if($_POST)
  267. {
  268. $days = form::data()->get()->days;
  269. if(!validater::checkInt($days)) return $this->send(array('result' => 'fail', 'message' => array('days' => sprintf($this->lang->admin->notice->int, $this->lang->admin->days))));
  270. $this->loadModel('setting')->setItem('system.admin.log.saveDays', (string)$days);
  271. if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError()));
  272. return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'load' => true, 'closeModal' => true));
  273. }
  274. $this->app->loadLang('webhook');
  275. $this->view->title = $this->lang->webhook->setting;
  276. $this->display();
  277. }
  278. /**
  279. * 删除过期日志。
  280. * Delete logs older than save days.
  281. *
  282. * @access public
  283. * @return bool
  284. */
  285. public function deleteLog()
  286. {
  287. $date = date(DT_DATE1, strtotime("-{$this->config->admin->log->saveDays} days"));
  288. $this->dao->delete()->from(TABLE_LOG)->where('date')->lt($date)->exec();
  289. return !dao::isError();
  290. }
  291. /**
  292. * 重置密码设置。
  293. * Reset password setting.
  294. *
  295. * @access public
  296. * @return void
  297. */
  298. public function resetPWDSetting()
  299. {
  300. if($_POST)
  301. {
  302. $resetPWDByMail = form::data()->get()->resetPWDByMail;
  303. $this->loadModel('setting')->setItem('system.common.resetPWDByMail', (string)$resetPWDByMail);
  304. return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'load' => true));
  305. }
  306. $this->view->title = $this->lang->admin->resetPWDSetting;
  307. $this->display();
  308. }
  309. /**
  310. * 表引擎。
  311. * Show table engine.
  312. *
  313. * @access public
  314. * @return void
  315. */
  316. public function tableEngine()
  317. {
  318. $this->view->title = $this->lang->admin->tableEngine;
  319. $this->view->tableEngines = $this->dao->getTableEngines();
  320. $this->display();
  321. }
  322. /**
  323. * 更新度量库表的索引。
  324. * Upgrade metriclib table index.
  325. *
  326. * @param int $key
  327. * @access public
  328. * @return void
  329. */
  330. public function metriclib($key = 0)
  331. {
  332. $sql = $this->config->admin->metricLib->updateSQLs[$key] ?? '';
  333. if($sql)
  334. {
  335. set_time_limit(0);
  336. session_write_close();
  337. try
  338. {
  339. $this->dbh->exec($sql);
  340. }
  341. catch(PDOException $e){}
  342. if(isset($this->config->admin->metricLib->updateSQLs[++$key])) return $this->send(['result' => 'success', 'key' => $key]);
  343. return $this->send(['result' => 'success']);
  344. }
  345. $this->view->title = $this->lang->metriclib->common;
  346. $this->display();
  347. }
  348. /**
  349. * 更换表引擎为InnoDB。
  350. * Ajax change table engine.
  351. *
  352. * @access public
  353. * @return void
  354. */
  355. public function ajaxChangeTableEngine()
  356. {
  357. $response = array();
  358. $response['result'] = 'success';
  359. $response['message'] = '';
  360. $response['thisTable'] = '';
  361. $response['nextTable'] = '';
  362. $tableEngines = $this->dao->getTableEngines();
  363. $thisTable = '';
  364. $nextTable = '';
  365. foreach($tableEngines as $table => $engine)
  366. {
  367. if($engine == 'InnoDB') continue;
  368. if(strpos(",{$this->session->errorTables},", ",{$table},") !== false) continue;
  369. if(stripos($table, 'searchindex') !== false)
  370. {
  371. $mysqlVersion = $this->loadModel('install')->getDatabaseVersion();
  372. if($mysqlVersion < 5.6) continue;
  373. }
  374. if($thisTable && empty($nextTable)) $nextTable = $table;
  375. if(empty($thisTable)) $thisTable = $table;
  376. if($thisTable && $nextTable) break;
  377. }
  378. if(empty($thisTable))
  379. {
  380. unset($_SESSION['errorTables']);
  381. $response['result'] = 'finished';
  382. return $this->send($response);
  383. }
  384. try
  385. {
  386. /* Check process this table or not. */
  387. $dbProcesses = $this->dbh->query("SHOW PROCESSLIST")->fetchAll();
  388. foreach($dbProcesses as $dbProcess)
  389. {
  390. if($dbProcess->db != $this->config->db->name) continue;
  391. if(!empty($dbProcess->Info) && strpos($dbProcess->Info, " {$thisTable} ") !== false)
  392. {
  393. $response['message'] = sprintf($this->lang->admin->changingTable, $thisTable);
  394. return $this->send($response);
  395. }
  396. }
  397. }
  398. catch(PDOException $e){}
  399. $response['thisTable'] = $thisTable;
  400. $response['nextTable'] = $nextTable;
  401. try
  402. {
  403. $sql = "ALTER TABLE `$thisTable` ENGINE='InnoDB'";
  404. $this->dbh->exec($sql);
  405. $response['message'] = sprintf($this->lang->admin->changeSuccess, $thisTable);
  406. }
  407. catch(PDOException $e)
  408. {
  409. $this->session->set('errorTables', $this->session->errorTables . ',' . $thisTable);
  410. $response['result'] = 'fail';
  411. $response['message'] = sprintf($this->lang->admin->changeFail, $thisTable, htmlspecialchars($e->getMessage()));
  412. }
  413. return $this->send($response);
  414. }
  415. /**
  416. * 设置1.5级后台下拉菜单。
  417. * AJAX: Get drop menu.
  418. *
  419. * @param string $currentMenuKey
  420. * @access public
  421. * @return void
  422. */
  423. public function ajaxGetDropMenu($currentMenuKey = '')
  424. {
  425. $this->admin->checkPrivMenu();
  426. $data = array();
  427. foreach($this->lang->admin->menuList as $menuKey => $menuGroup)
  428. {
  429. if($this->config->vision == 'lite' && !in_array($menuKey, $this->config->admin->liteMenuList)) continue;
  430. $data[] = array(
  431. 'id' => $menuKey,
  432. 'name' => $menuKey,
  433. 'content' => array('html' => "<div class='flex items-center my-0.5'>" . (!empty($menuGroup['icon']) ? "<i class='icon icon-{$menuGroup['icon']} svg-icon mr-2 rounded-lg content-center bg-{$menuGroup['bg']} text-white'></i>" : "<img class='mr-2' src='static/svg/admin-{$menuKey}.svg'/>") . " {$menuGroup['name']}</div>"),
  434. 'text' => $menuGroup['name'],
  435. 'titleClass' => 'hidden',
  436. 'type' => 'item',
  437. 'disabled' => $menuGroup['disabled'],
  438. 'url' => $menuGroup['link'],
  439. 'active' => $currentMenuKey == $menuKey,
  440. 'rootClass' => 'admin-menu-item',
  441. 'attrs' => array('disabled' => $menuGroup['disabled'])
  442. );
  443. }
  444. $this->view->data = $data;
  445. $this->display();
  446. }
  447. /**
  448. * 将队列中的SQL语句同步到SQLite中。
  449. * Execute sql from SQLite queue.
  450. *
  451. * @access public
  452. * @return void
  453. */
  454. public function execSqliteQueue()
  455. {
  456. $now = helper::now();
  457. $sqlite = $this->app->connectSqlite();
  458. $querys = $this->dao->select('*')->from(TABLE_SQLITE_QUEUE)->where('status')->eq('wait')->fetchAll();
  459. $sqlite->beginTransaction();
  460. foreach($querys as $query)
  461. {
  462. $sqlite->exec($query->sql);
  463. $this->dao->update(TABLE_SQLITE_QUEUE)
  464. ->set('status')->eq('done')
  465. ->set('execDate')->eq($now)
  466. ->where('id')->eq($query->id)
  467. ->exec();
  468. }
  469. $sqlite->commit();
  470. echo 'success';
  471. }
  472. /**
  473. * 绑定社区账号。
  474. * Bind community account.
  475. *
  476. * @access public
  477. * @return void
  478. */
  479. public function register()
  480. {
  481. if($this->loadModel('user')->isLogon() && !$this->app->user->admin) $this->locate(helper::createLink('user', 'deny', 'module=admin&method=register'));
  482. $bindCommunity = $this->config->admin->register->bindCommunity == 'true';
  483. $agreeUX = $this->config->admin->register->agreeUX == 'true';
  484. $this->view->bindCommunity = $bindCommunity;
  485. $this->view->agreeUX = $agreeUX;
  486. if($bindCommunity)
  487. {
  488. if(!$this->loadModel('user')->isLogon()) $this->locate(helper::createLink('user', 'deny', 'module=admin&method=register'));
  489. $bindCommunityMobile = $this->config->admin->register->bindCommunityMobile;
  490. $this->view->bindCommunityMobile = $bindCommunityMobile;
  491. }
  492. else
  493. {
  494. if(!empty($_POST))
  495. {
  496. $data = form::data($this->config->admin->form->register)->get();
  497. $apiRoot = $this->config->admin->register->apiRoot;
  498. $apiURL = $apiRoot . "/user-apiRegister.json";
  499. if(empty($this->config->global->sn)) $this->loadModel('setting')->setSN();
  500. $httpData['sn'] = $this->config->global->sn;
  501. $httpData['mobile'] = $data->mobile;
  502. $httpData['code'] = $data->code;
  503. $httpData['token'] = md5(session_id());
  504. $response = common::http($apiURL, $httpData);
  505. $response = json_decode($response, true);
  506. if(isset($response['result']) && $response['result'] == 'success')
  507. {
  508. $this->loadModel('setting')->setItem('system.admin.register.bindCommunity', 'true');
  509. $this->loadModel('setting')->setItem('system.admin.register.bindCommunityMobile', $data->mobile);
  510. $this->config->admin->register->bindCommunity = 'true';
  511. $this->config->admin->register->bindCommunityMobile = $data->mobile;
  512. $agreeUX = $data->agreeUX;
  513. $agreeUX = $agreeUX == 'on' ? 'true' : 'false';
  514. $this->loadModel('setting')->setItem('system.admin.register.agreeUX', $agreeUX);
  515. $this->config->admin->agreeUX = $agreeUX;
  516. $eventData = new stdClass();
  517. $eventData->fingerprint = $data->fingerprint;
  518. $eventData->location = 'join-community';
  519. $this->loadModel('misc')->sendInstallEvent($eventData);
  520. $callBack = $this->loadModel('user')->isLogon() ? 'loadToRegister()' : 'loadToIndex()';
  521. return $this->send(array('result' => 'success', 'message' => $this->lang->admin->community->joinSuccess, 'callback' => $callBack));
  522. }
  523. return $this->send(array('result' => 'fail', 'message' => isset($response['message']) ? $response['message'] : $this->lang->admin->community->loginFailed));
  524. }
  525. }
  526. $this->view->title = $this->lang->admin->community->registerTitle;
  527. $this->display();
  528. }
  529. /**
  530. * 解绑社区账号
  531. * Unbind community account。
  532. *
  533. * @access public
  534. * @return void
  535. */
  536. public function unBindCommunity()
  537. {
  538. $this->loadModel('setting')->setItem('system.admin.register.bindCommunity', 'false');
  539. $this->loadModel('setting')->setItem('system.admin.register.bindCommunityMobile', '');
  540. $this->loadModel('setting')->setItem('system.admin.register.agreeUX', 'false');
  541. $this->config->admin->register->bindCommunity = 'false';
  542. $this->config->admin->register->bindCommunityMobile = '';
  543. $this->config->admin->register->agreeUX = 'false';
  544. return $this->send(array('result' => 'success', 'message' => $this->lang->admin->community->unBind->success, 'load' => inlink('register')));
  545. }
  546. /**
  547. * 切换同意改进计划
  548. * Change the agreement to improve the plan。
  549. *
  550. * @access public
  551. * @return void
  552. */
  553. public function changeAgreeUX()
  554. {
  555. $agreeUX = $this->post->agreeUX;
  556. $this->loadModel('setting')->setItem('system.admin.register.agreeUX', $agreeUX);
  557. $this->config->admin->register->agreeUX = $agreeUX;
  558. $message = $agreeUX == 'true' ? $this->lang->admin->community->uxPlan->agree : $this->lang->admin->community->uxPlan->cancel;
  559. return $this->send(array('result' => 'success', 'message' => $message));
  560. }
  561. /**
  562. * 获取图形验证码
  563. * Obtain graphical captcha。
  564. *
  565. * @access public
  566. * @return void
  567. */
  568. public function getCaptcha()
  569. {
  570. $apiRoot = $this->config->admin->register->apiRoot;
  571. $apiURL = $apiRoot . "/guarder-apiGetCaptcha.json";
  572. $httpData['token'] = md5(session_id());
  573. $response = common::http($apiURL, $httpData);
  574. $response = json_decode($response, true);
  575. return $this->send($response);
  576. }
  577. /**
  578. * 发动短信验证码
  579. * Activate SMS verification code
  580. *
  581. * @access public
  582. * @return void
  583. */
  584. public function sendCode()
  585. {
  586. $apiRoot = $this->config->admin->register->apiRoot;
  587. $apiURL = $apiRoot . "/sms-apiSendCode.json";
  588. $_POST['token'] = md5(session_id());
  589. $response = common::http($apiURL, $_POST);
  590. $response = json_decode($response, true);
  591. return $this->send($response);
  592. }
  593. /**
  594. * 用户体验改进计划详情
  595. *
  596. * @access public
  597. * @return void
  598. */
  599. public function planModal()
  600. {
  601. $this->display();
  602. }
  603. /**
  604. * 填写信息表单
  605. *
  606. * @access public
  607. * @return void
  608. */
  609. public function giftPackage()
  610. {
  611. if(!empty($_POST))
  612. {
  613. $data = form::data($this->config->admin->form->giftPackage)->get();
  614. $bindCommunityMobile = $this->config->admin->register->bindCommunityMobile;
  615. if(!$bindCommunityMobile) return $this->send(array('result' => 'fail', 'message' => $this->lang->admin->community->giftPackageFailed));
  616. $apiRoot = $this->config->admin->register->apiRoot;
  617. $apiURL = $apiRoot . "/user-apiSaveProfile.json";
  618. if(empty($this->config->global->sn)) $this->loadModel('setting')->setSN();
  619. $httpData['sn'] = $this->config->global->sn;
  620. $httpData['nickname'] = $data->nickname;
  621. $httpData['position'] = $data->position;
  622. $httpData['company'] = $data->company;
  623. $httpData['solvedProblems'] = json_encode($data->solvedProblems);
  624. $httpData['mobile'] = $bindCommunityMobile;
  625. $httpData['token'] = md5(session_id());
  626. $response = common::http($apiURL, $httpData);
  627. $response = json_decode($response, true);
  628. if(isset($response['result']) && $response['result'] == 'success')
  629. {
  630. return $this->send(array('result' => 'success', 'message' => $this->lang->admin->community->giftPackageSuccess, 'closeModal' => true));
  631. }
  632. return $this->send(array('result' => 'fail', 'message' => isset($response['message']) ? $response['message'] : $this->lang->admin->community->giftPackageFailed));
  633. }
  634. $companyID = isset($this->app->company->id) ? $this->app->company->id : 1;
  635. $this->loadModel('company');
  636. $company = $this->company->getByID($companyID);
  637. $this->view->company = $company->name;
  638. $this->display();
  639. }
  640. }