source: trunk/www/Base/Types/DateTime.php

Last change on this file was 93, checked in by chronos, 11 years ago
  • Fixed: System variable as parameter to constructors of descendents of Module class.
  • Removed: End PHP mark "?>" from all files.
File size: 2.9 KB
Line 
1<?php
2
3class TypeDateTime extends TypeBase
4{
5 var $DatabaseCompareOperators = array('Rovno' => '=', 'Nerovno' => '!=', 'Menší' => '<', 'Větší' => '>');
6
7 function OnView($Item)
8 {
9 global $MonthNames;
10
11 if($Item['Value'] != '')
12 {
13 $ValueParts = explode(' ', $Item['Value']);
14 $DateParts = explode('-', $ValueParts[0]);
15 $TimeParts = explode(':', $ValueParts[1]);
16
17 $Output = ($DateParts[2] * 1).'.'.($DateParts[1] * 1).'.'.$DateParts[0].' '.$TimeParts[0].':'.$TimeParts[1].':'.$TimeParts[2];
18 } else $Output = '';
19 return($Output);
20 }
21
22 function OnEdit($Item)
23 {
24 global $MonthNames;
25
26 $ValueParts = explode(' ', $Item['Value']);
27 $DateParts = explode('-', $ValueParts[0]);
28 $TimeParts = explode(':', $ValueParts[1]);
29
30 // Hour
31 $Output = '<select name="'.$Item['Name'].'-hour">';
32 for($I = 1; $I <= 24; $I++)
33 {
34 if($TimeParts[2] == $I) $Selected = ' selected="1"'; else $Selected = '';
35 $Output .= '<option value="'.$I.'"'.$Selected.'>'.$I.'</option>';
36 }
37 $Output .= '</select>';
38 // Minute
39 $Output .= '<select name="'.$Item['Name'].'-minute">';
40 for($I = 1; $I <= 60; $I++)
41 {
42 if($TimeParts[1] == $I) $Selected = ' selected="1"'; else $Selected = '';
43 $Output .= '<option value="'.$I.'"'.$Selected.'>'.$I.'</option>';
44 }
45 $Output .= '</select>';
46 // Second
47 $Output .= '<select name="'.$Item['Name'].'-second">';
48 for($I = 1; $I <= 60; $I++)
49 {
50 if($TimeParts[0] == $I) $Selected = ' selected="1"'; else $Selected = '';
51 $Output .= '<option value="'.$I.'"'.$Selected.'>'.$I.'</option>';
52 }
53 $Output .= '</select>';
54 // Day
55 $Output .= ' <select name="'.$Item['Name'].'-day">';
56 for($I = 1; $I <= 31; $I++)
57 {
58 if($DateParts[2] == $I) $Selected = ' selected="1"'; else $Selected = '';
59 $Output .= '<option value="'.$I.'"'.$Selected.'>'.$I.'</option>';
60 }
61 $Output .= '</select>';
62 // Month
63 $Output .= '<select name="'.$Item['Name'].'-month">';
64 for($I = 1; $I <= 12; $I++)
65 {
66 if($DateParts[1] == $I) $Selected = ' selected="1"'; else $Selected = '';
67 $Output .= '<option value="'.$I.'"'.$Selected.'>'.$MonthNames[$I].'</option>';
68 }
69 $Output .= '</select>';
70 // Year
71 $Output .= '<select name="'.$Item['Name'].'-year">';
72 for($I = 1900; $I < 2100; $I++)
73 {
74 if($DateParts[0] == $I) $Selected = ' selected="1"'; else $Selected = '';
75 $Output .= '<option value="'.$I.'"'.$Selected.'>'.$I.'</option>';
76 }
77 $Output .= '</select>';
78 return($Output);
79 }
80
81 function OnLoad($Item)
82 {
83 return($_POST[$Item['Name'].'-year'].'-'.$_POST[$Item['Name'].'-month'].'-'.$_POST[$Item['Name'].'-day'].' '.
84 $_POST[$Item['Name'].'-hour'].':'.$_POST[$Item['Name'].'-minute'].':'.$_POST[$Item['Name'].'-second']);
85 }
86
87 function DatabaseEscape($Value)
88 {
89 return('"'.addslashes($Value).'"');
90 }
91}
Note: See TracBrowser for help on using the repository browser.