Example #1
0
 $course->teachers = get_string("defaultcourseteachers");
 $course->student = get_string("defaultcoursestudent");
 $course->students = get_string("defaultcoursestudents");
 if (!empty($CFG->restrictmodulesfor) && $CFG->restrictmodulesfor != 'none' && !empty($CFG->restrictbydefault)) {
     $course->restrictmodules = 1;
 }
 if ($courseid = insert_record("course", $course)) {
     $page = page_create_object(PAGE_COURSE_VIEW, $courseid);
     blocks_repopulate_page($page);
     // Return value not checked because you can always edit later
     add_teacher($teacherid, $courseid);
     $course->id = $courseid;
     if (!empty($CFG->restrictmodulesfor) && $CFG->restrictmodulesfor != 'none' && !empty($CFG->restrictbydefault)) {
         // if we're all or requested we're ok.
         $allowedmods = explode(',', $CFG->defaultallowedmodules);
         update_restricted_mods($course, $allowedmods);
     }
     delete_records('course_request', 'id', $approve);
     $success = 1;
 }
 if (!empty($success)) {
     $user = get_record('user', 'id', $teacherid);
     $a->name = $course->fullname;
     $a->url = $CFG->wwwroot . '/course/view.php?id=' . $courseid;
     $a->teacher = $course->teacher;
     email_to_user($user, $USER, get_string('courseapprovedsubject'), get_string('courseapprovedemail', 'moodle', $a));
     redirect($CFG->wwwroot . '/course/edit.php?id=' . $courseid);
     exit;
 } else {
     error(get_string('courseapprovedfailed'));
     exit;
Example #2
0
/**
 * Update a course and return true or false
 *
 * @param object $data  - all the data needed for an entry in the 'course' table
 */
function update_course($data)
{
    global $USER, $CFG;
    // Preprocess allowed mods
    $allowedmods = empty($data->allowedmods) ? array() : $data->allowedmods;
    unset($data->allowedmods);
    // Normal teachers can't change setting
    if (!has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM))) {
        unset($data->restrictmodules);
    }
    $movecat = false;
    $oldcourse = get_record('course', 'id', $data->id);
    // should not fail, already tested above
    if (!has_capability('moodle/course:create', get_context_instance(CONTEXT_COURSECAT, $oldcourse->category)) or !has_capability('moodle/course:create', get_context_instance(CONTEXT_COURSECAT, $data->category))) {
        // can not move to new category, keep the old one
        unset($data->category);
    } elseif ($oldcourse->category != $data->category) {
        $movecat = true;
    }
    // Update with the new data
    if (update_record('course', $data)) {
        $course = get_record('course', 'id', $data->id);
        add_to_log($course->id, "course", "update", "edit.php?id={$course->id}", $course->id);
        // "Admins" can change allowed mods for a course
        if (has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM))) {
            update_restricted_mods($course, $allowedmods);
        }
        if ($movecat) {
            $context = get_context_instance(CONTEXT_COURSE, $course->id);
            $newparent = get_context_instance(CONTEXT_COURSECAT, $course->category);
            context_moved($context, $newparent);
        }
        fix_course_sortorder();
        // Test for and remove blocks which aren't appropriate anymore
        $page = page_create_object(PAGE_COURSE_VIEW, $course->id);
        blocks_remove_inappropriate($page);
        // Save any custom role names.
        save_local_role_names($course->id, $data);
        // Trigger events
        events_trigger('course_updated', $course);
        return true;
    }
    return false;
}
Example #3
0
File: lib.php Project: r007/PMoodle
/**
 * Update a course and return true or false
 *
 * @param object $data  - all the data needed for an entry in the 'course' table
 */
function update_course($data)
{
    global $USER, $CFG;
    // Preprocess allowed mods
    $allowedmods = empty($data->allowedmods) ? array() : $data->allowedmods;
    unset($data->allowedmods);
    // Normal teachers can't change setting
    if (!has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM))) {
        unset($data->restrictmodules);
    }
    $movecat = false;
    $oldcourse = get_record('course', 'id', $data->id);
    // should not fail, already tested above
    if (!has_capability('moodle/course:create', get_context_instance(CONTEXT_COURSECAT, $oldcourse->category)) or !has_capability('moodle/course:create', get_context_instance(CONTEXT_COURSECAT, $data->category))) {
        // can not move to new category, keep the old one
        unset($data->category);
    } elseif ($oldcourse->category != $data->category) {
        $movecat = true;
    }
    // Update with the new data
    if (update_record('course', $data)) {
        $course = get_record('course', 'id', $data->id);
        add_to_log($course->id, "course", "update", "edit.php?id={$course->id}", $course->id);
        // "Admins" can change allowed mods for a course
        if (has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM))) {
            update_restricted_mods($course, $allowedmods);
        }
        if ($movecat) {
            $context = get_context_instance(CONTEXT_COURSE, $course->id);
            $newparent = get_context_instance(CONTEXT_COURSECAT, $course->category);
            context_moved($context, $newparent);
        }
        fix_course_sortorder();
        // Test for and remove blocks which aren't appropriate anymore
        $page = page_create_object(PAGE_COURSE_VIEW, $course->id);
        blocks_remove_inappropriate($page);
        // put custom role names into db
        $context = get_context_instance(CONTEXT_COURSE, $course->id);
        foreach ($data as $dname => $dvalue) {
            // is this the right param?
            $dvalue = clean_param($dvalue, PARAM_NOTAGS);
            if (!strstr($dname, 'role_')) {
                continue;
            }
            $dt = explode('_', $dname);
            $roleid = $dt[1];
            // make up our mind whether we want to delete, update or insert
            if (empty($dvalue)) {
                delete_records('role_names', 'contextid', $context->id, 'roleid', $roleid);
            } else {
                if ($t = get_record('role_names', 'contextid', $context->id, 'roleid', $roleid)) {
                    $t->name = $dvalue;
                    update_record('role_names', $t);
                } else {
                    $t->contextid = $context->id;
                    $t->roleid = $roleid;
                    $t->name = $dvalue;
                    insert_record('role_names', $t);
                }
            }
        }
        //trigger events
        events_trigger('course_updated', $course);
        return true;
    }
    return false;
}
Example #4
0
/**
 * Update a course.
 *
 * Please note this functions does not verify any access control,
 * the calling code is responsible for all validation (usually it is the form definition).
 *
 * @param object $data  - all the data needed for an entry in the 'course' table
 * @param array $editoroptions course description editor options
 * @return void
 */
function update_course($data, $editoroptions = NULL)
{
    global $CFG, $DB;
    $data->timemodified = time();
    $oldcourse = $DB->get_record('course', array('id' => $data->id), '*', MUST_EXIST);
    $context = get_context_instance(CONTEXT_COURSE, $oldcourse->id);
    if ($editoroptions) {
        $data = file_postupdate_standard_editor($data, 'summary', $editoroptions, $context, 'course', 'summary', 0);
    }
    if (!isset($data->category) or empty($data->category)) {
        // prevent nulls and 0 in category field
        unset($data->category);
    }
    $movecat = (isset($data->category) and $oldcourse->category != $data->category);
    if (!isset($data->visible)) {
        // data not from form, add missing visibility info
        $data->visible = $oldcourse->visible;
    }
    if ($data->visible != $oldcourse->visible) {
        // reset the visibleold flag when manually hiding/unhiding course
        $data->visibleold = $data->visible;
    } else {
        if ($movecat) {
            $newcategory = $DB->get_record('course_categories', array('id' => $data->category));
            if (empty($newcategory->visible)) {
                // make sure when moving into hidden category the course is hidden automatically
                $data->visible = 0;
            }
        }
    }
    // Update with the new data
    $DB->update_record('course', $data);
    $course = $DB->get_record('course', array('id' => $data->id));
    if ($movecat) {
        $newparent = get_context_instance(CONTEXT_COURSECAT, $course->category);
        context_moved($context, $newparent);
    }
    fix_course_sortorder();
    // Test for and remove blocks which aren't appropriate anymore
    blocks_remove_inappropriate($course);
    // update module restrictions
    if (isset($data->allowedmods)) {
        update_restricted_mods($course, $data->allowedmods);
    }
    // Save any custom role names.
    save_local_role_names($course->id, $data);
    // update enrol settings
    enrol_course_updated(false, $course, $data);
    add_to_log($course->id, "course", "update", "edit.php?id={$course->id}", $course->id);
    // Trigger events
    events_trigger('course_updated', $course);
}
Example #5
0
function update_course($data)
{
    global $USER, $CFG;
    // preprocess allowed mods
    $allowedmods = empty($data->allowedmods) ? array() : $data->allowedmods;
    unset($data->allowedmods);
    if (!has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM))) {
        unset($data->restrictmodules);
    }
    $oldcourse = get_record('course', 'id', $data->id);
    // should not fail, already tested above
    if (!has_capability('moodle/course:create', get_context_instance(CONTEXT_COURSECAT, $oldcourse->category)) or !has_capability('moodle/course:create', get_context_instance(CONTEXT_COURSECAT, $data->category))) {
        // can not move to new category, keep the old one
        unset($data->category);
    }
    // Update with the new data
    if (update_record('course', $data)) {
        $course = get_record('course', 'id', $data->id);
        add_to_log($course->id, "course", "update", "edit.php?id={$course->id}", $course->id);
        if (has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM))) {
            update_restricted_mods($course, $allowedmods);
        }
        fix_course_sortorder();
        // Test for and remove blocks which aren't appropriate anymore
        $page = page_create_object(PAGE_COURSE_VIEW, $course->id);
        blocks_remove_inappropriate($page);
        return true;
    }
    return false;
}