From: x2003bruneau Date: Sun, 25 Feb 2007 23:11:48 +0000 (+0000) Subject: Ajaxify event submission form X-Git-Tag: xorg/0.9.14~264 X-Git-Url: http://git.polytechnique.org/?a=commitdiff_plain;h=db3bd1464d42de8adbd48a8b3a22af70f0912129;p=platal.git Ajaxify event submission form git-svn-id: svn+ssh://murphy/home/svn/platal/trunk@1516 839d8a87-29fc-0310-9880-83ba4fa771e5 --- diff --git a/htdocs/javascript/ajax.js b/htdocs/javascript/ajax.js index 5cff50b..2bf3c02 100644 --- a/htdocs/javascript/ajax.js +++ b/htdocs/javascript/ajax.js @@ -55,7 +55,7 @@ Ajax = { if (obj != null) { document.getElementById(obj).innerHTML = Ajax.xml_client.responseText; } - if (func != null) { + if (func != null) { func(Ajax.xml_client.responseText); } } else if (Ajax.xml_client.status == 403) { diff --git a/include/xorg.misc.inc.php b/include/xorg.misc.inc.php index e98250e..d4154d8 100644 --- a/include/xorg.misc.inc.php +++ b/include/xorg.misc.inc.php @@ -19,7 +19,8 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ***************************************************************************/ -function quoted_printable_encode($input, $line_max = 76) { +function quoted_printable_encode($input, $line_max = 76) +{ $lines = preg_split("/(?:\r\n|\r|\n)/", $input); $eol = "\n"; $linebreak = "=0D=0A=\n "; @@ -72,6 +73,14 @@ function isvalid_email_redirection($email) { !preg_match("/@(polytechnique\.(org|edu)|melix\.(org|net)|m4x\.org)$/", $email); } +/** Check if the string is utf8 + */ +function is_utf8($s) +{ + return @iconv('utf-8', 'utf-8', $s) == $s; +} + + /** Remove accent from a string and replace them by the nearest letter */ global $lc_convert, $uc_convert; diff --git a/modules/events.php b/modules/events.php index 3881aa0..894d5c2 100644 --- a/modules/events.php +++ b/modules/events.php @@ -26,6 +26,7 @@ class EventsModule extends PLModule return array( 'events' => $this->make_hook('ev', AUTH_COOKIE), 'rss' => $this->make_hook('rss', AUTH_PUBLIC), + 'events/preview' => $this->make_hook('preview', AUTH_PUBLIC, '', NO_AUTH), 'events/submit' => $this->make_hook('ev_submit', AUTH_MDP), 'admin/events' => $this->make_hook('admin_events', AUTH_MDP, 'admin'), @@ -166,11 +167,35 @@ class EventsModule extends PLModule WHERE u.user_id = {?} AND FIND_IN_SET(e.flags, "valide") AND peremption >= NOW()', $uid); $page->assign('rss', $rss); - } + } + + function handler_preview(&$page) + { + require_once('url_catcher.inc.php'); + $page->changeTpl('events/preview.tpl', NO_SKIN); + $texte = Get::v('texte'); + if (!is_utf8($texte)) { + $texte = utf8_encode($texte); + } + if (strpos($_SERVER['HTTP_REFERER'], 'admin') === false) { + $texte = url_catcher(pl_entities($texte)); + } + $titre = Get::v('titre'); + if (!is_utf8($titre)) { + $titre = utf8_encode($titre); + } + $page->assign('texte_html', $texte); + $page->assign('titre', $titre); + header('Content-Type: text/html; charset=utf-8'); + } function handler_ev_submit(&$page) { $page->changeTpl('events/submit.tpl'); + $page->addJsLink('ajax.js'); + + require_once('wiki.inc.php'); + wiki_require_page('Xorg.Annonce'); $titre = Post::v('titre'); $texte = Post::v('texte'); @@ -202,7 +227,7 @@ class EventsModule extends PLModule if ($action && (!trim($texte) || !trim($titre))) { $page->trig("L'article doit avoir un titre et un contenu"); - } elseif ($action == 'Confirmer') { + } elseif ($action) { $texte = $texte_catch_url; require_once 'validations.inc.php'; $evtreq = new EvtReq($titre, $texte, $promo_min, $promo_max, @@ -257,6 +282,7 @@ class EventsModule extends PLModule function handler_admin_events(&$page, $action = 'list', $eid = null) { $page->changeTpl('events/admin.tpl'); + $page->addJsLink('ajax.js'); $page->assign('xorg_title','Polytechnique.org - Administration - Evenements'); $page->register_modifier('hde', 'html_entity_decode'); @@ -288,6 +314,7 @@ class EventsModule extends PLModule list($titre, $texte, $peremption, $promo_min, $promo_max) = $res->fetchOneRow(); $page->assign('titre',$titre); $page->assign('texte',$texte); + $page->assign('texte_html', pl_entity_decode($texte)); $page->assign('promo_min',$promo_min); $page->assign('promo_max',$promo_max); $page->assign('peremption',$peremption); diff --git a/templates/events/admin.tpl b/templates/events/admin.tpl index 23ee183..bb95087 100644 --- a/templates/events/admin.tpl +++ b/templates/events/admin.tpl @@ -41,7 +41,7 @@ {if $action eq 'edit'} -{include file="include/form.evenement.tpl"} +{include file="events/form.tpl"} {else} diff --git a/templates/include/form.evenement.tpl b/templates/events/form.tpl similarity index 71% rename from templates/include/form.evenement.tpl rename to templates/events/form.tpl index 7afc495..8a370f3 100644 --- a/templates/include/form.evenement.tpl +++ b/templates/events/form.tpl @@ -20,27 +20,51 @@ {* *} {**************************************************************************} + + +
+{include file="events/preview.tpl"} +
+
+
- - - {if strlen(trim($texte))} - - + - {/if} - + - - -
Contenu du message
- {$texte|smarty:nodefaults|nl2br} - Contenu de l'annonce
Titre - +
Texte
@@ -54,15 +78,25 @@ } {/literal} - Essaie de faire un texte court, une annonce ne doit pas excéder 800 caractères soit une douzaine de ligne. Tu en es déjà à caractères. + Essaie de faire un texte court, une annonce ne doit pas excéder 800 caractères soit une douzaine de ligne. Tu en es déjà à caractères.
Informations complémentaires
+
+ +
+

+ Le bouton de confirmation n'apparaît que si l'aperçu est concluant. +

+

+ N'oublie pas de remplir suivantes : +

+ + + +
Informations complémentaires
Tu peux limiter la visibilité de ton annonce aux camarades de certaines promotions : @@ -99,7 +133,7 @@
-
+
diff --git a/templates/events/preview.tpl b/templates/events/preview.tpl new file mode 100644 index 0000000..18058ed --- /dev/null +++ b/templates/events/preview.tpl @@ -0,0 +1,30 @@ +{**************************************************************************} +{* *} +{* Copyright (C) 2003-2007 Polytechnique.org *} +{* http://opensource.polytechnique.org/ *} +{* *} +{* This program is free software; you can redistribute it and/or modify *} +{* it under the terms of the GNU General Public License as published by *} +{* the Free Software Foundation; either version 2 of the License, or *} +{* (at your option) any later version. *} +{* *} +{* This program is distributed in the hope that it will be useful, *} +{* 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 *} +{* *} +{**************************************************************************} + +{if trim($titre) || trim($texte_html)} + + + +
Aperçu de : {$titre|nl2br}
{$texte_html|nl2br|smarty:nodefaults}
+{/if} + +{* vim:set et sw=2 sts=2 sws=2 enc=utf-8: *} diff --git a/templates/events/submit.tpl b/templates/events/submit.tpl index 29df338..44a71db 100644 --- a/templates/events/submit.tpl +++ b/templates/events/submit.tpl @@ -22,49 +22,6 @@

Proposition d'information événementielle

-{if $action eq "proposer" && trim($titre) && trim($texte)} - -

-Voici ton annonce : -

- - - - -
{$titre|nl2br}
{$texte_html|nl2br|smarty:nodefaults}
- -

-Ce message est à destination -{if $promo_min || $promo_max} -des promotions {if $promo_min}X{$promo_min}{/if} {if $promo_max}jusqu'à X{$promo_max}{else} et plus{/if} -{else} -de toutes les promotions -{/if} -et sera affiché sur la page d'accueil jusqu'au {$peremption|date_format}. -

- -{if $valid_mesg} -

-Tu as ajouté le message suivant à l'intention du validateur : {$valid_mesg|nl2br} -

-{/if} - - -
- - - - - - - - -
- - - -{elseif $action eq "confirmer"} - {if $ok}

Ta proposition a bien été enregistrée, un administrateur va se charger de la valider aussi rapidement que possible. @@ -76,15 +33,10 @@ Merci pour ta contribution à la vie du site! Retour à la page d'accueil

{else} -

-Une erreur s'est produite pendant l'enregistrement de ta proposition. -Merci de nous contacter! -

-{/if} -{else} +{include file="events/form.tpl"} -{include file="include/form.evenement.tpl"} +{include file="../spool/wiki.d/cache_Xorg.Annonce.tpl included=1} {/if}