introductionSection.inc.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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(TOOL_INTRO_TABLE);
  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. $fck_attribute['Width'] = '800';
  54. $fck_attribute['Height'] = '400';
  55. $fck_attribute['ToolbarSet'] = 'PluginTest';
  56. $form = new FormValidator('introduction_text');
  57. $renderer =& $form->defaultRenderer();
  58. $renderer->setElementTemplate('<!-- BEGIN error --><span class="form_error">{error}</span><br /><!-- END error --><div>{element}</div>');
  59. $form->add_html_editor('intro_content',null,false);
  60. $form->addElement('submit','intro_cmdUpdate',get_lang('Ok'));
  61. /*=========================================================
  62. INTRODUCTION MICRO MODULE - COMMANDS SECTION (IF ALLOWED)
  63. ========================================================*/
  64. if ($intro_editAllowed)
  65. {
  66. /* Replace command */
  67. if( $intro_cmdUpdate )
  68. {
  69. if( $form->validate())
  70. {
  71. $form_values = $form->exportValues();
  72. $intro_content = $form_values['intro_content'];
  73. if ( ! empty($intro_content) )
  74. {
  75. $sql = "REPLACE $TBL_INTRODUCTION SET id='$moduleId',intro_text='".mysql_real_escape_string($intro_content)."'";
  76. api_sql_query($sql,__FILE__,__LINE__);
  77. }
  78. else
  79. {
  80. $intro_cmdDel = true; // got to the delete command
  81. }
  82. }
  83. else
  84. {
  85. $intro_cmdEdit = true;
  86. }
  87. }
  88. /* Delete Command */
  89. if($intro_cmdDel)
  90. {
  91. api_sql_query("DELETE FROM $TBL_INTRODUCTION WHERE id='".$moduleId."'",__FILE__,__LINE__);
  92. }
  93. }
  94. /*===========================================
  95. INTRODUCTION MICRO MODULE - DISPLAY SECTION
  96. ===========================================*/
  97. /* Retrieves the module introduction text, if exist */
  98. $sql = "SELECT intro_text FROM $TBL_INTRODUCTION WHERE id='".$moduleId."'";
  99. $intro_dbQuery = api_sql_query($sql,__FILE__,__LINE__);
  100. $intro_dbResult = mysql_fetch_array($intro_dbQuery);
  101. $intro_content = $intro_dbResult['intro_text'];
  102. /* Determines the correct display */
  103. if ($intro_cmdEdit || $intro_cmdAdd)
  104. {
  105. $intro_dispDefault = false;
  106. $intro_dispForm = true;
  107. $intro_dispCommand = false;
  108. }
  109. else
  110. {
  111. $intro_dispDefault = true;
  112. $intro_dispForm = false;
  113. if ($intro_editAllowed)
  114. {
  115. $intro_dispCommand = true;
  116. }
  117. else
  118. {
  119. $intro_dispCommand = false;
  120. }
  121. }
  122. /* Executes the display */
  123. if ($intro_dispForm)
  124. {
  125. $default['intro_content'] = $intro_content;
  126. $form->setDefaults($default);
  127. echo '<div id="courseintro">';
  128. $form->display();
  129. echo '</div>';
  130. }
  131. if ($intro_dispDefault)
  132. {
  133. //$intro_content = make_clickable($intro_content); // make url in text clickable
  134. $intro_content = text_filter($intro_content); // parse [tex] codes
  135. //<img src='../../img/mr_dokeos.png'>
  136. if (!empty($intro_content))
  137. {
  138. //$intro_content="<img src='../../main/img/mr_dokeos.png'>".$intro_content;
  139. /*echo "<div id=\"courseintro\"><p>\n",
  140. $intro_content,"\n",
  141. "</p>\n</div>";*/
  142. echo "<table align='center' style='width: 80%;'><tr><td width='110'><img src='../../main/img/mr_dokeos.png'></td><td>$intro_content</td></tr></table>";
  143. }
  144. }
  145. if ($intro_dispCommand)
  146. {
  147. if( empty($intro_content) ) // displays "Add intro" Commands
  148. {
  149. echo "<div id=\"courseintro\"><p>\n",
  150. "<a href=\"".$_SERVER['PHP_SELF']."?intro_cmdAdd=1\">\n",get_lang('AddIntro'),"</a>\n",
  151. "</p>\n</div>";
  152. }
  153. else // displays "edit intro && delete intro" Commands
  154. {
  155. echo "<div id=\"courseintro_icons\"><p>\n",
  156. "<a href=\"".$_SERVER['PHP_SELF']."?intro_cmdEdit=1\"><img src=\"" . api_get_path(WEB_CODE_PATH) . "img/edit.gif\" alt=\"",get_lang('Modify'),"\" border=\"0\" /></a>\n",
  157. "<a href=\"".$_SERVER['PHP_SELF']."?intro_cmdDel=1\" onclick=\"javascript:if(!confirm('".addslashes(htmlentities(get_lang('ConfirmYourChoice')))."')) return false;\"><img src=\"" . api_get_path(WEB_CODE_PATH) . "img/delete.gif\" alt=\"",get_lang('Delete'),"\" border=\"0\" /></a>\n",
  158. "</p>\n</div>";
  159. }
  160. }
  161. ?>