introductionSection.inc.php 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. <?php
  2. /* For licensing terms, see /dokeos_license.txt */
  3. /**
  4. ==============================================================================
  5. * The INTRODUCTION MICRO MODULE is used to insert and edit
  6. * an introduction section on a Dokeos Module. It can be inserted on any
  7. * Dokeos Module, provided a connection to a course Database is already active.
  8. *
  9. * The introduction content are stored on a table called "introduction"
  10. * in the course Database. Each module introduction has an Id stored on
  11. * the table. It is this id that can make correspondance to a specific module.
  12. *
  13. * 'introduction' table description
  14. * id : int
  15. * intro_text :text
  16. *
  17. *
  18. * usage :
  19. *
  20. * $moduleId = XX // specifying the module Id
  21. * include(moduleIntro.inc.php);
  22. *
  23. * @package dokeos.include
  24. ==============================================================================
  25. */
  26. require_once api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php';
  27. require_once api_get_path(LIBRARY_PATH).'course_description.lib.php';
  28. /*
  29. -----------------------------------------------------------
  30. Constants and variables
  31. -----------------------------------------------------------
  32. */
  33. $TBL_INTRODUCTION = Database::get_course_table(TABLE_TOOL_INTRO);
  34. $intro_editAllowed = $is_allowed_to_edit;
  35. global $charset;
  36. $intro_cmdEdit = (empty($_GET['intro_cmdEdit'])?'':$_GET['intro_cmdEdit']);
  37. $intro_cmdUpdate = isset($_POST['intro_cmdUpdate'])?true:false;
  38. $intro_cmdDel= (empty($_GET['intro_cmdDel'])?'':$_GET['intro_cmdDel']);
  39. $intro_cmdAdd= (empty($_GET['intro_cmdAdd'])?'':$_GET['intro_cmdAdd']);
  40. if (!empty ($GLOBALS["_cid"])) {
  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. /*=========================================================
  79. INTRODUCTION MICRO MODULE - COMMANDS SECTION (IF ALLOWED)
  80. ========================================================*/
  81. if ($intro_editAllowed) {
  82. /* Replace command */
  83. if ( $intro_cmdUpdate ) {
  84. if ( $form->validate()) {
  85. $form_values = $form->exportValues();
  86. $intro_content = Security::remove_XSS(stripslashes(api_html_entity_decode($form_values['intro_content'])), COURSEMANAGERLOWSECURITY);
  87. if ( ! empty($intro_content) ) {
  88. $sql = "REPLACE $TBL_INTRODUCTION SET id='$moduleId',intro_text='".Database::escape_string($intro_content)."'";
  89. Database::query($sql,__FILE__,__LINE__);
  90. Display::display_confirmation_message(get_lang('IntroductionTextUpdated'),false);
  91. } else {
  92. $intro_cmdDel = true; // got to the delete command
  93. }
  94. } else {
  95. $intro_cmdEdit = true;
  96. }
  97. }
  98. /* Delete Command */
  99. if ($intro_cmdDel) {
  100. Database::query("DELETE FROM $TBL_INTRODUCTION WHERE id='".$moduleId."'",__FILE__,__LINE__);
  101. Display::display_confirmation_message(get_lang('IntroductionTextDeleted'));
  102. }
  103. }
  104. /*===========================================
  105. INTRODUCTION MICRO MODULE - DISPLAY SECTION
  106. ===========================================*/
  107. /* Retrieves the module introduction text, if exist */
  108. $sql = "SELECT intro_text FROM $TBL_INTRODUCTION WHERE id='".$moduleId."'";
  109. $intro_dbQuery = Database::query($sql,__FILE__,__LINE__);
  110. $intro_dbResult = Database::fetch_array($intro_dbQuery);
  111. $intro_content = $intro_dbResult['intro_text'];
  112. /* Determines the correct display */
  113. if ($intro_cmdEdit || $intro_cmdAdd) {
  114. $intro_dispDefault = false;
  115. $intro_dispForm = true;
  116. $intro_dispCommand = false;
  117. } else {
  118. $intro_dispDefault = true;
  119. $intro_dispForm = false;
  120. if ($intro_editAllowed) {
  121. $intro_dispCommand = true;
  122. } else {
  123. $intro_dispCommand = false;
  124. }
  125. }
  126. /* Executes the display */
  127. if ($intro_dispForm) {
  128. $default['intro_content'] = $intro_content;
  129. $form->setDefaults($default);
  130. //echo '<div id="courseintro">';
  131. echo '<div id="courseintro" style="width: 100%">';
  132. $form->display();
  133. echo '</div>';
  134. }
  135. $course_description = new CourseDescription();
  136. $course_description->set_session_id(api_get_session_id());
  137. $thematic_description = $course_description->get_data_by_description_type(8);
  138. $thematic_description_html = '';
  139. if (!empty($thematic_description)) {
  140. $thematic_advance = get_lang('ThematicAdvance').'&nbsp;'.$course_description->get_progress_porcent(false,8);
  141. if (api_is_allowed_to_edit(null,true)) {
  142. $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>';
  143. }
  144. $thematic_description_html = '<td valign="top" width="260px"><div class="thematic-postit">
  145. <div class="thematic-postit-top"><a class="thematic-postit-head" style="" href="#">'.Display::return_icon('postit_top.png').'</a></div>
  146. <div class="thematic-postit-center">
  147. <h3>'.$thematic_advance.'</h3>
  148. '.$thematic_description['description_title'].'
  149. <p>'.$thematic_description['description_content'].'</p>
  150. </div>
  151. <div class="thematic-postit-bottom">'.Display::return_icon('postit_bottom.png').'</div>
  152. </div></td>';
  153. }
  154. if ($intro_dispDefault) {
  155. //$intro_content = make_clickable($intro_content); // make url in text clickable
  156. $intro_content = text_filter($intro_content); // parse [tex] codes
  157. if (!empty($intro_content) || !empty($thematic_description_html)) {
  158. echo "<table align='center' style='width: 80%;'><tr><td>$intro_content</td>$thematic_description_html</tr></table>";
  159. }
  160. }
  161. if ($intro_dispCommand) {
  162. if ( empty($intro_content) ) {
  163. //displays "Add intro" Commands
  164. echo "<div id=\"courseintro\"><p>\n";
  165. if (!empty ($GLOBALS["_cid"])) {
  166. echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&amp;intro_cmdAdd=1\">\n".get_lang('AddIntro')."</a>\n";
  167. } else {
  168. echo "<a href=\"".api_get_self()."?intro_cmdAdd=1\">\n".get_lang('AddIntro')."</a>\n";
  169. }
  170. echo "</p>\n</div>";
  171. } else {
  172. // displays "edit intro && delete intro" Commands
  173. echo "<div id=\"courseintro_icons\"><p>\n";
  174. if (!empty ($GLOBALS["_cid"])) {
  175. 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";
  176. 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";
  177. } else {
  178. 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";
  179. 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";
  180. }
  181. echo "</p>\n</div>";
  182. }
  183. }
  184. ?>