introductionSection.inc.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use Chamilo\CourseBundle\Entity\CToolIntro;
  4. /**
  5. * The INTRODUCTION MICRO MODULE is used to insert and edit
  6. * an introduction section on a Chamilo module or on the course homepage.
  7. * It can be inserted on any Chamilo module, provided the corresponding setting
  8. * is enabled in the administration section.
  9. *
  10. * The introduction content are stored in a table called "tool_intro"
  11. * in the course Database. Each module introduction has an Id stored in
  12. * the table, which matches a specific module.
  13. *
  14. * '(c_)tool_intro' table description
  15. * c_id: int
  16. * id : int
  17. * intro_text :text
  18. * session_id: int
  19. *
  20. * usage :
  21. *
  22. * $moduleId = 'XX'; // specifying the module tool (string value)
  23. * include(introductionSection.inc.php);
  24. *
  25. * This script is also used since Chamilo 1.9 to show course progress (from the
  26. * course_progress module)
  27. *
  28. * @package chamilo.include
  29. */
  30. $em = Database::getManager();
  31. $TBL_INTRODUCTION = Database::get_course_table(TABLE_TOOL_INTRO);
  32. $intro_editAllowed = $is_allowed_to_edit;
  33. $session_id = api_get_session_id();
  34. $introduction_section = '';
  35. global $charset;
  36. $intro_cmdEdit = empty($_GET['intro_cmdEdit']) ? '' : $_GET['intro_cmdEdit'];
  37. $intro_cmdUpdate = isset($_POST['intro_cmdUpdate']);
  38. $intro_cmdDel = empty($_GET['intro_cmdDel']) ? '' : $_GET['intro_cmdDel'];
  39. $intro_cmdAdd = empty($_GET['intro_cmdAdd']) ? '' : $_GET['intro_cmdAdd'];
  40. $courseId = api_get_course_id();
  41. if (!empty($courseId)) {
  42. $form = new FormValidator(
  43. 'introduction_text',
  44. 'post',
  45. api_get_self().'?'.api_get_cidreq()
  46. );
  47. } else {
  48. $form = new FormValidator('introduction_text');
  49. }
  50. $config = array(
  51. 'ToolbarSet' => 'IntroductionTool',
  52. 'Width' => '100%',
  53. 'Height' => '300'
  54. );
  55. $form->addHtmlEditor('intro_content', null, false, false, $config, true);
  56. $form->addButtonSave(get_lang('SaveIntroText'), 'intro_cmdUpdate');
  57. /* INTRODUCTION MICRO MODULE - COMMANDS SECTION (IF ALLOWED) */
  58. $course_id = api_get_course_int_id();
  59. if ($intro_editAllowed) {
  60. /** @var CToolIntro $toolIntro */
  61. $toolIntro = $em
  62. ->getRepository('ChamiloCourseBundle:CToolIntro')
  63. ->findOneBy(['cId' => $course_id, 'id' => $moduleId, 'sessionId' => $session_id]);
  64. /* Replace command */
  65. if ($intro_cmdUpdate) {
  66. if ($form->validate()) {
  67. $form_values = $form->exportValues();
  68. $intro_content = $form_values['intro_content'];
  69. if (!empty($intro_content)) {
  70. if (!$toolIntro) {
  71. $toolIntro = new CToolIntro();
  72. $toolIntro
  73. ->setSessionId($session_id)
  74. ->setCId($course_id)
  75. ->setId($moduleId);
  76. }
  77. $toolIntro->setIntroText($intro_content);
  78. $em->persist($toolIntro);
  79. $em->flush();
  80. Display::addFlash(Display::return_message(get_lang('IntroductionTextUpdated'), 'confirmation', false));
  81. } else {
  82. // got to the delete command
  83. $intro_cmdDel = true;
  84. }
  85. } else {
  86. $intro_cmdEdit = true;
  87. }
  88. }
  89. /* Delete Command */
  90. if ($intro_cmdDel && $toolIntro) {
  91. $em->remove($toolIntro);
  92. $em->flush();
  93. Display::addFlash(Display::return_message(get_lang('IntroductionTextDeleted'), 'confirmation'));
  94. }
  95. }
  96. /* INTRODUCTION MICRO MODULE - DISPLAY SECTION */
  97. /* Retrieves the module introduction text, if exist */
  98. // Getting course intro
  99. /** @var CToolIntro $toolIntro */
  100. $toolIntro = $em
  101. ->getRepository('ChamiloCourseBundle:CToolIntro')
  102. ->findOneBy(['cId' => $course_id, 'id' => $moduleId, 'sessionId' => 0]);
  103. $intro_content = $toolIntro ? $toolIntro->getIntroText() : '';
  104. if ($session_id) {
  105. /** @var CToolIntro $toolIntro */
  106. $toolIntro = $em
  107. ->getRepository('ChamiloCourseBundle:CToolIntro')
  108. ->findOneBy(['cId' => $course_id, 'id' => $moduleId, 'sessionId' => $session_id]);
  109. $introSessionContent = $toolIntro && $toolIntro->getIntroText() ? $toolIntro->getIntroText() : '';
  110. $intro_content = $introSessionContent ?: $intro_content;
  111. }
  112. // Default behaviour show iframes.
  113. $userStatus = COURSEMANAGERLOWSECURITY;
  114. // Allows to do a remove_XSS in course introduction with user status COURSEMANAGERLOWSECURITY
  115. // Block embed type videos (like vimeo, wistia, etc) - see BT#12244 BT#12556
  116. if (api_get_configuration_value('course_introduction_html_strict_filtering')) {
  117. $userStatus = COURSEMANAGER;
  118. }
  119. $intro_content = Security::remove_XSS($intro_content, $userStatus);
  120. /* Determines the correct display */
  121. if ($intro_cmdEdit || $intro_cmdAdd) {
  122. $intro_dispDefault = false;
  123. $intro_dispForm = true;
  124. $intro_dispCommand = false;
  125. } else {
  126. $intro_dispDefault = true;
  127. $intro_dispForm = false;
  128. if ($intro_editAllowed) {
  129. $intro_dispCommand = true;
  130. } else {
  131. $intro_dispCommand = false;
  132. }
  133. }
  134. /* Executes the display */
  135. // display thematic advance inside a postit
  136. if ($intro_dispForm) {
  137. $default['intro_content'] = $intro_content;
  138. $form->setDefaults($default);
  139. $introduction_section .= '<div id="courseintro" style="width: 98%">';
  140. $introduction_section .= $form->returnForm();
  141. $introduction_section .= '</div>';
  142. }
  143. $thematic_description_html = '';
  144. $thematicItemTwo = '';
  145. if ($tool == TOOL_COURSE_HOMEPAGE && !isset($_GET['intro_cmdEdit'])) {
  146. // Only show this if we're on the course homepage and we're not currently editing
  147. $thematic = new Thematic();
  148. $displayMode = api_get_course_setting('display_info_advance_inside_homecourse');
  149. $class1 = '';
  150. if ($displayMode == '1') {
  151. // Show only the current course progress step
  152. // $information_title = get_lang('InfoAboutLastDoneAdvance');
  153. $last_done_advance = $thematic->get_last_done_thematic_advance();
  154. $thematic_advance_info = $thematic->get_thematic_advance_list($last_done_advance);
  155. $subTitle1 = get_lang('CurrentTopic');
  156. $class1 = ' current';
  157. } elseif ($displayMode == '2') {
  158. // Show only the two next course progress steps
  159. // $information_title = get_lang('InfoAboutNextAdvanceNotDone');
  160. $last_done_advance = $thematic->get_next_thematic_advance_not_done();
  161. $next_advance_not_done = $thematic->get_next_thematic_advance_not_done(2);
  162. $thematic_advance_info = $thematic->get_thematic_advance_list($last_done_advance);
  163. $thematic_advance_info2 = $thematic->get_thematic_advance_list($next_advance_not_done);
  164. $subTitle1 = $subTitle2 = get_lang('NextTopic');
  165. } elseif ($displayMode == '3') {
  166. // Show the current and next course progress steps
  167. // $information_title = get_lang('InfoAboutLastDoneAdvanceAndNextAdvanceNotDone');
  168. $last_done_advance = $thematic->get_last_done_thematic_advance();
  169. $next_advance_not_done = $thematic->get_next_thematic_advance_not_done();
  170. $thematic_advance_info = $thematic->get_thematic_advance_list($last_done_advance);
  171. $thematic_advance_info2 = $thematic->get_thematic_advance_list($next_advance_not_done);
  172. $subTitle1 = get_lang('CurrentTopic');
  173. $subTitle2 = get_lang('NextTopic');
  174. $class1 = ' current';
  175. }
  176. if (!empty($thematic_advance_info)) {
  177. $thematic_advance = get_lang('CourseThematicAdvance');
  178. $thematicScore = $thematic->get_total_average_of_thematic_advances().'%';
  179. $thematicUrl = api_get_path(WEB_CODE_PATH).'course_progress/index.php?action=thematic_details&'.api_get_cidreq();
  180. $thematic_info = $thematic->get_thematic_list(
  181. $thematic_advance_info['thematic_id']
  182. );
  183. $thematic_advance_info['start_date'] = api_get_local_time(
  184. $thematic_advance_info['start_date']
  185. );
  186. $thematic_advance_info['start_date'] = api_format_date(
  187. $thematic_advance_info['start_date'],
  188. DATE_TIME_FORMAT_LONG
  189. );
  190. $userInfo = api_get_user_info();
  191. $courseInfo = api_get_course_info();
  192. $titleThematic = $thematic_advance.' : '.$courseInfo['name'].' <b>( '.$thematicScore.' )</b>';
  193. $infoUser = '<div class="thematic-avatar"><img src="'.$userInfo['avatar'].'" class="img-circle img-responsive"></div>';
  194. $infoUser .= '<div class="progress">
  195. <div class="progress-bar progress-bar-danger" role="progressbar" style="width: ' . $thematicScore.';">
  196. '.$thematicScore.'
  197. </div>
  198. </div>';
  199. $thematicItemOne = '
  200. <div class="col-md-6 items-progress">
  201. <div class="thematic-cont '.$class1.'">
  202. <div class="topics">' . $subTitle1.'</div>
  203. <h4 class="title-topics">'.Display::returnFontAwesomeIcon('book').strip_tags($thematic_info['title']).'</h4>
  204. <p class="date">' . Display::returnFontAwesomeIcon('calendar-o').$thematic_advance_info['start_date'].'</p>
  205. <div class="views">' . Display::returnFontAwesomeIcon('file-text-o').strip_tags($thematic_advance_info['content']).'</div>
  206. <p class="time">'. Display::returnFontAwesomeIcon('clock-o').get_lang('DurationInHours').' : '.$thematic_advance_info['duration'].' - <a href="'.$thematicUrl.'">'.get_lang('SeeDetail').'</a></p>
  207. </div>
  208. </div>';
  209. if (!empty($thematic_advance_info2)) {
  210. $thematic_info2 = $thematic->get_thematic_list($thematic_advance_info2['thematic_id']);
  211. $thematic_advance_info2['start_date'] = api_get_local_time($thematic_advance_info2['start_date']);
  212. $thematic_advance_info2['start_date'] = api_format_date($thematic_advance_info2['start_date'], DATE_TIME_FORMAT_LONG);
  213. $thematicItemTwo = '
  214. <div class="col-md-6 items-progress">
  215. <div class="thematic-cont">
  216. <div class="topics">'.$subTitle2.'</div>
  217. <h4 class="title-topics">'. Display::returnFontAwesomeIcon('book').$thematic_info2['title'].'</h4>
  218. <p class="date">' . Display::returnFontAwesomeIcon('calendar-o').$thematic_advance_info2['start_date'].'</p>
  219. <div class="views">' . Display::returnFontAwesomeIcon('file-text-o').strip_tags($thematic_advance_info2['content']).'</div>
  220. <p class="time">'. Display::returnFontAwesomeIcon('clock-o').get_lang('DurationInHours').' : '.$thematic_advance_info2['duration'].' - <a href="'.$thematicUrl.'">'.get_lang('SeeDetail').'</a></p>
  221. </div>
  222. </div>';
  223. }
  224. $thematicPanel = '<div class="row">';
  225. $thematicPanel .= '<div class="col-md-2">'.$infoUser.'</div>';
  226. $thematicPanel .= '<div class="col-md-10"><div class="row">'.$thematicItemOne.$thematicItemTwo.'</div></div>';
  227. $thematicPanel .= '</div>';
  228. $thematicPanel .= '<div class="separate">
  229. <a href="' . $thematicUrl.'" class="btn btn-default btn-block">'.get_lang('ShowFullCourseAdvance').'</a>
  230. </div>';
  231. $thematicProgress = Display::panelCollapse($titleThematic, $thematicPanel, 'thematic', null, 'accordion-thematic', 'collapse-thematic', false);
  232. }
  233. }
  234. $introduction_section .= '<div class="row">';
  235. if (!empty($thematic_advance_info)) {
  236. $introduction_section .= '<div class="col-md-12">';
  237. $introduction_section .= $thematic_description_html;
  238. $introduction_section .= $thematicProgress;
  239. $introduction_section .= '</div>';
  240. }
  241. $editIconButton = '';
  242. if (api_is_allowed_to_edit() && empty($session_id)) {
  243. $editIconButton = Display::url(
  244. '<em class="fa fa-wrench"></em> ',
  245. api_get_path(WEB_CODE_PATH).'course_info/tools.php?'.api_get_cidreq(),
  246. ['class' => 'btn btn-default', 'title' => get_lang('CustomizeIcons')]
  247. );
  248. }
  249. $toolbar = '';
  250. $textIntro = '';
  251. if ($intro_dispCommand) {
  252. if (empty($intro_content)) {
  253. // Displays "Add intro" commands
  254. $toolbar .= '<div class="toolbar-edit">';
  255. $toolbar .= '<div class="btn-group pull-right" role="group">';
  256. if (!empty($courseId)) {
  257. $textIntro = '<a class="btn btn-default" title="'.addslashes(get_lang('AddIntro')).'" href="'.api_get_self().'?'.api_get_cidreq().'&intro_cmdAdd=1">';
  258. $textIntro .= '<em class="fa fa-file-text"></em> ';
  259. $textIntro .= "</a>";
  260. $toolbar .= $textIntro.$editIconButton;
  261. } else {
  262. $toolbar .= '<a class="btn btn-default" href="'.api_get_self().'?intro_cmdAdd=1">'.get_lang('AddIntro').'</a>';
  263. $toolbar .= $editIconButton;
  264. }
  265. $toolbar .= '</div></div>';
  266. } else {
  267. // Displays "edit intro && delete intro" commands
  268. $toolbar .= '<div class="toolbar-edit">';
  269. $toolbar .= '<div class="btn-group pull-right" rol="group">';
  270. if (!empty($courseId)) {
  271. $toolbar .=
  272. '<a class="btn btn-default" href="'.api_get_self().'?'.api_get_cidreq().'&intro_cmdEdit=1" title="'.get_lang('Modify').'">
  273. <em class="fa fa-pencil"></em></a>';
  274. $toolbar .= $editIconButton;
  275. $toolbar .= "<a class=\"btn btn-default\" href=\"".api_get_self()."?".api_get_cidreq()."&intro_cmdDel=1\" onclick=\"javascript:
  276. if(!confirm('".addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES, $charset)).
  277. "')) return false;\"><em class=\"fa fa-trash-o\"></em></a>";
  278. } else {
  279. $toolbar .=
  280. '<a class="btn btn-default" href="'.api_get_self().'?intro_cmdEdit=1" title="'.get_lang('Modify').'">
  281. <em class="fa fa-pencil"></em>
  282. </a>"';
  283. $toolbar .= $editIconButton;
  284. $toolbar .= "<a class=\"btn btn-default\" href=\"".api_get_self()."?".api_get_cidreq()."&intro_cmdDel=1\" onclick=\"javascript:
  285. if(!confirm('".addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES, $charset)).
  286. "')) return false;\"><em class=\"fa fa-trash-o\"></em></a>";
  287. }
  288. $toolbar .= "</div></div>";
  289. // Fix for chrome XSS filter for videos in iframes - BT#7930
  290. $browser = api_get_navigator();
  291. if (strpos($introduction_section, '<iframe') !== false && $browser['name'] == 'Chrome') {
  292. header('X-XSS-Protection: 0');
  293. }
  294. }
  295. }
  296. $introduction_section .= '<div class="col-md-12">';
  297. if ($intro_dispDefault) {
  298. if (!empty($intro_content)) {
  299. $introduction_section .= '<div class="page-course">';
  300. $introduction_section .= $intro_content;
  301. $introduction_section .= '</div>';
  302. } else {
  303. if (api_is_allowed_to_edit()) {
  304. $introduction_section .= '<div class="help-course">';
  305. $introduction_section .= get_lang('AddCustomCourseIntro').' '.$textIntro;
  306. $introduction_section .= '</div>';
  307. }
  308. }
  309. }
  310. $introduction_section .= $toolbar;
  311. $introduction_section .= '</div>';
  312. $introduction_section .= '</div>';
  313. $browser = api_get_navigator();
  314. if (strpos($introduction_section, '<iframe') !== false && $browser['name'] == 'Chrome') {
  315. header("X-XSS-Protection: 0");
  316. }