forked from bitweaver/tasks
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTaskLC.php
744 lines (683 loc) · 27.5 KB
/
TaskLC.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
<?php
/**
* @version $Header$
*
* Copyright ( c ) 2006 bitweaver.org
* All Rights Reserved. See below for details and a complete list of authors.
* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See http://www.gnu.org/copyleft/lesser.html for details
*
* @package tasks
*/
/**
* required setup
*/
require_once( LIBERTY_PKG_PATH.'LibertyContent.php' ); // Tasks base class
define( 'TASKS_CONTENT_TYPE_GUID', 'task_ticket' );
/**
* @package tasks
*/
class Tasks extends LibertyContent {
var $mTicketId;
var $mPropertyId;
var $mClientId;
/**
* Constructor
*
* Build a Citizen object based on LibertyContent
* @param integer Citizen Id identifer
* @param integer Base content_id identifier
*/
function Tasks( $pTicketId = NULL, $pContentId = NULL ) {
parent::__construct();
$this->registerContentType( TASKS_CONTENT_TYPE_GUID, array(
'content_type_guid' => TASKS_CONTENT_TYPE_GUID,
'content_name' => 'Task Ticket',
'handler_class' => 'Tasks',
'handler_package' => 'tasks',
'handler_file' => 'Tasks.php',
'maintainer_url' => 'http://lsces.co.uk'
) );
$this->mTicketId = (int)$pTicketId;
$this->mContentId = (int)$pContentId;
$this->mCitizenId = 0;
$this->mContentTypeGuid = TASKS_CONTENT_TYPE_GUID;
// Permission setup
$this->mViewContentPerm = 'p_tasks_view';
$this->mCreateContentPerm = 'p_tasks_create';
$this->mUpdateContentPerm = 'p_tasks_update';
$this->mAdminContentPerm = 'p_tasks_admin';
}
/**
* Load a Task Ticket
*
* (Describe Task object here )
*/
function load($pContentId = NULL) {
if ( $pContentId ) $this->mContentId = (int)$pContentId;
if( $this->verifyId( $this->mContentId ) ) {
$query = "select ti.*, lc.*, rs.`title` AS dept_title, rs.`ter_type` AS dept_mode,
tag.`title` AS status, tag.`reason_source` AS subtag, tag.`tag` AS tag_abv,
MOD( ti.`clearance`, 256 ) AS clearance_code,
CAST( ti.`clearance` / 256 AS INTEGER ) AS survey,
uue.`login` AS modifier_user, uue.`real_name` AS modifier_real_name,
uuc.`login` AS creator_user, uuc.`real_name` AS creator_real_name
FROM `".BIT_DB_PREFIX."task_ticket` ti
INNER JOIN `".BIT_DB_PREFIX."liberty_content` lc ON ( lc.`content_id` = ti.`ticket_id` )
LEFT JOIN `".BIT_DB_PREFIX."users_users` uue ON (uue.`user_id` = lc.`modifier_user_id`)
LEFT JOIN `".BIT_DB_PREFIX."users_users` uuc ON (uuc.`user_id` = lc.`user_id`)
LEFT JOIN `".BIT_DB_PREFIX."task_roomstat` rs ON (rs.`terminal` = ti.`department`)
LEFT JOIN `".BIT_DB_PREFIX."task_reason` tag ON (ti.`room` = tag.`reason`)
WHERE ti.`ticket_id`=?";
$result = $this->mDb->query( $query, array( $this->mContentId ) );
if ( $result && $result->numRows() ) {
$this->mInfo = $result->fields;
$this->mContentId = (int)$result->fields['content_id'];
$this->mPropertyId = (int)$result->fields['caller_id'];
$this->mClientId = (int)$result->fields['caller_id'];
$this->mInfo['display_url'] = $this->getDisplayUrl();
$this->mInfo['title'] = $this->mInfo['dept_title'].' - '.$this->mInfo['ticket_id'];
$this->mInfo['reason'] = $this->mInfo['tag_abv'].' - '.$this->mInfo['reason'];
}
}
LibertyContent::load();
if ( $this->mInfo['department'] != 0 ) {
$this->mInfo['parsed_data'] = $this->parseData();
}
$this->loadTransactionList();
return;
}
/**
* verify, clean up and prepare data to be stored
* @param $pParamHash all information that is being stored. will update $pParamHash by reference with fixed array of itmes
* @return bool TRUE on success, FALSE if store could not occur. If FALSE, $this->mErrors will have reason why
* @access private
**/
function verify( &$pParamHash ) {
// make sure we're all loaded up if everything is valid
if( $this->isValid() && empty( $this->mInfo ) ) {
$this->load( TRUE );
}
// It is possible a derived class set this to something different
if( empty( $pParamHash['content_type_guid'] ) ) {
$pParamHash['content_type_guid'] = $this->mContentTypeGuid;
}
if( !empty( $this->mContentId ) ) {
$pParamHash['content_id'] = $this->mContentId;
} else {
unset( $pParamHash['content_id'] );
}
// content store
// check for name issues, first truncate length if too long
// Secondary store entries
if( $this->isValid() ) {
if ( !empty( $pParamHash['new_client'] ) ) {
$pParamHash['task_store']['caller_id'] = $pParamHash['new_client'];
$pParamHash['task_store']['usn'] = $pParamHash['new_client'];
}
if ( !empty( $pParamHash['new_property'] ) ) {
$pParamHash['task_store']['caller_id'] = $pParamHash['new_property'];
$pParamHash['task_store']['usn'] = $pParamHash['new_property'];
}
if ( !empty( $pParamHash['new_dept'] ) ) {
$pParamHash['task_store']['department'] = $pParamHash['new_dept'];
}
if ( !empty( $pParamHash['new_user'] ) ) {
$pParamHash['task_store']['staff_id'] = $pParamHash['new_user'];
}
if ( !empty( $pParamHash['new_room'] ) ) {
$pParamHash['task_store']['room'] = $pParamHash['new_room'];
// Add transaction table insert here to replace database trigger
}
if ( !empty( $pParamHash['new_tag'] ) ) {
$pParamHash['task_store']['tags'] = $pParamHash['new_tag'];
// Add transaction table insert here to replace database trigger
}
}
return( count( $this->mErrors ) == 0 );
}
/**
* Store task data
* @param $pParamHash contains all data to store the task ticket
* @return bool TRUE on success, FALSE if store could not occur. If FALSE, $this->mErrors will have reason why
**/
function store( &$pParamHash ) {
if( $this->verify( $pParamHash ) ) {
// Start a transaction wrapping the whole insert into liberty
$this->mDb->StartTrans();
if ( LibertyContent::store( $pParamHash ) ) {
$table = BIT_DB_PREFIX."task_ticket";
if( $this->isValid() && !empty( $pParamHash['task_store'] ) ) {
$result = $this->mDb->associateUpdate( $table, $pParamHash['task_store'], array( "ticket_id" => $this->mContentId ) );
} else {
global $gBitUser;
$pParamHash['task_store']['ticket_id'] = $pParamHash['content_id'];
$pParamHash['task_store']['ticket_ref'] = $this->mDb->NOW();
$pParamHash['task_store']['last'] = $this->mDb->NOW();
$pParamHash['task_store']['ticket_no'] = $pParamHash['content_id'];
$pParamHash['task_store']['office'] = 1;
$pParamHash['task_store']['staff_id'] = 0;
$pParamHash['task_store']['init_id'] = $gBitUser->mUserId;
$pParamHash['task_store']['caller_id'] = 0;
$pParamHash['task_store']['department'] = $pParamHash['task_offset'];
$this->mContentId = $pParamHash['content_id'];
$result = $this->mDb->associateInsert( $table, $pParamHash['task_store'] );
}
// load before completing transaction as firebird isolates results
$this->load();
$this->mDb->CompleteTrans();
} else {
$this->mDb->RollbackTrans();
$this->mErrors['store'] = 'Failed to store this task ticket.';
}
}
return( count( $this->mErrors ) == 0 );
}
/**
* Delete content object and all related records
*/
function expunge()
{
$ret = FALSE;
if ($this->isValid() ) {
$this->mDb->StartTrans();
$query = "DELETE FROM `".BIT_DB_PREFIX."citizen` WHERE `content_id` = ?";
$result = $this->mDb->query($query, array($this->mContentId ) );
$query = "DELETE FROM `".BIT_DB_PREFIX."citizen_type_map` WHERE `content_id` = ?";
$result = $this->mDb->query($query, array($this->mContentId ) );
if (LibertyContent::expunge() ) {
$ret = TRUE;
$this->mDb->CompleteTrans();
} else {
$this->mDb->RollbackTrans();
}
}
return $ret;
}
/**
* Returns Request_URI to a Task content object
*
* @param string name of
* @param array different possibilities depending on derived class
* @return string the link to display the page.
*/
public static function getDisplayUrl( $pContentId=NULL ) {
global $gBitSystem;
if( empty( $pContentId ) ) {
$pContentId = $this->mContentId;
}
return TASKS_PKG_URL.'index.php?content_id='.$pContentId;
}
/**
* Returns HTML link to display a Task object
*
* @param string Not used ( generated locally )
* @param array mInfo style array of content information
* @return the link to display the page.
*/
function getDisplayLink( $pText=NULL, $pMixed=NULL, $pAnchor=NULL ) {
if ( $this->mContentId != $pMixed['content_id'] ) $this->load($aux['content_id']);
if (empty($this->mInfo['content_id']) ) {
$ret = '<a href="'.$this->getDisplayUrl($pMixed['content_id']).'">'.$pMixed['title'].'</a>';
} else {
$ret = '<a href="'.$this->getDisplayUrl($pMixed['content_id']).'">'."Citizen - ".$this->mInfo['title'].'</a>';
}
return $ret;
}
/**
* Returns title of an Task object
* @todo Need to expand this to handle type of task and date information
*
* @param array mInfo style array of content information
* @return string Text for the title description
*/
function getTitle( $pHash = NULL, $pDefault=TRUE ) {
$ret = NULL;
if( empty( $pHash ) ) {
$pHash = &$this->mInfo;
} else {
if ( $this->mContentId != $pHash['content_id'] ) {
$this->load($pHash['content_id']);
$pHash = &$this->mInfo;
}
}
if( !empty( $pHash['title'] ) ) {
$ret = "Ticket - ".$this->mInfo['title'];
} elseif( !empty( $pHash['content_name'] ) ) {
$ret = $pHash['content_name'];
}
return $ret;
}
/**
* Returns title of a queue
* @todo Need to cache department/queue information in object
*
* @param integer Queue Number
* @return string Text for the title description
*/
function getQueueTitle( $queue ) {
$query = "SELECT rs.`title` AS queue FROM `".BIT_DB_PREFIX."task_roomstat` rs WHERE rs.`terminal` = 80 + $queue";
return $this->mDb->getOne( $query );
}
/**
* Gets the next ticket number from a queue
*
* @param integer Queue Number
* @return bool True if switched to a valid task
*/
function getNextTask( $queue ) {
$query = "SELECT cd.`ticket_id` FROM `".BIT_DB_PREFIX."task_ticket` cd
WHERE cd.`ticket_ref` BETWEEN 'TODAY' AND 'TOMORROW' AND cd.`room` = $queue + 80
AND cd.`office` = 1
ORDER BY cd.`ticket_ref`";
$next = $this->mDb->getOne( $query );
// Add switch of user state to serving!
if ( $next ) return true;
else return false;
}
/**
* Returns title of a queue
* @todo Need to cache department/queue information in object
*
* @param integer Queue Number
* @return string Text for the title description
*/
function createTask( $queue ) {
$query = "SELECT cd.`ticket_id` FROM `".BIT_DB_PREFIX."task_ticket` cd
WHERE ti.`ticket_ref` BETWEEN TODAY AND TOMORROW AND cd.`room` = $queue + 80
AND cd.`office` = 1
ORDER BY cd.`ticket_ref`";
$next = $this->mDb->getOne( $query );
// Add switch of user state to serving!
if ( $next ) return true;
else return false;
}
/**
* Returns list of tesk entries
*
* @param integer
* @return array Enquiry tickets
*/
function getList( &$pListHash ) {
LibertyContent::prepGetList( $pListHash );
$whereSql = $joinSql = $selectSql = '';
$bindVars = array();
// Update to more flexible date management later
// array_push( $bindVars, 'TODAY' );
// array_push( $bindVars, 'TOMORROW' );
// $this->getServicesSql( 'content_list_sql_function', $selectSql, $joinSql, $whereSql, $bindVars );
if ( isset($pListHash['queue_id']) ) {
$whereSql .= " AND ti.`room` = 80 + ? ";
array_push( $bindVars, $pListHash['queue_id'] );
}
// init_id and staff_id will map to creator_user_id and modifier_user_id when fully converted to LC
// , lc.* INNER JOIN `".BIT_DB_PREFIX."liberty_content` lc ON ( lc.`content_id` = ci.`content_id` )
$query = "SELECT ti.*, lp.*, tr.`title` as reason,
uue.`login` AS modifier_user, uue.`real_name` AS modifier_real_name,
uuc.`login` AS creator_user, uuc.`real_name` AS creator_real_name $selectSql
FROM `".BIT_DB_PREFIX."task_ticket` ti
INNER JOIN `".BIT_DB_PREFIX."liberty_content` lc ON ( lc.`content_id` = ti.`ticket_id` )
LEFT JOIN `".BIT_DB_PREFIX."property` pro ON (pro.`property_id` = ti.`caller_id`)
INNER JOIN `".BIT_DB_PREFIX."liberty_content` lp ON ( lp.`content_id` = pro.`content_id` )
LEFT JOIN `".BIT_DB_PREFIX."users_users` uue ON (uue.`user_id` = ti.`staff_id`)
LEFT JOIN `".BIT_DB_PREFIX."users_users` uuc ON (uuc.`user_id` = ti.`init_id`)
LEFT JOIN `".BIT_DB_PREFIX."contact` ci ON (ci.`contact_id` = ti.`caller_id`)
LEFT JOIN `".BIT_DB_PREFIX."task_reason` tr ON (tr.`reason` = ti.`room`)
$joinSql
WHERE ti.`room` >= 0 $whereSql
order by ti.`ticket_ref`";
$query_cant = "SELECT COUNT(ti.`ticket_no`) FROM `".BIT_DB_PREFIX."task_ticket` ti
$joinSql
WHERE ti.`room` >= 0 $whereSql";
$ret = array();
$this->mDb->StartTrans();
$result = $this->mDb->query( $query, $bindVars, $pListHash['max_records'], $pListHash['offset'] );
$cant = $this->mDb->getOne( $query_cant, $bindVars );
$this->mDb->CompleteTrans();
while ($res = $result->fetchRow()) {
$res['ticket_url'] = $this->getDisplayUrl( $res['ticket_id'] );
$ret[] = $res;
}
$pListHash['cant'] = $cant;
LibertyContent::postGetList( $pListHash );
return $ret;
}
/**
* Returns list of queues
*
* @param integer
* @return array Queue records
*/
function listQueues() {
$query = "SELECT rs.`terminal` - 81, (rs.`terminal` - 80) AS que_no, rs.`title`, rs.`ter_type` AS dep_type
FROM `".BIT_DB_PREFIX."task_roomstat` rs
WHERE rs.`ter_type` > 6 AND rs.`terminal` > 80
ORDER BY rs.`terminal`";
$result = array();
$result['depts'] = $this->mDb->GetAssoc( $query );
if ( isset($this->mInfo['department']) && $this->mInfo['department'] > 0 ) {
$result['tags'] = $this->mDb->GetAssoc("SELECT `reason`, `reason` AS tag_no, `title`, `tag` FROM `".BIT_DB_PREFIX."task_reason` WHERE `reason_type` = ".$this->mInfo['department']." ORDER BY `reason`");
if ( $this->mInfo['subtag'] > 0 ) {
$result['subtags'] = $this->mDb->GetAssoc("SELECT `reason`, `reason` AS tag_no, `title`, `tag` FROM `".BIT_DB_PREFIX."task_reason` WHERE `reason_type` = ".$this->mInfo['subtag']." ORDER BY `reason`");
}
}
return $result;
}
/**
* Returns list of queue activity
*
* @param integer
* @return array Queue activity records
*/
function getQueueList( &$pListHash = NULL ) {
$query = "SELECT rs.`office`, rs.`terminal`, rs.`title`, rs.`ter_type`, rs.`x1` AS no_warn, rs.`x2` AS no_alarm, rs.`x3` AS aw_warn, rs.`x4` AS aw_alarm,
COUNT(tic.`ticket_ref`) AS `no_waiting`,
AVG(((CURRENT_TIMESTAMP - tic.`last`) * 86400)) AS `avg_wait`
FROM `".BIT_DB_PREFIX."task_roomstat` rs
LEFT JOIN `".BIT_DB_PREFIX."task_ticket` tic ON tic.`office` = rs.`office` AND tic.`room` = rs.`terminal` AND tic.`ticket_ref` BETWEEN CURRENT_DATE AND CURRENT_DATE + 1
WHERE rs.`ter_type` > 6 AND rs.`terminal` > 80
GROUP BY rs.`office`, rs.`terminal`, rs.`title`, rs.`ter_type`, rs.`x1`, rs.`x2`, rs.`x3`, rs.`x4`
ORDER BY rs.`terminal`";
$result = $this->mDb->query( $query );
while ($res = $result->fetchRow()) {
$res['queue_id'] = $res['terminal'] - 80;
$res['display_url'] = TASKS_PKG_URL.'view_queue.php?queue_id='.$res['queue_id'];
$ret[] = $res;
}
return $ret;
}
/**
* Returns list of patrol activity
*
* @param integer
* @return array patrol activity records
*/
function getPatrolList( &$pListHash = NULL ) {
$query = "SELECT tic.*, r.title AS patrol, lc.*
FROM `".BIT_DB_PREFIX."task_ticket` tic
LEFT JOIN `".BIT_DB_PREFIX."task_reason` r ON r.`reason` = tic.`room`
LEFT JOIN `".BIT_DB_PREFIX."liberty_content` lc ON lc.`content_id` = tic.`caller_id`
WHERE tic.`room` = 1 AND tic.`ticket_ref` BETWEEN CURRENT_DATE AND CURRENT_DATE + 1
ORDER BY tic.`ticket_ref`";
$result = $this->mDb->query( $query );
while ($res = $result->fetchRow()) {
$res['display_url'] = CONTACT_PKG_URL.'view.php?content_id='.$res['caller_id'];
$ret[] = $res;
}
vd($ret);
return $ret;
}
/**
* TicketRecordLoad( $data );
* Ticket file import
*/
function TicketRecordLoad( &$data ) {
$table = BIT_DB_PREFIX."task_ticket";
$pDataHash['ticket_store']['office'] = $data[0];
$pDataHash['ticket_store']['ticket_id'] = $data[1];
$pDataHash['ticket_store']['ticket_ref'] = $data[2];
$pDataHash['ticket_store']['ticket_no'] = $data[3];
$pDataHash['ticket_store']['tags'] = $data[4];
$pDataHash['ticket_store']['clearance'] = $data[5];
$pDataHash['ticket_store']['room'] = $data[6];
if ( $data[7] == '[null]' )
$pDataHash['ticket_store']['note'] = '';
else
$pDataHash['ticket_store']['note'] = $data[7];
if ( $data[8] == '[null]' )
$pDataHash['ticket_store']['last'] = '';
else
$pDataHash['ticket_store']['last'] = $data[8];
$pDataHash['ticket_store']['staff_id'] = $data[9];
$pDataHash['ticket_store']['init_id'] = $data[10];
$pDataHash['ticket_store']['caller_id'] = $data[11];
$pDataHash['ticket_store']['appoint_id'] = $data[12];
$pDataHash['ticket_store']['applet'] = $data[13];
if ( $data[14] != '[null]' ) $pDataHash['ticket_store']['memo'] = $data[14];
if ( $data[15] == '[null]' )
$pDataHash['ticket_store']['department'] = 0;
else
$pDataHash['ticket_store']['department'] = $data[15];
// Create LC entry details from legacy data
global $gBitSystem;
$this->mDb->StartTrans();
$this->mContentId = 0;
$pDataHash['content_id'] = 0;
$pDataHash['user_id'] = $pDataHash['ticket_store']['init_id'];
$pDataHash['modifier_user_id'] = $pDataHash['ticket_store']['staff_id'];
$pDataHash['created'] = $gBitSystem->mServerTimestamp->getTimestampFromISO($pDataHash['ticket_store']['ticket_ref'], true);
$pDataHash['event_time'] = $pDataHash['created'];
$pDataHash['last_modified'] = $gBitSystem->mServerTimestamp->getTimestampFromISO($pDataHash['ticket_store']['last'], true);
$pDataHash['title'] = $pDataHash['ticket_store']['ticket_ref'].'-Ticket-'.$pDataHash['ticket_store']['ticket_no'];
$pDataHash['content_status_id'] = 60; // Mark all records Finished - data can't be modified, so read only!
if ( LibertyContent::store( $pDataHash ) ) {
$pDataHash['ticket_store']['content_id'] = $pDataHash['content_id'];
$result = $this->mDb->associateInsert( $table, $pDataHash['ticket_store'] );
$this->mDb->CompleteTrans();
} else {
$this->mDb->RollbackTrans();
$this->mErrors['store'] = 'Failed to store this ticket.';
}
}
/**
* TransactionRecordLoad( $data );
* Transaction file import
*/
function TransactionRecordLoad( &$data ) {
$table = BIT_DB_PREFIX."task_transaction";
$pDataHash['data_store']['ticket_id'] = $data[0];
$pDataHash['data_store']['transact_no'] = $data[1];
$pDataHash['data_store']['transact'] = $data[2];
$pDataHash['data_store']['ticket_ref'] = $data[3];
$pDataHash['data_store']['staff_id'] = $data[4];
$pDataHash['data_store']['previous'] = $data[5];
$pDataHash['data_store']['room'] = $data[6];
$pDataHash['data_store']['applet'] = $data[7];
$pDataHash['data_store']['office'] = $data[8];
$pDataHash['data_store']['ticket_no'] = $data[9];
if ( $data[10] == '[null]' )
$pDataHash['data_store']['proom'] = 0;
else
$pDataHash['data_store']['proom'] = $data[10];
if ( $data[11] == '[null]' )
$pDataHash['data_store']['tags'] = 0;
else
$pDataHash['data_store']['tags'] = $data[11];
if ( $data[12] == '[null]' )
$pDataHash['data_store']['clearance'] = 0;
else
$pDataHash['data_store']['clearance'] = $data[12];
$result = $this->mDb->associateInsert( $table, $pDataHash['data_store'] );
}
/**
* ReasonRecordLoad( $data );
* Reason file import
*/
function ReasonRecordLoad( &$data ) {
$table = BIT_DB_PREFIX."task_reason";
$pDataHash['data_store']['reason'] = $data[0];
$pDataHash['data_store']['title'] = $data[1];
$pDataHash['data_store']['reason_type'] = $data[2];
$pDataHash['data_store']['reason_source'] = $data[3];
if ( $data[4] == '[null]' )
$pDataHash['data_store']['tag'] = '';
else
$pDataHash['data_store']['tag'] = $data[4];
$result = $this->mDb->associateInsert( $table, $pDataHash['data_store'] );
}
/**
* RoomstatRecordLoad( $data );
* Roomstat file import
*/
function RoomstatRecordLoad( &$data ) {
$table = BIT_DB_PREFIX."task_roomstat";
$pDataHash['data_store']['office'] = $data[0];
$pDataHash['data_store']['terminal'] = $data[1];
$pDataHash['data_store']['title'] = $data[2];
if ( $data[3] == '[null]' )
$pDataHash['data_store']['head'] = '';
else
$pDataHash['data_store']['head'] = $data[3];
if ( $data[4] == '[null]' )
$pDataHash['data_store']['announce'] = '';
else
$pDataHash['data_store']['announce'] = $data[4];
$pDataHash['data_store']['ter_type'] = $data[5];
$pDataHash['data_store']['led'] = $data[6];
if ( $data[7] != '[null]' ) $pDataHash['data_store']['ledhead'] = $data[7];
if ( $data[8] != '[null]' ) $pDataHash['data_store']['beacon'] = $data[8];
if ( $data[9] != '[null]' ) $pDataHash['data_store']['camera'] = $data[9];
if ( $data[10] != '[null]' ) $pDataHash['data_store']['serving'] = $data[10];
if ( $data[11] != '[null]' ) $pDataHash['data_store']['act1'] = $data[11];
if ( $data[12] != '[null]' ) $pDataHash['data_store']['fro_'] = $data[12];
if ( $data[13] != '[null]' ) $pDataHash['data_store']['alarm'] = $data[13];
if ( $data[14] != '[null]' ) $pDataHash['data_store']['curmode'] = $data[14];
if ( $data[15] != '[null]' ) $pDataHash['data_store']['x1'] = $data[15];
if ( $data[16] != '[null]' ) $pDataHash['data_store']['x2'] = $data[16];
if ( $data[17] != '[null]' ) $pDataHash['data_store']['x3'] = $data[17];
if ( $data[18] != '[null]' ) $pDataHash['data_store']['x4'] = $data[18];
if ( $data[19] != '[null]' ) $pDataHash['data_store']['x5'] = $data[19];
if ( $data[20] != '[null]' ) $pDataHash['data_store']['x6'] = $data[20];
if ( $data[21] != '[null]' ) $pDataHash['data_store']['x7'] = $data[21];
if ( $data[22] != '[null]' ) $pDataHash['data_store']['x8'] = $data[22];
if ( $data[23] != '[null]' ) $pDataHash['data_store']['x9'] = $data[23];
if ( $data[24] != '[null]' ) $pDataHash['data_store']['x10'] = $data[24];
if ( $data[25] != '[null]' ) $pDataHash['data_store']['status'] = $data[25];
if ( $data[26] != '[null]' ) $pDataHash['data_store']['logon'] = $data[26];
if ( $data[27] != '[null]' ) $pDataHash['data_store']['ter_location'] = $data[27];
if ( $data[28] != '[null]' ) $pDataHash['data_store']['ticketprint'] = $data[28];
if ( $data[29] != '[null]' ) $pDataHash['data_store']['reportprint'] = $data[29];
if ( $data[30] != '[null]' ) $pDataHash['data_store']['booking'] = $data[30];
if ( $data[31] != '[null]' ) $pDataHash['data_store']['book'] = $data[31];
$result = $this->mDb->associateInsert( $table, $pDataHash['data_store'] );
}
/**
* ReasonRecordLoad( $data );
* Reason file import
*/
function CallerRecordLoad( &$data ) {
$table = BIT_DB_PREFIX."task_caller";
$pDataHash['data_store']['caller_id'] = $data[0];
if ( $data[1] == '[null]' )
$pDataHash['data_store']['cltype'] = 0;
else
$pDataHash['data_store']['cltype'] = $data[1];
$pDataHash['data_store']['title'] = $data[2];
$pDataHash['data_store']['surname'] = $data[3];
$pDataHash['data_store']['forename'] = $data[4];
$pDataHash['data_store']['company'] = $data[5];
if ( $data[6] == '[null]' )
$pDataHash['data_store']['ni'] = '';
else
$pDataHash['data_store']['ni'] = $data[6];
if ( $data[7] == '[null]' )
$pDataHash['data_store']['hbis'] = '';
else
$pDataHash['data_store']['hbis'] = $data[7];
$pDataHash['data_store']['address'] = $data[8];
$pDataHash['data_store']['postcode'] = $data[9];
if ( $data[10] != '[null]' ) $pDataHash['data_store']['lastvisit'] = $data[10];
if ( $data[11] == '[null]' )
$pDataHash['data_store']['specialneeds'] = '';
else
$pDataHash['data_store']['specialneeds'] = $data[11];
if ( $data[12] == '[null]' )
$pDataHash['data_store']['staff_id'] = 0;
else
$pDataHash['data_store']['staff_id'] = $data[12];
if ( $data[13] == '[null]' )
$pDataHash['data_store']['note'] = '';
else
$pDataHash['data_store']['note'] = $data[13];
if ( $data[14] != '[null]' ) $pDataHash['data_store']['memo'] = $data[14];
if ( $data[15] != '[null]' ) $pDataHash['data_store']['cllink'] = $data[15];
if ( $data[16] == '[null]' )
$pDataHash['data_store']['usn'] = 0;
else
$pDataHash['data_store']['usn'] = $data[16];
$result = $this->mDb->associateInsert( $table, $pDataHash['data_store'] );
}
/**
* StaffRecordLoad( $data );
* Staff file import
*/
function StaffRecordLoad( &$data ) {
$table = BIT_DB_PREFIX."task_staff";
$pDataHash['data_store']['user_id'] = $data[0];
$pDataHash['login_store']['user_id'] = $data[0];
$pDataHash['data_store']['surname'] = $data[1];
$pDataHash['data_store']['forename'] = $data[2];
$pDataHash['data_store']['initials'] = $data[3];
$pDataHash['login_store']['login'] = strtolower( $data[1].substr( $data[2], 0, 1 ) );
$pDataHash['login_store']['real_name'] = ucfirst( $data[2] ).' '.ucfirst( $data[1] );
$pDataHash['login_store']['password'] = $pDataHash['login_store']['login'];
// Need to link this to system settings but manual will work for now
$pDataHash['login_store']['email'] = ucfirst( $data[2] ).'.'.ucfirst( $data[1] ).'@rother.gov.uk';
if ( $data[4] == '[null]' )
$pDataHash['data_store']['direct'] = '';
else
$pDataHash['data_store']['direct'] = $data[4];
$pDataHash['data_store']['team'] = $data[5];
if ( $data[6] == '[null]' )
$pDataHash['data_store']['ext'] = '';
else
$pDataHash['data_store']['ext'] = $data[6];
$pDataHash['data_store']['category'] = $data[7];
$pDataHash['data_store']['logon'] = $data[8];
if ( $data[9] == '[null]' )
$pDataHash['data_store']['note'] = '';
else
$pDataHash['data_store']['note'] = $data[9];
$pDataHash['data_store']['logged'] = 0;
$pDataHash['data_store']['content_id'] = 0;
$pDataHash['data_store']['office'] = $data[14];
// Need to map category to role/group setting
$newUser = new BitPermUser();
$result = $newUser->ImportUser( $pDataHash['login_store'] );
$newUser->storePreference('phone_no', $data[4] );
$newUser->storePreference('team', $data[5] );
// This should be populated by the system from site defaults
$newUser->storePreference('site_display_timezone', 'Europe/London' );
$newUser->storePreference('site_display_utc', 'Fixed' );
$newUser->storePreference('users_country', 'United_Kingdom' );
// $result = $this->mDb->associateInsert( $table, $pDataHash['data_store'] );
}
/**
* Delete golden object and all related records
*/
function HistoryExpunge()
{
$ret = FALSE;
$query = "DELETE FROM `".BIT_DB_PREFIX."task_ticket`";
$result = $this->mDb->query( $query );
$query = "DELETE FROM `".BIT_DB_PREFIX."task_transaction`";
$result = $this->mDb->query( $query );
$query = "DELETE FROM `".BIT_DB_PREFIX."task_reason`";
$result = $this->mDb->query( $query );
$query = "DELETE FROM `".BIT_DB_PREFIX."task_roomstat`";
$result = $this->mDb->query( $query );
$query = "DELETE FROM `".BIT_DB_PREFIX."task_caller`";
$result = $this->mDb->query( $query );
$query = "DELETE FROM `".BIT_DB_PREFIX."task_staff`";
$result = $this->mDb->query( $query );
return $ret;
}
/**
* loadTransactionList( &$pParamHash );
* Get list of transaction records relating to the active ticket
*/
function loadTransactionList() {
if( $this->isValid() ) {
$sql = "SELECT tran.*, tag.`title` AS status, sn.`real_name` AS staff_name
FROM `".BIT_DB_PREFIX."task_transaction` tran
LEFT JOIN `".BIT_DB_PREFIX."task_reason` tag ON (tran.`room` = tag.`reason`)
LEFT JOIN `".BIT_DB_PREFIX."users_users` sn ON (sn.`user_id` = tran.`staff_id`)
WHERE tran.ticket_id = ?
ORDER BY tran.`transact_no`";
$result = $this->mDb->query( $sql, array( $this->mContentId ) );
while( $res = $result->fetchRow() ) {
$this->mInfo['trans'][$res['transact_no']] = $res;
}
}
}
}
?>