diff --git a/htdocs/adherents/admin/adherent_type_extrafields.php b/htdocs/adherents/admin/adherent_type_extrafields.php new file mode 100644 index 00000000000..6afc89e7498 --- /dev/null +++ b/htdocs/adherents/admin/adherent_type_extrafields.php @@ -0,0 +1,158 @@ + + * Copyright (C) 2003 Jean-Louis Bergamo + * Copyright (C) 2004-2012 Laurent Destailleur + * Copyright (C) 2012 Regis Houssin + * Copyright (C) 2013 Florian Henry + * + * 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 . + */ + +/** + * \file htdocs/adherents/admin/adherent_type_extrafields.php + * \ingroup member + * \brief Page to setup extra fields of members + */ + +require '../../main.inc.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/member.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; + +$langs->load("members"); +$langs->load("admin"); + +$extrafields = new ExtraFields($db); +$form = new Form($db); + +// List of supported format +$tmptype2label=getStaticMember(get_class($extrafields),'type2label'); +$type2label=array(''); +foreach ($tmptype2label as $key => $val) $type2label[$key]=$langs->trans($val); + +$action=GETPOST('action', 'alpha'); +$attrname=GETPOST('attrname', 'alpha'); +$elementtype='adherent_type'; + +if (!$user->admin) accessforbidden(); + + +/* + * Actions + */ + +require DOL_DOCUMENT_ROOT.'/core/admin_extrafields.inc.php'; + + + +/* + * View + */ + +$textobject=$langs->transnoentitiesnoconv("Members"); + +$help_url='EN:Module_Foundations|FR:Module_Adhérents|ES:Módulo_Miembros'; +llxHeader('',$langs->trans("MembersSetup"),$help_url); + + +$linkback=''.$langs->trans("BackToModuleList").''; +print_fiche_titre($langs->trans("MembersSetup"),$linkback,'setup'); + + +$head = member_admin_prepare_head(); + +dol_fiche_head($head, 'attributes_type', $langs->trans("Member"), 0, 'user'); + + +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 ''; +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 '\n"; + print '\n"; + print ""; + // $i++; +} + +print "
'.$langs->trans("Label").''.$langs->trans("AttributeCode").''.$langs->trans("Type").''.$langs->trans("Size").''.$langs->trans("Unique").''.$langs->trans("Required").' 
".$extrafields->attribute_label[$key]."".$key."".$type2label[$extrafields->attribute_type[$key]]."'.$extrafields->attribute_size[$key]."'.yn($extrafields->attribute_unique[$key])."'.yn($extrafields->attribute_required[$key])."'.img_edit().''; + print "  ".img_delete()."
"; + +dol_fiche_end(); + + +// Buttons +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')); + + require DOL_DOCUMENT_ROOT.'/core/tpl/admin_extrafields_add.tpl.php'; +} + +/* ************************************************************************** */ +/* */ +/* Edition d'un champ optionnel */ +/* */ +/* ************************************************************************** */ +if ($action == 'edit' && ! empty($attrname)) +{ + print "
"; + print_titre($langs->trans("FieldEdition", $attrname)); + + require DOL_DOCUMENT_ROOT.'/core/tpl/admin_extrafields_edit.tpl.php'; +} + +llxFooter(); + +$db->close(); +?> diff --git a/htdocs/adherents/class/adherent_type.class.php b/htdocs/adherents/class/adherent_type.class.php index d61bb24a8c9..86ae0b803ea 100644 --- a/htdocs/adherents/class/adherent_type.class.php +++ b/htdocs/adherents/class/adherent_type.class.php @@ -43,7 +43,6 @@ class AdherentType extends CommonObject var $mail_valid; //mail envoye lors de la validation - /** * Constructor * @@ -114,6 +113,26 @@ class AdherentType extends CommonObject $result = $this->db->query($sql); if ($result) { + // 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('membertypedao')); + $parameters=array('membertype'=>$this->id); + $reshook=$hookmanager->executeHooks('insertExtraFields',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks + if (empty($reshook)) + { + if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used + { + $result=$this->insertExtraFields(); + if ($result < 0) + { + $error++; + } + } + } + else if ($reshook < 0) $error++; + + return 1; } else diff --git a/htdocs/adherents/type.php b/htdocs/adherents/type.php index d36fdb0deba..71c94d56c41 100644 --- a/htdocs/adherents/type.php +++ b/htdocs/adherents/type.php @@ -3,6 +3,7 @@ * Copyright (C) 2003 Jean-Louis Bergamo * Copyright (C) 2004-2011 Laurent Destailleur * Copyright (C) 2005-2012 Regis Houssin + * Copyright (C) 2013 Florian Henry * * 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 @@ -27,6 +28,7 @@ require '../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php'; require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent_type.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; $langs->load("members"); @@ -52,6 +54,8 @@ if (! $sortfield) { $sortfield="d.nom"; } // Security check $result=restrictedArea($user,'adherent',$rowid,'adherent_type'); +$extrafields = new ExtraFields($db); + if (GETPOST('button_removefilter')) { $search_lastname=""; @@ -62,6 +66,10 @@ if (GETPOST('button_removefilter')) } +// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array +include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; +$hookmanager=new HookManager($db); +$hookmanager->initHooks(array('membertypecard')); /* * Actions @@ -77,6 +85,15 @@ if ($action == 'add' && $user->rights->adherent->configurer) $adht->note = trim($_POST["comment"]); $adht->mail_valid = trim($_POST["mail_valid"]); $adht->vote = trim($_POST["vote"]); + + // Get extra fields + foreach($_POST as $key => $value) + { + if (preg_match("/^options_/",$key)) + { + $adht->array_options[$key]=GETPOST($key); + } + } if ($adht->libelle) { @@ -112,6 +129,15 @@ if ($action == 'update' && $user->rights->adherent->configurer) $adht->mail_valid = trim($_POST["mail_valid"]); $adht->vote = trim($_POST["vote"]); + // Get extra fields + foreach($_POST as $key => $value) + { + if (preg_match("/^options_/",$key)) + { + $adht->array_options[$key]=GETPOST($key); + } + } + $adht->update($user->id); header("Location: ".$_SERVER["PHP_SELF"]."?rowid=".$_POST["rowid"]); @@ -143,6 +169,8 @@ llxHeader('',$langs->trans("MembersTypeSetup"),'EN:Module_Foundations|FR:Module_ $form=new Form($db); +// fetch optionals attributes and labels +$extralabels=$extrafields->fetch_name_optionals_label('adherent_type'); // Liste of members type @@ -248,9 +276,28 @@ if ($action == 'create') $doleditor=new DolEditor('mail_valid',$adht->mail_valid,'',280,'dolibarr_notes','',false,true,$conf->fckeditor->enabled,15,90); $doleditor->Create(); print ''; - + + // Other attributes + $parameters=array(); + $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$act,$action); // Note that $action and $object may have been modified by hook + print "\n"; + if (empty($reshook) && ! empty($extrafields->attribute_label)) + { + print '

'; + foreach($extrafields->attribute_label as $key=>$label) + { + $value=(isset($_POST["options_".$key])?$_POST["options_".$key]:$act->array_options["options_".$key]); + print 'attribute_required[$key])) print ' class="fieldrequired"'; + print ' width="30%">'.$label.''."\n"; + } + print '
'; + print $extrafields->showInputField($key,$value); + print '


'; + } + print '
'; print '
    '; print '
'; @@ -269,6 +316,7 @@ if ($rowid > 0) { $adht = new AdherentType($db); $adht->fetch($rowid); + $adht->fetch_optionals($rowid,$extralabels); $h=0; @@ -307,7 +355,25 @@ if ($rowid > 0) print ''.$langs->trans("WelcomeEMail").''; print nl2br($adht->mail_valid).""; + // Other attributes + $parameters=array(); + $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$act,$action); // Note that $action and $object may have been modified by hook + print ''; + + //Extra field + if (empty($reshook) && ! empty($extrafields->attribute_label)) + { + print '

'; + foreach($extrafields->attribute_label as $key=>$label) + { + $value=(isset($_POST["options_".$key])?$_POST["options_".$key]:(isset($adht->array_options['options_'.$key])?$adht->array_options['options_'.$key]:'')); + print '\n"; + } + print '
'.$label.''; + print $extrafields->showOutputField($key,$value); + print "


'; + } print ''; @@ -593,7 +659,7 @@ if ($rowid > 0) $adht = new AdherentType($db); $adht->id = $rowid; $adht->fetch($rowid); - + $adht->fetch_optionals($rowid,$extralabels); $h=0; @@ -630,8 +696,26 @@ if ($rowid > 0) $doleditor=new DolEditor('mail_valid',$adht->mail_valid,'',280,'dolibarr_notes','',false,true,$conf->fckeditor->enabled,15,90); $doleditor->Create(); print ""; + + // Other attributes + $parameters=array(); + $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$act,$action); // Note that $action and $object may have been modified by hook print ''; + + //Extra field + if (empty($reshook) && ! empty($extrafields->attribute_label)) + { + print '

'; + foreach($extrafields->attribute_label as $key=>$label) + { + $value=(isset($_POST["options_".$key])?$_POST["options_".$key]:(isset($adht->array_options['options_'.$key])?$adht->array_options['options_'.$key]:'')); + print '\n"; + } + print '
'.$label.''; + print $extrafields->showInputField($key,$value); + print "


'; + } print '
   '; print '
'; diff --git a/htdocs/core/lib/member.lib.php b/htdocs/core/lib/member.lib.php index 835708295c3..eb6b4100f7f 100644 --- a/htdocs/core/lib/member.lib.php +++ b/htdocs/core/lib/member.lib.php @@ -127,9 +127,14 @@ function member_admin_prepare_head() complete_head_from_modules($conf,$langs,'',$head,$h,'member_admin'); $head[$h][0] = DOL_URL_ROOT.'/adherents/admin/adherent_extrafields.php'; - $head[$h][1] = $langs->trans("ExtraFields"); + $head[$h][1] = $langs->trans("ExtraFieldsMember"); $head[$h][2] = 'attributes'; $h++; + + $head[$h][0] = DOL_URL_ROOT.'/adherents/admin/adherent_type_extrafields.php'; + $head[$h][1] = $langs->trans("ExtraFieldsMemberType"); + $head[$h][2] = 'attributes_type'; + $h++; $head[$h][0] = DOL_URL_ROOT.'/adherents/admin/public.php'; $head[$h][1] = $langs->trans("BlankSubscriptionForm"); diff --git a/htdocs/install/mysql/tables/llx_adherent_type_extrafields.key.sql b/htdocs/install/mysql/tables/llx_adherent_type_extrafields.key.sql new file mode 100755 index 00000000000..a2b3f234816 --- /dev/null +++ b/htdocs/install/mysql/tables/llx_adherent_type_extrafields.key.sql @@ -0,0 +1,20 @@ +-- =================================================================== +-- Copyright (C) 2013 Florian HENRY +-- +-- 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 . +-- +-- =================================================================== + + +ALTER TABLE llx_adherent_type_extrafields ADD INDEX idx_adherent_type_extrafields (fk_object); diff --git a/htdocs/install/mysql/tables/llx_adherent_type_extrafields.sql b/htdocs/install/mysql/tables/llx_adherent_type_extrafields.sql new file mode 100755 index 00000000000..8f527e73da6 --- /dev/null +++ b/htdocs/install/mysql/tables/llx_adherent_type_extrafields.sql @@ -0,0 +1,26 @@ +-- ======================================================================== +-- Copyright (C) 2013 Florian HENRY +-- +-- 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 . +-- +-- ======================================================================== + +create table llx_adherent_type_extrafields +( + rowid integer AUTO_INCREMENT PRIMARY KEY, + tms timestamp, + fk_object integer NOT NULL, + import_key varchar(14) -- import key +) ENGINE=innodb; + diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang index 9586ce352a8..6007be581fc 100644 --- a/htdocs/langs/en_US/admin.lang +++ b/htdocs/langs/en_US/admin.lang @@ -928,6 +928,8 @@ DefineHereComplementaryAttributes=Define here all atributes, not already availab ExtraFields=Complementary attributes ExtraFieldsThirdParties=Complementary attributes (thirdparty) ExtraFieldsContacts=Complementary attributes (contact/address) +ExtraFieldsMember=Complementary attributes (member) +ExtraFieldsMemberType=Complementary attributes (Member type) ExtraFieldHasWrongValue=Attribut %s has a wrong value. AlphaNumOnlyCharsAndNoSpace=only alphanumericals characters without space SendingMailSetup=Setup of sendings by email diff --git a/htdocs/langs/fr_FR/admin.lang b/htdocs/langs/fr_FR/admin.lang index adb0a063d5d..d077ffedb4e 100644 --- a/htdocs/langs/fr_FR/admin.lang +++ b/htdocs/langs/fr_FR/admin.lang @@ -925,6 +925,8 @@ DefineHereComplementaryAttributes=Définissez ici la liste des attributs supplé ExtraFields=Attributs suplémentaires ExtraFieldsThirdParties=Attributs suplémentaires (tiers) ExtraFieldsContacts=Attributs suplémentaires (contacts/adresses) +ExtraFieldsMember=Attributs suplémentaires (adhérents) +ExtraFieldsMemberType=Attributs suplémentaires (type d'adhérents) ExtraFieldHasWrongValue=L'attribut %s a une valeur incorrecte. AlphaNumOnlyCharsAndNoSpace=uniquement caractères alphanumériques sans espace SendingMailSetup=Configuration de l'envoi par mail