From 6f0c66999ac98906af8113d19d55a3a82f604fcb Mon Sep 17 00:00:00 2001 From: juanmanuelr Date: Wed, 8 Jun 2011 14:11:12 +0000 Subject: [PATCH] 2011-06-08 Juan Manuel Ramon * include/functions_modules.php include/functions_tags.php: Support for policy's tag functionality. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@4418 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_console/ChangeLog | 5 + pandora_console/include/functions_modules.php | 4 +- pandora_console/include/functions_tags.php | 92 +++++++++++++++++++ 3 files changed, 100 insertions(+), 1 deletion(-) diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index edb3ccf421..a24b9d857c 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,8 @@ +2011-06-08 Juan Manuel Ramon + + * include/functions_modules.php + include/functions_tags.php: Support for policy's tag functionality. + 2011-06-08 Juan Manuel Ramon * godmode/massive/massive_edit_modules.php: Tags editor inside massive diff --git a/pandora_console/include/functions_modules.php b/pandora_console/include/functions_modules.php index 6e3bfa8e56..ea22f0f8b3 100644 --- a/pandora_console/include/functions_modules.php +++ b/pandora_console/include/functions_modules.php @@ -164,6 +164,7 @@ function modules_delete_agent_module ($id_agent_module) { db_process_sql_update ('tagente_modulo', array ('nombre' => 'delete_pending', 'delete_pending' => 1, 'disabled' => 1), $where); + db_process_sql_delete('ttag_module', $where); return true; } @@ -234,7 +235,8 @@ function modules_create_agent_module ($id_agent, $name, $values = false, $disabl if ($id_agent_module === false) return false; - $return_tag = tags_insert_module_tag ($id_agent_module, $tags); + if ($tags !== false) + $return_tag = tags_insert_module_tag ($id_agent_module, $tags); if ($return_tag === false){ db_process_sql_delete ('tagente_modulo', diff --git a/pandora_console/include/functions_tags.php b/pandora_console/include/functions_tags.php index 024c0145e4..a997abde30 100644 --- a/pandora_console/include/functions_tags.php +++ b/pandora_console/include/functions_tags.php @@ -273,6 +273,40 @@ function tags_insert_module_tag ($id_agent_module, $tags){ } } +/** + * Inserts tag's array of a policy module. + * + * @param int $id_agent_module Policy module's id. + * @param array $tags Array with tags to associate to the module. + * + * @return bool True or false if something goes wrong. + */ +function tags_insert_policy_module_tag ($id_agent_module, $tags){ + $errn = 0; + + $values = array(); + foreach ($tags as $tag){ + //Protect against default insert + if (empty($tag)) + continue; + + $values['id_tag'] = $tag; + $values['id_policy_module'] = $id_agent_module; + $result_tag = db_process_sql_insert('ttag_policy_module', $values, false); + if ($result_tag === false) + $errn++; + } + + if ($errn > 0){ + db_process_sql_rollback(); + return false; + } + else{ + db_process_sql_commit(); + return true; + } +} + /** * Updates tag's array of a module. * @@ -306,6 +340,39 @@ function tags_update_module_tag ($id_agent_module, $tags, $autocommit = false){ } +/** + * Updates tag's array of a policy module. + * + * @param int $id_policy_module Policy module's id. + * @param array $tags Array with tags to associate to the module. + * @param bool $autocommit Whether to do automatical commit or not. + * + * @return bool True or false if something goes wrong. + */ +function tags_update_policy_module_tag ($id_policy_module, $tags, $autocommit = false){ + $errn = 0; + + if (empty($tags)) + $tags = array(); + + /* First delete module tag entries */ + $result_tag = db_process_sql_delete ('ttag_policy_module', array('id_policy_module' => $id_policy_module)); + + $values = array(); + foreach ($tags as $tag){ + //Protect against default insert + if (empty($tag)) + continue; + + $values['id_tag'] = $tag; + $values['id_policy_module'] = $id_policy_module; + $result_tag = db_process_sql_insert('ttag_policy_module', $values, false); + if ($result_tag === false) + $errn++; + } + +} + /** * Select all tags of a module. * @@ -329,5 +396,30 @@ function tags_get_module_tags ($id_agent_module){ return $return; } + +/** + * Select all tags of a policy module. + * + * @param int $id_policy_module Policy module's id. + * + * @return mixed Array with module tags or false if something goes wrong. + */ +function tags_get_policy_module_tags ($id_policy_module){ + if (empty($id_policy_module)) + return false; + + $tags = db_get_all_rows_filter('ttag_policy_module', array('id_policy_module' => $id_policy_module), false); + + if ($tags === false) + return false; + + $return = array(); + foreach ($tags as $tag){ + $return[] = $tag['id_tag']; + } + + return $return; +} + ?>