Ejemplo n.º 1
0
$group[] = $form->createElement('radio', 'visibility', null, get_lang('Private'), COURSE_VISIBILITY_REGISTERED);
$group[] = $form->createElement('radio', 'visibility', null, get_lang('CourseVisibilityClosed'), COURSE_VISIBILITY_CLOSED);
$group[] = $form->createElement('radio', 'visibility', null, get_lang('CourseVisibilityHidden'), COURSE_VISIBILITY_HIDDEN);
$form->addGroup($group, '', get_lang('CourseAccess'), '<br />');
$group = array();
$group[] = $form->createElement('radio', 'subscribe', get_lang('Subscription'), get_lang('Allowed'), 1);
$group[] = $form->createElement('radio', 'subscribe', null, get_lang('Denied'), 0);
$form->addGroup($group, '', get_lang('Subscription'), '<br />');
$group = array();
$group[] = $form->createElement('radio', 'unsubscribe', get_lang('Unsubscription'), get_lang('AllowedToUnsubscribe'), 1);
$group[] = $form->createElement('radio', 'unsubscribe', null, get_lang('NotAllowedToUnsubscribe'), 0);
$form->addGroup($group, '', get_lang('Unsubscription'), '<br />');
$form->addElement('text', 'disk_quota', array(get_lang('CourseQuota'), null, get_lang('MB')));
$form->addRule('disk_quota', get_lang('ThisFieldShouldBeNumeric'), 'numeric');
$obj = new GradeModel();
$obj->fill_grade_model_select_in_form($form);
//Extra fields
$extra_field = new ExtraField('course');
$extra = $extra_field->addElements($form);
$htmlHeadXtra[] = '
<script>

$(function() {
    ' . $extra['jquery_ready_content'] . '
});
</script>';
$form->add_progress_bar();
$form->addButtonCreate(get_lang('CreateCourse'));
// Set some default values.
$values['course_language'] = api_get_setting('platformLanguage');
$values['disk_quota'] = round(api_get_setting('default_document_quotum') / 1024 / 1024, 1);
Ejemplo n.º 2
0
}
if (isset($first_time) && $first_time == 1 && api_is_allowed_to_edit(null, true)) {
    echo '<meta http-equiv="refresh" content="0;url=' . api_get_self() . '?cidReq=' . $course_code . '" />';
} else {
    $cats = Category::load(null, null, $course_code, null, null, $session_id, false);
    if (!empty($cats)) {
        if (api_get_setting('gradebook.gradebook_enable_grade_model') == 'true' && (api_is_platform_admin() || api_is_allowed_to_edit(null, true) && api_get_setting('gradebook.teachers_can_change_grade_model_settings') == 'true')) {
            // Getting grade models.
            $obj = new GradeModel();
            $grade_models = $obj->get_all();
            $grade_model_id = $cats[0]->get_grade_model_id();
            // No children.
            if (count($cats) == 1 && empty($grade_model_id) || count($cats) == 1 && $grade_model_id != -1) {
                if (!empty($grade_models)) {
                    $form_grade = new FormValidator('grade_model_settings');
                    $obj->fill_grade_model_select_in_form($form_grade, 'grade_model_id', $grade_model_id);
                    $form_grade->addButtonSave(get_lang('Save'));
                    if ($form_grade->validate()) {
                        $value = $form_grade->exportValue('grade_model_id');
                        $gradebook = new Gradebook();
                        $gradebook->update(array('id' => $cats[0]->get_id(), 'grade_model_id' => $value), true);
                        //do something
                        $obj = new GradeModel();
                        $components = $obj->get_components($value);
                        foreach ($components as $component) {
                            $gradebook = new Gradebook();
                            $params = array();
                            $params['name'] = $component['acronym'];
                            $params['description'] = $component['title'];
                            $params['user_id'] = api_get_user_id();
                            $params['parent_id'] = $cats[0]->get_id();
Ejemplo n.º 3
0
 /**
  *
  */
 private function build_basic_form()
 {
     $this->addElement('hidden', 'zero', 0);
     $this->addText('name', get_lang('CategoryName'), true, array('maxlength' => '50'));
     $this->addRule('name', get_lang('ThisFieldIsRequired'), 'required');
     if (isset($this->category_object) && $this->category_object->get_parent_id() == 0) {
         //we can't change the root category
         $this->freeze('name');
     }
     $global_weight = api_get_setting('gradebook.gradebook_default_weight');
     if (isset($global_weight)) {
         $value = $global_weight;
     } else {
         $value = 100;
     }
     $this->addText('weight', array(get_lang('TotalWeight'), get_lang('TotalSumOfWeights')), true, array('value' => $value, 'class' => 'span1', 'maxlength' => '5'));
     $this->addRule('weight', get_lang('ThisFieldIsRequired'), 'required');
     $skillsDefaults = [];
     if (api_is_platform_admin() || api_is_drh()) {
         if (api_get_setting('skill.allow_skills_tool') == 'true') {
             $skillSelect = $this->addElement('select_ajax', 'skills', array(get_lang('Skills'), get_lang('SkillsAchievedWhenAchievingThisGradebook')), null, ['id' => 'skills', 'multiple' => 'multiple', 'url' => api_get_path(WEB_AJAX_PATH) . 'skill.ajax.php?a=search_skills']);
             // The magic should be here
             $skills = $this->category_object->get_skills();
             foreach ($skills as $skill) {
                 $skillsDefaults[] = $skill['id'];
                 $skillSelect->addOption($skill['name'], $skill['id']);
             }
         }
     }
     if (isset($this->category_object) && $this->category_object->get_parent_id() == 0) {
         $this->addText('certif_min_score', get_lang('CertificateMinScore'), false, array('class' => 'span1', 'maxlength' => '5'));
         $this->addRule('certif_min_score', get_lang('ThisFieldIsRequired'), 'required');
         $this->addRule('certif_min_score', get_lang('OnlyNumbers'), 'numeric');
         $this->addRule(array('certif_min_score', 'zero'), get_lang('NegativeValue'), 'compare', '>=');
     } else {
         $this->addElement('checkbox', 'visible', null, get_lang('Visible'));
     }
     $this->addElement('hidden', 'hid_user_id');
     $this->addElement('hidden', 'hid_parent_id');
     $this->addElement('textarea', 'description', get_lang('Description'));
     if (isset($this->category_object) && $this->category_object->get_parent_id() == 0 && (api_is_platform_admin() || api_get_setting('gradebook.teachers_can_change_grade_model_settings') == 'true')) {
         //Getting grade models
         $obj = new GradeModel();
         $obj->fill_grade_model_select_in_form($this, 'grade_model_id', $this->category_object->get_grade_model_id());
         // Freeze or not
         $course_code = api_get_course_id();
         $session_id = api_get_session_id();
         $test_cats = Category::load(null, null, $course_code, null, null, $session_id, false);
         //already init
         $links = null;
         if (!empty($test_cats[0])) {
             $links = $test_cats[0]->get_links();
         }
         if (count($test_cats) > 1 || !empty($links)) {
             if (api_get_setting('gradebook.gradebook_enable_grade_model') == 'true') {
                 $this->freeze('grade_model_id');
             }
         }
         $generateCertificatesParams = array();
         if ($this->category_object->getGenerateCertificates()) {
             $generateCertificatesParams['checked'] = 'checked';
         }
         $this->addElement('checkbox', 'generate_certificates', null, get_lang('GenerateCertificates'), $generateCertificatesParams);
     }
     if (!empty($session_id)) {
         $isRequirementCheckbox = $this->addCheckBox('is_requirement', [null, get_lang('ConsiderThisGradebookAsRequirementForASessionSequence')], get_lang('IsRequirement'));
     }
     if ($this->category_object->getIsRequirement()) {
         $isRequirementCheckbox->setChecked(true);
     }
     if ($this->form_type == self::TYPE_ADD) {
         $this->addButtonCreate(get_lang('AddCategory'));
     } else {
         $this->addElement('hidden', 'editcat', intval($_GET['editcat']));
         $this->addButtonUpdate(get_lang('EditCategory'));
     }
     $this->addRule('weight', get_lang('OnlyNumbers'), 'numeric');
     $this->addRule(array('weight', 'zero'), get_lang('NegativeValue'), 'compare', '>=');
     $setting = api_get_setting('document.tool_visible_by_default_at_creation');
     $visibility_default = 1;
     if (isset($setting['gradebook']) && $setting['gradebook'] == 'false') {
         $visibility_default = 0;
     }
     $this->setDefaults(array('visible' => $visibility_default, 'skills' => $skillsDefaults));
 }
Ejemplo n.º 4
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));
 }
Ejemplo n.º 5
0
 /**
  *
  */
 private function build_basic_form()
 {
     $this->addElement('hidden', 'zero', 0);
     $this->add_textfield('name', get_lang('CategoryName'), true, array('class' => 'span3', 'maxlength' => '50'));
     $this->addRule('name', get_lang('ThisFieldIsRequired'), 'required');
     if (isset($this->category_object) && $this->category_object->get_parent_id() == 0) {
         //we can't change the root category
         $this->freeze('name');
     }
     $global_weight = api_get_setting('gradebook_default_weight');
     if (isset($global_weight)) {
         $value = $global_weight;
     } else {
         $value = 100;
     }
     $this->add_textfield('weight', array(get_lang('TotalWeight'), get_lang('TotalSumOfWeights')), true, array('value' => $value, 'class' => 'span1', 'maxlength' => '5'));
     $this->addRule('weight', get_lang('ThisFieldIsRequired'), 'required');
     if (api_is_platform_admin() || api_is_drh()) {
         if (api_get_setting('allow_skills_tool') == 'true') {
             // The magic should be here
             $skills = $this->category_object->get_skills();
             $skillToSelect = array();
             foreach ($skills as $skill) {
                 $skillToSelect[$skill['id']] = $skill['name'];
             }
             $this->addElement('select', 'skills', array(get_lang('Skills'), get_lang('SkillsAchievedWhenAchievingThisGradebook')), $skillToSelect, array('id' => 'skills', 'multiple' => 'multiple'));
             $content = '';
             if (!empty($skills)) {
                 foreach ($skills as $skill) {
                     $content .= Display::tag('li', $skill['name'] . '<a id="deleteskill_' . $skill['id'] . '" class="closebutton" href="#"></a>', array('id' => 'skill_' . $skill['id'], 'class' => 'bit-box'));
                 }
             }
             $this->addElement('label', null, Display::tag('ul', $content, array('class' => 'holder holder_simple')));
         }
     }
     if (isset($this->category_object) && $this->category_object->get_parent_id() == 0) {
         $this->add_textfield('certif_min_score', get_lang('CertificateMinScore'), false, array('class' => 'span1', 'maxlength' => '5'));
         $this->addRule('certif_min_score', get_lang('ThisFieldIsRequired'), 'required');
         $this->addRule('certif_min_score', get_lang('OnlyNumbers'), 'numeric');
         $this->addRule(array('certif_min_score', 'zero'), get_lang('NegativeValue'), 'compare', '>=');
     } else {
         $this->addElement('checkbox', 'visible', null, get_lang('Visible'));
     }
     $this->addElement('hidden', 'hid_user_id');
     $this->addElement('hidden', 'hid_parent_id');
     $this->addElement('textarea', 'description', get_lang('Description'), array('class' => 'span3', 'cols' => '34'));
     if (isset($this->category_object) && $this->category_object->get_parent_id() == 0 && (api_is_platform_admin() || api_get_setting('teachers_can_change_grade_model_settings') == 'true')) {
         //Getting grade models
         $obj = new GradeModel();
         $obj->fill_grade_model_select_in_form($this, 'grade_model_id', $this->category_object->get_grade_model_id());
         /*
                     $grade_models = $obj->get_all();
                     $options = array(-1 => get_lang('None'));
                     foreach ($grade_models as $item) {
            $options[$item['id']] = $item['name'];
                     }
                     $this->addElement('select', 'grade_model_id', array(get_lang('GradeModel'), get_lang('OnlyActiveWhenThereAreAnyComponents')), $options);
         *
         */
         //Freeze or not
         $course_code = api_get_course_id();
         $session_id = api_get_session_id();
         $test_cats = Category::load(null, null, $course_code, null, null, $session_id, false);
         //already init
         $links = null;
         if (!empty($test_cats[0])) {
             $links = $test_cats[0]->get_links();
         }
         if (count($test_cats) > 1 || !empty($links)) {
             if (api_get_setting('gradebook_enable_grade_model') == 'true') {
                 $this->freeze('grade_model_id');
             }
         }
     }
     if ($this->form_type == self::TYPE_ADD) {
         $this->addElement('style_submit_button', null, get_lang('AddCategory'), 'class="save"');
     } else {
         $this->addElement('hidden', 'editcat', intval($_GET['editcat']));
         $this->addElement('style_submit_button', null, get_lang('EditCategory'), 'class="save"');
     }
     //if (!empty($grading_contents)) {
     $this->addRule('weight', get_lang('OnlyNumbers'), 'numeric');
     //$this->addRule('weight',get_lang('NoDecimals'),'nopunctuation');
     $this->addRule(array('weight', 'zero'), get_lang('NegativeValue'), 'compare', '>=');
     //}
     $setting = api_get_setting('tool_visible_by_default_at_creation');
     $visibility_default = 1;
     if (isset($setting['gradebook']) && $setting['gradebook'] == 'false') {
         $visibility_default = 0;
     }
     $this->setDefaults(array('visible' => $visibility_default));
 }