New: Can use extrafields on third parties.

This commit is contained in:
Laurent Destailleur 2011-06-22 16:24:20 +00:00
parent da0c617e7e
commit fb2e7c063e
11 changed files with 494 additions and 85 deletions

View File

@ -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.

View File

@ -1,7 +1,7 @@
<?php
/* Copyright (C) 2001-2002 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2003 Jean-Louis Bergamo <jlb@j1b.org>
* Copyright (C) 2004-2009 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
*
* 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 '<br>';
dol_htmloutput_errors($mesg);
// Load attribute_label
$extrafields->fetch_name_optionals_label();
$extrafields->fetch_name_optionals_label($elementtype);
print "<table summary=\"listofattributes\" class=\"noborder\" width=\"100%\">";
@ -201,8 +208,8 @@ foreach($extrafields->attribute_type as $key => $value)
print "<td>".$key."</td>\n";
print "<td>".$type2label[$extrafields->attribute_type[$key]]."</td>\n";
print '<td align="right">'.$extrafields->attribute_size[$key]."</td>\n";
print '<td align="right"><a href="options.php?action=edit&attrname='.$key.'">'.img_edit().'</a>';
print "&nbsp; <a href=\"options.php?action=delete&attrname=$key\">".img_delete()."</a></td>\n";
print '<td align="right"><a href="".$_SERVER["PHP_SELF"]."?action=edit&attrname='.$key.'">'.img_edit().'</a>';
print "&nbsp; <a href=\"".$_SERVER["PHP_SELF"]."?action=delete&attrname=$key\">".img_delete()."</a></td>\n";
print "</tr>";
// $i++;
}
@ -218,7 +225,7 @@ dol_fiche_end();
if ($action != 'create' && $action != 'edit')
{
print '<div class="tabsAction">';
print "<a class=\"butAction\" href=\"options.php?action=create\">".$langs->trans("NewAttribute")."</a>";
print "<a class=\"butAction\" href=\"".$_SERVER["PHP_SELF"]."?action=create\">".$langs->trans("NewAttribute")."</a>";
print "</div>";
}
@ -234,7 +241,7 @@ if ($action == 'create')
print "<br>";
print_titre($langs->trans('NewAttribute'));
print '<form action="options.php" method="post">';
print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<table summary="listofattributes" class="border" width="100%">';
@ -270,7 +277,7 @@ if ($_GET["attrname"] && $action == 'edit')
/*
* formulaire d'edition
*/
print '<form method="post" action="options.php?attrname='.$_GET["attrname"].'">';
print '<form method="post" action="'.$_SERVER["PHP_SELF"].'?attrname='.$_GET["attrname"].'">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="attrname" value="'.$_GET["attrname"].'">';
print '<input type="hidden" name="action" value="update">';

View File

@ -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);

View File

@ -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];
}
}

View File

@ -1,7 +1,7 @@
<?php
/* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
* Copyright (C) 2005-2010 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2011 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2010 Regis Houssin <regis@dolibarr.fr>
*
* 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='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
print_fiche_titre($langs->trans("CompanySetup"),$linkback,'setup');
print "<br>";
$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 '</form>';
print '</table>';
dol_fiche_end();
$db->close();
llxFooter('$Date$ - $Revision$');

View File

@ -0,0 +1,315 @@
<?php
/* Copyright (C) 2001-2002 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2003 Jean-Louis Bergamo <jlb@j1b.org>
* Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
*
* 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&eacute;rents|ES:M&oacute;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).'<br>'."\n";
print '<br>';
dol_htmloutput_errors($mesg);
// Load attribute_label
$extrafields->fetch_name_optionals_label($elementtype);
print "<table summary=\"listofattributes\" class=\"noborder\" width=\"100%\">";
print '<tr class="liste_titre">';
print '<td>'.$langs->trans("Label").'</td>';
print '<td>'.$langs->trans("AttributeCode").'</td>';
print '<td>'.$langs->trans("Type").'</td>';
print '<td align="right">'.$langs->trans("Size").'</td>';
print '<td width="80">&nbsp;</td>';
print "</tr>\n";
$var=True;
foreach($extrafields->attribute_type as $key => $value)
{
$var=!$var;
print "<tr $bc[$var]>";
print "<td>".$extrafields->attribute_label[$key]."</td>\n";
print "<td>".$key."</td>\n";
print "<td>".$type2label[$extrafields->attribute_type[$key]]."</td>\n";
print '<td align="right">'.$extrafields->attribute_size[$key]."</td>\n";
print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=edit&attrname='.$key.'">'.img_edit().'</a>';
print "&nbsp; <a href=\"".$_SERVER["PHP_SELF"]."?action=delete&attrname=$key\">".img_delete()."</a></td>\n";
print "</tr>";
// $i++;
}
print "</table>";
dol_fiche_end();
/*
* Barre d'actions
*
*/
if ($action != 'create' && $action != 'edit')
{
print '<div class="tabsAction">';
print "<a class=\"butAction\" href=\"".$_SERVER["PHP_SELF"]."?action=create\">".$langs->trans("NewAttribute")."</a>";
print "</div>";
}
/* ************************************************************************** */
/* */
/* Creation d'un champ optionnel
/* */
/* ************************************************************************** */
if ($action == 'create')
{
print "<br>";
print_titre($langs->trans('NewAttribute'));
print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<table summary="listofattributes" class="border" width="100%">';
print '<input type="hidden" name="action" value="add">';
// Label
print '<tr><td class="fieldrequired" required>'.$langs->trans("Label").'</td><td class="valeur"><input type="text" name="label" size="40" value="'.GETPOST('label').'"></td></tr>';
// Code
print '<tr><td class="fieldrequired" required>'.$langs->trans("AttributeCode").' ('.$langs->trans("AlphaNumOnlyCharsAndNoSpace").')</td><td class="valeur"><input type="text" name="attrname" size="10" value"'.GETPOST('attrname').'"></td></tr>';
// Type
print '<tr><td class="fieldrequired" required>'.$langs->trans("Type").'</td><td class="valeur">';
print $form->selectarray('type',$type2label,GETPOST('type'));
print '</td></tr>';
// Size
print '<tr><td class="fieldrequired" required>'.$langs->trans("Size").'</td><td><input type="text" name="size" size="5" value="'.(GETPOST('size')?GETPOST('size'):'255').'"></td></tr>';
print '<tr><td colspan="2" align="center"><input type="submit" name="button" class="button" value="'.$langs->trans("Save").'"> &nbsp; ';
print '<input type="submit" name="button" class="button" value="'.$langs->trans("Cancel").'"></td></tr>';
print "</form>\n";
print "</table>\n";
}
/* ************************************************************************** */
/* */
/* Edition d'un champ optionnel */
/* */
/* ************************************************************************** */
if ($_GET["attrname"] && $action == 'edit')
{
print "<br>";
print_titre($langs->trans("FieldEdition",$_GET["attrname"]));
/*
* formulaire d'edition
*/
print '<form method="post" action="'.$_SERVER["PHP_SELF"].'?attrname='.$_GET["attrname"].'">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="attrname" value="'.$_GET["attrname"].'">';
print '<input type="hidden" name="action" value="update">';
print '<table summary="listofattributes" class="border" width="100%">';
// Label
print '<tr>';
print '<td class="fieldrequired" required>'.$langs->trans("Label").'</td><td class="valeur"><input type="text" name="label" size="40" value="'.$extrafields->attribute_label[$_GET["attrname"]].'"></td>';
print '</tr>';
// Code
print '<tr>';
print '<td class="fieldrequired" required>'.$langs->trans("AttributeCode").'</td>';
print '<td class="valeur">'.$_GET["attrname"].'&nbsp;</td>';
print '</tr>';
// Type
$type=$extrafields->attribute_type[$_GET["attrname"]];
$size=$extrafields->attribute_size[$_GET["attrname"]];
print '<tr><td class="fieldrequired" required>'.$langs->trans("Type").'</td>';
print '<td class="valeur">';
print $type2label[$type];
print '<input type="hidden" name="type" value="'.$type.'">';
print '</td></tr>';
// Size
print '<tr><td class="fieldrequired" required>'.$langs->trans("Size").'</td><td class="valeur"><input type="text" name="size" size="5" value="'.$size.'"></td></tr>';
print '<tr><td colspan="2" align="center"><input type="submit" class="button" value="'.$langs->trans("Save").'"> &nbsp; ';
print '<input type="submit" name="button" class="button" value="'.$langs->trans("Cancel").'"></td></tr>';
print '</table>';
print "</form>";
}
$db->close();
llxFooter('$Date$ - $Revision$');
?>

View File

@ -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;
}

View File

@ -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

View File

@ -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++;

View File

@ -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)." &lt;".$this->email."&gt;";
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)." &lt;".$this->email."&gt;";
}
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);

View File

@ -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 "<tr><td>".$label."</td><td>";
print "<tr><td>".$label.'</td><td colspan="3">';
print $extrafields->showOutputField($key,$value);
print "</td></tr>\n";
}