From d72d06929ac2c5567e540d1c07727420295e871a Mon Sep 17 00:00:00 2001 From: darode Date: Thu, 28 Feb 2013 14:41:26 +0000 Subject: [PATCH] 2013-02-28 Dario Rodriguez * include/functions_api.php: Added new API function to create custom field and to get custom field ID by name. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@7748 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_console/ChangeLog | 5 ++ pandora_console/include/functions_api.php | 56 +++++++++++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index 21b79d817e..cccbca8965 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,8 @@ +2013-02-28 Dario Rodriguez + + * include/functions_api.php: Added new API function to + create custom field and to get custom field ID by name. + 2013-02-28 Miguel de Dios * operation/gis_maps/render_view.php: fixed the mysql error diff --git a/pandora_console/include/functions_api.php b/pandora_console/include/functions_api.php index da8b03020e..f9da675aa8 100644 --- a/pandora_console/include/functions_api.php +++ b/pandora_console/include/functions_api.php @@ -762,6 +762,62 @@ function api_set_new_agent($thrash1, $thrash2, $other, $thrash3) { } } +/** + * + * Creates a custom field + * + * @param string $name Custom field name + * @param boolean $display_front Flag to display custom field in agent's operation view + */ +function api_set_create_custom_field($t1, $t2, $other, $returnType) { + + if ($other['type'] == 'string') { + returnError('error_parameter', 'Error in the parameters.'); + return; + } else if ($other['type'] == 'array') { + + $name = ""; + + if ($other['data'][0] != '') { + $name = $other['data'][0]; + } else { + returnError('error_parameter', 'Custom field name required'); + return; + } + + $display_front = 0; + + if ($other['data'][1] != '') { + $display_front = $other['data'][1]; + } else { + returnError('error_parameter', 'Custom field display flag required'); + return; + } + + $result = db_process_sql_insert('tagent_custom_fields', array('name' => $name, 'display_on_front' => $display_front)); + + $data['type'] = "string"; + $data["data"] = $result; + returnData("string", $data); + } +} + +/** + * + * Returns ID of custom field zero if not exists + * + * @param string $name Custom field name + */ +function api_get_custom_field_id($t1, $t2, $other, $returnType) { + + $name = $other["data"][0]; + $id = db_get_value ('id_field', 'tagent_custom_fields', 'name', $name); + + $data['type'] = "string"; + $data["data"] = $id; + returnData("string", $data); +} + /** * Delete a agent with the name pass as parameter. *