From 61f649e1aed2e79d3a81e51155dcf937a7a38ba0 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 29 Mar 2014 04:26:44 +0100 Subject: [PATCH] Fix: When select_date is called with '' as preselected date, automatic user date was not correctly et (We must set a date into PHP server timezone area) Fix: First param of select_date must always be forged with a dolibarr date function and not time(). New: Add a page for tests. --- htdocs/compta/bank/fiche.php | 2 +- htdocs/core/class/html.form.class.php | 24 +++++---- htdocs/core/lib/functions.lib.php | 6 +-- htdocs/cron/card.php | 8 +-- htdocs/public/test/test_arrays.php | 9 ++-- htdocs/public/test/test_forms.php | 71 +++++++++++++++++++++++++++ 6 files changed, 98 insertions(+), 22 deletions(-) create mode 100644 htdocs/public/test/test_forms.php diff --git a/htdocs/compta/bank/fiche.php b/htdocs/compta/bank/fiche.php index 37376aceb7a..806ca6fa5ad 100644 --- a/htdocs/compta/bank/fiche.php +++ b/htdocs/compta/bank/fiche.php @@ -325,7 +325,7 @@ if ($action == 'create') print ''.$langs->trans("Date").''; print ''; - $form->select_date(time(), 're', 0, 0, 0, 'formsoc'); + $form->select_date('', 're', 0, 0, 0, 'formsoc'); print ''; print ''.$langs->trans("BalanceMinimalAllowed").''; diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 452d0e7110d..5943d451b9c 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -2915,16 +2915,17 @@ class Form } /** - * Show a form to select a date + * Show a form + html select a date * * @param string $page Page * @param string $selected Date preselected - * @param string $htmlname Name of input html field + * @param string $htmlname Html name of date input fields or 'none' * @param int $displayhour Display hour selector * @param int $displaymin Display minutes selector * @return void + * @see select_date */ - function form_date($page, $selected, $htmlname,$displayhour=0,$displaymin=0) + function form_date($page, $selected, $htmlname, $displayhour=0, $displaymin=0) { global $langs; @@ -3437,13 +3438,13 @@ class Form /** - * Show a HTML widget to input a date or combo list for day, month, years and optionnaly hours and minutes + * Show a HTML widget to input a date or combo list for day, month, years and optionnaly hours and minutes. * Fields are preselected with : - * - set_time date (Local PHP server timestamps or date format YYYY-MM-DD or YYYY-MM-DD HH:MM) - * - local date of PHP server if set_time is '' - * - Empty (fields empty) if set_time is -1 (in this case, parameter empty must also have value 1) + * - set_time date (must be a local PHP server timestamp or string date with format 'YYYY-MM-DD' or 'YYYY-MM-DD HH:MM') + * - local date in user area, if set_time is '' (so if set_time is '', output may differs when done from two different location) + * - Empty (fields empty), if set_time is -1 (in this case, parameter empty must also have value 1) * - * @param timestamp $set_time Pre-selected date (must be a local PHP server timestamp) + * @param timestamp $set_time Pre-selected date (must be a local PHP server timestamp), -1 to keep date not preselected, '' to use current date. * @param string $prefix Prefix for fields name * @param int $h 1=Show also hours * @param int $m 1=Show also minutes @@ -3455,6 +3456,7 @@ class Form * @param int $disabled Disable input fields * @param int $fullday When a checkbox with this html name is on, hour and day are set with 00:00 or 23:59 * @return mixed Nothing or string if nooutput is 1 + * @see form_date */ function select_date($set_time='', $prefix='re', $h=0, $m=0, $empty=0, $form_name="", $d=1, $addnowbutton=0, $nooutput=0, $disabled=0, $fullday='') { @@ -3467,7 +3469,11 @@ class Form if($m == '') $m=0; if($empty == '') $empty=0; - if (! $set_time && $empty == 0) $set_time = dol_now('tzuser'); + if ($set_time === '' && $empty == 0) + { + include_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; + $set_time = dol_now('tzuser')-(getServerTimeZoneInt('now')*3600); // set_time must be relative to PHP server timezone + } // Analysis of the pre-selection date if (preg_match('/^([0-9]+)\-([0-9]+)\-([0-9]+)\s?([0-9]+)?:?([0-9]+)?/',$set_time,$reg)) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index bf398c389c0..c3889a41456 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -1058,7 +1058,7 @@ function dol_mktime($hour,$minute,$second,$month,$day,$year,$gm=false,$check=1) /** - * Return date for now. We should always use this function without parameters (that means GMT time) + * Return date for now. In mot cases, we use this function without parameters (that means GMT time). * * @param string $mode 'gmt' => we return GMT timestamp, * 'tzserver' => we add the PHP server timezone @@ -1068,7 +1068,7 @@ function dol_mktime($hour,$minute,$second,$month,$day,$year,$gm=false,$check=1) */ function dol_now($mode='gmt') { - // Note that gmmktime and mktime return same value (GMT) whithout parameters + // Note that gmmktime and mktime return same value (GMT) when used without parameters //if ($mode == 'gmt') $ret=gmmktime(); // Strict Standards: gmmktime(): You should be using the time() function instead if ($mode == 'gmt') $ret=time(); // Time for now at greenwich. else if ($mode == 'tzserver') // Time for now with PHP server timezone added @@ -1083,7 +1083,7 @@ function dol_now($mode='gmt') $tzsecond=getParentCompanyTimeZoneInt(); // Contains tz+dayling saving time $ret=dol_now('gmt')+($tzsecond*3600); }*/ - else if ($mode == 'tzuser') // Time for now with user timezone is added + else if ($mode == 'tzuser') // Time for now with user timezone added { //print 'eeee'.time().'-'.mktime().'-'.gmmktime(); $offsettz=(empty($_SESSION['dol_tz'])?0:$_SESSION['dol_tz'])*60*60; diff --git a/htdocs/cron/card.php b/htdocs/cron/card.php index 89b257ca817..4857523aaf5 100644 --- a/htdocs/cron/card.php +++ b/htdocs/cron/card.php @@ -303,11 +303,13 @@ if (($action=="create") || ($action=="edit")) print ""; print $langs->trans('CronHourStart').""; - if(!empty($object->datestart)){ + if(!empty($object->datestart)) + { $form->select_date($object->datestart,'datestart',1,1,'',"cronform"); } - else{ - $form->select_date(dol_now(),'datestart',1,1,'',"cronform"); + else + { + $form->select_date('','datestart',1,1,'',"cronform"); } print ""; print ""; diff --git a/htdocs/public/test/test_arrays.php b/htdocs/public/test/test_arrays.php index fb8274e5524..f7e29a695a1 100644 --- a/htdocs/public/test/test_arrays.php +++ b/htdocs/public/test/test_arrays.php @@ -131,11 +131,8 @@ Example 1 : Table using tags: div.tagtable+div.tagtr+div or div.tagtable+div.tag Example 2 : Table using tags: table/thead/tbody/tr/td + dataTable
- +
@@ -274,4 +271,4 @@ Example 3 : Standard table
- + \ No newline at end of file diff --git a/htdocs/public/test/test_forms.php b/htdocs/public/test/test_forms.php new file mode 100644 index 00000000000..126c9723fa7 --- /dev/null +++ b/htdocs/public/test/test_forms.php @@ -0,0 +1,71 @@ +global->MAIN_FEATURES_LEVEL)) +{ + print "Page available onto dev environment only"; + exit; +} +?> + + + + + + + + +Test page + + + + + + + + + + + + + + + + +
+
+This page is a sample of page using html methods.
+
+ + +select_date using tzuser date +print "Test 1: We must have here current hour for user (must match hour on browser). Note: Check your are logged so user TZ and DST are known."; +$offsettz=(empty($_SESSION['dol_tz'])?0:$_SESSION['dol_tz'])*60*60; +$offsetdst=(empty($_SESSION['dol_dst'])?0:$_SESSION['dol_dst'])*60*60; +print " (dol_tz=".$offsettz." dol_dst=".$dol_dst.")
\n"; +$form->select_date('', 'test1', 1, 1, 0); + +print '

'."\n"; + +// Test2: form->select_date using tzuser date +print "Test 2: We must have here 1970-01-01 00:00:00 selected (fields can be empty)
\n"; +$form->select_date(dol_get_first_day(1970,1,false), 'test2', 1, 1, 1); + +print '

'."\n"; + +// Test3: form->select_date for 1970-01-01 00:00:00 +print "Test 3: We must have here 1970-01-01 00:00:00 selected (fields are mandatory)
\n"; +$form->select_date(dol_get_first_day(1970,1,false), 'test3', 1, 1, 0); + +?> + +
+ + \ No newline at end of file
snake