/**
  * @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);
 }
Ejemplo n.º 2
0
 /**
  * @param $port   NetworkPort object
  **/
 static function showForNetworkPort(NetworkPort $port)
 {
     global $DB, $CFG_GLPI;
     $ID = $port->getID();
     if (!$port->can($ID, READ)) {
         return false;
     }
     $canedit = $port->canEdit($ID);
     $rand = mt_rand();
     $query = "SELECT `glpi_networkports_vlans`.id as assocID,\n                       `glpi_networkports_vlans`.tagged ,\n                       `glpi_vlans`.*\n                FROM `glpi_networkports_vlans`\n                LEFT JOIN `glpi_vlans`\n                        ON (`glpi_networkports_vlans`.`vlans_id` = `glpi_vlans`.`id`)\n                WHERE `networkports_id` = '{$ID}'";
     $result = $DB->query($query);
     $vlans = array();
     $used = array();
     if ($number = $DB->numrows($result)) {
         while ($line = $DB->fetch_assoc($result)) {
             $used[$line["id"]] = $line["id"];
             $vlans[$line["assocID"]] = $line;
         }
     }
     if ($canedit) {
         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'>" . __('Associate a VLAN') . "</th></tr>";
         echo "<tr class='tab_bg_1'><td class='right'>";
         echo "<input type='hidden' name='networkports_id' value='{$ID}'>";
         Vlan::dropdown(array('used' => $used));
         echo "</td>";
         echo "<td class='right'>" . __('Tagged') . "</td>";
         echo "<td class='left'><input type='checkbox' name='tagged' value='1'></td>";
         echo "<td><input type='submit' name='add' value='" . _sx('button', 'Associate') . "' class='submit'>";
         echo "</td></tr>\n";
         echo "</table>\n";
         Html::closeForm();
         echo "</div>\n";
     }
     echo "<div class='spaced'>";
     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) {
         $header_top .= "<th width='10'>";
         $header_top .= Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand) . "</th>";
         $header_bottom .= "<th width='10'>";
         $header_bottom .= Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand) . "</th>";
     }
     $header_end .= "<th>" . __('Name') . "</th>";
     $header_end .= "<th>" . __('Entity') . "</th>";
     $header_end .= "<th>" . __('Tagged') . "</th>";
     $header_end .= "<th>" . __('ID TAG') . "</th>";
     $header_end .= "</tr>";
     echo $header_begin . $header_top . $header_end;
     $used = array();
     foreach ($vlans as $data) {
         echo "<tr class='tab_bg_1'>";
         if ($canedit) {
             echo "<td>";
             Html::showMassiveActionCheckBox(__CLASS__, $data["assocID"]);
             echo "</td>";
         }
         $name = $data["name"];
         if ($_SESSION["glpiis_ids_visible"] || empty($data["name"])) {
             $name = sprintf(__('%1$s (%2$s)'), $name, $data["id"]);
         }
         echo "<td class='center b'>\n               <a href='" . $CFG_GLPI["root_doc"] . "/front/vlan.form.php?id=" . $data["id"] . "'>" . $name . "</a>";
         echo "</td>";
         echo "<td class='center'>" . Dropdown::getDropdownName("glpi_entities", $data["entities_id"]);
         echo "</td><td class='center'>" . Dropdown::getYesNo($data["tagged"]) . "</td>";
         echo "<td class='numeric'>" . $data["tag"] . "</td>";
         echo "</tr>";
     }
     if ($number) {
         echo $header_begin . $header_top . $header_end;
     }
     echo "</table>";
     if ($canedit && $number) {
         $massiveactionparams['ontop'] = false;
         Html::showMassiveActions($massiveactionparams);
         Html::closeForm();
     }
     echo "</div>";
 }