Пример #1
0
        } else {
            if (empty($SESSION->sessionverify)) {
                print_error('installsessionerror', 'admin', "index.php?sessionstarted=1&lang={$CFG->lang}");
            }
            unset($SESSION->sessionverify);
        }
    }
    $adminuser = get_complete_user_data('username', 'admin');
    if ($adminuser->password === 'adminsetuppending') {
        // prevent installation hijacking
        if ($adminuser->lastip !== getremoteaddr()) {
            print_error('installhijacked', 'admin');
        }
        // login user and let him set password and admin details
        $adminuser->newadminuser = 1;
        message_set_default_message_preferences($adminuser);
        complete_user_login($adminuser, false);
        redirect("{$CFG->wwwroot}/user/editadvanced.php?id={$adminuser->id}");
        // Edit thyself
    } else {
        unset_config('adminsetuppending');
    }
} else {
    // just make sure upgrade logging is properly terminated
    upgrade_finished('upgradesettings.php');
}
// Turn xmlstrictheaders back on now.
$CFG->xmlstrictheaders = $origxmlstrictheaders;
unset($origxmlstrictheaders);
// Check for valid admin user - no guest autologin
require_login(0, false);
Пример #2
0
    // update mail bounces
    useredit_update_bounces($user, $usernew);

    // update forum track preference
    useredit_update_trackforums($user, $usernew);

    // save custom profile fields data
    profile_save_data($usernew);

    // reload from db
    $usernew = $DB->get_record('user', array('id'=>$usernew->id));

    // trigger events
    if ($usercreated) {
        //set default message preferences
        if (!message_set_default_message_preferences( $usernew )){
            print_error('cannotsavemessageprefs', 'message');
        }
        events_trigger('user_created', $usernew);
    } else {
        events_trigger('user_updated', $usernew);
    }

    if ($user->id == $USER->id) {
        // Override old $USER session variable
        foreach ((array)$usernew as $variable => $value) {
            $USER->$variable = $value;
        }
        // preload custom fields
        profile_load_custom_fields($USER);
Пример #3
0
/**
 * Triggered when a message provider wants to send a message.
 * This functions checks the user's processor configuration to send the given type of message,
 * then tries to send it.
 * @param object $eventdata information about the message (origin, destination, type, content)
 * @return boolean success
 */
function message_send_handler($eventdata)
{
    global $CFG, $DB;
    if (isset($CFG->block_online_users_timetosee)) {
        $timetoshowusers = $CFG->block_online_users_timetosee * 60;
    } else {
        $timetoshowusers = TIMETOSHOWUSERS;
    }
    /// Work out if the user is logged in or not
    if (time() - $eventdata->userto->lastaccess > $timetoshowusers) {
        $userstate = 'loggedoff';
    } else {
        $userstate = 'loggedin';
    }
    /// Create the message object
    $savemessage = new object();
    $savemessage->useridfrom = $eventdata->userfrom->id;
    $savemessage->useridto = $eventdata->userto->id;
    $savemessage->subject = $eventdata->subject;
    $savemessage->fullmessage = $eventdata->fullmessage;
    $savemessage->fullmessageformat = $eventdata->fullmessageformat;
    $savemessage->fullmessagehtml = $eventdata->fullmessagehtml;
    $savemessage->smallmessage = $eventdata->smallmessage;
    $savemessage->timecreated = time();
    /// Find out what processors are defined currently
    /// When a user doesn't have settings none gets return, if he doesn't want contact "" gets returned
    $processor = get_user_preferences('message_provider_' . $eventdata->component . '_' . $eventdata->name . '_' . $userstate, NULL, $eventdata->userto->id);
    if ($processor == NULL) {
        //this user never had a preference, save default
        if (!message_set_default_message_preferences($eventdata->userto)) {
            print_error('cannotsavemessageprefs', 'message');
        }
        if ($userstate == 'loggedin') {
            $processor = 'popup';
        }
        if ($userstate == 'loggedoff') {
            $processor = 'email';
        }
    }
    //if we are suposed to do something with this message
    // No processor for this message, mark it as read
    if ($processor == "") {
        //this user cleared all the preferences
        $savemessage->timeread = time();
        $messageid = $message->id;
        unset($message->id);
        $DB->insert_record('message_read', $savemessage);
    } else {
        // Process the message
        /// Store unread message just in case we can not send it
        $savemessage->id = $DB->insert_record('message', $savemessage);
        /// Try to deliver the message to each processor
        $processorlist = explode(',', $processor);
        foreach ($processorlist as $procname) {
            $processorfile = $CFG->dirroot . '/message/output/' . $procname . '/message_output_' . $procname . '.php';
            if (is_readable($processorfile)) {
                include_once $processorfile;
                // defines $module with version etc
                $processclass = 'message_output_' . $procname;
                if (class_exists($processclass)) {
                    $pclass = new $processclass();
                    if (!$pclass->send_message($savemessage)) {
                        debugging('Error calling message processor ' . $procname);
                        return false;
                    }
                }
            } else {
                debugging('Error calling message processor ' . $procname);
                return false;
            }
        }
    }
    return true;
}
Пример #4
0
/**
 * Called when a message provider wants to send a message.
 * This functions checks the user's processor configuration to send the given type of message,
 * then tries to send it.
 *
 * Required parameter $eventdata structure:
 *  component string component name. must exist in message_providers
 *  name string message type name. must exist in message_providers
 *  userfrom object the user sending the message
 *  userto object the message recipient
 *  subject string the message subject
 *  fullmessage - the full message in a given format
 *  fullmessageformat  - the format if the full message (FORMAT_MOODLE, FORMAT_HTML, ..)
 *  fullmessagehtml  - the full version (the message processor will choose with one to use)
 *  smallmessage - the small version of the message
 *  contexturl - if this is a notification then you can specify a url to view the event. For example the forum post the user is being notified of.
 *  contexturlname - the display text for contexturl
 *
 * @param object $eventdata information about the message (component, userfrom, userto, ...)
 * @return int|false the ID of the new message or false if there was a problem with a processor
 */
function message_send($eventdata) {
    global $CFG, $DB;

    //new message ID to return
    $messageid = false;

    //TODO: we need to solve problems with database transactions here somehow, for now we just prevent transactions - sorry
    $DB->transactions_forbidden();

    if (is_int($eventdata->userto)) {
        mtrace('message_send() userto is a user ID when it should be a user object');
        $eventdata->userto = $DB->get_record('user', array('id' => $eventdata->useridto));
    }
    if (is_int($eventdata->userfrom)) {
        mtrace('message_send() userfrom is a user ID when it should be a user object');
        $eventdata->userfrom = $DB->get_record('user', array('id' => $message->userfrom));
    }

    //after how long inactive should the user be considered logged off?
    if (isset($CFG->block_online_users_timetosee)) {
        $timetoshowusers = $CFG->block_online_users_timetosee * 60;
    } else {
        $timetoshowusers = 300;//5 minutes
    }

    // Work out if the user is logged in or not
    if (!empty($eventdata->userto->lastaccess) && (time()-$timetoshowusers) < $eventdata->userto->lastaccess) {
        $userstate = 'loggedin';
    } else {
        $userstate = 'loggedoff';
    }

    // Create the message object
    $savemessage = new stdClass();
    $savemessage->useridfrom        = $eventdata->userfrom->id;
    $savemessage->useridto          = $eventdata->userto->id;
    $savemessage->subject           = $eventdata->subject;
    $savemessage->fullmessage       = $eventdata->fullmessage;
    $savemessage->fullmessageformat = $eventdata->fullmessageformat;
    $savemessage->fullmessagehtml   = $eventdata->fullmessagehtml;
    $savemessage->smallmessage      = $eventdata->smallmessage;

    if (!empty($eventdata->notification)) {
        $savemessage->notification = $eventdata->notification;
    } else {
        $savemessage->notification = 0;
    }

    if (!empty($eventdata->contexturl)) {
        $savemessage->contexturl = $eventdata->contexturl;
    } else {
        $savemessage->contexturl = null;
    }

    if (!empty($eventdata->contexturlname)) {
        $savemessage->contexturlname = $eventdata->contexturlname;
    } else {
        $savemessage->contexturlname = null;
    }

    $savemessage->timecreated = time();

    // Find out what processors are defined currently
    // When a user doesn't have settings none gets return, if he doesn't want contact "" gets returned
    $preferencename = 'message_provider_'.$eventdata->component.'_'.$eventdata->name.'_'.$userstate;

    $processor = get_user_preferences($preferencename, null, $eventdata->userto->id);
    if ($processor == NULL) { //this user never had a preference, save default
        if (!message_set_default_message_preferences($eventdata->userto)) {
            print_error('cannotsavemessageprefs', 'message');
        }
        $processor = get_user_preferences($preferencename, NULL, $eventdata->userto->id);
        if (empty($processor)) {
            //MDL-25114 They supplied an $eventdata->component $eventdata->name combination which doesn't
            //exist in the message_provider table
            $preferrormsg = get_string('couldnotfindpreference', 'message', $preferencename);
            throw new coding_exception($preferrormsg,'blah');
        }
    }

    if ($processor=='none' && $savemessage->notification) {
        //if they have deselected all processors and its a notification mark it read. The user doesnt want to be bothered
        $savemessage->timeread = time();
        $messageid = $DB->insert_record('message_read', $savemessage);
    } else {                        // Process the message
        // Store unread message just in case we can not send it
        $messageid = $savemessage->id = $DB->insert_record('message', $savemessage);
        $eventdata->savedmessageid = $savemessage->id;

        // Try to deliver the message to each processor
        if ($processor!='none') {
            $processorlist = explode(',', $processor);
            foreach ($processorlist as $procname) {
                $processorfile = $CFG->dirroot. '/message/output/'.$procname.'/message_output_'.$procname.'.php';

                if (is_readable($processorfile)) {
                    include_once($processorfile);  // defines $module with version etc
                    $processclass = 'message_output_' . $procname;

                    if (class_exists($processclass)) {
                        $pclass = new $processclass();

                        if (!$pclass->send_message($eventdata)) {
                            debugging('Error calling message processor '.$procname);
                            $messageid = false;
                        }
                    }
                } else {
                    debugging('Error finding message processor '.$procname);
                    $messageid = false;
                }
            }
            
            //if messaging is disabled and they previously had forum notifications handled by the popup processor
            //or any processor that puts a row in message_working then the notification will remain forever
            //unread. To prevent this mark the message read if messaging is disabled
            if (empty($CFG->messaging)) {
                require_once($CFG->dirroot.'/message/lib.php');
                $messageid = message_mark_message_read($savemessage, time());
            } else if ( $DB->count_records('message_working', array('unreadmessageid' => $savemessage->id)) == 0){
                //if there is no more processors that want to process this we can move message to message_read
                require_once($CFG->dirroot.'/message/lib.php');
                $messageid = message_mark_message_read($savemessage, time(), true);
            }
        }
    }

    return $messageid;
}
Пример #5
0
/**
 * Install Moodle DB,
 * config.php must exist, there must not be any tables in db yet.
 *
 * @param array $options adminpass is mandatory
 * @param bool $interactive
 * @return void
 */
function install_cli_database(array $options, $interactive)
{
    global $CFG, $DB;
    require_once $CFG->libdir . '/environmentlib.php';
    require_once $CFG->libdir . '/upgradelib.php';
    // show as much debug as possible
    @error_reporting(1023);
    @ini_set('display_errors', '1');
    $CFG->debug = 38911;
    $CFG->debugdisplay = true;
    $CFG->version = '';
    $CFG->release = '';
    $version = null;
    $release = null;
    // read $version and $release
    require $CFG->dirroot . '/version.php';
    if ($DB->get_tables()) {
        cli_error(get_string('clitablesexist', 'install'));
    }
    if (empty($options['adminpass'])) {
        cli_error('Missing required admin password');
    }
    // test environment first
    if (!check_moodle_environment(normalize_version($release), $environment_results, false, ENV_SELECT_RELEASE)) {
        $errors = environment_get_errors($environment_results);
        cli_heading(get_string('environment', 'admin'));
        foreach ($errors as $error) {
            list($info, $report) = $error;
            echo "!! {$info} !!\n{$report}\n\n";
        }
        exit(1);
    }
    if (!$DB->setup_is_unicodedb()) {
        if (!$DB->change_db_encoding()) {
            // If could not convert successfully, throw error, and prevent installation
            cli_error(get_string('unicoderequired', 'admin'));
        }
    }
    if ($interactive) {
        cli_separator();
        cli_heading(get_string('databasesetup'));
    }
    // install core
    install_core($version, true);
    set_config('release', $release);
    // install all plugins types, local, etc.
    upgrade_noncore(true);
    // set up admin user password
    $DB->set_field('user', 'password', hash_internal_user_password($options['adminpass']), array('username' => 'admin'));
    // rename admin username if needed
    if (isset($options['adminuser']) and $options['adminuser'] !== 'admin' and $options['adminuser'] !== 'guest') {
        $DB->set_field('user', 'username', $options['adminuser'], array('username' => 'admin'));
    }
    // indicate that this site is fully configured
    set_config('rolesactive', 1);
    upgrade_finished();
    // log in as admin - we need do anything when applying defaults
    $admins = get_admins();
    $admin = reset($admins);
    session_set_user($admin);
    message_set_default_message_preferences($admin);
    // apply all default settings, do it twice to fill all defaults - some settings depend on other setting
    admin_apply_default_settings(NULL, true);
    admin_apply_default_settings(NULL, true);
    set_config('registerauth', '');
    // set the site name
    if (isset($options['shortname']) and $options['shortname'] !== '') {
        $DB->set_field('course', 'shortname', $options['shortname'], array('format' => 'site'));
    }
    if (isset($options['fullname']) and $options['fullname'] !== '') {
        $DB->set_field('course', 'fullname', $options['fullname'], array('format' => 'site'));
    }
}