PageRenderTime 45ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/module/admin/control.php

https://github.com/easysoft/zentaopms
PHP | 376 lines | 235 code | 37 blank | 104 comment | 39 complexity | 23c03e6c12fadccee0dbbab8cfd88884 MD5 | raw file
  1. <?php
  2. /**
  3. * The control file of admin module of ZenTaoPMS.
  4. *
  5. * @copyright Copyright 2009-2015 青岛易软天创网络科技有限公司(QingDao Nature Easy Soft Network Technology 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 http://www.zentao.net
  11. */
  12. class admin extends control
  13. {
  14. /**
  15. * Index page.
  16. * @access public
  17. * @return void
  18. */
  19. public function index()
  20. {
  21. $community = zget($this->config->global, 'community', '');
  22. if(!$community or $community == 'na')
  23. {
  24. $this->view->bind = false;
  25. $this->view->account = false;
  26. $this->view->ignore = $community == 'na';
  27. }
  28. else
  29. {
  30. $this->view->bind = true;
  31. $this->view->account = $community;
  32. $this->view->ignore = false;
  33. }
  34. $this->loadModel('misc');
  35. $this->view->title = $this->lang->admin->common;
  36. $this->view->position[] = $this->lang->admin->index;
  37. $this->display();
  38. }
  39. /**
  40. * Ignore notice of register and bind.
  41. *
  42. * @access public
  43. * @return void
  44. */
  45. public function ignore()
  46. {
  47. $account = $this->app->user->account;
  48. $this->loadModel('setting');
  49. $this->setting->deleteItems('owner=system&module=common&section=global&key=ztPrivateKey');
  50. $this->setting->setItem("$account.common.global.community", 'na');
  51. echo js::locate(inlink('index'), 'parent');
  52. }
  53. /**
  54. * Register zentao.
  55. *
  56. * @param string $from
  57. * @access public
  58. * @return void
  59. */
  60. public function register($from = 'admin')
  61. {
  62. if($_POST)
  63. {
  64. $response = $this->admin->registerByAPI();
  65. $response = json_decode($response);
  66. if($response->result == 'success')
  67. {
  68. $user = $response->data;
  69. $data['community'] = $user->account;
  70. $data['ztPrivateKey'] = $user->private;
  71. $this->loadModel('setting');
  72. $this->setting->deleteItems('owner=system&module=common&section=global&key=community');
  73. $this->setting->deleteItems('owner=system&module=common&section=global&key=ztPrivateKey');
  74. $this->setting->setItems('system.common.global', $data);
  75. echo js::alert($this->lang->admin->registerNotice->success);
  76. if($from == 'admin') return print(js::locate(inlink('index'), 'parent'));
  77. if($from == 'mail') return print(js::locate($this->createLink('mail', 'ztcloud'), 'parent'));
  78. }
  79. $alertMessage = '';
  80. if(is_string($response->message))
  81. {
  82. $alertMessage = $response->message;
  83. }
  84. else
  85. {
  86. foreach($response->message as $item) $alertMessage .= is_array($item) ? join('\n', $item) . '\n' : $item . '\n';
  87. }
  88. $alertMessage = str_replace(array('<strong>', '</strong>'), '', $alertMessage);
  89. return print(js::alert($alertMessage));
  90. }
  91. $this->view->title = $this->lang->admin->registerNotice->caption;
  92. $this->view->position[] = $this->lang->admin->registerNotice->caption;
  93. $this->view->register = $this->admin->getRegisterInfo();
  94. $this->view->sn = $this->config->global->sn;
  95. $this->view->from = $from;
  96. $this->display();
  97. }
  98. /**
  99. * Bind zentao.
  100. *
  101. * @param string $from
  102. * @access public
  103. * @return void
  104. */
  105. public function bind($from = 'admin')
  106. {
  107. if($_POST)
  108. {
  109. $response = $this->admin->bindByAPI();
  110. $response = json_decode($response);
  111. if($response->result == 'success')
  112. {
  113. $user = $response->data;
  114. $data['community'] = $user->account;
  115. $data['ztPrivateKey'] = $user->private;
  116. $this->loadModel('setting');
  117. $this->setting->deleteItems('owner=system&module=common&section=global&key=community');
  118. $this->setting->deleteItems('owner=system&module=common&section=global&key=ztPrivateKey');
  119. $this->setting->setItems('system.common.global', $data);
  120. echo js::alert($this->lang->admin->bind->success);
  121. if($from == 'admin') return print(js::locate(inlink('index'), 'parent'));
  122. if($from == 'mail') return print(js::locate($this->createLink('mail', 'ztcloud'), 'parent'));
  123. }
  124. else
  125. {
  126. if($response->result == 'fail') return print(js::alert($response->message));
  127. }
  128. }
  129. $this->view->title = $this->lang->admin->bind->caption;
  130. $this->view->position[] = $this->lang->admin->bind->caption;
  131. $this->view->sn = $this->config->global->sn;
  132. $this->view->from = $from;
  133. $this->display();
  134. }
  135. /**
  136. * Check all tables.
  137. *
  138. * @access public
  139. * @return void
  140. */
  141. public function checkDB()
  142. {
  143. $tables = $this->dbh->query("show full tables where Table_Type != 'VIEW'")->fetchAll(PDO::FETCH_ASSOC);
  144. foreach($tables as $table)
  145. {
  146. $tableName = current($table);
  147. $result = $this->dbh->query("REPAIR TABLE $tableName")->fetch();
  148. echo "Repairing TABLE: " . $result->Table . (defined('IN_SHELL') ? "\t" : "&nbsp;&nbsp;&nbsp;&nbsp;") . $result->Msg_type . ":" . $result->Msg_text . (defined('IN_SHELL') ? "\n" : "<br />\n");
  149. }
  150. }
  151. /**
  152. * Account safe.
  153. *
  154. * @access public
  155. * @return void
  156. */
  157. public function safe()
  158. {
  159. if($_POST)
  160. {
  161. $data = fixer::input('post')->get();
  162. $this->loadModel('setting')->setItems('system.common.safe', $data);
  163. return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => 'reload'));
  164. }
  165. $this->view->title = $this->lang->admin->safe->common . $this->lang->colon . $this->lang->admin->safe->set;
  166. $this->view->position[] = $this->lang->admin->safe->common;
  167. $this->display();
  168. }
  169. /**
  170. * Check weak user.
  171. *
  172. * @access public
  173. * @return void
  174. */
  175. public function checkWeak()
  176. {
  177. $this->view->title = $this->lang->admin->safe->common . $this->lang->colon . $this->lang->admin->safe->checkWeak;
  178. $this->view->position[] = html::a(inlink('safe'), $this->lang->admin->safe->common);
  179. $this->view->position[] = $this->lang->admin->safe->checkWeak;
  180. $this->view->weakUsers = $this->loadModel('user')->getWeakUsers();
  181. $this->display();
  182. }
  183. /**
  184. * Config sso for ranzhi.
  185. *
  186. * @access public
  187. * @return void
  188. */
  189. public function sso()
  190. {
  191. if(!empty($_POST))
  192. {
  193. $ssoConfig = new stdclass();
  194. $ssoConfig->turnon = $this->post->turnon;
  195. $ssoConfig->redirect = $this->post->redirect;
  196. $ssoConfig->addr = $this->post->addr;
  197. $ssoConfig->code = trim($this->post->code);
  198. $ssoConfig->key = trim($this->post->key);
  199. if(!$ssoConfig->turnon) $ssoConfig->redirect = $ssoConfig->turnon;
  200. $this->loadModel('setting')->setItems('system.sso', $ssoConfig);
  201. if(dao::isError()) return print(js::error(dao::getError()));
  202. return print($this->locate(inlink('sso')));
  203. }
  204. $this->loadModel('sso');
  205. if(!isset($this->config->sso)) $this->config->sso = new stdclass();
  206. $this->view->title = $this->lang->admin->sso;
  207. $this->view->position[] = $this->lang->admin->sso;
  208. $this->view->turnon = isset($this->config->sso->turnon) ? $this->config->sso->turnon : 1;
  209. $this->view->redirect = isset($this->config->sso->redirect) ? $this->config->sso->redirect : 0;
  210. $this->view->addr = isset($this->config->sso->addr) ? $this->config->sso->addr : '';
  211. $this->view->key = isset($this->config->sso->key) ? $this->config->sso->key : '';
  212. $this->view->code = isset($this->config->sso->code) ? $this->config->sso->code : '';
  213. $this->display();
  214. }
  215. /**
  216. * Certify ztEmail.
  217. *
  218. * @param string $email
  219. * @access public
  220. * @return void
  221. */
  222. public function certifyZtEmail($email = '')
  223. {
  224. if($_POST)
  225. {
  226. $response = $this->admin->certifyByAPI('mail');
  227. $response = json_decode($response);
  228. if($response->result == 'fail') return print(js::alert($response->message));
  229. return print(js::locate($this->createLink('mail', 'ztCloud'), 'parent'));
  230. }
  231. $this->view->title = $this->lang->admin->certifyEmail;
  232. $this->view->position[] = $this->lang->admin->certifyEmail;
  233. $this->view->email = helper::safe64Decode($email);
  234. $this->display();
  235. }
  236. /**
  237. * Certify ztMobile.
  238. *
  239. * @param string $mobile
  240. * @access public
  241. * @return void
  242. */
  243. public function certifyZtMobile($mobile = '')
  244. {
  245. if($_POST)
  246. {
  247. $response = $this->admin->certifyByAPI('mobile');
  248. $response = json_decode($response);
  249. if($response->result == 'fail') return print(js::alert($response->message));
  250. return print(js::locate($this->createLink('mail', 'ztCloud'), 'parent'));
  251. }
  252. $this->view->title = $this->lang->admin->certifyMobile;
  253. $this->view->position[] = $this->lang->admin->certifyMobile;
  254. $this->view->mobile = helper::safe64Decode($mobile);
  255. $this->display();
  256. }
  257. /**
  258. * Set ztCompany.
  259. *
  260. * @access public
  261. * @return void
  262. */
  263. public function ztCompany($fields = 'company')
  264. {
  265. if($_POST)
  266. {
  267. $response = $this->admin->setCompanyByAPI();
  268. $response = json_decode($response);
  269. if($response->result == 'fail') return print(js::alert($response->message));
  270. return print(js::locate($this->createLink('mail', 'ztCloud'), 'parent'));
  271. }
  272. $this->view->title = $this->lang->admin->ztCompany;
  273. $this->view->position[] = $this->lang->admin->ztCompany;
  274. $this->view->fields = explode(',', $fields);
  275. $this->display();
  276. }
  277. /**
  278. * Ajax send code.
  279. *
  280. * @param string $type
  281. * @access public
  282. * @return void
  283. */
  284. public function ajaxSendCode($type)
  285. {
  286. return print($this->admin->sendCodeByAPI($type));
  287. }
  288. /**
  289. * Set save days of log.
  290. *
  291. * @access public
  292. * @return void
  293. */
  294. public function log()
  295. {
  296. if($_POST)
  297. {
  298. if(!validater::checkInt($this->post->days)) return $this->send(array('result' => 'fail', 'message' => array('days' => sprintf($this->lang->admin->notice->int, $this->lang->admin->days))));
  299. $this->loadModel('setting')->setItem('system.admin.log.saveDays', $this->post->days);
  300. if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError()));
  301. return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => 'parent'));
  302. }
  303. $this->loadModel('message');
  304. $this->loadModel('webhook');
  305. $this->view->title = $this->lang->admin->log;
  306. $this->view->position[] = html::a($this->createLink('webhook', 'browse'), $this->lang->admin->api);
  307. $this->view->position[] = $this->lang->admin->log;
  308. $this->view->position[] = $this->lang->admin->setting;
  309. $this->display();
  310. }
  311. /**
  312. * Delete logs older than save days.
  313. *
  314. * @access public
  315. * @return bool
  316. */
  317. public function deleteLog()
  318. {
  319. $date = date(DT_DATE1, strtotime("-{$this->config->admin->log->saveDays} days"));
  320. $this->dao->delete()->from(TABLE_LOG)->where('date')->lt($date)->exec();
  321. return !dao::isError();
  322. }
  323. /**
  324. * Reset password setting.
  325. *
  326. * @access public
  327. * @return void
  328. */
  329. public function resetPWDSetting()
  330. {
  331. if($_POST)
  332. {
  333. $this->loadModel('setting')->setItem('system.common.resetPWDByMail', $this->post->resetPWDByMail);
  334. return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => 'reload'));
  335. }
  336. $this->view->title = $this->lang->admin->resetPWDSetting;
  337. $this->display();
  338. }
  339. }