index.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. <?php // $Id: index.php 17447 2008-12-23 23:54:19Z iflorespaz $
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2004 Dokeos SPRL
  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, rue du Corbeau, 108, 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', 'accessibility');
  39. include '../inc/global.inc.php';
  40. $this_section = SECTION_COURSES;
  41. include api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php';
  42. include_once api_get_path(LIBRARY_PATH).'WCAG/WCAG_rendering.php';
  43. /*
  44. -----------------------------------------------------------
  45. Header
  46. -----------------------------------------------------------
  47. */
  48. $interbreadcrumb[] = array ("url" => "index.php", "name" => get_lang('CourseProgram'));
  49. if(isset($_GET['description_id']) && $_GET['description_id']==1) $interbreadcrumb[] = array ("url" => "#", "name" => get_lang('GeneralDescription'));
  50. if(isset($_GET['description_id']) && $_GET['description_id']==2) $interbreadcrumb[] = array ("url" => "#", "name" => get_lang('Objectives'));
  51. if(isset($_GET['description_id']) && $_GET['description_id']==3) $interbreadcrumb[] = array ("url" => "#", "name" => get_lang('Topics'));
  52. if(isset($_GET['description_id']) && $_GET['description_id']==4) $interbreadcrumb[] = array ("url" => "#", "name" => get_lang('Methodology'));
  53. if(isset($_GET['description_id']) && $_GET['description_id']==5) $interbreadcrumb[] = array ("url" => "#", "name" => get_lang('CourseMaterial'));
  54. if(isset($_GET['description_id']) && $_GET['description_id']==6) $interbreadcrumb[] = array ("url" => "#", "name" => get_lang('HumanAndTechnicalResources'));
  55. if(isset($_GET['description_id']) && $_GET['description_id']==7) $interbreadcrumb[] = array ("url" => "#", "name" => get_lang('Assessment'));
  56. if(isset($_GET['description_id']) && $_GET['description_id']==8) $interbreadcrumb[] = array ("url" => "#", "name" => get_lang('NewBloc'));
  57. api_protect_course_script(true);
  58. $nameTools = get_lang('CourseProgram');
  59. Display :: display_header('');
  60. //api_display_tool_title($nameTools);
  61. /*
  62. -----------------------------------------------------------
  63. Constants and variables
  64. -----------------------------------------------------------
  65. */
  66. $nameTools = get_lang(TOOL_COURSE_DESCRIPTION);
  67. $tbl_course_description = Database::get_course_table(TABLE_COURSE_DESCRIPTION);
  68. $show_description_list = true;
  69. $show_peda_suggest = true;
  70. define('ADD_BLOCK', 8);
  71. // Default descriptions
  72. $default_description_titles = array();
  73. $default_description_titles[1]= get_lang('GeneralDescription');
  74. $default_description_titles[2]= get_lang('Objectives');
  75. $default_description_titles[3]= get_lang('Topics');
  76. $default_description_titles[4]= get_lang('Methodology');
  77. $default_description_titles[5]= get_lang('CourseMaterial');
  78. $default_description_titles[6]= get_lang('HumanAndTechnicalResources');
  79. $default_description_titles[7]= get_lang('Assessment');
  80. $default_description_icon = array();
  81. $default_description_icon[1]= 'edu_miscellaneous.gif';
  82. $default_description_icon[2]= 'spire.gif';
  83. $default_description_icon[3]= 'kcmdf_big.gif';
  84. $default_description_icon[4]= 'misc.gif';
  85. $default_description_icon[5]= 'laptop.gif';
  86. $default_description_icon[6]= 'personal.gif';
  87. $default_description_icon[7]= 'korganizer.gif';
  88. $default_description_icon[8]= 'ktip.gif';
  89. $question = array();
  90. $question[1]= get_lang('GeneralDescriptionQuestions');
  91. $question[2]= get_lang('ObjectivesQuestions');
  92. $question[3]= get_lang('TopicsQuestions');
  93. $question[4]= get_lang('MethodologyQuestions');
  94. $question[5]= get_lang('CourseMaterialQuestions');
  95. $question[6]= get_lang('HumanAndTechnicalResourcesQuestions');
  96. $question[7]= get_lang('AssessmentQuestions');
  97. $information = array();
  98. $information[1]= get_lang('GeneralDescriptionInformation');
  99. $information[2]= get_lang('ObjectivesInformation');
  100. $information[3]= get_lang('TopicsInformation');
  101. $information[4]= get_lang('MethodologyInformation');
  102. $information[5]= get_lang('CourseMaterialInformation');
  103. $information[6]= get_lang('HumanAndTechnicalResourcesInformation');
  104. $information[7]= get_lang('AssessmentInformation');
  105. $default_description_title_editable = array();
  106. $default_description_title_editable[1] = false;
  107. $default_description_title_editable[2] = true;
  108. $default_description_title_editable[3] = true;
  109. $default_description_title_editable[4] = true;
  110. $default_description_title_editable[5] = true;
  111. $default_description_title_editable[6] = true;
  112. $default_description_title_editable[7] = true;
  113. /*
  114. ==============================================================================
  115. MAIN CODE
  116. ==============================================================================
  117. */
  118. $description_id = isset ($_REQUEST['description_id']) ? intval($_REQUEST['description_id']) : null;
  119. $action = $_GET['action'];
  120. if (api_is_allowed_to_edit() && !is_null($description_id) || $action =='add') {
  121. // Delete a description block
  122. if (isset ($_GET['action']) && $_GET['action'] == 'delete') {
  123. $sql = "DELETE FROM $tbl_course_description WHERE id='$description_id'";
  124. api_sql_query($sql, __FILE__, __LINE__);
  125. Display :: display_confirmation_message(get_lang('CourseDescriptionDeleted'));
  126. }
  127. // Add or edit a description block
  128. else {
  129. if (!empty($description_id)) {
  130. $sql = "SELECT * FROM $tbl_course_description WHERE id='$description_id'";
  131. $result = api_sql_query($sql, __FILE__, __LINE__);
  132. if ($description = mysql_fetch_array($result)) {
  133. $default_description_titles[$description_id] = $description['title'];
  134. $description_content = $description['content'];
  135. } else {
  136. $current_title = $default_description_titles[$description_id];
  137. }
  138. $fck_attribute['Width'] = '100%';
  139. $fck_attribute['Height'] = '225';
  140. $fck_attribute['ToolbarSet'] = 'Middle';
  141. $fck_attribute['Config']['InDocument'] = false;
  142. $fck_attribute['Config']['CreateDocumentDir'] = '../../';
  143. $fck_attribute['Config']['CreateDocumentWebDir'] = api_get_path('WEB_COURSE_PATH').$_course['path'].'/document/';
  144. } else {
  145. $sql = "SELECT MAX(id) as MAX FROM $tbl_course_description ";
  146. $result = api_sql_query($sql, __FILE__, __LINE__);
  147. $max= mysql_fetch_array($result);
  148. $description_id = $max['MAX']+1;
  149. if ($description_id < ADD_BLOCK) {
  150. $description_id=8;
  151. }
  152. }
  153. echo '
  154. <style>
  155. .row{
  156. width:100%;
  157. }
  158. div.row div.label {
  159. width: 60px;
  160. }
  161. div.row div.formw {
  162. width: 100%;
  163. }
  164. </style>';
  165. // Build the form
  166. $form = new FormValidator('course_description','POST','index.php','','style="width: 100%;"');
  167. $form->addElement('hidden', 'description_id');
  168. if ($_GET['action']=='edit' || $_POST['edit']==1 ) {
  169. $form->addElement('hidden', 'edit','1');
  170. }
  171. if ($_GET['action']=='add' || $_POST['add']==1 ) {
  172. $form->addElement('hidden', 'add','1');
  173. }
  174. if (($description_id >= ADD_BLOCK) || $default_description_title_editable[$description_id] || $_GET['action']=='add' || $_POST['add']=='1') {
  175. $form->add_textfield('title', get_lang('Title'), true, array('style'=>'width: 350px;'));
  176. }
  177. if (api_get_setting('wcag_anysurfer_public_pages')=='true') {
  178. WCAG_rendering::prepare_admin_form($description_content, $form);
  179. } else {
  180. $form->add_html_editor('contentDescription', get_lang('Content'));
  181. }
  182. $form->addElement('submit', null, get_lang('Ok'));
  183. // Set some default values
  184. $default['title'] = $default_description_titles[$description_id];
  185. $default['contentDescription'] = $description_content;
  186. $default['description_id'] = $description_id;
  187. if ($description_id == ADD_BLOCK) {
  188. $default['description_id'] = ADD_BLOCK;
  189. }
  190. $form->setDefaults($default);
  191. // If form validates: save the description block
  192. if ($form->validate()) {
  193. $description = $form->exportValues();
  194. if (api_get_setting('wcag_anysurfer_public_pages')=='true') {
  195. $content = WCAG_Rendering::prepareXHTML();
  196. } else {
  197. $content = $description['contentDescription'];
  198. }
  199. $title = $description['title'];
  200. if ($description['description_id'] >= ADD_BLOCK) {
  201. if ($description['edit']=='1') {
  202. $sql = "UPDATE $tbl_course_description SET title = '".mysql_real_escape_string($title)."', content = '".mysql_real_escape_string($content)."' WHERE id = '".$description_id."' ";
  203. api_sql_query($sql, __FILE__, __LINE__);
  204. } else {
  205. $result = api_sql_query($sql, __FILE__, __LINE__);
  206. $sql = "INSERT IGNORE INTO $tbl_course_description SET id = '".$description_id."', title = '".mysql_real_escape_string($title)."', content = '".mysql_real_escape_string($content)."'";
  207. api_sql_query($sql, __FILE__, __LINE__);
  208. }
  209. /*$sql = "SELECT id FROM $tbl_course_description WHERE id = ".ADD_BLOCK;
  210. $result = api_sql_query($sql, __FILE__, __LINE__);
  211. if (Database::num_rows($result)>0){
  212. $sqldel = "DELETE FROM $tbl_course_description WHERE id = ".ADD_BLOCK;
  213. $resultdel = api_sql_query($sqldel,__FILE__,__LINE__);
  214. }
  215. $sqlins = "INSERT INTO $tbl_course_description SET id = '".$description_id."', title = '".Database::escape_string($title)."', content = '".Database::escape_string($content)."'";
  216. api_sql_query($sqlins, __FILE__, __LINE__);*/
  217. } else {
  218. if (!$default_description_title_editable[$description_id]) {
  219. $title = $default_description_titles[$description_id];
  220. }
  221. $sql = "DELETE FROM $tbl_course_description WHERE id = '".$description_id."'";
  222. api_sql_query($sql, __FILE__, __LINE__);
  223. $sql = "INSERT IGNORE INTO $tbl_course_description SET id = '".$description_id."', title = '".mysql_real_escape_string($title)."', content = '".mysql_real_escape_string($content)."'";
  224. api_sql_query($sql, __FILE__, __LINE__);
  225. }
  226. Display :: display_confirmation_message(get_lang('CourseDescriptionUpdated'));
  227. }
  228. // Show the form
  229. else {
  230. if ($show_peda_suggest) {
  231. if (isset ($question[$description_id])) {
  232. $message = '<strong>'.get_lang('QuestionPlan').'</strong><br />';
  233. $message .= $question[$description_id];
  234. Display::display_normal_message($message, false);
  235. }
  236. }
  237. if (api_get_setting('wcag_anysurfer_public_pages')=='true') {
  238. echo (WCAG_Rendering::editor_header());
  239. }
  240. $form->display();
  241. if (api_get_setting('wcag_anysurfer_public_pages')=='true') {
  242. echo (WCAG_Rendering::editor_footer());
  243. }
  244. $show_description_list = false;
  245. }
  246. }
  247. }
  248. // Show the list of all description blocks
  249. if ($show_description_list) {
  250. $sql = "SELECT * FROM $tbl_course_description ORDER BY id";
  251. $result = api_sql_query($sql, __FILE__, __LINE__);
  252. $descriptions;
  253. while ($description = mysql_fetch_object($result)) {
  254. $descriptions[$description->id] = $description;
  255. }
  256. if (api_is_allowed_to_edit()) {
  257. $categories = array ();
  258. foreach ($default_description_titles as $id => $title) {
  259. $categories[$id] = $title;
  260. }
  261. $categories[ADD_BLOCK] = get_lang('NewBloc');
  262. $i=1;
  263. echo '<div class="actions">';
  264. foreach ($categories as $id => $title) {
  265. if ($i==8) {
  266. echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&action=add">'.Display::return_icon($default_description_icon[$id], $title, array('height'=>'20')).' '.$title.'</a>';
  267. } else {
  268. echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&description_id='.$id.'">'.Display::return_icon($default_description_icon[$id], $title, array('height'=>'20')).' '.$title.'</a>';
  269. $i++;
  270. }
  271. }
  272. echo '</div>';
  273. }
  274. if (isset($descriptions) && count($descriptions) > 0) {
  275. foreach ($descriptions as $id => $description) {
  276. echo '<div class="sectiontitle">';
  277. if (api_is_allowed_to_edit()) {
  278. //delete
  279. echo '<a href="'.api_get_self().'?action=delete&amp;description_id='.$description->id.'" onclick="javascript:if(!confirm(\''.addslashes(htmlentities(get_lang('ConfirmYourChoice'),ENT_QUOTES,$charset)).'\')) return false;">';
  280. echo Display::return_icon('delete.gif', get_lang('Delete'), array('style' => 'vertical-align:middle;float:right;'));
  281. echo '</a> ';
  282. //edit
  283. echo '<a href="'.api_get_self().'?action=edit&amp;description_id='.$description->id.'">';
  284. echo Display::return_icon('edit.gif', get_lang('Edit'), array('style' => 'vertical-align:middle;float:right;'));
  285. echo '</a> ';
  286. }
  287. echo $description->title;
  288. echo '</div>';
  289. echo '<div class="sectioncomment">';
  290. echo text_filter($description->content);
  291. echo '</div>';
  292. }
  293. } else {
  294. echo '<em>'.get_lang('ThisCourseDescriptionIsEmpty').'</em>';
  295. }
  296. }
  297. /*
  298. ==============================================================================
  299. FOOTER
  300. ==============================================================================
  301. */
  302. Display :: display_footer();
  303. ?>