.
* ---------------------------------------------------------------------
*/
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 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 0.85
**/
static function getMenuShorcut() {
return 'g';
}
function post_getEmpty () {
$this->fields['is_requester'] = 1;
$this->fields['is_watcher'] = 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() {
$this->deleteChildrenAndRelationsFromDb(
[
Change_Group::class,
Group_KnowbaseItem::class,
Group_Problem::class,
Group_Reminder::class,
Group_RSSFeed::class,
Group_Ticket::class,
Group_User::class,
ProjectTaskTeam::class,
ProjectTeam::class,
]
);
// Ticket rules use various _groups_id_*
Rule::cleanForItemAction($this, '_groups_id%');
Rule::cleanForItemCriteria($this, '_groups_id%');
// GROUPS for RuleMailcollector
Rule::cleanForItemCriteria($this, 'GROUPS');
}
function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) {
if (!$withtemplate && self::canView()) {
$nb = 0;
switch ($item->getType()) {
case 'Group' :
$ong = [];
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 = []) {
$ong = [];
$this->addDefaultFormTab($ong);
$this->addImpactTab($ong, $options);
$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 void
**/
function showForm($ID, $options = []) {
$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(['value' => $this->fields['groups_id'],
'name' => 'groups_id',
'entity' => $this->fields['entities_id'],
'used' => (($ID > 0) ? getSonsOf($this->getTable(), $ID) : [])]);
echo " |
";
echo "";
echo "
";
echo "";
echo "| "._n('Requester', 'Requesters', 1)." | ";
echo "";
Dropdown::showYesNo('is_requester', $this->fields['is_requester']);
echo " |
";
echo "";
echo "| "._n('Watcher', 'Watchers', 1)." | ";
echo "";
Dropdown::showYesNo('is_watcher', $this->fields['is_watcher']);
echo " |
";
echo "";
echo "| ".__('Assigned to')." | ";
Dropdown::showYesNo('is_assign', $this->fields['is_assign']);
echo " |
";
echo "";
echo "| "._n('Task', 'Tasks', 1)." | ";
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 "| ".User::getTypeName(Session::getPluralNumber())." | ";
Dropdown::showYesNo('is_usergroup', $this->fields['is_usergroup']);
echo " |
";
$this->showFormButtons($options);
return true;
}
/**
* Print a good title for group pages
*
*@return void
**/
function title() {
global $CFG_GLPI;
$buttons = [];
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);
}
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');
}
return $actions;
}
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'])) {
$condition = [];
if ($input['is_tech']) {
$condition['is_assign'] = 1;
} else {
$condition['is_itemgroup'] = 1;
}
self::dropdown([
'entity' => $group->fields["entities_id"],
'used' => [$group->fields["id"]],
'condition' => $condition
]);
echo "
";
return true;
}
}
}
return true;
}
return parent::showMassiveActionsSubForm($ma);
}
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(['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 rawSearchOptions() {
$tab = parent::rawSearchOptions();
if (AuthLDAP::useAuthLdap()) {
$tab[] = [
'id' => '3',
'table' => $this->getTable(),
'field' => 'ldap_field',
'name' => __('Attribute of the user containing its groups'),
'datatype' => 'string',
'autocomplete' => true,
];
$tab[] = [
'id' => '4',
'table' => $this->getTable(),
'field' => 'ldap_value',
'name' => __('Attribute value'),
'datatype' => 'text',
'autocomplete' => true,
];
$tab[] = [
'id' => '5',
'table' => $this->getTable(),
'field' => 'ldap_group_dn',
'name' => __('Group DN'),
'datatype' => 'text',
'autocomplete' => true,
];
}
$tab[] = [
'id' => '11',
'table' => $this->getTable(),
'field' => 'is_requester',
'name' => _n('Requester', 'Requesters', 1),
'datatype' => 'bool'
];
$tab[] = [
'id' => '12',
'table' => $this->getTable(),
'field' => 'is_assign',
'name' => __('Assigned to'),
'datatype' => 'bool'
];
$tab[] = [
'id' => '18',
'table' => $this->getTable(),
'field' => 'is_manager',
'name' => __('Can be manager'),
'datatype' => 'bool'
];
$tab[] = [
'id' => '20',
'table' => $this->getTable(),
'field' => 'is_notify',
'name' => __('Can be notified'),
'datatype' => 'bool'
];
$tab[] = [
'id' => '17',
'table' => $this->getTable(),
'field' => 'is_itemgroup',
'name' => sprintf(__('%1$s %2$s'), __('Can contain'), _n('Item', 'Items', Session::getPluralNumber())),
'datatype' => 'bool'
];
$tab[] = [
'id' => '15',
'table' => $this->getTable(),
'field' => 'is_usergroup',
'name' => sprintf(__('%1$s %2$s'), __('Can contain'), User::getTypeName(Session::getPluralNumber())),
'datatype' => 'bool'
];
$tab[] = [
'id' => '70',
'table' => 'glpi_users',
'field' => 'name',
'name' => __('Manager'),
'datatype' => 'dropdown',
'right' => 'all',
'forcegroupby' => true,
'massiveaction' => false,
'joinparams' => [
'beforejoin' => [
'table' => 'glpi_groups_users',
'joinparams' => [
'jointype' => 'child',
'condition' => 'AND NEWTABLE.`is_manager` = 1'
]
]
]
];
$tab[] = [
'id' => '71',
'table' => 'glpi_users',
'field' => 'name',
'name' => __('Delegatee'),
'datatype' => 'dropdown',
'right' => 'all',
'forcegroupby' => true,
'massiveaction' => false,
'joinparams' => [
'beforejoin' => [
'table' => 'glpi_groups_users',
'joinparams' => [
'jointype' => 'child',
'condition' => 'AND NEWTABLE.`is_userdelegate` = 1'
]
]
]
];
$tab[] = [
'id' => '72',
'table' => $this->getTable(),
'field' => 'is_task',
'name' => __('Can be in charge of a task'),
'datatype' => 'bool'
];
return $tab;
}
/**
* @param $ID
**/
function showLDAPForm($ID) {
$options = [];
$this->initForm($ID, $options);
echo "