当前位置: 首页>>代码示例>>PHP>>正文


PHP delete_records_sql函数代码示例

本文整理汇总了PHP中delete_records_sql函数的典型用法代码示例。如果您正苦于以下问题:PHP delete_records_sql函数的具体用法?PHP delete_records_sql怎么用?PHP delete_records_sql使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了delete_records_sql函数的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: webservices_server_submit

function webservices_server_submit(Pieform $form, $values)
{
    global $USER, $SESSION;
    $store = OAuthStore::instance();
    $is_admin = $USER->get('admin') || defined('ADMIN') || defined('INSTITUTIONALADMIN') || $USER->is_institutional_admin() ? true : false;
    $dbserver = get_record('oauth_server_registry', 'id', $values['token']);
    if ($dbserver) {
        if ($values['action'] == 'delete') {
            delete_records_sql('
                                DELETE FROM {oauth_server_token}
                                WHERE osr_id_ref = ?
                                ', array($dbserver->id));
            $store->deleteServer($dbserver->consumer_key, $dbserver->userid, $is_admin);
            $SESSION->add_ok_msg(get_string('oauthserverdeleted', 'auth.webservice'));
        } else {
            if ($values['action'] == 'edit') {
                redirect('/webservice/admin/oauthv1sregister.php?edit=' . $values['token']);
            }
        }
    }
    redirect('/webservice/admin/oauthv1sregister.php');
}
开发者ID:vohung96,项目名称:mahara,代码行数:22,代码来源:oauthv1sregister.php

示例2: instance_config_save

 public static function instance_config_save($instance, $values)
 {
     db_begin();
     // Autosubscribe
     delete_records_sql("DELETE FROM {interaction_forum_instance_config}\n            WHERE field = 'autosubscribe' AND forum = ?", array($instance->get('id')));
     insert_record('interaction_forum_instance_config', (object) array('forum' => $instance->get('id'), 'field' => 'autosubscribe', 'value' => (bool) $values['autosubscribe']));
     if ($values['justcreated'] && $values['autosubscribe']) {
         // Subscribe all existing users in the group to the forums
         if ($userids = get_column('group_member', 'member', 'group', $instance->get('group'))) {
             foreach ($userids as $userid) {
                 insert_record('interaction_forum_subscription_forum', (object) array('forum' => $instance->get('id'), 'user' => $userid));
             }
         }
     }
     // Moderators
     delete_records('interaction_forum_moderator', 'forum', $instance->get('id'));
     foreach ($values['moderator'] as $user) {
         insert_record('interaction_forum_moderator', (object) array('user' => $user, 'forum' => $instance->get('id')));
     }
     // Re-order the forums according to their new ordering
     delete_records_sql('DELETE FROM {interaction_forum_instance_config}
         WHERE field = \'weight\' AND forum IN (
             SELECT id FROM {interaction_instance} WHERE "group" = ?
         )', array($instance->get('group')));
     if (isset($values['weight'])) {
         foreach ($values['weight'] as $weight => $id) {
             if ($id === null) {
                 // This is where the current forum is to be placed
                 $id = $instance->get('id');
             }
             insert_record('interaction_forum_instance_config', (object) array('forum' => $id, 'field' => 'weight', 'value' => $weight));
         }
     } else {
         // Element was ignored - because this is the first forum in a group
         insert_record('interaction_forum_instance_config', (object) array('forum' => $instance->get('id'), 'field' => 'weight', 'value' => 0));
     }
     db_commit();
 }
开发者ID:Br3nda,项目名称:mahara,代码行数:38,代码来源:lib.php

示例3: auth_handle_account_expiries

/**
 * Sends notification e-mails to users in two situations:
 *
 *  - Their account is about to expire. This is controlled by the 'expiry'
 *    field of the usr table. Once that time has passed, the user may not
 *    log in.
 *  - They have not logged in for close to a certain amount of time. If that
 *    amount of time has passed, the user may not log in.
 *
 * The actual prevention of users logging in is handled by the authentication
 * code. This cron job sends e-mails to notify users that these events will
 * happen soon.
 */
function auth_handle_account_expiries()
{
    // The 'expiry' flag on the usr table
    $sitename = get_config('sitename');
    $wwwroot = get_config('wwwroot');
    $expire = get_config('defaultaccountinactiveexpire');
    $warn = get_config('defaultaccountinactivewarn');
    $daystoexpire = ceil($warn / 86400) . ' ';
    $daystoexpire .= $daystoexpire == 1 ? get_string('day') : get_string('days');
    // Expiry warning messages
    if ($users = get_records_sql_array('SELECT u.id, u.username, u.firstname, u.lastname, u.preferredname, u.email, u.admin, u.staff
        FROM {usr} u
        WHERE ' . db_format_tsfield('u.expiry', false) . ' < ?
        AND expirymailsent = 0 AND deleted = 0', array(time() + $warn))) {
        foreach ($users as $user) {
            $displayname = display_name($user);
            _email_or_notify($user, get_string('accountexpirywarning'), get_string('accountexpirywarningtext', 'mahara', $displayname, $sitename, $daystoexpire, $wwwroot . 'contact.php', $sitename), get_string('accountexpirywarninghtml', 'mahara', $displayname, $sitename, $daystoexpire, $wwwroot . 'contact.php', $sitename));
            set_field('usr', 'expirymailsent', 1, 'id', $user->id);
        }
    }
    // Actual expired users
    if ($users = get_records_sql_array('SELECT id
        FROM {usr}
        WHERE ' . db_format_tsfield('expiry', false) . ' < ?', array(time()))) {
        // Users have expired!
        foreach ($users as $user) {
            expire_user($user->id);
        }
    }
    if ($expire) {
        // Inactivity (lastlogin is too old)
        // MySQL doesn't want to compare intervals, so when editing the where clauses below, make sure
        // the intervals are always added to datetimes first.
        $dbexpire = db_interval($expire);
        $dbwarn = db_interval($warn);
        $installationtime = get_config('installation_time');
        $lastactive = "COALESCE(u.lastaccess, u.lastlogin, u.ctime, ?)";
        // Actual inactive users
        if ($users = get_records_sql_array("\n            SELECT u.id\n            FROM {usr} u\n            WHERE {$lastactive} + {$dbexpire} < current_timestamp\n                AND (u.expiry IS NULL OR u.expiry > current_timestamp) AND id > 0", array($installationtime))) {
            // Users have become inactive!
            foreach ($users as $user) {
                deactivate_user($user->id);
            }
        }
        // Inactivity warning emails
        if ($users = get_records_sql_array("\n            SELECT u.id, u.username, u.firstname, u.lastname, u.preferredname, u.email, u.admin, u.staff\n            FROM {usr} u\n            WHERE {$lastactive} + {$dbexpire} < current_timestamp + {$dbwarn}\n                AND (u.expiry IS NULL OR u.expiry > current_timestamp)\n                AND inactivemailsent = 0 AND deleted = 0 AND id > 0", array($installationtime))) {
            foreach ($users as $user) {
                $displayname = display_name($user);
                _email_or_notify($user, get_string('accountinactivewarning'), get_string('accountinactivewarningtext', 'mahara', $displayname, $sitename, $daystoexpire, $sitename), get_string('accountinactivewarninghtml', 'mahara', $displayname, $sitename, $daystoexpire, $sitename));
                set_field('usr', 'inactivemailsent', 1, 'id', $user->id);
            }
        }
    }
    // Institution membership expiry
    delete_records_sql('DELETE FROM {usr_institution}
        WHERE ' . db_format_tsfield('expiry', false) . ' < ? AND expirymailsent = 1', array(time()));
    // Institution membership expiry warnings
    if ($users = get_records_sql_array('
        SELECT
            u.id, u.username, u.firstname, u.lastname, u.preferredname, u.email, u.admin, u.staff,
            ui.institution, ui.expiry, i.displayname as institutionname
        FROM {usr} u
        INNER JOIN {usr_institution} ui ON u.id = ui.usr
        INNER JOIN {institution} i ON ui.institution = i.name
        WHERE ' . db_format_tsfield('ui.expiry', false) . ' < ?
        AND ui.expirymailsent = 0 AND u.deleted = 0', array(time() + $warn))) {
        foreach ($users as $user) {
            $displayname = display_name($user);
            _email_or_notify($user, get_string('institutionmembershipexpirywarning'), get_string('institutionmembershipexpirywarningtext', 'mahara', $displayname, $user->institutionname, $sitename, $daystoexpire, $wwwroot . 'contact.php', $sitename), get_string('institutionmembershipexpirywarninghtml', 'mahara', $displayname, $user->institutionname, $sitename, $daystoexpire, $wwwroot . 'contact.php', $sitename));
            set_field('usr_institution', 'expirymailsent', 1, 'usr', $user->id, 'institution', $user->institution);
        }
    }
}
开发者ID:janaece,项目名称:globalclassroom4_clean-old,代码行数:86,代码来源:lib.php

示例4: set_field_select

                    if ($moderator && $type == 'open') {
                        set_field_select('interaction_forum_topic', 'closed', 0, 'id IN (' . implode(',', $checked) . ')', array());
                        $SESSION->add_ok_msg(get_string('topicopenedsuccess', 'interaction.forum'));
                    } else {
                        if ($type == 'subscribe' && !$forum->subscribed) {
                            db_begin();
                            foreach ($checked as $key => $value) {
                                if (!record_exists('interaction_forum_subscription_topic', 'user', $USER->get('id'), 'topic', $value)) {
                                    insert_record('interaction_forum_subscription_topic', (object) array('user' => $USER->get('id'), 'topic' => $value, 'key' => PluginInteractionForum::generate_unsubscribe_key()));
                                }
                            }
                            db_commit();
                            $SESSION->add_ok_msg(get_string('topicsubscribesuccess', 'interaction.forum'));
                        } else {
                            if ($type == 'unsubscribe' && !$forum->subscribed) {
                                delete_records_sql('DELETE FROM {interaction_forum_subscription_topic}
                WHERE topic IN (' . implode(',', $checked) . ') AND "user" = ?', array($USER->get('id')));
                                $SESSION->add_ok_msg(get_string('topicunsubscribesuccess', 'interaction.forum'));
                            }
                        }
                    }
                }
            }
        }
    } else {
        // $checked contains bad values
        $SESSION->add_error_msg(get_string('topicupdatefailed', 'interaction.forum'));
    }
    redirect('/interaction/forum/view.php?id=' . $forumid . '&offset=' . $offset);
}
if ($membership) {
    $forum->subscribe = pieform(array('name' => 'subscribe_forum', 'renderer' => 'div', 'plugintype' => 'interaction', 'pluginname' => 'forum', 'autofocus' => false, 'elements' => array('submit' => array('type' => 'submit', 'class' => 'btn-subscribe', 'value' => $forum->subscribed ? get_string('unsubscribefromforum', 'interaction.forum') : get_string('subscribetoforum', 'interaction.forum'), 'help' => true), 'forum' => array('type' => 'hidden', 'value' => $forumid), 'redirect' => array('type' => 'hidden', 'value' => 'view'), 'offset' => array('type' => 'hidden', 'value' => $offset), 'type' => array('type' => 'hidden', 'value' => $forum->subscribed ? 'unsubscribe' : 'subscribe'))));
开发者ID:richardmansfield,项目名称:richardms-mahara,代码行数:32,代码来源:view.php

示例5: xmldb_core_upgrade


//.........这里部分代码省略.........
        $table = new XMLDBTable('group');
        $field = new XMLDBField('feedbacknotify');
        $field->setAttributes(XMLDB_TYPE_INTEGER, 1, null, XMLDB_NOTNULL, null, null, null, GROUP_ROLES_ALL);
        if (!field_exists($table, $field)) {
            add_field($table, $field);
        }
    }
    if ($oldversion < 2014073100) {
        log_debug('Delete leftover data which are not associated to any institution');
        // Institution collections
        $collectionids = get_column_sql('
            SELECT id
            FROM {collection} c
            WHERE c.institution IS NOT NULL
                AND NOT EXISTS (SELECT 1 FROM {institution} i WHERE i.name = c.institution)');
        if ($collectionids) {
            require_once get_config('libroot') . 'collection.php';
            $count = 0;
            $limit = 200;
            $total = count($collectionids);
            foreach ($collectionids as $collectionid) {
                $collection = new Collection($collectionid);
                $collection->delete();
                $count++;
                if ($count % $limit == 0) {
                    log_debug("Deleting leftover collections: {$count}/{$total}");
                    set_time_limit(30);
                }
            }
            log_debug("Deleting leftover collections: {$count}/{$total}");
        }
        log_debug('Delete leftover custom layouts / usr registration');
        // Institution custom layouts and registration
        delete_records_sql('
            DELETE FROM {usr_custom_layout}
            WHERE {usr_custom_layout}.institution IS NOT NULL
                AND NOT EXISTS (SELECT 1 FROM {institution} i WHERE i.name = {usr_custom_layout}.institution)');
        delete_records_sql('
            DELETE FROM {usr_registration}
            WHERE {usr_registration}.institution IS NOT NULL
                AND NOT EXISTS (SELECT 1 FROM {institution} i WHERE i.name = {usr_registration}.institution)');
    }
    if ($oldversion < 2014081900) {
        log_debug("Check blocktype 'text' is installed");
        if ($data = check_upgrades('blocktype.text')) {
            upgrade_plugin($data);
        }
    }
    if ($oldversion < 2014091600) {
        log_debug('Allow anonymous pages');
        $table = new XMLDBTable('view');
        $field = new XMLDBField('anonymise');
        $field->setAttributes(XMLDB_TYPE_INTEGER, 1, null, XMLDB_NOTNULL, null, null, null, 0);
        add_field($table, $field);
        set_config('allowanonymouspages', 0);
    }
    if ($oldversion < 2014091800) {
        log_debug("Add 'allowarchives' column to the 'group' table");
        $table = new XMLDBTable('group');
        $field = new XMLDBField('allowarchives');
        $field->setAttributes(XMLDB_TYPE_INTEGER, 1, null, XMLDB_NOTNULL, null, null, null, 0);
        add_field($table, $field);
        log_debug("Add 'submittedstatus' column to 'view' table");
        $table = new XMLDBTable('view');
        $field = new XMLDBField('submittedstatus');
        $field->setAttributes(XMLDB_TYPE_INTEGER, 1, null, XMLDB_NOTNULL, null, null, null, 0, 'submittedtime');
开发者ID:patkira,项目名称:mahara,代码行数:67,代码来源:upgrade.php

示例6: clear_menu_cache

/**
 * Clear the cached menu so that the next visit to the site will recreate the cache.
 *
 * @param   string   $institution   Optional institution name if we only want to delete cache from a certain institution
 */
function clear_menu_cache($institution = null)
{
    if ($institution) {
        try {
            delete_records_sql("DELETE FROM {institution_config} WHERE field LIKE '%/_nav/_%' ESCAPE '/' AND institution = ?", array($institution));
        } catch (SQLException $e) {
            // Institution_config table may not exist on install/upgrade at this point
        }
    } else {
        try {
            delete_records_sql("DELETE FROM {institution_config} WHERE field LIKE '%/_nav/_%' ESCAPE '/'", array());
        } catch (SQLException $e) {
            // Institution_config table may not exist on install/upgrade at this point
        }
    }
}
开发者ID:sarahjcotton,项目名称:mahara,代码行数:21,代码来源:web.php

示例7: delete_records_select

/**
 * Delete one or more records from a table
 *
 * @uses $db
 * @param string $table The database table to be checked against.
 * @param string $select A fragment of SQL to be used in a where clause in the SQL call (used to define the selection criteria).
 * @param array $values When using prepared statements, this is the value array (optional).
 * @return object A PHP standard object with the results from the SQL call.
 * @throws SQLException
 */
function delete_records_select($table, $select = '', $values = null)
{
    if ($select) {
        $select = 'WHERE ' . $select;
    }
    return delete_records_sql('DELETE FROM ' . db_table_name($table) . ' ' . $select, $values);
}
开发者ID:richardmansfield,项目名称:richardms-mahara,代码行数:17,代码来源:dml.php

示例8: checkServerNonce

 /**
  * Check an nonce/timestamp combination.  Clears any nonce combinations
  * that are older than the one received.
  *
  * @param string    consumer_key
  * @param string    token
  * @param int       timestamp
  * @param string    nonce
  * @exception OAuthException2   thrown when the timestamp is not in sequence or nonce is not unique
  */
 public function checkServerNonce($consumer_key, $token, $timestamp, $nonce)
 {
     $high_water = db_format_timestamp($timestamp + $this->max_timestamp_skew);
     $r = get_records_sql_assoc('
                         SELECT MAX(ctime) AS max_stamp, MAX(ctime) > ? AS max_highwater
                         FROM {oauth_server_nonce}
                         WHERE consumer_key = ?
                           AND token        = ?
                         ', array($high_water, $consumer_key, $token));
     $r = (array) array_shift($r);
     if (!empty($r) && $r['max_highwater'] != 'f' && $r['max_highwater'] == 1) {
         throw new OAuthException2('Timestamp is out of sequence. Request rejected. Got ' . $timestamp . ' last max is ' . $r['max_stamp'] . ' allowed skew is ' . $this->max_timestamp_skew);
     }
     // Insert the new combination
     $timestamp_fmt = db_format_timestamp($timestamp);
     $result = execute_sql('
             INSERT INTO {oauth_server_nonce}
               ( consumer_key,
                 token,
                 ctime,
                 nonce )
                 VALUES (?, ?, ?, ?)
             ', array($consumer_key, $token, $timestamp_fmt, $nonce));
     if (!$result) {
         throw new OAuthException2('Duplicate timestamp/nonce combination, possible replay attack.  Request rejected.');
     }
     // Clean up all timestamps older than the one we just received
     $low_water = db_format_timestamp($timestamp - $this->max_timestamp_skew);
     delete_records_sql('
             DELETE FROM {oauth_server_nonce}
             WHERE consumer_key  = ?
               AND token         = ?
               AND ctime         < ?
             ', array($consumer_key, $token, $low_water));
 }
开发者ID:rboyatt,项目名称:mahara,代码行数:45,代码来源:OAuthStoreMahara.php

示例9: export_cleanup_old_exports

/**
 * Looks in the export staging area in dataroot and deletes old, unneeded
 * exports.
 */
function export_cleanup_old_exports()
{
    require_once 'file.php';
    $basedir = get_config('dataroot') . 'export/';
    // If the export directory hasn't been created yet, there's no point
    // running the cron.
    if (!is_dir($basedir)) {
        return;
    }
    $exportdir = new DirectoryIterator($basedir);
    $mintime = time() - 24 * 60 * 60;
    // delete exports older than 24 hours
    // The export dir contains one directory for each user who has created
    // an export, named after their UID
    foreach ($exportdir as $userdir) {
        if ($userdir->isDot()) {
            continue;
        }
        // Each user's directory contains one directory for each export
        // they made, named as the unix timestamp of the time they
        // generated it
        $udir = new DirectoryIterator($basedir . $userdir->getFilename());
        foreach ($udir as $dir) {
            if ($dir->isDot()) {
                continue;
            }
            if ($dir->getCTime() < $mintime) {
                rmdirr($basedir . $userdir->getFilename() . '/' . $dir->getFilename());
            }
        }
    }
    // Remove any rows from the export_archive that are older than 24 hours and are not exports for submissions
    delete_records_sql('DELETE FROM {export_archive} WHERE submission = 0 AND ctime < ?', array(date('Y-m-d H:i:s', $mintime)));
}
开发者ID:vohung96,项目名称:mahara,代码行数:38,代码来源:lib.php

示例10: clear_menu_cache

/**
 * Clear the cached menu so that the next visit to the site will recreate the cache.
 *
 * @param   string   $institution   Optional institution name if we only want to delete cache from a certain institution
 */
function clear_menu_cache($institution = null)
{
    if ($institution) {
        try {
            delete_records_sql("DELETE FROM {institution_config} WHERE field IN ('adminnav','instadminnav','staffnav','inststaffnav','standardnav') AND institution = ?", array($institution));
        } catch (SQLException $e) {
            // Institution_config table may not exist on install/upgrade at this point
        }
    } else {
        try {
            delete_records_sql("DELETE FROM {institution_config} WHERE field IN ('adminnav','instadminnav','staffnav','inststaffnav','standardnav')", array());
        } catch (SQLException $e) {
            // Institution_config table may not exist on install/upgrade at this point
        }
    }
}
开发者ID:kienv,项目名称:mahara,代码行数:21,代码来源:web.php

示例11: institution_suspend_submit

 function institution_suspend_submit(Pieform $form, $values)
 {
     global $SESSION, $USER;
     if (!$USER->get('admin')) {
         $SESSION->add_error_msg(get_string('errorwhilesuspending', 'admin'));
     } else {
         // Need to logout any users that are using this institution's authinstance.
         if ($loggedin = get_records_sql_array("SELECT ui.usr FROM {usr_institution} ui\n                    JOIN {usr} u ON u.id = ui.usr\n                    JOIN {auth_instance} ai ON ai.id = u.authinstance\n                    JOIN {usr_session} us ON us.usr = u.id\n                    WHERE ui.institution = ?\n                    AND ai.institution = ?", array($values['i'], $values['i']))) {
             foreach ($loggedin as $user) {
                 $loggedinarray[] = $user->usr;
             }
             delete_records_sql("DELETE FROM {usr_session} WHERE usr IN (" . join(',', $loggedinarray) . ")");
             $SESSION->add_ok_msg(get_string('institutionlogoutusers', 'admin', count($loggedin)));
         }
         set_field('institution', 'suspended', 1, 'name', $values['i']);
         $SESSION->add_ok_msg(get_string('institutionsuspended', 'admin'));
     }
     redirect('/admin/users/institutions.php?i=' . $values['i']);
 }
开发者ID:sarahjcotton,项目名称:mahara,代码行数:19,代码来源:institutions.php

示例12: group_remove_user

/**
 * Removes a user from a group.
 *
 * Also removes view access given by the user to the group
 *
 * @param int $groupid ID of group
 * @param int $userid  ID of user to remove
 */
function group_remove_user($groupid, $userid = null, $force = false)
{
    // group_user_can_leave checks the validity of groupid and userid
    if (!$force && !group_user_can_leave($groupid, $userid)) {
        throw new AccessDeniedException(get_string('usercantleavegroup', 'group'));
    }
    db_begin();
    delete_records('group_member', 'group', $groupid, 'member', $userid);
    delete_records_sql('DELETE FROM {view_access_group}
        WHERE "group" = ?
        AND view IN (
            SELECT v.id
            FROM {view} v
            WHERE v.owner = ?
        )', array($groupid, $userid));
    db_commit();
    require_once get_config('docroot') . 'interaction/lib.php';
    $interactions = get_column('interaction_instance', 'id', 'group', $groupid);
    foreach ($interactions as $interaction) {
        interaction_instance_from_id($interaction)->interaction_remove_user($userid);
    }
}
开发者ID:Br3nda,项目名称:mahara,代码行数:30,代码来源:group.php

示例13: auth_handle_account_expiries

/**
 * Sends notification e-mails to users in two situations:
 *
 *  - Their account is about to expire. This is controlled by the 'expiry'
 *    field of the usr table. Once that time has passed, the user may not
 *    log in.
 *  - They have not logged in for close to a certain amount of time. If that
 *    amount of time has passed, the user may not log in.
 *
 * The actual prevention of users logging in is handled by the authentication
 * code. This cron job sends e-mails to notify users that these events will
 * happen soon.
 */
function auth_handle_account_expiries()
{
    // The 'expiry' flag on the usr table
    $sitename = get_config('sitename');
    $wwwroot = get_config('wwwroot');
    $expire = get_config('defaultaccountinactiveexpire');
    $warn = get_config('defaultaccountinactivewarn');
    $daystoexpire = ceil($warn / 86400) . ' ';
    $daystoexpire .= $daystoexpire == 1 ? get_string('day') : get_string('days');
    // Expiry warning messages
    if ($users = get_records_sql_array('SELECT u.id, u.username, u.firstname, u.lastname, u.preferredname, u.email, u.admin, u.staff
        FROM {usr} u
        WHERE ' . db_format_tsfield('u.expiry', false) . ' < ?
        AND expirymailsent = 0', array(time() + $warn))) {
        foreach ($users as $user) {
            $displayname = display_name($user);
            email_user($user, null, get_string('accountexpirywarning'), get_string('accountexpirywarningtext', 'mahara', $displayname, $sitename, $daystoexpire, $wwwroot . 'contact.php', $sitename), get_string('accountexpirywarninghtml', 'mahara', $displayname, $sitename, $daystoexpire, $wwwroot . 'contact.php', $sitename));
            set_field('usr', 'expirymailsent', 1, 'id', $user->id);
        }
    }
    // Actual expired users
    if ($users = get_records_sql_array('SELECT id
        FROM {usr}
        WHERE ' . db_format_tsfield('expiry', false) . ' < ?', array(time()))) {
        // Users have expired!
        foreach ($users as $user) {
            expire_user($user->id);
        }
    }
    if ($expire) {
        // Inactivity (lastlogin is too old)
        if ($users = get_records_sql_array('SELECT u.id, u.username, u.firstname, u.lastname, u.preferredname, u.email, u.admin, u.staff
            FROM {usr} u
            WHERE (? - ' . db_format_tsfield('u.lastlogin', false) . ') > ' . ($expire - $warn) . '
            AND inactivemailsent = 0', array(time()))) {
            foreach ($users as $user) {
                $displayname = display_name($user);
                email_user($user, null, get_string('accountinactivewarning'), get_string('accountinactivewarningtext', 'mahara', $displayname, $sitename, $daystoexpire, $sitename), get_string('accountinactivewarninghtml', 'mahara', $displayname, $sitename, $daystoexpire, $sitename));
                set_field('usr', 'inactivemailsent', 1, 'id', $user->id);
            }
        }
        // Actual inactive users
        if ($users = get_records_sql_array('SELECT u.id
            FROM {usr} u
            WHERE (? - ' . db_format_tsfield('lastlogin', false) . ') > ?', array(time(), $expire))) {
            // Users have become inactive!
            foreach ($users as $user) {
                deactivate_user($user->id);
            }
        }
    }
    // Institution membership expiry
    delete_records_sql('DELETE FROM {usr_institution} 
        WHERE ' . db_format_tsfield('expiry', false) . ' < ? AND expirymailsent = 1', array(time()));
    // Institution membership expiry warnings
    if ($users = get_records_sql_array('
        SELECT
            u.id, u.username, u.firstname, u.lastname, u.preferredname, u.email, u.admin, u.staff,
            ui.institution, ui.expiry, i.displayname as institutionname
        FROM {usr} u
        INNER JOIN {usr_institution} ui ON u.id = ui.usr
        INNER JOIN {institution} i ON ui.institution = i.name
        WHERE ' . db_format_tsfield('ui.expiry', false) . ' < ?
        AND ui.expirymailsent = 0', array(time() + $warn))) {
        foreach ($users as $user) {
            $displayname = display_name($user);
            email_user($user, null, get_string('institutionmembershipexpirywarning'), get_string('institutionmembershipexpirywarningtext', 'mahara', $displayname, $user->institutionname, $sitename, $daystoexpire, $wwwroot . 'contact.php', $sitename), get_string('institutionmembershipexpirywarninghtml', 'mahara', $displayname, $user->institutionname, $sitename, $daystoexpire, $wwwroot . 'contact.php', $sitename));
            set_field('usr_institution', 'expirymailsent', 1, 'usr', $user->id, 'institution', $user->institution);
        }
    }
}
开发者ID:Br3nda,项目名称:mahara,代码行数:84,代码来源:lib.php


注:本文中的delete_records_sql函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。