PageRenderTime 52ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/module/misc/control.php

https://github.com/easysoft/zentaopms
PHP | 335 lines | 184 code | 37 blank | 114 comment | 26 complexity | aa964a58f4f24c56d4f1ac1aaf6478a6 MD5 | raw file
  1. <?php
  2. /**
  3. * The control file of misc 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 misc
  9. * @version $Id: control.php 5128 2013-07-13 08:59:49Z chencongzhi520@gmail.com $
  10. * @link http://www.zentao.net
  11. */
  12. class misc extends control
  13. {
  14. /**
  15. * Ping the server every 5 minutes to keep the session.
  16. *
  17. * @access public
  18. * @return void
  19. */
  20. public function ping()
  21. {
  22. if(mt_rand(0, 1) == 1) $this->loadModel('setting')->setSN();
  23. echo "<html><head><meta http-equiv='refresh' content='600' /></head><body></body></html>";
  24. }
  25. /**
  26. * Show php info.
  27. *
  28. * @access public
  29. * @return void
  30. */
  31. public function phpinfo()
  32. {
  33. phpinfo();
  34. }
  35. /**
  36. * Show about info of zentao.
  37. *
  38. * @access public
  39. * @return void
  40. */
  41. public function about()
  42. {
  43. $this->display();
  44. }
  45. /**
  46. * Update nl.
  47. *
  48. * @access public
  49. * @return void
  50. */
  51. public function updateNL()
  52. {
  53. $this->loadModel('upgrade')->updateNL();
  54. }
  55. /**
  56. * Check current version is latest or not.
  57. *
  58. * @param string $sn
  59. * @access public
  60. * @return void
  61. */
  62. public function checkUpdate($sn = '')
  63. {
  64. session_write_close();
  65. $website = $this->config->misc->api;
  66. if(isset($this->config->qcVersion)) $website = $this->config->misc->qucheng;
  67. if(isset($this->config->isINT)) $website = $this->config->misc->enApi;
  68. $source = isset($this->config->qcVersion) ? 'qucheng' : 'zentao';
  69. $lang = str_replace('-', '_', $this->app->getClientLang());
  70. $link = $website . "/updater-getLatest-{$this->config->version}-$source-$lang-$sn.html";
  71. $latestVersionList = common::http($link);
  72. if(!isset($this->config->global->latestVersionList) or $this->config->global->latestVersionList != $latestVersionList)
  73. {
  74. $this->loadModel('setting')->setItem('system.common.global.latestVersionList', $latestVersionList);
  75. }
  76. }
  77. /**
  78. * Check model extension logic
  79. *
  80. * @access public
  81. * @return void
  82. */
  83. public function checkExtension()
  84. {
  85. echo $this->misc->hello();
  86. echo $this->misc->hello2();
  87. }
  88. /**
  89. * Down notify.
  90. *
  91. * @access public
  92. * @return void
  93. */
  94. public function downNotify()
  95. {
  96. $notifyDir = $this->app->getBasePath() . 'tmp/cache/notify/';
  97. if(!is_dir($notifyDir))mkdir($notifyDir, 0755, true);
  98. $account = $this->app->user->account;
  99. $packageFile = $notifyDir . $account . 'notify.zip';
  100. $loginFile = $notifyDir . 'config.json';
  101. /* write login info into tmp file. */
  102. $loginInfo = new stdclass();
  103. $userInfo = new stdclass();
  104. $userInfo->Account = $account;
  105. $userInfo->Url = common::getSysURL() . $this->config->webRoot;
  106. $userInfo->PassMd5 = '';
  107. $userInfo->Role = $this->app->user->role;
  108. $userInfo->AutoSignIn = true;
  109. $userInfo->Lang = $this->cookie->lang;
  110. $loginInfo->User = $userInfo;
  111. $loginInfo->LastLoginTime = time() / 86400 + 25569;
  112. $loginInfo = json_encode($loginInfo);
  113. file_put_contents($packageFile, file_get_contents("http://dl.cnezsoft.com/notify/newest/zentaonotify.win_32.zip"));
  114. file_put_contents($loginFile, $loginInfo);
  115. define('PCLZIP_TEMPORARY_DIR', $notifyDir);
  116. $this->app->loadClass('pclzip', true);
  117. /* remove the old config.json, add a new one. */
  118. $archive = new pclzip($packageFile);
  119. $result = $archive->delete(PCLZIP_OPT_BY_NAME, 'config.json');
  120. if($result == 0) return print("Error : " . $archive->errorInfo(true));
  121. $result = $archive->add($loginFile, PCLZIP_OPT_REMOVE_ALL_PATH, PCLZIP_OPT_ADD_PATH, 'notify');
  122. if($result == 0) return print("Error : " . $archive->errorInfo(true));
  123. $zipContent = file_get_contents($packageFile);
  124. unlink($loginFile);
  125. unlink($packageFile);
  126. $this->fetch('file', 'sendDownHeader', array('fileName' => 'notify.zip', 'zip', $zipContent));
  127. }
  128. /**
  129. * Create qrcode for mobile login.
  130. *
  131. * @access public
  132. * @return void
  133. */
  134. public function qrCode()
  135. {
  136. $loginAPI = common::getSysURL() . $this->config->webRoot;
  137. $session = $this->loadModel('user')->isLogon() ? '?' . $this->config->sessionVar . '=' . session_id() : '';
  138. if(!extension_loaded('gd'))
  139. {
  140. $this->view->noGDLib = sprintf($this->lang->misc->noGDLib, $loginAPI);
  141. return print($this->display());
  142. }
  143. $this->app->loadClass('qrcode');
  144. QRcode::png($loginAPI . $session, false, 4, 9);
  145. }
  146. /**
  147. * Ajax ignore browser.
  148. *
  149. * @access public
  150. * @return void
  151. */
  152. public function ajaxIgnoreBrowser()
  153. {
  154. $this->loadModel('setting')->setItem($this->app->user->account . '.common.global.browserNotice', 'true');
  155. }
  156. /**
  157. * Show version changelog
  158. * @access public
  159. * @return viod
  160. */
  161. public function changeLog($version = '')
  162. {
  163. if(empty($version)) $version = key($this->lang->misc->feature->all);
  164. $this->view->version = $version;
  165. $this->view->features = zget($this->lang->misc->feature->all, $version, '');
  166. $detailed = '';
  167. $changeLogFile = $this->app->getBasePath() . 'doc' . DS . 'CHANGELOG';
  168. if(file_exists($changeLogFile))
  169. {
  170. $handle = fopen($changeLogFile, 'r');
  171. $tag = false;
  172. while($line = fgets($handle))
  173. {
  174. $line = trim($line);
  175. if($tag and empty($line)) break;
  176. if($tag) $detailed .= $line . '<br />';
  177. if(preg_match("/{$version}$/", $line) > 0) $tag = true;
  178. }
  179. fclose($handle);
  180. }
  181. $this->view->detailed = $detailed;
  182. $this->display();
  183. }
  184. /**
  185. * Check net connect.
  186. *
  187. * @access public
  188. * @return void
  189. */
  190. public function checkNetConnect()
  191. {
  192. $this->app->loadConfig('extension');
  193. $check = @fopen(dirname($this->config->extension->apiRoot), "r");
  194. print($check ? 'success' : 'fail');
  195. }
  196. /**
  197. * Show captcha and save to session.
  198. *
  199. * @param string $sessionVar
  200. * @param string $uuid
  201. * @access public
  202. * @return void
  203. */
  204. public function captcha($sessionVar = 'captcha', $uuid = '')
  205. {
  206. $obLevel = ob_get_level();
  207. for($i = 0; $i < $obLevel; $i++) ob_end_clean();
  208. header('Content-Type: image/jpeg');
  209. $captcha = $this->app->loadClass('captcha');
  210. $this->session->set($sessionVar, $captcha->getPhrase());
  211. $captcha->build()->output();
  212. }
  213. /**
  214. * Ajax set unfoldID.
  215. *
  216. * @param int $objectID
  217. * @param string $objectType
  218. * @param string $action add|delete
  219. * @access public
  220. * @return void
  221. */
  222. public function ajaxSetUnfoldID($objectID, $objectType, $action = 'add')
  223. {
  224. $account = $this->app->user->account;
  225. if($objectType == 'execution')
  226. {
  227. $condition = "owner={$account}&module={$objectType}&section=task&key=unfoldTasks";
  228. $settingPath = $account . ".{$objectType}.task.unfoldTasks";
  229. }
  230. else
  231. {
  232. $condition = "owner={$account}&module=product&section=browse&key=unfoldStories";
  233. $settingPath = $account . ".{$objectType}.browse.unfoldStories";
  234. }
  235. $this->loadModel('setting');
  236. $setting = $this->setting->createDAO($this->setting->parseItemParam($condition), 'select')->fetch();
  237. $newUnfoldID = $this->post->newUnfoldID;
  238. if(empty($newUnfoldID)) return;
  239. $newUnfoldID = json_decode($newUnfoldID);
  240. $unfoldIdList = $setting ? json_decode($setting->value, true) : array();
  241. foreach($newUnfoldID as $unfoldID)
  242. {
  243. unset($unfoldIdList[$objectID][$unfoldID]);
  244. if($action == 'add') $unfoldIdList[$objectID][$unfoldID] = $unfoldID;
  245. }
  246. if(empty($setting))
  247. {
  248. $this->setting->setItem($settingPath, json_encode($unfoldIdList));
  249. }
  250. else
  251. {
  252. $this->dao->update(TABLE_CONFIG)->set('value')->eq(json_encode($unfoldIdList))->where('id')->eq($setting->id)->exec();
  253. }
  254. echo 'success';
  255. }
  256. /**
  257. * Get annual remind.
  258. *
  259. * @access public
  260. * @return void
  261. */
  262. public function getRemind()
  263. {
  264. $data = array('content' => $this->misc->getRemind(), 'title' => $this->lang->misc->remind);
  265. $this->send(array('result' => 'success', 'data' => $data));
  266. }
  267. /**
  268. * Features dialog.
  269. *
  270. * @access public
  271. * @return void
  272. */
  273. public function features()
  274. {
  275. $features = array();
  276. foreach($this->config->newFeatures as $feature)
  277. {
  278. $accounts = zget($this->config->global, 'skip' . ucfirst($feature), '');
  279. if(strpos(",$accounts,", $this->app->user->account) === false) $features[] = $feature;
  280. }
  281. $this->app->loadLang('install');
  282. $this->view->features = $features;
  283. $this->display();
  284. }
  285. /**
  286. * Save viewed feature.
  287. *
  288. * @param string $feature
  289. * @access public
  290. * @return void
  291. */
  292. public function ajaxSaveViewed($feature)
  293. {
  294. $accounts = zget($this->config->global, 'skip' . ucfirst($feature), '');
  295. if(strpos(",$accounts,", $this->app->user->account) === false) $accounts .= ',' . $this->app->user->account;
  296. $this->loadModel('setting')->setItem('system.common.global.skip' . ucfirst($feature), $accounts);
  297. }
  298. }