From 657c11da1fc9e52d1db9ca8413b7edf4cea16579 Mon Sep 17 00:00:00 2001 From: Hirofumi Kosaka Date: Fri, 2 Sep 2016 12:55:16 +0900 Subject: [PATCH] Added new API 'delete_group'. --- pandora_console/include/functions_api.php | 40 +++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/pandora_console/include/functions_api.php b/pandora_console/include/functions_api.php index 72318c948c..1d73c8844b 100644 --- a/pandora_console/include/functions_api.php +++ b/pandora_console/include/functions_api.php @@ -5745,6 +5745,46 @@ function api_set_update_group($id_group, $thrash2, $other, $thrash3) { array('type' => 'string', 'data' => (int)((bool)$return))); } +/** + * Delete a group + * + * @param integer $id Group ID + * @param $thrash1 Don't use. + * @param $thrast2 Don't use. + * @param $thrash3 Don't use. + */ +function api_set_delete_group($id_group, $thrash2, $other, $thrash3) { + global $config; + + if (defined ('METACONSOLE')) { + return; + } + + $group = db_get_row_filter('tgrupo', array('id_grupo' => $id_group)); + if (!$group) { + returnError('error_delete', 'Error in delete operation. Id does not exist.'); + return; + } + + $usedGroup = groups_check_used($id_group); + if ($usedGroup['return']) { + returnError('error_delete', + 'Error in delete operation. The group is not empty (used in ' . + implode(', ', $usedGroup['tables']) . ').' ); + return; + } + + db_process_sql_update('tgrupo', array('parent' => $group['parent']), array('parent' => $id_group)); + db_process_sql_delete('tgroup_stat', array('id_group' => $id_group)); + + $result = db_process_sql_delete('tgrupo', array('id_grupo' => $id_group)); + + if (!$result) + returnError('error_delete', 'Error in delete operation.'); + else + returnData('string', array('type' => 'string', 'data' => __('Correct Delete'))); +} + /** * Create a new netflow filter. And return the id_group of the new group. *