introductionSection.inc.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  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. It can be inserted on any
  6. * Chamilo Module, provided a connection to a course Database is already active.
  7. *
  8. * The introduction content are stored on a table called "introduction"
  9. * in the course Database. Each module introduction has an Id stored on
  10. * the table. It is this id that can make correspondance to a specific module.
  11. *
  12. * 'introduction' table description
  13. * id : int
  14. * intro_text :text
  15. *
  16. *
  17. * usage :
  18. *
  19. * $moduleId = XX // specifying the module Id
  20. * include(moduleIntro.inc.php);
  21. *
  22. * @package chamilo.include
  23. */
  24. require_once api_get_path(LIBRARY_PATH).'thematic.lib.php';
  25. /* Constants and variables */
  26. $TBL_INTRODUCTION = Database::get_course_table(TABLE_TOOL_INTRO);
  27. $intro_editAllowed = $is_allowed_to_edit;
  28. $session_id = api_get_session_id();
  29. $introduction_section = '';
  30. global $charset;
  31. $intro_cmdEdit = empty($_GET['intro_cmdEdit']) ? '' : $_GET['intro_cmdEdit'];
  32. $intro_cmdUpdate = isset($_POST['intro_cmdUpdate']);
  33. $intro_cmdDel = empty($_GET['intro_cmdDel']) ? '' : $_GET['intro_cmdDel'];
  34. $intro_cmdAdd = empty($_GET['intro_cmdAdd']) ? '' : $_GET['intro_cmdAdd'];
  35. $courseId = api_get_course_id();
  36. if (!empty($courseId)) {
  37. $form = new FormValidator('introduction_text', 'post', api_get_self().'?'.api_get_cidreq());
  38. } else {
  39. $form = new FormValidator('introduction_text');
  40. }
  41. $renderer =& $form->defaultRenderer();
  42. $renderer->setElementTemplate('<div style="width: 80%; margin: 0px auto; padding-bottom: 10px; ">{element}</div>');
  43. $toolbar_set = 'Introduction';
  44. $width = '100%';
  45. $height = '300';
  46. // The global variable $fck_attribute has been deprecated. It stays here for supporting old external code.
  47. global $fck_attribute;
  48. if (is_array($fck_attribute)) {
  49. if (isset($fck_attribute['ToolbarSet'])) {
  50. $toolbar_set = $fck_attribute['ToolbarSet'];
  51. }
  52. if (isset($fck_attribute['Width'])) {
  53. $toolbar_set = $fck_attribute['Width'];
  54. }
  55. if (isset($fck_attribute['Height'])) {
  56. $toolbar_set = $fck_attribute['Height'];
  57. }
  58. }
  59. if (is_array($editor_config)) {
  60. if (!isset($editor_config['ToolbarSet'])) {
  61. $editor_config['ToolbarSet'] = $toolbar_set;
  62. }
  63. if (!isset($editor_config['Width'])) {
  64. $editor_config['Width'] = $width;
  65. }
  66. if (!isset($editor_config['Height'])) {
  67. $editor_config['Height'] = $height;
  68. }
  69. } else {
  70. $editor_config = array('ToolbarSet' => $toolbar_set, 'Width' => $width, 'Height' => $height);
  71. }
  72. $form->add_html_editor('intro_content', null, null, false, $editor_config);
  73. $form->addElement('style_submit_button', 'intro_cmdUpdate', get_lang('SaveIntroText'), 'class="save"');
  74. /* INTRODUCTION MICRO MODULE - COMMANDS SECTION (IF ALLOWED) */
  75. $course_id = api_get_course_int_id();
  76. if ($intro_editAllowed) {
  77. $moduleId = Database::escape_string($moduleId);
  78. /* Replace command */
  79. if ($intro_cmdUpdate) {
  80. if ($form->validate()) {
  81. $form_values = $form->exportValues();
  82. $intro_content = Security::remove_XSS(stripslashes(api_html_entity_decode($form_values['intro_content'])), COURSEMANAGERLOWSECURITY);
  83. if (!empty($intro_content)) {
  84. $sql = "REPLACE $TBL_INTRODUCTION SET c_id = $course_id, id='$moduleId',intro_text='".Database::escape_string($intro_content)."', session_id='".intval($session_id)."'";
  85. Database::query($sql);
  86. $introduction_section .= Display::return_message(get_lang('IntroductionTextUpdated'),'confirmation', false);
  87. } else {
  88. $intro_cmdDel = true; // got to the delete command
  89. }
  90. } else {
  91. $intro_cmdEdit = true;
  92. }
  93. }
  94. /* Delete Command */
  95. if ($intro_cmdDel) {
  96. Database::query("DELETE FROM $TBL_INTRODUCTION WHERE c_id = $course_id AND id='".$moduleId."' AND session_id='".intval($session_id)."'");
  97. $introduction_section .= Display::return_message(get_lang('IntroductionTextDeleted'), 'confirmation');
  98. }
  99. }
  100. /* INTRODUCTION MICRO MODULE - DISPLAY SECTION */
  101. /* Retrieves the module introduction text, if exist */
  102. /* @todo use a lib to query the $TBL_INTRODUCTION table */
  103. // Getting course intro
  104. $intro_content = null;
  105. $sql = "SELECT intro_text FROM $TBL_INTRODUCTION
  106. WHERE c_id = $course_id AND id='".Database::escape_string($moduleId)."' AND session_id = 0";
  107. $intro_dbQuery = Database::query($sql);
  108. if (Database::num_rows($intro_dbQuery) > 0) {
  109. $intro_dbResult = Database::fetch_array($intro_dbQuery);
  110. $intro_content = $intro_dbResult['intro_text'];
  111. }
  112. // Getting session intro
  113. if (!empty($session_id)) {
  114. $sql = "SELECT intro_text FROM $TBL_INTRODUCTION
  115. WHERE c_id = $course_id AND id='".Database::escape_string($moduleId)."' AND session_id = '".intval($session_id)."'";
  116. $intro_dbQuery = Database::query($sql);
  117. $introSessionContent = null;
  118. if (Database::num_rows($intro_dbQuery) > 0) {
  119. $intro_dbResult = Database::fetch_array($intro_dbQuery);
  120. $introSessionContent = $intro_dbResult['intro_text'];
  121. }
  122. // If the course session intro exists replace it.
  123. if (!empty($introSessionContent)) {
  124. $intro_content = $introSessionContent;
  125. }
  126. }
  127. /* Determines the correct display */
  128. if ($intro_cmdEdit || $intro_cmdAdd) {
  129. $intro_dispDefault = false;
  130. $intro_dispForm = true;
  131. $intro_dispCommand = false;
  132. } else {
  133. $intro_dispDefault = true;
  134. $intro_dispForm = false;
  135. if ($intro_editAllowed) {
  136. $intro_dispCommand = true;
  137. } else {
  138. $intro_dispCommand = false;
  139. }
  140. }
  141. /* Executes the display */
  142. // display thematic advance inside a postit
  143. if ($intro_dispForm) {
  144. $default['intro_content'] = $intro_content;
  145. $form->setDefaults($default);
  146. $introduction_section .= '<div id="courseintro" style="width: 98%">';
  147. $introduction_section .= $form->return_form();
  148. $introduction_section .= '</div>';
  149. }
  150. $thematic_description_html = '';
  151. if ($tool == TOOL_COURSE_HOMEPAGE && !isset($_GET['intro_cmdEdit'])) {
  152. $thematic = new Thematic();
  153. if (api_get_course_setting('display_info_advance_inside_homecourse') == '1') {
  154. $information_title = get_lang('InfoAboutLastDoneAdvance');
  155. $last_done_advance = $thematic->get_last_done_thematic_advance();
  156. $thematic_advance_info = $thematic->get_thematic_advance_list($last_done_advance);
  157. } else if(api_get_course_setting('display_info_advance_inside_homecourse') == '2') {
  158. $information_title = get_lang('InfoAboutNextAdvanceNotDone');
  159. $next_advance_not_done = $thematic->get_next_thematic_advance_not_done();
  160. $thematic_advance_info = $thematic->get_thematic_advance_list($next_advance_not_done);
  161. } else if(api_get_course_setting('display_info_advance_inside_homecourse') == '3') {
  162. $information_title = get_lang('InfoAboutLastDoneAdvanceAndNextAdvanceNotDone');
  163. $last_done_advance = $thematic->get_last_done_thematic_advance();
  164. $next_advance_not_done = $thematic->get_next_thematic_advance_not_done();
  165. $thematic_advance_info = $thematic->get_thematic_advance_list($last_done_advance);
  166. $thematic_advance_info2 = $thematic->get_thematic_advance_list($next_advance_not_done);
  167. }
  168. if (!empty($thematic_advance_info)) {
  169. $thematic_advance = get_lang('CourseThematicAdvance').'&nbsp;'.$thematic->get_total_average_of_thematic_advances().'%';
  170. if (api_is_allowed_to_edit(null, true)) {
  171. //$thematic_advance = '<a href="'.api_get_path(WEB_CODE_PATH).'course_progress/index.php?action=thematic_details&'.api_get_cidreq().'">'.get_lang('CourseThematicAdvance').'&nbsp;'.$thematic->get_total_average_of_thematic_advances().'%</a>';
  172. }
  173. $thematic_info = $thematic->get_thematic_list($thematic_advance_info['thematic_id']);
  174. $thematic_advance_info['start_date'] = api_get_local_time($thematic_advance_info['start_date']);
  175. $thematic_advance_info['start_date'] = api_format_date($thematic_advance_info['start_date'], DATE_TIME_FORMAT_LONG);
  176. $thematic_description_html = '<div class="thematic-postit">
  177. <div class="thematic-postit-top"><h3><a class="thematic-postit-head" style="" href="#"> '.$thematic_advance.'</h3></a></div>
  178. <div class="thematic-postit-center" style="display:none">';
  179. $thematic_description_html .= '<div><strong>'.$thematic_info['title'].'</strong></div>';
  180. $thematic_description_html .= '<div style="font-size:8pt;"><strong>'.$thematic_advance_info['start_date'].'</strong></div>';
  181. $thematic_description_html .= '<div>'.$thematic_advance_info['content'].'</div>';
  182. $thematic_description_html .= '<div>'.get_lang('DurationInHours').' : '.$thematic_advance_info['duration'].'</div>';
  183. if (!empty($thematic_advance_info2)){
  184. $thematic_info2 = $thematic->get_thematic_list($thematic_advance_info2['thematic_id']);
  185. $thematic_advance_info2['start_date'] = api_get_local_time($thematic_advance_info2['start_date']);
  186. $thematic_advance_info2['start_date'] = api_format_date($thematic_advance_info2['start_date'], DATE_TIME_FORMAT_LONG);
  187. $thematic_description_html .= '<div><strong>'.$thematic_info2['title'].'</strong></div>';
  188. $thematic_description_html .= '<div style="font-size:8pt;"><strong>'.$thematic_advance_info2['start_date'].'</strong></div>';
  189. $thematic_description_html .= '<div>'.$thematic_advance_info2['content'].'</div>';
  190. $thematic_description_html .= '<div>'.get_lang('DurationInHours').' : '.$thematic_advance_info2['duration'].'</div>';
  191. $thematic_description_html .= '<br />';
  192. }
  193. $thematic_description_html .= '</div>
  194. <div class="thematic-postit-bottom"></div>
  195. </div>';
  196. }
  197. }
  198. $introduction_section .= '<div class="row course-tools-intro"><div class="span12">';
  199. $introduction_section .= $thematic_description_html;
  200. $introduction_section .= '</div>';
  201. $introduction_section .= '<div class="home-course-intro span12"><div class="page-course">';
  202. if ($intro_dispDefault) {
  203. $intro_content = $intro_content;
  204. if (!empty($intro_content)) {
  205. $introduction_section.='<div class="page-course-intro">';
  206. $introduction_section .= $intro_content;
  207. $introduction_section.='</div>';
  208. }
  209. }
  210. $introduction_section .= '</div></div>';
  211. if ($intro_dispCommand) {
  212. if (empty($intro_content)) {
  213. // Displays "Add intro" commands
  214. $introduction_section .= '<div id="courseintro_empty">';
  215. if (!empty ($GLOBALS['_cid'])) {
  216. $introduction_section .= "<a href=\"".api_get_self()."?".api_get_cidreq()."&amp;intro_cmdAdd=1\">";
  217. $introduction_section .= Display::return_icon('introduction_add.gif', get_lang('AddIntro')).' ';
  218. $introduction_section .= "</a>";
  219. } else {
  220. $introduction_section .= "<a href=\"".api_get_self()."?intro_cmdAdd=1\">\n".get_lang('AddIntro')."</a>";
  221. }
  222. $introduction_section .= "</div>";
  223. } else {
  224. // Displays "edit intro && delete intro" commands
  225. $introduction_section .= '<div id="courseintro_empty">';
  226. if (!empty ($GLOBALS['_cid'])) {
  227. $introduction_section .= "<a href=\"".api_get_self()."?".api_get_cidreq()."&amp;intro_cmdEdit=1\">".Display::return_icon('edit.png',get_lang('Modify'),'',ICON_SIZE_SMALL)."</a>";
  228. $introduction_section .= "<a href=\"".api_get_self()."?".api_get_cidreq()."&amp;intro_cmdDel=1\" onclick=\"javascript:if(!confirm('".addslashes(api_htmlentities(get_lang('ConfirmYourChoice'),ENT_QUOTES,$charset))."')) return false;\">".Display::return_icon('delete.png',get_lang('Delete'),'',ICON_SIZE_SMALL)."</a>";
  229. } else {
  230. $introduction_section .= "<a href=\"".api_get_self()."?intro_cmdEdit=1\">".Display::return_icon('edit.png',get_lang('Modify'),'',ICON_SIZE_SMALL)."</a>";
  231. $introduction_section .= "<a href=\"".api_get_self()."?intro_cmdDel=1\" onclick=\"javascript:if(!confirm('".addslashes(api_htmlentities(get_lang('ConfirmYourChoice'),ENT_QUOTES,$charset))."')) return false;\">".Display::return_icon('delete.png',get_lang('Delete'),'',ICON_SIZE_SMALL)."</a>";
  232. }
  233. $introduction_section .= "</div>";
  234. // Fix for chrome XSS filter for videos in iframes - BT#7930
  235. $browser = api_get_navigator();
  236. if (strpos($introduction_section, '<iframe') !== false && $browser['name'] == 'Chrome') {
  237. header('X-XSS-Protection: 0');
  238. }
  239. }
  240. }
  241. $introduction_section .= '</div>';
  242. $browser = api_get_navigator();
  243. if (strpos($introduction_section, '<iframe') !== false && $browser['name'] == 'Chrome') {
  244. header("X-XSS-Protection: 0");
  245. }