Example #1
0
    $g = update_group('promo_' . $abbrev . $promo, $promo . ' ' . $label, Group::NS_PROMO, $f);
    create_promo_image($g, $promo);
}
// Update on_platal, specifying the number of years a school remains on the platal
$onplatal_numyears = array('x' => 2, 'poly' => 0, 'master' => 0, 'doc' => 0, 'pei' => 0, 'iogs' => 0, 'fkz' => 0, 'stcyr' => 0, 'ensta' => 2);
$formations->select(FormationSelect::on_platal());
$formations->select(FormationSelect::promos());
$filters = array();
foreach ($formations as $f) {
    if (!isset($onplatal_numyears[$f->abbrev()])) {
        echo 'Warning: no numyears for ' . $f->label() . "\n";
        continue;
    }
    $numyears = $onplatal_numyears[$f->abbrev()];
    $promos = $f->promos();
    $onplatal_promos = new PlFlagSet();
    sort($promos);
    while ($numyears > 0) {
        $promo = array_pop($promos);
        if (is_null($promo)) {
            break;
        }
        $onplatal_promos->addFlag($promo);
        $filters[] = new UFC_Promo($promo, '=', $f->id());
        $numyears--;
    }
    // Update on_platal logic classes
    $f->platalyears($onplatal_promos);
}
$f = new UserFilter(new PFC_Or($filters));
update_group('on_platal', 'Sur le platal', Group::NS_PROMO, $f);
Example #2
0
 protected function action_updateProfile()
 {
     global $globals;
     $page =& Platal::page();
     $colors = glob(dirname(__FILE__) . '/../../htdocs/images/banana/m2*.gif');
     foreach ($colors as $key => $path) {
         $path = basename($path, '.gif');
         $colors[$key] = substr($path, 2);
     }
     $page->assign('colors', $colors);
     if (Post::has('action') && Post::v('action') == 'Enregistrer') {
         S::assert_xsrf_token();
         $flags = new PlFlagSet();
         if (Post::b('bananadisplay')) {
             $flags->addFlag('threads');
         }
         if (Post::b('bananaupdate')) {
             $flags->addFlag('automaj');
         }
         if (Post::b('bananaxface')) {
             $flags->addFlag('xface');
         }
         $unread = Post::s('unread');
         $read = Post::s('read');
         if (!in_array($unread, $colors) || !in_array($read, $colors)) {
             $page->trigError('Le choix de type pour l\'arborescence est invalide');
         } else {
             $last_seen = XDB::query('SELECT  last_seen
                                        FROM  forum_profiles
                                       WHERE  uid = {?}', $this->user->id());
             if ($last_seen->numRows() > 0) {
                 $last_seen = $last_seen->fetchOneCell();
             } else {
                 $last_seen = '0000-00-00';
             }
             XDB::execute('INSERT INTO  forum_profiles (uid, sig, mail, name, flags, tree_unread, tree_read, last_seen)
                                VALUES  ({?}, {?}, {?}, {?}, {?}, {?}, {?}, {?})
               ON DUPLICATE KEY UPDATE  sig = VALUES(sig), mail = VALUES(mail), name = VALUES(name), flags = VALUES(flags),
                                        tree_unread = VALUES(tree_unread), tree_read = VALUES(tree_read), last_seen = VALUES(last_seen)', $this->user->id(), Post::v('bananasig'), Post::v('bananamail'), Post::v('banananame'), $flags, $unread, $read, $last_seen);
             $page->trigSuccess('Ton profil a été mis à jour');
         }
     }
     $infos = $this->fetchProfile();
     $page->assign('nom', $infos['name']);
     $page->assign('mail', $infos['mail']);
     $page->assign('sig', $infos['sig']);
     $page->assign('disp', $infos['threads']);
     $page->assign('maj', $infos['maj']);
     $page->assign('xface', $infos['xface']);
     $page->assign('unread', $infos['tree_unread']);
     $page->assign('read', $infos['tree_read']);
     return null;
 }
Example #3
0
 public function handler_notifs($page, $action = null, $arg = null)
 {
     $page->changeTpl('carnet/notifs.tpl');
     if ($action) {
         S::assert_xsrf_token();
         switch ($action) {
             case 'add_promo':
                 $this->addPromo($page, $arg);
                 break;
             case 'del_promo':
                 $this->delPromo($page, $arg);
                 break;
             case 'add_group':
                 $this->addGroup($page, $arg);
                 break;
             case 'del_group':
                 $this->delGroup($page, $arg);
                 break;
             case 'del_nonins':
                 $user = User::get($arg);
                 if ($user) {
                     $this->delNonRegistered($page, $user);
                 }
                 break;
             case 'add_nonins':
                 $user = User::get($arg);
                 if ($user) {
                     $this->addNonRegistered($page, $user);
                 }
                 break;
         }
     }
     if (Env::has('subs')) {
         S::assert_xsrf_token();
         $flags = new PlFlagSet();
         foreach (Env::v('sub') as $key => $value) {
             $flags->addFlag($key, $value);
         }
         XDB::execute('UPDATE  watch
                          SET  actions = {?}
                        WHERE  uid = {?}', $flags, S::i('uid'));
         S::user()->invalidWatchCache();
         Platal::session()->updateNbNotifs();
     }
     if (Env::has('flags_contacts')) {
         S::assert_xsrf_token();
         XDB::execute('UPDATE  watch
                          SET  ' . XDB::changeFlag('flags', 'contacts', Env::b('contacts')) . '
                        WHERE  uid = {?}', S::i('uid'));
         S::user()->invalidWatchCache();
         Platal::session()->updateNbNotifs();
     }
     if (Env::has('flags_mail')) {
         S::assert_xsrf_token();
         XDB::execute('UPDATE  watch
                          SET  ' . XDB::changeFlag('flags', 'mail', Env::b('mail')) . '
                        WHERE  uid = {?}', S::i('uid'));
         S::user()->invalidWatchCache();
         Platal::session()->updateNbNotifs();
     }
     $user = S::user();
     $nonins = new UserFilter(new UFC_WatchRegistration($user));
     $promo = XDB::fetchColumn('SELECT  promo
                                  FROM  watch_promo
                                 WHERE  uid = {?}
                              ORDER BY  promo', S::i('uid'));
     $page->assign('promo_count', count($promo));
     $ranges = array();
     $range_start = null;
     $range_end = null;
     foreach ($promo as $p) {
         if (is_null($range_start)) {
             $range_start = $range_end = $p;
         } else {
             if ($p != $range_end + 1) {
                 $ranges[] = array($range_start, $range_end);
                 $range_start = $range_end = $p;
             } else {
                 $range_end = $p;
             }
         }
     }
     $ranges[] = array($range_start, $range_end);
     $page->assign('promo_ranges', $ranges);
     $page->assign('nonins', $nonins->getUsers());
     $groups = XDB::fetchColumn('SELECT  g.nom
                                   FROM  watch_group AS w
                             INNER JOIN  groups      AS g ON (g.id = w.groupid)
                                  WHERE  w.uid = {?}
                               ORDER BY  g.nom', S::i('uid'));
     $page->assign('groups', $groups);
     $page->assign('groups_count', count($groups));
     list($flags, $actions) = XDB::fetchOneRow('SELECT  flags, actions
                                                  FROM  watch
                                                 WHERE  uid = {?}', S::i('uid'));
     $flags = new PlFlagSet($flags);
     $actions = new PlFlagSet($actions);
     $page->assign('flags', $flags);
     $page->assign('actions', $actions);
 }
Example #4
0
 public static function makePerms($perms, $is_admin)
 {
     $flags = new PlFlagSet($perms);
     if ($is_admin) {
         $flags->addFlag(PERMS_ADMIN);
     }
     // Access to private directory implies access to 'less'-private version.
     if ($flags->hasFlag('directory_private')) {
         $flags->addFlag('directory_ax');
     }
     return $flags;
 }
Example #5
0
 */
require '../connect.db.inc.php';
require_once '../../classes/address.php';
$admin_visibility = Visibility::get(Visibility::VIEW_ADMIN);
// Enumerate every profile
$pids = XDB::iterRow("SELECT pid from profiles");
while ($row = $pids->next()) {
    $pid = $row[0];
    // Find the address which would be selected as "AX mail"
    // But don't update anything
    $best_mail = Address::updateBestMail($pid, true);
    if (is_null($best_mail)) {
        continue;
    }
    // Just continue if the returned address is already selected
    $flags = new PlFlagSet($best_mail['flags']);
    if ($flags->hasFlag('dn_best_mail')) {
        continue;
    }
    // The current profile is buggy.
    // Let's fetch more data to print detailed information
    $profile = Profile::get($pid);
    $addresses = ProfileField::getForPID('ProfileAddresses', array($pid), $admin_visibility);
    $addresses = $addresses->get(Profile::ADDRESS_POSTAL);
    $old_mail = null;
    $new_mail = null;
    foreach ($addresses as $addr) {
        if ($addr->flags->hasFlag('dn_best_mail')) {
            $old_mail = $addr;
        } else {
            if ($addr->id == $best_mail['id']) {
Example #6
0
 public function __call($method, $arguments)
 {
     $className = $this->className;
     $inferedMethod = 'batch' . ucfirst($method);
     if (method_exists($className, $inferedMethod)) {
         // Call $className->batch$method($this->collected, ...)
         array_unshift($arguments, $this->collected);
         $r = forward_static_call_array(array($className, $inferedMethod), $arguments);
         if (!is_array($r)) {
             return $r;
         }
         $c = new Collection($className);
         if (!empty($r)) {
             $c->add($r);
         }
         return $c;
     }
     // If there is no argument, build an array with values from $collected->$method
     if (empty($arguments)) {
         $values = array_map(function ($mixed) use($method) {
             return $mixed->{$method}();
         }, $this->collected);
         // Try magic things with the schema
         $schema = Schema::get($className);
         if ($schema->isScalar($method)) {
             // Return an array of scalar values
             return $values;
         } elseif ($schema->isObject($method)) {
             // Return a collection
             return Collection::fromArray($values, $schema->objectType($method));
         } elseif ($schema->isFlagset($method)) {
             // Return a merged flagset
             $fs = new PlFlagSet();
             foreach ($values as $flags) {
                 foreach ($flags as $flag) {
                     $fs->addFlag($flag);
                 }
             }
             return $fs;
         } elseif ($schema->isCollection($method)) {
             // Return a merged collection
             $col = new Collection();
             foreach ($values as $c) {
                 $col->merge($c);
             }
             return $col;
         }
         throw new Exception("Unknown automatic field {$method} is schema for {$className}");
     }
     throw new Exception("The method {$className}::{$inferedMethod} doesn't exist");
 }
Example #7
0
 function handler_admin_events($page, $action = 'list', $eid = null)
 {
     $page->changeTpl('events/admin.tpl');
     $page->setTitle('Administration - Evenements');
     $page->register_modifier('hde', 'html_entity_decode');
     $arch = $action == 'archives';
     $page->assign('action', $action);
     $upload = new PlUpload(S::user()->login(), 'event');
     if ((Env::has('preview') || Post::v('action') == "Proposer") && $eid) {
         $action = 'edit';
         $this->upload_image($page, $upload);
     }
     if (Post::v('action') == 'Pas d\'image' && $eid) {
         S::assert_xsrf_token();
         $upload->rm();
         XDB::execute("DELETE FROM announce_photos WHERE eid = {?}", $eid);
         $action = 'edit';
     } elseif (Post::v('action') == 'Supprimer l\'image' && $eid) {
         S::assert_xsrf_token();
         $upload->rm();
         $action = 'edit';
     } elseif (Post::v('action') == "Proposer" && $eid) {
         S::assert_xsrf_token();
         $promo_min = Post::i('promo_min');
         $promo_max = Post::i('promo_max');
         if ($promo_min != 0 && ($promo_min <= 1900 || $promo_min >= 2020) || $promo_max != 0 && ($promo_max <= 1900 || $promo_max >= 2020 || $promo_max < $promo_min)) {
             $page->trigError("L'intervalle de promotions {$promo_min} -> {$promo_max} n'est pas valide");
             $action = 'edit';
         } else {
             $res = XDB::query('SELECT flags FROM announces WHERE id = {?}', $eid);
             $flags = new PlFlagSet($res->fetchOneCell());
             $flags->addFlag('wiki');
             if (Post::v('important')) {
                 $flags->addFlag('important');
             } else {
                 $flags->rmFlag('important');
             }
             XDB::execute('UPDATE announces
                              SET creation_date = creation_date,
                                  titre={?}, texte={?}, expiration={?}, promo_min={?}, promo_max={?},
                                  flags = {?}
                            WHERE id = {?}', Post::v('titre'), Post::v('texte'), Post::v('expiration'), Post::v('promo_min'), Post::v('promo_max'), $flags, $eid);
             if ($upload->exists() && (list($x, $y, $type) = $upload->imageInfo())) {
                 XDB::execute('INSERT INTO  announce_photos (eid, attachmime, attach, x, y)
                                    VALUES  ({?}, {?}, {?}, {?}, {?})
                   ON DUPLICATE KEY UPDATE  attachmime = VALUES(attachmime), attach = VALUES(attach), x = VALUES(x), y = VALUES(y)', $eid, $type, $upload->getContents(), $x, $y);
                 $upload->rm();
             }
         }
     }
     if ($action == 'edit') {
         $res = XDB::query('SELECT titre, texte, expiration, promo_min, promo_max, FIND_IN_SET(\'important\', flags),
                                   attach IS NOT NULL
                              FROM announces       AS e
                         LEFT JOIN announce_photos AS p ON(e.id = p.eid)
                             WHERE id={?}', $eid);
         list($titre, $texte, $expiration, $promo_min, $promo_max, $important, $img) = $res->fetchOneRow();
         $page->assign('titre', $titre);
         $page->assign('texte', $texte);
         $page->assign('promo_min', $promo_min);
         $page->assign('promo_max', $promo_max);
         $page->assign('expiration', $expiration);
         $page->assign('important', $important);
         $page->assign('eid', $eid);
         $page->assign('img', $img);
         $page->assign_by_ref('upload', $upload);
         $select = "";
         for ($i = 1; $i < 30; $i++) {
             $p_stamp = date("Ymd", time() + 3600 * 24 * $i);
             $year = substr($p_stamp, 0, 4);
             $month = substr($p_stamp, 4, 2);
             $day = substr($p_stamp, 6, 2);
             $select .= "<option value=\"{$p_stamp}\"" . ($p_stamp == strtr($expiration, array("-" => "")) ? " selected" : "") . "> {$day} / {$month} / {$year}</option>\n";
         }
         $page->assign('select', $select);
     } else {
         switch ($action) {
             case 'delete':
                 S::assert_xsrf_token();
                 XDB::execute('DELETE from announces
                                WHERE id = {?}', $eid);
                 break;
             case "archive":
                 S::assert_xsrf_token();
                 XDB::execute('UPDATE announces
                                  SET creation_date = creation_date, flags = CONCAT(flags,",archive")
                                WHERE id = {?}', $eid);
                 break;
             case "unarchive":
                 S::assert_xsrf_token();
                 XDB::execute('UPDATE announces
                                  SET creation_date = creation_date, flags = REPLACE(flags,"archive","")
                                WHERE id = {?}', $eid);
                 $action = 'archives';
                 $arch = true;
                 break;
             case "valid":
                 S::assert_xsrf_token();
                 XDB::execute('UPDATE announces
                                  SET creation_date = creation_date, flags = CONCAT(flags,",valide")
                                WHERE id = {?}', $eid);
                 break;
             case "unvalid":
                 S::assert_xsrf_token();
                 XDB::execute('UPDATE announces
                                  SET creation_date = creation_date, flags = REPLACE(flags,"valide", "")
                                WHERE id = {?}', $eid);
                 break;
         }
         $pid = $eid && $action == 'preview' ? $eid : -1;
         $sql = "SELECT  e.id, e.titre, e.texte,e.id = {$pid} AS preview, e.uid,\n                            DATE_FORMAT(e.creation_date,'%d/%m/%Y %T') AS creation_date,\n                            DATE_FORMAT(e.expiration,'%d/%m/%Y') AS expiration,\n                            e.promo_min, e.promo_max,\n                            FIND_IN_SET('valide', e.flags) AS fvalide,\n                            FIND_IN_SET('archive', e.flags) AS farch,\n                            FIND_IN_SET('wiki', e.flags) AS wiki\n                      FROM  announces    AS e\n                     WHERE  " . ($arch ? "" : "!") . "FIND_IN_SET('archive',e.flags)\n                  ORDER BY  FIND_IN_SET('valide',e.flags), e.expiration DESC";
         $page->assign('evs', XDB::iterator($sql));
     }
     $page->assign('arch', $arch);
     $page->assign('admin_evts', true);
 }
Example #8
0
 function handler_edit_announce($page, $aid = null)
 {
     global $globals, $platal;
     $page->changeTpl('xnetgrp/announce-edit.tpl');
     $page->assign('new', is_null($aid));
     $art = array();
     if (Post::v('valid') == 'Visualiser' || Post::v('valid') == 'Enregistrer' || Post::v('valid') == 'Supprimer l\'image' || Post::v('valid') == 'Pas d\'image') {
         S::assert_xsrf_token();
         if (!is_null($aid)) {
             $art['id'] = $aid;
         }
         $art['titre'] = Post::v('titre');
         $art['texte'] = Post::v('texte');
         $art['contacts'] = Post::v('contacts');
         $art['promo_min'] = Post::i('promo_min');
         $art['promo_max'] = Post::i('promo_max');
         $art['nom'] = S::v('nom');
         $art['prenom'] = S::v('prenom');
         $art['promo'] = S::v('promo');
         $art['hruid'] = S::user()->login();
         $art['uid'] = S::user()->id();
         $art['expiration'] = Post::v('expiration');
         $art['public'] = Post::has('public');
         $art['xorg'] = Post::has('xorg');
         $art['nl'] = Post::has('nl');
         $art['event'] = Post::v('event');
         $upload = new PlUpload(S::user()->login(), 'xnetannounce');
         $this->upload_image($page, $upload);
         $art['contact_html'] = $art['contacts'];
         if ($art['event']) {
             $art['contact_html'] .= "\n{$globals->baseurl}/{$platal->ns}events/sub/{$art['event']}";
         }
         if (!$art['public'] && ($art['promo_min'] > $art['promo_max'] && $art['promo_max'] != 0 || $art['promo_min'] != 0 && ($art['promo_min'] <= 1900 || $art['promo_min'] >= 2020) || $art['promo_max'] != 0 && ($art['promo_max'] <= 1900 || $art['promo_max'] >= 2020))) {
             $page->trigError("L'intervalle de promotions est invalide.");
             Post::kill('valid');
         }
         if (!trim($art['titre']) || !trim($art['texte'])) {
             $page->trigError("L'article doit avoir un titre et un contenu.");
             Post::kill('valid');
         }
         if (Post::v('valid') == 'Supprimer l\'image') {
             $upload->rm();
             Post::kill('valid');
         }
         $art['photo'] = $upload->exists() || Post::i('photo');
         if (Post::v('valid') == 'Pas d\'image' && !is_null($aid)) {
             XDB::query('DELETE FROM  group_announces_photo
                               WHERE  eid = {?}', $aid);
             $upload->rm();
             Post::kill('valid');
             $art['photo'] = false;
         }
     }
     if (Post::v('valid') == 'Enregistrer') {
         $promo_min = $art['public'] ? 0 : $art['promo_min'];
         $promo_max = $art['public'] ? 0 : $art['promo_max'];
         $flags = new PlFlagSet();
         if ($art['public']) {
             $flags->addFlag('public');
         }
         if ($art['photo']) {
             $flags->addFlag('photo');
         }
         if (is_null($aid)) {
             $fulltext = $art['texte'];
             if (!empty($art['contact_html'])) {
                 $fulltext .= "\n\n'''Contacts :'''\\\\\n" . $art['contact_html'];
             }
             $post = null;
             if ($globals->asso('forum')) {
                 require_once 'banana/forum.inc.php';
                 $banana = new ForumsBanana(S::user());
                 $post = $banana->post($globals->asso('forum'), null, $art['titre'], MiniWiki::wikiToText($fulltext, false, 0, 80));
             }
             XDB::query('INSERT INTO  group_announces (uid, asso_id, create_date, titre, texte, contacts,
                                                       expiration, promo_min, promo_max, flags, post_id)
                              VALUES  ({?}, {?}, NOW(), {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?})', S::i('uid'), $globals->asso('id'), $art['titre'], $art['texte'], $art['contact_html'], $art['expiration'], $promo_min, $promo_max, $flags, $post);
             $aid = XDB::insertId();
             if ($art['photo']) {
                 list($imgx, $imgy, $imgtype) = $upload->imageInfo();
                 XDB::execute('INSERT INTO  group_announces_photo
                                       SET  eid = {?}, attachmime = {?}, x = {?}, y = {?}, attach = {?}', $aid, $imgtype, $imgx, $imgy, $upload->getContents());
             }
             if ($art['xorg']) {
                 $article = new EvtReq("[{$globals->asso('nom')}] " . $art['titre'], $fulltext, $art['promo_min'], $art['promo_max'], $art['expiration'], "", S::user(), $upload);
                 $article->submit();
                 $page->trigWarning("L'affichage sur la page d'accueil de Polytechnique.org est en attente de validation.");
             } else {
                 if ($upload && $upload->exists()) {
                     $upload->rm();
                 }
             }
             if ($art['nl']) {
                 $article = new NLReq(S::user(), $globals->asso('nom') . " : " . $art['titre'], $art['texte'], $art['contact_html']);
                 $article->submit();
                 $page->trigWarning("La parution dans la Lettre Mensuelle est en attente de validation.");
             }
         } else {
             XDB::query('UPDATE  group_announces
                            SET  titre = {?}, texte = {?}, contacts = {?}, expiration = {?},
                                 promo_min = {?}, promo_max = {?}, flags = {?}
                          WHERE  id = {?} AND asso_id = {?}', $art['titre'], $art['texte'], $art['contacts'], $art['expiration'], $promo_min, $promo_max, $flags, $art['id'], $globals->asso('id'));
             if ($art['photo'] && $upload->exists()) {
                 list($imgx, $imgy, $imgtype) = $upload->imageInfo();
                 XDB::execute('INSERT INTO  group_announces_photo (eid, attachmime, attach, x, y)
                                    VALUES  ({?}, {?}, {?}, {?}, {?})
                   ON DUPLICATE KEY UPDATE  attachmime = VALUES(attachmime), attach = VALUES(attach), x = VALUES(x), y = VALUES(y)', $aid, $imgtype, $upload->getContents(), $imgx, $imgy);
                 $upload->rm();
             }
         }
     }
     if (Post::v('valid') == 'Enregistrer' || Post::v('valid') == 'Annuler') {
         pl_redirect("");
     }
     if (empty($art) && !is_null($aid)) {
         $res = XDB::query("SELECT  *, FIND_IN_SET('public', flags) AS public,\n                                       FIND_IN_SET('photo', flags) AS photo\n                                 FROM  group_announces\n                                WHERE  asso_id = {?} AND id = {?}", $globals->asso('id'), $aid);
         if ($res->numRows()) {
             $art = $res->fetchOneAssoc();
             $art['contact_html'] = $art['contacts'];
         } else {
             $page->kill("Aucun article correspond à l'identifiant indiqué.");
         }
     }
     if (is_null($aid)) {
         $events = XDB::iterator("SELECT *\n                                      FROM group_events\n                                     WHERE asso_id = {?} AND archive = 0", $globals->asso('id'));
         if ($events->total()) {
             $page->assign('events', $events);
         }
     }
     $art['contact_html'] = @MiniWiki::WikiToHTML($art['contact_html']);
     $page->assign('art', $art);
     $page->assign_by_ref('upload', $upload);
 }