File: Artifact.class

package info (click to toggle)
gforge 3.1-31sarge5
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 9,148 kB
  • ctags: 11,865
  • sloc: sql: 27,860; php: 25,574; perl: 7,124; xml: 3,152; sh: 2,586; ansic: 315; makefile: 143
file content (1065 lines) | stat: -rw-r--r-- 28,114 bytes parent folder | download
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
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
<?php
/**
 * Artifact.class - Main Artifact class
 *
 * Copyright 1999-2001 (c) VA Linux Systems
 *
 * @version   $Id: Artifact.class,v 1.12 2003/08/22 18:56:03 bigdisk Exp $
 *
 * This file is part of GForge.
 *
 * GForge is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * GForge is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with GForge; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  US
 */
require_once('common/include/Error.class');

	/**
	* Factory method which creates an Artifact from an artifact ID
	*	
	* @param artifact_id	the artifact ID
	*	@param data	the DB handle, if it's passed in
	*	@return an Artifact object
	*/
	function &artifact_get_object($artifact_id,$data=false) {
		global $ARTIFACT_OBJ;
		if (!isset($ARTIFACT_OBJ["_".$artifact_id."_"])) {
			if ($data) {
				//the db result handle was passed in
			} else {
				$res=db_query("SELECT * FROM artifact_vw WHERE artifact_id='$artifact_id'");
				if (db_numrows($res) <1 ) {
					$ARTIFACT_OBJ["_".$artifact_id."_"]=false;
					return false;
				}
				$data =& db_fetch_array($res);
			}
			$Group =& group_get_object($data["group_id"]);
			$ArtifactType =& artifactType_get_object($data["group_artifact_id"]);
			$ARTIFACT_OBJ["_".$artifact_id."_"]= new Artifact($ArtifactType,$data);
		}
		return $ARTIFACT_OBJ["_".$artifact_id."_"];
	}	

class Artifact extends Error {

	/**
	 * Resource ID.
	 *
	 * @var		int		$status_res.
	 */
	var $status_res;

	/**
	 * Artifact Type object.
	 *
	 * @var		object	$ArtifactType.
	 */
	var $ArtifactType; 

	/**
	 * Array of artifact data.
	 *
	 * @var		array	$data_array.
	 */
	var $data_array;

	/**
	 * Array of ArtifactFile objects.
	 *
	 * @var		array	$files
	 */
	var $files; 

	/**
	 *  Artifact - constructor.
	 *
	 *	@param	object	The ArtifactType object.
	 *  @param	integer	(primary key from database OR complete assoc array) 
	 *		ONLY OPTIONAL WHEN YOU PLAN TO IMMEDIATELY CALL ->create()
	 *  @return	boolean	success.
	 */
	function Artifact(&$ArtifactType, $data=false) {
		global $Language;
		$this->Error(); 

		$this->ArtifactType =& $ArtifactType;

		//was ArtifactType legit?
		if (!$ArtifactType || !is_object($ArtifactType)) {
			$this->setError('Artifact: No Valid ArtifactType');
			return false;
		}

		//did ArtifactType have an error?
		if ($ArtifactType->isError()) {
			$this->setError('Artifact: '.$ArtifactType->getErrorMessage());
			return false;
		}

		//
		//	make sure this person has permission to view artifacts
		//
		if (!$this->ArtifactType->userCanView()) {
			$this->setError($Language->getText('tracker_artifact','private_error'));
			return false;
		}

		//
		//	set up data structures
		//
		if ($data) {
			if (is_array($data)) {
				$this->data_array =& $data;
//
//	Should verify ArtifactType ID
//
				return true;
			} else {
				if (!$this->fetchData($data)) {
					return false;
				} else {
					return true;
				}
			}
		}
	}


	/**
	 *	create - construct a new Artifact in the database.
	 *
	 *	@param	int		The category ID.
	 *	@param	int		The artifact group ID.
	 *	@param	string	The artifact summary.
	 *	@param	string	Details of the artifact.
	 *	@param	int		The ID of the user to which this artifact is to be assigned.
	 *	@param	int		The artifacts priority.
	 *	@param	string	An email address to add to the monitoring queue.
	 *  @return id on success / false on failure.
	 */
	function create($category_id, $artifact_group_id, $summary, $details, $assigned_to=100, $priority=5, $monitor_email=false) {
		global $Language;
		
		//
		//	make sure this person has permission to add artifacts
		//
		if (!$this->ArtifactType->isPublic()) {
			//
			//	Only admins can post/modify private artifacts
			//
			if (!$this->ArtifactType->userIsAdmin()) {
				$this->setError($Language->getText('tracker_artifact','error_admin_modify'));
				return false;
			}
		}

		//
		//	get the user_id
		//
		if (session_loggedin()) {
			$user=user_getid();
		} else {
			if ($this->ArtifactType->allowsAnon()) {
				$user=100;
			} else {
				$this->setError($Language->getText('tracker_artifact','error_no_anonymous'));
				return false;
			}
		}

		//
		//	data validation
		//
		if (!$summary) {
			$this->setError($Language->getText('tracker_artifact','error_summary_required'));
			return false;
		}
		if (!$details) {
			$this->setError($Language->getText('tracker_artifact','error_body_required'));
			return false;
		}
		if (!$assigned_to) {
			if ($category_id == 100) {
				$assigned_to=100;
			} else {
				//create an ArtifactCategory to determine who to auto-assign to
				$ac=new ArtifactCategory($this->ArtifactType,$category_id);
				if (!$ac || !is_object($ac) || $ac->isError()) {
					$assigned_to=100;
				} else {
					$assigned_to=$ac->getAssignee();
				}
			}
		}
		if ($assigned_to==100 && $category_id != 100) {
			//create an ArtifactCategory to determine who to auto-assign to
			$ac=new ArtifactCategory($this->ArtifactType,$category_id);
			if (!$ac || !is_object($ac) || $ac->isError()) {
				$assigned_to=100;
			} else {
				$assigned_to=$ac->getAssignee();
			}
		}
		if (!$priority) {
			$priority=5;
		}
		if (!$category_id) {
			$category_id=100;
		}
		if (!$artifact_group_id) {
			$artifact_group_id=100;
		}
		if (!$resolution_id) {
			$resolution_id=100;
		}

		db_begin();

		//
		//	Check to see if this user is trying to double-submit
		//
		$res=db_query("SELECT * FROM artifact 
			WHERE summary='$summary' 
			AND submitted_by='$user'
			AND group_artifact_id='".$this->ArtifactType->getID()."'
			AND open_date > '". (time() - 86400) ."'");
		if ($res && db_numrows($res) > 0) {
			$this->setError($Language->getText('tracker_artifact','double_submit'));
			db_rollback();
			return false;
		}

		$res=db_query("INSERT INTO artifact 
			(group_artifact_id,status_id,category_id,artifact_group_id,priority,
			submitted_by,assigned_to,open_date,summary,details,resolution_id) 
			VALUES 
			('".$this->ArtifactType->getID()."','1','$category_id','$artifact_group_id',
			'$priority','$user','$assigned_to','". time() ."','". 
			htmlspecialchars($summary)."','". htmlspecialchars($details)."','$resolution_id')");

		$artifact_id=db_insertid($res,'artifact','artifact_id');

		if (!$res || !$artifact_id) {
			$this->setError('Artifact: '.db_error());
			db_rollback();
			return false;
		} else {
			//
			//	Now set up our internal data structures
			//
			if (!$this->fetchData($artifact_id)) {
				db_rollback();
				return false;
			}

			//
			//	now send an email if appropriate
			//
			$this->mailFollowup(1);
			db_commit();

			return $artifact_id;
		}
	}

	/**
	 *	fetchData - re-fetch the data for this Artifact from the database.
	 *
	 *	@param	int		The artifact ID.
	 *	@return	boolean	success.
	 */
	function fetchData($artifact_id) {
		$res=db_query("SELECT * FROM artifact_vw 
			WHERE artifact_id='$artifact_id' AND group_artifact_id='".$this->ArtifactType->getID()."'");
		if (!$res || db_numrows($res) < 1) {
			$this->setError('Artifact: Invalid ArtifactID');
			return false;
		}
		$this->data_array =& db_fetch_array($res);
		db_free_result($res);
		return true;
	}

	/**
	 *	getArtifactType - get the ArtifactType Object this Artifact is associated with.
	 *
	 *	@return object	ArtifactType.
	 */
	function &getArtifactType() {
		return $this->ArtifactType;
	}
	
	/**
	 *	getID - get this ArtifactID.
	 *
	 *	@return	int	The artifact_id #.
	 */
	function getID() {
		return $this->data_array['artifact_id'];
	}

	/**
	 *	getStatusID - get open/closed/deleted flag.
	 *
	 *	@return	int	Status: (1) Open, (2) Closed, (3) Deleted.
	 */
	function getStatusID() {
		return $this->data_array['status_id'];
	}

	/**
	 *	getStatusName - get open/closed/deleted text.
	 *
	 *	@return	string	The status name.
	 */
	function getStatusName() {
		return $this->data_array['status_name'];
	}

	/**
	 *	getResolutionID - get resolution flag.
	 *
	 *	@return int	resolution.
	 */
	function getResolutionID() {
		return $this->data_array['resolution_id'];
	}

	/**
	 *	getResolutionName - get resolution name.
	 *
	 *	@return	string	The resolution name.
	 */
	function getResolutionName() {
		return $this->data_array['resolution_name'];
	}

	/**
	 *	getCategoryID - get category_id flag.
	 *
	 *	@return int category_id.
	 */
	function getCategoryID() {
		return $this->data_array['category_id'];
	}

	/**
	 *	getCategoryName - get category text name.
	 *
	 *	@return	string	The category name.
	 */
	function getCategoryName() {
		return $this->data_array['category_name'];
	}

	/**
	 *	getArtifactGroupID - get artifact_group_id flag.
	 *
	 *	@return int artifact_group_id
	 */
	function getArtifactGroupID() {
		return $this->data_array['artifact_group_id'];
	}

	/**
	 *	getArtifactGroupName - get artifact_group_name text.
	 *
	 *	@return	string	The artifact_group name.
	 */
	function getArtifactGroupName() {
		return $this->data_array['group_name'];
	}

	/**
	 *	getPriority - get priority flag.
	 *
	 *	@return int priority.
	 */
	function getPriority() {
		return $this->data_array['priority'];
	}

	/**
	 *	getSubmittedBy - get ID of submitter.
	 *
	 *	@return int user_id of submitter.
	 */
	function getSubmittedBy() {
		return $this->data_array['submitted_by'];
	}

	/**
	 *	getSubmittedEmail - get email of submitter.
	 *
	 *	@return	string	The email of submitter.
	 */
	function getSubmittedEmail() {
		return $this->data_array['submitted_email'];
	}

	/**
	 *	getSubmittedRealName - get real name of submitter.
	 *
	 *	@return	string	The real name of submitter.
	 */
	function getSubmittedRealName() {
		return $this->data_array['submitted_realname'];
	}

	/**
	 *	getSubmittedUnixName - get login name of submitter.
	 *
	 *	@return	string	The unix name of submitter.
	 */
	function getSubmittedUnixName() {
		return $this->data_array['submitted_unixname'];
	}

	/**
	 *	getAssignedTo - get ID of assignee.
	 *
	 *	@return int user_id of assignee.
	 */
	function getAssignedTo() {
		return $this->data_array['assigned_to'];
	}

	/**
	 *	getAssignedEmail - get email of assignee.
	 *
	 *	@return	string	The email of assignee.
	 */
	function getAssignedEmail() {
		return $this->data_array['assigned_email'];
	}

	/**
	 *	getAssignedRealName - get real name of assignee.
	 *
	 *	@return	string	The real name of assignee.
	 */
	function getAssignedRealName() {
		return $this->data_array['assigned_realname'];
	}

	/**
	 *	getAssignedUnixName - get login name of assignee.
	 *
	 *	@return	string	The unix name of assignee.
	 */
	function getAssignedUnixName() {
		return $this->data_array['assigned_unixname'];
	}

	/**
	 *	getOpenDate - get unix time of creation.
	 *
	 *	@return int unix time.
	 */
	function getOpenDate() {
		return $this->data_array['open_date'];
	}

	/**
	 *	getCloseDate - get unix time of closure.
	 *
	 *	@return int unix time.
	 */
	function getCloseDate() {
		return $this->data_array['close_date'];
	}

	/**
	 *	getSummary - get text summary of artifact.
	 *
	 *	@return	string The summary (subject).
	 */
	function getSummary() {
		return $this->data_array['summary'];
	}

	/**
	 *	getDetails - get text body (message) of artifact.
	 *
	 *	@return	string	The body (message).
	 */
	function getDetails() {
		return $this->data_array['details'];
	}

	/**
	 *  setMonitor - user can monitor this artifact.
	 *
	 *  @return false - always false - always use the getErrorMessage() for feedback
	 */
	function setMonitor() {
		global $Language;
		if (session_loggedin()) {

			$user_id=user_getid();
			$user =& user_get_object(user_getid());
			$email=' ';

			//we don't want to include the "And email=" because
			//a logged-in user's email may have changed
			$email_sql='';

		} else {

			$this->setError($Language->getText('tracker_artifact','error_valid_email_required'));
			return false;

		}

		$res=db_query("SELECT * FROM artifact_monitor 
			WHERE artifact_id='". $this->getID() ."' 
			AND user_id='$user_id'");

		if (!$res || db_numrows($res) < 1) {
			//not yet monitoring
			$res=db_query("INSERT INTO artifact_monitor (artifact_id,user_id) 
				VALUES ('". $this->getID() ."','$user_id')");
			if (!$res) {
				$this->setError(db_error());
				return false;
			} else {
				$this->setError($Language->getText('tracker_artifact','monitoring_activated'));
				return false;
			}
		} else {
			//already monitoring - remove their monitor
			db_query("DELETE FROM artifact_monitor 
				WHERE artifact_id='". $this->getID() ."' 
				AND user_id='$user_id'");
			$this->setError($Language->getText('tracker_artifact','monitoring_deactivated'));
			return false;
		}
	}

	function isMonitoring() {
		if (!session_loggedin()) {
			return false;
		}
		$sql="SELECT * FROM artifact_monitor WHERE user_id='".user_getid()."' AND artifact_id='".$this->getID()."';";
		$result = db_query($sql);
		if (!$result || db_numrows($result) < 1) {
			return false;
		} else {
			return true;
		}
	}


	/**
	 *  getMonitorIds - array of email addresses monitoring this Artifact.
	 *
	 *  @return array of email addresses monitoring this Artifact.
	 */
	function &getMonitorIds() {
		$res=db_query("SELECT user_id
			FROM artifact_monitor 
			WHERE artifact_id='". $this->getID() ."'");
		return util_result_column_to_array($res);
	}

	/**
	 *	getHistory - returns a result set of audit trail for this support request.
	 *
	 *	@return database result set.
	 */
	function getHistory() {
		$sql="SELECT * ".
		"FROM artifact_history_user_vw ".
		"WHERE artifact_id='". $this->getID() ."' ".
		"ORDER BY entrydate DESC";
		return db_query($sql);
	}

	/**
	 *	getMessages - get the list of messages attached to this artifact.
	 *
	 *	@return database result set.
	 */
	function getMessages() {
		$sql="select * ".
			"FROM artifact_message_user_vw ".
			"WHERE artifact_id='". $this->getID() ."' ORDER BY adddate DESC";
		return db_query($sql);
	}

	/**
	 *	getFiles - get array of ArtifactFile's.
	 *
	 *	@return array of ArtifactFile's.
	 */
	function &getFiles() {
		if (!isset($this->files)) {
			$sql="select * ".
			"FROM artifact_file_user_vw ".
			"WHERE artifact_id='". $this->getID() ."'";
			$res=db_query($sql);
			$rows=db_numrows($res);
			if ($rows > 0) {
				for ($i=0; $i < $rows; $i++) {
					$this->files[$i]=new ArtifactFile($this,db_fetch_array($res));
				}
			} else {
				$this->files=array();
			}
		}
		return $this->files;
	}

	/**
	 *  addMessage - attach a text message to this Artifact.
	 *
	 *	@param	string	The message being attached.
	 *	@param	string	Email address of message creator.
	 *	@param	bool	Whether to email out a followup.
	 *	@access private.
	 *  @return	boolean	success.
	 */
	function addMessage($body,$by=false,$send_followup=false) {
		global $Language;
		if (!$body) {
			$this->setMissingParamsError();
			return false;
		}

		if (session_loggedin()) {
			$user_id=user_getid();
			$user =& user_get_object($user_id);
			if (!$user || !is_object($user)) {
				$this->setError('ERROR - Logged In User Bug Could Not Get User Object');
				return false;
			}
			$body=$Language->getText('tracker_artifact','logged_in_yes')." \nuser_id=$user_id\n\n".$body;

			//	we'll store this email even though it will likely never be used - 
			//	since we have their correct user_id, we can join the USERS table to get email
			$by=$user->getEmail();
		} else {
			$body=$Language->getText('tracker_artifact','logged_in_no')." \n\n".$body;
			$user_id=100;
			if (!$by || !validate_email($by)) {
				$this->setMissingParamsError();
				return false;
			}
		}

		$sql="insert into artifact_message (artifact_id,submitted_by,from_email,adddate,body) ".
			"VALUES ('". $this->getID() ."','$user_id','$by','". time() ."','". htmlspecialchars($body). "')";
		$res = db_query($sql);
		if ($send_followup) {
			$this->mailFollowup(2,false);
		}
		return $res;
	}

	/**
	 *  addHistory - add an entry to audit trail.
	 *
	 *  @param	string	The name of the field in the database being modified.
	 *  @param	string	The former value of this field.
	 *  @access private.
	 *  @return	boolean	success.
	 */
	function addHistory($field_name,$old_value) {
		if (!session_loggedin()) {
			$user=100;
		} else {
			$user=user_getid();
		}
		$sql="insert into artifact_history(artifact_id,field_name,old_value,mod_by,entrydate) 
			VALUES ('". $this->getID() ."','$field_name','$old_value','$user','". time() ."')";
		return db_query($sql);
	}

	/**
	 *	update - update the fields in this artifact.
	 *
	 *	@param	int		The artifact priority.
	 *	@param	int		The artifact status ID.
	 *	@param	int		The artifact category ID.
	 *	@param	int		The artifact group ID.
	 *	@param	int		The artifact resolution ID.
	 *	@param	int		The person to which this artifact is to be assigned.
	 *	@param	string	The artifact summary.
	 *	@param	int		The canned response.
	 *	@param	string	Attaching another comment.
	 *	@param	int		Allows you to move an artifact to another type.
	 *	@return	boolean	success.
	 */
	function update($priority,$status_id,$category_id,$artifact_group_id,$resolution_id,
		$assigned_to,$summary,$canned_response,$details,$new_artifact_type_id) {

		global $Language;
		if (!$this->getID() 
			|| !$assigned_to 
			|| !$status_id 
			|| !$category_id 
			|| !$artifact_group_id 
			|| !$resolution_id
			|| !$canned_response 
			|| !$new_artifact_type_id) {
			$this->setMissingParamsError();
			return false;
		}

		// If the current status is Pending then auto-reset it to 'Open'
		// Assumes the status ID for 'Pending' is '4'
		/*
		//This was unexpected behavior - best to let the admin set their own status
		if ($status_id != '2' && $status_id != '3'  && $this->getStatusID() == '4') {
			$status_id = '1';
		}
		*/
		//	original submitter can always modify his/her items now
		if (!$this->ArtifactType->userIsAdmin() && ($this->getSubmittedBy() != user_getid()) && (!$this->ArtifactType->userIsTechnician())) {
			$this->setPermissionDeniedError();
			return false;
		}

		// Array to record which properties were changed
		$changes = array();

		db_begin();

		//
		//	Get a lock on this row in the database
		//
		$lock=db_query("SELECT * FROM artifact WHERE artifact_id='".$this->getID()."' FOR UPDATE");

		$artifact_type_id = $this->ArtifactType->getID();

		//
		//	Attempt to move this Artifact to a new ArtifactType
		//	need to instantiate new ArtifactType obj and test perms
		//
		if ($new_artifact_type_id != $artifact_type_id) {
			$newArtifactType= new ArtifactType($this->ArtifactType->getGroup(), $new_artifact_type_id);
			if (!is_object($newArtifactType) || $newArtifactType->isError()) {
				$this->setError('Artifact: Could not move to new ArtifactType'.$newArtifactType->getErrorMessage());
				return false;
			}
			//	do they have perms for new ArtifactType?
			if (!$newArtifactType->userIsAdmin()) {
				$this->setPermissionDeniedError();
				db_rollback();
				return false;
			}
			//
			//	Now set ArtifactGroup, Category, and Assigned to 100 in the new ArtifactType
			//
			$status_id=1;
			$category_id='100';
			$artifact_group_id='100';
			$assigned_to='100';
			//can't send a canned response when changing ArtifactType
			$canned_response=100;
			$this->ArtifactType =& $newArtifactType;
			$update = true;
		}

		$sqlu='';

		//
		//	handle audit trail & build SQL statement
		//
		if ($this->getStatusID() != $status_id) {
			$this->addHistory('status_id',$this->getStatusID());
			$sqlu .= " status_id='$status_id', ";
			$changes['status'] = 1;
			$update = true;
		}
		if (($this->getResolutionID() != $resolution_id) && ($resolution_id != 100)) {
			$this->addHistory('resolution_id',$this->getResolutionID());
			$sqlu .= " resolution_id='$resolution_id', ";
			$changes['resolution'] = 1;
			$update = true;
		}
		if ($this->getCategoryID() != $category_id) {
			$this->addHistory('category_id',$this->getCategoryID());
			$sqlu .= " category_id='$category_id', ";
			$changes['category'] = 1;
			$update = true;
		}
		if ($this->getArtifactGroupID() != $artifact_group_id) {
			$this->addHistory('artifact_group_id',$this->getArtifactGroupID());
			$sqlu .= " artifact_group_id='$artifact_group_id', ";
			$changes['artifact_group'] = 1;
			$update = true;
		}
		if ($this->getPriority() != $priority) {
			$this->addHistory('priority',$this->getPriority());
			$sqlu .= " priority='$priority', ";
			$changes['priority'] = 1;
			$update = true;
		}

		if ($this->getAssignedTo() != $assigned_to) {
			$this->addHistory('assigned_to',$this->getAssignedTo());
			$sqlu .= " assigned_to='$assigned_to', ";
			$changes['assigned_to'] = 1;
			$update = true;
		}
		if ($summary && (addslashes($this->getSummary()) != htmlspecialchars($summary))) {
			$this->addHistory('summary', addslashes($this->getSummary()));
			$sqlu .= " summary='". htmlspecialchars($summary) ."', ";
			$changes['summary'] = 1;
			$update = true;
		}

		if ($details) {
			$this->addMessage($details);
			$changes['details'] = 1;
			$send_message=true;
		}

		//
		//	Enter the timestamp if we are changing to closed
		//
		if ($status_id != 1) {
			$now=time();
			$sqlu .= " close_date='$now', ";
			$this->addHistory('close_date',$now);
			$update = true;
		}

		/*
			Finally, update the artifact itself
		*/
		if ($update){
			$sql = "UPDATE artifact 
				SET 
				$sqlu
				group_artifact_id='$new_artifact_type_id'
				WHERE 
				artifact_id='". $this->getID() ."'
				AND group_artifact_id='$artifact_type_id'";

			$result=db_query($sql);

			if (!$result || db_affected_rows($result) < 1) {
				$this->setError('Error - update failed!');
				echo db_error();
				db_rollback();
				return false;
			} else {
				$this->fetchData($this->getID());
//error check the data fetching??
			}
		}

		/*
			handle canned responses

			Instantiate ArtifactCanned and get the body of the message
		*/
		if ($canned_response != 100) {
			//don't care if this response is for this group - could be hacked
			$acr=new ArtifactCanned($this->ArtifactType,$canned_response);
			if (!$acr || !is_object($acr)) {
				$this->setError('Artifact: Could Not Create Canned Response Object');
			} elseif ($acr->isError()) {
				$this->setError('Artifact: '.$acr->getErrorMessage());
			} else {
				$body = addslashes($acr->getBody());
				if ($body) {
					if (!$this->addMessage(util_unconvert_htmlspecialchars($body),user_getname().'@'.$GLOBALS['sys_users_host'])) {
						db_rollback();
						return false;
					} else {
						$send_message=true;
					}
				} else {
					$this->setError('Artifact: Unable to Use Canned Response');
					return false;
				}
			}
		}

		if ($update || $send_message){
			/*
				now send the email
			*/
			$this->mailFollowup(2, false, $changes);
			db_commit();
			return true;
		} else {
			//nothing changed, so cancel the transaction
			$this->setError($Language->getText('tracker_artifact','nothing_changed'));
			db_rollback();
			return false;
		}
	}

	// function which returns proper marker for changed properties
	function marker($prop_name,$changes) {
		if ($changes[$prop_name]) {
			return '>';
		} else {
			return '';
		}
	}				

	/**
	 *	mailFollowup - send out an email update for this artifact.
	 *
	 *	@param	int		(1) initial/creation (2) update.
	 *	@param	array	Array of additional addresses to mail to.
	 *	@param	array	Array of fields changed in this update .
	 *	@access private.
	 *	@return	boolean	success.
	 */
	function mailFollowup($type, $more_addresses=false, $changes='') {
		global $sys_datefmt;

		if (!$changes) {
			$changes=array();
		}

		if ($this->ArtifactType->useResolution()) {
			$resolution_text = $this->marker('resolution',$changes).
			 "Resolution: ". $this->getResolutionName() ."\n";
		}

		$body = $this->ArtifactType->getName() ." item #". $this->getID() .", was opened at ". date( $sys_datefmt, $this->getOpenDate() ). 
			"\nYou can respond by visiting: ".
			"\nhttp://".$GLOBALS['sys_default_domain']."/tracker/?func=detail&atid=". $this->ArtifactType->getID() .
				"&aid=". $this->getID() .
				"&group_id=". $this->ArtifactType->Group->getID() .
			"\n\n".
			$this->marker('category',$changes).
			 "Category: ". $this->getCategoryName() ."\n".
			$this->marker('artifact_group',$changes).
			 "Group: ". $this->getArtifactGroupName() ."\n".
			$this->marker('status',$changes).
			 "Status: ". $this->getStatusName() ."\n".
			$resolution_text.
			$this->marker('priority',$changes).
			 "Priority: ". $this->getPriority() ."\n".
			"Submitted By: ". $this->getSubmittedRealName() .
			" (". $this->getSubmittedUnixName(). ")"."\n".
			$this->marker('assigned_to',$changes).
			 "Assigned to: ". $this->getAssignedRealName() .
			 " (". $this->getAssignedUnixName(). ")"."\n".
			$this->marker('summary',$changes).
			 "Summary: ". util_unconvert_htmlspecialchars( $this->getSummary() );
			
			
		$subject='[ '. $this->ArtifactType->Group->getUnixName() . '-' . $this->ArtifactType->getName() . '-' . $this->getID() .' ] '. util_unconvert_htmlspecialchars( $this->getSummary() );

		if ($type > 1) {
			/*
				get all the email addresses that are monitoring this request
			*/
			$monitor_ids =& $this->getMonitorIds();
		}

		if ($more_addresses) {
			$emails[] = $more_addresses;
		}
		//we don't email the current user
		if ($this->getAssignedTo() != user_getid()) {
			$monitor_ids[] = $this->getAssignedTo();
		}
		if ($this->getSubmittedBy() != user_getid()) {
			$monitor_ids[] = $this->getSubmittedBy();
		}
		//initial submission
		if ($type==1) {
			//if an email is set for this ArtifactType
			//add that address to the BCC: list
			if ($this->ArtifactType->getEmailAddress()) {
				$emails[] = $this->ArtifactType->getEmailAddress();
			}
		} else {
			//update
			if ($this->ArtifactType->emailAll()) {
				$emails[] = $this->ArtifactType->getEmailAddress();
			}
		}

		$body .= "\n\nInitial Comment:".
			"\n".util_unconvert_htmlspecialchars( $this->getDetails() ) .
			"\n\n----------------------------------------------------------------------";

		if ($type > 1) {
			/*
				Now include the followups
			*/
			$result2=$this->getMessages();

			$rows=db_numrows($result2);
		
			if ($result2 && $rows > 0) {
				for ($i=0; $i<$rows; $i++) {
					//
					//	for messages posted by non-logged-in users, 
					//	we grab the email they gave us
					//
					//	otherwise we use the confirmed one from the users table
					//
					if (db_result($result2,$i,'user_id') == 100) {
						$emails[] = db_result($result2,$i,'from_email');
					} else {
						$monitor_ids[] = db_result($result2,$i,'user_id');
					}


					$body .= "\n\n";
					if ($i == 0) {
						$body .= $this->marker('details',$changes);
					}
					$body .= "Comment By: ". db_result($result2,$i,'realname') . " (".db_result($result2,$i,'user_name').")".
					"\nDate: ". date( $sys_datefmt,db_result($result2,$i,'adddate') ).
					"\n\nMessage:".
					"\n".util_unconvert_htmlspecialchars( db_result($result2,$i,'body') ).
					"\n\n----------------------------------------------------------------------";
				}	   
			}

		}

		$body .= "\n\nYou can respond by visiting: ".
		"\nhttp://$GLOBALS[sys_default_domain]/tracker/?func=detail&atid=". $this->ArtifactType->getID() .
			"&aid=". $this->getID() .
			"&group_id=". $this->ArtifactType->Group->getID();

		//only send if some recipients were found
		if (count($emails) < 1 && count($monitor_ids) < 1) {
			return true;
		}

		//now remove all duplicates from the email list
		if (count($emails) > 0) {
			$BCC=implode(',',array_unique($emails));
		}

		if (count($monitor_ids) < 1) {
			$monitor_ids=array();
		} else {
			$monitor_ids=array_unique($monitor_ids);
		}
		/*
			Send the email
		*/
		util_handle_message($monitor_ids,$subject,$body,$BCC);
		return true;
	}

}

?>