introductionSection.inc.php 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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).'formvalidator/FormValidator.class.php';
  25. require_once api_get_path(LIBRARY_PATH).'course_description.lib.php';
  26. /* Constants and variables */
  27. $TBL_INTRODUCTION = Database::get_course_table(TABLE_TOOL_INTRO);
  28. $intro_editAllowed = $is_allowed_to_edit;
  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. if ($intro_editAllowed) {
  74. /* Replace command */
  75. if ($intro_cmdUpdate) {
  76. if ($form->validate()) {
  77. $form_values = $form->exportValues();
  78. $intro_content = Security::remove_XSS(stripslashes(api_html_entity_decode($form_values['intro_content'])), COURSEMANAGERLOWSECURITY);
  79. if (!empty($intro_content)) {
  80. $sql = "REPLACE $TBL_INTRODUCTION SET id='$moduleId',intro_text='".Database::escape_string($intro_content)."'";
  81. Database::query($sql);
  82. Display::display_confirmation_message(get_lang('IntroductionTextUpdated'), false);
  83. } else {
  84. $intro_cmdDel = true; // got to the delete command
  85. }
  86. } else {
  87. $intro_cmdEdit = true;
  88. }
  89. }
  90. /* Delete Command */
  91. if ($intro_cmdDel) {
  92. Database::query("DELETE FROM $TBL_INTRODUCTION WHERE id='".$moduleId."'");
  93. Display::display_confirmation_message(get_lang('IntroductionTextDeleted'));
  94. }
  95. }
  96. /* INTRODUCTION MICRO MODULE - DISPLAY SECTION */
  97. /* Retrieves the module introduction text, if exist */
  98. $sql = "SELECT intro_text FROM $TBL_INTRODUCTION WHERE id='".$moduleId."'";
  99. $intro_dbQuery = Database::query($sql);
  100. $intro_dbResult = Database::fetch_array($intro_dbQuery);
  101. $intro_content = $intro_dbResult['intro_text'];
  102. /* Determines the correct display */
  103. if ($intro_cmdEdit || $intro_cmdAdd) {
  104. $intro_dispDefault = false;
  105. $intro_dispForm = true;
  106. $intro_dispCommand = false;
  107. } else {
  108. $intro_dispDefault = true;
  109. $intro_dispForm = false;
  110. if ($intro_editAllowed) {
  111. $intro_dispCommand = true;
  112. } else {
  113. $intro_dispCommand = false;
  114. }
  115. }
  116. /* Executes the display */
  117. if ($intro_dispForm) {
  118. $default['intro_content'] = $intro_content;
  119. $form->setDefaults($default);
  120. echo '<div id="courseintro" style="width: 100%">';
  121. $form->display();
  122. echo '</div>';
  123. }
  124. $style_introduction_section = 'style="margin-left:10%;margin-right:10%;"';
  125. $thematic_description_html = '';
  126. if ($tool == TOOL_COURSE_HOMEPAGE && !isset($_GET['intro_cmdEdit'])) {
  127. $course_description = new CourseDescription();
  128. $course_description->set_session_id(api_get_session_id());
  129. $thematic_description = $course_description->get_data_by_description_type(8);
  130. if (!empty($thematic_description)) {
  131. $style_introduction_section = 'style="width:65%;float:left;margin-left:10%;"';
  132. $thematic_advance = get_lang('ThematicAdvance').'&nbsp;'.$course_description->get_progress_porcent(false, 8);
  133. if (api_is_allowed_to_edit(null, true)) {
  134. $thematic_advance = '<a href="'.api_get_path(WEB_CODE_PATH).'course_description/index.php?action=edit&'.api_get_cidreq().'&description_type=8'.'">'.get_lang('ThematicAdvance').'&nbsp;'.$course_description->get_progress_porcent(false, 8).'</a>';
  135. }
  136. $thematic_description_html = '<div style="width:20%;float:left;font-size:10pt;"><div class="thematic-postit">
  137. <div class="thematic-postit-top"><a class="thematic-postit-head" style="" href="#">'.Display::return_icon('postit_top.png').'</a></div>
  138. <div class="thematic-postit-center">
  139. <h3>'.$thematic_advance.'</h3>
  140. '.$thematic_description['description_title'].'
  141. <p>'.$thematic_description['description_content'].'</p>
  142. </div>
  143. <div class="thematic-postit-bottom">'.Display::return_icon('postit_bottom.png').'</div>
  144. </div></div>';
  145. }
  146. }
  147. echo '<div '.$style_introduction_section.'>';
  148. if ($intro_dispDefault) {
  149. //$intro_content = make_clickable($intro_content); // make url in text clickable
  150. $intro_content = text_filter($intro_content); // parse [tex] codes
  151. if (!empty($intro_content) || !empty($thematic_description_html)) {
  152. echo "<table><tr><td>$intro_content</td></tr></table>";
  153. }
  154. }
  155. if ($intro_dispCommand) {
  156. if (empty($intro_content)) {
  157. // Displays "Add intro" commands
  158. echo "<div id=\"courseintro\"><p>\n";
  159. if (!empty ($GLOBALS['_cid'])) {
  160. echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&amp;intro_cmdAdd=1\">\n".get_lang('AddIntro')."</a>\n";
  161. } else {
  162. echo "<a href=\"".api_get_self()."?intro_cmdAdd=1\">\n".get_lang('AddIntro')."</a>\n";
  163. }
  164. echo "</p>\n</div>";
  165. } else {
  166. // Displays "edit intro && delete intro" commands
  167. echo "<div id=\"courseintro_icons\"><p>\n";
  168. if (!empty ($GLOBALS['_cid'])) {
  169. echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&amp;intro_cmdEdit=1\"><img src=\"".api_get_path(WEB_CODE_PATH)."img/edit.gif\" alt=\"".get_lang('Modify')."\" border=\"0\" /></a>\n";
  170. echo "<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;\"><img src=\"".api_get_path(WEB_CODE_PATH)."img/delete.gif\" alt=\"".get_lang('Delete')."\" border=\"0\" /></a>\n";
  171. } else {
  172. echo "<a href=\"".api_get_self()."?intro_cmdEdit=1\"><img src=\"".api_get_path(WEB_CODE_PATH)."img/edit.gif\" alt=\"".get_lang('Modify')."\" border=\"0\" /></a>\n";
  173. echo "<a href=\"".api_get_self()."?intro_cmdDel=1\" onclick=\"javascript:if(!confirm('".addslashes(api_htmlentities(get_lang('ConfirmYourChoice'),ENT_QUOTES,$charset))."')) return false;\"><img src=\"".api_get_path(WEB_CODE_PATH)."img/delete.gif\" alt=\"".get_lang('Delete')."\" border=\"0\" /></a>\n";
  174. }
  175. echo "</p>\n</div>";
  176. }
  177. }
  178. echo '</div>';
  179. echo $thematic_description_html;
  180. echo '<div class="clear"></div>';