diff --git a/htdocs/compta/facture/card.php b/htdocs/compta/facture/card.php
index 5a9dad480a0..1349d3b9199 100644
--- a/htdocs/compta/facture/card.php
+++ b/htdocs/compta/facture/card.php
@@ -73,7 +73,7 @@ if (!empty($conf->incoterm->enabled)) $langs->load('incoterm');
if (! empty($conf->margin->enabled))
$langs->load('margins');
-$projectid = (GETPOST('projectid') ? GETPOST('projectid', 'int') : 0);
+$projectid = (GETPOST('projectid','int') ? GETPOST('projectid', 'int') : 0);
$id = (GETPOST('id', 'int') ? GETPOST('id', 'int') : GETPOST('facid', 'int')); // For backward compatibility
$ref = GETPOST('ref', 'alpha');
@@ -83,7 +83,7 @@ $confirm = GETPOST('confirm', 'alpha');
$cancel = GETPOST('cancel', 'alpha');
$lineid = GETPOST('lineid', 'int');
$userid = GETPOST('userid', 'int');
-$search_ref = GETPOST('sf_ref') ? GETPOST('sf_ref', 'alpha') : GETPOST('search_ref', 'alpha');
+$search_ref = GETPOST('sf_ref','alpha') ? GETPOST('sf_ref', 'alpha') : GETPOST('search_ref', 'alpha');
$search_societe = GETPOST('search_societe', 'alpha');
$search_montant_ht = GETPOST('search_montant_ht', 'alpha');
$search_montant_ttc = GETPOST('search_montant_ttc', 'alpha');
@@ -430,27 +430,52 @@ if (empty($reshook))
|| (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->facture->invoice_advance->validate)))
)
{
- $idwarehouse = GETPOST('idwarehouse');
+ $idwarehouse = GETPOST('idwarehouse','int');
$object->fetch($id);
$object->fetch_thirdparty();
// Check parameters
- // Check for mandatory prof id (but only if country is than than ours)
- if ($mysoc->country_id > 0 && $object->thirdparty->country_id == $mysoc->country_id)
+ // Check for mandatory fields defined into setup
+ $array_to_check=array('IDPROF1','IDPROF2','IDPROF3','IDPROF4','IDPROF5','IDPROF6','EMAIL');
+ foreach($array_to_check as $key)
{
- for ($i = 1; $i <= 6; $i++)
- {
- $idprof_mandatory = 'SOCIETE_IDPROF' . ($i) . '_INVOICE_MANDATORY';
- $idprof = 'idprof' . $i;
- if (! $object->thirdparty->$idprof && ! empty($conf->global->$idprof_mandatory))
- {
- if (! $error) $langs->load("errors");
- $error++;
- setEventMessages($langs->trans('ErrorProdIdIsMandatory', $langs->transcountry('ProfId' . $i, $object->thirdparty->country_code)), null, 'errors');
- }
- }
+ $keymin=strtolower($key);
+ $i=(int) preg_replace('/[^0-9]/','',$key);
+ $vallabel=$object->thirdparty->$keymin;
+
+ if ($i > 0)
+ {
+ if ($object->thirdparty->isACompany())
+ {
+ // Check for mandatory prof id (but only if country is other than ours)
+ if ($mysoc->country_id > 0 && $object->thirdparty->country_id == $mysoc->country_id)
+ {
+ $idprof_mandatory ='SOCIETE_'.$key.'_INVOICE_MANDATORY';
+ if (! $vallabel && ! empty($conf->global->$idprof_mandatory))
+ {
+ $langs->load("errors");
+ $error++;
+ setEventMessages($langs->trans('ErrorProdIdIsMandatory', $langs->transcountry('ProfId'.$i, $object->thirdparty->country_code)).' ('.$langs->trans("ForbiddenBySetupRules").')', null, 'errors');
+ }
+ }
+ }
+ }
+ else
+ {
+ //var_dump($conf->global->SOCIETE_EMAIL_MANDATORY);
+ if ($key == 'EMAIL')
+ {
+ // Check for mandatory
+ if (! empty($conf->global->SOCIETE_EMAIL_INVOICE_MANDATORY) && ! isValidEMail($object->thirdparty->email))
+ {
+ $langs->load("errors");
+ $error++;
+ setEventMessages($langs->trans("ErrorBadEMail", $object->thirdparty->email).' ('.$langs->trans("ForbiddenBySetupRules").')', null, 'errors');
+ }
+ }
+ }
}
$qualified_for_stock_change = 0;
@@ -4260,7 +4285,7 @@ else if ($id > 0 || ! empty($ref))
print '
';
// Select mail models is same action as presend
- if (GETPOST('modelselected')) {
+ if (GETPOST('modelselected','alpha')) {
$action = 'presend';
}
if ($action != 'prerelance' && $action != 'presend')
@@ -4347,7 +4372,7 @@ else if ($id > 0 || ! empty($ref))
// Build document if it not exists
if (! $file || ! is_readable($file)) {
- $result = $object->generateDocument(GETPOST('model') ? GETPOST('model') : $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
+ $result = $object->generateDocument(GETPOST('model','alpha') ? GETPOST('model','alpha') : $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
if ($result <= 0) {
dol_print_error($db, $object->error, $object->errors);
exit();
@@ -4367,7 +4392,7 @@ else if ($id > 0 || ! empty($ref))
include_once DOL_DOCUMENT_ROOT . '/core/class/html.formmail.class.php';
$formmail = new FormMail($db);
$formmail->param['langsmodels']=(empty($newlang)?$langs->defaultlang:$newlang);
- $formmail->fromtype = (GETPOST('fromtype')?GETPOST('fromtype'):(!empty($conf->global->MAIN_MAIL_DEFAULT_FROMTYPE)?$conf->global->MAIN_MAIL_DEFAULT_FROMTYPE:'user'));
+ $formmail->fromtype = (GETPOST('fromtype','alpha')?GETPOST('fromtype','alpha'):(!empty($conf->global->MAIN_MAIL_DEFAULT_FROMTYPE)?$conf->global->MAIN_MAIL_DEFAULT_FROMTYPE:'user'));
if($formmail->fromtype === 'user'){
$formmail->fromid = $user->id;
diff --git a/htdocs/core/actions_builddoc.inc.php b/htdocs/core/actions_builddoc.inc.php
index 076a7a6a035..a1ff6417f92 100644
--- a/htdocs/core/actions_builddoc.inc.php
+++ b/htdocs/core/actions_builddoc.inc.php
@@ -33,8 +33,8 @@
// Build doc
if ($action == 'builddoc' && $permissioncreate)
{
-
- if (is_numeric(GETPOST('model')))
+
+ if (is_numeric(GETPOST('model','alpha')))
{
$error=$langs->trans("ErrorFieldRequired",$langs->transnoentities("Model"));
}
@@ -48,18 +48,18 @@ if ($action == 'builddoc' && $permissioncreate)
dol_print_error('Object must have been loaded by a fetch');
exit;
}*/
-
+
// Save last template used to generate document
- if (GETPOST('model'))
+ if (GETPOST('model','alpha'))
{
$object->setDocModel($user, GETPOST('model','alpha'));
}
-
+
// Special case to force bank account
//if (property_exists($object, 'fk_bank'))
//{
- if (GETPOST('fk_bank')) { // this field may come from an external module
- $object->fk_bank = GETPOST('fk_bank');
+ if (GETPOST('fk_bank','int')) { // this field may come from an external module
+ $object->fk_bank = GETPOST('fk_bank','int');
} else if (! empty($object->fk_account)) {
$object->fk_bank = $object->fk_account;
}
@@ -76,13 +76,13 @@ if ($action == 'builddoc' && $permissioncreate)
$outputlangs = new Translate("",$conf);
$outputlangs->setDefaultLang($newlang);
}
-
+
// To be sure vars is defined
if (empty($hidedetails)) $hidedetails=0;
if (empty($hidedesc)) $hidedesc=0;
if (empty($hideref)) $hideref=0;
if (empty($moreparams)) $moreparams=null;
-
+
$result= $object->generateDocument($object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
if ($result <= 0)
{
diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php
index 4aa3ab65ce5..da6cbc6c15c 100644
--- a/htdocs/core/lib/functions.lib.php
+++ b/htdocs/core/lib/functions.lib.php
@@ -5738,8 +5738,8 @@ function dol_osencode($str)
* @param DoliDB $db Database handler
* @param string $key Code or Id to get Id or Code
* @param string $tablename Table name without prefix
- * @param string $fieldkey Field for code
- * @param string $fieldid Field for id
+ * @param string $fieldkey Field for search ('code' or 'id')
+ * @param string $fieldid Field to get ('id' or 'code')
* @return int <0 if KO, Id of code if OK
* @see $langs->getLabelFromKey
*/
diff --git a/htdocs/societe/admin/societe.php b/htdocs/societe/admin/societe.php
index 89ef7d0323d..ed4704471d0 100644
--- a/htdocs/societe/admin/societe.php
+++ b/htdocs/societe/admin/societe.php
@@ -167,23 +167,6 @@ if ($action == 'setdoc')
}
}
-//Activate ProfId
-if ($action == 'setprofid')
-{
- $status = GETPOST('status','alpha');
-
- $idprof="SOCIETE_IDPROF".$value."_UNIQUE";
- if (dolibarr_set_const($db, $idprof,$status,'chaine',0,'',$conf->entity) > 0)
- {
- header("Location: ".$_SERVER["PHP_SELF"]);
- exit;
- }
- else
- {
- dol_print_error($db);
- }
-}
-
//Activate Set ref in list
if ($action=="setaddrefinlist") {
$setaddrefinlist = GETPOST('value','int');
@@ -214,16 +197,33 @@ if ($action=="setaskforshippingmet") {
}
}
+//Activate ProfId unique
+if ($action == 'setprofid')
+{
+ $status = GETPOST('status','alpha');
+
+ $idprof="SOCIETE_".$value."_UNIQUE";
+ if (dolibarr_set_const($db, $idprof, $status, 'chaine', 0, '', $conf->entity) > 0)
+ {
+ //header("Location: ".$_SERVER["PHP_SELF"]);
+ //exit;
+ }
+ else
+ {
+ dol_print_error($db);
+ }
+}
+
//Activate ProfId mandatory
if ($action == 'setprofidmandatory')
{
$status = GETPOST('status','alpha');
- $idprof="SOCIETE_IDPROF".$value."_MANDATORY";
- if (dolibarr_set_const($db, $idprof,$status,'chaine',0,'',$conf->entity) > 0)
+ $idprof="SOCIETE_".$value."_MANDATORY";
+ if (dolibarr_set_const($db, $idprof, $status, 'chaine', 0, '', $conf->entity) > 0)
{
- header("Location: ".$_SERVER["PHP_SELF"]);
- exit;
+ //header("Location: ".$_SERVER["PHP_SELF"]);
+ //exit;
}
else
{
@@ -236,11 +236,11 @@ if ($action == 'setprofidinvoicemandatory')
{
$status = GETPOST('status','alpha');
- $idprof="SOCIETE_IDPROF".$value."_INVOICE_MANDATORY";
- if (dolibarr_set_const($db, $idprof,$status,'chaine',0,'',$conf->entity) > 0)
+ $idprof="SOCIETE_".$value."_INVOICE_MANDATORY";
+ if (dolibarr_set_const($db, $idprof, $status, 'chaine', 0, '', $conf->entity) > 0)
{
- header("Location: ".$_SERVER["PHP_SELF"]);
- exit;
+ //header("Location: ".$_SERVER["PHP_SELF"]);
+ //exit;
}
else
{
@@ -298,7 +298,6 @@ print '
'.$langs->trans("Status").' | ';
print ' '.$langs->trans("ShortInfo").' | ';
print "\n";
-$var = true;
foreach ($dirsociete as $dirroot)
{
$dir = dol_buildpath($dirroot,0);
@@ -327,7 +326,6 @@ foreach ($dirsociete as $dirroot)
if ($modCodeTiers->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) continue;
if ($modCodeTiers->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) continue;
- $var = !$var;
print ''."\n";
print '| '.$modCodeTiers->name.' | '."\n";
print ''.$modCodeTiers->info($langs).' | '."\n";
@@ -380,7 +378,6 @@ print ''.$langs->trans("Status").' | ';
print ''.$langs->trans("ShortInfo").' | ';
print "
\n";
-$var=true;
foreach ($dirsociete as $dirroot)
{
$dir = dol_buildpath($dirroot,0);
@@ -403,7 +400,6 @@ foreach ($dirsociete as $dirroot)
}
$modCodeCompta = new $file;
- $var = !$var;
print '';
print '| '.$modCodeCompta->name." | \n";
@@ -474,7 +470,6 @@ print ' | '.$langs->trans("ShortInfo").' | ';
print ''.$langs->trans("Preview").' | ';
print "
\n";
-$var=true;
foreach ($dirsociete as $dirroot)
{
$dir = dol_buildpath($dirroot.'doc/',0);
@@ -507,7 +502,6 @@ foreach ($dirsociete as $dirroot)
if ($modulequalified)
{
- $var = !$var;
print '| ';
print $module->name;
print " | \n";
@@ -597,76 +591,74 @@ print ' | '.$langs->trans("MustBeMandatory").' | ';
print ''.$langs->trans("MustBeInvoiceMandatory").' | ';
print "
\n";
-$profid[0][0]=$langs->trans("ProfId1");
-$profid[0][1]=$langs->transcountry('ProfId1', $mysoc->country_code);
-$profid[1][0]=$langs->trans("ProfId2");
-$profid[1][1]=$langs->transcountry('ProfId2', $mysoc->country_code);
-$profid[2][0]=$langs->trans("ProfId3");
-$profid[2][1]=$langs->transcountry('ProfId3', $mysoc->country_code);
-$profid[3][0]=$langs->trans("ProfId4");
-$profid[3][1]=$langs->transcountry('ProfId4', $mysoc->country_code);
-$profid[4][0]=$langs->trans("ProfId5");
-$profid[4][1]=$langs->transcountry('ProfId5', $mysoc->country_code);
-$profid[5][0]=$langs->trans("ProfId6");
-$profid[5][1]=$langs->transcountry('ProfId6', $mysoc->country_code);
-
-$var = true;
-$i=0;
+$profid['IDPROF1'][0]=$langs->trans("ProfId1");
+$profid['IDPROF1'][1]=$langs->transcountry('ProfId1', $mysoc->country_code);
+$profid['IDPROF2'][0]=$langs->trans("ProfId2");
+$profid['IDPROF2'][1]=$langs->transcountry('ProfId2', $mysoc->country_code);
+$profid['IDPROF3'][0]=$langs->trans("ProfId3");
+$profid['IDPROF3'][1]=$langs->transcountry('ProfId3', $mysoc->country_code);
+$profid['IDPROF4'][0]=$langs->trans("ProfId4");
+$profid['IDPROF4'][1]=$langs->transcountry('ProfId4', $mysoc->country_code);
+$profid['IDPROF5'][0]=$langs->trans("ProfId5");
+$profid['IDPROF5'][1]=$langs->transcountry('ProfId5', $mysoc->country_code);
+$profid['IDPROF6'][0]=$langs->trans("ProfId6");
+$profid['IDPROF6'][1]=$langs->transcountry('ProfId6', $mysoc->country_code);
+$profid['EMAIL'][0]=$langs->trans("EMail");
+$profid['EMAIL'][1]=$langs->trans('Email');
$nbofloop=count($profid);
-while ($i < $nbofloop)
+foreach($profid as $key => $val)
{
- if ($profid[$i][1]!='-')
+ if ($profid[$key][1]!='-')
{
- $var = !$var;
-
print '';
- print '| '.$profid[$i][0]." | \n";
- print $profid[$i][1];
+ print ' | '.$profid[$key][0]." | \n";
+ print $profid[$key][1];
print ' | ';
- $idprof_unique ='SOCIETE_IDPROF'.($i+1).'_UNIQUE';
- $idprof_mandatory ='SOCIETE_IDPROF'.($i+1).'_MANDATORY';
- $idprof_invoice_mandatory ='SOCIETE_IDPROF'.($i+1).'_INVOICE_MANDATORY';
+ $idprof_unique ='SOCIETE_'.$key.'_UNIQUE';
+ $idprof_mandatory ='SOCIETE_'.$key.'_MANDATORY';
+ $idprof_invoice_mandatory ='SOCIETE_'.$key.'_INVOICE_MANDATORY';
+
$verif=(empty($conf->global->$idprof_unique)?false:true);
$mandatory=(empty($conf->global->$idprof_mandatory)?false:true);
$invoice_mandatory=(empty($conf->global->$idprof_invoice_mandatory)?false:true);
if ($verif)
{
- print '';
+ print ' | ';
print img_picto($langs->trans("Activated"),'switch_on');
print ' | ';
}
else
{
- print '';
+ print ' | ';
print img_picto($langs->trans("Disabled"),'switch_off');
print ' | ';
}
if ($mandatory)
{
- print '';
+ print ' | ';
print img_picto($langs->trans("Activated"),'switch_on');
print ' | ';
}
else
{
- print '';
+ print ' | ';
print img_picto($langs->trans("Disabled"),'switch_off');
print ' | ';
}
if ($invoice_mandatory)
{
- print '';
+ print ' | ';
print img_picto($langs->trans("Activated"),'switch_on');
print ' | ';
}
else
{
- print '';
+ print ' | ';
print img_picto($langs->trans("Disabled"),'switch_off');
print ' | ';
}
@@ -683,7 +675,6 @@ print load_fiche_titre($langs->trans("Other"),'','');
// Autres options
$form=new Form($db);
-$var=true;
print '
- | trans('EMail').($conf->global->SOCIETE_MAIL_REQUIRED?'*':''); ?> |
+ trans('EMail').($conf->global->SOCIETE_EMAIL_MANDATORY?'*':''); ?> |
|
trans('Web'); ?> |
|
diff --git a/htdocs/societe/canvas/company/tpl/card_edit.tpl.php b/htdocs/societe/canvas/company/tpl/card_edit.tpl.php
index 1f6201ec829..951d17c5b63 100644
--- a/htdocs/societe/canvas/company/tpl/card_edit.tpl.php
+++ b/htdocs/societe/canvas/company/tpl/card_edit.tpl.php
@@ -148,7 +148,7 @@ if ($this->control->tpl['fournisseur']) {
- | trans('EMail').($conf->global->SOCIETE_MAIL_REQUIRED?'*':''); ?> |
+ trans('EMail').($conf->global->SOCIETE_EMAIL_MANDATORY?'*':''); ?> |
|
trans('Web'); ?> |
|
diff --git a/htdocs/societe/canvas/individual/tpl/card_create.tpl.php b/htdocs/societe/canvas/individual/tpl/card_create.tpl.php
index 1be20214c35..44bf9dadf58 100644
--- a/htdocs/societe/canvas/individual/tpl/card_create.tpl.php
+++ b/htdocs/societe/canvas/individual/tpl/card_create.tpl.php
@@ -143,7 +143,7 @@
- | trans('EMail').($conf->global->SOCIETE_MAIL_REQUIRED?'*':''); ?> |
+ trans('EMail').($conf->global->SOCIETE_EMAIL_MANDATORY?'*':''); ?> |
|
trans('Web'); ?> |
|
diff --git a/htdocs/societe/canvas/individual/tpl/card_edit.tpl.php b/htdocs/societe/canvas/individual/tpl/card_edit.tpl.php
index 90543958902..81e0b66c103 100644
--- a/htdocs/societe/canvas/individual/tpl/card_edit.tpl.php
+++ b/htdocs/societe/canvas/individual/tpl/card_edit.tpl.php
@@ -145,7 +145,7 @@ if ($this->control->tpl['fournisseur']) {
- | trans('EMail').($conf->global->SOCIETE_MAIL_REQUIRED?'*':''); ?> |
+ trans('EMail').($conf->global->SOCIETE_EMAIL_MANDATORY?'*':''); ?> |
|
trans('Web'); ?> |
|
diff --git a/htdocs/societe/card.php b/htdocs/societe/card.php
index 53c5a1add14..00b463f647a 100644
--- a/htdocs/societe/card.php
+++ b/htdocs/societe/card.php
@@ -325,7 +325,6 @@ if (empty($reshook))
$action='create';
}
-
if ($action == 'update')
{
$ret=$object->fetch($socid);
@@ -333,7 +332,7 @@ if (empty($reshook))
}
else $object->canvas=$canvas;
- if (GETPOST("private") == 1)
+ if (GETPOST("private") == 1) // Ask to create a contact
{
$object->particulier = GETPOST("private");
@@ -356,14 +355,14 @@ if (empty($reshook))
$object->skype = GETPOST('skype', 'alpha');
$object->phone = GETPOST('phone', 'alpha');
$object->fax = GETPOST('fax','alpha');
- $object->email = GETPOST('email', 'custom', 0, FILTER_SANITIZE_EMAIL);
- $object->url = GETPOST('url', 'custom', 0, FILTER_SANITIZE_URL);
- $object->idprof1 = GETPOST('idprof1', 'alpha');
- $object->idprof2 = GETPOST('idprof2', 'alpha');
- $object->idprof3 = GETPOST('idprof3', 'alpha');
- $object->idprof4 = GETPOST('idprof4', 'alpha');
- $object->idprof5 = GETPOST('idprof5', 'alpha');
- $object->idprof6 = GETPOST('idprof6', 'alpha');
+ $object->email = trim(GETPOST('email', 'custom', 0, FILTER_SANITIZE_EMAIL));
+ $object->url = trim(GETPOST('url', 'custom', 0, FILTER_SANITIZE_URL));
+ $object->idprof1 = trim(GETPOST('idprof1', 'alpha'));
+ $object->idprof2 = trim(GETPOST('idprof2', 'alpha'));
+ $object->idprof3 = trim(GETPOST('idprof3', 'alpha'));
+ $object->idprof4 = trim(GETPOST('idprof4', 'alpha'));
+ $object->idprof5 = trim(GETPOST('idprof5', 'alpha'));
+ $object->idprof6 = trim(GETPOST('idprof6', 'alpha'));
$object->prefix_comm = GETPOST('prefix_comm', 'alpha');
$object->code_client = GETPOST('code_client', 'alpha');
$object->code_fournisseur = GETPOST('code_fournisseur', 'alpha');
@@ -383,7 +382,9 @@ if (empty($reshook))
$object->forme_juridique_code = GETPOST('forme_juridique_code', 'int');
$object->effectif_id = GETPOST('effectif_id', 'int');
- $object->typent_id = GETPOST('typent_id');
+ $object->typent_id = GETPOST('typent_id','int');
+
+ $object->typent_code = dol_getIdFromCode($db, $object->typent_id, 'c_typent', 'id', 'code'); // Force typent_code too so check in verify() will be done on new type
$object->client = GETPOST('client', 'int');
$object->fournisseur = GETPOST('fournisseur', 'int');
@@ -461,40 +462,6 @@ if (empty($reshook))
$object->country_code=$tmparray['code'];
$object->country=$tmparray['label'];
}
-
- // Check for duplicate or mandatory prof id
- // Only for companies
- if (!($object->particulier || $private))
- {
- for ($i = 1; $i <= 6; $i++)
- {
- $slabel="idprof".$i;
- $_POST[$slabel]=trim($_POST[$slabel]);
- $vallabel=$_POST[$slabel];
- if ($vallabel && $object->id_prof_verifiable($i))
- {
- if($object->id_prof_exists($i,$vallabel,$object->id))
- {
- $langs->load("errors");
- $error++; $errors[] = $langs->transcountry('ProfId'.$i, $object->country_code)." ".$langs->trans("ErrorProdIdAlreadyExist", $vallabel);
- $action = (($action=='add'||$action=='create')?'create':'edit');
- }
- }
-
- // Check for mandatory prof id (but only if country is than than ours)
- if ($mysoc->country_id > 0 && $object->country_id == $mysoc->country_id)
- {
- $idprof_mandatory ='SOCIETE_IDPROF'.($i).'_MANDATORY';
- if (! $vallabel && ! empty($conf->global->$idprof_mandatory))
- {
- $langs->load("errors");
- $error++;
- $errors[] = $langs->trans("ErrorProdIdIsMandatory", $langs->transcountry('ProfId'.$i, $object->country_code));
- $action = (($action=='add'||$action=='create')?'create':'edit');
- }
- }
- }
- }
}
if (! $error)
@@ -512,7 +479,7 @@ if (empty($reshook))
{
if ($object->particulier)
{
- dol_syslog("This thirdparty is a personal people",LOG_DEBUG);
+ dol_syslog("We ask to create a contact/address too", LOG_DEBUG);
$result=$object->create_individual($user);
if (! $result >= 0)
{
@@ -1152,7 +1119,7 @@ else
}
// Email web
- print '
| '.fieldLabel('EMail','email').(! empty($conf->global->SOCIETE_MAIL_REQUIRED)?'*':'').' | ';
+ print '
| '.fieldLabel('EMail','email',$conf->global->SOCIETE_EMAIL_MANDATORY).' | ';
print ' |
';
print '| '.fieldLabel('Web','url').' | ';
print ' |
';
@@ -1710,7 +1677,7 @@ else
}
// EMail / Web
- print '| '.fieldLabel('EMail','email',(! empty($conf->global->SOCIETE_MAIL_REQUIRED))).' | ';
+ print '
| '.fieldLabel('EMail','email',(! empty($conf->global->SOCIETE_EMAIL_MANDATORY))).' | ';
print ' |
';
print '| '.fieldLabel('Web','url').' | ';
print ' |
';
@@ -1740,7 +1707,7 @@ else
if (($j % 2) == 0) print '';
$idprof_mandatory ='SOCIETE_IDPROF'.($i).'_MANDATORY';
- if(empty($conf->global->$idprof_mandatory))
+ if (empty($conf->global->$idprof_mandatory) || ! $object->isACompany())
print '| '.fieldLabel($idprof,$key).' | ';
else
print ' | '.fieldLabel($idprof,$key).' | ';
diff --git a/htdocs/societe/class/api_deprecated_thirdparty.class.php b/htdocs/societe/class/api_deprecated_thirdparty.class.php
index b335fb35183..c31e4278f46 100644
--- a/htdocs/societe/class/api_deprecated_thirdparty.class.php
+++ b/htdocs/societe/class/api_deprecated_thirdparty.class.php
@@ -60,7 +60,7 @@ class ThirdpartyApi extends DolibarrApi
$this->company = new Societe($this->db);
$this->customer = new Client($this->db);
- if (! empty($conf->global->SOCIETE_MAIL_REQUIRED)) {
+ if (! empty($conf->global->SOCIETE_EMAIL_MANDATORY)) {
static::$FIELDS[] = 'email';
}
}
diff --git a/htdocs/societe/class/api_thirdparties.class.php b/htdocs/societe/class/api_thirdparties.class.php
index 24cf991da52..f25fda9a5fb 100644
--- a/htdocs/societe/class/api_thirdparties.class.php
+++ b/htdocs/societe/class/api_thirdparties.class.php
@@ -49,7 +49,7 @@ class Thirdparties extends DolibarrApi
$this->db = $db;
$this->company = new Societe($this->db);
- if (! empty($conf->global->SOCIETE_MAIL_REQUIRED)) {
+ if (! empty($conf->global->SOCIETE_EMAIL_MANDATORY)) {
static::$FIELDS[] = 'email';
}
}
diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php
index 2bd764c92ed..00f49046d45 100644
--- a/htdocs/societe/class/societe.class.php
+++ b/htdocs/societe/class/societe.class.php
@@ -400,7 +400,7 @@ class Societe extends CommonObject
*/
function create($user)
{
- global $langs,$conf;
+ global $langs,$conf,$mysoc;
$error=0;
@@ -422,14 +422,6 @@ class Societe extends CommonObject
dol_syslog(get_class($this)."::create ".$this->name);
- // Check parameters
- if (! empty($conf->global->SOCIETE_MAIL_REQUIRED) && ! isValidEMail($this->email))
- {
- $langs->load("errors");
- $this->error = $langs->trans("ErrorBadEMail",$this->email);
- return -1;
- }
-
$now=dol_now();
$this->db->begin();
@@ -438,7 +430,7 @@ class Societe extends CommonObject
if ($this->code_client == -1) $this->get_codeclient($this,0);
if ($this->code_fournisseur == -1) $this->get_codefournisseur($this,1);
- // Check more parameters
+ // Check more parameters (including mandatory setup
// If error, this->errors[] is filled
$result = $this->verify();
@@ -524,6 +516,7 @@ class Societe extends CommonObject
}
}
+
/**
* Create a contact/address from thirdparty
*
@@ -568,6 +561,9 @@ class Societe extends CommonObject
*/
function verify()
{
+ global $conf, $langs, $mysoc;
+
+ $error = 0;
$this->errors=array();
$result = 0;
@@ -630,6 +626,69 @@ class Societe extends CommonObject
}
}
+ // Check for duplicate or mandatory fields defined into setup
+ $array_to_check=array('IDPROF1','IDPROF2','IDPROF3','IDPROF4','IDPROF5','IDPROF6','EMAIL');
+ foreach($array_to_check as $key)
+ {
+ $keymin=strtolower($key);
+ $i=(int) preg_replace('/[^0-9]/','',$key);
+ $vallabel=$this->$keymin;
+
+ if ($i > 0)
+ {
+ if ($this->isACompany())
+ {
+ // Check for unicity
+ if ($vallabel && $this->id_prof_verifiable($i))
+ {
+ if ($this->id_prof_exists($keymin, $vallabel, ($this->id > 0 ? $this->id : 0)))
+ {
+ $langs->load("errors");
+ $error++; $this->errors[] = $langs->transcountry('ProfId'.$i, $this->country_code)." ".$langs->trans("ErrorProdIdAlreadyExist", $vallabel).' ('.$langs->trans("ForbiddenBySetupRules").')';
+ }
+ }
+
+ // Check for mandatory prof id (but only if country is other than ours)
+ if ($mysoc->country_id > 0 && $this->country_id == $mysoc->country_id)
+ {
+ $idprof_mandatory ='SOCIETE_'.$key.'_MANDATORY';
+ if (! $vallabel && ! empty($conf->global->$idprof_mandatory))
+ {
+ $langs->load("errors");
+ $error++;
+ $this->errors[] = $langs->trans("ErrorProdIdIsMandatory", $langs->transcountry('ProfId'.$i, $this->country_code)).' ('.$langs->trans("ForbiddenBySetupRules").')';
+ }
+ }
+ }
+ }
+ else
+ {
+ //var_dump($conf->global->SOCIETE_EMAIL_MANDATORY);
+ if ($key == 'EMAIL')
+ {
+ // Check for unicity
+ if ($vallabel)
+ {
+ if ($this->id_prof_exists($keymin, $vallabel, ($this->id > 0 ? $this->id : 0)))
+ {
+ $langs->load("errors");
+ $error++; $this->errors[] = $langs->transcountry('ProfId'.$i, $this->country_code)." ".$langs->trans("ErrorProdIdAlreadyExist", $vallabel).' ('.$langs->trans("ForbiddenBySetupRules").')';
+ }
+ }
+
+ // Check for mandatory
+ if (! empty($conf->global->SOCIETE_EMAIL_MANDATORY) && ! isValidEMail($this->email))
+ {
+ $langs->load("errors");
+ $error++;
+ $this->errors[] = $langs->trans("ErrorBadEMail", $this->email).' ('.$langs->trans("ForbiddenBySetupRules").')';
+ }
+ }
+ }
+ }
+
+ if ($error) $result = -4;
+
return $result;
}
@@ -719,13 +778,7 @@ class Societe extends CommonObject
$this->code_compta=trim($this->code_compta);
$this->code_compta_fournisseur=trim($this->code_compta_fournisseur);
- // Check parameters
- if (! empty($conf->global->SOCIETE_MAIL_REQUIRED) && ! isValidEMail($this->email))
- {
- $langs->load("errors");
- $this->error = $langs->trans("ErrorBadEMail",$this->email);
- return -1;
- }
+ // Check parameters. More tests are done later in the ->verify()
if (! is_numeric($this->client) && ! is_numeric($this->fournisseur))
{
$langs->load("errors");
@@ -2581,7 +2634,7 @@ class Societe extends CommonObject
/**
* Returns if a profid sould be verified
*
- * @param int $idprof 1,2,3,4 (Exemple: 1=siren,2=siret,3=naf,4=rcs/rm)
+ * @param int $idprof 1,2,3,4,5,6 (Exemple: 1=siren,2=siret,3=naf,4=rcs/rm,5=idprof5,6=idprof6)
* @return boolean true , false
*/
function id_prof_verifiable($idprof)
@@ -2602,6 +2655,12 @@ class Societe extends CommonObject
case 4:
$ret=(!$conf->global->SOCIETE_IDPROF4_UNIQUE?false:true);
break;
+ case 5:
+ $ret=(!$conf->global->SOCIETE_IDPROF5_UNIQUE?false:true);
+ break;
+ case 6:
+ $ret=(!$conf->global->SOCIETE_IDPROF6_UNIQUE?false:true);
+ break;
default:
$ret=false;
}
@@ -2612,28 +2671,40 @@ class Societe extends CommonObject
/**
* Verify if a profid exists into database for others thirds
*
- * @param int $idprof 1,2,3,4 (Example: 1=siren,2=siret,3=naf,4=rcs/rm)
+ * @param string $idprof 'idprof1','idprof2','idprof3','idprof4','idprof5','idprof6','email' (Example: idprof1=siren, idprof2=siret, idprof3=naf, idprof4=rcs/rm)
* @param string $value Value of profid
- * @param int $socid Id of thirdparty if update
- * @return boolean true if exists, false if not
+ * @param int $socid Id of thirdparty to exclude (if update)
+ * @return boolean True if exists, False if not
*/
- function id_prof_exists($idprof,$value,$socid=0)
+ function id_prof_exists($idprof, $value, $socid=0)
{
- switch($idprof)
+ $field = $idprof;
+
+ switch($idprof) // For backward compatibility
{
- case 1:
+ case '1':
+ case 'idprof1':
$field="siren";
break;
- case 2:
+ case '2':
+ case 'idprof2':
$field="siret";
break;
- case 3:
+ case '3':
+ case 'idprof3':
$field="ape";
break;
- case 4:
+ case '4':
+ case 'idprof4':
$field="idprof4";
break;
- }
+ case '5':
+ $field="idprof5";
+ break;
+ case '6':
+ $field="idprof6";
+ break;
+ }
//Verify duplicate entries
$sql = "SELECT COUNT(*) as idprof FROM ".MAIN_DB_PREFIX."societe WHERE ".$field." = '".$value."' AND entity IN (".getEntity('societe').")";
@@ -2895,7 +2966,7 @@ class Societe extends CommonObject
$isacompany=empty($conf->global->MAIN_UNKNOWN_CUSTOMERS_ARE_COMPANIES)?0:1; // 0 by default
if (! empty($this->tva_intra)) $isacompany=1;
else if (! empty($this->typent_code) && in_array($this->typent_code,array('TE_PRIVATE'))) $isacompany=0;
- else if (! empty($this->typent_code) && in_array($this->typent_code,array('TE_SMALL','TE_MEDIUM','TE_LARGE'))) $isacompany=1;
+ else if (! empty($this->typent_code) && in_array($this->typent_code,array('TE_SMALL','TE_MEDIUM','TE_LARGE','TE_GROUP'))) $isacompany=1;
return $isacompany;
}
|