CMS  Version 3.9
mootools_date_time_field_renderer.inc
Go to the documentation of this file.
1 <?php
8 /**************************************************************
9 
10  Copyright (c) 2007-2010 Sonjara, Inc
11 
12  Permission is hereby granted, free of charge, to any person
13  obtaining a copy of this software and associated documentation
14  files (the "Software"), to deal in the Software without
15  restriction, including without limitation the rights to use,
16  copy, modify, merge, publish, distribute, sublicense, and/or sell
17  copies of the Software, and to permit persons to whom the
18  Software is furnished to do so, subject to the following
19  conditions:
20 
21  The above copyright notice and this permission notice shall be
22  included in all copies or substantial portions of the Software.
23 
24  Except as contained in this notice, the name(s) of the above
25  copyright holders shall not be used in advertising or otherwise
26  to promote the sale, use or other dealings in this Software
27  without prior written authorization.
28 
29  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
30  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
31  OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
32  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
33  HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
34  WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
35  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
36  OTHER DEALINGS IN THE SOFTWARE.
37 
38 *****************************************************************/
39 
40 Fakoli::usingFeature("field_renderers");
41 
50 class MooToolsDateTimeFieldRenderer extends FieldRenderer
51 {
53  var $requireTime = true; // whether the time component of the field is also required
54  var $template = ""; // default reaonly format is short style
55 
57  {
58  $this->FieldRenderer($parent);
59  }
60 
61  function addValidatorsToForm($field, $required = false)
62  {
63  $label = isset($this->label) ? $this->label : $this->parent->prettifyFieldName($field);
64 
65  $this->parent->validator->add(new DateValidator($field, $label));
66  $this->parent->validator->add(new TimeValidator($field, $label));
67 
68  if($required)
69  {
70  $this->parent->validator->add(new RequiredValidator($field, $label));
71  if($this->requireTime)
72  $this->parent->validator->add(new RequiredTimeValidator($field, $label . " Time"));
73  }
74  }
75 
76  function renderScript($field)
77  {
78  $theme = strtolower(Settings::getValue("date_picker", "date_picker_theme"));
79 
80  $script = <<<ENDSCRIPT
81 
82 <script type="text/javascript">
83 
84 window.addEvent('domready', function(){
85  new Picker.Date(document.id('{$this->parent->id}_{$field}'),
86  {
87  timePicker: true,
88  positionOffset: {x: 5, y: 0},
89  pickerClass: 'datepicker_{$theme}',
90  useFadeInOut: !Browser.ie
91  });
92 });
93 </script>
94 ENDSCRIPT;
95 
96  echo $script;
97  }
98 
99  function renderField($field)
100  {
101  $obj = $this->parent->data;
102  $value = $obj->get($field);
103 
104  // JDG 10/1/2010 check for empty saved string
105  $date = "";
106  if($value AND $value != '0000-00-00 00:00:00')
107  $date = DateTimeTypeRenderer::format($obj->reformatFromSQLDate($value), "m/d/Y");
108 
109  $this->_startField($field);
110  echo "<input id='{$this->parent->id}_{$field}' type='text' name='$field' value='$date' size='12'>&nbsp;<img src='{$this->parent->componentPath}/calendar/calendar.gif' alt='Popup Calendar' align='absmiddle' border='0' onclick='{$field}_calendar.toggle(this)'>\n";
111 
112  /*// If no time component, show as blank, not 12:00 AM
113  if ($value AND !preg_match("/00:00:00$/", $value))
114  {
115  $text = date("h/i/A", strtotime($value));
116  list($hh, $mm, $aa) = explode("/", $text);
117  }
118 
119  echo "<div id='{$this->parent->id}_{$field}_block' style='display: inline'>\n";
120  echo "&nbsp;&nbsp;<input type='text' value='$hh' name='{$field}_hh' size='2' maxlength='2' onkeydown='return maskInput(event);'>
121  &nbsp;:&nbsp;<input type='text' value='$mm' name='{$field}_mm' size='2' maxlength='2' onkeydown='return maskInput(event);'>";
122  echo "&nbsp;<select name='{$field}_aa'><option";
123  if ($aa == 'AM') echo " selected";
124  echo ">AM</option><option";
125  if ($aa == 'PM') echo " selected";
126  echo ">PM</option></select>";
127  echo "</div>\n";*/
128 
129  $this->_endField($field);
130  }
131 
133  {
134  /*$script = "";
135 
136  if (!$this->_includedDateScript)
137  {
138  echo "<script src='{$this->parent->componentPath}/calendar/sonjara_calendar.js' type='text/javascript'></script>\n";
139  echo "<link href='{$this->parent->componentPath}/calendar/sonjara_calendar.css' type='text/css' rel='stylesheet'>\n";
140  $this->_includedDateScript = true;
141  }
142 
143  if ($mode == "range")
144  {
145  $calendar_from = "{$field}_calendar_from";
146  $calendar_to = "{$field}_calendar_to";
147 
148  echo "<script type='text/javascript'>\n";
149  echo "var $calendar_from = new Calendar('$calendar_from', '{$this->parent->id}', '$field:from');\n";
150  echo "var $calendar_to = new Calendar('$calendar_to', '{$this->parent->id}', '$field:to');\n";
151  echo "</script>\n";
152  }
153  else
154  {
155  $calendar = "{$field}_calendar_{$mode}";
156  echo "<script type='text/javascript'>\n";
157  echo "var $calendar = new Calendar('$calendar', '{$this->parent->id}', '$field:$mode');\n";
158  echo "</script>\n";
159  }*/
160  }
161 
163  {
164  /*if ($mode == "range")
165  {
166  $date_from = $this->parent->params->get($field, "from");
167  $date_to = $this->parent->params->get($field, "to");
168  echo "<tr>\n";
169  $this->_printLabel($field);
170  echo "<td>";
171  echo "<input type='text' name='$field:from' value='$date_from' size='12'>&nbsp;<img src='{$this->parent->componentPath}/calendar/calendar.gif' alt='Popup Calendar' align='absmiddle' border='0' onclick='{$field}_calendar_from.toggle(this)'>";
172  echo " to <input type='text' name='$field:to' value='$date_to' size='12'>&nbsp;<img src='{$this->parent->componentPath}/calendar/calendar.gif' alt='Popup Calendar' align='absmiddle' border='0' onclick='{$field}_calendar_to.toggle(this)'></td>\n";
173  echo "</td>\n";
174  echo "</tr>\n";
175  }
176  else
177  {
178  $date = $this->parent->params->get($field, $mode);
179  echo "<tr>\n";
180  $this->_printLabel($field);
181  echo "<td>";
182  echo "<input type='text' name='$field:$mode' value='$date' size='12'>&nbsp;<img src='{$this->parent->componentPath}/calendar/calendar.gif' alt='Popup Calendar' align='absmiddle' border='0' onclick='{$field}_calendar_{$mode}.toggle(this)'></td>\n";
183  echo "</td>\n";
184  echo "</tr>\n";
185  }*/
186  }
187 
189  {
190  $this->_startField($field);
191 
192  echo $this->format($field);
193 
194  // AJG - if the field is read-only but the form is not, add a hidden field to
195  // retain the field value upon submission.
196  if (!$this->parent->readOnlyForm)
197  {
198  $obj = $this->parent->data;
199  $value = $obj->get($field);
200  echo "<input type='hidden' name='$field' value='{$value}'/>";
201  }
202 
203  $this->_endField($field);
204  }
205 
206  function preProcess($field = "")
207  {
208  $hh = checkNumeric($_POST["{$field}_hh"]);
209  if(intval($hh) == 0) $hh = "00";
210  $mm = checkNumeric($_POST["{$field}_mm"]);
211  if(intval($mm) == 0) $mm = "00";
212  $aa = $_POST["{$field}_aa"];
213  $dd = $_POST["{$field}"];
214 
215  if (!$dd)
216  {
217  $this->parent->data->set($field, $this->parent->data->reformatToSQLDate("00/00/0000 00:00:00"));
218  return;
219  }
220  if($hh == "00" && $mm == "00")
221  {
222  $this->parent->data->set($field, $this->parent->data->reformatToSQLDate("$dd"));
223  return;
224  }
225 
226  if ($aa != "AM" && $aa != "PM") throw new FakoliException("Invalid meridiem");
227  if ($aa == "PM" && $hh != "12") $hh += 12;
228  if ($aa == "AM" && $hh == "12") $hh = "00";
229  $this->parent->data->set($field, $this->parent->data->reformatToSQLDate("$dd $hh:$mm:00"));
230  }
231 
232  function format($field)
233  {
234  return DateTimeTypeRenderer::format($this->parent->data->get($field), $this->template);
235  }
236 
237 }
238 ?>
$_POST["owner_id"]
Definition: blog_form.inc:54
$parent
Definition: templates.inc:42
FakoliException is the base exception class for all Fakoli errors.
Definition: core.inc:53
static usingFeature()
Uses the specified framework feature(s).
Definition: core.inc:388
Field renderer for date data fields.
static getValue($component, $name)
Retrieve the value of the specified Setting.
Definition: settings.inc:104
$date
Definition: event_list.inc:51
$mode