diff --git a/ChangeLog b/ChangeLog index 2dcfde3a4d1..e511b0e9b86 100644 --- a/ChangeLog +++ b/ChangeLog @@ -29,6 +29,7 @@ For users: - New: Add link to third party into sells and purchase journal. - New: Suggest a method to generate a backup file for user with no access to mysqldump binary. +- New: Can use extrafields on contacts/addresses. - New: Extra fields supports more types (now int, string, double, date, datetime). - New: Can correct stock of a warehouse from warehouse card. - New: [ task #185 ]: Can input amount when correcting stock to recalculate PMP. diff --git a/htdocs/adherents/admin/adherent_extrafields.php b/htdocs/adherents/admin/adherent_extrafields.php index 7d39eb33883..e948b54482f 100755 --- a/htdocs/adherents/admin/adherent_extrafields.php +++ b/htdocs/adherents/admin/adherent_extrafields.php @@ -148,7 +148,7 @@ if ($action == 'create') print $form->selectarray('type',$type2label,GETPOST('type')); print ''; // Size - print ''.$langs->trans("Size").''; + print ''.$langs->trans("Size").''; print ''; diff --git a/htdocs/contact/class/contact.class.php b/htdocs/contact/class/contact.class.php index 7e09f688d2a..e5cd3bed15f 100644 --- a/htdocs/contact/class/contact.class.php +++ b/htdocs/contact/class/contact.class.php @@ -263,6 +263,22 @@ class Contact extends CommonObject unset($this->state_code); unset($this->state); + // Actions on extra fields (by external module or standard code) + include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; + $hookmanager=new HookManager($this->db); + $hookmanager->initHooks(array('contactdao')); + $parameters=array('socid'=>$this->id); + $reshook=$hookmanager->executeHooks('insertExtraFields',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks + if (empty($reshook)) + { + $result=$this->insertExtraFields(); + if ($result < 0) + { + $error++; + } + } + else if ($reshook < 0) $error++; + if (! $error && ! $notrigger) { // Appel des triggers @@ -809,11 +825,11 @@ class Contact extends CommonObject $sql.= " FROM ".MAIN_DB_PREFIX."mailing_cibles as mc"; $sql.= " WHERE mc.email = '".$this->db->escape($this->email)."'"; $sql.= " AND mc.statut NOT IN (-1,0)"; // -1 erreur, 0 non envoye, 1 envoye avec succes - + dol_syslog(get_class($this)."::getNbOfEMailings sql=".$sql, LOG_DEBUG); - + $resql=$this->db->query($sql); - + if ($resql) { $obj = $this->db->fetch_object($resql); diff --git a/htdocs/contact/fiche.php b/htdocs/contact/fiche.php index 07d2ee9e5c2..78c9e7e01e7 100644 --- a/htdocs/contact/fiche.php +++ b/htdocs/contact/fiche.php @@ -31,6 +31,7 @@ require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/contact.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; $langs->load("companies"); $langs->load("users"); @@ -47,6 +48,7 @@ $socid = GETPOST('socid','int'); if ($user->societe_id) $socid=$user->societe_id; $object = new Contact($db); +$extrafields = new ExtraFields($db); // Get object canvas (By default, this is not defined, so standard usage of dolibarr) $object->getCanvas($id); @@ -74,6 +76,7 @@ $hookmanager->initHooks(array('contactcard')); $parameters=array('id'=>$id, 'objcanvas'=>$objcanvas); $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks +$error=$hookmanager->error; $errors=array_merge($errors, (array) $hookmanager->errors); if (empty($reshook)) { @@ -154,6 +157,15 @@ if (empty($reshook)) $object->birthday = dol_mktime(0,0,0,$_POST["birthdaymonth"],$_POST["birthdayday"],$_POST["birthdayyear"]); $object->birthday_alert = $_POST["birthday_alert"]; + // Get extra fields + foreach($_POST as $key => $value) + { + if (preg_match("/^options_/",$key)) + { + $object->array_options[$key]=GETPOST($key); + } + } + if (! $_POST["lastname"]) { $error++; $errors[]=$langs->trans("ErrorFieldRequired",$langs->transnoentities("Lastname").' / '.$langs->transnoentities("Label")); @@ -242,6 +254,15 @@ if (empty($reshook)) $object->priv = $_POST["priv"]; $object->note = $_POST["note"]; + // Get extra fields + foreach($_POST as $key => $value) + { + if (preg_match("/^options_/",$key)) + { + $object->array_options[$key]=GETPOST($key); + } + } + $result = $object->update($_POST["contactid"], $user); if ($result > 0) @@ -264,6 +285,9 @@ if (empty($reshook)) * View */ +// fetch optionals attributes and labels +$extralabels=$extrafields->fetch_name_optionals_label('contact'); + $help_url='EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas'; llxHeader('',$langs->trans("ContactsAddresses"),$help_url); @@ -314,12 +338,9 @@ else { // Si edition contact deja existant $object = new Contact($db); - $return=$object->fetch($id, $user); - if ($return <= 0) - { - dol_print_error('',$object->error); - $id=0; - } + $res=$object->fetch($id, $user); + if ($res < 0) { dol_print_error($db,$object->error); exit; } + $res=$object->fetch_optionals($object->id,$extralabels); // Show tabs $head = contact_prepare_head($object); @@ -471,6 +492,20 @@ else // Note print ''.$langs->trans("Note").''; + // Other attributes + $parameters=array('colspan' => ' colspan="3"'); + $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook + if (empty($reshook) && ! empty($extrafields->attribute_label)) + { + foreach($extrafields->attribute_label as $key=>$label) + { + $value=(isset($_POST["options_".$key])?$_POST["options_".$key]:(isset($object->array_options["options_".$key])?$object->array_options["options_".$key]:'')); + print ''.$label.''; + print $extrafields->showInputField($key,$value); + print ''."\n"; + } + } + print "
"; @@ -503,10 +538,6 @@ else } print ''; - // Other attributes - $parameters=array('colspan' => ' colspan="3"'); - $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook - print "

"; @@ -651,11 +682,26 @@ else print $form->selectarray('priv',$selectarray,$object->priv,0); print ''; + // Note print ''.$langs->trans("Note").''; print ''; + // Other attributes + $parameters=array('colspan' => ' colspan="3"'); + $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook + if (empty($reshook) && ! empty($extrafields->attribute_label)) + { + foreach($extrafields->attribute_label as $key=>$label) + { + $value=(isset($_POST["options_".$key])?$_POST["options_".$key]:$object->array_options["options_".$key]); + print ''.$label.''; + print $extrafields->showInputField($key,$value); + print "\n"; + } + } + $object->load_ref_elements(); if (! empty($conf->commande->enabled)) @@ -697,10 +743,6 @@ else else print $langs->trans("NoDolibarrAccess"); print ''; - // Other attributes - $parameters=array('colspan' => ' colspan="3"'); - $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook - print '
'; print '
'; @@ -851,10 +893,25 @@ else print $object->LibPubPriv($object->priv); print ''; + // Note print ''.$langs->trans("Note").''; print nl2br($object->note); print ''; + // Other attributes + $parameters=array('socid'=>$socid, 'colspan' => ' colspan="3"'); + $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook + if (empty($reshook) && ! empty($extrafields->attribute_label)) + { + foreach($extrafields->attribute_label as $key=>$label) + { + $value=(isset($_POST["options_".$key])?$_POST["options_".$key]:(isset($object->array_options['options_'.$key])?$object->array_options['options_'.$key]:'')); + print ''.$label.''; + print $extrafields->showOutputField($key,$value); + print "\n"; + } + } + $object->load_ref_elements(); if (! empty($conf->commande->enabled)) @@ -895,10 +952,6 @@ else else print $langs->trans("NoDolibarrAccess"); print ''; - // Other attributes - $parameters=array('colspan' => ' colspan="3"'); - $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook - print ""; print ""; diff --git a/htdocs/core/lib/company.lib.php b/htdocs/core/lib/company.lib.php index 77b571e51c4..cace19d0c88 100644 --- a/htdocs/core/lib/company.lib.php +++ b/htdocs/core/lib/company.lib.php @@ -197,13 +197,10 @@ function societe_admin_prepare_head($object) $head[$h][2] = 'attributes'; $h++; - if ($conf->global->MAIN_FEATURES_LEVEL >= 2) - { - $head[$h][0] = DOL_URL_ROOT.'/societe/admin/contact_extrafields.php'; - $head[$h][1] = $langs->trans("ExtraFieldsContacts"); - $head[$h][2] = 'attributes_contacts'; - $h++; - } + $head[$h][0] = DOL_URL_ROOT.'/societe/admin/contact_extrafields.php'; + $head[$h][1] = $langs->trans("ExtraFieldsContacts"); + $head[$h][2] = 'attributes_contacts'; + $h++; complete_head_from_modules($conf,$langs,$object,$head,$h,'company_admin','remove'); diff --git a/htdocs/core/tpl/admin_extrafields.tpl.php b/htdocs/core/tpl/admin_extrafields.tpl.php new file mode 100644 index 00000000000..2291d9afc6c --- /dev/null +++ b/htdocs/core/tpl/admin_extrafields.tpl.php @@ -0,0 +1,39 @@ + + * + * 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 . + */ +?> + + + + diff --git a/htdocs/product/admin/product_extrafields.php b/htdocs/product/admin/product_extrafields.php index 67dea9bb7a9..9c9276669af 100755 --- a/htdocs/product/admin/product_extrafields.php +++ b/htdocs/product/admin/product_extrafields.php @@ -146,6 +146,8 @@ if ($action == 'create') print "
"; print_titre($langs->trans('NewAttribute')); + require DOL_DOCUMENT_ROOT.'/core/tpl/admin_extrafields.tpl.php'; + print '
'; print ''; print ''; @@ -161,7 +163,7 @@ if ($action == 'create') print $form->selectarray('type',$type2label,GETPOST('type')); print ''; // Size - print ''; + print ''; print "
'.$langs->trans("Size").'
'.$langs->trans("Size").'
\n"; diff --git a/htdocs/societe/admin/contact_extrafields.php b/htdocs/societe/admin/contact_extrafields.php index 4a67f92f320..8accb58f138 100755 --- a/htdocs/societe/admin/contact_extrafields.php +++ b/htdocs/societe/admin/contact_extrafields.php @@ -133,6 +133,8 @@ if ($action == 'create') print "
"; print_titre($langs->trans('NewAttribute')); + require DOL_DOCUMENT_ROOT.'/core/tpl/admin_extrafields.tpl.php'; + print ''; print ''; print ''; @@ -148,7 +150,7 @@ if ($action == 'create') print $form->selectarray('type',$type2label,GETPOST('type')); print ''; // Size - print ''; + print ''; print "
'.$langs->trans("Size").'
'.$langs->trans("Size").'
\n"; diff --git a/htdocs/societe/admin/societe_extrafields.php b/htdocs/societe/admin/societe_extrafields.php index cb0fd9df275..1b053ea4b50 100755 --- a/htdocs/societe/admin/societe_extrafields.php +++ b/htdocs/societe/admin/societe_extrafields.php @@ -133,6 +133,8 @@ if ($action == 'create') print "
"; print_titre($langs->trans('NewAttribute')); + require DOL_DOCUMENT_ROOT.'/core/tpl/admin_extrafields.tpl.php'; + print ''; print ''; print ''; @@ -148,7 +150,7 @@ if ($action == 'create') print $form->selectarray('type',$type2label,GETPOST('type')); print ''; // Size - print ''; + print ''; print "
'.$langs->trans("Size").'
'.$langs->trans("Size").'
\n";