public function layoutMinimodules(array $layout) { $cols = array_keys(FrankizMiniModule::emptyLayout()); $sql = array(); foreach ($cols as $col) { if (isset($layout[$col])) { foreach ($layout[$col] as $row => $name) { $sql[] = XDB::format('({?}, {?}, {?}, {?})', S::user()->id(), $name, $col, $row); } } } XDB::execute('INSERT INTO users_minimodules (uid, name, col, row) VALUES ' . implode(', ', $sql) . ' ON DUPLICATE KEY UPDATE col = VALUES(col), row = VALUES(row)'); if (!(XDB::affectedRows() > 0)) { return false; } $this->select(UserSelect::minimodules()); return true; }
* (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the Free Software * * Foundation, Inc., * * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ***************************************************************************/ /** /** * Activate timeleft inimodue for every user */ require_once dirname(__FILE__) . '/../connect.db.inc.php'; // Get all users $userfilter = new UserFilter(new UFC_Group(Group::from('on_platal'))); $users = $userfilter->get(); $users->select(UserSelect::minimodules()); $users->select(UserSelect::base()); // Get timeleft minimodules $m = FrankizMinimodule::get($argv[1]); foreach ($users as $u) { $minimodules = $u->minimodules(); if (in_array($argv[1], $minimodules)) { echo 'Remove minimodule for ' . $u->login() . PHP_EOL; $u->removeMinimodule($m); } }
public function handler_admin_account($page, $hruid = null, $added = false) { $err = array(); $msg = array(); $add = false; if ($added) { $msg[] = "L'utilisateur a été ajouté avec succès"; } if ($hruid === null) { $user = new User(); $add = true; } else { $user = new UserFilter(new UFC_Hruid($hruid)); $user = $user->get(true); if ($user !== false) { $user->select(UserSelect::tol()); } else { throw new Exception("Impossible de charger les données de l'utilisateur " . $hruid); } } if (Env::has('add_room') && !$add) { $r = Room::batchFrom(array(Env::t('rid'))); if ($r->count() == 0) { $err[] = "La chambre entrée n'existe pas."; } else { $user->addRoom($r->pop()); } } if (Env::has('del_room') && !$add) { $r = Room::batchFrom(array(Env::t('rid'))); if ($r->count() == 0) { $err[] = "La chambre entrée n'existe pas."; } else { $user->removeRoom($r->pop()); } } if (Env::has('add_perm') && !$add && S::user()->isAdmin()) { $user->addPerm(Env::t('perm')); } if (Env::has('del_perm') && !$add && S::user()->isAdmin()) { $user->removePerm(Env::t('perm')); } if (Env::has('upd_study') && !$add) { $user->updateStudy(Env::t('formation_id'), Env::t('forlife'), Env::t('year_in'), Env::t('year_out'), Env::t('promo')); } if (Env::has('add_study') && !$add) { $user->addStudy(Env::t('formation_id'), Env::t('year_in'), Env::t('year_out'), Env::t('promo'), Env::t('forlife')); } if (Env::has('del_study') && !$add) { $user->removeStudy(Env::t('formation_id'), Env::t('forlife')); } if (Env::has('add_group') && !$add) { $g = Group::from(Env::t('name'))->select(GroupSelect::castes()); $g->caste(Rights::member())->addUser($user); } if (Env::has('del_group') && !$add) { $g = Group::from(Env::t('name'))->select(GroupSelect::castes()); $g->caste(Rights::member())->removeUser($user); } if (Env::has('change_profile')) { if ($add) { if (Env::blank('hruid')) { $hruid = Env::t('firstname') . '.' . Env::t('lastname'); $hruid = strtolower($hruid); $already = new UserFilter(new UFC_Hruid($hruid)); $nbr = 1; while ($already->getTotalCount() > 0) { $nbr++; $hruid = Env::t('firstname') . '.' . Env::t('lastname') . '.' . $nbr; $hruid = strtolower($hruid); $already = new UserFilter(new UFC_Hruid($hruid)); } } else { $hruid = Env::t('hruid'); $already = new UserFilter(new UFC_Hruid($hruid)); if ($already->getTotalCount() > 0) { throw new Exception("Le hruid spécifié est déjà pris."); } } $user->insert(); if (Env::blank('hruid')) { $user->hruid($hruid); } $msg[] = "L'utilisateur a été ajouté."; } if (Env::has('image')) { $group = Group::from('tol')->select(GroupSelect::castes()); $image = new ImageFilter(new PFC_And(new IFC_Id(Env::i('image')), new IFC_Temp())); $image = $image->get(true); if (!$image) { throw new Exception("This image doesn't exist anymore"); } $image->select(FrankizImageSelect::caste()); $image->label($user->fullName()); $image->caste($group->caste(Rights::everybody())); $tv = new TolValidate($image, $user); $v = new Validate(array('writer' => $user, 'group' => $group, 'item' => $tv, 'type' => 'tol')); $v->insert(); $msg[] = 'La demande de changement de photo tol a été prise en compte. Les tolmestres essaieront de te la valider au plus tôt.'; } if (Env::has('password')) { $user->password(Env::t('password')); } if (!Env::blank('hruid')) { $user->hruid(Env::t('hruid')); } $user->nickname(Env::t('nickname')); $user->lastname(Env::t('lastname')); $user->firstname(Env::t('firstname')); $user->birthdate(new FrankizDateTime(Env::t('birthdate'))); $user->gender(Env::t('gender') == 'man' ? User::GENDER_MALE : User::GENDER_FEMALE); $user->email(Env::t('bestalias')); $user->cellphone(new Phone(Env::t('cellphone'))); $user->skin(Env::t('skin')); $user->email_format(Env::t('format') == 'text' ? User::FORMAT_TEXT : User::FORMAT_HTML); $user->comment(Env::t('comment')); if ($add) { //Let's add common minimodules if requested (we copy them from anonymous.internal (uid 0) one's) if (Env::has('addCommonMinimodules')) { $user->select(UserSelect::minimodules()); $user->copyMinimodulesFromUser(0); } pl_redirect('profile/admin/account/' . $user->hruid() . '/added'); } } if (!empty($err)) { $page->assign('err', $err); } if (!empty($msg)) { $page->assign('msg', $msg); } $page->assign('formations', XDB::query("SELECT formation_id, label FROM formations")->fetchAllAssoc()); $gfun = new GroupFilter(new PFC_And(new GFC_Namespace('nationality'), new GFC_User($user))); $page->assign('user_nationalities', $gfun->get()->select(GroupSelect::base())->toArray()); $gfn = new GroupFilter(new GFC_Namespace('nationality')); $page->assign('nationalities', $gfn->get()->select(GroupSelect::base())->toArray()); $gfus = new GroupFilter(new PFC_And(new GFC_Namespace('sport'), new GFC_User($user))); $page->assign('user_sports', $gfus->get()->select(GroupSelect::base())->toArray()); $gfs = new GroupFilter(new GFC_Namespace('sport')); $page->assign('sports', $gfs->get()->select(GroupSelect::base())->toArray()); $page->assign('userEdit', $user); $page->addCssLink('profile.css'); $page->assign('add', $add); $page->assign('title', "Changement du profil : " . $user->fullName()); if ($add) { $page->assign('title', "Création d'un utilisateur"); } $page->assign('perms', array('admin')); $page->changeTpl('profile/admin_account.tpl'); }