File: ProjectTask.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 (852 lines) | stat: -rw-r--r-- 24,659 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
<?php
/**
 * GForge Project Management Facility
 *
 * Copyright 2002 GForge, LLC
 * http://gforge.org/
 *
 * @version   $Id: ProjectTask.class,v 1.19 2003/06/12 23:31:26 cbayle 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
 */
/*

	Project/Task Manager
	By Tim Perdue, Sourceforge, 11/99
	Heavy rewrite by Tim Perdue April 2000

	Total rewrite in OO and GForge coding guidelines 12/2002 by Tim Perdue
*/


require_once('common/include/Error.class');
require_once('common/pm/Validator.class');

function &projecttask_get_object($project_task_id,$data=false) {
        global $PROJECTTASK_OBJ;
        if (!isset($PROJECTTASK_OBJ["_".$project_task_id."_"])) {
                if ($data) {
                        //the db result handle was passed in
                } else {
			echo "NO PT data<br>";
                        $res=db_query("SELECT * FROM project_task_vw
			WHERE project_task_id='$project_task_id'");

                        if (db_numrows($res) <1 ) {
                                $PROJECTTASK_OBJ["_".$project_task_id."_"]=false;
                                return false;
                        }
                        $data =& db_fetch_array($res);

                }
                $ProjectGroup =& projectgroup_get_object($data["group_project_id"]);
                $PROJECTTASK_OBJ["_".$project_task_id."_"]= new ProjectTask($ProjectGroup,$project_task_id,$data);

        }

        return $PROJECTTASK_OBJ["_".$project_task_id."_"];
}


class ProjectTask extends Error {

	/**
	 * Associative array of data from db.
	 *
	 * @var	 array   $data_array.
	 */
	var $data_array;

	/**
	 * The ProjectGroup object.
	 *
	 * @var	 object  $ProjectGroup.
	 */
	var $ProjectGroup;
	var $dependon;
	var $assignedto;
	var $relatedartifacts;

	/**
	 *  Constructor.
	 *
	 *	@param	object	The ProjectGroup object to which this ProjectTask is associated.
	 *  @param  int	 The project_task_id.
	 *  @param  array   The associative array of data.
	 *	@return	boolean success.
	 */
	function ProjectTask(&$ProjectGroup, $project_task_id=false, $arr=false) {
		$this->Error();
		if (!$ProjectGroup || !is_object($ProjectGroup)) {
			$this->setError('ProjectTask:: No Valid ProjectGroup Object');
			return false;
		}
		if ($ProjectGroup->isError()) {
			$this->setError('ProjectTask:: '.$ProjectGroup->getErrorMessage());
			return false;
		}
		$this->ProjectGroup =& $ProjectGroup;

		if ($project_task_id) {
			if (!$arr || !is_array($arr)) {
				if (!$this->fetchData($project_task_id)) {
					return false;
				}
			} else {
				$this->data_array =& $arr;
				//
				//	Verify this message truly belongs to this ProjectGroup
				//
				if ($this->data_array['group_project_id'] != $this->ProjectGroup->getID()) {
					$this->setError('Group_project_id in db result does not match ProjectGroup Object');
					return false;
				}
			}
		}
		return true;
	}

	/**
	 *	create - create a new ProjectTask in the database.
	 *
	 *	@param	string	The summary of this task.
	 *	@param	string	The detailed description of this task.
	 *	@param	int	The Priority of this task.
	 *	@param	int	The Hours estimated to complete this task.
	 *	@param	int	The (unix) start date of this task.
	 *	@param	int	The (unix) end date of this task.
	 *	@param	int	The category_id of this task.
	 *	@param	int	The percentage of completion in integer format of this task.
	 *	@param	array	An array of user_id's that are assigned this task.
	 *	@param	array	An array of project_task_id's that this task depends on.
	 *	@return	boolean success.
	 */
	function create($summary,$details,$priority,$hours,$start_date,$end_date,
			$category_id,$percent_complete,&$assigned_arr,&$depend_arr) {
		$v = new Validator();
		$v->check($summary, "summary");
		$v->check($details, "details");
		$v->check($priority, "priority");
		$v->check($hours, "hours");
		$v->check($start_date, "start date");
		$v->check($end_date, "end date");
		$v->check($category_id, "category");
		if (!$v->isClean()) {
			$this->setError($v->formErrorMsg("Must include "));
			return false;
 		}

		$perm =& $this->ProjectGroup->Group->getPermission( session_get_user() );

		if (!$perm || !is_object($perm) || !$perm->isPMAdmin()) {
			$this->setPermissionDeniedError();
			return false;
		}

		db_begin();
		$res=db_query("SELECT nextval('project_task_pk_seq') AS id");
		if (!$project_task_id=db_result($res,0,'id')) {
			$this->setError('Could Not Get Next ID');
			db_rollback();
			return false;
		} else {
			$this->data_array['project_task_id']=$project_task_id;

			if (!$this->setDependentOn($depend_arr)) {
				db_rollback();
				return false;
			} elseif (!$this->setAssignedTo($assigned_arr)) {
				db_rollback();
				return false;
			} else {
				$sql="INSERT INTO project_task (project_task_id,group_project_id,created_by,summary,
					details,start_date,end_date,status_id,category_id,priority,percent_complete,hours) 
					VALUES ('$project_task_id','". $this->ProjectGroup->getID() ."', '".user_getid()."', '". htmlspecialchars($summary) ."',
					'". htmlspecialchars($details) ."','$start_date','$end_date','1','$category_id','$priority','$percent_complete','$hours')";

				$result=db_query($sql);
				if (!$result || db_affected_rows($result) < 1) {
					$this->setError('ProjectTask::create() Posting Failed '.db_error());
					db_rollback();
					return false;
				} else {
					if (!$this->fetchData($project_task_id)) {
						db_rollback();
						return false;
					} else {
						$this->sendNotice(1);
						db_commit();
						return true;
					}
				}
			}
		}
	}

	/**
	 *  fetchData - re-fetch the data for this ProjectTask from the database.
	 *
	 *  @param  int	 The project_task_id.
	 *  @return	boolean	success.
	 */
	function fetchData($project_task_id) {
		$res=db_query("SELECT * FROM project_task_vw
			WHERE project_task_id='$project_task_id'
			AND group_project_id='". $this->ProjectGroup->getID() ."'");
		if (!$res || db_numrows($res) < 1) {
			$this->setError('ProjectTask::fetchData() Invalid MessageID'.db_error());
			return false;
		}
		$this->data_array =& db_fetch_array($res);
		db_free_result($res);
		return true;
	}

	/**
	 *	getProjectGroup - get the ProjectGroup object this ProjectTask is associated with.
	 *
	 *	@return	Object	The ProjectGroup object.
	 */
	function &getProjectGroup() {
		return $this->ProjectGroup;
	}

	/**
	 *	getID - get this project_task_id.
	 *
	 *	@return	int	The project_task_id.
	 */
	function getID() {
		return $this->data_array['project_task_id'];
	}

	/**
	 *	getSubmittedRealName - get the real name of the person who created this task.
	 *
	 *	@return	string	The real name person who created this task.
	 */
	function getSubmittedRealName() {
		return $this->data_array['realname'];
	}
	
	/**
	 *	getSubmittedUnixName - get the unix name of the person who created this task.
	 *
	 *	@return	string	The unix name of the person who created this task.
	 */
	function getSubmittedUnixName() {
		return $this->data_array['user_name'];
	}

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

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

	/**
	 *	getPercentComplete - an integer between 0 and 100.
	 *
	 *	@return	int	The percentage of completion of this task.
	 */
	function getPercentComplete() {
		return $this->data_array['percent_complete'];
	}

	/**
	 *	getPriority - the priority, between 1 and 9 of this task.
	 *
	 *	@return	int	The priority.
	 */
	function getPriority() {
		return $this->data_array['priority'];
	}

	/**
	 *	getHours - the hours this task is expected to take.
	 *
	 *	@return	int	The hours.
	 */
	function getHours() {
		return $this->data_array['hours'];
	}

	/**
	 *	getStartDate - the unix time that this task will start.
	 *
	 *	@return	int	The unix start time of this task.
	 */
	function getStartDate() {
		return $this->data_array['start_date'];
	}

	/**
	 *	getEndDate - the unix time that this task will end.
	 *
	 *	@return	int	The unix end time of this task.
	 */
	function getEndDate() {
		return $this->data_array['end_date'];
	}

	/**
	 *	getStatusID - the integer of the status of this task.
	 *
	 *	@return	int	the status_id.
	 */
	function getStatusID() {
		return $this->data_array['status_id'];
	}

	/**
	 *	getStatusName - the string of the status of this task.
	 *
	 *	@return	string	the status_name.
	 */
	function getStatusName() {
		return $this->data_array['status_name'];
	}

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

	/**
	 *	getCategoryName - the category_name of this task.
	 *
	 *	@return	int	the category_name.
	 */
	function getCategoryName() {
		return $this->data_array['category_name'];
	}

	/**
	 *	getRelatedArtifacts - Return a result set of artifacts which are related to this task.
	 *
	 *	@returns Database result set.
	 */
	function getRelatedArtifacts() {
		if (!$this->relatedartifacts) {
			$this->relatedartifacts=
			db_query("SELECT agl.group_id,agl.name,agl.group_artifact_id,a.artifact_id,a.open_date,a.summary 
			FROM artifact_group_list agl, artifact a 
			WHERE a.group_artifact_id=agl.group_artifact_id
			AND EXISTS (SELECT artifact_id FROM project_task_artifact 
				WHERE artifact_id=a.artifact_id
				AND project_task_id='". $this->getID() ."')");
		}
		return $this->relatedartifacts;
	}

	/**
	 *	addRelatedArtifacts - take an array of artifact_id's and build relationships.
	 *
	 *	@param	array	An array of artifact_id's to be attached to this task.
	 *	@return	boolean	success.
	 */
	function addRelatedArtifacts($art_array) {
		$perm =& $this->ProjectGroup->Group->getPermission( session_get_user() );

		if (!$perm || !is_object($perm) || !$perm->isPMAdmin()) {
			$this->setPermissionDeniedError();
			return false;
		}
//
//	SHOULD REALLY INSTANTIATE THIS ARTIFACT OBJECT TO ENSURE PROPER SECURITY - FUTURE
//
//	new ArtifactFromID($id)
//
		for ($i=0; $i<count($art_array); $i++) {
			if ($art_array[$i] < 1) {
				continue;
			}
			$res=db_query("INSERT INTO project_task_artifact (project_task_id,artifact_id) 
				VALUES ('".$this->getID()."','".$art_array[$i]."')");
			if (!$res) {
				$this->setError('Error inserting artifact relationship: '.db_error());
				return false;
			}
		}
		return true;
	}

	/**
	 *	removeRelatedArtifacts - take an array of artifact_id's and delete relationships.
	 *
	 *	@param	array	An array of artifact_id's to be removed from this task.
	 *	@return	boolean	success.
	 */
	function removeRelatedArtifacts($art_array) {
		$perm =& $this->ProjectGroup->Group->getPermission( session_get_user() );

		if (!$perm || !is_object($perm) || !$perm->isPMAdmin()) {
			$this->setPermissionDeniedError();
			return false;
		}

		for ($i=0; $i<count($art_array); $i++) {
			$res=db_query("DELETE FROM project_task_artifact
				WHERE project_task_id='".$this->getID()."'
				AND artifact_id='".$art_array[$i]."'");
			if (!$res) {
				$this->setError('Error deleting artifact relationship: '.db_error());
				return false;
			}
		}
		return true;
	}
/*
	function delete() {

		$project_task_id=$this->getID();

		$perm =& $this->ProjectGroup->Group->getPermission( session_get_user() );

		if (!$perm || !is_object($perm) || !$perm->isPMAdmin()) {
			$this->setPermissionDeniedError();
			return false;
		}

	}
*/

	/**
	 *	getOtherTasks - Return a result set of tasks in this subproject that do not equal
	 *	the current task_id.
	 *
	 *	@returns Database result set.
	 */
	function getOtherTasks () {
		//
		//	May not yet have an ID, if we are creating a NEW task
		//
		if ($this->getID()) {
			$addstr=" AND project_task_id <> '". $this->getID() ."' ";
		}
		$sql="SELECT project_task_id,summary 
		FROM project_task 
		WHERE group_project_id='". $this->ProjectGroup->getID() ."' 
		$addstr ORDER BY project_task_id DESC";
		return db_query($sql);
	}

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

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

	/**
	 * addMessage - Handle the addition of a followup message to this task.
	 *
	 * @param	   string  The message.
	 * @returns	boolean	success.
	 */
	function addMessage($message) {
		$sql="INSERT INTO project_messages (project_task_id,body,posted_by,postdate) 
			VALUES ('". $this->getID() ."','". htmlspecialchars($message) ."','".user_getid()."','". time() ."')";
		$res=db_query($sql);
		if (!$res || db_affected_rows($res) < 1) {
			$this->setError('AddMessage():: '.db_error());
			return false;
		} else {
			return true;
		}
	}

	/**
	 * addHistory - Handle the insertion of history for these parameters.
	 *
	 * @param	string  The field name.
	 * @param	string  The old value.
	 * @returns	boolean	success.
	 */
	function addHistory ($field_name,$old_value) {
		$sql="insert into project_history(project_task_id,field_name,old_value,mod_by,mod_date) 
			VALUES ('". $this->getID() ."','$field_name','$old_value','".user_getid()."','".time()."')";
		$result=db_query($sql);
		if (!$result) {
			$this->setError('ERROR IN AUDIT TRAIL - '.db_error());
			return false;
		} else {
			return true;
		}
	}

	/**
	 * checkCircular - recursive function calls itself to look at all tasks you are dependent on.
	 *
	 * @param	int	The project_task_id you are dependent on.
	 * @param	int	The project_task_id you are checking circular dependencies for.
	 * @returns	boolean	success.
	 */
	function checkCircular($depend_on_id, $original_id) {
		global $Language;
		if ($depend_on_id == $original_id) {
			$this->setError($Language->getText('pm_projecttask','circular_dependency'));
	 		return false;
		}

		$res=db_query("SELECT is_dependent_on_task_id AS id 
			FROM project_dependencies 
			WHERE project_task_id='$depend_on_id'");
		$rows=db_numrows($res);

		for ($i=0; $i<$rows; $i++) {
			if (!$this->checkCircular(db_result($res,$i,'id'), $original_id)) {
				return false;
			}
		}
		return true;
	}

	/**
	 * setDependentOn - takes an array of project_task_id's and builds dependencies.
	 *
	 * @param	array	The array of project_task_id's.
	 * @returns	boolean	success.
	 */
	function setDependentOn(&$arr) {
//
//	IMPORTANT - MUST VERIFY NO CIRCULAR DEPENDENCY!! 
//
		//get existing dependencies to diff against
		$arr2 =& $this->getDependentOn();
		$this->dependon =& $arr2;

		if (count($arr) || count($arr2)) {
			$add_arr = array_diff ($arr, $arr2);
			$del_arr = array_diff ($arr2, $arr);
			for ($i=0; $i<count($del_arr); $i++) {
				db_query("DELETE FROM project_dependencies 
					WHERE project_task_id='".$this->getID()."'
					AND is_dependent_on_task_id='". $del_arr[$i] ."'");
				if (db_error()) {
					$this->setError('setDependentOn()-1:: '.db_error());
					return false;
				}
			}
			for ($i=0; $i<count($add_arr); $i++) {
				//
				//	Check task for circular dependencies
				//
				if (!$this->checkCircular($add_arr[$i],$this->getID())) {
					return false;
				}
				db_query("INSERT INTO project_dependencies (project_task_id,is_dependent_on_task_id) 
					VALUES ('".$this->getID()."','". $add_arr[$i] ."')");
				if (db_error()) {
					$this->setError('setDependentOn()-2:: '.db_error());
					return false;
				}
			}
			return true;
		} else {
			return true;
		}
	}

	/**
	 *	getDependentOn - get an array of project_task_id's that you are dependent on.
	 *
	 *	@return	array	The array of project_task_id's.
	 */
	function &getDependentOn() {
		if (!$this->getID()) {
			return array();
		}
		if (!$this->dependon) {
			$this->dependon =& util_result_column_to_array(db_query("SELECT is_dependent_on_task_id 
				FROM project_dependencies 
				WHERE project_task_id='".$this->getID()."'"));
		}
		/* fix bug 319: if dependentlist is emtpy, set it to 100 (none) */
		if (!$this->dependon) {
			$this->dependon[]=100;
		}
		return $this->dependon;
	}

	/**
	 * setAssignedTo - takes an array of user_id's and builds assignments.
	 *
	 * @param	array	The array of user_id's.
	 * @returns	boolean	success.
	 */
	function setAssignedTo(&$arr) {
		$arr2 =& $this->getAssignedTo();
		$this->assignedto =& $arr2;

		//If no one is assigned, then assign it to "100" - NOBODY
		if (count($arr) < 1 || ((count($arr)==1) && ($arr[0]==''))) {
			$arr=array('100');
		}
		if (count($arr) || count($arr2)) {
			$add_arr = array_diff ($arr, $arr2);
			$del_arr = array_diff ($arr2, $arr);
			for ($i=0; $i<count($del_arr); $i++) {
				db_query("DELETE FROM project_assigned_to
					WHERE project_task_id='".$this->getID()."'
					AND assigned_to_id='". $del_arr[$i] ."'");
				if (db_error()) {
					$this->setError('setAssignedTo()-1:: '.db_error());
					return false;
				}
			}
			for ($i=0; $i<count($add_arr); $i++) {
				db_query("INSERT INTO project_assigned_to (project_task_id,assigned_to_id) 
					VALUES ('".$this->getID()."','". $add_arr[$i] ."')");
				if (db_error()) {
					$this->setError('setAssignedTo()-2:: '.db_error());
					return false;
				}
			}
			return true;
		} else {
			return true;
		}
	}

	/**
	 *	getAssignedTo - get an array of user_id's that you are assigned to.
	 *
	 *	@return	array	The array of user_id's.
	 */
	function &getAssignedTo() {
		if (!$this->getID()) {
			return array();
		}
		if (!$this->assignedto) {
			$this->assignedto =& util_result_column_to_array(db_query("SELECT assigned_to_id 
				FROM project_assigned_to 
				WHERE project_task_id='".$this->getID()."'"));
		}
		return $this->assignedto;
	}

	/**
	 *	update - update this ProjectTask in the database.
	 *
	 *	@param	string	The summary of this task.
	 *	@param	string	The detailed description of this task.
	 *	@param	int	The Priority of this task.
	 *	@param	int	The Hours estimated to complete this task.
	 *	@param	int	The (unix) start date of this task.
	 *	@param	int	The (unix) end date of this task.
	 *	@param	int	The status_id of this task.
	 *	@param	int	The category_id of this task.
	 *	@param	int	The percentage of completion in integer format of this task.
	 *	@param	array	An array of user_id's that are assigned this task.
	 *	@param	array	An array of project_task_id's that this task depends on.
	 *	@return	boolean success.
	 */
	function update($summary,$details,$priority,$hours,$start_date,$end_date,
		$status_id,$category_id,$percent_complete,&$assigned_arr,&$depend_arr) {
                $v = new Validator();
                $v->check($summary, "summary");
                $v->check($priority, "priority");
                $v->check($hours, "hours");
                $v->check($start_date, "start date");
                $v->check($end_date, "end date");
                $v->check($status_id, "status");
                $v->check($category_id, "category");
                if (!$v->isClean()) {
                        $this->setError($v->formErrorMsg("Must include "));
                        return false;
                }

		$perm =& $this->ProjectGroup->Group->getPermission( session_get_user() );

		if (!$perm || !is_object($perm) || !$perm->isPMAdmin()) {
			$this->setPermissionDeniedError();
			return false;
		}

		db_begin();
		if ($details) {
			if (!$this->addMessage($details)) {
				db_rollback();
				return false;
			}
		}
		if ($this->getStatusID() != $status_id)
			{ $this->addHistory ('status_id',$this->getStatusID());  }

		if ($this->getCategoryID() != $category_id)
			{ $this->addHistory ('category_id',$this->getCategoryID());  }

		if ($this->getPriority() != $priority)
			{ $this->addHistory ('priority',$this->getPriority());  }

		if ($this->getSummary() != htmlspecialchars(stripslashes($summary)))
			{ $this->addHistory ('summary',addslashes($this->getSummary()));  }

		if ($this->getPercentComplete() != $percent_complete)
			{ $this->addHistory ('percent_complete',$this->getPercentComplete()); }

		if ($this->getHours() != $hours)
			{ $this->addHistory ('hours',$this->getHours());  }

		if ($this->getStartDate() != $start_date)
			{ $this->addHistory ('start_date',$this->getStartDate());  }

		if ($this->getEndDate() != $end_date)
			{ $this->addHistory ('end_date',$this->getEndDate());  }

		$old_assigned = &$this->getAssignedTo();
		$diff_assigned_array=array_diff($old_assigned, $assigned_arr);
		if (count($diff_assigned_array)>0) { 
				for ($tmp=0;$tmp<count($old_assigned);$tmp++) { 
					$this->addHistory('assigned_to_id',$old_assigned[$tmp]);
				}
		}
		$old_array = &$this->getDependentOn();			
		$diff_array=array_diff($old_array,$depend_arr);
		if (count($diff_array)>0) { 
			for ($tmp=0;$tmp<count($old_array);$tmp++) {
				$this->addHistory('dependent_on_id', $old_array[$tmp]);	
			}
		}
		
		if (!$this->setDependentOn($depend_arr)) {
			db_rollback();
			return false;
		} elseif (!$this->setAssignedTo($assigned_arr)) {
			db_rollback();
			return false;
		} else {
			$sql="UPDATE project_task SET
				summary='".htmlspecialchars($summary)."',
				priority='$priority',
				hours='$hours',
				start_date='$start_date',
				end_date='$end_date',
				status_id='$status_id',
				percent_complete='$percent_complete',
				category_id='$category_id'
				WHERE group_project_id='".$this->ProjectGroup->getID()."'
				AND project_task_id='".$this->getID()."'";

			$res=db_query($sql);
			if (!$res || db_affected_rows($res) < 1) {
				$this->setError('Error On Update: '.db_error());
				db_rollback();
				return false;
			} else {
				if (!$this->fetchData($this->getID())) {
					return false;
				} else {
					$this->sendNotice();
					db_commit();
					return true;
				}
			}
		}

	}

	/**
	 *	sendNotice - contains the logic for sending email/jabber updates.
	 *
	 *	@return	boolean	success.
	 */
	function sendNotice($first=false) {
		$ids =& $this->getAssignedTo();

		//
		//	See if there is anyone to send messages to
		//
		if (count($ids) < 1 && !$this->ProjectGroup->getSendAllPostsTo()) {
			return true;
		}

		$body = "Task #". $this->getID() ." has been updated. ".
			"\n\nProject: ". $this->ProjectGroup->Group->getPublicName() .
			"\nSubproject: ". $this->ProjectGroup->getName() .
			"\nSummary: ".util_unconvert_htmlspecialchars( $this->getSummary() ).
			"\nComplete: ". $this->getPercentComplete() ."%".
			"\nStatus: ". $this->getStatusName() .
			"\n\nDescription: ". util_unconvert_htmlspecialchars( $this->getDetails() );

		/*
			Now get the followups to this task
		*/
		$result2=$this->getMessages();

		$rows=db_numrows($result2);

		if ($result2 && $rows > 0) {
			$body .= "\n\nFollow-Ups:";
			for ($i=0; $i<$rows;$i++) {
				$body .= "\n\n-------------------------------------------------------";
				$body .= "\nDate: ". date($GLOBALS['sys_datefmt'],db_result($result2,$i,'postdate'));
				$body .= "\nBy: ".db_result($result2,$i,'user_name');
				$body .= "\n\nComment:\n".util_unconvert_htmlspecialchars(db_result($result2,$i,'body'));
			}
		}
		$body .= "\n\n-------------------------------------------------------".
			"\nFor more info, visit:".
			"\n\nhttp://$GLOBALS[sys_default_domain]/pm/task.php?func=detailtask&project_task_id=".
				$this->getID() ."&group_id=".
				$this->ProjectGroup->Group->getID() ."&group_project_id=". $this->ProjectGroup->getID();

		$subject="[Task #". $this->getID() .'] '.
			util_unconvert_htmlspecialchars( $this->getSummary() );

		util_handle_message(array_unique($ids),$subject,$body,$this->ProjectGroup->getSendAllPostsTo());
		return true;
	}

}

?>