New: Function dol_now('tzuser') is now supported.

This commit is contained in:
Laurent Destailleur 2010-12-08 13:13:17 +00:00
parent 0d4aa481cd
commit 6846333ec8
15 changed files with 74 additions and 44 deletions

View File

@ -178,7 +178,7 @@ if (function_exists('date_default_timezone_get'))
$var=!$var; $var=!$var;
print "<tr ".$bc[$var]."><td width=\"300\">=> ".$langs->trans("PHPServerOffsetWithGreenwich")."</td><td>".(-dol_mktime(0,0,0,1,1,1970)>0?'+':'').(-dol_mktime(0,0,0,1,1,1970))."</td></tr>\n"; print "<tr ".$bc[$var]."><td width=\"300\">=> ".$langs->trans("PHPServerOffsetWithGreenwich")."</td><td>".(-dol_mktime(0,0,0,1,1,1970)>0?'+':'').(-dol_mktime(0,0,0,1,1,1970))."</td></tr>\n";
$var=!$var; $var=!$var;
print "<tr ".$bc[$var]."><td width=\"300\">=> ".$langs->trans("CurrentHour")."</td><td>".dol_print_date(dol_now('tzserver'),'dayhour')."</td></tr>\n"; print "<tr ".$bc[$var]."><td width=\"300\">=> ".$langs->trans("CurrentHour")."</td><td>".dol_print_date(dol_now(),'dayhour','tzserver')."</td></tr>\n";
$var=!$var; $var=!$var;
print "<tr ".$bc[$var].'><td width="300">=> dol_print_date(0,"dayhourtext")</td><td>'.dol_print_date(0,"dayhourtext")."</td>"; print "<tr ".$bc[$var].'><td width="300">=> dol_print_date(0,"dayhourtext")</td><td>'.dol_print_date(0,"dayhourtext")."</td>";
$var=!$var; $var=!$var;
@ -197,7 +197,7 @@ print "<tr ".$bc[$var]."><td width=\"300\">".$langs->trans("ClientTZ")."</td><td
$var=!$var; $var=!$var;
print "<tr ".$bc[$var]."><td width=\"300\">=> ".$langs->trans("ClientOffsetWithGreenwich")."</td><td>".($_SESSION['dol_tz']>=0?'+':'').($_SESSION['dol_tz']*60*60)."</td></tr>\n"; print "<tr ".$bc[$var]."><td width=\"300\">=> ".$langs->trans("ClientOffsetWithGreenwich")."</td><td>".($_SESSION['dol_tz']>=0?'+':'').($_SESSION['dol_tz']*60*60)."</td></tr>\n";
$var=!$var; $var=!$var;
print "<tr ".$bc[$var]."><td width=\"300\">=> ".$langs->trans("ClientHour")."</td><td>".dol_print_date(dol_now('tzuser'),'dayhour')."</td></tr>\n"; print "<tr ".$bc[$var]."><td width=\"300\">=> ".$langs->trans("ClientHour")."</td><td>".dol_print_date(dol_now(),'dayhour','tzuser')."</td></tr>\n";
#print "<tr ".$bc[$var]."><td width=\"300\">=> ".$langs->trans("ClientHour")."</td><td>".$langs->trans("FeatureNotYetAvailable")."</td></tr>\n"; #print "<tr ".$bc[$var]."><td width=\"300\">=> ".$langs->trans("ClientHour")."</td><td>".$langs->trans("FeatureNotYetAvailable")."</td></tr>\n";
$var=!$var; $var=!$var;

View File

@ -42,7 +42,7 @@ switch ( $_GET['action'] )
$company->fetch($conf->global->CASHDESK_ID_THIRDPARTY); $company->fetch($conf->global->CASHDESK_ID_THIRDPARTY);
$invoice=new Facture($db); $invoice=new Facture($db);
$invoice->date=dol_now('tzserver'); $invoice->date=dol_now();
$invoice->type=0; $invoice->type=0;
$num=$invoice->getNextNumRef($company); $num=$invoice->getNextNumRef($company);
@ -82,7 +82,7 @@ switch ( $_GET['action'] )
case 'valide_facture': case 'valide_facture':
$now=dol_now('tzserver'); $now=dol_now();
// Recuperation de la date et de l'heure // Recuperation de la date et de l'heure
$date = dol_print_date($now,'day'); $date = dol_print_date($now,'day');

View File

@ -110,7 +110,7 @@ class ActionComm extends CommonObject
{ {
global $langs,$conf; global $langs,$conf;
$now=dol_now('tzserver'); $now=dol_now();
// Clean parameters // Clean parameters
$this->label=dol_trunc(trim($this->label),128); $this->label=dol_trunc(trim($this->label),128);
@ -642,7 +642,7 @@ class ActionComm extends CommonObject
if ($cachedelay) if ($cachedelay)
{ {
$nowgmt = dol_now('gmt'); $nowgmt = dol_now();
if (filemtime($outputfile) > ($nowgmt - $cachedelay)) if (filemtime($outputfile) > ($nowgmt - $cachedelay))
{ {
dol_syslog("ActionComm::build_exportfile file ".$outputfile." is not older than now - cachedelay (".$nowgmt." - ".$cachedelay."). Build is canceled"); dol_syslog("ActionComm::build_exportfile file ".$outputfile." is not older than now - cachedelay (".$nowgmt." - ".$cachedelay."). Build is canceled");

View File

@ -568,7 +568,7 @@ class Propal extends CommonObject
global $langs,$conf,$mysoc; global $langs,$conf,$mysoc;
$error=0; $error=0;
$now=dol_now('gmt'); $now=dol_now();
// Clean parameters // Clean parameters
$this->fin_validite = $this->datep + ($this->duree_validite * 24 * 3600); $this->fin_validite = $this->datep + ($this->duree_validite * 24 * 3600);
@ -794,7 +794,7 @@ class Propal extends CommonObject
$error=0; $error=0;
$now=dol_now('gmt'); $now=dol_now();
$object=new Propal($this->db); $object=new Propal($this->db);

View File

@ -472,7 +472,7 @@ if ($account || $_GET["ref"])
$result = $db->query($sql); $result = $db->query($sql);
if ($result) if ($result)
{ {
$now=dol_now('tzserver'); $now=dol_now();
$nows=dol_date('Ymd',$now); $nows=dol_date('Ymd',$now);
//$html->load_cache_types_paiements(); //$html->load_cache_types_paiements();

View File

@ -152,7 +152,7 @@ class DiscountAbsolute
$sql.= " amount_ht, amount_tva, amount_ttc, tva_tx,"; $sql.= " amount_ht, amount_tva, amount_ttc, tva_tx,";
$sql.= " fk_facture_source"; $sql.= " fk_facture_source";
$sql.= ")"; $sql.= ")";
$sql.= " VALUES (".$this->db->idate($this->datec!=''?$this->datec:dol_now('tzserver')).", ".$this->fk_soc.", ".$user->id.", '".addslashes($this->description)."',"; $sql.= " VALUES (".$this->db->idate($this->datec!=''?$this->datec:dol_now()).", ".$this->fk_soc.", ".$user->id.", '".addslashes($this->description)."',";
$sql.= " ".$this->amount_ht.", ".$this->amount_tva.", ".$this->amount_ttc.", ".$this->tva_tx.","; $sql.= " ".$this->amount_ht.", ".$this->amount_tva.", ".$this->amount_ttc.", ".$this->tva_tx.",";
$sql.= " ".($this->fk_facture_source?"'".$this->fk_facture_source."'":"null"); $sql.= " ".($this->fk_facture_source?"'".$this->fk_facture_source."'":"null");
$sql.= ")"; $sql.= ")";

View File

@ -1291,7 +1291,7 @@ if ($step == 5 && $datatoimport)
$nboferrors=0; $nboferrors=0;
$nbofwarnings=0; $nbofwarnings=0;
$importid=dol_print_date(dol_now('tzserver'),'%Y%m%d%H%M%S'); $importid=dol_print_date(dol_now(),'%Y%m%d%H%M%S');
//var_dump($array_match_file_to_database); //var_dump($array_match_file_to_database);
@ -1379,7 +1379,7 @@ if ($step == 5 && $datatoimport)
} }
// Show import id // Show import id
$importid=dol_print_date(dol_now('tzserver'),'%Y%m%d%H%M%S'); $importid=dol_print_date(dol_now(),'%Y%m%d%H%M%S');
print '<center>'; print '<center>';
print $langs->trans("NowClickToRunTheImport",$langs->transnoentitiesnoconv("RunImportFile")).'<br>'; print $langs->trans("NowClickToRunTheImport",$langs->transnoentitiesnoconv("RunImportFile")).'<br>';
@ -1614,7 +1614,7 @@ if ($step == 6 && $datatoimport)
$nboferrors=0; $nboferrors=0;
$nbofwarnings=0; $nbofwarnings=0;
$importid=dol_print_date(dol_now('tzserver'),'%Y%m%d%H%M%S'); $importid=dol_print_date(dol_now(),'%Y%m%d%H%M%S');
//var_dump($array_match_file_to_database); //var_dump($array_match_file_to_database);

View File

@ -310,7 +310,7 @@ class doc_generic_invoice_odt extends ModelePDFFactures
//print "srctemplatepath=".$srctemplatepath; // Src filename //print "srctemplatepath=".$srctemplatepath; // Src filename
$newfile=basename($srctemplatepath); $newfile=basename($srctemplatepath);
$newfiletmp=preg_replace('/\.odt/i','',$newfile); $newfiletmp=preg_replace('/\.odt/i','',$newfile);
$file=$dir.'/'.$newfiletmp.'.'.dol_print_date(dol_now('tzserver'),'%Y%m%d%H%M%S').'.odt'; $file=$dir.'/'.$newfiletmp.'.'.dol_print_date(dol_now(),'%Y%m%d%H%M%S').'.odt';
//print "newdir=".$dir; //print "newdir=".$dir;
//print "newfile=".$newfile; //print "newfile=".$newfile;
//print "file=".$file; //print "file=".$file;

View File

@ -94,7 +94,7 @@ class mailing_dolibarr_services_expired extends MailingTargets
$product=$this->arrayofproducts[$key]; $product=$this->arrayofproducts[$key];
} }
$now=dol_now('gmt'); $now=dol_now();
// La requete doit retourner: id, email, name // La requete doit retourner: id, email, name
$sql = " select s.rowid, s.email, s.nom as name, cd.rowid as cdid, cd.date_ouverture, cd.date_fin_validite, cd.fk_contrat"; $sql = " select s.rowid, s.email, s.nom as name, cd.rowid as cdid, cd.date_ouverture, cd.date_fin_validite, cd.fk_contrat";
@ -173,7 +173,7 @@ class mailing_dolibarr_services_expired extends MailingTargets
*/ */
function getNbOfRecipients($filter=1,$option='') function getNbOfRecipients($filter=1,$option='')
{ {
$now=dol_now('gmt'); $now=dol_now();
// Example: return parent::getNbOfRecipients("SELECT count(*) as nb from dolibarr_table"); // Example: return parent::getNbOfRecipients("SELECT count(*) as nb from dolibarr_table");
// Example: return 500; // Example: return 500;

View File

@ -300,7 +300,7 @@ class doc_generic_odt extends ModeleThirdPartyDoc
//print "srctemplatepath=".$srctemplatepath; // Src filename //print "srctemplatepath=".$srctemplatepath; // Src filename
$newfile=basename($srctemplatepath); $newfile=basename($srctemplatepath);
$newfiletmp=preg_replace('/\.odt/i','',$newfile); $newfiletmp=preg_replace('/\.odt/i','',$newfile);
$file=$dir.'/'.$newfiletmp.'.'.dol_print_date(dol_now('tzserver'),'%Y%m%d%H%M%S').'.odt'; $file=$dir.'/'.$newfiletmp.'.'.dol_print_date(dol_now(),'%Y%m%d%H%M%S').'.odt';
//print "newdir=".$dir; //print "newdir=".$dir;
//print "newfile=".$newfile; //print "newfile=".$newfile;
//print "file=".$file; //print "file=".$file;

View File

@ -544,7 +544,7 @@ class InterfaceActionsAuto
// Add entry in event table // Add entry in event table
if ($ok) if ($ok)
{ {
$now=dol_now('tzserver'); $now=dol_now();
// Insertion action // Insertion action
require_once(DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'); require_once(DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php');

View File

@ -522,7 +522,7 @@ function write_conf_file($conffile)
fputs($fp, '<?php'); fputs($fp, '<?php');
fputs($fp,"\n"); fputs($fp,"\n");
fputs($fp,"#\n"); fputs($fp,"#\n");
fputs($fp,"# File generated by Dolibarr installer ".DOL_VERSION." on ".dol_print_date(dol_now('tzserver'),'')); fputs($fp,"# File generated by Dolibarr installer ".DOL_VERSION." on ".dol_print_date(dol_now(),''));
fputs($fp,"\n"); fputs($fp,"\n");
fputs($fp,"#\n"); fputs($fp,"#\n");
fputs($fp,"# Take a look at conf.php.example file for an example of conf.php file\n"); fputs($fp,"# Take a look at conf.php.example file for an example of conf.php file\n");

View File

@ -97,30 +97,32 @@ function dol_size($size,$type='')
/** /**
* \brief Return date for now * Return date for now. We should always use this function without parameters (that means GMT time).
* \param mode 'gmt' => we return GMT timestamp, * @param mode 'gmt' => we return GMT timestamp,
* 'tzserver' => we use the PHP server timezone * 'tzserver' => we add the PHP server timezone
* 'tzref' => we use the company timezone * 'tzref' => we add the company timezone
* 'tzuser' => we use the user timezone * 'tzuser' => we add the user timezone
* \return date Timestamp * @return date Timestamp
*/ */
function dol_now($mode='tzserver') function dol_now($mode='gmt')
{ {
// Note that gmmktime and mktime return same value (GMT) whithout parameters
if ($mode == 'gmt') $ret=gmmktime(); // Time for now at greenwich. if ($mode == 'gmt') $ret=gmmktime(); // Time for now at greenwich.
else if ($mode == 'tzserver') // Time for now where PHP server is located else if ($mode == 'tzserver') // Time for now with PHP server timezone added
{ {
$ret=mktime(); $tzsecond=-dol_mktime(0,0,0,1,1,1970);
$ret=gmmktime()+$tzsecond;
} }
else if ($mode == 'tzref') // Time for now where the parent company is located else if ($mode == 'tzref') // Time for now where parent company timezone is added
{ {
// TODO Should use the timezone of the company instead of timezone of server // TODO Should add the company timezone
$ret=mktime(); $ret=gmmktime();
} }
else if ($mode == 'tzuser') // Time for now where the user is located else if ($mode == 'tzuser') // Time for now where user timezone is added
{ {
// TODO Should use the timezone of the user instead of timezone of server //print 'eeee'.time().'-'.mktime().'-'.gmmktime();
$tz=isset($_SESSION['dol_tz'])?$_SESSION['dol_tz']:0; $tzhour=isset($_SESSION['dol_tz'])?$_SESSION['dol_tz']:0;
$ret=gmmktime()+($tz*24*60*60); $ret=gmmktime()+($tzhour*60*60);
} }
return $ret; return $ret;
} }
@ -437,21 +439,49 @@ function dolibarr_print_date($time,$format='',$to_gmt=false,$outputlangs='',$enc
/** /**
* Output date in a string format according to outputlangs (or langs if not defined). * Output date in a string format according to outputlangs (or langs if not defined).
* Return charset is always UTF-8, except if encodetoouput is defined. In this cas charset is output charset. * Return charset is always UTF-8, except if encodetoouput is defined. In this cas charset is output charset.
* @param time GM Timestamps date (or 'YYYY-MM-DD' or 'YYYY-MM-DD HH:MM:SS') * @param time GM Timestamps date (or deprecated strings 'YYYY-MM-DD' or 'YYYY-MM-DD HH:MM:SS')
* @param format Output date format * @param format Output date format
* "%d %b %Y", * "%d %b %Y",
* "%d/%m/%Y %H:%M", * "%d/%m/%Y %H:%M",
* "%d/%m/%Y %H:%M:%S", * "%d/%m/%Y %H:%M:%S",
* "day", "daytext", "dayhour", "dayhourldap", "dayhourtext" * "day", "daytext", "dayhour", "dayhourldap", "dayhourtext"
* @param to_gmt false=output string is for local server TZ usage, true=output string is for GMT usage * @param tzoutput true=output string is for Greenwich location
* false or 'tzserver'=output string is for local PHP server TZ usage
* 'tzuser'=output string is for local browser TZ usage
* @param outputlangs Object lang that contains language for text translation. * @param outputlangs Object lang that contains language for text translation.
* @return string Formated date or '' if time is null * @return string Formated date or '' if time is null
* @see dol_mktime, dol_stringtotime * @see dol_mktime, dol_stringtotime
*/ */
function dol_print_date($time,$format='',$to_gmt=false,$outputlangs='',$encodetooutput=false) function dol_print_date($time,$format='',$tzoutput='tzserver',$outputlangs='',$encodetooutput=false)
{ {
global $conf,$langs; global $conf,$langs;
$to_gmt=false;
$offset=0;
if ($tzoutput)
{
$to_gmt=true; // For backward compatibility
$offset=0;
if (is_string($tzoutput))
{
if ($tzoutput == 'tzserver')
{
$to_gmt=false;
$offset=0;
}
if ($tzoutput == 'tzuser')
{
$to_gmt=true;
$offset=(empty($_SESSION['dol_tz'])?0:$_SESSION['dol_tz'])*60*60;
}
if ($tzoutput == 'tzcompany')
{
$to_gmt=false;
$offset=0; // TODO Define this and use it later
}
}
}
if (! is_object($outputlangs)) $outputlangs=$langs; if (! is_object($outputlangs)) $outputlangs=$langs;
// Si format non defini, on prend $conf->format_date_text_short sinon %Y-%m-%d %H:%M:%S // Si format non defini, on prend $conf->format_date_text_short sinon %Y-%m-%d %H:%M:%S
@ -506,14 +536,14 @@ function dol_print_date($time,$format='',$to_gmt=false,$outputlangs='',$encodeto
$ssec = $reg[6]; $ssec = $reg[6];
$time=dol_mktime($shour,$smin,$ssec,$smonth,$sday,$syear,true); $time=dol_mktime($shour,$smin,$ssec,$smonth,$sday,$syear,true);
$ret=adodb_strftime($format,$time,$to_gmt); $ret=adodb_strftime($format,$time+$offset,$to_gmt);
} }
else else
{ {
// Date is a timestamps // Date is a timestamps
if ($time < 100000000000) // Protection against bad date values if ($time < 100000000000) // Protection against bad date values
{ {
$ret=adodb_strftime($format,$time,$to_gmt); $ret=adodb_strftime($format,$time+$offset,$to_gmt);
} }
else $ret='Bad value '.$time.' for date'; else $ret='Bad value '.$time.' for date';
} }
@ -521,7 +551,7 @@ function dol_print_date($time,$format='',$to_gmt=false,$outputlangs='',$encodeto
if (preg_match('/__b__/i',$format)) if (preg_match('/__b__/i',$format))
{ {
// Here ret is string in PHP setup language (strftime was used). Now we convert to $outputlangs. // Here ret is string in PHP setup language (strftime was used). Now we convert to $outputlangs.
$month=adodb_strftime('%m',$time); $month=adodb_strftime('%m',$time+$offset);
if ($encodetooutput) if ($encodetooutput)
{ {
$monthtext=$outputlangs->transnoentities('Month'.$month); $monthtext=$outputlangs->transnoentities('Month'.$month);
@ -540,7 +570,7 @@ function dol_print_date($time,$format='',$to_gmt=false,$outputlangs='',$encodeto
} }
if (preg_match('/__a__/i',$format)) if (preg_match('/__a__/i',$format))
{ {
$w=adodb_strftime('%w',$time); $w=adodb_strftime('%w',$time+$offset);
$dayweek=$outputlangs->transnoentitiesnoconv('Day'.$w); $dayweek=$outputlangs->transnoentitiesnoconv('Day'.$w);
$ret=str_replace('__A__',$dayweek,$ret); $ret=str_replace('__A__',$dayweek,$ret);
$ret=str_replace('__a__',dol_substr($dayweek,0,3),$ret); $ret=str_replace('__a__',dol_substr($dayweek,0,3),$ret);

View File

@ -77,7 +77,7 @@ if ($_POST["action"] == 'add' && $user->rights->projet->creer)
$project->socid = $_POST["socid"]; $project->socid = $_POST["socid"];
$project->description = $_POST["description"]; $project->description = $_POST["description"];
$project->public = $_POST["public"]; $project->public = $_POST["public"];
$project->datec=dol_now('tzserver'); $project->datec=dol_now();
$project->dateo=dol_mktime(12,0,0,$_POST['projectmonth'],$_POST['projectday'],$_POST['projectyear']); $project->dateo=dol_mktime(12,0,0,$_POST['projectmonth'],$_POST['projectday'],$_POST['projectyear']);
$project->datee=dol_mktime(12,0,0,$_POST['projectendmonth'],$_POST['projectendday'],$_POST['projectendyear']); $project->datee=dol_mktime(12,0,0,$_POST['projectendmonth'],$_POST['projectendday'],$_POST['projectendyear']);

View File

@ -84,7 +84,7 @@ if ($_POST["action"] == 'createtask' && $user->rights->projet->creer)
$task->label = $_POST["label"]; $task->label = $_POST["label"];
$task->description = $_POST['description']; $task->description = $_POST['description'];
$task->fk_task_parent = $task_parent; $task->fk_task_parent = $task_parent;
$task->date_c = dol_now('tzserver'); $task->date_c = dol_now();
$task->date_start = dol_mktime(12,0,0,$_POST['dateomonth'],$_POST['dateoday'],$_POST['dateoyear']); $task->date_start = dol_mktime(12,0,0,$_POST['dateomonth'],$_POST['dateoday'],$_POST['dateoyear']);
$task->date_end = dol_mktime(12,0,0,$_POST['dateemonth'],$_POST['dateeday'],$_POST['dateeyear']); $task->date_end = dol_mktime(12,0,0,$_POST['dateemonth'],$_POST['dateeday'],$_POST['dateeyear']);
$task->progress = $_POST['progress']; $task->progress = $_POST['progress'];