Overview

Packages

  • Hermes
  • Horde
    • Data
  • Kronolith
  • None

Classes

  • Hermes
  • Hermes_Ajax_Application
  • Hermes_Api
  • Hermes_Driver
  • Hermes_Driver_Sql
  • Hermes_Factory_Driver
  • Hermes_Form_Admin_AddJobType
  • Hermes_Form_Admin_DeleteJobType
  • Hermes_Form_Admin_EditClientStepOne
  • Hermes_Form_Admin_EditClientStepTwo
  • Hermes_Form_Admin_EditJobTypeStepOne
  • Hermes_Form_Admin_EditJobTypeStepTwo
  • Hermes_Form_Deliverable
  • Hermes_Form_Deliverable_ClientSelector
  • Hermes_Form_Export
  • Hermes_Form_JobType_Edit_Step1
  • Hermes_Form_Search
  • Hermes_Form_Time
  • Hermes_Form_Time_Entry
  • Hermes_LoginTasks_SystemTask_Upgrade
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * @package Hermes
  4:  *
  5:  * Copyright 2002-2012 Horde LLC (http://www.horde.org/)
  6:  *
  7:  * See the enclosed file LICENSE for license information (BSD). If you
  8:  * did not receive this file, see http://www.horde.org/licenses/bsdl.php.
  9:  *
 10:  */
 11: 
 12: /**
 13:  * Hermes time search form.
 14:  *
 15:  * @author Chuck Hagenbuch <chuck@horde.org>
 16:  * @package Hermes
 17:  */
 18: class Hermes_Form_Search extends Horde_Form
 19: {
 20:     protected $_useFormToken = false;
 21: 
 22:     public function __construct(&$vars)
 23:     {
 24:         parent::Horde_Form($vars, _("Search For Time"));
 25:         $perms = $GLOBALS['injector']->getInstance('Horde_Perms');
 26: 
 27:         if ($perms->hasPermission('hermes:review', $GLOBALS['registry']->getAuth(), Horde_Perms::SHOW)) {
 28:             $type = Hermes::getEmployeesType();
 29:             $this->addVariable(_("Employees"), 'employees', $type[0], false,
 30:                                false, null, $type[1]);
 31:         }
 32:         $type = $this->getClientsType();
 33:         $cli = &$this->addVariable(_("Clients"), 'clients', $type[0], false, false, null, $type[1]);
 34:         $cli->setAction(Horde_Form_Action::factory('submit'));
 35:         $cli->setOption('trackchange', true);
 36: 
 37:         $type = $this->getJobTypesType();
 38:         $this->addVariable(_("Job Types"), 'jobtypes', $type[0], false, false,
 39:                            null, $type[1]);
 40: 
 41:         $this->addVariable(_("Cost Objects"), 'costobjects', 'multienum',
 42:                            false, false, null,
 43:                            array(Hermes::getCostObjectType($vars->get('clients'))));
 44: 
 45:         $this->addVariable(_("Do not include entries before"), 'start',
 46:                            'monthdayyear', false, false, null,
 47:                            array(date('Y') - 10));
 48:         $this->addVariable(_("Do not include entries after"), 'end',
 49:                            'monthdayyear', false, false, null,
 50:                            array(date('Y') - 10));
 51: 
 52:         $states = array(''  => '',
 53:                         '1' => _("Yes"),
 54:                         '0' => _("No"));
 55:         $this->addVariable(_("Submitted?"), 'submitted', 'enum', false, false,
 56:                            null, array($states));
 57: 
 58:         $this->addVariable(_("Exported?"), 'exported', 'enum', false, false,
 59:                            null, array($states));
 60: 
 61:         $this->addVariable(_("Billable?"), 'billable', 'enum', false, false,
 62:                            null, array($states));
 63: 
 64:         $this->setButtons(_("Search"));
 65:     }
 66: 
 67:     public function getClientsType()
 68:     {
 69:         try {
 70:             $clients = Hermes::listClients();
 71:         } catch (Exception $e) {
 72:             return array('invalid', array(sprintf(_("An error occurred listing clients: %s"), $e->getMessage())));
 73:         }
 74:         $clients = array('' => _("- - None - -")) + $clients;
 75: 
 76:         return array('multienum', array($clients));
 77:     }
 78: 
 79:     public function getJobTypesType()
 80:     {
 81:         try {
 82:             $types = $GLOBALS['injector']->getInstance('Hermes_Driver')->listJobTypes();
 83:         } catch (Horde_Exception $e) {
 84:             return array('invalid', array(sprintf(_("An error occurred listing job types: %s"), $e->getMessage())));
 85:         }
 86:         $values = array();
 87:         foreach ($types as $id => $type) {
 88:             $values[$id] = $type['name'];
 89:             if (empty($type['enabled'])) {
 90:                 $values[$id] .= _(" (DISABLED)");
 91:             }
 92:         }
 93: 
 94:         return array('multienum', array($values));
 95:     }
 96: 
 97:     public function getCostObjectType($vars)
 98:     {
 99:         global $registry;
100: 
101:         $clients = $vars->get('clients');
102:         if (count($clients) == 0){
103:             $clients = array('');
104:         }
105: 
106:         $costobjects = array();
107:         foreach ($clients as $client) {
108:             $criteria = array('user' => $GLOBALS['registry']->getAuth(),
109:                               'active' => true,
110:                               'client_id' => $client);
111: 
112:             foreach ($registry->listApps() as $app) {
113:                 if ($registry->hasMethod('listCostObjects', $app)) {
114:                     try {
115:                         $res = $registry->callByPackage($app, 'listCostObjects', array($criteria));
116:                     } catch (Horde_Exception $e) {
117:                         $GLOBALS['notification']->push(sprintf(_("Error retrieving cost objects from \"%s\": %s"), $registry->get('name', $app), $res->getMessage()), 'horde.error');
118:                         continue;
119:                     }
120:                     foreach (array_keys($res) as $catkey) {
121:                         foreach (array_keys($res[$catkey]['objects']) as $okey){
122:                             $res[$catkey]['objects'][$okey]['id'] = $app . ':' .
123:                                 $res[$catkey]['objects'][$okey]['id'];
124:                         }
125:                     }
126:                     $costobjects = array_merge($costobjects, $res);
127:                 }
128:             }
129:         }
130: 
131:         $elts = array();
132:         $counter = 0;
133:         foreach ($costobjects as $category) {
134:             Horde_Array::arraySort($category['objects'], 'name');
135:             foreach ($category['objects'] as $object) {
136:                 $name = $object['name'];
137:                 if (Horde_String::length($name) > 80) {
138:                     $name = Horde_String::substr($name, 0, 76) . ' ...';
139:                 }
140:                 $elts[$object['id']] = $name;
141:             }
142:         }
143: 
144:         return $elts;
145:     }
146: 
147: 
148:     public function getSearchCriteria(&$vars)
149:     {
150:         if (!$this->isValid() || !$this->isSubmitted()) {
151:             return null;
152:         }
153:         $this->getInfo($vars, $info);
154:         $perms = $GLOBALS['injector']->getInstance('Horde_Perms');
155: 
156:         $criteria = array();
157:         if ($perms->hasPermission('hermes:review', $GLOBALS['registry']->getAuth(), Horde_Perms::SHOW)) {
158:             if (!empty($info['employees'])) {
159:                 $auth = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Auth')->create();
160:                 if (!$auth->hasCapability('list')) {
161:                     $criteria['employee'] = explode(',', $info['employees']);
162:                 } else {
163:                     $criteria['employee'] = $info['employees'];
164:                 }
165:             }
166:         } else {
167:             $criteria['employee'] = $GLOBALS['registry']->getAuth();
168:         }
169:         if (!empty($info['clients'])) {
170:             $criteria['client'] = $info['clients'];
171:         }
172:         if (!empty($info['jobtypes'])) {
173:             $criteria['jobtype'] = $info['jobtypes'];
174:         }
175:         if (!empty($info['costobjects'])) {
176:             $criteria['costobject'] = $info['costobjects'];
177:         }
178:         if (!empty($info['start'])) {
179:             $dt = new Horde_Date($info['start']);
180:             $criteria['start'] = $dt->timestamp();
181:         }
182:         if (!empty($info['end'])) {
183:             $dt = new Horde_Date($info['end']);
184:             $criteria['end'] = $dt->add(86400)->timestamp();
185:         }
186:         if (isset($info['submitted']) && $info['submitted'] != '') {
187:             $criteria['submitted'] = $info['submitted'];
188:         }
189:         if (isset($info['exported']) && $info['exported'] != '') {
190:             $criteria['exported'] = $info['exported'];
191:         }
192:         if (isset($info['billable']) && $info['billable'] != '') {
193:             $criteria['billable'] = $info['billable'];
194:         }
195: 
196:         return $criteria;
197:     }
198: 
199: }
200: 
API documentation generated by ApiGen