+
+ function handler_rss(&$page, $user = null, $hash = null)
+ {
+ global $globals;
+ require_once('rss.inc.php');
+ $uid = init_rss('xnetgrp/announce-rss.tpl', $user, $hash, false);
+
+ if ($uid) {
+ $rss = XDB::iterator("SELECT a.id, a.titre, a.texte, a.contacts, a.create_date,
+ IF(u2.nom_usage != '', u2.nom_usage, u2.nom) AS nom, u2.prenom, u2.promo,
+ FIND_IN_SET('photo', a.flags) AS photo
+ FROM auth_user_md5 AS u
+ INNER JOIN groupex.announces AS a ON ( (a.promo_min = 0 OR a.promo_min <= u.promo)
+ AND (a.promo_max = 0 OR a.promo_max <= u.promo))
+ INNER JOIN auth_user_md5 AS u2 ON (u2.user_id = a.user_id)
+ WHERE u.user_id = {?} AND peremption >= NOW() AND a.asso_id = {?}",
+ $uid, $globals->asso('id'));
+ } else {
+ $rss = XDB::iterator("SELECT a.id, a.titre, a.texte, a.create_date,
+ IF(u.nom_usage != '', u.nom_usage, u.nom) AS nom, u.prenom, u.promo
+ FROM groupex.announces AS a
+ INNER JOIN auth_user_md5 AS u USING(user_id)
+ WHERE FIND_IN_SET('public', a.flags) AND peremption >= NOW() AND a.asso_id = {?}",
+ $globals->asso('id'));
+ }
+ $page->assign('asso', $globals->asso());
+ $page->assign('rss', $rss);
+ }
+
+ private function upload_image(PlatalPage &$page, PlUpload &$upload)
+ {
+ if (@!$_FILES['image']['tmp_name'] && !Env::v('image_url')) {
+ return true;
+ }
+ if (!$upload->upload($_FILES['image']) && !$upload->download(Env::v('image_url'))) {
+ $page->trig('Impossible de télécharger l\'image');
+ return false;
+ } elseif (!$upload->isType('image')) {
+ $page->trig('Le fichier n\'est pas une image valide au format JPEG, GIF ou PNG.');
+ $upload->rm();
+ return false;
+ } elseif (!$upload->resizeImage(200, 300, 100, 100, 32284)) {
+ $page->trig('Impossible de retraiter l\'image');
+ return false;
+ }
+ return true;
+ }
+
+ function handler_photo_announce(&$page, $eid = null) {
+ if ($eid) {
+ $res = XDB::query("SELECT * FROM groupex.announces_photo WHERE eid = {?}", $eid);
+ if ($res->numRows()) {
+ $photo = $res->fetchOneAssoc();
+ header('Content-Type: image/' . $photo['attachmime']);
+ echo $photo['attach'];
+ exit;
+ }
+ } else {
+ $upload = new PlUpload(S::v('forlife'), 'xnetannounce');
+ if ($upload->exists() && $upload->isType('image')) {
+ header('Content-Type: ' . $upload->contentType());
+ echo $upload->getContents();
+ exit;
+ }
+ }
+ global $globals;
+ header('Content-Type: image/png');
+ echo file_get_contents($globals->spoolroot . '/htdocs/images/logo.png');
+ exit;
+ }
+
+ 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') {
+ 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['forlife'] = S::v('forlife');
+ $art['peremption'] = Post::v('peremption');
+ $art['public'] = Post::has('public');
+ $art['xorg'] = Post::has('xorg');
+ $art['nl'] = Post::has('nl');
+ $art['event'] = Post::v('event');
+ $upload = new PlUpload(S::v('forlife'), '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->trig("L'intervalle de promotions est invalide.");
+ Post::kill('valid');
+ }
+
+ if (!trim($art['titre']) || !trim($art['texte'])) {
+ $page->trig("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 groupex.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 = array();
+ if ($art['public']) {
+ $flags[] = 'public';
+ }
+ if ($art['photo']) {
+ $flags[] = 'photo';
+ }
+ $flags = implode(',', $flags);
+ 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::v('forlife'));
+ $post = $banana->post($globals->asso('forum'), null,
+ $art['titre'], MiniWiki::wikiToText($fulltext, false, 0, 80));
+ }*/
+ XDB::query("INSERT INTO groupex.announces
+ (user_id, asso_id, create_date, titre, texte, contacts,
+ peremption, promo_min, promo_max, flags, post_id)
+ VALUES ({?}, {?}, NOW(), {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?})",
+ S::i('uid'), $globals->asso('id'), $art['titre'], $art['texte'], $art['contact_html'],
+ $art['peremption'], $promo_min, $promo_max, $flags, $post);
+ $aid = XDB::insertId();
+ if ($art['photo']) {
+ list($imgx, $imgy, $imgtype) = $upload->imageInfo();
+ XDB::execute("INSERT INTO groupex.announces_photo
+ SET eid = {?}, attachmime = {?}, x = {?}, y = {?}, attach = {?}",
+ $aid, $imgtype, $imgx, $imgy, $upload->getContents());
+ }
+ if ($art['xorg']) {
+ require_once('validations.inc.php');
+ $article = new EvtReq("[{$globals->asso('nom')}] " . $art['titre'], $fulltext,
+ $art['promo_min'], $art['promo_max'], $art['peremption'], "", S::v('uid'),
+ $upload);
+ $article->submit();
+ $page->trig("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']) {
+ require_once('validations.inc.php');
+ $article = new NLReq(S::v('uid'), $globals->asso('nom') . " : " .$art['titre'],
+ $art['texte'], $art['contact_html']);
+ $article->submit();
+ $page->trig("La parution dans la Lettre Mensuelle est en attente de validation.");
+ }
+ } else {
+ XDB::query("UPDATE groupex.announces
+ SET titre={?}, texte={?}, contacts={?}, peremption={?},
+ promo_min={?}, promo_max={?}, flags={?}
+ WHERE id={?} AND asso_id={?}",
+ $art['titre'], $art['texte'], $art['contacts'], $art['peremption'],
+ $promo_min, $promo_max, $flags,
+ $art['id'], $globals->asso('id'));
+ if ($art['photo'] && $upload->exists()) {
+ list($imgx, $imgy, $imgtype) = $upload->imageInfo();
+ XDB::execute("REPLACE INTO groupex.announces_photo
+ SET eid = {?}, attachmime = {?}, x = {?}, y = {?}, attach = {?}",
+ $aid, $imgtype, $imgx, $imgy, $upload->getContents());
+ $upload->rm();
+ }
+ }
+ }
+ if (Post::v('valid') == 'Enregistrer' || Post::v('valid') == 'Annuler') {
+ pl_redirect("");
+ }
+
+ if (empty($art) && !is_null($aid)) {
+ $res = XDB::query("SELECT a.*, u.nom, u.prenom, u.promo, l.alias AS forlife,
+ FIND_IN_SET('public', a.flags) AS public,
+ FIND_IN_SET('photo', a.flags) AS photo
+ FROM groupex.announces AS a
+ INNER JOIN auth_user_md5 AS u USING(user_id)
+ INNER JOIN aliases AS l ON (l.id = u.user_id AND l.type = 'a_vie')
+ WHERE asso_id = {?} AND a.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 *
+ FROM groupex.evenements
+ 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);
+ }
+
+ function handler_admin_announce(&$page)
+ {
+ global $globals;
+ $page->changeTpl('xnetgrp/announce-admin.tpl');
+
+ if (Env::has('del')) {
+ XDB::execute("DELETE FROM groupex.announces
+ WHERE id = {?} AND asso_id = {?}",
+ Env::i('del'), $globals->asso('id'));
+ }
+ $res = XDB::iterator("SELECT a.id, a.titre, a.peremption, a.peremption < CURRENT_DATE() AS perime
+ FROM groupex.announces AS a
+ WHERE a.asso_id = {?}
+ ORDER BY a.peremption DESC",
+ $globals->asso('id'));
+ $page->assign('articles', $res);
+ }