Gentoo Archives: gentoo-commits

From: Brian Evans <grknight@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/bouncer:master commit in: php/lib/, php/admin/
Date: Tue, 30 Jan 2018 20:19:07
Message-Id: 1517339072.7d0f0bf7d27e662293c71ea45c8f73241012537f.grknight@gentoo
1 commit: 7d0f0bf7d27e662293c71ea45c8f73241012537f
2 Author: Brian Evans <grknight <AT> gentoo <DOT> org>
3 AuthorDate: Tue Jan 30 19:04:32 2018 +0000
4 Commit: Brian Evans <grknight <AT> gentoo <DOT> org>
5 CommitDate: Tue Jan 30 19:04:32 2018 +0000
6 URL: https://gitweb.gentoo.org/proj/bouncer.git/commit/?id=7d0f0bf7
7
8 Update lib/list to be the class ListOut
9
10 php/admin/index.php | 2 +-
11 php/admin/locations.php | 2 +-
12 php/admin/lstats.php | 2 +-
13 php/admin/mstats.php | 2 +-
14 php/admin/os.php | 2 +-
15 php/admin/products.php | 2 +-
16 php/admin/pstats.php | 2 +-
17 php/admin/regions.php | 2 +-
18 php/admin/users.php | 2 +-
19 php/lib/list.php | 56 ++++++++++++++-----------------------------------
20 10 files changed, 25 insertions(+), 49 deletions(-)
21
22 diff --git a/php/admin/index.php b/php/admin/index.php
23 index aceae66..1e08189 100644
24 --- a/php/admin/index.php
25 +++ b/php/admin/index.php
26 @@ -98,7 +98,7 @@ $actions = array(
27 );
28
29 form_start();
30 -show_list($mirrors,$headers,'radio',$actions);
31 +ListOut::show($mirrors,$headers,'radio',$actions);
32 form_end();
33
34 echo '<h2>Add a Mirror</h2>';
35
36 diff --git a/php/admin/locations.php b/php/admin/locations.php
37 index 138cff1..029594e 100644
38 --- a/php/admin/locations.php
39 +++ b/php/admin/locations.php
40 @@ -87,7 +87,7 @@ $actions = array(
41 );
42
43 form_start();
44 -show_list($locations,$headers,'radio',$actions);
45 +ListOut::show($locations,$headers,'radio',$actions);
46 form_end();
47
48 echo '<h2>Add a Location</h2>';
49
50 diff --git a/php/admin/lstats.php b/php/admin/lstats.php
51 index 9416eb5..667d9cb 100644
52 --- a/php/admin/lstats.php
53 +++ b/php/admin/lstats.php
54 @@ -51,7 +51,7 @@ echo '<h2>Location Statistics</h2>';
55
56 echo '<p>This shows whether or not a server is serving up a certain file.</p>';
57
58 -show_list($stats,$headers,'simple');
59 +ListOut::show($stats,$headers,'simple');
60
61 echo '<p><a href="./lstats.php?csv=1&amp;sort='.$_GET['sort'].'&amp;order='.$_GET['order'].'">Save this page as CSV &raquo;</a></p>';
62
63
64 diff --git a/php/admin/mstats.php b/php/admin/mstats.php
65 index 284dcf4..46c1b89 100644
66 --- a/php/admin/mstats.php
67 +++ b/php/admin/mstats.php
68 @@ -26,6 +26,6 @@ $headers = array(
69 'region_name'=>'Region'
70 );
71
72 -show_list($stats,$headers,'simple');
73 +ListOut::show($stats,$headers,'simple');
74
75 require_once(FOOTER);
76
77 diff --git a/php/admin/os.php b/php/admin/os.php
78 index 731d405..8be6c0e 100644
79 --- a/php/admin/os.php
80 +++ b/php/admin/os.php
81 @@ -87,7 +87,7 @@ $actions = array(
82 );
83
84 form_start();
85 -show_list($oss,$headers,'radio',$actions);
86 +ListOut::show($oss,$headers,'radio',$actions);
87 form_end();
88
89 echo '<h2>Add a OS</h2>';
90
91 diff --git a/php/admin/products.php b/php/admin/products.php
92 index 962a3cd..fbf5e87 100644
93 --- a/php/admin/products.php
94 +++ b/php/admin/products.php
95 @@ -88,7 +88,7 @@ $actions = array(
96 );
97
98 form_start();
99 -show_list($products,$headers,'radio',$actions);
100 +ListOut::show($products,$headers,'radio',$actions);
101 form_end();
102
103 echo '<h2>Add a Product</h2>';
104
105 diff --git a/php/admin/pstats.php b/php/admin/pstats.php
106 index ef887bd..5e2e593 100644
107 --- a/php/admin/pstats.php
108 +++ b/php/admin/pstats.php
109 @@ -23,6 +23,6 @@ $headers = array(
110 'product_name'=>'Product'
111 );
112
113 -show_list($stats,$headers,'simple');
114 +ListOut::show($stats,$headers,'simple');
115
116 require_once(FOOTER);
117
118 diff --git a/php/admin/regions.php b/php/admin/regions.php
119 index f2b6b54..370f953 100644
120 --- a/php/admin/regions.php
121 +++ b/php/admin/regions.php
122 @@ -88,7 +88,7 @@ $actions = array(
123 );
124
125 form_start();
126 -show_list($regions,$headers,'radio',$actions);
127 +ListOut::show($regions,$headers,'radio',$actions);
128 form_end();
129
130 echo '<h2>Add a Region</h2>';
131
132 diff --git a/php/admin/users.php b/php/admin/users.php
133 index 4814f0d..c200a70 100644
134 --- a/php/admin/users.php
135 +++ b/php/admin/users.php
136 @@ -91,7 +91,7 @@ $actions = array(
137 );
138
139 form_start();
140 -show_list($users,$headers,'radio',$actions);
141 +ListOut::show($users,$headers,'radio',$actions);
142 form_end();
143
144 echo '<h2>Add a User</h2>';
145
146 diff --git a/php/lib/list.php b/php/lib/list.php
147 index 86334c0..4709769 100644
148 --- a/php/lib/list.php
149 +++ b/php/lib/list.php
150 @@ -1,13 +1,13 @@
151 <?php
152 /**
153 * List functions for lists of values.
154 - * @package mirror
155 + * @package mirror
156 * @subpackage lib
157 - * @author Mike Morgan <mike.morgan@×××××××××××.edu>
158 - *
159 + * @author Mike Morgan <mike.morgan@×××××××××××.edu>
160 + *
161 * Usage example:
162 * <code>
163 - * $orderby=get_order();
164 + * $orderby=List::getOrder();
165 * $query="SELECT * FROM fic_courses $orderby";
166 * $courses=DB::get($query,PDO::FETCH_ASSOC);
167 * $headers=array(
168 @@ -20,7 +20,7 @@
169 * 'active'=>'Active?',
170 * 'entry_date'=>'Created'
171 * );
172 - * show_list($courses,$headers);
173 + * List::show($courses,$headers);
174 * </code>
175 *
176 * Accompanying CSS for table output:
177 @@ -97,17 +97,19 @@
178 * </code>
179 */
180
181 +class ListOut {
182 +
183 /**
184 * Show a list of values, for forms.
185 * @param array $list associative array
186 * @param array $headers column name => column title (for table heads)
187 * @param string $type checkbox, radio, simple
188 - * @param array $array actions to display in actions select list
189 + * @param array $array actions to display in actions select list
190 * @param string $form_id id of form holding list
191 * @param bool $sortable whether or not to show sortable column headers (links in th's)
192 * @param array|string $selected if type is checkbox, array otherwise string with one val
193 */
194 -function show_list($list,$headers,$type='checkbox',$actions=null,$form_id=null,$sortable=true,$selected=null)
195 +public static function show($list,$headers,$type='checkbox',$actions=null,$form_id=null,$sortable=true,$selected=null)
196 {
197 $count = 0;
198 if ( is_array($list) && count($list)>0 && is_array($headers) )
199 @@ -118,11 +120,11 @@ function show_list($list,$headers,$type='checkbox',$actions=null,$form_id=null,$
200 form_hidden('order',$_GET['order']);
201 }
202 echo "\n".'<table class="list">';
203 - show_headers($headers,$type,$sortable);
204 + static::showHeaders($headers,$type,$sortable);
205 echo "\n".'<tbody>';
206 foreach ($list as $row)
207 {
208 - show_row($headers,$row,$type,$count++,$selected);
209 + static::showRow($headers,$row,$type,$count++,$selected);
210 }
211 echo "\n".'</tbody>';
212 echo "\n".'</table>';
213 @@ -156,7 +158,7 @@ js;
214 }
215 if ($type=='radio'||$type='checkbox-small')
216 {
217 - echo '<br />';
218 + echo '<br />';
219 }
220 if (is_array($actions)&&$type!='simple')
221 {
222 @@ -190,11 +192,11 @@ js;
223 * @param string $type type of list that is being shown
224 * @param bool $sortable whether or not to show sortable column headers (links in th's)
225 */
226 -function show_headers($headers,$type,$sortable=true)
227 +private static function showHeaders($headers,$type,$sortable=true)
228 {
229 echo "\n".'<thead><tr>';
230 $sort=$_GET['sort'];
231 - $order=get_order();
232 + $order=static::getOrder();
233 $count=0;
234 foreach ($headers as $col=>$title)
235 {
236 @@ -244,7 +246,7 @@ function show_headers($headers,$type,$sortable=true)
237 * @param string $type type of table, determines first column, which could be an input
238 * @param array|string $selected selected items; if type is checkbox, array otherwise string with one val
239 */
240 -function show_row($headers,$row,$type,$num=null,$selected=null)
241 +private static function showRow($headers,$row,$type,$num=null,$selected=null)
242 {
243 $indexes=array_keys($headers);
244 $idname = $indexes[0];
245 @@ -282,35 +284,9 @@ function show_row($headers,$row,$type,$num=null,$selected=null)
246 /**
247 * Determine current sort order.
248 */
249 -function get_order()
250 +public static function getOrder()
251 {
252 return ($_GET['order']=='ASC')?'DESC':'ASC';
253 }
254
255 -/**
256 - * Determine whether or not list is currently sorted.
257 - * @param string $method which http method to check for sort information
258 - * @return mixed cleaned orderby clause based on saved sort information or null if no orderby is set in the defined method
259 - */
260 -function get_orderby($method='get')
261 -{
262 - if ( $method=='get' && !empty($_GET['sort']) && !empty($_GET['order']) )
263 - {
264 - $sort=clean_in($_GET['sort']);
265 - $order=clean_in($_GET['order']);
266 - return " ORDER BY $sort $order ";
267 - }
268 - elseif ( $method=='post' && !empty($_POST['sort']) && !empty($_POST['order']) )
269 - {
270 - $sort=clean_in($_POST['sort']);
271 - $order=clean_in($_POST['order']);
272 - return " ORDER BY $sort $order ";
273 - }
274 - elseif ( $method=='session' && !empty($_SESSION['sort']) && !empty($_SESSION['order']) )
275 - {
276 - $sort=clean_in($_SESSION['sort']);
277 - $order=clean_in($_SESSION['order']);
278 - return " ORDER BY $sort $order ";
279 - }
280 - else return null;
281 }