public function handle_editor() { $this->title = Env::t('title', ''); $this->content = Env::t('news_content', ''); $this->begin = new FrankizDateTime(Env::t('begin')); $this->end = new FrankizDateTime(Env::t('end')); if (Env::has('image')) { $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($this->title); $image->caste($this->target); $this->image($image); } return true; }
function handler_admin($page, $nid = false) { $news = News::fromId($nid); if ($news !== false) { $news->select(NewsSelect::news()); if (S::user()->hasRights($news->target()->group(), Rights::admin()) || S::user()->isWeb()) { if (Env::has('modify') || Env::has('delete')) { S::assert_xsrf_token(); } if (Env::has('modify')) { $news->title(Env::t('title')); $news->content(Env::t('news_content')); $news->begin(new FrankizDateTime(Env::t('begin'))); $news->end(new FrankizDateTime(Env::t('end'))); if (Env::has('reappear')) { $news->removeReadFlags(); } if (Env::has('image')) { $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($news->title()); $image->caste($news->target()); $news->image($image); } $page->assign('msg', "L'annonce a été modifiée."); } if (Env::has('delete')) { $news->delete(); $page->assign('delete', true); } } } $page->assign('news', $news); $page->assign('isEdition', true); $page->assign('title', "Modifier l'annonce"); $page->addCssLink('validate.css'); $page->changeTpl('news/admin.tpl'); }
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'); }
function handler_group_admin($page, $group = null) { $group = Group::fromId($group); if ($group && (S::user()->hasRights($group, Rights::admin()) || S::user()->isWeb())) { $group->select(GroupSelect::see()); $page->assign('group', $group); if (Env::has('name') && Env::t('name') != '' && S::user()->isAdmin()) { S::logger()->log("groups/admin", array("gid" => $group->id(), "old_name" => $group->name(), "new_name" => Env::t('name'))); $group->name(Env::t('name')); } if (Env::has('update') && S::user()->isAdmin()) { $group->external(Env::has('external')); $group->leavable(Env::has('leavable')); $group->visible(Env::has('visible')); } if (Env::has('label')) { $group->label(Env::t('label')); } if (Env::has('update')) { $group->description(Env::t('description')); $group->web(Env::t('web')); $group->wikix(Env::t('wikix')); $group->mail(Env::t('mail')); } if (Env::has('image')) { $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($group->label()); $image->caste($group->caste(Rights::everybody())); $group->image($image); } if (S::user()->isWeb()) { $nss = XDB::fetchColumn('SELECT ns FROM groups GROUP BY ns'); $page->assign('nss', $nss); if (Env::has('ns')) { S::logger()->log("groups/admin", array("gid" => $group->id(), "old_ns" => $group->ns(), "new_ns" => Env::t('ns'))); $group->ns(Env::t('ns')); } } $promos = S::user()->castes()->groups()->filter('ns', Group::NS_PROMO); $page->assign('promos', $promos); $page->assign('title', 'Administration de "' . $group->label() . '"'); $page->addCssLink('groups.css'); $page->changeTpl('groups/admin.tpl'); } else { $page->assign('title', "Ce groupe n'existe pas ou vous n'en êtes pas administrateur"); $page->changeTpl('groups/no_group.tpl'); } }
function handler_image($page, $size, $iid = null) { global $globals; $image = new FrankizImage($iid); $image->select(FrankizImageSelect::caste()); $user = S::user(); try { if ($user && $user->canSee($image->caste())) { $image->send($size); return; } } catch (DataNotFetchedException $e) { } // Not found of error => HTTP 403 header($_SERVER['SERVER_PROTOCOL'] . ' 403 Forbidden'); $img = new StaticImage($globals->images->forbidden); $img->send($size); }