3 /***************************************************************************\
4 * SPIP, Systeme de publication pour l'internet *
6 * Copyright (c) 2001-2013 *
7 * Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James *
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 \***************************************************************************/
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
23 if (!defined("_ECRIRE_INC_VERSION")) return;
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
29 // http://doc.spip.org/@vertebrer_sort
30 function vertebrer_sort($fields, $direction)
33 foreach($fields as $n => $t) {
34 $res .= "\n\t\t<th scope='col'>[(#TRI{"."$n,$n,ajax})]</th>";
39 // Autant de formulaire que de champs (pour les criteres conditionnels)
40 // http://doc.spip.org/@vertebrer_form
41 function vertebrer_form($fields)
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] : '');
50 if (!in_array($n, array('date', 'date_redac', 'lang'))){
53 <a href='#' onclick=\"jQuery(this).toggle('fast').siblings('form').toggle('fast');return false;\">[(#CHEMIN_IMAGE{rechercher-20.png}|balise_img)]</a>
55 <form class='[(#ENV{".$n."}|non)none-js]' action='./' method='get'>"
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>";
69 // Autant de criteres conditionnels que de champs
71 // http://doc.spip.org/@vertebrer_crit
72 function vertebrer_crit($v)
75 foreach($v as $n => $t) {
76 if (!in_array($n, array('date', 'date_redac', 'lang', 'recherche','logo')))
77 $res .= "\n\t\t{" . $n . " ?}";
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)
89 // http://doc.spip.org/@vertebrer_cell
90 function vertebrer_cell($fields)
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>";
100 $s = " style='text-align: right;'";
103 if (sql_test_date($t))
104 $texte = "[($texte|affdate_heure)]";
106 $res .= "\n\t\t<td$s>$texte</td>";
111 // http://doc.spip.org/@public_vertebrer_dist
112 function public_vertebrer_dist($desc)
114 $nom = $desc['table'];
115 $surnom = $desc['id_table'];
116 $connexion = $desc['connexion'];
117 $field = $desc['field'];
120 $defaut_tri = array_keys($field);
121 $defaut_tri = reset($defaut_tri);
125 $form = vertebrer_form($field);
126 $crit = vertebrer_crit($field);
127 $cell = vertebrer_cell($field);
128 $sort = vertebrer_sort($field,'');
129 $distant = !$connexion ?
'' : "&connect=$connexion";
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'>
139 <tr class='row_first'>
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>
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
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>
167 <div style='overflow: scroll;overflow-y: auto'>
168 <h2><:texte_vide:></h2>
171 <tr class='row_first'>
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>