introductionSection.inc.php 16 KB

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