Esempio n. 1
0
/**
 * @param $data   array
**/
function plugin_ocsinventoryng_MassiveActionsProcess($data)
{
    global $CFG_GLPI, $DB, $REDIRECT;
    $nbok = 0;
    $nbko = 0;
    $noright = 0;
    $notimport = new PluginOcsinventoryngNotimportedcomputer();
    if (!($item = getItemForItemtype($data['itemtype']))) {
        return;
    }
    switch ($data["action"]) {
        case "plugin_ocsinventoryng_import":
            foreach ($data["item"] as $key => $val) {
                if ($val == 1) {
                    PluginOcsinventoryngNotimportedcomputer::computerImport(array('id' => $key, 'force' => true, 'entity' => $data['entity']));
                }
            }
            break;
        case "plugin_ocsinventoryng_replayrules":
            foreach ($data["item"] as $key => $val) {
                if ($val == 1) {
                    PluginOcsinventoryngNotimportedcomputer::computerImport(array('id' => $key));
                }
            }
            break;
        case "plugin_ocsinventoryng_delete":
            $plugin = new Plugin();
            if ($plugin->isActivated("uninstall")) {
                foreach ($data["item"] as $key => $val) {
                    if ($val == 1) {
                        $notimport->deleteNotImportedComputer($key);
                    }
                }
            }
            break;
        case "plugin_ocsinventoryng_unlock_ocsng_field":
            $nbok = 0;
            $nbnoright = 0;
            $nbko = 0;
            $fields = PluginOcsinventoryngOcsServer::getLockableFields();
            if ($_POST['field'] == 'all' || isset($fields[$_POST['field']])) {
                foreach ($_POST["item"] as $key => $val) {
                    if ($val == 1) {
                        if ($item->can($key, 'w')) {
                            if ($_POST['field'] == 'all') {
                                if (PluginOcsinventoryngOcsServer::replaceOcsArray($key, array(), "computer_update")) {
                                    $nbok++;
                                } else {
                                    $nbko++;
                                }
                            } else {
                                if (PluginOcsinventoryngOcsServer::deleteInOcsArray($key, $_POST['field'], "computer_update", true)) {
                                    $nbok++;
                                } else {
                                    $nbko++;
                                }
                            }
                        } else {
                            $nbnoright++;
                        }
                    }
                }
            }
            break;
        case "plugin_ocsinventoryng_force_ocsng_update":
            // First time
            if (!isset($_GET['multiple_actions'])) {
                $_SESSION['glpi_massiveaction']['POST'] = $_POST;
                $_SESSION['glpi_massiveaction']['REDIRECT'] = $REDIRECT;
                $_SESSION['glpi_massiveaction']['items'] = array();
                foreach ($_POST["item"] as $key => $val) {
                    if ($val == 1) {
                        $_SESSION['glpi_massiveaction']['items'][$key] = $key;
                    }
                }
                $_SESSION['glpi_massiveaction']['item_count'] = count($_SESSION['glpi_massiveaction']['items']);
                $_SESSION['glpi_massiveaction']['items_ok'] = 0;
                $_SESSION['glpi_massiveaction']['items_ko'] = 0;
                $_SESSION['glpi_massiveaction']['items_nbnoright'] = 0;
                Html::redirect($_SERVER['PHP_SELF'] . '?multiple_actions=1');
            } else {
                if (count($_SESSION['glpi_massiveaction']['items']) > 0) {
                    $key = array_pop($_SESSION['glpi_massiveaction']['items']);
                    if ($item->can($key, 'w')) {
                        //Try to get the OCS server whose machine belongs
                        $query = "SELECT `plugin_ocsinventoryng_ocsservers_id`, `id`\n                            FROM `glpi_plugin_ocsinventoryng_ocslinks`\n                            WHERE `computers_id` = '" . $key . "'";
                        $result = $DB->query($query);
                        if ($DB->numrows($result) == 1) {
                            $data = $DB->fetch_assoc($result);
                            if ($data['plugin_ocsinventoryng_ocsservers_id'] != -1) {
                                //Force update of the machine
                                PluginOcsinventoryngOcsServer::updateComputer($data['id'], $data['plugin_ocsinventoryng_ocsservers_id'], 1, 1);
                                $_SESSION['glpi_massiveaction']['items_ok']++;
                            } else {
                                $_SESSION['glpi_massiveaction']['items_ko']++;
                            }
                        } else {
                            $_SESSION['glpi_massiveaction']['items_ko']++;
                        }
                    } else {
                        $_SESSION['glpi_massiveaction']['items_nbnoright']++;
                    }
                    Html::redirect($_SERVER['PHP_SELF'] . '?multiple_actions=1');
                } else {
                    $REDIRECT = $_SESSION['glpi_massiveaction']['REDIRECT'];
                    $nbok = $_SESSION['glpi_massiveaction']['items_ok'];
                    $nbko = $_SESSION['glpi_massiveaction']['items_ko'];
                    $nbnoright = $_SESSION['glpi_massiveaction']['items_nbnoright'];
                    unset($_SESSION['glpi_massiveaction']);
                }
            }
            break;
    }
    return array('ok' => $nbok, 'ko' => $nbko, 'noright' => $noright);
}
 /**
  * @since version 0.85
  *
  * @see CommonDBTM::processMassiveActionsForOneItemtype()
  * @param MassiveAction $ma
  * @param CommonDBTM $item
  * @param array $ids
  * @return nothing|void
  */
 static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids)
 {
     $notimport = new PluginOcsinventoryngNotimportedcomputer();
     switch ($ma->getAction()) {
         case "plugin_ocsinventoryng_import":
             $input = $ma->getInput();
             foreach ($ids as $id) {
                 if (PluginOcsinventoryngNotimportedcomputer::computerImport(array('id' => $id, 'force' => true, 'entity' => $input['entity']))) {
                     $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK);
                 } else {
                     $ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_KO);
                 }
             }
             return;
         case "plugin_ocsinventoryng_replayrules":
             foreach ($ids as $id) {
                 if (PluginOcsinventoryngNotimportedcomputer::computerImport(array('id' => $id))) {
                     $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK);
                 } else {
                     $ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_KO);
                 }
             }
             return;
         case "plugin_ocsinventoryng_delete":
             foreach ($ids as $id) {
                 if ($notimport->deleteNotImportedComputer($id)) {
                     $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK);
                 } else {
                     $ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_KO);
                 }
             }
             return;
     }
     parent::processMassiveActionsForOneItemtype($ma, $item, $ids);
 }
(at your option) any later version.

ocsinventoryng 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 ocsinventoryng. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/
include '../../../inc/includes.php';
$dropdown = new PluginOcsinventoryngNotimportedcomputer();
if (isset($_POST['action'])) {
    switch ($_POST['action']) {
        case 'plugin_ocsinventoryng_import':
            $_POST['force'] = true;
        case 'plugin_ocsinventoryng_replayrules':
            if (PluginOcsinventoryngNotimportedcomputer::computerImport($_POST)) {
                $dropdown->redirectToList();
            } else {
                Html::redirect(Html::getItemTypeFormURL('PluginOcsinventoryngNotimportedcomputer') . '?id=' . $_POST['id']);
            }
            break;
        case 'plugin_ocsinventoryng_link':
            $dropdown->linkComputer($_POST);
            $dropdown->redirectToList();
            break;
    }
}
include GLPI_ROOT . "/front/dropdown.common.form.php";