Example #1
0
 /**
  * Do automatic transfer if option is enable
  *
  * @param $line_links array : data from glpi_plugin_ocsinventoryng_ocslinks table
  * @param $line_ocs array : data from ocs tables
  *
  * @return nothing
  **/
 static function transferComputer($line_links, $line_ocs)
 {
     global $DB, $PluginOcsinventoryngDBocs, $CFG_GLPI;
     // Get all rules for the current plugin_ocsinventoryng_ocsservers_id
     $rule = new RuleImportEntityCollection();
     $data = array();
     $data = $rule->processAllRules(array('ocsservers_id' => $line_links["plugin_ocsinventoryng_ocsservers_id"], '_source' => 'ocsinventoryng'), array(), array('ocsid' => $line_links["ocsid"]));
     // If entity is changing move items to the new entities_id
     if (isset($data['entities_id']) && $data['entities_id'] != $line_links['entities_id']) {
         if (!isCommandLine() && !Session::haveAccessToEntity($data['entities_id'])) {
             Html::displayRightError();
         }
         $transfer = new Transfer();
         $transfer->getFromDB($CFG_GLPI['transfers_id_auto']);
         $item_to_transfer = array("Computer" => array($line_links['computers_id'] => $line_links['computers_id']));
         $transfer->moveItems($item_to_transfer, $data['entities_id'], $transfer->fields);
     }
     //If location is update by a rule
     self::updateLocation($line_links, $data);
 }
Example #2
0
 /**
  * @param $item         CommonGLPI object
  * @param $tabnum       (default 1)
  * @param $withtemplate (default 0)
  **/
 static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0)
 {
     if ($item->getType() == 'Entity') {
         $collection = new RuleRightCollection();
         if ($collection->canList()) {
             $ldaprule = new RuleRight();
             $ldaprule->showAndAddRuleForm($item);
         }
         $collection = new RuleImportEntityCollection();
         if ($collection->canList()) {
             $importrule = new RuleImportEntity();
             $importrule->showAndAddRuleForm($item);
         }
         $collection = new RuleMailCollectorCollection();
         if ($collection->canList()) {
             $mailcollector = new RuleMailCollector();
             $mailcollector->showAndAddRuleForm($item);
         }
     } else {
         if ($item->getType() == 'SLA') {
             $rule = new RuleTicket();
             $rule->showAndAddRuleForm($item);
         } else {
             if ($item instanceof Rule) {
                 $item->getRuleWithCriteriasAndActions($item->getID(), 1, 1);
                 switch ($tabnum) {
                     case 1:
                         $item->showCriteriasList($item->getID());
                         break;
                     case 2:
                         $item->showActionsList($item->getID());
                         break;
                 }
             }
         }
     }
     return true;
 }
 /**
  * Do automatic transfer if option is enable
  *
  * @param $line_links array : data from glpi_plugin_ocsinventoryng_ocslinks table
  * @return nothing
  * @internal param array $line_ocs : data from ocs tables
  *
  */
 static function transferComputer($line_links)
 {
     global $DB, $CFG_GLPI;
     $ocsClient = self::getDBocs($line_links["plugin_ocsinventoryng_ocsservers_id"]);
     $cfg_ocs = self::getConfig($line_links["plugin_ocsinventoryng_ocsservers_id"]);
     $ocsComputer = $ocsClient->getComputer($line_links["ocsid"]);
     $locations_id = 0;
     $contact = isset($ocsComputer['META']["USERID"]) ? $ocsComputer['META']["USERID"] : "";
     if (!empty($contact)) {
         $query = "SELECT `id`\n                   FROM `glpi_users`\n                   WHERE `name` = '" . $contact . "';";
         $result = $DB->query($query);
         if ($DB->numrows($result) == 1) {
             $user_id = $DB->result($result, 0, 0);
             $user = new User();
             $user->getFromDB($user_id);
             $locations_id = $user->fields["locations_id"];
         }
     }
     // Get all rules for the current plugin_ocsinventoryng_ocsservers_id
     $rule = new RuleImportEntityCollection();
     $data = array();
     $data = $rule->processAllRules(array('ocsservers_id' => $line_links["plugin_ocsinventoryng_ocsservers_id"], '_source' => 'ocsinventoryng', 'locations_id' => $locations_id), array('locations_id' => $locations_id), array('ocsid' => $line_links["ocsid"]));
     // If entity is changing move items to the new entities_id
     if (isset($data['entities_id']) && $data['entities_id'] > -1 && $data['entities_id'] != $line_links['entities_id']) {
         if (!isCommandLine() && !Session::haveAccessToEntity($data['entities_id'])) {
             Html::displayRightError();
         }
         $transfer = new Transfer();
         $transfer->getFromDB($CFG_GLPI['transfers_id_auto']);
         $item_to_transfer = array("Computer" => array($line_links['computers_id'] => $line_links['computers_id']));
         $transfer->moveItems($item_to_transfer, $data['entities_id'], $transfer->fields);
     }
     //If location is update by a rule
     self::updateLocation($line_links, $data, $cfg_ocs);
 }