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. *