| 1 | <?php
|
|---|
| 2 |
|
|---|
| 3 | include_once(dirname(__FILE__).'/Base.php');
|
|---|
| 4 |
|
|---|
| 5 | class TypeTime 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 | $TimeParts = getdate($Item['Value']);
|
|---|
| 18 |
|
|---|
| 19 | $Output = sprintf('%02d', $TimeParts['hours']).':'.sprintf('%02d', $TimeParts['minutes']).':'.sprintf('%02d', $TimeParts['seconds']);
|
|---|
| 20 | return $Output;
|
|---|
| 21 | }
|
|---|
| 22 |
|
|---|
| 23 | function OnEdit(array $Item): string
|
|---|
| 24 | {
|
|---|
| 25 | if (($Item['Value'] == null) or (($Item['Value'] !== null) and ((strtolower($Item['Value']) == 'now') or (strtolower($Item['Value']) == ''))))
|
|---|
| 26 | {
|
|---|
| 27 | $Item['Value'] = time();
|
|---|
| 28 | $IsNull = true;
|
|---|
| 29 | } else $IsNull = false;
|
|---|
| 30 | $TimeParts = getdate($Item['Value']);
|
|---|
| 31 |
|
|---|
| 32 | $Output = '';
|
|---|
| 33 | $Style = '';
|
|---|
| 34 | if (array_key_exists('Null', $Item) and $Item['Null'])
|
|---|
| 35 | {
|
|---|
| 36 | if ($IsNull)
|
|---|
| 37 | {
|
|---|
| 38 | $Checked = ' checked="1"';
|
|---|
| 39 | $Style = 'style="display:inline;"';
|
|---|
| 40 | } else
|
|---|
| 41 | {
|
|---|
| 42 | $Checked = '';
|
|---|
| 43 | $Style = 'style="display:none;"';
|
|---|
| 44 | }
|
|---|
| 45 | $Output .= '<input type="checkbox" name="'.$Item['Name'].'-null"'.$Checked.' onclick="toggle(\''.
|
|---|
| 46 | $Item['Name'].'-hour\');toggle(\''.$Item['Name'].'-minute\');toggle(\''.$Item['Name'].'-second\');"/>';
|
|---|
| 47 | }
|
|---|
| 48 |
|
|---|
| 49 | // Hour
|
|---|
| 50 | $Output .= '<select name="'.$Item['Name'].'-hour" id="'.$Item['Name'].'-hour" '.$Style.'>';
|
|---|
| 51 | for ($I = 1; $I <= 24; $I++)
|
|---|
| 52 | {
|
|---|
| 53 | if ($TimeParts['hours'] == $I) $Selected = ' selected="1"'; else $Selected = '';
|
|---|
| 54 | $Output .= '<option value="'.$I.'"'.$Selected.'>'.$I.'</option>';
|
|---|
| 55 | }
|
|---|
| 56 | $Output .= '</select>';
|
|---|
| 57 | // Minute
|
|---|
| 58 | $Output .= '<select name="'.$Item['Name'].'-minute" id="'.$Item['Name'].'-minute" '.$Style.'>';
|
|---|
| 59 | for ($I = 1; $I <= 60; $I++)
|
|---|
| 60 | {
|
|---|
| 61 | if ($TimeParts['month'] == $I) $Selected = ' selected="1"'; else $Selected = '';
|
|---|
| 62 | $Output .= '<option value="'.$I.'"'.$Selected.'>'.$I.'</option>';
|
|---|
| 63 | }
|
|---|
| 64 | $Output .= '</select>';
|
|---|
| 65 | // Second
|
|---|
| 66 | $Output .= '<select name="'.$Item['Name'].'-second" id="'.$Item['Name'].'-second" '.$Style.'>';
|
|---|
| 67 | for ($I = 1; $I <= 60; $I++)
|
|---|
| 68 | {
|
|---|
| 69 | if ($TimeParts['seconds'] == $I) $Selected = ' selected="1"'; else $Selected = '';
|
|---|
| 70 | $Output .= '<option value="'.$I.'"'.$Selected.'>'.$I.'</option>';
|
|---|
| 71 | }
|
|---|
| 72 | $Output .= '</select>';
|
|---|
| 73 | return $Output;
|
|---|
| 74 | }
|
|---|
| 75 |
|
|---|
| 76 | function OnLoad(array $Item): ?string
|
|---|
| 77 | {
|
|---|
| 78 | if (!array_key_exists($Item['Name'].'-null', $_POST) and array_key_exists('Null', $Item) and ($Item['Null'] == true)) return null;
|
|---|
| 79 | return mktime($_POST[$Item['Name'].'-hour'], $_POST[$Item['Name'].'-minute'], $_POST[$Item['Name'].'-second']);
|
|---|
| 80 | }
|
|---|
| 81 |
|
|---|
| 82 | function OnCanLoad(array $Item): bool
|
|---|
| 83 | {
|
|---|
| 84 | return array_key_exists($Item['Name'].'-null', $_POST) or (array_key_exists($Item['Name'].'-hour', $_POST) and
|
|---|
| 85 | array_key_exists($Item['Name'].'-minute', $_POST) and array_key_exists($Item['Name'].'-second', $_POST)
|
|---|
| 86 | );
|
|---|
| 87 | }
|
|---|
| 88 |
|
|---|
| 89 | function OnLoadDb(array $Item): ?string
|
|---|
| 90 | {
|
|---|
| 91 | return MysqlTimeToTime($Item['Value']);
|
|---|
| 92 | }
|
|---|
| 93 |
|
|---|
| 94 | function OnSaveDb(array $Item): ?string
|
|---|
| 95 | {
|
|---|
| 96 | if ($Item['Value'] == null) return null;
|
|---|
| 97 | else return date('H:i:s', $Item['Value']);
|
|---|
| 98 | }
|
|---|
| 99 |
|
|---|
| 100 | function DatabaseEscape(string $Value): string
|
|---|
| 101 | {
|
|---|
| 102 | return '"'.addslashes($Value).'"';
|
|---|
| 103 | }
|
|---|
| 104 | }
|
|---|