diff --git a/htdocs/core/lib/usergroups.lib.php b/htdocs/core/lib/usergroups.lib.php index 276efe85f02..c76e2de77fc 100644 --- a/htdocs/core/lib/usergroups.lib.php +++ b/htdocs/core/lib/usergroups.lib.php @@ -195,6 +195,11 @@ function user_admin_prepare_head() $head[$h][0] = DOL_URL_ROOT.'/user/admin/user_extrafields.php'; $head[$h][1] = $langs->trans("ExtraFields"); $head[$h][2] = 'attributes'; + $h++; + + $head[$h][0] = DOL_URL_ROOT.'/user/admin/group_extrafields.php'; + $head[$h][1] = $langs->trans("ExtraFields")." ".$langs->trans("Groups"); + $head[$h][2] = 'attributes_group'; $h++; // Show more tabs from modules diff --git a/htdocs/install/mysql/migration/3.6.0-3.7.0.sql b/htdocs/install/mysql/migration/3.6.0-3.7.0.sql index 24cb1a6203d..47ecd5efa58 100644 --- a/htdocs/install/mysql/migration/3.6.0-3.7.0.sql +++ b/htdocs/install/mysql/migration/3.6.0-3.7.0.sql @@ -1046,4 +1046,11 @@ CREATE TABLE llx_fichinterdet_extrafields ALTER TABLE llx_fichinterdet_extrafields ADD INDEX idx_ficheinterdet_extrafields (fk_object); +CREATE TABLE IF NOT EXISTS llx_usergroup_extrafields ( + rowid integer AUTO_INCREMENT PRIMARY KEY, + tms timestamp, + fk_object integer NOT NULL, + import_key varchar(14) -- import key +) ENGINE=InnoDB ; +ALTER TABLE llx_usergroup_extrafields ADD INDEX idx_usergroup_extrafields (fk_object); diff --git a/htdocs/install/mysql/tables/llx_usergroup_extrafields.key.sql b/htdocs/install/mysql/tables/llx_usergroup_extrafields.key.sql new file mode 100644 index 00000000000..378f4514539 --- /dev/null +++ b/htdocs/install/mysql/tables/llx_usergroup_extrafields.key.sql @@ -0,0 +1,20 @@ +-- =================================================================== +-- Copyright (C) 2013 Alexis Algoud +-- +-- 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 3 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_usergroup_extrafields ADD INDEX idx_usergroup_extrafields (fk_object); diff --git a/htdocs/install/mysql/tables/llx_usergroup_extrafields.sql b/htdocs/install/mysql/tables/llx_usergroup_extrafields.sql new file mode 100644 index 00000000000..333eb41ad08 --- /dev/null +++ b/htdocs/install/mysql/tables/llx_usergroup_extrafields.sql @@ -0,0 +1,26 @@ +-- =================================================================== +-- Copyright (C) 2014 Alexis Algoud +-- +-- 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 3 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 IF NOT EXISTS llx_usergroup_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/user/admin/group_extrafields.php b/htdocs/user/admin/group_extrafields.php new file mode 100644 index 00000000000..dbb9e863af4 --- /dev/null +++ b/htdocs/user/admin/group_extrafields.php @@ -0,0 +1,155 @@ + + * Copyright (C) 2003 Jean-Louis Bergamo + * Copyright (C) 2004-2012 Laurent Destailleur + * Copyright (C) 2012 Regis Houssin + * Copyright (C) 2014 Alexis Algoud + * + * 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 3 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_extrafields.php + * \ingroup member + * \brief Page to setup extra fields of members + */ + +require '../../main.inc.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/usergroups.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; + +$langs->load("users"); +$langs->load("admin"); + +$extrafields = new ExtraFields($db); +$form = new Form($db); + +// List of supported format +$tmptype2label=ExtraFields::$type2label; +$type2label=array(''); +foreach ($tmptype2label as $key => $val) $type2label[$key]=$langs->trans($val); + +$action=GETPOST('action', 'alpha'); +$attrname=GETPOST('attrname', 'alpha'); +$elementtype='usergroup'; //Must be the $table_element of the class that manage extrafield + +if (!$user->admin) accessforbidden(); + + +/* + * Actions + */ + +require DOL_DOCUMENT_ROOT.'/core/actions_extrafields.inc.php'; + + + +/* + * View + */ + +$textobject=$langs->transnoentitiesnoconv("Groups"); + +$help_url='EN:Module_Users|FR:Module_Utilisateurs|ES:Módulo_Usuarios'; +llxHeader('',$langs->trans("UsersSetup"),$help_url); + + +$linkback=''.$langs->trans("BackToModuleList").''; +print_fiche_titre($langs->trans("UsersSetup"),$linkback,'setup'); + + +$head = user_admin_prepare_head(); + +dol_fiche_head($head, 'attributes_group', $langs->trans("Group"), 0, 'user'); + + +print $langs->trans("DefineHereComplementaryAttributes",$textobject).'
'."\n"; +print '
'; + +// 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/user/class/usergroup.class.php b/htdocs/user/class/usergroup.class.php index b801c2660aa..3b6be065879 100644 --- a/htdocs/user/class/usergroup.class.php +++ b/htdocs/user/class/usergroup.class.php @@ -4,7 +4,8 @@ * Copyright (c) 2005-2012 Regis Houssin * Copyright (C) 2012 Florian Henry * Copyright (C) 2014 Juanjo Menent - * + * Copyright (C) 2014 Alexis Algoud + * * 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 3 of the License, or @@ -105,6 +106,15 @@ class UserGroup extends CommonObject $this->members=$this->listUsersForGroup(); + + // Retreive all extrafield for group + // fetch optionals attributes and labels + dol_include_once('/core/class/extrafields.class.php'); + $extrafields=new ExtraFields($this->db); + $extralabels=$extrafields->fetch_name_optionals_label($this->table_element,true); + $this->fetch_optionals($this->id,$extralabels); + + // Sav current LDAP Current DN //$this->ldap_dn = $this->_load_ldap_dn($this->_load_ldap_info(),0); } @@ -539,6 +549,17 @@ class UserGroup extends CommonObject $sql .= " WHERE fk_usergroup = ".$this->id; $this->db->query($sql); + // Remove extrafields + if ((! $error) && (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED))) // For avoid conflicts if trigger used + { + $result=$this->deleteExtraFields(); + if ($result < 0) + { + $error++; + dol_syslog(get_class($this)."::delete error -4 ".$this->error, LOG_ERR); + } + } + $sql = "DELETE FROM ".MAIN_DB_PREFIX."usergroup"; $sql .= " WHERE rowid = ".$this->id; $result=$this->db->query($sql); @@ -568,7 +589,7 @@ class UserGroup extends CommonObject */ function create($notrigger=0) { - global $user, $conf, $langs; + global $user, $conf, $langs, $hookmanager; $error=0; $now=dol_now(); @@ -605,8 +626,28 @@ class UserGroup extends CommonObject if ($result < 0) { $error++; $this->db->rollback(); return -1; } // End call triggers } - - $this->db->commit(); + + + // Actions on extra fields (by external module or standard code) + $hookmanager->initHooks(array('groupdao')); + $parameters=array(); + $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++; + + if ($error > 0) { $error++; $this->db->rollback(); return -1; } + else $this->db->commit(); + return $this->id; } else @@ -625,7 +666,7 @@ class UserGroup extends CommonObject */ function update($notrigger=0) { - global $user, $conf, $langs; + global $user, $conf, $langs, $hookmanager; $error=0; @@ -654,7 +695,24 @@ class UserGroup extends CommonObject if ($result < 0) { $error++; } // End call triggers } - + + // Actions on extra fields (by external module or standard code) + $hookmanager->initHooks(array('groupdao')); + $parameters=array(); + $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++; + if (! $error) { $this->db->commit(); diff --git a/htdocs/user/group/fiche.php b/htdocs/user/group/fiche.php index f97ef35ae6e..00dcc4c4cfb 100644 --- a/htdocs/user/group/fiche.php +++ b/htdocs/user/group/fiche.php @@ -4,6 +4,7 @@ * Copyright (C) 2005-2012 Regis Houssin * Copyright (C) 2011 Herve Prot * Copyright (C) 2012 Florian Henry + * Copyright (C) 2014 Alexis Algoud * * 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 @@ -29,6 +30,8 @@ require_once DOL_DOCUMENT_ROOT.'/user/class/usergroup.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/usergroups.lib.php'; if(! empty($conf->multicompany->enabled)) dol_include_once('/multicompany/class/actions_multicompany.class.php'); +dol_include_once('/core/class/extrafields.class.php'); + // Defini si peux lire/modifier utilisateurs et permisssions $canreadperms=($user->admin || $user->rights->user->user->lire); $caneditperms=($user->admin || $user->rights->user->user->creer); @@ -59,6 +62,9 @@ if (! empty($conf->multicompany->enabled) && $conf->entity > 1 && $conf->multico $object = new Usergroup($db); +$extrafields = new ExtraFields($db); +// fetch optionals attributes and labels +$extralabels=$extrafields->fetch_name_optionals_label($object->table_element); /** * Action remove group @@ -93,6 +99,9 @@ if ($action == 'add') $object->nom = trim($_POST["nom"]); $object->note = trim($_POST["note"]); + // Fill array 'array_options' with data from add form + $ret = $extrafields->setOptionalsFromPost($extralabels,$object); + if (! empty($conf->multicompany->enabled) && ! empty($conf->multicompany->transverse_mode)) $object->entity = 0; else $object->entity = $_POST["entity"]; @@ -171,6 +180,9 @@ if ($action == 'update') $object->nom = trim($_POST["group"]); $object->note = dol_htmlcleanlastbr($_POST["note"]); + // Fill array 'array_options' with data from add form + $ret = $extrafields->setOptionalsFromPost($extralabels,$object); + if (! empty($conf->multicompany->enabled) && ! empty($conf->multicompany->transverse_mode)) $object->entity = 0; else $object->entity = $_POST["entity"]; @@ -240,6 +252,15 @@ if ($action == 'create') $doleditor=new DolEditor('note','','',240,'dolibarr_notes','',false,true,$conf->global->FCKEDITOR_ENABLE_SOCIETE,ROWS_8,90); $doleditor->Create(); print "\n"; + + // Other attributes + $parameters=array('object' => $object, 'colspan' => ' colspan="2"'); + $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)) + { + print $object->showOptionals($extrafields,'edit'); + } + print "\n"; print '

'; @@ -311,6 +332,16 @@ else print ''.$langs->trans("Note").''; print ''.dol_htmlentitiesbr($object->note).' '; print "\n"; + + // Other attributes + $parameters=array('colspan' => ' colspan="2"'); + $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)) + { + print $object->showOptionals($extrafields); + } + + print "\n"; print ''; @@ -495,6 +526,14 @@ else $doleditor->Create(); print ''; print "\n"; + // Other attributes + $parameters=array('colspan' => ' colspan="2"'); + $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)) + { + print $object->showOptionals($extrafields,'edit'); + } + print "\n"; print '

';