1 | <?php |
---|
2 | |
---|
3 | function navig($current, $total, $max, $base_url, $start_param, $legende = null) |
---|
4 | { $navig = ""; |
---|
5 | if($total > $max) |
---|
6 | { if(isset($legende)) |
---|
7 | { $navig .= |
---|
8 | $legende." ".($current + 1)." à " |
---|
9 | .(($current + $max) > $total ? $total : $current + $max) |
---|
10 | ." sur ".$total." - aller à la "; |
---|
11 | } |
---|
12 | $get_params = array(); |
---|
13 | if(($q = strpos($base_url, "?")) !== false) |
---|
14 | { $v_query = explode("&", substr($base_url, $q + 1)); |
---|
15 | $base_url = substr($base_url, 0, $q); |
---|
16 | foreach($v_query as $query) |
---|
17 | { if($query) |
---|
18 | { $v = explode("=", $query); |
---|
19 | $get_params[$v[0]] = $v[1]; |
---|
20 | } |
---|
21 | } |
---|
22 | } |
---|
23 | if(isset($get_params[$start_param])) unset($get_params[$start_param]); |
---|
24 | $base_url .= "?"; |
---|
25 | foreach($get_params as $key => $value) $base_url .= $key."=".$value."&"; |
---|
26 | $nb_pages = ceil($total / $max); |
---|
27 | $navig .= |
---|
28 | "page : " |
---|
29 | ."<select onchange=\"document.location=this.options[this.selectedIndex].value;\">\n"; |
---|
30 | $np = 1; |
---|
31 | $ni = 0; |
---|
32 | while($ni < $total) |
---|
33 | { $navig .= |
---|
34 | " <option value=\"".$base_url.$start_param."=".$ni."\"".($current >= $ni && $current <= $ni ? " SELECTED" : "").">" |
---|
35 | .$np |
---|
36 | ."</option>\n"; |
---|
37 | $np++; |
---|
38 | $ni += $max; |
---|
39 | } |
---|
40 | $navig .= |
---|
41 | "</select>\n"; |
---|
42 | if($current >= $max) |
---|
43 | { $navig .= |
---|
44 | " <a href=\"".$base_url.$start_param."=".($current - $max)."\"><<</a>\n"; |
---|
45 | } |
---|
46 | if($current < $total - $max) |
---|
47 | { $navig .= |
---|
48 | " <a href=\"".$base_url.$start_param."=".($current + $max)."\">>></a>\n"; |
---|
49 | } |
---|
50 | } |
---|
51 | // elseif(isset($legende)) $navig .= $total." ".$legende; |
---|
52 | return $navig; |
---|
53 | } |
---|
54 | |
---|
55 | function order_link($env, $text, $order_by, $base_url) |
---|
56 | { $get_params = array(); |
---|
57 | if(($q = strpos($base_url, "?")) !== false) |
---|
58 | { $v_query = explode("&", substr($base_url, $q + 1)); |
---|
59 | $base_url = substr($base_url, 0, $q); |
---|
60 | foreach($v_query as $query) |
---|
61 | { if($query) |
---|
62 | { $v = explode("=", $query); |
---|
63 | $get_params[$v[0]] = $v[1]; |
---|
64 | } |
---|
65 | } |
---|
66 | } |
---|
67 | if(isset($get_params[$env->param("order_by")])) unset($get_params[$env->param("order_by")]); |
---|
68 | if(isset($get_params[$env->param("order")])) unset($get_params[$env->param("order")]); |
---|
69 | $base_url .= "?"; |
---|
70 | foreach($get_params as $key => $value) $base_url .= $key."=".$value."&"; |
---|
71 | if(substr($base_url, -1) === "&") $base_url = substr($base_url, 0, -1); |
---|
72 | $order_params = ""; |
---|
73 | $order_img = ""; |
---|
74 | if($order_by === $env->order_by) |
---|
75 | { if($env->order === "ASC") |
---|
76 | { $order_params = $env->param("order_by")."=".$order_by."&".$env->param("order")."=DESC"; |
---|
77 | $order_img = "<img src=\"icons/asc.gif\" >"; |
---|
78 | } |
---|
79 | elseif($env->order === "DESC") |
---|
80 | { $order_img = "<img src=\"icons/desc.gif\" >"; |
---|
81 | } |
---|
82 | } |
---|
83 | else |
---|
84 | { $order_params = $env->param("order_by")."=".$order_by."&".$env->param("order")."=ASC"; |
---|
85 | } |
---|
86 | return "<a href=\"".$base_url.($order_params ? "&".$order_params : "")."\">".$text."</a> ".$order_img; |
---|
87 | } |
---|
88 | |
---|
89 | function is_date($date) |
---|
90 | { return ereg("^[0-9][0-9][0-9][0-9]-[0-9]{1,2}-[0-9]{1,2}$", $date); |
---|
91 | } |
---|
92 | |
---|
93 | function is_num($num) |
---|
94 | { $num = str_replace(array(",", " "), array(".", ""), $num); |
---|
95 | $v_num = explode(".", $num); |
---|
96 | if(count($v_num) > 2) return false; |
---|
97 | $OK = true; |
---|
98 | for($n = 0; $n < count($v_num) && $OK; $n++) $OK = ereg("^[0-9]+$", $v_num[$n]); |
---|
99 | return $OK ? $num : false; |
---|
100 | } |
---|
101 | |
---|
102 | function date_texte($moment) |
---|
103 | { $moment = explode("-", $moment); |
---|
104 | return jour_semaine($moment[0], $moment[1], $moment[2])." ".(0 + $moment[0])." ".mois(0 + $moment[1])." ".$moment[2]; |
---|
105 | } |
---|
106 | |
---|
107 | function jour_semaine($jour, $mois, $annee) |
---|
108 | { switch(date("N", mktime(1, 0, 0, 0 + $mois, 0 + $jour, 0 + $annee))) |
---|
109 | { case 1: return "lundi"; |
---|
110 | case 2: return "mardi"; |
---|
111 | case 3: return "mercredi"; |
---|
112 | case 4: return "jeudi"; |
---|
113 | case 5: return "vendredi"; |
---|
114 | case 6: return "samedi"; |
---|
115 | case 7: return "dimanche"; |
---|
116 | } |
---|
117 | } |
---|
118 | |
---|
119 | function mois($mois) |
---|
120 | { switch($mois) |
---|
121 | { case 1: return "janvier"; |
---|
122 | case 2: return "fevrier"; |
---|
123 | case 3: return "mars"; |
---|
124 | case 4: return "avril"; |
---|
125 | case 5: return "mai"; |
---|
126 | case 6: return "juin"; |
---|
127 | case 7: return "juillet"; |
---|
128 | case 8: return "août"; |
---|
129 | case 9: return "septembre"; |
---|
130 | case 10: return "octobre"; |
---|
131 | case 11: return "novembre"; |
---|
132 | case 12: return "decembre"; |
---|
133 | } |
---|
134 | return "?"; |
---|
135 | } |
---|
136 | |
---|
137 | function resume($content, $n) |
---|
138 | { if($n) |
---|
139 | { $v_content = explode(" ", $content); |
---|
140 | if(count($v_content) > $n) |
---|
141 | { $_content = ""; |
---|
142 | for($i = 0; $i <= $n; $i++) $_content .= $v_content[$i]." "; |
---|
143 | return $_content." (...)"; |
---|
144 | } |
---|
145 | } |
---|
146 | return $content; |
---|
147 | } |
---|
148 | |
---|
149 | function js_str($content) |
---|
150 | { return str_replace |
---|
151 | ( array("\"", "\r", "\n"), |
---|
152 | array("\\\"", "\\r", "\\n"), |
---|
153 | $content |
---|
154 | ); |
---|
155 | } |
---|
156 | |
---|
157 | function js_str_nocrlf($content) |
---|
158 | { return str_replace |
---|
159 | ( array("\"", "\r", "\n"), |
---|
160 | array("\\\"", " ", " "), |
---|
161 | $content |
---|
162 | ); |
---|
163 | } |
---|
164 | |
---|
165 | ?> |
---|