Accéder au contenu.
Menu Sympa

devel - [Devel] [MyFirstPatch] calendrier annuel

Objet : devel-adl

Archives de la liste

[Devel] [MyFirstPatch] calendrier annuel


Chronologique Discussions 
  • From: David MENTRE <dmentre AT linux-france.org>
  • To: devel AT agendadulibre.org
  • Subject: [Devel] [MyFirstPatch] calendrier annuel
  • Date: Wed, 06 Jul 2005 22:59:04 +0200
  • List-archive: <http://lolut.utbm.info/pipermail/devel>
  • List-id: Developpement de l'Agenda du Libre <devel.agendadulibre.org>
  • Organization: none

Bonjour Mélanie et Thomas,

Ci-joint un patch pour l'agenda qui permet d'afficher un calendrier
annuel : les 12 mois à partir du mois en cours.

Grosso modo, j'ai déplacé votre code dans one_month_calendar() et
ajouter une fonction year_calendar(), avec l'appel qui va bien dans
index.php.

Comme c'est ma première contribution en PHP et HTML, n'hésitez pas à
critiquer le code. :-)

diff -ru -x '*~' trunk/calendar.css agenda/calendar.css
--- trunk/calendar.css 2005-06-30 21:00:26.000000000 +0200
+++ agenda/calendar.css 2005-07-06 22:32:03.499806032 +0200
@@ -52,6 +52,10 @@
text-align: center;
}

+h3 {
+ text-align: center;
+}
+
a:link, a:visited {
font-weight: bold;
text-decoration: none;
diff -ru -x '*~' trunk/funcs.inc.php agenda/funcs.inc.php
--- trunk/funcs.inc.php 2005-06-30 21:00:26.000000000 +0200
+++ agenda/funcs.inc.php 2005-07-06 22:43:45.716052936 +0200
@@ -271,6 +271,70 @@
echo "</table>\n";
}

+function one_month_calendar($db, $month, $year)
+{
+ /*
+ * Compute previous and next months
+ */
+ $next = get_next_month($month, $year);
+ $next_year = $next['year'];
+ $next_month = $next['month'];
+
+ $prev = get_prev_month($month, $year);
+ $prev_year = $prev['year'];
+ $prev_month = $prev['month'];
+
+ /*
+ * Display links for previous and next months
+ */
+ echo "<h2>\n";
+ echo " <a href=\"?year=".$prev_year."&amp;month=".$prev_month."\">
&lt;&lt; </a>\n";
+ echo " <span id=\"month_name\">".date_month2string($month)." ";
+ echo " <a href=\"?year=".$year."\">".$year."</a>"."</span>\n";
+ echo " <a href=\"?year=".$next_year."&amp;month=".$next_month."\">
&gt;&gt; </a>\n";
+ echo "</h2>\n\n";
+
+ /*
+ * Display the calendar
+ */
+ calendar($db, $month, $year);
+}
+
+function year_calendar($db, $year)
+{
+ /*
+ * Display links for previous and next years
+ */
+ $next_year = $year + 1;
+ $prev_year = $year - 1;
+ echo "<h2>\n";
+ echo " <a href=\"?year=".$prev_year."\"> &lt;&lt; </a>\n";
+ echo " <span id=\"month_name\">".$year."</span>\n";
+ echo " <a href=\"?year=".$next_year."\"> &gt;&gt; </a>\n";
+ echo "</h2>\n\n";
+
+ /*
+ * Display the calendar over 12 months starting from current one
+ */
+ $num = 0;
+ $month = date("n");
+ while ($num < 12) {
+ // month header, with a link to the single month on a page
+ echo "<h3>\n";
+ echo " <a href=\"?year=".$year."&amp;month=".$month."\">\n";
+ echo " <span id=\"month_name\">".date_month2string($month)."
".$year."</span>\n";
+ echo " </a>\n";
+ echo "</h3>\n\n";
+
+ calendar($db, $month, $year);
+
+ $next = get_next_month($month, $year);
+ $year = $next['year'];
+ $month = $next['month'];
+ $num++;
+ }
+}
+
function fetch_event($db, $id)
{
$result = $db->query ("select * from events where id=" .
$db->quote_smart($id));
diff -ru -x '*~' trunk/index.php agenda/index.php
--- trunk/index.php 2005-06-30 21:00:26.000000000 +0200
+++ agenda/index.php 2005-07-06 22:54:24.891883440 +0200
@@ -33,43 +33,26 @@
$db = new db();

/*
- * Compute the month to be displayed in the agenda
+ * Depending on URL type, display the requested agenda
*/
-if($_GET['month'] && $_GET['year'])
+if($_GET['year'] && !$_GET['month'])
+{
+ $year = $_GET['year'];
+ year_calendar($db, $year);
+}
+else if($_GET['month'] && $_GET['year'])
{
$month = $_GET['month'];
$year = $_GET['year'];
+ one_month_calendar($db, $month, $year);
}
else
{
$year = date("Y");
$month = date("n");
+ one_month_calendar($db, $month, $year);
}

-/*
- * Compute previous and next months
- */
-$next = get_next_month($month, $year);
-$next_year = $next['year'];
-$next_month = $next['month'];
-
-$prev = get_prev_month($month, $year);
-$prev_year = $prev['year'];
-$prev_month = $prev['month'];
-
-/*
- * Display links for previous and next months
- */
-echo "<h2>\n";
-echo " <a href=\"?year=".$prev_year."&amp;month=".$prev_month."\"> &lt;&lt;
</a>\n";
-echo " <span id=\"month_name\">". date_month2string($month)."
".$year."</span>\n";
-echo " <a href=\"?year=".$next_year."&amp;month=".$next_month."\"> &gt;&gt;
</a>\n";
-echo "</h2>\n\n";
-
-/*
- * Display the calendar
- */
-calendar($db, $month, $year);

put_footer();
-?>
\ No newline at end of file
+?>


Amicalement,
d.
--
pub 1024D/A3AD7A2A 2004-10-03 David MENTRE <dmentre AT linux-france.org>
5996 CC46 4612 9CA4 3562 D7AC 6C67 9E96 A3AD 7A2A





  • [Devel] [MyFirstPatch] calendrier annuel, David MENTRE, 06/07/2005

Archives gérées par MHonArc 2.6.16.

Haut de le page