GtkListStore *lstore_persone;
gboolean selezione;
+ guint id_uffici;
+ GDateTime *when;
+
GtkWindow *wtransient;
};
* Returns: the newly created #OrganigrammaPersone object.
*/
OrganigrammaPersone
-*organigramma_persone_new (OrganigrammaCommons *commons, gboolean selezione)
+*organigramma_persone_new (OrganigrammaCommons *commons, gboolean selezione,
+ guint id_uffici, GDateTime *when)
{
GError *error;
priv->commons = commons;
priv->selezione = selezione;
+ priv->id_uffici = id_uffici;
+ if (when != NULL)
+ {
+ priv->when = g_date_time_ref (when);
+ }
+ else
+ {
+ priv->when = NULL;
+ }
error = NULL;
gtk_builder_add_objects_from_file (priv->commons->gtkbuilder, priv->commons->guifile,
GtkTreeIter iter;
gchar *sql;
+ gchar *sql_join;
+ gchar *sql_where;
+
GdaDataModel *dm;
gint rows;
gtk_list_store_clear (priv->lstore_persone);
- sql = g_strdup_printf ("SELECT c.id, c.cognome || ' ' || c.nome AS cognome_nome"
- " FROM persone AS c"
- " WHERE c.status <> 'E'"
- " ORDER BY c.cognome, c.nome");
+ sql_where = g_strdup ("");
+ sql_join = g_strdup ("");
+ if (priv->id_uffici > 0)
+ {
+ sql_join = g_strconcat (sql_join,
+ " LEFT JOIN persona_uffici AS pu"
+ " ON p.id = pu.id_persone",
+ NULL);
+ sql_where = g_strconcat (sql_where,
+ g_strdup_printf (" AND pu.id_uffici = %d", priv->id_uffici),
+ NULL);
+ if (priv->when != NULL)
+ {
+ sql_where = g_strconcat (sql_where,
+ g_strdup_printf (" AND pu.da_data <= '%s'"
+ " AND (pu.a_data IS NULL OR pu.a_data >= '%s')",
+ solipa_gdatetime_format (priv->when, "%F"),
+ solipa_gdatetime_format (priv->when, "%F")),
+ NULL);
+ }
+ else
+ {
+ sql_where = g_strconcat (sql_where,
+ g_strdup_printf (" AND pu.da_data <= '%s'"
+ " AND (pu.a_data IS NULL OR pu.a_data >= '%s')",
+ solipa_gdatetime_format (g_date_time_new_now_local (), "%F"),
+ solipa_gdatetime_format (g_date_time_new_now_local (), "%F")),
+ NULL);
+ }
+ }
+
+ sql = g_strdup_printf ("SELECT p.id, p.cognome || ' ' || p.nome AS cognome_nome"
+ " FROM persone AS p"
+ "%s"
+ " WHERE p.status <> 'E'"
+ "%s"
+ " ORDER BY p.cognome, p.nome",
+ sql_join,
+ sql_where);
dm = gdaex_query (priv->commons->gdaex, sql);
+ g_free (sql_join);
+ g_free (sql_where);
g_free (sql);
if (dm != NULL)
{