aboutsummaryrefslogtreecommitdiff
path: root/php
diff options
context:
space:
mode:
authorBrian Evans <grknight@gentoo.org>2018-01-30 14:04:32 -0500
committerBrian Evans <grknight@gentoo.org>2018-01-30 14:04:32 -0500
commit7d0f0bf7d27e662293c71ea45c8f73241012537f (patch)
tree822a010543da30991904096e40e7b0c559ba6a3f /php
parentRemove a debugging statement from index (diff)
downloadbouncer-7d0f0bf7d27e662293c71ea45c8f73241012537f.tar.gz
bouncer-7d0f0bf7d27e662293c71ea45c8f73241012537f.tar.bz2
bouncer-7d0f0bf7d27e662293c71ea45c8f73241012537f.zip
Update lib/list to be the class ListOut
Diffstat (limited to 'php')
-rw-r--r--php/admin/index.php2
-rw-r--r--php/admin/locations.php2
-rw-r--r--php/admin/lstats.php2
-rw-r--r--php/admin/mstats.php2
-rw-r--r--php/admin/os.php2
-rw-r--r--php/admin/products.php2
-rw-r--r--php/admin/pstats.php2
-rw-r--r--php/admin/regions.php2
-rw-r--r--php/admin/users.php2
-rw-r--r--php/lib/list.php56
10 files changed, 25 insertions, 49 deletions
diff --git a/php/admin/index.php b/php/admin/index.php
index aceae66..1e08189 100644
--- a/php/admin/index.php
+++ b/php/admin/index.php
@@ -98,7 +98,7 @@ $actions = array(
);
form_start();
-show_list($mirrors,$headers,'radio',$actions);
+ListOut::show($mirrors,$headers,'radio',$actions);
form_end();
echo '<h2>Add a Mirror</h2>';
diff --git a/php/admin/locations.php b/php/admin/locations.php
index 138cff1..029594e 100644
--- a/php/admin/locations.php
+++ b/php/admin/locations.php
@@ -87,7 +87,7 @@ $actions = array(
);
form_start();
-show_list($locations,$headers,'radio',$actions);
+ListOut::show($locations,$headers,'radio',$actions);
form_end();
echo '<h2>Add a Location</h2>';
diff --git a/php/admin/lstats.php b/php/admin/lstats.php
index 9416eb5..667d9cb 100644
--- a/php/admin/lstats.php
+++ b/php/admin/lstats.php
@@ -51,7 +51,7 @@ echo '<h2>Location Statistics</h2>';
echo '<p>This shows whether or not a server is serving up a certain file.</p>';
-show_list($stats,$headers,'simple');
+ListOut::show($stats,$headers,'simple');
echo '<p><a href="./lstats.php?csv=1&amp;sort='.$_GET['sort'].'&amp;order='.$_GET['order'].'">Save this page as CSV &raquo;</a></p>';
diff --git a/php/admin/mstats.php b/php/admin/mstats.php
index 284dcf4..46c1b89 100644
--- a/php/admin/mstats.php
+++ b/php/admin/mstats.php
@@ -26,6 +26,6 @@ $headers = array(
'region_name'=>'Region'
);
-show_list($stats,$headers,'simple');
+ListOut::show($stats,$headers,'simple');
require_once(FOOTER);
diff --git a/php/admin/os.php b/php/admin/os.php
index 731d405..8be6c0e 100644
--- a/php/admin/os.php
+++ b/php/admin/os.php
@@ -87,7 +87,7 @@ $actions = array(
);
form_start();
-show_list($oss,$headers,'radio',$actions);
+ListOut::show($oss,$headers,'radio',$actions);
form_end();
echo '<h2>Add a OS</h2>';
diff --git a/php/admin/products.php b/php/admin/products.php
index 962a3cd..fbf5e87 100644
--- a/php/admin/products.php
+++ b/php/admin/products.php
@@ -88,7 +88,7 @@ $actions = array(
);
form_start();
-show_list($products,$headers,'radio',$actions);
+ListOut::show($products,$headers,'radio',$actions);
form_end();
echo '<h2>Add a Product</h2>';
diff --git a/php/admin/pstats.php b/php/admin/pstats.php
index ef887bd..5e2e593 100644
--- a/php/admin/pstats.php
+++ b/php/admin/pstats.php
@@ -23,6 +23,6 @@ $headers = array(
'product_name'=>'Product'
);
-show_list($stats,$headers,'simple');
+ListOut::show($stats,$headers,'simple');
require_once(FOOTER);
diff --git a/php/admin/regions.php b/php/admin/regions.php
index f2b6b54..370f953 100644
--- a/php/admin/regions.php
+++ b/php/admin/regions.php
@@ -88,7 +88,7 @@ $actions = array(
);
form_start();
-show_list($regions,$headers,'radio',$actions);
+ListOut::show($regions,$headers,'radio',$actions);
form_end();
echo '<h2>Add a Region</h2>';
diff --git a/php/admin/users.php b/php/admin/users.php
index 4814f0d..c200a70 100644
--- a/php/admin/users.php
+++ b/php/admin/users.php
@@ -91,7 +91,7 @@ $actions = array(
);
form_start();
-show_list($users,$headers,'radio',$actions);
+ListOut::show($users,$headers,'radio',$actions);
form_end();
echo '<h2>Add a User</h2>';
diff --git a/php/lib/list.php b/php/lib/list.php
index 86334c0..4709769 100644
--- a/php/lib/list.php
+++ b/php/lib/list.php
@@ -1,13 +1,13 @@
<?php
/**
* List functions for lists of values.
- * @package mirror
+ * @package mirror
* @subpackage lib
- * @author Mike Morgan <mike.morgan@oregonstate.edu>
- *
+ * @author Mike Morgan <mike.morgan@oregonstate.edu>
+ *
* Usage example:
* <code>
- * $orderby=get_order();
+ * $orderby=List::getOrder();
* $query="SELECT * FROM fic_courses $orderby";
* $courses=DB::get($query,PDO::FETCH_ASSOC);
* $headers=array(
@@ -20,7 +20,7 @@
* 'active'=>'Active?',
* 'entry_date'=>'Created'
* );
- * show_list($courses,$headers);
+ * List::show($courses,$headers);
* </code>
*
* Accompanying CSS for table output:
@@ -97,17 +97,19 @@
* </code>
*/
+class ListOut {
+
/**
* Show a list of values, for forms.
* @param array $list associative array
* @param array $headers column name => column title (for table heads)
* @param string $type checkbox, radio, simple
- * @param array $array actions to display in actions select list
+ * @param array $array actions to display in actions select list
* @param string $form_id id of form holding list
* @param bool $sortable whether or not to show sortable column headers (links in th's)
* @param array|string $selected if type is checkbox, array otherwise string with one val
*/
-function show_list($list,$headers,$type='checkbox',$actions=null,$form_id=null,$sortable=true,$selected=null)
+public static function show($list,$headers,$type='checkbox',$actions=null,$form_id=null,$sortable=true,$selected=null)
{
$count = 0;
if ( is_array($list) && count($list)>0 && is_array($headers) )
@@ -118,11 +120,11 @@ function show_list($list,$headers,$type='checkbox',$actions=null,$form_id=null,$
form_hidden('order',$_GET['order']);
}
echo "\n".'<table class="list">';
- show_headers($headers,$type,$sortable);
+ static::showHeaders($headers,$type,$sortable);
echo "\n".'<tbody>';
foreach ($list as $row)
{
- show_row($headers,$row,$type,$count++,$selected);
+ static::showRow($headers,$row,$type,$count++,$selected);
}
echo "\n".'</tbody>';
echo "\n".'</table>';
@@ -156,7 +158,7 @@ js;
}
if ($type=='radio'||$type='checkbox-small')
{
- echo '<br />';
+ echo '<br />';
}
if (is_array($actions)&&$type!='simple')
{
@@ -190,11 +192,11 @@ js;
* @param string $type type of list that is being shown
* @param bool $sortable whether or not to show sortable column headers (links in th's)
*/
-function show_headers($headers,$type,$sortable=true)
+private static function showHeaders($headers,$type,$sortable=true)
{
echo "\n".'<thead><tr>';
$sort=$_GET['sort'];
- $order=get_order();
+ $order=static::getOrder();
$count=0;
foreach ($headers as $col=>$title)
{
@@ -244,7 +246,7 @@ function show_headers($headers,$type,$sortable=true)
* @param string $type type of table, determines first column, which could be an input
* @param array|string $selected selected items; if type is checkbox, array otherwise string with one val
*/
-function show_row($headers,$row,$type,$num=null,$selected=null)
+private static function showRow($headers,$row,$type,$num=null,$selected=null)
{
$indexes=array_keys($headers);
$idname = $indexes[0];
@@ -282,35 +284,9 @@ function show_row($headers,$row,$type,$num=null,$selected=null)
/**
* Determine current sort order.
*/
-function get_order()
+public static function getOrder()
{
return ($_GET['order']=='ASC')?'DESC':'ASC';
}
-/**
- * Determine whether or not list is currently sorted.
- * @param string $method which http method to check for sort information
- * @return mixed cleaned orderby clause based on saved sort information or null if no orderby is set in the defined method
- */
-function get_orderby($method='get')
-{
- if ( $method=='get' && !empty($_GET['sort']) && !empty($_GET['order']) )
- {
- $sort=clean_in($_GET['sort']);
- $order=clean_in($_GET['order']);
- return " ORDER BY $sort $order ";
- }
- elseif ( $method=='post' && !empty($_POST['sort']) && !empty($_POST['order']) )
- {
- $sort=clean_in($_POST['sort']);
- $order=clean_in($_POST['order']);
- return " ORDER BY $sort $order ";
- }
- elseif ( $method=='session' && !empty($_SESSION['sort']) && !empty($_SESSION['order']) )
- {
- $sort=clean_in($_SESSION['sort']);
- $order=clean_in($_SESSION['order']);
- return " ORDER BY $sort $order ";
- }
- else return null;
}