Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Suggestion for Smarty function "html_select_date"

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Feature Requests
View previous topic :: View next topic  
Author Message
gallien
Smarty n00b


Joined: 24 Apr 2007
Posts: 1

PostPosted: Tue Apr 24, 2007 8:12 pm    Post subject: Suggestion for Smarty function "html_select_date" Reply with quote

Hard to believe, but I missed a feature in the full-featured function "hml_select_date". I have tried to get an output with days, months and years in the following style, so 16 months (with years) in the future will be displayed:

<select name="beginDay">
<option label="" value=""></option>
<option label="01" value="1">01</option>
<option label="02" value="2">02</option>
...
<option label="30" value="31">30</option>
<option label="31" value="31">31</option>
</select>
<select name="beginMonth">
<option label="" value=""></option>
<option label="Apr. 2007" value="04,2007" selected="selected">Apr. 2007</option>
<option label="Mai. 2007" value="05,2007">Mai. 2007</option>
...
<option label="Jun. 2008" value="06,2008">Jun. 2008</option>
<option label="Jul. 2008" value="07,2008">Jul. 2008</option>
</select>

The selection of dates could be keep short, e. g. for travel booking engines with a 16 month forecast. The user isn't able to choose some older months of the year etc. I use the preferred style in templates with:

{html_select_date prefix="begin" day_empty="" month_empty="" month_format="%b. %Y" month_value_format="%m,%Y" start_month=-1 end_month=16 field_order="DM"}

Perhaps it is possible to include the piece of code in this or in a similar way for the requested feature. Thanks!

Code:

--- function.html_select_date.php.orig   2007-03-06 21:13:54.000000000 +0100
+++ function.html_select_date.php   2007-04-24 21:12:15.741631448 +0200
@@ -42,6 +42,8 @@
     require_once $smarty->_get_plugin_filepath('function','html_options');
     /* Default values. */
     $prefix          = "Date_";
+    $start_month     = 1;
+    $end_month       = 12;
     $start_year      = strftime("%Y");
     $end_year        = $start_year;
     $display_days    = true;
@@ -88,6 +90,8 @@
         switch ($_key) {
             case 'prefix':
             case 'time':
+            case 'start_month':
+            case 'end_month':
             case 'start_year':
             case 'end_year':
             case 'month_format':
@@ -187,9 +191,18 @@
             $month_names[''] = $month_empty;
             $month_values[''] = '';
         }
-        for ($i = 1; $i <= 12; $i++) {
-            $month_names[$i] = strftime($month_format, mktime(0, 0, 0, $i, 1, 2000));
-            $month_values[$i] = strftime($month_value_format, mktime(0, 0, 0, $i, 1, 2000));
+
+        if ($start_month == -1) {
+            $start_month = strftime("%m");
+        }
+        $year = $start_year;
+        for ($i = 1; $i <= $end_month; $i++) {
+            $month = ($start_month + $i - 2) % 12 + 1;
+            if ($month == 1 && $i > 1) {
+                $year++;
+            }
+            $month_names[$i] = strftime($month_format, mktime(0, 0, 0, $month, 1, $year - 2000));
+            $month_values[$i] = strftime($month_value_format, mktime(0, 0, 0, $month, 1, $year - 2000));
         }
 
         $month_result .= '<select name=';
@@ -211,7 +224,7 @@
 
         $month_result .= smarty_function_html_options(array('output'     => $month_names,
                                                             'values'     => $month_values,
-                                                            'selected'   => (int)$time[1] ? strftime($month_value_format, mktime(0, 0, 0, (int)$time[1], 1, 2000)) : '',
+                                                            'selected'   => (int)$time[1] ? strftime($month_value_format, mktime(0, 0, 0, (int)$time[1], 1, (int)$time[0] - 2000)) : '',
                                                             'print_result' => false),
                                                       $smarty);
         $month_result .= '</select>';
Back to top
View user's profile Send private message
cybot
Smarty Regular


Joined: 20 Apr 2005
Posts: 83

PostPosted: Thu May 03, 2007 1:22 pm    Post subject: Reply with quote

start_month and end_month should be start_date and end_date, and dates (an array of dates)

it should not only possible to display [day] [month-year] but also other things

[day], [month], [year] <- this is current

what would be fine:

[weekofyear], [weekofyear-year], [month-year], [day-month-year], [dayofweek], [dayofyear]


just some ideas ...
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Feature Requests All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP