index.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. <?php // $Id: index.php 22253 2009-07-20 17:03:48Z ivantcholakov $
  2. /* For licensing terms, see /dokeos_license.txt */
  3. /**
  4. ==============================================================================
  5. * This script edits the course description.
  6. * This script is reserved for users with write access on the course.
  7. *
  8. * @author Thomas Depraetere
  9. * @author Hugues Peeters
  10. * @author Christophe Gesché
  11. * @author Olivier brouckaert
  12. * @package dokeos.course_description
  13. ==============================================================================
  14. */
  15. /*
  16. ==============================================================================
  17. INIT SECTION
  18. ==============================================================================
  19. */
  20. // name of the language file that needs to be included
  21. $language_file = array ('course_description', 'pedaSuggest', 'accessibility');
  22. include '../inc/global.inc.php';
  23. $this_section = SECTION_COURSES;
  24. include api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php';
  25. include_once api_get_path(LIBRARY_PATH).'WCAG/WCAG_rendering.php';
  26. /*
  27. -----------------------------------------------------------
  28. Header
  29. -----------------------------------------------------------
  30. */
  31. $interbreadcrumb[] = array ("url" => "index.php", "name" => get_lang('CourseProgram'));
  32. $description_id = isset ($_REQUEST['description_id']) ? Security::remove_XSS($_REQUEST['description_id']) : null;
  33. $action = isset($_GET['action'])?Security::remove_XSS($_GET['action']):'';
  34. $edit = isset($_POST['edit'])?Security::remove_XSS($_POST['edit']):'';
  35. $add = isset($_POST['add'])?Security::remove_XSS($_POST['add']):'';
  36. if(intval($description_id) == 1) $interbreadcrumb[] = array ("url" => "#", "name" => get_lang('GeneralDescription'));
  37. if(intval($description_id) == 2) $interbreadcrumb[] = array ("url" => "#", "name" => get_lang('Objectives'));
  38. if(intval($description_id) == 3) $interbreadcrumb[] = array ("url" => "#", "name" => get_lang('Topics'));
  39. if(intval($description_id) == 4) $interbreadcrumb[] = array ("url" => "#", "name" => get_lang('Methodology'));
  40. if(intval($description_id) == 5) $interbreadcrumb[] = array ("url" => "#", "name" => get_lang('CourseMaterial'));
  41. if(intval($description_id) == 6) $interbreadcrumb[] = array ("url" => "#", "name" => get_lang('HumanAndTechnicalResources'));
  42. if(intval($description_id) == 7) $interbreadcrumb[] = array ("url" => "#", "name" => get_lang('Assessment'));
  43. if(intval($description_id) >= 8) $interbreadcrumb[] = array ("url" => "#", "name" => get_lang('NewBloc'));
  44. api_protect_course_script(true);
  45. $nameTools = get_lang('CourseProgram');
  46. Display :: display_header('');
  47. //api_display_tool_title($nameTools);
  48. /*
  49. -----------------------------------------------------------
  50. Constants and variables
  51. -----------------------------------------------------------
  52. */
  53. $nameTools = get_lang(TOOL_COURSE_DESCRIPTION);
  54. /*
  55. -----------------------------------------------------------
  56. Introduction section
  57. -----------------------------------------------------------
  58. */
  59. Display::display_introduction_section(TOOL_COURSE_DESCRIPTION);
  60. $tbl_course_description = Database::get_course_table(TABLE_COURSE_DESCRIPTION);
  61. $show_description_list = true;
  62. $show_peda_suggest = true;
  63. define('ADD_BLOCK', 8);
  64. // Default descriptions
  65. $default_description_titles = array();
  66. $default_description_titles[1]= get_lang('GeneralDescription');
  67. $default_description_titles[2]= get_lang('Objectives');
  68. $default_description_titles[3]= get_lang('Topics');
  69. $default_description_titles[4]= get_lang('Methodology');
  70. $default_description_titles[5]= get_lang('CourseMaterial');
  71. $default_description_titles[6]= get_lang('HumanAndTechnicalResources');
  72. $default_description_titles[7]= get_lang('Assessment');
  73. $default_description_titles[8]= get_lang('Other');
  74. $default_description_icon = array();
  75. $default_description_icon[1]= 'edu_miscellaneous.gif';
  76. $default_description_icon[2]= 'spire.gif';
  77. $default_description_icon[3]= 'kcmdf_big.gif';
  78. $default_description_icon[4]= 'misc.gif';
  79. $default_description_icon[5]= 'laptop.gif';
  80. $default_description_icon[6]= 'personal.gif';
  81. $default_description_icon[7]= 'korganizer.gif';
  82. $default_description_icon[8]= 'ktip.gif';
  83. $question = array();
  84. $question[1]= get_lang('GeneralDescriptionQuestions');
  85. $question[2]= get_lang('ObjectivesQuestions');
  86. $question[3]= get_lang('TopicsQuestions');
  87. $question[4]= get_lang('MethodologyQuestions');
  88. $question[5]= get_lang('CourseMaterialQuestions');
  89. $question[6]= get_lang('HumanAndTechnicalResourcesQuestions');
  90. $question[7]= get_lang('AssessmentQuestions');
  91. $information = array();
  92. $information[1]= get_lang('GeneralDescriptionInformation');
  93. $information[2]= get_lang('ObjectivesInformation');
  94. $information[3]= get_lang('TopicsInformation');
  95. $information[4]= get_lang('MethodologyInformation');
  96. $information[5]= get_lang('CourseMaterialInformation');
  97. $information[6]= get_lang('HumanAndTechnicalResourcesInformation');
  98. $information[7]= get_lang('AssessmentInformation');
  99. $default_description_title_editable = array();
  100. $default_description_title_editable[1] = true;
  101. $default_description_title_editable[2] = true;
  102. $default_description_title_editable[3] = true;
  103. $default_description_title_editable[4] = true;
  104. $default_description_title_editable[5] = true;
  105. $default_description_title_editable[6] = true;
  106. $default_description_title_editable[7] = true;
  107. /*
  108. ==============================================================================
  109. MAIN CODE
  110. ==============================================================================
  111. */
  112. if (api_is_allowed_to_edit() && !is_null($description_id) || $action =='add') {
  113. $description_id = intval($description_id);
  114. // Delete a description block
  115. if ($action == 'delete') {
  116. $sql = "DELETE FROM $tbl_course_description WHERE id='".$description_id."'";
  117. api_sql_query($sql, __FILE__, __LINE__);
  118. Display :: display_confirmation_message(get_lang('CourseDescriptionDeleted'));
  119. }
  120. // Add or edit a description block
  121. else {
  122. if (!empty($description_id)) {
  123. $sql = "SELECT * FROM $tbl_course_description WHERE id='".$description_id."'";
  124. $result = api_sql_query($sql, __FILE__, __LINE__);
  125. if ($description = Database::fetch_array($result)) {
  126. $default_description_titles[$description_id] = $description['title'];
  127. $description_content = $description['content'];
  128. } else {
  129. $current_title = $default_description_titles[$description_id];
  130. }
  131. } else {
  132. $sql = "SELECT MAX(id) as MAX FROM $tbl_course_description ";
  133. $result = api_sql_query($sql, __FILE__, __LINE__);
  134. $max= Database::fetch_array($result);
  135. $description_id = $max['MAX']+1;
  136. if ($description_id < ADD_BLOCK) {
  137. $description_id=8;
  138. }
  139. }
  140. //Se borro: echo ' <style> .row{} <\style> por que hacia conflicto en apartado personalizado con los estilos propios del formvalidator
  141. // Build the form
  142. $form = new FormValidator('course_description','POST','index.php?'.api_get_cidreq(),'','style="width: 100%;"');
  143. $form->addElement('header', '', $default_description_titles[$description_id]);
  144. $form->addElement('hidden', 'description_id');
  145. if ($action == 'edit' || intval($edit) == 1 ) {
  146. $form->addElement('hidden', 'edit','1');
  147. }
  148. if ($action == 'add' || intval($add) == 1 ) {
  149. $form->addElement('hidden', 'add','1');
  150. }
  151. if (($description_id >= ADD_BLOCK) || $default_description_title_editable[$description_id] || $action == 'add' || intval($edit) == 1) {
  152. $form->add_textfield('title', get_lang('Title'), true, array('size'=>'width: 350px;'));
  153. $form->applyFilter('title','html_filter');
  154. }
  155. if (api_get_setting('wcag_anysurfer_public_pages')=='true') {
  156. WCAG_rendering::prepare_admin_form($description_content, $form);
  157. } else {
  158. $form->add_html_editor('contentDescription', get_lang('Content'), true, false, array('ToolbarSet' => 'TrainingDescription', 'Width' => '100%', 'Height' => '200'));
  159. }
  160. $form->addElement('style_submit_button', null, get_lang('Save'), 'class="save"');
  161. // Set some default values
  162. $default['title'] = $default_description_titles[$description_id];
  163. $default['contentDescription'] = $description_content;
  164. $default['description_id'] = $description_id;
  165. //if ($description_id >= ADD_BLOCK) {
  166. //$default['description_id'] = ADD_BLOCK;
  167. //}
  168. $form->setDefaults($default);
  169. // If form validates: save the description block
  170. if ($form->validate()) {
  171. $description = $form->exportValues();
  172. if (api_get_setting('wcag_anysurfer_public_pages')=='true') {
  173. $content = WCAG_Rendering::prepareXHTML();
  174. } else {
  175. $content = $description['contentDescription'];
  176. }
  177. $title = $description['title'];
  178. if ($description['description_id'] >= ADD_BLOCK) {
  179. if ($description['add']=='1') { //if this element has been submitted for addition
  180. $result = api_sql_query($sql, __FILE__, __LINE__);
  181. $sql = "INSERT IGNORE INTO $tbl_course_description SET id = '".$description_id."', title = '".Database::escape_string(Security::remove_XSS($title,COURSEMANAGERLOWSECURITY))."', content = '".Database::escape_string(Security::remove_XSS($content,COURSEMANAGERLOWSECURITY))."'";
  182. api_sql_query($sql, __FILE__, __LINE__);
  183. } else {
  184. $sql = "UPDATE $tbl_course_description SET title = '".Database::escape_string(Security::remove_XSS($title,COURSEMANAGERLOWSECURITY))."', content = '".Database::escape_string(Security::remove_XSS($content,COURSEMANAGERLOWSECURITY))."' WHERE id = '".$description_id."' ";
  185. api_sql_query($sql, __FILE__, __LINE__);
  186. }
  187. } else {
  188. //if title is not editable, then use default title
  189. if (!$default_description_title_editable[$description_id]) {
  190. $title = $default_description_titles[$description_id];
  191. }
  192. $sql = "DELETE FROM $tbl_course_description WHERE id = '".$description_id."'";
  193. api_sql_query($sql, __FILE__, __LINE__);
  194. $sql = "INSERT INTO $tbl_course_description SET id = '".$description_id."', title = '".Database::escape_string(Security::remove_XSS($title,COURSEMANAGERLOWSECURITY))."', content = '".Database::escape_string(Security::remove_XSS($content,COURSEMANAGERLOWSECURITY))."'";
  195. api_sql_query($sql, __FILE__, __LINE__);
  196. }
  197. Display :: display_confirmation_message(get_lang('CourseDescriptionUpdated'));
  198. }
  199. // Show the form
  200. else {
  201. // menu top
  202. //***********************************
  203. if (api_is_allowed_to_edit()) {
  204. $categories = array ();
  205. foreach ($default_description_titles as $id => $title) {
  206. $categories[$id] = $title;
  207. }
  208. $categories[ADD_BLOCK] = get_lang('NewBloc');
  209. $i=1;
  210. echo '<div class="actions">';
  211. ksort($categories);
  212. foreach ($categories as $id => $title) {
  213. if ($i==8) {
  214. echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&action=add">'.Display::return_icon($default_description_icon[$id], $title, array('height'=>'22')).' '.$title.'</a>';
  215. break;
  216. } else {
  217. echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&description_id='.$id.'">'.Display::return_icon($default_description_icon[$id], $title, array('height'=>'22')).' '.$title.'</a>&nbsp;&nbsp;';
  218. $i++;
  219. }
  220. }
  221. echo '</div>';
  222. }
  223. //***********************************
  224. if ($show_peda_suggest) {
  225. if (isset ($question[$description_id])) {
  226. $message = '<strong>'.get_lang('QuestionPlan').'</strong><br />';
  227. $message .= $question[$description_id];
  228. Display::display_normal_message($message, false);
  229. }
  230. }
  231. if (api_get_setting('wcag_anysurfer_public_pages')=='true') {
  232. echo (WCAG_Rendering::editor_header());
  233. }
  234. $form->display();
  235. if (api_get_setting('wcag_anysurfer_public_pages')=='true') {
  236. echo (WCAG_Rendering::editor_footer());
  237. }
  238. $show_description_list = false;
  239. }
  240. }
  241. }
  242. // Show the list of all description blocks
  243. if ($show_description_list) {
  244. $sql = "SELECT * FROM $tbl_course_description ORDER BY id";
  245. $result = api_sql_query($sql, __FILE__, __LINE__);
  246. $descriptions;
  247. while ($description = Database::fetch_object($result)) {
  248. $descriptions[$description->id] = $description;
  249. }
  250. if (api_is_allowed_to_edit()) {
  251. $categories = array ();
  252. foreach ($default_description_titles as $id => $title) {
  253. $categories[$id] = $title;
  254. }
  255. $categories[ADD_BLOCK] = get_lang('NewBloc');
  256. $i=1;
  257. echo '<div class="actions" style="margin-bottom:30px">';
  258. ksort($categories);
  259. foreach ($categories as $id => $title) {
  260. if ($i==8) {
  261. echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&action=add">'.Display::return_icon($default_description_icon[$id], $title, array('height'=>'22')).' '.$title.'</a>';
  262. break;
  263. } else {
  264. echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&description_id='.$id.'">'.Display::return_icon($default_description_icon[$id], $title, array('height'=>'22')).' '.$title.'</a>&nbsp;&nbsp;';
  265. $i++;
  266. }
  267. }
  268. echo '</div>';
  269. }
  270. if (isset($descriptions) && count($descriptions) > 0) {
  271. foreach ($descriptions as $id => $description) {
  272. echo '<div class="sectiontitle">';
  273. if (api_is_allowed_to_edit()) {
  274. //delete
  275. echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;action=delete&amp;description_id='.$description->id.'" onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang('ConfirmYourChoice'),ENT_QUOTES,$charset)).'\')) return false;">';
  276. echo Display::return_icon('delete.gif', get_lang('Delete'), array('style' => 'vertical-align:middle;float:right;'));
  277. echo '</a> ';
  278. //edit
  279. echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;description_id='.$description->id.'">';
  280. echo Display::return_icon('edit.gif', get_lang('Edit'), array('style' => 'vertical-align:middle;float:right; padding-right:4px;'));
  281. echo '</a> ';
  282. }
  283. echo $description->title;
  284. echo '</div>';
  285. echo '<div class="sectioncomment">';
  286. echo text_filter($description->content);
  287. echo '</div>';
  288. }
  289. } else {
  290. echo '<em>'.get_lang('ThisCourseDescriptionIsEmpty').'</em>';
  291. }
  292. }
  293. /*
  294. ==============================================================================
  295. FOOTER
  296. ==============================================================================
  297. */
  298. Display :: display_footer();
  299. ?>