introductionSection.inc.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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. /* Constants and variables */
  25. $TBL_INTRODUCTION = Database::get_course_table(TABLE_TOOL_INTRO);
  26. $intro_editAllowed = $is_allowed_to_edit;
  27. $session_id = api_get_session_id();
  28. $introduction_section = '';
  29. global $charset;
  30. $intro_cmdEdit = empty($_GET['intro_cmdEdit']) ? '' : $_GET['intro_cmdEdit'];
  31. $intro_cmdUpdate = isset($_POST['intro_cmdUpdate']);
  32. $intro_cmdDel = empty($_GET['intro_cmdDel']) ? '' : $_GET['intro_cmdDel'];
  33. $intro_cmdAdd = empty($_GET['intro_cmdAdd']) ? '' : $_GET['intro_cmdAdd'];
  34. if (!empty ($GLOBALS['_cid'])) {
  35. $form = new FormValidator('introduction_text', 'post', api_get_self().'?'.api_get_cidreq());
  36. } else {
  37. $form = new FormValidator('introduction_text');
  38. }
  39. $renderer =& $form->defaultRenderer();
  40. $renderer->setElementTemplate('<div style="width: 80%; margin: 0px auto; padding-bottom: 10px; ">{element}</div>');
  41. $toolbar_set = 'Introduction';
  42. $width = '100%';
  43. $height = '300';
  44. // The global variable $fck_attribute has been deprecated. It stays here for supporting old external code.
  45. global $fck_attribute;
  46. if (is_array($fck_attribute)) {
  47. if (isset($fck_attribute['ToolbarSet'])) {
  48. $toolbar_set = $fck_attribute['ToolbarSet'];
  49. }
  50. if (isset($fck_attribute['Width'])) {
  51. $toolbar_set = $fck_attribute['Width'];
  52. }
  53. if (isset($fck_attribute['Height'])) {
  54. $toolbar_set = $fck_attribute['Height'];
  55. }
  56. }
  57. if (is_array($editor_config)) {
  58. if (!isset($editor_config['ToolbarSet'])) {
  59. $editor_config['ToolbarSet'] = $toolbar_set;
  60. }
  61. if (!isset($editor_config['Width'])) {
  62. $editor_config['Width'] = $width;
  63. }
  64. if (!isset($editor_config['Height'])) {
  65. $editor_config['Height'] = $height;
  66. }
  67. } else {
  68. $editor_config = array('ToolbarSet' => $toolbar_set, 'Width' => $width, 'Height' => $height);
  69. }
  70. $form->add_html_editor('intro_content', null, null, false, $editor_config);
  71. $form->addElement('style_submit_button', 'intro_cmdUpdate', get_lang('SaveIntroText'), 'class="save"');
  72. /* INTRODUCTION MICRO MODULE - COMMANDS SECTION (IF ALLOWED) */
  73. $course_id = api_get_course_int_id();
  74. if ($intro_editAllowed) {
  75. $moduleId = Database::escape_string($moduleId);
  76. /* Replace command */
  77. if ($intro_cmdUpdate) {
  78. if ($form->validate()) {
  79. $form_values = $form->exportValues();
  80. $intro_content = Security::remove_XSS(stripslashes(api_html_entity_decode($form_values['intro_content'])), COURSEMANAGERLOWSECURITY);
  81. if (!empty($intro_content)) {
  82. $sql = "REPLACE $TBL_INTRODUCTION SET c_id = $course_id, id='$moduleId',intro_text='".Database::escape_string($intro_content)."', session_id='".intval($session_id)."'";
  83. Database::query($sql);
  84. $introduction_section .= Display::return_message(get_lang('IntroductionTextUpdated'),'confirmation', false);
  85. } else {
  86. $intro_cmdDel = true; // got to the delete command
  87. }
  88. } else {
  89. $intro_cmdEdit = true;
  90. }
  91. }
  92. /* Delete Command */
  93. if ($intro_cmdDel) {
  94. Database::query("DELETE FROM $TBL_INTRODUCTION WHERE c_id = $course_id AND id='".$moduleId."' AND session_id='".intval($session_id)."'");
  95. $introduction_section .= Display::return_message(get_lang('IntroductionTextDeleted'), 'confirmation');
  96. }
  97. }
  98. /* INTRODUCTION MICRO MODULE - DISPLAY SECTION */
  99. /* Retrieves the module introduction text, if exist */
  100. $sql = "SELECT intro_text FROM $TBL_INTRODUCTION
  101. WHERE c_id = $course_id AND id='".Database::escape_string($moduleId)."' AND session_id = '".intval($session_id)."'";
  102. $intro_dbQuery = Database::query($sql);
  103. if (Database::num_rows($intro_dbQuery) > 0) {
  104. $intro_dbResult = Database::fetch_array($intro_dbQuery);
  105. $intro_content = $intro_dbResult['intro_text'];
  106. } else {
  107. $intro_content = '';
  108. }
  109. /* Determines the correct display */
  110. if ($intro_cmdEdit || $intro_cmdAdd) {
  111. $intro_dispDefault = false;
  112. $intro_dispForm = true;
  113. $intro_dispCommand = false;
  114. } else {
  115. $intro_dispDefault = true;
  116. $intro_dispForm = false;
  117. if ($intro_editAllowed) {
  118. $intro_dispCommand = true;
  119. } else {
  120. $intro_dispCommand = false;
  121. }
  122. }
  123. /* Executes the display */
  124. // display thematic advance inside a postit
  125. if ($intro_dispForm) {
  126. $default['intro_content'] = $intro_content;
  127. $form->setDefaults($default);
  128. $introduction_section .= '<div id="courseintro" style="width: 98%">';
  129. $introduction_section .= $form->return_form();
  130. $introduction_section .= '</div>';
  131. }
  132. $thematic_description_html = '';
  133. if ($tool == TOOL_COURSE_HOMEPAGE && !isset($_GET['intro_cmdEdit'])) {
  134. $thematic = new Thematic();
  135. if (api_get_course_setting('display_info_advance_inside_homecourse') == '1') {
  136. $information_title = get_lang('InfoAboutLastDoneAdvance');
  137. $last_done_advance = $thematic->get_last_done_thematic_advance();
  138. $thematic_advance_info = $thematic->get_thematic_advance_list($last_done_advance);
  139. } else if(api_get_course_setting('display_info_advance_inside_homecourse') == '2') {
  140. $information_title = get_lang('InfoAboutNextAdvanceNotDone');
  141. $next_advance_not_done = $thematic->get_next_thematic_advance_not_done();
  142. $thematic_advance_info = $thematic->get_thematic_advance_list($next_advance_not_done);
  143. } else if(api_get_course_setting('display_info_advance_inside_homecourse') == '3') {
  144. $information_title = get_lang('InfoAboutLastDoneAdvanceAndNextAdvanceNotDone');
  145. $last_done_advance = $thematic->get_last_done_thematic_advance();
  146. $next_advance_not_done = $thematic->get_next_thematic_advance_not_done();
  147. $thematic_advance_info = $thematic->get_thematic_advance_list($last_done_advance);
  148. $thematic_advance_info2 = $thematic->get_thematic_advance_list($next_advance_not_done);
  149. }
  150. if (!empty($thematic_advance_info)) {
  151. $thematic_advance = get_lang('CourseThematicAdvance').'&nbsp;'.$thematic->get_total_average_of_thematic_advances().'%';
  152. if (api_is_allowed_to_edit(null, true)) {
  153. //$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>';
  154. }
  155. $thematic_info = $thematic->get_thematic_list($thematic_advance_info['thematic_id']);
  156. $thematic_advance_info['start_date'] = api_get_local_time($thematic_advance_info['start_date']);
  157. $thematic_advance_info['start_date'] = api_format_date($thematic_advance_info['start_date'], DATE_TIME_FORMAT_LONG);
  158. $thematic_description_html = '<div class="thematic-postit">
  159. <div class="thematic-postit-top"><h3><a class="thematic-postit-head" style="" href="#"> '.$thematic_advance.'</h3></a></div>
  160. <div class="thematic-postit-center" style="display:none">';
  161. $thematic_description_html .= '<div><strong>'.$thematic_info['title'].'</strong></div>';
  162. $thematic_description_html .= '<div style="font-size:8pt;"><strong>'.$thematic_advance_info['start_date'].'</strong></div>';
  163. $thematic_description_html .= '<div>'.$thematic_advance_info['content'].'</div>';
  164. $thematic_description_html .= '<div>'.get_lang('DurationInHours').' : '.$thematic_advance_info['duration'].'</div>';
  165. if (!empty($thematic_advance_info2)){
  166. $thematic_info2 = $thematic->get_thematic_list($thematic_advance_info2['thematic_id']);
  167. $thematic_advance_info2['start_date'] = api_get_local_time($thematic_advance_info2['start_date']);
  168. $thematic_advance_info2['start_date'] = api_format_date($thematic_advance_info2['start_date'], DATE_TIME_FORMAT_LONG);
  169. $thematic_description_html .= '<div><strong>'.$thematic_info2['title'].'</strong></div>';
  170. $thematic_description_html .= '<div style="font-size:8pt;"><strong>'.$thematic_advance_info2['start_date'].'</strong></div>';
  171. $thematic_description_html .= '<div>'.$thematic_advance_info2['content'].'</div>';
  172. $thematic_description_html .= '<div>'.get_lang('DurationInHours').' : '.$thematic_advance_info2['duration'].'</div>';
  173. $thematic_description_html .= '<br />';
  174. }
  175. $thematic_description_html .= '</div>
  176. <div class="thematic-postit-bottom"></div>
  177. </div>';
  178. }
  179. }
  180. $introduction_section .= '<div class="row"><div class="span12">';
  181. $introduction_section .= $thematic_description_html;
  182. $introduction_section .= '</div>';
  183. $introduction_section .= '<div class="span12">';
  184. if ($intro_dispDefault) {
  185. $intro_content = $intro_content;
  186. if (!empty($intro_content)) {
  187. $introduction_section .= $intro_content;
  188. }
  189. }
  190. $introduction_section .= '</div>';
  191. if ($intro_dispCommand) {
  192. if (empty($intro_content)) {
  193. // Displays "Add intro" commands
  194. $introduction_section .= '<div id="courseintro_empty">';
  195. if (!empty ($GLOBALS['_cid'])) {
  196. $introduction_section .= "<a href=\"".api_get_self()."?".api_get_cidreq()."&amp;intro_cmdAdd=1\">";
  197. $introduction_section .= Display::return_icon('introduction_add.gif', get_lang('AddIntro')).' ';
  198. $introduction_section .= "</a>";
  199. } else {
  200. $introduction_section .= "<a href=\"".api_get_self()."?intro_cmdAdd=1\">\n".get_lang('AddIntro')."</a>";
  201. }
  202. $introduction_section .= "</div>";
  203. } else {
  204. // Displays "edit intro && delete intro" commands
  205. $introduction_section .= '<div id="courseintro_empty">';
  206. if (!empty ($GLOBALS['_cid'])) {
  207. $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>";
  208. $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>";
  209. } else {
  210. $introduction_section .= "<a href=\"".api_get_self()."?intro_cmdEdit=1\">".Display::return_icon('edit.png',get_lang('Modify'),'',ICON_SIZE_SMALL)."</a>";
  211. $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>";
  212. }
  213. $introduction_section .= "</div>";
  214. }
  215. }
  216. $introduction_section .= '</div>';