示例#1
0
function requestfriendship_submit(Pieform $form, $values)
{
    global $USER, $SESSION, $id, $goto;
    $loggedinid = $USER->get('id');
    $user = get_record('usr', 'id', $id);
    // friend db record
    $f = new StdClass();
    $f->ctime = db_format_timestamp(time());
    // notification info
    $n = new StdClass();
    $n->url = profile_url($USER, false);
    $n->users = array($user->id);
    $n->fromuser = $loggedinid;
    $lang = get_user_language($user->id);
    $displayname = display_name($USER, $user);
    $n->strings = new stdClass();
    $n->strings->urltext = (object) array('key' => 'Requests');
    $f->owner = $id;
    $f->requester = $loggedinid;
    $f->message = $values['message'];
    insert_record('usr_friend_request', $f);
    $n->subject = get_string_from_language($lang, 'requestedfriendlistsubject', 'group');
    if (isset($values['message']) && !empty($values['message'])) {
        $n->message = get_string_from_language($lang, 'requestedfriendlistmessageexplanation', 'group', $displayname) . $values['message'];
    } else {
        $n->message = get_string_from_language($lang, 'requestedfriendlistinboxmessage', 'group', $displayname);
    }
    require_once 'activity.php';
    activity_occurred('maharamessage', $n);
    handle_event('addfriendrequest', array('requester' => $loggedinid, 'owner' => $id));
    $SESSION->add_ok_msg(get_string('friendformrequestsuccess', 'group', display_name($id)));
    redirect($goto);
}
function cancelrequest_submit(Pieform $form, $values)
{
    global $USER;
    foreach ($values as $k => $v) {
        if (preg_match('/^\\_cancelrequest\\_([a-z0-9]+)$/', $k, $m)) {
            $institution = $m[1];
            break;
        }
    }
    if (!empty($institution)) {
        delete_records('usr_institution_request', 'usr', $USER->id, 'institution', $institution);
        handle_event('updateuser', $USER->id);
    }
    redirect(get_config('wwwroot') . 'account/institutions.php');
}
示例#3
0
/**
 * Notify user (if configured), do the masquerading and emit event. Called when
 * no (further) interaction with the admin is needed before the loginas.
 *
 * @param string $why The masquerading reason (if given) or null.
 */
function do_masquerade($why = null)
{
    global $USER, $SESSION;
    $id = param_integer('id');
    $who = display_name($USER, $id);
    $when = format_date(time());
    if (get_config('masqueradingnotified')) {
        $msg = (object) array('subject' => get_string('masqueradenotificationsubject', 'admin'), 'message' => $why === null ? get_string('masqueradenotificationnoreason', 'admin', $who, $when) : get_string('masqueradenotificationreason', 'admin', $who, $when, $why), 'users' => array($id), 'url' => profile_url($USER, false), 'urltext' => $who);
        activity_occurred('maharamessage', $msg);
        $SESSION->add_info_msg(get_string('masqueradenotificationdone', 'admin'));
    }
    $USER->change_identity_to($id);
    // Permissions checking is done in here
    handle_event('loginas', array('who' => $who, 'when' => $when, 'reason' => $why));
    redirect(get_config('wwwroot'));
}
示例#4
0
function denyrequest_submit(Pieform $form, $values)
{
    global $USER, $SESSION, $id;
    $loggedinid = $USER->get('id');
    $user = get_record('usr', 'id', $id);
    // friend db record
    $f = new StdClass();
    $f->ctime = db_format_timestamp(time());
    // notification info
    $n = new StdClass();
    $n->url = profile_url($USER, false);
    $n->users = array($user->id);
    $n->fromuser = $USER->get('id');
    $lang = get_user_language($user->id);
    $displayname = display_name($USER, $user);
    $n->urltext = $displayname;
    delete_records('usr_friend_request', 'owner', $loggedinid, 'requester', $id);
    $n->subject = get_string_from_language($lang, 'friendrequestrejectedsubject', 'group');
    if (isset($values['reason']) && !empty($values['reason'])) {
        $n->message = get_string_from_language($lang, 'friendrequestrejectedmessagereason', 'group', $displayname) . $values['reason'];
    } else {
        $n->message = get_string_from_language($lang, 'friendrequestrejectedmessage', 'group', $displayname);
    }
    require_once 'activity.php';
    activity_occurred('maharamessage', $n);
    handle_event('removefriendrequest', array('owner' => $loggedinid, 'requester' => $id));
    $SESSION->add_ok_msg(get_string('friendformrejectsuccess', 'group'));
    $offset = param_integer('offset', 0);
    switch (param_alpha('returnto', 'myfriends')) {
        case 'find':
            $goto = 'user/find.php';
            break;
        case 'view':
            $goto = profile_url($user, false);
            break;
        default:
            $goto = 'user/myfriends.php';
            break;
    }
    $goto .= strpos($goto, '?') ? '&offset=' . $offset : '?offset=' . $offset;
    $goto = get_config('wwwroot') . $goto;
    redirect($goto);
}
function removefriend_submit(Pieform $form, $values)
{
    global $USER, $SESSION, $id;
    $loggedinid = $USER->get('id');
    $user = get_record('usr', 'id', $id);
    // friend db record
    $f = new StdClass();
    $f->ctime = db_format_timestamp(time());
    // notification info
    $n = new StdClass();
    $n->url = get_config('wwwroot') . 'user/view.php?id=' . $loggedinid;
    $n->users = array($user->id);
    $lang = get_user_language($user->id);
    $displayname = display_name($USER, $user);
    $n->urltext = $displayname;
    delete_records_select('usr_friend', '(usr1 = ? AND usr2 = ?) OR (usr2 = ? AND usr1 = ?)', array($id, $loggedinid, $id, $loggedinid));
    $n->subject = get_string_from_language($lang, 'removedfromfriendslistsubject', 'group');
    if (isset($values['reason']) && !empty($values['reason'])) {
        $n->message = get_string_from_language($lang, 'removedfromfriendslistmessage', 'group', $displayname) . $values['reason'];
    } else {
        $n->message = get_string_from_language($lang, 'removedfromfriendslistmessage', 'group', $displayname);
    }
    require_once 'activity.php';
    activity_occurred('maharamessage', $n);
    handle_event('removefriend', array('user' => $loggedinid, 'friend' => $id));
    $SESSION->add_ok_msg(get_string('friendformremovesuccess', 'group', display_name($id)));
    switch (param_alpha('returnto', 'myfriends')) {
        case 'find':
            redirect('/user/find.php');
            break;
        case 'view':
            redirect('/user/view.php?id=' . $id);
            break;
        default:
            redirect('/user/myfriends.php');
            break;
    }
}
示例#6
0
文件: skin.php 项目: rboyatt/mahara
function viewskin_submit(Pieform $form, $values)
{
    global $SESSION;
    $view = new View($values['view']);
    $new = $values['new'];
    $view->set('skin', $values['skin']);
    $view->commit();
    handle_event('saveview', $view->get('id'));
    $SESSION->add_ok_msg(get_string('viewskinchanged', 'skin'));
    redirect('/view/view.php?id=' . $view->get('id') . ($new ? '&new=1' : ''));
}
示例#7
0
文件: user.php 项目: patkira/mahara
/**
 * Create user
 *
 * @param object $user stdclass or User object for the usr table
 * @param array  $profile profile field/values to set
 * @param string|object $institution Institution the user should joined to (name or Institution object)
 * @param bool $remoteauth authinstance record for a remote authinstance
 * @param string $remotename username on the remote site
 * @param array $accountprefs user account preferences to set
 * @return integer id of the new user
 */
function create_user($user, $profile = array(), $institution = null, $remoteauth = null, $remotename = null, $accountprefs = array(), $quickhash = false)
{
    db_begin();
    if ($user instanceof User) {
        $user->create();
        $user->quota_init();
        $user->commit();
        $user = $user->to_stdclass();
    } else {
        $user->ctime = db_format_timestamp(time());
        // Ensure this user has a profile urlid
        if (get_config('cleanurls') && (!isset($user->urlid) || is_null($user->urlid))) {
            $user->urlid = generate_urlid($user->username, get_config('cleanurluserdefault'), 3, 30);
            $user->urlid = get_new_profile_urlid($user->urlid);
        }
        if (empty($user->quota)) {
            $user->quota = get_config_plugin('artefact', 'file', 'defaultquota');
        }
        if (get_config('defaultaccountlifetime')) {
            // we need to set the user expiry to the site default one
            $user->expiry = date('Y-m-d', mktime(0, 0, 0, date('m'), date('d'), date('Y')) + (int) get_config('defaultaccountlifetime'));
        }
        $user->id = insert_record('usr', $user, 'id', true);
    }
    if (isset($user->email) && $user->email != '') {
        set_profile_field($user->id, 'email', $user->email, TRUE);
    }
    if (isset($user->firstname) && $user->firstname != '') {
        set_profile_field($user->id, 'firstname', $user->firstname, TRUE);
    }
    if (isset($user->lastname) && $user->lastname != '') {
        set_profile_field($user->id, 'lastname', $user->lastname, TRUE);
    }
    foreach ($profile as $k => $v) {
        if (in_array($k, array('firstname', 'lastname', 'email'))) {
            continue;
        }
        set_profile_field($user->id, $k, $v, TRUE);
    }
    if (!empty($institution)) {
        if (is_string($institution)) {
            $institution = new Institution($institution);
        }
        if ($institution->name != 'mahara') {
            $institution->addUserAsMember($user);
            // uses $user->newuser
            if (empty($accountprefs['licensedefault'])) {
                $accountprefs['licensedefault'] = LICENSE_INSTITUTION_DEFAULT;
            }
        }
    }
    $authobj = get_record('auth_instance', 'id', $user->authinstance);
    $authinstance = AuthFactory::create($authobj->id);
    // For legacy compatibility purposes, we'll also put the remote auth on there if it has been
    // specifically requested.
    if ($authinstance->needs_remote_username() || !empty($remoteauth)) {
        if (isset($remotename) && strlen($remotename) > 0) {
            $un = $remotename;
        } else {
            $un = $user->username;
        }
        // remote username must not already exist
        if (record_exists('auth_remote_user', 'remoteusername', $un, 'authinstance', $user->authinstance)) {
            throw new InvalidArgumentException("user_create: remoteusername already exists: ({$un}, {$user->authinstance})");
        }
        insert_record('auth_remote_user', (object) array('authinstance' => $user->authinstance, 'remoteusername' => $un, 'localusr' => $user->id));
    }
    // Set account preferences
    if (!empty($accountprefs)) {
        $expectedprefs = expected_account_preferences();
        foreach ($expectedprefs as $eprefkey => $epref) {
            if (isset($accountprefs[$eprefkey]) && $accountprefs[$eprefkey] != $epref) {
                set_account_preference($user->id, $eprefkey, $accountprefs[$eprefkey]);
            }
        }
    }
    // Copy site views and collections to the new user's profile
    $userobj = new User();
    $userobj->find_by_id($user->id);
    $userobj->copy_site_views_collections_to_new_user();
    reset_password($user, false, $quickhash);
    handle_event('createuser', $user);
    db_commit();
    return $user->id;
}
示例#8
0
 public function commit()
 {
     if (empty($this->dirty)) {
         return;
     }
     $fordb = new StdClass();
     foreach (get_object_vars($this) as $k => $v) {
         // The configdata is initially fetched from the database in string
         // form. Calls to get() will convert it to an array on the fly. We
         // ensure that it is a string again here
         if ($k == 'configdata' && is_array($v)) {
             $fordb->{$k} = serialize($v);
         } else {
             $fordb->{$k} = $v;
         }
     }
     if (empty($this->id)) {
         $this->id = insert_record('block_instance', $fordb, 'id', true);
     } else {
         update_record('block_instance', $fordb, 'id');
     }
     $this->rebuild_artefact_list();
     // Tell stuff about this
     handle_event('blockinstancecommit', $this);
     $this->dirty = false;
 }
示例#9
0
文件: upgrade.php 项目: Br3nda/mahara
function core_install_lastcoredata_defaults()
{
    db_begin();
    $institution = new StdClass();
    $institution->name = 'mahara';
    $institution->displayname = 'No Institution';
    $institution->authplugin = 'internal';
    $institution->theme = 'default';
    insert_record('institution', $institution);
    $auth_instance = new StdClass();
    $auth_instance->instancename = 'Internal';
    $auth_instance->priority = '1';
    $auth_instance->institution = 'mahara';
    $auth_instance->authname = 'internal';
    $auth_instance->id = insert_record('auth_instance', $auth_instance, 'id', true);
    // Insert the root user
    $user = new StdClass();
    $user->id = 0;
    $user->username = '******';
    $user->password = '******';
    $user->salt = '*';
    $user->firstname = 'System';
    $user->lastname = 'User';
    $user->email = '*****@*****.**';
    $user->quota = get_config_plugin('artefact', 'file', 'defaultquota');
    $user->authinstance = $auth_instance->id;
    if (is_mysql()) {
        // gratuitous mysql workaround
        $newid = insert_record('usr', $user, 'id', true);
        set_field('usr', 'id', 0, 'id', $newid);
        execute_sql('ALTER TABLE {usr} AUTO_INCREMENT=1');
    } else {
        insert_record('usr', $user);
    }
    install_system_profile_view();
    // Insert the admin user
    $user = new StdClass();
    $user->username = '******';
    $user->password = '******';
    $user->authinstance = $auth_instance->id;
    $user->passwordchange = 1;
    $user->admin = 1;
    $user->firstname = 'Admin';
    $user->lastname = 'User';
    $user->email = '*****@*****.**';
    $user->quota = get_config_plugin('artefact', 'file', 'defaultquota');
    $user->id = insert_record('usr', $user, 'id', true);
    set_profile_field($user->id, 'email', $user->email);
    set_profile_field($user->id, 'firstname', $user->firstname);
    set_profile_field($user->id, 'lastname', $user->lastname);
    set_config('installed', true);
    handle_event('createuser', $user->id);
    activity_add_admin_defaults(array($user->id));
    db_commit();
    // if we're installing, set up the block categories here and then poll the plugins.
    // if we're upgrading this happens somewhere else.  This is because of dependency issues around
    // the order of installation stuff.
    install_blocktype_extras();
}
<?php

// addnews ready.
// translator ready
// mail ready
require_once "common.php";
require_once "lib/http.php";
require_once "lib/buffs.php";
require_once "lib/events.php";
tlschema("graveyard");
page_header("The Graveyard");
$skipgraveyardtext = handle_event("graveyard");
$deathoverlord = getsetting('deathoverlord', '`$Ramius');
if (!$skipgraveyardtext) {
    if ($session['user']['alive']) {
        redirect("village.php", "Redirecting from Shades because the player isn't dead!");
    }
    checkday();
}
$battle = false;
strip_all_buffs();
$op = httpget('op');
switch ($op) {
    case "search":
        require_once "lib/graveyard/case_battle_search.php";
        break;
    case "run":
        if (e_rand(0, 2) == 1) {
            output("`\$%s`) curses you for your cowardice.`n`n", $deathoverlord);
            $favor = 5 + e_rand(0, $session['user']['level']);
            if ($favor > $session['user']['deathpower']) {
示例#11
0
 public function set_access($accessdata)
 {
     global $USER;
     require_once 'activity.php';
     $beforeusers = activity_get_viewaccess_users($this->get('id'), $USER->get('id'), 'viewaccess');
     db_begin();
     delete_records('view_access', 'view', $this->get('id'), 'visible', 1);
     // View access
     if ($accessdata) {
         /*
          * There should be a cleaner way to do this
          * $accessdata_added ensures that the same access is not granted twice because the profile page
          * gets very grumpy if there are duplicate access rules
          *
          * Additional rules:
          * - Don't insert records with stopdate in the past
          * - Remove startdates that are in the past
          * - If view allows comments, access record comment permissions, don't apply, so reset them.
          * @todo: merge overlapping date ranges.
          */
         $accessdata_added = array();
         $time = time();
         foreach ($accessdata as $item) {
             if (!empty($item['stopdate']) && $item['stopdate'] < $time) {
                 continue;
             }
             if (!empty($item['startdate']) && $item['startdate'] < $time) {
                 unset($item['startdate']);
             }
             if ($this->get('allowcomments')) {
                 unset($item['allowcomments']);
                 unset($item['approvecomments']);
             }
             $accessrecord = new StdClass();
             switch ($item['type']) {
                 case 'user':
                     $accessrecord->usr = $item['id'];
                     break;
                 case 'group':
                     $accessrecord->group = $item['id'];
                     if (isset($item['role']) && strlen($item['role'])) {
                         // Don't insert a record for a role the group doesn't have
                         $roleinfo = group_get_role_info($item['id']);
                         if (!isset($roleinfo[$item['role']])) {
                             break;
                         }
                         $accessrecord->role = $item['role'];
                     }
                     break;
                 case 'token':
                     $accessrecord->token = $item['id'];
                     break;
                 case 'friends':
                     if (!$this->owner) {
                         continue;
                         // Don't add friend access to group, institution or system views
                     }
                 case 'public':
                 case 'loggedin':
                     $accessrecord->accesstype = $item['type'];
             }
             $accessrecord->view = $this->get('id');
             if (isset($item['allowcomments'])) {
                 $accessrecord->allowcomments = (int) (!empty($item['allowcomments']));
                 if ($accessrecord->allowcomments) {
                     $accessrecord->approvecomments = (int) (!empty($item['approvecomments']));
                 }
             }
             if (isset($item['startdate'])) {
                 $accessrecord->startdate = db_format_timestamp($item['startdate']);
             }
             if (isset($item['stopdate'])) {
                 $accessrecord->stopdate = db_format_timestamp($item['stopdate']);
             }
             if (array_search($accessrecord, $accessdata_added) === false) {
                 insert_record('view_access', $accessrecord);
                 $accessdata_added[] = $accessrecord;
             }
         }
     }
     $data = new StdClass();
     $data->view = $this->get('id');
     $data->owner = $USER->get('id');
     $data->oldusers = $beforeusers;
     activity_occurred('viewaccess', $data);
     handle_event('saveview', $this->get('id'));
     db_commit();
 }
$schemas = array("text" => "village", "clock" => "village", "title" => "village", "talk" => "village", "sayline" => "village", "newest" => "village", "newestplayer" => "village", "newestid" => "village", "gatenav" => "village", "fightnav" => "village", "marketnav" => "village", "tavernnav" => "village", "infonav" => "village", "othernav" => "village", "section" => "village", "innname" => "village", "stablename" => "village", "mercenarycamp" => "village", "armorshop" => "village", "weaponshop" => "village");
// Now store the schemas
$origtexts['schemas'] = $schemas;
// don't hook on to this text for your standard modules please, use "village"
// instead.
// This hook is specifically to allow modules that do other villages to create
// ambience.
$texts = modulehook("villagetext", $origtexts);
//and now a special hook for the village
//$texts = modulehook("villagetext-{$session['user']['location']}",$texts);
$schemas = $texts['schemas'];
tlschema($schemas['title']);
page_header($texts['title']);
tlschema();
addcommentary();
$skipvillagedesc = handle_event("village");
checkday();
if ($session['user']['slaydragon'] == 1) {
    $session['user']['slaydragon'] = 0;
}
if ($session['user']['alive']) {
} else {
    redirect("shades.php", "Player in village but not alive");
}
if (getsetting("automaster", 1) && $session['user']['seenmaster'] != 1) {
    //masters hunt down truant students
    $level = $session['user']['level'] + 1;
    $dks = $session['user']['dragonkills'];
    $expreqd = exp_for_next_level($level, $dks);
    if ($session['user']['experience'] > $expreqd && $session['user']['level'] < 15) {
        redirect("train.php?op=autochallenge", "Master auto-challenge");
示例#13
0
function core_install_lastcoredata_defaults()
{
    global $USER;
    db_begin();
    $institution = new StdClass();
    $institution->name = 'mahara';
    $institution->displayname = 'No Institution';
    $institution->authplugin = 'internal';
    $institution->theme = 'default';
    $institution->priority = 0;
    insert_record('institution', $institution);
    $pages = site_content_pages();
    $now = db_format_timestamp(time());
    foreach ($pages as $name) {
        $page = new stdClass();
        $page->name = $name;
        $page->ctime = $now;
        $page->mtime = $now;
        $page->content = get_string($page->name . 'defaultcontent', 'install', get_string('staticpageconfigdefault', 'install'));
        $page->institution = 'mahara';
        insert_record('site_content', $page);
    }
    $auth_instance = new StdClass();
    $auth_instance->instancename = 'Internal';
    $auth_instance->priority = '1';
    $auth_instance->institution = 'mahara';
    $auth_instance->authname = 'internal';
    $auth_instance->id = insert_record('auth_instance', $auth_instance, 'id', true);
    // Insert the root user
    $user = new StdClass();
    $user->id = 0;
    $user->username = '******';
    $user->password = '******';
    $user->salt = '*';
    $user->firstname = 'System';
    $user->lastname = 'User';
    $user->email = '*****@*****.**';
    $user->quota = get_config_plugin('artefact', 'file', 'defaultquota');
    $user->authinstance = $auth_instance->id;
    if (is_mysql()) {
        // gratuitous mysql workaround
        $newid = insert_record('usr', $user, 'id', true);
        set_field('usr', 'id', 0, 'id', $newid);
        execute_sql('ALTER TABLE {usr} AUTO_INCREMENT=1');
    } else {
        insert_record('usr', $user);
    }
    // install the default layout options
    install_view_layout_defaults();
    require_once 'group.php';
    install_system_profile_view();
    install_system_dashboard_view();
    install_system_grouphomepage_view();
    require_once 'license.php';
    install_licenses_default();
    require_once 'skin.php';
    install_skins_default();
    // Insert the admin user
    $user = new StdClass();
    $user->username = '******';
    $user->salt = auth_get_random_salt();
    $user->password = crypt('mahara', '$2a$' . get_config('bcrypt_cost') . '$' . substr(md5(get_config('passwordsaltmain') . $user->salt), 0, 22));
    $user->password = substr($user->password, 0, 7) . substr($user->password, 7 + 22);
    $user->authinstance = $auth_instance->id;
    $user->passwordchange = 1;
    $user->admin = 1;
    $user->firstname = 'Admin';
    $user->lastname = 'User';
    $user->email = '*****@*****.**';
    $user->quota = get_config_plugin('artefact', 'file', 'defaultquota');
    $user->id = insert_record('usr', $user, 'id', true);
    set_profile_field($user->id, 'email', $user->email);
    set_profile_field($user->id, 'firstname', $user->firstname);
    set_profile_field($user->id, 'lastname', $user->lastname);
    handle_event('createuser', $user);
    activity_add_admin_defaults(array($user->id));
    db_commit();
    // if we're installing, set up the block categories here and then poll the plugins.
    // if we're upgrading this happens somewhere else.  This is because of dependency issues around
    // the order of installation stuff.
    install_blocktype_extras();
}
示例#14
0
文件: view.php 项目: Br3nda/mahara
 public function set_access($accessdata)
 {
     global $USER;
     require_once 'activity.php';
     // For users who are being removed from having access to this view, they
     // need to have the view and any attached artefacts removed from their
     // watchlist.
     $oldusers = array();
     foreach ($this->get_access() as $item) {
         if ($item['type'] == 'user') {
             $oldusers[] = $item;
         }
     }
     $newusers = array();
     if ($accessdata) {
         foreach ($accessdata as $item) {
             if ($item['type'] == 'user') {
                 $newusers[] = $item;
             }
         }
     }
     $userstodelete = array();
     foreach ($oldusers as $olduser) {
         foreach ($newusers as $newuser) {
             if ($olduser['id'] == $newuser['id']) {
                 continue 2;
             }
         }
         $userstodelete[] = $olduser;
     }
     if ($userstodelete) {
         $userids = array();
         foreach ($userstodelete as $user) {
             $userids[] = intval($user['id']);
         }
         $userids = implode(',', $userids);
         execute_sql('DELETE FROM {usr_watchlist_view}
             WHERE view = ' . $this->get('id') . '
             AND usr IN (' . $userids . ')');
     }
     $beforeusers = activity_get_viewaccess_users($this->get('id'), $USER->get('id'), 'viewaccess');
     // Procedure:
     // get list of current friends - this is available in global $data
     // compare with list of new friends
     // work out which friends are being removed
     // foreach friend
     //     // remove record from usr_watchlist_view where usr = ? and view = ?
     //     // remove records from usr_watchlist_artefact where usr = ? and view = ?
     // endforeach
     //
     db_begin();
     delete_records('view_access', 'view', $this->get('id'));
     delete_records('view_access_usr', 'view', $this->get('id'));
     delete_records('view_access_group', 'view', $this->get('id'));
     delete_records('view_access_token', 'view', $this->get('id'), 'visible', 1);
     $time = db_format_timestamp(time());
     // View access
     if ($accessdata) {
         foreach ($accessdata as $item) {
             $accessrecord = new StdClass();
             $accessrecord->view = $this->get('id');
             if (isset($item['startdate'])) {
                 $accessrecord->startdate = db_format_timestamp($item['startdate']);
             }
             if (isset($item['stopdate'])) {
                 $accessrecord->stopdate = db_format_timestamp($item['stopdate']);
             }
             switch ($item['type']) {
                 case 'public':
                 case 'loggedin':
                 case 'friends':
                     $accessrecord->accesstype = $item['type'];
                     insert_record('view_access', $accessrecord);
                     break;
                 case 'user':
                     $accessrecord->usr = $item['id'];
                     insert_record('view_access_usr', $accessrecord);
                     break;
                 case 'group':
                     $accessrecord->group = $item['id'];
                     if ($item['role']) {
                         // Don't insert a record for a role the group doesn't have
                         $roleinfo = group_get_role_info($item['id']);
                         if (!isset($roleinfo[$item['role']])) {
                             break;
                         }
                         $accessrecord->role = $item['role'];
                     }
                     insert_record('view_access_group', $accessrecord);
                     break;
                 case 'token':
                     $accessrecord->token = $item['id'];
                     insert_record('view_access_token', $accessrecord);
                     break;
             }
         }
     }
     $data = new StdClass();
     $data->view = $this->get('id');
     $data->owner = $USER->get('id');
     $data->oldusers = $beforeusers;
     activity_occurred('viewaccess', $data);
     handle_event('saveview', $this->get('id'));
     db_commit();
 }
<?php

include_once dirname(__FILE__) . "/../lib/utilities.php";
include_once dirname(__FILE__) . "/../lib/app.php";
$fixture = file_get_contents("test_status.json");
handle_event($fixture);
<?php

include_once "utilities.php";
include_once "app.php";
//get body
$entityBody = file_get_contents('php://input');
handle_event($entityBody);
示例#17
0
 public function delete()
 {
     if (empty($this->id)) {
         $this->dirty = false;
         return;
     }
     //Propagate the deletion of the block
     handle_event('deleteblockinstance', $this);
     db_begin();
     safe_require('blocktype', $this->get('blocktype'), 'lib.php', 'require_once', true);
     $classname = generate_class_name('blocktype', $this->get('blocktype'));
     if (is_callable($classname . '::delete_instance')) {
         call_static_method($classname, 'delete_instance', $this);
     }
     delete_records('view_artefact', 'block', $this->id);
     delete_records('block_instance', 'id', $this->id);
     db_commit();
     $this->dirty = false;
 }
示例#18
0
 public function removeMember($user)
 {
     if (is_numeric($user)) {
         $user = get_record('usr', 'id', $user);
     }
     db_begin();
     // If the user is being authed by the institution they are
     // being removed from, change them to internal auth, or if
     // we can't find that, some other no institution auth.
     $authinstances = get_records_select_assoc('auth_instance', "institution IN ('mahara', ?)", array($this->name), "institution = 'mahara' DESC, authname = 'internal' DESC");
     $oldauth = $user->authinstance;
     if (isset($authinstances[$oldauth]) && $authinstances[$oldauth]->institution == $this->name) {
         foreach ($authinstances as $ai) {
             if ($ai->authname == 'internal' && $ai->institution == 'mahara') {
                 $user->authinstance = $ai->id;
                 break;
             } else {
                 if ($ai->institution == 'mahara') {
                     $user->authinstance = $ai->id;
                     break;
                 }
             }
         }
         delete_records('auth_remote_user', 'authinstance', $oldauth, 'localusr', $user->id);
         // If the old authinstance was external, the user may need
         // to set a password
         if ($user->password == '') {
             log_debug('resetting pw for ' . $user->id);
             $this->removeMemberSetPassword($user);
         } else {
             if ($authinstances[$oldauth]->authname != 'internal') {
                 $sitename = get_config('sitename');
                 $fullname = display_name($user, null, true);
                 email_user($user, null, get_string('noinstitutionoldpassemailsubject', 'mahara', $sitename, $this->displayname), get_string('noinstitutionoldpassemailmessagetext', 'mahara', $fullname, $this->displayname, $sitename, $user->username, get_config('wwwroot'), get_config('wwwroot'), $sitename, get_config('wwwroot')), get_string('noinstitutionoldpassemailmessagehtml', 'mahara', hsc($fullname), hsc($this->displayname), hsc($sitename), hsc($user->username), get_config('wwwroot'), get_config('wwwroot'), get_config('wwwroot'), hsc($sitename), get_config('wwwroot'), get_config('wwwroot')));
             }
         }
         update_record('usr', $user);
     }
     // If this user has a favourites list which is updated by this institution, remove it
     // from this institution's control.
     // Don't delete it in case the user wants to keep it, but move it out of the way, so
     // another institution can create a new faves list with the same name.
     execute_sql("\n            UPDATE {favorite}\n            SET institution = NULL, shortname = substring(shortname from 1 for 100) || '.' || ?\n            WHERE owner = ? AND institution = ?", array(substr($this->name, 0, 100) . '.' . get_random_key(), $user->id, $this->name));
     execute_sql("\n            DELETE FROM {usr_tag}\n            WHERE usr = ? AND tag " . db_ilike() . " 'lastinstitution:%'", array($user->id));
     insert_record('usr_tag', (object) array('usr' => $user->id, 'tag' => 'lastinstitution:' . strtolower($this->name)));
     // If the user's license default is set to "institution default", remove the pref
     delete_records('usr_account_preference', 'usr', $user->id, 'field', 'licensedefault', 'value', LICENSE_INSTITUTION_DEFAULT);
     delete_records('usr_institution', 'usr', $user->id, 'institution', $this->name);
     handle_event('updateuser', $user->id);
     db_commit();
 }
示例#19
0
文件: group.php 项目: vohung96/mahara
/**
 * Adds a member to a group.
 *
 * Doesn't do any jointype checking, that should be handled by the caller.
 *
 * TODO: it should though. We should probably have group_user_can_be_added
 *
 * @param int $groupid
 * @param int $userid
 * @param string $role
 */
function group_add_user($groupid, $userid, $role = null, $method = 'internal')
{
    $groupid = group_param_groupid($groupid);
    $userid = group_param_userid($userid);
    $gm = new StdClass();
    $gm->member = $userid;
    $gm->group = $groupid;
    $gm->ctime = db_format_timestamp(time());
    if (!$role) {
        $role = get_field_sql('SELECT gt.defaultrole FROM {grouptype} gt, {group} g WHERE g.id = ? AND g.grouptype = gt.name', array($groupid));
    }
    $gm->role = $role;
    $gm->method = $method;
    db_begin();
    insert_record('group_member', $gm);
    delete_records('group_member_request', 'group', $groupid, 'member', $userid);
    delete_records('group_member_invite', 'group', $groupid, 'member', $userid);
    handle_event('userjoinsgroup', $gm);
    db_commit();
    global $USER;
    $USER->reset_grouproles();
}
<?php

include_once dirname(__FILE__) . "/../lib/events.php";
include_once dirname(__FILE__) . "/../lib/utilities.php";
$post = file_get_contents("php://input");
handle_event($post);
示例#21
0
文件: lib.php 项目: kienv/mahara
 /**
  * Does a bulk_delete on a list of artefacts, grouping artefacts of
  * the same type.
  *
  * Currently only tested for folders and their contents.
  */
 public static function delete_by_artefacttype($artefactids)
 {
     if (empty($artefactids)) {
         return;
     }
     db_begin();
     artefact_watchlist_notification($artefactids);
     // Delete comments first
     safe_require('artefact', 'comment');
     ArtefactTypeComment::delete_comments_onartefacts($artefactids);
     $records = get_records_select_assoc('artefact', 'id IN (' . join(',', array_map('intval', $artefactids)) . ')', null, 'artefacttype', 'id,parent,artefacttype,container');
     $containers = array();
     $leaves = array();
     foreach ($records as $r) {
         if ($r->container) {
             $containers[$r->artefacttype][] = (int) $r->id;
         } else {
             $leaves[$r->artefacttype][] = $r->id;
         }
     }
     // Delete non-containers grouped by artefacttype
     foreach ($leaves as $artefacttype => $ids) {
         $classname = generate_artefact_class_name($artefacttype);
         call_static_method($classname, 'bulk_delete', $ids);
     }
     // Delete containers grouped by artefacttype
     foreach ($containers as $artefacttype => $ids) {
         $classname = generate_artefact_class_name($artefacttype);
         if (is_mysql()) {
             set_field_select('artefact', 'parent', null, 'id IN (' . join(',', $ids) . ')', array());
         }
         call_static_method($classname, 'bulk_delete', $ids);
     }
     handle_event('deleteartefacts', $artefactids);
     db_commit();
 }
示例#22
0
function edituser_institution_submit(Pieform $form, $values)
{
    $user = new User();
    if (!$user->find_by_id($values['id'])) {
        return false;
    }
    $userinstitutions = $user->get('institutions');
    global $USER, $SESSION;
    foreach ($userinstitutions as $i) {
        if ($USER->can_edit_institution($i->institution)) {
            if (isset($values[$i->institution . '_submit'])) {
                $newuser = (object) array('usr' => $user->id, 'institution' => $i->institution, 'ctime' => db_format_timestamp($i->ctime), 'studentid' => $values[$i->institution . '_studentid'], 'staff' => (int) ($values[$i->institution . '_staff'] == 'on'), 'admin' => (int) ($values[$i->institution . '_admin'] == 'on'));
                if ($values[$i->institution . '_expiry']) {
                    $newuser->expiry = db_format_timestamp($values[$i->institution . '_expiry']);
                }
                db_begin();
                delete_records('usr_institution', 'usr', $user->id, 'institution', $i->institution);
                insert_record('usr_institution', $newuser);
                if ($newuser->admin) {
                    activity_add_admin_defaults(array($user->id));
                }
                handle_event('updateuser', $user->id);
                db_commit();
                $SESSION->add_ok_msg(get_string('userinstitutionupdated', 'admin', $i->displayname));
                break;
            } else {
                if (isset($values[$i->institution . '_remove'])) {
                    if ($user->id == $USER->id) {
                        $USER->leave_institution($i->institution);
                    } else {
                        $user->leave_institution($i->institution);
                    }
                    $SESSION->add_ok_msg(get_string('userinstitutionremoved', 'admin', $i->displayname));
                    // Institutional admins can no longer access this page
                    // if they remove the user from the institution, so
                    // send them back to user search.
                    if (!$USER->get('admin')) {
                        if (!$USER->is_institutional_admin()) {
                            redirect(get_config('wwwroot'));
                        }
                        redirect('/admin/users/search.php');
                    }
                    break;
                }
            }
        }
    }
    if (isset($values['add']) && $USER->get('admin') && (empty($userinstitutions) || get_config('usersallowedmultipleinstitutions'))) {
        if ($user->id == $USER->id) {
            $USER->join_institution($values['addinstitution']);
            $USER->commit();
            $userinstitutions = $USER->get('institutions');
        } else {
            $user->join_institution($values['addinstitution']);
            $userinstitutions = $user->get('institutions');
        }
        $SESSION->add_ok_msg(get_string('userinstitutionjoined', 'admin', $userinstitutions[$values['addinstitution']]->displayname));
    }
    redirect('/admin/users/edit.php?id=' . $user->id);
}
示例#23
0
 private function changetheme($values)
 {
     if ($theme = $values['theme']) {
         $themes = get_user_accessible_themes();
         if (isset($themes[$theme])) {
             if ($theme == 'sitedefault') {
                 $theme = null;
             }
             $this->set('theme', $theme);
             $this->commit();
             handle_event('saveview', $this->get('id'));
         }
     }
 }
<?php

// addnews ready
// translator ready
// mail ready
require_once "common.php";
require_once "lib/commentary.php";
require_once "lib/villagenav.php";
require_once "lib/events.php";
require_once "lib/http.php";
tlschema("gardens");
page_header("The Gardens");
addcommentary();
$skipgardendesc = handle_event("gardens");
$op = httpget('op');
$com = httpget('comscroll');
$refresh = httpget("refresh");
$commenting = httpget("commenting");
$comment = httppost('insertcommentary');
// Don't give people a chance at a special event if they are just browsing
// the commentary (or talking) or dealing with any of the hooks in the village.
if (!$op && $com == "" && !$comment && !$refresh && !$commenting) {
    if (module_events("gardens", getsetting("gardenchance", 0)) != 0) {
        if (checknavs()) {
            page_footer();
        } else {
            // Reset the special for good.
            $session['user']['specialinc'] = "";
            $session['user']['specialmisc'] = "";
            $skipgardendesc = true;
            $op = "";
示例#25
0
/**
 * Create user
 *
 * @param object $user stdclass or User object for the usr table
 * @param array  $profile profile field/values to set
 * @param string $institution Institution the user should joined to
 * @param stdclass $remoteauth authinstance record for a remote authinstance
 * @param string $remotename username on the remote site
 * @return integer id of the new user
 */
function create_user($user, $profile = array(), $institution = null, $remoteauth = null, $remotename = null)
{
    db_begin();
    if ($user instanceof User) {
        $user->create();
        $user->quota_init();
        $user->commit();
        $user = $user->to_stdclass();
    } else {
        $user->ctime = db_format_timestamp(time());
        if (empty($user->quota)) {
            $user->quota = get_config_plugin('artefact', 'file', 'defaultquota');
        }
        $user->id = insert_record('usr', $user, 'id', true);
    }
    // Bypass access check for 'copynewuser' institution/site views, because this user may not be logged in yet
    $user->newuser = true;
    if (isset($user->email) && $user->email != '') {
        set_profile_field($user->id, 'email', $user->email);
    }
    if (isset($user->firstname) && $user->firstname != '') {
        set_profile_field($user->id, 'firstname', $user->firstname);
    }
    if (isset($user->lastname) && $user->lastname != '') {
        set_profile_field($user->id, 'lastname', $user->lastname);
    }
    foreach ($profile as $k => $v) {
        if (in_array($k, array('firstname', 'lastname', 'email'))) {
            continue;
        }
        set_profile_field($user->id, $k, $v);
    }
    if (!empty($institution) && $institution != 'mahara') {
        if (is_string($institution)) {
            $institution = new Institution($institution);
        }
        if ($institution->name != 'mahara') {
            $institution->addUserAsMember($user);
            // uses $user->newuser
        }
    }
    if (!empty($remoteauth) && $remoteauth->authname != 'internal') {
        if (isset($remotename) && strlen($remotename) > 0) {
            $un = $remotename;
        } else {
            $un = $user->username;
        }
        delete_records('auth_remote_user', 'authinstance', $user->authinstance, 'remoteusername', $un);
        insert_record('auth_remote_user', (object) array('authinstance' => $user->authinstance, 'remoteusername' => $un, 'localusr' => $user->id));
    }
    // Copy site views to the new user's profile
    $checkviewaccess = !$user->newuser;
    $userobj = new User();
    $userobj->find_by_id($user->id);
    $userobj->copy_views(get_column('view', 'id', 'institution', 'mahara', 'copynewuser', 1), $checkviewaccess);
    handle_event('createuser', $user);
    db_commit();
    return $user->id;
}
<?php

// addnews ready
// translator ready
// mail ready
require_once "common.php";
require_once "lib/forest.php";
require_once "lib/fightnav.php";
require_once "lib/http.php";
require_once "lib/taunt.php";
require_once "lib/events.php";
require_once "lib/battle-skills.php";
tlschema("forest");
$fight = false;
page_header("The Forest");
$dontdisplayforestmessage = handle_event("forest");
$op = httpget("op");
$battle = false;
if ($op == "run") {
    if (e_rand() % 3 == 0) {
        output("`c`b`&You have successfully fled your opponent!`0`b`c`n");
        $op = "";
        httpset('op', "");
        unsuspend_buffs();
        foreach ($companions as $index => $companion) {
            if (isset($companion['expireafterfight']) && $companion['expireafterfight']) {
                unset($companions[$index]);
            }
        }
    } else {
        output("`c`b`\$You failed to flee your opponent!`0`b`c");
示例#27
0
文件: index.php 项目: patkira/mahara
function profileform_submit(Pieform $form, $values)
{
    global $SESSION;
    global $USER;
    global $element_list;
    global $profilefields;
    require_once 'embeddedimage.php';
    db_begin();
    $now = db_format_timestamp(time());
    $email_errors = array();
    $lockedfields = locked_profile_fields();
    foreach ($element_list as $element => $type) {
        if (isset($lockedfields[$element]) && !$USER->get('admin')) {
            continue;
        }
        if ($element == 'email') {
            if (!isset($values['email']['unsent'])) {
                $values['email']['unsent'] = array();
            }
            // find new addresses
            foreach ($values['email']['unsent'] as $email) {
                if (in_array($email, $profilefields['email']['validated']) || in_array($email, $profilefields['email']['unvalidated'])) {
                    continue;
                }
                $key = get_random_key();
                $key_url = get_config('wwwroot') . 'artefact/internal/validate.php?email=' . rawurlencode($email) . '&key=' . $key;
                $key_url_decline = $key_url . '&decline=1';
                try {
                    $sitename = get_config('sitename');
                    email_user((object) array('id' => $USER->get('id'), 'username' => $USER->get('username'), 'firstname' => $USER->get('firstname'), 'lastname' => $USER->get('lastname'), 'preferredname' => $USER->get('preferredname'), 'admin' => $USER->get('admin'), 'staff' => $USER->get('staff'), 'email' => $email), null, get_string('emailvalidation_subject', 'artefact.internal'), get_string('emailvalidation_body1', 'artefact.internal', $USER->get('firstname'), $email, $sitename, $key_url, $sitename, $key_url_decline));
                } catch (EmailException $e) {
                    $email_errors[] = $email;
                }
                insert_record('artefact_internal_profile_email', (object) array('owner' => $USER->get('id'), 'email' => $email, 'verified' => 0, 'key' => $key, 'expiry' => db_format_timestamp(time() + 86400)));
            }
            // remove old addresses
            foreach ($profilefields['email']['validated'] as $email) {
                if (in_array($email, $values['email']['validated'])) {
                    continue;
                }
                if (!empty($values['email']['unvalidated']) && in_array($email, $values['email']['unvalidated'])) {
                    continue;
                }
                $artefact_id = get_field('artefact_internal_profile_email', 'artefact', 'email', $email, 'owner', $USER->get('id'));
                delete_records('artefact_internal_profile_email', 'email', $email, 'owner', $USER->get('id'));
                if ($artefact_id) {
                    $artefact = new ArtefactTypeEmail($artefact_id);
                    $artefact->delete();
                    // this is unset here to force the destructor to run now,
                    // rather than script exit time where it doesn't like
                    // throwing exceptions properly
                    unset($artefact);
                }
            }
            foreach ($profilefields['email']['unvalidated'] as $email) {
                if (in_array($email, $values['email']['validated']) || isset($values['email']['unvalidated']) && in_array($email, $values['email']['unvalidated'])) {
                    continue;
                }
                delete_records('artefact_internal_profile_email', 'email', $email, 'owner', $USER->get('id'));
            }
            if ($profilefields['email']['default'] != $values['email']['default']) {
                update_record('artefact_internal_profile_email', (object) array('principal' => 0), (object) array('owner' => $USER->get('id'), 'email' => $profilefields['email']['default']));
                update_record('artefact_internal_profile_email', (object) array('principal' => 1), (object) array('owner' => $USER->get('id'), 'email' => $values['email']['default']));
                update_record('usr', (object) array('email' => $values['email']['default']), (object) array('id' => $USER->get('id')));
                $USER->email = $values['email']['default'];
                $USER->commit();
            }
        } else {
            if ($element == 'maildisabled') {
                continue;
            } else {
                if ($element == 'socialprofile') {
                    continue;
                } else {
                    if (!isset($profilefields[$element]) || $values[$element] != $profilefields[$element]) {
                        if ($element == 'introduction') {
                            $newintroduction = EmbeddedImage::prepare_embedded_images($values[$element], 'profileintrotext', $USER->get('id'));
                            $values[$element] = $newintroduction;
                        }
                        $classname = generate_artefact_class_name($element);
                        $profile = new $classname(0, array('owner' => $USER->get('id')));
                        $profile->set('title', $values[$element]);
                        $profile->commit();
                    }
                }
            }
        }
    }
    try {
        db_commit();
    } catch (Exception $e) {
        profileform_reply($form, PIEFORM_ERR, get_string('profilefailedsaved', 'artefact.internal'));
    }
    handle_event('updateuser', $USER->get('id'));
    if (count($email_errors)) {
        profileform_reply($form, PIEFORM_ERR, array('message' => get_string('emailingfailed', 'artefact.internal', join(', ', $email_errors))));
    }
    profileform_reply($form, PIEFORM_OK, get_string('profilesaved', 'artefact.internal'));
}
 public function removeMember($user)
 {
     if (is_numeric($user)) {
         $user = get_record('usr', 'id', $user);
     }
     db_begin();
     // If the user is being authed by the institution they are
     // being removed from, change them to internal auth, or if
     // we can't find that, some other no institution auth.
     $authinstances = get_records_select_assoc('auth_instance', "institution IN ('mahara', ?)", array($this->name), "institution = 'mahara' DESC, authname = 'internal' DESC");
     $oldauth = $user->authinstance;
     if (isset($authinstances[$oldauth]) && $authinstances[$oldauth]->institution == $this->name) {
         foreach ($authinstances as $ai) {
             if ($ai->authname == 'internal' && $ai->institution == 'mahara') {
                 $user->authinstance = $ai->id;
                 break;
             } else {
                 if ($ai->institution == 'mahara') {
                     $user->authinstance = $ai->id;
                     break;
                 }
             }
         }
         delete_records('auth_remote_user', 'authinstance', $oldauth, 'localusr', $user->id);
         // If the old authinstance was external, the user may need
         // to set a password
         if ($user->password == '') {
             log_debug('resetting pw for ' . $user->id);
             $this->removeMemberSetPassword($user);
         }
         update_record('usr', $user);
     }
     delete_records('usr_institution', 'usr', $user->id, 'institution', $this->name);
     handle_event('updateuser', $user->id);
     db_commit();
 }
function worldmapen_run_real()
{
    global $session, $badguy, $pvptimeout, $options, $outdoors, $shady;
    $outdoors = true;
    $op = httpget("op");
    $battle = false;
    if ($op == 'move' && rawurldecode(httpget('oloc')) != get_module_pref('worldXYZ')) {
        debug(get_module_pref('worldXYZ'));
        $op = 'continue';
        httpset('op', $op);
    }
    //	debug("Worldmap running op={$op} ...");
    // handle the admin editor first
    if ($op == "edit") {
        if (!get_module_pref("canedit")) {
            check_su_access(SU_EDIT_USERS);
        }
        if (get_module_setting("worldmapenInstalled") != 1) {
            set_module_setting('worldmapenInstalled', "1");
            worldmapen_defaultcityloc();
        }
        worldmapen_editor();
    }
    if ($op == "destination") {
        $cname = httpget("cname");
        $session['user']['location'] = $cname;
        addnav(array("Enter %s", $cname), "village.php");
        output("`c`4`bYou've Arrived in %s.`b`0`c`n", $cname);
        output("`cYou have reached the outer gates of the city.`c");
    }
    if (!get_module_setting("worldmapenInstalled")) {
        page_header("A rip in the fabric of space and time");
        require_once "lib/villagenav.php";
        villagenav();
        output("`^The admins of this game haven't yet finished installing the worldmapen module.");
        output("You should send them a petition and tell them that they forgot to generate the initial locations of the cities.");
        output("Until then, you are kind of stuck here, so I hope you like where you are.`n`n");
        output("After all, remember:`nWherever you go, there you are.`0");
        page_footer();
    }
    $subop = httpget("subop");
    $act = httpget("act");
    $type = httpget("type");
    $name = httpget("name");
    $direction = httpget("dir");
    $su = httpget("su");
    $buymap = httpget("buymap");
    $worldmapCostGold = get_module_setting("worldmapCostGold");
    $pvp = httpget('pvp');
    require_once "lib/events.php";
    if ($session['user']['specialinc'] != "" || httpget("eventhandler")) {
        $in_event = handle_event(get_module_setting("randevent"), "runmodule.php?module=worldmapen&op=continue&", "Travel");
        if ($in_event) {
            addnav("Continue", "runmodule.php?module=worldmapen&op=continue");
            module_display_events(get_module_setting("randevent"), "runmodule.php?module=worldmapen&op=continue");
            page_footer();
        }
    }
    page_header("Journey");
    //is the player looking at chat?
    if (httpget('comscroll') || httpget('comscroll') === 0 || httpget('comment') || httpget('refresh')) {
        $chatoverride = 1;
        require_once "lib/commentary.php";
        addcommentary();
        $loc = get_module_pref("worldXYZ", "worldmapen");
        viewcommentary("mapchat-" . $loc, "Chat with others who walk this path...", 25);
    }
    if ($op == "beginjourney") {
        $loc = $session['user']['location'];
        $x = get_module_setting($loc . "X");
        $y = get_module_setting($loc . "Y");
        $z = get_module_setting($loc . "Z");
        $xyz = $x . "," . $y . "," . $z;
        set_module_pref("worldXYZ", $xyz);
        output("`b`&The gates of %s`& stand closed behind you.`0`b`n`n", $session['user']['location']);
        $num = e_rand(1, 5);
        $msg = get_module_setting("leaveGates{$num}");
        output("`c`n`^%s`0`n`c`n", $msg);
        worldmapen_determinenav();
        if (get_module_setting("smallmap")) {
            worldmapen_viewsmallmap();
        }
        if (!$chatoverride) {
            require_once "lib/commentary.php";
            addcommentary();
            $loc = get_module_pref("worldXYZ", "worldmapen");
            viewcommentary("mapchat-" . $loc, "Chat with others who walk this path...", 25);
        }
        worldmapen_viewmapkey(true, false);
        module_display_events(get_module_setting("randevent"), "runmodule.php?module=worldmapen&op=continue");
        $loc = get_module_pref('worldXYZ');
        list($x, $y, $z) = explode(",", $loc);
        $t = worldmapen_getTerrain($x, $y, $z);
        //debug($t);
        if ($t['type'] == "Forest") {
            $shady = true;
        }
    } elseif ($op == "continue") {
        checkday();
        worldmapen_determinenav();
        if (get_module_setting("smallmap")) {
            worldmapen_viewsmallmap();
        }
        if (!$chatoverride) {
            require_once "lib/commentary.php";
            addcommentary();
            $loc = get_module_pref("worldXYZ", "worldmapen");
            viewcommentary("mapchat-" . $loc, "Chat with others who walk this path...", 25);
        }
        worldmapen_viewmapkey(true, false);
        $loc = get_module_pref('worldXYZ');
        list($x, $y, $z) = explode(",", $loc);
        $t = worldmapen_getTerrain($x, $y, $z);
        //debug($t);
        if ($t['type'] == "Forest") {
            $shady = true;
        }
        //Turns Trading bit, added by CavemanJoe
    } elseif ($op == "tradeturn") {
        checkday();
        $pointstrade = get_module_setting("turntravel");
        output("You can trade one Turn for %s Travel Points.  Do you want to do this now?", $pointstrade);
        addnav("Yes, use a turn", "runmodule.php?module=worldmapen&op=tradeturnconfirm");
        addnav("No, cancel and return to the map", "runmodule.php?module=worldmapen&op=continue");
    } elseif ($op == "tradeturnconfirm") {
        $pointstrade = get_module_setting("turntravel");
        output("By conserving energy that you would have otherwise used for fighting creatures, you have gained %s Travel Points.", $pointstrade);
        $session['user']['turns']--;
        $ttoday = get_module_pref("traveltoday", "cities");
        set_module_pref("traveltoday", $ttoday - $pointstrade, "cities");
        addnav("Continue", "runmodule.php?module=worldmapen&op=continue");
    } elseif ($op == "move" && !$chatoverride) {
        checkday();
        if ($session['user']['location'] != 'World') {
            set_module_pref("lastCity", $session['user']['location']);
            $session['user']['location'] = "World";
        }
        $session['user']['restorepage'] = "runmodule.php?module=worldmapen&op=continue";
        $loc = get_module_pref('worldXYZ');
        list($x, $y, $z) = explode(",", $loc);
        if ($direction == "north") {
            $y += 1;
        }
        if (get_module_setting("compasspoints") == "1" and $direction == "northeast") {
            $y += 1;
            $x += 1;
        }
        if (get_module_setting("compasspoints") == "1" and $direction == "northwest") {
            $y += 1;
            $x -= 1;
        }
        if ($direction == "east") {
            $x += 1;
        }
        if ($direction == "south") {
            $y -= 1;
        }
        if (get_module_setting("compasspoints") == "1" and $direction == "southeast") {
            $y -= 1;
            $x += 1;
        }
        if (get_module_setting("compasspoints") == "1" and $direction == "southwest") {
            $y -= 1;
            $x -= 1;
        }
        if ($direction == "west") {
            $x -= 1;
        }
        $terraincost = worldmapen_terrain_cost($x, $y, $z);
        $encounterbase = worldmapen_encounter($x, $y, $z);
        $encounterchance = get_module_pref("encounterchance");
        $encounter = $encounterbase * $encounterchance / 100;
        debug($encounterbase . " * " . $encounterchance . " / 100 = " . $encounter);
        $ttoday = get_module_pref("traveltoday", "cities");
        set_module_pref("traveltoday", $ttoday + $terraincost, "cities");
        worldmapen_terrain_takestamina($x, $y, $z);
        $xyz = $x . "," . $y . "," . $z;
        set_module_pref("worldXYZ", $xyz);
        // $randchance = get_module_setting("randchance");
        // if (e_rand(0,100) < $randchance){
        // $eventravel = "travel";
        // set_module_setting("randevent", $eventravel);
        // }else{
        // $eventravel = "forest";
        // set_module_setting("randevent", $eventravel);
        // }
        //Extra Gubbins pertaining to trading Turns for Travel, added by Caveman Joe
        $useturns = get_module_setting("useturns");
        $allowzeroturns = get_module_setting("allowzeroturns");
        $playerturns = $session['user']['turns'];
        $proceed = 1;
        //the Proceed value is used when the player has hit a monster, to make sure it's okay to actually run the event/monster.
        if ($playerturns == 0 && $allowzeroturns == 0) {
            $proceed = 0;
        }
        if (e_rand(0, 100) < $encounter && $su != '1' && $proceed == 1 && !$chatoverride) {
            // They've hit a monster!
            if (module_events(get_module_setting("randevent"), get_module_setting("wmspecialchance"), "runmodule.php?module=worldmapen&op=continue&") != 0) {
                page_header("Something Special!");
                if (checknavs()) {
                    page_footer();
                } else {
                    // Reset the special for good.
                    $session['user']['specialinc'] = "";
                    $session['user']['specialmisc'] = "";
                    $skipvillagedesc = true;
                    $op = "";
                    httpset("op", "");
                    addnav("Continue", "runmodule.php?module=worldmapen&op=continue&");
                    module_display_events(get_module_setting("randevent"), "runmodule.php?module=worldmapen&op=continue");
                    page_footer();
                }
            }
            //Check if we're removing a turn when the player encounters a monster, and if so, do it
            if ($useturns == 1) {
                $session['user']['turns']--;
            }
            //Fix to only search for Forest type creatures, added by CavemanJoe
            $sql = "SELECT * FROM " . db_prefix("creatures") . " WHERE creaturelevel = '{$session['user']['level']}' AND forest = 1 ORDER BY rand(" . e_rand() . ") LIMIT 1";
            $result = db_query($sql);
            restore_buff_fields();
            if (db_num_rows($result) == 0) {
                // There is nothing in the database to challenge you,
                // let's give you a doppleganger.
                $badguy = array();
                $badguy['creaturename'] = "An evil doppleganger of " . $session['user']['name'];
                $badguy['creatureweapon'] = $session['user']['weapon'];
                $badguy['creaturelevel'] = $session['user']['level'];
                $badguy['creaturegold'] = rand($session['user']['level'] * 15, $session['user']['level'] * 30);
                $badguy['creatureexp'] = round($session['user']['experience'] / 10, 0);
                $badguy['creaturehealth'] = $session['user']['maxhitpoints'];
                $badguy['creatureattack'] = $session['user']['attack'];
                $badguy['creaturedefense'] = $session['user']['defense'];
            } else {
                $badguy = db_fetch_assoc($result);
                require_once "lib/forestoutcomes.php";
                $badguy = buffbadguy($badguy);
            }
            calculate_buff_fields();
            $badguy['playerstarthp'] = $session['user']['hitpoints'];
            $badguy['diddamage'] = 0;
            $badguy['type'] = 'world';
            //debug("Worldmap run.php is debugging badguy");
            //debug($badguy);
            $session['user']['badguy'] = createstring($badguy);
            $battle = true;
        } else {
            // $args = modulehook("count-travels", array('available'=>0, 'used'=>0));
            // $free = max(0, $args['available'] - $args['used']);
            // if (get_module_setting("usestamina")==1){
            // output("`c`nYou think to yourself what a nice day it is.`c`n");
            // } else {
            // output("`c`nYou think to yourself what a nice day it is.`nYou have %s Travel Points remaining.%s`c`n",$free);
            // }
            $free = 100;
            worldmapen_determinenav();
            if (get_module_setting("smallmap")) {
                worldmapen_viewsmallmap();
            }
            if (!$chatoverride) {
                require_once "lib/commentary.php";
                addcommentary();
                $loc = get_module_pref("worldXYZ", "worldmapen");
                viewcommentary("mapchat-" . $loc, "Chat with others who walk this path...", 25);
            }
            worldmapen_viewmapkey(true, false);
            module_display_events(get_module_setting("randevent"), "runmodule.php?module=worldmapen&op=continue");
        }
        $loc = get_module_pref('worldXYZ');
        list($x, $y, $z) = explode(",", $loc);
        $t = worldmapen_getTerrain($x, $y, $z);
        //debug($t);
        if ($t['type'] == "Forest") {
            $shady = true;
        }
    } elseif ($op == "gypsy") {
        $outdoors = false;
        if ($buymap == '') {
            output("`5\"`!Ah, yes.  An adventurer.  I could tell by looking into your eyes,`5\" the gypsy says.`n");
            output("\"`!Many people have lost their way while journeying without a guide such as this.");
            output("It will let you see all the world.`5\"`n");
            output("\"`!Yes, yes.  Let's see...  What sort of price should we put on this?");
            output("Hmm.  How about `^%s`! gold?`5\"", $worldmapCostGold);
            addnav(array("Buy World Map `0(`^%s gold`0)", $worldmapCostGold), "runmodule.php?module=worldmapen&op=gypsy&buymap=yes");
            addnav("Forget it", "village.php");
        } elseif ($buymap == 'yes') {
            if ($session['user']['gold'] < $worldmapCostGold) {
                output("`5\"`!What do you take me for?  A blind hag?  Come back when you have the money`5\"");
                addnav("Leave quickly", "village.php");
            } else {
                output("`5\"`!Enjoy your newfound sight,`5\"  the gypsy says as she walks away to greet some patrons that have just strolled in.");
                $session['user']['gold'] -= $worldmapCostGold;
                set_module_pref("worldmapbuy", 1);
                require_once "lib/villagenav.php";
                villagenav();
            }
        }
    } elseif ($op == "viewmap") {
        worldmapen_determinenav();
        worldmapen_viewmap(true);
        if (is_module_active("medals")) {
            require_once "modules/medals.php";
            medals_award_medal("boughtmap", "Bearer of the Map", "This player purchased the World Map from the Comms Tent!", "medal_islandmap.png");
        }
    } elseif ($op == "camp") {
        if ($session['user']['loggedin']) {
            $session['user']['loggedin'] = 0;
            $session['user']['restorepage'] = "runmodule.php?module=worldmapen&op=wake";
            saveuser();
            invalidatedatacache("charlisthomepage");
            invalidatedatacache("list.php-warsonline");
        }
        $session = array();
        redirect("index.php", "Redirected to Index from World Map");
    } elseif ($op == "wake") {
        if ($session['user']['hitpoints'] > 0) {
            // runmodule.php calls do_forced_nav,
            $session['user']['alive'] = true;
            // and that resets ['alive'], so
        } else {
            // this is from common.php to make sure
            $session['user']['alive'] = false;
            // the player is not half-dead after log-in.
        }
        output("You yawn and stretch and look around your campsite.`n`n");
        output("Ah, how wonderful it is to sleep in the open air!`n");
        output("The world seems full of possibilities today.`n`n");
        checkday();
        worldmapen_determinenav();
        if (get_module_setting("smallmap")) {
            worldmapen_viewsmallmap();
        }
        if (!$chatoverride) {
            require_once "lib/commentary.php";
            addcommentary();
            $loc = get_module_pref("worldXYZ", "worldmapen");
            viewcommentary("mapchat-" . $loc, "Chat with others who walk this path...", 25);
        }
        worldmapen_viewmapkey(true, false);
        $loc = get_module_pref('worldXYZ');
        list($x, $y, $z) = explode(",", $loc);
        $t = worldmapen_getTerrain($x, $y, $z);
        //debug($t);
        if ($t['type'] == "Forest") {
            $shady = true;
        }
    } elseif ($op == "combat") {
        // Okay, we've picked a person to fight.
        require_once "lib/pvpsupport.php";
        $name = httpget("name");
        $badguy = setup_target($name);
        $failedattack = false;
        if ($badguy === false) {
            output("`0`n`nYou survey the area again.`n");
            worldmapen_determinenav();
        } else {
            $battle = true;
            $badguy['type'] = 'pvp';
            //$options['type'] = 'pvp';
            $session['user']['badguy'] = createstring($badguy);
            $session['user']['playerfights']--;
        }
    } elseif ($op == "fight" || $op == "run") {
        if (!$chatoverride && !httpget("frombio")) {
            $battle = true;
        } else {
            worldmapen_determinenav();
            if (get_module_setting("smallmap")) {
                worldmapen_viewsmallmap();
            }
            worldmapen_viewmapkey(true, false);
        }
        // $args = modulehook("count-travels", array('available'=>0,'used'=>0));
        // $free = max(0, $args['available'] - $args['used']);
        // if (get_module_setting("usestamina")==1){
        $free = 100;
        // }
        if ($op == "run" && !$pvp) {
            if (!$chatoverride) {
                if (e_rand(1, 5) < 3 && $free) {
                    // They managed to get away.
                    output("You set off running at a breakneck pace!`n`n");
                    output("A short time later, you have managed to avoid your opponent, so you stop to catch your breath.");
                    $ttoday = get_module_pref("traveltoday", "cities");
                    set_module_pref("traveltoday", $ttoday + 1, "cities");
                    output("As you look around, you realize that all you really managed was to run in circles.");
                    $battle = false;
                    worldmapen_determinenav();
                    if (get_module_setting("smallmap")) {
                        worldmapen_viewsmallmap();
                    }
                    require_once "lib/commentary.php";
                    addcommentary();
                    $loc = get_module_pref("worldXYZ", "worldmapen");
                    viewcommentary("mapchat-" . $loc, "Chat with others who walk this path...", 25);
                    worldmapen_viewmapkey(true, false);
                } else {
                    output("You try to run, but you don't manage to get away!`n");
                    $op = "fight";
                    httpset('op', $op);
                }
            } else {
                if (get_module_setting("smallmap")) {
                    worldmapen_viewsmallmap();
                }
                require_once "lib/commentary.php";
                addcommentary();
                $loc = get_module_pref("worldXYZ", "worldmapen");
                viewcommentary("mapchat-" . $loc, "Chat with others who walk this path...", 25);
                worldmapen_determinenav();
                worldmapen_viewmapkey(true, false);
            }
        } elseif ($op == "run" && $pvp) {
            output("Your pride prevents you from running");
            $op = "fight";
            httpset('op', $op);
        }
        $loc = get_module_pref('worldXYZ');
        list($x, $y, $z) = explode(",", $loc);
        $t = worldmapen_getTerrain($x, $y, $z);
        //debug($t);
        if ($t['type'] == "Forest") {
            $shady = true;
        }
    }
    if ($battle) {
        include_once "battle.php";
        if (isset($enemies) && !$pvp) {
            $badguy =& $enemies;
        }
        if ($victory) {
            if ($pvp) {
                require_once "lib/pvpsupport.php";
                $aliveloc = $badguy['location'];
                pvpvictory($badguy, $aliveloc, $options);
                addnews("`4%s`3 defeated `4%s`3 while they were camped in the wilderness.`0", $session['user']['name'], $badguy['creaturename']);
                $badguy = array();
            } else {
                if (!$chatoverride && !httpget('frombio')) {
                    //is talking
                    require_once "lib/forestoutcomes.php";
                    forestvictory($badguy, false);
                }
            }
            //has just beaten a badguy
            worldmapen_determinenav();
            if (get_module_setting("smallmap")) {
                worldmapen_viewsmallmap();
            }
            if (!$chatoverride) {
                require_once "lib/commentary.php";
                addcommentary();
                $loc = get_module_pref("worldXYZ", "worldmapen");
                viewcommentary("mapchat-" . $loc, "Chat with others who walk this path...", 25);
            }
            worldmapen_viewmapkey(true, false);
        } elseif ($defeat) {
            // Reset the players body to the last city they were in
            $session['user']['location'] = get_module_pref('lastCity');
            if ($pvp) {
                require_once "lib/pvpsupport.php";
                require_once "lib/taunt.php";
                $killedloc = $badguy['location'];
                $taunt = select_taunt();
                pvpdefeat($badguy, $killedloc, $taunt, $options);
                addnews("`4%s`3 was defeated while attacking `4%s`3 as they were camped in the wilderness.`0`n%s", $session['user']['name'], $badguy['creaturename'], $taunt);
            } else {
                require_once "lib/forestoutcomes.php";
                forestdefeat($badguy, "in the wild");
            }
            output("`n`n`&You are sure that someone, sooner or later, will stumble over your corpse and return it to %s`& for you.`0", $session['user']['location']);
        } else {
            require_once "lib/fightnav.php";
            $allow = true;
            $extra = "";
            if ($pvp) {
                $allow = false;
                $extra = "pvp=1&";
            }
            fightnav($allow, $allow, "runmodule.php?module=worldmapen&{$extra}");
        }
    }
    page_footer();
}
示例#30
0
文件: lib.php 项目: Br3nda/mahara
 /** 
  * This function provides basic delete functionality.  It gets rid of the
  * artefact's row in the artefact table, and the tables that reference the
  * artefact table.  It also recursively deletes child artefacts.
  *
  * If your artefact has additional data in another table, you should
  * override this function, but you MUST call parent::delete() after you
  * have done your own thing.
  */
 public function delete()
 {
     if (empty($this->id)) {
         $this->dirty = false;
         return;
     }
     db_begin();
     // Call delete() on children (if there are any)
     if ($children = $this->get_children_instances()) {
         foreach ($children as $child) {
             $child->delete();
         }
     }
     artefact_watchlist_notification($this->id);
     // Delete any references to this artefact from non-artefact places.
     delete_records_select('artefact_parent_cache', 'artefact = ? OR parent = ?', array($this->id, $this->id));
     // Make sure that the artefact is removed from any view blockinstances that have it
     if ($records = get_column('view_artefact', 'block', 'artefact', $this->id)) {
         foreach ($records as $blockid) {
             require_once get_config('docroot') . 'blocktype/lib.php';
             $bi = new BlockInstance($blockid);
             $bi->delete_artefact($this->id);
         }
     }
     delete_records('view_artefact', 'artefact', $this->id);
     delete_records('artefact_feedback', 'artefact', $this->id);
     delete_records('artefact_tag', 'artefact', $this->id);
     delete_records('artefact_access_role', 'artefact', $this->id);
     delete_records('artefact_access_usr', 'artefact', $this->id);
     if ($this->can_be_logged()) {
         $this->log('deleted');
     }
     // Delete the record itself.
     delete_records('artefact', 'id', $this->id);
     handle_event('deleteartefact', $this);
     // Set flags.
     $this->dirty = false;
     $this->parentdirty = true;
     $this->deleted = true;
     db_commit();
 }