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 locked_profile_fields()
{
global $USER, $SESSION;
// Profile fields are locked for a user if they are locked by any
// institution the user is a member of, but not an admin for.
$lockinginstitutions = array_keys($USER->get('institutions'));
$lockinginstitutions[] = 'mahara';
$lockinginstitutions = array_diff($lockinginstitutions, $USER->get('admininstitutions'));
$locked = get_records_select_assoc('institution_locked_profile_field', 'name IN (' . join(',', array_map('db_quote', $lockinginstitutions)) . ')', null, '', 'profilefield,name');
if ($remotelocked = $SESSION->get('lockedfields')) {
foreach ($remotelocked as $f) {
if (!isset($locked[$f])) {
$locked[$f] = $f;
}
}
}
return $locked;
}
开发者ID:patkira,项目名称:mahara,代码行数:18,代码来源:index.php
示例4: progressbarform_submit
function progressbarform_submit(Pieform $form, $values)
{
global $SESSION, $USER, $possibleitems;
$institution = $values['institution'];
// Pre-fetching the current settings to reduce SELECT queries
$currentsettings = get_records_select_assoc('institution_config', 'institution=? and field like \'progressbaritem_%\'', array($institution), 'field', 'field, value');
if (!$currentsettings) {
$currentsettings = array();
}
foreach ($possibleitems as $plugin => $pluginitems) {
foreach ($pluginitems as $artefact) {
$itemname = "progressbaritem_{$plugin}_{$artefact->name}";
// Format the value into an integer or 0/1
$val = $values[$itemname];
if ($artefact->iscountable) {
$val = (int) $val;
} else {
$val = (int) (bool) $val;
}
// Update the record if it already exists, or create the record if it doesn't
if (array_key_exists($itemname, $currentsettings)) {
if ($val) {
set_field('institution_config', 'value', $val, 'institution', $institution, 'field', $itemname);
} else {
delete_records('institution_config', 'institution', $institution, 'field', $itemname);
}
} else {
if ($val) {
insert_record('institution_config', (object) array('institution' => $institution, 'field' => $itemname, 'value' => $val));
}
}
}
}
$SESSION->add_ok_msg(get_string('progressbarsaved', 'admin'));
redirect('/admin/users/progressbar.php?institution=' . $institution);
}
/**
* Deletes a Collection
*
*/
public function delete()
{
$viewids = get_column('collection_view', 'view', 'collection', $this->id);
db_begin();
// Delete navigation blocks within the collection's views which point at this collection.
if ($viewids) {
$values = $viewids;
$values[] = 'navigation';
$navigationblocks = get_records_select_assoc('block_instance', 'view IN (' . join(',', array_fill(0, count($viewids), '?')) . ') AND blocktype = ?', $values);
if ($navigationblocks) {
safe_require('blocktype', 'navigation');
foreach ($navigationblocks as $b) {
$bi = new BlockInstance($b->id, $b);
$configdata = $bi->get('configdata');
if (isset($configdata['collection']) && $configdata['collection'] == $this->id) {
$bi->delete();
}
}
}
}
delete_records('collection_view', 'collection', $this->id);
delete_records('collection_tag', 'collection', $this->id);
delete_records('collection', 'id', $this->id);
// Secret url records belong to the collection, so remove them from the view.
// @todo: add user message to whatever calls this.
if ($viewids) {
delete_records_select('view_access', 'view IN (' . join(',', $viewids) . ') AND token IS NOT NULL');
}
db_commit();
}
function locked_profile_fields()
{
global $USER;
// Profile fields are locked for a user if they are locked by any
// institution the user is a member of, but not an admin for.
$lockinginstitutions = array_keys($USER->get('institutions'));
$lockinginstitutions[] = 'mahara';
$lockinginstitutions = array_diff($lockinginstitutions, $USER->get('admininstitutions'));
return get_records_select_assoc('institution_locked_profile_field', 'name IN (' . join(',', array_map('db_quote', $lockinginstitutions)) . ')', null, '', 'profilefield,name');
}
开发者ID:Br3nda,项目名称:mahara,代码行数:10,代码来源:index.php
示例15: get_folder_path_for_file
/**
* Given a file, returns the folder path for it in the Mahara files area
*
* The path is pre-sanitised so it can be used when generating the export
*
* @param $file The file or folder to get the folder path for
* @return string
*/
private function get_folder_path_for_file($file)
{
if ($this->folderdata === null) {
$this->folderdata = get_records_select_assoc('artefact', "artefacttype = 'folder' AND owner = ?", array($file->get('owner')));
if ($this->folderdata) {
foreach ($this->folderdata as &$folder) {
$folder->title = PluginExportHtml::sanitise_path($folder->title);
}
}
}
$folderpath = ArtefactTypeFileBase::get_full_path($file->get('parent'), $this->folderdata);
return $folderpath;
}
开发者ID:rboyatt,项目名称:mahara,代码行数:21,代码来源:lib.php
示例16: removeMember
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();
}
function progressbar_sideblock($preview = false)
{
global $USER;
// TODO: Remove this URL param from here, and when previewing pass institution
// by function param instead
$institution = param_alphanum('i', null);
if (is_array($USER->institutions) && count($USER->institutions) > 0) {
// Get all institutions where user is member
$institutions = array();
foreach ($USER->institutions as $inst) {
if (empty($inst->suspended)) {
$institutions = array_merge($institutions, array($inst->institution => $inst->displayname));
}
}
// Set user's first institution in case that institution isn't
// set yet or user is not member of currently set institution.
if (!$institution || !array_key_exists($institution, $institutions)) {
$institution = key(array_slice($institutions, 0, 1));
}
} else {
$institutions = array();
$institution = 'mahara';
}
// Set appropriate preview according to institution, if the institutio is selected
// If the institution isn't selected then show preview for first institution, which
// is also selected as a default value in institution selection box
if ($preview) {
$default = get_column('institution', 'name');
// TODO: Remove this URL param from here, and when previewing pass institution
// by function param instead
$institution = param_alphanum('institution', $default[0]);
}
// We need to check to see if any of the institutions have profile completeness to allow
// the select box to work correctly for users with more than one institution
$multiinstitutionprogress = false;
$counting = null;
if (!empty($institutions)) {
foreach ($institutions as $key => $value) {
if ($result = get_records_select_assoc('institution_config', 'institution=? and field like \'progressbaritem_%\'', array($key), 'field', 'field, value')) {
$multiinstitutionprogress = true;
if ($key == $institution) {
$counting = $result;
break;
}
}
}
} else {
$counting = get_records_select_assoc('institution_config', 'institution=? and field like \'progressbaritem_%\'', array($institution), 'field', 'field, value');
}
// Get artefacts that count towards profile completeness
if ($counting) {
// Without locked ones (site locked and institution locked)
$sitelocked = (array) get_column('institution_locked_profile_field', 'profilefield', 'name', 'mahara');
$instlocked = (array) get_column('institution_locked_profile_field', 'profilefield', 'name', $institution);
$locked = $sitelocked + $instlocked;
foreach ($locked as $l) {
unset($counting["progressbaritem_internal_{$l}"]);
}
$totalcounting = 0;
foreach ($counting as $c) {
$totalcounting = $totalcounting + $c->value;
}
// Get all artefacts for progressbar and create data structure
$data = array();
// For the artefact_get_progressbar_items function, we want them indexed by plugin
// and then subindexed by artefact. For most other purposes, having them indexed
// by config name is sufficient
$onlytheseplugins = array();
foreach ($counting as $key => $obj) {
// This one has no value. So remove it from the list.
if (!$obj->value) {
unset($counting[$key]);
continue;
}
$parts = explode('_', $obj->field);
$plugin = $parts[1];
$item = $parts[2];
if (empty($onlytheseplugins[$plugin])) {
$onlytheseplugins[$plugin] = array();
}
$onlytheseplugins[$plugin][$item] = $item;
}
$progressbaritems = artefact_get_progressbar_items($onlytheseplugins);
// Get the data link about every item
foreach ($progressbaritems as $pluginname => $itemlist) {
foreach ($itemlist as $artefactname => $item) {
$itemname = "progressbaritem_{$pluginname}_{$artefactname}";
$c = $counting[$itemname];
$target = $c->value;
$completed = 0;
$data[$itemname] = array('artefact' => $artefactname, 'link' => progressbar_artefact_link($pluginname, $artefactname), 'counting' => $target, 'completed' => $completed, 'display' => (bool) $c->value, 'label' => progressbar_artefact_task_label($pluginname, $artefactname, $target, $completed));
}
}
if ($preview) {
$percent = 0;
} else {
// Since this is not a preview, gather data about the users' actual progress,
// and update the records we placed in $data.
// Get a list of all the basic artefact types in this progress bar.
$nonmeta = array();
//.........这里部分代码省略.........
开发者ID:kienv,项目名称:mahara,代码行数:101,代码来源:mahara.php
示例18: artefactchooser_folder_data
public static function artefactchooser_folder_data(&$artefact)
{
// Grab data about all folders the artefact owner has, so we
// can make full paths to them, and show the artefact owner if
// it's a group or institution.
static $folderdata = array();
$ownerkey = $artefact->owner . '::' . $artefact->group . '::' . $artefact->institution;
if (!isset($folderdata[$ownerkey])) {
$ownersql = artefact_owner_sql($artefact->owner, $artefact->group, $artefact->institution);
$folderdata[$ownerkey]->data = get_records_select_assoc('artefact', "artefacttype='folder' AND {$ownersql}", array(), '', 'id, title, parent');
if ($artefact->group) {
$folderdata[$ownerkey]->ownername = get_field('group', 'name', 'id', $artefact->group) . ':';
} else {
if ($artefact->institution) {
if ($artefact->institution == 'mahara') {
$folderdata[$ownerkey]->ownername = get_config('sitename') . ':';
} else {
$folderdata[$ownerkey]->ownername = get_field('institution', 'displayname', 'name', $artefact->institution) . ':';
}
} else {
$folderdata[$ownerkey]->ownername = '';
}
}
}
return $folderdata[$ownerkey];
}
请发表评论