Framework  3.9
time_field_renderer.inc
Go to the documentation of this file.
1 <?php
6 /**************************************************************
7 
8  Copyright (c) 2007-2010 Sonjara, Inc
9 
10  Permission is hereby granted, free of charge, to any person
11  obtaining a copy of this software and associated documentation
12  files (the "Software"), to deal in the Software without
13  restriction, including without limitation the rights to use,
14  copy, modify, merge, publish, distribute, sublicense, and/or sell
15  copies of the Software, and to permit persons to whom the
16  Software is furnished to do so, subject to the following
17  conditions:
18 
19  The above copyright notice and this permission notice shall be
20  included in all copies or substantial portions of the Software.
21 
22  Except as contained in this notice, the name(s) of the above
23  copyright holders shall not be used in advertising or otherwise
24  to promote the sale, use or other dealings in this Software
25  without prior written authorization.
26 
27  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
28  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
29  OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
30  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
31  HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
32  WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
33  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
34  OTHER DEALINGS IN THE SOFTWARE.
35 
36 *****************************************************************/
37 
38 require_once realpath(dirname(__FILE__))."/../field_renderers.inc";
39 
44 {
46  {
47  $this->FieldRenderer($parent);
48  }
49 
50  function writeScript($field)
51  {
52  //TODO: Script to mask for correct input
53  }
54 
55  function renderField($field)
56  {
57  $value = $this->parent->data->get($field);
58 
59  // JDG show as empty if value stored is 00
60  if ($value AND $value != '00:00:00')
61  {
62  $text = date("h/i/A", strtotime($value));
63  list($hh, $mm, $aa) = explode("/", $text);
64  }
65 
66  $this->_startField($field);
67 
68  echo "<input type='text' value='$hh' name='{$field}_hh' size='2' maxlength='2' onkeydown='return maskInput(event);'>&nbsp;:&nbsp;<input type='text' value='$mm' name='{$field}_mm' size='2' maxlength='2' onkeydown='return maskInput(event);'>";
69  echo "&nbsp;<select name='{$field}_aa'><option";
70  if ($aa == 'AM') echo " selected";
71  echo ">AM</option><option";
72  if ($aa == 'PM') echo " selected";
73  echo ">PM</option></select>";
74 
75  $this->_endField($field);
76  }
77 
78  function addValidatorsToForm($field, $required = false)
79  {
80  $prettyName = $this->parent->prettifyFieldName($field);
81 
82  $this->parent->validator->add(new TimeValidator($field, $label));
83 
84  if($required)
85  {
86  $this->parent->validator->add(new RequiredTimeValidator($field, $label));
87  }
88  }
89 
90  function renderSearchField($field, $mode)
91  {
92  echo "<tr>\n";
93  echo "<td colspan='2'";
94  if ($this->parent->labelCSS) echo " class='{$this->parent->labelCSS}'";
95  echo "><input type='checkbox' value='1' name='$field:$mode'";
96  if ($this->parent->data->get($field))
97  {
98  echo " checked";
99  }
100  echo ">&nbsp;";
101  echo $this->parent->prettifyFieldName($field);
102  echo "</td>\n</tr>\n";
103  }
104 
105  function renderReadOnly($field)
106  {
107  $this->_startField($field);
108 
109  //echo date('h:i A', strttotime($this->parent->data->get($field)));
110 
111  echo $this->parent->data->format("{{$field}:h:i A}");
112 
113  $this->_endField($field);
114  }
115 
116  function preProcess($field = "")
117  {
118  $hh = checkNumeric($_POST["{$field}_hh"]);
119  $mm = checkNumeric($_POST["{$field}_mm"]);
120  $aa = $_POST["{$field}_aa"];
121  if ($aa != "AM" && $aa != "PM") die("Invalid meridiem");
122 
123  // JDG - allow time fields to be empty
124  if(!$hh)
125  {
126  $this->parent->data->set($field, $this->parent->data->reformatToSQLDate("00:00"));
127  return;
128  }
129 
130  if ($aa == "PM" && $hh != "12") $hh += 12;
131  if ($aa == "AM" && $hh == "12") $hh = "00";
132  $this->parent->data->set($field, "$hh:$mm");
133  }
134 }
135 ?>
FieldRenderer is the abstract base class for all FieldRenderers.
_startField($field, $styles="")
Internal method to generate the starting HTML for the field (including the label)
_endField($field)
Internal method to generate the closing HTML for the field.
FieldRenderer($parent)
Constructor.
RequiredTimeValidator.
Definition: validation.inc:702
Field renderer for time data fields.
preProcess($field="")
FieldRenderers can override this method to provide behavior that occurs prior to the saving of the pa...
renderSearchField($field, $mode)
FieldRenderers must override this method to provide the HTML implementation of the control displayed ...
renderField($field)
FieldRenderers must override this method to provide the HTML implementation of the control used to ed...
addValidatorsToForm($field, $required=false)
This method is called by the AutoForm to add any default input validators that are required by the Fi...
TimeValidator.
Definition: validation.inc:658
checkNumeric($p)
Security helper function.
Definition: functions.inc:630