From 7d0f0bf7d27e662293c71ea45c8f73241012537f Mon Sep 17 00:00:00 2001 From: Brian Evans Date: Tue, 30 Jan 2018 14:04:32 -0500 Subject: Update lib/list to be the class ListOut --- php/admin/index.php | 2 +- php/admin/locations.php | 2 +- php/admin/lstats.php | 2 +- php/admin/mstats.php | 2 +- php/admin/os.php | 2 +- php/admin/products.php | 2 +- php/admin/pstats.php | 2 +- php/admin/regions.php | 2 +- php/admin/users.php | 2 +- php/lib/list.php | 56 ++++++++++++++----------------------------------- 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 '

Add a Mirror

'; 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 '

Add a Location

'; 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 '

Location Statistics

'; echo '

This shows whether or not a server is serving up a certain file.

'; -show_list($stats,$headers,'simple'); +ListOut::show($stats,$headers,'simple'); echo '

Save this page as CSV »

'; 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 '

Add a OS

'; 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 '

Add a Product

'; 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 '

Add a Region

'; 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 '

Add a User

'; 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 @@ - * + * @author Mike Morgan + * * Usage example: * - * $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); * * * Accompanying CSS for table output: @@ -97,17 +97,19 @@ * */ +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".''; - show_headers($headers,$type,$sortable); + static::showHeaders($headers,$type,$sortable); echo "\n".''; foreach ($list as $row) { - show_row($headers,$row,$type,$count++,$selected); + static::showRow($headers,$row,$type,$count++,$selected); } echo "\n".''; echo "\n".'
'; @@ -156,7 +158,7 @@ js; } if ($type=='radio'||$type='checkbox-small') { - echo '
'; + echo '
'; } 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".''; $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; } -- cgit v1.2.3-65-gdbad