* Copyright (C) 2005-2015 Laurent Destailleur * Copyright (C) 2005-2015 Regis Houssin * Copyright (C) 2011 Herve Prot * Copyright (C) 2012 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 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/user/group/card.php * \brief Onglet groupes utilisateurs */ require '../../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/user/class/usergroup.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/usergroups.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; if(! empty($conf->multicompany->enabled)) dol_include_once('/multicompany/class/actions_multicompany.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); $candisableperms=($user->admin || $user->rights->user->user->supprimer); // Advanced permissions if (! empty($conf->global->MAIN_USE_ADVANCED_PERMS)) { $canreadperms=($user->admin || $user->rights->user->group_advance->read); $caneditperms=($user->admin || $user->rights->user->group_advance->write); $candisableperms=($user->admin || $user->rights->user->group_advance->delete); } $langs->load("users"); $langs->load("other"); $id=GETPOST('id', 'int'); $action=GETPOST('action', 'alpha'); $confirm=GETPOST('confirm', 'alpha'); $userid=GETPOST('user', 'int'); // Security check $result = restrictedArea($user, 'user', $id, 'usergroup&usergroup', 'user'); if (! empty($conf->multicompany->enabled) && $conf->entity > 1 && $conf->multicompany->transverse_mode) { accessforbidden(); } $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 */ if ($action == 'confirm_delete' && $confirm == "yes") { if ($caneditperms) { $object->fetch($id); $object->delete(); header("Location: index.php"); exit; } else { $langs->load("errors"); setEventMessage($langs->trans('ErrorForbidden'), 'errors'); } } /** * Action add group */ if ($action == 'add') { if ($caneditperms) { if (! $_POST["nom"]) { setEventMessage($langs->trans("NameNotDefined"), 'errors'); $action="create"; // Go back to create page } else { $object->nom = trim($_POST["nom"]); // For backward compatibility $object->name = trim($_POST["nom"]); $object->note = trim($_POST["note"]); // Fill array 'array_options' with data from add form $ret = $extrafields->setOptionalsFromPost($extralabels,$object); if ($ret < 0) $error++; if (! empty($conf->multicompany->enabled) && ! empty($conf->multicompany->transverse_mode)) $object->entity = 0; else $object->entity = $_POST["entity"]; $db->begin(); $id = $object->create(); if ($id > 0) { $db->commit(); header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); exit; } else { $db->rollback(); $langs->load("errors"); setEventMessage($langs->trans("ErrorGroupAlreadyExists",$object->name), 'errors'); $action="create"; // Go back to create page } } } else { $langs->load("errors"); setEventMessage($langs->trans('ErrorForbidden'), 'errors'); } } // Add/Remove user into group if ($action == 'adduser' || $action =='removeuser') { if ($caneditperms) { if ($userid) { $object->fetch($id); $object->oldcopy=dol_clone($object); $edituser = new User($db); $edituser->fetch($userid); if ($action == 'adduser') $result=$edituser->SetInGroup($object->id,(! empty($conf->multicompany->transverse_mode)?GETPOST('entity','int'):$object->entity)); if ($action == 'removeuser') $result=$edituser->RemoveFromGroup($object->id,(! empty($conf->multicompany->transverse_mode)?GETPOST('entity','int'):$object->entity)); if ($result > 0) { header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); exit; } else { setEventMessage($edituser->error, 'errors'); } } } else { $langs->load("errors"); setEventMessage($langs->trans('ErrorForbidden'), 'errors'); } } if ($action == 'update') { if ($caneditperms) { $db->begin(); $object->fetch($id); $object->oldcopy=dol_clone($object); $object->name = trim($_POST["group"]); $object->nom = $object->name; // For backward compatibility $object->note = dol_htmlcleanlastbr($_POST["note"]); // Fill array 'array_options' with data from add form $ret = $extrafields->setOptionalsFromPost($extralabels,$object); if ($ret < 0) $error++; if (! empty($conf->multicompany->enabled) && ! empty($conf->multicompany->transverse_mode)) $object->entity = 0; else $object->entity = $_POST["entity"]; $ret=$object->update(); if ($ret >= 0 && ! count($object->errors)) { setEventMessage($langs->trans("GroupModified")); $db->commit(); } else { setEventMessage($object->error); $db->rollback(); } } else { $langs->load("errors"); setEventMessage($langs->trans('ErrorForbidden')); } } /* * View */ llxHeader('',$langs->trans("GroupCard")); $form = new Form($db); $fuserstatic = new User($db); if ($action == 'create') { print_fiche_titre($langs->trans("NewGroup")); print dol_set_focus('#nom'); print '
'; print ''; print ''; dol_fiche_head('', '', '', 0, ''); print ''; print ""; print ''; print ''; // Multicompany if (! empty($conf->multicompany->enabled) && is_object($mc)) { if (empty($conf->multicompany->transverse_mode) && $conf->entity == 1 && $user->admin && ! $user->entity) { print "".''; print "\n"; } else { print ''; } } 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 "
'.$langs->trans("Name").'
'.$langs->trans("Entity").'".$mc->select_entities($conf->entity); print "
'.$langs->trans("Description").''; require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; $doleditor=new DolEditor('note','','',240,'dolibarr_notes','',false,true,$conf->global->FCKEDITOR_ENABLE_SOCIETE,ROWS_8,90); $doleditor->Create(); print "
\n"; dol_fiche_end(); print '
'; print "
"; } /* ************************************************************************** */ /* */ /* Visu et edition */ /* */ /* ************************************************************************** */ else { if ($id) { $object->fetch($id); $head = group_prepare_head($object); $title = $langs->trans("Group"); /* * Confirmation suppression */ if ($action == 'delete') { print $form->formconfirm($_SERVER['PHP_SELF']."?id=".$object->id,$langs->trans("DeleteAGroup"),$langs->trans("ConfirmDeleteGroup",$object->name),"confirm_delete", '',0,1); } /* * Fiche en mode visu */ if ($action != 'edit') { dol_fiche_head($head, 'group', $title, 0, 'group'); print ''; // Ref print ''; print ''; print ''; // Name print ''; print '\n"; // Multicompany if (! empty($conf->multicompany->enabled) && is_object($mc) && empty($conf->multicompany->transverse_mode) && $conf->entity == 1 && $user->admin && ! $user->entity) { $mc->getInfo($object->entity); print "".''; print '\n"; } // Note print ''; 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); } print "
'.$langs->trans("Ref").''; print $form->showrefnav($object,'id','',$user->rights->user->user->lire || $user->admin); print '
'.$langs->trans("Name").''.$object->name; if (empty($object->entity)) { print img_picto($langs->trans("GlobalGroup"),'redstar'); } print "
'.$langs->trans("Entity").''.$mc->label; print "
'.$langs->trans("Description").''.dol_htmlentitiesbr($object->note).' 
\n"; dol_fiche_end(); /* * Barre d'actions */ print '
'; if ($caneditperms) { print ''.$langs->trans("Modify").''; } if ($candisableperms) { print ''.$langs->trans("DeleteGroup").''; } print "
\n"; print "
\n"; /* * Liste des utilisateurs dans le groupe */ print_fiche_titre($langs->trans("ListOfUsersInGroup"),'',''); // On selectionne les users qui ne sont pas deja dans le groupe $exclude = array(); if (! empty($object->members)) { if (! (! empty($conf->multicompany->enabled) && ! empty($conf->multicompany->transverse_mode))) { foreach($object->members as $useringroup) { $exclude[]=$useringroup->id; } } } if ($caneditperms) { print '
'."\n"; print ''; print ''; print ''."\n"; print ''."\n"; print ''; print "'."\n"; print '
'.$langs->trans("NonAffectedUsers").''; print $form->select_dolusers('','user',1,$exclude,0,'','',$object->entity); print '   '; // Multicompany if (! empty($conf->multicompany->enabled) && is_object($mc)) { if ($conf->entity == 1 && $conf->multicompany->transverse_mode) { print ''.$langs->trans("Entity").'".$mc->select_entities($conf->entity); } else { print ''; } } else { print ''; } print ''; print '
'."\n"; print '
'; } /* * Group members */ print ''; print ''; print ''; print ''; print ''; if (! empty($conf->multicompany->enabled) && $conf->entity == 1) { print ''; } print ''; print ''; print "\n"; if (! empty($object->members)) { $var=True; foreach($object->members as $useringroup) { $var=!$var; print ""; print ''; print ''; print ''; if (! empty($conf->multicompany->enabled) && is_object($mc) && ! empty($conf->multicompany->transverse_mode) && $conf->entity == 1 && $user->admin && ! $user->entity) { print ''; } print ''; print '\n"; } } else { print ''; } print "
'.$langs->trans("Login").''.$langs->trans("Lastname").''.$langs->trans("Firstname").''.$langs->trans("Entity").''.$langs->trans("Status").' 
'; print ''.img_object($langs->trans("ShowUser"),"user").' '.$useringroup->login.''; if ($useringroup->admin && ! $useringroup->entity) print img_picto($langs->trans("SuperAdministrator"),'redstar'); else if ($useringroup->admin) print img_picto($langs->trans("Administrator"),'star'); print ''.$useringroup->lastname.''.$useringroup->firstname.''; if (! empty($useringroup->usergroup_entity)) { $nb=0; foreach($useringroup->usergroup_entity as $group_entity) { $mc->getInfo($group_entity); print ($nb > 0 ? ', ' : '').$mc->label; print ''; print img_delete($langs->trans("RemoveFromGroup")); print ''; $nb++; } } print ''.$useringroup->getLibStatut(3).''; if (! empty($user->admin) && empty($conf->multicompany->enabled)) { print ''; print img_delete($langs->trans("RemoveFromGroup")); print ''; } else { print "-"; } print "
'.$langs->trans("None").'
"; print "
"; } /* * Fiche en mode edition */ if ($action == 'edit' && $caneditperms) { print '
'; print ''; print ''; dol_fiche_head($head, 'group', $title, 0, 'group'); print ''; print ''; print '\n"; // Multicompany if (! empty($conf->multicompany->enabled) && is_object($mc)) { if (empty($conf->multicompany->transverse_mode) && $conf->entity == 1 && $user->admin && ! $user->entity) { print "".''; print "\n"; } else { print ''; } } print ''; 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 "
'.$langs->trans("Name").''; print "
'.$langs->trans("Entity").'".$mc->select_entities($object->entity); print "
'.$langs->trans("Description").''; require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; $doleditor=new DolEditor('note',$object->note,'',240,'dolibarr_notes','',true,false,$conf->global->FCKEDITOR_ENABLE_SOCIETE,ROWS_8,90); $doleditor->Create(); print '
\n"; dol_fiche_end(); print '
'; print '
'; } } } llxFooter(); $db->close();