diff --git a/dev/skeletons/build_class_from_table.php b/dev/skeletons/build_class_from_table.php index ff045901041..95be3cfaf43 100644 --- a/dev/skeletons/build_class_from_table.php +++ b/dev/skeletons/build_class_from_table.php @@ -301,9 +301,7 @@ foreach($property as $key => $prop) if ($prop['field'] != 'rowid') { $varprop.="\t\t\$sql.= \" "; - if ($prop['istime']) $varprop.="\".\$this->db->pdate('"; $varprop.="t.".$prop['field']; - if ($prop['istime']) $varprop.="').\" as ".$prop['field']; if ($i < sizeof($property)) $varprop.=","; $varprop.="\";"; $varprop.="\n"; @@ -322,7 +320,9 @@ foreach($property as $key => $prop) if ($prop['field'] != 'rowid') { $varprop.="\t\t\t\t\$this->".$prop['field']." = "; - $varprop.="\$obj->".$prop['field']; + if ($prop['istime']) $varprop.='$this->db->jdate('; + $varprop.='$obj->'.$prop['field']; + if ($prop['istime']) $varprop.=')'; $varprop.=";"; $varprop.="\n"; } diff --git a/htdocs/actioncomm.class.php b/htdocs/actioncomm.class.php index ad90d11884b..d7c493b613a 100644 --- a/htdocs/actioncomm.class.php +++ b/htdocs/actioncomm.class.php @@ -210,11 +210,12 @@ class ActionComm global $langs; $sql = "SELECT a.id,"; - $sql.= " ".$this->db->pdate("a.datea")." as datea,"; - $sql.= " ".$this->db->pdate("a.datea2")." as datea2,"; - $sql.= " ".$this->db->pdate("a.datep")." as datep,"; - $sql.= " ".$this->db->pdate("a.datep2")." as datep2,"; - $sql.= " ".$this->db->pdate("a.datec")." as datec, tms as datem,"; + $sql.= " datep,"; + $sql.= " datep2,"; + //$sql.= " datea,"; + //$sql.= " datea2,"; + $sql.= " datec,"; + $sql.= " tms as datem,"; $sql.= " a.note, a.label, a.fk_action as type_id,"; $sql.= " a.fk_soc,"; $sql.= " a.fk_user_author, a.fk_user_mod,"; @@ -243,13 +244,14 @@ class ActionComm $this->type = $type_libelle; $this->label = $obj->label; - $this->datep = $obj->datep; - $this->datef = $obj->datep2; - $this->date = $obj->datea; - $this->dateend = $obj->datea2; - - $this->datec = $obj->datec; - $this->datem = $obj->datem; + $this->datep = $this->db->jdate($obj->datep); + $this->datef = $this->db->jdate($obj->datep2); + //$this->date = $this->db->jdate($obj->datea); + //$this->dateend = $this->db->jdate($obj->datea2); + + $this->datec = $this->db->jdate($obj->datec); + $this->datem = $this->db->jdate($obj->datem); + $this->note =$obj->note; $this->percentage =$obj->percentage; @@ -349,8 +351,8 @@ class ActionComm $sql.= ", label = ".($this->label ? "'".addslashes($this->label)."'":"null"); $sql.= ", datep = ".(strval($this->datep)!='' ? "'".$this->db->idate($this->datep)."'" : 'null'); $sql.= ", datep2 = ".(strval($this->datef)!='' ? "'".$this->db->idate($this->datef)."'" : 'null'); - $sql.= ", datea = ".(strval($this->date)!='' ? "'".$this->db->idate($this->date)."'" : 'null'); - $sql.= ", datea2 = ".(strval($this->dateend)!='' ? "'".$this->db->idate($this->dateend)."'" : 'null'); + //$sql.= ", datea = ".(strval($this->date)!='' ? "'".$this->db->idate($this->date)."'" : 'null'); + //$sql.= ", datea2 = ".(strval($this->dateend)!='' ? "'".$this->db->idate($this->dateend)."'" : 'null'); $sql.= ", note = ".($this->note ? "'".addslashes($this->note)."'":"null"); $sql.= ", fk_soc =". ($this->societe->id > 0 ? "'".$this->societe->id."'":"null"); $sql.= ", fk_contact =". ($this->contact->id > 0 ? "'".$this->contact->id."'":"null"); @@ -385,7 +387,7 @@ class ActionComm global $conf, $user; $this->nbtodo=$this->nbtodolate=0; - $sql = "SELECT a.id,".$this->db->pdate("a.datep")." as dp"; + $sql = "SELECT a.id, a.datep as dp"; if (!$user->rights->societe->client->voir && !$user->societe_id) $sql .= ", sc.fk_soc, sc.fk_user"; $sql.= " FROM ".MAIN_DB_PREFIX."actioncomm as a"; if (!$user->rights->societe->client->voir && !$user->societe_id) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; @@ -398,7 +400,7 @@ class ActionComm while ($obj=$this->db->fetch_object($resql)) { $this->nbtodo++; - if ($obj->dp < (time() - $conf->actions->warning_delay)) $this->nbtodolate++; + if ($this->db->jdate($obj->dp) < (time() - $conf->actions->warning_delay)) $this->nbtodolate++; } return 1; } @@ -416,8 +418,10 @@ class ActionComm */ function info($id) { - $sql = 'SELECT a.id, '.$this->db->pdate('a.datec').' as datec,'; - $sql.= ' '.$this->db->pdate('tms').' as datem,'; + $sql = 'SELECT '; + $sql.= ' a.id,'; + $sql.= ' datec,'; + $sql.= ' tms as datem,'; $sql.= ' fk_user_author,'; $sql.= ' fk_user_mod'; $sql.= ' FROM '.MAIN_DB_PREFIX.'actioncomm as a'; @@ -444,8 +448,8 @@ class ActionComm $this->user_modification = $muser; } - $this->date_creation = $obj->datec; - $this->date_modification = $obj->datem; + $this->date_creation = $this->db->jdate($obj->datec); + $this->date_modification = $this->db->jdate($obj->datem); } $this->db->free($result); } @@ -668,9 +672,9 @@ class ActionComm //$datestart=$obj->datea?$obj->datea:$obj->datep; //$dateend=$obj->datea2?$obj->datea2:$obj->datep2; //$duration=$obj->durationa?$obj->durationa:$obj->durationp; - $datestart=dolibarr_stringtotime($obj->datep); + $datestart=$this->db->jdate($obj->datep); //print $datestart.'x'; exit; - $dateend=dolibarr_stringtotime($obj->datep2); + $dateend=$this->db->jdate($obj->datep2); $duration=$obj->durationp; $event['summary']=$langs->convToOutputCharset($obj->label); $event['desc']=$langs->convToOutputCharset($obj->note); diff --git a/htdocs/comm/action/fiche.php b/htdocs/comm/action/fiche.php index 6b136442faa..14824fac536 100644 --- a/htdocs/comm/action/fiche.php +++ b/htdocs/comm/action/fiche.php @@ -77,15 +77,15 @@ if ($_POST["action"] == 'add_action') exit; } - // Nettoyage parametres + // Clean parameters if ($_POST["aphour"] == -1) $_POST["aphour"]='0'; if ($_POST["apmin"] == -1) $_POST["apmin"]='0'; if ($_POST["p2hour"] == -1) $_POST["p2hour"]='0'; if ($_POST["p2min"] == -1) $_POST["p2min"]='0'; - if ($_POST["adhour"] == -1) $_POST["adhour"]='0'; - if ($_POST["admin"] == -1) $_POST["admin"]='0'; - if ($_POST["a2hour"] == -1) $_POST["a2hour"]='0'; - if ($_POST["a2min"] == -1) $_POST["a2min"]='0'; + //if ($_POST["adhour"] == -1) $_POST["adhour"]='0'; + //if ($_POST["admin"] == -1) $_POST["admin"]='0'; + //if ($_POST["a2hour"] == -1) $_POST["a2hour"]='0'; + //if ($_POST["a2min"] == -1) $_POST["a2min"]='0'; $datep=dolibarr_mktime($_POST["aphour"], $_POST["apmin"], 0, @@ -98,7 +98,7 @@ if ($_POST["action"] == 'add_action') $_POST["p2month"], $_POST["p2day"], $_POST["p2year"]); - $datea=dolibarr_mktime($_POST["adhour"], // deprecated + /*$datea=dolibarr_mktime($_POST["adhour"], // deprecated $_POST["admin"], 0, $_POST["admonth"], @@ -110,7 +110,8 @@ if ($_POST["action"] == 'add_action') $_POST["a2month"], $_POST["a2day"], $_POST["a2year"]); - + */ + if (! $datep2 && $_POST["percentage"] == 100) { $error=1; @@ -296,10 +297,13 @@ if ($_POST["action"] == 'update') { if (! $_POST["cancel"]) { + // Clean parameters if ($_POST["aphour"] == -1) $_POST["aphour"]='0'; if ($_POST["apmin"] == -1) $_POST["apmin"]='0'; - if ($_POST["adhour"] == -1) $_POST["adhour"]='0'; - if ($_POST["admin"] == -1) $_POST["admin"]='0'; + if ($_POST["p2hour"] == -1) $_POST["p2hour"]='0'; + if ($_POST["p2min"] == -1) $_POST["p2min"]='0'; + //if ($_POST["adhour"] == -1) $_POST["adhour"]='0'; + //if ($_POST["admin"] == -1) $_POST["admin"]='0'; $actioncomm = new Actioncomm($db); $actioncomm->fetch($_POST["id"]); @@ -317,7 +321,7 @@ if ($_POST["action"] == 'update') $_POST["p2month"], $_POST["p2day"], $_POST["p2year"]); - $datea=dolibarr_mktime($_POST["adhour"], + /*$datea=dolibarr_mktime($_POST["adhour"], $_POST["admin"], 0, $_POST["admonth"], @@ -329,15 +333,16 @@ if ($_POST["action"] == 'update') $_POST["a2month"], $_POST["a2day"], $_POST["a2year"]); - + */ + //print $_POST["apmonth"].",".$_POST["apday"].",".$_POST["apyear"].",".$_POST["aphour"].",".$_POST["apmin"]."
\n"; //print $actioncomm->datep; //print 'dddd'.$datep; $actioncomm->label = $_POST["label"]; $actioncomm->datep = $datep; $actioncomm->datef = $datep2; - $actioncomm->date = $datea; - $actioncomm->dateend = $datea2; + //$actioncomm->date = $datea; + //$actioncomm->dateend = $datea2; $actioncomm->percentage = $_POST["percentage"]; $actioncomm->priority = $_POST["priority"]; $actioncomm->location = isset($_POST["location"])?$_POST["location"]:''; @@ -368,7 +373,13 @@ if ($_POST["action"] == 'update') if (! $error) { $db->begin(); - + //print $_POST["aphour"].','.$_POST["apmin"].',0,'.$_POST["apmonth"].','.$_POST["apday"].','.$_POST["apyear"]; + //print $actioncomm->datep; + //print gmmktime($_POST["aphour"],$_POST["apmin"],0,$_POST["apmonth"],$_POST["apday"],$_POST["apyear"]); + //print $actioncomm->datep; // This is a GMT time + //print '-'.$db->idate($actioncomm->datep); + //print '-'.$db->jdate('19700101020000'); + //print '-'.$db->gm($actioncomm->datep); $result=$actioncomm->update($user); if ($result > 0) diff --git a/htdocs/lib/databases/mssql.lib.php b/htdocs/lib/databases/mssql.lib.php index e4e35ab9d13..5bd9afd69c9 100644 --- a/htdocs/lib/databases/mssql.lib.php +++ b/htdocs/lib/databases/mssql.lib.php @@ -545,12 +545,37 @@ class DoliDb } /** - * \brief Convert a GM string date into a GM Timestamps date - * \param string Date in a string (YYYYMMDD, YYYYMMDDHHMMSS, YYYY-MM-DD HH:MM:SS) - * \return date Date - * \example 19700101020000 -> 7200 + * \brief Convert (by PHP) a PHP server TZ string date into a GM Timestamps date + * \param string Date in a string (YYYYMMDDHHMMSS, YYYYMMDD, YYYY-MM-DD HH:MM:SS) + * \return date Date TMS + * \example 19700101020000 -> 3600 with TZ+1 */ function jdate($string) + { + $string=eregi_replace('[^0-9]','',$string); + $tmp=$string.'000000'; + $date=dolibarr_mktime(substr($tmp,8,2),substr($tmp,10,2),substr($tmp,12,2),substr($tmp,4,2),substr($tmp,6,2),substr($tmp,0,4)); + return $date; + } + + /** + * \brief Convert (by PHP) a GM Timestamp date into a GM string date to insert into a date field. + * Function to use to build INSERT, UPDATE or WHERE predica + * \param param Date TMS to convert + * \return string Date in a string YYYYMMDDHHMMSS + */ + function gmtosdate($param) + { + return adodb_strftime("%Y%m%d%H%M%S",$param,true); + } + + /** + * \brief Convert (by PHP) a GM string date into a GM Timestamps date + * \param string Date in a string (YYYYMMDDHHMMSS, YYYYMMDD, YYYY-MM-DD HH:MM:SS) + * \return date Date TMS + * \example 19700101020000 -> 7200 + */ + function gmtotdate($string) { $string=eregi_replace('[^0-9]','',$string); $tmp=$string.'000000'; diff --git a/htdocs/lib/databases/mysql.lib.php b/htdocs/lib/databases/mysql.lib.php index 05f2e2f0931..e3ae50d58f1 100644 --- a/htdocs/lib/databases/mysql.lib.php +++ b/htdocs/lib/databases/mysql.lib.php @@ -503,9 +503,9 @@ class DoliDb /** - \brief Escape a string to insert data. - \param stringtoencode String to escape - \return string String escaped + * \brief Escape a string to insert data. + * \param stringtoencode String to escape + * \return string String escaped */ function escape($stringtoencode) { @@ -526,24 +526,38 @@ class DoliDb return "unix_timestamp(".$param.")"; } + /** + * \brief Convert (by PHP) a PHP server TZ string date into a GM Timestamps date + * \param string Date in a string (YYYYMMDDHHMMSS, YYYYMMDD, YYYY-MM-DD HH:MM:SS) + * \return date Date TMS + * \example 19700101020000 -> 3600 with TZ+1 + */ + function jdate($string) + { + $string=eregi_replace('[^0-9]','',$string); + $tmp=$string.'000000'; + $date=dolibarr_mktime(substr($tmp,8,2),substr($tmp,10,2),substr($tmp,12,2),substr($tmp,4,2),substr($tmp,6,2),substr($tmp,0,4)); + return $date; + } + /** * \brief Convert (by PHP) a GM Timestamp date into a GM string date to insert into a date field. * Function to use to build INSERT, UPDATE or WHERE predica * \param param Date TMS to convert * \return string Date in a string YYYYMMDDHHMMSS */ - function idate($param) + function gmtosdate($param) { - return adodb_strftime("%Y%m%d%H%M%S",$param); + return adodb_strftime("%Y%m%d%H%M%S",$param,true); } - + /** * \brief Convert (by PHP) a GM string date into a GM Timestamps date * \param string Date in a string (YYYYMMDDHHMMSS, YYYYMMDD, YYYY-MM-DD HH:MM:SS) * \return date Date TMS * \example 19700101020000 -> 7200 */ - function jdate($string) + function gmtotdate($string) { $string=eregi_replace('[^0-9]','',$string); $tmp=$string.'000000'; diff --git a/htdocs/lib/databases/mysqli.lib.php b/htdocs/lib/databases/mysqli.lib.php index ca42edd6ca2..c08c6105e67 100644 --- a/htdocs/lib/databases/mysqli.lib.php +++ b/htdocs/lib/databases/mysqli.lib.php @@ -517,9 +517,9 @@ class DoliDb /** - \brief Escape a string to insert data. - \param stringtoencode String to escape - \return string String escaped + * \brief Escape a string to insert data. + * \param stringtoencode String to escape + * \return string String escaped */ function escape($stringtoencode) { @@ -541,7 +541,7 @@ class DoliDb } /** - * \brief Convert (by PHP) a GM Timestamp date into a GM string date to insert into a date field. + * \brief Convert (by PHP) a GM Timestamp date into a PHP server TZ to insert into a date field. * Function to use to build INSERT, UPDATE or WHERE predica * \param param Date TMS to convert * \return string Date in a string YYYYMMDDHHMMSS @@ -551,13 +551,38 @@ class DoliDb return adodb_strftime("%Y%m%d%H%M%S",$param); } + /** + * \brief Convert (by PHP) a PHP server TZ string date into a GM Timestamps date + * \param string Date in a string (YYYYMMDDHHMMSS, YYYYMMDD, YYYY-MM-DD HH:MM:SS) + * \return date Date TMS + * \example 19700101020000 -> 3600 with TZ+1 + */ + function jdate($string) + { + $string=eregi_replace('[^0-9]','',$string); + $tmp=$string.'000000'; + $date=dolibarr_mktime(substr($tmp,8,2),substr($tmp,10,2),substr($tmp,12,2),substr($tmp,4,2),substr($tmp,6,2),substr($tmp,0,4)); + return $date; + } + + /** + * \brief Convert (by PHP) a GM Timestamp date into a GM string date to insert into a date field. + * Function to use to build INSERT, UPDATE or WHERE predica + * \param param Date TMS to convert + * \return string Date in a string YYYYMMDDHHMMSS + */ + function gmtosdate($param) + { + return adodb_strftime("%Y%m%d%H%M%S",$param,true); + } + /** * \brief Convert (by PHP) a GM string date into a GM Timestamps date * \param string Date in a string (YYYYMMDDHHMMSS, YYYYMMDD, YYYY-MM-DD HH:MM:SS) * \return date Date TMS * \example 19700101020000 -> 7200 */ - function jdate($string) + function gmtotdate($string) { $string=eregi_replace('[^0-9]','',$string); $tmp=$string.'000000'; diff --git a/htdocs/lib/databases/pgsql.lib.php b/htdocs/lib/databases/pgsql.lib.php index f21b1283982..d91dce603d9 100644 --- a/htdocs/lib/databases/pgsql.lib.php +++ b/htdocs/lib/databases/pgsql.lib.php @@ -669,20 +669,45 @@ class DoliDb return adodb_strftime("%Y%m%d%H%M%S",$param); } + /** + * \brief Convert (by PHP) a PHP server TZ string date into a GM Timestamps date + * \param string Date in a string (YYYYMMDDHHMMSS, YYYYMMDD, YYYY-MM-DD HH:MM:SS) + * \return date Date TMS + * \example 19700101020000 -> 3600 with TZ+1 + */ + function jdate($string) + { + $string=eregi_replace('[^0-9]','',$string); + $tmp=$string.'000000'; + $date=dolibarr_mktime(substr($tmp,8,2),substr($tmp,10,2),substr($tmp,12,2),substr($tmp,4,2),substr($tmp,6,2),substr($tmp,0,4)); + return $date; + } + + /** + * \brief Convert (by PHP) a GM Timestamp date into a GM string date to insert into a date field. + * Function to use to build INSERT, UPDATE or WHERE predica + * \param param Date TMS to convert + * \return string Date in a string YYYYMMDDHHMMSS + */ + function gmtosdate($param) + { + return adodb_strftime("%Y%m%d%H%M%S",$param,true); + } + /** * \brief Convert (by PHP) a GM string date into a GM Timestamps date * \param string Date in a string (YYYYMMDDHHMMSS, YYYYMMDD, YYYY-MM-DD HH:MM:SS) * \return date Date TMS * \example 19700101020000 -> 7200 */ - function jdate($string) + function gmtotdate($string) { $string=eregi_replace('[^0-9]','',$string); $tmp=$string.'000000'; $date=dolibarr_mktime(substr($tmp,8,2),substr($tmp,10,2),substr($tmp,12,2),substr($tmp,4,2),substr($tmp,6,2),substr($tmp,0,4),1); return $date; } - + /** * \brief Formatage d'un if SQL * \param test chaine test diff --git a/htdocs/lib/functions.lib.php b/htdocs/lib/functions.lib.php index 566f8686ca4..9651153d03a 100644 --- a/htdocs/lib/functions.lib.php +++ b/htdocs/lib/functions.lib.php @@ -593,8 +593,8 @@ function dolibarr_getdate($timestamp,$fast=false) } /** - * Retourne une date fabriquee depuis infos. - * Remplace la fonction mktime non implementee sous Windows si annee < 1970 + * Return a GMT date built from detailed informations + * Replace function mktime not available under Windows if year < 1970 * PHP mktime is restricted to the years 1901-2038 on Unix and 1970-2038 on Windows * @param hour Hour (can be -1 for undefined) * @param minute Minute (can be -1 for undefined) @@ -602,8 +602,8 @@ function dolibarr_getdate($timestamp,$fast=false) * @param month Month * @param day Day * @param year Year - * @param gm Time gm - * @param check No check on parameters (Can use day 32, etc...) + * @param gm 1=Input informations are GMT values, otherwise local to user + * @param check 0=No check on parameters (Can use day 32, etc...) * @return timestamp Date en timestamp, '' if error */ function dolibarr_mktime($hour,$minute,$second,$month,$day,$year,$gm=0,$check=1)