course_request_edit.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * A page for detailed preview or edition of a given course request.
  5. * @package chamilo.admin
  6. * @author Ivan Tcholakov <ivantcholakov@gmail.com>, 2010
  7. */
  8. // Initialization section.
  9. // Language files that need to be included.
  10. $language_file = array('admin', 'create_course');
  11. $cidReset = true;
  12. require '../inc/global.inc.php';
  13. $this_section = SECTION_PLATFORM_ADMIN;
  14. $tool_name = get_lang('CourseRequestEdit');
  15. api_protect_admin_script();
  16. // A check whether the course validation feature is enabled.
  17. $course_validation_feature = api_get_setting('course_validation') == 'true';
  18. // Filltering passed to this page parameters.
  19. $id = intval($_GET['id']);
  20. $caller = intval($_GET['caller']);
  21. if ($course_validation_feature) {
  22. // Retrieve request's data from the corresponding database record.
  23. $course_request_info = CourseRequestManager::get_course_request_info($id);
  24. if (!is_array($course_request_info)) {
  25. // Prepare an error message notifying that the course request has not been found or does not exist.
  26. $message = get_lang('CourseRequestHasNotBeenFound');
  27. $is_error_message = true;
  28. } else {
  29. global $_configuration;
  30. $dbnamelength = strlen($_configuration['db_prefix']);
  31. // Ensure the database prefix + database name do not get over 40 characters.
  32. $maxlength = 40 - $dbnamelength;
  33. // Build the form.
  34. $form = new FormValidator('add_course', 'post', 'course_request_edit.php?id='.$id.'&caller='.$caller);
  35. // Form title.
  36. $form->addElement('header', '', $tool_name);
  37. // Title.
  38. $form->addElement('text', 'title', get_lang('CourseName'), array('size' => '60', 'id' => 'title'));
  39. $form->applyFilter('title', 'html_filter');
  40. $form->addRule('title', get_lang('ThisFieldIsRequired'), 'required');
  41. // Course category.
  42. $categories_select = $form->addElement('select', 'category_code', get_lang('Fac'), array());
  43. $form->applyFilter('category_code', 'html_filter');
  44. CourseManager::select_and_sort_categories($categories_select);
  45. // Course code.
  46. $form->add_textfield('wanted_code', get_lang('Code'), false, array('size' => '$maxlength', 'maxlength' => $maxlength));
  47. $form->applyFilter('wanted_code', 'html_filter');
  48. $form->addRule('wanted_code', get_lang('Max'), 'maxlength', $maxlength);
  49. $form->addRule('wanted_code', get_lang('ThisFieldIsRequired'), 'required');
  50. // The teacher.
  51. $titular = $form->add_textfield('tutor_name', get_lang('Professor'), null, array('size' => '60', 'disabled' => 'disabled'));
  52. //$form->applyFilter('tutor_name', 'html_filter');
  53. // Description of the requested course.
  54. $form->addElement('textarea', 'description', get_lang('Description'), array('style' => 'border:#A5ACB2 solid 1px; font-family:arial,verdana,helvetica,sans-serif; font-size:12px', 'rows' => '3', 'cols' => '116'));
  55. $form->addRule('description', get_lang('ThisFieldIsRequired'), 'required');
  56. // Objectives of the requested course.
  57. $form->addElement('textarea', 'objetives', get_lang('Objectives'), array('style' => 'border:#A5ACB2 solid 1px; font-family:arial,verdana,helvetica,sans-serif; font-size:12px', 'rows' => '3', 'cols' => '116'));
  58. $form->addRule('objetives', get_lang('ThisFieldIsRequired'), 'required');
  59. // Target audience of the requested course.
  60. $form->addElement('textarea', 'target_audience', get_lang('TargetAudience'), array('style' => 'border:#A5ACB2 solid 1px; font-family:arial,verdana,helvetica,sans-serif; font-size:12px', 'rows' => '3', 'cols' => '116'));
  61. $form->addRule('target_audience', get_lang('ThisFieldIsRequired'), 'required');
  62. // Course language.
  63. $form->addElement('select_language', 'course_language', get_lang('Ln'));
  64. $form->applyFilter('select_language', 'html_filter');
  65. // Exemplary content checkbox.
  66. $form->addElement('checkbox', 'exemplary_content', get_lang('FillWithExemplaryContent'));
  67. // Submit buttons.
  68. $submit_buttons[] = FormValidator::createElement('style_submit_button', 'save_button', get_lang('Save'), array('class' => 'save'));
  69. if ($course_request_info['status'] != COURSE_REQUEST_ACCEPTED) {
  70. $submit_buttons[] = FormValidator::createElement('style_submit_button', 'accept_button', get_lang('Accept'), array('class' => 'save', 'style' => 'background-image: url('.api_get_path(WEB_IMG_PATH).'icons/16/accept.png);'));
  71. }
  72. if ($course_request_info['status'] != COURSE_REQUEST_ACCEPTED && $course_request_info['status'] != COURSE_REQUEST_REJECTED) {
  73. $submit_buttons[] = FormValidator::createElement('style_submit_button', 'reject_button', get_lang('Reject'), array('class' => 'save', 'style' => 'background-image: url('.api_get_path(WEB_IMG_PATH).'icons/16/error.png);'));
  74. }
  75. if ($course_request_info['status'] != COURSE_REQUEST_ACCEPTED && intval($course_request_info['info']) <= 0) {
  76. $submit_buttons[] = FormValidator::createElement('style_submit_button', 'ask_info_button', get_lang('AskAdditionalInfo'), array('class' => 'save', 'style' => 'background-image: url('.api_get_path(WEB_IMG_PATH).'request_info.gif);'));
  77. }
  78. $form->addGroup($submit_buttons);
  79. // Hidden form fields.
  80. $form->addElement('hidden', 'user_id');
  81. $form->addElement('hidden', 'directory');
  82. $form->addElement('hidden', 'db_name');
  83. $form->addElement('hidden', 'visual_code');
  84. $form->addElement('hidden', 'request_date');
  85. $form->addElement('hidden', 'status');
  86. $form->addElement('hidden', 'info');
  87. // Set the default values based on the corresponding database record.
  88. $values['wanted_code'] = $course_request_info['code'];
  89. $values['user_id'] = $course_request_info['user_id'];
  90. $values['directory'] = $course_request_info['directory'];
  91. $values['db_name'] = $course_request_info['db_name'];
  92. $values['course_language'] = $course_request_info['course_language'];
  93. $values['title'] = $course_request_info['title'];
  94. $values['description'] = $course_request_info['description'];
  95. $values['category_code'] = $course_request_info['category_code'];
  96. $values['tutor_name'] = $course_request_info['tutor_name'];
  97. $values['visual_code'] = $course_request_info['visual_code'];
  98. $values['request_date'] = $course_request_info['request_date'];
  99. $values['objetives'] = $course_request_info['objetives'];
  100. $values['target_audience'] = $course_request_info['target_audience'];
  101. $values['status'] = $course_request_info['status'];
  102. $values['info'] = $course_request_info['info'];
  103. $values['exemplary_content'] = $course_request_info['exemplary_content'];
  104. $form->setDefaults($values);
  105. // Validate the form and perform the ordered actions.
  106. if ($form->validate()) {
  107. $course_request_values = $form->exportValues();
  108. // Filter incoming data.
  109. foreach ($course_request_values as &$value) {
  110. $value = trim(Security::remove_XSS(stripslashes($value)));
  111. }
  112. // Detection which submit button has been pressed.
  113. $submit_button = isset($_POST['save_button']) ? 'save_button'
  114. : (isset($_POST['accept_button']) ? 'accept_button'
  115. : (isset($_POST['reject_button']) ? 'reject_button'
  116. : (isset($_POST['ask_info_button']) ? 'ask_info_button'
  117. : 'submit_button')));
  118. // Check the course code for avoiding duplication.
  119. $course_code_ok = $course_request_values['wanted_code'] == $course_request_info['code']
  120. ? true
  121. : !CourseRequestManager::course_code_exists($course_request_values['wanted_code']);
  122. if ($course_code_ok) {
  123. $message = array();
  124. $is_error_message = false;
  125. // Update the course request.
  126. $update_ok = CourseRequestManager::update_course_request($id,
  127. $course_request_values['wanted_code'],
  128. $course_request_values['title'],
  129. $course_request_values['description'],
  130. $course_request_values['category_code'],
  131. $course_request_values['course_language'],
  132. $course_request_values['objetives'],
  133. $course_request_values['target_audience'],
  134. $course_request_values['user_id'],
  135. $course_request_values['exemplary_content']
  136. );
  137. if ($update_ok) {
  138. $message[] = sprintf(get_lang(CourseRequestUpdated), $course_request_values['wanted_code']);
  139. switch ($submit_button) {
  140. case 'accept_button':
  141. if (CourseRequestManager::accept_course_request($id)) {
  142. $message[] = sprintf(get_lang('CourseRequestAccepted'), $course_request_values['wanted_code'], $course_request_values['wanted_code']);
  143. } else {
  144. $message[] = sprintf(get_lang('CourseRequestAcceptanceFailed'), $course_request_values['wanted_code']);
  145. $is_error_message = true;
  146. }
  147. break;
  148. case 'reject_button':
  149. if (CourseRequestManager::reject_course_request($id)) {
  150. $message[] = sprintf(get_lang('CourseRequestRejected'), $course_request_values['wanted_code']);
  151. } else {
  152. $message[] = sprintf(get_lang('CourseRequestRejectionFailed'), $course_request_values['wanted_code']);
  153. $is_error_message = true;
  154. }
  155. break;
  156. case 'ask_info_button':
  157. if (CourseRequestManager::ask_for_additional_info($id)) {
  158. $message[] = sprintf(get_lang('CourseRequestInfoAsked'), $course_request_values['wanted_code']);
  159. } else {
  160. $message[] = sprintf(get_lang('CourseRequestInfoFailed'), $course_request_values['wanted_code']);
  161. $is_error_message = true;
  162. }
  163. break;
  164. }
  165. // Line of code for testing purposes, to be removed
  166. //$message = 'The button "'.$submit_button.'" has been pressed.';
  167. } else {
  168. $message[] = sprintf(get_lang(CourseRequestUpdateFailed), $course_request_values['wanted_code']);
  169. $is_error_message = true;
  170. }
  171. $message = implode(' ', $message);
  172. $back_url = get_caller_name($caller);
  173. if ($message != '') {
  174. $back_url = api_add_url_param($back_url, 'message='.urlencode(Security::remove_XSS($message)), false);
  175. }
  176. if ($is_error_message) {
  177. $back_url = api_add_url_param($back_url, 'is_error_message=1', false);
  178. }
  179. header('location:'.$back_url);
  180. } else {
  181. $message = $course_request_values['wanted_code'].' - '.get_lang('CourseCodeAlreadyExists');
  182. $is_error_message = true;
  183. }
  184. }
  185. }
  186. } else {
  187. // Prepare an error message notifying that the course validation feature has not been enabled.
  188. $link_to_setting = api_get_path(WEB_CODE_PATH).'admin/settings.php?category=Platform#course_validation';
  189. $message = sprintf(get_lang('PleaseActivateCourseValidationFeature'), sprintf('<strong><a href="%s">%s</a></strong>', $link_to_setting, get_lang('EnableCourseValidation')));
  190. $is_error_message = true;
  191. }
  192. // Functions.
  193. // Converts the given numerical id to the name of the page that opened this editor.
  194. function get_caller_name($caller_id) {
  195. switch ($caller_id) {
  196. case 1:
  197. return 'course_request_accepted.php';
  198. case 2:
  199. return 'course_request_rejected.php';
  200. }
  201. return 'course_request_review.php';
  202. }
  203. // The header.
  204. $interbreadcrumb[] = array('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));
  205. $interbreadcrumb[] = array('url' => 'course_list.php', 'name' => get_lang('CourseList'));
  206. Display :: display_header($tool_name);
  207. // Display confirmation or error message.
  208. if (!empty($message)) {
  209. if ($is_error_message) {
  210. Display::display_error_message($message, false);
  211. } else {
  212. Display::display_normal_message($message, false);
  213. }
  214. }
  215. if (!$course_validation_feature) {
  216. // Disabled course validation feature - show nothing after the error message.
  217. Display :: display_footer();
  218. exit;
  219. }
  220. // The action bar.
  221. echo '<div class="actions">';
  222. echo '<a href="course_list.php">'.Display::return_icon('courses.gif', get_lang('CourseList')).get_lang('CourseList').'</a>';
  223. echo '<a href="course_request_review.php">'.Display::return_icon('course_request_pending.png', get_lang('ReviewCourseRequests')).get_lang('ReviewCourseRequests').'</a>';
  224. echo '<a href="course_request_accepted.php">'.Display::return_icon('course_request_accepted.gif', get_lang('AcceptedCourseRequests')).get_lang('AcceptedCourseRequests').'</a>';
  225. echo '<a href="course_request_rejected.php">'.Display::return_icon('course_request_rejected.gif', get_lang('RejectedCourseRequests')).get_lang('RejectedCourseRequests').'</a>';
  226. echo '</div>';
  227. if (!is_array($course_request_info)) {
  228. // Not accessible database record - show the error message and the action bar.
  229. Display :: display_footer();
  230. exit;
  231. }
  232. // Display the form.
  233. $form->display();
  234. // The footer.
  235. Display :: display_footer();