introductionSection.inc.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  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. $intro_editAllowed = $is_allowed_to_edit = api_is_allowed_to_edit();
  32. $session_id = api_get_session_id();
  33. $blogParam = isset($_GET['blog_id']) ? ('&blog_id='.(int) $_GET['blog_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().$blogParam
  46. );
  47. } else {
  48. $form = new FormValidator('introduction_text');
  49. }
  50. $config = [
  51. 'ToolbarSet' => 'Basic',
  52. 'Width' => '100%',
  53. 'Height' => '300'
  54. ];
  55. $form->addHtmlEditor('intro_content', null, false, false, $config, ['card-full'=>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. // Ignore editor.css
  120. $cssEditor = api_get_path(WEB_CSS_PATH).'editor.css';
  121. $linkToReplace = [
  122. '<link href="'.$cssEditor.'" rel="stylesheet" type="text/css" />',
  123. '<link href="'.$cssEditor.'" media="screen" rel="stylesheet" type="text/css" />',
  124. ];
  125. $intro_content = str_replace($linkToReplace, '', $intro_content);
  126. $intro_content = Security::remove_XSS($intro_content, $userStatus);
  127. /* Determines the correct display */
  128. if ($intro_cmdEdit || $intro_cmdAdd) {
  129. $intro_dispDefault = false;
  130. $intro_dispForm = true;
  131. $intro_dispCommand = false;
  132. } else {
  133. $intro_dispDefault = true;
  134. $intro_dispForm = false;
  135. if ($intro_editAllowed) {
  136. $intro_dispCommand = true;
  137. } else {
  138. $intro_dispCommand = false;
  139. }
  140. }
  141. /* Executes the display */
  142. // display thematic advance inside a postit
  143. if ($intro_dispForm) {
  144. $default['intro_content'] = $intro_content;
  145. $form->setDefaults($default);
  146. $introduction_section .= $form->returnForm();
  147. }
  148. $thematic_description_html = '';
  149. $thematicItemTwo = '';
  150. if ($tool == TOOL_COURSE_HOMEPAGE && !isset($_GET['intro_cmdEdit'])) {
  151. // Only show this if we're on the course homepage and we're not currently editing
  152. $thematic = new Thematic();
  153. $displayMode = api_get_course_setting('display_info_advance_inside_homecourse');
  154. $class1 = '';
  155. if ($displayMode == '1') {
  156. // Show only the current course progress step
  157. // $information_title = get_lang('InfoAboutLastDoneAdvance');
  158. $last_done_advance = $thematic->get_last_done_thematic_advance();
  159. $thematic_advance_info = $thematic->get_thematic_advance_list($last_done_advance);
  160. $subTitle1 = get_lang('CurrentTopic');
  161. $class1 = ' current';
  162. } elseif ($displayMode == '2') {
  163. // Show only the two next course progress steps
  164. // $information_title = get_lang('InfoAboutNextAdvanceNotDone');
  165. $last_done_advance = $thematic->get_next_thematic_advance_not_done();
  166. $next_advance_not_done = $thematic->get_next_thematic_advance_not_done(2);
  167. $thematic_advance_info = $thematic->get_thematic_advance_list($last_done_advance);
  168. $thematic_advance_info2 = $thematic->get_thematic_advance_list($next_advance_not_done);
  169. $subTitle1 = $subTitle2 = get_lang('NextTopic');
  170. } elseif ($displayMode == '3') {
  171. // Show the current and next course progress steps
  172. // $information_title = get_lang('InfoAboutLastDoneAdvanceAndNextAdvanceNotDone');
  173. $last_done_advance = $thematic->get_last_done_thematic_advance();
  174. $next_advance_not_done = $thematic->get_next_thematic_advance_not_done();
  175. $thematic_advance_info = $thematic->get_thematic_advance_list($last_done_advance);
  176. $thematic_advance_info2 = $thematic->get_thematic_advance_list($next_advance_not_done);
  177. $subTitle1 = get_lang('CurrentTopic');
  178. $subTitle2 = get_lang('NextTopic');
  179. $class1 = ' current';
  180. }
  181. if (!empty($thematic_advance_info)) {
  182. $thematic_advance = get_lang('CourseThematicAdvance');
  183. $thematicScore = $thematic->get_total_average_of_thematic_advances().'%';
  184. $thematicUrl = api_get_path(WEB_CODE_PATH).'course_progress/index.php?action=thematic_details&'.api_get_cidreq();
  185. $thematic_info = $thematic->get_thematic_list(
  186. $thematic_advance_info['thematic_id']
  187. );
  188. $thematic_advance_info['start_date'] = api_get_local_time(
  189. $thematic_advance_info['start_date']
  190. );
  191. $thematic_advance_info['start_date'] = api_format_date(
  192. $thematic_advance_info['start_date'],
  193. DATE_TIME_FORMAT_LONG
  194. );
  195. $userInfo = api_get_user_info();
  196. $courseInfo = api_get_course_info();
  197. $titleThematic = $thematic_advance.' : '.$courseInfo['name'].' <b>( '.$thematicScore.' )</b>';
  198. $infoUser = '<div class="thematic-avatar"><img src="'.$userInfo['avatar'].'" class="img-circle img-responsive"></div>';
  199. $infoUser .= '<div class="progress">
  200. <div class="progress-bar progress-bar-primary" role="progressbar" style="width: '.$thematicScore.';">
  201. '.$thematicScore.'
  202. </div>
  203. </div>';
  204. $thematicItemOne = '
  205. <div class="col-md-6 items-progress">
  206. <div class="thematic-cont '.$class1.'">
  207. <div class="topics">'.$subTitle1.'</div>
  208. <h4 class="title-topics">'.Display::returnFontAwesomeIcon('book').strip_tags($thematic_info['title']).'</h4>
  209. <p class="date">'.Display::returnFontAwesomeIcon('calendar-o').$thematic_advance_info['start_date'].'</p>
  210. <div class="views">'.Display::returnFontAwesomeIcon('file-text-o').strip_tags($thematic_advance_info['content']).'</div>
  211. <p class="time">'.Display::returnFontAwesomeIcon('clock-o').get_lang('DurationInHours').' : '.$thematic_advance_info['duration'].' - <a href="'.$thematicUrl.'">'.get_lang('SeeDetail').'</a></p>
  212. </div>
  213. </div>';
  214. if (!empty($thematic_advance_info2)) {
  215. $thematic_info2 = $thematic->get_thematic_list($thematic_advance_info2['thematic_id']);
  216. $thematic_advance_info2['start_date'] = api_get_local_time($thematic_advance_info2['start_date']);
  217. $thematic_advance_info2['start_date'] = api_format_date($thematic_advance_info2['start_date'], DATE_TIME_FORMAT_LONG);
  218. $thematicItemTwo = '
  219. <div class="col-md-6 items-progress">
  220. <div class="thematic-cont">
  221. <div class="topics">'.$subTitle2.'</div>
  222. <h4 class="title-topics">'.Display::returnFontAwesomeIcon('book').$thematic_info2['title'].'</h4>
  223. <p class="date">'.Display::returnFontAwesomeIcon('calendar-o').$thematic_advance_info2['start_date'].'</p>
  224. <div class="views">'.Display::returnFontAwesomeIcon('file-text-o').strip_tags($thematic_advance_info2['content']).'</div>
  225. <p class="time">'.Display::returnFontAwesomeIcon('clock-o').get_lang('DurationInHours').' : '.$thematic_advance_info2['duration'].' - <a href="'.$thematicUrl.'">'.get_lang('SeeDetail').'</a></p>
  226. </div>
  227. </div>';
  228. }
  229. $thematicPanel = '<div class="row">';
  230. $thematicPanel .= '<div class="col-md-2">'.$infoUser.'</div>';
  231. $thematicPanel .= '<div class="col-md-10"><div class="row">'.$thematicItemOne.$thematicItemTwo.'</div></div>';
  232. $thematicPanel .= '</div>';
  233. $thematicPanel .= '<div class="separate">
  234. <a href="'.$thematicUrl.'" class="btn btn-default btn-block">'.get_lang('ShowFullCourseAdvance').'</a>
  235. </div>';
  236. $thematicProgress = Display::panelCollapse(
  237. $titleThematic,
  238. $thematicPanel,
  239. 'thematic',
  240. null,
  241. 'accordion-thematic',
  242. 'collapse-thematic',
  243. false
  244. );
  245. }
  246. }
  247. $introduction_section .= '<div class="row">';
  248. if (!empty($thematic_advance_info)) {
  249. $introduction_section .= '<div class="col-md-12">';
  250. $introduction_section .= $thematic_description_html;
  251. $introduction_section .= $thematicProgress;
  252. $introduction_section .= '</div>';
  253. }
  254. $toolbar = [];
  255. if (api_is_allowed_to_edit() && empty($session_id)) {
  256. $tool = [
  257. 'name' => get_lang('CustomizeIcons'),
  258. 'url' => api_get_path(WEB_CODE_PATH).'course_info/tools.php?'.api_get_cidreq(),
  259. 'icon' => 'fas fa-cog',
  260. ];
  261. $toolbar[] = $tool;
  262. }
  263. if ($intro_dispCommand) {
  264. if (empty($intro_content)) {
  265. // Displays "Add intro" commands
  266. if (!empty($courseId)) {
  267. $tool = [
  268. 'name' => addslashes(get_lang('AddIntro')),
  269. 'url' => api_get_self().'?'.api_get_cidreq().$blogParam.'&intro_cmdAdd=1',
  270. 'icon' => 'fas fa-pencil-alt',
  271. ];
  272. $toolbar[] = $tool;
  273. } else {
  274. $tool = [
  275. 'name' => get_lang('AddIntro'),
  276. 'url' => api_get_self().'?intro_cmdAdd=1',
  277. 'icon' => 'fas fa-pencil-alt',
  278. ];
  279. $toolbar[] = $tool;
  280. }
  281. } else {
  282. // Displays "edit intro && delete intro" commands
  283. if (!empty($courseId)) {
  284. $tool = [
  285. 'name' => get_lang('Modify'),
  286. 'url' => api_get_self().'?'.api_get_cidreq().$blogParam.'&intro_cmdEdit=1',
  287. 'icon' => 'fas fa-pencil-alt',
  288. ];
  289. $toolbar[] = $tool;
  290. $tool = [
  291. 'name' => get_lang('ConfirmYourChoice'),
  292. 'url' => api_get_self()."?".api_get_cidreq().$blogParam."&intro_cmdDel=1",
  293. 'onclick' => "javascript:if(!confirm('".addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES, $charset)).
  294. "')) return false",
  295. 'icon' => 'fas fa-trash-alt',
  296. ];
  297. $toolbar[] = $tool;
  298. } else {
  299. $tool = [
  300. 'name' => get_lang('Modify'),
  301. 'url' => api_get_self().'?intro_cmdEdit=1',
  302. 'icon' => 'fas fa-pencil-alt',
  303. ];
  304. $toolbar[] = $tool;
  305. $tool = [
  306. 'name' => get_lang('ConfirmYourChoice'),
  307. 'url' => api_get_self()."?".api_get_cidreq()."&intro_cmdDel=1",
  308. 'onclick' => "javascript:if(!confirm('".addslashes(api_htmlentities(get_ilang('ConfirmYourChoice'), ENT_QUOTES, $charset)).
  309. "')) return false",
  310. 'icon' => 'fas fa-trash-alt',
  311. ];
  312. $toolbar[] = $tool;
  313. }
  314. // Fix for chrome XSS filter for videos in iframes - BT#7930
  315. $browser = api_get_navigator();
  316. if (strpos($introduction_section, '<iframe') !== false && $browser['name'] == 'Chrome') {
  317. header('X-XSS-Protection: 0');
  318. }
  319. }
  320. }
  321. $nameSection = get_lang('AddCustomCourseIntro');
  322. if ($moduleId != 'course_homepage') {
  323. $nameSection = get_lang('AddCustomToolsIntro');
  324. }
  325. $textContent = [];
  326. if ($intro_dispDefault) {
  327. if (!empty($intro_content)) {
  328. $textContent = [
  329. 'name' => 'introduction-course',
  330. 'help' => $nameSection,
  331. 'text' => $intro_content,
  332. ];
  333. } else {
  334. if (api_is_allowed_to_edit()) {
  335. $textContent = [
  336. 'name' => 'introduction-section',
  337. 'help' => $nameSection,
  338. 'text' => $intro_content,
  339. ];
  340. }
  341. }
  342. }
  343. //$introduction_section .= $toolbar;
  344. $introduction_section .= '</div>';
  345. $browser = api_get_navigator();
  346. if (strpos($introduction_section, '<iframe') !== false && $browser['name'] == 'Chrome') {
  347. header("X-XSS-Protection: 0");
  348. }
  349. $data = null;
  350. $tpl = new Template(null);
  351. $tpl->assign('intro', $textContent);
  352. $tpl->assign('toolbar', $toolbar);
  353. $introduction_section .= $tpl->fetch($tpl->get_template('auth/introduction_section.html.twig'));