[SPIP] ~maj v3.0.14-->v3.0.17
[ptitvelo/web/www.git] / www / plugins-dist / vertebres / public / vertebrer.php
1 <?php
2
3 /***************************************************************************\
4 * SPIP, Systeme de publication pour l'internet *
5 * *
6 * Copyright (c) 2001-2014 *
7 * Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James *
8 * *
9 * Ce programme est un logiciel libre distribue sous licence GNU/GPL. *
10 * Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. *
11 \***************************************************************************/
12
13 //
14 // Production dynamique d'un squelette lorsqu'il ne figure pas
15 // dans les dossiers de squelettes mais que son nom est celui d'une table SQL:
16 // on produit une table HTML montrant le contenu de la table SQL
17 // Le squelette produit illustre quelques possibilites de SPIP:
18 // - pagination automatique
19 // - tri ascendant et descendant sur chacune des colonnes
20 // - critere conditionnel donnant l'extrait correspondant a la colonne en URL
21 //
22
23 if (!defined("_ECRIRE_INC_VERSION")) return;
24
25 // nomme chaque colonne par le nom du champ,
26 // qui sert de lien vers la meme page, avec la table triee selon ce champ
27 // distingue champ numerique et non numerique
28
29 // http://doc.spip.org/@vertebrer_sort
30 function vertebrer_sort($fields, $direction)
31 {
32 $res = '';
33 foreach($fields as $n => $t) {
34 $res .= "\n\t\t<th scope='col'>[(#TRI{"."$n,$n,ajax})]</th>";
35 }
36 return $res;
37 }
38
39 // Autant de formulaire que de champs (pour les criteres conditionnels)
40 // http://doc.spip.org/@vertebrer_form
41 function vertebrer_form($fields)
42 {
43 $res = '';
44 $url = join('|', array_keys($fields));
45 $url = "#SELF|\n\t\t\tparametre_url{'$url',''}";
46 foreach($fields as $n => $t) {
47 $s = sql_test_int($t) ? 11
48 : (preg_match('/char\s*\((\d)\)/i', $t, $r) ? $r[1] : '');
49
50 if (!in_array($n, array('date', 'date_redac', 'lang'))){
51 $res .= "\n\t\t<td>
52 [(#ENV{".$n."}|non)
53 <a href='#' onclick=\"jQuery(this).toggle('fast').siblings('form').toggle('fast');return false;\">[(#CHEMIN_IMAGE{rechercher-20.png}|balise_img)]</a>
54 ]
55 <form class='[(#ENV{".$n."}|non)none-js]' action='./' method='get'>"
56 . "<div>"
57 . "\n\t\t\t<input name='$n'"
58 . ($s ? " size='$s'" : '')
59 . "value=\"[(#ENV{".$n."}|entites_html)]\""
60 . " />\n\t\t\t[($url|\n\t\t\tform_hidden)]"
61 . "\n\t\t</div></form></td>";
62 }
63 else
64 $res .= "<td></td>";
65 }
66 return $res;
67 }
68
69 // Autant de criteres conditionnels que de champs
70
71 // http://doc.spip.org/@vertebrer_crit
72 function vertebrer_crit($v)
73 {
74 $res = "";
75 foreach($v as $n => $t) {
76 if (!in_array($n, array('date', 'date_redac', 'lang', 'recherche','logo')))
77 $res .= "\n\t\t{" . $n . " ?}";
78 }
79 return $res;
80 }
81
82
83 // Class CSS en fonction de la parite du numero de ligne.
84 // Style text-align en fonction du type SQL (numerique ou non).
85 // Filtre de belle date sur type SQL signalant une date ou une estampille.
86 // Si une colonne reference une table, ajoute un href sur sa page dynamique
87 // (il faudrait aller chercher sa def pour ilustrer les jointures en SPIP)
88
89 // http://doc.spip.org/@vertebrer_cell
90 function vertebrer_cell($fields)
91 {
92 $res = "";
93 foreach($fields as $n => $t) {
94 $texte = "#CHAMP_SQL{".$n."}";
95 if (preg_match('/\s+references\s+([\w_]+)/' , $t, $r)) {
96 $url = "[(#SELF|parametre_url{page,'" . $r[1] . "'})]";
97 $texte = "<a href='$url'>" . $texte . "</a>";
98 }
99 if (sql_test_int($t))
100 $s = " style='text-align: right;'";
101 else {
102 $s = '';
103 if (sql_test_date($t))
104 $texte = "[($texte|affdate_heure)]";
105 }
106 $res .= "\n\t\t<td$s>$texte</td>";
107 }
108 return $res;
109 }
110
111 // http://doc.spip.org/@public_vertebrer_dist
112 function public_vertebrer_dist($desc)
113 {
114 $nom = $desc['table'];
115 $surnom = $desc['id_table'];
116 $connexion = $desc['connexion'];
117 $field = $desc['field'];
118 $key = $desc['key'];
119
120 $defaut_tri = array_keys($field);
121 $defaut_tri = reset($defaut_tri);
122
123 //ksort($field);
124
125 $form = vertebrer_form($field);
126 $crit = vertebrer_crit($field);
127 $cell = vertebrer_cell($field);
128 $sort = vertebrer_sort($field,'');
129 $distant = !$connexion ? '' : "&amp;connect=$connexion";
130
131 return
132 "#CACHE{0}
133 <B1>
134 <h2>[(#GRAND_TOTAL|singulier_ou_pluriel{vertebres:1_donnee,vertebres:nb_donnees})]</h2>
135 [<p class='pagination'>(#PAGINATION)</p>]
136 <div style='overflow: scroll;overflow-y: auto'>
137 <table class='spip'>
138 <thead>
139 <tr class='row_first'>
140 <th>
141 <p class='tri'>#TRI{'>',#CHEMIN_IMAGE{tri-asc-16.png}|balise_img{up},ajax} #TRI{'<',#CHEMIN_IMAGE{tri-desc-16.png}|balise_img{desc},ajax}</p>
142 </th>
143 $sort
144 </tr>
145 <tr>
146 <td></td>$form
147 </tr>
148 </thead>
149 <tbody>
150 <BOUCLE1($surnom){pagination}
151 {tri $defaut_tri, direct}$crit>
152 <tr class='[row_(#COMPTEUR_BOUCLE|alterner{'odd','even'})]'>
153 <td style='text-align: right;'>#COMPTEUR_BOUCLE</td>$cell
154 </tr>
155 </BOUCLE1>
156 </tbody>
157 <tfoot>
158 <tr>
159 <th>
160 <p class='tri'>#TRI{'>',#CHEMIN_IMAGE{tri-asc-16.png}|balise_img{up},ajax} #TRI{'<',#CHEMIN_IMAGE{tri-desc-16.png}|balise_img{desc},ajax}</p>
161 </th>
162 $sort
163 </tr>
164 </tfoot>
165 </table>
166 </B1>
167 <div style='overflow: scroll;overflow-y: auto'>
168 <h2><:texte_vide:></h2>
169 <table class='spip'>
170 <thead>
171 <tr class='row_first'>
172 <th>
173 <p class='tri'>#TRI{'>',#CHEMIN_IMAGE{tri-asc-16.png}|balise_img{up},ajax} #TRI{'<',#CHEMIN_IMAGE{tri-desc-16.png}|balise_img{desc},ajax}</p>
174 </th>
175 $sort
176 </tr>
177 <tr>
178 <td></td>$form
179 </tr>
180 </thead>
181 </table>
182 <//B1>
183 </div>
184 ";
185 }
186 ?>