PageRenderTime 47ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 1ms

/php/main/inc/introductionSection.inc.php

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