From 6d63303f496c1265c27d3007bae6d80cf853775d Mon Sep 17 00:00:00 2001 From: Filipp Lepalaan Date: Wed, 4 Apr 2012 17:54:57 +0300 Subject: Lots of experimental changes --- gsxcl | 177 ++++++++++++++++++++++++++++++++++++++++-------------------------- 1 file changed, 107 insertions(+), 70 deletions(-) (limited to 'gsxcl') diff --git a/gsxcl b/gsxcl index 7781f53..7bb0ee6 100755 --- a/gsxcl +++ b/gsxcl @@ -14,19 +14,22 @@ * http://sam.zoy.org/wtfpl/COPYING for more details. */ -if (FALSE) { - error_reporting(E_ALL|E_STRICT); +if (TRUE) { + error_reporting( E_ALL|E_STRICT ); } -$modes = array( 'warranty', 'parts', 'pending', 'repair', 'lookup', 'status', 'label', 'model', 'osdispatchdetail' ); -$modes_str = implode(', ', $modes); +$verbs = array( 'create', 'lookup', 'update', 'status', 'label', 'pending', 'details' ); +$nouns = array( 'repair', 'part', 'dispatch', 'order', 'return', 'warranty' ); + +$nouns_str = implode( ', ', $nouns ); +$verbs_str = implode( ', ', $verbs ); require 'gsxlib.php'; -if (count($argv) < 6) { +if( count( $argv ) < 6 ) { echo <<warrantyStatus($query); - break; - case 'parts': - $result = $gsx->partsLookup($query); - break; - case 'pending': - $result = $gsx->partsPendingReturn($query); - break; + switch( $verb ) { + case 'status': + $result = $gsx->warrantyStatus( $data ); + break; + } + + break; + + case 'part': + switch( $verb ) { + case 'lookup': + $result = $gsx->partsLookup( $data ); + break; + case 'pending': + $result = $gsx->partsPendingReturn( $data ); + break; + case 'details': + $result = $gsx->partsPendingReturn( $data ); + break; + } + + break; + case 'repair': - $result = $gsx->repairDetails($query); - break; - case 'lookup': - $result = $gsx->repairLookup($query); - break; - case 'status': - $result = $gsx->repairStatus($query); - break; - case 'comptia': - $result = $gsx->compTiaCodes(); - break; + switch( $verb ) { + case 'lookup': + $result = $gsx->repairLookup( $data ); + break; + case 'details': + $result = $gsx->partsPendingReturn( $data ); + break; + case 'status': + $result = $gsx->repairStatus( $query ); + break; + } + case 'model': $result = $gsx->productModel( $query ); break; @@ -104,55 +130,66 @@ switch ($mode) $result = $gsx->onsiteDispatchDetail( $query ); break; case 'label': - list($order, $part) = explode(':', $query); - $result = $gsx->returnLabel($order, $part); + list($order, $part) = explode( ':', $query ); + $result = $gsx->returnLabel( $order, $part ); $name = $result->returnLabelFileName; echo $result->returnLabelFileData; break; } -switch ($format) +switch( $format ) { case 'json': - echo json_encode($result); + echo json_encode( $result ); break; + case 'xml': - $xml = simplexml_load_string(''); + if( !function_exists( 'simplexml_load_string' )) { + exit( "Error: your PHP lacks SimpleXML support!\n" ); + } + + $xml = simplexml_load_string( '' ); + foreach ($result as $k => $v) { - $key = (is_numeric($k)) ? 'item' : $k; - $value = (is_object($v)) ? null : $v; - $item = $xml->addChild($key, $value); - if (is_object($v)) { - foreach ($v as $vk => $vv) { - $item->addChild($vk, $vv); + $key = (is_numeric( $k )) ? 'item' : $k; + $value = (is_object( $v )) ? null : $v; + $item = $xml->addChild( $key, $value ); + if( is_object( $v )) { + foreach( $v as $vk => $vv ) { + $item->addChild( $vk, $vv ); } } } + echo $xml->asXML(); break; + case 'csv': $i = 0; $fo = fopen('php://stdout', 'w'); - foreach ($result as $k => $v) + foreach( $result as $k => $v ) { - if (is_object($v)) + if( is_object( $v )) { $keys = array(); $vals = array(); - foreach ($v as $vk => $vv) - { + + foreach ($v as $vk => $vv) { if ($i == 0) { $keys[] = $vk; } $vals[] = $vv; } + // treat field names of first item as header row if ($i == 0) { - fputcsv($fo, $keys); + fputcsv( $fo, $keys ); } - fputcsv($fo, $vals); + + fputcsv( $fo, $vals ); + } else { $keys[] = $k; $vals[] = $v; -- cgit v1.2.3