/[drupal]/contributions/modules/helpdesk/contract.php
ViewVC logotype

Contents of /contributions/modules/helpdesk/contract.php

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.1 - (show annotations) (download) (as text)
Tue Jan 17 19:55:10 2006 UTC (3 years, 10 months ago) by fgm
Branch: MAIN
CVS Tags: HEAD
Branch point for: DRUPAL-4-6
File MIME type: text/x-php
First version under CVS control: not yet a working version: only performs a minimal subset of the functionality designed for the module.
1 <?php
2 /**
3 * @package helpdesk
4 * Copyright OSI 2005. Licensed under GPL version 2.
5 * $Id$
6 */
7
8 $_contract_saved_er = error_reporting(E_ALL || E_STRICT) ;
9
10 /**
11 * import ancillary functions
12 */
13 require_once("misc.php");
14
15 /**
16 * import HD core
17 */
18 require_once("core.php");
19
20 /**
21 * Support contract
22 * @package helpdesk
23 */
24 class helpdeskContract extends helpdeskObject
25 {
26 public $node ; ///< backlink to drupal node object
27 public $defTimeIncrement; // default increment for elapsed time on timed contracts
28 public $isSuspended; // is contract currently in suspended mode ?
29 public $maxDate; // maximum date for which this contract is valid
30 public $maxIssue;// maximum number of issues for which this contract is valid
31 public $maxTime; // maximum elapsed time for which this contract is valid
32 public $timeId; // time information for this contract
33 public $uidCustomer; // owner of contract
34 public $useMaxDate; // use the $maxDate parameter
35 public $useMaxIssue;// use the $maxIssue parameter
36 public $useMaxTime; // use the $maxTime parameter
37
38 /**
39 * Constructor-like method filling node from set of data in node
40 * If nid is NULL, the node is new and nothing can be filled.
41 * @param object $node
42 * @todo consider the issues surrounding timeId from initial submission to actual insert
43 */
44 function init($node, $fromDB)
45 {
46 if (HELPDESKDEBUGALLFUNCTIONS == TRUE)
47 { echo "<pre>HD CONTRACT/init (" . (isset($node->nid) ? $node->nid : 'new node') . ")</pre>\r\n" ; }
48 $this->node = $node ;
49
50 /**
51 * node == NULL: can it happen ?
52 * !is_object($node): can it happen ?
53 * !isset($node->nid): new node before insert (doing preview)
54 * full node, but not in DB: new node before insert (initialising for insert)
55 */
56 if (!$fromDB)
57 {
58 // This is a new node, we initialize the object from the variable, there's nothing in the DB
59 foreach ($this as $key => $value)
60 {
61 if (($key <> 'node') && ($key <> 'timeId')) // node: Don't recurse, timeId: must think more deeply about it
62 $this->$key = isset($node->$key) ? $node->$key : NULL ;
63 }
64 return;
65 }
66 else
67 {
68 $q = '
69 SELECT
70 hdc.defTimeIncrement, hdc.isSuspended,
71 hdc.timeId, hdc.uidCustomer,
72 hdc.maxDate, hdc.maxIssue, hdc.maxTime,
73 hdc.useMaxDate, hdc.useMaxIssue, hdc.useMaxTime,
74 hdt.stime, hdt.atime, hdt.mtime, hdt.etime
75 FROM
76 {hd_contract} hdc
77 LEFT JOIN {hd_timeinfo} hdt on hdc.timeid = hdt.timeid
78 WHERE
79 hdc.nid = %d' ;
80 $res = db_query($q, $node->nid);
81 $ar = db_fetch_array($res) ; // Should give exactly one row of result, zero if contract does not exist yet
82 foreach ($ar as $key => $value)
83 {
84 $this->$key = $value ;
85 }
86 // echo "<pre>New contract object: " ; print_r ($this) ; "</pre>\r\n";
87 }
88 }
89
90
91 /**
92 * implement hook_view for HD contracts
93 * @todo implement display of the timeinfo object
94 * @todo implement contract balance display
95 * @return string
96 *
97 */
98 function view()
99 {
100 $headers = array(
101 t('Attribute'),
102 t('Use'),
103 t('Maximum'),
104 t('Current')
105 ) ;
106
107 $rows = array
108 ( // Row with attributes on the row and some of its cells.
109 array // First row
110 (
111 t('Number of issues'),
112 array ('data' => $this->useMaxIssue ? t('Yes') : t('No'), 'style' => 'text-align: center'),
113 array ('data' => _helpdesk_notempty($this->maxIssue, '0'), 'style' => 'text-align: center'),
114 HELPDESKUNIMPLEMENTED
115 ),
116 array // First row
117 (
118 t('Date'),
119 array ('data' => $this->useMaxDate ? t('Yes') : t('No'), 'style' => 'text-align: center'),
120 array ('data' => format_date($this->maxDate, 'medium'), 'style' => 'text-align: center'),
121 HELPDESKUNIMPLEMENTED
122 ),
123 array // First row
124 (
125 t('Spent minutes'),
126 array ('data' => $this->useMaxTime ? t('Yes') : t('No'), 'style' => 'text-align: center'),
127 array ('data' => _helpdesk_notempty($this->maxTime, '0'), 'style' => 'text-align: center'),
128 HELPDESKUNIMPLEMENTED
129 ),
130 );
131
132 $output = theme_table($headers, $rows);
133
134 $ar = array();
135 $custname = user_load(array('uid' => $this->uidCustomer))->name;
136 $ar[] = sprintf (t('Contract holder: %s'), l($custname, 'user/' . $this->uidCustomer)) ;
137 unset($custname);
138 $ar[] = sprintf(t('Default time increment for events, in minutes: %d '), _helpdesk_notempty($this->defTimeIncrement, '0'));
139 $ar[] = sprintf(t('Is contract suspended ? %s'), $this->isSuspended ? t('Yes') : t('No'));
140 $output .= theme_item_list($ar);
141
142 return $output;
143 }
144
145 /**
146 * Implement hook_insert for HD Contracts
147 *
148 * @return void
149 */
150 function insert()
151 {
152
153 /* all of this must be inserted
154 public $node ; ///< backlink to drupal node object
155 public $defTimeIncrement; // default increment for elapsed time on timed contracts
156 public $isSuspended; // is contract currently in suspended mode ?
157 public $maxDate; // maximum date for which this contract is valid
158 public $maxIssue;// maximum number of issues for which this contract is valid
159 public $maxTime; // maximum elapsed time for which this contract is valid
160 public $timeId; // time information for this contract
161 public $uidCustomer; // owner of contract
162 public $useMaxDate; // use the $maxDate parameter
163 public $useMaxIssue;// use the $maxIssue parameter
164 public $useMaxTime; // use the $maxTime parameter */
165 $q = '
166 INSERT INTO {hd_contract}
167 (deftimeincrement, issuspended,
168 maxdate, maxissue, maxtime,
169 nid, timeid, uidcustomer,
170 usemaxdate, usemaxissue, usemaxtime)
171 VALUES
172 (%d, %d,
173 %d, %d, %d,
174 %d, %d, %d,
175 %d, %d, %d)
176 ';
177 $res = db_query($q,
178 $this->defTimeIncrement, $this->isSuspended,
179 $this->maxDate, $this->maxIssue, $this->maxTime,
180 $this->node->nid, $this->timeId, $this->uidCustomer,
181 $this->useMaxDate, $this->useMaxIssue, $this->useMaxTime
182 );
183 }
184
185 /**
186 *
187 * @param helpdeskCustomer $uidcustomer
188 * @desc lists contracts held by a helpdeskCustomer
189 * @return array contract summaries (nid, title, created, changed) orderd by nid
190 */
191 static function getContractsByUid (helpdeskCustomer $uidcustomer)
192 {
193 $q = '
194 select
195 n.nid, n.title, n.created, n.changed
196 from
197 hd_contract hdc
198 left join node n on hdc.nid = n.nid
199 where UIDCUSTOMER = %d
200 order by
201 1
202 ' ;
203
204 $ret = array () ;
205 $res = db_query ($q, $uidcustomer) ;
206 while ($o = db_fetch_object($res))
207 {
208 $ret[] = array();
209 $ret[]['nid'] = $o->nid ;
210 $ret[]['title'] = $o->title ;
211 $ret[]['created'] = $o->created ;
212 $ret[]['changed'] = $o->changed ;
213 }
214 return $ret ;
215 }
216
217 /**
218 * @return array
219 * @desc Returns the nids of all tickets bound to this contracts
220 */
221 function getTickets ()
222 {
223 $ret = array() ;
224 $sq = 'select distinct NID from {hd_event} ev '
225 . 'inner join {hd_timeinfo} ti on ev.TIMEID = ti.TIMEID '
226 . 'where '
227 . ' (NIDROOT = NID) ' // This only matches tickets, not other events
228 . ' and (CONTRACTID=%1) '
229 . 'order by ti.TIMEID desc ' ;
230 $q = db_query($sq, $this->nid) ;
231 while ($o = db_result($q))
232 {
233 array_push ($o) ;
234 }
235 unset ($o) ;
236 unset ($q) ;
237 unset ($sq) ;
238 return $ret ;
239 }
240
241 /**
242 * Generates the code for hook_form when node is a helpdesk Contract
243 * @return string HTML
244 */
245 function form()
246 {
247 // Now we define the form elements specific to our node type.
248 if (HELPDESKDEBUGALLFUNCTIONS == TRUE)
249 {
250 $ret = t ("<p>Defining new %nodename</p>\n", array ('%nodename' => $this->node_name())) ;
251 }
252 else
253 $ret = '' ;
254
255
256 /* This would allow format selection, but contracts are plain text, so we use 1 = filtered html */
257 // $ret .= filter_form ('format', $node->format);
258 // $node->format = 1 ; // Filtered HTML
259 // But there's no "node" code in this method !
260 // @todo find where input filtering goes in this model
261
262 // Select contract holder
263 $q = '
264 select
265 distinct hdu.uidcustomer,
266 u.name
267 from
268 {hd_user} hdu
269 left join {users} u on hdu.uidcustomer = u.uid
270 order by
271 1
272 ' ;
273 $res = db_query($q);
274 $arCustomers = array() ;
275 while ($o = db_fetch_object($res))
276 $arCustomers[$o->uidcustomer] = "$o->name ($o->uidcustomer)" ; // We do this in code instead of SQL because SQL concatenation is not portable
277 $ret = form_select('Contract holder', 'uidCustomer', $this->uidCustomer, $arCustomers,
278 t('Choose the customer holding this contract.'), NULL,
279 FALSE, // Only one customer per contract
280 TRUE);
281
282 /* display contract timeinfo */
283 $ti = new helpdeskTimeInfo();
284 $ti->init(array(
285 'S' => time(),
286 'A' => time(),
287 'M' => time(),
288 'E' => '',
289 'showS' => TRUE, 'showA' => TRUE, 'showM' => TRUE, 'showE' => TRUE,
290 'enabledS' => TRUE, 'enabledA' => FALSE, 'enabledM' => FALSE, 'enabledE' => TRUE),
291 FALSE) ; // Load from params, not from DB
292 $items = $ti->form();
293 $ret .= form_group
294 (
295 t ('Contract date information'),
296 $items,
297 t ('Here you must define the date the contract starts (default to current date) and can optionally define when it ends'
298 // . ', and access/modification dates (default to current date)'
299 ),
300 NULL) ;
301
302 /**
303 * Parameters for new contract
304 */
305 $items = form_checkbox (t ('Suspended'), 'isSuspended', 1, $this->isSuspended, '', NULL, FALSE) ;
306 $items .= theme_table
307 (
308 array (t ('Contract limits'), t ('Limit value'), t ('Increment')),
309 array
310 (
311 array (
312 form_checkbox (t ('Minutes spent'), 'useMaxTime', 1, $this->useMaxTime, '', NULL, FALSE),
313 form_textfield ('', 'maxTime', $this->maxTime, 16, 16, NULL, NULL, FALSE),
314 form_textfield ('', 'defTimeIncrement', $this->defTimeIncrement, 4, 4, NULL, NULL, FALSE)
315 ),
316 array (
317 form_checkbox (t ('Number of tickets'), 'useMaxIssue', 1, $this->useMaxIssue, '', NULL, FALSE),
318 form_textfield ('', 'maxIssue', $this->maxIssue, 16, 16, NULL, NULL, FALSE),
319 '&nbsp;'),
320 array (
321 form_checkbox (t ('Date'), 'useMaxDate', 1, $this->useMaxDate, '', NULL, FALSE),
322 form_textfield ('', 'maxDate', $this->maxDate, 16, 16, NULL, NULL, FALSE),
323 '&nbsp;')
324 )
325 ) ;
326
327 $ret .= form_group (
328 t ('Contract status'),
329 $items,
330 t ('Here you set the attributes of the contract: is it time-limited, duration-limited, issue-limited ? does it start suspended ?'
331 . ' The increment value for time-limited contracts is the default duration consumed by each followup.'),
332 NULL) ;
333
334 $ret .= form_textarea(t('Contract wording'), 'body', (isset($this->node->body) ? $this->node->body : ''), 60, 20);
335 return $ret ;
336 }
337 }
338
339 error_reporting($_contract_saved_er) ;
340 unset($_contract_saved_er) ;
341 ?>

  ViewVC Help
Powered by ViewVC 1.1.2