Ejemplo n.º 1
0
/**
 * Validates imported data.
 */
function validate_data($courses)
{
    $errors = array();
    $coursecodes = array();
    foreach ($courses as $index => $course) {
        $course['line'] = $index + 1;
        // 1. Check whether mandatory fields are set.
        $mandatory_fields = array('Code', 'Title', 'CourseCategory');
        foreach ($mandatory_fields as $field) {
            if (!isset($course[$field]) || strlen($course[$field]) == 0) {
                $course['error'] = get_lang($field . 'Mandatory');
                $errors[] = $course;
            }
        }
        // 2. Check current course code.
        if (isset($course['Code']) && strlen($course['Code']) != 0) {
            // 2.1 Check whether code has been already used by this CVS-file.
            if (isset($coursecodes[$course['Code']])) {
                $course['error'] = get_lang('CodeTwiceInFile');
                $errors[] = $course;
            } else {
                // 2.2 Check whether course code has been occupied.
                $courseInfo = api_get_course_info($course['Code']);
                if (!empty($courseInfo)) {
                    $course['error'] = get_lang('CodeExists');
                    $errors[] = $course;
                }
            }
            $coursecodes[$course['Code']] = 1;
        }
        // 3. Check whether teacher exists.
        $teacherList = getTeacherListInArray($course['Teacher']);
        if (!empty($teacherList)) {
            foreach ($teacherList as $teacher) {
                $teacherInfo = api_get_user_info_from_username($teacher);
                if (empty($teacherInfo)) {
                    $course['error'] = get_lang('UnknownTeacher') . ' (' . $teacher . ')';
                    $errors[] = $course;
                } else {
                    /*if ($teacherInfo['status'] != COURSEMANAGER) {
                          $course['error'] = get_lang('UserIsNotATeacher').' ('.$teacher.')';
                          $errors[] = $course;
                      }*/
                }
            }
        }
        // 4. Check whether course category exists.
        if (isset($course['CourseCategory']) && strlen($course['CourseCategory']) != 0) {
            $categoryInfo = CourseCategory::getCategory($course['CourseCategory']);
            if (empty($categoryInfo)) {
                //@todo this is so bad even all lang variables are wrong ...
                $course['error'] = get_lang('UnkownCategoryCourseCode') . ' (' . $course['CourseCategory'] . ')';
                $errors[] = $course;
            }
        }
    }
    return $errors;
}
Ejemplo n.º 2
0
 } 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');
     // Course category.
     $url = api_get_path(WEB_AJAX_PATH) . 'course.ajax.php?a=search_category';
     $courseSelect = $form->addElement('select_ajax', 'category_code', get_lang('CourseFaculty'), null, array('url' => $url));
     if (!empty($course_request_info['category_code'])) {
         $data = CourseCategory::getCategory($course_request_info['category_code']);
         $courseSelect->addOption($data['name'], $data['code'], ['selected' => 'selected']);
     }
     // Course code.
     $form->addText('wanted_code', get_lang('Code'), false, array('size' => '$maxlength', 'maxlength' => $maxlength));
     $form->applyFilter('wanted_code', 'html_filter');
     $form->addRule('wanted_code', get_lang('Max'), 'maxlength', $maxlength);
     $form->addRule('wanted_code', get_lang('ThisFieldIsRequired'), 'required');
     // The teacher.
     $titular = $form->addText('tutor_name', get_lang('Professor'), null, array('size' => '60', 'disabled' => 'disabled'));
     // Description of the requested course.
     $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'));
     $form->addRule('description', get_lang('ThisFieldIsRequired'), 'required');
     // Objectives of the requested course.
     $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'));
     $form->addRule('objetives', get_lang('ThisFieldIsRequired'), 'required');
Ejemplo n.º 3
0
        }
        $groupName = 'session_coaches[' . $sessionId . ']';
        $platformTeacherId = 'platform_teachers_by_session_' . $sessionId;
        $coachId = 'coaches_by_session_' . $sessionId;
        $platformTeacherName = 'platform_teachers_by_session';
        $coachName = 'coaches_by_session';
        $sessionUrl = api_get_path(WEB_CODE_PATH) . 'session/resume_session.php?id_session=' . $sessionId;
        $form->addElement('advmultiselect', $groupName, Display::url($session['name'], $sessionUrl, array('target' => '_blank')) . ' - ' . get_lang('Coaches'), $allTeachers);
        $courseInfo[$groupName] = $sessionTeachers;
    }
}
// Category code
$url = api_get_path(WEB_AJAX_PATH) . 'course.ajax.php?a=search_category';
$categorySelect = $form->addElement('select_ajax', 'category_code', get_lang('CourseFaculty'), null, array('url' => $url));
if (!empty($courseInfo['categoryCode'])) {
    $data = CourseCategory::getCategory($courseInfo['categoryCode']);
    $categorySelect->addOption($data['name'], $data['code']);
}
$form->addText('department_name', get_lang('CourseDepartment'), false, array('size' => '60'));
$form->applyFilter('department_name', 'html_filter');
$form->applyFilter('department_name', 'trim');
$form->addText('department_url', get_lang('CourseDepartmentURL'), false, array('size' => '60'));
$form->applyFilter('department_url', 'html_filter');
$form->applyFilter('department_url', 'trim');
$form->addElement('select_language', 'course_language', get_lang('CourseLanguage'));
$form->applyFilter('select_language', 'html_filter');
$group = array();
$group[] = $form->createElement('radio', 'visibility', get_lang("CourseAccess"), get_lang('OpenToTheWorld'), COURSE_VISIBILITY_OPEN_WORLD);
$group[] = $form->createElement('radio', 'visibility', null, get_lang('OpenToThePlatform'), COURSE_VISIBILITY_OPEN_PLATFORM);
$group[] = $form->createElement('radio', 'visibility', null, get_lang('Private'), COURSE_VISIBILITY_REGISTERED);
$group[] = $form->createElement('radio', 'visibility', null, get_lang('CourseVisibilityClosed'), COURSE_VISIBILITY_CLOSED);
Ejemplo n.º 4
0
/* For licensing terms, see /license.txt */
use Chamilo\CoreBundle\Framework\Container;
/**
 * 	@package chamilo.admin
 */
$cidReset = true;
$this_section = SECTION_PLATFORM_ADMIN;
api_protect_admin_script();
$category = isset($_GET['category']) ? $_GET['category'] : null;
$parentInfo = [];
if (!empty($category)) {
    $parentInfo = CourseCategory::getCategory($category);
}
$categoryId = isset($_GET['id']) ? Security::remove_XSS($_GET['id']) : null;
if (!empty($categoryId)) {
    $categoryInfo = CourseCategory::getCategory($categoryId);
}
$action = isset($_GET['action']) ? $_GET['action'] : null;
$errorMsg = '';
if (!empty($action)) {
    if ($action == 'delete') {
        CourseCategory::deleteNode($categoryId);
        Display::addFlash(Display::return_message(get_lang('Deleted')));
        header('Location: ' . api_get_self() . '?category=' . Security::remove_XSS($category));
        exit;
    } elseif (($action == 'add' || $action == 'edit') && isset($_POST['formSent']) && $_POST['formSent']) {
        if ($action == 'add') {
            $ret = CourseCategory::addNode($_POST['code'], $_POST['name'], $_POST['auth_course_child'], $category);
            Display::addFlash(Display::return_message(get_lang('Created')));
        } else {
            $ret = CourseCategory::editNode($_POST['code'], $_POST['name'], $_POST['auth_course_child'], $categoryId);