function smarty_function_origin_picker($params, &$smarty)
{
    $gf = new GroupFilter(new PFC_And(new PFC_Not(new GFC_Namespace(Group::NS_USER)), new GFC_User(S::user(), Rights::admin())), new GFO_Score());
    $gs = $gf->get();
    if ($params['not_only_admin']) {
        $gfo = new GroupFilter(new PFC_And(new GFC_Namespace(array(Group::NS_BINET, Group::NS_FREE)), new GFC_User(S::user(), Rights::restricted())), new GFO_Score());
        $gso = $gfo->get()->diff($gs);
        $temp = new Collection();
        $temp->merge($gs)->merge($gso);
        $temp->select(GroupSelect::base());
        $smarty->assign('not_admin', $gso);
    } else {
        $gs = $gf->get()->select(GroupSelect::base());
    }
    $smarty->assign($params['out'], $gs);
}
Example #2
0
/**
 * Update a group
 * @return Group instance
 */
function update_group($name, $label, $ns, Userfilter $filter)
{
    $gf = new GroupFilter(new GFC_Name($name));
    $g = $gf->get(true);
    if ($g instanceof Group) {
        echo 'Updating ' . $label . ' (' . $name . ', ' . $g->id() . ') ';
        $g->select(GroupSelect::castes());
    } else {
        echo 'Creating ' . $label . ' (' . $name . ') ';
        $g = new Group();
        $g->insert();
        $g->ns($ns);
        $g->name($name);
        $g->label($label);
    }
    $c = $g->caste(Rights::member());
    $c->select(CasteSelect::base());
    $c->userfilter($filter);
    $c->compute();
    echo '... ' . $c->users()->count() . ' member(s)' . "\n";
    return $g;
}
function smarty_function_target_picker($params, &$smarty)
{
    // Get user groups
    $everybody_groups = S::user()->castes(Rights::everybody())->groups();
    // Get Frankiz special groups
    $fkz = new Collection('Group');
    $fkz->add(array('everybody', 'public'));
    $fkz->select(new GroupSelect(array('description')));
    // BDE, study and promo groups
    $study_groups = $everybody_groups->filter('ns', Group::NS_BDE);
    $study_groups->merge($everybody_groups->filter('ns', Group::NS_PROMO));
    $study_groups->merge($everybody_groups->filter('ns', Group::NS_STUDY));
    // Get all groups user is admin, without the user one
    $gs = S::user()->castes(Rights::admin())->groups();
    $gs->diff($fkz);
    $gs->filter(function ($g) {
        return $g->ns() != Group::NS_USER;
    });
    if ($params['even_only_friend']) {
        $gfo = new GroupFilter(new PFC_And(new GFC_Namespace(array(Group::NS_BINET, Group::NS_FREE)), new GFC_User(S::user(), Rights::everybody())), new GFO_Score());
        $gso = $gfo->get()->diff($gs)->diff($fkz);
        $temp = new Collection();
        $temp->merge($gs)->merge($gso);
        $temp->select(GroupSelect::base());
        $smarty->assign('only_friend', $gso);
        $temp = new Collection();
        $temp->merge($gs)->merge($fkz)->merge($gso);
        $temp->select(GroupSelect::base());
    } else {
        $temp = new Collection();
        $temp->merge($gs)->merge($fkz);
        $temp->select(GroupSelect::base());
    }
    $smarty->assign($params['user_groups'], $gs);
    $smarty->assign($params['fkz_groups'], $fkz);
    $smarty->assign($params['study_groups'], $study_groups);
    $smarty->assign($params['own_group'], S::user()->group());
}
Example #4
0
 public function run()
 {
     // Total Users
     $f = new UserFilter(null);
     $users = $f->getTotalCount();
     $this->assign('users', $users);
     // Total Groups
     $f = new GroupFilter(null);
     $groups = $f->getTotalCount();
     $this->assign('groups', $groups);
     // Total Castes
     $f = new CasteFilter(null);
     $castes = $f->getTotalCount();
     $this->assign('castes', $castes);
     // Total News
     $f = new NewsFilter(null);
     $news = $f->getTotalCount();
     $this->assign('news', $news);
     // Total Images
     $f = new ImageFilter(null);
     $images = $f->getTotalCount();
     $this->assign('images', $images);
     $this->assign('user', S::user());
 }
Example #5
0
 function handler_groups($page)
 {
     global $globals;
     $except = new PFC_True();
     $max = $globals->groups->limit;
     // Re-fetch user's groups
     S::user()->select(UserSelect::castes());
     // Fetch samples of other groups
     $binet = new GroupFilter(new PFC_And(new GFC_Namespace(Group::NS_BINET), $except), new GFO_Score(true));
     $binet = $binet->get(new PlLimit($max));
     $course = new GroupFilter(new PFC_And(new GFC_Namespace(Group::NS_COURSE), $except), new GFO_Score(true));
     $course = $course->get(new PlLimit($max));
     $free = new GroupFilter(new PFC_And(new GFC_Namespace(Group::NS_FREE), $except), new GFO_Score(true));
     $free = $free->get(new PlLimit($max));
     // Load associated datas
     $temp = new Collection('Group');
     $temp->merge($binet)->merge($course)->merge($free);
     $temp->select(GroupSelect::base());
     // Fetch the total count of groups
     $allf = new GroupFilter(new GFC_Visible());
     $total = $allf->getTotalCount();
     $user_binet = S::user()->castes()->groups()->filter('ns', Group::NS_BINET)->remove($binet);
     $page->assign('binet', $binet);
     $page->assign('user_binet', $user_binet);
     $user_course = S::user()->castes()->groups()->filter('ns', Group::NS_COURSE)->remove($course);
     $page->assign('course', $course);
     $page->assign('user_course', $user_course);
     $user_free = S::user()->castes()->groups()->filter('ns', Group::NS_FREE)->remove($free);
     $page->assign('free', $free);
     $page->assign('user_free', $user_free);
     $page->assign('user', S::user());
     $page->assign('total', $total);
     $page->assign('title', 'Groupes');
     $page->changeTpl('groups/groups.tpl');
     $page->addCssLink('groups.css');
 }
Example #6
0
 *  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                *
 ***************************************************************************/
/*
 * This script creates and updates the groups corresponding to the promos
 */
require_once dirname(__FILE__) . '/../connect.db.inc.php';
$gf = new GroupFilter(new GFC_Name('everybody'));
$g = $gf->get(true);
$g->select(GroupSelect::castes());
$c = $g->caste(Rights::member());
$c->select(CasteSelect::base())->compute();
echo 'Groupe everybody mis à jour' . "\n";
$gf = new GroupFilter(new GFC_Name('public'));
$g = $gf->get(true);
$g->select(GroupSelect::castes());
$c = $g->caste(Rights::member());
$c->select(CasteSelect::base())->compute();
echo 'Groupe visibilité extérieure mis à jour' . "\n";
$gf = new GroupFilter(new GFC_Name('licenses'));
$g = $gf->get(true);
$g->select(GroupSelect::castes());
$c = $g->caste(Rights::member());
$c->select(CasteSelect::base())->compute();
echo 'Groupe licenses mis à jour' . "\n";
Example #7
0
 function handler_validate($page, $gid = null, $vid = null)
 {
     $page->assign('msg', '');
     $gf = new GroupFilter(new PFC_Or(new GFC_Id($gid), new GFC_Name($gid)));
     $group = $gf->get(true);
     if (!$group) {
         throw new Exception("This Group (' . {$gid} . ') doesn't exist");
     }
     $group->select(GroupSelect::base());
     if (!S::user()->hasRights($group, Rights::admin())) {
         throw new Exception("You don't have the credential to validate request in this group");
     }
     $filter = new ValidateFilter(new VFC_Group($group));
     $collec = $filter->get()->select(ValidateSelect::validate());
     if (Env::has('val_id')) {
         $el = $collec->get(Env::v('val_id'));
         if (!$el) {
             $page->assign('msg', 'La validation a déjà été effectuée.');
         } else {
             if (Env::has('accept') || Env::has('delete')) {
                 S::logger()->log('admin/validate', array('type' => $el->type(), 'writer' => $el->writer()->id(), 'group' => $el->group()->id(), 'created' => $el->created()->toDb(), 'valid' => Env::has('accept'), 'item' => $el->itemToDb()));
             }
             if ($el->handle_form() && (Env::has('accept') || Env::has('delete'))) {
                 $collec->remove(Env::v('val_id'));
             }
         }
     }
     $page->assign('validation', is_null($vid) ? 0 : $vid);
     $page->assign('isEdition', false);
     $page->assign('gid', $gid);
     $page->assign('group', $group);
     $page->assign('val', $collec);
     $page->addCssLink('validate.css');
     $page->addCssLink('surveys.css');
     $page->assign('title', "Validations des requêtes");
     $page->changeTpl('validate/validate.tpl');
 }
Example #8
0
                 case 5: // PEI
                 $formation_id = 5;
                 break;
     
                 default: // Master
                 $formation_id = 3; 
             }*/
 } else {
     $login = $datas['login'] . '.' . $datas['promo'];
     $formation_id = 2;
 }
 $u->login($login);
 $u->addStudy($formation_id, $datas['promo'], (int) $datas['promo'] + 4, $datas['promo'], $login);
 // Linking with the nationality
 if (!empty($datas['nationalite'])) {
     $nf = new GroupFilter(new GFC_Name('nation_' . conv_name($datas['nationalite'])));
     $n = $nf->get(true);
     if ($n) {
         $n->select(GroupSelect::castes());
         $n->caste(Rights::member())->addUser($u);
     }
 }
 // Linking with the sport
 /*    if (!empty($datas['sport'])) {
         $nf = new GroupFilter(new GFC_Name('sport_' . conv_name($datas['sport'])));
         $n = $nf->get(true);
         $n->select(GroupSelect::castes());
         $n->caste(Rights::member())->addUser($u);
     }
 */
 //Photo
Example #9
0
 function handler_remote($page)
 {
     global $globals, $platal;
     if (!(Env::has('timestamp') && Env::has('site') && Env::has('hash') && Env::has('request'))) {
         $page->trigError("Requête non valide");
         return;
     }
     // Read request
     $timestamp = Env::s('timestamp');
     if (abs($timestamp - time()) > $globals->remote->lag) {
         $page->trigError("Delai d'attente dépassé");
         return;
     }
     $site = Env::s('site');
     $request = Env::s('request');
     // Load remote information
     try {
         $remote = Remote::from(Env::s('site'));
         $remote->select(RemoteSelect::groups());
     } catch (ItemNotFoundException $e) {
         $page->trigError("Ton site n'est pas renseigné dans la base de données");
         return;
     }
     // Check request
     if (md5($timestamp . $site . $remote->privkey() . $request) != Env::s('hash')) {
         $page->trigError("Erreur de validation de la requête d'authentification");
         return;
     }
     $request = json_decode($request, true);
     // Force login
     $user = Platal::session()->doAuthWithoutStart(AUTH_COOKIE);
     if (empty($user)) {
         $page->assign('remote_site', $remote->label());
         $platal->force_login($page);
         return PL_FORBIDDEN;
     }
     // Build response
     $response = array('uid' => $user->id());
     if ($remote->hasRight('names') && in_array('names', $request)) {
         $response['hruid'] = $user->login();
         $response['firstname'] = $user->firstname();
         $response['lastname'] = $user->lastname();
         $response['nickname'] = $user->nickname();
     }
     if ($remote->hasRight('email') && in_array('email', $request)) {
         $response['email'] = $user->email();
     }
     if ($remote->hasRight('rights') && in_array('rights', $request)) {
         $r = array();
         foreach ($remote->groups() as $g) {
             $r[$g->name()] = array_map(function ($r) {
                 return (string) $r;
             }, $user->rights($g));
         }
         if (!empty($r)) {
             $response['rights'] = $r;
         }
     }
     if ($remote->hasRight('sport') && in_array('sport', $request)) {
         $groups = $user->castes()->groups();
         $group = $groups->filter('ns', Group::NS_SPORT)->first();
         if ($group) {
             $response['sport'] = $group->label();
         }
     }
     if ($remote->hasRight('promo') && in_array('promo', $request)) {
         $groups = $user->castes()->groups()->filter('ns', Group::NS_PROMO);
         $groups = $groups->remove(Group::from('on_platal'));
         // Extract promos from group labels
         // For backward compatibility, compute the minimal promo year
         $promo = 0;
         $promos = array();
         foreach ($groups as $g) {
             $matches = array();
             if (preg_match('/^promo_([a-z_]+)([1-9][0-9]{3})$/', $g->name(), $matches)) {
                 $promos[] = $matches[1] . $matches[2];
                 $year = (int) $matches[2];
                 if (!$promo || $year < $promo) {
                     $promo = $year;
                 }
             }
         }
         if ($promo) {
             $response['promo'] = $promo;
             $response['promos'] = $promos;
         }
     }
     if ($remote->hasRight('photo') && in_array('photo', $request)) {
         $img = $user->photo();
         if ($img === false) {
             $img = $user->original();
         }
         if ($img !== false) {
             $response['photo'] = $globals->baseurl . '/' . $img->src('full');
         }
     }
     if ($remote->hasRight('binets_admin') && in_array('binets_admin', $request)) {
         $gf = new GroupFilter(new PFC_And(new GFC_User($user, Rights::admin()), new GFC_Namespace('binet')));
         $gs = $gf->get();
         if ($gs->count() > 0) {
             $gs->select(GroupSelect::base());
             $r = array();
             foreach ($gs as $g) {
                 $r[$g->name()] = $g->label();
             }
             if (!empty($r)) {
                 $response['binets_admin'] = $r;
             }
         }
     }
     // Send response
     $response = json_encode($response);
     $location = Env::s('location');
     header('Location: ' . $site . '?location=' . $location . '&timestamp=' . $timestamp . '&response=' . $response . '&hash=' . md5($timestamp . $remote->privkey() . $response));
 }
Example #10
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');
 }
Example #11
0
 * - UserFilter to define the users to work on
 * - Folder to search the pictures in
 * - Method of the User to use to find the correct picture
 * - Load the original picture or the current photo ?
 * 
 * Example :
 * ./import.tol.php '{"type":"user","condition":{"type":"uid","uids":[2]}}' . poly original
 *
 * Or :
 *
 * ./import.tol.php '{"type":"user","condition":{"type":"promo","comparison":"=","promo":2008}}' /home/2008/riton/dev/tol/2008 poly original
 * 
 */
require_once dirname(__FILE__) . '/connect.db.inc.php';
$globals->debug = 0;
$gf = new GroupFilter(new GFC_Name('tol'));
$group = $gf->get(true)->select(GroupSelect::castes());
$tol_caste = $group->caste(Rights::everybody());
// Concerned users
$uf = UserFilter::fromExport(json_decode($argv[1], true));
// Folder to look in
$folder = $argv[2];
// Field to use for the "join"
$field = $argv[3];
// Update original or current picture ?
$original = $argv[4] == 'photo' ? false : true;
$total = $uf->getTotalCount();
$chunk = empty($argv[5]) ? 100 : $argv[5];
$from = 0;
while (true) {
    echo "Chunk from {$from} to " . ($from + $chunk) . "\n";