1 | <?php |
---|
2 | |
---|
3 | /***************************************************************************\ |
---|
4 | * SPIP, Systeme de publication pour l'internet * |
---|
5 | * * |
---|
6 | * Copyright (c) 2001-2011 * |
---|
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 | if (!defined('_ECRIRE_INC_VERSION')) return; |
---|
14 | |
---|
15 | define('_TRANCHES', 10); |
---|
16 | |
---|
17 | // Cette fonction prend un argument un tableau decrivant une requete Select |
---|
18 | // et une fonction formatant chaque ligne du resultat de la requete |
---|
19 | // Elle renvoie une enumeration HTML de ces lignes formatees, |
---|
20 | // avec une pagination appelable en Ajax si $idom et $url sont fournis |
---|
21 | |
---|
22 | // http://doc.spip.org/@inc_presenter_liste_dist |
---|
23 | function inc_presenter_liste_dist($requete, $fonc, &$prims, $own, $force, $styles, $idom='', $title='', $icone='', $url='', $cpt=NULL) |
---|
24 | { |
---|
25 | global $spip_display, $spip_lang_left; |
---|
26 | |
---|
27 | // $requete est passe par reference, pour modifier l'index LIMIT |
---|
28 | if ($idom AND $spip_display != 4) |
---|
29 | $tranches = affiche_tranche_bandeau($requete, $idom, $url, $cpt, _TRANCHES); |
---|
30 | else $tranches = ''; |
---|
31 | |
---|
32 | $prim = $prims; |
---|
33 | $prims = array(); |
---|
34 | $result = sql_allfetsel((isset($requete["SELECT"]) ? $requete["SELECT"] : "*"), $requete['FROM'], $requete['WHERE'], $requete['GROUP BY'], $requete['ORDER BY'], $requete['LIMIT']); |
---|
35 | |
---|
36 | if (!count($result)) { |
---|
37 | if (!$force) return ''; |
---|
38 | } else { |
---|
39 | if ($spip_display != 4) { |
---|
40 | $evt = !preg_match(",msie,i", $GLOBALS['browser_name']) ? '' |
---|
41 | : " |
---|
42 | onmouseover=\"changeclass(this,'tr_liste_over');\" |
---|
43 | onmouseout=\"changeclass(this,'tr_liste');\"" ; |
---|
44 | |
---|
45 | $table = $head = ''; |
---|
46 | $th = 0; |
---|
47 | foreach ($result as $r) { |
---|
48 | if ($prim) $prims[]= $r[$prim]; |
---|
49 | if ($vals = $fonc($r, $own)) { |
---|
50 | reset($styles); |
---|
51 | $res = ''; |
---|
52 | foreach ($vals as $t) { |
---|
53 | $style = $largeur = $nom = ""; |
---|
54 | list(,$s) = each($styles); |
---|
55 | if (count($s)) $style = array_shift($s); |
---|
56 | if (count($s)) $largeur = array_shift($s); |
---|
57 | if (count($s)) $nom = array_shift($s); |
---|
58 | if ($largeur) $largeur = " style='width: $largeur" ."px;'"; |
---|
59 | if ($style) $style = " class=\"$style\""; |
---|
60 | $t = !trim($t) ? " " : lignes_longues($t); |
---|
61 | $res .= "\n<td$style$largeur>$t</td>"; |
---|
62 | if (!$table) { |
---|
63 | $th |= $nom ? 1 : 0; |
---|
64 | $head .= "\n<th style='text-align:center'>$nom</th>"; |
---|
65 | } |
---|
66 | } |
---|
67 | $table .= "\n<tr class='tr_liste'$evt>$res</tr>"; |
---|
68 | } |
---|
69 | } |
---|
70 | if (!$th) $head= ''; |
---|
71 | $tranches .= "<table width='100%' cellpadding='2' border='0'>$head$table</table>"; |
---|
72 | } else { |
---|
73 | foreach ($result as $r) { |
---|
74 | if ($prim) $prims[]= $r[$prim]; |
---|
75 | if ($t = $fonc($r, $own)) { |
---|
76 | $tranches = '<li>' . join('</li><li>', $t) . '</li>'; |
---|
77 | $tranches = "\n<ul style='text-align: $spip_lang_left; background-color: white;'>" |
---|
78 | . $tranches |
---|
79 | . "</ul>"; |
---|
80 | } |
---|
81 | } |
---|
82 | } |
---|
83 | } |
---|
84 | |
---|
85 | $id = 't'.substr(md5(join('',$requete)),0,8); |
---|
86 | $bouton = !$icone ? '' : bouton_block_depliable($title, true, $id); |
---|
87 | |
---|
88 | return debut_cadre('liste', $icone, "", $bouton, "", "", false) |
---|
89 | . debut_block_depliable(true, $id) |
---|
90 | . $tranches |
---|
91 | . fin_block() |
---|
92 | . fin_cadre('liste'); |
---|
93 | } |
---|
94 | |
---|
95 | // http://doc.spip.org/@afficher_tranches_requete |
---|
96 | function afficher_tranches_requete($num_rows, $idom, $url='', $nb_aff = 10, $old_arg=NULL) { |
---|
97 | static $ancre = 0; |
---|
98 | global $browser_name, $spip_lang_right, $spip_display; |
---|
99 | if ($old_arg!==NULL){ // eviter de casser la compat des vieux appels $cols_span ayant disparu ... |
---|
100 | $idom = $url; $url = $nb_aff; $nb_aff=$old_arg; |
---|
101 | } |
---|
102 | |
---|
103 | $ancre++; |
---|
104 | $self = self(); |
---|
105 | $ie_style = ($browser_name == "MSIE") ? "height:1%" : ''; |
---|
106 | $style = "style='visibility: hidden; float: $spip_lang_right'"; |
---|
107 | $nav= navigation_pagination($num_rows, $nb_aff, $url, _request($idom), $idom, true); |
---|
108 | $script = parametre_url($self, $idom, -1); |
---|
109 | $l = htmlentities(_T('lien_tout_afficher')); |
---|
110 | |
---|
111 | return http_img_pack("searching.gif", "*", "$style id='img_$idom'") |
---|
112 | . "\n<div style='$ie_style;' class='arial1 tranches' id='a$ancre'>" |
---|
113 | . $nav |
---|
114 | . "<a href='$script#a$ancre' class='plus'" |
---|
115 | . (!$url ? '' : generer_onclic_ajax($url, $idom,-1)) |
---|
116 | . "><img title=\"$l\" alt=\"$l\"\nsrc=\"" |
---|
117 | . chemin_image("plus-16.png") |
---|
118 | . "\" /></a></div>\n"; |
---|
119 | } |
---|
120 | |
---|
121 | // http://doc.spip.org/@affiche_tranche_bandeau |
---|
122 | function affiche_tranche_bandeau(&$requete, $idom, $url='', $cpt=NULL, $pas=10) |
---|
123 | { |
---|
124 | if (!isset($requete['GROUP BY'])) $requete['GROUP BY'] = ''; |
---|
125 | |
---|
126 | if ($cpt === NULL) |
---|
127 | $cpt = sql_countsel($requete['FROM'], $requete['WHERE'], $requete['GROUP BY']); |
---|
128 | |
---|
129 | $deb_aff = intval(_request($idom)); |
---|
130 | $nb_aff = $pas + ($pas>>1); |
---|
131 | |
---|
132 | if (isset($requete['LIMIT'])) $cpt = min($requete['LIMIT'], $cpt); |
---|
133 | |
---|
134 | if ($cpt > $nb_aff) { |
---|
135 | $nb_aff = $pas; |
---|
136 | $res = afficher_tranches_requete($cpt, $idom, $url, $nb_aff); |
---|
137 | } else $res = ''; |
---|
138 | |
---|
139 | if (!isset($requete['LIMIT']) AND $deb_aff <> -1) |
---|
140 | $requete['LIMIT'] = "$deb_aff, $nb_aff"; |
---|
141 | |
---|
142 | return $res; |
---|
143 | } |
---|
144 | ?> |
---|