forked from Wavyzz/dolibarr
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.
This commit is contained in:
@@ -325,7 +325,7 @@ if ($action == 'create')
|
||||
|
||||
print '<tr><td valign="top">'.$langs->trans("Date").'</td>';
|
||||
print '<td colspan="3">';
|
||||
$form->select_date(time(), 're', 0, 0, 0, 'formsoc');
|
||||
$form->select_date('', 're', 0, 0, 0, 'formsoc');
|
||||
print '</td></tr>';
|
||||
|
||||
print '<tr><td valign="top">'.$langs->trans("BalanceMinimalAllowed").'</td>';
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -303,11 +303,13 @@ if (($action=="create") || ($action=="edit"))
|
||||
|
||||
print "<tr><td>";
|
||||
print $langs->trans('CronHourStart')."</td><td>";
|
||||
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 "</td>";
|
||||
print "<td>";
|
||||
|
||||
@@ -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<br>
|
||||
|
||||
<script type="text/javascript">
|
||||
/*$(document).ready(function(){
|
||||
$('#abc').dataTable();
|
||||
});*/
|
||||
$(document).ready(function(){
|
||||
$('#def').dataTable();
|
||||
$('#idtableexample2').dataTable();
|
||||
});
|
||||
|
||||
/*
|
||||
@@ -179,7 +176,7 @@ $('xxxth').replaceWith(
|
||||
*/
|
||||
</script>
|
||||
|
||||
<table id="def">
|
||||
<table id="idtableexample2">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>snake</th>
|
||||
|
||||
71
htdocs/public/test/test_forms.php
Normal file
71
htdocs/public/test/test_forms.php
Normal file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
define("NOLOGIN",1); // This means this output page does not require to be logged.
|
||||
define("NOCSRFCHECK",1); // We accept to go on this page from external web site.
|
||||
|
||||
require '../../main.inc.php';
|
||||
include_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
|
||||
|
||||
if (empty($conf->global->MAIN_FEATURES_LEVEL))
|
||||
{
|
||||
print "Page available onto dev environment only";
|
||||
exit;
|
||||
}
|
||||
?>
|
||||
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta name="robots" content="noindex,nofollow" />
|
||||
<meta name="author" content="Dolibarr Development Team">
|
||||
<link rel="shortcut icon" type="image/x-icon" href="<?php echo DOL_URL_ROOT ?>/theme/eldy/img/favicon.ico"/>
|
||||
<title>Test page</title>
|
||||
<!-- Includes for JQuery (Ajax library) -->
|
||||
<link rel="stylesheet" type="text/css" href="<?php echo DOL_URL_ROOT ?>/includes/jquery/css/smoothness/jquery-ui-latest.custom.css" />
|
||||
<link rel="stylesheet" type="text/css" href="<?php echo DOL_URL_ROOT ?>/includes/jquery/plugins/datatables/css/jquery.dataTables.css" />
|
||||
<!-- <link rel="stylesheet" type="text/css" href="<?php echo DOL_URL_ROOT ?>/includes/jquery/plugins/mobile/jquery.mobile-latest.min.css" /> -->
|
||||
<!-- <link rel="stylesheet" type="text/css" title="default" href="<?php echo DOL_URL_ROOT ?>/theme/eldy/style.css.php?dol_use_jmobile=1" /> -->
|
||||
<link rel="stylesheet" type="text/css" title="default" href="<?php echo DOL_URL_ROOT ?>/theme/eldy/style.css.php?dol_use_jmobile=0" />
|
||||
<!-- Includes JS for JQuery -->
|
||||
<script type="text/javascript" src="<?php echo DOL_URL_ROOT ?>/includes/jquery/js/jquery-latest.min.js"></script>
|
||||
<script type="text/javascript" src="<?php echo DOL_URL_ROOT ?>/includes/jquery/plugins/tablednd/jquery.tablednd.0.6.min.js"></script>
|
||||
<script type="text/javascript" src="<?php echo DOL_URL_ROOT ?>/includes/jquery/plugins/datatables/js/jquery.dataTables.js"></script>
|
||||
<!-- <script type="text/javascript" src="<?php echo DOL_URL_ROOT ?>/includes/jquery/plugins/mobile/jquery.mobile-latest.min.js"></script> -->
|
||||
</head>
|
||||
|
||||
|
||||
|
||||
<body style="margin: 4px;">
|
||||
<div data-role="page">
|
||||
<br>
|
||||
This page is a sample of page using html methods.<br>
|
||||
<br>
|
||||
|
||||
<!-- Output to test html.form.class.php -->
|
||||
<?php
|
||||
$form=new Form($db);
|
||||
|
||||
// Test1: form->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.")<br>\n";
|
||||
$form->select_date('', 'test1', 1, 1, 0);
|
||||
|
||||
print '<br><br>'."\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)<br>\n";
|
||||
$form->select_date(dol_get_first_day(1970,1,false), 'test2', 1, 1, 1);
|
||||
|
||||
print '<br><br>'."\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)<br>\n";
|
||||
$form->select_date(dol_get_first_day(1970,1,false), 'test3', 1, 1, 0);
|
||||
|
||||
?>
|
||||
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user