control.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <?php
  2. /**
  3. * The control file of tutorial 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 Hao Sun <sunhao@cnezsoft.com>
  8. * @package tutorial
  9. * @version $Id: control.php 5002 2013-07-03 08:25:39Z chencongzhi520@gmail.com $
  10. * @link https://www.zentao.net
  11. */
  12. class tutorial extends control
  13. {
  14. /**
  15. * 新手教程开始页面。
  16. * Tutorial start page.
  17. *
  18. * @access public
  19. * @return void
  20. */
  21. public function start()
  22. {
  23. $this->view->title = $this->lang->tutorial->common;
  24. $this->display();
  25. }
  26. /**
  27. * 新手教程页面。
  28. * Tutorial page.
  29. *
  30. * @access public
  31. * @return void
  32. * @param string $referer
  33. * @param string $task
  34. */
  35. public function index($referer = '', $guide = '', $task = '')
  36. {
  37. $setting = isset($this->config->tutorial->tasks->setting) ? $this->config->tutorial->tasks->setting : '';
  38. $this->loadModel('setting')->setItem($this->app->user->account . '.common.global.novice', 0);
  39. $this->session->set('tutorialMode', true);
  40. $this->view->title = $this->lang->tutorial->common;
  41. $this->view->currentGuide = $guide;
  42. $this->view->currentTask = $task;
  43. $this->view->guides = $this->config->tutorial->guides;
  44. $this->view->setting = $setting;
  45. $this->view->referer = base64_decode($referer);
  46. $this->view->mode = $this->setting->getItem('owner=system&module=common&section=global&key=mode');
  47. $this->display();
  48. }
  49. /**
  50. * Ajax设置任务。
  51. * Ajax set tasks
  52. *
  53. * @param string $finish
  54. * @access public
  55. * @return string
  56. */
  57. public function ajaxSetTasks($finish = 'keepAll')
  58. {
  59. if($_POST && isset($_POST['finish'])) $finish = $_POST['finish'];
  60. if($finish == 'keepAll') return $this->send(array('result' => 'fail', 'alert' => $this->lang->tutorial->ajaxSetError));
  61. $this->session->set('tutorialMode', false);
  62. $this->loadModel('setting')->setItem("{$this->app->user->account}.tutorial.tasks.setting", $finish);
  63. $this->session->set('tutorialMode', true);
  64. return $this->send(array('result' => 'success'));
  65. }
  66. /**
  67. * 退出新手教程模式。
  68. * Exit tutorial mode.
  69. *
  70. * @access public
  71. * @return void
  72. */
  73. public function quit()
  74. {
  75. $this->session->set('tutorialMode', false);
  76. $this->loadModel('setting')->setItem($this->app->user->account . '.common.global.novice', 0);
  77. return $this->send(array('result' => 'success', 'open' => $this->createLink('index', 'index')));
  78. }
  79. /**
  80. * 通过ajax退出新手教程模式。
  81. * Ajax quit tutorial mode
  82. *
  83. * @access public
  84. * @return void
  85. */
  86. public function ajaxQuit()
  87. {
  88. $this->session->set('tutorialMode', false);
  89. $this->loadModel('setting')->setItem($this->app->user->account . '.common.global.novice', 0);
  90. echo json_encode(array('result' => 'success'));
  91. }
  92. /**
  93. * 向导页面。
  94. * Wizard.
  95. *
  96. * @param string $module
  97. * @param string $method
  98. * @param string $params
  99. * @access public
  100. * @return void
  101. */
  102. public function wizard($module, $method, $params = '')
  103. {
  104. if(!commonModel::isTutorialMode()) $_SESSION['tutorialMode'] = true;
  105. define('WIZARD_MODULE', $module);
  106. define('WIZARD_METHOD', $method);
  107. /* Check priv for tutorial. */
  108. $hasPriv = false;
  109. $moduleLower = strtolower($module);
  110. foreach($this->config->tutorial->guides as $guide)
  111. {
  112. if(!isset($guide->modules)) continue;
  113. $guideModules = explode(',', strtolower($guide->modules));
  114. if(in_array($moduleLower, $guideModules))
  115. {
  116. $hasPriv = true;
  117. break;
  118. }
  119. }
  120. if(!$hasPriv && $module == 'my' && $method == 'index') $hasPriv = true;
  121. if(!$hasPriv)
  122. {
  123. if(helper::isAjaxRequest()) return $this->send(array('result' => 'success', 'message' => $this->lang->error->accessDenied, 'load' => array('alert' => $this->lang->error->accessDenied)));
  124. return print(js::locate('back'));
  125. }
  126. $params = helper::safe64Decode($params);
  127. if($_POST)
  128. {
  129. $target = 'parent';
  130. if(($module == 'story' || $module == 'task' || $module == 'bug') && $method == 'create') $target = 'self';
  131. if($module == 'execution' && ($method == 'linkStory' || $method == 'managemembers')) $target = 'self';
  132. if(helper::isAjaxRequest()) return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'load' => helper::createLink('tutorial', 'wizard', "module={$module}&method={$method}&params=" . helper::safe64Encode($params))));
  133. return print(js::locate(helper::createLink('tutorial', 'wizard', "module={$module}&method={$method}&params=" . helper::safe64Encode($params)), $target));
  134. }
  135. if(in_array("{$module}-{$method}", $this->config->excludeDropmenuList)) $this->config->excludeDropmenuList[] = 'tutorial-wizard';
  136. echo $this->fetch($module, $method, $params);
  137. }
  138. /**
  139. * 通过ajax保存新手教程结果。
  140. * Ajax save novice result.
  141. *
  142. * @param string $novice
  143. * @param string $reload
  144. *
  145. * @access public
  146. * @return void
  147. */
  148. public function ajaxSaveNovice($novice = 'true', $reload = 'false')
  149. {
  150. $this->loadModel('setting')->setItem($this->app->user->account . '.common.global.novice', $novice == 'true' ? 1 : 0);
  151. if($reload == 'true')
  152. {
  153. if(helper::isAjaxRequest()) return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'load' => true));
  154. return print(js::reload('parent'));
  155. }
  156. }
  157. /**
  158. * 通过ajax保存新手教程进度。
  159. * Ajax save tutorial score.
  160. *
  161. * @access public
  162. * @return void
  163. */
  164. public function ajaxFinish()
  165. {
  166. $tutorialMode = $this->session->tutorialMode;
  167. $this->session->set('tutorialMode', false);
  168. $this->loadModel('score')->create('tutorial', 'finish');
  169. $this->session->set('tutorialMode', $tutorialMode);
  170. }
  171. }