2 * collection4 - action_show_graph.c
3 * Copyright (C) 2010 Florian octo Forster
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301 USA
21 * Florian octo Forster <ff at octo.it>
32 #include "action_show_graph.h"
35 #include "graph_ident.h"
36 #include "graph_instance.h"
37 #include "graph_list.h"
38 #include "utils_cgi.h"
41 #include <fcgi_stdio.h>
43 #define OUTPUT_ERROR(...) do { \
44 printf ("Content-Type: text/plain\n\n"); \
45 printf (__VA_ARGS__); \
49 #define MAX_SHOW_GRAPHS 10
51 struct show_graph_data_s
55 typedef struct show_graph_data_s show_graph_data_t;
57 static int show_time_selector (__attribute__((unused)) void *user_data) /* {{{ */
61 pl = param_create (/* query string = */ NULL);
62 param_set (pl, "begin", NULL);
63 param_set (pl, "end", NULL);
64 param_set (pl, "button", NULL);
66 printf ("<form action=\"%s\" method=\"get\">\n", script_name ());
68 param_print_hidden (pl);
70 printf (" <select name=\"begin\">\n"
71 " <option value=\"-3600\">Hour</option>\n"
72 " <option value=\"-86400\">Day</option>\n"
73 " <option value=\"-604800\">Week</option>\n"
74 " <option value=\"-2678400\">Month</option>\n"
75 " <option value=\"-31622400\">Year</option>\n"
77 " <input type=\"submit\" name=\"button\" value=\"Go\" />\n");
84 } /* }}} int show_time_selector */
86 static int show_instance_cb (graph_instance_t *inst, /* {{{ */
89 show_graph_data_t *data = user_data;
93 memset (descr, 0, sizeof (descr));
94 inst_describe (data->cfg, inst, descr, sizeof (descr));
95 html_escape_buffer (descr, sizeof (descr));
97 memset (params, 0, sizeof (params));
98 inst_get_params (data->cfg, inst, params, sizeof (params));
99 html_escape_buffer (params, sizeof (params));
101 printf (" <li class=\"instance\"><a href=\"%s?action=show_instance;%s\">"
103 script_name (), params, descr);
106 } /* }}} int show_instance_cb */
108 static int show_graph (void *user_data) /* {{{ */
110 show_graph_data_t *data = user_data;
112 printf ("<h2>Available instances</h2>\n");
113 printf ("<ul class=\"instance_list\">\n");
114 graph_inst_foreach (data->cfg, show_instance_cb, data);
118 } /* }}} int show_graph */
120 int action_show_graph (void) /* {{{ */
122 page_callbacks_t pg_callbacks = PAGE_CALLBACKS_INIT;
123 show_graph_data_t pg_data;
128 memset (&pg_data, 0, sizeof (pg_data));
129 pg_data.cfg = gl_graph_get_selected ();
130 if (pg_data.cfg == NULL)
131 OUTPUT_ERROR ("gl_graph_get_selected () failed.\n");
133 memset (tmp, 0, sizeof (tmp));
134 graph_get_title (pg_data.cfg, tmp, sizeof (tmp));
135 snprintf (title, sizeof (title), "Graph \"%s\"", tmp);
136 title[sizeof (title) - 1] = 0;
138 pg_callbacks.top_right = html_print_search_box;
139 pg_callbacks.middle_center = show_graph;
140 pg_callbacks.middle_right = show_time_selector;
142 html_print_page (title, &pg_callbacks, &pg_data);
145 } /* }}} int action_show_graph */
147 /* vim: set sw=2 sts=2 et fdm=marker : */