introductionSection.inc.php 16 KB

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