From 55156edd0d28b0899d116606e6f49a76c795273b Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 30 Dec 2011 14:18:19 +0100 Subject: [PATCH 01/10] Enhance PHPUnits --- htdocs/adherents/class/adherent.class.php | 62 +++-- htdocs/contact/class/contact.class.php | 131 +++++----- htdocs/societe/class/societe.class.php | 51 ++-- htdocs/societe/soc.php | 6 +- test/phpunit/AdherentTest.php | 48 +++- test/phpunit/AllTests.php | 2 + test/phpunit/ContactTest.php | 283 ++++++++++++++++++++++ test/phpunit/SocieteTest.php | 10 +- 8 files changed, 484 insertions(+), 109 deletions(-) create mode 100755 test/phpunit/ContactTest.php diff --git a/htdocs/adherents/class/adherent.class.php b/htdocs/adherents/class/adherent.class.php index d80b862bd5b..30505903f1d 100644 --- a/htdocs/adherents/class/adherent.class.php +++ b/htdocs/adherents/class/adherent.class.php @@ -80,7 +80,7 @@ class Adherent extends CommonObject var $morphy; var $public; - var $note; // Note + var $note; // Private note var $statut; // -1:brouillon, 0:resilie, >=1:valide,paye var $photo; @@ -115,11 +115,11 @@ class Adherent extends CommonObject /** * Constructor * - * @param DoliDB $DB Database handler + * @param DoliDB $db Database handler */ - function Adherent($DB) + function Adherent($db) { - $this->db = $DB ; + $this->db = $db; $this->statut = -1; // l'adherent n'est pas public par defaut $this->public = 0; @@ -388,8 +388,15 @@ class Adherent extends CommonObject dol_syslog(get_class($this)."::update notrigger=".$notrigger.", nosyncuser=".$nosyncuser.", nosyncuserpass=".$nosyncuserpass.", email=".$this->email); // Clean parameters - if (! empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->nom=ucwords(trim($this->nom)); - if (! empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->prenom=ucwords(trim($this->prenom)); + $this->lastname=trim($this->lastname)?trim($this->lastname):trim($this->nom); + $this->firstname=trim($this->firstname)?trim($this->firstname):trim($this->prenom); + $this->address=($this->address?$this->address:$this->adresse); + $this->zip=($this->zip?$this->zip:$this->cp); + $this->town=($this->town?$this->town:$this->ville); + $this->country_id=($this->country_id > 0?$this->country_id:$this->fk_pays); + $this->state_id=($this->state_id > 0?$this->state_id:$this->fk_departement); + if (! empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->lastname=ucwords(trim($this->lastname)); + if (! empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->firstname=ucwords(trim($this->firstname)); // Check parameters if (! empty($conf->global->ADHERENT_MAIL_REQUIRED) && ! isValidEMail($this->email)) @@ -403,16 +410,16 @@ class Adherent extends CommonObject $sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET"; $sql.= " civilite = ".($this->civilite_id?"'".$this->civilite_id."'":"null"); - $sql.= ", prenom = ".($this->prenom?"'".$this->db->escape($this->prenom)."'":"null"); - $sql.= ", nom=" .($this->nom?"'".$this->db->escape($this->nom)."'":"null"); + $sql.= ", prenom = ".($this->firstname?"'".$this->db->escape($this->firstname)."'":"null"); + $sql.= ", nom=" .($this->lastname?"'".$this->db->escape($this->lastname)."'":"null"); $sql.= ", login=" .($this->login?"'".$this->db->escape($this->login)."'":"null"); $sql.= ", societe=" .($this->societe?"'".$this->db->escape($this->societe)."'":"null"); $sql.= ", fk_soc=" .($this->fk_soc > 0?"'".$this->fk_soc."'":"null"); - $sql.= ", adresse=" .($this->adresse?"'".$this->db->escape($this->adresse)."'":"null"); - $sql.= ", cp=" .($this->cp?"'".$this->db->escape($this->cp)."'":"null"); - $sql.= ", ville=" .($this->ville?"'".$this->db->escape($this->ville)."'":"null"); + $sql.= ", adresse=" .($this->address?"'".$this->db->escape($this->address)."'":"null"); + $sql.= ", cp=" .($this->zip?"'".$this->db->escape($this->zip)."'":"null"); + $sql.= ", ville=" .($this->town?"'".$this->db->escape($this->town)."'":"null"); $sql.= ", pays=" .($this->country_id>0?"'".$this->country_id."'":"null"); - $sql.= ", fk_departement=".($this->fk_departement>0?"'".$this->fk_departement."'":"null"); + $sql.= ", fk_departement=".($this->state_id>0?"'".$this->state_id."'":"null"); $sql.= ", email='".$this->email."'"; $sql.= ", phone=" .($this->phone?"'".$this->db->escape($this->phone)."'":"null"); $sql.= ", phone_perso=" .($this->phone_perso?"'".$this->db->escape($this->phone_perso)."'":"null"); @@ -433,7 +440,12 @@ class Adherent extends CommonObject $resql = $this->db->query($sql); if ($resql) { - $nbrowsaffected+=$this->db->affected_rows($resql); + unset($this->country_code); + unset($this->country); + unset($this->state_code); + unset($this->state); + + $nbrowsaffected+=$this->db->affected_rows($resql); // Actions on extra fields (by external module) include_once(DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'); @@ -953,7 +965,7 @@ class Adherent extends CommonObject { global $conf, $langs; - $sql = "SELECT d.rowid, d.civilite, d.prenom as firstname, d.nom as name, d.societe, d.fk_soc, d.statut, d.public, d.adresse as address, d.cp as zip, d.ville as town, d.note,"; + $sql = "SELECT d.rowid, d.civilite, d.prenom as firstname, d.nom as lastname, d.societe, d.fk_soc, d.statut, d.public, d.adresse as address, d.cp as zip, d.ville as town, d.note,"; $sql.= " d.email, d.phone, d.phone_perso, d.phone_mobile, d.login, d.pass,"; $sql.= " d.photo, d.fk_adherent_type, d.morphy,"; $sql.= " d.datec as datec,"; @@ -990,8 +1002,8 @@ class Adherent extends CommonObject $this->civilite_id = $obj->civilite; $this->prenom = $obj->firstname; $this->firstname = $obj->firstname; - $this->nom = $obj->name; - $this->lastname = $obj->name; + $this->nom = $obj->lastname; + $this->lastname = $obj->lastname; $this->login = $obj->login; $this->pass = $obj->pass; $this->societe = $obj->societe; @@ -1755,14 +1767,23 @@ class Adherent extends CommonObject /** * Return full address of member * - * @param int $withcountry 1=Add country into address string - * @param string $sep Separator to use to build string - * @return string Full address string + * + * @param int $withcountry 1=Add country into address string + * @param string $sep Separator to use to build string + * @return string Full address string */ function getFullAddress($withcountry=0,$sep="\n") { $ret=''; - if (in_array($this->country,array('us'))) + if ($withcountry && $this->country_id && (empty($this->country_code) || empty($this->country))) + { + require_once(DOL_DOCUMENT_ROOT ."/core/lib/company.lib.php"); + $tmparray=getCountry($this->country_id,'all'); + $this->country_code=$tmparray['code']; + $this->country =$tmparray['label']; + } + + if (in_array($this->country_code,array('US'))) { $ret.=($this->address?$this->address.$sep:''); $ret.=trim($this->zip.' '.$this->town); @@ -1777,7 +1798,6 @@ class Adherent extends CommonObject return trim($ret); } - /** * Retourne le libelle du statut d'un adherent (brouillon, valide, resilie) * diff --git a/htdocs/contact/class/contact.class.php b/htdocs/contact/class/contact.class.php index fd857f0431d..4b481e93902 100644 --- a/htdocs/contact/class/contact.class.php +++ b/htdocs/contact/class/contact.class.php @@ -53,6 +53,9 @@ class Contact extends CommonObject var $fk_departement; // Id of department var $departement_code; // Code of department var $departement; // Label of department + var $state_id; // Id of department + var $state_code; // Code of department + var $state; // Label of department var $fk_pays; // Id of country var $pays_code; // Code of country @@ -68,6 +71,7 @@ class Contact extends CommonObject var $email; var $birthday; var $default_lang; + var $note; // Private note var $ref_facturation; // Nb de reference facture pour lequel il est contact var $ref_contrat; // Nb de reference contrat pour lequel il est contact @@ -83,11 +87,11 @@ class Contact extends CommonObject /** * Constructor * - * @param DoliDB $DB Database handler + * @param DoliDB $db Database handler */ - function Contact($DB) + function Contact($db) { - $this->db = $DB; + $this->db = $db; } /** @@ -106,9 +110,9 @@ class Contact extends CommonObject $this->db->begin(); // Clean parameters - $this->name=trim($this->name); + $this->lastname=$this->lastname?trim($this->lastname):$this->name; $this->firstname=trim($this->firstname); - if (! empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->name=ucwords($this->name); + if (! empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->lastname=ucwords($this->lastname); if (! empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->firstname=ucwords($this->firstname); if (! $this->socid) $this->socid = 0; if (! $this->priv) $this->priv = 0; @@ -134,7 +138,7 @@ class Contact extends CommonObject $sql.= " ".$conf->entity; $sql.= ")"; - dol_syslog("Contact::create sql=".$sql); + dol_syslog(get_class($this)."::create sql=".$sql); $resql=$this->db->query($sql); if ($resql) { @@ -178,7 +182,7 @@ class Contact extends CommonObject else { $this->db->rollback(); - dol_syslog("Contact::create ".$this->error, LOG_ERR); + dol_syslog(get_class($this)."::create ".$this->error, LOG_ERR); return -2; } } @@ -187,7 +191,7 @@ class Contact extends CommonObject $this->error=$this->db->lasterror(); $this->db->rollback(); - dol_syslog("Contact::create ".$this->error, LOG_ERR); + dol_syslog(get_class($this)."::create ".$this->error, LOG_ERR); return -1; } } @@ -208,16 +212,18 @@ class Contact extends CommonObject $this->id = $id; - // Nettoyage parametres - $this->name=trim($this->name); + // Clean parameters + $this->lastname=trim($this->lastname)?trim($this->lastname):trim($this->name); $this->firstname=trim($this->firstname); - $this->email=trim($this->email); $this->phone_pro=trim($this->phone_pro); $this->phone_perso=trim($this->phone_perso); $this->phone_mobile=trim($this->phone_mobile); $this->fax=trim($this->fax); + $this->zip=($this->zip?$this->zip:$this->cp); + $this->town=($this->town?$this->town:$this->ville); $this->country_id=($this->country_id > 0?$this->country_id:$this->fk_pays); + $this->state_id=($this->state_id > 0?$this->state_id:$this->fk_departement); $this->db->begin(); @@ -225,13 +231,13 @@ class Contact extends CommonObject if ($this->socid > 0) $sql .= " fk_soc='".$this->db->escape($this->socid)."',"; if ($this->socid == -1) $sql .= " fk_soc=null,"; $sql .= " civilite='".$this->db->escape($this->civilite_id)."'"; - $sql .= ", name='".$this->db->escape($this->name)."'"; + $sql .= ", name='".$this->db->escape($this->lastname)."'"; $sql .= ", firstname='".$this->db->escape($this->firstname)."'"; $sql .= ", address='".$this->db->escape($this->address)."'"; $sql .= ", cp='".$this->db->escape($this->zip)."'"; $sql .= ", ville='".$this->db->escape($this->town)."'"; $sql .= ", fk_pays=".($this->country_id>0?$this->country_id:'NULL'); - $sql .= ", fk_departement=".($this->fk_departement>0?$this->fk_departement:'NULL'); + $sql .= ", fk_departement=".($this->state_id>0?$this->state_id:'NULL'); $sql .= ", poste='".$this->db->escape($this->poste)."'"; $sql .= ", fax='".$this->db->escape($this->fax)."'"; $sql .= ", email='".$this->db->escape($this->email)."'"; @@ -245,10 +251,15 @@ class Contact extends CommonObject $sql .= ", default_lang=".($this->default_lang?"'".$this->default_lang."'":"null"); $sql .= " WHERE rowid=".$id; - dol_syslog("Contact::update sql=".$sql,LOG_DEBUG); + dol_syslog(get_class($this)."::update sql=".$sql,LOG_DEBUG); $result = $this->db->query($sql); if ($result) { + unset($this->country_code); + unset($this->country); + unset($this->state_code); + unset($this->state); + if (! $error && ! $notrigger) { // Appel des triggers @@ -267,7 +278,7 @@ class Contact extends CommonObject else { $this->error=join(',',$this->errors); - dol_syslog("Contact::update Error ".$this->error,LOG_ERR); + dol_syslog(get_class($this)."::update Error ".$this->error,LOG_ERR); $this->db->rollback(); return -$error; } @@ -275,7 +286,7 @@ class Contact extends CommonObject else { $this->error=$this->db->lasterror().' sql='.$sql; - dol_syslog("Contact::update Error ".$this->error,LOG_ERR); + dol_syslog(get_class($this)."::update Error ".$this->error,LOG_ERR); $this->db->rollback(); return -1; } @@ -390,7 +401,7 @@ class Contact extends CommonObject if ($user) $sql .= ", fk_user_modif=".$user->id; $sql .= " WHERE rowid=".$id; //print "update_perso: ".$this->birthday.'-'.$this->db->idate($this->birthday); - dol_syslog("Contact::update_perso this->birthday=".$this->birthday." - sql=".$sql); + dol_syslog(get_class($this)."::update_perso this->birthday=".$this->birthday." - sql=".$sql); $resql = $this->db->query($sql); if (! $resql) { @@ -450,14 +461,14 @@ class Contact extends CommonObject $langs->load("companies"); - $sql = "SELECT c.rowid, c.fk_soc, c.civilite as civilite_id, c.name, c.firstname,"; - $sql.= " c.address, c.cp, c.ville,"; - $sql.= " c.fk_pays,"; + $sql = "SELECT c.rowid, c.fk_soc, c.civilite as civilite_id, c.name as lastname, c.firstname,"; + $sql.= " c.address, c.cp as zip, c.ville as town,"; + $sql.= " c.fk_pays as country_id,"; $sql.= " c.fk_departement,"; $sql.= " c.birthday,"; $sql.= " c.poste, c.phone, c.phone_perso, c.phone_mobile, c.fax, c.email, c.jabberid,"; $sql.= " c.priv, c.note, c.default_lang, c.canvas,"; - $sql.= " p.libelle as pays, p.code as pays_code,"; + $sql.= " p.libelle as country, p.code as country_code,"; $sql.= " d.nom as departement, d.code_departement as departement_code,"; $sql.= " u.rowid as user_id, u.login as user_login,"; $sql.= " s.nom as socname, s.address as socaddress, s.cp as soccp, s.ville as soccity, s.default_lang as socdefault_lang"; @@ -468,7 +479,7 @@ class Contact extends CommonObject $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON c.fk_soc = s.rowid"; $sql.= " WHERE c.rowid = ". $id; - dol_syslog("Contact::fetch sql=".$sql); + dol_syslog(get_class($this)."::fetch sql=".$sql); $resql=$this->db->query($sql); if ($resql) { @@ -479,31 +490,32 @@ class Contact extends CommonObject $this->id = $obj->rowid; $this->ref = $obj->rowid; $this->civilite_id = $obj->civilite_id; - $this->name = $obj->name; + $this->lastname = $obj->lastname; + $this->name = $obj->lastname; // TODO deprecated $this->firstname = $obj->firstname; - $this->nom = $obj->name; // TODO deprecated + $this->nom = $obj->lastname; // TODO deprecated $this->prenom = $obj->firstname; // TODO deprecated $this->address = $obj->address; $this->adresse = $obj->address; // TODO deprecated - $this->cp = $obj->cp; // TODO deprecated - $this->zip = $obj->cp; - $this->ville = $obj->ville; // TODO deprecated - $this->town = $obj->ville; + $this->cp = $obj->zip; // TODO deprecated + $this->zip = $obj->zip; + $this->ville = $obj->town; // TODO deprecated + $this->town = $obj->town; $this->fk_departement = $obj->fk_departement; $this->state_id = $obj->fk_departement; $this->departement_code = $obj->departement_code; // TODO deprecated $this->state_code = $obj->departement_code; - $this->departement = $obj->departement; // TODO deprecated + $this->departement = $obj->departement; // TODO deprecated $this->state = $obj->departement; - $this->fk_pays = $obj->fk_pays; - $this->country_id = $obj->fk_pays; - $this->pays_code = $obj->fk_pays?$obj->pays_code:''; - $this->country_code = $obj->fk_pays?$obj->pays_code:''; - $this->pays = ($obj->fk_pays > 0)?$langs->transnoentitiesnoconv("Country".$obj->pays_code):''; - $this->country = ($obj->fk_pays > 0)?$langs->transnoentitiesnoconv("Country".$obj->pays_code):''; + $this->fk_pays = $obj->country_id; + $this->country_id = $obj->country_id; + $this->pays_code = $obj->country_id?$obj->country_code:''; + $this->country_code = $obj->country_id?$obj->country_code:''; + $this->pays = ($obj->country_id > 0)?$langs->transnoentitiesnoconv("Country".$obj->country_code):''; + $this->country = ($obj->country_id > 0)?$langs->transnoentitiesnoconv("Country".$obj->country_code):''; $this->socid = $obj->fk_soc; $this->socname = $obj->socname; @@ -547,7 +559,7 @@ class Contact extends CommonObject else { $this->error=$this->db->error(); - dol_syslog("Contact::fetch ".$this->error, LOG_ERR); + dol_syslog(get_class($this)."::fetch ".$this->error, LOG_ERR); return -1; } @@ -572,7 +584,7 @@ class Contact extends CommonObject else { $this->error=$this->db->error(); - dol_syslog("Contact::fetch ".$this->error, LOG_ERR); + dol_syslog(get_class($this)."::fetch ".$this->error, LOG_ERR); return -1; } } @@ -588,7 +600,7 @@ class Contact extends CommonObject else { $this->error=$this->db->error(); - dol_syslog("Contact::fetch ".$this->error, LOG_ERR); + dol_syslog(get_class($this)."::fetch ".$this->error, LOG_ERR); return -1; } } @@ -612,7 +624,7 @@ class Contact extends CommonObject $sql.=" AND fk_socpeople = ". $this->id; $sql.=" GROUP BY tc.element"; - dol_syslog("Contact::load_ref_elements sql=".$sql); + dol_syslog(get_class($this)."::load_ref_elements sql=".$sql); $resql=$this->db->query($sql); if ($resql) @@ -633,7 +645,7 @@ class Contact extends CommonObject else { $this->error=$this->db->error()." - ".$sql; - dol_syslog("Contact::load_ref_elements Error ".$this->error, LOG_ERR); + dol_syslog(get_class($this)."::load_ref_elements Error ".$this->error, LOG_ERR); return -1; } } @@ -664,7 +676,7 @@ class Contact extends CommonObject $sql.= " WHERE ec.fk_socpeople=".$this->id; $sql.= " AND ec.fk_c_type_contact=tc.rowid"; $sql.= " AND tc.source='external'"; - dol_syslog("Contact::delete sql=".$sql); + dol_syslog(get_class($this)."::delete sql=".$sql); $resql = $this->db->query($sql); if ($resql) { @@ -677,7 +689,7 @@ class Contact extends CommonObject $sqldel = "DELETE FROM ".MAIN_DB_PREFIX."element_contact"; $sqldel.=" WHERE rowid = ".$obj->rowid; - dol_syslog("Contact::delete sql=".$sqldel); + dol_syslog(get_class($this)."::delete sql=".$sqldel); $result = $this->db->query($sqldel); if (! $result) { @@ -699,7 +711,7 @@ class Contact extends CommonObject { $sql = "DELETE FROM ".MAIN_DB_PREFIX."socpeople"; $sql .= " WHERE rowid=".$this->id; - dol_syslog("Contact::delete sql=".$sql); + dol_syslog(get_class($this)."::delete sql=".$sql); $result = $this->db->query($sql); if (! $result) { @@ -847,7 +859,15 @@ class Contact extends CommonObject function getFullAddress($withcountry=0,$sep="\n") { $ret=''; - if (in_array($this->country,array('us'))) + if ($withcountry && $this->country_id && (empty($this->country_code) || empty($this->country))) + { + require_once(DOL_DOCUMENT_ROOT ."/core/lib/company.lib.php"); + $tmparray=getCountry($this->country_id,'all'); + $this->country_code=$tmparray['code']; + $this->country =$tmparray['label']; + } + + if (in_array($this->country_code,array('US'))) { $ret.=($this->address?$this->address.$sep:''); $ret.=trim($this->zip.' '.$this->town); @@ -875,13 +895,6 @@ class Contact extends CommonObject $code=$this->civilite_id; return $langs->trans("Civility".$code)!="Civility".$code ? $langs->trans("Civility".$code) : ''; - /*if (empty($ret)) - { - $ret=$code; - $langs->getLabelFromKey($this->db,$reg[1],'c_civilite','code','civilite'); - //$ret=dol_getIdFromCode($this->db,$code,'c_civilite', - } - return $ret;*/ } @@ -1035,16 +1048,14 @@ class Contact extends CommonObject // Initialise parameters $this->id=0; $this->specimen=1; - $this->nom = 'DOLIBARR'; - $this->name = $this->nom; - $this->prenom = 'SPECIMEN'; - $this->firstname = $this->prenom; + $this->name = 'DOLIBARR'; + $this->firstname = 'SPECIMEN'; $this->address = '61 jump street'; - $this->cp = '75000'; - $this->ville = 'Paris'; - $this->fk_pays = 1; - $this->pays_code = 'FR'; - $this->pays = 'France'; + $this->zip = '75000'; + $this->town = 'Paris'; + $this->country_id = 1; + $this->country_code = 'FR'; + $this->country = 'France'; $this->email = 'specimen@specimen.com'; $socid = rand(1, $num_socs); $this->socid = $socids[$socid]; diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index f7538120dc1..abcc5937a76 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -377,7 +377,7 @@ class Societe extends CommonObject $error=0; - dol_syslog("Societe::Update id=".$id." call_trigger=".$call_trigger." allowmodcodeclient=".$allowmodcodeclient." allowmodcodefournisseur=".$allowmodcodefournisseur); + dol_syslog(get_class($this)."::Update id=".$id." call_trigger=".$call_trigger." allowmodcodeclient=".$allowmodcodeclient." allowmodcodefournisseur=".$allowmodcodefournisseur); // For triggers if ($call_trigger) @@ -401,7 +401,7 @@ class Societe extends CommonObject $this->ville=$this->town; // TODO obsolete $this->state_id=trim($this->state_id); $this->country_id = ($this->country_id > 0)?$this->country_id:$this->pays_id; - $this->pays_id = $this->country_id; + $this->pays_id = $this->country_id; $this->tel = trim($this->tel); $this->fax = trim($this->fax); $this->tel = preg_replace("/\s/","",$this->tel); @@ -456,7 +456,7 @@ class Societe extends CommonObject if ($result >= 0) { - dol_syslog("Societe::Update verify ok"); + dol_syslog(get_class($this)."::Update verify ok"); $sql = "UPDATE ".MAIN_DB_PREFIX."societe"; $sql.= " SET nom = '" . $this->db->escape($this->name) ."'"; // Champ obligatoire @@ -534,6 +534,11 @@ class Societe extends CommonObject $resql=$this->db->query($sql); if ($resql) { + unset($this->country_code); + unset($this->country); + unset($this->state_code); + unset($this->state); + // Si le fournisseur est classe on l'ajoute $this->AddFournisseurInCategory($this->fournisseur_categorie); @@ -698,7 +703,7 @@ class Societe extends CommonObject $this->country_code = $obj->country_id?$obj->country_code:''; $this->pays = $obj->country_id?($langs->trans('Country'.$obj->country_code)!='Country'.$obj->country_code?$langs->trans('Country'.$obj->country_code):$obj->country):''; // TODO obsolete $this->country = $obj->country_id?($langs->trans('Country'.$obj->country_code)!='Country'.$obj->country_code?$langs->trans('Country'.$obj->country_code):$obj->country):''; - + $this->state_id = $obj->fk_departement; $this->state_code = $obj->departement_code; $this->state = $obj->departement; @@ -1426,24 +1431,33 @@ class Societe extends CommonObject /** * Return full address of third party - * @param withcountry 1=Add country into address string - * @param sep Separator to use to build string - * @return string Full address string + * + * @param int $withcountry 1=Add country into address string + * @param string $sep Separator to use to build string + * @return string Full address string */ function getFullAddress($withcountry=0,$sep="\n") { $ret=''; - if (in_array($this->country,array('us'))) + if ($withcountry && $this->country_id && (empty($this->country_code) || empty($this->country))) { - $ret.=($this->address?$this->address.$sep:''); - $ret.=trim($this->zip.' '.$this->town); - if ($withcountry) $ret.=($this->country?$sep.$this->country:''); + require_once(DOL_DOCUMENT_ROOT ."/core/lib/company.lib.php"); + $tmparray=getCountry($this->country_id,'all'); + $this->country_code=$tmparray['code']; + $this->country =$tmparray['label']; + } + + if (in_array($this->country_code,array('US'))) + { + $ret.=($this->address?$this->address.$sep:''); + $ret.=trim($this->zip.' '.$this->town); + if ($withcountry) $ret.=($this->country?$sep.$this->country:''); } else { - $ret.=($this->address?$this->address.$sep:''); - $ret.=trim($this->zip.' '.$this->town); - if ($withcountry) $ret.=($this->country?$sep.$this->country:''); + $ret.=($this->address?$this->address.$sep:''); + $ret.=trim($this->zip.' '.$this->town); + if ($withcountry) $ret.=($this->country?$sep.$this->country:''); } return trim($ret); } @@ -1913,10 +1927,11 @@ class Societe extends CommonObject /** * Verify if a profid exists into database for others thirds - * @param idprof 1,2,3,4 (Exemple: 1=siren,2=siret,3=naf,4=rcs/rm) - * @param value value of profid - * @param socid id of society if update - * @return boolean true if exists, false if not + * + * @param int $idprof 1,2,3,4 (Example: 1=siren,2=siret,3=naf,4=rcs/rm) + * @param string $value Value of profid + * @param int $socid Id of society if update + * @return boolean true if exists, false if not */ function id_prof_exists($idprof,$value,$socid=0) { diff --git a/htdocs/societe/soc.php b/htdocs/societe/soc.php index d205cfefb3d..a30531e35a9 100644 --- a/htdocs/societe/soc.php +++ b/htdocs/societe/soc.php @@ -234,11 +234,9 @@ if (empty($reshook)) $contact->firstname = $object->firstname; $contact->address = $object->address; $contact->zip = $object->zip; - $contact->cp = $object->cp; // TODO obsolete $contact->town = $object->town; - $contact->ville = $object->ville; // TODO obsolete - $contact->fk_departement = $object->state_id; - $contact->fk_pays = $object->country_id; + $contact->state_id = $object->state_id; + $contact->country_id = $object->country_id; $contact->socid = $object->id; // fk_soc $contact->status = 1; $contact->email = $object->email; diff --git a/test/phpunit/AdherentTest.php b/test/phpunit/AdherentTest.php index ef473d7d5c1..d0e68c1ba7e 100644 --- a/test/phpunit/AdherentTest.php +++ b/test/phpunit/AdherentTest.php @@ -158,10 +158,52 @@ class AdherentTest extends PHPUnit_Framework_TestCase $langs=$this->savlangs; $db=$this->savdb; + $localobject->login='newlogin'; + $localobject->societe='New company'; $localobject->note='New note after update'; - $result=$localobject->update($user); - print __METHOD__." id=".$localobject->id." result=".$result."\n"; - $this->assertLessThan($result, 0); + //$localobject->note_public='New note public after update'; + $localobject->lastname='New name'; + $localobject->firstname='New firstname'; + $localobject->address='New address'; + $localobject->zip='New zip'; + $localobject->town='New town'; + $localobject->country_id=2; + $localobject->statut=0; + $localobject->phone='New tel pro'; + $localobject->phone_perso='New tel perso'; + $localobject->phone_mobile='New tel mobile'; + $localobject->email='newemail@newemail.com'; + $result=$localobject->update($user); + print __METHOD__." id=".$localobject->id." result=".$result."\n"; + $this->assertLessThan($result, 0); + $result=$localobject->update_note($localobject->note); + print __METHOD__." id=".$localobject->id." result=".$result."\n"; + $this->assertLessThan($result, 0); + //$result=$localobject->update_note_public($localobject->note_public); + //print __METHOD__." id=".$localobject->id." result=".$result."\n"; + //$this->assertLessThan($result, 0); + + $newobject=new Adherent($this->savdb); + $result=$newobject->fetch($localobject->id); + print __METHOD__." id=".$localobject->id." result=".$result."\n"; + $this->assertLessThan($result, 0); + + $this->assertEquals($localobject->login, $newobject->login); + $this->assertEquals($localobject->societe, $newobject->societe); + $this->assertEquals($localobject->note, $newobject->note); + //$this->assertEquals($localobject->note_public, $newobject->note_public); + $this->assertEquals($localobject->lastname, $newobject->lastname); + $this->assertEquals($localobject->firstname, $newobject->firstname); + $this->assertEquals($localobject->address, $newobject->address); + $this->assertEquals($localobject->zip, $newobject->zip); + $this->assertEquals($localobject->town, $newobject->town); + $this->assertEquals($localobject->country_id, $newobject->country_id); + $this->assertEquals('BE', $newobject->country_code); + $this->assertEquals($localobject->statut, $newobject->statut); + $this->assertEquals($localobject->phone, $newobject->phone); + $this->assertEquals($localobject->phone_perso, $newobject->phone_perso); + $this->assertEquals($localobject->phone_mobile, $newobject->phone_mobile); + $this->assertEquals($localobject->email, $newobject->email); return $localobject; } diff --git a/test/phpunit/AllTests.php b/test/phpunit/AllTests.php index 83d8427396d..cb11567eac5 100644 --- a/test/phpunit/AllTests.php +++ b/test/phpunit/AllTests.php @@ -74,6 +74,8 @@ class AllTests require_once dirname(__FILE__).'/SocieteTest.php'; $suite->addTestSuite('SocieteTest'); + require_once dirname(__FILE__).'/ContactTest.php'; + $suite->addTestSuite('ContactTest'); require_once dirname(__FILE__).'/AdherentTest.php'; $suite->addTestSuite('AdherentTest'); diff --git a/test/phpunit/ContactTest.php b/test/phpunit/ContactTest.php new file mode 100755 index 00000000000..dcb989e8359 --- /dev/null +++ b/test/phpunit/ContactTest.php @@ -0,0 +1,283 @@ + + * + * 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 + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * or see http://www.gnu.org/ + */ + +/** + * \file test/phpunit/ContactTest.php + * \ingroup test + * \brief PHPUnit test + * \remarks To run this script as CLI: phpunit filename.php + */ + +global $conf,$user,$langs,$db; +//define('TEST_DB_FORCE_TYPE','mysql'); // This is to force using mysql driver +require_once 'PHPUnit/Autoload.php'; +require_once dirname(__FILE__).'/../../htdocs/master.inc.php'; +require_once dirname(__FILE__).'/../../htdocs/contact/class/contact.class.php'; +$langs->load("dict"); + +if (empty($user->id)) +{ + print "Load permissions for admin user nb 1\n"; + $user->fetch(1); + $user->getrights(); +} +$conf->global->MAIN_DISABLE_ALL_MAILS=1; + + +/** + * Class for PHPUnit tests + * + * @backupGlobals disabled + * @backupStaticAttributes enabled + * @remarks backupGlobals must be disabled to have db,conf,user and lang not erased. + */ +class ContactTest extends PHPUnit_Framework_TestCase +{ + protected $savconf; + protected $savuser; + protected $savlangs; + protected $savdb; + + /** + * Constructor + * We save global variables into local variables + * + * @return ContactTest + */ + function ContactTest() + { + //$this->sharedFixture + global $conf,$user,$langs,$db; + $this->savconf=$conf; + $this->savuser=$user; + $this->savlangs=$langs; + $this->savdb=$db; + + print __METHOD__." db->type=".$db->type." user->id=".$user->id; + //print " - db ".$db->db; + print "\n"; + } + + // Static methods + public static function setUpBeforeClass() + { + global $conf,$user,$langs,$db; + + $db->begin(); // This is to have all actions inside a transaction even if test launched without suite. + + print __METHOD__."\n"; + } + public static function tearDownAfterClass() + { + global $conf,$user,$langs,$db; + $db->rollback(); + + print __METHOD__."\n"; + } + + /** + */ + protected function setUp() + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; + + print __METHOD__."\n"; + } + /** + */ + protected function tearDown() + { + print __METHOD__."\n"; + } + + /** + */ + public function testContactCreate() + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; + + $localobject=new Contact($this->savdb); + $localobject->initAsSpecimen(); + $result=$localobject->create($user); + + print __METHOD__." result=".$result."\n"; + $this->assertLessThanOrEqual($result, 0); + + return $result; + } + + /** + * @depends testContactCreate + * The depends says test is run only if previous is ok + */ + public function testContactFetch($id) + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; + + $localobject=new Contact($this->savdb); + $result=$localobject->fetch($id); + print __METHOD__." id=".$id." result=".$result."\n"; + $this->assertLessThan($result, 0); + + return $localobject; + } + + /** + * @depends testContactFetch + * The depends says test is run only if previous is ok + */ + public function testContactUpdate($localobject) + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; + + $localobject->note='New note after update'; + //$localobject->note_public='New note public after update'; + $localobject->lastname='New name'; + $localobject->firstname='New firstname'; + $localobject->address='New address'; + $localobject->zip='New zip'; + $localobject->town='New town'; + $localobject->country_id=2; + $localobject->status=0; + $localobject->phone_pro='New tel pro'; + $localobject->phone_perso='New tel perso'; + $localobject->phone_mobile='New tel mobile'; + $localobject->fax='New fax'; + $localobject->email='newemail@newemail.com'; + $localobject->jabberid='New im id'; + $localobject->default_lang='es_ES'; + $result=$localobject->update($localobject->id,$user); + print __METHOD__." id=".$localobject->id." result=".$result."\n"; + $this->assertLessThan($result, 0); + $result=$localobject->update_note($localobject->note); + print __METHOD__." id=".$localobject->id." result=".$result."\n"; + $this->assertLessThan($result, 0); + //$result=$localobject->update_note_public($localobject->note_public); + //print __METHOD__." id=".$localobject->id." result=".$result."\n"; + //$this->assertLessThan($result, 0); + + $newobject=new Contact($this->savdb); + $result=$newobject->fetch($localobject->id); + print __METHOD__." id=".$localobject->id." result=".$result."\n"; + $this->assertLessThan($result, 0); + + $this->assertEquals($localobject->note, $newobject->note); + //$this->assertEquals($localobject->note_public, $newobject->note_public); + $this->assertEquals($localobject->lastname, $newobject->lastname); + $this->assertEquals($localobject->firstname, $newobject->firstname); + $this->assertEquals($localobject->address, $newobject->address); + $this->assertEquals($localobject->zip, $newobject->zip); + $this->assertEquals($localobject->town, $newobject->town); + $this->assertEquals($localobject->country_id, $newobject->country_id); + $this->assertEquals('BE', $newobject->country_code); + $this->assertEquals($localobject->status, $newobject->status); + $this->assertEquals($localobject->phone_pro, $newobject->phone_pro); + $this->assertEquals($localobject->phone_perso, $newobject->phone_perso); + $this->assertEquals($localobject->phone_mobile, $newobject->phone_mobile); + $this->assertEquals($localobject->fax, $newobject->fax); + $this->assertEquals($localobject->email, $newobject->email); + $this->assertEquals($localobject->jabberid, $newobject->jabberid); + $this->assertEquals($localobject->default_lang, $newobject->default_lang); + + return $localobject; + } + + /** + * @depends testContactUpdate + * The depends says test is run only if previous is ok + */ + public function testContactOther($localobject) + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; + + //$localobject->fetch($localobject->id); + + $result=$localobject->getNomUrl(1); + print __METHOD__." id=".$localobject->id." result=".$result."\n"; + $this->assertNotEquals($result, ''); + + $result=$localobject->getFullAddress(1); + print __METHOD__." id=".$localobject->id." result=".$result."\n"; + $this->assertContains("New address\nNew zip New town\nBelgium", $result); + + $localobject->info($localobject->id); + print __METHOD__." localobject->date_creation=".$localobject->date_creation."\n"; + $this->assertNotEquals($localobject->date_creation, ''); + + return $localobject->id; + } + + /** + * @depends testContactOther + * The depends says test is run only if previous is ok + */ + public function testContactDelete($id) + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; + + $localobject=new Contact($this->savdb); + $result=$localobject->fetch($id); + + $result=$localobject->delete($id); + print __METHOD__." id=".$id." result=".$result."\n"; + $this->assertLessThan($result, 0); + + return $result; + } + + /** + */ + public function testContactStatic() + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; + + $localobject=new Contact($db); + + + return; + } +} +?> \ No newline at end of file diff --git a/test/phpunit/SocieteTest.php b/test/phpunit/SocieteTest.php index d43ad86471d..53fd04d90cb 100755 --- a/test/phpunit/SocieteTest.php +++ b/test/phpunit/SocieteTest.php @@ -28,6 +28,7 @@ global $conf,$user,$langs,$db; require_once 'PHPUnit/Autoload.php'; require_once dirname(__FILE__).'/../../htdocs/master.inc.php'; require_once dirname(__FILE__).'/../../htdocs/societe/class/societe.class.php'; +$langs->load("dict"); if (empty($user->id)) { @@ -172,10 +173,11 @@ class SocieteTest extends PHPUnit_Framework_TestCase $localobject->address='New address'; $localobject->zip='New zip'; $localobject->town='New town'; + $localobject->country_id=2; $localobject->status=0; $localobject->tel='New tel'; $localobject->fax='New fax'; - $localobject->email='New email'; + $localobject->email='newemail@newemail.com'; $localobject->url='New url'; $localobject->idprof1='new idprof1'; $localobject->idprof2='new idprof2'; @@ -202,6 +204,8 @@ class SocieteTest extends PHPUnit_Framework_TestCase $this->assertEquals($localobject->address, $newobject->address); $this->assertEquals($localobject->zip, $newobject->zip); $this->assertEquals($localobject->town, $newobject->town); + $this->assertEquals($localobject->country_id, $newobject->country_id); + $this->assertEquals('BE', $newobject->country_code); $this->assertEquals($localobject->status, $newobject->status); $this->assertEquals($localobject->tel, $newobject->tel); $this->assertEquals($localobject->fax, $newobject->fax); @@ -243,9 +247,9 @@ class SocieteTest extends PHPUnit_Framework_TestCase print __METHOD__." id=".$localobject->id." result=".$result."\n"; $this->assertNotEquals($result, ''); - $result=$localobject->getFullAddress(); + $result=$localobject->getFullAddress(1); print __METHOD__." id=".$localobject->id." result=".$result."\n"; - $this->assertContains("New address\nNew zip New town", $result); + $this->assertContains("New address\nNew zip New town\nBelgium", $result); $result=$localobject->isInEEC(); print __METHOD__." id=".$localobject->id." country_code=".$this->country_code." result=".$result."\n"; From fd7d2fe667243a9a606b92371d88f589efd280f6 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 30 Dec 2011 14:27:18 +0100 Subject: [PATCH 02/10] Test format to removed scope warnings --- htdocs/admin/fournisseur.php | 686 ++++++++++++++++++----------------- 1 file changed, 345 insertions(+), 341 deletions(-) diff --git a/htdocs/admin/fournisseur.php b/htdocs/admin/fournisseur.php index ac2087bbf64..208ed58daaa 100644 --- a/htdocs/admin/fournisseur.php +++ b/htdocs/admin/fournisseur.php @@ -52,13 +52,13 @@ $specimenthirdparty->initAsSpecimen(); if ($action == 'updateMask') { - $maskconstorder=$_POST['maskconstorder']; - $maskorder=$_POST['maskorder']; - if ($maskconstorder) $res = dolibarr_set_const($db,$maskconstorder,$maskorder,'chaine',0,'',$conf->entity); + $maskconstorder=$_POST['maskconstorder']; + $maskorder=$_POST['maskorder']; + if ($maskconstorder) $res = dolibarr_set_const($db,$maskconstorder,$maskorder,'chaine',0,'',$conf->entity); - if (! $res > 0) $error++; + if (! $res > 0) $error++; - if (! $error) + if (! $error) { $mesg = "".$langs->trans("SetupSaved").""; } @@ -70,76 +70,76 @@ if ($action == 'updateMask') if ($action == 'specimen') // For orders { - $modele=GETPOST("module"); + $modele=GETPOST("module"); - $commande = new CommandeFournisseur($db); - $commande->initAsSpecimen(); + $commande = new CommandeFournisseur($db); + $commande->initAsSpecimen(); $commande->thirdparty=$specimenthirdparty; - // Charge le modele - $dir = "/core/modules/supplier_order/pdf/"; - $file = "pdf_".$modele.".modules.php"; - $file = dol_buildpath($dir.$file); - if (file_exists($file)) - { - $classname = "pdf_".$modele; - require_once($file); + // Charge le modele + $dir = "/core/modules/supplier_order/pdf/"; + $file = "pdf_".$modele.".modules.php"; + $file = dol_buildpath($dir.$file); + if (file_exists($file)) + { + $classname = "pdf_".$modele; + require_once($file); - $obj = new $classname($db,$commande); + $obj = new $classname($db,$commande); - if ($obj->write_file($commande,$langs) > 0) - { - header("Location: ".DOL_URL_ROOT."/document.php?modulepart=commande_fournisseur&file=SPECIMEN.pdf"); - return; - } - else - { - $mesg='
'.$obj->error.'
'; - dol_syslog($obj->error, LOG_ERR); - } - } - else - { - $mesg='
'.$langs->trans("ErrorModuleNotFound").'
'; - dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR); - } + if ($obj->write_file($commande,$langs) > 0) + { + header("Location: ".DOL_URL_ROOT."/document.php?modulepart=commande_fournisseur&file=SPECIMEN.pdf"); + return; + } + else + { + $mesg='
'.$obj->error.'
'; + dol_syslog($obj->error, LOG_ERR); + } + } + else + { + $mesg='
'.$langs->trans("ErrorModuleNotFound").'
'; + dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR); + } } if ($action == 'specimenfacture') // For invoices { - $modele=GETPOST("module"); + $modele=GETPOST("module"); - $facture = new FactureFournisseur($db); - $facture->initAsSpecimen(); + $facture = new FactureFournisseur($db); + $facture->initAsSpecimen(); $facture->thirdparty=$specimenthirdparty; // Define who should has build the invoice (so the supplier) - // Charge le modele - $dir = "/core/modules/supplier_invoice/pdf/"; - $file = "pdf_".$modele.".modules.php"; - $file = dol_buildpath($dir.$file); + // Charge le modele + $dir = "/core/modules/supplier_invoice/pdf/"; + $file = "pdf_".$modele.".modules.php"; + $file = dol_buildpath($dir.$file); if (file_exists($file)) - { - $classname = "pdf_".$modele; - require_once($file); + { + $classname = "pdf_".$modele; + require_once($file); - $obj = new $classname($db,$facture); + $obj = new $classname($db,$facture); - if ($obj->write_file($facture,$langs) > 0) - { - header("Location: ".DOL_URL_ROOT."/document.php?modulepart=facture_fournisseur&file=SPECIMEN.pdf"); - return; - } - else - { - $mesg='
'.$obj->error.'
'; - dol_syslog($obj->error, LOG_ERR); - } - } - else - { - $mesg='
'.$langs->trans("ErrorModuleNotFound").'
'; - dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR); - } + if ($obj->write_file($facture,$langs) > 0) + { + header("Location: ".DOL_URL_ROOT."/document.php?modulepart=facture_fournisseur&file=SPECIMEN.pdf"); + return; + } + else + { + $mesg='
'.$obj->error.'
'; + dol_syslog($obj->error, LOG_ERR); + } + } + else + { + $mesg='
'.$langs->trans("ErrorModuleNotFound").'
'; + dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR); + } } if ($action == 'set') @@ -149,87 +149,87 @@ if ($action == 'set') $sql.= ($_GET["label"]?"'".$db->escape($_GET["label"])."'":'null').", "; $sql.= (! empty($_GET["scandir"])?"'".$db->escape($_GET["scandir"])."'":"null"); $sql.= ")"; - $res=$db->query($sql); - if ($res) - { + $res=$db->query($sql); + if ($res) + { - } -// else dol_print_error($db); + } + // else dol_print_error($db); } if ($action == 'del') { - $sql = "DELETE FROM ".MAIN_DB_PREFIX."document_model"; - $sql.= " WHERE nom = '".$value."'"; - $sql.= " AND type = '".$type."'"; - $sql.= " AND entity = ".$conf->entity; - $db->query($sql); - if ($res) - { + $sql = "DELETE FROM ".MAIN_DB_PREFIX."document_model"; + $sql.= " WHERE nom = '".$value."'"; + $sql.= " AND type = '".$type."'"; + $sql.= " AND entity = ".$conf->entity; + $db->query($sql); + if ($res) + { - } -// else dol_print_error($db); + } + // else dol_print_error($db); } if ($action == 'setdoc') { - $db->begin(); + $db->begin(); - if ($_GET["type"] == 'order_supplier' && dolibarr_set_const($db, "COMMANDE_SUPPLIER_ADDON_PDF",$value,'chaine',0,'',$conf->entity)) - { - $conf->global->COMMANDE_SUPPLIER_ADDON_PDF = $value; - } + if ($_GET["type"] == 'order_supplier' && dolibarr_set_const($db, "COMMANDE_SUPPLIER_ADDON_PDF",$value,'chaine',0,'',$conf->entity)) + { + $conf->global->COMMANDE_SUPPLIER_ADDON_PDF = $value; + } - if ($_GET["type"] == 'invoice_supplier' && dolibarr_set_const($db, "INVOICE_SUPPLIER_ADDON_PDF",$value,'chaine',0,'',$conf->entity)) - { - $conf->global->INVOICE_SUPPLIER_ADDON_PDF = $value; - } + if ($_GET["type"] == 'invoice_supplier' && dolibarr_set_const($db, "INVOICE_SUPPLIER_ADDON_PDF",$value,'chaine',0,'',$conf->entity)) + { + $conf->global->INVOICE_SUPPLIER_ADDON_PDF = $value; + } - // On active le modele - $sql_del = "DELETE FROM ".MAIN_DB_PREFIX."document_model"; - $sql_del.= " WHERE nom = '".$db->escape($value)."'"; - $sql_del.= " AND type = '".$type."'"; - $sql_del.= " AND entity = ".$conf->entity; - $result1=$db->query($sql_del); + // On active le modele + $sql_del = "DELETE FROM ".MAIN_DB_PREFIX."document_model"; + $sql_del.= " WHERE nom = '".$db->escape($value)."'"; + $sql_del.= " AND type = '".$type."'"; + $sql_del.= " AND entity = ".$conf->entity; + $result1=$db->query($sql_del); $sql = "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity, libelle, description)"; $sql.= " VALUES ('".$db->escape($value)."', '".$type."', ".$conf->entity.", "; $sql.= ($_GET["label"]?"'".$db->escape($_GET["label"])."'":'null').", "; $sql.= (! empty($_GET["scandir"])?"'".$db->escape($_GET["scandir"])."'":"null"); $sql.= ")"; - $result2=$db->query($sql); - if ($result1 && $result2) - { - $db->commit(); - } - else - { - $db->rollback(); - } + $result2=$db->query($sql); + if ($result1 && $result2) + { + $db->commit(); + } + else + { + $db->rollback(); + } } if ($action == 'setmod') { - // TODO Verifier si module numerotation choisi peut etre active - // par appel methode canBeActivated + // TODO Verifier si module numerotation choisi peut etre active + // par appel methode canBeActivated - dolibarr_set_const($db, "COMMANDE_SUPPLIER_ADDON",$value,'chaine',0,'',$conf->entity); + dolibarr_set_const($db, "COMMANDE_SUPPLIER_ADDON",$value,'chaine',0,'',$conf->entity); } if ($action == 'addcat') { - $fourn = new Fournisseur($db); - $fourn->CreateCategory($user,$_POST["cat"]); + $fourn = new Fournisseur($db); + $fourn->CreateCategory($user,$_POST["cat"]); } if ($action == 'set_SUPPLIER_INVOICE_FREE_TEXT') { - $free = GETPOST("SUPPLIER_INVOICE_FREE_TEXT"); - $res = dolibarr_set_const($db, "SUPPLIER_INVOICE_FREE_TEXT",$free,'chaine',0,'',$conf->entity); + $free = GETPOST("SUPPLIER_INVOICE_FREE_TEXT"); + $res = dolibarr_set_const($db, "SUPPLIER_INVOICE_FREE_TEXT",$free,'chaine',0,'',$conf->entity); - if (! $res > 0) $error++; + if (! $res > 0) $error++; - if (! $error) + if (! $error) { $mesg = "".$langs->trans("SetupSaved").""; } @@ -238,6 +238,8 @@ if ($action == 'set_SUPPLIER_INVOICE_FREE_TEXT') $mesg = "".$langs->trans("Error").""; } } + + /* * View */ @@ -269,87 +271,89 @@ clearstatcache(); foreach ($conf->file->dol_document_root as $dirroot) { - $dir = $dirroot . "/core/modules/supplier_order/"; + $dir = $dirroot . "/core/modules/supplier_order/"; - if (is_dir($dir)) - { - $handle = opendir($dir); - if (is_resource($handle)) - { - $var=true; + if (is_dir($dir)) + { + $handle = opendir($dir); + if (is_resource($handle)) + { + $var=true; - while (($file = readdir($handle))!==false) - { - if (substr($file, 0, 25) == 'mod_commande_fournisseur_' && substr($file, dol_strlen($file)-3, 3) == 'php') - { - $file = substr($file, 0, dol_strlen($file)-4); + while (($file = readdir($handle))!==false) + { + if (substr($file, 0, 25) == 'mod_commande_fournisseur_' && substr($file, dol_strlen($file)-3, 3) == 'php') + { + $file = substr($file, 0, dol_strlen($file)-4); - require_once($dir.$file.".php"); + require_once($dir.$file.".php"); - $module = new $file; + $module = new $file; - if ($module->isEnabled()) - { - // Show modules according to features level - if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) continue; - if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) continue; + if ($module->isEnabled()) + { + // Show modules according to features level + if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) continue; + if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) continue; - $var=!$var; - print ''.$module->nom."\n"; - print $module->info(); - print ''; + $var=!$var; + print ''.$module->nom."\n"; + print $module->info(); + print ''; - // Show example of numbering module - print ''; + // Show example of numbering module + print ''; $tmp=$module->getExample(); - if (preg_match('/^Error/',$tmp)) { $langs->load("errors"); print '
'.$langs->trans($tmp).'
'; } + if (preg_match('/^Error/',$tmp)) { + $langs->load("errors"); print '
'.$langs->trans($tmp).'
'; + } elseif ($tmp=='NotConfigured') print $langs->trans($tmp); else print $tmp; - print ''."\n"; + print ''."\n"; - print ''; - if ($conf->global->COMMANDE_SUPPLIER_ADDON == "$file") - { - print img_picto($langs->trans("Activated"),'switch_on'); - } - else - { - print ''.img_picto($langs->trans("Disabled"),'switch_off').''; - } - print ''; + print ''; + if ($conf->global->COMMANDE_SUPPLIER_ADDON == "$file") + { + print img_picto($langs->trans("Activated"),'switch_on'); + } + else + { + print ''.img_picto($langs->trans("Disabled"),'switch_off').''; + } + print ''; - $commande=new CommandeFournisseur($db); - $commande->initAsSpecimen(); + $commande=new CommandeFournisseur($db); + $commande->initAsSpecimen(); - // Info - $htmltooltip=''; - $htmltooltip.=''.$langs->trans("Version").': '.$module->getVersion().'
'; - $facture->type=0; - $nextval=$module->getNextValue($mysoc,$commande); - if ("$nextval" != $langs->trans("NotAvailable")) // Keep " on nextval - { - $htmltooltip.=''.$langs->trans("NextValue").': '; - if ($nextval) - { - $htmltooltip.=$nextval.'
'; - } - else - { - $htmltooltip.=$langs->trans($module->error).'
'; - } - } + // Info + $htmltooltip=''; + $htmltooltip.=''.$langs->trans("Version").': '.$module->getVersion().'
'; + $facture->type=0; + $nextval=$module->getNextValue($mysoc,$commande); + if ("$nextval" != $langs->trans("NotAvailable")) // Keep " on nextval + { + $htmltooltip.=''.$langs->trans("NextValue").': '; + if ($nextval) + { + $htmltooltip.=$nextval.'
'; + } + else + { + $htmltooltip.=$langs->trans($module->error).'
'; + } + } - print ''; - print $form->textwithpicto('',$htmltooltip,1,0); - print ''; + print ''; + print $form->textwithpicto('',$htmltooltip,1,0); + print ''; - print ''; - } - } - } - closedir($handle); - } - } + print ''; + } + } + } + closedir($handle); + } + } } print '
'; @@ -374,18 +378,18 @@ $sql.= " AND entity = ".$conf->entity; $resql=$db->query($sql); if ($resql) { - $i = 0; - $num_rows=$db->num_rows($resql); - while ($i < $num_rows) - { - $array = $db->fetch_array($resql); - array_push($def, $array[0]); - $i++; - } + $i = 0; + $num_rows=$db->num_rows($resql); + while ($i < $num_rows) + { + $array = $db->fetch_array($resql); + array_push($def, $array[0]); + $i++; + } } else { - dol_print_error($db); + dol_print_error($db); } print ''."\n"; @@ -401,90 +405,90 @@ clearstatcache(); foreach ($conf->file->dol_document_root as $dirroot) { - $dir = $dirroot . "/core/modules/supplier_order/pdf/"; + $dir = $dirroot . "/core/modules/supplier_order/pdf/"; - if (is_dir($dir)) - { - $var=true; + if (is_dir($dir)) + { + $var=true; - $handle=opendir($dir); + $handle=opendir($dir); - if (is_resource($handle)) - { - while (($file = readdir($handle))!==false) - { - if (preg_match('/\.modules\.php$/i',$file) && substr($file,0,4) == 'pdf_') - { - $name = substr($file, 4, dol_strlen($file) -16); - $classname = substr($file, 0, dol_strlen($file) -12); + if (is_resource($handle)) + { + while (($file = readdir($handle))!==false) + { + if (preg_match('/\.modules\.php$/i',$file) && substr($file,0,4) == 'pdf_') + { + $name = substr($file, 4, dol_strlen($file) -16); + $classname = substr($file, 0, dol_strlen($file) -12); - $var=!$var; - print "\n"; - print "\n"; - print "\n"; + $var=!$var; + print "\n"; + print "\n"; + print "\n"; - // Active - if (in_array($name, $def)) - { - print '"; - } - else - { - print '"; - } + // Active + if (in_array($name, $def)) + { + print '"; + } + else + { + print '"; + } - // Defaut - print ''; + // Defaut + print ''; - // Info - $htmltooltip = ''.$langs->trans("Name").': '.$module->name; - $htmltooltip.='
'.$langs->trans("Type").': '.($module->type?$module->type:$langs->trans("Unknown")); - $htmltooltip.='
'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur; - $htmltooltip.='

'.$langs->trans("FeaturesSupported").':'; - $htmltooltip.='
'.$langs->trans("Logo").': '.yn($module->option_logo,1,1); - $htmltooltip.='
'.$langs->trans("PaymentMode").': '.yn($module->option_modereg,1,1); - $htmltooltip.='
'.$langs->trans("PaymentConditions").': '.yn($module->option_condreg,1,1); - print ''; - print ''; + // Info + $htmltooltip = ''.$langs->trans("Name").': '.$module->name; + $htmltooltip.='
'.$langs->trans("Type").': '.($module->type?$module->type:$langs->trans("Unknown")); + $htmltooltip.='
'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur; + $htmltooltip.='

'.$langs->trans("FeaturesSupported").':'; + $htmltooltip.='
'.$langs->trans("Logo").': '.yn($module->option_logo,1,1); + $htmltooltip.='
'.$langs->trans("PaymentMode").': '.yn($module->option_modereg,1,1); + $htmltooltip.='
'.$langs->trans("PaymentConditions").': '.yn($module->option_condreg,1,1); + print ''; + print ''; - print "\n"; - } - } + print "\n"; + } + } - closedir($handle); - } - } + closedir($handle); + } + } } print '
".$name."\n"; - require_once($dir.$file); - $module = new $classname($db,$specimenthirdparty); - print $module->description; - print "
".$name."\n"; + require_once($dir.$file); + $module = new $classname($db,$specimenthirdparty); + print $module->description; + print "'."\n"; - if ($conf->global->COMMANDE_SUPPLIER_ADDON_PDF != "$name") - { - print 'scandir.'&label='.urlencode($module->name).'&type=order_supplier">'; - print img_picto($langs->trans("Enabled"),'switch_on'); - print ''; - } - else - { - print img_picto($langs->trans("Enabled"),'switch_on'); - } - print "'."\n"; - print 'scandir.'&label='.urlencode($module->name).'&type=order_supplier">'.img_picto($langs->trans("Disabled"),'switch_off').''; - print "'."\n"; + if ($conf->global->COMMANDE_SUPPLIER_ADDON_PDF != "$name") + { + print 'scandir.'&label='.urlencode($module->name).'&type=order_supplier">'; + print img_picto($langs->trans("Enabled"),'switch_on'); + print ''; + } + else + { + print img_picto($langs->trans("Enabled"),'switch_on'); + } + print "'."\n"; + print 'scandir.'&label='.urlencode($module->name).'&type=order_supplier">'.img_picto($langs->trans("Disabled"),'switch_off').''; + print "'; - if ($conf->global->COMMANDE_SUPPLIER_ADDON_PDF == "$name") - { - print img_picto($langs->trans("Default"),'on'); - } - else - { - print 'scandir.'&label='.urlencode($module->name).'&type=order_supplier"" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"),'off').''; - } - print ''; + if ($conf->global->COMMANDE_SUPPLIER_ADDON_PDF == "$name") + { + print img_picto($langs->trans("Default"),'on'); + } + else + { + print 'scandir.'&label='.urlencode($module->name).'&type=order_supplier"" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"),'off').''; + } + print ''; - print $form->textwithpicto('',$htmltooltip,1,0); - print ''; - print ''.img_object($langs->trans("Preview"),'order').''; - print ''; + print $form->textwithpicto('',$htmltooltip,1,0); + print ''; + print ''.img_object($langs->trans("Preview"),'order').''; + print '

'; @@ -506,18 +510,18 @@ $sql.= " AND entity = ".$conf->entity; $resql=$db->query($sql); if ($resql) { - $i = 0; - $num_rows=$db->num_rows($resql); - while ($i < $num_rows) - { - $array = $db->fetch_array($resql); - array_push($def, $array[0]); - $i++; - } + $i = 0; + $num_rows=$db->num_rows($resql); + while ($i < $num_rows) + { + $array = $db->fetch_array($resql); + array_push($def, $array[0]); + $i++; + } } else { - dol_print_error($db); + dol_print_error($db); } @@ -534,88 +538,88 @@ clearstatcache(); foreach ($conf->file->dol_document_root as $dirroot) { - $dir = $dirroot . "/core/modules/supplier_invoice/pdf/"; + $dir = $dirroot . "/core/modules/supplier_invoice/pdf/"; - if (is_dir($dir)) - { - $var=true; + if (is_dir($dir)) + { + $var=true; - $handle=opendir($dir); + $handle=opendir($dir); - if (is_resource($handle)) - { - while (($file = readdir($handle)) !== false) - { - if (preg_match('/\.modules\.php$/i',$file) && substr($file,0,4) == 'pdf_') - { - $name = substr($file, 4, dol_strlen($file) -16); - $classname = substr($file, 0, dol_strlen($file) -12); + if (is_resource($handle)) + { + while (($file = readdir($handle)) !== false) + { + if (preg_match('/\.modules\.php$/i',$file) && substr($file,0,4) == 'pdf_') + { + $name = substr($file, 4, dol_strlen($file) -16); + $classname = substr($file, 0, dol_strlen($file) -12); - $var=!$var; - print "\n"; - print "".$name."\n"; - print ""; - require_once($dir.$file); - $module = new $classname($db,$specimenthirdparty); - print $module->description; - print "\n"; + $var=!$var; + print "\n"; + print "".$name."\n"; + print ""; + require_once($dir.$file); + $module = new $classname($db,$specimenthirdparty); + print $module->description; + print "\n"; - // Active - if (in_array($name, $def)) - { - print "\n"; - if ($conf->global->INVOICE_SUPPLIER_ADDON_PDF != "$name") - { - print 'scandir.'&label='.urlencode($module->name).'&type=invoice_supplier">'; - print img_picto($langs->trans("Enabled"),'switch_on'); - print ''; - } - else - { - print img_picto($langs->trans("Enabled"),'switch_on'); - } - print ""; - } - else - { - print "\n"; - print 'scandir.'&label='.urlencode($module->name).'&type=invoice_supplier">'.img_picto($langs->trans("Disabled"),'switch_off').''; - print ""; - } + // Active + if (in_array($name, $def)) + { + print "\n"; + if ($conf->global->INVOICE_SUPPLIER_ADDON_PDF != "$name") + { + print 'scandir.'&label='.urlencode($module->name).'&type=invoice_supplier">'; + print img_picto($langs->trans("Enabled"),'switch_on'); + print ''; + } + else + { + print img_picto($langs->trans("Enabled"),'switch_on'); + } + print ""; + } + else + { + print "\n"; + print 'scandir.'&label='.urlencode($module->name).'&type=invoice_supplier">'.img_picto($langs->trans("Disabled"),'switch_off').''; + print ""; + } - // Defaut - print ""; - if ($conf->global->INVOICE_SUPPLIER_ADDON_PDF == "$name") - { - print img_picto($langs->trans("Default"),'on'); - } - else - { - print 'scandir.'&label='.urlencode($module->name).'&type=invoice_supplier" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"),'off').''; - } - print ''; + // Defaut + print ""; + if ($conf->global->INVOICE_SUPPLIER_ADDON_PDF == "$name") + { + print img_picto($langs->trans("Default"),'on'); + } + else + { + print 'scandir.'&label='.urlencode($module->name).'&type=invoice_supplier" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"),'off').''; + } + print ''; - // Info - $htmltooltip = ''.$langs->trans("Name").': '.$module->name; - $htmltooltip.='
'.$langs->trans("Type").': '.($module->type?$module->type:$langs->trans("Unknown")); - $htmltooltip.='
'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur; - $htmltooltip.='

'.$langs->trans("FeaturesSupported").':'; - $htmltooltip.='
'.$langs->trans("Logo").': '.yn($module->option_logo,1,1); - $htmltooltip.='
'.$langs->trans("PaymentMode").': '.yn($module->option_modereg,1,1); - $htmltooltip.='
'.$langs->trans("PaymentConditions").': '.yn($module->option_condreg,1,1); - print ''; - print $form->textwithpicto('',$htmltooltip,1,0); - print ''; - print ''; - print ''.img_object($langs->trans("Preview"),'bill').''; - print ''; + // Info + $htmltooltip = ''.$langs->trans("Name").': '.$module->name; + $htmltooltip.='
'.$langs->trans("Type").': '.($module->type?$module->type:$langs->trans("Unknown")); + $htmltooltip.='
'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur; + $htmltooltip.='

'.$langs->trans("FeaturesSupported").':'; + $htmltooltip.='
'.$langs->trans("Logo").': '.yn($module->option_logo,1,1); + $htmltooltip.='
'.$langs->trans("PaymentMode").': '.yn($module->option_modereg,1,1); + $htmltooltip.='
'.$langs->trans("PaymentConditions").': '.yn($module->option_condreg,1,1); + print ''; + print $form->textwithpicto('',$htmltooltip,1,0); + print ''; + print ''; + print ''.img_object($langs->trans("Preview"),'bill').''; + print ''; - print "\n"; - } - } - closedir($handle); - } - } + print "\n"; + } + } + closedir($handle); + } + } } print '
'; @@ -641,7 +645,7 @@ print ''; dol_htmloutput_mesg($mesg); -$db->close(); - llxFooter(); + +$db->close(); ?> From 83acf605c306a230ccf48cae1f1da6ef3e816921 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 30 Dec 2011 14:32:33 +0100 Subject: [PATCH 03/10] Removed checkstyle rule --- dev/codesniffer/ruleset.xml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/dev/codesniffer/ruleset.xml b/dev/codesniffer/ruleset.xml index 839d7549048..e4e7962ab47 100755 --- a/dev/codesniffer/ruleset.xml +++ b/dev/codesniffer/ruleset.xml @@ -205,7 +205,10 @@ - + + 0 + + 0 From 00aa90606c1be7b512f7f905c5a00fbd6d64e5da Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 30 Dec 2011 14:45:07 +0100 Subject: [PATCH 04/10] Qual: Removed a FIXME --- htdocs/fourn/class/fournisseur.class.php | 16 +++++++++------- htdocs/fourn/fiche.php | 2 +- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/htdocs/fourn/class/fournisseur.class.php b/htdocs/fourn/class/fournisseur.class.php index ffce7ae6681..43ef033c532 100644 --- a/htdocs/fourn/class/fournisseur.class.php +++ b/htdocs/fourn/class/fournisseur.class.php @@ -2,7 +2,7 @@ /* Copyright (C) 2004-2007 Rodolphe Quiedeville * Copyright (C) 2006 Laurent Destailleur * Copyright (C) 2005-2009 Regis Houssin - * Copyright (C) 2011 Juanjo Menent + * Copyright (C) 2011 Juanjo Menent * * 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 @@ -82,19 +82,21 @@ class Fournisseur extends Societe } /** - * FIXME This returns number of prices, not number of products. Is it what we want ? + * Returns number of ref prices (not number of products). + * + * @return int Nb of ref prices, or <0 if error */ - function NbProduct() + function nbOfProductRefs() { - $sql = "SELECT count(pfp.rowid)"; + $sql = "SELECT count(pfp.rowid) as nb"; $sql.= " FROM ".MAIN_DB_PREFIX."product_fournisseur_price as pfp"; $sql .= " WHERE pfp.fk_soc = ".$this->id; $resql = $this->db->query($sql); if ( $resql ) { - $row = $this->db->fetch_row($resql); - return $row[0]; + $obj = $this->db->fetch_object($resql); + return $obj->nb; } else { @@ -104,7 +106,7 @@ class Fournisseur extends Societe /** * Create the order from an existing - * + * * @param User $user Creator user * @param int $idc Id source * @param int $comclientid Id thirdparty diff --git a/htdocs/fourn/fiche.php b/htdocs/fourn/fiche.php index a45b15d62b1..0afce405673 100644 --- a/htdocs/fourn/fiche.php +++ b/htdocs/fourn/fiche.php @@ -229,7 +229,7 @@ if ($object->fetch($id)) print ''; print ''; print '
'.$langs->trans("ProductsAndServices").''; - print ''.$langs->trans("All").' ('.$object->NbProduct().')'; + print ''.$langs->trans("All").' ('.$object->nbOfProductRefs().')'; print '
'; } From 903607126597cfeff282678bbc663dea3b0ac4a5 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 30 Dec 2011 20:15:13 +0100 Subject: [PATCH 05/10] Fix: W3C --- htdocs/cashdesk/index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/cashdesk/index.php b/htdocs/cashdesk/index.php index e8547706da8..b5a1a4fbfb1 100644 --- a/htdocs/cashdesk/index.php +++ b/htdocs/cashdesk/index.php @@ -123,7 +123,7 @@ if ($conf->stock->enabled)
-
+
From 4ea77e6d5532c78ede91c178b40560c0ba35536a Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 30 Dec 2011 23:07:27 +0100 Subject: [PATCH 06/10] Prepare code to allow left menu add by modules --- dev/skeletons/modMyModule.class.php | 8 +- htdocs/core/class/menubase.class.php | 83 ++++++++++++------- htdocs/core/menus/standard/eldy.lib.php | 12 +-- htdocs/core/modules/DolibarrModules.class.php | 11 ++- 4 files changed, 64 insertions(+), 50 deletions(-) diff --git a/dev/skeletons/modMyModule.class.php b/dev/skeletons/modMyModule.class.php index d94002a37b7..f0973d60c03 100644 --- a/dev/skeletons/modMyModule.class.php +++ b/dev/skeletons/modMyModule.class.php @@ -37,13 +37,13 @@ class modMyModule extends DolibarrModules /** * Constructor. Define names, constants, directories, boxes, permissions * - * @param DoliDB $DB Database handler + * @param DoliDB $db Database handler */ - function modMyModule($DB) + function modMyModule($db) { global $langs,$conf; - $this->db = $DB; + $this->db = $db; // Id for module (must be unique). // Use here a free id (See in Home -> System information -> Dolibarr for list of used modules id). @@ -184,7 +184,7 @@ class modMyModule extends DolibarrModules // $r++; // // Example to declare a Left Menu entry: - // $this->menu[$r]=array( 'fk_menu'=>'r=0', // Use r=value where r is index key used for the parent menu entry (higher parent must be a top menu entry) + // $this->menu[$r]=array( 'fk_menu'=>'r=0', // Use r=value where r is index key used for the parent menu entry (higher parent must be a top menu entry) or use 'fk_mainmenu=xxx,fk_leftmenu=yyy' // 'type'=>'left', // This is a Left menu entry // 'titre'=>'MyModule left menu 1', // 'mainmenu'=>'mymodule', diff --git a/htdocs/core/class/menubase.class.php b/htdocs/core/class/menubase.class.php index 166bd664c10..ea1a1db783e 100644 --- a/htdocs/core/class/menubase.class.php +++ b/htdocs/core/class/menubase.class.php @@ -85,9 +85,9 @@ class Menubase $this->menu_handler=trim($this->menu_handler); $this->module=trim($this->module); $this->type=trim($this->type); - $this->mainmenu=trim($this->mainmenu); + $this->mainmenu=trim($this->mainmenu); // If type='top' $this->leftmenu=trim($this->leftmenu); - $this->fk_menu=trim($this->fk_menu); + $this->fk_menu=trim($this->fk_menu); // If -1, fk_mainmenu and fk_leftmenu must be defined $this->fk_mainmenu=trim($this->fk_mainmenu); $this->fk_leftmenu=trim($this->fk_leftmenu); $this->position=trim($this->position); @@ -146,8 +146,8 @@ class Menubase $sql.= " '".$conf->entity."',"; $sql.= " '".$this->module."',"; $sql.= " '".$this->type."',"; - $sql.= " '".$this->mainmenu."',"; - $sql.= " '".$this->leftmenu."',"; + $sql.= " ".($this->mainmenu?"'".$this->mainmenu."'":"''").","; // Can't be null + $sql.= " ".($this->leftmenu?"'".$this->leftmenu."'":"null").","; $sql.= " '".$this->fk_menu."',"; $sql.= " ".($this->fk_mainmenu?"'".$this->fk_mainmenu."'":"null").","; $sql.= " ".($this->fk_leftmenu?"'".$this->fk_leftmenu."'":"null").","; @@ -392,22 +392,22 @@ class Menubase for ($x = 0; $x < $num; $x++) { //si un element a pour pere : $pere - if ($tab[$x][1] == $pere) + if ($tab[$x]['fk_menu'] == $pere) { - if ($tab[$x][7]) + if ($tab[$x]['enabled']) { $leftmenuConstraint = true; - if ($tab[$x][6]) + if ($tab[$x]['leftmenu']) { - $leftmenuConstraint = verifCond($tab[$x][6]); + $leftmenuConstraint = verifCond($tab[$x]['leftmenu']); } if ($leftmenuConstraint) { //print 'name='.$tab[$x][3].' pere='.$pere." ".$tab[$x][6]; - $this->newmenu->add((! preg_match("/^(http:\/\/|https:\/\/)/i",$tab[$x][2])) ? $tab[$x][2] : $tab[$x][2], $tab[$x][3], $rang -1, $tab[$x][4], $tab[$x][5], $tab[$x][8]); - $this->recur($tab, $tab[$x][0], $rang +1, $leftmenu); + $this->newmenu->add((! preg_match("/^(http:\/\/|https:\/\/)/i",$tab[$x]['url'])) ? $tab[$x]['url'] : $tab[$x]['url'], $tab[$x]['titre'], $rang -1, $tab[$x]['perms'], $tab[$x]['atarget'], $tab[$x]['mainmenu']); + $this->recur($tab, $tab[$x]['rowid'], $rang +1, $leftmenu); } } } @@ -443,20 +443,20 @@ class Menubase { foreach($tabMenu as $val) { - if ($val[9]=='top') + if ($val['type']=='top') { + $newTabMenu[$i]['rowid']=$val['rowid']; + $newTabMenu[$i]['fk_menu']=$val['fk_menu']; + $newTabMenu[$i]['url']=$val['url']; + $newTabMenu[$i]['titre']=$val['titre']; + $newTabMenu[$i]['right']=$val['perms']; + $newTabMenu[$i]['atarget']=$val['atarget']; + $newTabMenu[$i]['leftmenu']=$val['leftmenu']; + $newTabMenu[$i]['enabled']=$val['enabled']; + $newTabMenu[$i]['mainmenu']=$val['mainmenu']; + $newTabMenu[$i]['type']=$val['type']; + $newTabMenu[$i]['lang']=$val['langs']; - $newTabMenu[$i]['rowid']=$val[0]; - $newTabMenu[$i]['fk_menu']=$val[1]; - $newTabMenu[$i]['url']=$val[2]; - $newTabMenu[$i]['titre']=$val[3]; - $newTabMenu[$i]['right']=$val[4]; - $newTabMenu[$i]['atarget']=$val[5]; - $newTabMenu[$i]['leftmenu']=$val[6]; - $newTabMenu[$i]['enabled']=$val[7]; - $newTabMenu[$i]['mainmenu']=$val[8]; - $newTabMenu[$i]['type']=$val[9]; - $newTabMenu[$i]['lang']=$val[10]; $i++; } } @@ -469,7 +469,7 @@ class Menubase * Load entries found in database in a menu array. * * @param array $newmenu Menu array to complete (in most cases, it's empty, may be already initialized with some menu manager like eldy) - * @param string $mainmenu Value for mainmenu that defines top menu of left menu + * @param string $mainmenu Value for mainmenu that defines top menu of left menu to load * @param string $myleftmenu Value that defines leftmenu * @param int $type_user 0=Internal,1=External,2=All * @param string $menu_handler Name of menu_handler used (auguria, eldy...) @@ -483,9 +483,10 @@ class Menubase $leftmenu=$myleftmenu; // To export to dol_eval function + // We initialize newmenu to return with first already found menu entries $this->newmenu = $newmenu; - // Load datas into tabMenu + // Load datas from database into $tabMenu if (count($tabMenu) == 0) { $this->menuLoad($leftmenu, $type_user, $menu_handler, $tabMenu); @@ -498,9 +499,9 @@ class Menubase { foreach($tabMenu as $val) { - if ($val[9] == 'top' && $val[8] == $mainmenu) + if ($val['type'] == 'top' && $val['mainmenu'] == $mainmenu) // 9 is type, 8 is mainmenu { - $menutopid=$val[0]; + $menutopid=$val['rowid']; break; } } @@ -514,12 +515,12 @@ class Menubase /** - * Load entries found in database in a menu array. + * Load entries found in database to $tabMenu. * * @param string $myleftmenu Value for left that defined leftmenu * @param int $type_user 0=Internal,1=External,2=All * @param string $menu_handler Name of menu_handler used (auguria, eldy...) - * @param array &$tabMenu If array with menu entries already load, we put this array here (in most cases, it's empty) + * @param array &$tabMenu Array to store new entries found (in most cases, it's empty, but may be alreay filled) * @return int >0 if OK, <0 if KO */ function menuLoad($myleftmenu, $type_user, $menu_handler, &$tabMenu) @@ -530,7 +531,7 @@ class Menubase $menutopid=0; $leftmenu=$myleftmenu; // To export to dol_eval function - $sql = "SELECT m.rowid, m.type, m.fk_menu, m.url, m.titre, m.langs, m.perms, m.enabled, m.target, m.mainmenu, m.leftmenu"; + $sql = "SELECT m.rowid, m.type, m.fk_menu, m.fk_mainmenu, m.fk_leftmenu, m.url, m.titre, m.langs, m.perms, m.enabled, m.target, m.mainmenu, m.leftmenu"; $sql.= " FROM ".MAIN_DB_PREFIX."menu as m"; $sql.= " WHERE m.entity = ".$conf->entity; $sql.= " AND m.menu_handler in('".$menu_handler."','all')"; @@ -539,7 +540,7 @@ class Menubase // If type_user == 2, no test required $sql.= " ORDER BY m.position, m.rowid"; - dol_syslog("Menubase::menuLeftCharger sql=".$sql); + dol_syslog(get_class($this)."::menuLeftCharger sql=".$sql); $resql = $this->db->query($sql); if ($resql) { @@ -615,6 +616,28 @@ class Menubase $tabMenu[$b][9] = $menu['type']; $tabMenu[$b][10] = $menu['langs']; + // We complete tabMenu + $tabMenu[$b]['rowid'] = $menu['rowid']; + $tabMenu[$b]['fk_menu'] = $menu['fk_menu']; + $tabMenu[$b]['url'] = $menu['url']; + if (! preg_match("/^(http:\/\/|https:\/\/)/i",$tabMenu[$b]['url'])) + { + if (preg_match('/\?/',$tabMenu[$b]['url'])) $tabMenu[$b]['url'].='&idmenu='.$menu['rowid']; + else $tabMenu[$b]['url'].='?idmenu='.$menu['rowid']; + } + $tabMenu[$b]['titre'] = $chaine; + $tabMenu[$b]['target'] = $menu['target']; + $tabMenu[$b]['leftmenu'] = $menu['leftmenu']; + if (! isset($tabMenu[$b]['perms'])) $tabMenu[$b]['perms'] = $perms; + else $tabMenu[$b]['perms'] = ($tabMenu[$b]['perms'] && $perms); + if (! isset($tabMenu[$b]['enabled'])) $tabMenu[$b]['enabled'] = $enabled; + else $tabMenu[$b]['enabled'] = ($tabMenu[$b]['enabled'] && $enabled); + $tabMenu[$b]['mainmenu'] = $menu['mainmenu']; + $tabMenu[$b]['type'] = $menu['type']; + $tabMenu[$b]['langs'] = $menu['langs']; + $tabMenu[$b]['fk_mainmenu'] = $menu['fk_mainmenu']; + $tabMenu[$b]['fk_leftmenu'] = $menu['fk_leftmenu']; + $b++; $a++; } diff --git a/htdocs/core/menus/standard/eldy.lib.php b/htdocs/core/menus/standard/eldy.lib.php index 9d7f4df5918..1fcbab35497 100644 --- a/htdocs/core/menus/standard/eldy.lib.php +++ b/htdocs/core/menus/standard/eldy.lib.php @@ -1257,22 +1257,14 @@ function print_left_eldy_menu($db,$menu_array_before,$menu_array_after) $newmenu->add("/imports/import.php?leftmenu=import",$langs->trans("NewImport"),1, $user->rights->import->run); } - if (! empty($conf->domain->enabled)) - { - $langs->load("domains"); - $newmenu->add("/domain/index.php?leftmenu=export",$langs->trans("DomainNames"),0, $user->rights->domain->read); - $newmenu->add("/domain/fiche.php?action=create&leftmenu=export",$langs->trans("NewDomain"),1, $user->rights->domain->create); - $newmenu->add("/domain/index.php?leftmenu=export",$langs->trans("List"),1, $user->rights->domain->read); - } - - if (! empty($conf->submiteverywhere->enabled)) + /*if (! empty($conf->submiteverywhere->enabled)) { $langs->load("submiteverywhere@submiteverywhere"); $newmenu->add("/submiteverywhere/index.php?leftmenu=submiteverywhere", $langs->trans("News"), 0, $user->rights->submiteverywhere->read); $newmenu->add("/submiteverywhere/fiche.php?leftmenu=submiteverywhere&action=create", $langs->trans("NewNews"), 1, $user->rights->submiteverywhere->create); $newmenu->add("/submiteverywhere/liste.php?leftmenu=submiteverywhere", $langs->trans("List"), 1, $user->rights->submiteverywhere->read); - } + }*/ } /* diff --git a/htdocs/core/modules/DolibarrModules.class.php b/htdocs/core/modules/DolibarrModules.class.php index e9541291e26..3f90ddaf06b 100644 --- a/htdocs/core/modules/DolibarrModules.class.php +++ b/htdocs/core/modules/DolibarrModules.class.php @@ -92,7 +92,7 @@ abstract class DolibarrModules // Insert permission definitions of module into llx_rights_def. If user is admin, grant this permission to user. if (! $err) $err+=$this->insert_permissions(1); - // Insere les constantes associees au module dans llx_const + // Insert specific menus entries into database if (! $err) $err+=$this->insert_menus(); // Create module's directories @@ -1090,7 +1090,7 @@ abstract class DolibarrModules function insert_menus() { global $user; - + require_once(DOL_DOCUMENT_ROOT."/core/class/menubase.class.php"); $err=0; @@ -1122,7 +1122,7 @@ abstract class DolibarrModules $foundparent=1; } } - elseif (preg_match('/mainmenu=(.*),leftmenu=(.*)/',$fk_parent,$reg)) + elseif (preg_match('/fk_mainmenu=(.*),fk_leftmenu=(.*)/',$fk_parent,$reg)) { $menu->fk_menu=-1; $menu->fk_mainmenu=$reg[1]; @@ -1138,15 +1138,14 @@ abstract class DolibarrModules } $menu->type=$this->menu[$key]['type']; $menu->mainmenu=$this->menu[$key]['mainmenu']; + $menu->leftmenu=isset($this->menu[$key]['leftmenu'])?$this->menu[$key]['leftmenu']:''; $menu->titre=$this->menu[$key]['titre']; - $menu->leftmenu=isset($this->menu[$key]['leftmenu'])?$this->menu[$key]['leftmenu']:0; $menu->url=$this->menu[$key]['url']; $menu->langs=$this->menu[$key]['langs']; $menu->position=$this->menu[$key]['position']; $menu->perms=$this->menu[$key]['perms']; $menu->target=$this->menu[$key]['target']; $menu->user=$this->menu[$key]['user']; - //$menu->constraint=$this->menu[$key]['constraint']; $menu->enabled=isset($this->menu[$key]['enabled'])?$this->menu[$key]['enabled']:0; if (! $err) @@ -1159,7 +1158,7 @@ abstract class DolibarrModules else { $this->error=$menu->error; - dol_syslog('DolibarrModules::insert_menus result='.$result." ".$this->error, LOG_ERR); + dol_syslog(get_class($this).'::insert_menus result='.$result." ".$this->error, LOG_ERR); $err++; break; } From af4627d5edc1b7c21eb522e1785cba584bd6602b Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 31 Dec 2011 00:31:40 +0100 Subject: [PATCH 07/10] Removed dead code --- htdocs/core/menus/standard/eldy.lib.php | 9 --------- 1 file changed, 9 deletions(-) diff --git a/htdocs/core/menus/standard/eldy.lib.php b/htdocs/core/menus/standard/eldy.lib.php index 1fcbab35497..9a5b8018801 100644 --- a/htdocs/core/menus/standard/eldy.lib.php +++ b/htdocs/core/menus/standard/eldy.lib.php @@ -1256,15 +1256,6 @@ function print_left_eldy_menu($db,$menu_array_before,$menu_array_after) $newmenu->add("/imports/index.php?leftmenu=import",$langs->trans("FormatedImport"),0, $user->rights->import->run); $newmenu->add("/imports/import.php?leftmenu=import",$langs->trans("NewImport"),1, $user->rights->import->run); } - - /*if (! empty($conf->submiteverywhere->enabled)) - { - $langs->load("submiteverywhere@submiteverywhere"); - - $newmenu->add("/submiteverywhere/index.php?leftmenu=submiteverywhere", $langs->trans("News"), 0, $user->rights->submiteverywhere->read); - $newmenu->add("/submiteverywhere/fiche.php?leftmenu=submiteverywhere&action=create", $langs->trans("NewNews"), 1, $user->rights->submiteverywhere->create); - $newmenu->add("/submiteverywhere/liste.php?leftmenu=submiteverywhere", $langs->trans("List"), 1, $user->rights->submiteverywhere->read); - }*/ } /* From 92c27b1732a21c301bafb2acc5d50c208bc71790 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 31 Dec 2011 01:33:12 +0100 Subject: [PATCH 08/10] New: Can add a left menu (first level) into an existing top menu. --- ChangeLog | 17 +++-- dev/skeletons/modMyModule.class.php | 15 ++-- htdocs/core/class/menubase.class.php | 76 +++++++++++++------ htdocs/core/modules/DolibarrModules.class.php | 7 ++ 4 files changed, 75 insertions(+), 40 deletions(-) diff --git a/ChangeLog b/ChangeLog index f0a0b1264da..ee63510305b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -35,22 +35,23 @@ For users: - Fix: Can use POS module with several concurrent users. For developers: -- New: Add webservice to get or create a product, service. -- New: Add webservice to get a user. -- New: Add hooks to change way of showing/editing lines into dictionnaries. +- New: Can add a left menu (first level) into an existing top menu. - New: Add webservice to get or create a product or service. +- New: Add webservice to get a user. +- New: Add more "hooks" (like hooks to change way of showing/editing lines into dictionnaries). - New: Log module outputs can be setup with "or" rule (not only "xor"). - New: Add FirePHP output for logging module. -- New: Add trigger ACTION_DELETE and ACTION_MODIFY +- New: Add trigger ACTION_DELETE and ACTION_MODIFY. - New: Can define different requests according to database type into migration files. +- New: Add "canvas" feature to overwrite page of thirdparty, contact, product with yours. +- Qual: Add a lot of more PHPUnit tests. - Qual: Data structure for supplier prices is simpler. - Qual: Removed no more used external libraries. - Qual: Cleaned a lot of dead code. -- Qual: Add more "hooks". -- Qual: Add "canvas" feature to overwrite page of thirdparty, contact, product with yours. - Qual: More OOP (usage of "abstract", "static", ...), uniformize constructors. -- Qual: task #216 : Move /lib in /core/lib directory -- Qual: task #217 : Move core files in core directory (login, menus, triggers, boxes, modules) +- Qual: Fix a lot of checkstyle warnings. +- Qual: task #216 : Move /lib into /core/lib directory +- Qual: task #217 : Move core files into core directory (login, menus, triggers, boxes, modules) ***** ChangeLog for 3.1 compared to 3.0 ***** diff --git a/dev/skeletons/modMyModule.class.php b/dev/skeletons/modMyModule.class.php index f0973d60c03..d0c9daabeb5 100644 --- a/dev/skeletons/modMyModule.class.php +++ b/dev/skeletons/modMyModule.class.php @@ -169,7 +169,8 @@ class modMyModule extends DolibarrModules $r=0; // Add here entries to declare new menus - // Example to declare the Top Menu entry: + // + // Example to declare a new Top Menu entry and its Left menu entry: // $this->menu[$r]=array( 'fk_menu'=>0, // Put 0 if this is a top menu // 'type'=>'top', // This is a Top menu entry // 'titre'=>'MyModule top menu', @@ -182,11 +183,9 @@ class modMyModule extends DolibarrModules // 'target'=>'', // 'user'=>2); // 0=Menu for internal users, 1=external users, 2=both // $r++; - // - // Example to declare a Left Menu entry: - // $this->menu[$r]=array( 'fk_menu'=>'r=0', // Use r=value where r is index key used for the parent menu entry (higher parent must be a top menu entry) or use 'fk_mainmenu=xxx,fk_leftmenu=yyy' + // $this->menu[$r]=array( 'fk_menu'=>'r=0', // Use r=value where r is index key used for the parent menu entry (higher parent must be a top menu entry) // 'type'=>'left', // This is a Left menu entry - // 'titre'=>'MyModule left menu 1', + // 'titre'=>'MyModule left menu', // 'mainmenu'=>'mymodule', // 'url'=>'/mymodule/pagelevel1.php', // 'langs'=>'mylangfile', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory. @@ -197,10 +196,10 @@ class modMyModule extends DolibarrModules // 'user'=>2); // 0=Menu for internal users, 1=external users, 2=both // $r++; // - // Example to declare another Left Menu entry: - // $this->menu[$r]=array( 'fk_menu'=>'r=1', // Use r=value where r is index key used for the parent menu entry (higher parent must be a top menu entry) + // Example to declare a Left Menu entry into an existing Top menu entry: + // $this->menu[$r]=array( 'fk_menu'=>'fk_mainmenu=mainmenucode', // Use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' // 'type'=>'left', // This is a Left menu entry - // 'titre'=>'MyModule left menu 2', + // 'titre'=>'MyModule left menu', // 'mainmenu'=>'mymodule', // 'url'=>'/mymodule/pagelevel2.php', // 'langs'=>'mylangfile', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory. diff --git a/htdocs/core/class/menubase.class.php b/htdocs/core/class/menubase.class.php index ea1a1db783e..0c2b9804600 100644 --- a/htdocs/core/class/menubase.class.php +++ b/htdocs/core/class/menubase.class.php @@ -392,24 +392,11 @@ class Menubase for ($x = 0; $x < $num; $x++) { //si un element a pour pere : $pere - if ($tab[$x]['fk_menu'] == $pere) + if ($tab[$x]['fk_menu'] == $pere && $tab[$x]['enabled']) { - if ($tab[$x]['enabled']) - { - $leftmenuConstraint = true; - if ($tab[$x]['leftmenu']) - { - $leftmenuConstraint = verifCond($tab[$x]['leftmenu']); - } - - if ($leftmenuConstraint) - { - //print 'name='.$tab[$x][3].' pere='.$pere." ".$tab[$x][6]; - - $this->newmenu->add((! preg_match("/^(http:\/\/|https:\/\/)/i",$tab[$x]['url'])) ? $tab[$x]['url'] : $tab[$x]['url'], $tab[$x]['titre'], $rang -1, $tab[$x]['perms'], $tab[$x]['atarget'], $tab[$x]['mainmenu']); - $this->recur($tab, $tab[$x]['rowid'], $rang +1, $leftmenu); - } - } + //print 'mainmenu='.$tab[$x]['mainmenu']; + $this->newmenu->add($tab[$x]['url'], $tab[$x]['titre'], $rang - 1, $tab[$x]['perms'], $tab[$x]['atarget'], $tab[$x]['mainmenu']); + $this->recur($tab, $tab[$x]['rowid'], $rang + 1, $leftmenu); } } } @@ -483,23 +470,23 @@ class Menubase $leftmenu=$myleftmenu; // To export to dol_eval function - // We initialize newmenu to return with first already found menu entries + // We initialize newmenu with first already found menu entries $this->newmenu = $newmenu; - // Load datas from database into $tabMenu + // Load datas from database into $tabMenu, then we will complete this->newmenu with values into $tabMenu if (count($tabMenu) == 0) { $this->menuLoad($leftmenu, $type_user, $menu_handler, $tabMenu); } //var_dump($tabMenu); - // Define menutopid $menutopid=''; if (is_array($tabMenu)) { - foreach($tabMenu as $val) + foreach($tabMenu as $key => $val) { - if ($val['type'] == 'top' && $val['mainmenu'] == $mainmenu) // 9 is type, 8 is mainmenu + // Define menutopid of mainmenu + if (empty($menutopid) && $val['type'] == 'top' && $val['mainmenu'] == $mainmenu) // 9 is type, 8 is mainmenu { $menutopid=$val['rowid']; break; @@ -507,8 +494,48 @@ class Menubase } } - // Now edit this->newmenu->list to add entries found into tabMenu that are in childs of mainmenu claimed + // Update fk_menu when value is -1 (left menu added by modules with no top menu) + if (is_array($tabMenu)) + { + foreach($tabMenu as $key => $val) + { + if ($val['fk_menu'] == -1 && $val['fk_mainmenu'] == $mainmenu) + { + if (empty($val['fk_leftmenu'])) + { + //print 'Try to find fk_menu for '.join(',',$val); + //var_dump($this->newmenu->liste);exit; + $tabMenu[$key]['fk_menu']=$menutopid; + } + else if ($val['fk_leftmenu'] == $fk_leftmenu) + { + // TODO + /* + foreach($this->newmenu as $keyparent => $valparent) + { + if (empty($val['fk_leftmenu']) && $valparent['type'] == 'top' && $valparent['mainmenu'] == $val['fk_mainmenu']) + { + $tabMenu[$key]['fk_menu']=$valparent['rowid']; + break; + } + //var_dump($tabMenu);exit; + if (! empty($val['fk_leftmenu']) && $valparent['type'] == 'left' && $valparent['mainmenu'] == $val['fk_mainmenu'] && $valparent['leftmenu'] == $val['fk_leftmenu']) + { + print 'eeee'; + $tabMenu[$key]['fk_menu']=$valparent['rowid']; + break; + } + } + */ + //exit; + } + } + } + } + + // Now edit this->newmenu->list to add entries found into tabMenu that are childs of mainmenu claimed $this->recur($tabMenu, $menutopid, 1, $leftmenu); + //var_dump($this->newmenu->liste);exit; return $this->newmenu; } @@ -596,6 +623,7 @@ class Menubase //print "verifCond chaine=".$chaine." rowid=".$menu['rowid']." ".$menu['enabled'].":".$enabled."
\n"; } +/* // 0=rowid, 1=fk_menu, 2=url, 3=text, 4=perms, 5=target, 8=mainmenu $tabMenu[$b][0] = $menu['rowid']; $tabMenu[$b][1] = $menu['fk_menu']; @@ -615,7 +643,7 @@ class Menubase $tabMenu[$b][8] = $menu['mainmenu']; $tabMenu[$b][9] = $menu['type']; $tabMenu[$b][10] = $menu['langs']; - +*/ // We complete tabMenu $tabMenu[$b]['rowid'] = $menu['rowid']; $tabMenu[$b]['fk_menu'] = $menu['fk_menu']; diff --git a/htdocs/core/modules/DolibarrModules.class.php b/htdocs/core/modules/DolibarrModules.class.php index 3f90ddaf06b..dff911efe48 100644 --- a/htdocs/core/modules/DolibarrModules.class.php +++ b/htdocs/core/modules/DolibarrModules.class.php @@ -1129,6 +1129,13 @@ abstract class DolibarrModules $menu->fk_leftmenu=$reg[2]; $foundparent=1; } + elseif (preg_match('/fk_mainmenu=(.*)/',$fk_parent,$reg)) + { + $menu->fk_menu=-1; + $menu->fk_mainmenu=$reg[1]; + $menu->fk_leftmenu=''; + $foundparent=1; + } if (! $foundparent) { $this->error="ErrorBadDefinitionOfMenuArrayInModuleDescriptor (bad value for key fk_menu)"; From 680d4bac44aca92922a6fc199e570c420c78d401 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 31 Dec 2011 02:30:20 +0100 Subject: [PATCH 09/10] Fix: mime type --- htdocs/core/lib/files.lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/lib/files.lib.php b/htdocs/core/lib/files.lib.php index c9fa9d4e54a..6225c0cc501 100644 --- a/htdocs/core/lib/files.lib.php +++ b/htdocs/core/lib/files.lib.php @@ -237,7 +237,7 @@ function dol_mimetype($file,$default='application/octet-stream',$mode=0) if (preg_match('/\.xlt(x)?$/i',$tmpfile)) { $mime='application/vnd.ms-excel'; $imgmime='xls.png'; } if (preg_match('/\.xla(m)?$/i',$tmpfile)) { $mime='application/vnd.ms-excel'; $imgmime='xls.png'; } if (preg_match('/\.xls$/i',$tmpfile)) { $mime='application/vnd.ms-excel'; $imgmime='xls.png'; } - if (preg_match('/\.xls(b|m|x)?$/i',$tmpfile)) { $mime='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'; $imgmime='xls.png'; } + if (preg_match('/\.xls(b|m|x)$/i',$tmpfile)) { $mime='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'; $imgmime='xls.png'; } if (preg_match('/\.pps(m|x)?$/i',$tmpfile)) { $mime='application/vnd.ms-powerpoint'; $imgmime='ppt.png'; } if (preg_match('/\.ppt(m|x)?$/i',$tmpfile)) { $mime='application/x-mspowerpoint'; $imgmime='ppt.png'; } // Other From 700c83125e3075be837e0dc1d5b23e88c15d950f Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 31 Dec 2011 02:50:37 +0100 Subject: [PATCH 10/10] New: Add file size and description into download wrapper --- htdocs/document.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/htdocs/document.php b/htdocs/document.php index 7e4ad347a01..ecac2268886 100644 --- a/htdocs/document.php +++ b/htdocs/document.php @@ -535,15 +535,19 @@ else // Open and return file // Les drois sont ok et fichier trouve, on l'envoie + header('Content-Description: File Transfer'); if ($encoding) header('Content-Encoding: '.$encoding); if ($type) header('Content-Type: '.$type.(preg_match('/text/',$type)?'; charset="'.$conf->file->character_set_client:'')); if ($attachment) header('Content-Disposition: attachment; filename="'.$filename.'"'); else header('Content-Disposition: inline; filename="'.$filename.'"'); - + header('Content-Length: ' . dol_filesize($original_file)); // Ajout directives pour resoudre bug IE header('Cache-Control: Public, must-revalidate'); header('Pragma: public'); + //ob_clean(); + //flush(); + readfile($original_file_osencoded); }