diff --git a/htdocs/core/lib/usergroups.lib.php b/htdocs/core/lib/usergroups.lib.php index 276efe85f02d702d14fd8e6fb395fdf0c3b9d650..c76e2de77fc652b082c960a3bcbc53c1a5975233 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 24cb1a6203de2f6390c5e30d6674eeb0328330a9..47ecd5efa580ba30ec83f335a2d0ef6f7a545689 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 0000000000000000000000000000000000000000..378f45145391cb0a796c0e88bb3460c94312b496 --- /dev/null +++ b/htdocs/install/mysql/tables/llx_usergroup_extrafields.key.sql @@ -0,0 +1,20 @@ +-- =================================================================== +-- Copyright (C) 2013 Alexis Algoud <alexis@atm-consulting.fr> +-- +-- 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 <http://www.gnu.org/licenses/>. +-- +-- =================================================================== + + +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 0000000000000000000000000000000000000000..333eb41ad084626bb15b3e8f874b2a167dc1f192 --- /dev/null +++ b/htdocs/install/mysql/tables/llx_usergroup_extrafields.sql @@ -0,0 +1,26 @@ +-- =================================================================== +-- Copyright (C) 2014 Alexis Algoud <alexis@atm-consulting.fr> +-- +-- 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 <http://www.gnu.org/licenses/>. +-- +-- =================================================================== + +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 0000000000000000000000000000000000000000..dbb9e863af4bc0f4a5c435d859367c2349b7e1d9 --- /dev/null +++ b/htdocs/user/admin/group_extrafields.php @@ -0,0 +1,155 @@ +<?php +/* Copyright (C) 2001-2002 Rodolphe Quiedeville <rodolphe@quiedeville.org> + * Copyright (C) 2003 Jean-Louis Bergamo <jlb@j1b.org> + * Copyright (C) 2004-2012 Laurent Destailleur <eldy@users.sourceforge.net> + * Copyright (C) 2012 Regis Houssin <regis.houssin@capnetworks.com> + * Copyright (C) 2014 Alexis Algoud <alexis@atm-consulting.fr> + * + * 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 <http://www.gnu.org/licenses/>. + */ + +/** + * \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='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>'; +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).'<br>'."\n"; +print '<br>'; + +// 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 align="center">'.$langs->trans("Unique").'</td>'; +print '<td align="center">'.$langs->trans("Required").'</td>'; +print '<td width="80"> </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="center">'.yn($extrafields->attribute_unique[$key])."</td>\n"; + print '<td align="center">'.yn($extrafields->attribute_required[$key])."</td>\n"; + print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=edit&attrname='.$key.'">'.img_edit().'</a>'; + print " <a href=\"".$_SERVER["PHP_SELF"]."?action=delete&attrname=".$key."\">".img_delete()."</a></td>\n"; + print "</tr>"; + // $i++; +} + +print "</table>"; + +dol_fiche_end(); + + +// Buttons +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')); + + require DOL_DOCUMENT_ROOT.'/core/tpl/admin_extrafields_add.tpl.php'; +} + +/* ************************************************************************** */ +/* */ +/* Edition d'un champ optionnel */ +/* */ +/* ************************************************************************** */ +if ($action == 'edit' && ! empty($attrname)) +{ + print "<br>"; + 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 b801c2660aad6512e11e9d8ab477fef714227937..3b6be065879630c3ed7fe72811103b44a2cebd42 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 <regis.houssin@capnetworks.com> * Copyright (C) 2012 Florian Henry <florian.henry@open-concept.pro> * Copyright (C) 2014 Juanjo Menent <jmenent@2byte.es> - * + * Copyright (C) 2014 Alexis Algoud <alexis@atm-consulting.fr> + * * 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 f97ef35ae6eeff3cdec2e3278fde0a49b2ea25ef..00dcc4c4cfbc6fd34bd65d040472fc495dd68105 100644 --- a/htdocs/user/group/fiche.php +++ b/htdocs/user/group/fiche.php @@ -4,6 +4,7 @@ * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com> * Copyright (C) 2011 Herve Prot <herve.prot@symeos.com> * Copyright (C) 2012 Florian Henry <florian.henry@open-concept.pro> + * Copyright (C) 2014 Alexis Algoud <alexis@atm-consulting.fr> * * 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 "</td></tr>\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 "</table>\n"; print '<center><br><input class="button" value="'.$langs->trans("CreateGroup").'" type="submit"></center>'; @@ -311,6 +332,16 @@ else print '<tr><td width="25%" valign="top">'.$langs->trans("Note").'</td>'; print '<td class="valeur">'.dol_htmlentitiesbr($object->note).' </td>'; print "</tr>\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 "</table>\n"; print '</div>'; @@ -495,6 +526,14 @@ else $doleditor->Create(); print '</td>'; print "</tr>\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 "</table>\n"; print '<center><br><input class="button" value="'.$langs->trans("Save").'" type="submit"></center>';