From fb2e7c063e4f706e0a59c82547ecaa6b43469d78 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 22 Jun 2011 16:24:20 +0000 Subject: [PATCH] New: Can use extrafields on third parties. --- ChangeLog | 1 + .../adherent_extrafields.php} | 39 ++- htdocs/adherents/class/adherent.class.php | 8 +- htdocs/adherents/fiche.php | 2 - htdocs/admin/societe.php | 11 +- htdocs/admin/societe_extrafields.php | 315 ++++++++++++++++++ htdocs/core/class/extrafields.class.php | 8 +- htdocs/lib/company.lib.php | 34 ++ htdocs/lib/member.lib.php | 2 +- htdocs/societe/class/societe.class.php | 148 +++++--- htdocs/societe/soc.php | 11 +- 11 files changed, 494 insertions(+), 85 deletions(-) rename htdocs/adherents/{options.php => admin/adherent_extrafields.php} (89%) mode change 100644 => 100755 create mode 100755 htdocs/admin/societe_extrafields.php diff --git a/ChangeLog b/ChangeLog index 5314f67397f..d721ec3a8eb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -71,6 +71,7 @@ For users: - New: task #9744 : Add the barcode to select products on Point of Sale module - New: Subscription/Unsubscription to mailman mailing-list can be done on validate/resiliate in foundation module. +- New: Can use extrafields on third parties. - Fix: Better Postgresql compatibility. - Fix: Numbering module for invoices use same number for invoice and credit note if mask is same. diff --git a/htdocs/adherents/options.php b/htdocs/adherents/admin/adherent_extrafields.php old mode 100644 new mode 100755 similarity index 89% rename from htdocs/adherents/options.php rename to htdocs/adherents/admin/adherent_extrafields.php index c20a8ccc531..1cd2f89cfad --- a/htdocs/adherents/options.php +++ b/htdocs/adherents/admin/adherent_extrafields.php @@ -1,7 +1,7 @@ * Copyright (C) 2003 Jean-Louis Bergamo - * Copyright (C) 2004-2009 Laurent Destailleur + * Copyright (C) 2004-2011 Laurent Destailleur * * 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 @@ -19,13 +19,13 @@ */ /** - * \file htdocs/adherents/options.php + * \file htdocs/adherents/admin/adherent_extrafields.php * \ingroup member - * \brief Page de configuratin des champs optionnels + * \brief Page to setup extra fields of members * \version $Id$ */ -require("../main.inc.php"); +require("../../main.inc.php"); require_once(DOL_DOCUMENT_ROOT."/lib/member.lib.php"); require_once(DOL_DOCUMENT_ROOT."/core/class/extrafields.class.php"); @@ -47,12 +47,15 @@ $type2label=array( $action=GETPOST("action"); $elementtype='member'; +if (!$user->admin) +accessforbidden(); + /* * Actions */ -if ($action == 'add' && $user->rights->adherent->configurer) +if ($action == 'add') { if ($_POST["button"] != $langs->trans("Cancel")) { @@ -94,7 +97,7 @@ if ($action == 'add' && $user->rights->adherent->configurer) } // Rename field -if ($action == 'update' && $user->rights->adherent->configurer) +if ($action == 'update') { if ($_POST["button"] != $langs->trans("Cancel")) { @@ -138,13 +141,17 @@ if ($action == 'update' && $user->rights->adherent->configurer) } # Suppression attribut -if ($action == 'delete' && $user->rights->adherent->configurer) +if ($action == 'delete') { if(isset($_GET["attrname"]) && preg_match("/^\w[a-zA-Z0-9-_]*$/",$_GET["attrname"])) { - $extrafields->delete($_GET["attrname"],$elementtype); - Header("Location: ".$_SERVER["PHP_SELF"]); - exit; + $result=$extrafields->delete($_GET["attrname"],$elementtype); + if ($result >= 0) + { + Header("Location: ".$_SERVER["PHP_SELF"]); + exit; + } + else $mesg=$extrafields->error; } else { @@ -180,7 +187,7 @@ print '
'; dol_htmloutput_errors($mesg); // Load attribute_label -$extrafields->fetch_name_optionals_label(); +$extrafields->fetch_name_optionals_label($elementtype); print ""; @@ -201,8 +208,8 @@ foreach($extrafields->attribute_type as $key => $value) print "\n"; print "\n"; print '\n"; - print '\n"; + print '\n"; print ""; // $i++; } @@ -218,7 +225,7 @@ dol_fiche_end(); if ($action != 'create' && $action != 'edit') { print '"; } @@ -234,7 +241,7 @@ if ($action == 'create') print "
"; print_titre($langs->trans('NewAttribute')); - print ''; + print ''; print ''; print '
".$key."".$type2label[$extrafields->attribute_type[$key]]."'.$extrafields->attribute_size[$key]."'.img_edit().''; - print "  ".img_delete()."'.img_edit().''; + print "  ".img_delete()."
'; @@ -270,7 +277,7 @@ if ($_GET["attrname"] && $action == 'edit') /* * formulaire d'edition */ - print ''; + print ''; print ''; print ''; print ''; diff --git a/htdocs/adherents/class/adherent.class.php b/htdocs/adherents/class/adherent.class.php index e13fadb44cf..f00eac17f9a 100644 --- a/htdocs/adherents/class/adherent.class.php +++ b/htdocs/adherents/class/adherent.class.php @@ -421,6 +421,8 @@ class Adherent extends CommonObject { $nbrowsaffected+=$this->db->affected_rows($resql); + // Add/Update extra fields + // TODO Run a method into commonobject if (sizeof($this->array_options) > 0) { $sql_del = "DELETE FROM ".MAIN_DB_PREFIX."adherent_extrafields WHERE fk_object = ".$this->id; @@ -450,11 +452,7 @@ class Adherent extends CommonObject dol_syslog(get_class($this)."::update update option sql=".$sql); $resql = $this->db->query($sql); - if ($resql) - { - $nbrowsaffected+=1; - } - else + if (! $resql) { $this->error=$this->db->error(); dol_syslog(get_class($this)."::update ".$this->error,LOG_ERR); diff --git a/htdocs/adherents/fiche.php b/htdocs/adherents/fiche.php index bcb6e394ce5..7a01db892db 100644 --- a/htdocs/adherents/fiche.php +++ b/htdocs/adherents/fiche.php @@ -404,8 +404,6 @@ if ($_POST["action"] == 'add' && $user->rights->adherent->creer) { if (preg_match("/^options_/",$key)) { - //escape values from POST, at least with $db->escape, to avoid obvious SQL injections - //(array_options is directly input in the DB in adherent.class.php::update()) $adh->array_options[$key]=$_POST[$key]; } } diff --git a/htdocs/admin/societe.php b/htdocs/admin/societe.php index 2b312f76127..d5c45d54f13 100644 --- a/htdocs/admin/societe.php +++ b/htdocs/admin/societe.php @@ -1,7 +1,7 @@ * Copyright (C) 2004 Eric Seigne - * Copyright (C) 2005-2010 Laurent Destailleur + * Copyright (C) 2005-2011 Laurent Destailleur * Copyright (C) 2005-2010 Regis Houssin * * This program is free software; you can redistribute it and/or modify @@ -28,6 +28,7 @@ require("../main.inc.php"); require_once(DOL_DOCUMENT_ROOT."/lib/admin.lib.php"); +require_once(DOL_DOCUMENT_ROOT."/lib/company.lib.php"); $langs->load("admin"); @@ -171,7 +172,10 @@ llxHeader('',$langs->trans("CompanySetup"),'EN:Module Third Parties setup|FR:Par $linkback=''.$langs->trans("BackToModuleList").''; print_fiche_titre($langs->trans("CompanySetup"),$linkback,'setup'); -print "
"; + +$head = societe_admin_prepare_head($soc); + +dol_fiche_head($head, 'general', $langs->trans("ThirdParty"), 0, 'company'); // Choix du module de gestion des codes clients / fournisseurs @@ -490,6 +494,9 @@ print ''; print '
'; + +dol_fiche_end(); + $db->close(); llxFooter('$Date$ - $Revision$'); diff --git a/htdocs/admin/societe_extrafields.php b/htdocs/admin/societe_extrafields.php new file mode 100755 index 00000000000..9c6c527f30f --- /dev/null +++ b/htdocs/admin/societe_extrafields.php @@ -0,0 +1,315 @@ + + * Copyright (C) 2003 Jean-Louis Bergamo + * Copyright (C) 2004-2011 Laurent Destailleur + * + * 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +/** + * \file htdocs/admin/societe_extrafields.php + * \ingroup societe + * \brief Page to setup extra fields of third party + * \version $Id$ + */ + +require("../main.inc.php"); +require_once(DOL_DOCUMENT_ROOT."/lib/company.lib.php"); +require_once(DOL_DOCUMENT_ROOT."/core/class/extrafields.class.php"); + +$langs->load("companies"); +$langs->load("admin"); + +$extrafields = new ExtraFields($db); +$form = new Form($db); + +// List of supported format +$type2label=array( +'varchar'=>$langs->trans('String'), +'text'=>$langs->trans('Text'), +'int'=>$langs->trans('Int'), +'date'=>$langs->trans('Date'), +'datetime'=>$langs->trans('DateAndTime') +); + +$action=GETPOST("action"); +$elementtype='company'; + +if (!$user->admin) +accessforbidden(); + + +/* + * Actions + */ + +if ($action == 'add') +{ + if ($_POST["button"] != $langs->trans("Cancel")) + { + // Check values + if (GETPOST('type')=='varchar' && GETPOST('size') > 255) + { + $error++; + $langs->load("errors"); + $mesg=$langs->trans("ErrorSizeTooLongForVarcharType"); + $action = 'create'; + } + + if (! $error) + { + // Type et taille non encore pris en compte => varchar(255) + if (isset($_POST["attrname"]) && preg_match("/^\w[a-zA-Z0-9-_]*$/",$_POST['attrname'])) + { + $result=$extrafields->addExtraField($_POST['attrname'],$_POST['label'],$_POST['type'],$_POST['pos'],$_POST['size'],$elementtype); + if ($result > 0) + { + Header("Location: ".$_SERVER["PHP_SELF"]); + exit; + } + else + { + $error++; + $mesg=$extrafields->error; + } + } + else + { + $error++; + $langs->load("errors"); + $mesg=$langs->trans("ErrorFieldCanNotContainSpecialCharacters",$langs->transnoentities("AttributeCode")); + $action = 'create'; + } + } + } +} + +// Rename field +if ($action == 'update') +{ + if ($_POST["button"] != $langs->trans("Cancel")) + { + // Check values + if (GETPOST('type')=='varchar' && GETPOST('size') > 255) + { + $error++; + $langs->load("errors"); + $mesg=$langs->trans("ErrorSizeTooLongForVarcharType"); + $action = 'edit'; + } + + if (! $error) + { + if (isset($_POST["attrname"]) && preg_match("/^\w[a-zA-Z0-9-_]*$/",$_POST['attrname'])) + { + $result=$extrafields->update($_POST['attrname'],$_POST['type'],$_POST['size'],$elementtype); + if ($result > 0) + { + if (isset($_POST['label'])) + { + $extrafields->update_label($_POST['attrname'],$_POST['label'],$_POST['type'],$_POST['size'],$elementtype); + } + Header("Location: ".$_SERVER["PHP_SELF"]); + exit; + } + else + { + $error++; + $mesg=$extrafields->error; + } + } + else + { + $error++; + $langs->load("errors"); + $mesg=$langs->trans("ErrorFieldCanNotContainSpecialCharacters",$langs->transnoentities("AttributeCode")); + } + } + } +} + +# Suppression attribut +if ($action == 'delete') +{ + if(isset($_GET["attrname"]) && preg_match("/^\w[a-zA-Z0-9-_]*$/",$_GET["attrname"])) + { + $result=$extrafields->delete($_GET["attrname"],$elementtype); + if ($result >= 0) + { + Header("Location: ".$_SERVER["PHP_SELF"]); + exit; + } + else $mesg=$extrafields->error; + } + else + { + $error++; + $langs->load("errors"); + $mesg=$langs->trans("ErrorFieldCanNotContainSpecialCharacters",$langs->transnoentities("AttributeCode")); + } +} + + + +/* + * View + */ + +$textobject=$langs->transnoentitiesnoconv("ThirdParty"); + +$help_url='EN:Module_Foundations|FR:Module_Adhérents|ES:Módulo_Miembros'; +llxHeader('',$langs->trans("CompanySetup"),$help_url); + + +print_fiche_titre($langs->trans("OptionalFieldsSetup")); + + +$head = societe_admin_prepare_head($adh); + +dol_fiche_head($head, 'attributes', $langs->trans("ThirdParty"), 0, 'company'); + + +print $langs->trans("DefineHereComplementaryAttributes",$textobject).'
'."\n"; +print '
'; + +dol_htmloutput_errors($mesg); + +// Load attribute_label +$extrafields->fetch_name_optionals_label($elementtype); + +print ""; + +print ''; +print ''; +print ''; +print ''; +print ''; +print ''; +print "\n"; + +$var=True; +foreach($extrafields->attribute_type as $key => $value) +{ + $var=!$var; + print ""; + print "\n"; + print "\n"; + print "\n"; + print '\n"; + print '\n"; + print ""; + // $i++; +} + +print "
'.$langs->trans("Label").''.$langs->trans("AttributeCode").''.$langs->trans("Type").''.$langs->trans("Size").' 
".$extrafields->attribute_label[$key]."".$key."".$type2label[$extrafields->attribute_type[$key]]."'.$extrafields->attribute_size[$key]."'.img_edit().''; + print "  ".img_delete()."
"; + +dol_fiche_end(); + +/* + * Barre d'actions + * + */ +if ($action != 'create' && $action != 'edit') +{ + print '
'; + print "".$langs->trans("NewAttribute").""; + print "
"; +} + + +/* ************************************************************************** */ +/* */ +/* Creation d'un champ optionnel + /* */ +/* ************************************************************************** */ + +if ($action == 'create') +{ + print "
"; + print_titre($langs->trans('NewAttribute')); + + print '
'; + print ''; + print ''; + + print ''; + + // Label + print ''; + // Code + print ''; + // Type + print ''; + // Size + print ''; + + print ''; + print "\n"; + print "
'.$langs->trans("Label").'
'.$langs->trans("AttributeCode").' ('.$langs->trans("AlphaNumOnlyCharsAndNoSpace").')
'.$langs->trans("Type").''; + print $form->selectarray('type',$type2label,GETPOST('type')); + print '
'.$langs->trans("Size").'
  '; + print '
\n"; +} + +/* ************************************************************************** */ +/* */ +/* Edition d'un champ optionnel */ +/* */ +/* ************************************************************************** */ +if ($_GET["attrname"] && $action == 'edit') +{ + print "
"; + print_titre($langs->trans("FieldEdition",$_GET["attrname"])); + + /* + * formulaire d'edition + */ + print '
'; + print ''; + print ''; + print ''; + print ''; + + // Label + print ''; + print ''; + print ''; + // Code + print ''; + print ''; + print ''; + print ''; + // Type + $type=$extrafields->attribute_type[$_GET["attrname"]]; + $size=$extrafields->attribute_size[$_GET["attrname"]]; + print ''; + print ''; + // Size + print ''; + print ''; + print '
'.$langs->trans("Label").'
'.$langs->trans("AttributeCode").''.$_GET["attrname"].' 
'.$langs->trans("Type").''; + print $type2label[$type]; + print ''; + print '
'.$langs->trans("Size").'
  '; + print '
'; + print "
"; + +} + +$db->close(); + +llxFooter('$Date$ - $Revision$'); +?> diff --git a/htdocs/core/class/extrafields.class.php b/htdocs/core/class/extrafields.class.php index cfc49cd4358..76d7bd63f7c 100755 --- a/htdocs/core/class/extrafields.class.php +++ b/htdocs/core/class/extrafields.class.php @@ -74,7 +74,7 @@ class ExtraFields if (empty($attrname)) return -1; if (empty($label)) return -1; - $result=$this->create($attrname,$type,$size); + $result=$this->create($attrname,$type,$size,$elementtype); if ($result > 0) { $result2=$this->create_label($attrname,$label,$type,$pos,$size,$elementtype); @@ -190,16 +190,16 @@ class ExtraFields return -1; } - if (isset($attrname) && $attrname != '' && preg_match("/^\w[a-zA-Z0-9-_]*$/",$attrname)) + if (! empty($attrname) && preg_match("/^\w[a-zA-Z0-9-_]*$/",$attrname)) { - $result=$this->db->DDLDropField(MAIN_DB_PREFIX.$table,$attrname); + $result=$this->db->DDLDropField(MAIN_DB_PREFIX.$table,$attrname); if ($result < 0) { $this->error=$this->db->lasterror(); dol_syslog(get_class($this)."::delete ".$this->error, LOG_ERR); } - $result=$this->delete_label($attrname); + $result=$this->delete_label($attrname,$elementtype); return $result; } diff --git a/htdocs/lib/company.lib.php b/htdocs/lib/company.lib.php index 95e5bd49af1..e41af0b7c39 100644 --- a/htdocs/lib/company.lib.php +++ b/htdocs/lib/company.lib.php @@ -173,6 +173,40 @@ function societe_prepare_head2($object) } + +/** + * Return array head with list of tabs to view object informations + * @param object Thirdparty + * @return array head + */ +function societe_admin_prepare_head($object) +{ + global $langs, $conf, $user; + + $h = 0; + $head = array(); + + $head[$h][0] = DOL_URL_ROOT.'/admin/societe.php'; + $head[$h][1] = $langs->trans("Miscellanous"); + $head[$h][2] = 'general'; + $h++; + + $head[$h][0] = DOL_URL_ROOT.'/admin/societe_extrafields.php'; + $head[$h][1] = $langs->trans("ExtraFields"); + $head[$h][2] = 'attributes'; + $h++; + + // Show more tabs from modules + // Entries must be declared in modules descriptor with line + // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab + // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab + complete_head_from_modules($conf,$langs,$object,$head,$h,'company_admin'); + + return $head; +} + + + /** * Return country translated from an id or a code * @param id Id or code of country diff --git a/htdocs/lib/member.lib.php b/htdocs/lib/member.lib.php index c3f11ec35e8..96444256918 100644 --- a/htdocs/lib/member.lib.php +++ b/htdocs/lib/member.lib.php @@ -111,7 +111,7 @@ function member_admin_prepare_head($object) $head[$h][2] = 'general'; $h++; - $head[$h][0] = DOL_URL_ROOT.'/adherents/options.php'; + $head[$h][0] = DOL_URL_ROOT.'/adherents/admin/adherent_extrafields.php'; $head[$h][1] = $langs->trans("ExtraFields"); $head[$h][2] = 'attributes'; $h++; diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index f8946035f5b..ca1dc1dc499 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -524,6 +524,46 @@ class Societe extends CommonObject // Si le fournisseur est classe on l'ajoute $this->AddFournisseurInCategory($this->fournisseur_categorie); + // Add/Update extra fields + // TODO Run a method into commonobject + if (sizeof($this->array_options) > 0) + { + $sql_del = "DELETE FROM ".MAIN_DB_PREFIX."societe_extrafields WHERE fk_object = ".$this->id; + dol_syslog(get_class($this)."::update sql=".$sql_del); + $this->db->query($sql_del); + + $sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_extrafields (fk_object"; + foreach($this->array_options as $key => $value) + { + // Add field of attribut + $sql.=",".substr($key,8); // Remove 'options_' prefix + } + $sql .= ") VALUES (".$this->id; + foreach($this->array_options as $key => $value) + { + // Add field o fattribut + if ($this->array_options[$key] != '') + { + $sql.=",'".$this->array_options[$key]."'"; + } + else + { + $sql.=",null"; + } + } + $sql.=")"; + + dol_syslog(get_class($this)."::update update option sql=".$sql); + $resql = $this->db->query($sql); + if (! $resql) + { + $this->error=$this->db->error(); + dol_syslog(get_class($this)."::update ".$this->error,LOG_ERR); + $this->db->rollback(); + return -2; + } + } + if ($call_trigger) { // Appel des triggers @@ -832,25 +872,25 @@ class Societe extends CommonObject $haschild=0; foreach($listtable as $table) { - // Check if third party can be deleted - $nb=0; - $sql = "SELECT COUNT(*) as nb from ".MAIN_DB_PREFIX.$table; - $sql.= " WHERE fk_soc = " . $id; - $resql=$this->db->query($sql); - if ($resql) - { - $obj=$this->db->fetch_object($resql); - if ($obj->nb > 0) - { - $haschild+=$obj->nb; - } - } - else - { - $this->error .= $this->db->lasterror(); - dol_syslog("Societe::Delete erreur -1 ".$this->error, LOG_ERR); - return -1; - } + // Check if third party can be deleted + $nb=0; + $sql = "SELECT COUNT(*) as nb from ".MAIN_DB_PREFIX.$table; + $sql.= " WHERE fk_soc = " . $id; + $resql=$this->db->query($sql); + if ($resql) + { + $obj=$this->db->fetch_object($resql); + if ($obj->nb > 0) + { + $haschild+=$obj->nb; + } + } + else + { + $this->error .= $this->db->lasterror(); + dol_syslog("Societe::Delete erreur -1 ".$this->error, LOG_ERR); + return -1; + } } if ($haschild > 0) { @@ -1294,7 +1334,7 @@ class Societe extends CommonObject dol_print_error($this->db); return -1; } -} + } /** * Set the price level @@ -1488,15 +1528,15 @@ class Societe extends CommonObject $ret=''; if (in_array($this->country,array('us'))) { - $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:''); } 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); } @@ -1513,9 +1553,9 @@ class Societe extends CommonObject $contact_email = $this->contact_property_array('email'); if ($this->email) { - if (empty($this->name)) $this->name=$this->nom; - // TODO: Tester si email non deja present dans tableau contact - $contact_email[-1]=$langs->trans("ThirdParty").': '.dol_trunc($this->name,16)." <".$this->email.">"; + if (empty($this->name)) $this->name=$this->nom; + // TODO: Tester si email non deja present dans tableau contact + $contact_email[-1]=$langs->trans("ThirdParty").': '.dol_trunc($this->name,16)." <".$this->email.">"; } return $contact_email; } @@ -1988,52 +2028,52 @@ class Societe extends CommonObject $string = strtoupper($string); for ($i = 0; $i < 9; $i ++) - $num[$i] = substr($string, $i, 1); + $num[$i] = substr($string, $i, 1); //Check format if (!preg_match('/((^[A-Z]{1}[0-9]{7}[A-Z0-9]{1}$|^[T]{1}[A-Z0-9]{8}$)|^[0-9]{8}[A-Z]{1}$)/', $string)) - return 0; + return 0; //Check NIF if (preg_match('/(^[0-9]{8}[A-Z]{1}$)/', $string)) - if ($num[8] == substr('TRWAGMYFPDXBNJZSQVHLCKE', substr($string, 0, 8) % 23, 1)) - return 1; - else - return -1; + if ($num[8] == substr('TRWAGMYFPDXBNJZSQVHLCKE', substr($string, 0, 8) % 23, 1)) + return 1; + else + return -1; //algorithm checking type code CIF $sum = $num[2] + $num[4] + $num[6]; for ($i = 1; $i < 8; $i += 2) - $sum += substr((2 * $num[$i]),0,1) + substr((2 * $num[$i]),1,1); + $sum += substr((2 * $num[$i]),0,1) + substr((2 * $num[$i]),1,1); $n = 10 - substr($sum, strlen($sum) - 1, 1); //Chek special NIF if (preg_match('/^[KLM]{1}/', $string)) - if ($num[8] == chr(64 + $n) || $num[8] == substr('TRWAGMYFPDXBNJZSQVHLCKE', substr($string, 1, 8) % 23, 1)) - return 1; - else - return -1; + if ($num[8] == chr(64 + $n) || $num[8] == substr('TRWAGMYFPDXBNJZSQVHLCKE', substr($string, 1, 8) % 23, 1)) + return 1; + else + return -1; //Check CIF if (preg_match('/^[ABCDEFGHJNPQRSUVW]{1}/', $string)) - if ($num[8] == chr(64 + $n) || $num[8] == substr($n, strlen($n) - 1, 1)) - return 2; - else - return -2; + if ($num[8] == chr(64 + $n) || $num[8] == substr($n, strlen($n) - 1, 1)) + return 2; + else + return -2; //Check NIE T if (preg_match('/^[T]{1}/', $string)) - if ($num[8] == preg_match('/^[T]{1}[A-Z0-9]{8}$/', $string)) - return 3; - else - return -3; + if ($num[8] == preg_match('/^[T]{1}[A-Z0-9]{8}$/', $string)) + return 3; + else + return -3; //Check NIE XYZ if (preg_match('/^[XYZ]{1}/', $string)) - if ($num[8] == substr('TRWAGMYFPDXBNJZSQVHLCKE', substr(str_replace(array('X','Y','Z'), array('0','1','2'), $string), 0, 8) % 23, 1)) - return 3; - else - return -3; + if ($num[8] == substr('TRWAGMYFPDXBNJZSQVHLCKE', substr(str_replace(array('X','Y','Z'), array('0','1','2'), $string), 0, 8) % 23, 1)) + return 3; + else + return -3; //Can not be verified return -4; @@ -2196,14 +2236,14 @@ class Societe extends CommonObject 'LV', // Latvia 'MC', // Monaco Seems to use same IntraVAT than France (http://www.gouv.mc/devwww/wwwnew.nsf/c3241c4782f528bdc1256d52004f970b/9e370807042516a5c1256f81003f5bb3!OpenDocument) 'MT', // Malta - //'NO', // Norway + //'NO', // Norway 'PL', // Poland 'PT', // Portugal 'RO', // Romania 'SE', // Sweden 'SK', // Slovakia 'SI', // Slovenia - //'CH', // Switzerland - No. Swizerland in not in EEC + //'CH', // Switzerland - No. Swizerland in not in EEC ); //print "dd".$this->pays_code; return in_array($this->pays_code,$country_code_in_EEC); diff --git a/htdocs/societe/soc.php b/htdocs/societe/soc.php index 442c96aa3dd..b9c57c2807d 100644 --- a/htdocs/societe/soc.php +++ b/htdocs/societe/soc.php @@ -196,6 +196,15 @@ else $soc->commercial_id = $_POST["commercial_id"]; $soc->default_lang = $_POST["default_lang"]; + // Get extra fields + foreach($_POST as $key => $value) + { + if (preg_match("/^options_/",$key)) + { + $soc->array_options[$key]=$_POST[$key]; + } + } + if (GETPOST('deletephoto')) $soc->logo = ''; else if (! empty($_FILES['photo']['name'])) $soc->logo = dol_sanitizeFileName($_FILES['photo']['name']); @@ -1749,7 +1758,7 @@ else foreach($extrafields->attribute_label as $key=>$label) { $value=$soc->array_options["options_$key"]; - print "".$label.""; + print "".$label.''; print $extrafields->showOutputField($key,$value); print "\n"; }