From 4e6c54eaa645e8c8522141a8e12cc823943434f4 Mon Sep 17 00:00:00 2001 From: Ben Klang Date: Wed, 26 May 2010 14:41:40 -0400 Subject: [PATCH] Hermes: Update script initialization to H4 --- hermes/admin.php | 14 +- hermes/deliverables.php | 16 +- hermes/entry.php | 12 +- hermes/invoicing.php | 8 +- hermes/lib/Api.php | 728 ++++++++++++++++++++++-------------------------- hermes/lib/base.php | 2 - hermes/search.php | 12 +- hermes/start.php | 4 +- hermes/time.php | 14 +- 9 files changed, 377 insertions(+), 433 deletions(-) diff --git a/hermes/admin.php b/hermes/admin.php index 840f93b9a..bf136de87 100644 --- a/hermes/admin.php +++ b/hermes/admin.php @@ -2,7 +2,7 @@ /** * $Horde: hermes/admin.php,v 1.33 2009/07/14 18:43:47 selsky Exp $ * - * Copyright 2002-2009 The Horde Project (http://www.horde.org/) + * Copyright 2002-2010 The Horde Project (http://www.horde.org/) * * See the enclosed file LICENSE for license information (BSD). If you * did not receive this file, see http://www.horde.org/licenses/bsdl.php. @@ -10,8 +10,8 @@ * @author Chuck Hagenbuch */ -@define('HERMES_BASE', dirname(__FILE__)); -require_once HERMES_BASE . '/lib/base.php'; +require_once dirname(__FILE__) . '/lib/Application.php'; +$hermes = Horde_Registry::appInit('hermes'); require_once HERMES_BASE . '/lib/Admin.php'; if (!Horde_Auth::isAdmin()) { @@ -45,7 +45,7 @@ if ($vars->exists('formname')) { if ($form->isValid()) { $form->getInfo($vars, $info); - $result = $hermes->updateJobType($info); + $result = $hermes->driver->updateJobType($info); if (!is_a($result, 'PEAR_Error')) { $notification->push(sprintf(_("The job type \"%s\" has been added."), $vars->get('name')), 'horde.success'); } else { @@ -142,7 +142,7 @@ if ($vars->exists('formname')) { // update everything. $form1->getInfo($vars, $info); $info['id'] = $info['jobtype']; - $result = $hermes->updateJobType($info); + $result = $hermes->driver->updateJobType($info); if (!PEAR::isError($result)) { $notification->push(_("The job type has been modified."), 'horde.success'); } else { @@ -165,7 +165,7 @@ if ($vars->exists('formname')) { $form->validate($vars); if ($form->isValid()) { - $result = $hermes->updateClientSettings($vars->get('client'), + $result = $hermes->driver->updateClientSettings($vars->get('client'), $vars->get('enterdescription') ? 1 : 0, $vars->get('exportid')); if (PEAR::isError($result)) { @@ -191,7 +191,7 @@ if ($vars->exists('formname')) { if ($form->isValid()) { if ($vars->get('yesno') == 1) { - $result = $hermes->deleteJobType($vars->get('jobtype')); + $result = $hermes->driver->deleteJobType($vars->get('jobtype')); if (!PEAR::isError($result)) { $notification->push(_("The job type has been deleted."), 'horde.success'); } else { diff --git a/hermes/deliverables.php b/hermes/deliverables.php index 11cd6f064..2d32f0db2 100644 --- a/hermes/deliverables.php +++ b/hermes/deliverables.php @@ -2,7 +2,7 @@ /** * $Horde: hermes/deliverables.php,v 1.14 2009/07/14 18:43:47 selsky Exp $ * - * Copyright 2005-2009 The Horde Project (http://www.horde.org/) + * Copyright 2005-2010 The Horde Project (http://www.horde.org/) * * See the enclosed file LICENSE for license information (BSD). If you * did not receive this file, see http://www.horde.org/licenses/bsdl.php. @@ -10,8 +10,8 @@ * @author Jason M. Felice */ -@define('HERMES_BASE', dirname(__FILE__)); -require_once HERMES_BASE . '/lib/base.php'; +require_once dirname(__FILE__) . '/lib/Application.php'; +$hermes = Horde_Registry::appInit('hermes'); require_once HERMES_BASE . '/lib/Forms/Deliverable.php'; $vars = Horde_Variables::getDefaultVariables(); @@ -25,13 +25,13 @@ case 'deliverableform': if (!empty($info['deliverable_id'])) { $info['id'] = $info['deliverable_id']; if (empty($info['parent'])) { - $origdeliv = $hermes->getDeliverableByID($info['id']); + $origdeliv = $hermes->driver->getDeliverableByID($info['id']); if (!is_a($origdeliv, 'PEAR_Error')) { $info['parent'] = $origdeliv['parent']; } } } - $res = $hermes->updateDeliverable($info); + $res = $hermes->driver->updateDeliverable($info); if (is_a($res, 'PEAR_Error')) { $notification->push(sprintf(_("Error saving deliverable: %s"), $res->getMessage()), @@ -45,7 +45,7 @@ case 'deliverableform': break; case 'deletedeliverable': - $res = $hermes->deleteDeliverable($vars->get('delete')); + $res = $hermes->driver->deleteDeliverable($vars->get('delete')); if (is_a($res, 'PEAR_Error')) { $notification->push(sprintf(_("Error deleting deliverable: %s"), $res->getMessage()), 'horde.error'); @@ -69,7 +69,7 @@ if (!$vars->exists('deliverable_id') && !$vars->exists('new')) { if ($vars->exists('deliverable_id') || $vars->exists('new')) { if ($vars->exists('deliverable_id')) { - $deliverable = $hermes->getDeliverableByID($vars->get('deliverable_id')); + $deliverable = $hermes->driver->getDeliverableByID($vars->get('deliverable_id')); if (is_a($deliverable, 'PEAR_Error')) { Horde::fatal($deliverable, __FILE__, __LINE__); } @@ -85,7 +85,7 @@ if ($vars->exists('deliverable_id') || $vars->exists('new')) { $clients = Hermes::listClients(); $clientname = $clients[$vars->get('client_id')]; - $deliverables = $hermes->listDeliverables(array('client_id' => $vars->get('client_id'))); + $deliverables = $hermes->driver->listDeliverables(array('client_id' => $vars->get('client_id'))); if (is_a($deliverables, 'PEAR_Error')) { Horde::fatal($deliverables, __FILE__, __LINE__); } diff --git a/hermes/entry.php b/hermes/entry.php index d07eb1ed6..5877fd6e4 100644 --- a/hermes/entry.php +++ b/hermes/entry.php @@ -2,7 +2,7 @@ /** * $Horde: hermes/entry.php,v 1.27 2009/07/08 18:29:07 slusarz Exp $ * - * Copyright 2002-2009 The Horde Project (http://www.horde.org/) + * Copyright 2002-2010 The Horde Project (http://www.horde.org/) * * See the enclosed file LICENSE for license information (BSD). If you * did not receive this file, see http://www.horde.org/licenses/bsdl.php. @@ -11,8 +11,8 @@ * @author Jan Schneider */ -@define('HERMES_BASE', dirname(__FILE__)); -require_once HERMES_BASE . '/lib/base.php'; +require_once dirname(__FILE__) . '/lib/Application.php'; +$hermes = Horde_Registry::appInit('hermes'); require_once HERMES_BASE . '/lib/Forms/Time.php'; $vars = Horde_Variables::getDefaultVariables(); @@ -40,11 +40,11 @@ case 'timeentryform': $form->getInfo($vars, $info); if ($vars->exists('id')) { $msg = _("Your time was successfully updated."); - $result = $hermes->updateTime(array($info)); + $result = $hermes->driver->updateTime(array($info)); $do_redirect = true; } else { $msg = _("Your time was successfully entered."); - $result = $hermes->enterTime(Horde_Auth::getAuth(), $info); + $result = $hermes->driver->enterTime(Horde_Auth::getAuth(), $info); $do_redirect = false; } if (is_a($result, 'PEAR_Error')) { @@ -74,7 +74,7 @@ default: header('Location: ' . Horde::applicationUrl('time.php')); exit; } - $myhours = $hermes->getHours(array('id' => $id)); + $myhours = $hermes->driver->getHours(array('id' => $id)); if (is_array($myhours)) { foreach ($myhours as $item) { if (isset($item['id']) && $item['id'] == $id) { diff --git a/hermes/invoicing.php b/hermes/invoicing.php index 2aab4ce63..3fd517232 100644 --- a/hermes/invoicing.php +++ b/hermes/invoicing.php @@ -2,7 +2,7 @@ /** * $Horde: hermes/invoicing.php,v 1.12 2009/06/10 17:33:20 slusarz Exp $ * - * Copyright 2002-2009 The Horde Project (http://www.horde.org/) + * Copyright 2002-2010 The Horde Project (http://www.horde.org/) * * See the enclosed file LICENSE for license information (BSD). If you * did not receive this file, see http://www.horde.org/licenses/bsdl.php. @@ -10,14 +10,14 @@ * @author Duck */ -@define('HERMES_BASE', dirname(__FILE__)); -require_once HERMES_BASE . '/lib/base.php'; +require_once dirname(__FILE__) . '/lib/Application.php'; +$hermes = Horde_Registry::appInit('hermes'); require_once 'Horde/Form.php'; require_once 'Horde/Form/Renderer.php'; require_once 'Horde/Form/Type/tableset.php'; -$hours = $hermes->getHours(array('billable' => true, +$hours = $hermes->driver->getHours(array('billable' => true, 'submitted' => true)); if (is_a($hours, 'PEAR_Error')) { $notification->push($hours->getMessage(), 'horde.error'); diff --git a/hermes/lib/Api.php b/hermes/lib/Api.php index 7cd8ca54b..fe53f9c99 100644 --- a/hermes/lib/Api.php +++ b/hermes/lib/Api.php @@ -2,452 +2,398 @@ /** * Hermes external API interface. * - * $Horde: hermes/lib/api.php,v 1.45 2009/07/08 18:29:07 slusarz Exp $ - * * This file defines Hermes's external API interface. Other applications * can interact with Hermes through this API. * * @package Hermes */ -$_services['perms'] = array( - 'args' => array(), - 'type' => '{urn:horde}stringArray'); - -$_services['getTableMetaData'] = array( - 'args' => array('name' => 'string', 'params' => '{urn:horde}stringArray'), - 'type' => '{urn:horde}stringArray'); - -$_services['getTableData'] = array( - 'args' => array('name' => 'string', 'params' => '{urn:horde}stringArray'), - 'type' => '{urn:horde}stringArray'); - -$_services['listCostObjects'] = array( - 'args' => array('criteria' => '{urn:horde}hash'), - 'type' => '{urn:horde}array'); - -$_services['listJobTypes'] = array( - 'arga' => array('criteria' => '{urn:horde}hash'), - 'type' => '{urn:horde}array'); - -$_services['listClients'] = array( - 'arga' => array(), - 'type' => '{urn:horde}array'); - -$_services['recordTime'] = array( - 'arga' => array('date' => 'int', - 'client' => 'string', - 'jobType' => 'int', - 'costObject' => 'int', - 'hours' => 'string', // Can not use 'float' - 'billable' => 'boolean', - 'description' => 'string', - 'notes' => 'string'), - 'type' => 'boolean'); // FIXME: Is there something more useful to return? - -function _hermes_perms() -{ - $perms = array(); - $perms['tree']['hermes']['review'] = array(); - $perms['title']['hermes:review'] = _("Time Review Screen"); - $perms['tree']['hermes']['deliverables'] = array(); - $perms['title']['hermes:deliverables'] = _("Deliverables"); - $perms['tree']['hermes']['invoicing'] = array(); - $perms['title']['hermes:invoicing'] = _("Invoicing"); - - return $perms; -} - -function _hermes_getTableMetaData($name, $params) +class Hermes_Api extends Horde_Registry_Api { - require_once dirname(__FILE__) . '/base.php'; - - switch ($name) { - case 'hours': - $emptype = Hermes::getEmployeesType('enum'); - $clients = Hermes::listClients(); - $hours = $GLOBALS['hermes']->getHours($params); - $yesno = array(1 => _("Yes"), - 0 => _("No")); - - $columns = array( - array('name' => 'icons', - 'title' => '', - 'type' => '%html', - 'nobr' => true), - array('name' => 'checkbox', - 'title' => '', - 'type' => '%html', - 'nobr' => true), - array('name' => 'date', - 'title' => _("Date"), - 'type' => 'date', - 'params' => array($GLOBALS['prefs']->getValue('date_format')), - 'nobr' => true), - array('name' => 'employee', - 'title' => _("Employee"), - 'type' => $emptype[0], - 'params' => $emptype[1]), - array('name' => 'client', - 'title' => _("Client"), - 'type' => 'enum', - 'params' => array($clients)), - array('name' => '_type_name', - 'title' => _("Job Type")), - array('name' => '_costobject_name', - 'title' => _("Cost Object")), - array('name' => 'hours', - 'title' => _("Hours"), - 'type' => 'number', - 'align' => 'right')); - if ($GLOBALS['conf']['time']['choose_ifbillable']) { - $columns[] = - array('name' => 'billable', - 'title' => _("Bill?"), - 'type' => 'enum', - 'params' => array($yesno)); - } - $columns = array_merge($columns, array( - array('name' => 'description', - 'title' => _("Description")), - array('name' => 'note', - 'title' => _("Notes")))); - - $colspan = 6; - if ($GLOBALS['conf']['time']['choose_ifbillable']) { - $colspan++; - } - $fColumns = array( - array('name' => 'approval', - 'colspan' => $colspan, - 'type' => '%html', - 'align' => 'right'), - array('name' => 'hours', - 'type' => 'number', - 'align' => 'right')); - if ($GLOBALS['conf']['time']['choose_ifbillable']) { - $fColumns[] = - array('name' => 'billable', + + function getTableMetaData($name, $params) + { + switch ($name) { + case 'hours': + $emptype = Hermes::getEmployeesType('enum'); + $clients = Hermes::listClients(); + $hours = $GLOBALS['hermes']->getHours($params); + $yesno = array(1 => _("Yes"), + 0 => _("No")); + + $columns = array( + array('name' => 'icons', + 'title' => '', + 'type' => '%html', + 'nobr' => true), + array('name' => 'checkbox', + 'title' => '', + 'type' => '%html', + 'nobr' => true), + array('name' => 'date', + 'title' => _("Date"), + 'type' => 'date', + 'params' => array($GLOBALS['prefs']->getValue('date_format')), + 'nobr' => true), + array('name' => 'employee', + 'title' => _("Employee"), + 'type' => $emptype[0], + 'params' => $emptype[1]), + array('name' => 'client', + 'title' => _("Client"), 'type' => 'enum', - 'params' => array($yesno)); + 'params' => array($clients)), + array('name' => '_type_name', + 'title' => _("Job Type")), + array('name' => '_costobject_name', + 'title' => _("Cost Object")), + array('name' => 'hours', + 'title' => _("Hours"), + 'type' => 'number', + 'align' => 'right')); + if ($GLOBALS['conf']['time']['choose_ifbillable']) { + $columns[] = + array('name' => 'billable', + 'title' => _("Bill?"), + 'type' => 'enum', + 'params' => array($yesno)); + } + $columns = array_merge($columns, array( + array('name' => 'description', + 'title' => _("Description")), + array('name' => 'note', + 'title' => _("Notes")))); + + $colspan = 6; + if ($GLOBALS['conf']['time']['choose_ifbillable']) { + $colspan++; + } + $fColumns = array( + array('name' => 'approval', + 'colspan' => $colspan, + 'type' => '%html', + 'align' => 'right'), + array('name' => 'hours', + 'type' => 'number', + 'align' => 'right')); + if ($GLOBALS['conf']['time']['choose_ifbillable']) { + $fColumns[] = + array('name' => 'billable', + 'type' => 'enum', + 'params' => array($yesno)); + } + $fColumns = array_merge($fColumns, array( + array('name' => 'description'), + array('name' => 'blank2'))); + + return array('title' => _("Search Results"), + 'sections' => array( + 'data' => array( + 'rows' => count($hours), + 'columns' => $columns), + 'footer' => array( + 'rows' => 3, + 'strong' => true, + 'columns' => $fColumns))); + + default: + return PEAR::raiseError(sprintf(_("\"%s\" is not a defined table."), + $name)); } - $fColumns = array_merge($fColumns, array( - array('name' => 'description'), - array('name' => 'blank2'))); - - return array('title' => _("Search Results"), - 'sections' => array( - 'data' => array( - 'rows' => count($hours), - 'columns' => $columns), - 'footer' => array( - 'rows' => 3, - 'strong' => true, - 'columns' => $fColumns))); - - default: - return PEAR::raiseError(sprintf(_("\"%s\" is not a defined table."), - $name)); } -} -function _hermes_getTableData($name, $params) -{ - require_once dirname(__FILE__) . '/base.php'; + function getTableData($name, $params) + { + switch ($name) { + case 'hours': + $time_data = $GLOBALS['hermes']->getHours($params); + if (is_a($time_data, 'PEAR_Error')) { + return $time_data; + } - switch ($name) { - case 'hours': - $time_data = $GLOBALS['hermes']->getHours($params); - if (is_a($time_data, 'PEAR_Error')) { - return $time_data; - } + $subtotal_column = null; + if (isset($_SESSION['hermes_search_mode'])) { + switch ($_SESSION['hermes_search_mode']) { + case 'date': + $subtotal_column = 'date'; + break; - $subtotal_column = null; - if (isset($_SESSION['hermes_search_mode'])) { - switch ($_SESSION['hermes_search_mode']) { - case 'date': - $subtotal_column = 'date'; - break; + case 'employee': + $subtotal_column = 'employee'; + break; - case 'employee': - $subtotal_column = 'employee'; - break; + case 'client': + $subtotal_column = '_client_name'; + break; - case 'client': - $subtotal_column = '_client_name'; - break; + case 'jobtype': + $subtotal_column = '_type_name'; + break; - case 'jobtype': - $subtotal_column = '_type_name'; - break; + case 'costobject': + $subtotal_column = '_costobject_name'; + break; + } - case 'costobject': - $subtotal_column = '_costobject_name'; - break; + if (!empty($subtotal_column)) { + $clients = Hermes::listClients(); + $column = array(); + foreach ($time_data as $key => $row) { + if (empty($row['client'])) { + $time_data[$key]['_client_name'] = _("no client"); + } elseif (isset($clients[$row['client']])) { + $time_data[$key]['_client_name'] = $clients[$row['client']]; + } else { + $time_data[$key]['_client_name'] = $row['client']; + } + $column[$key] = $time_data[$key][$subtotal_column]; + } + array_multisort($column, SORT_ASC, $time_data); + } } - if (!empty($subtotal_column)) { - $clients = Hermes::listClients(); - $column = array(); - foreach ($time_data as $key => $row) { - if (empty($row['client'])) { - $time_data[$key]['_client_name'] = _("no client"); - } elseif (isset($clients[$row['client']])) { - $time_data[$key]['_client_name'] = $clients[$row['client']]; + $total_hours = 0.0; + $total_billable_hours = 0.0; + $subtotal_hours = 0.0; + $subtotal_billable_hours = 0.0; + $subtotal_control = null; + + $result['data'] = array(); + foreach ($time_data as $k => $vals) { + // Initialize subtotal break value. + if (is_null($subtotal_control) && isset($vals[$subtotal_column])) { + $subtotal_control = $vals[$subtotal_column]; + } + + if (!empty($subtotal_column) && + $vals[$subtotal_column] != $subtotal_control) { + renderSubtotals($result['data'], $subtotal_hours, $subtotal_billable_hours, + $subtotal_column == 'date' ? strftime("%m/%d/%Y", $subtotal_control) : + $subtotal_control); + $subtotal_hours = 0.0; + $subtotal_billable_hours = 0.0; + $subtotal_control = $vals[$subtotal_column]; + } + + // Set up edit/delete icons. + if (Hermes::canEditTimeslice($vals['id'])) { + $edit_link = Horde::applicationUrl('entry.php', true); + $edit_link = Horde_Util::addParameter($edit_link, 'id', $vals['id']); + $edit_link = Horde_Util::addParameter($edit_link, 'url', Horde::selfUrl(true, true, true)); + + $vals['icons'] = + Horde::link($edit_link, _("Edit Entry")) . + Horde::img('edit.png', _("Edit Entry"), '', $GLOBALS['registry']->getImageDir('horde')) . ''; + + if (empty($vals['submitted'])) { + $vals['checkbox'] = + ''; } else { - $time_data[$key]['_client_name'] = $row['client']; + $vals['checkbox'] = ''; } - $column[$key] = $time_data[$key][$subtotal_column]; } - array_multisort($column, SORT_ASC, $time_data); - } - } - $total_hours = 0.0; - $total_billable_hours = 0.0; - $subtotal_hours = 0.0; - $subtotal_billable_hours = 0.0; - $subtotal_control = null; - - $result['data'] = array(); - foreach ($time_data as $k => $vals) { - // Initialize subtotal break value. - if (is_null($subtotal_control) && isset($vals[$subtotal_column])) { - $subtotal_control = $vals[$subtotal_column]; + // Add to totals. + $subtotal_hours += (double)$vals['hours']; + $total_hours += (double)$vals['hours']; + if ($vals['billable']) { + $subtotal_billable_hours += (double)$vals['hours']; + $total_billable_hours += (double)$vals['hours']; + } + + // Localize hours. + $vals['hours'] = sprintf('%.02f', $vals['hours']); + + $result['data'][] = $vals; } - if (!empty($subtotal_column) && - $vals[$subtotal_column] != $subtotal_control) { + if (!empty($subtotal_column)) { renderSubtotals($result['data'], $subtotal_hours, $subtotal_billable_hours, $subtotal_column == 'date' ? strftime("%m/%d/%Y", $subtotal_control) : $subtotal_control); - $subtotal_hours = 0.0; - $subtotal_billable_hours = 0.0; - $subtotal_control = $vals[$subtotal_column]; - } - - // Set up edit/delete icons. - if (Hermes::canEditTimeslice($vals['id'])) { - $edit_link = Horde::applicationUrl('entry.php', true); - $edit_link = Horde_Util::addParameter($edit_link, 'id', $vals['id']); - $edit_link = Horde_Util::addParameter($edit_link, 'url', Horde::selfUrl(true, true, true)); - - $vals['icons'] = - Horde::link($edit_link, _("Edit Entry")) . - Horde::img('edit.png', _("Edit Entry"), '', $GLOBALS['registry']->getImageDir('horde')) . ''; - - if (empty($vals['submitted'])) { - $vals['checkbox'] = - ''; - } else { - $vals['checkbox'] = ''; - } } - // Add to totals. - $subtotal_hours += (double)$vals['hours']; - $total_hours += (double)$vals['hours']; - if ($vals['billable']) { - $subtotal_billable_hours += (double)$vals['hours']; - $total_billable_hours += (double)$vals['hours']; + // Avoid a divide by zero. + if ($total_hours == 0.0) { + $billable_pct = 0.0; + } else { + $billable_pct = round($total_billable_hours / $total_hours * 100.0); } - // Localize hours. - $vals['hours'] = sprintf('%.02f', $vals['hours']); - - $result['data'][] = $vals; + $descr = _("Billable Hours") . ' (' . $billable_pct . '%)'; + $result['footer'] = array(); + $result['footer'][] = array( + 'hours' => sprintf('%.02f', $total_billable_hours), + 'description' => $descr); + + $descr = _("Non-billable Hours") . ' (' . (100.0 - $billable_pct) . '%)'; + $result['footer'][] = array( + 'hours' => sprintf('%.02f', $total_hours - $total_billable_hours), + 'description' => $descr); + $result['footer'][] = array( + 'hours' => sprintf('%.02f', $total_hours), + 'description' => _("Total Hours"), + 'approval' => '
' . _("Approved By:") . + ' ________________________________________ ' . + ' 
'); + break; } - if (!empty($subtotal_column)) { - renderSubtotals($result['data'], $subtotal_hours, $subtotal_billable_hours, - $subtotal_column == 'date' ? strftime("%m/%d/%Y", $subtotal_control) : - $subtotal_control); - } - - // Avoid a divide by zero. - if ($total_hours == 0.0) { - $billable_pct = 0.0; - } else { - $billable_pct = round($total_billable_hours / $total_hours * 100.0); - } + return $result; + } + function renderSubtotals(&$table_data, $hours, $billable_hours, $value) + { + $billable_pct = ($hours == 0.0) ? 0.0 : + round($billable_hours / $hours * 100.0); $descr = _("Billable Hours") . ' (' . $billable_pct . '%)'; - $result['footer'] = array(); - $result['footer'][] = array( - 'hours' => sprintf('%.02f', $total_billable_hours), + $table_data[] = array( + 'date' => '', + 'employee' => '', + 'client' => '', + 'billable' => '', + 'note' => '', + '_type_name' => '', + '_costobject_name' => '', + 'hours' => sprintf('%.02f', $billable_hours), + 'description' => $descr); + $descr = _("Non-billable Hours") . ' (' . (100.0 - $billable_pct) . '%)'; + $table_data[] = array( + 'hours' => sprintf('%.02f', $hours - $billable_hours), 'description' => $descr); + $table_data[] = array( + 'hours' => sprintf('%.02f', $hours), + 'description' => sprintf(_("Total Hours for %s"), $value), + ); - $descr = _("Non-billable Hours") . ' (' . (100.0 - $billable_pct) . '%)'; - $result['footer'][] = array( - 'hours' => sprintf('%.02f', $total_hours - $total_billable_hours), - 'description' => $descr); - $result['footer'][] = array( - 'hours' => sprintf('%.02f', $total_hours), - 'description' => _("Total Hours"), - 'approval' => '
' . _("Approved By:") . - ' ________________________________________ ' . - ' 
'); - break; + return; } - return $result; -} - -function renderSubtotals(&$table_data, $hours, $billable_hours, $value) -{ - $billable_pct = ($hours == 0.0) ? 0.0 : - round($billable_hours / $hours * 100.0); - $descr = _("Billable Hours") . ' (' . $billable_pct . '%)'; - $table_data[] = array( - 'date' => '', - 'employee' => '', - 'client' => '', - 'billable' => '', - 'note' => '', - '_type_name' => '', - '_costobject_name' => '', - 'hours' => sprintf('%.02f', $billable_hours), - 'description' => $descr); - $descr = _("Non-billable Hours") . ' (' . (100.0 - $billable_pct) . '%)'; - $table_data[] = array( - 'hours' => sprintf('%.02f', $hours - $billable_hours), - 'description' => $descr); - $table_data[] = array( - 'hours' => sprintf('%.02f', $hours), - 'description' => sprintf(_("Total Hours for %s"), $value), - ); - - return; -} - -function _hermes_listCostObjects($criteria) -{ - require_once dirname(__FILE__) . '/base.php'; - - if (!$GLOBALS['conf']['time']['deliverables']) { - return array(); - } + function listCostObjects($criteria) + { + if (!$GLOBALS['conf']['time']['deliverables']) { + return array(); + } - $deliverables = $GLOBALS['hermes']->listDeliverables($criteria); - if (is_a($deliverables, 'PEAR_Error')) { - return PEAR::raiseError(sprintf(_("An error occurred retrieving deliverables: %s"), $deliverables->getMessage())); - } + $deliverables = $GLOBALS['hermes']->listDeliverables($criteria); + if (is_a($deliverables, 'PEAR_Error')) { + return PEAR::raiseError(sprintf(_("An error occurred retrieving deliverables: %s"), $deliverables->getMessage())); + } - if (empty($criteria['id'])) { - /* Build heirarchical tree. */ - $levels = array(); - $hash = array(); - foreach ($deliverables as $deliverable) { - if (empty($deliverable['parent'])) { - $parent = -1; - } else { - $parent = $deliverable['parent']; + if (empty($criteria['id'])) { + /* Build heirarchical tree. */ + $levels = array(); + $hash = array(); + foreach ($deliverables as $deliverable) { + if (empty($deliverable['parent'])) { + $parent = -1; + } else { + $parent = $deliverable['parent']; + } + $levels[$parent][$deliverable['id']] = $deliverable['name']; + $hash[$deliverable['id']] = $deliverable; } - $levels[$parent][$deliverable['id']] = $deliverable['name']; - $hash[$deliverable['id']] = $deliverable; - } - /* Sort levels alphabetically, keeping keys intact. */ - foreach ($levels as $key => $level) { - asort($levels[$key]); - } + /* Sort levels alphabetically, keeping keys intact. */ + foreach ($levels as $key => $level) { + asort($levels[$key]); + } - /* Traverse the tree and glue them back together. Lots of magic - * involved, so don't try to understand. */ - $elts = array(); - $stack = empty($levels[-1]) ? array() : array(-1); - while (count($stack)) { - if (!(list($key, $val) = each($levels[$stack[count($stack) - 1]]))) { - array_pop($stack); - continue; + /* Traverse the tree and glue them back together. Lots of magic + * involved, so don't try to understand. */ + $elts = array(); + $stack = empty($levels[-1]) ? array() : array(-1); + while (count($stack)) { + if (!(list($key, $val) = each($levels[$stack[count($stack) - 1]]))) { + array_pop($stack); + continue; + } + $elts[$key] = str_repeat(' + ', count($stack)-1) . $val; + if (!empty($levels[$key])) { + $stack[] = $key; + } } - $elts[$key] = str_repeat(' + ', count($stack)-1) . $val; - if (!empty($levels[$key])) { - $stack[] = $key; + + $results = array(); + foreach ($elts as $key => $value) { + $results[] = array('id' => $key, + 'active' => $hash[$key]['active'], + 'estimate' => $hash[$key]['estimate'], + 'name' => $value); } + } else { + $results = $deliverables; } - $results = array(); - foreach ($elts as $key => $value) { - $results[] = array('id' => $key, - 'active' => $hash[$key]['active'], - 'estimate' => $hash[$key]['estimate'], - 'name' => $value); + if (!$results) { + return array(); } - } else { - $results = $deliverables; - } - if (!$results) { - return array(); + return array(array('category' => _("Deliverables"), + 'objects' => $results)); } - return array(array('category' => _("Deliverables"), - 'objects' => $results)); -} - -/** - * Retrieve list of job types. - * - * @abstract - * - * @param array $criteria Hash of filter criteria: - * - * 'enabled' => If present, only retrieve enabled - * or disabled job types. - * - * @return mixed Associative array of job types, or PEAR_Error on failure. - */ -function _hermes_listJobTypes($criteria = array()) -{ - require_once dirname(__FILE__) . '/base.php'; - return $GLOBALS['hermes']->listJobTypes($criteria); -} + /** + * Retrieve list of job types. + * + * @abstract + * + * @param array $criteria Hash of filter criteria: + * + * 'enabled' => If present, only retrieve enabled + * or disabled job types. + * + * @return mixed Associative array of job types, or PEAR_Error on failure. + */ + function listJobTypes($criteria = array()) + { + return $GLOBALS['hermes']->listJobTypes($criteria); + } -function _hermes_listClients() -{ - require_once dirname(__FILE__) . '/base.php'; - return Hermes::listClients(); -} + function listClients() + { + return Hermes::listClients(); + } -function _hermes_recordTime($date, $client, $jobType, - $costObject, $hours, $billable = true, - $description = '', $notes = '') -{ - require_once dirname(__FILE__) . '/base.php'; - require_once 'Date.php'; - require_once HERMES_BASE . '/lib/Forms/Time.php'; - - $dateobj = new Horde_Date($date); - $date['year'] = $dateobj->year; - $date['month'] = $dateobj->month; - $date['day'] = $dateobj->mday; - - $vars = Horde_Variables::getDefaultVariables(); - $vars->set('date', $date); - $vars->set('client', $client); - $vars->set('jobType', $jobType); - $vars->set('costObject', $costObject); - $vars->set('hours', $hours); - $vars->set('billable', $billable); - $vars->set('description', $description); - $vars->set('notes', $notes); - - // Validate and submit the data - $form = new TimeEntryForm($vars); - $form->setSubmitted(); - $form->useToken(false); - if ($form->validate($vars)) { - $form->getInfo($vars, $info); - $result = $GLOBALS['hermes']->enterTime(Horde_Auth::getAuth(), $info); - if (is_a($result, 'PEAR_Error')) { - return $result; + function recordTime($date, $client, $jobType, + $costObject, $hours, $billable = true, + $description = '', $notes = '') + { + require_once dirname(__FILE__) . '/base.php'; + require_once 'Date.php'; + require_once HERMES_BASE . '/lib/Forms/Time.php'; + + $dateobj = new Horde_Date($date); + $date['year'] = $dateobj->year; + $date['month'] = $dateobj->month; + $date['day'] = $dateobj->mday; + + $vars = Horde_Variables::getDefaultVariables(); + $vars->set('date', $date); + $vars->set('client', $client); + $vars->set('jobType', $jobType); + $vars->set('costObject', $costObject); + $vars->set('hours', $hours); + $vars->set('billable', $billable); + $vars->set('description', $description); + $vars->set('notes', $notes); + + // Validate and submit the data + $form = new TimeEntryForm($vars); + $form->setSubmitted(); + $form->useToken(false); + if ($form->validate($vars)) { + $form->getInfo($vars, $info); + $result = $GLOBALS['hermes']->enterTime(Horde_Auth::getAuth(), $info); + if (is_a($result, 'PEAR_Error')) { + return $result; + } else { + return true; + } } else { - return true; + return PEAR::raiseError(_("Invalid entry: check data and retry.")); } - } else { - return PEAR::raiseError(_("Invalid entry: check data and retry.")); } -} +} \ No newline at end of file diff --git a/hermes/lib/base.php b/hermes/lib/base.php index 013a4585b..c0f70a1d7 100644 --- a/hermes/lib/base.php +++ b/hermes/lib/base.php @@ -1,7 +1,5 @@ * * See the enclosed file LICENSE for license information (BSD). If you diff --git a/hermes/search.php b/hermes/search.php index 2e4643c87..7937ee7ea 100644 --- a/hermes/search.php +++ b/hermes/search.php @@ -2,7 +2,7 @@ /** * $Horde: hermes/search.php,v 1.47 2009/12/10 17:42:31 jan Exp $ * - * Copyright 2004-2009 The Horde Project (http://www.horde.org/) + * Copyright 2004-2010 The Horde Project (http://www.horde.org/) * * See the enclosed file LICENSE for license information (BSD). If you * did not receive this file, see http://www.horde.org/licenses/bsdl.php. @@ -10,8 +10,8 @@ * @author Jason M. Felice */ -@define('HERMES_BASE', dirname(__FILE__)); -require_once HERMES_BASE . '/lib/base.php'; +require_once dirname(__FILE__) . '/lib/Application.php'; +$hermes = Horde_Registry::appInit('hermes'); require_once HERMES_BASE . '/lib/Forms/Export.php'; require_once HERMES_BASE . '/lib/Forms/Search.php'; require_once HERMES_BASE . '/lib/Forms/Time.php'; @@ -23,7 +23,7 @@ $vars = Horde_Variables::getDefaultVariables(); $delete = $vars->get('delete'); if (!empty($delete)) { - $result = $hermes->updateTime(array(array('id' => $delete, 'delete' => true))); + $result = $hermes->driver->updateTime(array(array('id' => $delete, 'delete' => true))); if (is_a($result, 'PEAR_Error')) { Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR); $notification->push(sprintf(_("There was an error deleting the time: %s"), $result->getMessage()), 'horde.error'); @@ -62,7 +62,7 @@ case 'exportform': $form->validate($vars); if ($form->isValid()) { $form->getInfo($vars, $info); - $hours = $hermes->getHours($criteria); + $hours = $hermes->driver->getHours($criteria); if (is_a($hours, 'PEAR_Error')) { $notification->push($hours, 'horde.error'); } elseif (is_null($hours) || count($hours) == 0) { @@ -78,7 +78,7 @@ case 'exportform': $info['mark_exported'] == 'yes' && $perms->hasPermission('hermes:review', Horde_Auth::getAuth(), Horde_Perms::EDIT)) { - $hermes->markAs('exported', $hours); + $hermes->driver->markAs('exported', $hours); } exit; } diff --git a/hermes/start.php b/hermes/start.php index 07b7509c1..d7695e558 100644 --- a/hermes/start.php +++ b/hermes/start.php @@ -11,8 +11,8 @@ * @author Jan Schneider */ -@define('HERMES_BASE', dirname(__FILE__)); -require_once HERMES_BASE . '/lib/base.php'; +require_once dirname(__FILE__) . '/lib/Application.php'; +$hermes = Horde_Registry::appInit('hermes'); $vars = Horde_Variables::getDefaultVariables(); diff --git a/hermes/time.php b/hermes/time.php index 01f0e93ad..7e5390494 100644 --- a/hermes/time.php +++ b/hermes/time.php @@ -1,17 +1,17 @@ + * @author Ben Klang */ -@define('HERMES_BASE', dirname(__FILE__)); -require_once HERMES_BASE . '/lib/base.php'; +require_once dirname(__FILE__) . '/lib/Application.php'; +$hermes = Horde_Registry::appInit('hermes'); + require_once HERMES_BASE . '/lib/Forms/Time.php'; require_once HERMES_BASE . '/lib/Table.php'; @@ -19,7 +19,7 @@ $vars = Horde_Variables::getDefaultVariables(); $delete = $vars->get('delete'); if (!empty($delete)) { - $result = $hermes->updateTime(array(array('id' => $delete, 'delete' => true))); + $result = $hermes->driver->updateTime(array(array('id' => $delete, 'delete' => true))); if (is_a($result, 'PEAR_Error')) { Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR); $notification->push(sprintf(_("There was an error deleting the time: %s"), $result->getMessage()), 'horde.error'); @@ -40,7 +40,7 @@ case 'submittimeform': foreach ($item as $id => $val) { $time[] = array('id' => $id); } - $result = $hermes->markAs('submitted', $time); + $result = $hermes->driver->markAs('submitted', $time); if (is_a($result, 'PEAR_Error')) { $notification->push(sprintf(_("There was an error submitting your time: %s"), $result->getMessage()), 'horde.error'); } else { -- 2.11.0