can() public method

Check right on an item
public can ( $ID, $right, array &$input = NULL ) : boolean
$ID ID of the item (-1 if new item)
$right Right to check : r / w / recursive / READ / UPDATE / DELETE
$input array
return boolean
 /**
  * @since version 0.85
  *
  * @see CommonDBTM::processMassiveActionsForOneItemtype()
  **/
 static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids)
 {
     switch ($ma->getAction()) {
         case 'add':
             $input = $ma->getInput();
             $ticket = new Ticket();
             if (isset($input['link']) && isset($input['tickets_id_1'])) {
                 if ($item->getFromDB($input['tickets_id_1'])) {
                     foreach ($ids as $id) {
                         $input2 = array();
                         $input2['id'] = $input['tickets_id_1'];
                         $input2['_link']['tickets_id_1'] = $input['tickets_id_1'];
                         $input2['_link']['link'] = $input['link'];
                         $input2['_link']['tickets_id_2'] = $id;
                         if ($item->can($input['tickets_id_1'], UPDATE)) {
                             if ($ticket->update($input2)) {
                                 $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));
                         }
                     }
                 }
             }
             return;
     }
     parent::processMassiveActionsForOneItemtype($ma, $item, $ids);
 }
Exemplo n.º 2
0
 /**
  * @since version 0.85
  *
  * @see CommonDBTM::processMassiveActionsForOneItemtype()
  **/
 static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids)
 {
     switch ($ma->getAction()) {
         case 'backtostock':
             foreach ($ids as $id) {
                 if ($item->can($id, UPDATE)) {
                     if ($item->backToStock(array("id" => $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));
                 }
             }
             return;
         case 'give':
             $input = $ma->getInput();
             if ($input["give_items_id"] > 0 && !empty($input['give_itemtype'])) {
                 foreach ($ids as $key) {
                     if ($item->can($key, UPDATE)) {
                         if ($item->out($key, $input['give_itemtype'], $input["give_items_id"])) {
                             $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_OK);
                         } else {
                             $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO);
                             $ma->addMessage($item->getErrorMessage(ERROR_ON_ACTION));
                         }
                     } else {
                         $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_NORIGHT);
                         $ma->addMessage($item->getErrorMessage(ERROR_RIGHT));
                     }
                 }
                 Event::log($item->fields['consumableitems_id'], "consumables", 5, "inventory", sprintf(__('%s gives a consumable'), $_SESSION["glpiname"]));
             } else {
                 $ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_KO);
             }
             return;
     }
     parent::processMassiveActionsForOneItemtype($ma, $item, $ids);
 }
Exemplo n.º 3
0
 /**
  * \brief Show names for an item from its form
  * Beware that the rendering can be different if readden from direct item form (ie : add new
  * NetworkName, remove, ...) or if readden from item of the item (for instance from the computer
  * form through NetworkPort::ShowForItem).
  *
  * @param $item                     CommonGLPI object
  * @param $withtemplate   integer   withtemplate param (default 0)
  **/
 static function showForItem(CommonDBTM $item, $withtemplate = 0)
 {
     global $DB, $CFG_GLPI;
     $ID = $item->getID();
     if (!$item->can($ID, READ)) {
         return false;
     }
     $rand = mt_rand();
     if ($item->getType() == 'NetworkPort' && Session::haveRight('internet', UPDATE) && $item->canUpdateItem()) {
         $items_id = $item->getID();
         $itemtype = $item->getType();
         echo "<div class='firstbloc'>\n";
         echo "<form method='post' action='" . static::getFormURL() . "'>\n";
         echo "<table class='tab_cadre_fixe'>\n";
         echo "<tr><th colspan='4'>" . __('Add a network name') . "</th></tr>";
         echo "<tr class='tab_bg_1'><td class='right'>";
         echo "<input type='hidden' name='items_id' value='{$items_id}'>\n";
         echo "<input type='hidden' name='itemtype' value='{$itemtype}'>\n";
         _e('Not associated');
         echo "</td><td class='left'>";
         self::dropdown(array('name' => 'addressID', 'condition' => '`items_id`=0'));
         echo "</td><td class='left'>";
         echo "<input type='submit' name='assign_address' value='" . _sx('button', 'Associate') . "' class='submit'>";
         echo "</td>";
         if (static::canCreate()) {
             echo "<td class='right' width='30%'>";
             echo "<a href=\"" . static::getFormURL() . "?items_id={$items_id}&amp;itemtype={$itemtype}\">";
             echo __('Create a new network name') . "</a>";
             echo "</td>";
         }
         echo "</tr>\n";
         echo "</table>\n";
         Html::closeForm();
         echo "</div>\n";
     }
     $table_options = array('createRow' => true);
     if ($item->getType() == 'FQDN' || $item->getType() == 'NetworkEquipment') {
         if (isset($_GET["start"])) {
             $start = $_GET["start"];
         } else {
             $start = 0;
         }
         if (!empty($_GET["order"])) {
             $table_options['order'] = $_GET["order"];
         } else {
             $table_options['order'] = 'name';
         }
         if ($item->getType() == 'FQDN') {
             $table_options['column_links'] = array('NetworkName' => 'javascript:reloadTab("order=name");', 'NetworkAlias' => 'javascript:reloadTab("order=alias");', 'IPAddress' => 'javascript:reloadTab("order=ip");');
         }
         $table_options['SQL_options'] = "LIMIT " . $_SESSION['glpilist_limit'] . "\n                                           OFFSET {$start}";
         $canedit = false;
     } else {
         $canedit = Session::haveRight('internet', UPDATE) && $item->canUpdateItem();
     }
     $table_options['canedit'] = false;
     $table_options['rand'] = $rand;
     $table_options['massiveactionnetworkname'] = $canedit;
     $table = new HTMLTableMain();
     $column = $table->addHeader('Internet', self::getTypeName(Session::getPluralNumber()));
     $t_group = $table->createGroup('Main', '');
     self::getHTMLTableHeader(__CLASS__, $t_group, $column, NULL, $table_options);
     $t_row = $t_group->createRow();
     self::getHTMLTableCellsForItem($t_row, $item, NULL, $table_options);
     if ($table->getNumberOfRows() > 0) {
         $number = $table->getNumberOfRows();
         if ($item->getType() == 'FQDN') {
             $number = min($_SESSION['glpilist_limit'], $table->getNumberOfRows());
             Html::printAjaxPager(self::getTypeName(Session::getPluralNumber()), $start, self::countForItem($item));
         }
         Session::initNavigateListItems(__CLASS__, sprintf(__('%1$s = %2$s'), $item->getTypeName(1), $item->getName()));
         if ($canedit && $number) {
             Html::openMassiveActionsForm('mass' . __CLASS__ . $rand);
             $massiveactionparams = array('num_displayed' => $number, 'container' => 'mass' . __CLASS__ . $rand);
             Html::showMassiveActions($massiveactionparams);
         }
         $table->display(array('display_title_for_each_group' => false, 'display_thead' => false, 'display_tfoot' => false, 'display_header_on_foot_for_each_group' => true));
         if ($canedit && $number) {
             $massiveactionparams['ontop'] = false;
             Html::showMassiveActions($massiveactionparams);
             Html::closeForm();
         }
         if ($item->getType() == 'FQDN') {
             Html::printAjaxPager(self::getTypeName(Session::getPluralNumber()), $start, self::countForItem($item));
         }
     } else {
         echo "<table class='tab_cadre_fixe'><tr><th>" . __('No network name found') . "</th></tr>";
         echo "</table>";
     }
 }
Exemplo n.º 4
0
 static function addNewTasks(CommonDBTM $item, $withtemplate = '')
 {
     global $CFG_GLPI;
     $rand = mt_rand();
     $ID = $item->getField('id');
     $entities_id = $item->getField('entities_id');
     $canedit = $item->can($ID, 'w');
     if (plugin_resources_haveRight('task', 'w') && $canedit && $withtemplate < 2) {
         echo "<div align='center'>";
         echo "<a href='" . $CFG_GLPI["root_doc"] . "/plugins/resources/front/task.form.php?plugin_resources_resources_id=" . $ID . "&entities_id=" . $entities_id . "' >" . __('Add a new task') . "</a></div>";
         echo "</div>";
     }
 }
Exemplo n.º 5
0
 /**
  * @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);
 }
Exemplo n.º 6
0
 /**
  * @since version 0.90
  *
  * @see CommonDBTM::processMassiveActionsForOneItemtype()
  **/
 static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids)
 {
     switch ($ma->getAction()) {
         case 'merge':
             foreach ($ids as $key) {
                 if ($item->can($key, UPDATE)) {
                     if ($item->getEntityID() == $_SESSION['glpiactive_entity']) {
                         if ($item->update(array('id' => $key, 'is_recursive' => 1))) {
                             $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_OK);
                         } else {
                             $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO);
                             $ma->addMessage($item->getErrorMessage(ERROR_ON_ACTION));
                         }
                     } else {
                         $input2 = $item->fields;
                         // Change entity
                         $input2['entities_id'] = $_SESSION['glpiactive_entity'];
                         $input2['is_recursive'] = 1;
                         $input2 = Toolbox::addslashes_deep($input2);
                         if (!$item->import($input2)) {
                             $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO);
                             $ma->addMessage($item->getErrorMessage(ERROR_ON_ACTION));
                         } else {
                             $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_OK);
                         }
                     }
                 } else {
                     $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_NORIGHT);
                     $ma->addMessage($item->getErrorMessage(ERROR_RIGHT));
                 }
             }
             return;
     }
     parent::processMassiveActionsForOneItemtype($ma, $item, $ids);
 }
Exemplo n.º 7
0
 /**
  * @since version 0.85
  *
  * @see CommonDBTM::processMassiveActionsForOneItemtype()
  **/
 static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids)
 {
     switch ($ma->getAction()) {
         case 'solveticket':
             $input = $ma->getInput();
             $ticket = new Ticket();
             foreach ($ids as $id) {
                 if ($item->can($id, READ)) {
                     if ($ticket->getFromDB($item->fields['tickets_id']) && $ticket->canSolve()) {
                         $toupdate = array();
                         $toupdate['id'] = $ticket->getID();
                         $toupdate['solutiontypes_id'] = $input['solutiontypes_id'];
                         $toupdate['solution'] = $input['solution'];
                         if ($ticket->update($toupdate)) {
                             $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK);
                         } else {
                             $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO);
                             $ma->addMessage($ticket->getErrorMessage(ERROR_ON_ACTION));
                         }
                     } else {
                         $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_NORIGHT);
                         $ma->addMessage($ticket->getErrorMessage(ERROR_RIGHT));
                     }
                 } else {
                     $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_NORIGHT);
                     $ma->addMessage($ticket->getErrorMessage(ERROR_RIGHT));
                 }
             }
             return;
     }
     parent::processMassiveActionsForOneItemtype($ma, $item, $ids);
 }
 /**
  * @since version 0.85
  *
  * @see CommonDBTM::processMassiveActionsForOneItemtype()
  **/
 static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids)
 {
     global $DB;
     switch ($ma->getAction()) {
         case 'move_license':
             $input = $ma->getInput();
             if (isset($input['softwarelicenses_id'])) {
                 foreach ($ids as $id) {
                     if ($item->can($id, UPDATE)) {
                         //Process rules
                         if ($item->update(array('id' => $id, 'softwarelicenses_id' => $input['softwarelicenses_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);
             }
             return;
         case 'install':
             $csl = new self();
             $csv = new Computer_SoftwareVersion();
             foreach ($ids as $id) {
                 if ($csl->getFromDB($id)) {
                     $sl = new SoftwareLicense();
                     if ($sl->getFromDB($csl->fields["softwarelicenses_id"])) {
                         $version = 0;
                         if ($sl->fields["softwareversions_id_use"] > 0) {
                             $version = $sl->fields["softwareversions_id_use"];
                         } else {
                             $version = $sl->fields["softwareversions_id_buy"];
                         }
                         if ($version > 0) {
                             $params = array('computers_id' => $csl->fields['computers_id'], 'softwareversions_id' => $version);
                             //Get software name and manufacturer
                             if ($csv->can(-1, CREATE, $params)) {
                                 //Process rules
                                 if ($csv->add($params)) {
                                     $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK);
                                 } else {
                                     $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO);
                                 }
                             } else {
                                 $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_NORIGHT);
                             }
                         } else {
                             $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO);
                         }
                     } else {
                         $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO);
                     }
                 }
             }
             return;
     }
     parent::processMassiveActionsForOneItemtype($ma, $item, $ids);
 }
Exemplo n.º 9
0
 /**
  * @since version 0.85
  *
  * @see CommonDBTM::processMassiveActionsForOneItemtype()
  **/
 static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids)
 {
     $account_item = new PluginAccountsAccount_Item();
     switch ($ma->getAction()) {
         case "add_item":
             $input = $ma->getInput();
             foreach ($ma->items as $itemtype => $myitem) {
                 foreach ($myitem as $key => $value) {
                     if (!countElementsInTable('glpi_plugin_accounts_accounts_items', "itemtype='{$itemtype}' \n                                             AND items_id='{$key}' \n                                             AND plugin_accounts_accounts_id='" . $input['plugin_accounts_accounts_id'] . "'")) {
                         $myvalue['plugin_accounts_accounts_id'] = $input['plugin_accounts_accounts_id'];
                         $myvalue['itemtype'] = $itemtype;
                         $myvalue['items_id'] = $key;
                         if ($account_item->add($myvalue)) {
                             $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_OK);
                         } else {
                             $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO);
                         }
                     } else {
                         $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO);
                     }
                 }
             }
             break;
         case "transfer":
             $input = $ma->getInput();
             if ($item->getType() == 'PluginAccountsAccount') {
                 foreach ($ids as $key) {
                     $item->getFromDB($key);
                     $type = PluginAccountsAccountType::transfer($item->fields["plugin_accounts_accounttypes_id"], $input['entities_id']);
                     if ($type > 0) {
                         $values["id"] = $key;
                         $values["plugin_accounts_accounttypes_id"] = $type;
                         $item->update($values);
                     }
                     unset($values);
                     $values["id"] = $key;
                     $values["entities_id"] = $input['entities_id'];
                     if ($item->update($values)) {
                         $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_OK);
                     } else {
                         $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO);
                     }
                 }
             }
             break;
         case 'install':
             $input = $ma->getInput();
             foreach ($ids as $key) {
                 if ($item->can($key, UPDATE)) {
                     $values = array('plugin_accounts_accounts_id' => $key, 'items_id' => $input["item_item"], 'itemtype' => $input['typeitem']);
                     if ($account_item->add($values)) {
                         $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_OK);
                     } else {
                         $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO);
                     }
                 } else {
                     $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_NORIGHT);
                     $ma->addMessage($item->getErrorMessage(ERROR_RIGHT));
                 }
             }
             break;
         case 'uninstall':
             $input = $ma->getInput();
             foreach ($ids as $key) {
                 if ($val == 1) {
                     if ($account_item->deleteItemByAccountsAndItem($key, $input['item_item'], $input['typeitem'])) {
                         $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_OK);
                     } else {
                         $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO);
                     }
                 }
             }
             break;
     }
 }
Exemplo n.º 10
0
 /**
  * @since version 0.90
  *
  * @param $item
  * @param $withtemplate    (default '')
  * @param $options         array
  *
  * @return boolean
  **/
 static function showAddFormForItem(CommonDBTM $item, $withtemplate = '', $options = array())
 {
     global $DB, $CFG_GLPI;
     //default options
     $params['rand'] = mt_rand();
     if (is_array($options) && count($options)) {
         foreach ($options as $key => $val) {
             $params[$key] = $val;
         }
     }
     if (!$item->can($item->fields['id'], READ)) {
         return false;
     }
     if (empty($withtemplate)) {
         $withtemplate = 0;
     }
     // find documents already associated to the item
     $doc_item = new self();
     $used_found = $doc_item->find("`items_id` = '" . $item->getID() . "'\n                                    AND `itemtype` = '" . $item->getType() . "'");
     $used = array_keys($used_found);
     $used = array_combine($used, $used);
     if ($item->canAddItem('Document') && $withtemplate < 2) {
         // Restrict entity for knowbase
         $entities = "";
         $entity = $_SESSION["glpiactive_entity"];
         if ($item->isEntityAssign()) {
             /// Case of personal items : entity = -1 : create on active entity (Reminder case))
             if ($item->getEntityID() >= 0) {
                 $entity = $item->getEntityID();
             }
             if ($item->isRecursive()) {
                 $entities = getSonsOf('glpi_entities', $entity);
             } else {
                 $entities = $entity;
             }
         }
         $limit = getEntitiesRestrictRequest(" AND ", "glpi_documents", '', $entities, true);
         $q = "SELECT COUNT(*)\n               FROM `glpi_documents`\n               WHERE `is_deleted` = '0'\n               {$limit}";
         $result = $DB->query($q);
         $nb = $DB->result($result, 0, 0);
         if ($item->getType() == 'Document') {
             $used[$item->getID()] = $item->getID();
         }
         echo "<div class='firstbloc'>";
         echo "<form name='documentitem_form" . $params['rand'] . "' id='documentitem_form" . $params['rand'] . "' method='post' action='" . Toolbox::getItemTypeFormURL('Document') . "' enctype=\"multipart/form-data\">";
         echo "<table class='tab_cadre_fixe'>";
         echo "<tr class='tab_bg_2'><th colspan='5'>" . __('Add a document') . "</th></tr>";
         echo "<tr class='tab_bg_1'>";
         echo "<td class='center'>";
         _e('Heading');
         echo "</td><td width='20%'>";
         DocumentCategory::dropdown(array('entity' => $entities));
         echo "</td>";
         echo "<td class='right'>";
         echo "<input type='hidden' name='entities_id' value='{$entity}'>";
         echo "<input type='hidden' name='is_recursive' value='" . $item->isRecursive() . "'>";
         echo "<input type='hidden' name='itemtype' value='" . $item->getType() . "'>";
         echo "<input type='hidden' name='items_id' value='" . $item->getID() . "'>";
         if ($item->getType() == 'Ticket') {
             echo "<input type='hidden' name='tickets_id' value='" . $item->getID() . "'>";
         }
         echo Html::file(array('multiple' => true));
         echo "</td><td class='left'>(" . Document::getMaxUploadSize() . ")&nbsp;</td>";
         echo "<td class='center' width='20%'>";
         echo "<input type='submit' name='add' value=\"" . _sx('button', 'Add a new file') . "\"\n                class='submit'>";
         echo "</td></tr>";
         echo "</table>";
         Html::closeForm();
         if (Document::canView() && $nb > count($used)) {
             echo "<form name='document_form" . $params['rand'] . "' id='document_form" . $params['rand'] . "' method='post' action='" . Toolbox::getItemTypeFormURL(__CLASS__) . "'>";
             echo "<table class='tab_cadre_fixe'>";
             echo "<tr class='tab_bg_1'>";
             echo "<td colspan='4' class='center'>";
             echo "<input type='hidden' name='itemtype' value='" . $item->getType() . "'>";
             echo "<input type='hidden' name='items_id' value='" . $item->getID() . "'>";
             if ($item->getType() == 'Ticket') {
                 echo "<input type='hidden' name='tickets_id' value='" . $item->getID() . "'>";
                 echo "<input type='hidden' name='documentcategories_id' value='" . $CFG_GLPI["documentcategories_id_forticket"] . "'>";
             }
             Document::dropdown(array('entity' => $entities, 'used' => $used));
             echo "</td><td class='center' width='20%'>";
             echo "<input type='submit' name='add' value=\"" . _sx('button', 'Associate an existing document') . "\" class='submit'>";
             echo "</td>";
             echo "</tr>";
             echo "</table>";
             Html::closeForm();
         }
         echo "</div>";
     }
 }
 /**
  * @since version 0.85
  *
  * @see CommonDBTM::processMassiveActionsForOneItemtype()
  **/
 static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids)
 {
     global $DB;
     switch ($ma->getAction()) {
         case 'move_version':
             $input = $ma->getInput();
             if (isset($input['softwareversions_id'])) {
                 foreach ($ids as $id) {
                     if ($item->can($id, UPDATE)) {
                         //Process rules
                         if ($item->update(array('id' => $id, 'softwareversions_id' => $input['softwareversions_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);
             }
             return;
         case 'add':
             $itemtoadd = new Computer_SoftwareVersion();
             if (isset($_POST['peer_softwareversions_id'])) {
                 foreach ($ids as $id) {
                     if ($item->can($id, UPDATE)) {
                         //Process rules
                         if ($itemtoadd->add(array('computers_id' => $id, 'softwareversions_id' => $_POST['peer_softwareversions_id']))) {
                             $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK);
                         } else {
                             $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO);
                             $ma->addMessage($itemtoadd->getErrorMessage(ERROR_ON_ACTION));
                         }
                     } else {
                         $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_NORIGHT);
                         $ma->addMessage($itemtoadd->getErrorMessage(ERROR_RIGHT));
                     }
                 }
             } else {
                 $ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_KO);
             }
             return;
     }
     parent::processMassiveActionsForOneItemtype($ma, $item, $ids);
 }
Exemplo n.º 12
0
 static function showUsers(CommonDBTM $item)
 {
     global $DB, $CFG_GLPI;
     $ID = $item->getField('id');
     if ($item->isNewID($ID)) {
         return false;
     }
     if (!plugin_projet_haveRight('projet', 'r')) {
         return false;
     }
     if (!$item->can($item->fields['id'], 'r')) {
         return false;
     }
     $canread = $item->can($ID, 'r');
     $query = "SELECT `glpi_plugin_projet_projets`.* FROM `glpi_plugin_projet_projets` " . " LEFT JOIN `glpi_entities` ON (`glpi_entities`.`id` = `glpi_plugin_projet_projets`.`entities_id`) ";
     if ($item->getType() == 'User') {
         $query .= " WHERE `glpi_plugin_projet_projets`.`users_id` = '" . $ID . "' ";
     } else {
         $query .= " WHERE `glpi_plugin_projet_projets`.`groups_id` = '" . $ID . "' ";
     }
     $query .= "AND `glpi_plugin_projet_projets`.`is_template` = 0 " . getEntitiesRestrictRequest(" AND ", "glpi_plugin_projet_projets", '', '', $item->maybeRecursive());
     $result = $DB->query($query);
     $number = $DB->numrows($result);
     if (Session::isMultiEntitiesMode()) {
         $colsup = 1;
     } else {
         $colsup = 0;
     }
     if ($number > 0) {
         echo "<form method='post' action=\"" . $CFG_GLPI["root_doc"] . "/plugins/projet/front/projet.form.php\">";
         echo "<div align='center'><table class='tab_cadre_fixe'>";
         echo "<tr><th colspan='" . (4 + $colsup) . "'>" . __('Responsible of projects', 'projet') . ":</th></tr>";
         echo "<tr><th>" . __('Name') . "</th>";
         if (Session::isMultiEntitiesMode()) {
             echo "<th>" . __('Entity') . "</th>";
         }
         echo "<th>" . __('Description') . "</th>";
         echo "<th>" . __('Progress') . "</th>";
         echo "</tr>";
         while ($data = $DB->fetch_array($result)) {
             echo "<tr class='tab_bg_1" . ($data["is_deleted"] == '1' ? "_2" : "") . "'>";
             if ($canread && (in_array($data['entities_id'], $_SESSION['glpiactiveentities']) || $data["recursive"])) {
                 echo "<td class='center'><a href='" . $CFG_GLPI["root_doc"] . "/plugins/projet/front/projet.form.php?id=" . $data["id"] . "'>" . $data["name"];
                 if ($_SESSION["glpiis_ids_visible"]) {
                     echo " (" . $data["id"] . ")";
                 }
                 echo "</a></td>";
             } else {
                 echo "<td class='center'>" . $data["name"];
                 if ($_SESSION["glpiis_ids_visible"]) {
                     echo " (" . $data["id"] . ")";
                 }
                 echo "</td>";
             }
             if (Session::isMultiEntitiesMode()) {
                 echo "<td class='center'>" . Dropdown::getDropdownName("glpi_entities", $data['entities_id']) . "</td>";
             }
             echo "<td align='center'>" . Html::resume_text($data["description"], 250) . "</td>";
             echo "<td align='center'>" . $data["advance"] . " %</td>";
             echo "</tr>";
         }
         echo "</table></div>";
         Html::closeForm();
         echo "<br>";
     } else {
         echo "<div align='center'><table class='tab_cadre_fixe' style='text-align:center'>";
         echo "<tr><th>" . __('Responsible of projects', 'projet') . " - " . __('No item found');
         echo "</th></tr></table></div><br>";
     }
 }
Exemplo n.º 13
0
 /**
  * @since version 0.85
  *
  * @see CommonDBTM::processMassiveActionsForOneItemtype()
  **/
 static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids)
 {
     $input = $ma->getInput();
     switch ($ma->getAction()) {
         case 'move_under':
             if (isset($input['parent'])) {
                 $fk = $item->getForeignKeyField();
                 $parent = clone $item;
                 if (!$parent->getFromDB($input['parent'])) {
                     $ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_KO);
                     $ma->addMessage($parent->getErrorMessage(ERROR_NOT_FOUND));
                     return;
                 }
                 foreach ($ids as $id) {
                     if ($item->can($id, UPDATE)) {
                         // Check if parent is not a child of the original one
                         if (!in_array($parent->getID(), getSonsOf($item->getTable(), $item->getID()))) {
                             if ($item->update(array('id' => $id, $fk => $parent->getID()))) {
                                 $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_KO);
                             $ma->addMessage($item->getErrorMessage(ERROR_COMPAT));
                         }
                     } 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($parent->getErrorMessage(ERROR_COMPAT));
             }
             return;
     }
     parent::processMassiveActionsForOneItemtype($ma, $item, $ids);
 }
 /**
  * Show rack associated to an item
  *
  * @since version 0.84
  *
  * @param $item            CommonDBTM object for which associated rack must be displayed
  * @param $withtemplate    (default '')
  **/
 static function showForItem(CommonDBTM $item, $withtemplate = '')
 {
     global $DB, $CFG_GLPI;
     $ID = $item->getField('id');
     if ($item->isNewID($ID) || !self::canView() || !$item->can($item->fields['id'], READ)) {
         return false;
     }
     if (empty($withtemplate)) {
         $withtemplate = 0;
     }
     $canedit = $item->canadditem('PluginRacksRack');
     $rand = mt_rand();
     $is_recursive = $item->isRecursive();
     $itemtype = $item->getType() . "Model";
     $query = "SELECT `glpi_plugin_racks_racks_items`.`id` AS assocID,\n                       `glpi_plugin_racks_racks_items`.`faces_id`,\n                       `glpi_plugin_racks_racks_items`.`position`,\n                       `glpi_entities`.`id` AS entity,\n                       `glpi_plugin_racks_racks`.`name` AS assocName,\n                       `glpi_plugin_racks_racks`.*\n                FROM `glpi_plugin_racks_racks_items`\n                LEFT JOIN `glpi_plugin_racks_racks`\n                 ON (`glpi_plugin_racks_racks_items`.`plugin_racks_racks_id`=`glpi_plugin_racks_racks`.`id`)\n                LEFT JOIN `glpi_entities` ON (`glpi_plugin_racks_racks`.`entities_id`=`glpi_entities`.`id`)\n                WHERE `glpi_plugin_racks_racks_items`.`items_id` = '{$ID}'\n                      AND `glpi_plugin_racks_racks_items`.`itemtype` = '" . $itemtype . "' ";
     $query .= getEntitiesRestrictRequest(" AND", "glpi_plugin_racks_racks", '', '', true);
     $query .= " ORDER BY `assocName`";
     $result = $DB->query($query);
     $number = $DB->numrows($result);
     $i = 0;
     $racks = array();
     $rack = new PluginRacksRack();
     $used = array();
     if ($numrows = $DB->numrows($result)) {
         while ($data = $DB->fetch_assoc($result)) {
             $racks[$data['assocID']] = $data;
             $used[$data['id']] = $data['id'];
         }
     }
     echo "<div class='spaced'>";
     if ($canedit && $number && $withtemplate < 2) {
         Html::openMassiveActionsForm('mass' . __CLASS__ . $rand);
         $massiveactionparams = array('num_displayed' => $number);
         Html::showMassiveActions($massiveactionparams);
     }
     echo "<table class='tab_cadre_fixe'>";
     echo "<tr>";
     if ($canedit && $number && $withtemplate < 2) {
         echo "<th width='10'>" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand) . "</th>";
     }
     echo "<th>" . __('Name') . "</th>";
     if (Session::isMultiEntitiesMode()) {
         echo "<th>" . __('Entity') . "</th>";
     }
     echo "<th>" . __('Disposition', 'racks') . "</th>";
     echo "<th>" . __('Position', 'racks') . "</th>";
     echo "<th>" . __('Location') . "</th>";
     echo "<th>" . __('Place', 'racks') . "</th>";
     echo "<th>" . __('Manufacturer') . "</th>";
     echo "</tr>";
     $used = array();
     if ($number) {
         Session::initNavigateListItems('PluginRacksRack', sprintf(__('%1$s = %2$s'), $item->getTypeName(1), $item->getName()));
         foreach ($racks as $data) {
             $rackID = $data["id"];
             $link = NOT_AVAILABLE;
             if ($rack->getFromDB($rackID)) {
                 $link = $rack->getLink();
             }
             Session::addToNavigateListItems('PluginRacksRack', $rackID);
             $used[$rackID] = $rackID;
             $assocID = $data["assocID"];
             echo "<tr class='tab_bg_1" . ($data["is_deleted"] ? "_2" : "") . "'>";
             if ($canedit && $withtemplate < 2) {
                 echo "<td width='10'>";
                 Html::showMassiveActionCheckBox(__CLASS__, $data["assocID"]);
                 echo "</td>";
             }
             echo "<td class='center'>{$link}</td>";
             if (Session::isMultiEntitiesMode()) {
                 echo "<td class='center'>" . Dropdown::getDropdownName("glpi_entities", $data['entities_id']) . "</td>";
             }
             if ($data["faces_id"] == PluginRacksRack::FRONT_FACE) {
                 $faces_id = __('Front', 'racks');
             } else {
                 $faces_id = _x('Rack enclosure', 'Back', 'racks');
             }
             echo "<td class='center'>" . $faces_id . "</td>";
             echo "<td class='center'>" . $data["position"] . "</td>";
             echo "<td>" . Dropdown::getDropdownName("glpi_locations", $data["locations_id"]) . "</td>";
             echo "<td class='center'>" . Dropdown::getDropdownName("glpi_plugin_racks_roomlocations", $data["plugin_racks_roomlocations_id"], 0) . "</td>";
             echo "<td>" . Dropdown::getDropdownName("glpi_manufacturers", $data["manufacturers_id"]) . "</td>";
             echo "</tr>";
             $i++;
         }
     }
     echo "</table>";
     if ($canedit && $number && $withtemplate < 2) {
         $massiveactionparams['ontop'] = false;
         Html::showMassiveActions($massiveactionparams);
         Html::closeForm();
     }
     echo "</div>";
 }
 /**
  * Show webapplications associated to an item
  *
  * @since version 0.84
  *
  * @param $item            CommonDBTM object for which associated webapplications must be displayed
  * @param $withtemplate    (default '')
  **/
 static function showForItem(CommonDBTM $item, $withtemplate = '')
 {
     global $DB, $CFG_GLPI;
     $ID = $item->getField('id');
     if ($item->isNewID($ID)) {
         return false;
     }
     if (!Session::haveRight("plugin_webapplications", READ)) {
         return false;
     }
     if (!$item->can($item->fields['id'], READ)) {
         return false;
     }
     if (empty($withtemplate)) {
         $withtemplate = 0;
     }
     $canedit = $item->canadditem('PluginWebapplicationsWebapplication');
     $rand = mt_rand();
     $is_recursive = $item->isRecursive();
     $query = "SELECT `glpi_plugin_webapplications_webapplications_items`.`id` AS assocID,\n                       `glpi_entities`.`id` AS entity,\n                       `glpi_plugin_webapplications_webapplications`.`name` AS assocName,\n                       `glpi_plugin_webapplications_webapplications`.*\n                FROM `glpi_plugin_webapplications_webapplications_items`\n                LEFT JOIN `glpi_plugin_webapplications_webapplications`\n                 ON (`glpi_plugin_webapplications_webapplications_items`.`plugin_webapplications_webapplications_id`=`glpi_plugin_webapplications_webapplications`.`id`)\n                LEFT JOIN `glpi_entities` ON (`glpi_plugin_webapplications_webapplications`.`entities_id`=`glpi_entities`.`id`)\n                WHERE `glpi_plugin_webapplications_webapplications_items`.`items_id` = '{$ID}'\n                      AND `glpi_plugin_webapplications_webapplications_items`.`itemtype` = '" . $item->getType() . "' ";
     $query .= getEntitiesRestrictRequest(" AND", "glpi_plugin_webapplications_webapplications", '', '', true);
     $query .= " ORDER BY `assocName`";
     $result = $DB->query($query);
     $number = $DB->numrows($result);
     $i = 0;
     $webs = array();
     $web = new PluginWebapplicationsWebapplication();
     $used = array();
     if ($numrows = $DB->numrows($result)) {
         while ($data = $DB->fetch_assoc($result)) {
             $webs[$data['assocID']] = $data;
             $used[$data['id']] = $data['id'];
         }
     }
     if ($canedit && $withtemplate < 2) {
         // Restrict entity for knowbase
         $entities = "";
         $entity = $_SESSION["glpiactive_entity"];
         if ($item->isEntityAssign()) {
             /// Case of personal items : entity = -1 : create on active entity (Reminder case))
             if ($item->getEntityID() >= 0) {
                 $entity = $item->getEntityID();
             }
             if ($item->isRecursive()) {
                 $entities = getSonsOf('glpi_entities', $entity);
             } else {
                 $entities = $entity;
             }
         }
         $limit = getEntitiesRestrictRequest(" AND ", "glpi_plugin_webapplications_webapplications", '', $entities, true);
         $q = "SELECT COUNT(*)\n               FROM `glpi_plugin_webapplications_webapplications`\n               WHERE `is_deleted` = '0'\n               {$limit}";
         $result = $DB->query($q);
         $nb = $DB->result($result, 0, 0);
         echo "<div class='firstbloc'>";
         if (Session::haveRight("plugin_webapplications", READ) && $nb > count($used)) {
             echo "<form name='webapplication_form{$rand}' id='webapplication_form{$rand}' method='post'\n                   action='" . Toolbox::getItemTypeFormURL('PluginWebapplicationsWebapplication') . "'>";
             echo "<table class='tab_cadre_fixe'>";
             echo "<tr class='tab_bg_1'>";
             echo "<td colspan='4' class='center'>";
             echo "<input type='hidden' name='entities_id' value='{$entity}'>";
             echo "<input type='hidden' name='is_recursive' value='{$is_recursive}'>";
             echo "<input type='hidden' name='itemtype' value='" . $item->getType() . "'>";
             echo "<input type='hidden' name='items_id' value='{$ID}'>";
             if ($item->getType() == 'Ticket') {
                 echo "<input type='hidden' name='tickets_id' value='{$ID}'>";
             }
             PluginWebapplicationsWebapplication::dropdownWebapplication(array('entity' => $entities, 'used' => $used));
             echo "</td><td class='center' width='20%'>";
             echo "<input type='submit' name='additem' value=\"" . __s('Associate a web application', 'webapplications') . "\" class='submit'>";
             echo "</td>";
             echo "</tr>";
             echo "</table>";
             Html::closeForm();
         }
         echo "</div>";
     }
     echo "<div class='spaced'>";
     if ($canedit && $number && $withtemplate < 2) {
         Html::openMassiveActionsForm('mass' . __CLASS__ . $rand);
         $massiveactionparams = array('num_displayed' => $number);
         Html::showMassiveActions($massiveactionparams);
     }
     echo "<table class='tab_cadre_fixe'>";
     echo "<tr>";
     if ($canedit && $number && $withtemplate < 2) {
         echo "<th width='10'>" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand) . "</th>";
     }
     echo "<th>" . __('Name') . "</th>";
     if (Session::isMultiEntitiesMode()) {
         echo "<th>" . __('Entity') . "</th>";
     }
     echo "<th>" . PluginWebapplicationsWebapplicationType::getTypeName(1) . "</th>";
     echo "<th>" . __('URL') . "</th>";
     echo "<th>" . __('Server') . "</th>";
     echo "<th>" . __('Language') . "</th>";
     echo "<th>" . __('Version') . "</th>";
     echo "<th>" . __('Comments') . "</th>";
     echo "</tr>";
     $used = array();
     if ($number) {
         Session::initNavigateListItems('PluginWebapplicationsWebapplication', sprintf(__('%1$s = %2$s'), $item->getTypeName(1), $item->getName()));
         foreach ($webs as $data) {
             $webID = $data["id"];
             $link = NOT_AVAILABLE;
             if ($web->getFromDB($webID)) {
                 $link = $web->getLink();
             }
             Session::addToNavigateListItems('PluginWebapplicationsWebapplication', $webID);
             $used[$webID] = $webID;
             $assocID = $data["assocID"];
             echo "<tr class='tab_bg_1" . ($data["is_deleted"] ? "_2" : "") . "'>";
             if ($canedit && $withtemplate < 2) {
                 echo "<td width='10'>";
                 Html::showMassiveActionCheckBox(__CLASS__, $data["assocID"]);
                 echo "</td>";
             }
             echo "<td class='center'>{$link}</td>";
             if (Session::isMultiEntitiesMode()) {
                 echo "<td class='center'>" . Dropdown::getDropdownName("glpi_entities", $data['entities_id']) . "</td>";
             }
             echo "<td>" . Dropdown::getDropdownName("glpi_plugin_webapplications_webapplicationtypes", $data["plugin_webapplications_webapplicationtypes_id"]) . "</td>";
             $link = Toolbox::substr($data["address"], 0, 30) . "...";
             echo "<td class='center'>" . "<a href=\"" . str_replace("&", "&amp;", $data["address"]) . "\" target=\"_blank\">" . "<u>" . $link . "</u></a></td>";
             echo "<td>" . Dropdown::getDropdownName("glpi_plugin_webapplications_webapplicationservertypes", $data["plugin_webapplications_webapplicationservertypes_id"]) . "</td>";
             echo "<td>" . Dropdown::getDropdownName("glpi_plugin_webapplications_webapplicationtechnics", $data["plugin_webapplications_webapplicationtechnics_id"]) . "</td>";
             echo "<td>" . $data["version"] . "</td>";
             echo "<td>" . $data["comment"] . "</td>";
             echo "</tr>";
             $i++;
         }
     }
     echo "</table>";
     if ($canedit && $number && $withtemplate < 2) {
         $massiveactionparams['ontop'] = false;
         Html::showMassiveActions($massiveactionparams);
         Html::closeForm();
     }
     echo "</div>";
 }
Exemplo n.º 16
0
 /**
  * Print an HTML array of contract associated to an object
  *
  * @since version 0.84
  *
  * @param $item            CommonDBTM object wanted
  * @param $withtemplate    not used (to be deleted) (default '')
  *
  * @return Nothing (display)
  **/
 static function showForItem(CommonDBTM $item, $withtemplate = '')
 {
     global $DB, $CFG_GLPI;
     $itemtype = $item->getType();
     $ID = $item->fields['id'];
     if (!Contract::canView() || !$item->can($ID, READ)) {
         return false;
     }
     $canedit = $item->can($ID, UPDATE);
     $rand = mt_rand();
     $query = "SELECT `glpi_contracts_items`.*\n                FROM `glpi_contracts_items`,\n                     `glpi_contracts`\n                LEFT JOIN `glpi_entities` ON (`glpi_contracts`.`entities_id`=`glpi_entities`.`id`)\n                WHERE `glpi_contracts`.`id`=`glpi_contracts_items`.`contracts_id`\n                      AND `glpi_contracts_items`.`items_id` = '{$ID}'\n                      AND `glpi_contracts_items`.`itemtype` = '{$itemtype}'" . getEntitiesRestrictRequest(" AND", "glpi_contracts", '', '', true) . "\n                ORDER BY `glpi_contracts`.`name`";
     $result = $DB->query($query);
     $contracts = array();
     $used = array();
     if ($number = $DB->numrows($result)) {
         while ($data = $DB->fetch_assoc($result)) {
             $contracts[$data['id']] = $data;
             $used[$data['contracts_id']] = $data['contracts_id'];
         }
     }
     if ($canedit && $withtemplate != 2) {
         echo "<div class='firstbloc'>";
         echo "<form name='contractitem_form{$rand}' id='contractitem_form{$rand}' method='post'\n                action='" . Toolbox::getItemTypeFormURL(__CLASS__) . "'>";
         echo "<input type='hidden' name='items_id' value='{$ID}'>";
         echo "<input type='hidden' name='itemtype' value='{$itemtype}'>";
         echo "<table class='tab_cadre_fixe'>";
         echo "<tr class='tab_bg_2'><th colspan='2'>" . __('Add a contract') . "</th></tr>";
         echo "<tr class='tab_bg_1'><td>";
         Contract::dropdown(array('entity' => $item->getEntityID(), 'used' => $used));
         echo "</td><td class='center'>";
         echo "<input type='submit' name='add' value=\"" . _sx('button', 'Add') . "\" class='submit'>";
         echo "</td></tr>";
         echo "</table>";
         Html::closeForm();
         echo "</div>";
     }
     echo "<div class='spaced'>";
     if ($withtemplate != 2) {
         if ($canedit && $number) {
             Html::openMassiveActionsForm('mass' . __CLASS__ . $rand);
             $massiveactionparams = array('num_displayed' => $number, 'container' => 'mass' . __CLASS__ . $rand);
             Html::showMassiveActions($massiveactionparams);
         }
     }
     echo "<table class='tab_cadre_fixehov'>";
     $header_begin = "<tr>";
     $header_top = '';
     $header_bottom = '';
     $header_end = '';
     if ($canedit && $number && $withtemplate != 2) {
         $header_top .= "<th width='10'>" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand);
         $header_top .= "</th>";
         $header_bottom .= "<th width='10'>" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand);
         $header_bottom .= "</th>";
     }
     $header_end .= "<th>" . __('Name') . "</th>";
     $header_end .= "<th>" . __('Entity') . "</th>";
     $header_end .= "<th>" . _x('phone', 'Number') . "</th>";
     $header_end .= "<th>" . __('Contract type') . "</th>";
     $header_end .= "<th>" . __('Supplier') . "</th>";
     $header_end .= "<th>" . __('Start date') . "</th>";
     $header_end .= "<th>" . __('Initial contract period') . "</th>";
     $header_end .= "</tr>";
     echo $header_begin . $header_top . $header_end;
     if ($number > 0) {
         Session::initNavigateListItems(__CLASS__, sprintf(__('%1$s = %2$s'), $item->getTypeName(1), $item->getName()));
         foreach ($contracts as $data) {
             $cID = $data["contracts_id"];
             Session::addToNavigateListItems(__CLASS__, $cID);
             $contracts[] = $cID;
             $assocID = $data["id"];
             $con = new Contract();
             $con->getFromDB($cID);
             echo "<tr class='tab_bg_1" . ($con->fields["is_deleted"] ? "_2" : "") . "'>";
             if ($canedit && $withtemplate != 2) {
                 echo "<td width='10'>";
                 Html::showMassiveActionCheckBox(__CLASS__, $data["id"]);
                 echo "</td>";
             }
             echo "<td class='center b'>";
             $name = $con->fields["name"];
             if ($_SESSION["glpiis_ids_visible"] || empty($con->fields["name"])) {
                 $name = sprintf(__('%1$s (%2$s)'), $name, $con->fields["id"]);
             }
             echo "<a href='" . $CFG_GLPI["root_doc"] . "/front/contract.form.php?id={$cID}'>" . $name;
             echo "</a></td>";
             echo "<td class='center'>";
             echo Dropdown::getDropdownName("glpi_entities", $con->fields["entities_id"]) . "</td>";
             echo "<td class='center'>" . $con->fields["num"] . "</td>";
             echo "<td class='center'>";
             echo Dropdown::getDropdownName("glpi_contracttypes", $con->fields["contracttypes_id"]) . "</td>";
             echo "<td class='center'>" . $con->getSuppliersNames() . "</td>";
             echo "<td class='center'>" . Html::convDate($con->fields["begin_date"]) . "</td>";
             echo "<td class='center'>" . sprintf(__('%1$s %2$s'), $con->fields["duration"], _n('month', 'months', $con->fields["duration"]));
             if ($con->fields["begin_date"] != '' && !empty($con->fields["begin_date"])) {
                 echo " -> " . Infocom::getWarrantyExpir($con->fields["begin_date"], $con->fields["duration"], 0, true);
             }
             echo "</td>";
             echo "</tr>";
         }
         echo $header_begin . $header_bottom . $header_end;
     }
     echo "</table>";
     if ($canedit && $number && $withtemplate != 2) {
         $massiveactionparams['ontop'] = false;
         Html::showMassiveActions($massiveactionparams);
         Html::closeForm();
     }
     echo "</div>";
 }
Exemplo n.º 17
0
 /**
  * @since version 0.85
  *
  * @see CommonDBTM::processMassiveActionsForOneItemtype()
  **/
 static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids)
 {
     switch ($ma->getAction()) {
         case 'add_task':
             if (!($task = getItemForItemtype('TicketTask'))) {
                 $ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_KO);
                 break;
             }
             $ticket = new Ticket();
             $field = $ticket->getForeignKeyField();
             $input = $ma->getInput();
             foreach ($ids as $id) {
                 if ($item->can($id, READ)) {
                     if ($ticket->getFromDB($item->fields['tickets_id'])) {
                         $input2 = array($field => $item->fields['tickets_id'], 'taskcategories_id' => $input['taskcategories_id'], 'actiontime' => $input['actiontime'], 'content' => $input['content']);
                         if ($task->can(-1, CREATE, $input2)) {
                             if ($task->add($input2)) {
                                 $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(), $id, MassiveAction::ACTION_NORIGHT);
                         $ma->addMessage($item->getErrorMessage(ERROR_RIGHT));
                     }
                 }
             }
             return;
         case 'solveticket':
             $input = $ma->getInput();
             $ticket = new Ticket();
             foreach ($ids as $id) {
                 if ($item->can($id, READ)) {
                     if ($ticket->getFromDB($item->fields['tickets_id']) && $ticket->canSolve()) {
                         $toupdate = array();
                         $toupdate['id'] = $ticket->getID();
                         $toupdate['solutiontypes_id'] = $input['solutiontypes_id'];
                         $toupdate['solution'] = $input['solution'];
                         if ($ticket->update($toupdate)) {
                             $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK);
                         } else {
                             $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO);
                             $ma->addMessage($ticket->getErrorMessage(ERROR_ON_ACTION));
                         }
                     } else {
                         $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_NORIGHT);
                         $ma->addMessage($ticket->getErrorMessage(ERROR_RIGHT));
                     }
                 } else {
                     $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_NORIGHT);
                     $ma->addMessage($ticket->getErrorMessage(ERROR_RIGHT));
                 }
             }
             return;
     }
     parent::processMassiveActionsForOneItemtype($ma, $item, $ids);
 }
Exemplo n.º 18
0
 /**
  * @see CommonDBTM::processMassiveActionsForOneItemtype()
  **/
 static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids)
 {
     global $CFG_GLPI;
     $action = $ma->getAction();
     switch ($action) {
         case 'delete':
             foreach ($ids as $id) {
                 if ($item->can($id, DELETE)) {
                     if ($item->delete(array("id" => $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));
                 }
             }
             break;
         case 'restore':
             foreach ($ids as $id) {
                 if ($item->can($id, PURGE)) {
                     if ($item->restore(array("id" => $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));
                 }
             }
             break;
         case 'purge_item_but_devices':
         case 'purge_but_item_linked':
         case 'purge':
             foreach ($ids as $id) {
                 if ($item->can($id, PURGE)) {
                     $force = 1;
                     // Only mark deletion for
                     if ($item->maybeDeleted() && $item->useDeletedToLockIfDynamic() && $item->isDynamic()) {
                         $force = 0;
                     }
                     $delete_array = array('id' => $id);
                     if ($action == 'purge_item_but_devices') {
                         $delete_array['keep_devices'] = true;
                     }
                     if ($item instanceof CommonDropdown) {
                         if ($item->haveChildren()) {
                             if ($action != 'purge_but_item_linked') {
                                 $force = 0;
                                 $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO);
                                 $ma->addMessage(__("You can't delete that item by massive actions, because it has sub-items"));
                                 $ma->addMessage(__("but you can do it by the form of the item"));
                                 continue;
                             }
                         }
                         if ($item->isUsed()) {
                             if ($action != 'purge_but_item_linked') {
                                 $force = 0;
                                 $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO);
                                 $ma->addMessage(__("You can't delete that item, because it is used for one or more items"));
                                 $ma->addMessage(__("but you can do it by the form of the item"));
                                 continue;
                             }
                         }
                     }
                     if ($item->delete($delete_array, $force)) {
                         $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));
                 }
             }
             break;
         case 'update':
             if (!isset($ma->POST['search_options']) || !isset($ma->POST['search_options'][$item->getType()])) {
                 return false;
             }
             $index = $ma->POST['search_options'][$item->getType()];
             $searchopt = Search::getCleanedOptions($item->getType(), UPDATE);
             $input = $ma->POST;
             if (isset($searchopt[$index])) {
                 /// Infocoms case
                 if (!isPluginItemType($item->getType()) && Search::isInfocomOption($item->getType(), $index)) {
                     $ic = new Infocom();
                     $link_entity_type = -1;
                     /// Specific entity item
                     if ($searchopt[$index]["table"] == "glpi_suppliers") {
                         $ent = new Supplier();
                         if ($ent->getFromDB($input[$input["field"]])) {
                             $link_entity_type = $ent->fields["entities_id"];
                         }
                     }
                     foreach ($ids as $key) {
                         if ($item->getFromDB($key)) {
                             if ($link_entity_type < 0 || $link_entity_type == $item->getEntityID() || $ent->fields["is_recursive"] && in_array($link_entity_type, getAncestorsOf("glpi_entities", $item->getEntityID()))) {
                                 $input2["items_id"] = $key;
                                 $input2["itemtype"] = $item->getType();
                                 if ($ic->can(-1, CREATE, $input2)) {
                                     // Add infocom if not exists
                                     if (!$ic->getFromDBforDevice($item->getType(), $key)) {
                                         $input2["items_id"] = $key;
                                         $input2["itemtype"] = $item->getType();
                                         unset($ic->fields);
                                         $ic->add($input2);
                                         $ic->getFromDBforDevice($item->getType(), $key);
                                     }
                                     $id = $ic->fields["id"];
                                     unset($ic->fields);
                                     if ($ic->update(array('id' => $id, $input["field"] => $input[$input["field"]]))) {
                                         $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_OK);
                                     } else {
                                         $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO);
                                         $ma->addMessage($item->getErrorMessage(ERROR_ON_ACTION));
                                     }
                                 } else {
                                     $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_NORIGHT);
                                     $ma->addMessage($item->getErrorMessage(ERROR_RIGHT));
                                 }
                             } else {
                                 $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO);
                                 $ma->addMessage($item->getErrorMessage(ERROR_COMPAT));
                             }
                         } else {
                             $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO);
                             $ma->addMessage($item->getErrorMessage(ERROR_NOT_FOUND));
                         }
                     }
                 } else {
                     /// Not infocoms
                     $link_entity_type = array();
                     /// Specific entity item
                     $itemtable = getTableForItemType($item->getType());
                     $itemtype2 = getItemTypeForTable($searchopt[$index]["table"]);
                     if ($item2 = getItemForItemtype($itemtype2)) {
                         if ($index != 80 && $searchopt[$index]["table"] != $itemtable && $item2->isEntityAssign() && $item->isEntityAssign()) {
                             if ($item2->getFromDB($input[$input["field"]])) {
                                 if (isset($item2->fields["entities_id"]) && $item2->fields["entities_id"] >= 0) {
                                     if (isset($item2->fields["is_recursive"]) && $item2->fields["is_recursive"]) {
                                         $link_entity_type = getSonsOf("glpi_entities", $item2->fields["entities_id"]);
                                     } else {
                                         $link_entity_type[] = $item2->fields["entities_id"];
                                     }
                                 }
                             }
                         }
                     }
                     foreach ($ids as $key) {
                         if ($item->canEdit($key) && $item->canMassiveAction($action, $input['field'], $input[$input["field"]])) {
                             if (count($link_entity_type) == 0 || in_array($item->fields["entities_id"], $link_entity_type)) {
                                 if ($item->update(array('id' => $key, $input["field"] => $input[$input["field"]]))) {
                                     $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_OK);
                                 } else {
                                     $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO);
                                     $ma->addMessage($item->getErrorMessage(ERROR_ON_ACTION));
                                 }
                             } else {
                                 $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO);
                                 $ma->addMessage($item->getErrorMessage(ERROR_COMPAT));
                             }
                         } else {
                             $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_NORIGHT);
                             $ma->addMessage($item->getErrorMessage(ERROR_RIGHT));
                         }
                     }
                 }
             }
             break;
         case 'add_transfer_list':
             $itemtype = $item->getType();
             if (!isset($_SESSION['glpitransfer_list'])) {
                 $_SESSION['glpitransfer_list'] = array();
             }
             if (!isset($_SESSION['glpitransfer_list'][$itemtype])) {
                 $_SESSION['glpitransfer_list'][$itemtype] = array();
             }
             foreach ($ids as $id) {
                 $_SESSION['glpitransfer_list'][$itemtype][$id] = $id;
                 $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK);
             }
             $ma->setRedirect($CFG_GLPI['root_doc'] . '/front/transfer.action.php');
             break;
     }
 }
Exemplo n.º 19
0
 /**
  * Get contracts associated to an item
  *
  * @param $item            CommonDBTM : object wanted
  *
  * @return Nothing (display)
  **/
 static function getAssociatedContracts(CommonDBTM $item)
 {
     global $DB;
     $contracts = array();
     if (!Session::haveRight("contract", READ) || !$item->can($item->fields['id'], READ)) {
         return array();
     }
     $query = "SELECT `glpi_contracts_items`.*\n                FROM `glpi_contracts_items`,\n                     `glpi_contracts`\n                LEFT JOIN `glpi_entities` ON (`glpi_contracts`.`entities_id`=`glpi_entities`.`id`)\n                WHERE `glpi_contracts`.`id`=`glpi_contracts_items`.`contracts_id`\n                      AND `glpi_contracts_items`.`items_id` = '" . $item->fields['id'] . "'\n                      AND `glpi_contracts_items`.`itemtype` = '" . $item->getType() . "'" . getEntitiesRestrictRequest(" AND", "glpi_contracts", '', '', true) . "\n               ORDER BY `glpi_contracts`.`name`";
     foreach ($DB->request($query) as $data) {
         $contracts[] = $data;
     }
     return $contracts;
 }
   /**
    * Show certificates associated to an item
    *
    * @since version 0.84
    *
    * @param $item            CommonDBTM object for which associated certificates must be displayed
    * @param $withtemplate    (default '')
   **/
   static function showForItem(CommonDBTM $item, $withtemplate='') {
      global $DB, $CFG_GLPI;

      $ID = $item->getField('id');

      if ($item->isNewID($ID)) {
         return false;
      }
      if (!Session::haveRight("plugin_certificates", READ)) {
         return false;
      }

      if (!$item->can($item->fields['id'], READ)) {
         return false;
      }

      if (empty($withtemplate)) {
         $withtemplate = 0;
      }

      $canedit       =  $item->canadditem('PluginCertificatesCertificate');
      $rand          = mt_rand();
      $is_recursive  = $item->isRecursive();

      $query = "SELECT `glpi_plugin_certificates_certificates_items`.`id` AS assocID,
                       `glpi_entities`.`id` AS entity,
                       `glpi_plugin_certificates_certificates`.`name` AS assocName,
                       `glpi_plugin_certificates_certificates`.*
                FROM `glpi_plugin_certificates_certificates_items`
                LEFT JOIN `glpi_plugin_certificates_certificates`
                 ON (`glpi_plugin_certificates_certificates_items`.`plugin_certificates_certificates_id`=`glpi_plugin_certificates_certificates`.`id`)
                LEFT JOIN `glpi_entities` ON (`glpi_plugin_certificates_certificates`.`entities_id`=`glpi_entities`.`id`)
                WHERE `glpi_plugin_certificates_certificates_items`.`items_id` = '$ID'
                      AND `glpi_plugin_certificates_certificates_items`.`itemtype` = '".$item->getType()."' ";

      $query .= getEntitiesRestrictRequest(" AND","glpi_plugin_certificates_certificates",'','',true);

      $query .= " ORDER BY `assocName`";

      $result = $DB->query($query);
      $number = $DB->numrows($result);
      $i      = 0;

      $certificates      = array();
      $certificate       = new PluginCertificatesCertificate();
      $used      = array();
      if ($numrows = $DB->numrows($result)) {
         while ($data = $DB->fetch_assoc($result)) {
            $certificates[$data['assocID']] = $data;
            $used[$data['id']] = $data['id'];
         }
      }

      if ($canedit && $withtemplate < 2) {
         // Restrict entity for knowbase
         $entities = "";
         $entity   = $_SESSION["glpiactive_entity"];

         if ($item->isEntityAssign()) {
            /// Case of personal items : entity = -1 : create on active entity (Reminder case))
            if ($item->getEntityID() >=0 ) {
               $entity = $item->getEntityID();
            }

            if ($item->isRecursive()) {
               $entities = getSonsOf('glpi_entities',$entity);
            } else {
               $entities = $entity;
            }
         }
         $limit = getEntitiesRestrictRequest(" AND ","glpi_plugin_certificates_certificates",'',$entities,true);
         $q = "SELECT COUNT(*)
               FROM `glpi_plugin_certificates_certificates`
               WHERE `is_deleted` = '0'
               $limit";

         $result = $DB->query($q);
         $nb     = $DB->result($result,0,0);

         echo "<div class='firstbloc'>";       
         
         
         if (Session::haveRight("plugin_certificates", READ)
             && ($nb > count($used))) {
            echo "<form name='certificate_form$rand' id='certificate_form$rand' method='post'
                   action='".Toolbox::getItemTypeFormURL('PluginCertificatesCertificate')."'>";
            echo "<table class='tab_cadre_fixe'>";
            echo "<tr class='tab_bg_1'>";
            echo "<td colspan='4' class='center'>";
            echo "<input type='hidden' name='entities_id' value='$entity'>";
            echo "<input type='hidden' name='is_recursive' value='$is_recursive'>";
            echo "<input type='hidden' name='itemtype' value='".$item->getType()."'>";
            echo "<input type='hidden' name='items_id' value='$ID'>";
            if ($item->getType() == 'Ticket') {
               echo "<input type='hidden' name='tickets_id' value='$ID'>";
            }

            PluginCertificatesCertificate::dropdown(array('entity' => $entities ,
                                                            'used'   => $used));
                                     
            echo "</td><td class='center' width='20%'>";
            echo "<input type='submit' name='additem' value=\"".
                     _sx('button', 'Associate a certificate', 'certificates')."\" class='submit'>";
            echo "</td>";
            echo "</tr>";
            echo "</table>";
            Html::closeForm();
         }

         echo "</div>";
      }

      echo "<div class='spaced'>";
      if ($canedit && $number && ($withtemplate < 2)) {
         Html::openMassiveActionsForm('mass'.__CLASS__.$rand);
         $massiveactionparams = array('num_displayed'  => $number);
         Html::showMassiveActions($massiveactionparams);
      }
      echo "<table class='tab_cadre_fixe'>";

      echo "<tr>";
      if ($canedit && $number && ($withtemplate < 2)) {
         echo "<th width='10'>".Html::getCheckAllAsCheckbox('mass'.__CLASS__.$rand)."</th>";
      }
      echo "<th>".__('Name')."</th>";
      if (Session::isMultiEntitiesMode()) {
         echo "<th>".__('Entity')."</th>";
      }
      echo "<th>".__('Type')."</th>";
      echo "<th>".__('DNS name', 'certificates')."</th>";
      echo "<th>".__('DNS suffix', 'certificates')."</th>";
      echo "<th>".__('Creation date')."</th>";
      echo "<th>".__('Expiration date')."</th>";
      echo "<th>".__('Status')."</th>";
      echo "</tr>";
      $used = array();

      if ($number) {

         Session::initNavigateListItems('PluginCertificatesCertificate',
                           //TRANS : %1$s is the itemtype name,
                           //        %2$s is the name of the item (used for headings of a list)
                                        sprintf(__('%1$s = %2$s'),
                                                $item->getTypeName(1), $item->getName()));

         
         foreach  ($certificates as $data) {
            $certificateID        = $data["id"];
            $link         = NOT_AVAILABLE;

            if ($certificate->getFromDB($certificateID)) {
               $link         = $certificate->getLink();
            }

            Session::addToNavigateListItems('PluginCertificatesCertificate', $certificateID);
            
            $used[$certificateID] = $certificateID;
            $assocID      = $data["assocID"];

            echo "<tr class='tab_bg_1".($data["is_deleted"]?"_2":"")."'>";
            if ($canedit && ($withtemplate < 2)) {
               echo "<td width='10'>";
               Html::showMassiveActionCheckBox(__CLASS__, $data["assocID"]);
               echo "</td>";
            }
            echo "<td class='center'>$link</td>";
            if (Session::isMultiEntitiesMode()) {
               echo "<td class='center'>".Dropdown::getDropdownName("glpi_entities", $data['entities_id']).
                    "</td>";
            }
            echo "<td class='center'>";
            echo Dropdown::getDropdownName("glpi_plugin_certificates_certificatetypes",
                                          $data["plugin_certificates_certificatetypes_id"]);
            echo "</td>";
            echo "<td class='center'>".$data["dns_name"]."</td>";
            echo "<td class='center'>".$data["dns_suffix"]."</td>";
            echo "<td class='center'>".Html::convdate($data["date_query"])."</td>";
            if ($data["date_expiration"] <= date('Y-m-d') 
                  && !empty($data["date_expiration"])) {
               echo "<td class='center'>";
               echo "<div class='deleted'>".Html::convdate($data["date_expiration"])."</div>";
               echo "</td>";
            } else if (empty($data["date_expiration"])) {
               echo "<td class='center'>".__('Does not expire', 'certificates')."</td>";
            } else {
               echo "<td class='center'>".Html::convdate($data["date_expiration"])."</td>";
            }
            echo "<td class='center'>";
            echo Dropdown::getDropdownName("glpi_plugin_certificates_certificatestates",
                                                $data["plugin_certificates_certificatestates_id"]);
            echo "</td>";
            echo "</tr>";
            $i++;
         }
      }


      echo "</table>";
      if ($canedit && $number && ($withtemplate < 2)) {
         $massiveactionparams['ontop'] = false;
         Html::showMassiveActions($massiveactionparams);
         Html::closeForm();
      }
      echo "</div>";
   }
 static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids)
 {
     switch ($ma->getAction()) {
         case 'export':
             foreach ($ids as $key) {
                 if ($item->can($key, UPDATE)) {
                     $item->exportPackage($key);
                     $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_OK);
                 }
             }
             break;
         case 'transfert':
             $pfDeployPackage = new PluginFusioninventoryDeployPackage();
             foreach ($ids as $key) {
                 if ($pfDeployPackage->getFromDB($key)) {
                     $input = array();
                     $input['id'] = $key;
                     $input['entities_id'] = $ma->POST['entities_id'];
                     $pfDeployPackage->update($input);
                 }
             }
             break;
         case 'import':
             foreach ($ids as $key) {
                 $item->importPackage($key);
                 $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_OK);
             }
             break;
     }
     return;
 }
 /**
  * @since version 0.85
  *
  * @see CommonDBTM::processMassiveActionsForOneItemtype()
  **/
 static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids)
 {
     global $DB;
     $certif_item = new PluginCertificatesCertificate_Item();
     switch ($ma->getAction()) {
         case "plugin_certificates_add_item":
             $input = $ma->getInput();
             foreach ($ids as $id) {
                 $input = array('plugin_certificates_certificates_id' => $input['plugin_certificates_certificates_id'], 'items_id' => $id, 'itemtype' => $item->getType());
                 if ($certif_item->can(-1, UPDATE, $input)) {
                     if ($certif_item->add($input)) {
                         $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK);
                     } else {
                         $ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_KO);
                     }
                 } else {
                     $ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_KO);
                 }
             }
             return;
         case "transfer":
             $input = $ma->getInput();
             if ($item->getType() == 'PluginCertificatesCertificate') {
                 foreach ($ids as $key) {
                     $item->getFromDB($key);
                     $type = PluginCertificatesCertificateType::transfer($item->fields["plugin_certificates_certificatetypes_id"], $input['entities_id']);
                     if ($type > 0) {
                         $values["id"] = $key;
                         $values["plugin_certificates_certificatetypes_id"] = $type;
                         $item->update($values);
                     }
                     $state = PluginCertificatesCertificateState::transfer($this->fields["plugin_certificates_certificatestates_id"], $input['entities_id']);
                     if ($state > 0) {
                         $values["id"] = $key;
                         $values["plugin_certificates_certificatestates_id"] = $state;
                         $item->update($values);
                     }
                     unset($values);
                     $values["id"] = $key;
                     $values["entities_id"] = $input['entities_id'];
                     if ($item->update($values)) {
                         $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_OK);
                     } else {
                         $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO);
                     }
                 }
             }
             return;
         case 'install':
             $input = $ma->getInput();
             foreach ($ids as $key) {
                 if ($item->can($key, UPDATE)) {
                     $values = array('plugin_certificates_certificates_id' => $key, 'items_id' => $input["item_item"], 'itemtype' => $input['typeitem']);
                     if ($certif_item->add($values)) {
                         $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_OK);
                     } else {
                         $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO);
                     }
                 } else {
                     $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_NORIGHT);
                     $ma->addMessage($item->getErrorMessage(ERROR_RIGHT));
                 }
             }
             return;
         case 'uninstall':
             $input = $ma->getInput();
             foreach ($ids as $key) {
                 if ($val == 1) {
                     if ($certif_item->deleteItemByCertificatesAndItem($key, $input['item_item'], $input['typeitem'])) {
                         $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_OK);
                     } else {
                         $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO);
                     }
                 }
             }
             return;
     }
     parent::processMassiveActionsForOneItemtype($ma, $item, $ids);
 }
 /**
  * @since version 0.85
  *
  * @see CommonDBTM::processMassiveActionsForOneItemtype()
  **/
 static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids)
 {
     global $DB;
     switch ($ma->getAction()) {
         case 'transform_to':
             $input = $ma->getInput();
             if (isset($input["transform_to"]) && !empty($input["transform_to"])) {
                 $networkport = new NetworkPort();
                 foreach ($ids as $id) {
                     if ($networkport->canEdit($id) && $item->can($id, DELETE)) {
                         if (empty($networkport->fields['instantiation_type'])) {
                             if ($networkport->switchInstantiationType($input['transform_to']) !== false) {
                                 $instantiation = $networkport->getInstantiation();
                                 $input2 = $item->fields;
                                 $input2['networkports_id'] = $input2['id'];
                                 unset($input2['id']);
                                 if ($instantiation->add($input2)) {
                                     $item->delete(array('id' => $id));
                                     $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK);
                                 } else {
                                     $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO);
                                     $ma->addMessage($networkport->getErrorMessage(ERROR_ON_ACTION));
                                 }
                             } else {
                                 $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO);
                                 $ma->addMessage($networkport->getErrorMessage(ERROR_ON_ACTION));
                             }
                         } else {
                             $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO);
                             $ma->addMessage($networkport->getErrorMessage(ERROR_ON_ACTION));
                         }
                     } else {
                         $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_NORIGHT);
                         $ma->addMessage($networkport->getErrorMessage(ERROR_RIGHT));
                     }
                 }
             } else {
                 $ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_KO);
             }
             return;
     }
     parent::processMassiveActionsForOneItemtype($ma, $item, $ids);
 }
 function showForm(CommonDBTM $item, $options = array())
 {
     $ID = $item->getField('id');
     if ($item->isNewID($ID)) {
         return false;
     }
     if (!$item->can($item->fields['id'], READ)) {
         return false;
     }
     $rand = mt_rand();
     $a_data = getAllDatasFromTable('glpi_plugin_fusioninventory_ipranges_configsecurities', "`plugin_fusioninventory_ipranges_id`='" . $item->getID() . "'", false, '`rank`');
     $a_used = array();
     foreach ($a_data as $data) {
         $a_used[] = $data['plugin_fusioninventory_configsecurities_id'];
     }
     echo "<div class='firstbloc'>";
     echo "<form name='iprange_configsecurity_form{$rand}' id='iprange_configsecurity_form{$rand}' method='post'\n             action='" . Toolbox::getItemTypeFormURL('PluginFusioninventoryIPRange_ConfigSecurity') . "' >";
     echo "<table class='tab_cadre_fixe'>";
     echo "<tr class='tab_bg_2'>";
     echo "<th colspan='2'>" . __('Add a SNMP authentication') . "</th>";
     echo "</tr>";
     echo "<tr class='tab_bg_2'>";
     echo "<td>";
     Dropdown::show('PluginFusioninventoryConfigSecurity', array('used' => $a_used));
     echo "</td>";
     echo "<td>";
     echo Html::hidden('plugin_fusioninventory_ipranges_id', array('value' => $item->getID()));
     echo "<input type='submit' name='add' value=\"" . _sx('button', 'Associate') . "\" class='submit'>";
     echo "</td>";
     echo "</tr>";
     echo "</table>";
     Html::closeForm();
     echo "</div>";
     // Display list of auth associated with IP range
     $rand = mt_rand();
     echo "<div class='spaced'>";
     Html::openMassiveActionsForm('mass' . __CLASS__ . $rand);
     $massiveactionparams = array('container' => 'mass' . __CLASS__ . $rand);
     Html::showMassiveActions($massiveactionparams);
     echo "<table class='tab_cadre_fixe'>";
     echo "<tr class='tab_bg_2'>";
     echo "<th width='10'>" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand) . "</th>";
     echo "<th>";
     echo __('SNMP Authentication', 'fusioninventory');
     echo "</th>";
     echo "<th>";
     echo __('Version', 'fusioninventory');
     echo "</th>";
     echo "<th>";
     echo __('Rank');
     echo "</th>";
     echo "</tr>";
     $pfConfigSecurity = new PluginFusioninventoryConfigSecurity();
     foreach ($a_data as $data) {
         echo "<tr class='tab_bg_2'>";
         echo "<td>";
         Html::showMassiveActionCheckBox(__CLASS__, $data["id"]);
         echo "</td>";
         echo "<td>";
         $pfConfigSecurity->getFromDB($data['plugin_fusioninventory_configsecurities_id']);
         echo $pfConfigSecurity->getLink();
         echo "</td>";
         echo "<td>";
         echo $pfConfigSecurity->getSNMPVersion($pfConfigSecurity->fields['snmpversion']);
         echo "</td>";
         echo "<td>";
         echo $data['rank'];
         echo "</td>";
         echo "</tr>";
     }
     echo "</table>";
     $massiveactionparams['ontop'] = false;
     Html::showMassiveActions($massiveactionparams);
     echo "</div>";
 }
Exemplo n.º 25
0
 /**
  * @since version 0.85
  *
  * @see CommonDBTM::processMassiveActionsForOneItemtype()
  **/
 static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids)
 {
     global $DB;
     switch ($ma->getAction()) {
         case 'force_user_ldap_update':
             foreach ($ids as $id) {
                 if ($item->can($id, UPDATE)) {
                     if ($item->fields["authtype"] == Auth::LDAP || $item->fields["authtype"] == Auth::EXTERNAL) {
                         if (AuthLdap::ldapImportUserByServerId(array('method' => AuthLDAP::IDENTIFIER_LOGIN, 'value' => $item->fields["name"]), 1, $item->fields["auths_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_KO);
                         $ma->addMessage($item->getErrorMessage(ERROR_ON_ACTION));
                     }
                 } else {
                     $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_NORIGHT);
                     $ma->addMessage($item->getErrorMessage(ERROR_RIGHT));
                 }
             }
             return;
         case 'change_authtype':
             $input = $ma->getInput();
             if (!isset($input["authtype"]) || !isset($input["auths_id"])) {
                 $ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_KO);
                 $ma->addMessage($item->getErrorMessage(ERROR_ON_ACTION));
                 return;
             }
             if (Session::haveRight(self::$rightname, self::UPDATEAUTHENT)) {
                 if (User::changeAuthMethod($ids, $input["authtype"], $input["auths_id"])) {
                     $ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_OK);
                 } else {
                     $ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_KO);
                 }
             } else {
                 $ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_NORIGHT);
                 $ma->addMessage($item->getErrorMessage(ERROR_RIGHT));
             }
             return;
     }
     parent::processMassiveActionsForOneItemtype($ma, $item, $ids);
 }
Exemplo n.º 26
0
 /**
  * @since version 0.85
  *
  * @see CommonDBTM::processMassiveActionsForOneItemtype()
  **/
 static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids)
 {
     switch ($ma->getAction()) {
         case 'uninstall':
             foreach ($ids as $key) {
                 if ($item->can($key, UPDATE)) {
                     if ($item->uninstall($key)) {
                         $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_OK);
                     } else {
                         $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO);
                         $ma->addMessage($item->getErrorMessage(ERROR_ON_ACTION));
                     }
                 } else {
                     $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_NORIGHT);
                     $ma->addMessage($item->getErrorMessage(ERROR_RIGHT));
                 }
             }
             return;
         case 'backtostock':
             foreach ($ids as $id) {
                 if ($item->can($id, UPDATE)) {
                     if ($item->backToStock(array("id" => $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));
                 }
             }
             return;
         case 'updatepages':
             $input = $ma->getInput();
             if (isset($input['pages'])) {
                 foreach ($ids as $key) {
                     if ($item->can($key, UPDATE)) {
                         if ($item->update(array('id' => $key, 'pages' => $input['pages']))) {
                             $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_OK);
                         } else {
                             $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO);
                             $ma->addMessage($item->getErrorMessage(ERROR_ON_ACTION));
                         }
                     } else {
                         $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_NORIGHT);
                         $ma->addMessage($item->getErrorMessage(ERROR_RIGHT));
                     }
                 }
             } else {
                 $ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_KO);
             }
             return;
     }
     parent::processMassiveActionsForOneItemtype($ma, $item, $ids);
 }
 /**
  * @since version 0.85
  *
  * @see CommonDBTM::processMassiveActionsForOneItemtype()
  **/
 static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids)
 {
     global $DB;
     switch ($ma->getAction()) {
         case 'add_actor':
             $input = $ma->getInput();
             foreach ($ids as $id) {
                 $input2 = array('id' => $id);
                 if (isset($input['_itil_requester'])) {
                     $input2['_itil_requester'] = $input['_itil_requester'];
                 }
                 if (isset($input['_itil_observer'])) {
                     $input2['_itil_observer'] = $input['_itil_observer'];
                 }
                 if (isset($input['_itil_assign'])) {
                     $input2['_itil_assign'] = $input['_itil_assign'];
                 }
                 if ($item->can($id, UPDATE)) {
                     if ($item->update($input2)) {
                         $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));
                 }
             }
             return;
         case 'update_notif':
             $input = $ma->getInput();
             foreach ($ids as $id) {
                 if ($item->can($id, UPDATE)) {
                     $linkclass = new $item->userlinkclass();
                     foreach ($linkclass->getActors($id) as $type => $users) {
                         foreach ($users as $data) {
                             $data['use_notification'] = $input['use_notification'];
                             $linkclass->update($data);
                         }
                     }
                     $linkclass = new $this->supplierlinkclass();
                     foreach ($linkclass->getActors($id) as $type => $users) {
                         foreach ($users as $data) {
                             $data['use_notification'] = $input['use_notification'];
                             $linkclass->update($data);
                         }
                     }
                     $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK);
                 } else {
                     $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_NORIGHT);
                     $ma->addMessage($item->getErrorMessage(ERROR_RIGHT));
                 }
             }
             return;
         case 'add_task':
             if (!($task = getItemForItemtype($item->getType() . 'Task'))) {
                 $ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_KO);
                 break;
             }
             $field = $item->getForeignKeyField();
             $input = $ma->getInput();
             foreach ($ids as $id) {
                 if ($item->getFromDB($id)) {
                     $input2 = array($field => $id, 'taskcategories_id' => $input['taskcategories_id'], 'content' => $input['content']);
                     if ($task->can(-1, CREATE, $input2)) {
                         if ($task->add($input2)) {
                             $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(), $id, MassiveAction::ACTION_KO);
                     $ma->addMessage($item->getErrorMessage(ERROR_NOT_FOUND));
                 }
             }
             return;
     }
     parent::processMassiveActionsForOneItemtype($ma, $item, $ids);
 }
Exemplo n.º 28
0
 /**
  * Show resource associated to an item
  *
  * @since version 0.84
  *
  * @param $item            CommonDBTM object for which associated resource must be displayed
  * @param $withtemplate    (default '')
  **/
 static function showForItem(CommonDBTM $item, $withtemplate = '')
 {
     global $DB, $CFG_GLPI;
     $ID = $item->getField('id');
     if ($item->isNewID($ID)) {
         return false;
     }
     if (!plugin_resources_haveRight('resources', 'r')) {
         return false;
     }
     if (!$item->can($item->fields['id'], 'r')) {
         return false;
     }
     if (empty($withtemplate)) {
         $withtemplate = 0;
     }
     $canedit = $item->canadditem('PluginResourcesResource');
     $rand = mt_rand();
     $is_recursive = $item->isRecursive();
     $query = "SELECT `glpi_plugin_resources_resources_items`.`id` AS assocID,\n                       `glpi_entities`.`id` AS entity,\n                       `glpi_plugin_resources_resources`.`name` AS assocName,\n                       `glpi_plugin_resources_resources`.*\n                FROM `glpi_plugin_resources_resources_items`\n                LEFT JOIN `glpi_plugin_resources_resources`\n                 ON (`glpi_plugin_resources_resources_items`.`plugin_resources_resources_id`=`glpi_plugin_resources_resources`.`id`)\n                LEFT JOIN `glpi_entities` ON (`glpi_plugin_resources_resources`.`entities_id`=`glpi_entities`.`id`)\n                WHERE `glpi_plugin_resources_resources_items`.`items_id` = '{$ID}'\n                      AND `glpi_plugin_resources_resources_items`.`itemtype` = '" . $item->getType() . "' ";
     $query .= getEntitiesRestrictRequest(" AND", "glpi_plugin_resources_resources", '', '', true);
     $query .= " ORDER BY `assocName`";
     $result = $DB->query($query);
     $number = $DB->numrows($result);
     $i = 0;
     $resources = array();
     $used = array();
     if ($numrows = $DB->numrows($result)) {
         while ($data = $DB->fetch_assoc($result)) {
             $resources[$data['assocID']] = $data;
             $used[$data['id']] = $data['id'];
         }
     }
     $resource = new PluginResourcesResource();
     $more = true;
     if ($item->getType() == "User" && $number != 0) {
         $more = false;
     }
     if ($canedit && $withtemplate < 2 && $more) {
         // Restrict entity for knowbase
         $entities = "";
         $entity = $_SESSION["glpiactive_entity"];
         if ($item->isEntityAssign()) {
             /// Case of personal items : entity = -1 : create on active entity (Reminder case))
             if ($item->getEntityID() >= 0) {
                 $entity = $item->getEntityID();
             }
             if ($item->isRecursive()) {
                 $entities = getSonsOf('glpi_entities', $entity);
             } else {
                 $entities = $entity;
             }
         }
         $limit = getEntitiesRestrictRequest(" AND ", "glpi_plugin_resources_resources", '', $entities, true);
         $q = "SELECT COUNT(*)\n               FROM `glpi_plugin_resources_resources`\n               WHERE `is_deleted` = '0'\n               AND `is_template` = '0' ";
         if ($item->getType() != 'User') {
             $q .= " {$limit}";
         }
         $result = $DB->query($q);
         $nb = $DB->result($result, 0, 0);
         echo "<div class='firstbloc'>";
         if (plugin_resources_haveRight('resources', 'r') && $nb > count($used)) {
             echo "<form name='resource_form{$rand}' id='resource_form{$rand}' method='post'\n                   action='" . Toolbox::getItemTypeFormURL('PluginResourcesResource') . "'>";
             echo "<table class='tab_cadre_fixe'>";
             echo "<tr class='tab_bg_1'>";
             echo "<td colspan='4' class='center'>";
             echo "<input type='hidden' name='itemtype' value='" . $item->getType() . "'>";
             echo "<input type='hidden' name='items_id' value='{$ID}'>";
             if ($item->getType() == 'Ticket') {
                 echo "<input type='hidden' name='tickets_id' value='{$ID}'>";
             }
             PluginResourcesResource::dropdown(array('entity' => $entities, 'used' => $used));
             echo "</td><td class='center' width='20%'>";
             echo "<input type='submit' name='additem' value=\"" . __s('Associate a resource', 'resources') . "\" class='submit'>";
             echo "</td>";
             echo "</tr>";
             echo "</table>";
             Html::closeForm();
         }
         echo "</div>";
     }
     echo "<div class='spaced'>";
     if ($canedit && $number && $withtemplate < 2) {
         Html::openMassiveActionsForm('mass' . __CLASS__ . $rand);
         $massiveactionparams = array('num_displayed' => $number);
         Html::showMassiveActions(__CLASS__, $massiveactionparams);
     }
     echo "<table class='tab_cadre_fixe'>";
     if (Session::isMultiEntitiesMode()) {
         $colsup = 1;
     } else {
         $colsup = 0;
     }
     echo "<tr>";
     if ($canedit && $number && $withtemplate < 2) {
         echo "<th width='10'>" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand) . "</th>";
     }
     echo "<th>" . __('Name') . "</th>";
     echo "<th>" . __('First name') . "</th>";
     if (Session::isMultiEntitiesMode()) {
         echo "<th>" . __('Entity') . "</th>";
     }
     echo "<th>" . __('Location') . "</th>";
     echo "<th>" . PluginResourcesContractType::getTypeName(1) . "</th>";
     echo "<th>" . PluginResourcesDepartment::getTypeName(1) . "</th>";
     echo "<th>" . __('Arrival date', 'resources') . "</th>";
     echo "<th>" . __('Departure date', 'resources') . "</th>";
     echo "</tr>";
     $used = array();
     $resourceID = 0;
     if ($number) {
         Session::initNavigateListItems('PluginResourcesResource', sprintf(__('%1$s = %2$s'), $item->getTypeName(1), $item->getName()));
         foreach ($resources as $data) {
             $resourceID = $data["id"];
             $link = NOT_AVAILABLE;
             if ($resource->getFromDB($resourceID)) {
                 $link = $resource->getLink();
             }
             Session::addToNavigateListItems('PluginResourcesResource', $resourceID);
             $used[$resourceID] = $resourceID;
             $assocID = $data["assocID"];
             echo "<tr class='tab_bg_1" . ($data["is_deleted"] ? "_2" : "") . "'>";
             if ($canedit && $withtemplate < 2) {
                 echo "<td width='10'>";
                 Html::showMassiveActionCheckBox(__CLASS__, $data["assocID"]);
                 echo "</td>";
             }
             echo "<td class='center'>{$link}</td>";
             echo "<td class='center'>" . $data['firstname'] . "</td>";
             if (Session::isMultiEntitiesMode()) {
                 echo "<td class='center'>" . Dropdown::getDropdownName("glpi_entities", $data['entities_id']) . "</td>";
             }
             echo "<td class='center'>";
             echo Dropdown::getDropdownName("glpi_locations", $data["locations_id"]);
             echo "</td>";
             echo "<td class='center'>";
             echo Dropdown::getDropdownName("glpi_plugin_resources_contracttypes", $data["plugin_resources_contracttypes_id"]);
             echo "</td>";
             echo "<td class='center'>";
             echo Dropdown::getDropdownName("glpi_plugin_resources_departments", $data["plugin_resources_departments_id"]);
             echo "</td>";
             echo "<td class='center'>" . Html::convDate($data["date_begin"]) . "</td>";
             if ($data["date_end"] <= date('Y-m-d') && !empty($data["date_end"])) {
                 echo "<td class='center'>";
                 echo "<span class='plugin_resources_date_color'>";
                 echo Html::convDate($data["date_end"]);
                 echo "</span>";
                 echo "</td>";
             } else {
                 if (empty($data["date_end"])) {
                     echo "<td class='center'>" . __('Not defined', 'resources') . "</td>";
                 } else {
                     echo "<td class='center'>" . Html::convDate($data["date_end"]) . "</td>";
                 }
             }
             echo "</tr>";
             $i++;
         }
     }
     echo "</table>";
     if ($canedit && $number && $withtemplate < 2) {
         $massiveactionparams['ontop'] = false;
         Html::showMassiveActions(__CLASS__, $massiveactionparams);
         Html::closeForm();
     }
     echo "</div>";
     if ($item->getType() == "User") {
         $PluginResourcesEmployee = new PluginResourcesEmployee();
         $PluginResourcesEmployee->showForm($resourceID, $ID, 0);
     }
 }
Exemplo n.º 29
0
 /**
  * Show ports for an item
  *
  * @param $item                     CommonDBTM object
  * @param $withtemplate   integer   withtemplate param (default '')
  **/
 static function showForItem(CommonDBTM $item, $withtemplate = '')
 {
     global $DB, $CFG_GLPI;
     $rand = mt_rand();
     $itemtype = $item->getType();
     $items_id = $item->getField('id');
     if (!Session::haveRight('networking', 'r') || !$item->can($items_id, 'r')) {
         return false;
     }
     $netport = new self();
     $netport->item = $item;
     if ($itemtype == 'NetworkPort') {
         $canedit = false;
     } else {
         $canedit = $item->can($items_id, 'w');
     }
     $showmassiveactions = false;
     if ($withtemplate != 2) {
         $showmassiveactions = $canedit;
     }
     // Show Add Form
     if ($canedit && (empty($withtemplate) || $withtemplate != 2)) {
         echo "\n<form method='get' action='" . $netport->getFormURL() . "'>\n";
         echo "<input type='hidden' name='items_id' value='" . $item->getID() . "'>\n";
         echo "<input type='hidden' name='itemtype' value='" . $item->getType() . "'>\n";
         echo "<div class='firstbloc'><table class='tab_cadre_fixe'>\n";
         echo "<tr class='tab_bg_2'><td class='center'>\n";
         _e('Network port type to be added');
         echo "&nbsp;";
         $instantiations = array();
         foreach (self::getNetworkPortInstantiations() as $inst_type) {
             if (call_user_func(array($inst_type, 'canCreate'))) {
                 $instantiations[$inst_type] = call_user_func(array($inst_type, 'getTypeName'));
             }
         }
         Dropdown::showFromArray('instantiation_type', $instantiations, array('value' => 'NetworkPortEthernet'));
         echo "</td>\n";
         echo "<td class='tab_bg_2 center' width='50%'>";
         _e('Add several ports');
         echo "&nbsp;<input type='checkbox' name='several' value='1'></td>\n";
         echo "<td>\n";
         echo "<input type='submit' name='create' value=\"" . _sx('button', 'Add') . "\" class='submit'>\n";
         echo "</td></tr></table></div>\n";
         Html::closeForm();
     }
     if ($showmassiveactions) {
         $checkbox_column = true;
         Html::openMassiveActionsForm('mass' . __CLASS__ . $rand);
     } else {
         $checkbox_column = false;
     }
     $is_active_network_port = false;
     Session::initNavigateListItems('NetworkPort', sprintf(__('%1$s = %2$s'), $item->getTypeName(1), $item->getName()));
     if ($itemtype == 'NetworkPort') {
         $porttypes = array('NetworkPortAlias', 'NetworkPortAggregate');
     } else {
         $porttypes = self::getNetworkPortInstantiations();
         // Manage NetworkportMigration
         $porttypes[] = '';
     }
     $display_options = self::getDisplayOptions($itemtype);
     $table = new HTMLTableMain();
     $number_port = self::countForItem($item);
     $table_options = array('canedit' => $canedit, 'display_options' => &$display_options);
     // Make table name and add the correct show/hide parameters
     $table_name = sprintf(__('%1$s: %2$d'), self::getTypeName($number_port), $number_port);
     // Add the link to the popup to display the options ...
     $table_namelink = self::getDisplayOptionsLink($itemtype);
     $table_name = sprintf(__('%1$s - %2$s'), $table_name, $table_namelink);
     $table->setTitle($table_name);
     $c_main = $table->addHeader('main', self::getTypeName(2));
     if ($display_options['dynamic_import'] && $item->isDynamic()) {
         $table_options['display_isDynamic'] = true;
     } else {
         $table_options['display_isDynamic'] = false;
     }
     if ($display_options['characteristics']) {
         $c_instant = $table->addHeader('Instantiation', __('Characteristics'));
         $c_instant->setHTMLClass('center');
     }
     if ($display_options['internet']) {
         $options = array('names' => 'NetworkName', 'aliases' => 'NetworkAlias', 'ipaddresses' => 'IPAddress', 'ipnetworks' => 'IPNetwork');
         $table_options['dont_display'] = array();
         foreach ($options as $option => $itemtype_for_option) {
             if (!$display_options[$option]) {
                 $table_options['dont_display'][$itemtype_for_option] = true;
             }
         }
         $c_network = $table->addHeader('Internet', _n(__('Internet information'), __('Internet information'), 2));
         $c_network->setHTMLClass('center');
     } else {
         $c_network = NULL;
     }
     foreach ($porttypes as $portType) {
         if (empty($portType)) {
             $group_name = 'Migration';
             $group_title = __('Network ports waiting for manual migration');
         } else {
             $group_name = $portType;
             $group_title = $portType::getTypeName(2);
         }
         $t_group = $table->createGroup($group_name, $group_title);
         if ($withtemplate != 2 && $canedit) {
             $c_checkbox = $t_group->addHeader('checkbox', Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand, '__RAND__'), $c_main);
         } else {
             $c_checkbox = NULL;
         }
         $c_number = $t_group->addHeader('NetworkPort', "#", $c_main);
         $c_name = $t_group->addHeader("Name", __('Name'), $c_main);
         $c_name->setItemType('NetworkPort');
         $c_name->setHTMLClass('center');
         if ($table_options['display_isDynamic']) {
             $c_dynamic = $t_group->addHeader("Dynamic", __('Automatic inventory'), $c_main);
             $c_dynamic->setHTMLClass('center');
         }
         if ($display_options['characteristics']) {
             if (empty($portType)) {
                 NetworkPortMigration::getMigrationInstantiationHTMLTableHeaders($t_group, $c_instant, $c_network, NULL, $table_options);
             } else {
                 $instantiation = new $portType();
                 $instantiation->getInstantiationHTMLTableHeaders($t_group, $c_instant, $c_network, NULL, $table_options);
                 unset($instantiation);
             }
         }
         if ($display_options['internet'] && !$display_options['characteristics']) {
             NetworkName::getHTMLTableHeader(__CLASS__, $t_group, $c_network, NULL, $table_options);
         }
         if ($itemtype == 'NetworkPort') {
             switch ($portType) {
                 case 'NetworkPortAlias':
                     $search_table = 'glpi_networkportaliases';
                     $search_request = "`networkports_id_alias`='{$items_id}'";
                     break;
                 case 'NetworkPortAggregate':
                     $search_table = 'glpi_networkportaggregates';
                     $search_request = "`networkports_id_list` like '%\"{$items_id}\"%'";
                     break;
             }
             $query = "SELECT `networkports_id` AS id\n                      FROM  `{$search_table}`\n                      WHERE {$search_request}";
         } else {
             $query = "SELECT `id`\n                      FROM `glpi_networkports`\n                      WHERE `items_id` = '{$items_id}'\n                            AND `itemtype` = '{$itemtype}'\n                            AND `instantiation_type` = '{$portType}'\n                            AND `is_deleted` = '0'\n                      ORDER BY `name`,\n                               `logical_number`";
         }
         if ($result = $DB->query($query)) {
             echo "<div class='spaced'>";
             $number_port = $DB->numrows($result);
             if ($number_port != 0) {
                 $is_active_network_port = true;
                 $save_canedit = $canedit;
                 if (!empty($portType)) {
                     $name = sprintf(__('%1$s (%2$s)'), self::getTypeName($number_port), call_user_func(array($portType, 'getTypeName')));
                     $name = sprintf(__('%1$s: %2$s'), $name, $number_port);
                 } else {
                     $name = __('Network ports waiting for manual migration');
                     $canedit = false;
                 }
                 while ($devid = $DB->fetch_row($result)) {
                     $t_row = $t_group->createRow();
                     $netport->getFromDB(current($devid));
                     // No massive action for migration ports
                     if ($withtemplate != 2 && $canedit && !empty($portType)) {
                         $ce_checkbox = $t_row->addCell($c_checkbox, "<input type='checkbox' name='item[" . $netport->fields["id"] . "]' value='1'>");
                     } else {
                         $ce_checkbox = NULL;
                     }
                     $content = "<span class='b'>";
                     // Display link based on default rights
                     if ($save_canedit && $withtemplate != 2) {
                         if (!empty($portType)) {
                             $content .= "<a href=\"" . $CFG_GLPI["root_doc"] . "/front/networkport.form.php?id=" . $netport->fields["id"] . "\">";
                         } else {
                             $content .= "<a href=\"" . $CFG_GLPI["root_doc"] . "/front/networkportmigration.form.php?id=" . $netport->fields["id"] . "\">";
                         }
                     }
                     $content .= $netport->fields["logical_number"];
                     if ($canedit && $withtemplate != 2) {
                         $content .= "</a>";
                     }
                     $content .= "</span>";
                     $content .= Html::showToolTip($netport->fields['comment'], array('display' => false));
                     $t_row->addCell($c_number, $content);
                     $value = $netport->fields["name"];
                     $t_row->addCell($c_name, $value, NULL, $netport);
                     if ($table_options['display_isDynamic']) {
                         $t_row->addCell($c_dynamic, Dropdown::getYesNo($netport->fields['is_dynamic']));
                     }
                     $instant_cell = NULL;
                     if ($display_options['characteristics']) {
                         $instantiation = $netport->getInstantiation();
                         if ($instantiation !== false) {
                             $instantiation->getInstantiationHTMLTable($netport, $t_row, NULL, $table_options);
                             unset($instantiation);
                         }
                     } else {
                         if ($display_options['internet']) {
                             NetworkName::getHTMLTableCellsForItem($t_row, $netport, NULL, $table_options);
                         }
                     }
                 }
                 $canedit = $save_canedit;
             }
             echo "</div>";
         }
     }
     if ($is_active_network_port && $showmassiveactions) {
         $massiveactionparams = array('num_displayed' => $number_port, 'check_itemtype' => $itemtype, 'check_items_id' => $items_id);
         Html::showMassiveActions('NetworkPort', $massiveactionparams);
     }
     $table->display(array('display_thead' => false, 'display_tfoot' => false));
     unset($table);
     if (!$is_active_network_port) {
         echo "<table class='tab_cadre_fixe'><tr><th>" . __('No network port found') . "</th></tr>";
         echo "</table>";
     }
     if ($showmassiveactions) {
         $massiveactionparams['ontop'] = false;
         Html::showMassiveActions('NetworkPort', $massiveactionparams);
         Html::closeForm();
     }
 }
Exemplo n.º 30
0
 /**
  * @since version 0.85
  *
  * @see CommonDBTM::processMassiveActionsForOneItemtype()
  **/
 static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids)
 {
     switch ($ma->getAction()) {
         case 'merge':
             $input = $ma->getInput();
             if (isset($input['item_items_id'])) {
                 $items = array();
                 foreach ($ids as $id) {
                     $items[$id] = 1;
                 }
                 if ($item->can($input['item_items_id'], UPDATE)) {
                     if ($item->merge($items)) {
                         $ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_OK);
                     } else {
                         $ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_KO);
                         $ma->addMessage($item->getErrorMessage(ERROR_ON_ACTION));
                     }
                 } else {
                     $ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_NORIGHT);
                     $ma->addMessage($item->getErrorMessage(ERROR_RIGHT));
                 }
             } else {
                 $ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_KO);
             }
             return;
         case 'compute_software_category':
             $softcatrule = new RuleSoftwareCategoryCollection();
             foreach ($ids as $id) {
                 $params = array();
                 //Get software name and manufacturer
                 if ($item->can($id, UPDATE)) {
                     $params["name"] = $item->fields["name"];
                     $params["manufacturers_id"] = $item->fields["manufacturers_id"];
                     $params["comment"] = $item->fields["comment"];
                     $output = array();
                     $output = $softcatrule->processAllRules(null, $output, $params);
                     //Process rules
                     if (isset($output['softwarecategories_id']) && $item->update(array('id' => $id, 'softwarecategories_id' => $output['softwarecategories_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(), $ids, MassiveAction::ACTION_NORIGHT);
                     $ma->addMessage($item->getErrorMessage(ERROR_RIGHT));
                 }
             }
             return;
         case 'replay_dictionnary':
             $softdictionnayrule = new RuleDictionnarySoftwareCollection();
             $allowed_ids = array();
             foreach ($ids as $id) {
                 if ($item->can($id, UPDATE)) {
                     $allowed_ids[] = $id;
                 } else {
                     $ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_NORIGHT);
                     $ma->addMessage($item->getErrorMessage(ERROR_RIGHT));
                 }
             }
             if ($softdictionnayrule->replayRulesOnExistingDB(0, 0, $allowed_ids) > 0) {
                 $ma->itemDone($item->getType(), $allowed_ids, MassiveAction::ACTION_OK);
             } else {
                 $ma->itemDone($item->getType(), $allowed_ids, MassiveAction::ACTION_KO);
             }
             return;
     }
     parent::processMassiveActionsForOneItemtype($ma, $item, $ids);
 }