introductionSection.inc.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  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->setElementTemplate('<div style="width: 80%; margin: 0px auto; padding-bottom: 10px; ">{element}</div>');
  47. $toolbar_set = 'Introduction';
  48. $width = '100%';
  49. $height = '300';
  50. // The global variable $fck_attribute has been deprecated. It stays here for supporting old external code.
  51. global $fck_attribute;
  52. if (is_array($fck_attribute)) {
  53. if (isset($fck_attribute['ToolbarSet'])) {
  54. $toolbar_set = $fck_attribute['ToolbarSet'];
  55. }
  56. if (isset($fck_attribute['Width'])) {
  57. $toolbar_set = $fck_attribute['Width'];
  58. }
  59. if (isset($fck_attribute['Height'])) {
  60. $toolbar_set = $fck_attribute['Height'];
  61. }
  62. }
  63. if (is_array($editor_config)) {
  64. if (!isset($editor_config['ToolbarSet'])) {
  65. $editor_config['ToolbarSet'] = $toolbar_set;
  66. }
  67. if (!isset($editor_config['Width'])) {
  68. $editor_config['Width'] = $width;
  69. }
  70. if (!isset($editor_config['Height'])) {
  71. $editor_config['Height'] = $height;
  72. }
  73. } else {
  74. $editor_config = array('ToolbarSet' => $toolbar_set, 'Width' => $width, 'Height' => $height);
  75. }
  76. $form->add_html_editor('intro_content', null, null, false, $editor_config);
  77. $form->addElement('style_submit_button', 'intro_cmdUpdate', get_lang('SaveIntroText'), 'class="save"');
  78. /* INTRODUCTION MICRO MODULE - COMMANDS SECTION (IF ALLOWED) */
  79. $course_id = api_get_course_int_id();
  80. if ($intro_editAllowed) {
  81. /* Replace command */
  82. if ($intro_cmdUpdate) {
  83. if ($form->validate()) {
  84. $form_values = $form->exportValues();
  85. $intro_content = Security::remove_XSS(stripslashes(api_html_entity_decode($form_values['intro_content'])), COURSEMANAGERLOWSECURITY);
  86. if (!empty($intro_content)) {
  87. $sql = "REPLACE $TBL_INTRODUCTION
  88. SET
  89. c_id = $course_id, id='".Database::escape_string($moduleId)."',
  90. intro_text='".Database::escape_string($intro_content)."',
  91. session_id='".intval($session_id)."'
  92. ";
  93. Database::query($sql);
  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 c_id = $course_id AND id='".Database::escape_string($moduleId)."' AND session_id = 0";
  125. $intro_dbQuery = Database::query($sql);
  126. if (Database::num_rows($intro_dbQuery) > 0) {
  127. $intro_dbResult = Database::fetch_array($intro_dbQuery);
  128. $intro_content = $intro_dbResult['intro_text'];
  129. }
  130. // Getting session intro
  131. if (!empty($session_id)) {
  132. $sql = "SELECT intro_text FROM $TBL_INTRODUCTION
  133. WHERE c_id = $course_id AND id='".Database::escape_string($moduleId)."' AND session_id = '".intval($session_id)."'";
  134. $intro_dbQuery = Database::query($sql);
  135. $introSessionContent = null;
  136. if (Database::num_rows($intro_dbQuery) > 0) {
  137. $intro_dbResult = Database::fetch_array($intro_dbQuery);
  138. $introSessionContent = $intro_dbResult['intro_text'];
  139. }
  140. // If the course session intro exists replace it.
  141. if (!empty($introSessionContent)) {
  142. $intro_content = $introSessionContent;
  143. }
  144. }
  145. /* Determines the correct display */
  146. if ($intro_cmdEdit || $intro_cmdAdd) {
  147. $intro_dispDefault = false;
  148. $intro_dispForm = true;
  149. $intro_dispCommand = false;
  150. } else {
  151. $intro_dispDefault = true;
  152. $intro_dispForm = false;
  153. if ($intro_editAllowed) {
  154. $intro_dispCommand = true;
  155. } else {
  156. $intro_dispCommand = false;
  157. }
  158. }
  159. /* Executes the display */
  160. // display thematic advance inside a postit
  161. if ($intro_dispForm) {
  162. $default['intro_content'] = $intro_content;
  163. $form->setDefaults($default);
  164. $introduction_section .= '<div id="courseintro" style="width: 98%">';
  165. $introduction_section .= $form->return_form();
  166. $introduction_section .= '</div>';
  167. }
  168. $thematic_description_html = '';
  169. if ($tool == TOOL_COURSE_HOMEPAGE && !isset($_GET['intro_cmdEdit'])) {
  170. // Only show this if we're on the course homepage and we're not currently editing
  171. $thematic = new Thematic();
  172. $displayMode = api_get_course_setting('display_info_advance_inside_homecourse');
  173. $class1 = '';
  174. if ($displayMode == '1') {
  175. // Show only the current course progress step
  176. // $information_title = get_lang('InfoAboutLastDoneAdvance');
  177. $last_done_advance = $thematic->get_last_done_thematic_advance();
  178. $thematic_advance_info = $thematic->get_thematic_advance_list($last_done_advance);
  179. $subTitle1 = get_lang('CurrentTopic');
  180. $class1 = ' current';
  181. } else if($displayMode == '2') {
  182. // Show only the two next course progress steps
  183. // $information_title = get_lang('InfoAboutNextAdvanceNotDone');
  184. $last_done_advance = $thematic->get_next_thematic_advance_not_done();
  185. $next_advance_not_done = $thematic->get_next_thematic_advance_not_done(2);
  186. $thematic_advance_info = $thematic->get_thematic_advance_list($last_done_advance);
  187. $thematic_advance_info2 = $thematic->get_thematic_advance_list($next_advance_not_done);
  188. $subTitle1 = $subTitle2 = get_lang('NextTopic');
  189. } else if($displayMode == '3') {
  190. // Show the current and next course progress steps
  191. // $information_title = get_lang('InfoAboutLastDoneAdvanceAndNextAdvanceNotDone');
  192. $last_done_advance = $thematic->get_last_done_thematic_advance();
  193. $next_advance_not_done = $thematic->get_next_thematic_advance_not_done();
  194. $thematic_advance_info = $thematic->get_thematic_advance_list($last_done_advance);
  195. $thematic_advance_info2 = $thematic->get_thematic_advance_list($next_advance_not_done);
  196. $subTitle1 = get_lang('CurrentTopic');
  197. $subTitle2 = get_lang('NextTopic');
  198. $class1 = ' current';
  199. }
  200. if (!empty($thematic_advance_info)) {
  201. /*$thematic_advance = get_lang('CourseThematicAdvance').'&nbsp;'.
  202. $thematic->get_total_average_of_thematic_advances().'%';*/
  203. $thematic_advance = get_lang('CourseThematicAdvance');
  204. $thematicScore = $thematic->get_total_average_of_thematic_advances() . '%';
  205. $thematicUrl = api_get_path(WEB_CODE_PATH) .
  206. '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 = $_SESSION['_user'];
  218. $courseInfo = api_get_course_info();
  219. //die('<pre>'.print_r($courseInfo,1).'</pre>');
  220. $thematic_description_html =
  221. '<div class="thematic-postit">
  222. <div class="row-fluid"><div class="span12">
  223. <div class="accordion" id="progress-bar-course">
  224. <div class="accordion-group">
  225. <div class="accordion-heading">
  226. <div class="title-accordion">
  227. <div class="row-fluid score-thematic">
  228. <div class="span8">';
  229. $thematic_description_html .=
  230. '<div class="span6 name-student">
  231. <h2>' . $userInfo['firstName'] . '</h2>
  232. <h3>' . $userInfo['lastName'] . '</h3>
  233. </div>
  234. <div class="span2 score">
  235. <h1>' . $thematicScore . '</h1>
  236. </div>
  237. <div class="span4">
  238. <h3>' . $thematic_advance . '</h3>
  239. <p>' . $courseInfo['name'] . '</p>
  240. </div>
  241. </div>';
  242. $thematic_description_html .=
  243. '<div class="span4">
  244. <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">
  245. ' . get_lang('SeeDetail') . '
  246. </a>
  247. <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;">
  248. ' . get_lang('Hide') . '
  249. </a>
  250. </div>
  251. </div>
  252. </div>
  253. </div>';
  254. $thematic_description_html .=
  255. '<div class="accordion-body collapse in" id="pross" style="height: auto !important;">
  256. <div class="accordion-inner">
  257. <div class="row-fluid">
  258. <div class="span4">
  259. <div class="row-fluid">
  260. <div class="span4">
  261. <div class="thumbnail">
  262. <img src="' . $userInfo['avatar'] . '" class="img-polaroid">
  263. </div>
  264. </div>
  265. <div class="span8">
  266. <div class="info-progress">
  267. <div class="tittle-score">' . $thematic_advance . '&nbsp;' . $thematicScore .'
  268. </div>
  269. <div class="progress progress-striped">
  270. <div class="bar" style="width: ' . $thematicScore . ';"></div>
  271. </div>
  272. <a href="' . $thematicUrl . '" class="btn btn-info">' . get_lang('ShowFullCourseAdvance') . '</a>
  273. </div>
  274. </div>
  275. </div>
  276. </div>';
  277. $thematic_description_html .=
  278. '<div class="span8">
  279. <div class="row-fluid">';
  280. $thematic_description_html .=
  281. '<div class="span6 items-progress'.$class1.'">
  282. <div class="topics">' . $subTitle1 . '</div>
  283. <p class="title_topics">' . $thematic_info['title'] . '</p>
  284. <p class="date">' . $thematic_advance_info['start_date'] . '</p>
  285. <h3 class="title">' . $thematic_advance_info['content'] . '</h3>
  286. <p class="time">' . get_lang('DurationInHours') . ' : ' . $thematic_advance_info['duration'] . ' - <a href="' . $thematicUrl . '">' . get_lang('SeeDetail') . '</a></p>
  287. </div>';
  288. if (!empty($thematic_advance_info2)) {
  289. $thematic_info2 = $thematic->get_thematic_list($thematic_advance_info2['thematic_id']);
  290. $thematic_advance_info2['start_date'] = api_get_local_time($thematic_advance_info2['start_date']);
  291. $thematic_advance_info2['start_date'] = api_format_date($thematic_advance_info2['start_date'], DATE_TIME_FORMAT_LONG);
  292. $thematic_description_html .=
  293. '<div class="span6 items-progress">
  294. <div class="topics">'.$subTitle2.'</div>
  295. <p class="title_topics">'.$thematic_info2['title'].'</p>
  296. <p class="date">'.$thematic_advance_info2['start_date'].'</p>
  297. <h3 class="title">'.$thematic_advance_info2['content'].'</h3>
  298. <p class="time">'.get_lang('DurationInHours').' : '.$thematic_advance_info2['duration'].' - <a href="'.$thematicUrl.'">'.get_lang('SeeDetail').'</a></p>
  299. </div>';
  300. }
  301. $thematic_description_html.=
  302. '</div>
  303. </div>
  304. </div>
  305. </div>
  306. </div>
  307. </div>
  308. </div>
  309. </div>
  310. </div>
  311. </div>';
  312. }
  313. }
  314. $introduction_section .= '<div class="row course-tools-intro"><div class="span12">';
  315. $introduction_section .= $thematic_description_html;
  316. $introduction_section .= '</div>';
  317. $introduction_section .= '<div class="home-course-intro span12"><div class="page-course">';
  318. if ($intro_dispDefault) {
  319. if (!empty($intro_content)) {
  320. $introduction_section.='<div class="page-course-intro">';
  321. $introduction_section .= $intro_content;
  322. $introduction_section.='</div>';
  323. }
  324. }
  325. $introduction_section .= '</div></div>';
  326. if ($intro_dispCommand) {
  327. if (empty($intro_content)) {
  328. // Displays "Add intro" commands
  329. $introduction_section .= '<div id="courseintro_empty">';
  330. if (!empty ($GLOBALS['_cid'])) {
  331. $introduction_section .= "<a href=\"".api_get_self()."?".api_get_cidreq()."&amp;intro_cmdAdd=1\">";
  332. $introduction_section .= Display::return_icon('introduction_add.gif', get_lang('AddIntro')).' ';
  333. $introduction_section .= "</a>";
  334. } else {
  335. $introduction_section .= "<a href=\"".api_get_self()."?intro_cmdAdd=1\">\n".get_lang('AddIntro')."</a>";
  336. }
  337. $introduction_section .= "</div>";
  338. } else {
  339. // Displays "edit intro && delete intro" commands
  340. $introduction_section .= '<div id="courseintro_empty">';
  341. if (!empty ($GLOBALS['_cid'])) {
  342. $introduction_section .=
  343. "<a href=\"".api_get_self()."?".api_get_cidreq()."&amp;intro_cmdEdit=1\">".
  344. Display::return_icon('edit.png', get_lang('Modify'), '', ICON_SIZE_SMALL).
  345. "</a>";
  346. $introduction_section .=
  347. "<a href=\"".api_get_self()."?".api_get_cidreq()."&amp;intro_cmdDel=1\" onclick=\"javascript:
  348. if(!confirm('".addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES, $charset)).
  349. "')) return false;\">".
  350. Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL).
  351. "</a>";
  352. } else {
  353. $introduction_section .=
  354. "<a href=\"".api_get_self()."?intro_cmdEdit=1\">".
  355. Display::return_icon('edit.png', get_lang('Modify'), '', ICON_SIZE_SMALL).
  356. "</a>";
  357. $introduction_section .=
  358. "<a href=\"".api_get_self()."?intro_cmdDel=1\" onclick=\"javascript:
  359. if(!confirm('".addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES, $charset)).
  360. "')) return false;\">".
  361. Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL).
  362. "</a>";
  363. }
  364. $introduction_section .= "</div>";
  365. // Fix for chrome XSS filter for videos in iframes - BT#7930
  366. $browser = api_get_navigator();
  367. if (strpos($introduction_section, '<iframe') !== false && $browser['name'] == 'Chrome') {
  368. header('X-XSS-Protection: 0');
  369. }
  370. }
  371. }
  372. $introduction_section .= '</div>';
  373. $browser = api_get_navigator();
  374. if (strpos($introduction_section, '<iframe') !== false && $browser['name'] == 'Chrome') {
  375. header("X-XSS-Protection: 0");
  376. }