5 * Copyright 1999-2001, VA Linux Systems, Inc.
6 * Copyright 2002-2004, GForge, LLC
7 * Copyright 2009, Roland Mas
8 * Copyright 2009, Alcatel-Lucent
10 * This file is part of FusionForge. FusionForge is free software;
11 * you can redistribute it and/or modify it under the terms of the
12 * GNU General Public License as published by the Free Software
13 * Foundation; either version 2 of the Licence, or (at your option)
16 * FusionForge is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License along
22 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 * Standard Alcatel-Lucent disclaimer for contributing to open source
29 * "The Artifact ("Contribution") has not been tested and/or
30 * validated for release as or in products, combinations with products or
31 * other commercial use. Any use of the Contribution is entirely made at
32 * the user's own responsibility and the user can not rely on any features,
33 * functionalities or performances Alcatel-Lucent has attributed to the
36 * THE CONTRIBUTION BY ALCATEL-LUCENT IS PROVIDED AS IS, WITHOUT WARRANTY
37 * OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
38 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, COMPLIANCE,
39 * NON-INTERFERENCE AND/OR INTERWORKING WITH THE SOFTWARE TO WHICH THE
40 * CONTRIBUTION HAS BEEN MADE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL
41 * ALCATEL-LUCENT BE LIABLE FOR ANY DAMAGES OR OTHER LIABLITY, WHETHER IN
42 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
43 * CONTRIBUTION OR THE USE OR OTHER DEALINGS IN THE CONTRIBUTION, WHETHER
44 * TOGETHER WITH THE SOFTWARE TO WHICH THE CONTRIBUTION RELATES OR ON A STAND
47 require_once $gfcommon.'include/Error.class.php';
48 require_once $gfcommon.'tracker/ArtifactMessage.class.php';
49 require_once $gfcommon.'tracker/ArtifactExtraField.class.php';
50 require_once $gfcommon.'tracker/ArtifactWorkflow.class.php';
51 require_once $gfcommon.'tracker/ArtifactStorage.class.php';
53 // This string is used when sending the notification mail for identifying the
55 define('ARTIFACT_MAIL_MARKER', '#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+');
58 * Factory method which creates an Artifact from an artifact ID
60 * @param int The artifact ID
61 * @param array The result array, if it's passed in
62 * @return object Artifact object
64 function &artifact_get_object($artifact_id,$data=false) {
66 if (!isset($ARTIFACT_OBJ["_".$artifact_id."_"])) {
68 //the db result handle was passed in
70 $res = db_query_params ('SELECT * FROM artifact_vw WHERE artifact_id=$1',
71 array ($artifact_id)) ;
72 if (db_numrows($res) <1 ) {
73 $ARTIFACT_OBJ["_".$artifact_id."_"]=false;
76 $data = db_fetch_array($res);
78 $ArtifactType =& artifactType_get_object($data["group_artifact_id"]);
79 $ARTIFACT_OBJ["_".$artifact_id."_"]= new Artifact($ArtifactType,$data);
81 return $ARTIFACT_OBJ["_".$artifact_id."_"];
84 class Artifact extends Error {
89 * @var int $status_res.
94 * Artifact Type object.
96 * @var object $ArtifactType.
101 * Array of artifact data.
103 * @var array $data_array.
108 * Array of artifact data for extra fields defined by Admin.
110 * @var array $extra_field_data.
112 var $extra_field_data;
115 * Array of ArtifactFile objects.
122 * Database result set of related tasks
124 * @var result $relatedtasks
129 * Artifact - constructor.
131 * @param ArtifactType $ArtifactType The ArtifactType object.
132 * @param int|bool $data (primary key from database OR complete assoc array)
133 * ONLY OPTIONAL WHEN YOU PLAN TO IMMEDIATELY CALL ->create()
135 function __construct(&$ArtifactType, $data=false) {
138 $this->ArtifactType =& $ArtifactType;
140 // Was ArtifactType legit?
141 if (!$ArtifactType || !is_object($ArtifactType)) {
142 $this->setError(_('No Valid Artifact Type'));
146 // Did ArtifactType have an error?
147 if ($ArtifactType->isError()) {
148 $this->setError($ArtifactType->getErrorMessage());
152 // Make sure this person has permission to view artifacts
153 if (!forge_check_perm ('tracker', $this->ArtifactType->getID(), 'read')) {
154 $this->setError(_('Only project members can view private artifact types'));
159 if (is_array($data)) {
160 $this->data_array =& $data;
162 $this->fetchData($data);
168 * create - construct a new Artifact in the database.
170 * @param string The artifact summary.
171 * @param string Details of the artifact.
172 * @param int The ID of the user to which this artifact is to be assigned.
173 * @param int The artifacts priority.
174 * @param array Array of extra fields like: array(15=>'foobar',22=>'1');
175 * @param array Array of data to change submitter and time of submit like: array('user' => 127, 'time' => 1234556789)
176 * @return id on success / false on failure.
178 function create( $summary, $details, $assigned_to=100, $priority=3, $extra_fields=array(), $importData = array()) {
180 // make sure this person has permission to add artifacts
186 if(array_key_exists('user', $importData)){
187 $user = $importData['user'];
189 if (!forge_check_perm ('tracker',$this->ArtifactType->getID(),'submit')) {
190 $this->setError(_('You are not currently allowed to submit items to this tracker.'));
194 if (session_loggedin()) {
205 $this->setError(_('Message Summary Is Required'));
209 $this->setError(_('Message Body Is Required'));
218 // if (!$status_id) {
219 $status_id=1; // on creation, status is set to "open"
222 // They may be using an extra field "status" box so we have to remap
223 // the status_id based on the extra field - this keeps the counters
226 $status_id=$this->ArtifactType->remapStatus($status_id,$extra_fields);
228 $this->setError(_('Error remapping status'));
233 if (array_key_exists('time',$importData)){
234 $time = $importData['time'];
238 $res = db_query_params ('INSERT INTO artifact
239 (group_artifact_id,status_id,priority,
240 submitted_by,assigned_to,open_date,summary,details)
241 VALUES ($1,$2,$3,$4,$5,$6,$7,$8)',
242 array ($this->ArtifactType->getID(),
248 htmlspecialchars($summary),
249 htmlspecialchars($details))) ;
251 $this->setError(db_error());
256 $artifact_id=db_insertid($res,'artifact','artifact_id');
258 if (!$res || !$artifact_id) {
259 $this->setError(db_error());
264 // Now set up our internal data structures
266 if (!$this->fetchData($artifact_id)) {
270 // the changes to the extra fields will be logged in this array.
271 // (we won't use it however)
272 $extra_field_changes = array();
273 if (!$this->updateExtraFields($extra_fields,$extra_field_changes)) {
279 // now send an email if appropriate
281 $this->mailFollowupEx(0, 1);
289 * fetchData - re-fetch the data for this Artifact from the database.
291 * @param int The artifact ID.
292 * @return boolean success.
294 function fetchData($artifact_id) {
295 $res = db_query_params ('SELECT * FROM artifact_vw WHERE artifact_id=$1 AND group_artifact_id=$2',
297 $this->ArtifactType->getID())) ;
298 if (!$res || db_numrows($res) < 1) {
299 $this->setError(_('Invalid Artifact ID'));
302 $this->data_array = db_fetch_array($res);
303 db_free_result($res);
308 * getArtifactType - get the ArtifactType Object this Artifact is associated with.
310 * @return object ArtifactType.
312 function &getArtifactType() {
313 return $this->ArtifactType;
317 * getID - get this ArtifactID.
319 * @return int The artifact_id #.
322 return $this->data_array['artifact_id'];
326 * getStringID - get a string display for this ArtifactID.
328 * @return string The artifact_id #.
330 function getStringID() {
331 return '[#'.$this->data_array['artifact_id'].']';
335 * getStatusID - get open/closed/deleted flag.
337 * @return int Status: (1) Open, (2) Closed, (3) Deleted.
339 function getStatusID() {
340 return $this->data_array['status_id'];
344 * getStatusName - get open/closed/deleted text.
346 * @return string The status name.
348 function getStatusName() {
349 return $this->data_array['status_name'];
353 * getCustomStatusName - get custom status value text.
355 * @return string The custom status name.
357 function getCustomStatusName() {
358 $custom_status_id = $this->ArtifactType->getCustomStatusField();
359 if ($custom_status_id) {
360 $result = db_query_params ('SELECT element_name FROM artifact_extra_field_elements aefe, artifact_extra_field_data aefd
361 WHERE artifact_id=$1 AND aefd.extra_field_id=$2 AND CAST(aefd.field_data AS INTEGER)=aefe.element_id',
362 array ($this->getID(), $custom_status_id)) ;
364 return db_result($result, 0, 'element_name');
367 return $this->data_array['status_name'];
371 * getPriority - get priority flag.
373 * @return int priority.
375 function getPriority() {
376 return $this->data_array['priority'];
380 * getSubmittedBy - get ID of submitter.
382 * @return int user_id of submitter.
384 function getSubmittedBy() {
385 return $this->data_array['submitted_by'];
389 * getSubmittedEmail - get email of submitter.
391 * @return string The email of submitter.
393 function getSubmittedEmail() {
394 return $this->data_array['submitted_email'];
398 * getSubmittedRealName - get real name of submitter.
400 * @return string The real name of submitter.
402 function getSubmittedRealName() {
403 return $this->data_array['submitted_realname'];
407 * getSubmittedUnixName - get login name of submitter.
409 * @return string The unix name of submitter.
411 function getSubmittedUnixName() {
412 return $this->data_array['submitted_unixname'];
416 * getAssignedTo - get ID of assignee.
418 * @return int user_id of assignee.
420 function getAssignedTo() {
421 return $this->data_array['assigned_to'];
425 * getAssignedEmail - get email of assignee.
427 * @return string The email of assignee.
429 function getAssignedEmail() {
430 return $this->data_array['assigned_email'];
434 * getAssignedRealName - get real name of assignee.
436 * @return string The real name of assignee.
438 function getAssignedRealName() {
439 return $this->data_array['assigned_realname'];
443 * getAssignedUnixName - get login name of assignee.
445 * @return string The unix name of assignee.
447 function getAssignedUnixName() {
448 return $this->data_array['assigned_unixname'];
452 * getOpenDate - get unix time of creation.
454 * @return int unix time.
456 function getOpenDate() {
457 return $this->data_array['open_date'];
461 * getCloseDate - get unix time of closure.
463 * @return int unix time.
465 function getCloseDate() {
466 return $this->data_array['close_date'];
470 * getLastModifiedDate - the last_modified_date of this task.
472 * @return int the last_modified_date.
474 function getLastModifiedDate() {
475 return $this->data_array['last_modified_date'];
479 * getSummary - get text summary of artifact.
481 * @return string The summary (subject).
483 function getSummary() {
484 return $this->data_array['summary'];
488 * getDetails - get text body (message) of artifact.
490 * @return string The body (message).
492 function getDetails() {
493 return $this->data_array['details'];
497 * delete - delete this tracker and all its related data.
499 * @param bool I'm Sure.
500 * @return bool true/false;
502 function delete($sure) {
504 $this->setMissingParamsError(_('Please tick all checkboxes.'));
507 if (!forge_check_perm ('tracker_admin', $this->ArtifactType->Group->getID())) {
508 $this->setPermissionDeniedError();
512 $res = db_query_params ('DELETE FROM artifact_extra_field_data WHERE artifact_id=$1',
513 array ($this->getID())) ;
515 $this->setError(_('Error deleting extra field data: ').db_error());
520 ArtifactStorage::instance()->deleteFromQuery('SELECT id FROM artifact_file WHERE artifact_id=$1',
521 array ($this->getID())) ;
523 $res = db_query_params ('DELETE FROM artifact_file WHERE artifact_id=$1',
524 array ($this->getID())) ;
526 $this->setError(_('Error deleting file from db: ').db_error());
528 ArtifactStorage::instance()->rollback();
531 $res = db_query_params ('DELETE FROM artifact_message WHERE artifact_id=$1',
532 array ($this->getID())) ;
534 $this->setError(_('Error deleting message: ').db_error());
536 ArtifactStorage::instance()->rollback();
539 $res = db_query_params ('DELETE FROM artifact_history WHERE artifact_id=$1',
540 array ($this->getID())) ;
542 $this->setError(_('Error deleting history: ').db_error());
544 ArtifactStorage::instance()->rollback();
547 $res = db_query_params ('DELETE FROM artifact_monitor WHERE artifact_id=$1',
548 array ($this->getID())) ;
550 $this->setError(_('Error deleting monitor: ').db_error());
552 ArtifactStorage::instance()->rollback();
555 $res = db_query_params ('DELETE FROM artifact WHERE artifact_id=$1',
556 array ($this->getID())) ;
558 $this->setError(_('Error deleting artifact: ').db_error());
560 ArtifactStorage::instance()->rollback();
564 if ($this->getStatusID() == 1) {
565 $res = db_query_params ('UPDATE artifact_counts_agg SET count=count-1,open_count=open_count-1
566 WHERE group_artifact_id=$1',
567 array ($this->getID())) ;
569 $this->setError(_('Error updating artifact counts: ').db_error());
571 ArtifactStorage::instance()->rollback();
574 } elseif ($this->getStatusID() == 2) {
575 $res = db_query_params ('UPDATE artifact_counts_agg SET count=count-1
576 WHERE group_artifact_id=$1',
577 array ($this->getID())) ;
579 $this->setError(_('Error updating artifact counts: ').db_error());
581 ArtifactStorage::instance()->rollback();
587 ArtifactStorage::instance()->commit();
592 * setMonitor - user can monitor this artifact.
594 * @return false - always false - always use the getErrorMessage() for feedback
596 function setMonitor() {
597 if (session_loggedin()) {
599 $user_id=user_getid();
600 $user =& user_get_object(user_getid());
603 //we don't want to include the "And email=" because
604 //a logged-in user's email may have changed
609 $this->setError(_('Valid Email Address Required'));
614 $res = db_query_params ('SELECT * FROM artifact_monitor WHERE artifact_id=$1 AND user_id=$2',
615 array ($this->getID(),
618 if (!$res || db_numrows($res) < 1) {
620 $res = db_query_params ('INSERT INTO artifact_monitor (artifact_id,user_id) VALUES ($1,$2)',
621 array ($this->getID(),
624 $this->setError(db_error());
627 $this->setError(_('Now Monitoring Artifact'));
631 //already monitoring - remove their monitor
632 db_query_params ('DELETE FROM artifact_monitor
635 array ($this->getID(),
637 $this->setError(_('Artifact Monitoring Deactivated'));
642 function isMonitoring() {
643 if (!session_loggedin()) {
646 $result = db_query_params ('SELECT count(*) AS count FROM artifact_monitor WHERE user_id=$1 AND artifact_id=$2',
649 $row_count = db_fetch_array($result);
650 return $result && $row_count['count'] > 0;
654 * getMonitorIds - array of email addresses monitoring this Artifact.
656 * @return array of email addresses monitoring this Artifact.
658 function getMonitorIds() {
659 $res = db_query_params ('SELECT user_id FROM artifact_monitor WHERE artifact_id=$1',
660 array ($this->getID())) ;
661 return array_unique(array_merge($this->ArtifactType->getMonitorIds(),util_result_column_to_array($res)));
665 * getHistory - returns a result set of audit trail for this support request.
667 * @return database result set.
669 function getHistory() {
670 return db_query_params ('SELECT * FROM artifact_history_user_vw WHERE artifact_id=$1 ORDER BY entrydate DESC',
671 array ($this->getID())) ;
675 * getMessages - get the list of messages attached to this artifact.
677 * @return database result set.
679 function getMessages($asc=false) {
680 return db_query_params ('SELECT * FROM artifact_message_user_vw WHERE artifact_id=$1 ORDER BY adddate ' . ($asc ? 'ASC' : 'DESC'),
681 array ($this->getID())) ;
685 * getMessageObjects - get an array of message objects.
687 * @return array Of ArtifactMessage objects.
689 function &getMessageObjects() {
690 $res=$this->getMessages();
692 while ($arr = db_fetch_array($res)) {
693 //$return[]=new ArtifactMessage($arr['artifact_id'],$arr);
694 $return[] = new ArtifactMessage($this, $arr);
700 * getFiles - get array of ArtifactFile's.
702 * @return array of ArtifactFile's.
704 function &getFiles() {
705 if (!isset($this->files)) {
706 $res = db_query_params ('SELECT id,artifact_id,description,filename,filesize,' .
707 'filetype,adddate,submitted_by,user_name,realname
708 FROM artifact_file_user_vw WHERE artifact_id=$1',
709 array ($this->getID())) ;
710 $rows=db_numrows($res);
712 for ($i=0; $i < $rows; $i++) {
713 $this->files[$i]=new ArtifactFile($this,db_fetch_array($res));
716 $this->files=array();
723 * getRelatedTasks - get array of related tasks
725 * @return Database result set
727 function getRelatedTasks() {
728 if (!$this->relatedtasks) {
729 $this->relatedtasks = db_query_params ('SELECT pt.group_project_id,pt.project_task_id,pt.summary,pt.start_date,pt.end_date,pgl.group_id,pt.status_id,pt.percent_complete,ps.status_name
730 FROM project_task pt, project_group_list pgl, project_status ps
731 WHERE pt.group_project_id = pgl.group_project_id
732 AND ps.status_id = pt.status_id
733 AND EXISTS (SELECT project_task_id FROM project_task_artifact
734 WHERE project_task_id=pt.project_task_id
735 AND artifact_id = $1)',
736 array ($this->getID())) ;
738 return $this->relatedtasks;
742 * addMessage - attach a text message to this Artifact.
744 * @param string The message being attached.
745 * @param string Email address of message creator.
746 * @param bool Whether to email out a followup.
748 * @return boolean success.
750 function addMessage($body,$by=false,$send_followup=false) {
752 $this->setMissingParamsError();
755 if (!forge_check_perm ('tracker',$this->ArtifactType->getID(),'submit')) {
756 $this->setError(_('You are not currently allowed to submit items to this tracker.'));
759 if (session_loggedin()) {
760 $user_id=user_getid();
761 $user =& user_get_object($user_id);
762 if (!$user || !is_object($user)) {
763 $this->setError('ERROR - Logged In User But Could Not Get User Object');
766 // we'll store this email even though it will likely never be used -
767 // since we have their correct user_id, we can join the USERS table to get email
768 $by=$user->getEmail();
771 if (!$by || !validate_email($by)) {
772 $this->setMissingParamsError();
778 $res = db_query_params ('INSERT INTO artifact_message (artifact_id,submitted_by,from_email,adddate,body) VALUES ($1,$2,$3,$4,$5)',
779 array ($this->getID(),
783 htmlspecialchars($body))) ;
785 $this->updateLastModifiedDate();
787 if ($send_followup) {
788 $this->mailFollowupEx($now, 2, false);
794 * addHistory - add an entry to audit trail.
796 * @param string The name of the field in the database being modified.
797 * @param string The former value of this field.
798 * @param array Array of data to change submitter and time of submit like: array('user' => 127, 'time' => 1234556789)
800 * @return boolean success.
802 function addHistory($field_name,$old_value, $importData = array()) {
803 if (array_key_exists('user', $importData)){
804 $user = $importData['user'];
806 if (!session_loggedin()) {
812 if (array_key_exists('time',$importData)){
813 $time = $importData['time'];
817 return db_query_params ('INSERT INTO artifact_history(artifact_id,field_name,old_value,mod_by,entrydate) VALUES ($1,$2,$3,$4,$5)',
818 array ($this->getID(),
826 * setStatus - set the status of this artifact.
828 * @param int The artifact status ID.
829 * @param int Closing date if status = 1
831 * @return boolean success.
833 function setStatus($status_id, $closingTime=False) {
835 $qpa = db_construct_qpa (false, 'UPDATE artifact SET status_id=$1', array ($status_id)) ;
836 if ($closingTime && $status_id != 1) {
838 $qpa = db_construct_qpa ($qpa, ', close_date=$1 ', array ($time)) ;
840 $qpa = db_construct_qpa ($qpa,
841 'WHERE artifact_id=$1 AND group_artifact_id=$2',
842 array ($this->getID(), $artifact_type_id)) ;
843 $result=db_query_qpa($qpa);
845 if (!$result || db_affected_rows($result) < 1) {
846 $this->setError('Error - update failed!'.db_error());
850 if (!$this->fetchData($this->getID())) {
863 * update - update the fields in this artifact.
865 * @param int The artifact priority.
866 * @param int The artifact status ID.
867 * @param int The person to which this artifact is to be assigned.
868 * @param string The artifact summary.
869 * @param int The canned response.
870 * @param string Attaching another comment.
871 * @param int Allows you to move an artifact to another type.
872 * @param array Array of extra fields like: array(15=>'foobar',22=>'1');
873 * @param string The description.
874 * @return boolean success.
876 function update($priority,$status_id,
877 $assigned_to,$summary,$canned_response,$details,$new_artifact_type_id,
878 $extra_fields=array(), $description='') {
881 Field-level permission checking
883 if (!forge_check_perm ('tracker', $this->ArtifactType->getID(), 'manager')) {
884 // Non-managers cannot modify these fields
885 $priority=$this->getPriority();
886 $summary=htmlspecialchars_decode($this->getSummary());
887 $description=htmlspecialchars_decode($this->getDetails());
888 $canned_response=100;
889 $new_artifact_type_id=$this->ArtifactType->getID();
890 $assigned_to=$this->getAssignedTo();
892 if (!forge_check_perm ('tracker', $this->ArtifactType->getID(), 'tech')) {
893 $this->setPermissionDeniedError();
898 // They may be using an extra field "status" box so we have to remap
899 // the status_id based on the extra field - this keeps the counters
902 if (count($extra_fields) > 0) {
903 $status_id=$this->ArtifactType->remapStatus($status_id,$extra_fields);
905 if (!$this->getID()) {
906 $this->setMissingParamsError('ID');
910 $this->setMissingParamsError(_('Assigned to'));
914 $this->setMissingParamsError(_('State'));
917 if (!$canned_response) {
918 $this->setMissingParamsError(_('Canned Response'));
921 if (!$new_artifact_type_id) {
922 $this->setMissingParamsError(_('Data Type'));
926 // Check that assigned_to is a tech for the tracker
927 if ($assigned_to != 100) {
928 if (!forge_check_perm_for_user ($assigned_to, 'tracker', $this->ArtifactType->getID(), 'tech')) {
929 $this->setError(_("Invalid assigned_to (assigned person is not a technician)"));
934 // Array to record which properties were changed
941 // Get a lock on this row in the database
943 $lock = db_query_params ('SELECT * FROM artifact WHERE artifact_id=$1 FOR UPDATE',
944 array ($this->getID())) ;
945 $artifact_type_id = $this->ArtifactType->getID();
947 // Attempt to move this Artifact to a new ArtifactType
948 // need to instantiate new ArtifactType obj and test perms
950 if ($new_artifact_type_id != $artifact_type_id) {
951 $newArtifactType= new ArtifactType($this->ArtifactType->getGroup(), $new_artifact_type_id);
952 if (!is_object($newArtifactType) || $newArtifactType->isError()) {
953 $this->setError(_('Could not move to new Artifact Type'). $newArtifactType->getErrorMessage());
957 // do they have perms for new ArtifactType?
958 if (!forge_check_perm ('tracker', $newArtifactType->getID(), 'manager')) {
959 $this->setPermissionDeniedError();
964 // Add a message to explain that the tracker was moved.
965 $message = 'Moved from '.$this->ArtifactType->getName().' to '.$newArtifactType->getName();
966 $this->addHistory('type', $this->ArtifactType->getName());
967 $this->addMessage($message,'',0);
969 // Fake change to send a mail when moved.
970 $changes['Type'] = 1;
972 // Try to remap extra_fields values when possible.
973 // If there is an extra_field with the same alias
974 // and if the value exist in the new one, then recode
975 // the value to keep it.
976 $new_extra_fields = array();
977 $ef = $this->ArtifactType->getExtraFields();
978 $ef_new = $newArtifactType->getExtraFields();
979 foreach($extra_fields as $extra_id => $value) {
980 $alias = preg_replace('/^@/', '', $ef[$extra_id]['alias']);
981 $type = $ef[$extra_id]['field_type'];
983 // Search if there is an extra field with the same alias.
985 foreach($ef_new as $id => $arr) {
986 if (preg_replace('/^@/', '', $arr['alias']) == $alias) {
991 // If we found one, copy for simple fields or
992 // search if there is the same value.
994 if ($type == ARTIFACT_EXTRAFIELDTYPE_TEXT ||
995 $type == ARTIFACT_EXTRAFIELDTYPE_INTEGER ||
996 $type == ARTIFACT_EXTRAFIELDTYPE_TEXTAREA ||
997 $type == ARTIFACT_EXTRAFIELDTYPE_RELATION) {
998 $new_extra_fields[$new_id] = $value;
1000 $values = $newArtifactType->getExtraFieldElements($new_id);
1001 if (is_array($value)) {
1002 foreach($value as $v) {
1003 $v = $this->ArtifactType->getElementName($v);
1004 foreach($values as $ev) {
1005 if ($ev['element_name'] == $v) {
1006 $new_extra_fields[$new_id][] = $ev['element_id'];
1011 $value = $this->ArtifactType->getElementName($value);
1012 foreach($values as $ev) {
1013 if ($ev['element_name'] == $value) {
1014 $new_extra_fields[$new_id] = $ev['element_id'];
1022 // Special case if moving to a tracker with custom status (previous has not).
1023 $custom_status_id = $newArtifactType->getCustomStatusField();
1024 if ($custom_status_id && !$new_extra_fields[$custom_status_id]) {
1025 $atw = new ArtifactWorkflow($newArtifactType, $custom_status_id);
1026 $nodes = $atw->getNextNodes(100);
1028 $new_extra_fields[$custom_status_id] = $nodes[0];
1032 $extra_fields = $new_extra_fields;
1034 $res = db_query_params ('DELETE FROM artifact_extra_field_data WHERE artifact_id=$1',
1035 array ($this->getID()));
1037 $this->setError(_('Removal of old artifact_extra_field_data failed: ').db_error());
1042 // Check that assigned_to is a tech in the new tracker
1043 if ($assigned_to != 100) {
1044 if (!forge_check_perm ('tracker', $newArtifactType->getID(), 'tech')) {
1049 //can't send a canned response when changing ArtifactType
1050 $canned_response=100;
1051 $this->ArtifactType =& $newArtifactType;
1055 $qpa = db_construct_qpa();
1056 $qpa = db_construct_qpa($qpa, 'UPDATE artifact SET');
1059 // handle audit trail
1062 if ($this->getStatusID() != $status_id) {
1063 $this->addHistory('status_id',$this->getStatusID());
1064 $qpa = db_construct_qpa($qpa, ' status_id=$1,', array($status_id));
1065 $changes['status'] = 1;
1068 if ($status_id != 1) {
1069 $qpa = db_construct_qpa($qpa, ' close_date=$1,', array($now));
1071 $qpa = db_construct_qpa($qpa, ' close_date=$1,', array(0));
1073 $this->addHistory('close_date', $this->getCloseDate());
1075 if ($this->getPriority() != $priority) {
1076 $this->addHistory('priority',$this->getPriority());
1077 $qpa = db_construct_qpa($qpa, ' priority=$1,', array($priority));
1078 $changes['priority'] = 1;
1082 if ($this->getAssignedTo() != $assigned_to) {
1083 $this->addHistory('assigned_to',$this->getAssignedTo());
1084 $qpa = db_construct_qpa($qpa, ' assigned_to=$1,', array($assigned_to));
1085 $changes['assigned_to'] = 1;
1088 if ($summary && ($this->getSummary() != htmlspecialchars($summary))) {
1089 $this->addHistory('summary', $this->getSummary());
1090 $qpa = db_construct_qpa($qpa, ' summary=$1,', array(htmlspecialchars($summary)));
1091 $changes['summary'] = 1;
1094 if ($description && ($this->getDetails() != htmlspecialchars($description))) {
1095 $this->addHistory('details', $this->getDetails());
1096 $qpa = db_construct_qpa($qpa, ' details=$1,', array(htmlspecialchars($description)));
1097 $changes['details'] = 1;
1101 $this->addMessage($details,'',0);
1102 $changes['details'] = 1;
1107 Finally, update the artifact itself
1110 $qpa = db_construct_qpa($qpa, ' group_artifact_id=$1
1111 WHERE artifact_id=$2 AND group_artifact_id=$3',
1112 array($new_artifact_type_id,
1113 $this->getID(), $artifact_type_id));
1114 $result = db_query_qpa($qpa);
1116 if (!$result || db_affected_rows($result) < 1) {
1117 $this->setError(_('Error - update failed!').db_error());
1121 if (!$this->fetchData($this->getID())) {
1128 //extra field handling
1130 if (!$this->updateExtraFields($extra_fields,$changes)) {
1131 //TODO - see if anything actually did change
1137 handle canned responses
1139 Instantiate ArtifactCanned and get the body of the message
1141 if ($canned_response != 100) {
1142 //don't care if this response is for this group - could be hacked
1143 $acr=new ArtifactCanned($this->ArtifactType,$canned_response);
1144 if (!$acr || !is_object($acr)) {
1145 $this->setError(_('Could Not Create Canned Response Object'));
1146 } elseif ($acr->isError()) {
1147 $this->setError($acr->getErrorMessage());
1149 $body = $acr->getBody();
1151 if (!$this->addMessage(util_unconvert_htmlspecialchars($body),'',0)) {
1158 $this->setError(_('Unable to Use Canned Response'));
1164 if ($update || $send_message){
1165 if (!empty($changes)) {
1166 // Send the email with changes
1167 $this->mailFollowupEx($now, 2, false, $changes);
1172 //nothing changed, so cancel the transaction
1173 $this->setError(_('Nothing Changed - Update Cancelled'));
1181 * updateLastModifiedDate - update the last_modified_date attribute of this artifact.
1183 * @return true on success / false on failure
1185 function updateLastModifiedDate() {
1186 $res = db_query_params ('UPDATE artifact SET last_modified_date=EXTRACT(EPOCH FROM now())::integer WHERE artifact_id=$1',
1187 array ($this->getID()));
1192 * assignToMe - assigns this artifact to current user
1194 * @return true on success / false on failure
1196 function assignToMe() {
1197 if (!session_loggedin() || !($this->ArtifactType->userIsAdmin() || $this->ArtifactType->userIsTechnician())) {
1198 $this->setPermissionDeniedError();
1202 $user_id = user_getid();
1203 $res = db_query_params ('UPDATE artifact SET assigned_to=$1 WHERE artifact_id=$2',
1204 array ($user_id, $this->getID())) ;
1206 $this->setError(_('Error updating assigned_to in artifact: ').db_error());
1209 $this->fetchData($this->getID());
1215 * updateExtraFields - updates the extra data elements for this artifact
1216 * e.g. the extra fields created and defined by the admin.
1218 * @param array Array of extra fields like: array(15=>'foobar',22=>'1');
1219 * @param array Array where changes to the extra fields should be logged
1220 * @return true on success / false on failure
1222 function updateExtraFields($extra_fields,&$changes){
1224 This is extremely complex code - we have take the passed array
1225 and see if we need to insert it into the db, and may have to
1226 add history rows for the audit trail
1228 start by getting all the available extra fields from ArtifactType
1229 For each field from ArtifacType, check the passed array -
1230 This prevents someone from passing bogus extra field entries - they will be ignored
1231 if the passed entry is blank, may have to force a default value
1232 if the passed array is different from the existing data in db,
1233 delete old entry and insert new entries, along with possible audit trail
1235 skip it and continue to next item
1240 //get a list of extra fields for this artifact_type
1241 $ef = $this->ArtifactType->getExtraFields();
1242 $efk=array_keys($ef);
1244 if (empty($extra_fields) && empty($ef)) {
1248 // If there is a status field, then check against the workflow.
1249 // Unless if we change type.
1250 if (! isset($changes['Type']) || !$changes['Type']) {
1251 for ($i=0; $i<count($efk); $i++) {
1253 $type=$ef[$efid]['field_type'];
1254 if ($type == ARTIFACT_EXTRAFIELDTYPE_STATUS) {
1255 // Get previous value.
1256 $res = db_query_params ('SELECT field_data FROM artifact_extra_field_data
1257 WHERE artifact_id=$1 AND extra_field_id=$2',
1258 array($this->getID(),
1260 $old = (db_numrows($res)>0) ? db_result($res,0,'field_data') : 100;
1261 if ($old != $extra_fields[$efid]) {
1262 $atw = new ArtifactWorkflow($this->ArtifactType, $efid);
1263 if (!$atw->checkEvent($old, $extra_fields[$efid])) {
1264 $this->setError('Workflow error: You are not authorized to change the Status ('.$old.' => '.$extra_fields[$efid].')');
1272 //now we'll update this artifact for each extra field
1273 for ($i=0; $i<count($efk); $i++) {
1275 $type=$ef[$efid]['field_type'];
1277 // check required fields
1278 if ($ef[$efid]['is_required']) {
1279 if (!array_key_exists($efid, $extra_fields)) {
1280 if ($type == ARTIFACT_EXTRAFIELDTYPE_STATUS) {
1281 $this->setError(_('Status Custom Field Must Be Set'));
1284 $this->setMissingParamsError($ef[$efid]['field_name']);
1289 if ($extra_fields[$efid] === '') {
1290 if ($type == ARTIFACT_EXTRAFIELDTYPE_STATUS) {
1291 $this->setError(_('Status Custom Field Must Be Set'));
1294 $this->setMissingParamsError($ef[$efid]['field_name']);
1299 if (($type == ARTIFACT_EXTRAFIELDTYPE_SELECT || $type == ARTIFACT_EXTRAFIELDTYPE_RADIO) &&
1300 $extra_fields[$efid] == '100') {
1301 $this->setMissingParamsError($ef[$efid]['field_name']);
1304 elseif (($type == ARTIFACT_EXTRAFIELDTYPE_MULTISELECT || $type == ARTIFACT_EXTRAFIELDTYPE_CHECKBOX) &&
1305 (count($extra_fields[$efid]) == 1 && $extra_fields[$efid][0] == '100')) {
1306 $this->setMissingParamsError($ef[$efid]['field_name']);
1313 // Force each field to have some value if it is a numeric field
1314 // text fields will just be purged and skipped
1316 if (!array_key_exists($efid, $extra_fields) || $extra_fields[$efid] === '') {
1317 if (($type == ARTIFACT_EXTRAFIELDTYPE_SELECT) || ($type == ARTIFACT_EXTRAFIELDTYPE_RADIO)) {
1318 $extra_fields[$efid]='100';
1319 } elseif (($type == ARTIFACT_EXTRAFIELDTYPE_MULTISELECT) || ($type == ARTIFACT_EXTRAFIELDTYPE_CHECKBOX)) {
1320 $extra_fields[$efid]=array('100');
1322 $resdel = db_query_params ('DELETE FROM artifact_extra_field_data WHERE artifact_id=$1 AND extra_field_id=$2',
1323 array ($this->getID(),
1330 // get the old rows of data
1332 $resd = db_query_params ('SELECT * FROM artifact_extra_field_data WHERE artifact_id=$1 AND extra_field_id=$2',
1333 array ($this->getID(),
1335 $rows=db_numrows($resd);
1336 if ($resd && $rows) {
1338 //POTENTIAL PROBLEM - no entry was there before, but adding one now - may need history
1341 // Compare for history purposes
1344 // these types have arrays associated to them, so they need
1345 // special handling to check for differences
1346 if ($type == ARTIFACT_EXTRAFIELDTYPE_MULTISELECT || $type == ARTIFACT_EXTRAFIELDTYPE_CHECKBOX) {
1347 // check the differences between the old values and the new values
1348 $old_values = util_result_column_to_array($resd,"field_data");
1350 $added_values = array_diff($extra_fields[$efid], $old_values);
1351 $deleted_values = array_diff($old_values, $extra_fields[$efid]);
1353 if (!empty($added_values) || !empty($deleted_values)) { // there are differences...
1354 $field_name = $ef[$efid]['field_name'];
1355 if (!preg_match('/^@/', $ef[$efid]['alias'])) {
1356 $changes["extra_fields"][$efid] = 1;
1359 $this->addHistory($field_name, $this->ArtifactType->getElementName(array_reverse($old_values)));
1362 $resdel = db_query_params ('DELETE FROM artifact_extra_field_data WHERE artifact_id=$1 AND extra_field_id=$2',
1363 array ($this->getID(),
1368 } elseif (db_result($resd,0,'field_data') == htmlspecialchars($extra_fields[$efid])) {
1369 //element did not change
1372 //element DID change - do a history entry
1373 $field_name = $ef[$efid]['field_name'];
1374 if (!preg_match('/^@/', $ef[$efid]['alias'])) {
1375 $changes["extra_fields"][$efid] = 1;
1377 $resdel = db_query_params ('DELETE FROM artifact_extra_field_data WHERE artifact_id=$1 AND extra_field_id=$2',
1378 array ($this->getID(),
1381 // Adding history with previous value.
1382 if (($type == ARTIFACT_EXTRAFIELDTYPE_SELECT) || ($type == ARTIFACT_EXTRAFIELDTYPE_RADIO) || ($type == ARTIFACT_EXTRAFIELDTYPE_STATUS)) {
1383 $this->addHistory($field_name,$this->ArtifactType->getElementName(db_result($resd,0,'field_data')));
1385 $this->addHistory($field_name, db_result($resd,0,'field_data'));
1391 //no history for this extra field exists
1396 // Some rewrite & consistency checks on the relation type field.
1398 // 1) Convert syntax [#NNN] to NNN
1399 // 2) Allow multiple spaces as separator.
1400 // 3) Ensure that only integers are given.
1401 // 4) Ensure that id corresponds to valid tracker id.
1403 if ($type == ARTIFACT_EXTRAFIELDTYPE_RELATION) {
1404 $value = preg_replace('/\[\#(\d+)\]/', "\\1", trim($extra_fields[$efid]));
1405 $value = preg_replace('/\\s+/', ' ', $value);
1407 foreach (explode(' ',$value) as $id) {
1408 if (preg_match('/^(\d+)$/', $id)) {
1409 // Control that the id is present in the db
1411 $res = db_query_params ('SELECT artifact_id FROM artifact WHERE artifact_id=$1',
1413 if (db_numrows($res) == 1) {
1416 $this->setError('Illegal id '.$id.', it\'s not a valid tracker id for field: '.$ef[$efid]['field_name'].'.'); // @todo: lang
1420 $this->setError('Illegal value '.$id.', only trackers id are allowed for field: '.$ef[$efid]['field_name'].'.'); // @todo: lang
1424 $extra_fields[$efid] = trim($new);
1427 // Ensure that only integer are allowed for type ARTIFACT_EXTRAFIELDTYPE_INTEGER
1428 if ($type == ARTIFACT_EXTRAFIELDTYPE_INTEGER) {
1429 $extra_fields[$efid] = trim($extra_fields[$efid]);
1430 if (!preg_match('/^[-+]?(\d+)$/', $extra_fields[$efid])) {
1431 $this->setError('Illegal value '.$extra_fields[$efid].' for field '.$ef[$efid]['field_name'].': Only integer is allowed.');
1434 if ($extra_fields[$efid] < -2147483648 || $extra_fields[$efid] > 2147483647) {
1435 $this->setError('Illegal value '.$extra_fields[$efid].' for field '.$ef[$efid]['field_name'].': Integer out of range (-2147483648 to +2147483647).');
1438 $extra_fields[$efid] = intval($extra_fields[$efid]);
1442 // See if anything was even passed for this extra_field_id
1444 if ($extra_fields[$efid] === '') {
1445 //nothing in field to update - text fields may be blank
1447 //determine the type of field and whether it should have multiple rows supporting it
1448 $type=$ef[$efid]['field_type'];
1449 if (($type == ARTIFACT_EXTRAFIELDTYPE_CHECKBOX) || ($type==ARTIFACT_EXTRAFIELDTYPE_MULTISELECT)) {
1451 $count=count($extra_fields[$efid]);
1452 for ($fin=0; $fin<$count; $fin++) {
1453 $res = db_query_params ('INSERT INTO artifact_extra_field_data (artifact_id,extra_field_id,field_data) VALUES ($1,$2,$3)',
1454 array ($this->getID(),
1456 $extra_fields[$efid][$fin])) ;
1458 $this->setError(db_error());
1465 $res = db_query_params ('INSERT INTO artifact_extra_field_data (artifact_id,extra_field_id,field_data) VALUES ($1,$2,$3)',
1466 array ($this->getID(),
1468 htmlspecialchars($extra_fields[$efid]))) ;
1470 $this->setError(db_error());
1477 unset($this->extra_field_data);
1480 $this->updateLastModifiedDate();
1486 * getExtraFieldData - get an array of data for the extra fields associated with this artifact
1488 * @return array array of data
1490 function &getExtraFieldData() {
1491 if (!isset($this->extra_field_data)) {
1492 $this->extra_field_data = array();
1493 $res = db_query_params ('SELECT * FROM artifact_extra_field_data WHERE artifact_id=$1 ORDER BY extra_field_id',
1494 array ($this->getID())) ;
1495 $ef = $this->ArtifactType->getExtraFields();
1496 while ($arr = db_fetch_array($res)) {
1497 $type=$ef[$arr['extra_field_id']]['field_type'];
1498 if (($type == ARTIFACT_EXTRAFIELDTYPE_CHECKBOX) || ($type==ARTIFACT_EXTRAFIELDTYPE_MULTISELECT)) {
1499 //accumulate a sub-array of values in cases where you may have multiple rows
1500 if (!array_key_exists($arr['extra_field_id'], $this->extra_field_data) || !is_array($this->extra_field_data[$arr['extra_field_id']])) {
1501 $this->extra_field_data[$arr['extra_field_id']] = array();
1503 $this->extra_field_data[$arr['extra_field_id']][]=$arr['field_data'];
1505 $this->extra_field_data[$arr['extra_field_id']]=$arr['field_data'];
1509 return $this->extra_field_data;
1513 * marker - adds the > symbol to fields that have been modified for the email message
1517 function marker($prop_name,$changes,$extra_field_id=0) {
1518 if ($prop_name == 'extra_fields' && isset($changes[$prop_name][$extra_field_id])) {
1520 } elseif ($prop_name != 'extra_fields' && isset($changes[$prop_name])) {
1528 * mailFollowupEx - send out an email update for this artifact.
1530 * @param time_t Time of the change
1531 * @param int (1) initial/creation (2) update.
1532 * @param array Array of additional addresses to mail to.
1533 * @param array Array of fields changed in this update .
1535 * @return boolean success.
1537 function mailFollowupEx($tm,$type,$more_addresses=false,$changes='') {
1539 $monitor_ids = array();
1545 $sess = session_get_user() ;
1546 if ($type == 1) { // Initial opening
1548 $body = $this->ArtifactType->Group->getUnixName() . '-' . $this->ArtifactType->getName() ." item #". $this->getID() .", was opened at ". date( _('Y-m-d H:i'), $this->getOpenDate() ) . " by " . $sess->getRealName () ;
1550 $body = $this->ArtifactType->Group->getUnixName() . '-' . $this->ArtifactType->getName() ." item #". $this->getID() .", was opened at ". date( _('Y-m-d H:i'), $this->getOpenDate() ) ;
1554 $body = $this->ArtifactType->Group->getUnixName() . '-' . $this->ArtifactType->getName() .
1555 " item #" . $this->getID() .
1556 " was changed at " .
1557 date(_('Y-m-d H:i'), $tm) . " by " .
1558 $sess->getRealName();
1560 $body = $this->ArtifactType->Group->getUnixName() . '-' . $this->ArtifactType->getName() .
1561 " item #" . $this->getID() .
1562 " was changed at " .
1563 date(_('Y-m-d H:i'), $tm);
1568 $body .= "\nYou can respond by visiting: ".
1569 "\n".util_make_url ('/tracker/?func=detail&atid='. $this->ArtifactType->getID() .
1570 "&aid=". $this->getID() .
1571 "&group_id=". $this->ArtifactType->Group->getID()) .
1572 "\nOr by replying to this e-mail entering your response between the following markers: ".
1573 "\n".ARTIFACT_MAIL_MARKER.
1574 "\n(enter your response here, only in plain text format)".
1575 "\n".ARTIFACT_MAIL_MARKER.
1577 $this->marker('status',$changes).
1578 "Status: ". $this->getStatusName() ."\n".
1579 $this->marker('priority',$changes).
1580 "Priority: ". $this->getPriority() ."\n".
1581 "Submitted By: ". $this->getSubmittedRealName() .
1582 " (". $this->getSubmittedUnixName(). ")"."\n".
1583 $this->marker('assigned_to',$changes).
1584 "Assigned to: ". $this->getAssignedRealName() .
1585 " (". $this->getAssignedUnixName(). ")"."\n".
1586 $this->marker('summary',$changes).
1587 "Summary: ". util_unconvert_htmlspecialchars( $this->getSummary() )." \n";
1589 // Now display the extra fields
1590 $efd = $this->getExtraFieldDataText();
1591 foreach ($efd as $efid => $ef) {
1592 $body .= $this->marker('extra_fields', $changes, $efid);
1593 $body .= $ef["name"].": ".$ef["value"]."\n";
1596 $subject='['. $this->ArtifactType->Group->getUnixName() . '-' . $this->ArtifactType->getName() . '][' . $this->getID() .'] '. util_unconvert_htmlspecialchars( $this->getSummary() );
1599 // get all the email addresses that are monitoring this request or the ArtifactType
1600 $monitor_ids = $this->getMonitorIds();
1602 // initial creation, we just get the users monitoring the ArtifactType
1603 $monitor_ids = $this->ArtifactType->getMonitorIds();
1607 if ($more_addresses) {
1608 $emails[] = $more_addresses;
1610 //we don't email the current user
1611 if ($this->getAssignedTo() != user_getid()) {
1612 $monitor_ids[] = $this->getAssignedTo();
1614 if ($this->getSubmittedBy() != user_getid()) {
1615 $monitor_ids[] = $this->getSubmittedBy();
1617 //initial submission
1619 //if an email is set for this ArtifactType
1620 //add that address to the BCC: list
1621 if ($this->ArtifactType->getEmailAddress()) {
1622 $emails[] = $this->ArtifactType->getEmailAddress();
1626 if ($this->ArtifactType->emailAll()) {
1627 $emails[] = $this->ArtifactType->getEmailAddress();
1631 $body .= "\n\nInitial Comment:".
1632 "\n".util_unconvert_htmlspecialchars( $this->getDetails() ) .
1633 "\n\n----------------------------------------------------------------------";
1637 Now include the followups
1639 $result2=$this->getMessages();
1641 $rows=db_numrows($result2);
1643 if ($result2 && $rows > 0) {
1644 for ($i=0; $i<$rows; $i++) {
1646 // for messages posted by non-logged-in users,
1647 // we grab the email they gave us
1649 // otherwise we use the confirmed one from the users table
1651 if (db_result($result2,$i,'user_id') == 100) {
1652 $emails[] = db_result($result2,$i,'from_email');
1654 $monitor_ids[] = db_result($result2,$i,'user_id');
1660 $body .= $this->marker('details',$changes);
1662 $body .= "Comment By: ". db_result($result2,$i,'realname') . " (".db_result($result2,$i,'user_name').")".
1663 "\nDate: ". date( _('Y-m-d H:i'),db_result($result2,$i,'adddate') ).
1665 "\n".util_unconvert_htmlspecialchars( db_result($result2,$i,'body') ).
1666 "\n\n----------------------------------------------------------------------";
1672 $body .= "\n\nYou can respond by visiting: ".
1673 "\n".util_make_url ('/tracker/?func=detail&atid='. $this->ArtifactType->getID() .
1674 "&aid=". $this->getID() .
1675 "&group_id=". $this->ArtifactType->Group->getID());
1677 //only send if some recipients were found
1678 if (count($emails) < 1 && count($monitor_ids) < 1) {
1682 if (count($monitor_ids) < 1) {
1683 $monitor_ids=array();
1685 $monitor_ids=array_unique($monitor_ids);
1688 $from = $this->ArtifactType->getReturnEmailAddress();
1689 $extra_headers = 'Reply-to: '.$from;
1691 // load the e-mail addresses of the users
1692 $users =& user_get_objects($monitor_ids);
1693 if (count($users) > 0) {
1694 foreach ($users as $user) {
1695 if ($user->getStatus() == "A") { //we are only sending emails to active users
1696 $emails[] = $user->getEmail();
1701 //now remove all duplicates from the email list
1702 if (count($emails) > 0) {
1703 $BCC=implode(',',array_unique($emails));
1704 util_send_message('',$subject,$body,$from,$BCC,'',$extra_headers);
1707 $this->sendSubjectMsg = $subject;
1708 $this->sendBodyMsg = $body;
1710 //util_handle_message($monitor_ids,$subject,$body,$BCC);
1716 * getExtraFieldDataText - Return the extra fields' data in a human-readable form.
1718 * @return array Array containing field ID => field name and value associated to it for
1721 function getExtraFieldDataText() {
1722 // First we get the list of extra fields and the data
1723 // associated to the fields
1724 $efs = $this->ArtifactType->getExtraFields();
1725 $efd = $this->getExtraFieldData();
1729 foreach ($efs as $efid => $ef) {
1730 $name = $ef["field_name"];
1731 $type = $ef["field_type"];
1733 // Get the value according to the type
1736 // for these types, the associated value comes straight
1737 case ARTIFACT_EXTRAFIELDTYPE_TEXT:
1738 case ARTIFACT_EXTRAFIELDTYPE_TEXTAREA:
1739 case ARTIFACT_EXTRAFIELDTYPE_RELATION:
1740 case ARTIFACT_EXTRAFIELDTYPE_INTEGER:
1741 if (isset($efd[$efid])) {
1742 $value = $efd[$efid];
1748 // the other types have and ID or an array of IDs associated to them
1750 if (isset($efd[$efid])) {
1751 $value = $this->ArtifactType->getElementName($efd[$efid]);
1757 $return[$efid] = array("name" => $name, "value" => $value, 'type' => $type);
1764 class ArtifactComparator {
1765 var $criterion = 'artifact_id' ;
1766 var $order = 'ASC' ;
1768 function Compare ($a, $b) {
1769 if ($this->order == 'DESC') {
1770 $c = $a ; $a = $b ; $b = $c ;
1772 switch ($this->criterion) {
1774 $namecmp = strcoll ($a->getSummary(),
1776 if ($namecmp != 0) {
1781 $namecmp = strcoll (user_get_object($a->getAssignedTo())->getRealName(),
1782 user_get_object($b->getAssignedTo())->getRealName()) ;
1783 if ($namecmp != 0) {
1787 case 'submitted_by':
1788 $namecmp = strcoll (user_get_object($a->getSubmittedBy())->getRealName(),
1789 user_get_object($b->getSubmittedBy())->getRealName()) ;
1790 if ($namecmp != 0) {
1795 $a_date = $a->getOpenDate() ;
1796 $b_date = $b->getOpenDate() ;
1797 return ($a_date < $b_date) ? -1 : 1;
1800 $a_date = $a->getCloseDate() ;
1801 $b_date = $b->getCloseDate() ;
1802 return ($a_date < $b_date) ? -1 : 1;
1804 case 'last_modified_date':
1805 $a_date = $a->getLastModifiedDate() ;
1806 $b_date = $b->getLastModifiedDate() ;
1807 return ($a_date < $b_date) ? -1 : 1;
1810 $a_prority = $a->getPriority() ;
1811 $b_prority = $b->getPriority() ;
1812 return ($a_prority < $b_prority) ? -1 : 1;
1815 $aa=$a->getExtraFieldDataText();
1816 $ba=$b->getExtraFieldDataText();
1817 if(!isset($this->criterion) || empty($this->criterion)) {
1821 $criterion = $this->criterion;
1823 $af=$aa[$criterion]['value'];
1824 $bf=$ba[$criterion]['value'];
1825 $namecmp = strcoll ($af,$bf) ;
1826 if ($namecmp != 0) {
1832 // When in doubt, sort on artifact ID
1833 $aid = $a->getID() ;
1834 $bid = $b->getID() ;
1838 return ($aid < $bid) ? -1 : 1;
1842 function sortArtifactList (&$list, $criterion='name', $order='ASC') {
1843 $cmp = new ArtifactComparator () ;
1844 $cmp->criterion = $criterion ;
1845 $cmp->order = $order ;
1847 return usort ($list, array ($cmp, 'Compare')) ;
1852 // c-file-style: "bsd"