コード例 #1
0
 * A page for detailed preview or edition of a given course request.
 * @package chamilo.admin
 * @author Ivan Tcholakov <*****@*****.**>, 2010
 */
$cidReset = true;
$this_section = SECTION_PLATFORM_ADMIN;
$tool_name = get_lang('CourseRequestEdit');
api_protect_admin_script();
// A check whether the course validation feature is enabled.
$course_validation_feature = api_get_setting('course.course_validation') == 'true';
// Filltering passed to this page parameters.
$id = intval($_GET['id']);
$caller = intval($_GET['caller']);
if ($course_validation_feature) {
    // Retrieve request's data from the corresponding database record.
    $course_request_info = CourseRequestManager::get_course_request_info($id);
    if (!is_array($course_request_info)) {
        // Prepare an error message notifying that the course request has not been found or does not exist.
        $message = get_lang('CourseRequestHasNotBeenFound');
        $is_error_message = true;
    } else {
        // Ensure the database prefix + database name do not get over 40 characters.
        $maxlength = 40;
        // Build the form.
        $form = new FormValidator('add_course', 'post', 'course_request_edit.php?id=' . $id . '&caller=' . $caller);
        // Form title.
        $form->addElement('header', $tool_name);
        // Title.
        $form->addElement('text', 'title', get_lang('CourseName'), array('size' => '60', 'id' => 'title'));
        $form->applyFilter('title', 'html_filter');
        $form->addRule('title', get_lang('ThisFieldIsRequired'), 'required');
コード例 #2
0
 /**
  * @Route("/add_course", name="add_course")
  * @Method({"GET|POST"})
  * @Security("has_role('ROLE_USER')")
  *
  * @return Response
  */
 public function addCourseAction()
 {
     // "Course validation" feature. This value affects the way of a new course creation:
     // true  - the new course is requested only and it is created after approval;
     // false - the new course is created immediately, after filling this form.
     $courseValidation = false;
     if (api_get_setting('course.course_validation') == 'true' && !api_is_platform_admin()) {
         $courseValidation = true;
     }
     // Displaying the header.
     $tool_name = $courseValidation ? get_lang('CreateCourseRequest') : get_lang('CreateSite');
     if (api_get_setting('course.allow_users_to_create_courses') == 'false' && !api_is_platform_admin()) {
         api_not_allowed(true);
     }
     // Check access rights.
     if (!api_is_allowed_to_create_course()) {
         api_not_allowed(true);
     }
     $url = $this->generateUrl('add_course');
     // Build the form.
     $form = new \FormValidator('add_course', 'post', $url);
     // Form title
     $form->addElement('header', $tool_name);
     // Title
     $form->addElement('text', 'title', array(get_lang('CourseName'), get_lang('Ex')), array('id' => 'title'));
     $form->applyFilter('title', 'html_filter');
     $form->addRule('title', get_lang('ThisFieldIsRequired'), 'required');
     $form->addButtonAdvancedSettings('advanced_params');
     $form->addElement('html', '<div id="advanced_params_options" style="display:none">');
     // Category category.
     $url = api_get_path(WEB_AJAX_PATH) . 'course.ajax.php?a=search_category';
     $form->addElement('select_ajax', 'category_code', get_lang('CourseFaculty'), null, array('url' => $url));
     // Course code
     $form->addText('wanted_code', array(get_lang('Code'), get_lang('OnlyLettersAndNumbers')), '', array('maxlength' => \CourseManager::MAX_COURSE_LENGTH_CODE, 'pattern' => '[a-zA-Z0-9]+', 'title' => get_lang('OnlyLettersAndNumbers')));
     $form->applyFilter('wanted_code', 'html_filter');
     $form->addRule('wanted_code', get_lang('Max'), 'maxlength', \CourseManager::MAX_COURSE_LENGTH_CODE);
     // The teacher
     //array(get_lang('Professor'), null), null, array('size' => '60', 'disabled' => 'disabled'));
     $titular =& $form->addElement('hidden', 'tutor_name', '');
     if ($courseValidation) {
         // Description of the requested course.
         $form->addElement('textarea', 'description', get_lang('Description'), array('rows' => '3'));
         // Objectives of the requested course.
         $form->addElement('textarea', 'objetives', get_lang('Objectives'), array('rows' => '3'));
         // Target audience of the requested course.
         $form->addElement('textarea', 'target_audience', get_lang('TargetAudience'), array('rows' => '3'));
     }
     // Course language.
     $form->addElement('select_language', 'course_language', get_lang('Ln'), array(), array('style' => 'width:150px'));
     $form->applyFilter('select_language', 'html_filter');
     // Exemplary content checkbox.
     $form->addElement('checkbox', 'exemplary_content', null, get_lang('FillWithExemplaryContent'));
     if ($courseValidation) {
         // A special URL to terms and conditions that is set
         // in the platform settings page.
         $terms_and_conditions_url = trim(api_get_setting('course_validation_terms_and_conditions_url'));
         // If the special setting is empty,
         // then we may get the URL from Chamilo's module "Terms and conditions",
         // if it is activated.
         if (empty($terms_and_conditions_url)) {
             if (api_get_setting('registration.allow_terms_conditions') == 'true') {
                 $terms_and_conditions_url = api_get_path(WEB_CODE_PATH);
                 $terms_and_conditions_url .= 'auth/inscription.php?legal';
             }
         }
         if (!empty($terms_and_conditions_url)) {
             // Terms and conditions to be accepted before sending a course request.
             $form->addElement('checkbox', 'legal', null, get_lang('IAcceptTermsAndConditions'), 1);
             $form->addRule('legal', get_lang('YouHaveToAcceptTermsAndConditions'), 'required');
             // Link to terms and conditions.
             $link_terms_and_conditions = '
                 <script>
                 function MM_openBrWindow(theURL, winName, features) { //v2.0
                     window.open(theURL,winName,features);
                 }
                 </script>
             ';
             $link_terms_and_conditions .= \Display::url(get_lang('ReadTermsAndConditions'), '#', ['onclick' => "javascript:MM_openBrWindow('{$terms_and_conditions_url}', 'Conditions', 'scrollbars=yes, width=800');"]);
             $form->addElement('label', null, $link_terms_and_conditions);
         }
     }
     $obj = new \GradeModel();
     $obj->fill_grade_model_select_in_form($form);
     $form->addElement('html', '</div>');
     // Submit button.
     $form->addButtonCreate($courseValidation ? get_lang('CreateThisCourseRequest') : get_lang('CreateCourseArea'));
     // Set default values.
     if (isset($_user['language']) && $_user['language'] != '') {
         $values['course_language'] = $_user['language'];
     } else {
         $values['course_language'] = api_get_setting('language.platform_language');
     }
     $form->setDefaults($values);
     $message = null;
     $content = null;
     // Validate the form.
     if ($form->validate()) {
         $course_values = $form->exportValues();
         $wanted_code = $course_values['wanted_code'];
         //$category_code = $course_values['category_code'];
         $category_code = '';
         $title = $course_values['title'];
         $course_language = $course_values['course_language'];
         $exemplary_content = !empty($course_values['exemplary_content']);
         if ($courseValidation) {
             $description = $course_values['description'];
             $objetives = $course_values['objetives'];
             $target_audience = $course_values['target_audience'];
         }
         if ($wanted_code == '') {
             $wanted_code = \CourseManager::generate_course_code(api_substr($title, 0, \CourseManager::MAX_COURSE_LENGTH_CODE));
         }
         // Check whether the requested course code has already been occupied.
         if (!$courseValidation) {
             $course_code_ok = !\CourseManager::course_code_exists($wanted_code);
         } else {
             $course_code_ok = !\CourseRequestManager::course_code_exists($wanted_code);
         }
         if ($course_code_ok) {
             if (!$courseValidation) {
                 $params = array();
                 $params['title'] = $title;
                 $params['exemplary_content'] = $exemplary_content;
                 $params['wanted_code'] = $wanted_code;
                 $params['course_category'] = $category_code;
                 $params['course_language'] = $course_language;
                 $params['gradebook_model_id'] = isset($course_values['gradebook_model_id']) ? $course_values['gradebook_model_id'] : null;
                 $course_info = \CourseManager::create_course($params);
                 if (!empty($course_info)) {
                     $url = api_get_path(WEB_CODE_PATH);
                     $url .= 'course_info/start.php?cidReq=';
                     $url .= $course_info['code'];
                     $url .= '&first=1';
                     header('Location: ' . $url);
                     exit;
                 } else {
                     $this->addFlash('error', $this->trans('CourseCreationFailed'));
                     // Display the form.
                     $content = $form->returnForm();
                 }
             } else {
                 // Create a request for a new course.
                 $request_id = \CourseRequestManager::create_course_request($wanted_code, $title, $description, $category_code, $course_language, $objetives, $target_audience, api_get_user_id(), $exemplary_content);
                 if ($request_id) {
                     $course_request_info = \CourseRequestManager::get_course_request_info($request_id);
                     $message = (is_array($course_request_info) ? '<strong>' . $course_request_info['code'] . '</strong> : ' : '') . get_lang('CourseRequestCreated');
                     \Display::return_message($message, 'confirmation', false);
                     \Display::return_message('div', \Display::url(get_lang('Enter'), api_get_path(WEB_PATH) . 'user_portal.php', ['class' => 'btn btn-default']), ['style' => 'float: left; margin:0px; padding: 0px;']);
                 } else {
                     \Display::return_message(get_lang('CourseRequestCreationFailed'), 'error', false);
                     // Display the form.
                     $content = $form->returnForm();
                 }
             }
         } else {
             \Display::return_message(get_lang('CourseCodeAlreadyExists'), 'error', false);
             // Display the form.
             $content = $form->returnForm();
         }
     } else {
         if (!$courseValidation) {
             $this->addFlash('warning', get_lang('Explanation'));
         }
         // Display the form.
         $content = $form->returnForm();
     }
     return $this->render('ChamiloCoreBundle:Index:userportal.html.twig', array('content' => $content));
 }