Commit | Line | Data |
---|---|---|
696f20d5 MS |
1 | <? |
2 | class FieldDate extends Field { | |
3 | function FieldDate($tmp_params) { | |
4 | global $load; | |
5 | $load->setOverwrite(true); | |
6 | $load->system("functions/date.php"); | |
7 | ||
8 | parent::Field("date", $tmp_params[0]); | |
9 | ||
10 | $this->label = $tmp_params[1]; | |
11 | $this->setInputType("date"); | |
12 | } | |
13 | ||
14 | function setFilterType($tmp_type) { | |
15 | //1 - interval of 2 fields | |
16 | //2 - combo of months | |
17 | $this->filter_type = $tmp_type; | |
18 | } | |
19 | ||
20 | function setInputType($tmp_type) { | |
21 | switch ($tmp_type) { | |
22 | default: | |
23 | case "date": | |
24 | $this->input_type = "date"; | |
25 | $this->filter_type = 2; | |
26 | $this->testRequiredType(array("date")); | |
27 | $this->validation = "DAT"; | |
28 | $this->size_cols = 10; | |
29 | $this->maxlength = 10; | |
30 | $this->minlength = 10; | |
31 | $this->list_width = 90; | |
32 | ||
33 | break; | |
34 | case "datetime": | |
35 | $this->input_type = "datetime"; | |
36 | $this->testRequiredType(array("datetime")); | |
37 | $this->validation = "DAT"; | |
38 | $this->maxlength = 19; | |
39 | $this->minlength = 19; | |
40 | $this->list_width = 100; | |
41 | ||
42 | break; | |
43 | } | |
44 | } | |
45 | ||
46 | //private functions | |
47 | function getHtmlList($tmp_extra) { | |
48 | $this->formatValue(); | |
49 | ||
50 | if ($this->value == "") { | |
51 | $this->value = "<font color='silver'>(vazio)</font>"; | |
52 | } | |
53 | ||
54 | $html = "<td " . $tmp_extra . " align='center'>" . $this->value . "</td>" . LF; | |
55 | ||
56 | return $html; | |
57 | } | |
58 | ||
59 | function getInput($tmp_n = 0) { | |
60 | if ($tmp_n == 0) { | |
61 | $tmp_n = ""; | |
62 | } | |
63 | ||
64 | $v = $this->getValue(); | |
65 | ||
66 | if ($this->input_type == "datetime") { | |
67 | $tmp = explode(" ", $v); | |
68 | $v = $tmp[0]; | |
69 | ||
70 | if (sizeof($tmp) > 1) { | |
71 | $v2 = $tmp[1]; | |
72 | } else { | |
73 | $v2 = ""; | |
74 | } | |
75 | ||
76 | $this->maxlength = 10; | |
77 | $this->minlength = 10; | |
78 | $this->size_cols = 10; | |
79 | } | |
80 | ||
81 | $id = $this->_getFormatedId($tmp_n); | |
82 | ||
83 | $html = "<input "; | |
84 | $html .= "class='input' "; | |
85 | $html .= "type='text' "; | |
86 | $html .= "id='" . $id . "' "; | |
87 | $html .= "name='" . $this->name . "' "; | |
88 | $html .= "size='" . $this->size_cols . "' "; | |
89 | $html .= "maxlength='" . $this->maxlength . "' "; | |
90 | $html .= "value=\"" . $this->_escapeValue($v) . "\" "; | |
91 | $html .= " " . $this->input_extra; | |
92 | $html .= ">"; | |
93 | ||
94 | ||
95 | ||
96 | if (($this->input_type == "datetime") && (!$this->in_filter)) { | |
97 | $this->validation = "HO2"; | |
98 | $this->maxlength = 8; | |
99 | $this->minlength = 8; | |
100 | $this->size_cols = 8; | |
101 | ||
102 | $id2 = $this->_getFormatedId($tmp_n); | |
103 | $html .= " <input "; | |
104 | $html .= "class='input' "; | |
105 | $html .= "type='text' "; | |
106 | $html .= "id='" . $id2 . "' "; | |
107 | $html .= "name='" . $this->name . "_2' "; | |
108 | $html .= "size='" . $this->size_cols . "' "; | |
109 | $html .= "maxlength='" . $this->maxlength . "' "; | |
110 | $html .= "value=\"" . $this->_escapeValue($v2) . "\" "; | |
111 | $html .= " " . $this->input_extra; | |
112 | $html .= ">"; | |
113 | } | |
114 | ||
115 | if (($this->input_type == "date") || ($this->input_type == "datetime")) { | |
116 | $html .= "<img title='Abrir calendário' align='top' onclick=\"javascript: objcalendario.open('" . $id . "');\" src='../img/buttons/bt-calendar.gif' style='cursor: pointer; margin: 1 2 0 3px; _margin: 2 2 0 3px;'>"; | |
117 | } | |
118 | ||
119 | if (($this->input_type == "datetime") && (!$this->in_filter)) { | |
120 | $html .= "<img title='Data/Hora atual' align='top' onclick=\"javascript: { $$('" . $id . "').value = '" . date("d/m/Y") . "'; $$('" . $id2 . "').value = '" . date("H:i:s") . "'; }\" src='../img/icons/time_go.gif' style='cursor: pointer; margin: 1 2 0 3px; _margin: 2 2 0 3px;'>"; | |
121 | } else { | |
122 | $html .= "<img title='Data atual' align='top' onclick=\"javascript: { $$('" . $id . "').value = '" . date("d/m/Y") . "'; }\" src='../img/icons/time_go.gif' style='cursor: pointer; margin: 1 2 0 3px; _margin: 2 2 0 3px;'>"; | |
123 | } | |
124 | ||
125 | return $html; | |
126 | } | |
127 | ||
128 | function getValueFormated() { | |
129 | if (($this->value != "") and ($this->value != "0000-00-00") and ($this->value != "0000-00-00 00:00:00")) { | |
130 | $this->detectInputType(); | |
131 | ||
132 | if ($this->input_type == "datetime") { | |
133 | $v = datetimeFromMysql($this->value); | |
134 | } else { | |
135 | $v = dateFromMysql($this->value); | |
136 | } | |
137 | } else { | |
138 | $v = ""; | |
139 | } | |
140 | ||
141 | return $v; | |
142 | } | |
143 | function getValueUnformated() { | |
144 | if (($this->value != "") and ($this->value != "00/00/0000") and ($this->value != "0000-00-00 00:00:00")) { | |
145 | $this->detectInputType(); | |
146 | ||
147 | if ($this->input_type == "datetime") { | |
148 | $tmp = explode(" ", $this->value); | |
149 | ||
150 | if (sizeof($tmp) <= 1) { | |
151 | global $input; | |
152 | ||
153 | $this->value = $this->value . " " . $input->request($this->name . "_2"); | |
154 | } | |
155 | ||
156 | $v = datetimeToMysql($this->value); | |
157 | } else { | |
158 | $v = dateToMysql($this->value); | |
159 | } | |
160 | } else { | |
161 | $v = ""; | |
162 | } | |
163 | ||
164 | return $v; | |
165 | } | |
166 | ||
167 | function detectInputType() { | |
168 | if ($this->input_type == "") { | |
169 | $tmp = explode(" ", $this->value); | |
170 | ||
171 | if (sizeof($tmp) > 1) { | |
172 | $this->input_type = "datetime"; | |
173 | } else { | |
174 | $this->input_type = "date"; | |
175 | } | |
176 | } | |
177 | } | |
178 | ||
179 | function getFilter() { | |
180 | global $input; | |
181 | ||
182 | $html = ""; | |
183 | $sql = ""; | |
184 | ||
185 | $filter_name = $this->_getFilterName(); | |
186 | $filter_value = $this->_getFilterValue(); | |
187 | $filter_chk = $this->_getFilterChecked(); | |
188 | $old_name = $this->name; | |
189 | ||
190 | $html = "<tr class='fieldset'>" . LF; | |
191 | $html .= " <td class='label'>" . $this->label . ":</td>" . LF; | |
192 | $html .= " <td class='label' style='width: 30px; text-align: center;'><input type='checkbox' name='" . $filter_name . "-chk' id='" . $filter_name . "-chk' value='1' " . $filter_chk . "></td>" . LF; | |
193 | ||
194 | //crete filter input | |
195 | $this->is_required = false; | |
196 | $this->in_filter = true; | |
197 | ||
198 | $html .= " <td class='input'>"; | |
199 | ||
200 | if ($this->filter_type == 1) { | |
201 | //Field 2 | |
202 | $filter_name2 = $this->_getFilterName(2); | |
203 | $filter_value2 = $this->_getFilterValue(2); | |
204 | ||
205 | //Field 1 | |
206 | $this->name = $filter_name; | |
207 | $this->value = $filter_value; | |
208 | $this->input_extra = "onKeyUp=\"javascript: { if (this.value != '') { $$('" . $filter_name . "-chk').checked = true; } else { $$('" . $filter_name . "-chk').checked = false; } }\""; | |
209 | ||
210 | $html .= $this->getInput(); | |
211 | ||
212 | ||
213 | //Field 2 | |
214 | $this->name = $filter_name2; | |
215 | ||
216 | if ($filter_value != "") { | |
217 | $this->value = $filter_value2; | |
218 | } else { | |
219 | $this->value = ""; | |
220 | } | |
221 | ||
222 | $html .= " à " . $this->getInput(2); | |
223 | ||
224 | ||
225 | if ($filter_value != "") { | |
226 | $v2 = dateToMysql($filter_value2); | |
227 | $v2 = strtotime($v2); | |
228 | $v2 += (24 * 60 * 60); | |
229 | $v2 = date("Y-m-d", $v2); | |
230 | ||
231 | $sql = " and " . $old_name . " >= '" . dateToMysql($filter_value) . "' and " . $old_name . " < '" . $v2 . "'"; | |
232 | } | |
233 | } else { | |
234 | global $form; | |
235 | global $db; | |
236 | global $load; | |
237 | ||
238 | $sql_list = " | |
239 | select | |
240 | distinct(concat(month(" . $old_name . "), '/', year(" . $old_name . "))) as junto, | |
241 | " . $old_name . " as data, | |
242 | year(" . $old_name . ") as ano, | |
243 | month(" . $old_name . ") as mes | |
244 | from | |
245 | " . $form->table . " | |
246 | where | |
247 | " . $old_name . " != '' and | |
248 | " . $old_name . " != '0000-00-00' | |
249 | group by | |
250 | junto | |
251 | order by | |
252 | ano desc, | |
253 | mes asc | |
254 | "; | |
255 | $rs = $db->execute($sql_list); | |
256 | ||
257 | $html .= "<select class='input' name='" . $filter_name . "' id='" . $this->label . "_CMB0' onclick=\"javascript: { if (this.value != '') { $$('" . $filter_name . "-chk').checked = true; } else { $$('" . $filter_name . "-chk').checked = false; } }\""; | |
258 | ||
259 | $html .= "<option value=''>Selecione</option>"; | |
260 | $html .= "<option value=''>------</option>"; | |
261 | ||
262 | while (!$rs->EOF) { | |
263 | $v = $rs->fields("ano") . "-" . substr("0" . $rs->fields("mes"), -2); | |
264 | if ($filter_value == $v) { | |
265 | $sql = " and month(" . $old_name . ") = '" . substr("0" . $rs->fields("mes"), -2) . "' and year(" . $old_name . ") > '" . substr("0" . $rs->fields("ano"), -2) . "'"; | |
266 | $s = " selected"; | |
267 | } else { | |
268 | $s = ""; | |
269 | } | |
270 | ||
271 | $html .= "<option value='" . $v . "'" . $s . ">" . monthToBrName($rs->fields("mes")) . "</option>"; | |
272 | ||
273 | $rs->moveNext(); | |
274 | } | |
275 | ||
276 | $html .= "</select>"; | |
277 | } | |
278 | ||
279 | $html .= "</td>" . LF; | |
280 | $html .= "</tr>" . LF; | |
281 | ||
282 | ||
283 | return array("html" => $html, "sql" => $sql); | |
284 | } | |
285 | } | |
286 | ?> |