introductionSection.inc.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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. $form->add_html_editor('intro_content',null,null,false);
  47. $form->addElement('style_submit_button', 'intro_cmdUpdate', get_lang('SaveIntroText'), 'class="save"');
  48. /*=========================================================
  49. INTRODUCTION MICRO MODULE - COMMANDS SECTION (IF ALLOWED)
  50. ========================================================*/
  51. if ($intro_editAllowed) {
  52. /* Replace command */
  53. if ( $intro_cmdUpdate ) {
  54. if ( $form->validate()) {
  55. $form_values = $form->exportValues();
  56. $intro_content = $form_values['intro_content'];
  57. if ( ! empty($intro_content) ) {
  58. $sql = "REPLACE $TBL_INTRODUCTION SET id='$moduleId',intro_text='".Database::escape_string($intro_content)."'";
  59. api_sql_query($sql,__FILE__,__LINE__);
  60. Display::display_confirmation_message(get_lang('IntroductionTextUpdated'),false);
  61. } else {
  62. $intro_cmdDel = true; // got to the delete command
  63. }
  64. } else {
  65. $intro_cmdEdit = true;
  66. }
  67. }
  68. /* Delete Command */
  69. if ($intro_cmdDel) {
  70. api_sql_query("DELETE FROM $TBL_INTRODUCTION WHERE id='".$moduleId."'",__FILE__,__LINE__);
  71. Display::display_confirmation_message(get_lang('IntroductionTextDeleted'));
  72. }
  73. }
  74. /*===========================================
  75. INTRODUCTION MICRO MODULE - DISPLAY SECTION
  76. ===========================================*/
  77. /* Retrieves the module introduction text, if exist */
  78. $sql = "SELECT intro_text FROM $TBL_INTRODUCTION WHERE id='".$moduleId."'";
  79. $intro_dbQuery = api_sql_query($sql,__FILE__,__LINE__);
  80. $intro_dbResult = mysql_fetch_array($intro_dbQuery);
  81. $intro_content = $intro_dbResult['intro_text'];
  82. /* Determines the correct display */
  83. if ($intro_cmdEdit || $intro_cmdAdd) {
  84. $intro_dispDefault = false;
  85. $intro_dispForm = true;
  86. $intro_dispCommand = false;
  87. } else {
  88. $intro_dispDefault = true;
  89. $intro_dispForm = false;
  90. if ($intro_editAllowed) {
  91. $intro_dispCommand = true;
  92. } else {
  93. $intro_dispCommand = false;
  94. }
  95. }
  96. /* Executes the display */
  97. if ($intro_dispForm) {
  98. $default['intro_content'] = $intro_content;
  99. $form->setDefaults($default);
  100. //echo '<div id="courseintro">';
  101. echo '<div id="courseintro" style="width: 100%">';
  102. $form->display();
  103. echo '</div>';
  104. }
  105. if ($intro_dispDefault) {
  106. //$intro_content = make_clickable($intro_content); // make url in text clickable
  107. $intro_content = text_filter($intro_content); // parse [tex] codes
  108. if (!empty($intro_content)) {
  109. echo "<table align='center' style='width: 80%;'><tr><td>$intro_content</td></tr></table>";
  110. }
  111. }
  112. if ($intro_dispCommand) {
  113. if ( empty($intro_content) ) {
  114. //displays "Add intro" Commands
  115. echo "<div id=\"courseintro\"><p>\n";
  116. if (!empty ($GLOBALS["_cid"])) {
  117. echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&amp;intro_cmdAdd=1\">\n".get_lang('AddIntro')."</a>\n";
  118. } else {
  119. echo "<a href=\"".api_get_self()."?intro_cmdAdd=1\">\n".get_lang('AddIntro')."</a>\n";
  120. }
  121. echo "</p>\n</div>";
  122. } else {
  123. // displays "edit intro && delete intro" Commands
  124. echo "<div id=\"courseintro_icons\"><p>\n";
  125. if (!empty ($GLOBALS["_cid"])) {
  126. 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";
  127. echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&amp;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";
  128. } else {
  129. 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";
  130. echo "<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";
  131. }
  132. echo "</p>\n</div>";
  133. }
  134. }
  135. ?>