From e30b28cb017222c8c3ee6bd739e154d13686bff0 Mon Sep 17 00:00:00 2001
From: "Committo,Ergo:sum" <esj@rezo.net>
Date: Wed, 17 Aug 2005 10:41:07 +0000
Subject: [PATCH] =?UTF-8?q?nouveau=20filtre=20agenda=5Faffiche=20permettan?=
 =?UTF-8?q?t=20la=20diff=C3=A9renciation=20de=20couleur=20et=20am=C3=A9lio?=
 =?UTF-8?q?rant=20la=20lisibilit=C3=A9=20des=20filtres=20de=20calendriers?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 dist/jour.html            | 14 +++++-----
 dist/mois.html            | 12 ++++----
 dist/semaine.html         | 14 +++++-----
 ecrire/inc_calendrier.php | 17 ++++++-----
 ecrire/inc_filtres.php3   | 59 +++++++++++++++++++++++++--------------
 5 files changed, 65 insertions(+), 51 deletions(-)

diff --git a/dist/jour.html b/dist/jour.html
index 07c0847989..b60d12e810 100644
--- a/dist/jour.html
+++ b/dist/jour.html
@@ -1,8 +1,8 @@
 <BOUCLE_jour(ARTICLES)
-    {agenda date, jour, #ENV{annee}, #ENV{mois}, #ENV{jour}}>[
-(#DATE|agenda_memo{#DESCRIPTIF, #TITRE, #URL_ARTICLE, 'calendrier-couleur1'})
-]</BOUCLE_jour>
-[(#DATE|agenda_memo{'', '', '', 'calendrier-couleur1', 'jour'})]
-</B_jour>
-<:aucun_article:>
-<//B_jour>
\ No newline at end of file
+    {agenda date, jour, #ENV{annee}, #ENV{mois}, #ENV{jour}}{par date}
+>[(#DATE|agenda_memo{#DESCRIPTIF, #TITRE, #URL_ARTICLE, 
+  [(#COMPTEUR_BOUCLE|
+	alterner{'calendrier-couleur1', 'calendrier-couleur3'})]})]</BOUCLE_jour>[(#TOTAL_BOUCLE|
+	agenda_affiche{'jour', 'calendrier-couleur1', 'calendrier-couleur3'}
+)][(#TOTAL_BOUCLE|
+	choixsivide{<:aucun_article:>,''})]<//B_jour>
\ No newline at end of file
diff --git a/dist/mois.html b/dist/mois.html
index f9b6c8283f..5125be6fa5 100644
--- a/dist/mois.html
+++ b/dist/mois.html
@@ -1,8 +1,6 @@
 <BOUCLE_mois(ARTICLES)
-    {agenda date, mois, #ENV{annee}, #ENV{mois}}>[
-(#DATE|agenda_memo{#DESCRIPTIF, #TITRE, #URL_ARTICLE, 'calendrier-couleur3'})
-]</BOUCLE_mois>
-[(#DATE|agenda_memo{'', '', '','calendrier-couleur3', 'mois'})]
-</B_mois>
-<:aucun_article:>
-<//B_mois>
\ No newline at end of file
+    {agenda date, mois, #ENV{annee}, #ENV{mois}}{par date}>[
+(#DATE|agenda_memo{#DESCRIPTIF, #TITRE, #URL_ARTICLE,'calendrier-couleur5'})]</BOUCLE_mois>[(#TOTAL_BOUCLE|
+	agenda_affiche{'mois', 'calendrier-couleur5'}
+)][(#TOTAL_BOUCLE|
+	choixsivide{<:aucun_article:>,''})]<//B_mois>
\ No newline at end of file
diff --git a/dist/semaine.html b/dist/semaine.html
index 17ade5ae11..7e87bc01fa 100644
--- a/dist/semaine.html
+++ b/dist/semaine.html
@@ -1,8 +1,8 @@
 <BOUCLE_semaine(ARTICLES)
-    {agenda date, semaine, #ENV{annee}, #ENV{mois}, #ENV{jour}}>[
-(#DATE|agenda_memo{#DESCRIPTIF, #TITRE, #URL_ARTICLE, 'calendrier-couleur2'})
-]</BOUCLE_semaine>
-[(#DATE|agenda_memo{'', '', '', 'calendrier-couleur2', 'semaine'})]
-</B_semaine>
-<:aucun_article:>
-<//B_semaine>
+    {agenda date, semaine, #ENV{annee}, #ENV{mois}, #ENV{jour}}{par date}
+>[(#DATE|agenda_memo{#DESCRIPTIF, #TITRE, #URL_ARTICLE,
+  [(#COMPTEUR_BOUCLE|
+	alterner{'calendrier-couleur2', 'calendrier-couleur4'})]})]</BOUCLE_semaine>[(#TOTAL_BOUCLE|
+	agenda_affiche{'semaine', 'calendrier-couleur2','calendrier-couleur4'}
+)][(#TOTAL_BOUCLE|
+	choixsivide{<:aucun_article:>,''})]<//B_semaine>
diff --git a/ecrire/inc_calendrier.php b/ecrire/inc_calendrier.php
index 038821d7be..e96f467626 100644
--- a/ecrire/inc_calendrier.php
+++ b/ecrire/inc_calendrier.php
@@ -298,6 +298,7 @@ function http_calendrier_mois_sept($annee, $mois, $premier_jour, $dernier_jour,$
 
 	$total = '';
 	$ligne = '';
+	$today=date("Ymd");
 	for ($j=$premier_jour; $j<=$dernier_jour; $j++){
 		$nom = mktime(1,1,1,$mois,$j,$annee);
 		$jour = date("d",$nom);
@@ -315,20 +316,18 @@ function http_calendrier_mois_sept($annee, $mois, $premier_jour, $dernier_jour,$
 			    $ligne = $init = '';
 			  }
 		
-		if ($amj == date("Ymd")) {
+		if ($amj == $today) {
 			$couleur_lien = "red";
 			$couleur_fond = "white";
 		}
-		$evts = $evenements[$amj];
-		if ($evts) {
-		  $res = '';
+		$res = '';
+		if ($evts = $evenements[$amj]) {
 		  foreach ($evts as $evenement)
 		    {
 		      $res .= isset($evenement['DTSTART']) ?
 			http_calendrier_avec_heure($evenement, $amj) :
 			http_calendrier_sans_heure($evenement);
 		    }
-		  $evts = $res;
 		}
 
 		$ligne .= "\n\t\t<td\tclass='calendrier-td'
@@ -338,7 +337,7 @@ function http_calendrier_mois_sept($annee, $mois, $premier_jour, $dernier_jour,$
 		   " border-$spip_lang_left: 1px solid $couleur_claire;") .
 		  "'>" .
 		  http_calendrier_mois_clics($annee_en_cours, $mois_en_cours, $jour, $script, $ancre, $couleur_lien) .
-		  $evts .
+		  $res .
 		  "\n\t</td>";
 	}
 	return  $total . ($ligne ? "\n<tr>$ligne\n</tr>" : '');
@@ -705,9 +704,9 @@ function http_calendrier_ics_grille($debut, $fin, $dimheure, $dimjour, $fontsize
 	for ($i = $debut; $i < $fin; $i++) {
 		for ($j=0; $j < $slice; $j++) 
 		{
-			$gras = "calendrier-heure" . ($j  ? "face" : "pile");
-			
-			$total .= "\n<div class='$gras' style='$spip_lang_left: 0px; top: ".
+			$total .= "\n<div class='calendrier-heure" .
+				($j  ? "face" : "pile") .
+				"' style='$spip_lang_left: 0px; top: ".
 				calendrier_top ("$i:".sprintf("%02d",floor(($j*60)/$slice)), $debut, $fin, $dimheure, $dimjour, $fontsize) .
 				"px;'>$i:" .
 				sprintf("%02d",floor(($j*60)/$slice)) . 
diff --git a/ecrire/inc_filtres.php3 b/ecrire/inc_filtres.php3
index 6125ac535a..26dbb38f4c 100644
--- a/ecrire/inc_filtres.php3
+++ b/ecrire/inc_filtres.php3
@@ -715,46 +715,63 @@ function agenda_connu($type)
   return in_array($type, array('jour','mois','semaine','periode')) ? ' ' : '';
 }
 
-// A chaque appel de moins 5 arguments,cette fonction memorise un evenement
-// decrit par une date, un descriptif, un titre et une URL. 
-// A l'appel avec 6 arguments, l'ensemble sera mis en page selon le type
-// indique par le 6e argument et le style CSS indiquee par le 5e 
-// Ce 5e argument sert aussi d'index de memorisation
-// pour avoir plusieurs calendriers dans une meme page sans interferences
 
+// Cette fonction memorise dans un tableau indexe par son 5e arg
+// un evenement decrit par les 4 autres (date, descriptif, titre, URL). 
+// Appellee avec une date nulle, elle renvoie le tableau construit.
+// l'indexation par le 5e arg autorise plusieurs calendriers dans une page
 
-function agenda_memo($date='', $descriptif='', $titre='', $url='', $cal='', $type='')
+function agenda_memo($date=0 , $descriptif='', $titre='', $url='', $cal='')
 {
   static $agenda = array();
-  if (!$type)
-    {
-      $idate = date_ical($date);
-      $agenda[$cal][(date_anneemoisjour($date))][] =  array(
+  if (!$date) return $agenda;
+  $idate = date_ical($date);
+  $cal = trim($cal); // func_get_args (filtre alterner) rajoute \n !!!!
+  $agenda[$cal][(date_anneemoisjour($date))][] =  array(
 			'CATEGORIES' => $cal,
 			'DTSTART' => $idate,
 			'DTEND' => $idate,
                         'DESCRIPTION' => texte_script($descriptif),
                         'SUMMARY' => texte_script($titre),
                         'URL' => $url);
-    // signifier qu'il y a qqch
-      return " ";
-  }  else {
-    if ($type != 'periode')
-      $evt = array('', $agenda[$cal]);
-    else
+  // toujours retourner vide pour qu'il ne se passe rien
+  return "";
+}
+
+// Cette fonction recoit un nombre d'evenements, un type de calendriers
+// et une suite de noms N.
+// Elle demande a la fonction la precedente son tableau
+// et affiche selon le type les elements indexes par N dans ce tableau.
+// Ces noms N sont aussi des classes CSS utilisees par http_calendrier_init
+
+function agenda_affiche($i)
+{
+  $args = func_get_args();
+  $nb = array_shift($args); // nombre d'evenements (on pourrait l'afficher)
+  if (!$nb) return "";
+  $type = array_shift($args);
+  $agenda = agenda_memo(0);
+  $evt = array();
+  foreach ($args as $k) {  
+      if (is_array($agenda[$k]))
+	foreach($agenda[$k] as $d => $v) { 
+	  $evt[$d] = $evt[$d] ? (array_merge($evt[$d], $v)) : $v;
+	}
+  }
+  if ($type != 'periode')
+      $evt = array('', $evt);
+  else
       {
-	$d = array_keys($agenda[$cal]);
+	$d = array_keys($evt);
 	$mindate = min($d);
 	$min = substr($mindate,6,2);
 	$max = $min + ((strtotime(max($d)) - strtotime($mindate)) / (3600 * 24));
 	if ($max < 31) $max = 0;
-	$evt = array('', $agenda[$cal], $min, $max);
+	$evt = array('', $evt, $min, $max);
 	$type = 'mois';
       }
     include('ecrire/inc_calendrier.php');
     return http_calendrier_init('', $type, '', '', '', $evt);
-    }
-
 }
 
 //
-- 
GitLab