1 |
commit: ef19aa17b0bbdb31ebfc4a2b8744cda8075bd9ff |
2 |
Author: Brian Evans <grknight <AT> gentoo <DOT> org> |
3 |
AuthorDate: Mon Jan 29 21:08:25 2018 +0000 |
4 |
Commit: Brian Evans <grknight <AT> gentoo <DOT> org> |
5 |
CommitDate: Mon Jan 29 21:08:25 2018 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/bouncer.git/commit/?id=ef19aa17 |
7 |
|
8 |
Remove the unused php/lib/list.php |
9 |
|
10 |
php/lib/list.php | 391 ------------------------------------------------------- |
11 |
1 file changed, 391 deletions(-) |
12 |
|
13 |
diff --git a/php/lib/list.php b/php/lib/list.php |
14 |
deleted file mode 100644 |
15 |
index 5deb5e9..0000000 |
16 |
--- a/php/lib/list.php |
17 |
+++ /dev/null |
18 |
@@ -1,391 +0,0 @@ |
19 |
-<?php |
20 |
-/** |
21 |
- * List functions for lists of values. |
22 |
- * @package mirror |
23 |
- * @subpackage lib |
24 |
- * @author Mike Morgan <mike.morgan@×××××××××××.edu> |
25 |
- * |
26 |
- * Usage example: |
27 |
- * <code> |
28 |
- * $orderby=get_order(); |
29 |
- * $query="SELECT * FROM fic_courses $orderby"; |
30 |
- * $courses=db_get($query,MYSQL_ASSOC); |
31 |
- * $headers=array( |
32 |
- * 'course_id'=>'', |
33 |
- * 'title'=>'Course Title', |
34 |
- * 'date_start_course'=>'Start', |
35 |
- * 'date_end_course'=>'End', |
36 |
- * 'date_start_reg'=>'Reg Starts', |
37 |
- * 'date_end_reg'=>'Reg Ends', |
38 |
- * 'active'=>'Active?', |
39 |
- * 'entry_date'=>'Created' |
40 |
- * ); |
41 |
- * show_list($courses,$headers); |
42 |
- * </code> |
43 |
- * |
44 |
- * Accompanying CSS for table output: |
45 |
- * <code> |
46 |
- * .list |
47 |
- * { |
48 |
- * border:1px solid #999; |
49 |
- * } |
50 |
- * .list th |
51 |
- * { |
52 |
- * background:#eee; |
53 |
- * border:1px solid #000; |
54 |
- * font-weight:bold; |
55 |
- * } |
56 |
- * .list th a |
57 |
- * { |
58 |
- * display:block; |
59 |
- * padding:0 14px; |
60 |
- * } |
61 |
- * .list th a:hover |
62 |
- * { |
63 |
- * background-color:#fff; |
64 |
- * } |
65 |
- * .row1 |
66 |
- * { |
67 |
- * background:#ddd; |
68 |
- * } |
69 |
- * .row2 |
70 |
- * { |
71 |
- * background:#ccc; |
72 |
- * } |
73 |
- * .row1:hover, .row2:hover |
74 |
- * { |
75 |
- * background-color:#fec; |
76 |
- * } |
77 |
- * .current-sort |
78 |
- * { |
79 |
- * background:#fda; |
80 |
- * } |
81 |
- * .sort-desc |
82 |
- * { |
83 |
- * background:#fec url(../img/up.gif) no-repeat right; |
84 |
- * } |
85 |
- * .sort-asc |
86 |
- * { |
87 |
- * background:#fec url(../img/down.gif) no-repeat right; |
88 |
- * } |
89 |
- * </code> |
90 |
- |
91 |
- * Accompanying JavaScript for select all / inverse: |
92 |
- * <code> |
93 |
- * <script type="text/javascript"> |
94 |
- * //<!-- |
95 |
- * function selectAll(formObj,invert) |
96 |
- * { |
97 |
- * for (var i=0;i < formObj.elements.length;i++) |
98 |
- * { |
99 |
- * fldObj = formObj.elements[i]; |
100 |
- * if (fldObj.type == 'checkbox') |
101 |
- * { |
102 |
- * if (invert==1) |
103 |
- * { |
104 |
- * fldObj.checked = (fldObj.checked) ? false : true; |
105 |
- * } |
106 |
- * else |
107 |
- * { |
108 |
- * fldObj.checked = true; |
109 |
- * } |
110 |
- * } |
111 |
- * } |
112 |
- * } |
113 |
- * //--> |
114 |
- * </script> |
115 |
- * </code> |
116 |
- */ |
117 |
- |
118 |
-/** |
119 |
- * Show a list of values, for forms. |
120 |
- * @param array $list associative array |
121 |
- * @param array $headers column name => column title (for table heads) |
122 |
- * @param string $type checkbox, radio, simple |
123 |
- * @param array $array actions to display in actions select list |
124 |
- * @param string $form_id id of form holding list |
125 |
- * @param bool $sortable whether or not to show sortable column headers (links in th's) |
126 |
- * @param array|string $selected if type is checkbox, array otherwise string with one val |
127 |
- */ |
128 |
-function show_list($list,$headers,$type='checkbox',$actions=null,$form_id=null,$sortable=true,$selected=null) |
129 |
-{ |
130 |
- if ( is_array($list) && count($list)>0 && is_array($headers) ) |
131 |
- { |
132 |
- if ( $type!='simple' && !empty($_GET['sort']) && !empty($_GET['order']) ) |
133 |
- { |
134 |
- form_hidden('sort',$_GET['sort']); |
135 |
- form_hidden('order',$_GET['order']); |
136 |
- } |
137 |
- echo "\n".'<table class="list">'; |
138 |
- show_headers($headers,$type,$sortable); |
139 |
- echo "\n".'<tbody>'; |
140 |
- foreach ($list as $row) |
141 |
- { |
142 |
- show_row($headers,$row,$type,$count++,$selected); |
143 |
- } |
144 |
- echo "\n".'</tbody>'; |
145 |
- echo "\n".'</table>'; |
146 |
- if ($type=='checkbox') |
147 |
- { |
148 |
-echo <<<js |
149 |
-<script type="text/javascript"> |
150 |
-//<!-- |
151 |
-function list_select(formObj,invert) |
152 |
-{ |
153 |
- for (var i=0;i < formObj.elements.length;i++) |
154 |
- { |
155 |
- fldObj = formObj.elements[i]; |
156 |
- if (fldObj.type == 'checkbox') |
157 |
- { |
158 |
- if (invert==1) |
159 |
- { |
160 |
- fldObj.checked = (fldObj.checked) ? false : true; |
161 |
- } |
162 |
- else |
163 |
- { |
164 |
- fldObj.checked = true; |
165 |
- } |
166 |
- } |
167 |
- } |
168 |
-} |
169 |
-//--> |
170 |
-</script> |
171 |
-js; |
172 |
- echo "\n".'<p><input type="button" name="selectall" onclick="list_select(this.form,0);" class="button2" value="Select All"/> <input type="button" name="selectall" onclick="list_select(this.form,1);" class="button2" value="Invert"/></p>'; |
173 |
- } |
174 |
- if ($type=='radio'||$type='checkbox-small') |
175 |
- { |
176 |
- echo '<br />'; |
177 |
- } |
178 |
- if (is_array($actions)&&$type!='simple') |
179 |
- { |
180 |
- if (count($actions) == 1) { |
181 |
- $actions = array_values($actions); |
182 |
- echo '<p>'; |
183 |
- form_submit('submit','submit','button1',$actions[0].' »'); |
184 |
- echo '</p>'; |
185 |
- } else { |
186 |
- echo '<p>'; |
187 |
- echo '<label for="action">With selected: </label>'; |
188 |
- form_select('action','action','text2',$actions,''); |
189 |
- form_submit('submit','submit','button1','Go »'); |
190 |
- echo '</p>'; |
191 |
- } |
192 |
- } |
193 |
- } |
194 |
- elseif ( !is_array($headers) ) |
195 |
- { |
196 |
- echo "\n".'<h1>FIX HEADERS ARRAY</h1>'; |
197 |
- } |
198 |
- else |
199 |
- { |
200 |
- echo "\n".'<p>No records found.</p>'; |
201 |
- } |
202 |
-} |
203 |
- |
204 |
-/** |
205 |
- * Show table headers. |
206 |
- * @param array $headers column name => column title (for table heads) |
207 |
- * @param string $type type of list that is being shown |
208 |
- * @param bool $sortable whether or not to show sortable column headers (links in th's) |
209 |
- */ |
210 |
-function show_headers($headers,$type,$sortable=true) |
211 |
-{ |
212 |
- echo "\n".'<thead><tr>'; |
213 |
- $sort=$_GET['sort']; |
214 |
- $order=get_order(); |
215 |
- $count=0; |
216 |
- foreach ($headers as $col=>$title) |
217 |
- { |
218 |
- if ( !empty($sort) && !empty($order) ) |
219 |
- { |
220 |
- if ($col==$sort && $order=='ASC') |
221 |
- { |
222 |
- $a_class=' class="sort-asc current-sort" '; |
223 |
- } |
224 |
- elseif ($col==$sort && $order=='DESC') |
225 |
- { |
226 |
- $a_class=' class="sort-desc current-sort" '; |
227 |
- } |
228 |
- else |
229 |
- { |
230 |
- $a_class=null; |
231 |
- } |
232 |
- } |
233 |
- if ($type!='simple'&&$count==0) |
234 |
- { |
235 |
- echo "\n".'<th> </th>'; |
236 |
- next; |
237 |
- } |
238 |
- elseif($sortable) |
239 |
- { |
240 |
- $qs = array(); |
241 |
- foreach ($_GET as $qn=>$qv) { $qs[$qn] = $qv; } // existing query string variables |
242 |
- $qs['sort'] = $col; // add/replace sort to query string |
243 |
- $qs['order'] = $order; // add/replace order by to query string |
244 |
- foreach ($qs as $qn=>$qv) { $querystring[] = $qn.'='.$qv; } // existing query string variables |
245 |
- echo "\n".'<th><a '.$a_class.'href="'.$_SERVER['PHP_SELF'].'?'.implode('&',$querystring).'">'.$title.'</a></th>'; |
246 |
- unset($qs); |
247 |
- unset($querystring); |
248 |
- } |
249 |
- else |
250 |
- { |
251 |
- echo "\n".'<th>'.$title.'</th>'; |
252 |
- } |
253 |
- $count++; |
254 |
- } |
255 |
- echo "\n".'</tr></thead>'; |
256 |
-} |
257 |
- |
258 |
-/** |
259 |
- * Show table data. |
260 |
- * @param array $headers column name => column title (for knowing which ones to display) |
261 |
- * @param array $row table row, assoc |
262 |
- * @param string $type type of table, determines first column, which could be an input |
263 |
- * @param array|string $selected selected items; if type is checkbox, array otherwise string with one val |
264 |
- */ |
265 |
-function show_row($headers,$row,$type,$num=null,$selected=null) |
266 |
-{ |
267 |
- $indexes=array_keys($headers); |
268 |
- $idname = $indexes[0]; |
269 |
- $count=0; |
270 |
- $tr_class=($num%2)?' class="row1" ':' class="row2" '; |
271 |
- echo "\n".'<tr'.$tr_class.'>'; |
272 |
- foreach ($indexes as $index) |
273 |
- { |
274 |
- $row[$index]=clean_out($row[$index]); |
275 |
- if ($type!='simple'&&$count==0) |
276 |
- { |
277 |
- $id=preg_replace('/[^[:alnum:]]/', '', $index).$row[$index]; |
278 |
- if ($type=='checkbox'||$type=='checkbox-small') |
279 |
- { |
280 |
- echo "\n".'<td>'; |
281 |
- form_checkbox($idname.'[]',$id,null,$row[$index],(is_array($selected) && in_array($row[$index], $selected))); |
282 |
- echo "\n".'</td>'; |
283 |
- } |
284 |
- elseif ($type=='radio') |
285 |
- { |
286 |
- echo "\n".'<td>'; |
287 |
- form_radio($idname,$id,null,$row[$index], ($row[$index] == $selected)); |
288 |
- echo "\n".'</td>'; |
289 |
- } |
290 |
- } |
291 |
- else |
292 |
- { |
293 |
- echo ($type=='simple')?"\n".'<td>'.$row[$index].'</td>':"\n".'<td><label for="'.$id.'">'.$row[$index].'</label></td>'; |
294 |
- } |
295 |
- $count++; |
296 |
- } |
297 |
- echo "\n".'</tr>'; |
298 |
-} |
299 |
- |
300 |
-/** |
301 |
- * Determine current sort order. |
302 |
- */ |
303 |
-function get_order() |
304 |
-{ |
305 |
- return ($_GET['order']=='ASC')?'DESC':'ASC'; |
306 |
-} |
307 |
- |
308 |
-/** |
309 |
- * Determine whether or not list is currently sorted. |
310 |
- * @param string $method which http method to check for sort information |
311 |
- * @return mixed cleaned orderby clause based on saved sort information or null if no orderby is set in the defined method |
312 |
- */ |
313 |
-function get_orderby($method='get') |
314 |
-{ |
315 |
- if ( $method=='get' && !empty($_GET['sort']) && !empty($_GET['order']) ) |
316 |
- { |
317 |
- $sort=clean_in($_GET['sort']); |
318 |
- $order=clean_in($_GET['order']); |
319 |
- return " ORDER BY $sort $order "; |
320 |
- } |
321 |
- elseif ( $method=='post' && !empty($_POST['sort']) && !empty($_POST['order']) ) |
322 |
- { |
323 |
- $sort=clean_in($_POST['sort']); |
324 |
- $order=clean_in($_POST['order']); |
325 |
- return " ORDER BY $sort $order "; |
326 |
- } |
327 |
- elseif ( $method=='session' && !empty($_SESSION['sort']) && !empty($_SESSION['order']) ) |
328 |
- { |
329 |
- $sort=clean_in($_SESSION['sort']); |
330 |
- $order=clean_in($_SESSION['order']); |
331 |
- return " ORDER BY $sort $order "; |
332 |
- } |
333 |
- else return null; |
334 |
-} |
335 |
- |
336 |
-/** |
337 |
- * Parses $_POST for ids, shows edit forms for each id with populated data. |
338 |
- * <ul> |
339 |
- * <li>name will be used to retrieve an _array_ from $_POST of the same name</li> |
340 |
- * <li>the form will be an include, with $posts[col_name] as the default for all values</li> |
341 |
- * <li>try to keep your query simple (no crazy sorting, etc.) -- we're talking one record at a time here anyway</li> |
342 |
- * </ul> |
343 |
- * Example: |
344 |
- * <code> |
345 |
- * list_edit_ids('course_id','../forms/course.php','SELECT * FROM fic_courses','1'); |
346 |
- * </code> |
347 |
- * @param string $name name of id field |
348 |
- * @param string $form path to form to be used to items |
349 |
- * @param string $q_front front half of query |
350 |
- * @param string $q_where where statement |
351 |
- * @param array $dates array of date field names, so they can be fixed for forms |
352 |
- * @param array $datetimes array of datetime field names, so they can be fixed for forms |
353 |
- */ |
354 |
-function list_edit_ids($name,$form,$q_front,$q_where='1',$dates=null,$datetimes=null) |
355 |
-{ |
356 |
- if ( !empty($_SESSION[$name]) && is_array($_SESSION[$name]) ) |
357 |
- { |
358 |
- $ids=implode(',',$_SESSION[$name]); |
359 |
- $orderby=get_orderby('session'); |
360 |
- $query=$q_front.' WHERE '.$q_where." AND $name IN($ids) ".$orderby; |
361 |
- $records=db_get($query); |
362 |
- form_start($name); |
363 |
- foreach ($records as $record) |
364 |
- { |
365 |
- echo "\n".'<div class="record">'; |
366 |
- $record=form_array_fix_dates($dates,$datetimes,2,$record); |
367 |
- foreach ($record as $key=>$val) |
368 |
- { |
369 |
- $posts[$key]=clean_out($val); |
370 |
- } |
371 |
- include($form); |
372 |
- echo "\n".'<div class="record-submit">'; |
373 |
- form_submit('submit', '', 'button1'); |
374 |
- echo "\n".'</div>'; |
375 |
- echo "\n".'</div>'; |
376 |
- } |
377 |
- form_end(); |
378 |
- } |
379 |
- else |
380 |
- { |
381 |
- echo '<p>You must select a record. <a href="javascript:history.back();">Go back</a>.</p>'; |
382 |
- } |
383 |
-} |
384 |
- |
385 |
-/** |
386 |
- * Process a submitted list_edit_ids form. |
387 |
- * @param array $name array of primary ids posted from the form, these are vital to the WHERE clause of the UPDATE statements. |
388 |
- * @param string $table name of table being affected |
389 |
- */ |
390 |
-function list_update_ids($name,$table) |
391 |
-{ |
392 |
- $keys=array_keys($_POST[$name]); |
393 |
- foreach ($keys as $index) |
394 |
- { |
395 |
- foreach ($_POST as $key=>$val) |
396 |
- { |
397 |
- if ($key!='submit') |
398 |
- { |
399 |
- $posts[$index][$key]=$val[$index]; |
400 |
- } |
401 |
- } |
402 |
- } |
403 |
- foreach ($posts as $dataset) |
404 |
- { |
405 |
- $query=db_makeupdate($dataset,$table," WHERE $name='".$dataset[$name]."' "); |
406 |
- db_query($query); |
407 |
- } |
408 |
-} |
409 |
-?> |