introductionSection.inc.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  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' => 'IntroductionSection',
  52. 'Width' => '100%',
  53. 'Height' => '300',
  54. ];
  55. $form->addHtmlEditor('intro_content', null, false, false, $config);
  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 .= '<div id="courseintro" style="width: 98%">';
  147. $introduction_section .= $form->returnForm();
  148. $introduction_section .= '</div>';
  149. }
  150. $thematic_description_html = '';
  151. $thematicItemTwo = '';
  152. if ($tool == TOOL_COURSE_HOMEPAGE && !isset($_GET['intro_cmdEdit'])) {
  153. // Only show this if we're on the course homepage and we're not currently editing
  154. $thematic = new Thematic();
  155. $displayMode = api_get_course_setting('display_info_advance_inside_homecourse');
  156. $class1 = '';
  157. if ($displayMode == '1') {
  158. // Show only the current course progress step
  159. $last_done_advance = $thematic->get_last_done_thematic_advance();
  160. $thematic_advance_info = $thematic->get_thematic_advance_list($last_done_advance);
  161. $subTitle1 = get_lang('CurrentTopic');
  162. $class1 = ' current';
  163. } elseif ($displayMode == '2') {
  164. // Show only the two next course progress steps
  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. $last_done_advance = $thematic->get_last_done_thematic_advance();
  173. $next_advance_not_done = $thematic->get_next_thematic_advance_not_done();
  174. $thematic_advance_info = $thematic->get_thematic_advance_list($last_done_advance);
  175. $thematic_advance_info2 = $thematic->get_thematic_advance_list($next_advance_not_done);
  176. $subTitle1 = get_lang('CurrentTopic');
  177. $subTitle2 = get_lang('NextTopic');
  178. $class1 = ' current';
  179. }
  180. if (!empty($thematic_advance_info)) {
  181. $thematic_advance = get_lang('CourseThematicAdvance');
  182. $thematicScore = $thematic->get_total_average_of_thematic_advances().'%';
  183. $thematicUrl = api_get_path(WEB_CODE_PATH).'course_progress/index.php?action=thematic_details&'.api_get_cidreq();
  184. $thematic_info = $thematic->get_thematic_list($thematic_advance_info['thematic_id']);
  185. $thematic_advance_info['start_date'] = api_get_local_time(
  186. $thematic_advance_info['start_date']
  187. );
  188. $thematic_advance_info['start_date'] = api_format_date(
  189. $thematic_advance_info['start_date'],
  190. DATE_TIME_FORMAT_LONG
  191. );
  192. $userInfo = api_get_user_info();
  193. $courseInfo = api_get_course_info();
  194. $titleThematic = $thematic_advance.' : '.$courseInfo['name'].' <b>( '.$thematicScore.' )</b>';
  195. $infoUser = '<div class="thematic-avatar"><img src="'.$userInfo['avatar'].'" class="img-circle img-responsive"></div>';
  196. $infoUser .= '<div class="progress">
  197. <div class="progress-bar progress-bar-primary" role="progressbar" style="width: '.$thematicScore.';">
  198. '.$thematicScore.'
  199. </div>
  200. </div>';
  201. $thematicItemOne = '
  202. <div class="col-md-6 items-progress">
  203. <div class="thematic-cont '.$class1.'">
  204. <div class="topics">'.$subTitle1.'</div>
  205. <h4 class="title-topics">'.Display::returnFontAwesomeIcon('book').strip_tags($thematic_info['title']).'</h4>
  206. <p class="date">'.Display::returnFontAwesomeIcon('calendar-o').$thematic_advance_info['start_date'].'</p>
  207. <div class="views">'.Display::returnFontAwesomeIcon('file-text-o').strip_tags($thematic_advance_info['content']).'</div>
  208. <p class="time">'.Display::returnFontAwesomeIcon('clock-o').get_lang('DurationInHours').' : '.$thematic_advance_info['duration'].' - <a href="'.$thematicUrl.'">'.get_lang('SeeDetail').'</a></p>
  209. </div>
  210. </div>';
  211. if (!empty($thematic_advance_info2)) {
  212. $thematic_info2 = $thematic->get_thematic_list($thematic_advance_info2['thematic_id']);
  213. $thematic_advance_info2['start_date'] = api_get_local_time($thematic_advance_info2['start_date']);
  214. $thematic_advance_info2['start_date'] = api_format_date($thematic_advance_info2['start_date'], DATE_TIME_FORMAT_LONG);
  215. $thematicItemTwo = '
  216. <div class="col-md-6 items-progress">
  217. <div class="thematic-cont">
  218. <div class="topics">'.$subTitle2.'</div>
  219. <h4 class="title-topics">'.Display::returnFontAwesomeIcon('book').$thematic_info2['title'].'</h4>
  220. <p class="date">'.Display::returnFontAwesomeIcon('calendar-o').$thematic_advance_info2['start_date'].'</p>
  221. <div class="views">'.Display::returnFontAwesomeIcon('file-text-o').strip_tags($thematic_advance_info2['content']).'</div>
  222. <p class="time">'.Display::returnFontAwesomeIcon('clock-o').get_lang('DurationInHours').' : '.$thematic_advance_info2['duration'].' - <a href="'.$thematicUrl.'">'.get_lang('SeeDetail').'</a></p>
  223. </div>
  224. </div>';
  225. }
  226. $thematicPanel = '<div class="row">';
  227. $thematicPanel .= '<div class="col-md-2">'.$infoUser.'</div>';
  228. $thematicPanel .= '<div class="col-md-10"><div class="row">'.$thematicItemOne.$thematicItemTwo.'</div></div>';
  229. $thematicPanel .= '</div>';
  230. $thematicPanel .= '<div class="separate">
  231. <a href="'.$thematicUrl.'" class="btn btn-default btn-block">'.get_lang('ShowFullCourseAdvance').'</a>
  232. </div>';
  233. $thematicProgress = Display::panelCollapse(
  234. $titleThematic,
  235. $thematicPanel,
  236. 'thematic',
  237. null,
  238. 'accordion-thematic',
  239. 'collapse-thematic',
  240. false
  241. );
  242. }
  243. }
  244. $introduction_section .= '<div class="row">';
  245. if (!empty($thematic_advance_info)) {
  246. $introduction_section .= '<div class="col-md-12">';
  247. $introduction_section .= $thematic_description_html;
  248. $introduction_section .= $thematicProgress;
  249. $introduction_section .= '</div>';
  250. }
  251. $editIconButton = '';
  252. if (api_is_allowed_to_edit() && empty($session_id)) {
  253. $editIconButton = Display::url(
  254. '<em class="fa fa-wrench"></em> ',
  255. api_get_path(WEB_CODE_PATH).'course_info/tools.php?'.api_get_cidreq(),
  256. ['class' => 'btn btn-default', 'title' => get_lang('CustomizeIcons')]
  257. );
  258. }
  259. $toolbar = '';
  260. $textIntro = '';
  261. if ($intro_dispCommand) {
  262. if (empty($intro_content)) {
  263. // Displays "Add intro" commands
  264. $toolbar .= '<div class="toolbar-edit">';
  265. $toolbar .= '<div class="btn-group pull-right" role="group">';
  266. if (!empty($courseId)) {
  267. $textIntro = '<a class="btn btn-default" title="'.addslashes(get_lang('AddIntro')).'" href="'.api_get_self().'?'.api_get_cidreq().$blogParam.'&intro_cmdAdd=1">';
  268. $textIntro .= '<em class="fa fa-file-text"></em> ';
  269. $textIntro .= "</a>";
  270. $toolbar .= $textIntro.$editIconButton;
  271. } else {
  272. $toolbar .= '<a class="btn btn-default" href="'.api_get_self().'?intro_cmdAdd=1">'.get_lang('AddIntro').'</a>';
  273. $toolbar .= $editIconButton;
  274. }
  275. $toolbar .= '</div></div>';
  276. } else {
  277. // Displays "edit intro && delete intro" commands
  278. $toolbar .= '<div class="toolbar-edit">';
  279. $toolbar .= '<div class="btn-group pull-right" rol="group">';
  280. if (!empty($courseId)) {
  281. $toolbar .=
  282. '<a class="btn btn-default" href="'.api_get_self().'?'.api_get_cidreq().$blogParam.'&intro_cmdEdit=1" title="'.get_lang('Modify').'">
  283. <em class="fa fa-pencil"></em></a>';
  284. $toolbar .= $editIconButton;
  285. $toolbar .= "<a class=\"btn btn-default\" href=\"".api_get_self()."?".api_get_cidreq().$blogParam."&intro_cmdDel=1\" onclick=\"javascript:
  286. if(!confirm('".addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES, $charset)).
  287. "')) return false;\"><em class=\"fa fa-trash-o\"></em></a>";
  288. } else {
  289. $toolbar .=
  290. '<a class="btn btn-default" href="'.api_get_self().'?intro_cmdEdit=1" title="'.get_lang('Modify').'">
  291. <em class="fa fa-pencil"></em>
  292. </a>"';
  293. $toolbar .= $editIconButton;
  294. $toolbar .= "<a class=\"btn btn-default\" href=\"".api_get_self()."?".api_get_cidreq()."&intro_cmdDel=1\" onclick=\"javascript:
  295. if(!confirm('".addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES, $charset)).
  296. "')) return false;\"><em class=\"fa fa-trash-o\"></em></a>";
  297. }
  298. $toolbar .= "</div></div>";
  299. // Fix for chrome XSS filter for videos in iframes - BT#7930
  300. $browser = api_get_navigator();
  301. if (strpos($introduction_section, '<iframe') !== false && $browser['name'] == 'Chrome') {
  302. header('X-XSS-Protection: 0');
  303. }
  304. }
  305. }
  306. $nameSection = get_lang('AddCustomCourseIntro');
  307. if ($moduleId != 'course_homepage') {
  308. $nameSection = get_lang('AddCustomToolsIntro');
  309. }
  310. $introduction_section .= '<div class="col-md-12">';
  311. if ($intro_dispDefault) {
  312. if (!empty($intro_content)) {
  313. $introduction_section .= '<div class="page-course">';
  314. $introduction_section .= $intro_content;
  315. $introduction_section .= '</div>';
  316. } else {
  317. if (api_is_allowed_to_edit()) {
  318. $introduction_section .= '<div class="help-course">';
  319. $introduction_section .= $nameSection.' '.$textIntro;
  320. $introduction_section .= '</div>';
  321. }
  322. }
  323. }
  324. $introduction_section .= $toolbar;
  325. $introduction_section .= '</div>';
  326. $introduction_section .= '</div>';
  327. $browser = api_get_navigator();
  328. if (strpos($introduction_section, '<iframe') !== false && $browser['name'] == 'Chrome') {
  329. header("X-XSS-Protection: 0");
  330. }