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