introductionSection.inc.php 16 KB

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