index.php 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. <?php // $Id: index.php 10204 2006-11-26 20:46:53Z pcool $
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2004 Dokeos S.A.
  6. Copyright (c) 2003 Ghent University (UGent)
  7. Copyright (c) 2001 Universite catholique de Louvain (UCL)
  8. Copyright (c) Bart Mollet, Hogeschool Gent
  9. For a full list of contributors, see "credits.txt".
  10. The full license can be read in "license.txt".
  11. This program is free software; you can redistribute it and/or
  12. modify it under the terms of the GNU General Public License
  13. as published by the Free Software Foundation; either version 2
  14. of the License, or (at your option) any later version.
  15. See the GNU General Public License for more details.
  16. Contact address: Dokeos, 44 rue des palais, B-1030 Brussels, Belgium
  17. Mail: info@dokeos.com
  18. ==============================================================================
  19. */
  20. /**
  21. ==============================================================================
  22. * This script edits the course description.
  23. * This script is reserved for users with write access on the course.
  24. *
  25. * @author Thomas Depraetere
  26. * @author Hugues Peeters
  27. * @author Christophe Gesché
  28. * @author Olivier brouckaert
  29. * @package dokeos.course_description
  30. ==============================================================================
  31. */
  32. /*
  33. ==============================================================================
  34. INIT SECTION
  35. ==============================================================================
  36. */
  37. // name of the language file that needs to be included
  38. $language_file = array ('course_description', 'pedaSuggest');
  39. include ('../inc/global.inc.php');
  40. $this_section = SECTION_COURSES;
  41. include (api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php');
  42. /*
  43. -----------------------------------------------------------
  44. Header
  45. -----------------------------------------------------------
  46. */
  47. Display :: display_header($nameTools, "Description");
  48. api_display_tool_title($nameTools);
  49. api_protect_course_script();
  50. /*
  51. -----------------------------------------------------------
  52. Constants and variables
  53. -----------------------------------------------------------
  54. */
  55. $nameTools = get_lang(TOOL_COURSE_DESCRIPTION);
  56. $interbreadcrumb[] = array ("url" => "index.php", "name" => get_lang('CourseProgram'));
  57. $tbl_course_description = Database::get_course_table(TABLE_COURSE_DESCRIPTION);
  58. $show_description_list = true;
  59. $show_peda_suggest = true;
  60. define('ADD_BLOCK', 0);
  61. // Default descriptions
  62. $default_description_titles = array();
  63. $default_description_titles[1]= get_lang('GeneralDescription');
  64. $default_description_titles[2]= get_lang('Objectives');
  65. $default_description_titles[3]= get_lang('Topics');
  66. $default_description_titles[4]= get_lang('Methodology');
  67. $default_description_titles[5]= get_lang('CourseMaterial');
  68. $default_description_titles[6]= get_lang('HumanAndTechnicalResources');
  69. $default_description_titles[7]= get_lang('Assessment');
  70. $question = array();
  71. $question[1]= get_lang('GeneralDescriptionQuestions');
  72. $question[2]= get_lang('ObjectivesQuestions');
  73. $question[3]= get_lang('TopicsQuestions');
  74. $question[4]= get_lang('MethodologyQuestions');
  75. $question[5]= get_lang('CourseMaterialQuestions');
  76. $question[6]= get_lang('HumanAndTechnicalResourcesQuestions');
  77. $question[7]= get_lang('AssessmentQuestions');
  78. $information = array();
  79. $information[1]= get_lang('GeneralDescriptionInformation');
  80. $information[2]= get_lang('ObjectivesInformation');
  81. $information[3]= get_lang('TopicsInformation');
  82. $information[4]= get_lang('MethodologyInformation');
  83. $information[5]= get_lang('CourseMaterialInformation');
  84. $information[6]= get_lang('HumanAndTechnicalResourcesInformation');
  85. $information[7]= get_lang('AssessmentInformation');
  86. $default_description_title_editable = array();
  87. $default_description_title_editable[1] = false;
  88. $default_description_title_editable[2] = true;
  89. $default_description_title_editable[3] = true;
  90. $default_description_title_editable[4] = true;
  91. $default_description_title_editable[5] = true;
  92. $default_description_title_editable[6] = true;
  93. $default_description_title_editable[7] = true;
  94. /*
  95. ==============================================================================
  96. MAIN CODE
  97. ==============================================================================
  98. */
  99. $description_id = isset ($_REQUEST['description_id']) ? intval($_REQUEST['description_id']) : null;
  100. if (api_is_allowed_to_edit() && !is_null($description_id))
  101. {
  102. // Delete a description block
  103. if (isset ($_GET['action']) && $_GET['action'] == 'delete')
  104. {
  105. $sql = "DELETE FROM $tbl_course_description WHERE id='$description_id'";
  106. api_sql_query($sql, __FILE__, __LINE__);
  107. Display :: display_normal_message(get_lang('CourseDescriptionDeleted'));
  108. }
  109. // Add or edit a description block
  110. else
  111. {
  112. $sql = "SELECT * FROM $tbl_course_description WHERE id='$description_id'";
  113. $result = api_sql_query($sql, __FILE__, __LINE__);
  114. if ($description = mysql_fetch_array($result))
  115. {
  116. $default_description_titles[$description_id] = $description['title'];
  117. $description_content = $description['content'];
  118. }
  119. // Build the form
  120. $form = new FormValidator('course_description');
  121. $form->addElement('hidden', 'description_id');
  122. if (($description_id == ADD_BLOCK) || $default_description_title_editable[$description_id])
  123. {
  124. $form->add_textfield('title', get_lang('Title'));
  125. }
  126. $form->add_html_editor('content', get_lang('Content'));
  127. $form->addElement('submit', null, get_lang('Ok'));
  128. // Set some default values
  129. $default['title'] = $default_description_titles[$description_id];
  130. $default['content'] = $description_content;
  131. $default['description_id'] = $description_id;
  132. $form->setDefaults($default);
  133. // If form validates: save the description block
  134. if ($form->validate())
  135. {
  136. $description = $form->exportValues();
  137. $content = $description['content'];
  138. $title = $description['title'];
  139. if ($description['description_id'] == ADD_BLOCK)
  140. {
  141. $sql = "SELECT MAX(id) FROM $tbl_course_description";
  142. $result = api_sql_query($sql, __FILE__, __LINE__);
  143. list ($new_id) = mysql_fetch_row($result);
  144. $new_id = max(sizeof($default_description_titles), $new_id);
  145. $sql = "INSERT IGNORE INTO $tbl_course_description SET id = '".$new_id."', title = '".mysql_real_escape_string($title)."', content = '".mysql_real_escape_string($content)."'";
  146. api_sql_query($sql, __FILE__, __LINE__);
  147. }
  148. else
  149. {
  150. if (!$default_description_title_editable[$description_id])
  151. {
  152. $title = $default_description_titles[$description_id];
  153. }
  154. $sql = "DELETE FROM $tbl_course_description WHERE id = '".$description_id."'";
  155. api_sql_query($sql, __FILE__, __LINE__);
  156. $sql = "INSERT IGNORE INTO $tbl_course_description SET id = '".$description_id."', title = '".mysql_real_escape_string($title)."', content = '".mysql_real_escape_string($content)."'";
  157. api_sql_query($sql, __FILE__, __LINE__);
  158. }
  159. Display :: display_normal_message(get_lang('CourseDescriptionUpdated'));
  160. }
  161. // Show the form
  162. else
  163. {
  164. if ($show_peda_suggest)
  165. {
  166. echo '<dl>';
  167. if (isset ($question[$description_id]))
  168. {
  169. echo '<dt><b>'.get_lang('QuestionPlan').'</b></dt>';
  170. echo '<dd>'.$question[$description_id].'</dd>';
  171. }
  172. if (isset ($information[$description_id]))
  173. {
  174. echo '<dt><b>'.get_lang('Info2Say').'</b></dt>';
  175. echo '<dd>'.$information[$description_id].'</dd>';
  176. }
  177. echo '</dl>';
  178. }
  179. $form->display();
  180. $show_description_list = false;
  181. }
  182. }
  183. }
  184. // Show the list of all description blocks
  185. if ($show_description_list)
  186. {
  187. $sql = "SELECT * FROM $tbl_course_description ORDER BY id";
  188. $result = api_sql_query($sql, __FILE__, __LINE__);
  189. $descriptions;
  190. while ($description = mysql_fetch_object($result))
  191. {
  192. $descriptions[$description->id] = $description;
  193. }
  194. if (api_is_allowed_to_edit())
  195. {
  196. $categories = array ();
  197. foreach ($default_description_titles as $id => $title)
  198. {
  199. if (!array_key_exists($id, $descriptions))
  200. {
  201. $categories[$id] = $title;
  202. }
  203. }
  204. $categories[ADD_BLOCK] = get_lang('NewBloc');
  205. $cat_form = new FormValidator('category', 'get');
  206. $group = array ();
  207. $group[] = $cat_form->createElement('select', 'description_id', get_lang('AddCat'), $categories);
  208. $group[] = $cat_form->createElement('submit', null, get_lang('Ok'));
  209. $cat_form->addGroup($group, 'cat', get_lang('AddCat'), null, false);
  210. $cat_form->display();
  211. }
  212. if (count($descriptions) > 0)
  213. {
  214. foreach ($descriptions as $id => $description)
  215. {
  216. echo '<hr noshade="noshade" size="1"/>';
  217. echo '<div>';
  218. if (api_is_allowed_to_edit())
  219. {
  220. echo '<a href="'.$_SERVER['PHP_SELF'].'?description_id='.$description->id.'">';
  221. echo '<img src="../img/edit.gif" alt="'.get_lang('Modify').'" border="0" style="vertical-align:middle;float:right;margin:2px;" />';
  222. echo '</a> ';
  223. echo '<a href="'.$_SERVER['PHP_SELF'].'?action=delete&amp;description_id='.$description->id.'" onclick="javascript:if(!confirm(\''.addslashes(htmlentities(get_lang('ConfirmYourChoice'))).'\')) return false;">';
  224. echo '<img src="../img/delete.gif" alt="'.get_lang("Delete").'" border="0" style="vertical-align:middle;float:right;margin:2px;" />';
  225. echo '</a> ';
  226. }
  227. echo '<h3>'.$description->title.'</h3>';
  228. echo '</div>';
  229. echo text_filter($description->content);
  230. }
  231. }
  232. else
  233. {
  234. echo '<br /><em>'.get_lang('ThisCourseDescriptionIsEmpty').'</em>';
  235. }
  236. }
  237. /*
  238. ==============================================================================
  239. FOOTER
  240. ==============================================================================
  241. */
  242. Display :: display_footer();
  243. ?>