[SPIP] ~2.1.12 -->2.1.25
[velocampus/web/www.git] / www / extensions / 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 $tri = $direction . 'tri';
35
36 $url = vertebrer_sanstri($tri)
37 . "|parametre_url{" . $tri . ",'" . $n . "'}";
38
39 $res .= "\n\t\t<th style='text-align: center'>"
40 . "\n\t\t\t<a href='[(#SELF$url)]'>$n</a>"
41 . "\n\t\t</th>";
42 }
43 return $res;
44 }
45
46 // http://doc.spip.org/@vertebrer_sanstri
47 function vertebrer_sanstri($sauf='')
48 {
49 $url ="";
50 foreach (array('tri', '_tri') as $c) {
51 if ($sauf != $c) $url .= "|$c";
52 }
53 return '|parametre_url{"' . substr($url,1) .'",""}';
54 }
55
56 // Autant de formulaire que de champs (pour les criteres conditionnels)
57
58 // http://doc.spip.org/@vertebrer_form
59 function vertebrer_form($fields)
60 {
61 $res = '';
62 $url = join('|', array_keys($fields));
63 $url = "#SELF|\n\t\t\tparametre_url{'$url',''}";
64 foreach($fields as $n => $t) {
65 $s = sql_test_int($t) ? 11
66 : (preg_match('/char\s*\((\d)\)/i', $t, $r) ? $r[1] : '');
67
68 $res .= "\n\t\t<td><form action='./' method='get'>"
69 . "<div style='text-align: center;' >"
70 . "\n\t\t\t<input name='$n'"
71 . ($s ? " size='$s'" : '')
72 . " />\n\t\t\t[($url|\n\t\t\tform_hidden)]"
73 . "\n\t\t</div></form></td>";
74 }
75 return $res;
76 }
77
78 // Autant de criteres conditionnels que de champs
79
80 // http://doc.spip.org/@vertebrer_crit
81 function vertebrer_crit($v)
82 {
83 $res = "";
84 foreach($v as $n => $t) { $res .= "\n\t\t{" . $n . " ?}"; }
85 return $res;
86 }
87
88
89 // Class CSS en fonction de la parite du numero de ligne.
90 // Style text-align en fonction du type SQL (numerique ou non).
91 // Filtre de belle date sur type SQL signalant une date ou une estampille.
92 // Si une colonne reference une table, ajoute un href sur sa page dynamique
93 // (il faudrait aller chercher sa def pour ilustrer les jointures en SPIP)
94
95 // http://doc.spip.org/@vertebrer_cell
96 function vertebrer_cell($fields)
97 {
98 $res = "";
99 foreach($fields as $n => $t) {
100 $texte = "#" . strtoupper($n);
101 if (preg_match('/\s+references\s+([\w_]+)/' , $t, $r)) {
102 $url = "[(#SELF|parametre_url{page,'" . $r[1] . "'})]";
103 $texte = "<a href='$url'>" . $texte . "</a>";
104 }
105 if (sql_test_int($t))
106 $s = " style='text-align: right;'";
107 else {
108 $s = '';
109 if (sql_test_date($t))
110 $texte = "[($texte|affdate_heure)]";
111 }
112 $res .= "\n\t\t<td$s>$texte</td>";
113 }
114 return $res;
115 }
116
117 // http://doc.spip.org/@public_vertebrer_dist
118 function public_vertebrer_dist($desc)
119 {
120 $nom = $desc['table'];
121 $surnom = $desc['id_table'];
122 $connexion = $desc['connexion'];
123 $field = $desc['field'];
124 $key = $desc['key'];
125
126 ksort($field);
127
128 $form = vertebrer_form($field);
129 $crit = vertebrer_crit($field);
130 $cell = vertebrer_cell($field);
131 $sort = vertebrer_sort($field,'');
132 $tros = vertebrer_sort($field,'_');
133 $distant = !$connexion ? '' : "&amp;connect=$connexion";
134 $skel = "./?"._SPIP_PAGE."=table:$surnom$distant&amp;var_mode=debug&amp;var_mode_affiche=squelette#debug_boucle";
135
136 return
137 "#CACHE{0}
138 <!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>
139 <html xmlns='http://www.w3.org/1999/xhtml' xml:lang='#LANG' lang='#LANG' dir='#LANG_DIR'>
140 <head>
141 <title>[(#NOM_SITE_SPIP|textebrut)] - #ENV{page}</title>
142 <INCLURE{fond=inc-head}>
143 </head>
144 <body class='page_rubrique'><div id='page'>
145 <INCLURE{fond=inc-entete}>
146 <div id='contenu'>
147 <h1 style='text-align:center'>#ENV{page}</h1><br />
148 <B1>
149 [<p class='pagination'>(#PAGINATION)</p>]
150 <table class='spip' border='1' width='90%'>
151 <tr>
152 <th><:info_numero_abbreviation:></th>$sort
153 </tr>
154 <tr>
155 <td></td>$form
156 </tr>
157 <BOUCLE1($surnom){pagination}
158 {par #ENV{tri}}{!par #ENV{_tri}}$crit>
159 <tr class='[row_(#COMPTEUR_BOUCLE|alterner{'odd','even'})]'>
160 <td style='text-align: right;'>#COMPTEUR_BOUCLE</td>$cell
161 </tr>
162 </BOUCLE1>
163 <tr>
164 <th><:info_numero_abbreviation:></th>$tros
165 </tr>
166 </table>
167 </B1>\n<h2 style='text-align:center'><:texte_vide:></h2>
168 <//B1></div>
169 <INCLURE{fond=inc-pied}{skel='$skel'}>
170 </div>
171 </body>
172 </html>";
173 }
174 ?>