コード例 #1
0
ファイル: lib.php プロジェクト: numbas/moodle
 /**
  * This function approves the request turning it into a course
  *
  * This function converts the course request into a course, at the same time
  * transferring any files used in the summary to the new course and then removing
  * the course request and the files associated with it.
  *
  * @return int The id of the course that was created from this request
  */
 public function approve()
 {
     global $CFG, $DB, $USER;
     $user = $DB->get_record('user', array('id' => $this->properties->requester, 'deleted' => 0), '*', MUST_EXIST);
     $category = get_course_category($CFG->defaultrequestcategory);
     $courseconfig = get_config('moodlecourse');
     // Transfer appropriate settings
     $data = clone $this->properties;
     unset($data->id);
     unset($data->reason);
     unset($data->requester);
     // Set category
     $data->category = $category->id;
     $data->sortorder = $category->sortorder;
     // place as the first in category
     // Set misc settings
     $data->requested = 1;
     // Apply course default settings
     $data->format = $courseconfig->format;
     $data->numsections = $courseconfig->numsections;
     $data->hiddensections = $courseconfig->hiddensections;
     $data->newsitems = $courseconfig->newsitems;
     $data->showgrades = $courseconfig->showgrades;
     $data->showreports = $courseconfig->showreports;
     $data->maxbytes = $courseconfig->maxbytes;
     $data->groupmode = $courseconfig->groupmode;
     $data->groupmodeforce = $courseconfig->groupmodeforce;
     $data->visible = $courseconfig->visible;
     $data->visibleold = $data->visible;
     $data->lang = $courseconfig->lang;
     $course = create_course($data);
     $context = get_context_instance(CONTEXT_COURSE, $course->id, MUST_EXIST);
     // add enrol instances
     if (!$DB->record_exists('enrol', array('courseid' => $course->id, 'enrol' => 'manual'))) {
         if ($manual = enrol_get_plugin('manual')) {
             $manual->add_default_instance($course);
         }
     }
     // enrol the requester as teacher if necessary
     if (!empty($CFG->creatornewroleid) and !is_viewing($context, $user, 'moodle/role:assign') and !is_enrolled($context, $user, 'moodle/role:assign')) {
         enrol_try_internal_enrol($course->id, $user->id, $CFG->creatornewroleid);
     }
     $this->delete();
     $a = new stdClass();
     $a->name = format_string($course->fullname, true, array('context' => get_context_instance(CONTEXT_COURSE, $course->id)));
     $a->url = $CFG->wwwroot . '/course/view.php?id=' . $course->id;
     $this->notify($user, $USER, 'courserequestapproved', get_string('courseapprovedsubject'), get_string('courseapprovedemail2', 'moodle', $a));
     return $course->id;
 }
コード例 #2
0
ファイル: pending.php プロジェクト: nicolasconnault/moodle2.0
require_once $CFG->dirroot . '/course/lib.php';
require_once $CFG->dirroot . '/course/request_form.php';
require_login();
require_capability('moodle/site:approvecourse', get_context_instance(CONTEXT_SYSTEM));
$approve = optional_param('approve', 0, PARAM_INT);
$reject = optional_param('reject', 0, PARAM_INT);
$baseurl = $CFG->wwwroot . '/course/pending.php';
admin_externalpage_setup('coursespending');
/// Process approval of a course.
if (!empty($approve) and confirm_sesskey()) {
    /// Load the request.
    if (!($course = $DB->get_record('course_request', array('id' => $approve)))) {
        print_error('unknowncourserequest');
    }
    /// Get the category courses are added to.
    $category = get_course_category($CFG->defaultrequestcategory);
    /// Build up a course record based on the request.
    $course->category = $category->id;
    $course->sortorder = $category->sortorder;
    // place as the first in category
    $course->requested = 1;
    unset($course->reason);
    unset($course->id);
    $teacherid = $course->requester;
    unset($course->requester);
    if (!empty($CFG->restrictmodulesfor) && $CFG->restrictmodulesfor != 'none' && !empty($CFG->restrictbydefault)) {
        $course->restrictmodules = 1;
    }
    /// Insert the record.
    if ($courseid = $DB->insert_record('course', $course)) {
        $course = $DB->get_record('course', array('id' => $courseid));
コード例 #3
0
ファイル: install.php プロジェクト: esyacelga/sisadmaca
function xmldb_main_install()
{
    global $CFG, $DB, $SITE, $OUTPUT;
    /// make sure system context exists
    $syscontext = get_system_context(false);
    if ($syscontext->id != 1) {
        throw new moodle_exception('generalexceptionmessage', 'error', '', 'Unexpected new system context id!');
    }
    /// create site course
    $newsite = new stdClass();
    $newsite->fullname = '';
    $newsite->shortname = '';
    $newsite->summary = NULL;
    $newsite->newsitems = 3;
    $newsite->numsections = 0;
    $newsite->category = 0;
    $newsite->format = 'site';
    // Only for this course
    $newsite->timecreated = time();
    $newsite->timemodified = $newsite->timecreated;
    $newsite->id = $DB->insert_record('course', $newsite);
    $SITE = get_site();
    if ($newsite->id != 1 or $SITE->id != 1) {
        throw new moodle_exception('generalexceptionmessage', 'error', '', 'Unexpected new site course id!');
    }
    /// make sure site course context exists
    get_context_instance(CONTEXT_COURSE, $SITE->id);
    /// create default course category
    $cat = get_course_category();
    $defaults = array('rolesactive' => '0', 'auth' => 'email', 'auth_pop3mailbox' => 'INBOX', 'enrol_plugins_enabled' => 'manual,guest,self,cohort', 'theme' => theme_config::DEFAULT_THEME, 'filter_multilang_converted' => 1, 'siteidentifier' => random_string(32) . get_host_from_url($CFG->wwwroot), 'backup_version' => 2008111700, 'backup_release' => '2.0 dev', 'mnet_dispatcher_mode' => 'off', 'sessiontimeout' => 7200, 'stringfilters' => '', 'filterall' => 0, 'texteditors' => 'tinymce,textarea');
    foreach ($defaults as $key => $value) {
        set_config($key, $value);
    }
    /// bootstrap mnet
    $mnethost = new stdClass();
    $mnethost->wwwroot = $CFG->wwwroot;
    $mnethost->name = '';
    $mnethost->name = '';
    $mnethost->public_key = '';
    if (empty($_SERVER['SERVER_ADDR'])) {
        // SERVER_ADDR is only returned by Apache-like webservers
        preg_match("@^(?:http[s]?://)?([A-Z0-9\\-\\.]+).*@i", $CFG->wwwroot, $matches);
        $my_hostname = $matches[1];
        $my_ip = gethostbyname($my_hostname);
        // Returns unmodified hostname on failure. DOH!
        if ($my_ip == $my_hostname) {
            $mnethost->ip_address = 'UNKNOWN';
        } else {
            $mnethost->ip_address = $my_ip;
        }
    } else {
        $mnethost->ip_address = $_SERVER['SERVER_ADDR'];
    }
    $mnetid = $DB->insert_record('mnet_host', $mnethost);
    set_config('mnet_localhost_id', $mnetid);
    // Initial insert of mnet applications info
    $mnet_app = new stdClass();
    $mnet_app->name = 'moodle';
    $mnet_app->display_name = 'Moodle';
    $mnet_app->xmlrpc_server_url = '/mnet/xmlrpc/server.php';
    $mnet_app->sso_land_url = '/auth/mnet/land.php';
    $mnet_app->sso_jump_url = '/auth/mnet/jump.php';
    $moodleapplicationid = $DB->insert_record('mnet_application', $mnet_app);
    $mnet_app = new stdClass();
    $mnet_app->name = 'mahara';
    $mnet_app->display_name = 'Mahara';
    $mnet_app->xmlrpc_server_url = '/api/xmlrpc/server.php';
    $mnet_app->sso_land_url = '/auth/xmlrpc/land.php';
    $mnet_app->sso_jump_url = '/auth/xmlrpc/jump.php';
    $DB->insert_record('mnet_application', $mnet_app);
    // Set up the probably-to-be-removed-soon 'All hosts' record
    $mnetallhosts = new stdClass();
    $mnetallhosts->wwwroot = '';
    $mnetallhosts->ip_address = '';
    $mnetallhosts->public_key = '';
    $mnetallhosts->public_key_expires = 0;
    $mnetallhosts->last_connect_time = 0;
    $mnetallhosts->last_log_id = 0;
    $mnetallhosts->deleted = 0;
    $mnetallhosts->name = 'All Hosts';
    $mnetallhosts->applicationid = $moodleapplicationid;
    $mnetallhosts->id = $DB->insert_record('mnet_host', $mnetallhosts, true);
    set_config('mnet_all_hosts_id', $mnetallhosts->id);
    /// Create guest record - do not assign any role, guest user get's the default guest role automatically on the fly
    $guest = new stdClass();
    $guest->auth = 'manual';
    $guest->username = '******';
    $guest->password = hash_internal_user_password('guest');
    $guest->firstname = get_string('guestuser');
    $guest->lastname = ' ';
    $guest->email = 'root@localhost';
    $guest->description = get_string('guestuserinfo');
    $guest->mnethostid = $CFG->mnet_localhost_id;
    $guest->confirmed = 1;
    $guest->lang = $CFG->lang;
    $guest->timemodified = time();
    $guest->id = $DB->insert_record('user', $guest);
    if ($guest->id != 1) {
        echo $OUTPUT->notification('Unexpected id generated for the Guest account. Your database configuration or clustering setup may not be fully supported', 'notifyproblem');
    }
    // Store guest id
    set_config('siteguest', $guest->id);
    /// Now create admin user
    $admin = new stdClass();
    $admin->auth = 'manual';
    $admin->firstname = get_string('admin');
    $admin->lastname = get_string('user');
    $admin->username = '******';
    $admin->password = '******';
    $admin->email = '';
    $admin->confirmed = 1;
    $admin->mnethostid = $CFG->mnet_localhost_id;
    $admin->lang = $CFG->lang;
    $admin->maildisplay = 1;
    $admin->timemodified = time();
    $admin->lastip = CLI_SCRIPT ? '0.0.0.0' : getremoteaddr();
    // installation hijacking prevention
    $admin->id = $DB->insert_record('user', $admin);
    if ($admin->id != 2) {
        echo $OUTPUT->notification('Unexpected id generated for the Admin account. Your database configuration or clustering setup may not be fully supported', 'notifyproblem');
    }
    if ($admin->id != $guest->id + 1) {
        echo $OUTPUT->notification('Nonconsecutive id generated for the Admin account. Your database configuration or clustering setup may not be fully supported.', 'notifyproblem');
    }
    /// Store list of admins
    set_config('siteadmins', $admin->id);
    /// Install the roles system.
    $managerrole = create_role(get_string('manager', 'role'), 'manager', get_string('managerdescription', 'role'), 'manager');
    $coursecreatorrole = create_role(get_string('coursecreators'), 'coursecreator', get_string('coursecreatorsdescription'), 'coursecreator');
    $editteacherrole = create_role(get_string('defaultcourseteacher'), 'editingteacher', get_string('defaultcourseteacherdescription'), 'editingteacher');
    $noneditteacherrole = create_role(get_string('noneditingteacher'), 'teacher', get_string('noneditingteacherdescription'), 'teacher');
    $studentrole = create_role(get_string('defaultcoursestudent'), 'student', get_string('defaultcoursestudentdescription'), 'student');
    $guestrole = create_role(get_string('guest'), 'guest', get_string('guestdescription'), 'guest');
    $userrole = create_role(get_string('authenticateduser'), 'user', get_string('authenticateduserdescription'), 'user');
    $frontpagerole = create_role(get_string('frontpageuser', 'role'), 'frontpage', get_string('frontpageuserdescription', 'role'), 'frontpage');
    /// Now is the correct moment to install capabilities - after creation of legacy roles, but before assigning of roles
    update_capabilities('moodle');
    /// Default allow assign
    $defaultallowassigns = array(array($managerrole, $managerrole), array($managerrole, $coursecreatorrole), array($managerrole, $editteacherrole), array($managerrole, $noneditteacherrole), array($managerrole, $studentrole), array($editteacherrole, $noneditteacherrole), array($editteacherrole, $studentrole));
    foreach ($defaultallowassigns as $allow) {
        list($fromroleid, $toroleid) = $allow;
        allow_assign($fromroleid, $toroleid);
    }
    /// Default allow override
    $defaultallowoverrides = array(array($managerrole, $managerrole), array($managerrole, $coursecreatorrole), array($managerrole, $editteacherrole), array($managerrole, $noneditteacherrole), array($managerrole, $studentrole), array($managerrole, $guestrole), array($managerrole, $userrole), array($managerrole, $frontpagerole), array($editteacherrole, $noneditteacherrole), array($editteacherrole, $studentrole), array($editteacherrole, $guestrole));
    foreach ($defaultallowoverrides as $allow) {
        list($fromroleid, $toroleid) = $allow;
        allow_override($fromroleid, $toroleid);
        // There is a rant about this in MDL-15841.
    }
    /// Default allow switch.
    $defaultallowswitch = array(array($managerrole, $editteacherrole), array($managerrole, $noneditteacherrole), array($managerrole, $studentrole), array($managerrole, $guestrole), array($editteacherrole, $noneditteacherrole), array($editteacherrole, $studentrole), array($editteacherrole, $guestrole), array($noneditteacherrole, $studentrole), array($noneditteacherrole, $guestrole));
    foreach ($defaultallowswitch as $allow) {
        list($fromroleid, $toroleid) = $allow;
        allow_switch($fromroleid, $toroleid);
    }
    /// Set up the context levels where you can assign each role.
    set_role_contextlevels($managerrole, get_default_contextlevels('manager'));
    set_role_contextlevels($coursecreatorrole, get_default_contextlevels('coursecreator'));
    set_role_contextlevels($editteacherrole, get_default_contextlevels('editingteacher'));
    set_role_contextlevels($noneditteacherrole, get_default_contextlevels('teacher'));
    set_role_contextlevels($studentrole, get_default_contextlevels('student'));
    set_role_contextlevels($guestrole, get_default_contextlevels('guest'));
    set_role_contextlevels($userrole, get_default_contextlevels('user'));
    // Init themes
    set_config('themerev', 1);
    // Install licenses
    require_once $CFG->libdir . '/licenselib.php';
    license_manager::install_licenses();
    /// Add two lines of data into this new table
    $mypage = new stdClass();
    $mypage->userid = NULL;
    $mypage->name = '__default';
    $mypage->private = 0;
    $mypage->sortorder = 0;
    if (!$DB->record_exists('my_pages', array('userid' => NULL, 'private' => 0))) {
        $DB->insert_record('my_pages', $mypage);
    }
    $mypage->private = 1;
    if (!$DB->record_exists('my_pages', array('userid' => NULL, 'private' => 1))) {
        $DB->insert_record('my_pages', $mypage);
    }
}
コード例 #4
0
ファイル: enrol.php プロジェクト: ajv/Offline-Caching
 function create_course($course_ext, $skip_fix_course_sortorder = 0)
 {
     global $CFG, $DB, $OUTPUT;
     // override defaults with template course
     if (!empty($CFG->enrol_ldap_template)) {
         $course = $DB->get_record("course", array('shortname' => $CFG->enrol_ldap_template));
         unset($course->id);
         // so we are clear to reinsert the record
         unset($course->sortorder);
     } else {
         // set defaults
         $course = new object();
         $course->format = 'topics';
     }
     // override with required ext data
     $course->idnumber = $course_ext[$CFG->enrol_ldap_course_idnumber][0];
     $course->fullname = $course_ext[$CFG->enrol_ldap_course_fullname][0];
     $course->shortname = $course_ext[$CFG->enrol_ldap_course_shortname][0];
     if (empty($course->idnumber) || empty($course->fullname) || empty($course->shortname)) {
         // we are in trouble!
         error_log("Cannot create course: missing required data from the LDAP record!");
         error_log(var_export($course, true));
         return false;
     }
     $course->summary = empty($CFG->enrol_ldap_course_summary) || empty($course_ext[$CFG->enrol_ldap_course_summary][0]) ? '' : $course_ext[$CFG->enrol_ldap_course_summary][0];
     $category = get_course_category($CFG->enrol_db_category);
     // put at the end of category
     $course->sortorder = $category->sortorder + MAX_COURSES_IN_CATEGORY - 1;
     // override with local data
     $course->startdate = time();
     $course->timecreated = time();
     $course->visible = 1;
     // store it and log
     if ($newcourseid = $DB->insert_record("course", $course)) {
         // Set up new course
         $section = new object();
         $section->course = $newcourseid;
         // Create a default section.
         $section->section = 0;
         $section->id = $DB->insert_record("course_sections", $section);
         $course = $DB->get_record('course', array('id' => $newcourseid));
         blocks_add_default_course_blocks($course);
         if (!$skip_fix_course_sortorder) {
             fix_course_sortorder();
         }
         add_to_log($newcourseid, "course", "new", "view.php?id={$newcourseid}", "enrol/ldap auto-creation");
     } else {
         error_log("Could not create new course from LDAP from DN:" . $course_ext['dn']);
         echo $OUTPUT->notification("Serious Error! Could not create the new course!");
         return false;
     }
     return $newcourseid;
 }
コード例 #5
0
function restore_create_new_course($restore, &$course_header)
{
    global $CFG, $DB;
    $status = true;
    $fullname = $course_header->course_fullname;
    $shortname = $course_header->course_shortname;
    $currentfullname = "";
    $currentshortname = "";
    $counter = 0;
    //Iteratere while the name exists
    do {
        if ($counter) {
            $suffixfull = " " . get_string("copyasnoun") . " " . $counter;
            $suffixshort = "_" . $counter;
        } else {
            $suffixfull = "";
            $suffixshort = "";
        }
        $currentfullname = $fullname . $suffixfull;
        // Limit the size of shortname - database column accepts <= 100 chars
        $currentshortname = substr($shortname, 0, 100 - strlen($suffixshort)) . $suffixshort;
        $coursefull = $DB->get_record("course", array("fullname" => $currentfullname));
        $courseshort = $DB->get_record("course", array("shortname" => $currentshortname));
        $counter++;
    } while ($coursefull || $courseshort);
    //New name = currentname
    $course_header->course_fullname = $currentfullname;
    $course_header->course_shortname = $currentshortname;
    // first try to get it from restore
    if ($restore->restore_restorecatto) {
        $category = $DB->get_record('course_categories', array('id' => $restore->restore_restorecatto));
    }
    // else we try to get it from the xml file
    //Now calculate the category
    if (empty($category)) {
        $category = $DB->get_record("course_categories", array("id" => $course_header->category->id, "name" => $course_header->category->name));
    }
    //If no exists, try by name only
    if (!$category) {
        $category = $DB->get_record("course_categories", array("name" => $course_header->category->name));
    }
    //If no exists, get default category
    if (!$category) {
        $category = get_course_category();
    }
    $course_header->category->id = $category->id;
    $course_header->category->name = $category->name;
    //Create the course_object
    if ($status) {
        $course = new object();
        $course->category = $course_header->category->id;
        $course->password = $course_header->course_password;
        $course->fullname = $course_header->course_fullname;
        $course->shortname = $course_header->course_shortname;
        $course->idnumber = $course_header->course_idnumber;
        $course->idnumber = '';
        //$course_header->course_idnumber; // we don't want this at all.
        $course->summary = $course_header->course_summary;
        $course->format = $course_header->course_format;
        $course->showgrades = $course_header->course_showgrades;
        $course->newsitems = $course_header->course_newsitems;
        $course->guest = $course_header->course_guest;
        $course->startdate = $course_header->course_startdate;
        $course->startdate += $restore->course_startdateoffset;
        $course->numsections = $course_header->course_numsections;
        //$course->showrecent = $course_header->course_showrecent;   INFO: This is out in 1.3
        $course->maxbytes = $course_header->course_maxbytes;
        $course->showreports = $course_header->course_showreports;
        if (isset($course_header->course_groupmode)) {
            $course->groupmode = $course_header->course_groupmode;
        }
        if (isset($course_header->course_groupmodeforce)) {
            $course->groupmodeforce = $course_header->course_groupmodeforce;
        }
        if (isset($course_header->course_defaultgroupingid)) {
            //keep the original now - convert after groupings restored
            $course->defaultgroupingid = $course_header->course_defaultgroupingid;
        }
        $course->lang = $course_header->course_lang;
        $course->theme = $course_header->course_theme;
        $course->cost = $course_header->course_cost;
        $course->currency = isset($course_header->course_currency) ? $course_header->course_currency : '';
        $course->marker = $course_header->course_marker;
        $course->visible = $course_header->course_visible;
        $course->hiddensections = $course_header->course_hiddensections;
        $course->timecreated = $course_header->course_timecreated;
        $course->timemodified = $course_header->course_timemodified;
        $course->metacourse = $course_header->course_metacourse;
        $course->expirynotify = isset($course_header->course_expirynotify) ? $course_header->course_expirynotify : 0;
        $course->notifystudents = isset($course_header->course_notifystudents) ? $course_header->course_notifystudents : 0;
        $course->expirythreshold = isset($course_header->course_expirythreshold) ? $course_header->course_expirythreshold : 0;
        $course->enrollable = isset($course_header->course_enrollable) ? $course_header->course_enrollable : 1;
        $course->enrolstartdate = isset($course_header->course_enrolstartdate) ? $course_header->course_enrolstartdate : 0;
        if ($course->enrolstartdate) {
            //Roll course dates
            $course->enrolstartdate += $restore->course_startdateoffset;
        }
        $course->enrolenddate = isset($course_header->course_enrolenddate) ? $course_header->course_enrolenddate : 0;
        if ($course->enrolenddate) {
            //Roll course dates
            $course->enrolenddate += $restore->course_startdateoffset;
        }
        $course->enrolperiod = $course_header->course_enrolperiod;
        $course->enablecompletion = isset($course_header->course_enablecompletion) ? $course_header->course_enablecompletion : 0;
        //Put as last course in category
        $course->sortorder = $category->sortorder + MAX_COURSES_IN_CATEGORY - 1;
        //Now, recode some languages (Moodle 1.5)
        if ($course->lang == 'ma_nt') {
            $course->lang = 'mi_nt';
        }
        //Disable course->metacourse if avoided in restore config
        if (!$restore->metacourse) {
            $course->metacourse = 0;
        }
        //Check if the theme exists in destination server
        $themes = get_list_of_themes();
        if (!in_array($course->theme, $themes)) {
            $course->theme = '';
        }
        //Now insert the record
        $newid = $DB->insert_record("course", $course);
        if ($newid) {
            //save old and new course id
            backup_putid($restore->backup_unique_code, "course", $course_header->course_id, $newid);
            //Replace old course_id in course_header
            $course_header->course_id = $newid;
        } else {
            $status = false;
        }
    }
    return $status;
}
コード例 #6
0
ファイル: install.php プロジェクト: ajv/Offline-Caching
function xmldb_main_install()
{
    global $CFG, $DB, $SITE;
    /// make sure system context exists
    $syscontext = get_system_context(false);
    if ($syscontext->id != 1) {
        throw new moodle_exception('generalexceptionmessage', 'error', '', 'Unexpected system context id created!');
    }
    // create site course
    $newsite = new object();
    $newsite->fullname = "";
    $newsite->shortname = "";
    $newsite->summary = NULL;
    $newsite->newsitems = 3;
    $newsite->numsections = 0;
    $newsite->category = 0;
    $newsite->format = 'site';
    // Only for this course
    $newsite->teacher = get_string("defaultcourseteacher");
    $newsite->teachers = get_string("defaultcourseteachers");
    $newsite->student = get_string("defaultcoursestudent");
    $newsite->students = get_string("defaultcoursestudents");
    $newsite->timemodified = time();
    $DB->insert_record('course', $newsite);
    $SITE = get_site();
    if ($SITE->id != 1) {
        throw new moodle_exception('generalexceptionmessage', 'error', '', 'Unexpected site course id created!');
    }
    /// make sure site course context exists
    get_context_instance(CONTEXT_COURSE, $SITE->id);
    /// create default course category
    $cat = get_course_category();
    $defaults = array('rolesactive' => '0', 'auth' => 'email', 'auth_pop3mailbox' => 'INBOX', 'enrol' => 'manual', 'enrol_plugins_enabled' => 'manual', 'style' => 'default', 'template' => 'default', 'theme' => 'standardwhite', 'filter_multilang_converted' => 1, 'siteidentifier' => random_string(32) . get_host_from_url($CFG->wwwroot), 'backup_version' => 2008111700, 'backup_release' => '2.0 dev', 'blocks_version' => 2007081300, 'mnet_dispatcher_mode' => 'off', 'sessiontimeout' => 7200, 'stringfilters' => '', 'filterall' => 0, 'texteditors' => 'tinymce,textarea');
    foreach ($defaults as $key => $value) {
        set_config($key, $value);
    }
    /// bootstrap mnet
    $mnethost = new object();
    $mnethost->wwwroot = $CFG->wwwroot;
    $mnethost->name = '';
    $mnethost->name = '';
    $mnethost->public_key = '';
    if (empty($_SERVER['SERVER_ADDR'])) {
        // SERVER_ADDR is only returned by Apache-like webservers
        preg_match("@^(?:http[s]?://)?([A-Z0-9\\-\\.]+).*@i", $CFG->wwwroot, $matches);
        $my_hostname = $matches[1];
        $my_ip = gethostbyname($my_hostname);
        // Returns unmodified hostname on failure. DOH!
        if ($my_ip == $my_hostname) {
            $mnethost->ip_address = 'UNKNOWN';
        } else {
            $mnethost->ip_address = $my_ip;
        }
    } else {
        $mnethost->ip_address = $_SERVER['SERVER_ADDR'];
    }
    $mnetid = $DB->insert_record('mnet_host', $mnethost);
    set_config('mnet_localhost_id', $mnetid);
    // Initial insert of mnet applications info
    $mnet_app = new object();
    $mnet_app->name = 'moodle';
    $mnet_app->display_name = 'Moodle';
    $mnet_app->xmlrpc_server_url = '/mnet/xmlrpc/server.php';
    $mnet_app->sso_land_url = '/auth/mnet/land.php';
    $mnet_app->sso_jump_url = '/auth/mnet/land.php';
    $DB->insert_record('mnet_application', $mnet_app);
    $mnet_app = new object();
    $mnet_app->name = 'mahara';
    $mnet_app->display_name = 'Mahara';
    $mnet_app->xmlrpc_server_url = '/api/xmlrpc/server.php';
    $mnet_app->sso_land_url = '/auth/xmlrpc/land.php';
    $mnet_app->sso_jump_url = '/auth/xmlrpc/jump.php';
    $DB->insert_record('mnet_application', $mnet_app);
    /// insert log entries - replaces statements section in install.xml
    update_log_display_entry('user', 'view', 'user', 'CONCAT(firstname,\' \',lastname)');
    update_log_display_entry('course', 'user report', 'user', 'CONCAT(firstname,\' \',lastname)');
    update_log_display_entry('course', 'view', 'course', 'fullname');
    update_log_display_entry('course', 'update', 'course', 'fullname');
    update_log_display_entry('course', 'enrol', 'course', 'fullname');
    update_log_display_entry('course', 'unenrol', 'course', 'fullname');
    update_log_display_entry('course', 'report log', 'course', 'fullname');
    update_log_display_entry('course', 'report live', 'course', 'fullname');
    update_log_display_entry('course', 'report outline', 'course', 'fullname');
    update_log_display_entry('course', 'report participation', 'course', 'fullname');
    update_log_display_entry('course', 'report stats', 'course', 'fullname');
    update_log_display_entry('message', 'write', 'user', 'CONCAT(firstname,\' \',lastname)');
    update_log_display_entry('message', 'read', 'user', 'CONCAT(firstname,\' \',lastname)');
    update_log_display_entry('message', 'add contact', 'user', 'CONCAT(firstname,\' \',lastname)');
    update_log_display_entry('message', 'remove contact', 'user', 'CONCAT(firstname,\' \',lastname)');
    update_log_display_entry('message', 'block contact', 'user', 'CONCAT(firstname,\' \',lastname)');
    update_log_display_entry('message', 'unblock contact', 'user', 'CONCAT(firstname,\' \',lastname)');
    update_log_display_entry('group', 'view', 'groups', 'name');
    /// Create guest record
    $guest = new object();
    $guest->auth = 'manual';
    $guest->username = '******';
    $guest->password = hash_internal_user_password('guest');
    $guest->firstname = get_string('guestuser');
    $guest->lastname = ' ';
    $guest->email = 'root@localhost';
    $guest->description = get_string('guestuserinfo');
    $guest->mnethostid = $CFG->mnet_localhost_id;
    $guest->confirmed = 1;
    $guest->lang = $CFG->lang;
    $guest->timemodified = time();
    $guest->id = $DB->insert_record('user', $guest);
    /// Now create admin user
    $admin = new object();
    $admin->auth = 'manual';
    $admin->firstname = get_string('admin');
    $admin->lastname = get_string('user');
    $admin->username = '******';
    $admin->password = '******';
    $admin->email = '';
    $admin->confirmed = 1;
    $admin->mnethostid = $CFG->mnet_localhost_id;
    $admin->lang = $CFG->lang;
    $admin->maildisplay = 1;
    $admin->timemodified = time();
    $admin->lastip = CLI_SCRIPT ? '0.0.0.0' : getremoteaddr();
    // installation hijacking prevention
    $admin->id = $DB->insert_record('user', $admin);
    /// Install the roles system.
    $adminrole = create_role(get_string('administrator'), 'admin', get_string('administratordescription'), 'moodle/legacy:admin');
    $coursecreatorrole = create_role(get_string('coursecreators'), 'coursecreator', get_string('coursecreatorsdescription'), 'moodle/legacy:coursecreator');
    $editteacherrole = create_role(get_string('defaultcourseteacher'), 'editingteacher', get_string('defaultcourseteacherdescription'), 'moodle/legacy:editingteacher');
    $noneditteacherrole = create_role(get_string('noneditingteacher'), 'teacher', get_string('noneditingteacherdescription'), 'moodle/legacy:teacher');
    $studentrole = create_role(get_string('defaultcoursestudent'), 'student', get_string('defaultcoursestudentdescription'), 'moodle/legacy:student');
    $guestrole = create_role(get_string('guest'), 'guest', get_string('guestdescription'), 'moodle/legacy:guest');
    $userrole = create_role(get_string('authenticateduser'), 'user', get_string('authenticateduserdescription'), 'moodle/legacy:user');
    /// Now is the correct moment to install capabilities - after creation of legacy roles, but before assigning of roles
    assign_capability('moodle/site:doanything', CAP_ALLOW, $adminrole, $syscontext->id);
    update_capabilities('moodle');
    /// assign default roles
    role_assign($guestrole, $guest->id, 0, $syscontext->id);
    role_assign($adminrole, $admin->id, 0, $syscontext->id);
    /// Default allow assign/override/switch.
    $defaultallows = array($coursecreatorrole => $noneditteacherrole, $coursecreatorrole => $editteacherrole, $coursecreatorrole => $studentrole, $coursecreatorrole => $guestrole, $editteacherrole => $noneditteacherrole, $editteacherrole => $studentrole, $editteacherrole => $guestrole);
    foreach ($defaultallows as $fromroleid => $toroleid) {
        allow_assign($fromroleid, $toroleid);
        allow_override($fromroleid, $toroleid);
        // There is a rant about this in MDL-15841.
        allow_switch($fromroleid, $toroleid);
    }
    allow_switch($noneditteacherrole, $studentrole);
    /// Set up the context levels where you can assign each role.
    set_role_contextlevels($adminrole, get_default_contextlevels('admin'));
    set_role_contextlevels($coursecreatorrole, get_default_contextlevels('coursecreator'));
    set_role_contextlevels($editteacherrole, get_default_contextlevels('editingteacher'));
    set_role_contextlevels($noneditteacherrole, get_default_contextlevels('teacher'));
    set_role_contextlevels($studentrole, get_default_contextlevels('student'));
    set_role_contextlevels($guestrole, get_default_contextlevels('guest'));
    set_role_contextlevels($userrole, get_default_contextlevels('user'));
}
コード例 #7
0
ファイル: enrol.php プロジェクト: nicolasconnault/moodle2.0
 function create_course($course, $skip_fix_course_sortorder = 0)
 {
     global $CFG, $DB;
     // define a template
     if (!empty($CFG->enrol_db_template)) {
         $template = $DB->get_record("course", array('shortname' => $CFG->enrol_db_template));
         $template = (array) $template;
     } else {
         $site = get_site();
         $template = array('startdate' => time() + 3600 * 24, 'summary' => get_string("defaultcoursesummary"), 'format' => "weeks", 'password' => "", 'guest' => 0, 'numsections' => 10, 'idnumber' => '', 'cost' => '', 'newsitems' => 5, 'showgrades' => 1, 'groupmode' => 0, 'groupmodeforce' => 0);
     }
     // overlay template
     foreach (array_keys($template) as $key) {
         if (empty($course->{$key})) {
             $course->{$key} = $template[$key];
         }
     }
     $category = get_course_category($CFG->enrol_db_category);
     // put at the end of category
     $course->sortorder = $category->sortorder + MAX_COURSES_IN_CATEGORY - 1;
     // override with local data
     $course->startdate = time() + 3600 * 24;
     $course->timecreated = time();
     $course->visible = 1;
     // clear out id just in case
     unset($course->id);
     // truncate a few key fields
     $course->idnumber = substr($course->idnumber, 0, 100);
     $course->shortname = substr($course->shortname, 0, 100);
     // store it and log
     if ($newcourseid = $DB->insert_record("course", $course)) {
         // Set up new course
         $section = new object();
         $section->course = $newcourseid;
         // Create a default section.
         $section->section = 0;
         $section->id = $DB->insert_record("course_sections", $section);
         $course = $DB->get_record('course', array('id' => $newcourseid));
         blocks_add_default_course_blocks($course);
         if (!$skip_fix_course_sortorder) {
             fix_course_sortorder();
         }
         add_to_log($newcourseid, "course", "new", "view.php?id={$newcourseid}", "enrol/database auto-creation");
     } else {
         trigger_error("Could not create new course {$extcourse} from  from database");
         notify("Serious Error! Could not create the new course!");
         return false;
     }
     return $newcourseid;
 }
コード例 #8
0
     }
     $newsite = new Object();
     $newsite->fullname = $sitefullname;
     $newsite->shortname = $siteshortname;
     $newsite->summary = $sitesummary;
     $newsite->newsitems = $sitenewsitems;
     $newsite->numsections = 0;
     $newsite->category = 0;
     $newsite->format = 'site';
     // Only for this course
     $newsite->timemodified = time();
     if ($newid = $DB->insert_record('course', $newsite)) {
         // Site created, add blocks for it
         blocks_add_default_course_blocks($DB->get_record('course', array('id' => $newid)));
         // create default course category
         $cat = get_course_category();
     }
 }
 /// Define the unique site ID code if it isn't already
 if (empty($CFG->siteidentifier)) {
     // Unique site identification code
     set_config('siteidentifier', random_string(32) . $_SERVER['HTTP_HOST']);
 }
 /// Check if the guest user exists.  If not, create one.
 if (!$DB->record_exists("user", array("username" => "guest"))) {
     if (!($guest = create_guest_record())) {
         notify("Could not create guest user record !!!");
     }
 }
 /// Set up the admin user
 if (empty($CFG->rolesactive)) {