function groupquotasform_submit(Pieform $form, $values)
{
global $SESSION;
$oldquota = get_field('group', 'quota', 'id', $values['groupid']);
$group = new StdClass();
$group->id = $values['groupid'];
$group->quota = $values['quota'];
update_record('group', $group);
if (!empty($values['quota']) && $values['quota'] != $oldquota) {
// We need to alert group admins that the group may now be over the threshold
$quotanotifylimit = get_config_plugin('artefact', 'file', 'quotanotifylimit');
$sqlwhere = " ((g.quotaused / g.quota) * 100) ";
if (is_postgres()) {
$sqlwhere = " ((CAST(g.quotaused AS float) / CAST(g.quota AS float)) * 100) ";
}
if ($groups = get_records_sql_assoc("SELECT g.id, g.name, g.quota, " . $sqlwhere . " AS quotausedpercent FROM {group} g WHERE " . $sqlwhere . " >= ? AND id = ?", array($quotanotifylimit, $values['groupid']))) {
require_once get_config('docroot') . 'artefact/file/lib.php';
ArtefactTypeFile::notify_groups_threshold_exceeded($groups);
}
}
$SESSION->add_ok_msg(get_string('groupquotaupdated', 'admin'));
redirect(get_config('wwwroot') . 'admin/groups/groups.php');
}
function edituser_site_submit(Pieform $form, $values)
{
global $USER, $authobj, $SESSION;
if (!($user = get_record('usr', 'id', $values['id']))) {
return false;
}
if (is_using_probation()) {
// Value should be between 0 and 10 inclusive
$user->probation = ensure_valid_probation_points($values['probationpoints']);
}
if ($USER->get('admin') || get_config_plugin('artefact', 'file', 'institutionaloverride')) {
$user->quota = $values['quota'];
// check if the user has gone over the quota notify limit
$quotanotifylimit = get_config_plugin('artefact', 'file', 'quotanotifylimit');
if ($quotanotifylimit <= 0 || $quotanotifylimit >= 100) {
$quotanotifylimit = 100;
}
$user->quotausedpercent = $user->quotaused / $user->quota * 100;
$overlimit = false;
if ($quotanotifylimit <= $user->quotausedpercent) {
$overlimit = true;
}
$notified = get_field('usr_account_preference', 'value', 'field', 'quota_exceeded_notified', 'usr', $user->id);
if ($overlimit && '1' !== $notified) {
require_once get_config('docroot') . 'artefact/file/lib.php';
ArtefactTypeFile::notify_users_threshold_exceeded(array($user), false);
// no need to email admin as we can alert them right now
$SESSION->add_error_msg(get_string('useroverquotathreshold', 'artefact.file', display_name($user)));
} else {
if ($notified && !$overlimit) {
set_account_preference($user->id, 'quota_exceeded_notified', false);
}
}
}
$unexpire = $user->expiry && strtotime($user->expiry) < time() && (empty($values['expiry']) || $values['expiry'] > time());
$newexpiry = db_format_timestamp($values['expiry']);
if ($user->expiry != $newexpiry) {
$user->expiry = $newexpiry;
if ($unexpire) {
$user->expirymailsent = 0;
$user->lastaccess = db_format_timestamp(time());
}
}
// Try to kick the user from any active login sessions, before saving data.
require_once get_config('docroot') . 'auth/session.php';
remove_user_sessions($user->id);
if ($USER->get('admin')) {
// Not editable by institutional admins
$user->staff = (int) ($values['staff'] == 'on');
$user->admin = (int) ($values['admin'] == 'on');
if ($user->admin) {
activity_add_admin_defaults(array($user->id));
}
}
if ($values['maildisabled'] == 0 && get_account_preference($user->id, 'maildisabled') == 1) {
// Reset the sent and bounce counts otherwise mail will be disabled
// on the next send attempt
$u = new StdClass();
$u->email = $user->email;
$u->id = $user->id;
update_bounce_count($u, true);
update_send_count($u, true);
}
set_account_preference($user->id, 'maildisabled', $values['maildisabled']);
// process the change of the authinstance and or the remoteuser
if (isset($values['authinstance']) && isset($values['remoteusername'])) {
// Authinstance can be changed by institutional admins if both the
// old and new authinstances belong to the admin's institutions
$authinst = get_records_select_assoc('auth_instance', 'id = ? OR id = ?', array($values['authinstance'], $user->authinstance));
// But don't bother if the auth instance doesn't take a remote username
$authobj = AuthFactory::create($values['authinstance']);
if ($USER->get('admin') || $USER->is_institutional_admin($authinst[$values['authinstance']]->institution) && ($USER->is_institutional_admin($authinst[$user->authinstance]->institution) || $user->authinstance == 1)) {
if ($authobj->needs_remote_username()) {
// determine the current remoteuser
$current_remotename = get_field('auth_remote_user', 'remoteusername', 'authinstance', $user->authinstance, 'localusr', $user->id);
if (!$current_remotename) {
$current_remotename = $user->username;
}
// if the remoteuser is empty
if (strlen(trim($values['remoteusername'])) == 0) {
delete_records('auth_remote_user', 'authinstance', $user->authinstance, 'localusr', $user->id);
}
// what should the new remoteuser be
$new_remoteuser = get_field('auth_remote_user', 'remoteusername', 'authinstance', $values['authinstance'], 'localusr', $user->id);
// save the remotename for the target existence check
$target_remotename = $new_remoteuser;
if (!$new_remoteuser) {
$new_remoteuser = $user->username;
}
if (strlen(trim($values['remoteusername'])) > 0) {
// value changed on page - use it
if ($values['remoteusername'] != $current_remotename) {
$new_remoteuser = $values['remoteusername'];
}
}
// only update remote name if the input actually changed on the page or it doesn't yet exist
if ($current_remotename != $new_remoteuser || !$target_remotename) {
// only remove the ones related to this traget authinstance as we now allow multiple
// for dual login mechanisms
delete_records('auth_remote_user', 'authinstance', $values['authinstance'], 'localusr', $user->id);
//.........这里部分代码省略.........
/**
* Creates a group.
*
* All group creation should be done through this function, as the
* implementation of group creation may change over time.
*
* @param array $data Data required to create the group. The following
* key/value pairs can be specified:
*
* - name: The group name [required, must be unique]
* - description: The group description [optional, defaults to empty string]
* - grouptype: The grouptype for the new group. Must be an installed grouptype.
* - open (jointype): anyone can join the group
* - controlled (jointype): admin adds members; members cannot leave the group
* - request: allows membership requests
* - ctime: The unix timestamp of the time the group will be recorded as having
* been created. Defaults to the current time.
* - members: Array of users who should be in the group, structured like this:
* array(
* userid => role,
* userid => role,
* ...
* )
* @return int The ID of the created group
*/
function group_create($data)
{
if (!is_array($data)) {
throw new InvalidArgumentException("group_create: data must be an array, see the doc comment for this " . "function for details on its format");
}
if (!isset($data['name'])) {
throw new InvalidArgumentException("group_create: must specify a name for the group");
}
if (get_records_sql_array('SELECT id FROM {group} WHERE LOWER(TRIM(name)) = ?', array(strtolower(trim($data['name']))))) {
throw new UserException(get_string('groupalreadyexists', 'group') . ': ' . $data['name']);
}
if (!isset($data['grouptype']) || !in_array($data['grouptype'], group_get_grouptypes())) {
throw new InvalidArgumentException("group_create: grouptype specified must be an installed grouptype");
}
safe_require('grouptype', $data['grouptype']);
if (!empty($data['open'])) {
if (!empty($data['controlled'])) {
throw new InvalidArgumentException("group_create: a group cannot have both open and controlled membership");
}
if (!empty($data['request'])) {
throw new InvalidArgumentException("group_create: open-membership groups don't accept membership requests");
}
$jointype = 'open';
} else {
if (!empty($data['controlled'])) {
$jointype = 'controlled';
} else {
$jointype = 'approve';
}
}
if (isset($data['jointype'])) {
log_warn("group_create: ignoring supplied jointype");
}
if (!isset($data['ctime'])) {
$data['ctime'] = time();
}
$data['ctime'] = db_format_timestamp($data['ctime']);
$data['public'] = isset($data['public']) ? intval($data['public']) : 0;
$data['hidden'] = isset($data['hidden']) ? intval($data['hidden']) : 0;
$data['hidemembers'] = isset($data['hidemembers']) ? intval($data['hidemembers']) : 0;
$data['hidemembersfrommembers'] = isset($data['hidemembersfrommembers']) ? intval($data['hidemembersfrommembers']) : 0;
$data['groupparticipationreports'] = isset($data['groupparticipationreports']) ? intval($data['groupparticipationreports']) : 0;
$data['usersautoadded'] = isset($data['usersautoadded']) ? intval($data['usersautoadded']) : 0;
$data['quota'] = get_config_plugin('artefact', 'file', 'defaultgroupquota');
if (!empty($data['invitefriends']) && !empty($data['suggestfriends'])) {
throw new InvalidArgumentException("group_create: a group cannot enable both invitefriends and suggestfriends");
}
$data['invitefriends'] = isset($data['invitefriends']) ? intval($data['invitefriends']) : 0;
$data['suggestfriends'] = isset($data['suggestfriends']) ? intval($data['suggestfriends']) : 0;
if (isset($data['shortname']) && strlen($data['shortname'])) {
// This is a group whose details and membership can be updated automatically, using a
// webservice api or possibly csv upload.
// On updates to this group, it will be identified using the institution and shortname
// which must be unique.
// The $USER object will be set to someone with at least institutional admin permission.
global $USER;
if (empty($data['institution'])) {
throw new SystemException("group_create: a group with a shortname must have an institution; shortname: " . $data['shortname']);
}
if (!$USER->can_edit_institution($data['institution'])) {
throw new AccessDeniedException("group_create: cannot create a group in this institution");
}
if (!preg_match('/^[a-zA-Z0-9_.-]{2,255}$/', $data['shortname'])) {
$message = get_string('invalidshortname', 'group') . ': ' . $data['shortname'];
$message .= "\n" . get_string('shortnameformat', 'group');
throw new UserException($message);
}
if (record_exists('group', 'shortname', $data['shortname'], 'institution', $data['institution'])) {
throw new UserException('group_create: group with shortname ' . $data['shortname'] . ' and institution ' . $data['institution'] . ' already exists');
}
if (empty($data['members'])) {
$data['members'] = array($USER->get('id') => 'admin');
}
} else {
if (!empty($data['institution'])) {
//.........这里部分代码省略.........
请发表评论