/** * @since version 0.85 * * @see CommonDBTM::showMassiveActionsSubForm() **/ static function showMassiveActionsSubForm(MassiveAction $ma) { global $UNINSTALL_TYPES; foreach ($ma->getItems() as $itemtype => $data) { if (!in_array($itemtype, $UNINSTALL_TYPES)) { return ""; } } switch ($ma->getAction()) { case 'uninstall': $uninst = new PluginUninstallUninstall(); $uninst->dropdownUninstallModels("model_id", $_SESSION["glpiID"], $_SESSION["glpiactive_entity"]); echo " " . Html::submit(_x('button', 'Post'), array('name' => 'massiveaction')); return true; } return ""; }
/** * get the type of the item with the name of the action or the types of the input * * @since version 0.85 * * @param $ma current massive action * * @return number of the peer **/ static function getRelationMassiveActionsPeerForSubForm(MassiveAction $ma) { $items = $ma->getItems(); // If direct itemtype, then, its easy to find ! if (isset($items[static::$itemtype_1])) { return 2; } if (isset($items[static::$itemtype_2])) { return 1; } // Else, check if one of both peer is 'itemtype*' if (preg_match('/^itemtype/', static::$itemtype_1)) { return 2; } if (preg_match('/^itemtype/', static::$itemtype_2)) { return 1; } // Else we cannot define ! return 0; }
/** * @since version 0.85 * * @see CommonDBTM::showMassiveActionsSubForm() **/ static function showMassiveActionsSubForm(MassiveAction $ma) { $action = $ma->getAction(); $items = $ma->getItems(); $itemtypes_affect = array(); $itemtypes_unaffect = array(); foreach (array_keys($items) as $itemtype) { if (!Toolbox::is_a($itemtype, __CLASS__)) { continue; } $specificities = $itemtype::getConnexityMassiveActionsSpecificities(); if (in_array($action, $specificities['normalized']['affect'])) { $itemtypes_affect[$itemtype] = $specificities; continue; } if (in_array($action, $specificities['normalized']['unaffect'])) { $itemtypes_unaffect[$itemtype] = $specificities; continue; } } if (count($itemtypes_affect) > count($itemtypes_unaffect)) { $normalized_action = 'affect'; $itemtypes = $itemtypes_affect; } else { if (count($itemtypes_affect) < count($itemtypes_unaffect)) { $normalized_action = 'unaffect'; $itemtypes = $itemtypes_unaffect; } else { return parent::showMassiveActionsSubForm($ma); } } switch ($normalized_action) { case 'unaffect': foreach ($itemtypes as $itemtype => $specificities) { if (Toolbox::is_a($itemtype, 'CommonDBRelation')) { $peer_field = "peer[{$itemtype}]"; if (!$itemtype::$mustBeAttached_1 && !$itemtype::$mustBeAttached_2) { // Should never occur ... But we must care ! $values = array(); if (empty($itemtype::$itemtype_1) || preg_match('/^itemtype/', $itemtype::$itemtype_1)) { $values[0] = __('First Item'); } else { $itemtype_1 = $itemtype::$itemtype_1; $values[0] = $itemtype_1::getTypeName(Session::getPluralNumber()); } if (empty($itemtype::$itemtype_2) || preg_match('/^itemtype/', $itemtype::$itemtype_2)) { $values[1] = __('Second Item'); } else { $itemtype_2 = $itemtype::$itemtype_2; $values[1] = $itemtype_2::getTypeName(Session::getPluralNumber()); } echo sprintf(__('Select a peer for %s:'), $itemtype::getTypeName()); Dropdown::showFromArray($peer_field, $values); echo "<br>\n"; } else { if (!$itemtype::$mustBeAttached_1) { echo "<input type='hidden' name='{$peer_field}' value='0'>"; } else { if (!$itemtype::$mustBeAttached_2) { echo "<input type='hidden' name='{$peer_field}' value='1'>"; } } } } } echo "<br><br>" . Html::submit(_x('button', 'Dissociate'), array('name' => 'massiveaction')); return true; case 'affect': $peertypes = array(); foreach ($itemtypes as $itemtype => $specificities) { if (!$specificities['reaffect']) { continue; } if (Toolbox::is_a($itemtype, 'CommonDBRelation')) { if ($specificities['reaffect'] == 1) { $peertype = $itemtype::$itemtype_1; } else { $peertype = $itemtype::$itemtype_2; } } else { $peertype = $itemtype::$itemtype; } if (preg_match('/^itemtype/', $peertype)) { $peertypes = array_merge($peertypes, $specificities['itemtypes']); } else { $peertypes[] = $peertype; } } $peertypes = array_unique($peertypes); if (count($peertypes) == 0) { echo __('Unable to reaffect given elements !'); exit; } $options = array(); if (count($peertypes) == 1) { $options['name'] = 'peers_id'; $type_for_dropdown = $peertypes[0]; if (preg_match('/^itemtype/', $peertype)) { echo Html::hidden('peertype', array('value' => $type_for_dropdown)); } $type_for_dropdown::dropdown($options); } else { $options['itemtype_name'] = 'peertype'; $options['items_id_name'] = 'peers_id'; $options['itemtypes'] = $peertypes; Dropdown::showSelectItemFromItemtypes($options); } echo "<br><br>" . Html::submit(_x('button', 'Associate'), array('name' => 'massiveaction')); return true; } return parent::showMassiveActionsSubForm($ma); }