New "valid_date" smarty function to select purge dates
authorx2003bruneau <x2003bruneau@839d8a87-29fc-0310-9880-83ba4fa771e5>
Sun, 15 Apr 2007 20:25:30 +0000 (20:25 +0000)
committerx2003bruneau <x2003bruneau@839d8a87-29fc-0310-9880-83ba4fa771e5>
Sun, 15 Apr 2007 20:25:30 +0000 (20:25 +0000)
 modules/axletter.php                |   17 -----------------
 modules/events.php                  |   16 ----------------
 modules/xnetgrp.php                 |   16 ----------------
 templates/axletter/edit.tpl         |    2 +-
 templates/events/form.tpl           |    4 +---
 templates/xnetgrp/announce-edit.tpl |    4 +---
 6 files changed, 3 insertions(+), 56 deletions(-)

git-svn-id: svn+ssh://murphy/home/svn/platal/trunk@1700 839d8a87-29fc-0310-9880-83ba4fa771e5

modules/axletter.php
modules/events.php
modules/xnetgrp.php
plugins/function.valid_date.php [new file with mode: 0644]
templates/axletter/edit.tpl
templates/events/form.tpl
templates/xnetgrp/announce-edit.tpl

index 523b09a..a94db3a 100644 (file)
@@ -207,23 +207,6 @@ class AXLetterModule extends PLModule
 
         if (!$saved) {
             $select = '';
-            $time   = time() + 3600 * 24 * 2;
-            for ($i = 0 ; $i < 15 ; $i++) {
-                $time    += 3600 * 24;
-                $p_stamp = date('Ymd', $time);
-                $year    = date('Y',   $time);
-                $month   = date('m',   $time);
-                $day     = date('d',   $time);
-                
-                if ($p_stamp == $echeance_date) {
-                    $sel = ' selected="selected"';
-                } else {
-                    $sel = '';
-                }
-                $select .= "<option value=\"$p_stamp\"$sel> $day / $month / $year</option>\n";
-            }
-            $page->assign('echeance_date', $select);
-            $select = '';
             for ($i = 0 ; $i < 24 ; $i++) {
                 $stamp = sprintf('%02d:00:00', $i);
                 if ($stamp == $echeance_time) {
index 4981279..b3e2d87 100644 (file)
@@ -335,22 +335,6 @@ class EventsModule extends PLModule
         } elseif (!Env::v('preview')) {
             $upload->rm();
         }
-
-        $select = '';
-        for ($i = 1 ; $i < 30 ; $i++) {
-            $time    = time() + 3600 * 24 * $i;
-            $p_stamp = date('Ymd', $time);
-            $year    = date('Y',   $time);
-            $month   = date('m',   $time);
-            $day     = date('d',   $time);
-
-            $select .= "<option value=\"$p_stamp\"";
-            if ($p_stamp == strtr($peremption, array("-" => ""))) {
-                $select .= " selected='selected'";
-            }
-            $select .= "> $day / $month / $year</option>\n";
-        }
-        $page->assign('select',$select);
     }
 
     function handler_tips(&$page, $tips = null)
index a226054..88547d8 100644 (file)
@@ -1067,22 +1067,6 @@ class XnetGrpModule extends PLModule
             }
         }
 
-        $select = '';
-        for ($i = 1 ; $i < 30 ; $i++) {
-            $time    = time() + 3600 * 24 * $i;
-            $p_stamp = date('Ymd', $time);
-            $year    = date('Y',   $time);
-            $month   = date('m',   $time);
-            $day     = date('d',   $time);
-
-            $select .= "<option value=\"$p_stamp\"";
-            if ($p_stamp == strtr(@$art['peremption'], array("-" => ""))) {
-                $select .= " selected='selected'";
-            }
-            $select .= "> $day / $month / $year</option>\n";
-        }
-        $page->assign('select', $select);
-
         if (is_null($aid)) {
             $events = XDB::iterator("SELECT *
                                       FROM groupex.evenements
diff --git a/plugins/function.valid_date.php b/plugins/function.valid_date.php
new file mode 100644 (file)
index 0000000..bceb752
--- /dev/null
@@ -0,0 +1,59 @@
+<?php
+/***************************************************************************
+ *  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                *
+ ***************************************************************************/
+require_once 'platal.inc.php';
+
+function smarty_function_valid_date($params, &$smarty)
+{
+    extract($params);
+
+    if (!isset($name)) {
+        $name = 'valid_date';
+    }
+    $text = "<select name=\"$name\">";
+    if (!isset($from)) {
+        $from = 1;
+    }
+    if (!isset($to)) {
+        $to = 30;
+    }
+    $value = strtr($value, array('-' => ''));
+    $time = time() + 3600 * 24 * $from;
+    $mth  = '';
+    for ($i = $from ; $i <= $to ; $i++) {
+        $p_stamp = date('Ymd', $time);
+        $date    = date('d / m / Y', $time);
+        $select  = ($p_stamp == $value) ? 'selected="selected"' : '';
+        $month   = pl_entities(strftime('%B', $time), ENT_QUOTES);
+        if ($mth != $month) {
+            if ($i != $from) {
+                $text .= '</optgroup>';
+            }
+            $text .= "<optgroup label=\"$month\">";
+            $mth = $month;
+        }
+        $time += 3600 * 24;
+        $text .= "<option value=\"$p_stamp\" $select>$date</option>";
+    }
+    return $text . "</optgroup></select>";
+}
+
+/* vim: set expandtab enc=utf-8: */
+?>
index d32365a..e61a09f 100644 (file)
@@ -80,7 +80,7 @@
     <tr>
       <td class="titre">EchĂ©ance d'envoi</td>
       <td>
-        le <select name="echeance_date">{$echeance_date|smarty:nodefaults}</select>
+        le {valid_date name="echeance_date" value=$echeance_date from=3 to=15}
         vers <select name="echeance_time">{$echeance_time|smarty:nodefaults}</select>
       </td>
     </tr>
index fc2a958..9d7485d 100644 (file)
         Dernier jour d'affichage
       </td>
       <td>
-        <select name="peremption">
-          {$select|smarty:nodefaults}
-        </select>
+        {valid_date name="peremption" value=$peremption}
       </td>
     </tr>
     {if $admin_evts}
index a351e76..e0546fc 100644 (file)
@@ -111,9 +111,7 @@ function visibilityChange(box)
     <tr>
       <td class="titre">Date de pĂ©remption :</td>
       <td>
-        <select name="peremption">
-          {$select|smarty:nodefaults}
-        </select>
+        {valid_date name="peremption" value=$art.peremption}
       </td>
     </tr>
     {if $events}