Accéder au contenu.
Menu Sympa

devel - [Devel] Filtrage par région

Objet : devel-adl

Archives de la liste

[Devel] Filtrage par région


Chronologique Discussions 
  • From: Thomas Petazzoni <thomas.petazzoni AT enix.org>
  • To: Developpement de l'Agenda du Libre <devel AT agendadulibre.org>
  • Subject: [Devel] Filtrage par région
  • Date: Sat, 24 Sep 2005 16:34:40 +0200
  • List-archive: <http://lolut.utbm.info/pipermail/devel>
  • List-id: Developpement de l'Agenda du Libre <devel.agendadulibre.org>

Bonjour,

J'ai écrit un petit patch pour l'Agenda du Libre pour avoir le filtrage
par région. Pour cela, il y a une petite liste de sélection en bas de la
page, et dès que l'on sélectionne une région, la page est rechargée, et
seuls les évènements de la région sélectionnée sont affichés dans le
calendrier.

À votre avis, est-ce une fonctionnalité utile ? Si oui, où faut-il
placer la boîte de sélection de la région ?

Ci-joint le patch en question. Vous pouvez voir la chose en
démonstration sur http://humanoidz.org/~thomas/agenda/ (seulement
disponible aux heures normales de vie d'un geek).

Bonne journée,

Thomas
--
PETAZZONI Thomas - thomas.petazzoni AT enix.org
http://{thomas,sos,kos}.enix.org - Jabber: thomas.petazzoni AT jabber.dk
http://{agenda,livret}dulibre.org
Fingerprint : 0BE1 4CF3 CEA4 AC9D CC6E 1624 F653 CB30 98D3 F7A7
Index: index.php
===================================================================
--- index.php	(révision 101)
+++ index.php	(copie de travail)
@@ -32,6 +32,13 @@
 
 $db = new db();
 
+if ($_POST['__calendar_region'] &&
+    ($_POST['__calendar_region'] == "all" ||
+     ereg("^[0-9][0-9]?", $_POST['__calendar_region'])))
+  $region = $_POST['__calendar_region'];
+else
+$region = "all";
+
 /*
  * Compute the month to be displayed in the agenda
  */
@@ -41,7 +48,8 @@
     $year = $_GET['year'];
   else
     $year = date("Y");
-  year_calendar ($db, $year);
+
+  year_calendar ($db, $year, $region);
 }
 else if($_GET['month'] && $_GET['year'])
 {
@@ -54,14 +62,40 @@
     $year = date("Y");
     $month = date("n");
   }
-  one_month_calendar ($db, $month, $year);
+  one_month_calendar ($db, $month, $year, $region);
 }
 else
 {
   $year = date("Y");
   $month = date("n");
-  one_month_calendar ($db, $month, $year);
+  one_month_calendar ($db, $month, $year, $region);
 }
 
+echo "<p id=\"region_select\"><form name=\"region_select_form\" method=\"post\">\n";
+
+echo "<select onchange=\"document.region_select_form.submit()\" name=\"__calendar_region\">\n";
+
+$ret = $db->query ("select * from regions");
+if ($ret == FALSE)
+{
+  error ("Erreur lors de la recherche des régions");
+  put_footer();
+  exit;
+}
+
+echo "  <option value=\"all\">Toutes les régions</option>\n";
+
+while ($row = mysql_fetch_object($ret))
+{
+  if ($row->id == $region)
+    echo "  <option value=\"" . $row->id . "\" selected=\"1\">" . $row->name . "</option>\n";
+  else
+    echo "  <option value=\"" . $row->id . "\">" . $row->name . "</option>\n";
+}
+
+echo "</select>";
+
+echo "</form></p>";
+
 put_footer();
 ?>
\ No newline at end of file
Index: calendar.css
===================================================================
--- calendar.css	(révision 101)
+++ calendar.css	(copie de travail)
@@ -58,6 +58,23 @@
   text-align: justify;
 }
 
+p.#region_select
+{
+  text-align: center;
+}
+
+form
+{
+  margin: 0;
+  padding: 0;
+  text-align: center;
+}
+
+select
+{
+  border: 3px #eee solid;
+}
+
 h1 {
 	text-align: center;
 	font: 26pt georgia; 
Index: funcs.inc.php
===================================================================
--- funcs.inc.php	(révision 101)
+++ funcs.inc.php	(copie de travail)
@@ -188,7 +188,7 @@
 	      'month'  => $next_month);
 }
 
-function show_day_events ($db, $day, $month, $year)
+function show_day_events ($db, $day, $month, $year, $region)
 {
   /*
    * Compute timestamp of current day and next day. The next day is
@@ -197,10 +197,17 @@
   $cur  = mktime (0, 0, 0, $month, $day, $year);
   $next = $cur + (24 * 60 * 60);
 
-  $sql = "select * from events where
+  if ($region == "all")
+    $sql = "select * from events where
                       ((end_time >= " . $db->quote_smart(date_timestamp2mysql($cur)) . ") AND
                       (start_time <= " . $db->quote_smart(date_timestamp2mysql($next)) . ") AND
                       (moderated = 1))";
+  else
+    $sql = "select * from events where
+                      ((end_time >= " . $db->quote_smart(date_timestamp2mysql($cur)) . ") AND
+                      (start_time <= " . $db->quote_smart(date_timestamp2mysql($next)) . ") AND
+                      (moderated = 1) AND
+                      (region = " . $db->quote_smart($region) . "))";
 
   $result = $db->query ($sql);
 
@@ -223,7 +230,7 @@
     }
 }
 
-function calendar($db, $month, $year)
+function calendar($db, $month, $year, $region)
 {
   $prev = get_prev_month($month, $year);
   $prev_year  = $prev['year'];
@@ -265,7 +272,7 @@
 	      echo "   <h1>";
 	      echo $max_day_in_prev_month + $day;
 	      echo "</h1>\n";
-	      show_day_events ($db, $max_day_in_prev_month + $day, $prev_month, $prev_year);
+	      show_day_events ($db, $max_day_in_prev_month + $day, $prev_month, $prev_year, $region);
 	      echo "  </td>\n";
 	    }
 	  /* Show days of the current month */
@@ -281,7 +288,7 @@
 		echo "  <td class=\"current_month\"><h1>";
 	      echo $day;
 	      echo "</h1>\n";
-	      show_day_events ($db, $day, $month, $year);
+	      show_day_events ($db, $day, $month, $year, $region);
 	      echo "</td>\n";
 	    }
 	  /* Show days after the current month (next month) */
@@ -290,7 +297,7 @@
 	      echo "  <td class=\"other_month\"><h1>";
 	      echo $day - $max_day_in_month;
 	      echo "</h1>\n";
-	      show_day_events ($db, $day - $max_day_in_month, $next_month, $next_year);
+	      show_day_events ($db, $day - $max_day_in_month, $next_month, $next_year, $region);
 	      echo "</td>\n";
 	    }
 	  $day++;
@@ -300,7 +307,7 @@
   echo "</table>\n";
 }
 
-function one_month_calendar($db, $month, $year)
+function one_month_calendar($db, $month, $year, $region)
 {
   /*
    * Compute previous and next months
@@ -326,10 +333,10 @@
   /*
    * Display the calendar
    */
-  calendar($db, $month, $year);
+  calendar($db, $month, $year, $region);
 }
 
-function year_calendar($db, $year)
+function year_calendar($db, $year, $region)
 {
   /*
    * Display links for previous and next years
@@ -355,7 +362,7 @@
     echo " </a>\n";
     echo "</h3>\n\n";
 
-    calendar($db, $month, $year);
+    calendar($db, $month, $year, $region);
 
     $next = get_next_month($month, $year);
     $year = $next['year'];

Attachment: signature.asc
Description: OpenPGP digital signature




Archives gérées par MHonArc 2.6.16.

Haut de le page