@since     2010

  ------------------------------------------------------------------------
*/
include "../../../inc/includes.php";
Html::header(__('FusionInventory', 'fusioninventory'), $_SERVER["PHP_SELF"], "plugins", "fusioninventory", "agentmodules");
Session::checkRight('plugin_fusioninventory_agent', READ);
$agentmodule = new PluginFusioninventoryAgentmodule();
if (isset($_POST["agent_add"])) {
    $agentmodule->getFromDB($_POST['id']);
    $a_agentList = importArrayFromDB($agentmodule->fields['exceptions']);
    $a_agentList[] = $_POST['agent_to_add'][0];
    $input = array();
    $input['exceptions'] = exportArrayToDB($a_agentList);
    $input['id'] = $_POST['id'];
    $agentmodule->update($input);
    Html::back();
} else {
    if (isset($_POST["agent_delete"])) {
        $agentmodule->getFromDB($_POST['id']);
        $a_agentList = importArrayFromDB($agentmodule->fields['exceptions']);
        foreach ($a_agentList as $key => $value) {
            if ($value == $_POST['agent_to_delete'][0]) {
                unset($a_agentList[$key]);
            }
        }
        $input = array();
        $input['exceptions'] = exportArrayToDB($a_agentList);
        $input['id'] = $_POST['id'];
        $agentmodule->update($input);
        Html::back();
 static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids)
 {
     $pfAgent = new self();
     switch ($ma->getAction()) {
         case 'transfert':
             foreach ($ids as $key) {
                 if ($pfAgent->getFromDB($key)) {
                     $input = array();
                     $input['id'] = $key;
                     $input['entities_id'] = $_POST['entities_id'];
                     if ($pfAgent->update($input)) {
                         //set action massive ok for this item
                         $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_OK);
                     } else {
                         // KO
                         $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO);
                     }
                 }
             }
             return;
             break;
     }
     $pfAgentmodule = new PluginFusioninventoryAgentmodule();
     $a_modules = $pfAgentmodule->find();
     foreach ($a_modules as $data2) {
         if ($ma->getAction() == $data2['modulename']) {
             foreach ($ids as $key) {
                 if ($ma->POST[$data2['modulename']] == $data2['is_active']) {
                     // Remove from exceptions
                     $a_exceptions = importArrayFromDB($data2['exceptions']);
                     if (in_array($key, $a_exceptions)) {
                         foreach ($a_exceptions as $key2 => $value2) {
                             if ($value2 == $key) {
                                 unset($a_exceptions[$key2]);
                             }
                         }
                     }
                     $data2['exceptions'] = exportArrayToDB($a_exceptions);
                 } else {
                     // Add to exceptions
                     $a_exceptions = importArrayFromDB($data2['exceptions']);
                     if (!in_array($key, $a_exceptions)) {
                         $a_exceptions[] = (string) $key;
                     }
                     $data2['exceptions'] = exportArrayToDB($a_exceptions);
                 }
                 $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_OK);
             }
             $pfAgentmodule->update($data2);
         }
     }
     return;
 }