[PLUGINS] +clavettes et dependances
[lhc/web/clavette_www.git] / www / plugins / agenda_3_5 / inc / agenda_filtres.php
1 <?php
2 /**
3 * Plugin Agenda 4 pour Spip 3.0
4 * Licence GPL 3
5 *
6 * 2006-2011
7 * Auteurs : cf paquet.xml
8 */
9
10 if (!defined("_ECRIRE_INC_VERSION")) return;
11
12
13 /**
14 * Filtres&criteres deprecies/obsoletes
15 */
16
17
18 /**
19 * {agendafull ..} variante etendue du crietre agenda du core
20 * qui accepte une date de debut et une date de fin
21 *
22 * {agendafull date_debut, date_fin, jour, #ENV{annee}, #ENV{mois}, #ENV{jour}}
23 * {agendafull date_debut, date_fin, semaine, #ENV{annee}, #ENV{mois}, #ENV{jour}}
24 * {agendafull date_debut, date_fin, mois, #ENV{annee}, #ENV{mois}}
25 * {agendafull date_debut, date_fin, periode, #ENV{annee}, #ENV{mois}, #ENV{jour},
26 * #ENV{annee_fin}, #ENV{mois_fin}, #ENV{jour_fin}}
27 *
28 * @param string $idb
29 * @param object $boucles
30 * @param object $crit
31 */
32 function critere_agendafull_dist($idb, &$boucles, $crit)
33 {
34 $params = $crit->param;
35
36 if (count($params) < 1)
37 erreur_squelette(_T('zbug_info_erreur_squelette'),
38 "{agenda ?} BOUCLE$idb");
39
40 $parent = $boucles[$idb]->id_parent;
41
42 // les valeurs $date et $type doivent etre connus a la compilation
43 // autrement dit ne pas etre des champs
44
45 $date_deb = array_shift($params);
46 $date_deb = $date_deb[0]->texte;
47
48 $date_fin = array_shift($params);
49 $date_fin = $date_fin[0]->texte;
50
51 $type = array_shift($params);
52 $type = $type[0]->texte;
53
54 $annee = $params ? array_shift($params) : "";
55 $annee = "\n" . 'sprintf("%04d", ($x = ' .
56 calculer_liste($annee, array(), $boucles, $parent) .
57 ') ? $x : date("Y"))';
58
59 $mois = $params ? array_shift($params) : "";
60 $mois = "\n" . 'sprintf("%02d", ($x = ' .
61 calculer_liste($mois, array(), $boucles, $parent) .
62 ') ? $x : date("m"))';
63
64 $jour = $params ? array_shift($params) : "";
65 $jour = "\n" . 'sprintf("%02d", ($x = ' .
66 calculer_liste($jour, array(), $boucles, $parent) .
67 ') ? $x : date("d"))';
68
69 $annee2 = $params ? array_shift($params) : "";
70 $annee2 = "\n" . 'sprintf("%04d", ($x = ' .
71 calculer_liste($annee2, array(), $boucles, $parent) .
72 ') ? $x : date("Y"))';
73
74 $mois2 = $params ? array_shift($params) : "";
75 $mois2 = "\n" . 'sprintf("%02d", ($x = ' .
76 calculer_liste($mois2, array(), $boucles, $parent) .
77 ') ? $x : date("m"))';
78
79 $jour2 = $params ? array_shift($params) : "";
80 $jour2 = "\n" . 'sprintf("%02d", ($x = ' .
81 calculer_liste($jour2, array(), $boucles, $parent) .
82 ') ? $x : date("d"))';
83
84 $boucle = &$boucles[$idb];
85 $date = $boucle->id_table . ".$date";
86
87 $quote_end = ",'".$boucle->sql_serveur."','text'";
88
89 if ($type == 'jour')
90 $boucle->where[]= array("'AND'",
91 array("'<='", "'DATE_FORMAT($date_deb, \'%Y%m%d\')'",("sql_quote($annee . $mois . $jour$quote_end)")),
92 array("'>='", "'DATE_FORMAT($date_fin, \'%Y%m%d\')'",("sql_quote($annee . $mois . $jour$quote_end)")));
93 elseif ($type == 'mois')
94 $boucle->where[]= array("'AND'",
95 array("'<='", "'DATE_FORMAT($date_deb, \'%Y%m\')'",("sql_quote($annee . $mois$quote_end)")),
96 array("'>='", "'DATE_FORMAT($date_fin, \'%Y%m\')'",("sql_quote($annee . $mois$quote_end)")));
97 elseif ($type == 'semaine')
98 $boucle->where[]= array("'AND'",
99 array("'>='",
100 "'DATE_FORMAT($date_fin, \'%Y%m%d\')'",
101 ("date_debut_semaine($annee, $mois, $jour)")),
102 array("'<='",
103 "'DATE_FORMAT($date_deb, \'%Y%m%d\')'",
104 ("date_fin_semaine($annee, $mois, $jour)")));
105 elseif (count($crit->param) > 3)
106 $boucle->where[]= array("'AND'",
107 array("'>='",
108 "'DATE_FORMAT($date_fin, \'%Y%m%d\')'",
109 ("sql_quote($annee . $mois . $jour$quote_end)")),
110 array("'<='", "'DATE_FORMAT($date_deb, \'%Y%m%d\')'", ("sql_quote($annee2 . $mois2 . $jour2$quote_end)")));
111 // sinon on prend tout
112 }
113
114
115 /**
116 * Afficher de facon textuelle les dates de debut et fin en fonction des cas
117 * - Le lundi 20 fevrier a 18h
118 * - Le 20 fevrier de 18h a 20h
119 * - Du 20 au 23 fevrier
120 * - du 20 fevrier au 30 mars
121 * - du 20 fevrier 2007 au 30 mars 2008
122 * $horaire='oui' permet d'afficher l'horaire, toute autre valeur n'indique que le jour
123 * $forme peut contenir abbr (afficher le nom des jours en abbrege) et ou hcal (generer une date au format hcal)
124 *
125 * @param string $date_debut
126 * @param string $date_fin
127 * @param string $horaire
128 * @param string $forme
129 * @return string
130 */
131 function agenda_affdate_debut_fin($date_debut, $date_fin, $horaire = 'oui', $forme=''){
132 $abbr = '';
133 if (strpos($forme,'abbr')!==false) $abbr = 'abbr';
134 $affdate = "affdate_jourcourt";
135 if (strpos($forme,'annee')!==false) $affdate = 'affdate';
136
137 $dtstart = $dtend = $dtabbr = "";
138 if (strpos($forme,'hcal')!==false) {
139 $dtstart = "<abbr class='dtstart' title='".date_iso($date_debut)."'>";
140 $dtend = "<abbr class='dtend' title='".date_iso($date_fin)."'>";
141 $dtabbr = "</abbr>";
142 }
143
144 $date_debut = strtotime($date_debut);
145 $date_fin = strtotime($date_fin);
146 $d = date("Y-m-d", $date_debut);
147 $f = date("Y-m-d", $date_fin);
148 $h = $horaire=='oui';
149 $hd = date("H:i",$date_debut);
150 $hf = date("H:i",$date_fin);
151 $au = " " . strtolower(_T('agenda:evenement_date_au'));
152 $du = _T('agenda:evenement_date_du') . " ";
153 $s = "";
154 if ($d==$f)
155 { // meme jour
156 $s = ucfirst(nom_jour($d,$abbr))." ".$affdate($d);
157 if ($h)
158 $s .= " $hd";
159 $s = "$dtstart$s$dtabbr";
160 if ($h AND $hd!=$hf) $s .= "-$dtend$hf$dtabbr";
161 }
162 else if ((date("Y-m",$date_debut))==date("Y-m",$date_fin))
163 { // meme annee et mois, jours differents
164 if ($h){
165 $s = $du . $dtstart . affdate_jourcourt($d) . " $hd" . $dtabbr;
166 $s .= $au . $dtend . $affdate($f);
167 if ($hd!=$hf) $s .= " $hf";
168 $s .= $dtabbr;
169 }
170 else {
171 $s = $du . $dtstart . jour($d) . $dtabbr;
172 $s .= $au . $dtend . $affdate($f) . $dtabbr;
173 }
174 }
175 else if ((date("Y",$date_debut))==date("Y",$date_fin))
176 { // meme annee, mois et jours differents
177 $s = $du . $dtstart . affdate_jourcourt($d);
178 if ($h) $s .= " $hd";
179 $s .= $dtabbr . $au . $dtend . $affdate($f);
180 if ($h) $s .= " $hf";
181 $s .= $dtabbr;
182 }
183 else
184 { // tout different
185 $s = $du . $dtstart . affdate($d);
186 if ($h)
187 $s .= " ".date("(H:i)",$date_debut);
188 $s .= $dtabbr . $au . $dtend. affdate($f);
189 if ($h)
190 $s .= " ".date("(H:i)",$date_fin);
191 $s .= $dtabbr;
192 }
193 return unicode2charset(charset2unicode($s,'AUTO'));
194 }
195
196
197 ?>