diff --git a/pandora_console/include/functions_api.php b/pandora_console/include/functions_api.php index 77b2f9e3fa..69a8cb2bac 100644 --- a/pandora_console/include/functions_api.php +++ b/pandora_console/include/functions_api.php @@ -7833,24 +7833,26 @@ function api_set_planned_downtimes_add_agents($id, $thrash1, $other, $thrash3) } if (!empty($other['data'][0])) { - $agents = $other['data']; + $agents = explode(';', $other['data'][0]); $results = false; foreach ($agents as $agent) { - if (db_get_value_sql(sprintf('SELECT id from tplanned_downtime_agents tpd WHERE tpd.id_agent = %d AND id_downtime = %d', $agent, $id)) === false) { - $res = db_process_sql_insert( - 'tplanned_downtime_agents', - [ - 'id_agent' => $agent, - 'id_downtime' => $id, - 'all_modules' => 0, - 'manually_disabled' => 0, - ] - ); - if ($res) { - $results = true; + if (!empty($agent)) { + if (db_get_value_sql(sprintf('SELECT id from tplanned_downtime_agents tpd WHERE tpd.id_agent = %d AND id_downtime = %d', $agent, $id)) === false) { + $res = db_process_sql_insert( + 'tplanned_downtime_agents', + [ + 'id_agent' => $agent, + 'id_downtime' => $id, + 'all_modules' => 0, + 'manually_disabled' => 0, + ] + ); + if ($res) { + $results = true; + } + } else { + returnError(" Agent $agent is already at the planned downtime."); } - } else { - returnError(" Agent $agent is already at the planned downtime."); } }