/**
  * @since version 0.84
  *
  * @see CommonDBTM::doSpecificMassiveActions()
  **/
 function doSpecificMassiveActions($input = array())
 {
     $res = array('ok' => 0, 'ko' => 0, 'noright' => 0);
     switch ($input['action']) {
         case "move_license":
             if (isset($input['softwarelicenses_id'])) {
                 foreach ($input["item"] as $key => $val) {
                     if ($val == 1) {
                         //Get software name and manufacturer
                         if ($this->can($key, 'w')) {
                             //Process rules
                             if ($this->update(array('id' => $key, 'softwarelicenses_id' => $input['softwarelicenses_id']))) {
                                 $res['ok']++;
                             } else {
                                 $res['ko']++;
                             }
                         } else {
                             $res['noright']++;
                         }
                     }
                 }
             } else {
                 $res['ko']++;
             }
             break;
         case "install":
             $csl = new self();
             $csv = new Computer_SoftwareVersion();
             foreach ($input["item"] as $key => $val) {
                 if ($val == 1) {
                     if ($csl->getFromDB($key)) {
                         $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, 'w', $params)) {
                                     //Process rules
                                     if ($csv->add($params)) {
                                         $res['ok']++;
                                     } else {
                                         $res['ko']++;
                                     }
                                 } else {
                                     $res['noright']++;
                                 }
                             } else {
                                 $res['ko']++;
                             }
                         } else {
                             $res['ko']++;
                         }
                     } else {
                         $res['ko']++;
                     }
                 }
             }
             break;
         default:
             return parent::doSpecificMassiveActions($input);
     }
     return $res;
 }
 /**
  * @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);
 }
Example #3
0
 /**
  * @see CommonDBTM::doSpecificMassiveActions()
  **/
 function doSpecificMassiveActions($input = array())
 {
     $res = array('ok' => 0, 'ko' => 0, 'noright' => 0);
     switch ($input['action']) {
         case "connect":
             $ci = new Computer_Item();
             return $ci->doSpecificMassiveActions($input);
         case "install":
             if (isset($input['softwareversions_id']) && $input['softwareversions_id'] > 0) {
                 $inst = new Computer_SoftwareVersion();
                 foreach ($input['item'] as $key => $val) {
                     if ($val == 1) {
                         $input2 = array('computers_id' => $key, 'softwareversions_id' => $input['softwareversions_id']);
                         if ($inst->can(-1, 'w', $input2)) {
                             if ($inst->add($input2)) {
                                 $res['ok']++;
                             } else {
                                 $res['ko']++;
                             }
                         } else {
                             $res['noright']++;
                         }
                     }
                 }
             } else {
                 $res['ko']++;
             }
             break;
         default:
             return parent::doSpecificMassiveActions($input);
     }
     return $res;
 }