From 1706c1f9fded83a17d560685a0e9141cbcecdc05 Mon Sep 17 00:00:00 2001 From: darode Date: Tue, 2 Apr 2013 16:49:43 +0000 Subject: [PATCH] 2013-04-02 Dario Rodriguez * include/functions_api.php: New function to create a tag via API. * include/functions_tags.php: Create tag only if not exists. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@7916 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_console/ChangeLog | 6 ++++ pandora_console/include/functions_api.php | 34 ++++++++++++++++++++++ pandora_console/include/functions_tags.php | 5 ++++ 3 files changed, 45 insertions(+) diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index 4e5ee94cac..140e319f85 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,9 @@ +2013-04-02 Dario Rodriguez + + * include/functions_api.php: New function to create a tag + via API. + * include/functions_tags.php: Create tag only if not exists. + 2013-04-02 Mario Pulido * include/help/en/help_inventory_tab.php, diff --git a/pandora_console/include/functions_api.php b/pandora_console/include/functions_api.php index b7eea32d3c..186188c3aa 100644 --- a/pandora_console/include/functions_api.php +++ b/pandora_console/include/functions_api.php @@ -5698,6 +5698,40 @@ function api_get_event_info($id_event, $trash1, $trash, $returnType) { return; } +//http://127.0.0.1/pandora_console/include/api.php?op=set&op2=create_tag&other=tag_name|tag_description|tag_url|tag_email&other_mode=url_encode_separator_|&apipass=1234&user=admin&pass=pandora +function api_set_create_tag ($id, $trash1, $other, $returnType) { + + $data = array(); + + if ($other['type'] == 'string') { + $data["name"] = $other["data"]; + } else if ($other['type'] == 'array') { + + $data['name'] = $other["data"][0]; + + if ($other["data"][1] != '') { + $data['description'] = $other["data"][1]; + } else { + $data['description'] = ""; + } + + if ($other["data"][1] != '') { + $data['url'] = $other["data"][2]; + } else { + $data['url'] = ""; + } + + if ($other["data"][1] != '') { + $data['email'] = $other["data"][3]; + } else { + $data['email'] = ''; + } + } + + tags_create_tag ($data); +} + + //http://127.0.0.1/pandora_console/include/api.php?op=set&op2=create_event&id=name_event&other=2|system|3|admin|2|1|10|0|comments||Pandora||critical_inst|warning_inst|unknown_inst|other&other_mode=url_encode_separator_|&apipass=1234&user=admin&pass=pandora function api_set_create_event($id, $trash1, $other, $returnType) { diff --git a/pandora_console/include/functions_tags.php b/pandora_console/include/functions_tags.php index 23dd102599..958be23b09 100644 --- a/pandora_console/include/functions_tags.php +++ b/pandora_console/include/functions_tags.php @@ -197,6 +197,11 @@ function tags_create_tag($values) { if (empty($values)) { return false; } + + //No create tag if the tag exists + if (tags_get_id($values["name"])) { + return false; + } return db_process_sql_insert('ttag',$values); }