1: <?php
2: 3: 4: 5: 6: 7:
8: class Whups_Form_Search extends Horde_Form
9: {
10: protected $_useFormToken = false;
11:
12: public function __construct(&$vars)
13: {
14: parent::__construct($vars);
15:
16: $this->setButtons(true);
17: $this->appendButtons(_("Save as Query"));
18: $this->setSection('attributes', _("Attributes"));
19:
20: $queues = Whups::permissionsFilter(
21: $GLOBALS['whups_driver']->getQueues(), 'queue', Horde_Perms::READ);
22: $queue_count = count($queues);
23: $types = array();
24: if ($queue_count == 1) {
25: $types = $GLOBALS['whups_driver']->getTypes(key($queues));
26: $this->addHidden('', 'queue', 'int', false, true);
27: $vars->set('queue', key($queues));
28: } else {
29: if ($queue_count > 0) {
30: $modtype = 'enum';
31: $queue_params = array(array('0' => _("Any")) + $queues);
32: foreach ($queues as $queueID => $name) {
33: $types = $types + $GLOBALS['whups_driver']->getTypes($queueID);
34: }
35: } else {
36: $modtype = 'invalid';
37: $queue_params = array(_("There are no queues which you can search."));
38: }
39: $this->addVariable(
40: _("Queue"), 'queue', $modtype, false, false, null, $queue_params);
41: }
42:
43: $this->addVariable(_("Summary like"), 'summary', 'text', false);
44:
45: $states = array();
46: foreach ($types as $typeID => $typeName) {
47: $states = $GLOBALS['whups_driver']->getAllStateInfo($typeID);
48: $list = $default = array();
49: foreach ($states as $state) {
50: $list[$state['state_id']] = $state['state_name'];
51: if ($state['state_category'] != 'resolved') {
52: $default[] = $state['state_id'];
53: }
54: }
55: $v = $this->addVariable(
56: $typeName, "states[$typeID]", 'multienum', false, false, null,
57: array ($list, 4));
58: if (!$this->isSubmitted()) {
59: $v->setDefault($default);
60: }
61: }
62:
63: $this->setSection('dates', _("Dates"));
64: $this->addVariable(
65: _("Created from"), 'ticket_timestamp[from]', 'monthdayyear', false,
66: false, null, array(date('Y') - 10));
67: $this->addVariable(
68: _("to"), 'ticket_timestamp[to]', 'monthdayyear', false, false, null,
69: array(date('Y') - 10));
70: $this->addVariable(
71: _("Updated from"), 'date_updated[from]', 'monthdayyear', false,
72: false, null, array(date('Y') - 10));
73: $this->addVariable(
74: _("to"), 'date_updated[to]', 'monthdayyear', false, false, null,
75: array(date('Y') - 10));
76: $this->addVariable(
77: _("Resolved from"), 'date_resolved[from]', 'monthdayyear', false,
78: false, null, array(date('Y') - 10));
79: $this->addVariable(
80: _("to"), 'date_resolved[to]', 'monthdayyear', false, false, null,
81: array(date('Y') - 10));
82: $this->addVariable(
83: _("Assigned from"), 'date_assigned[from]', 'monthdayyear', false,
84: false, null, array(date('Y') - 10));
85: $this->addVariable(
86: _("to"), 'date_assigned[to]', 'monthdayyear', false, false, null,
87: array(date('Y') - 10));
88: $this->addVariable(
89: _("Due from"), 'ticket_due[from]', 'monthdayyear', false, false,
90: null, array(date('Y') - 10));
91: $this->addVariable(
92: _("to"), 'ticket_due[to]', 'monthdayyear', false, false, null,
93: array(date('Y') - 10));
94: }
95:
96: 97: 98: 99: 100: 101: 102:
103: public function getInfo($vars, &$info)
104: {
105: parent::getInfo($vars, $info);
106:
107: if (empty($info['queue'])) {
108: $info['queue'] = array_keys(
109: Whups::permissionsFilter(
110: $GLOBALS['whups_driver']->getQueues(),
111: 'queue',
112: Horde_Perms::READ,
113: $GLOBALS['registry']->getAuth(),
114: $GLOBALS['registry']->getAuth()));
115: } else {
116: $info['queue'] = array($info['queue']);
117: }
118:
119: if (empty($info['states'])) {
120: unset($info['states']);
121: }
122:
123:
124: if (isset($info['states'])) {
125:
126: $info['state_id'] = array();
127: foreach ($info['states'] as $states) {
128: if (isset($states)) {
129:
130: $info['state_id'] = array_merge($info['state_id'], $states);
131: }
132: }
133: unset($info['states']);
134: }
135:
136:
137: $types = array();
138: foreach ($info['queue'] as $queue) {
139: foreach ($GLOBALS['whups_driver']->getTypeIds($queue) as $type) {
140: $types[$type][$queue] = true;
141: }
142: }
143: $queues = array();
144: foreach ($info['state_id'] as $stateId) {
145: $state = $GLOBALS['whups_driver']->getState($stateId);
146: if (isset($types[$state['type']])) {
147: $queues = array_merge($queues, array_keys($types[$state['type']]));
148: }
149: }
150: $info['queue'] = array_intersect($info['queue'], $queues);
151: }
152: }
153: