introductionSection.inc.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  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. /* Constants and variables */
  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('introduction_text', 'post', api_get_self().'?'.api_get_cidreq());
  42. } else {
  43. $form = new FormValidator('introduction_text');
  44. }
  45. $renderer =& $form->defaultRenderer();
  46. $renderer->setCustomElementTemplate('<div style="width: 80%; margin: 0px auto; padding-bottom: 10px; ">{element}</div>');
  47. $toolbar_set = 'IntroductionTool';
  48. $width = '100%';
  49. $height = '300';
  50. $editor_config = array('ToolbarSet' => $toolbar_set, 'Width' => $width, 'Height' => $height);
  51. $form->addHtmlEditor('intro_content', null, null, false, $editor_config);
  52. $form->addElement('style_submit_button', 'intro_cmdUpdate', get_lang('SaveIntroText'), 'class="save"');
  53. /* INTRODUCTION MICRO MODULE - COMMANDS SECTION (IF ALLOWED) */
  54. $course_id = api_get_course_int_id();
  55. if ($intro_editAllowed) {
  56. /* Replace command */
  57. if ($intro_cmdUpdate) {
  58. if ($form->validate()) {
  59. $form_values = $form->exportValues();
  60. $intro_content = Security::remove_XSS(stripslashes(api_html_entity_decode($form_values['intro_content'])), COURSEMANAGERLOWSECURITY);
  61. if (!empty($intro_content)) {
  62. $sql = "REPLACE $TBL_INTRODUCTION
  63. SET
  64. c_id = $course_id, id='".Database::escape_string($moduleId)."',
  65. intro_text='".Database::escape_string($intro_content)."',
  66. session_id='".intval($session_id)."'
  67. ";
  68. Database::query($sql);
  69. $introduction_section .= Display::return_message(
  70. get_lang('IntroductionTextUpdated'),
  71. 'confirmation',
  72. false
  73. );
  74. } else {
  75. // got to the delete command
  76. $intro_cmdDel = true;
  77. }
  78. } else {
  79. $intro_cmdEdit = true;
  80. }
  81. }
  82. /* Delete Command */
  83. if ($intro_cmdDel) {
  84. $sql = "DELETE FROM $TBL_INTRODUCTION
  85. WHERE
  86. c_id = $course_id AND
  87. id='".Database::escape_string($moduleId)."' AND
  88. session_id='".intval($session_id)."'";
  89. Database::query($sql);
  90. $introduction_section .= Display::return_message(get_lang('IntroductionTextDeleted'), 'confirmation');
  91. }
  92. }
  93. /* INTRODUCTION MICRO MODULE - DISPLAY SECTION */
  94. /* Retrieves the module introduction text, if exist */
  95. /* @todo use a lib to query the $TBL_INTRODUCTION table */
  96. // Getting course intro
  97. $intro_content = null;
  98. $sql = "SELECT intro_text FROM $TBL_INTRODUCTION
  99. WHERE c_id = $course_id AND id='".Database::escape_string($moduleId)."' AND session_id = 0";
  100. $intro_dbQuery = Database::query($sql);
  101. if (Database::num_rows($intro_dbQuery) > 0) {
  102. $intro_dbResult = Database::fetch_array($intro_dbQuery);
  103. $intro_content = $intro_dbResult['intro_text'];
  104. }
  105. // Getting session intro
  106. if (!empty($session_id)) {
  107. $sql = "SELECT intro_text FROM $TBL_INTRODUCTION
  108. WHERE c_id = $course_id AND id='".Database::escape_string($moduleId)."' AND session_id = '".intval($session_id)."'";
  109. $intro_dbQuery = Database::query($sql);
  110. $introSessionContent = null;
  111. if (Database::num_rows($intro_dbQuery) > 0) {
  112. $intro_dbResult = Database::fetch_array($intro_dbQuery);
  113. $introSessionContent = $intro_dbResult['intro_text'];
  114. }
  115. // If the course session intro exists replace it.
  116. if (!empty($introSessionContent)) {
  117. $intro_content = $introSessionContent;
  118. }
  119. }
  120. /* Determines the correct display */
  121. if ($intro_cmdEdit || $intro_cmdAdd) {
  122. $intro_dispDefault = false;
  123. $intro_dispForm = true;
  124. $intro_dispCommand = false;
  125. } else {
  126. $intro_dispDefault = true;
  127. $intro_dispForm = false;
  128. if ($intro_editAllowed) {
  129. $intro_dispCommand = true;
  130. } else {
  131. $intro_dispCommand = false;
  132. }
  133. }
  134. /* Executes the display */
  135. // display thematic advance inside a postit
  136. if ($intro_dispForm) {
  137. $default['intro_content'] = $intro_content;
  138. $form->setDefaults($default);
  139. $introduction_section .= '<div id="courseintro" style="width: 98%">';
  140. $introduction_section .= $form->return_form();
  141. $introduction_section .= '</div>';
  142. }
  143. $thematic_description_html = '';
  144. if ($tool == TOOL_COURSE_HOMEPAGE && !isset($_GET['intro_cmdEdit'])) {
  145. // Only show this if we're on the course homepage and we're not currently editing
  146. $thematic = new Thematic();
  147. $displayMode = api_get_course_setting('display_info_advance_inside_homecourse');
  148. $class1 = '';
  149. if ($displayMode == '1') {
  150. // Show only the current course progress step
  151. // $information_title = get_lang('InfoAboutLastDoneAdvance');
  152. $last_done_advance = $thematic->get_last_done_thematic_advance();
  153. $thematic_advance_info = $thematic->get_thematic_advance_list($last_done_advance);
  154. $subTitle1 = get_lang('CurrentTopic');
  155. $class1 = ' current';
  156. } else if($displayMode == '2') {
  157. // Show only the two next course progress steps
  158. // $information_title = get_lang('InfoAboutNextAdvanceNotDone');
  159. $last_done_advance = $thematic->get_next_thematic_advance_not_done();
  160. $next_advance_not_done = $thematic->get_next_thematic_advance_not_done(2);
  161. $thematic_advance_info = $thematic->get_thematic_advance_list($last_done_advance);
  162. $thematic_advance_info2 = $thematic->get_thematic_advance_list($next_advance_not_done);
  163. $subTitle1 = $subTitle2 = get_lang('NextTopic');
  164. } else if($displayMode == '3') {
  165. // Show the current and next course progress steps
  166. // $information_title = get_lang('InfoAboutLastDoneAdvanceAndNextAdvanceNotDone');
  167. $last_done_advance = $thematic->get_last_done_thematic_advance();
  168. $next_advance_not_done = $thematic->get_next_thematic_advance_not_done();
  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 = get_lang('CurrentTopic');
  172. $subTitle2 = get_lang('NextTopic');
  173. $class1 = ' current';
  174. }
  175. if (!empty($thematic_advance_info)) {
  176. /*$thematic_advance = get_lang('CourseThematicAdvance').'&nbsp;'.
  177. $thematic->get_total_average_of_thematic_advances().'%';*/
  178. $thematic_advance = get_lang('CourseThematicAdvance');
  179. $thematicScore = $thematic->get_total_average_of_thematic_advances() . '%';
  180. $thematicUrl = api_get_path(WEB_CODE_PATH) .
  181. 'course_progress/index.php?action=thematic_details&'.api_get_cidreq();
  182. $thematic_info = $thematic->get_thematic_list(
  183. $thematic_advance_info['thematic_id']
  184. );
  185. $thematic_advance_info['start_date'] = api_get_local_time(
  186. $thematic_advance_info['start_date']
  187. );
  188. $thematic_advance_info['start_date'] = api_format_date(
  189. $thematic_advance_info['start_date'],
  190. DATE_TIME_FORMAT_LONG
  191. );
  192. $userInfo = $_SESSION['_user'];
  193. $courseInfo = api_get_course_info();
  194. //die('<pre>'.print_r($courseInfo,1).'</pre>');
  195. $thematic_description_html =
  196. '<div class="thematic-postit">
  197. <div class="row"><div class="col-md-12">
  198. <div class="accordion" id="progress-bar-course">
  199. <div class="accordion-group">
  200. <div class="accordion-heading">
  201. <div class="title-accordion">
  202. <div class="row score-thematic">
  203. <div class="col-md-12">';
  204. $thematic_description_html .= '<div class="col-md-3 name-student">
  205. <h2>' . $userInfo['firstName'] . '</h2>
  206. <h3>' . $userInfo['lastName'] . '</h3>
  207. </div>
  208. <div class="col-md-3 score">
  209. <h1>' . $thematicScore . '</h1>
  210. </div>
  211. <div class="col-md-3">
  212. <h3>' . $thematic_advance . '</h3>
  213. <p>' . $courseInfo['name'] . '</p>
  214. </div>
  215. ';
  216. $thematic_description_html .= '<div class="col-md-3">
  217. <a id="thematic-show" class="btn btn-small btn-primary accordion-toggle btn-hide-thematic" href="#pross" data-toggle="collapse" data-parent="#progress-bar-course">
  218. ' . get_lang('SeeDetail') . '
  219. </a>
  220. <a id="thematic-hide" class="btn btn-small accordion-toggle btn-show-thematic" href="#pross" data-toggle="collapse" data-parent="#progress-bar-course" style="display:none;">
  221. ' . get_lang('Hide') . '
  222. </a>
  223. </div>
  224. </div>
  225. </div>
  226. </div>
  227. </div>';
  228. $thematic_description_html .=
  229. '<div class="accordion-body collapse in" id="pross" style="height: auto !important;">
  230. <div class="accordion-inner">
  231. <div class="row">
  232. <div class="col-md-12">
  233. <div class="row">
  234. <div class="col-md-4">
  235. <div class="thumbnail">
  236. <img src="' . $userInfo['avatar'] . '" class="img-polaroid">
  237. </div>
  238. </div>
  239. <div class="col-md-8">
  240. <div class="info-progress">
  241. <div class="tittle-score">' . $thematic_advance . '&nbsp;' . $thematicScore .'
  242. </div>
  243. <div class="progress progress-striped">
  244. <div class="bar" style="width: ' . $thematicScore . ';"></div>
  245. </div>
  246. <a href="' . $thematicUrl . '" class="btn btn-info">' . get_lang('ShowFullCourseAdvance') . '</a>
  247. </div>
  248. </div>
  249. </div>
  250. </div>';
  251. $thematic_description_html .=
  252. '<div class="col-md-8">
  253. <div class="row">';
  254. $thematic_description_html .=
  255. '<div class="col-md-6 items-progress'.$class1.'">
  256. <div class="topics">' . $subTitle1 . '</div>
  257. <p class="title_topics">' . $thematic_info['title'] . '</p>
  258. <p class="date">' . $thematic_advance_info['start_date'] . '</p>
  259. <h3 class="title">' . $thematic_advance_info['content'] . '</h3>
  260. <p class="time">' . get_lang('DurationInHours') . ' : ' . $thematic_advance_info['duration'] . ' - <a href="' . $thematicUrl . '">' . get_lang('SeeDetail') . '</a></p>
  261. </div>';
  262. if (!empty($thematic_advance_info2)) {
  263. $thematic_info2 = $thematic->get_thematic_list($thematic_advance_info2['thematic_id']);
  264. $thematic_advance_info2['start_date'] = api_get_local_time($thematic_advance_info2['start_date']);
  265. $thematic_advance_info2['start_date'] = api_format_date($thematic_advance_info2['start_date'], DATE_TIME_FORMAT_LONG);
  266. $thematic_description_html .=
  267. '<div class="col-md-6 items-progress">
  268. <div class="topics">'.$subTitle2.'</div>
  269. <p class="title_topics">'.$thematic_info2['title'].'</p>
  270. <p class="date">'.$thematic_advance_info2['start_date'].'</p>
  271. <h3 class="title">'.$thematic_advance_info2['content'].'</h3>
  272. <p class="time">'.get_lang('DurationInHours').' : '.$thematic_advance_info2['duration'].' - <a href="'.$thematicUrl.'">'.get_lang('SeeDetail').'</a></p>
  273. </div>';
  274. }
  275. $thematic_description_html.=
  276. '</div>
  277. </div>
  278. </div>
  279. </div>
  280. </div>
  281. </div>
  282. </div>
  283. </div>
  284. </div>
  285. </div>';
  286. }
  287. }
  288. $introduction_section .= '<div class="row"><div class="col-md-12">';
  289. $introduction_section .= $thematic_description_html;
  290. $introduction_section .= '</div>';
  291. $introduction_section .= '<div class="home-course-intro col-md-12"><div class="page-course">';
  292. if ($intro_dispDefault) {
  293. if (!empty($intro_content)) {
  294. $introduction_section.='<div class="page-course-intro">';
  295. $introduction_section .= $intro_content;
  296. $introduction_section.='</div>';
  297. }
  298. }
  299. $introduction_section .= '</div></div>';
  300. if ($intro_dispCommand) {
  301. if (empty($intro_content)) {
  302. // Displays "Add intro" commands
  303. $introduction_section .= '<div id="courseintro_empty">';
  304. if (!empty ($GLOBALS['_cid'])) {
  305. $introduction_section .= "<a href=\"".api_get_self()."?".api_get_cidreq()."&amp;intro_cmdAdd=1\">";
  306. $introduction_section .= Display::return_icon('introduction_add.gif', get_lang('AddIntro')).' ';
  307. $introduction_section .= "</a>";
  308. } else {
  309. $introduction_section .= "<a href=\"".api_get_self()."?intro_cmdAdd=1\">\n".get_lang('AddIntro')."</a>";
  310. }
  311. $introduction_section .= "</div>";
  312. } else {
  313. // Displays "edit intro && delete intro" commands
  314. $introduction_section .= '<div id="courseintro_empty">';
  315. if (!empty ($GLOBALS['_cid'])) {
  316. $introduction_section .=
  317. "<a href=\"".api_get_self()."?".api_get_cidreq()."&amp;intro_cmdEdit=1\">".
  318. Display::return_icon('edit.png', get_lang('Modify'), '', ICON_SIZE_SMALL).
  319. "</a>";
  320. $introduction_section .=
  321. "<a href=\"".api_get_self()."?".api_get_cidreq()."&amp;intro_cmdDel=1\" onclick=\"javascript:
  322. if(!confirm('".addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES, $charset)).
  323. "')) return false;\">".
  324. Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL).
  325. "</a>";
  326. } else {
  327. $introduction_section .=
  328. "<a href=\"".api_get_self()."?intro_cmdEdit=1\">".
  329. Display::return_icon('edit.png', get_lang('Modify'), '', ICON_SIZE_SMALL).
  330. "</a>";
  331. $introduction_section .=
  332. "<a href=\"".api_get_self()."?intro_cmdDel=1\" onclick=\"javascript:
  333. if(!confirm('".addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES, $charset)).
  334. "')) return false;\">".
  335. Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL).
  336. "</a>";
  337. }
  338. $introduction_section .= "</div>";
  339. // Fix for chrome XSS filter for videos in iframes - BT#7930
  340. $browser = api_get_navigator();
  341. if (strpos($introduction_section, '<iframe') !== false && $browser['name'] == 'Chrome') {
  342. header('X-XSS-Protection: 0');
  343. }
  344. }
  345. }
  346. $introduction_section .= '</div>';
  347. $browser = api_get_navigator();
  348. if (strpos($introduction_section, '<iframe') !== false && $browser['name'] == 'Chrome') {
  349. header("X-XSS-Protection: 0");
  350. }