From: Michael J. Rubinsky Date: Tue, 21 Dec 2010 00:03:23 +0000 (-0500) Subject: H4 style file/class names for the various forms X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=664f333a973653dfb579b39851bcc1e6b4291b74;p=horde.git H4 style file/class names for the various forms --- diff --git a/hermes/deliverables.php b/hermes/deliverables.php index 4ed1e39dc..014a66505 100644 --- a/hermes/deliverables.php +++ b/hermes/deliverables.php @@ -8,17 +8,13 @@ * @author Jason M. Felice */ require_once dirname(__FILE__) . '/lib/Application.php'; - Horde_Registry::appInit('hermes'); -// @TODO -require_once HERMES_BASE . '/lib/Forms/Deliverable.php'; - $vars = Horde_Variables::getDefaultVariables(); switch ($vars->get('formname')) { case 'deliverableform': - $form = new DeliverableForm($vars); + $form = new Hermes_Form_Deliverable($vars); $form->validate($vars); if ($form->isValid()) { try { @@ -56,7 +52,7 @@ require HERMES_TEMPLATES . '/menu.inc'; $renderer = new Horde_Form_Renderer(); if (!$vars->exists('deliverable_id') && !$vars->exists('new')) { - $clientSelector = new DeliverableClientSelector($vars); + $clientSelector = new Hermes_Form_Deliverable_ClientSelector($vars); $clientSelector->renderActive($renderer, $vars, 'deliverables.php', 'post'); } @@ -67,7 +63,7 @@ if ($vars->exists('deliverable_id') || $vars->exists('new')) { $vars->set($name, $value); } } - $form = new DeliverableForm($vars); + $form = new Hermes_Form_Deliverable($vars); $form->renderActive($renderer, $vars, 'deliverables.php', 'post'); } elseif ($vars->exists('client_id')) { $clients = Hermes::listClients(); diff --git a/hermes/entry.php b/hermes/entry.php index 9763be590..82ad412eb 100644 --- a/hermes/entry.php +++ b/hermes/entry.php @@ -12,11 +12,7 @@ require_once dirname(__FILE__) . '/lib/Application.php'; Horde_Registry::appInit('hermes'); -// @TODO -require_once HERMES_BASE . '/lib/Forms/Time.php'; - $vars = Horde_Variables::getDefaultVariables(); - if (!$vars->exists('id') && $vars->exists('timer')) { $timer_id = $vars->get('timer'); $timers = @unserialize($prefs->getValue('running_timers')); @@ -34,8 +30,8 @@ if (!$vars->exists('id') && $vars->exists('timer')) { } switch ($vars->get('formname')) { -case 'timeentryform': - $form = new TimeEntryForm($vars); +case 'hermes_form_time_entry': + $form = new Hermes_Form_Time_Entry($vars); if ($form->validate($vars)) { $form->getInfo($vars, $info); try { @@ -85,7 +81,7 @@ default: } } } - $form = new TimeEntryForm($vars); + $form = new Hermes_Form_Time_Entry($vars); break; } $form->setCostObjects($vars); diff --git a/hermes/lib/Admin.php b/hermes/lib/Admin.php index 16f4a8114..9be88af27 100644 --- a/hermes/lib/Admin.php +++ b/hermes/lib/Admin.php @@ -9,11 +9,6 @@ */ /** - * Horde_Form - */ -require_once 'Horde/Form.php'; - -/** * @package Hermes */ class AddJobTypeForm extends Horde_Form { diff --git a/hermes/lib/Api.php b/hermes/lib/Api.php index ba13f1122..668e71899 100644 --- a/hermes/lib/Api.php +++ b/hermes/lib/Api.php @@ -400,8 +400,6 @@ class Hermes_Api extends Horde_Registry_Api $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); diff --git a/hermes/lib/Data/hermes_csv.php b/hermes/lib/Data/hermes_csv.php index 07fba35e4..0c74ed1fc 100644 --- a/hermes/lib/Data/hermes_csv.php +++ b/hermes/lib/Data/hermes_csv.php @@ -1,7 +1,4 @@ + * @package Hermes + */ +class Hermes_Form_Deliverable extends Horde_Form +{ + public function __construct(&$vars) + { + parent::Horde_Form($vars, _("Deliverable Detail")); + + $this->addHidden('', 'deliverable_id', 'text', false); + $this->addHidden('', 'client_id', 'text', false); + $this->addHidden('', 'parent', 'text', false); + + $this->addVariable(_("Display Name"), 'name', 'text', true); + $this->addVariable(_("Active?"), 'active', 'boolean', true); + $this->addVariable(_("Estimated Hours"), 'estimate', 'number', false); + $this->addVariable(_("Description"), 'description', 'longtext', false); + } + +} diff --git a/hermes/lib/Form/Deliverable/ClientSelector.php b/hermes/lib/Form/Deliverable/ClientSelector.php new file mode 100644 index 000000000..7ab05181a --- /dev/null +++ b/hermes/lib/Form/Deliverable/ClientSelector.php @@ -0,0 +1,41 @@ + + * @package Hermes + */ +class Hermes_Form_Deliverable_ClientSelector extends Horde_Form +{ + public function __construct(&$vars) + { + parent::Horde_Form($vars, _("Select Client")); + $action = &Horde_Form_Action::factory('submit'); + list($clienttype, $clientparams) = $this->getClientType(); + + $cli = &$this->addVariable(_("Client"), 'client_id', $clienttype, true, false, null, $clientparams); + $cli->setAction($action); + $this->setButtons(_("Edit Deliverables")); + } + + public function getClientType() + { + try { + $clients = Hermes::listClients(); + } catch (Hermes_Exception $e) { + return array('invalid', array(sprintf(_("An error occurred listing clients: %s"), + $clients->getMessage()))); + } + if (count($clients)) { + return array('enum', array($clients)); + } else { + return array('invalid', array(_("There are no clients which you have access to."))); + } + } + +} \ No newline at end of file diff --git a/hermes/lib/Form/Export.php b/hermes/lib/Form/Export.php new file mode 100644 index 000000000..2b9dfffa6 --- /dev/null +++ b/hermes/lib/Form/Export.php @@ -0,0 +1,50 @@ + + * @author Jason M. Felice + * @package Hermes + */ +class Hermes_Form_Export extends Horde_Form +{ + protected $_useFormToken = false; + + public function __construct(&$vars) + { + $perms = $GLOBALS['injector']->getInstance('Horde_Perms');; + parent::Horde_Form($vars, _("Export Search Results")); + + $formats = array('hermes_csv' => _("Comma-Separated Variable (.csv)"), + 'hermes_xls' => _("Microsoft Excel (.xls)"), + 'iif' => _("QuickBooks (.iif)"), + 'hermes_tsv' => _("Tab-Separated Variable (.tsv, .txt)"), + ); + + $this->addVariable(_("Select the export format"), 'format', 'enum', + true, false, null, array($formats)); + + if ($perms->hasPermission('hermes:review', $GLOBALS['registry']->getAuth(), Horde_Perms::EDIT)) { + $yesno = array('yes' => _("Yes"), + 'no' => _("No")); + $var = &$this->addVariable(_("Mark the time as exported?"), + 'mark_exported', 'enum', true, false, + null, array($yesno)); + $var->setDefault('no'); + } + + $this->setButtons(_("Export")); + } + +} diff --git a/hermes/lib/Form/Search.php b/hermes/lib/Form/Search.php new file mode 100644 index 000000000..e9b16043d --- /dev/null +++ b/hermes/lib/Form/Search.php @@ -0,0 +1,202 @@ + + * @package Hermes + */ +class Hermes_Form_Search extends Horde_Form +{ + protected $_useFormToken = false; + + public function __construct(&$vars) + { + parent::Horde_Form($vars, _("Search For Time")); + $perms = $GLOBALS['injector']->getInstance('Horde_Perms'); + + if ($perms->hasPermission('hermes:review', $GLOBALS['registry']->getAuth(), Horde_Perms::SHOW)) { + $type = Hermes::getEmployeesType(); + $this->addVariable(_("Employees"), 'employees', $type[0], false, + false, null, $type[1]); + } + $type = $this->getClientsType(); + $cli = &$this->addVariable(_("Clients"), 'clients', $type[0], false, false, null, $type[1]); + $cli->setAction(Horde_Form_Action::factory('submit')); + $cli->setOption('trackchange', true); + + $type = $this->getJobTypesType(); + $this->addVariable(_("Job Types"), 'jobtypes', $type[0], false, false, + null, $type[1]); + + $this->addVariable(_("Cost Objects"), 'costobjects', 'multienum', + false, false, null, + array($this->getCostObjectType($vars))); + + $this->addVariable(_("Do not include entries before"), 'start', + 'monthdayyear', false, false, null, + array(date('Y') - 10)); + $this->addVariable(_("Do not include entries after"), 'end', + 'monthdayyear', false, false, null, + array(date('Y') - 10)); + + $states = array('' => '', + '1' => _("Yes"), + '0' => _("No")); + $this->addVariable(_("Submitted?"), 'submitted', 'enum', false, false, + null, array($states)); + + $this->addVariable(_("Exported?"), 'exported', 'enum', false, false, + null, array($states)); + + $this->addVariable(_("Billable?"), 'billable', 'enum', false, false, + null, array($states)); + + $this->setButtons(_("Search")); + } + + public function getClientsType() + { + try { + $clients = Hermes::listClients(); + } catch (Exception $e) { + return array('invalid', array(sprintf(_("An error occurred listing clients: %s"), $e->getMessage()))); + } + $clients = array('' => _("- - None - -")) + $clients; + + return array('multienum', array($clients)); + } + + public function getJobTypesType() + { + try { + $types = $GLOBALS['injector']->getInstance('Hermes_Driver')->listJobTypes(); + } catch (Horde_Exception $e) { + return array('invalid', array(sprintf(_("An error occurred listing job types: %s"), $e->getMessage()))); + } + $values = array(); + foreach ($types as $id => $type) { + $values[$id] = $type['name']; + if (empty($type['enabled'])) { + $values[$id] .= _(" (DISABLED)"); + } + } + + return array('multienum', array($values)); + } + + public function getCostObjectType($vars) + { + global $registry; + + $clients = $vars->get('clients'); + if (count($clients) == 0){ + $clients = array(''); + } + + $costobjects = array(); + foreach ($clients as $client) { + $criteria = array('user' => $GLOBALS['registry']->getAuth(), + 'active' => true, + 'client_id' => $client); + + foreach ($registry->listApps() as $app) { + if ($registry->hasMethod('listCostObjects', $app)) { + try { + $res = $registry->callByPackage($app, 'listCostObjects', array($criteria)); + } catch (Horde_Exception $e) { + $GLOBALS['notification']->push(sprintf(_("Error retrieving cost objects from \"%s\": %s"), $registry->get('name', $app), $res->getMessage()), 'horde.error'); + continue; + } + foreach (array_keys($res) as $catkey) { + foreach (array_keys($res[$catkey]['objects']) as $okey){ + $res[$catkey]['objects'][$okey]['id'] = $app . ':' . + $res[$catkey]['objects'][$okey]['id']; + } + } + $costobjects = array_merge($costobjects, $res); + } + } + } + + $elts = array(); + $counter = 0; + foreach ($costobjects as $category) { + Horde_Array::arraySort($category['objects'], 'name'); + foreach ($category['objects'] as $object) { + $name = $object['name']; + if (Horde_String::length($name) > 80) { + $name = Horde_String::substr($name, 0, 76) . ' ...'; + } + $elts[$object['id']] = $name; + } + } + + return $elts; + } + + + public function getSearchCriteria(&$vars) + { + if (!$this->isValid() || !$this->isSubmitted()) { + return null; + } + $this->getInfo($vars, $info); + $perms = $GLOBALS['injector']->getInstance('Horde_Perms'); + + $criteria = array(); + if ($perms->hasPermission('hermes:review', $GLOBALS['registry']->getAuth(), Horde_Perms::SHOW)) { + if (!empty($info['employees'])) { + $auth = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Auth')->create(); + if (!$auth->hasCapability('list')) { + $criteria['employee'] = explode(',', $info['employees']); + } else { + $criteria['employee'] = $info['employees']; + } + } + } else { + $criteria['employee'] = $GLOBALS['registry']->getAuth(); + } + if (!empty($info['clients'])) { + $criteria['client'] = $info['clients']; + } + if (!empty($info['jobtypes'])) { + $criteria['jobtype'] = $info['jobtypes']; + } + if (!empty($info['costobjects'])) { + $criteria['costobject'] = $info['costobjects']; + } + if (!empty($info['start'])) { + $dt = new Date($info['start']); + $criteria['start'] = $dt->getDate(DATE_FORMAT_UNIXTIME); + } + if (!empty($info['end'])) { + $dt = new Date($info['end']); + $dt->setHour(23); + $dt->setMinute(59); + $dt->setSecond(59); + $criteria['end'] = $dt->getDate(DATE_FORMAT_UNIXTIME); + } + if (isset($info['submitted']) && $info['submitted'] != '') { + $criteria['submitted'] = $info['submitted']; + } + if (isset($info['exported']) && $info['exported'] != '') { + $criteria['exported'] = $info['exported']; + } + if (isset($info['billable']) && $info['billable'] != '') { + $criteria['billable'] = $info['billable']; + } + + return $criteria; + } + +} diff --git a/hermes/lib/Form/Time.php b/hermes/lib/Form/Time.php new file mode 100644 index 000000000..a1ee6c679 --- /dev/null +++ b/hermes/lib/Form/Time.php @@ -0,0 +1,142 @@ + + * @package Hermes + */ +class Hermes_Form_Time extends Horde_Form +{ + public function __construct(&$vars, $name = null) + { + parent::Horde_Form($vars, $name); + } + + public function getJobTypeType() + { + try { + $types = $GLOBALS['injector']->getInstance('Hermes_Driver')->listJobTypes(array('enabled' => true)); + } catch (Horde_Exception $e) { + return array('invalid', array(sprintf(_("An error occurred listing job types: %s"), $e->getMessage()))); + } + if (count($types)) { + $values = array(); + foreach ($types as $id => $type) { + $values[$id] = $type['name']; + } + return array('enum', array($values)); + } + + return array('invalid', array(_("There are no job types configured."))); + } + + public function getClientType() + { + try { + $clients = Hermes::listClients(); + } catch (Horde_Exception $e) { + return array('invalid', array(sprintf(_("An error occurred listing clients: %s"), $e->getMessage()))); + } + if ($clients) { + if (count($clients) > 1) { + $clients = array('' => _("--- Select A Client ---")) + $clients; + } + return array('enum', array($clients)); + } else { + return array('invalid', array(_("There are no clients which you have access to."))); + } + } + + /** + */ + public function getCostObjectType($clientID = null) + { + global $registry; + + /* Check to see if any other active applications are exporting cost + * objects to which we might want to bill our time. */ + $criteria = array('user' => $GLOBALS['registry']->getAuth(), + 'active' => true); + if (!empty($clientID)) { + $criteria['client_id'] = $clientID; + } + + $costobjects = array(); + foreach ($registry->listApps() as $app) { + if (!$registry->hasMethod('listCostObjects', $app)) { + continue; + } + + try { + $result = $registry->callByPackage($app, 'listCostObjects', array($criteria)); + } catch (Horde_Exception $e) { + $GLOBALS['notification']->push(sprintf(_("Error retrieving cost objects from \"%s\": %s"), $registry->get('name', $app), $e->getMessage()), 'horde.error'); + continue; + } + + foreach (array_keys($result) as $catkey) { + foreach (array_keys($result[$catkey]['objects']) as $okey){ + $result[$catkey]['objects'][$okey]['id'] = $app . ':' . + $result[$catkey]['objects'][$okey]['id']; + } + } + + if ($app == $registry->getApp()) { + $costobjects = array_merge($result, $costobjects); + } else { + $costobjects = array_merge($costobjects, $result); + } + } + + $elts = array('' => _("--- No Cost Object ---")); + $counter = 0; + foreach ($costobjects as $category) { + Horde_Array::arraySort($category['objects'], 'name'); + $elts['category%' . $counter++] = sprintf('--- %s ---', $category['category']); + foreach ($category['objects'] as $object) { + $name = $object['name']; + if (Horde_String::length($name) > 80) { + $name = Horde_String::substr($name, 0, 76) . ' ...'; + } + + $hours = 0.0; + $filter = array('costobject' => $object['id']); + if (!empty($GLOBALS['conf']['time']['sum_billable_only'])) { + $filter['billable'] = true; + } + $result = $GLOBALS['injector']->getInstance('Hermes_Driver')->getHours($filter, array('hours')); + foreach ($result as $entry) { + if (!empty($entry['hours'])) { + $hours += $entry['hours']; + } + } + + /* Show summary of hours versus estimate for this + * deliverable. */ + if (empty($object['estimate'])) { + $name .= sprintf(_(" (%0.2f hours)"), $hours); + } else { + $name .= sprintf(_(" (%d%%, %0.2f of %0.2f hours)"), + (int)($hours / $object['estimate'] * 100), + $hours, $object['estimate']); + } + + $elts[$object['id']] = $name; + } + } + + return $elts; + } + +} \ No newline at end of file diff --git a/hermes/lib/Form/Time/Entry.php b/hermes/lib/Form/Time/Entry.php new file mode 100644 index 000000000..7276b1411 --- /dev/null +++ b/hermes/lib/Form/Time/Entry.php @@ -0,0 +1,90 @@ + + * @package Hermes + */ +class Hermes_Form_Time_Entry extends Hermes_Form_Time +{ + /** + * Reference to the form field storing the cost objects. + * + * @var Horde_Form_Variable + */ + protected $_costObjects; + + public function __construct (&$vars) + { + global $conf; + + if ($vars->exists('id')) { + parent::__construct($vars, _("Update Time")); + $delete_link = Horde::url(time.php)->add('delete', $vars->get('id'))->link(array('title' => _("Delete Entry"))) . _("Delete"); + $this->setExtra('' . $delete_link . ''); + } else { + parent::__construct($vars, _("New Time")); + } + $this->setButtons(_("Save")); + + list($clienttype, $clientparams) = $this->getClientType(); + if ($clienttype == 'enum') { + $action = &Horde_Form_Action::factory('submit'); + } + + list($typetype, $typeparams) = $this->getJobTypeType(); + + if ($vars->exists('id')) { + $this->addHidden('', 'id', 'int', true); + } + + if ($vars->exists('url')) { + $this->addHidden('', 'url', 'text', true); + } + + $var = &$this->addVariable(_("Date"), 'date', 'monthdayyear', true, + false, null, array(date('Y') - 1)); + $var->setDefault(date('Y-m-d')); + + $cli = &$this->addVariable(_("Client"), 'client', $clienttype, true, false, null, $clientparams); + if (isset($action)) { + $cli->setAction($action); + $cli->setOption('trackchange', true); + } + + $this->addVariable(_("Job Type"), 'type', $typetype, true, false, null, $typeparams); + + $this->_costObjects = &$this->addVariable( + _("Cost Object"), 'costobject', 'enum', false, false, null, + array(array())); + + $this->addVariable(_("Hours"), 'hours', 'number', true); + + if ($conf['time']['choose_ifbillable']) { + $yesno = array(1 => _("Yes"), 0 => _("No")); + $this->addVariable(_("Billable?"), 'billable', 'enum', true, false, null, array($yesno)); + } + + if ($vars->exists('client')) { + try { + $info = $GLOBALS['injector']->getInstance('Hermes_Driver')->getClientSettings($vars->get('client')); + } catch (Horde_Exception $e) {} + if (!$info['enterdescription']) { + $vars->set('description', _("See Attached Timesheet")); + } + } + $descvar = &$this->addVariable(_("Description"), 'description', 'longtext', true, false, null, array(4, 60)); + $this->addVariable(_("Additional Notes"), 'note', 'longtext', false, false, null, array(4, 60)); + } + + function setCostObjects($vars) + { + $this->_costObjects->type->setValues($this->getCostObjectType($vars->get('client'))); + } + +} \ No newline at end of file diff --git a/hermes/lib/Table.php b/hermes/lib/Table.php index 1e3eb7842..c8e9c2db4 100644 --- a/hermes/lib/Table.php +++ b/hermes/lib/Table.php @@ -8,20 +8,20 @@ * See the enclosed file LICENSE for license information (BSD). If you * did not receive this file, see http://www.horde.org/licenses/bsdl.php. */ -class Horde_Core_Ui_Table extends Horde_Core_Ui_Widget { - +class Hermes_Table extends Horde_Core_Ui_Widget +{ /** * Data loaded from the getTableMetaData API. * * @access private * @var array */ - var $_metaData = null; + private $_metaData = null; /** * @var array */ - var $_formVars = array(); + protected $_formVars = array(); public function getMetaData() { diff --git a/hermes/search.php b/hermes/search.php index affeb295a..b4a067077 100644 --- a/hermes/search.php +++ b/hermes/search.php @@ -11,14 +11,7 @@ require_once dirname(__FILE__) . '/lib/Application.php'; Horde_Registry::appInit('hermes'); -// @TODO -require_once HERMES_BASE . '/lib/Forms/Export.php'; -require_once HERMES_BASE . '/lib/Forms/Search.php'; -require_once HERMES_BASE . '/lib/Forms/Time.php'; -require_once HERMES_BASE . '/lib/Table.php'; - $vars = Horde_Variables::getDefaultVariables(); - $delete = $vars->get('delete'); if (!empty($delete)) { try { @@ -34,8 +27,8 @@ $criteria = null; $formname = $vars->get('formname'); switch ($formname) { -case 'searchform': - $form = new SearchForm($vars); +case 'hermes_form_search': + $form = new Hermes_Form_Search($vars); $form->validate($vars); $criteria = $form->getSearchCriteria($vars); if (is_null($criteria)) { @@ -45,16 +38,16 @@ case 'searchform': } break; -case 'exportform': +case 'hermes_form_export': if (!($searchVars = $session->get('hermes', 'search_criteria'))) { $notification->push(_("No search to export!"), 'horde.error'); } else { - $searchForm = new SearchForm($searchVars); + $searchForm = new Hermes_Form_Search($searchVars); $criteria = $searchForm->getSearchCriteria($searchVars); if (is_null($criteria)) { $notification->push(_("No search to export!"), 'horde.error'); } else { - $form = new ExportForm($vars); + $form = new Hermes_Form_Export($vars); $form->validate($vars); if ($form->isValid()) { $form->getInfo($vars, $info); @@ -94,7 +87,7 @@ require $registry->get('templates', 'horde') . '/common-header.inc'; if (!($searchVars = $session->get('hermes', 'search_criteria'))) { $searchVars = $vars; } -$form = new SearchForm($searchVars); +$form = new Hermes_Form_Search($searchVars); $print_link = Horde::url(Horde_Util::addParameter('search.php', array('print' => 'true'))); require HERMES_TEMPLATES . '/menu.inc'; @@ -108,7 +101,7 @@ if ($session->exists('hermes', 'search_criteria')) { $criteria = $form->getSearchCriteria($searchVars); } - $table = new Horde_Core_Ui_Table('results', $vars, + $table = new Hermes_Table('results', $vars, array('title' => _("Search Results"), 'name' => 'hermes/hours', 'params' => $criteria)); @@ -124,7 +117,7 @@ if ($session->exists('hermes', 'search_criteria')) { if (!$print_view) { echo '
'; - $exportForm = new ExportForm($vars); + $exportForm = new Hermes_Form_Export($vars); $exportForm->renderActive(new Horde_Form_Renderer(), $vars, 'search.php', 'post'); } diff --git a/hermes/time.php b/hermes/time.php index 7e4ccec81..b98030c67 100644 --- a/hermes/time.php +++ b/hermes/time.php @@ -12,11 +12,7 @@ require_once dirname(__FILE__) . '/lib/Application.php'; Horde_Registry::appInit('hermes'); -require_once HERMES_BASE . '/lib/Forms/Time.php'; -require_once HERMES_BASE . '/lib/Table.php'; - $vars = Horde_Variables::getDefaultVariables(); - $delete = $vars->get('delete'); if (!empty($delete)) { try { @@ -55,7 +51,7 @@ $tabs = Hermes::tabs(); $criteria = array('employee' => $GLOBALS['registry']->getAuth(), 'submitted' => false, 'link_page' => 'time.php'); -$table = new Horde_Core_Ui_Table('week', $vars, +$table = new Hermes_Table('week', $vars, array('title' => _("My Unsubmitted Time"), 'name' => 'hermes/hours', 'params' => $criteria));