From: Andrea Zagli Date: Sat, 30 Jan 2016 12:18:14 +0000 (+0100) Subject: Draft of ticket saving. X-Git-Url: https://saetta.ns0.it/gitweb?a=commitdiff_plain;h=147c3a77ad6f99e22b5f0690d997b3cd61ed6e23;p=bcity%2Ffe Draft of ticket saving. --- diff --git a/data/bcity_fe/ctpl/Makefile.am b/data/bcity_fe/ctpl/Makefile.am index 36e4598..7b71168 100644 --- a/data/bcity_fe/ctpl/Makefile.am +++ b/data/bcity_fe/ctpl/Makefile.am @@ -3,6 +3,8 @@ ctpldir = $(datadir)/$(PACKAGE)/ctpl ctpl_DATA = \ template.ctpl \ index_index.ctpl \ + index_category.ctpl \ + index_save.ctpl \ login_index.ctpl EXTRA_DIST = diff --git a/data/bcity_fe/ctpl/index_category.ctpl b/data/bcity_fe/ctpl/index_category.ctpl new file mode 100644 index 0000000..9b38d85 --- /dev/null +++ b/data/bcity_fe/ctpl/index_category.ctpl @@ -0,0 +1,7 @@ +

B-City

+ +

Selezionare la categoria della segnalazione

+ +
+ +
\ No newline at end of file diff --git a/data/bcity_fe/ctpl/index_index.ctpl b/data/bcity_fe/ctpl/index_index.ctpl index afa0f4a..6a7fbf7 100644 --- a/data/bcity_fe/ctpl/index_index.ctpl +++ b/data/bcity_fe/ctpl/index_index.ctpl @@ -2,7 +2,8 @@
-
+ +
\ No newline at end of file diff --git a/data/bcity_fe/ctpl/index_save.ctpl b/data/bcity_fe/ctpl/index_save.ctpl new file mode 100644 index 0000000..0b0655b --- /dev/null +++ b/data/bcity_fe/ctpl/index_save.ctpl @@ -0,0 +1,7 @@ +

B-City

+ +

La segnalazione inserita è stata salvata correttamente e inviata all'ufficio competente

+ +
+ +
\ No newline at end of file diff --git a/doc/bcity_fe/db/bcity_fe.sql b/doc/bcity_fe/db/bcity_fe.sql index 3fa46c1..bf14ecb 100644 --- a/doc/bcity_fe/db/bcity_fe.sql +++ b/doc/bcity_fe/db/bcity_fe.sql @@ -13,6 +13,30 @@ SET check_function_bodies = false; SET client_min_messages = warning; SET row_security = off; +SET search_path = public, pg_catalog; + +SET default_with_oids = false; + +-- +-- Name: segnalazioni; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE segnalazioni ( + id integer NOT NULL, + utente character varying(255) DEFAULT ''::character varying, + latitudine double precision, + longitudine double precision +); + + +-- +-- Name: segnalazioni_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY segnalazioni + ADD CONSTRAINT segnalazioni_pkey PRIMARY KEY (id); + + -- -- PostgreSQL database dump complete -- diff --git a/src/index.c b/src/index.c index 16ebd01..75f4834 100644 --- a/src/index.c +++ b/src/index.c @@ -105,3 +105,101 @@ index_index (GMatchInfo *minfo, gpointer user_data) g_free (head); g_free (content); } + +void +index_category (GMatchInfo *minfo, gpointer user_data) +{ + CtplEnviron *env; + + gchar *filename; + gchar *content; + + Commons *commons = (Commons *)user_data; + + if (!get_is_logged (commons)) + { + zak_cgi_main_redirect (commons->zcgi_main, "/bcity/bcity_fe/login/index"); + return; + } + + if (zak_cgi_main_is_post (commons->zcgi_main)) + { + zak_cgi_session_set_value (commons->zcgi_session, "latitudine", g_value_get_string (zak_cgi_main_get_stdin_field (commons->zcgi_main, "lat"))); + zak_cgi_session_set_value (commons->zcgi_session, "longitudine", g_value_get_string (zak_cgi_main_get_stdin_field (commons->zcgi_main, "lng"))); + + filename = g_build_filename (commons->ctpldir, "index_category.ctpl", NULL); + content = get_ctpl_filled (filename, NULL); + g_free (filename); + + env = ctpl_environ_new (); + ctpl_environ_push_string (env, "head", ""); + ctpl_environ_push_string (env, "body_tag", ""); + ctpl_environ_push_string (env, "body", content); + + filename = g_build_filename (commons->ctpldir, "template.ctpl", NULL); + g_string_printf (commons->out, "%s", + get_ctpl_filled (filename, env)); + g_free (filename); + + g_free (content); + } + else + { + zak_cgi_main_redirect (commons->zcgi_main, "/bcity/bcity_fe/index/index"); + } +} + +void +index_save (GMatchInfo *minfo, gpointer user_data) +{ + CtplEnviron *env; + + gchar *filename; + gchar *content; + + Commons *commons = (Commons *)user_data; + + if (!get_is_logged (commons)) + { + zak_cgi_main_redirect (commons->zcgi_main, "/bcity/bcity_fe/login/index"); + return; + } + + if (zak_cgi_main_is_post (commons->zcgi_main)) + { + guint newid; + gchar *sql; + + newid = gdaex_get_new_id(commons->gdaex, "segnalazioni", "id", NULL); + + sql = g_strdup_printf ("INSERT INTO segnalazioni" + " (id, utente, latitudine, longitudine)" + " VALUES (%d, '%s', %s, %s)", + newid, + zak_cgi_session_get_value (commons->zcgi_session, "username"), + zak_cgi_session_get_value (commons->zcgi_session, "latitudine"), + zak_cgi_session_get_value (commons->zcgi_session, "longitudine")); + gdaex_execute (commons->gdaex, sql); + g_free (sql); + + filename = g_build_filename (commons->ctpldir, "index_save.ctpl", NULL); + content = get_ctpl_filled (filename, NULL); + g_free (filename); + + env = ctpl_environ_new (); + ctpl_environ_push_string (env, "head", ""); + ctpl_environ_push_string (env, "body_tag", ""); + ctpl_environ_push_string (env, "body", content); + + filename = g_build_filename (commons->ctpldir, "template.ctpl", NULL); + g_string_printf (commons->out, "%s", + get_ctpl_filled (filename, env)); + g_free (filename); + + g_free (content); + } + else + { + zak_cgi_main_redirect (commons->zcgi_main, "/bcity/bcity_fe/index/index"); + } +} diff --git a/src/index.h b/src/index.h index 07c7cb6..e37235e 100644 --- a/src/index.h +++ b/src/index.h @@ -28,6 +28,8 @@ void index_index (GMatchInfo *minfo, gpointer user_data); +void index_category (GMatchInfo *minfo, gpointer user_data); +void index_save (GMatchInfo *minfo, gpointer user_data); #endif /* __INDEX_H__ */ diff --git a/src/main.c b/src/main.c index acc2f29..d0bc0dd 100644 --- a/src/main.c +++ b/src/main.c @@ -96,6 +96,8 @@ main (int argc, char *argv[]) zak_cgi_url_connect (zcgi_url, "/", (ZakCgiUrlConnectedFunction)index_index, commons); zak_cgi_url_connect (zcgi_url, "/index[/]?", (ZakCgiUrlConnectedFunction)index_index, commons); zak_cgi_url_connect (zcgi_url, "/index/index", (ZakCgiUrlConnectedFunction)index_index, commons); + zak_cgi_url_connect (zcgi_url, "/index/category", (ZakCgiUrlConnectedFunction)index_category, commons); + zak_cgi_url_connect (zcgi_url, "/index/save", (ZakCgiUrlConnectedFunction)index_save, commons); zak_cgi_url_connect (zcgi_url, "/login[/]?", (ZakCgiUrlConnectedFunction)login_index, commons); zak_cgi_url_connect (zcgi_url, "/login/index", (ZakCgiUrlConnectedFunction)login_index, commons);