Exemple #1
0
include '../inc/includes.php';
Session::checkRight("computer", READ);
if (!isset($_GET["id"])) {
    $_GET["id"] = "";
}
if (!isset($_GET["withtemplate"])) {
    $_GET["withtemplate"] = "";
}
$computer = new Computer();
//Add a new computer
if (isset($_POST["add"])) {
    $computer->check(-1, CREATE, $_POST);
    if ($newID = $computer->add($_POST)) {
        Event::log($newID, "computers", 4, "inventory", sprintf(__('%1$s adds the item %2$s'), $_SESSION["glpiname"], $_POST["name"]));
        if ($_SESSION['glpibackcreated']) {
            Html::redirect($computer->getFormURL() . "?id=" . $newID);
        }
    }
    Html::back();
    // delete a computer
} else {
    if (isset($_POST["delete"])) {
        $computer->check($_POST['id'], DELETE);
        $ok = $computer->delete($_POST);
        if ($ok) {
            Event::log($_POST["id"], "computers", 4, "inventory", sprintf(__('%s deletes an item'), $_SESSION["glpiname"]));
        }
        $computer->redirectToList();
    } else {
        if (isset($_POST["restore"])) {
            $computer->check($_POST['id'], DELETE);
 /**
  * Prints a direct connection to a computer
  *
  * @param $item the Monitor/Phone/Peripheral/Printer
  *
  * @return nothing (print out a table)
  */
 static function showForItem(CommonDBTM $item)
 {
     // Prints a direct connection to a computer
     global $DB, $LANG;
     $comp = new Computer();
     $target = $comp->getFormURL();
     $ID = $item->getField('id');
     if (!$item->can($ID, "r")) {
         return false;
     }
     $canedit = $item->can($ID, "w");
     // Is global connection ?
     $global = $item->getField('is_global');
     $used = array();
     $compids = array();
     $crit = array('FIELDS' => array('id', 'computers_id'), 'itemtype' => $item->getType(), 'items_id' => $ID);
     foreach ($DB->request('glpi_computers_items', $crit) as $data) {
         $compids[$data['id']] = $data['computers_id'];
     }
     echo "<div class='spaced'><table width='50%' class='tab_cadre_fixe'>";
     echo "<tr><th colspan='2'>";
     if (count($compids) == 0) {
         echo $LANG['connect'][4];
     } else {
         if (count($compids) == 1) {
             echo $LANG['connect'][3] . "&nbsp;:&nbsp;" . count($compids);
         } else {
             echo $LANG['connect'][2] . "&nbsp;:&nbsp;" . count($compids);
         }
     }
     echo "</th></tr>";
     if (count($compids) > 0) {
         foreach ($compids as $key => $compid) {
             $comp->getFromDB($compid);
             echo "<tr><td class='b tab_bg_1" . ($comp->getField('is_deleted') ? "_2" : "") . "'>";
             echo $LANG['help'][25] . "&nbsp;:&nbsp;" . $comp->getLink() . "</td>";
             echo "<td class='tab_bg_2" . ($comp->getField('is_deleted') ? "_2" : "") . " center b'>";
             if ($canedit) {
                 echo "<a href=\"{$target}?disconnect=1&amp;computers_id={$compid}&amp;id={$key}\">" . $LANG['buttons'][10] . "</a>";
             } else {
                 echo "&nbsp;";
             }
             $used[] = $compid;
         }
     } else {
         echo "<tr><td class='tab_bg_1 b'>" . $LANG['help'][25] . "&nbsp;:&nbsp;";
         echo "<i>" . $LANG['connect'][1] . "</i></td>";
         echo "<td class='tab_bg_2' class='center'>";
         if ($canedit) {
             echo "<form method='post' action=\"{$target}\">";
             echo "<input type='hidden' name='items_id' value='{$ID}'>";
             echo "<input type='hidden' name='itemtype' value='" . $item->getType() . "'>";
             if ($item->isRecursive()) {
                 self::dropdownConnect('Computer', $item->getType(), "computers_id", getSonsOf("glpi_entities", $item->getEntityID()), 0, $used);
             } else {
                 self::dropdownConnect('Computer', $item->getType(), "computers_id", $item->getEntityID(), 0, $used);
             }
             echo "<input type='submit' name='connect' value=\"" . $LANG['buttons'][9] . "\"\n                   class='submit'>";
             echo "</form>";
         } else {
             echo "&nbsp;";
         }
     }
     if ($global && count($compids) > 0) {
         echo "</td></tr>";
         echo "<tr><td class='tab_bg_1'>&nbsp;</td>";
         echo "<td class='tab_bg_2' class='center'>";
         if ($canedit) {
             echo "<form method='post' action=\"{$target}\">";
             echo "<input type='hidden' name='items_id' value='{$ID}'>";
             echo "<input type='hidden' name='itemtype' value='" . $item->getType() . "'>";
             if ($item->isRecursive()) {
                 self::dropdownConnect('Computer', $item->getType(), "computers_id", getSonsOf("glpi_entities", $item->getEntityID()), 0, $used);
             } else {
                 self::dropdownConnect('Computer', $item->getType(), "computers_id", $item->getEntityID(), 0, $used);
             }
             echo "<input type='submit' name='connect' value=\"" . $LANG['buttons'][9] . "\"\n                   class='submit'>";
             echo "</form>";
         } else {
             echo "&nbsp;";
         }
     }
     echo "</td></tr>";
     echo "</table></div>";
 }