function updateVisibility($to) { if (!is_array($to)) { $to = array(); } if ($this->that->mayI(EDIT_PRIVILEGES)) { global $DB, $Controller; $b = $Controller->get($DB->privileges->asList(array('id' => $this->that->ID), 'beneficiary')); foreach ($b as $id => $obj) { if (is_a($obj, 'Group') && $this->that->may($obj, READ)) { if (!in_array($id, $to)) { $del[] = $id; } else { arrayRemove($to, $id); } } } foreach ($to as $group) { $this->that->allow($group, READ); } $Controller->forceReload($this->that); } }
function diassociateFrom($name, $ids) { $this->getAssociations($name); $ids = array_map(function ($id) { return is_object($id) ? $id->ID : $id; }, (array) $ids); $this->ASSOCIATIONS[$name] = arrayRemove($this->ASSOCIATIONS[$name], $ids); $DB->associations->delete(array($this->A_INWARDS[$name] ? 'from' : 'to' => $ids, $this->A_INWARDS[$name] ? 'to' : 'from' => $this->ID, 'name' => $this->A_INWARDS[$name] ? $this->A_INWARDS[$name] : $name), false); }
/** * Render the page * @return void */ function run() { global $Templates, $USER, $CONFIG, $Controller, $DB; if (!$this->may($USER, ANYTHING)) { errorPage('401'); } /** * User input types */ $_REQUEST->setType('editField', 'string'); $_REQUEST->setType('editFieldSubm', 'string'); $_REQUEST->setType('newFieldSubm', 'any'); $_REQUEST->setType('fieldlabel', 'string'); $_REQUEST->setType('fieldtype', '#^(string|image|file)$#'); $_REQUEST->setType('fieldvalidation', 'string'); $_REQUEST->setType('deleteField', 'string'); $_REQUEST->setType('moveField', '#^(up|down)$#'); $_REQUEST->setType('field', 'string'); $_REQUEST->setType('oldname', 'string'); /** * Create a new field or edit an existing one */ if ($this->may($USER, EDIT) && ($_REQUEST['newFieldSubm'] || $_REQUEST['editFieldSubm'])) { if (!is_array($a = $CONFIG->userinfo->Fields)) { $a = array(); } $busy = false; $newname = idfy($_REQUEST['fieldlabel']); if (!empty($newname)) { if ($_REQUEST['editFieldSubm'] || !in_array($_REQUEST['newname'], (array) $this->Fields)) { $a[$newname] = array('label' => $_REQUEST['fieldlabel'], 'type' => $_REQUEST['fieldtype'], 'validation' => $_REQUEST['fieldvalidation'], 'description' => $_REQUEST['fielddesc']); if ($_REQUEST['editFieldSubm'] && $_REQUEST['oldname'] != $newname) { $this->Fields = arrayRemove($this->Fields, $_REQUEST['oldname']); unset($a[$_REQUEST['oldname']]); $DB->userinfo->update(array('prop' => $newname), array('prop' => $_REQUEST['oldname']), false, false); $this->Fields[] = $newname; } if ($_REQUEST['newFieldSubm']) { $this->Fields[] = $newname; Flash::create(__('Field created'), 'confirmation'); } else { Flash::create(__('Field updated'), 'confirmation'); } $CONFIG->userinfo->Fields = $a; } else { Flash::create(__('Name is already taken. Please try again')); } } else { Flash::create('Fieldname is not valid. Please try again', 'warning'); } } elseif ($_REQUEST->valid('moveField') && $this->may($USER, EDIT)) { $dir = $_REQUEST['moveField']; $which = $_REQUEST['field']; $uinfoFields = @$CONFIG->userinfo->Fields; if (!is_array($uinfoFields)) { $uinfoFields = array(); } $last = false; $a = array(); foreach ($uinfoFields as $name => $uf) { if ($last == false) { $last = array($name, $uf); continue; } if ($dir == 'up' && $name == $which || $dir == 'down' && $last[0] == $which) { $a[$name] = $uf; } else { $a[$last[0]] = $last[1]; $last = array($name, $uf); } } if ($last) { $a[$last[0]] = $last[1]; } $CONFIG->userinfo->Fields = $a; } elseif ($_REQUEST['deleteField'] !== false && $this->may($USER, DELETE)) { if (!is_array($a = $CONFIG->userinfo->Fields)) { $a = array(); } $na = array(); foreach ($a as $name => $b) { if ($name != $_REQUEST['deleteField']) { $na[$name] = $b; } else { if (in_array($b['type'], array('image', 'file'))) { $otd = $Controller->get($DB->userinfo->asList(array('prop' => $_REQUEST['deleteField']), 'val')); foreach ($otd as $f) { if (is_a($f, 'File') && strpos($f->path, $this->rootDir() . '/UInfoFiles') === 0) { $f->delete(); } } } $DB->userinfo->delete(array('prop' => $_REQUEST['deleteField'])); Flash::create(__('Field removed')); break; } } $CONFIG->userinfo->Fields = $na; } if ($_REQUEST->valid('editField') && in_array($_REQUEST['editField'], $this->Fields)) { $this->setContent('header', __('Edit field')); $this->setContent('main', $this->fieldForm($_REQUEST['editField'])); } else { $this->setContent('header', __('User information-fields')); $this->setContent('main', $this->fieldSettings()); } $Templates->admin->render(); }
/** * Removes a member from the group * @param User|integer $id The user or the user ID to insert into the group * @return bool */ function removeMember($id) { global $DB, $Controller, $USER; if (is_numeric($id)) { $obj = $Controller->get($id); } elseif (is_a($id, 'Base')) { $obj = $id; $id = $obj->ID; } else { return false; } if (in_array($this->GroupType, array('vol', 'volpre')) && $id == $USER->ID || $this->mayI(EDIT)) { $this->loadMembers(); if (in_array($id, $this->_MEMBERS) xor $this->GroupType == 'volpre') { /* * Prevent deletion of the last administrator */ if ($this->ID === ADMIN_GROUP && count($this->_MEMBERS) == 1) { return false; } if ($this->GroupType == 'volpre') { $DB->group_members->insert(array('user' => $id, 'group' => $this->ID), false, true, true); } else { $DB->group_members->delete(array('user' => $id, 'group' => $this->ID)); } $this->_MEMBERS = arrayRemove($this->_MEMBERS, $id, true); Log::write('Removed member \'' . $obj->Name . '\' (id=' . $id . ') from group \'' . $this->Name . '\' (id=' . $this->ID . ')', 10); return true; } else { return false; } } else { return false; } }