New: dol_strintotime accept format YYYY-MM-DD HH:MM:SS

Fix: create member was missing field import_key
New: Uniformize code
This commit is contained in:
Laurent Destailleur 2013-06-27 16:02:52 +02:00
parent c590f6482e
commit c92aa1f6aa
6 changed files with 34 additions and 30 deletions

View File

@ -266,6 +266,9 @@ class Adherent extends CommonObject
$now=dol_now(); $now=dol_now();
// Clean parameters
$this->import_key = trim($this->import_key);
// Check parameters // Check parameters
if (! empty($conf->global->ADHERENT_MAIL_REQUIRED) && ! isValidEMail($this->email)) if (! empty($conf->global->ADHERENT_MAIL_REQUIRED) && ! isValidEMail($this->email))
{ {
@ -287,7 +290,7 @@ class Adherent extends CommonObject
// Insert member // Insert member
$sql = "INSERT INTO ".MAIN_DB_PREFIX."adherent"; $sql = "INSERT INTO ".MAIN_DB_PREFIX."adherent";
$sql.= " (datec,login,fk_user_author,fk_user_mod,fk_user_valid,morphy,fk_adherent_type,entity)"; $sql.= " (datec,login,fk_user_author,fk_user_mod,fk_user_valid,morphy,fk_adherent_type,entity,import_key)";
$sql.= " VALUES ("; $sql.= " VALUES (";
$sql.= " '".$this->db->idate($this->datec)."'"; $sql.= " '".$this->db->idate($this->datec)."'";
$sql.= ", ".($this->login?"'".$this->db->escape($this->login)."'":"null"); $sql.= ", ".($this->login?"'".$this->db->escape($this->login)."'":"null");
@ -295,6 +298,7 @@ class Adherent extends CommonObject
$sql.= ", null, null, '".$this->morphy."'"; $sql.= ", null, null, '".$this->morphy."'";
$sql.= ", '".$this->typeid."'"; $sql.= ", '".$this->typeid."'";
$sql.= ", ".$conf->entity; $sql.= ", ".$conf->entity;
$sql.= ", ".(! empty($this->import_key) ? "'".$this->import_key."'":"null");
$sql.= ")"; $sql.= ")";
dol_syslog(get_class($this)."::create sql=".$sql); dol_syslog(get_class($this)."::create sql=".$sql);

View File

@ -96,9 +96,9 @@ class Cotisation extends CommonObject
/** /**
* Fonction qui permet de recuperer une cotisation * Method to load a subscription
* *
* @param int $rowid Id cotisation * @param int $rowid Id subscription
* @return int <0 if KO, =0 if not found, >0 if OK * @return int <0 if KO, =0 if not found, >0 if OK
*/ */
function fetch($rowid) function fetch($rowid)
@ -111,7 +111,7 @@ class Cotisation extends CommonObject
$sql.=" FROM ".MAIN_DB_PREFIX."cotisation"; $sql.=" FROM ".MAIN_DB_PREFIX."cotisation";
$sql.=" WHERE rowid=".$rowid; $sql.=" WHERE rowid=".$rowid;
dol_syslog("Cotisation::fetch sql=".$sql); dol_syslog(get_class($this)."::fetch sql=".$sql);
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
if ($resql) if ($resql)
{ {
@ -166,7 +166,7 @@ class Cotisation extends CommonObject
$sql .= " fk_bank = ".($this->fk_bank ? $this->fk_bank : 'null'); $sql .= " fk_bank = ".($this->fk_bank ? $this->fk_bank : 'null');
$sql .= " WHERE rowid = ".$this->id; $sql .= " WHERE rowid = ".$this->id;
dol_syslog("Cotisation::update sql=".$sql); dol_syslog(get_class($this)."::update sql=".$sql);
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if ($resql) if ($resql)
{ {
@ -181,7 +181,7 @@ class Cotisation extends CommonObject
{ {
$this->db->rollback(); $this->db->rollback();
$this->error=$this->db->error(); $this->error=$this->db->error();
dol_syslog("Cotisation::update ".$this->error, LOG_ERR); dol_syslog(get_class($this)."::update ".$this->error, LOG_ERR);
return -1; return -1;
} }
} }
@ -205,7 +205,7 @@ class Cotisation extends CommonObject
$this->db->begin(); $this->db->begin();
$sql = "DELETE FROM ".MAIN_DB_PREFIX."cotisation WHERE rowid = ".$this->id; $sql = "DELETE FROM ".MAIN_DB_PREFIX."cotisation WHERE rowid = ".$this->id;
dol_syslog("Cotisation::delete sql=".$sql); dol_syslog(get_class($this)."::delete sql=".$sql);
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
if ($resql) if ($resql)
{ {

View File

@ -37,11 +37,11 @@ abstract class CommonObject
public $errors; public $errors;
public $canvas; // Contains canvas name if it is public $canvas; // Contains canvas name if it is
public $name;
public $lastname; public $lastname;
public $firstname; public $firstname;
public $name;
public $nom;
public $civility_id; public $civility_id;
public $import_key;
public $array_options=array(); public $array_options=array();

View File

@ -205,9 +205,9 @@ function societe_admin_prepare_head($object)
/** /**
* Return country label, code or id from an id or a code * Return country label, code or id from an id, code or label
* *
* @param int $id Id or code of country * @param int $searchkey Id or code of country to search
* @param int $withcode '0'=Return label, * @param int $withcode '0'=Return label,
* '1'=Return code + label, * '1'=Return code + label,
* '2'=Return code from id, * '2'=Return code from id,
@ -215,15 +215,16 @@ function societe_admin_prepare_head($object)
* 'all'=Return array('id'=>,'code'=>,'label'=>) * 'all'=Return array('id'=>,'code'=>,'label'=>)
* @param DoliDB $dbtouse Database handler (using in global way may fail because of conflicts with some autoload features) * @param DoliDB $dbtouse Database handler (using in global way may fail because of conflicts with some autoload features)
* @param Translate $outputlangs Langs object for output translation * @param Translate $outputlangs Langs object for output translation
* @param int $entconv 0=Return value without entities and not converted to output charset * @param int $entconv 0=Return value without entities and not converted to output charset, 1=Ready for html output
* @param int $searchlabel Label of country to search (warning: searching on label is not reliable)
* @return mixed String with country code or translated country name or Array('id','code','label') * @return mixed String with country code or translated country name or Array('id','code','label')
*/ */
function getCountry($id,$withcode='',$dbtouse=0,$outputlangs='',$entconv=1) function getCountry($searchkey,$withcode='',$dbtouse=0,$outputlangs='',$entconv=1,$searchlabel='')
{ {
global $db,$langs; global $db,$langs;
// Check parameters // Check parameters
if (empty($id)) if (empty($searchkey) && empty($searchlabel))
{ {
if ($withcode === 'all') return array('id'=>'','code'=>'','label'=>''); if ($withcode === 'all') return array('id'=>'','code'=>'','label'=>'');
else return ''; else return '';
@ -232,8 +233,9 @@ function getCountry($id,$withcode='',$dbtouse=0,$outputlangs='',$entconv=1)
if (! is_object($outputlangs)) $outputlangs=$langs; if (! is_object($outputlangs)) $outputlangs=$langs;
$sql = "SELECT rowid, code, libelle FROM ".MAIN_DB_PREFIX."c_pays"; $sql = "SELECT rowid, code, libelle FROM ".MAIN_DB_PREFIX."c_pays";
if (is_numeric($id)) $sql.= " WHERE rowid=".$id; if (is_numeric($searchkey)) $sql.= " WHERE rowid=".$searchkey;
else $sql.= " WHERE code='".$db->escape($id)."'"; elseif (! empty($searchkey)) $sql.= " WHERE code='".$db->escape($searchkey)."'";
else $sql.= " WHERE libelle='".$db->escape($searchlabel)."'";
dol_syslog("Company.lib::getCountry sql=".$sql); dol_syslog("Company.lib::getCountry sql=".$sql);
$resql=$dbtouse->query($sql); $resql=$dbtouse->query($sql);
@ -259,6 +261,7 @@ function getCountry($id,$withcode='',$dbtouse=0,$outputlangs='',$entconv=1)
{ {
return 'NotDefined'; return 'NotDefined';
} }
$dbtouse->free($resql);
} }
else dol_print_error($dbtouse,''); else dol_print_error($dbtouse,'');
return 'Error'; return 'Error';

View File

@ -337,19 +337,11 @@ function dol_stringtotime($string, $gm=1)
if ($syear >= 50 && $syear < 100) $syear+=2000; if ($syear >= 50 && $syear < 100) $syear+=2000;
$string=sprintf("%04d%02d%02d%02d%02d%02d",$syear,$smonth,$sday,$shour,$smin,$ssec); $string=sprintf("%04d%02d%02d%02d%02d%02d",$syear,$smonth,$sday,$shour,$smin,$ssec);
} }
// Convert date with format RFC3339 else if (
else if (preg_match('/^([0-9]{4})-([0-9]{2})-([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})Z$/i',$string,$reg)) preg_match('/^([0-9]{4})-([0-9]{2})-([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})Z$/i',$string,$reg) // Convert date with format RFC3339
{ || preg_match('/^([0-9]{4})-([0-9]{2})-([0-9]{2}) ([0-9]{2}):([0-9]{2}):([0-9]{2})$/i',$string,$reg) // Convert date with format YYYY-MM-DD HH:MM:SS
$syear = $reg[1]; || preg_match('/^([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2})([0-9]{2})([0-9]{2})Z$/i',$string,$reg) // Convert date with format YYYYMMDDTHHMMSSZ
$smonth = $reg[2]; )
$sday = $reg[3];
$shour = $reg[4];
$smin = $reg[5];
$ssec = $reg[6];
$string=sprintf("%04d%02d%02d%02d%02d%02d",$syear,$smonth,$sday,$shour,$smin,$ssec);
}
// Convert date with format YYYYMMDDTHHMMSSZ
else if (preg_match('/^([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2})([0-9]{2})([0-9]{2})Z$/i',$string,$reg))
{ {
$syear = $reg[1]; $syear = $reg[1];
$smonth = $reg[2]; $smonth = $reg[2];

View File

@ -306,6 +306,11 @@ class DateLibTest extends PHPUnit_Framework_TestCase
print __METHOD__." result=".$result."\n"; print __METHOD__." result=".$result."\n";
$this->assertEquals(7200,$result); $this->assertEquals(7200,$result);
$stime='1970-01-01 02:00:00';
$result=dol_stringtotime($stime);
print __METHOD__." result=".$result."\n";
$this->assertEquals(7200,$result);
$stime='19700101T020000Z'; $stime='19700101T020000Z';
$result=dol_stringtotime($stime); $result=dol_stringtotime($stime);
print __METHOD__." result=".$result."\n"; print __METHOD__." result=".$result."\n";