| 1 | <?php
|
|---|
| 2 |
|
|---|
| 3 | include_once(dirname(__FILE__).'/Base.php');
|
|---|
| 4 |
|
|---|
| 5 | class TypeDateTime extends TypeBase
|
|---|
| 6 | {
|
|---|
| 7 | function __construct(FormManager $FormManager)
|
|---|
| 8 | {
|
|---|
| 9 | parent::__construct($FormManager);
|
|---|
| 10 | $this->DatabaseCompareOperators = array('Rovno' => '=', 'Nerovno' => '!=', 'Menší' => '<', 'Větší' => '>');
|
|---|
| 11 | }
|
|---|
| 12 |
|
|---|
| 13 | function OnView(array $Item): ?string
|
|---|
| 14 | {
|
|---|
| 15 | if ($Item['Value'] == 0) return '';
|
|---|
| 16 | if ((strtolower($Item['Value']) == 'now') or (strtolower($Item['Value']) == '')) $Item['Value'] = time();
|
|---|
| 17 | $Parts = getdate($Item['Value']);
|
|---|
| 18 | $Output = $Parts['mday'].'.'.$Parts['mon'].'.'.$Parts['year'].' '.
|
|---|
| 19 | sprintf('%02d', $Parts['hours']).':'.sprintf('%02d', $Parts['minutes']).':'.sprintf('%02d', $Parts['seconds']);
|
|---|
| 20 | return $Output;
|
|---|
| 21 | }
|
|---|
| 22 |
|
|---|
| 23 | function OnEdit(array $Item): string
|
|---|
| 24 | {
|
|---|
| 25 | global $MonthNames;
|
|---|
| 26 |
|
|---|
| 27 | if (($Item['Value'] == null) or (($Item['Value'] !== null) and ((strtolower($Item['Value']) == 'now') or (strtolower($Item['Value']) == ''))))
|
|---|
| 28 | {
|
|---|
| 29 | $Item['Value'] = time();
|
|---|
| 30 | $IsNull = true;
|
|---|
| 31 | } else $IsNull = false;
|
|---|
| 32 | $Parts = getdate($Item['Value']);
|
|---|
| 33 |
|
|---|
| 34 | $Output = '';
|
|---|
| 35 | $Style = '';
|
|---|
| 36 | if (array_key_exists('Null', $Item) and $Item['Null'])
|
|---|
| 37 | {
|
|---|
| 38 | if (!$IsNull)
|
|---|
| 39 | {
|
|---|
| 40 | $Checked = ' checked="1"';
|
|---|
| 41 | $Style = 'style="display:inline;"';
|
|---|
| 42 | } else
|
|---|
| 43 | {
|
|---|
| 44 | $Checked = '';
|
|---|
| 45 | $Style = 'style="display:none;"';
|
|---|
| 46 | }
|
|---|
| 47 | $Output .= '<input type="checkbox" name="'.$Item['Name'].'-null"'.$Checked.' onclick="toggle(\''.
|
|---|
| 48 | $Item['Name'].'-hour\');toggle(\''.$Item['Name'].'-minute\');toggle(\''.$Item['Name'].'-second\');toggle(\''.
|
|---|
| 49 | $Item['Name'].'-day\');toggle(\''.$Item['Name'].'-month\');toggle(\''.$Item['Name'].'-year\');"/>';
|
|---|
| 50 | }
|
|---|
| 51 |
|
|---|
| 52 | // Hour
|
|---|
| 53 | $Output .= '<select name="'.$Item['Name'].'-hour" id="'.$Item['Name'].'-hour" '.$Style.'>';
|
|---|
| 54 | for ($I = 1; $I <= 24; $I++)
|
|---|
| 55 | {
|
|---|
| 56 | if ($Parts['hours'] == $I) $Selected = ' selected="1"'; else $Selected = '';
|
|---|
| 57 | $Output .= '<option value="'.$I.'"'.$Selected.'>'.$I.'</option>';
|
|---|
| 58 | }
|
|---|
| 59 | $Output .= '</select>';
|
|---|
| 60 | // Minute
|
|---|
| 61 | $Output .= '<select name="'.$Item['Name'].'-minute" id="'.$Item['Name'].'-minute" '.$Style.'>';
|
|---|
| 62 | for ($I = 1; $I <= 60; $I++)
|
|---|
| 63 | {
|
|---|
| 64 | if ($Parts['minutes'] == $I) $Selected = ' selected="1"'; else $Selected = '';
|
|---|
| 65 | $Output .= '<option value="'.$I.'"'.$Selected.'>'.$I.'</option>';
|
|---|
| 66 | }
|
|---|
| 67 | $Output .= '</select>';
|
|---|
| 68 | // Second
|
|---|
| 69 | $Output .= '<select name="'.$Item['Name'].'-second" id="'.$Item['Name'].'-second" '.$Style.'>';
|
|---|
| 70 | for ($I = 1; $I <= 60; $I++)
|
|---|
| 71 | {
|
|---|
| 72 | if ($Parts['seconds'] == $I) $Selected = ' selected="1"'; else $Selected = '';
|
|---|
| 73 | $Output .= '<option value="'.$I.'"'.$Selected.'>'.$I.'</option>';
|
|---|
| 74 | }
|
|---|
| 75 | $Output .= '</select>';
|
|---|
| 76 | // Day
|
|---|
| 77 | $Output .= ' <select name="'.$Item['Name'].'-day" id="'.$Item['Name'].'-day" '.$Style.'>';
|
|---|
| 78 | for ($I = 1; $I <= 31; $I++)
|
|---|
| 79 | {
|
|---|
| 80 | if ($Parts['mday'] == $I) $Selected = ' selected="1"'; else $Selected = '';
|
|---|
| 81 | $Output .= '<option value="'.$I.'"'.$Selected.'>'.$I.'</option>';
|
|---|
| 82 | }
|
|---|
| 83 | $Output .= '</select>';
|
|---|
| 84 | // Month
|
|---|
| 85 | $Output .= '<select name="'.$Item['Name'].'-month" id="'.$Item['Name'].'-month" '.$Style.'>';
|
|---|
| 86 | for ($I = 1; $I <= 12; $I++)
|
|---|
| 87 | {
|
|---|
| 88 | if ($Parts['mon'] == $I) $Selected = ' selected="1"'; else $Selected = '';
|
|---|
| 89 | $Output .= '<option value="'.$I.'"'.$Selected.'>'.$MonthNames[$I].'</option>';
|
|---|
| 90 | }
|
|---|
| 91 | $Output .= '</select>';
|
|---|
| 92 | // Year
|
|---|
| 93 | $Output .= '<select name="'.$Item['Name'].'-year" id="'.$Item['Name'].'-year" '.$Style.'>';
|
|---|
| 94 | for ($I = 1900; $I < 2100; $I++)
|
|---|
| 95 | {
|
|---|
| 96 | if ($Parts['year'] == $I) $Selected = ' selected="1"'; else $Selected = '';
|
|---|
| 97 | $Output .= '<option value="'.$I.'"'.$Selected.'>'.$I.'</option>';
|
|---|
| 98 | }
|
|---|
| 99 | $Output .= '</select>';
|
|---|
| 100 | return $Output;
|
|---|
| 101 | }
|
|---|
| 102 |
|
|---|
| 103 | function OnLoad(array $Item): ?string
|
|---|
| 104 | {
|
|---|
| 105 | if (!array_key_exists($Item['Name'].'-null', $_POST) and array_key_exists('Null', $Item) and ($Item['Null'] == true)) return null;
|
|---|
| 106 | else return mktime($_POST[$Item['Name'].'-hour'], $_POST[$Item['Name'].'-minute'], $_POST[$Item['Name'].'-second'],
|
|---|
| 107 | $_POST[$Item['Name'].'-month'], $_POST[$Item['Name'].'-day'], $_POST[$Item['Name'].'-year']);
|
|---|
| 108 | }
|
|---|
| 109 |
|
|---|
| 110 | function OnCanLoad(array $Item): bool
|
|---|
| 111 | {
|
|---|
| 112 | return array_key_exists($Item['Name'].'-null', $_POST) or (array_key_exists($Item['Name'].'-day', $_POST) and
|
|---|
| 113 | array_key_exists($Item['Name'].'-month', $_POST) and array_key_exists($Item['Name'].'-year', $_POST) and
|
|---|
| 114 | array_key_exists($Item['Name'].'-hour', $_POST) and array_key_exists($Item['Name'].'-minute', $_POST) and
|
|---|
| 115 | array_key_exists($Item['Name'].'-second', $_POST)
|
|---|
| 116 | );
|
|---|
| 117 | }
|
|---|
| 118 |
|
|---|
| 119 | function OnLoadDb(array $Item): ?string
|
|---|
| 120 | {
|
|---|
| 121 | return MysqlDateTimeToTime($Item['Value']);
|
|---|
| 122 | }
|
|---|
| 123 |
|
|---|
| 124 | function OnSaveDb(array $Item): ?string
|
|---|
| 125 | {
|
|---|
| 126 | if ($Item['Value'] == null) return null;
|
|---|
| 127 | else return date('Y-m-d H:i:s', $Item['Value']);
|
|---|
| 128 | }
|
|---|
| 129 |
|
|---|
| 130 | function DatabaseEscape(string $Value): string
|
|---|
| 131 | {
|
|---|
| 132 | return '"'.addslashes($Value).'"';
|
|---|
| 133 | }
|
|---|
| 134 | }
|
|---|