示例#1
0
 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');
 }
示例#2
0
文件: platal.php 项目: Ekleog/platal
 function handler_webredir($page)
 {
     $page->changeTpl('platal/webredirect.tpl');
     $page->setTitle('Redirection de page WEB');
     if (Env::v('submit') == 'Valider' && !Env::blank('url')) {
         if (Env::blank('url')) {
             $page->trigError('URL invalide');
         } else {
             $url = Env::t('url');
             XDB::execute('INSERT INTO  carvas (uid, url)
                                VALUES  ({?}, {?})
               ON DUPLICATE KEY UPDATE  url = VALUES(url)', S::i('uid'), $url);
             S::logger()->log('carva_add', 'http://' . $url);
             $page->trigSuccess("Redirection activée vers <a href='http://{$url}'>{$url}</a>");
         }
     } elseif (Env::v('submit') == 'Supprimer') {
         XDB::execute('DELETE FROM carvas
                             WHERE uid = {?}', S::i('uid'));
         Post::kill('url');
         S::logger()->log('carva_del');
         $page->trigSuccess('Redirection supprimée');
     }
     $url = XDB::fetchOneCell('SELECT  url
                                 FROM  carvas
                                WHERE  uid = {?}', S::i('uid'));
     $page->assign('carva', $url);
     # FIXME: this code is not multi-domain compatible. We should decide how
     # carva will extend to users not in the main domain.
     $best = XDB::fetchOneCell('SELECT  email
                                  FROM  email_source_account
                                 WHERE  uid = {?} AND FIND_IN_SET(\'bestalias\', flags)', S::user()->id());
     $page->assign('bestalias', $best);
 }
示例#3
0
 public function blank($key, $strict = false)
 {
     if ($this->fake_env) {
         return $this->fake_env->blank($key, $strict);
     } else {
         return Env::blank($key, $strict);
     }
 }