Exemplo n.º 1
0
This file is part of GLPI.

GLPI is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

GLPI is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with GLPI. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/
/** @file
* @brief
* @since version 0.84
*/
include '../inc/includes.php';
Session::checkCentralAccess();
$contract_item = new Contract_Item();
if (isset($_POST["add"])) {
    $contract_item->check(-1, CREATE, $_POST);
    if ($contract_item->add($_POST)) {
        Event::log($_POST["contracts_id"], "contracts", 4, "financial", sprintf(__('%s adds a link with an item'), $_SESSION["glpiname"]));
    }
    Html::back();
}
Html::displayErrorAndDie("lost");
Exemplo n.º 2
0
/** Generate bigdump : add contracts to an item
 *
 * @param $type   item type
 * @param $ID     item ID
**/
function addContracts($type, $ID) {
   global $CONTRACT_PER_ITEM, $DB, $FIRST, $LAST;

   $nb  = mt_rand(0, $CONTRACT_PER_ITEM);
   $con = array();

   for ($i=0 ; $i<$nb ; $i++) {
      $con[] = mt_rand($FIRST["contract"], $LAST["contract"]);
   }
   $con = array_unique($con);
   $ci  = new Contract_Item();
   foreach ($con as $val) {
      $ci->add(array('contracts_id' => $val,
                     'itemtype'     => $type,
                     'items_id'     => $ID));
   }
}
Exemplo n.º 3
0
     if ($_POST["itemtype"] == 'Supplier') {
         $contactsupplier = new Contact_Supplier();
         foreach ($_POST["item"] as $key => $val) {
             $input = array('suppliers_id' => $key, 'contacts_id' => $_POST['conID']);
             if ($contactsupplier->can(-1, 'w', $input)) {
                 $contactsupplier->add($input);
             }
         }
     }
     break;
 case "add_contract":
     $contractitem = new Contract_Item();
     foreach ($_POST["item"] as $key => $val) {
         $input = array('itemtype' => $_POST["itemtype"], 'items_id' => $key, 'contracts_id' => $_POST['contracts_id']);
         if ($contractitem->can(-1, 'w', $input)) {
             $contractitem->add($input);
         }
     }
     break;
 case "add_enterprise":
     if ($_POST["itemtype"] == 'Contact') {
         $contactsupplier = new Contact_Supplier();
         foreach ($_POST["item"] as $key => $val) {
             $input = array('suppliers_id' => $_POST['entID'], 'contacts_id' => $key);
             if ($contactsupplier->can(-1, 'w', $input)) {
                 $contactsupplier->add($input);
             }
         }
     }
     break;
 case "activate_infocoms":
Exemplo n.º 4
0
 function post_addItem()
 {
     global $DB, $CFG_GLPI;
     // Manage add from template
     if (isset($this->input["_oldID"])) {
         // ADD Infocoms
         $ic = new Infocom();
         $ic->cloneItem($this->getType(), $this->input["_oldID"], $this->fields['id']);
         // ADD Ports
         $query = "SELECT `id`\n                   FROM `glpi_networkports`\n                   WHERE `items_id` = '" . $this->input["_oldID"] . "'\n                         AND `itemtype` = '" . $this->getType() . "'";
         $result = $DB->query($query);
         if ($DB->numrows($result) > 0) {
             while ($data = $DB->fetch_array($result)) {
                 $np = new NetworkPort();
                 $npv = new NetworkPort_Vlan();
                 $np->getFromDB($data["id"]);
                 unset($np->fields["id"]);
                 unset($np->fields["ip"]);
                 unset($np->fields["mac"]);
                 unset($np->fields["netpoints_id"]);
                 $np->fields["items_id"] = $this->fields['id'];
                 $portid = $np->addToDB();
                 foreach ($DB->request('glpi_networkports_vlans', array('networkports_id' => $data["id"])) as $vlan) {
                     $npv->assignVlan($portid, $vlan['vlans_id']);
                 }
             }
         }
         // ADD Contract
         $query = "SELECT `contracts_id`\n                   FROM `glpi_contracts_items`\n                   WHERE `items_id` = '" . $this->input["_oldID"] . "'\n                         AND `itemtype` = '" . $this->getType() . "'";
         $result = $DB->query($query);
         if ($DB->numrows($result) > 0) {
             $contractitem = new Contract_Item();
             while ($data = $DB->fetch_array($result)) {
                 $contractitem->add(array('contracts_id' => $data["contracts_id"], 'itemtype' => $this->getType(), 'items_id' => $this->fields['id']));
             }
         }
         // ADD Documents
         $query = "SELECT `documents_id`\n                   FROM `glpi_documents_items`\n                   WHERE `items_id` = '" . $this->input["_oldID"] . "'\n                         AND `itemtype` = '" . $this->getType() . "'";
         $result = $DB->query($query);
         if ($DB->numrows($result) > 0) {
             $docitem = new Document_Item();
             while ($data = $DB->fetch_array($result)) {
                 $docitem->add(array('documents_id' => $data["documents_id"], 'itemtype' => $this->getType(), 'items_id' => $this->fields['id']));
             }
         }
     }
 }
Exemplo n.º 5
0
 /**
  * Do the standard massive actions
  *
  * @since version 0.84
  *
  * This must not be overloaded in Class
  * @param $input array of input datas
  *
  * @return an array of results (ok, ko, noright counts, may include REDIRECT field to set REDIRECT page)
  **/
 function doMassiveActions($input = array())
 {
     global $CFG_GLPI;
     if (!isset($input["item"]) || count($input["item"]) == 0) {
         return false;
     }
     $res = array('ok' => 0, 'ko' => 0, 'noright' => 0);
     switch ($input['action']) {
         case 'add_document':
         case 'remove_document':
             $doc = new Document();
             return $doc->doSpecificMassiveActions($input);
         case "add_transfer_list":
             if (!isset($_SESSION['glpitransfer_list'])) {
                 $_SESSION['glpitransfer_list'] = array();
             }
             if (!isset($_SESSION['glpitransfer_list'][$input["itemtype"]])) {
                 $_SESSION['glpitransfer_list'][$input["itemtype"]] = array();
             }
             foreach ($input["item"] as $key => $val) {
                 if ($val == 1) {
                     $_SESSION['glpitransfer_list'][$input["itemtype"]][$key] = $key;
                     $res['ok']++;
                 }
             }
             $res['REDIRECT'] = $CFG_GLPI['root_doc'] . '/front/transfer.action.php';
             break;
         case "delete":
             foreach ($input["item"] as $key => $val) {
                 if ($val == 1) {
                     if ($this->can($key, 'd')) {
                         if ($this->delete(array("id" => $key))) {
                             $res['ok']++;
                         } else {
                             $res['ko']++;
                         }
                     } else {
                         $res['noright']++;
                     }
                 }
             }
             break;
         case "purge":
             foreach ($input["item"] as $key => $val) {
                 if ($val == 1) {
                     if ($this->can($key, 'd')) {
                         $force = 1;
                         // Only mark deletion for
                         if ($this->maybeDeleted() && $this->useDeletedToLockIfDynamic() && $this->isDynamic()) {
                             $force = 0;
                         }
                         if ($this->delete(array("id" => $key), $force)) {
                             $res['ok']++;
                         } else {
                             $res['ko']++;
                         }
                     } else {
                         $res['noright']++;
                     }
                 }
             }
             break;
         case "restore":
             foreach ($input["item"] as $key => $val) {
                 if ($val == 1) {
                     if ($this->can($key, 'd')) {
                         if ($this->restore(array("id" => $key))) {
                             $res['ok']++;
                         } else {
                             $res['ko']++;
                         }
                     } else {
                         $res['noright']++;
                     }
                 }
             }
             break;
         case "update":
             $searchopt = Search::getCleanedOptions($input["itemtype"], 'w');
             if (isset($searchopt[$input["id_field"]])) {
                 /// Infocoms case
                 if (!isPluginItemType($input["itemtype"]) && Search::isInfocomOption($input["itemtype"], $input["id_field"])) {
                     $ic = new Infocom();
                     $link_entity_type = -1;
                     /// Specific entity item
                     if ($searchopt[$input["id_field"]]["table"] == "glpi_suppliers") {
                         $ent = new Supplier();
                         if ($ent->getFromDB($input[$input["field"]])) {
                             $link_entity_type = $ent->fields["entities_id"];
                         }
                     }
                     foreach ($input["item"] as $key => $val) {
                         if ($val == 1) {
                             if ($this->getFromDB($key)) {
                                 if ($link_entity_type < 0 || $link_entity_type == $this->getEntityID() || $ent->fields["is_recursive"] && in_array($link_entity_type, getAncestorsOf("glpi_entities", $this->getEntityID()))) {
                                     $input2["items_id"] = $key;
                                     $input2["itemtype"] = $input["itemtype"];
                                     if ($ic->can(-1, 'w', $input2)) {
                                         // Add infocom if not exists
                                         if (!$ic->getFromDBforDevice($input["itemtype"], $key)) {
                                             $input2["items_id"] = $key;
                                             $input2["itemtype"] = $input["itemtype"];
                                             unset($ic->fields);
                                             $ic->add($input2);
                                             $ic->getFromDBforDevice($input["itemtype"], $key);
                                         }
                                         $id = $ic->fields["id"];
                                         unset($ic->fields);
                                         if ($ic->update(array('id' => $id, $input["field"] => $input[$input["field"]]))) {
                                             $res['ok']++;
                                         } else {
                                             $res['ko']++;
                                         }
                                     } else {
                                         $res['noright']++;
                                     }
                                 } else {
                                     $res['ko']++;
                                 }
                             } else {
                                 $res['ko']++;
                             }
                         }
                     }
                 } else {
                     /// Not infocoms
                     $link_entity_type = array();
                     /// Specific entity item
                     $itemtable = getTableForItemType($input["itemtype"]);
                     $itemtype2 = getItemTypeForTable($searchopt[$input["id_field"]]["table"]);
                     if ($item2 = getItemForItemtype($itemtype2)) {
                         if ($input["id_field"] != 80 && $searchopt[$input["id_field"]]["table"] != $itemtable && $item2->isEntityAssign() && $this->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 ($input["item"] as $key => $val) {
                         if ($val == 1) {
                             if ($this->can($key, 'w') && $this->canMassiveAction($input['action'], $input['field'], $input[$input["field"]])) {
                                 if (count($link_entity_type) == 0 || in_array($this->fields["entities_id"], $link_entity_type)) {
                                     if ($this->update(array('id' => $key, $input["field"] => $input[$input["field"]]))) {
                                         $res['ok']++;
                                     } else {
                                         $res['ko']++;
                                     }
                                 } else {
                                     $res['ko']++;
                                 }
                             } else {
                                 $res['noright']++;
                             }
                         }
                     }
                 }
             }
             break;
         case "activate_infocoms":
             $ic = new Infocom();
             if ($ic->canCreate()) {
                 foreach ($input["item"] as $key => $val) {
                     $input = array('itemtype' => $input['itemtype'], 'items_id' => $key);
                     if (!$ic->getFromDBforDevice($input['itemtype'], $key)) {
                         if ($ic->can(-1, 'w', $input)) {
                             if ($ic->add($input)) {
                                 $res['ok']++;
                             } else {
                                 $res['ko']++;
                             }
                         } else {
                             $res['noright']++;
                         }
                     } else {
                         $res['ko']++;
                     }
                 }
             }
             break;
         case "add_contract_item":
             $contractitem = new Contract_Item();
             foreach ($input["item"] as $key => $val) {
                 if (isset($input['items_id'])) {
                     // Add items to contracts
                     $input = array('itemtype' => $input["item_itemtype"], 'items_id' => $input["items_id"], 'contracts_id' => $key);
                 }
                 if (isset($input['contracts_id'])) {
                     // Add contract to item
                     $input = array('itemtype' => $input["itemtype"], 'items_id' => $key, 'contracts_id' => $input['contracts_id']);
                 } else {
                     return false;
                 }
                 if ($contractitem->can(-1, 'w', $input)) {
                     if ($contractitem->add($input)) {
                         $res['ok']++;
                     } else {
                         $res['ko']++;
                     }
                 } else {
                     $res['noright']++;
                 }
             }
             break;
         case "remove_contract_item":
             foreach ($input["item"] as $key => $val) {
                 if (isset($input['items_id'])) {
                     // Remove item to contracts
                     $input = array('itemtype' => $input["item_itemtype"], 'items_id' => $input["items_id"], 'contracts_id' => $key);
                 } else {
                     // Remove contract to items
                     $input = array('itemtype' => $input["itemtype"], 'items_id' => $key, 'contracts_id' => $input['contracts_id']);
                 }
                 $contractitem = new Contract_Item();
                 if ($contractitem->can(-1, 'w', $input)) {
                     if ($item = getItemForItemtype($input["itemtype"])) {
                         if ($item->getFromDB($input['items_id'])) {
                             $contract = new Contract();
                             if ($contract->getFromDB($input['contracts_id'])) {
                                 if ($contractitem->getFromDBForItems($contract, $item)) {
                                     if ($contractitem->delete(array('id' => $contractitem->getID()))) {
                                         $res['ok']++;
                                     } else {
                                         $res['ko']++;
                                     }
                                 } else {
                                     $res['ko']++;
                                 }
                             } else {
                                 $res['ko']++;
                             }
                         } else {
                             $res['ko']++;
                         }
                     } else {
                         $res['ko']++;
                     }
                 } else {
                     $res['noright']++;
                 }
             }
             break;
             //Lock management
         //Lock management
         case 'unlock_Printer':
         case 'unlock_Monitor':
         case 'unlock_NetworkPort':
         case 'unlock_NetworkName':
         case 'unlock_IPAddress':
         case 'unlock_ComputerDisk':
         case 'unlock_ComputerVirtualMachine':
         case 'unlock_Peripheral':
         case 'unlock_SoftwareVersion':
             $itemtype = Lock::getItemTypeForMassiveAction($input["action"]);
             if ($itemtype) {
                 $res = Lock::unlockItems($itemtype, $this->getType(), $input["item"]);
             }
             break;
         case 'unlock_Device':
             foreach (Item_Devices::getDeviceTypes() as $itemtype) {
                 $res = Lock::unlockItems($itemtype, $this->getType(), $input["item"]);
             }
             break;
         default:
             // Plugin specific actions
             $split = explode('_', $input["action"]);
             $res = '';
             if ($split[0] == 'plugin' && isset($split[1])) {
                 // Normalized name plugin_name_action
                 // Allow hook from any plugin on any (core or plugin) type
                 $res = Plugin::doOneHook($split[1], 'MassiveActionsProcess', $input);
                 //            } else if ($plug=isPluginItemType($input["itemtype"])) {
                 // non-normalized name
                 // hook from the plugin defining the type
                 //               $res = Plugin::doOneHook($plug['plugin'], 'MassiveActionsProcess', $input);
             } else {
                 $res = $this->doSpecificMassiveActions($input);
             }
             break;
     }
     return $res;
 }
Exemplo n.º 6
0
 function post_addItem()
 {
     global $DB, $CFG_GLPI;
     // Manage add from template
     if (isset($this->input["_oldID"])) {
         // ADD Infocoms
         $ic = new Infocom();
         $ic->cloneItem($this->getType(), $this->input["_oldID"], $this->fields['id']);
         // ADD Contract
         $query = "SELECT `contracts_id`\n                   FROM `glpi_contracts_items`\n                   WHERE `items_id` = '" . $this->input["_oldID"] . "'\n                         AND `itemtype` = '" . $this->getType() . "'";
         $result = $DB->query($query);
         if ($DB->numrows($result) > 0) {
             $contractitem = new Contract_Item();
             while ($data = $DB->fetch_array($result)) {
                 $contractitem->add(array('contracts_id' => $data["contracts_id"], 'itemtype' => $this->getType(), 'items_id' => $this->fields['id']));
             }
         }
         // ADD Documents
         $query = "SELECT `documents_id`\n                   FROM `glpi_documents_items`\n                   WHERE `items_id` = '" . $this->input["_oldID"] . "'\n                         AND `itemtype` = '" . $this->getType() . "'";
         $result = $DB->query($query);
         if ($DB->numrows($result) > 0) {
             $docitem = new Document_Item();
             while ($data = $DB->fetch_array($result)) {
                 $docitem->add(array('documents_id' => $data["documents_id"], 'itemtype' => $this->getType(), 'items_id' => $this->fields['id']));
             }
         }
     }
 }