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')) { |
---|
11 | return; |
---|
12 | } |
---|
13 | |
---|
14 | |
---|
15 | /** |
---|
16 | * Filtres&criteres deprecies/obsoletes |
---|
17 | */ |
---|
18 | |
---|
19 | |
---|
20 | /** |
---|
21 | * {agendafull ..} variante etendue du crietre agenda du core |
---|
22 | * qui accepte une date de debut et une date de fin |
---|
23 | * |
---|
24 | * {agendafull date_debut, date_fin, jour, #ENV{annee}, #ENV{mois}, #ENV{jour}} |
---|
25 | * {agendafull date_debut, date_fin, semaine, #ENV{annee}, #ENV{mois}, #ENV{jour}} |
---|
26 | * {agendafull date_debut, date_fin, mois, #ENV{annee}, #ENV{mois}} |
---|
27 | * {agendafull date_debut, date_fin, periode, #ENV{annee}, #ENV{mois}, #ENV{jour}, |
---|
28 | * #ENV{annee_fin}, #ENV{mois_fin}, #ENV{jour_fin}} |
---|
29 | * |
---|
30 | * @param string $idb |
---|
31 | * @param object $boucles |
---|
32 | * @param object $crit |
---|
33 | */ |
---|
34 | function critere_agendafull_dist($idb, &$boucles, $crit) { |
---|
35 | $params = $crit->param; |
---|
36 | |
---|
37 | if (count($params) < 1) { |
---|
38 | erreur_squelette(_T('zbug_info_erreur_squelette'), "{agenda ?} BOUCLE$idb"); |
---|
39 | } |
---|
40 | |
---|
41 | $parent = $boucles[$idb]->id_parent; |
---|
42 | |
---|
43 | // les valeurs $date et $type doivent etre connus a la compilation |
---|
44 | // autrement dit ne pas etre des champs |
---|
45 | |
---|
46 | $date_deb = array_shift($params); |
---|
47 | $date_deb = $date_deb[0]->texte; |
---|
48 | |
---|
49 | $date_fin = array_shift($params); |
---|
50 | $date_fin = $date_fin[0]->texte; |
---|
51 | |
---|
52 | $type = array_shift($params); |
---|
53 | $type = $type[0]->texte; |
---|
54 | |
---|
55 | $annee = $params ? array_shift($params) : ''; |
---|
56 | $annee = "\n" . 'sprintf("%04d", ($x = ' . |
---|
57 | calculer_liste($annee, array(), $boucles, $parent) . |
---|
58 | ') ? $x : date("Y"))'; |
---|
59 | |
---|
60 | $mois = $params ? array_shift($params) : ''; |
---|
61 | $mois = "\n" . 'sprintf("%02d", ($x = ' . |
---|
62 | calculer_liste($mois, array(), $boucles, $parent) . |
---|
63 | ') ? $x : date("m"))'; |
---|
64 | |
---|
65 | $jour = $params ? array_shift($params) : ''; |
---|
66 | $jour = "\n" . 'sprintf("%02d", ($x = ' . |
---|
67 | calculer_liste($jour, array(), $boucles, $parent) . |
---|
68 | ') ? $x : date("d"))'; |
---|
69 | |
---|
70 | $annee2 = $params ? array_shift($params) : ''; |
---|
71 | $annee2 = "\n" . 'sprintf("%04d", ($x = ' . |
---|
72 | calculer_liste($annee2, array(), $boucles, $parent) . |
---|
73 | ') ? $x : date("Y"))'; |
---|
74 | |
---|
75 | $mois2 = $params ? array_shift($params) : ''; |
---|
76 | $mois2 = "\n" . 'sprintf("%02d", ($x = ' . |
---|
77 | calculer_liste($mois2, array(), $boucles, $parent) . |
---|
78 | ') ? $x : date("m"))'; |
---|
79 | |
---|
80 | $jour2 = $params ? array_shift($params) : ''; |
---|
81 | $jour2 = "\n" . 'sprintf("%02d", ($x = ' . |
---|
82 | calculer_liste($jour2, array(), $boucles, $parent) . |
---|
83 | ') ? $x : date("d"))'; |
---|
84 | |
---|
85 | $boucle = &$boucles[$idb]; |
---|
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 | /** |
---|
117 | * Afficher de facon textuelle les dates de debut et fin en fonction des cas |
---|
118 | * - Le lundi 20 fevrier a 18h |
---|
119 | * - Le 20 fevrier de 18h a 20h |
---|
120 | * - Du 20 au 23 fevrier |
---|
121 | * - du 20 fevrier au 30 mars |
---|
122 | * - du 20 fevrier 2007 au 30 mars 2008 |
---|
123 | * $horaire='oui' permet d'afficher l'horaire, toute autre valeur n'indique que le jour |
---|
124 | * $forme peut contenir abbr (afficher le nom des jours en abbrege) et ou hcal (generer une date au format hcal) |
---|
125 | * |
---|
126 | * @param string $date_debut |
---|
127 | * @param string $date_fin |
---|
128 | * @param string $horaire |
---|
129 | * @param string $forme |
---|
130 | * @return string |
---|
131 | */ |
---|
132 | function agenda_affdate_debut_fin($date_debut, $date_fin, $horaire = 'oui', $forme = '') { |
---|
133 | $abbr = ''; |
---|
134 | if (strpos($forme, 'abbr') !== false) { |
---|
135 | $abbr = 'abbr'; |
---|
136 | } |
---|
137 | $affdate = 'affdate_jourcourt'; |
---|
138 | if (strpos($forme, 'annee') !== false) { |
---|
139 | $affdate = 'affdate'; |
---|
140 | } |
---|
141 | |
---|
142 | $dtstart = $dtend = $dtabbr = ''; |
---|
143 | if (strpos($forme, 'hcal') !== false) { |
---|
144 | $dtstart = "<abbr class='dtstart' title='".date_iso($date_debut)."'>"; |
---|
145 | $dtend = "<abbr class='dtend' title='".date_iso($date_fin)."'>"; |
---|
146 | $dtabbr = '</abbr>'; |
---|
147 | } |
---|
148 | |
---|
149 | $date_debut = strtotime($date_debut); |
---|
150 | $date_fin = strtotime($date_fin); |
---|
151 | $d = date('Y-m-d', $date_debut); |
---|
152 | $f = date('Y-m-d', $date_fin); |
---|
153 | $h = $horaire == 'oui'; |
---|
154 | $hd = date('H:i', $date_debut); |
---|
155 | $hf = date('H:i', $date_fin); |
---|
156 | $au = ' ' . strtolower(_T('agenda:evenement_date_au')); |
---|
157 | $du = _T('agenda:evenement_date_du') . ' '; |
---|
158 | $s = ''; |
---|
159 | if ($d == $f) { // meme jour |
---|
160 | $s = ucfirst(nom_jour($d, $abbr)).' '.$affdate($d); |
---|
161 | if ($h) { |
---|
162 | $s .= " $hd"; |
---|
163 | } |
---|
164 | $s = "$dtstart$s$dtabbr"; |
---|
165 | if ($h and $hd != $hf) { |
---|
166 | $s .= "-$dtend$hf$dtabbr"; |
---|
167 | } |
---|
168 | } elseif ((date('Y-m', $date_debut)) == date('Y-m', $date_fin)) { |
---|
169 | // meme annee et mois, jours differents |
---|
170 | if ($h) { |
---|
171 | $s = $du . $dtstart . affdate_jourcourt($d) . " $hd" . $dtabbr; |
---|
172 | $s .= $au . $dtend . $affdate($f); |
---|
173 | $s .= " $hf"; |
---|
174 | $s .= $dtabbr; |
---|
175 | } else { |
---|
176 | $s = $du . $dtstart . jour($d) . $dtabbr; |
---|
177 | $s .= $au . $dtend . $affdate($f) . $dtabbr; |
---|
178 | } |
---|
179 | } elseif ((date('Y', $date_debut)) == date('Y', $date_fin)) { |
---|
180 | // meme annee, mois et jours differents |
---|
181 | $s = $du . $dtstart . affdate_jourcourt($d); |
---|
182 | if ($h) { |
---|
183 | $s .= " $hd"; |
---|
184 | } |
---|
185 | $s .= $dtabbr . $au . $dtend . $affdate($f); |
---|
186 | if ($h) { |
---|
187 | $s .= " $hf"; |
---|
188 | } |
---|
189 | $s .= $dtabbr; |
---|
190 | } else { |
---|
191 | // tout different |
---|
192 | $s = $du . $dtstart . affdate($d); |
---|
193 | if ($h) { |
---|
194 | $s .= ' '.date('(H:i)', $date_debut); |
---|
195 | } |
---|
196 | $s .= $dtabbr . $au . $dtend. affdate($f); |
---|
197 | if ($h) { |
---|
198 | $s .= ' '.date('(H:i)', $date_fin); |
---|
199 | } |
---|
200 | $s .= $dtabbr; |
---|
201 | } |
---|
202 | return unicode2charset(charset2unicode($s, 'AUTO')); |
---|
203 | } |
---|