3 /***************************************************************************\
4 * SPIP, Systeme de publication pour l'internet *
6 * Copyright (c) 2001-2009 *
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 $tri = $direction . 'tri';
36 $url = vertebrer_sanstri($tri)
37 . "|parametre_url{" . $tri . ",'" . $n . "'}";
39 $res .= "\n\t\t<th style='text-align: center'>"
40 . "\n\t\t\t<a href='[(#SELF$url)]'>$n</a>"
46 // http://doc.spip.org/@vertebrer_sanstri
47 function vertebrer_sanstri($sauf='')
50 foreach (array('tri', '_tri') as $c) {
51 if ($sauf != $c) $url .= "|$c";
53 return '|parametre_url{"' . substr($url,1) .'",""}';
56 // Autant de formulaire que de champs (pour les criteres conditionnels)
58 // http://doc.spip.org/@vertebrer_form
59 function vertebrer_form($fields)
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] : '');
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>";
78 // Autant de criteres conditionnels que de champs
80 // http://doc.spip.org/@vertebrer_crit
81 function vertebrer_crit($v)
84 foreach($v as $n => $t) { $res .= "\n\t\t{" . $n . " ?}"; }
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)
95 // http://doc.spip.org/@vertebrer_cell
96 function vertebrer_cell($fields)
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>";
105 if (sql_test_int($t))
106 $s = " style='text-align: right;'";
109 if (sql_test_date($t))
110 $texte = "[($texte|affdate_heure)]";
112 $res .= "\n\t\t<td$s>$texte</td>";
117 // http://doc.spip.org/@public_vertebrer_dist
118 function public_vertebrer_dist($desc)
120 $nom = $desc['table'];
121 $surnom = $desc['id_table'];
122 $connexion = $desc['connexion'];
123 $field = $desc['field'];
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 ?
'' : "&connect=$connexion";
134 $skel = "./?"._SPIP_PAGE
."=table:$surnom$distant&var_mode=debug&var_mode_affiche=squelette#debug_boucle";
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'>
141 <title>[(#NOM_SITE_SPIP|textebrut)] - #ENV{page}</title>
142 <INCLURE{fond=inc-head}>
144 <body class='page_rubrique'><div id='page'>
145 <INCLURE{fond=inc-entete}>
147 <h1 style='text-align:center'>#ENV{page}</h1><br />
149 [<p class='pagination'>(#PAGINATION)</p>]
150 <table class='spip' border='1' width='90%'>
152 <th><:info_numero_abbreviation:></th>$sort
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
164 <th><:info_numero_abbreviation:></th>$tros
167 </B1>\n<h2 style='text-align:center'><:texte_vide:></h2>
169 <INCLURE{fond=inc-pied}{skel='$skel'}>