From: Ben Klang Date: Sun, 10 Jan 2010 18:21:08 +0000 (-0500) Subject: Operator: Continue porting to Horde 4. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=978a721195a700bd4a97b78d36cfa6d5a3802c84;p=horde.git Operator: Continue porting to Horde 4. * Whitespace and coding changes * Remove call to Horde_Date#correct() (handled by __set() override) * Remove require_once statements * Create lib/Application.php and remove lib/base.php --- diff --git a/operator/graphgen.php b/operator/graphgen.php index 06e186df8..bbf5a88bd 100644 --- a/operator/graphgen.php +++ b/operator/graphgen.php @@ -1,8 +1,6 @@ + * Copyright 2008-2010 The Horde Project * * See the enclosed file COPYING for license information (GPL). If you * did not receive this file, see http://www.fsf.org/copyleft/gpl.html. @@ -10,14 +8,13 @@ * @author Ben Klang */ -@define('OPERATOR_BASE', dirname(__FILE__)); -require_once OPERATOR_BASE . '/lib/base.php'; +require_once dirname(__FILE__) . '/lib/Application.php'; -// Load PEAR's Image_Graph library -require_once 'Image/Graph.php'; +$operator = new Operator_Application(array('init' => true)); +$cache = &$GLOBALS['cache']; #setlocale(LC_ALL, Horde_Nls::select()); -setlocale(LC_ALL, 'en_US'); +#setlocale(LC_ALL, 'en_US'); $graphtype = Horde_Util::getFormData('graph'); $graphinfo = Operator::getGraphInfo($graphtype); @@ -42,7 +39,9 @@ if (!isset($graphinfo['legendsplit'])) { $graphinfo['legendsplit'] = 90; } -$canvas =& Image_Canvas::factory('png', array('width' => $graphinfo['imageX'], 'height' => $graphinfo['imageY'], 'antialias' => true)); +$canvas =& Image_Canvas::factory('png', array('width' => $graphinfo['imageX'], + 'height' => $graphinfo['imageY'], + 'antialias' => true)); $graph =& Image_Graph::factory('graph', $canvas); if (isset($graphinfo['orientation']) && @@ -59,13 +58,17 @@ if (!empty($conf['ttf_font'])) { $Font->setSize(8); $graph->setFont($Font); } - - + // create the plotarea layout if ($graph->horizontal) { - $plotarea =& Image_Graph::factory('plotarea', array('Image_Graph_Axis_Category', 'Image_Graph_Axis', 'horizontal')); + $plotarea = Image_Graph::factory('plotarea', + array('Image_Graph_Axis_Category', + 'Image_Graph_Axis', 'horizontal')); } else { - $plotarea =& Image_Graph::factory('plotarea', array('Image_Graph_Axis_Category', 'Image_Graph_Axis', 'vertical')); + $plotarea = Image_Graph::factory('plotarea', + array('Image_Graph_Axis_Category', + 'Image_Graph_Axis', + 'vertical')); } $graph->add( @@ -78,22 +81,22 @@ $graph->add( ), 5 ) -); +); $plotarea->setAxisPadding(array('top' => 20)); - + // make the legend use the plotarea (or implicitly its plots) -$legend->setPlotarea($plotarea); - +$legend->setPlotarea($plotarea); + // create a grid and assign it to the secondary Y axis -$gridY2 =& $plotarea->addNew('line_grid', IMAGE_GRAPH_AXIS_Y_SECONDARY); +$gridY2 =& $plotarea->addNew('line_grid', IMAGE_GRAPH_AXIS_Y_SECONDARY); #$gridY2->setLineColor('black'); #$gridY2->setFillStyle( # Image_Graph::factory( -# 'gradient', +# 'gradient', # array(IMAGE_GRAPH_GRAD_HORIZONTAL, 'white', 'lightgrey') # ) -#); +#); $linecolor = 0x000042; $increment = 0x173147; @@ -132,8 +135,8 @@ foreach ($stats[$graphtype] as $title => $data) { $marker->setBorderColor(false); $marker->setFillColor(false); // and use the marker on the 1st plot - $plot->setMarker($PointingMarker); - + $plot->setMarker($PointingMarker); + #if (!empty($graphinfo['numberformat'])) { # $marker->setDataPreprocessor(Image_Graph::factory('Image_Graph_DataPreprocessor_Formatted', $graphinfo['numberformat'])); #} @@ -143,30 +146,30 @@ foreach ($stats[$graphtype] as $title => $data) { } // create an area plot using a random dataset -#$dataset2 =& Image_Graph::factory('random', array(8, 1, 10, true)); +#$dataset2 =& Image_Graph::factory('random', array(8, 1, 10, true)); #$plot2 =& $plotarea->addNew( -# 'Image_Graph_Plot_Area', -# $dataset2, +# 'Image_Graph_Plot_Area', +# $dataset2, # IMAGE_GRAPH_AXIS_Y_SECONDARY #); - + #$plot2->setLineColor('gray'); #$plot2->setFillColor('blue@0.2'); #$plot2->setTitle('Secondary Axis'); - + $axisX =& $plotarea->getAxis(IMAGE_GRAPH_AXIS_X); $axisY =& $plotarea->getAxis(IMAGE_GRAPH_AXIS_Y); if ($graph->horizontal) { $axisX->setTitle($graphinfo['axisX'], 'vertical'); - $axisY->setTitle($graphinfo['axisY'], 'horizontal'); + $axisY->setTitle($graphinfo['axisY'], 'horizontal'); } else { $axisX->setTitle($graphinfo['axisX'], 'horizontal'); - $axisY->setTitle($graphinfo['axisY'], 'vertical'); + $axisY->setTitle($graphinfo['axisY'], 'vertical'); } $axisY->setDataPreprocessor(Image_Graph::factory('Image_Graph_DataPreprocessor_Function', 'axis2human')); #$axisYsecondary =& $plotarea->getAxis(IMAGE_GRAPH_AXIS_Y_SECONDARY); -#$axisYsecondary->setTitle('Pears', 'vertical2'); - +#$axisYsecondary->setTitle('Pears', 'vertical2'); + // output the Graph $graph->done(); exit; diff --git a/operator/index.php b/operator/index.php index bb539f4c6..0c688e482 100644 --- a/operator/index.php +++ b/operator/index.php @@ -1,8 +1,6 @@ */ -@define('OPERATOR_BASE', dirname(__FILE__)); -$operator_configured = (is_readable(OPERATOR_BASE . '/config/conf.php')); - -if (!$operator_configured) { - require OPERATOR_BASE . '/../lib/Test.php'; - Horde_Test::configFilesMissing('Operator', OPERATOR_BASE, - array('conf.php')); -} - -require OPERATOR_BASE . '/viewgraph.php'; +require 'viewgraph.php'; diff --git a/operator/lib/Application.php b/operator/lib/Application.php new file mode 100644 index 000000000..c686f965e --- /dev/null +++ b/operator/lib/Application.php @@ -0,0 +1,100 @@ + + * @package Shout + */ +if (!defined('OPERATOR_BASE')) { + define('OPERATOR_BASE', dirname(__FILE__). '/..'); +} + +if (!defined('HORDE_BASE')) { + /* If horde does not live directly under the app directory, the HORDE_BASE + * constant should be defined in config/horde.local.php. */ + if (file_exists(OPERATOR_BASE. '/config/horde.local.php')) { + include OPERATOR_BASE . '/config/horde.local.php'; + } else { + define('HORDE_BASE', OPERATOR_BASE . '/..'); + } +} + +/* Load the Horde Framework core (needed to autoload + * Horde_Registry_Application::). */ +require_once HORDE_BASE . '/lib/core.php'; + +class Operator_Application extends Horde_Registry_Application +{ + public $version = 'H4 (1.0-git)'; + public $driver = null; + + public function __construct($args = array()) + { + if (!empty($args['init'])) { + // Registry. + $GLOBALS['registry'] = Horde_Registry::singleton(); + $registry = &$GLOBALS['registry']; + + try { + $registry->pushApp('operator', !defined('AUTH_HANDLER')); + } catch (Horde_Exception $e) { + if ($e->getCode() == 'permission_denied') { + Horde::authenticationFailureRedirect(); + } + Horde::fatal($e, __FILE__, __LINE__, false); + } + $conf = &$GLOBALS['conf']; + @define('OPERATOR_TEMPLATES', $registry->get('templates')); + + // Notification system. + $GLOBALS['notification'] = &Horde_Notification::singleton(); + $notification = &$GLOBALS['notification']; + $notification->attach('status'); + + // Define the base file path of Operator. + @define('OPERATOR_BASE', dirname(__FILE__) . '/..'); + + // Operator base library + require_once OPERATOR_BASE . '/lib/Operator.php'; + + // Operator backend. + require_once OPERATOR_BASE . '/lib/Driver.php'; + $this->driver = Operator_Driver::factory(); + + // Caching system for storing DB results + $GLOBALS['cache'] = &Horde_Cache::singleton($conf['cache']['driver'], + Horde::getDriverConfig('cache', $conf['cache']['driver'])); + + // Start output compression. + Horde::compressOutput(); + } + } + + public function perms() + { + static $perms = array(); + + if (!empty($perms)) { + return $perms; + } + + $perms['tree']['operator']['accountcodes'] = false; + $perms['title']['operator:accountcodes'] = _("Account Codes"); + + $accountcodes = Operator::getAccountCodes(); + foreach ($accountcodes as $accountcode) { + $perms['tree']['operator']['accountcodes'][$accountcode] = false; + $perms['title']['operator:accountcodes:' . $accountcode] = $accountcode; + } + + return $perms; + } +} diff --git a/operator/lib/Driver/asterisksql.php b/operator/lib/Driver/asterisksql.php index d7c9fa49e..48181d7c3 100644 --- a/operator/lib/Driver/asterisksql.php +++ b/operator/lib/Driver/asterisksql.php @@ -326,7 +326,6 @@ class Operator_Driver_asterisksql extends Operator_Driver { // Find the first day of the next month $start->month++; - $start->correct(); } $info = Operator::getGraphInfo('numcalls'); diff --git a/operator/lib/base.php b/operator/lib/base.php deleted file mode 100644 index 17ab6b543..000000000 --- a/operator/lib/base.php +++ /dev/null @@ -1,56 +0,0 @@ - - */ - -// Check for a prior definition of HORDE_BASE (perhaps by an auto_prepend_file -// definition for site customization). -if (!defined('HORDE_BASE')) { - @define('HORDE_BASE', dirname(__FILE__) . '/../../..'); -} - -// Load the Horde Framework core, and set up inclusion paths. -require_once HORDE_BASE . '/lib/core.php'; - -// Registry. -$registry = Horde_Registry::singleton(); -try { - $registry->pushApp('operator', !defined('AUTH_HANDLER')); -} catch (Horde_Exception $e) { - if ($e->getCode() == 'permission_denied') { - Horde::authenticationFailureRedirect(); - } - Horde::fatal($e, __FILE__, __LINE__, false); -} -$conf = &$GLOBALS['conf']; -@define('OPERATOR_TEMPLATES', $registry->get('templates')); - -// Notification system. -$notification = &Horde_Notification::singleton(); -$notification->attach('status'); - -// Define the base file path of Operator. -@define('OPERATOR_BASE', dirname(__FILE__) . '/..'); - -// Operator base library -require_once OPERATOR_BASE . '/lib/Operator.php'; - -// Operator backend. -require_once OPERATOR_BASE . '/lib/Driver.php'; -$GLOBALS['operator_driver'] = Operator_Driver::factory(); - -// Caching system for storing DB results -$cache = &Horde_Cache::singleton($GLOBALS['conf']['cache']['driver'], - Horde::getDriverConfig('cache', $GLOBALS['conf']['cache']['driver'])); - -// Start output compression. -Horde::compressOutput(); diff --git a/operator/search.php b/operator/search.php index 3eae3e5db..8f31a5adc 100644 --- a/operator/search.php +++ b/operator/search.php @@ -10,12 +10,11 @@ * @author Ben Klang */ -@define('OPERATOR_BASE', dirname(__FILE__)); -require_once OPERATOR_BASE . '/lib/base.php'; +require_once dirname(__FILE__) . '/lib/Application.php'; + +$operator = new Operator_Application(array('init' => true)); +$cache = &$GLOBALS['cache']; -// Form libraries. -require_once 'Horde/Form.php'; -require_once 'Horde/Form/Renderer.php'; require_once OPERATOR_BASE . '/lib/Form/SearchCDR.php'; $renderer = new Horde_Form_Renderer(); diff --git a/operator/viewgraph.php b/operator/viewgraph.php index 58dd9a02c..fe36c5d74 100644 --- a/operator/viewgraph.php +++ b/operator/viewgraph.php @@ -10,12 +10,11 @@ * @author Ben Klang */ -@define('OPERATOR_BASE', dirname(__FILE__)); -require_once OPERATOR_BASE . '/lib/base.php'; +require_once dirname(__FILE__) . '/lib/Application.php'; + +$operator = new Operator_Application(array('init' => true)); +$cache = &$GLOBALS['cache']; -// Form libraries. -require_once 'Horde/Form.php'; -require_once 'Horde/Form/Renderer.php'; require_once OPERATOR_BASE . '/lib/Form/SearchCDR.php'; $renderer = new Horde_Form_Renderer();