introductionSection.inc.php 16 KB

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