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 Databases. If not, see <http://www.gnu.org/licenses/>. -------------------------------------------------------------------------- */ include '../../../inc/includes.php'; if (!isset($_GET["id"])) { $_GET["id"] = ""; } if (!isset($_GET["withtemplate"])) { $_GET["withtemplate"] = ""; } $database = new PluginDatabasesDatabase(); $database_item = new PluginDatabasesDatabase_Item(); if (isset($_POST["add"])) { $database->check(-1, CREATE, $_POST); $newID = $database->add($_POST); if ($_SESSION['glpibackcreated']) { Html::redirect($web->getFormURL() . "?id=" . $newID); } Html::back(); } else { if (isset($_POST["delete"])) { $database->check($_POST['id'], DELETE); $database->delete($_POST); $database->redirectToList(); } else { if (isset($_POST["restore"])) { $database->check($_POST['id'], PURGE);
function doSpecificMassiveActions($input = array()) { $res = array('ok' => 0, 'ko' => 0, 'noright' => 0); $database_item = new PluginDatabasesDatabase_Item(); switch ($input['action']) { case "Transfert": if ($input['itemtype'] == 'PluginDatabasesDatabase') { foreach ($input["item"] as $key => $val) { if ($val == 1) { $this->getFromDB($key); $type = PluginDatabasesDatabaseType::transfer($this->fields["plugin_databases_databasetypes_id"], $input['entities_id']); if ($type > 0) { $values["id"] = $key; $values["plugin_databases_databasetypes_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_databases_databases_id' => $key, 'items_id' => $input["item_item"], 'itemtype' => $input['typeitem']); if ($database_item->add($values)) { $res['ok']++; } else { $res['ko']++; } } } break; case "Desinstall": foreach ($input["item"] as $key => $val) { if ($val == 1) { if ($database_item->deleteItemByDatabasesAndItem($key, $input['item_item'], $input['typeitem'])) { $res['ok']++; } else { $res['ko']++; } } } break; default: return parent::doSpecificMassiveActions($input); break; } return $res; }
/** * @since version 0.85 * * @see CommonDBTM::processMassiveActionsForOneItemtype() **/ static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids) { global $DB; $database_item = new PluginDatabasesDatabase_Item(); switch ($ma->getAction()) { case "plugin_databases_add_item": $input = $ma->getInput(); foreach ($ids as $id) { $input = array('plugin_databases_databasetypes_id' => $input['plugin_databases_databasetypes_id'], 'items_id' => $id, 'itemtype' => $item->getType()); if ($database_item->can(-1, UPDATE, $input)) { if ($database_item->add($input)) { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK); } else { $ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_KO); } } else { $ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_KO); } } return; case "transfer": $input = $ma->getInput(); if ($item->getType() == 'PluginDatabasesDatabase') { foreach ($ids as $key) { $item->getFromDB($key); $type = PluginDatabasesDatabaseType::transfer($item->fields["plugin_databases_databasetypes_id"], $input['entities_id']); if ($type > 0) { $values["id"] = $key; $values["plugin_databases_databasetypes_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); } } } return; case 'install': $input = $ma->getInput(); foreach ($ids as $key) { if ($item->can($key, UPDATE)) { $values = array('plugin_databases_databases_id' => $key, 'items_id' => $input["item_item"], 'itemtype' => $input['typeitem']); if ($database_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)); } } return; case 'uninstall': $input = $ma->getInput(); foreach ($ids as $key) { if ($val == 1) { if ($database_item->deleteItemByDatabasesAndItem($key, $input['item_item'], $input['typeitem'])) { $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_OK); } else { $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO); } } } return; } parent::processMassiveActionsForOneItemtype($ma, $item, $ids); }
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 Databases. If not, see <http://www.gnu.org/licenses/>. -------------------------------------------------------------------------- */ include '../../../inc/includes.php'; if (!isset($_GET["id"])) { $_GET["id"] = ""; } if (!isset($_GET["withtemplate"])) { $_GET["withtemplate"] = ""; } $database = new PluginDatabasesDatabase(); $database_item = new PluginDatabasesDatabase_Item(); if (isset($_POST["add"])) { $database->check(-1, 'w', $_POST); $newID = $database->add($_POST); Html::back(); } else { if (isset($_POST["delete"])) { $database->check($_POST['id'], 'w'); $database->delete($_POST); $database->redirectToList(); } else { if (isset($_POST["restore"])) { $database->check($_POST['id'], 'w'); $database->restore($_POST); $database->redirectToList(); } else {
function plugin_databases_MassiveActionsProcess($data) { $res = array('ok' => 0, 'ko' => 0, 'noright' => 0); $database_item = new PluginDatabasesDatabase_Item(); switch ($data['action']) { case "plugin_databases_add_item": foreach ($data["item"] as $key => $val) { if ($val == 1) { $input = array('plugin_databases_databases_id' => $data['plugin_databases_databases_id'], 'items_id' => $key, 'itemtype' => $data['itemtype']); if ($database_item->can(-1, 'w', $input)) { if ($database_item->can(-1, 'w', $input)) { $database_item->add($input); $res['ok']++; } else { $res['ko']++; } } else { $res['noright']++; } } } break; } return $res; }