diff --git a/interface/lib/classes/tform.inc.php b/interface/lib/classes/tform.inc.php index 026047c7dca480ff4a42f353f3b71b34f7320290..3d29591f87af0688c52007953d999178beca37cc 100644 --- a/interface/lib/classes/tform.inc.php +++ b/interface/lib/classes/tform.inc.php @@ -428,6 +428,20 @@ class tform { } $new_record[$key] = $out; break; + + case 'DATETIME': + if (strtotime($val) !== false) { + $dt_value = $val; + } elseif ( isset($field['default']) && (strtotime($field['default']) !== false) ) { + $dt_value = $field['default']; + } else { + $dt_value = 0; + } + + $display_seconds = (isset($field['display_seconds']) && $field['display_seconds'] == true) ? true : false; + + $new_record[$key] = $this->_getDateTimeHTML($key, $dt_value, $display_seconds); + break; default: $new_record[$key] = htmlspecialchars($record[$key]); @@ -520,6 +534,13 @@ class tform { } $new_record[$key] = $out; break; + + case 'DATETIME': + $dt_value = (isset($field['default'])) ? $field['default'] : 0; + $display_seconds = (isset($field['display_seconds']) && $field['display_seconds'] == true) ? true : false; + + $new_record[$key] = $this->_getDateTimeHTML($key, $dt_value, $display_seconds); + break; default: $new_record[$key] = htmlspecialchars($field['default']); @@ -585,6 +606,18 @@ class tform { case 'CURRENCY': $new_record[$key] = str_replace(",",".",$record[$key]); break; + + case 'DATETIME': + if (is_array($record[$key])) + { + $filtered_values = array_map(create_function('$item','return (int)$item;'), $record[$key]); + extract($filtered_values, EXTR_PREFIX_ALL, '_dt'); + + if ($_dt_day != 0 && $_dt_month != 0 && $_dt_year != 0) { + $new_record[$key] = date( 'Y-m-d H:i:s', mktime($_dt_hour, $_dt_minute, $_dt_second, $_dt_month, $_dt_day, $_dt_year) ); + } + } + break; } // The use of the field value is deprecated, use validators instead @@ -1256,7 +1289,109 @@ class tform { return $diffrec; } - + + /** + * Generate HTML for DATETIME fields. + * + * @access private + * @param string $form_element Name of the form element. + * @param string $default_value Selected value for fields. + * @param bool $display_secons Include seconds selection. + * @return string HTML + */ + function _getDateTimeHTML($form_element, $default_value, $display_seconds=false) + { + $_datetime = strtotime($default_value); + $_showdate = ($_datetime === false) ? false : true; + + $dselect = array('day','month','year','hour','minute'); + if ($display_seconds === true) { + $dselect[] = 'second'; + } + + $out = ''; + + foreach ($dselect as $dt_element) + { + $dt_options = array(); + $dt_space = 1; + + switch ($dt_element) { + case 'day': + for ($i = 1; $i <= 31; $i++) { + $dt_options[] = array('name' => sprintf('%02d', $i), + 'value' => sprintf('%d', $i)); + } + $selected_value = date('d', $_datetime); + break; + + case 'month': + for ($i = 1; $i <= 12; $i++) { + $dt_options[] = array('name' => strftime('%b', mktime(0, 0, 0, $i, 1, 2000)), + 'value' => strftime('%m', mktime(0, 0, 0, $i, 1, 2000))); + } + $selected_value = date('n', $_datetime); + break; + + case 'year': + $start_year = strftime("%Y"); + $years = range((int)$start_year, (int)($start_year+3)); + + foreach ($years as $year) { + $dt_options[] = array('name' => $year, + 'value' => $year); + } + $selected_value = date('Y', $_datetime); + $dt_space = 2; + break; + + case 'hour': + foreach(range(0, 23) as $hour) { + $dt_options[] = array('name' => sprintf('%02d', $hour), + 'value' => sprintf('%d', $hour)); + } + $selected_value = date('G', $_datetime); + break; + + case 'minute': + foreach(range(0, 59) as $minute) { + if (($minute % 5) == 0) { + $dt_options[] = array('name' => sprintf('%02d', $minute), + 'value' => sprintf('%d', $minute)); + } + } + $selected_value = (int)floor(date('i', $_datetime)); + break; + + case 'second': + foreach(range(0, 59) as $second) { + $dt_options[] = array('name' => sprintf('%02d', $second), + 'value' => sprintf('%d', $second)); + } + $selected_value = (int)floor(date('s', $_datetime)); + break; + } + + $out .= "<select name=\"".$form_element."[$dt_element]\" id=\"".$form_element."_$dt_element\" class=\"selectInput\" style=\"width: auto; float: none;\">"; + if (!$_showdate) { + $out .= "<option value=\"-\" selected=\"selected\">--</option>" . PHP_EOL; + } else { + $out .= "<option value=\"-\">--</option>" . PHP_EOL; + } + + foreach ($dt_options as $dt_opt) { + if ( $_showdate && ($selected_value == $dt_opt['value']) ) { + $out .= "<option value=\"{$dt_opt['value']}\" selected=\"selected\">{$dt_opt['name']}</option>" . PHP_EOL; + } else { + $out .= "<option value=\"{$dt_opt['value']}\">{$dt_opt['name']}</option>" . PHP_EOL; + } + } + + $out .= '</select>' . str_repeat(' ', $dt_space); + } + + return $out; + } } ?> \ No newline at end of file diff --git a/interface/web/js/uni-form/uni-form.jquery.js b/interface/web/js/uni-form/uni-form.jquery.js index 9786dde6c1d3f4af353b04bd41454eb249c6abb5..515c5570222104ec5a99be083e33e38420eded96 100644 --- a/interface/web/js/uni-form/uni-form.jquery.js +++ b/interface/web/js/uni-form/uni-form.jquery.js @@ -38,4 +38,68 @@ jQuery.fn.uniform = function(settings) { // Auto set on page load... $(document).ready(function() { jQuery('form.uniForm').uniform(); -}); \ No newline at end of file +}); + +function AR_ResetDates() +{ + if ($("#autoresponder:checked").val() == null) { + $("form.uniForm select").each( + function(){ + $(this).val( $("#" + $(this).attr("id") + " option:first").val() ); + } + ); + } +} + +function AR_SetNow() +{ + DateTime_SetValues('autoresponder_start_date'); + + now = new Date(); + end_date = new Date(now.getFullYear(), now.getMonth(), now.getDate()+2, 0, 0); + + DateTime_SetValues('autoresponder_end_date', end_date); +} + +function DateTime_SetValues(datetime_id, date_obj) +{ + var selects = ['day', 'month', 'year', 'hour', 'minute', 'second']; + + if ( (typeof(date_obj) == 'object') && (typeof(date_obj.getDate()) == 'number') ) { + var now = date_obj; + } else { + var now = new Date(); + } + + jQuery.each(selects, function() { + var unit_name = this.toString(); + var unit_value = ''; + + switch(unit_name) + { + case 'day': + unit_value = now.getDate(); + break; + case 'month': + unit_value = now.getMonth() + 1; + break; + case 'year': + unit_value = now.getFullYear(); + break; + case 'hour': + unit_value = now.getHours(); + break; + case 'minute': + unit_value = Math.round(parseInt(now.getMinutes())/5)*5; + break; + case 'second': + unit_value = now.getSeconds(); + break; + } + + unit_obj = $("#"+ datetime_id + "_" + unit_name); + if (unit_obj.val() !== null) { + unit_obj.val(unit_value); + } + }); +} \ No newline at end of file diff --git a/interface/web/mail/form/mail_user.tform.php b/interface/web/mail/form/mail_user.tform.php index a96d80c4fad5542abf96506989bd65ad14428d4f..22dea8488d3c5f4d4b9de267d5f6422757477c30 100644 --- a/interface/web/mail/form/mail_user.tform.php +++ b/interface/web/mail/form/mail_user.tform.php @@ -188,6 +188,24 @@ $form["tabs"]['autoresponder'] = array ( 'default' => 'n', 'value' => array(1 => 'y',0 => 'n') ), + 'autoresponder_start_date' => array ( + 'datatype' => 'DATETIME', + 'formtype' => 'DATETIME', + 'validators'=> array ( 0 => array ( 'type' => 'CUSTOM', + 'class' => 'validate_autoresponder', + 'function' => 'start_date', + 'errmsg'=> 'autoresponder_start_date_isfuture'), + ), + ), + 'autoresponder_end_date' => array ( + 'datatype' => 'DATETIME', + 'formtype' => 'DATETIME', + 'validators'=> array ( 0 => array ( 'type' => 'CUSTOM', + 'class' => 'validate_autoresponder', + 'function' => 'end_date', + 'errmsg'=> 'autoresponder_end_date_isgreater'), + ), + ), ################################## # ENDE Datatable fields ################################## diff --git a/interface/web/mail/mail_user_edit.php b/interface/web/mail/mail_user_edit.php index 0d4e7fdcca447dc1a32fe9424ba32732c1c9ccf4..374c77743095655c33bae72eb393b6d66810cba5 100644 --- a/interface/web/mail/mail_user_edit.php +++ b/interface/web/mail/mail_user_edit.php @@ -107,6 +107,13 @@ class page_action extends tform_actions { // Convert quota from Bytes to MB if($this->dataRecord["quota"] != -1) $app->tpl->setVar("quota",$this->dataRecord["quota"] / 1024 / 1024); + // Is autoresponder set? + if ($this->dataRecord['autoresponder'] == 'y') { + $app->tpl->setVar("ar_active", 'checked="checked"'); + } else { + $app->tpl->setVar("ar_active", ''); + } + parent::onShowEnd(); } @@ -188,6 +195,12 @@ class page_action extends tform_actions { } + //* if autoresponder checkbox not selected, do not save dates + if (!isset($_POST['autoresponder']) && array_key_exists('autoresponder_start_date', $_POST)) { + $this->dataRecord['autoresponder_start_date'] = array_map(create_function('$item','return 0;'), $this->dataRecord['autoresponder_start_date']); + $this->dataRecord['autoresponder_end_date'] = array_map(create_function('$item','return 0;'), $this->dataRecord['autoresponder_end_date']); + } + parent::onSubmit(); } diff --git a/interface/web/mail/templates/mail_user_autoresponder_edit.htm b/interface/web/mail/templates/mail_user_autoresponder_edit.htm index 883c3527304cb53bcf1c5d4129f058a97d3234c8..5a149047d60f5cbfccea68a38ecb0c2cc50f40c5 100644 --- a/interface/web/mail/templates/mail_user_autoresponder_edit.htm +++ b/interface/web/mail/templates/mail_user_autoresponder_edit.htm @@ -12,9 +12,18 @@ <div class="ctrlHolder"> <p class="label">{tmpl_var name='autoresponder_txt'}</p> <div class="multiField"> - {tmpl_var name='autoresponder'} + <div class="ctrlHolder" style="margin-bottom: 5px;"> + <input type="checkbox" value="y" id="autoresponder" name="autoresponder" onclick="AR_ResetDates();" {tmpl_var name='ar_active'} /> {tmpl_var format='strtoupper' name='page_and_txt'}<br /> + </div> + + <p style="margin-bottom: 3px;"> + <label for="autoresponder_start_date[day]" style="width: 55px;">{tmpl_var name='autoresponder_start_date_txt'}</label> + {tmpl_var name='autoresponder_start_date'} <a href="javascript:AR_SetNow();">now</a></p> + + <label for="password" style="width: 55px;">{tmpl_var name='autoresponder_end_date_txt'}</label> + {tmpl_var name='autoresponder_end_date'} </div> - </div> + </div> </fieldset> <input type="hidden" name="id" value="{tmpl_var name='id'}"> @@ -25,4 +34,4 @@ </div> </div> -</div> +</div> \ No newline at end of file