introductionSection.inc.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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. include_once(api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php');
  27. /*
  28. -----------------------------------------------------------
  29. Constants and variables
  30. -----------------------------------------------------------
  31. */
  32. $TBL_INTRODUCTION = Database::get_course_table(TABLE_TOOL_INTRO);
  33. $intro_editAllowed = $is_allowed_to_edit;
  34. global $charset;
  35. $intro_cmdEdit = (empty($_GET['intro_cmdEdit'])?'':$_GET['intro_cmdEdit']);
  36. $intro_cmdUpdate = isset($_POST['intro_cmdUpdate'])?true:false;
  37. $intro_cmdDel= (empty($_GET['intro_cmdDel'])?'':$_GET['intro_cmdDel']);
  38. $intro_cmdAdd= (empty($_GET['intro_cmdAdd'])?'':$_GET['intro_cmdAdd']);
  39. if (!empty ($GLOBALS["_cid"])) {
  40. $form = new FormValidator('introduction_text', 'post', api_get_self()."?".api_get_cidreq());
  41. } else {
  42. $form = new FormValidator('introduction_text');
  43. }
  44. $renderer =& $form->defaultRenderer();
  45. $renderer->setElementTemplate('<div style="width: 80%; margin: 0px auto; padding-bottom: 10px; ">{element}</div>');
  46. $toolbar_set = 'Introduction';
  47. $width = '100%';
  48. $height = '300';
  49. // The global variable $fck_attribute has been deprecated. It stays here for supporting old external code.
  50. global $fck_attribute;
  51. if (is_array($fck_attribute)) {
  52. if (isset($fck_attribute['ToolbarSet'])) {
  53. $toolbar_set = $fck_attribute['ToolbarSet'];
  54. }
  55. if (isset($fck_attribute['Width'])) {
  56. $toolbar_set = $fck_attribute['Width'];
  57. }
  58. if (isset($fck_attribute['Height'])) {
  59. $toolbar_set = $fck_attribute['Height'];
  60. }
  61. }
  62. if (is_array($editor_config)) {
  63. if (!isset($editor_config['ToolbarSet'])) {
  64. $editor_config['ToolbarSet'] = $toolbar_set;
  65. }
  66. if (!isset($editor_config['Width'])) {
  67. $editor_config['Width'] = $width;
  68. }
  69. if (!isset($editor_config['Height'])) {
  70. $editor_config['Height'] = $height;
  71. }
  72. } else {
  73. $editor_config = array('ToolbarSet' => $toolbar_set, 'Width' => $width, 'Height' => $height);
  74. }
  75. $form->add_html_editor('intro_content', null, null, false, $editor_config);
  76. $form->addElement('style_submit_button', 'intro_cmdUpdate', get_lang('SaveIntroText'), 'class="save"');
  77. /*=========================================================
  78. INTRODUCTION MICRO MODULE - COMMANDS SECTION (IF ALLOWED)
  79. ========================================================*/
  80. if ($intro_editAllowed) {
  81. /* Replace command */
  82. if ( $intro_cmdUpdate ) {
  83. if ( $form->validate()) {
  84. $form_values = $form->exportValues();
  85. $intro_content = Security::remove_XSS(stripslashes(api_html_entity_decode($form_values['intro_content'])), COURSEMANAGERLOWSECURITY);
  86. if ( ! empty($intro_content) ) {
  87. $sql = "REPLACE $TBL_INTRODUCTION SET id='$moduleId',intro_text='".Database::escape_string($intro_content)."'";
  88. Database::query($sql,__FILE__,__LINE__);
  89. Display::display_confirmation_message(get_lang('IntroductionTextUpdated'),false);
  90. } else {
  91. $intro_cmdDel = true; // got to the delete command
  92. }
  93. } else {
  94. $intro_cmdEdit = true;
  95. }
  96. }
  97. /* Delete Command */
  98. if ($intro_cmdDel) {
  99. Database::query("DELETE FROM $TBL_INTRODUCTION WHERE id='".$moduleId."'",__FILE__,__LINE__);
  100. Display::display_confirmation_message(get_lang('IntroductionTextDeleted'));
  101. }
  102. }
  103. /*===========================================
  104. INTRODUCTION MICRO MODULE - DISPLAY SECTION
  105. ===========================================*/
  106. /* Retrieves the module introduction text, if exist */
  107. $sql = "SELECT intro_text FROM $TBL_INTRODUCTION WHERE id='".$moduleId."'";
  108. $intro_dbQuery = Database::query($sql,__FILE__,__LINE__);
  109. $intro_dbResult = mysql_fetch_array($intro_dbQuery);
  110. $intro_content = $intro_dbResult['intro_text'];
  111. /* Determines the correct display */
  112. if ($intro_cmdEdit || $intro_cmdAdd) {
  113. $intro_dispDefault = false;
  114. $intro_dispForm = true;
  115. $intro_dispCommand = false;
  116. } else {
  117. $intro_dispDefault = true;
  118. $intro_dispForm = false;
  119. if ($intro_editAllowed) {
  120. $intro_dispCommand = true;
  121. } else {
  122. $intro_dispCommand = false;
  123. }
  124. }
  125. /* Executes the display */
  126. if ($intro_dispForm) {
  127. $default['intro_content'] = $intro_content;
  128. $form->setDefaults($default);
  129. //echo '<div id="courseintro">';
  130. echo '<div id="courseintro" style="width: 100%">';
  131. $form->display();
  132. echo '</div>';
  133. }
  134. if ($intro_dispDefault) {
  135. //$intro_content = make_clickable($intro_content); // make url in text clickable
  136. $intro_content = text_filter($intro_content); // parse [tex] codes
  137. if (!empty($intro_content)) {
  138. echo "<table align='center' style='width: 80%;'><tr><td>$intro_content</td></tr></table>";
  139. }
  140. }
  141. if ($intro_dispCommand) {
  142. if ( empty($intro_content) ) {
  143. //displays "Add intro" Commands
  144. echo "<div id=\"courseintro\"><p>\n";
  145. if (!empty ($GLOBALS["_cid"])) {
  146. echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&amp;intro_cmdAdd=1\">\n".get_lang('AddIntro')."</a>\n";
  147. } else {
  148. echo "<a href=\"".api_get_self()."?intro_cmdAdd=1\">\n".get_lang('AddIntro')."</a>\n";
  149. }
  150. echo "</p>\n</div>";
  151. } else {
  152. // displays "edit intro && delete intro" Commands
  153. echo "<div id=\"courseintro_icons\"><p>\n";
  154. if (!empty ($GLOBALS["_cid"])) {
  155. 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";
  156. 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";
  157. } else {
  158. 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";
  159. 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";
  160. }
  161. echo "</p>\n</div>";
  162. }
  163. }
  164. ?>