Exemplo n.º 1
0
function plugin_accounts_getDropdown()
{
    $plugin = new Plugin();
    if ($plugin->isActivated("accounts")) {
        return array("PluginAccountsAccountType" => PluginAccountsAccountType::getTypeName(2), "PluginAccountsAccountState" => PluginAccountsAccountState::getTypeName(2));
    } else {
        return array();
    }
}
Exemplo n.º 2
0
 /**
  * @since version 0.85
  *
  * @see CommonDBTM::processMassiveActionsForOneItemtype()
  **/
 static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids)
 {
     $account_item = new PluginAccountsAccount_Item();
     switch ($ma->getAction()) {
         case "add_item":
             $input = $ma->getInput();
             foreach ($ma->items as $itemtype => $myitem) {
                 foreach ($myitem as $key => $value) {
                     if (!countElementsInTable('glpi_plugin_accounts_accounts_items', "itemtype='{$itemtype}' \n                                             AND items_id='{$key}' \n                                             AND plugin_accounts_accounts_id='" . $input['plugin_accounts_accounts_id'] . "'")) {
                         $myvalue['plugin_accounts_accounts_id'] = $input['plugin_accounts_accounts_id'];
                         $myvalue['itemtype'] = $itemtype;
                         $myvalue['items_id'] = $key;
                         if ($account_item->add($myvalue)) {
                             $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_OK);
                         } else {
                             $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO);
                         }
                     } else {
                         $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO);
                     }
                 }
             }
             break;
         case "transfer":
             $input = $ma->getInput();
             if ($item->getType() == 'PluginAccountsAccount') {
                 foreach ($ids as $key) {
                     $item->getFromDB($key);
                     $type = PluginAccountsAccountType::transfer($item->fields["plugin_accounts_accounttypes_id"], $input['entities_id']);
                     if ($type > 0) {
                         $values["id"] = $key;
                         $values["plugin_accounts_accounttypes_id"] = $type;
                         $item->update($values);
                     }
                     unset($values);
                     $values["id"] = $key;
                     $values["entities_id"] = $input['entities_id'];
                     if ($item->update($values)) {
                         $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_OK);
                     } else {
                         $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO);
                     }
                 }
             }
             break;
         case 'install':
             $input = $ma->getInput();
             foreach ($ids as $key) {
                 if ($item->can($key, UPDATE)) {
                     $values = array('plugin_accounts_accounts_id' => $key, 'items_id' => $input["item_item"], 'itemtype' => $input['typeitem']);
                     if ($account_item->add($values)) {
                         $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_OK);
                     } else {
                         $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO);
                     }
                 } else {
                     $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_NORIGHT);
                     $ma->addMessage($item->getErrorMessage(ERROR_RIGHT));
                 }
             }
             break;
         case 'uninstall':
             $input = $ma->getInput();
             foreach ($ids as $key) {
                 if ($val == 1) {
                     if ($account_item->deleteItemByAccountsAndItem($key, $input['item_item'], $input['typeitem'])) {
                         $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_OK);
                     } else {
                         $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO);
                     }
                 }
             }
             break;
     }
 }
Exemplo n.º 3
0
 /**
  * Do the specific massive actions
  *
  * @since version 0.84
  * 
  * @param $input array of input datas
  * 
  * @return an array of results (nbok, nbko, nbnoright counts)
  **/
 public function doSpecificMassiveActions($input = array())
 {
     $res = array('ok' => 0, 'ko' => 0, 'noright' => 0);
     $account_item = new PluginAccountsAccount_Item();
     switch ($input['action']) {
         case "Transfert":
             if ($input['itemtype'] == 'PluginAccountsAccount') {
                 foreach ($input["item"] as $key => $val) {
                     if ($val == 1) {
                         $this->getFromDB($key);
                         $type = PluginAccountsAccountType::transfer($this->fields["plugin_accounts_accounttypes_id"], $input['entities_id']);
                         if ($type > 0) {
                             $values["id"] = $key;
                             $values["plugin_accounts_accounttypes_id"] = $type;
                             if ($this->update($values)) {
                                 $res['ok']++;
                             } else {
                                 $res['ko']++;
                             }
                         }
                         unset($values);
                         $values["id"] = $key;
                         $values["entities_id"] = $input['entities_id'];
                         if ($this->update($values)) {
                             $res['ok']++;
                         } else {
                             $res['ko']++;
                         }
                     }
                 }
             }
             break;
         case "Install":
             foreach ($input["item"] as $key => $val) {
                 if ($val == 1) {
                     $values = array('plugin_accounts_accounts_id' => $key, 'items_id' => $input["item_item"], 'itemtype' => $input['typeitem']);
                     if ($account_item->add($values)) {
                         $res['ok']++;
                     } else {
                         $res['ko']++;
                     }
                 }
             }
             break;
         case "Desinstall":
             foreach ($input["item"] as $key => $val) {
                 if ($val == 1) {
                     if ($account_item->deleteItemByAccountsAndItem($key, $input['item_item'], $input['typeitem'])) {
                         $res['ok']++;
                     } else {
                         $res['ko']++;
                     }
                 }
             }
             break;
         default:
             return parent::doSpecificMassiveActions($input);
             break;
     }
     return $res;
 }