introductionSection.inc.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <?php
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2004-2005 Dokeos S.A.
  6. Copyright (c) Bart Mollet, Hogeschool Gent
  7. For a full list of contributors, see "credits.txt".
  8. The full license can be read in "license.txt".
  9. This program is free software; you can redistribute it and/or
  10. modify it under the terms of the GNU General Public License
  11. as published by the Free Software Foundation; either version 2
  12. of the License, or (at your option) any later version.
  13. See the GNU General Public License for more details.
  14. Contact address: Dokeos, 44 rue des palais, B-1030 Brussels, Belgium
  15. Mail: info@dokeos.com
  16. ==============================================================================
  17. */
  18. /**
  19. ==============================================================================
  20. * The INTRODUCTION MICRO MODULE is used to insert and edit
  21. * an introduction section on a Dokeos Module. It can be inserted on any
  22. * Dokeos Module, provided a connection to a course Database is already active.
  23. *
  24. * The introduction content are stored on a table called "introduction"
  25. * in the course Database. Each module introduction has an Id stored on
  26. * the table. It is this id that can make correspondance to a specific module.
  27. *
  28. * 'introduction' table description
  29. * id : int
  30. * intro_text :text
  31. *
  32. *
  33. * usage :
  34. *
  35. * $moduleId = XX // specifying the module Id
  36. * include(moduleIntro.inc.php);
  37. *
  38. * @package dokeos.include
  39. ==============================================================================
  40. */
  41. include_once(api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php');
  42. /*
  43. -----------------------------------------------------------
  44. Constants and variables
  45. -----------------------------------------------------------
  46. */
  47. $TBL_INTRODUCTION = Database::get_course_table(TABLE_TOOL_INTRO);
  48. $intro_editAllowed = $is_allowed_to_edit;
  49. $intro_cmdEdit = $_GET['intro_cmdEdit'];
  50. $intro_cmdUpdate = $_POST['intro_cmdUpdate'];
  51. $intro_cmdDel= $_GET['intro_cmdDel'];
  52. $intro_cmdAdd= $_GET['intro_cmdAdd'];
  53. $form = new FormValidator('introduction_text');
  54. $renderer =& $form->defaultRenderer();
  55. $renderer->setElementTemplate('<div style="width: 80%; margin: 0px auto;">{element}</div>');
  56. $form->add_html_editor('intro_content',null,null,false);
  57. $form->addElement('submit','intro_cmdUpdate',get_lang('Ok'));
  58. /*=========================================================
  59. INTRODUCTION MICRO MODULE - COMMANDS SECTION (IF ALLOWED)
  60. ========================================================*/
  61. if ($intro_editAllowed)
  62. {
  63. /* Replace command */
  64. if( $intro_cmdUpdate )
  65. {
  66. if( $form->validate())
  67. {
  68. $form_values = $form->exportValues();
  69. $intro_content = $form_values['intro_content'];
  70. if ( ! empty($intro_content) )
  71. {
  72. $sql = "REPLACE $TBL_INTRODUCTION SET id='$moduleId',intro_text='".mysql_real_escape_string($intro_content)."'";
  73. api_sql_query($sql,__FILE__,__LINE__);
  74. Display::display_confirmation_message(get_lang('IntroductionTextUpdated'));
  75. }
  76. else
  77. {
  78. $intro_cmdDel = true; // got to the delete command
  79. }
  80. }
  81. else
  82. {
  83. $intro_cmdEdit = true;
  84. }
  85. }
  86. /* Delete Command */
  87. if($intro_cmdDel)
  88. {
  89. api_sql_query("DELETE FROM $TBL_INTRODUCTION WHERE id='".$moduleId."'",__FILE__,__LINE__);
  90. Display::display_confirmation_message(get_lang('IntroductionTextDeleted'));
  91. }
  92. }
  93. /*===========================================
  94. INTRODUCTION MICRO MODULE - DISPLAY SECTION
  95. ===========================================*/
  96. /* Retrieves the module introduction text, if exist */
  97. $sql = "SELECT intro_text FROM $TBL_INTRODUCTION WHERE id='".$moduleId."'";
  98. $intro_dbQuery = api_sql_query($sql,__FILE__,__LINE__);
  99. $intro_dbResult = mysql_fetch_array($intro_dbQuery);
  100. $intro_content = $intro_dbResult['intro_text'];
  101. /* Determines the correct display */
  102. if ($intro_cmdEdit || $intro_cmdAdd)
  103. {
  104. $intro_dispDefault = false;
  105. $intro_dispForm = true;
  106. $intro_dispCommand = false;
  107. }
  108. else
  109. {
  110. $intro_dispDefault = true;
  111. $intro_dispForm = false;
  112. if ($intro_editAllowed)
  113. {
  114. $intro_dispCommand = true;
  115. }
  116. else
  117. {
  118. $intro_dispCommand = false;
  119. }
  120. }
  121. /* Executes the display */
  122. if ($intro_dispForm)
  123. {
  124. $default['intro_content'] = $intro_content;
  125. $form->setDefaults($default);
  126. echo '<div id="courseintro">';
  127. $form->display();
  128. echo '</div>';
  129. }
  130. if ($intro_dispDefault)
  131. {
  132. //$intro_content = make_clickable($intro_content); // make url in text clickable
  133. $intro_content = text_filter($intro_content); // parse [tex] codes
  134. if (!empty($intro_content))
  135. {
  136. echo "<table align='center' style='width: 80%;'><tr><td>$intro_content</td></tr></table>";
  137. }
  138. }
  139. if ($intro_dispCommand)
  140. {
  141. if( empty($intro_content) ) // displays "Add intro" Commands
  142. {
  143. echo "<div id=\"courseintro\"><p>\n",
  144. "<a href=\"".api_get_self()."?intro_cmdAdd=1\">\n",get_lang('AddIntro'),"</a>\n",
  145. "</p>\n</div>";
  146. }
  147. else // displays "edit intro && delete intro" Commands
  148. {
  149. echo "<div id=\"courseintro_icons\"><p>\n",
  150. "<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",
  151. "<a href=\"".api_get_self()."?intro_cmdDel=1\" onclick=\"javascript:if(!confirm('".addslashes(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",
  152. "</p>\n</div>";
  153. }
  154. }
  155. ?>