Fix: La fonction dolibarr_print_date accepte indifféremment une date au format timestamp tout comme au format YYYY-MM-DD.

This commit is contained in:
Laurent Destailleur 2004-07-17 17:16:42 +00:00
parent 3e9a4232c2
commit c1c365c3c1
3 changed files with 122 additions and 42 deletions

View File

@ -1,6 +1,7 @@
<?PHP <?PHP
/* Copyright (C) 2002-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org> /* Copyright (C) 2002-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be> * Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
* Copyright (C) 2004 Laurent Destailleur <eldy@users.sourceforge.net>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -42,10 +43,10 @@ class Contact
return 1; return 1;
} }
/** /**
* Création du contact * Création du contact
* *
*
*/ */
Function create($user) Function create($user)
{ {
@ -91,7 +92,13 @@ class Contact
$this->phone_pro = $soc->tel; $this->phone_pro = $soc->tel;
} }
$sql = "UPDATE ".MAIN_DB_PREFIX."socpeople SET name='$this->name', firstname='$this->firstname'"; $sql = "UPDATE ".MAIN_DB_PREFIX."socpeople SET ";
$sql .= " civilite='$this->civilite_id'";
$sql .= ", name='$this->name'";
$sql .= ", firstname='$this->firstname'";
$sql .= ", address='$this->address'";
// $sql .= ", cp='$this->cp'";
// $sql .= ", ville='$this->ville'";
$sql .= ", poste='$this->poste'"; $sql .= ", poste='$this->poste'";
$sql .= ", fax='$this->fax'"; $sql .= ", fax='$this->fax'";
$sql .= ", email='$this->email'"; $sql .= ", email='$this->email'";
@ -100,6 +107,9 @@ class Contact
$sql .= ", phone_perso = '$this->phone_perso'"; $sql .= ", phone_perso = '$this->phone_perso'";
$sql .= ", phone_mobile = '$this->phone_mobile'"; $sql .= ", phone_mobile = '$this->phone_mobile'";
$sql .= ", jabberid = '$this->jabberid'"; $sql .= ", jabberid = '$this->jabberid'";
if ($user) {
$sql .= ", fk_user_modif=".$user->id;
}
$sql .= " WHERE idp=$id"; $sql .= " WHERE idp=$id";
$result = $this->db->query($sql); $result = $this->db->query($sql);
@ -247,13 +257,36 @@ class Contact
*/ */
Function update_perso($id, $user=0) Function update_perso($id, $user=0)
{ {
# Mis a jour contact
$sql = "UPDATE ".MAIN_DB_PREFIX."socpeople SET idp=$id ";
$sql = "UPDATE llx_socpeople SET "; if ($this->birthday>0) {
$sql .= " birthday='".$this->birthday."'"; if (eregi('\-',$this->birthday)) {
// Si date = chaine
$sql .= ", birthday='".$this->birthday."'";
}
else {
// Si date = timestamp
$sql .= ", birthday=".$this->db->idate($this->birthday);
}
}
$sql .= " WHERE idp=$id"; $sql .= " WHERE idp=$id";
$result = $this->db->query($sql); $result = $this->db->query($sql);
if (!$result)
{
print $this->db->error() . '<br>' . $sql;
}
# Mis a jour alerte birthday
if ($this->birthday_alert) {
$sql = "INSERT into ".MAIN_DB_PREFIX."user_alert(type,fk_contact,fk_user) ";
$sql.= "values (1,".$id.",".$user->id.")";
} else {
$sql = "DELETE from ".MAIN_DB_PREFIX."user_alert ";
$sql.= "where type=1 AND fk_contact=".$id." AND fk_user=".$user->id;
}
$result = $this->db->query($sql);
if (!$result) if (!$result)
{ {
print $this->db->error() . '<br>' . $sql; print $this->db->error() . '<br>' . $sql;
@ -269,7 +302,7 @@ class Contact
*/ */
Function fetch($id, $user=0) Function fetch($id, $user=0)
{ {
$sql = "SELECT c.idp, c.fk_soc, c.name, c.firstname, c.email, phone, phone_perso, phone_mobile, fax, jabberid, c.birthday, c.note, poste"; $sql = "SELECT c.idp, c.fk_soc, c.civilite civilite_id, c.name, c.firstname, c.address, c.birthday as birthday, poste, phone, phone_perso, phone_mobile, fax, c.email, jabberid, c.note";
$sql .= " FROM ".MAIN_DB_PREFIX."socpeople as c"; $sql .= " FROM ".MAIN_DB_PREFIX."socpeople as c";
$sql .= " WHERE c.idp = $id"; $sql .= " WHERE c.idp = $id";
@ -282,13 +315,18 @@ class Contact
$obj = $this->db->fetch_object($result , 0); $obj = $this->db->fetch_object($result , 0);
$this->id = $obj->idp; $this->id = $obj->idp;
$this->civilite_id = $obj->civilite_id;
$this->name = $obj->name; $this->name = $obj->name;
$this->firstname = $obj->firstname; $this->firstname = $obj->firstname;
$this->nom = $obj->name; $this->nom = $obj->name;
$this->prenom = $obj->firstname; $this->prenom = $obj->firstname;
$this->address = $obj->address;
$this->societeid = $obj->fk_soc; $this->societeid = $obj->fk_soc;
$this->socid = $obj->fk_soc; $this->socid = $obj->fk_soc;
$this->poste = $obj->poste; $this->poste = $obj->poste;
$this->fullname = $this->firstname . ' ' . $this->name; $this->fullname = $this->firstname . ' ' . $this->name;
$this->phone_pro = dolibarr_print_phone($obj->phone); $this->phone_pro = dolibarr_print_phone($obj->phone);
@ -304,13 +342,14 @@ class Contact
$this->birthday = $obj->birthday; $this->birthday = $obj->birthday;
$this->birthday_alert = $obj->birthday_alert; $this->birthday_alert = $obj->birthday_alert;
$this->note = $obj->note; $this->note = $obj->note;
} }
$this->db->free(); $this->db->free();
if ($user) if ($user)
{ {
$sql = "SELECT fk_user"; $sql = "SELECT fk_user";
$sql .= " FROM ".MAIN_DB_PREFIX."birthday_alert"; $sql .= " FROM ".MAIN_DB_PREFIX."user_alert";
$sql .= " WHERE fk_user = $user->id AND fk_contact = $id"; $sql .= " WHERE fk_user = $user->id AND fk_contact = $id";
if ($this->db->query($sql)) if ($this->db->query($sql))
@ -388,7 +427,7 @@ class Contact
Function info($id) Function info($id)
{ {
$sql = "SELECT c.idp, ".$this->db->pdate("datec")." as datec, fk_user"; $sql = "SELECT c.idp, ".$this->db->pdate("datec")." as datec, fk_user";
$sql .= ", ".$this->db->pdate("tms")." as tms"; $sql .= ", ".$this->db->pdate("tms")." as tms, fk_user_modif";
$sql .= " FROM ".MAIN_DB_PREFIX."socpeople as c"; $sql .= " FROM ".MAIN_DB_PREFIX."socpeople as c";
$sql .= " WHERE c.idp = $id"; $sql .= " WHERE c.idp = $id";
@ -402,9 +441,12 @@ class Contact
$cuser = new User($this->db, $obj->fk_user); $cuser = new User($this->db, $obj->fk_user);
$cuser->fetch(); $cuser->fetch();
$this->user_creation = $cuser; $this->user_creation = $cuser;
$muser = new User($this->db, $obj->fk_user_modif);
$muser->fetch();
$this->user_modification = $muser;
$this->date_creation = $obj->datec; $this->date_creation = $obj->datec;
$this->date_modification = $obj->tms; $this->date_modification = $obj->tms;

View File

@ -1,7 +1,7 @@
<?PHP <?PHP
/* Copyright (c) 2002-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org> /* Copyright (c) 2002-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2004 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be> * Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -280,12 +280,19 @@ class Form {
print '</select>'; print '</select>';
} }
/*
* Affiche zone de selection de date
* Liste deroulante pour les jours, mois, annee et eventuellement heurs et minutes
* Les champs sont présélectionnées avec:
* - La date set_time (timestamps ou date au format YYYY-MM-DD ou YYYY-MM-DD HH:MM)
* - La date du jour si set_time vaut ''
* - Aucune date (champs vides) si set_time vaut -1
*/
Function select_date($set_time='', $prefix='re', $h = 0, $m = 0, $empty=0) Function select_date($set_time='', $prefix='re', $h = 0, $m = 0, $empty=0)
{ {
if (! $set_time && !$empty) if (! $set_time && ! $empty)
{ {
$set_time = time(); $set_time = time();
} }
$strmonth[1] = "Janvier"; $strmonth[1] = "Janvier";
@ -301,30 +308,42 @@ class Form {
$strmonth[11] = "Novembre"; $strmonth[11] = "Novembre";
$strmonth[12] = "D&eacute;cembre"; $strmonth[12] = "D&eacute;cembre";
$smonth = 1; # Analyse de la date de préselection
if (eregi('^([0-9]+)\-([0-9]+)\-([0-9]+)\s?([0-9]+)?:?([0-9]+)?',$set_time,$reg)) {
$cday = date("d", $set_time); // Date au format 'YYYY-MM-DD' ou 'YYYY-MM-DD HH:MM:SS'
$cmonth = date("n", $set_time); $syear = $reg[1];
$syear = date("Y", $set_time); $smonth = $reg[2];
$shour = date("H", $set_time); $sday = $reg[3];
$smin = date("i", $set_time); $shour = $reg[4];
$smin = $reg[5];
}
else {
// Date est un timestamps
$syear = date("Y", $set_time);
$smonth = date("n", $set_time);
$sday = date("d", $set_time);
$shour = date("H", $set_time);
$smin = date("i", $set_time);
}
print '<select name="'.$prefix.'day">'; print '<select name="'.$prefix.'day">';
if ($empty) if ($empty || $set_time == -1)
{ {
$cday = 0; $sday = 0;
$cmonth = 0; $smonth = 0;
$syear = 0; $syear = 0;
$shour = 0;
$smin = 0;
print '<option value="0" SELECTED>'; print '<option value="0" selected>';
} }
for ($day = 1 ; $day < $sday + 32 ; $day++) for ($day = 1 ; $day <= 31; $day++)
{ {
if ($day == $cday) if ($day == $sday)
{ {
print "<option value=\"$day\" SELECTED>$day"; print "<option value=\"$day\" selected>$day";
} }
else else
{ {
@ -336,17 +355,17 @@ class Form {
print '<select name="'.$prefix.'month">'; print '<select name="'.$prefix.'month">';
if ($empty) if ($empty || $set_time == -1)
{ {
print '<option value="0" SELECTED>'; print '<option value="0" selected>';
} }
for ($month = $smonth ; $month < $smonth + 12 ; $month++) for ($month = 1 ; $month <= 12 ; $month++)
{ {
if ($month == $cmonth) if ($month == $smonth)
{ {
print "<option value=\"$month\" SELECTED>" . $strmonth[$month]; print "<option value=\"$month\" selected>" . $strmonth[$month];
} }
else else
{ {
@ -355,7 +374,7 @@ class Form {
} }
print "</select>"; print "</select>";
if ($empty) if ($empty || $set_time == -1)
{ {
print '<input type="text" size="5" maxlength="4" name="'.$prefix.'year">'; print '<input type="text" size="5" maxlength="4" name="'.$prefix.'year">';
} }
@ -364,11 +383,11 @@ class Form {
print '<select name="'.$prefix.'year">'; print '<select name="'.$prefix.'year">';
for ($year = $syear - 2; $year < $syear + 5 ; $year++) for ($year = $syear - 3; $year < $syear + 5 ; $year++)
{ {
if ($year == $syear) if ($year == $syear)
{ {
print "<option value=\"$year\" SELECTED>$year"; print "<option value=\"$year\" selected>$year";
} }
else else
{ {
@ -390,7 +409,7 @@ class Form {
} }
if ($hour == $shour) if ($hour == $shour)
{ {
print "<option value=\"$hour\" SELECTED>$hour"; print "<option value=\"$hour\" selected>$hour";
} }
else else
{ {
@ -411,7 +430,7 @@ class Form {
} }
if ($min == $smin) if ($min == $smin)
{ {
print "<option value=\"$min\" SELECTED>$min"; print "<option value=\"$min\" selected>$min";
} }
else else
{ {

View File

@ -165,14 +165,33 @@ function dolibarr_print_ca($ca)
/*! /*!
\brief formattage de la date \brief formattage de la date
\param time date \param time date timestamp ou au format YYYY-MM-DD
\param format format de la date "%d %b %Y" \param format format de la date "%d %b %Y"
\remarks retourne la date formatée \remarks retourne la date formatée
*/ */
function dolibarr_print_date($time,$format="%d %b %Y") function dolibarr_print_date($time,$format="%d %b %Y")
{ {
return strftime($format,$time); # Analyse de la date
if (eregi('^([0-9]+)\-([0-9]+)\-([0-9]+)\s?([0-9]+)?:?([0-9]+)?',$time,$reg)) {
// Date au format 'YYYY-MM-DD' ou 'YYYY-MM-DD HH:MM:SS'
$syear = $reg[1];
$smonth = $reg[2];
$sday = $reg[3];
$shour = $reg[4];
$smin = $reg[5];
if ($syear < 1970 && $_SERVER["WINDIR"]) {
# Le formatage ne peut etre appliqué car windows ne supporte pas la fonction
# mktime si l'année est inférieur à 1970. On retourne un format fixe
return "$syear-$smonth-$sday";
} else {
return strftime($format,mktime($shour,$smin,0,$smonth,$sday,$syear));
}
}
else {
// Date est un timestamps
return strftime($format,$time);
}
} }