2015-12-01 05:06:34 +00:00
|
|
|
<?php
|
|
|
|
/*----------------------------------------------------------------------------------| www.giz.de |----/
|
|
|
|
Deutsche Gesellschaft für International Zusammenarbeit (GIZ) Gmb
|
|
|
|
/-------------------------------------------------------------------------------------------------------/
|
|
|
|
|
2018-05-05 13:43:04 +00:00
|
|
|
@version 3.4.3
|
|
|
|
@build 5th May, 2018
|
2015-12-01 05:06:34 +00:00
|
|
|
@created 15th June, 2012
|
|
|
|
@package Cost Benefit Projection
|
|
|
|
@subpackage router.php
|
|
|
|
@author Llewellyn van der Merwe <http://www.vdm.io>
|
|
|
|
@owner Deutsche Gesellschaft für International Zusammenarbeit (GIZ) Gmb
|
|
|
|
@copyright Copyright (C) 2015. All Rights Reserved
|
|
|
|
@license GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html
|
|
|
|
|
|
|
|
/-------------------------------------------------------------------------------------------------------/
|
|
|
|
Cost Benefit Projection Tool.
|
|
|
|
/------------------------------------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
// No direct access to this file
|
|
|
|
defined('_JEXEC') or die('Restricted access');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Routing class from com_costbenefitprojection
|
|
|
|
*
|
|
|
|
* @since 3.3
|
|
|
|
*/
|
|
|
|
class CostbenefitprojectionRouter extends JComponentRouterBase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Build the route for the com_costbenefitprojection component
|
|
|
|
*
|
|
|
|
* @param array &$query An array of URL arguments
|
|
|
|
*
|
|
|
|
* @return array The URL arguments to use to assemble the subsequent URL.
|
|
|
|
*
|
|
|
|
* @since 3.3
|
|
|
|
*/
|
|
|
|
public function build(&$query)
|
|
|
|
{
|
|
|
|
$segments = array();
|
|
|
|
|
|
|
|
// Get a menu item based on Itemid or currently active
|
|
|
|
$params = JComponentHelper::getParams('com_costbenefitprojection');
|
|
|
|
|
|
|
|
if (empty($query['Itemid']))
|
|
|
|
{
|
|
|
|
$menuItem = $this->menu->getActive();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$menuItem = $this->menu->getItem($query['Itemid']);
|
|
|
|
}
|
|
|
|
|
|
|
|
$mView = (empty($menuItem->query['view'])) ? null : $menuItem->query['view'];
|
|
|
|
$mId = (empty($menuItem->query['id'])) ? null : $menuItem->query['id'];
|
|
|
|
|
|
|
|
if (isset($query['view']))
|
|
|
|
{
|
|
|
|
$view = $query['view'];
|
|
|
|
|
|
|
|
if (empty($query['Itemid']))
|
|
|
|
{
|
|
|
|
$segments[] = $query['view'];
|
|
|
|
}
|
|
|
|
|
|
|
|
unset($query['view']);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Are we dealing with a item that is attached to a menu item?
|
|
|
|
if (isset($view) && ($mView == $view) and (isset($query['id'])) and ($mId == (int) $query['id']))
|
|
|
|
{
|
|
|
|
unset($query['view']);
|
|
|
|
unset($query['catid']);
|
|
|
|
unset($query['id']);
|
|
|
|
return $segments;
|
|
|
|
}
|
|
|
|
|
2018-05-05 13:43:04 +00:00
|
|
|
if (isset($view) && isset($query['id']) && ($view === 'company' || $view === 'scaling_factor' || $view === 'intervention' || $view === 'cpanel' || $view === 'publicresults' || $view === 'createaccount' || $view === 'companyresults' || $view === 'combinedresults'))
|
2015-12-01 05:06:34 +00:00
|
|
|
{
|
|
|
|
if ($mId != (int) $query['id'] || $mView != $view)
|
|
|
|
{
|
2018-05-05 13:43:04 +00:00
|
|
|
if (($view === 'company' || $view === 'scaling_factor' || $view === 'intervention' || $view === 'cpanel' || $view === 'publicresults' || $view === 'createaccount' || $view === 'companyresults' || $view === 'combinedresults'))
|
2015-12-01 05:06:34 +00:00
|
|
|
{
|
|
|
|
$segments[] = $view;
|
|
|
|
$id = explode(':', $query['id']);
|
|
|
|
if (count($id) == 2)
|
|
|
|
{
|
|
|
|
$segments[] = $id[1];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$segments[] = $id[0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
unset($query['id']);
|
|
|
|
}
|
|
|
|
|
|
|
|
$total = count($segments);
|
|
|
|
|
|
|
|
for ($i = 0; $i < $total; $i++)
|
|
|
|
{
|
|
|
|
$segments[$i] = str_replace(':', '-', $segments[$i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $segments;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Parse the segments of a URL.
|
|
|
|
*
|
|
|
|
* @param array &$segments The segments of the URL to parse.
|
|
|
|
*
|
|
|
|
* @return array The URL attributes to be used by the application.
|
|
|
|
*
|
|
|
|
* @since 3.3
|
|
|
|
*/
|
|
|
|
public function parse(&$segments)
|
2018-05-05 13:43:04 +00:00
|
|
|
{
|
2015-12-01 05:06:34 +00:00
|
|
|
$count = count($segments);
|
|
|
|
$vars = array();
|
2018-05-05 13:43:04 +00:00
|
|
|
|
2015-12-01 05:06:34 +00:00
|
|
|
//Handle View and Identifier
|
|
|
|
switch($segments[0])
|
|
|
|
{
|
2016-02-14 22:39:12 +00:00
|
|
|
case 'company':
|
|
|
|
$vars['view'] = 'company';
|
|
|
|
if (is_numeric($segments[$count-1]))
|
|
|
|
{
|
|
|
|
$vars['id'] = (int) $segments[$count-1];
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'scaling_factor':
|
|
|
|
$vars['view'] = 'scaling_factor';
|
|
|
|
if (is_numeric($segments[$count-1]))
|
|
|
|
{
|
|
|
|
$vars['id'] = (int) $segments[$count-1];
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'intervention':
|
|
|
|
$vars['view'] = 'intervention';
|
|
|
|
if (is_numeric($segments[$count-1]))
|
|
|
|
{
|
|
|
|
$vars['id'] = (int) $segments[$count-1];
|
|
|
|
}
|
|
|
|
break;
|
2015-12-01 05:06:34 +00:00
|
|
|
case 'cpanel':
|
|
|
|
$vars['view'] = 'cpanel';
|
|
|
|
if (is_numeric($segments[$count-1]))
|
|
|
|
{
|
|
|
|
$vars['id'] = (int) $segments[$count-1];
|
|
|
|
}
|
2018-05-05 13:43:04 +00:00
|
|
|
elseif ($segments[$count-1])
|
2015-12-01 05:06:34 +00:00
|
|
|
{
|
2018-05-05 13:43:04 +00:00
|
|
|
$id = $this->getVar('company', $segments[$count-1], 'alias', 'id');
|
2015-12-01 05:06:34 +00:00
|
|
|
if($id)
|
|
|
|
{
|
|
|
|
$vars['id'] = $id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2015-12-17 14:38:15 +00:00
|
|
|
case 'publicresults':
|
|
|
|
$vars['view'] = 'publicresults';
|
|
|
|
if (is_numeric($segments[$count-1]))
|
|
|
|
{
|
|
|
|
$vars['id'] = (int) $segments[$count-1];
|
|
|
|
}
|
2018-05-05 13:43:04 +00:00
|
|
|
elseif ($segments[$count-1])
|
2015-12-17 14:38:15 +00:00
|
|
|
{
|
2018-05-05 13:43:04 +00:00
|
|
|
$id = $this->getVar('country', $segments[$count-1], 'alias', 'id');
|
2015-12-17 14:38:15 +00:00
|
|
|
if($id)
|
|
|
|
{
|
|
|
|
$vars['id'] = $id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2015-12-01 05:06:34 +00:00
|
|
|
case 'createaccount':
|
|
|
|
$vars['view'] = 'createaccount';
|
|
|
|
if (is_numeric($segments[$count-1]))
|
|
|
|
{
|
|
|
|
$vars['id'] = (int) $segments[$count-1];
|
|
|
|
}
|
2018-05-05 13:43:04 +00:00
|
|
|
elseif ($segments[$count-1])
|
2015-12-01 05:06:34 +00:00
|
|
|
{
|
2018-05-05 13:43:04 +00:00
|
|
|
$id = $this->getVar('country', $segments[$count-1], 'alias', 'id');
|
2015-12-01 05:06:34 +00:00
|
|
|
if($id)
|
|
|
|
{
|
|
|
|
$vars['id'] = $id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'companyresults':
|
|
|
|
$vars['view'] = 'companyresults';
|
|
|
|
if (is_numeric($segments[$count-1]))
|
|
|
|
{
|
|
|
|
$vars['id'] = (int) $segments[$count-1];
|
|
|
|
}
|
2018-05-05 13:43:04 +00:00
|
|
|
elseif ($segments[$count-1])
|
2015-12-01 05:06:34 +00:00
|
|
|
{
|
2018-05-05 13:43:04 +00:00
|
|
|
$id = $this->getVar('company', $segments[$count-1], 'alias', 'id');
|
2015-12-01 05:06:34 +00:00
|
|
|
if($id)
|
|
|
|
{
|
|
|
|
$vars['id'] = $id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'combinedresults':
|
|
|
|
$vars['view'] = 'combinedresults';
|
|
|
|
if (is_numeric($segments[$count-1]))
|
|
|
|
{
|
|
|
|
$vars['id'] = (int) $segments[$count-1];
|
|
|
|
}
|
2018-05-05 13:43:04 +00:00
|
|
|
elseif ($segments[$count-1])
|
2015-12-01 05:06:34 +00:00
|
|
|
{
|
2018-05-05 13:43:04 +00:00
|
|
|
$id = $this->getVar('company', $segments[$count-1], 'alias', 'id');
|
2015-12-01 05:06:34 +00:00
|
|
|
if($id)
|
|
|
|
{
|
|
|
|
$vars['id'] = $id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $vars;
|
|
|
|
}
|
|
|
|
|
2018-05-05 13:43:04 +00:00
|
|
|
protected function getVar($table, $where = null, $whereString = null, $what = null, $category = false, $operator = '=', $main = 'costbenefitprojection')
|
2015-12-01 05:06:34 +00:00
|
|
|
{
|
2018-05-05 13:43:04 +00:00
|
|
|
if(!$where || !$what || !$whereString)
|
2015-12-01 05:06:34 +00:00
|
|
|
{
|
2018-05-05 13:43:04 +00:00
|
|
|
return false;
|
2015-12-01 05:06:34 +00:00
|
|
|
}
|
|
|
|
// Get a db connection.
|
|
|
|
$db = JFactory::getDbo();
|
|
|
|
// Create a new query object.
|
|
|
|
$query = $db->getQuery(true);
|
|
|
|
|
|
|
|
$query->select($db->quoteName(array($what)));
|
2018-05-05 13:43:04 +00:00
|
|
|
if ('categories' == $table || 'category' == $table || $category)
|
2015-12-01 05:06:34 +00:00
|
|
|
{
|
2018-05-05 13:43:04 +00:00
|
|
|
$getTable = '#__categories';
|
|
|
|
$query->from($db->quoteName($getTable));
|
2015-12-01 05:06:34 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-05-05 13:43:04 +00:00
|
|
|
// we must check if the table exist (TODO not ideal)
|
|
|
|
$tables = $db->getTableList();
|
|
|
|
$app = JFactory::getApplication();
|
|
|
|
$prefix = $app->get('dbprefix');
|
|
|
|
$check = $prefix.$main.'_'.$table;
|
|
|
|
if (in_array($check, $tables))
|
|
|
|
{
|
|
|
|
$getTable = '#__'.$main.'_'.$table;
|
|
|
|
$query->from($db->quoteName($getTable));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2015-12-01 05:06:34 +00:00
|
|
|
}
|
|
|
|
if (is_numeric($where))
|
|
|
|
{
|
2018-05-05 13:43:04 +00:00
|
|
|
return false;
|
2015-12-01 05:06:34 +00:00
|
|
|
}
|
2018-05-05 13:43:04 +00:00
|
|
|
elseif ($this->checkString($where))
|
2015-12-01 05:06:34 +00:00
|
|
|
{
|
2018-05-05 13:43:04 +00:00
|
|
|
// we must first check if this table has the column
|
|
|
|
$columns = $db->getTableColumns($getTable);
|
|
|
|
if (isset($columns[$whereString]))
|
|
|
|
{
|
|
|
|
$query->where($db->quoteName($whereString) . ' '.$operator.' '. $db->quote((string)$where));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2015-12-01 05:06:34 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
$db->setQuery($query);
|
|
|
|
$db->execute();
|
|
|
|
if ($db->getNumRows())
|
|
|
|
{
|
|
|
|
return $db->loadResult();
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2018-05-05 13:43:04 +00:00
|
|
|
|
|
|
|
protected function checkString($string)
|
|
|
|
{
|
|
|
|
if (isset($string) && is_string($string) && strlen($string) > 0)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2015-12-01 05:06:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function CostbenefitprojectionBuildRoute(&$query)
|
|
|
|
{
|
|
|
|
$router = new CostbenefitprojectionRouter;
|
|
|
|
|
|
|
|
return $router->build($query);
|
|
|
|
}
|
|
|
|
|
|
|
|
function CostbenefitprojectionParseRoute($segments)
|
|
|
|
{
|
2018-05-05 13:43:04 +00:00
|
|
|
$router = new CostbenefitprojectionRouter;
|
2015-12-01 05:06:34 +00:00
|
|
|
|
|
|
|
return $router->parse($segments);
|
|
|
|
}
|