grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026.
--------------------------------------------------------------------------
*/
/** @file
* @brief
*/
if (!defined('GLPI_ROOT')) {
die("Sorry. You can't access this file directly");
}
/**
* Group class
**/
class Group extends CommonTreeDropdown {
public $dohistory = true;
static $rightname = 'group';
protected $usenotepad = true;
static function getTypeName($nb=0) {
return _n('Group', 'Groups', $nb);
}
/**
* @see CommonGLPI::getAdditionalMenuOptions()
*
* @since version 0.85
**/
static function getAdditionalMenuOptions() {
if (Session::haveRight('user', User::UPDATEAUTHENT)) {
$options['ldap']['title'] = AuthLDAP::getTypeName(Session::getPluralNumber());
$options['ldap']['page'] = "/front/ldap.group.php";
return $options;
}
return false;
}
/**
* @see CommonGLPI::getMenuShorcut()
*
* @since version 0.85
**/
static function getMenuShorcut() {
return 'g';
}
function post_getEmpty () {
$this->fields['is_requester'] = 1;
$this->fields['is_assign'] = 1;
$this->fields['is_notify'] = 1;
$this->fields['is_itemgroup'] = 1;
$this->fields['is_usergroup'] = 1;
$this->fields['is_manager'] = 1;
}
function cleanDBonPurge() {
global $DB;
$gu = new Group_User();
$gu->cleanDBonItemDelete($this->getType(), $this->fields['id']);
$gt = new Group_Ticket();
$gt->cleanDBonItemDelete($this->getType(), $this->fields['id']);
$gp = new Group_Problem();
$gp->cleanDBonItemDelete($this->getType(), $this->fields['id']);
$cg = new Change_Group();
$cg->cleanDBonItemDelete($this->getType(), $this->fields['id']);
$query1 = "DELETE
FROM `glpi_projecttaskteams`
WHERE `items_id` = '".$this->fields['id']."'
AND `itemtype` = '".__CLASS__."'";
$DB->query($query1);
$query1 = "DELETE
FROM `glpi_projectteams`
WHERE `items_id` = '".$this->fields['id']."'
AND `itemtype` = '".__CLASS__."'";
$DB->query($query1);
$gki = new Group_KnowbaseItem();
$gki->cleanDBonItemDelete($this->getType(), $this->fields['id']);
$gr = new Group_Reminder();
$gr->cleanDBonItemDelete($this->getType(), $this->fields['id']);
// Ticket rules use various _groups_id_*
Rule::cleanForItemAction($this, '_groups_id%');
Rule::cleanForItemCriteria($this, '_groups_id%');
// GROUPS for RuleMailcollector
Rule::cleanForItemCriteria($this, 'GROUPS');
// Set no group to consumables
$query = "UPDATE `glpi_consumables`
SET `items_id` = '0'
WHERE `items_id` = '".$this->fields['id']."'
AND `itemtype` = 'Group'";
$DB->query($query);
}
function getTabNameForItem(CommonGLPI $item, $withtemplate=0) {
if (!$withtemplate && self::canView()) {
$nb = 0;
switch ($item->getType()) {
case 'Group' :
$ong = array();
if ($_SESSION['glpishow_count_on_tabs']) {
$nb = countElementsInTable($this->getTable(),
"`groups_id` = '".$item->getID()."'");
}
$ong[4] = self::createTabEntry(__('Child groups'), $nb);
if ($item->getField('is_itemgroup')) {
$ong[1] = __('Used items');
}
if ($item->getField('is_assign')) {
$ong[2] = __('Managed items');
}
if ($item->getField('is_usergroup')
&& Group::canUpdate()
&& Session::haveRight("user", User::UPDATEAUTHENT)
&& AuthLdap::useAuthLdap()) {
$ong[3] = __('LDAP directory link');
}
return $ong;
}
}
return '';
}
static function displayTabContentForItem(CommonGLPI $item, $tabnum=1, $withtemplate=0) {
switch ($item->getType()) {
case 'Group' :
switch ($tabnum) {
case 1 :
$item->showItems(false);
return true;
case 2 :
$item->showItems(true);
return true;
case 3 :
$item->showLDAPForm($item->getID());
return true;
case 4 :
$item->showChildren();
return true;
}
break;
}
return false;
}
function defineTabs($options=array()) {
$ong = array();
$this->addDefaultFormTab($ong);
$this->addStandardTab('Group', $ong, $options);
if (isset($this->fields['is_usergroup'])
&& $this->fields['is_usergroup']) {
$this->addStandardTab('Group_User', $ong, $options);
}
if (isset($this->fields['is_notify'])
&& $this->fields['is_notify']) {
$this->addStandardTab('NotificationTarget', $ong, $options);
}
if (isset($this->fields['is_requester'])
&& $this->fields['is_requester']) {
$this->addStandardTab('Ticket', $ong, $options);
}
$this->addStandardTab('Item_Problem', $ong, $options);
$this->addStandardTab('Change_Item', $ong, $options);
$this->addStandardTab('Notepad',$ong, $options);
$this->addStandardTab('Log',$ong, $options);
return $ong;
}
/**
* Print the group form
*
* @param $ID integer ID of the item
* @param $options array
* - target filename : where to go when done.
* - withtemplate boolean : template or basic item
*
* @return Nothing (display)
**/
function showForm($ID, $options=array()) {
$this->initForm($ID, $options);
$this->showFormHeader($options);
echo "
";
echo "| ".__('Name')." | ";
echo "";
Html::autocompletionTextField($this, "name");
echo " | ";
echo "".__('Comments')." | ";
echo "";
echo "";
echo " |
";
echo "";
echo "| ".__('As child of')." | ";
self::dropdown(array('value' => $this->fields['groups_id'],
'name' => 'groups_id',
'entity' => $this->fields['entities_id'],
'used' => (($ID > 0) ? getSonsOf($this->getTable(), $ID) : array())));
echo " |
";
echo "";
echo "
";
echo "";
echo "| ".__('Requester')." | ";
echo "";
Dropdown::showYesNo('is_requester', $this->fields['is_requester']);
echo " |
";
echo "";
echo "| ".__('Assigned to')." | ";
Dropdown::showYesNo('is_assign', $this->fields['is_assign']);
echo " |
";
echo "";
echo "| ".__('Task')." | ";
Dropdown::showYesNo('is_task', $this->fields['is_task']);
echo " |
";
echo "";
echo "| ".__('Can be notified')." | ";
echo "";
Dropdown::showYesNo('is_notify', $this->fields['is_notify']);
echo " |
";
echo "";
echo "
";
echo "";
echo "| ".__('Can be manager')." | ";
echo "";
Dropdown::showYesNo('is_manager', $this->fields['is_manager']);
echo " |
";
echo "";
echo "
";
echo "";
echo "| "._n('Item', 'Items', Session::getPluralNumber())." | ";
echo "";
Dropdown::showYesNo('is_itemgroup', $this->fields['is_itemgroup']);
echo " | |
";
echo "";
echo "| "._n('User', 'Users', Session::getPluralNumber())." | ";
Dropdown::showYesNo('is_usergroup', $this->fields['is_usergroup']);
echo " | ";
echo "";
echo " |
";
$this->showFormButtons($options);
return true;
}
/**
* Print a good title for group pages
*
*@return nothing (display)
**/
function title() {
global $CFG_GLPI;
$buttons = array();
if (Group::canUpdate()
&& Session::haveRight("user", User::UPDATEAUTHENT)
&& AuthLdap::useAuthLdap()) {
$buttons["ldap.group.php"] = __('LDAP directory link');
$title = "";
} else {
$title = self::getTypeName(Session::getPluralNumber());
}
Html::displayTitle($CFG_GLPI["root_doc"] . "/pics/groupes.png", self::getTypeName(Session::getPluralNumber()), $title,
$buttons);
}
/**
* @see CommonDBTM::getSpecificMassiveActions()
**/
function getSpecificMassiveActions($checkitem=NULL) {
$isadmin = static::canUpdate();
$actions = parent::getSpecificMassiveActions($checkitem);
if ($isadmin) {
$prefix = 'Group_User'.MassiveAction::CLASS_ACTION_SEPARATOR;
$actions[$prefix.'add'] = _x('button', 'Add a user');
$actions[$prefix.'add_supervisor'] = _x('button', 'Add a manager');
$actions[$prefix.'add_delegatee'] = _x('button', 'Add a delegatee');
$actions[$prefix.'remove'] = _x('button', 'Remove a user');
}
if ($isadmin) {
MassiveAction::getAddTransferList($actions);
}
return $actions;
}
/**
* @since version 0.85
*
* @see CommonDBTM::showMassiveActionsSubForm()
**/
static function showMassiveActionsSubForm(MassiveAction $ma) {
$input = $ma->getInput();
switch ($ma->getAction()) {
case 'changegroup' :
if (isset($input['is_tech'])
&& isset($input['check_items_id'])
&& isset($input['check_itemtype'])) {
if ($group = getItemForItemtype($input['check_itemtype'])) {
if ($group->getFromDB($input['check_items_id'])) {
self::dropdown(array('entity' => $group->fields["entities_id"],
'used' => array($group->fields["id"]),
'condition' => ($input['is_tech'] ? '`is_assign`'
: '`is_itemgroup`')));
echo "
";
return true;
}
}
}
return true;
}
return parent::showMassiveActionsSubForm($ma);
}
/**
* @since version 0.85
*
* @see CommonDBTM::processMassiveActionsForOneItemtype()
**/
static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item,
array $ids) {
switch ($ma->getAction()) {
case 'changegroup' :
$input = $ma->getInput();
if (isset($input["field"])
&& isset($input['groups_id'])) {
foreach ($ids as $id) {
if ($item->can($id, UPDATE)) {
if ($item->update(array('id' => $id,
$input["field"] => $input["groups_id"]))) {
$ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK);
} else {
$ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO);
$ma->addMessage($item->getErrorMessage(ERROR_ON_ACTION));
}
} else {
$ma->itemDone($item->getType(), $id, MassiveAction::ACTION_NORIGHT);
$ma->addMessage($item->getErrorMessage(ERROR_RIGHT));
}
}
} else {
$ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_KO);
$ma->addMessage($item->getErrorMessage(ERROR_ON_ACTION));
}
return;
}
parent::processMassiveActionsForOneItemtype($ma, $baseitem, $ids);
}
function getSearchOptions() {
$tab = parent::getSearchOptions();
if (AuthLdap::useAuthLdap()) {
$tab[3]['table'] = $this->getTable();
$tab[3]['field'] = 'ldap_field';
$tab[3]['name'] = __('Attribute of the user containing its groups');
$tab[3]['datatype'] = 'string';
$tab[4]['table'] = $this->getTable();
$tab[4]['field'] = 'ldap_value';
$tab[4]['name'] = __('Attribute value');
$tab[4]['datatype'] = 'text';
$tab[5]['table'] = $this->getTable();
$tab[5]['field'] = 'ldap_group_dn';
$tab[5]['name'] = __('Group DN');
$tab[5]['datatype'] = 'text';
}
$tab[11]['table'] = $this->getTable();
$tab[11]['field'] = 'is_requester';
$tab[11]['name'] = __('Requester');
$tab[11]['datatype'] = 'bool';
$tab[12]['table'] = $this->getTable();
$tab[12]['field'] = 'is_assign';
$tab[12]['name'] = __('Assigned to');
$tab[12]['datatype'] = 'bool';
$tab[18]['table'] = $this->getTable();
$tab[18]['field'] = 'is_manager';
$tab[18]['name'] = __('Can be manager');
$tab[18]['datatype'] = 'bool';
$tab[20]['table'] = $this->getTable();
$tab[20]['field'] = 'is_notify';
$tab[20]['name'] = __('Can be notified');
$tab[20]['datatype'] = 'bool';
$tab[17]['table'] = $this->getTable();
$tab[17]['field'] = 'is_itemgroup';
$tab[17]['name'] = sprintf(__('%1$s %2$s'), __('Can contain'), _n('Item', 'Items', Session::getPluralNumber()));
$tab[17]['datatype'] = 'bool';
$tab[15]['table'] = $this->getTable();
$tab[15]['field'] = 'is_usergroup';
$tab[15]['name'] = sprintf(__('%1$s %2$s'), __('Can contain'), User::getTypeName(Session::getPluralNumber()));
$tab[15]['datatype'] = 'bool';
$tab[19]['table'] = $this->getTable();
$tab[19]['field'] = 'date_mod';
$tab[19]['name'] = __('Last update');
$tab[19]['datatype'] = 'datetime';
$tab[19]['massiveaction'] = false;
$tab[121]['table'] = $this->getTable();
$tab[121]['field'] = 'date_creation';
$tab[121]['name'] = __('Creation date');
$tab[121]['datatype'] = 'datetime';
$tab[121]['massiveaction'] = false;
$tab[70]['table'] = 'glpi_users';
$tab[70]['field'] = 'name';
$tab[70]['name'] = __('Manager');
$tab[70]['datatype'] = 'dropdown';
$tab[70]['right'] = 'all';
$tab[70]['forcegroupby'] = true;
$tab[70]['massiveaction'] = false;
$tab[70]['joinparams'] = array('beforejoin'
=> array('table' => 'glpi_groups_users',
'joinparams' => array('jointype' => 'child',
'condition' => "AND NEWTABLE.`is_manager` = 1")));
$tab[71]['table'] = 'glpi_users';
$tab[71]['field'] = 'name';
$tab[71]['name'] = __('Delegatee');
$tab[71]['datatype'] = 'dropdown';
$tab[71]['right'] = 'all';
$tab[71]['forcegroupby'] = true;
$tab[71]['massiveaction'] = false;
$tab[71]['joinparams'] = array('beforejoin'
=> array('table' => 'glpi_groups_users',
'joinparams' => array('jointype' => 'child',
'condition' => "AND NEWTABLE.`is_userdelegate` = 1")));
$tab[72]['table'] = $this->getTable();
$tab[72]['field'] = 'is_task';
$tab[72]['name'] = __('Can be in charge of a task');
$tab[72]['datatype'] = 'bool';
return $tab;
}
/**
* @param $ID
**/
function showLDAPForm($ID) {
$options = array();
$this->initForm($ID, $options);
echo "