Replaces all left occurences of 'shortname' in AXLetter, as it uses extract() to...
authorVincent Zanotti <vincent.zanotti@polytechnique.org>
Sun, 18 May 2008 14:17:40 +0000 (16:17 +0200)
committerVincent Zanotti <vincent.zanotti@polytechnique.org>
Sun, 18 May 2008 14:19:13 +0000 (16:19 +0200)
Also fixes an issue with deadline insertion in MySQL (input in YYYYMMDD format instead of YYYY-MM-DD).

Signed-off-by: Vincent Zanotti <vincent.zanotti@polytechnique.org>
modules/axletter.php
templates/axletter/edit.tpl

index 5f6eb9a..7ea3f06 100644 (file)
@@ -80,18 +80,19 @@ class AXLetterModule extends PLModule
 
         $page->changeTpl('axletter/edit.tpl');
 
-        $saved     = Post::i('saved');
-        $new       = false;
-        $id        = Post::i('id');
-        $shortname = trim(Post::v('shortname'));
-        $subject   = trim(Post::v('subject'));
-        $title     = trim(Post::v('title'));
-        $body      = rtrim(Post::v('body'));
-        $signature = trim(Post::v('signature'));
-        $promo_min = Post::i('promo_min');
-        $promo_max = Post::i('promo_max');
-        $echeance  = Post::has('echeance_date') ? Post::v('echeance_date') . ' ' . Post::v('echeance_time')
-                                                : Post::v('echeance');
+        $saved      = Post::i('saved');
+        $new        = false;
+        $id         = Post::i('id');
+        $short_name = trim(Post::v('short_name'));
+        $subject    = trim(Post::v('subject'));
+        $title      = trim(Post::v('title'));
+        $body       = rtrim(Post::v('body'));
+        $signature  = trim(Post::v('signature'));
+        $promo_min  = Post::i('promo_min');
+        $promo_max  = Post::i('promo_max');
+        $echeance   = Post::has('echeance_date') ?
+              preg_replace('/^(\d\d\d\d)(\d\d)(\d\d)$/', '\1-\2-\3', Post::v('echeance_date')) . ' ' . Post::v('echeance_time')
+            : Post::v('echeance');
         $echeance_date = Post::v('echeance_date');
         $echeance_time = Post::v('echeance_time');
 
@@ -126,19 +127,19 @@ class AXLetterModule extends PLModule
                 $page->trig("L'intervalle de promotions n'est pas valide");
                 Post::kill('valid');
             }
-            if (empty($shortname)) {
+            if (empty($short_name)) {
                 $page->trig("L'annonce doit avoir un nom raccourci pour simplifier la navigation dans les archives");
                 Post::kill('valid');
-            } elseif (!preg_match('/^[a-z][-a-z0-9]*[a-z0-9]$/', $shortname)) {
+            } elseif (!preg_match('/^[a-z][-a-z0-9]*[a-z0-9]$/', $short_name)) {
                 $page->trig("Le nom raccourci n'est pas valide, il doit comporter au moins 2 caractères et n'être composé "
                           . "que de chiffres, lettres et tirets");
                 Post::kill('valid');
-            } elseif ($shortname != Post::v('old_shortname')) {
-                $res = XDB::query("SELECT id FROM axletter WHERE short_name = {?}", $shortname);
+            } elseif ($short_name != Post::v('old_short_name')) {
+                $res = XDB::query("SELECT id FROM axletter WHERE short_name = {?}", $short_name);
                 if ($res->numRows() && $res->fetchOneCell() != $id) {
-                    $page->trig("Le nom $shortname est déjà utilisé, merci d'en choisir un autre");
-                    $shortname = Post::v('old_shortname');
-                    if (empty($shortname)) {
+                    $page->trig("Le nom $short_name est déjà utilisé, merci d'en choisir un autre");
+                    $short_name = Post::v('old_short_name');
+                    if (empty($short_name)) {
                         Post::kill('valid');
                     }
                 }
@@ -147,7 +148,7 @@ class AXLetterModule extends PLModule
             switch (@Post::v('valid')) {
               case 'Aperçu':
                 require_once dirname(__FILE__) . '/axletter/axletter.inc.php';
-                $al = new AXLetter(array($id, $shortname, $subject, $title, $body, $signature,
+                $al = new AXLetter(array($id, $short_name, $subject, $title, $body, $signature,
                                          $promo_min, $promo_max, $echeance, 0, 'new'));
                 $al->toHtml($page, S::v('prenom'), S::v('nom'), S::v('femme'));
                 break;
@@ -156,7 +157,7 @@ class AXLetterModule extends PLModule
                 XDB::execute("REPLACE INTO  axletter
                                        SET  id = {?}, short_name = {?}, subject = {?}, title = {?}, body = {?},
                                             signature = {?}, promo_min = {?}, promo_max = {?}, echeance = {?}",
-                             $id, $shortname, $subject, $title, $body, $signature, $promo_min, $promo_max, $echeance);
+                             $id, $short_name, $subject, $title, $body, $signature, $promo_min, $promo_max, $echeance);
                 if (!$saved) {
                     global $globals;
                     $mailer = new PlMailer();
@@ -191,7 +192,7 @@ class AXLetterModule extends PLModule
             }
         }
         $page->assign('id', $id);
-        $page->assign('shortname', $shortname);
+        $page->assign('short_name', $short_name);
         $page->assign('subject', $subject);
         $page->assign('title', $title);
         $page->assign('body', $body);
index dbff9f9..12a0092 100644 (file)
@@ -28,7 +28,7 @@
 
   <p class="center">
     <input type="hidden" name="id" value="{$id}" />
-    <input type="hidden" name="old_shortname" value="{$shortname}" />
+    <input type="hidden" name="old_short_name" value="{$short_name}" />
     <input type="hidden" name="saved" value="{$saved}" />
     {if $echeance}
     <input type="hidden" name="echeance" value="{$echeance}" />
@@ -58,7 +58,7 @@
     <tr>
       <td class="titre">Nom raccourci</td>
       <td>
-        <input type="text" name="shortname" value="{$shortname}" size="16" maxlength="16" />
+        <input type="text" name="short_name" value="{$short_name}" size="16" maxlength="16" />
         <span class="smaller">(uniquement lettres, chiffres ou -)</span>
       </td>
     </tr>
@@ -89,7 +89,7 @@
 
   <p class="center">
     <input type="hidden" name="id" value="{$id}" />
-    <input type="hidden" name="old_shortname" value="{$shortname}" />
+    <input type="hidden" name="old_short_name" value="{$short_name}" />
     <input type="hidden" name="saved" value="{$saved}" />
     {if $echeance}
     <input type="hidden" name="echeance" value="{$echeance}" />