introductionSection.inc.php 16 KB

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