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 object The ArtifactType object.
132 * @param integer (primary key from database OR complete assoc array)
133 * ONLY OPTIONAL WHEN YOU PLAN TO IMMEDIATELY CALL ->create()
134 * @return boolean success.
136 function __construct(&$ArtifactType, $data=false) {
139 $this->ArtifactType =& $ArtifactType;
141 //was ArtifactType legit?
142 if (!$ArtifactType || !is_object($ArtifactType)) {
143 $this->setError(_('No Valid Artifact Type'));
147 //did ArtifactType have an error?
148 if ($ArtifactType->isError()) {
149 $this->setError($ArtifactType->getErrorMessage());
154 // make sure this person has permission to view artifacts
156 if (!forge_check_perm ('tracker', $this->ArtifactType->getID(), 'read')) {
157 $this->setError(_('Only project members can view private artifact types'));
162 // set up data structures
165 if (is_array($data)) {
166 $this->data_array =& $data;
168 // Should verify ArtifactType ID
172 if (!$this->fetchData($data)) {
182 * create - construct a new Artifact in the database.
184 * @param string The artifact summary.
185 * @param string Details of the artifact.
186 * @param int The ID of the user to which this artifact is to be assigned.
187 * @param int The artifacts priority.
188 * @param array Array of extra fields like: array(15=>'foobar',22=>'1');
189 * @param array Array of data to change submitter and time of submit like: array('user' => 127, 'time' => 1234556789)
190 * @return id on success / false on failure.
192 function create( $summary, $details, $assigned_to=100, $priority=3, $extra_fields=array(), $importData = array()) {
194 // make sure this person has permission to add artifacts
200 if(array_key_exists('user', $importData)){
201 $user = $importData['user'];
203 if (!forge_check_perm ('tracker',$this->ArtifactType->getID(),'submit')) {
204 $this->setError(_('You are not currently allowed to submit items to this tracker.'));
208 if (session_loggedin()) {
219 $this->setError(_('Message Summary Is Required'));
223 $this->setError(_('Message Body Is Required'));
232 // if (!$status_id) {
233 $status_id=1; // on creation, status is set to "open"
236 // They may be using an extra field "status" box so we have to remap
237 // the status_id based on the extra field - this keeps the counters
240 $status_id=$this->ArtifactType->remapStatus($status_id,$extra_fields);
242 $this->setError(_('Error remapping status'));
247 if (array_key_exists('time',$importData)){
248 $time = $importData['time'];
252 $res = db_query_params ('INSERT INTO artifact
253 (group_artifact_id,status_id,priority,
254 submitted_by,assigned_to,open_date,summary,details)
255 VALUES ($1,$2,$3,$4,$5,$6,$7,$8)',
256 array ($this->ArtifactType->getID(),
262 htmlspecialchars($summary),
263 htmlspecialchars($details))) ;
265 $this->setError(db_error());
270 $artifact_id=db_insertid($res,'artifact','artifact_id');
272 if (!$res || !$artifact_id) {
273 $this->setError(db_error());
278 // Now set up our internal data structures
280 if (!$this->fetchData($artifact_id)) {
284 // the changes to the extra fields will be logged in this array.
285 // (we won't use it however)
286 $extra_field_changes = array();
287 if (!$this->updateExtraFields($extra_fields,$extra_field_changes)) {
293 // now send an email if appropriate
295 $this->mailFollowupEx(0, 1);
303 * fetchData - re-fetch the data for this Artifact from the database.
305 * @param int The artifact ID.
306 * @return boolean success.
308 function fetchData($artifact_id) {
309 $res = db_query_params ('SELECT * FROM artifact_vw WHERE artifact_id=$1 AND group_artifact_id=$2',
311 $this->ArtifactType->getID())) ;
312 if (!$res || db_numrows($res) < 1) {
313 $this->setError(_('Invalid Artifact ID'));
316 $this->data_array = db_fetch_array($res);
317 db_free_result($res);
322 * getArtifactType - get the ArtifactType Object this Artifact is associated with.
324 * @return object ArtifactType.
326 function &getArtifactType() {
327 return $this->ArtifactType;
331 * getID - get this ArtifactID.
333 * @return int The artifact_id #.
336 return $this->data_array['artifact_id'];
340 * getStringID - get a string display for this ArtifactID.
342 * @return string The artifact_id #.
344 function getStringID() {
345 return '[#'.$this->data_array['artifact_id'].']';
349 * getStatusID - get open/closed/deleted flag.
351 * @return int Status: (1) Open, (2) Closed, (3) Deleted.
353 function getStatusID() {
354 return $this->data_array['status_id'];
358 * getStatusName - get open/closed/deleted text.
360 * @return string The status name.
362 function getStatusName() {
363 return $this->data_array['status_name'];
367 * getCustomStatusName - get custom status value text.
369 * @return string The custom status name.
371 function getCustomStatusName() {
372 $custom_status_id = $this->ArtifactType->getCustomStatusField();
373 if ($custom_status_id) {
374 $result = db_query_params ('SELECT element_name FROM artifact_extra_field_elements aefe, artifact_extra_field_data aefd
375 WHERE artifact_id=$1 AND aefd.extra_field_id=$2 AND CAST(aefd.field_data AS INTEGER)=aefe.element_id',
376 array ($this->getID(), $custom_status_id)) ;
378 return db_result($result, 0, 'element_name');
381 return $this->data_array['status_name'];
385 * getPriority - get priority flag.
387 * @return int priority.
389 function getPriority() {
390 return $this->data_array['priority'];
394 * getSubmittedBy - get ID of submitter.
396 * @return int user_id of submitter.
398 function getSubmittedBy() {
399 return $this->data_array['submitted_by'];
403 * getSubmittedEmail - get email of submitter.
405 * @return string The email of submitter.
407 function getSubmittedEmail() {
408 return $this->data_array['submitted_email'];
412 * getSubmittedRealName - get real name of submitter.
414 * @return string The real name of submitter.
416 function getSubmittedRealName() {
417 return $this->data_array['submitted_realname'];
421 * getSubmittedUnixName - get login name of submitter.
423 * @return string The unix name of submitter.
425 function getSubmittedUnixName() {
426 return $this->data_array['submitted_unixname'];
430 * getAssignedTo - get ID of assignee.
432 * @return int user_id of assignee.
434 function getAssignedTo() {
435 return $this->data_array['assigned_to'];
439 * getAssignedEmail - get email of assignee.
441 * @return string The email of assignee.
443 function getAssignedEmail() {
444 return $this->data_array['assigned_email'];
448 * getAssignedRealName - get real name of assignee.
450 * @return string The real name of assignee.
452 function getAssignedRealName() {
453 return $this->data_array['assigned_realname'];
457 * getAssignedUnixName - get login name of assignee.
459 * @return string The unix name of assignee.
461 function getAssignedUnixName() {
462 return $this->data_array['assigned_unixname'];
466 * getOpenDate - get unix time of creation.
468 * @return int unix time.
470 function getOpenDate() {
471 return $this->data_array['open_date'];
475 * getCloseDate - get unix time of closure.
477 * @return int unix time.
479 function getCloseDate() {
480 return $this->data_array['close_date'];
484 * getLastModifiedDate - the last_modified_date of this task.
486 * @return int the last_modified_date.
488 function getLastModifiedDate() {
489 return $this->data_array['last_modified_date'];
493 * getSummary - get text summary of artifact.
495 * @return string The summary (subject).
497 function getSummary() {
498 return $this->data_array['summary'];
502 * getDetails - get text body (message) of artifact.
504 * @return string The body (message).
506 function getDetails() {
507 return $this->data_array['details'];
511 * delete - delete this tracker and all its related data.
513 * @param bool I'm Sure.
514 * @return bool true/false;
516 function delete($sure) {
518 $this->setMissingParamsError(_('Please tick all checkboxes.'));
521 if (!forge_check_perm ('tracker_admin', $this->ArtifactType->Group->getID())) {
522 $this->setPermissionDeniedError();
526 $res = db_query_params ('DELETE FROM artifact_extra_field_data WHERE artifact_id=$1',
527 array ($this->getID())) ;
529 $this->setError(_('Error deleting extra field data: ').db_error());
534 ArtifactStorage::instance()->deleteFromQuery('SELECT id FROM artifact_file WHERE artifact_id=$1',
535 array ($this->getID())) ;
537 $res = db_query_params ('DELETE FROM artifact_file WHERE artifact_id=$1',
538 array ($this->getID())) ;
540 $this->setError(_('Error deleting file from db: ').db_error());
542 ArtifactStorage::instance()->rollback();
545 $res = db_query_params ('DELETE FROM artifact_message WHERE artifact_id=$1',
546 array ($this->getID())) ;
548 $this->setError(_('Error deleting message: ').db_error());
550 ArtifactStorage::instance()->rollback();
553 $res = db_query_params ('DELETE FROM artifact_history WHERE artifact_id=$1',
554 array ($this->getID())) ;
556 $this->setError(_('Error deleting history: ').db_error());
558 ArtifactStorage::instance()->rollback();
561 $res = db_query_params ('DELETE FROM artifact_monitor WHERE artifact_id=$1',
562 array ($this->getID())) ;
564 $this->setError(_('Error deleting monitor: ').db_error());
566 ArtifactStorage::instance()->rollback();
569 $res = db_query_params ('DELETE FROM artifact WHERE artifact_id=$1',
570 array ($this->getID())) ;
572 $this->setError(_('Error deleting artifact: ').db_error());
574 ArtifactStorage::instance()->rollback();
578 if ($this->getStatusID() == 1) {
579 $res = db_query_params ('UPDATE artifact_counts_agg SET count=count-1,open_count=open_count-1
580 WHERE group_artifact_id=$1',
581 array ($this->getID())) ;
583 $this->setError(_('Error updating artifact counts: ').db_error());
585 ArtifactStorage::instance()->rollback();
588 } elseif ($this->getStatusID() == 2) {
589 $res = db_query_params ('UPDATE artifact_counts_agg SET count=count-1
590 WHERE group_artifact_id=$1',
591 array ($this->getID())) ;
593 $this->setError(_('Error updating artifact counts: ').db_error());
595 ArtifactStorage::instance()->rollback();
601 ArtifactStorage::instance()->commit();
606 * setMonitor - user can monitor this artifact.
608 * @return false - always false - always use the getErrorMessage() for feedback
610 function setMonitor() {
611 if (session_loggedin()) {
613 $user_id=user_getid();
614 $user =& user_get_object(user_getid());
617 //we don't want to include the "And email=" because
618 //a logged-in user's email may have changed
623 $this->setError(_('Valid Email Address Required'));
628 $res = db_query_params ('SELECT * FROM artifact_monitor WHERE artifact_id=$1 AND user_id=$2',
629 array ($this->getID(),
632 if (!$res || db_numrows($res) < 1) {
634 $res = db_query_params ('INSERT INTO artifact_monitor (artifact_id,user_id) VALUES ($1,$2)',
635 array ($this->getID(),
638 $this->setError(db_error());
641 $this->setError(_('Now Monitoring Artifact'));
645 //already monitoring - remove their monitor
646 db_query_params ('DELETE FROM artifact_monitor
649 array ($this->getID(),
651 $this->setError(_('Artifact Monitoring Deactivated'));
656 function isMonitoring() {
657 if (!session_loggedin()) {
660 $result = db_query_params ('SELECT count(*) AS count FROM artifact_monitor WHERE user_id=$1 AND artifact_id=$2',
663 $row_count = db_fetch_array($result);
664 return $result && $row_count['count'] > 0;
668 * getMonitorIds - array of email addresses monitoring this Artifact.
670 * @return array of email addresses monitoring this Artifact.
672 function getMonitorIds() {
673 $res = db_query_params ('SELECT user_id FROM artifact_monitor WHERE artifact_id=$1',
674 array ($this->getID())) ;
675 return array_unique(array_merge($this->ArtifactType->getMonitorIds(),util_result_column_to_array($res)));
679 * getHistory - returns a result set of audit trail for this support request.
681 * @return database result set.
683 function getHistory() {
684 return db_query_params ('SELECT * FROM artifact_history_user_vw WHERE artifact_id=$1 ORDER BY entrydate DESC',
685 array ($this->getID())) ;
689 * getMessages - get the list of messages attached to this artifact.
691 * @return database result set.
693 function getMessages($asc=false) {
694 return db_query_params ('SELECT * FROM artifact_message_user_vw WHERE artifact_id=$1 ORDER BY adddate ' . ($asc ? 'ASC' : 'DESC'),
695 array ($this->getID())) ;
699 * getMessageObjects - get an array of message objects.
701 * @return array Of ArtifactMessage objects.
703 function &getMessageObjects() {
704 $res=$this->getMessages();
706 while ($arr = db_fetch_array($res)) {
707 //$return[]=new ArtifactMessage($arr['artifact_id'],$arr);
708 $return[] = new ArtifactMessage($this, $arr);
714 * getFiles - get array of ArtifactFile's.
716 * @return array of ArtifactFile's.
718 function &getFiles() {
719 if (!isset($this->files)) {
720 $res = db_query_params ('SELECT id,artifact_id,description,filename,filesize,' .
721 'filetype,adddate,submitted_by,user_name,realname
722 FROM artifact_file_user_vw WHERE artifact_id=$1',
723 array ($this->getID())) ;
724 $rows=db_numrows($res);
726 for ($i=0; $i < $rows; $i++) {
727 $this->files[$i]=new ArtifactFile($this,db_fetch_array($res));
730 $this->files=array();
737 * getRelatedTasks - get array of related tasks
739 * @return Database result set
741 function getRelatedTasks() {
742 if (!$this->relatedtasks) {
743 $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
744 FROM project_task pt, project_group_list pgl, project_status ps
745 WHERE pt.group_project_id = pgl.group_project_id
746 AND ps.status_id = pt.status_id
747 AND EXISTS (SELECT project_task_id FROM project_task_artifact
748 WHERE project_task_id=pt.project_task_id
749 AND artifact_id = $1)',
750 array ($this->getID())) ;
752 return $this->relatedtasks;
756 * addMessage - attach a text message to this Artifact.
758 * @param string The message being attached.
759 * @param string Email address of message creator.
760 * @param bool Whether to email out a followup.
762 * @return boolean success.
764 function addMessage($body,$by=false,$send_followup=false) {
766 $this->setMissingParamsError();
769 if (!forge_check_perm ('tracker',$this->ArtifactType->getID(),'submit')) {
770 $this->setError(_('You are not currently allowed to submit items to this tracker.'));
773 if (session_loggedin()) {
774 $user_id=user_getid();
775 $user =& user_get_object($user_id);
776 if (!$user || !is_object($user)) {
777 $this->setError('ERROR - Logged In User But Could Not Get User Object');
780 // we'll store this email even though it will likely never be used -
781 // since we have their correct user_id, we can join the USERS table to get email
782 $by=$user->getEmail();
785 if (!$by || !validate_email($by)) {
786 $this->setMissingParamsError();
792 $res = db_query_params ('INSERT INTO artifact_message (artifact_id,submitted_by,from_email,adddate,body) VALUES ($1,$2,$3,$4,$5)',
793 array ($this->getID(),
797 htmlspecialchars($body))) ;
799 $this->updateLastModifiedDate();
801 if ($send_followup) {
802 $this->mailFollowupEx($now, 2, false);
808 * addHistory - add an entry to audit trail.
810 * @param string The name of the field in the database being modified.
811 * @param string The former value of this field.
812 * @param array Array of data to change submitter and time of submit like: array('user' => 127, 'time' => 1234556789)
814 * @return boolean success.
816 function addHistory($field_name,$old_value, $importData = array()) {
817 if (array_key_exists('user', $importData)){
818 $user = $importData['user'];
820 if (!session_loggedin()) {
826 if (array_key_exists('time',$importData)){
827 $time = $importData['time'];
831 return db_query_params ('INSERT INTO artifact_history(artifact_id,field_name,old_value,mod_by,entrydate) VALUES ($1,$2,$3,$4,$5)',
832 array ($this->getID(),
840 * setStatus - set the status of this artifact.
842 * @param int The artifact status ID.
843 * @param int Closing date if status = 1
845 * @return boolean success.
847 function setStatus($status_id, $closingTime=False) {
849 $qpa = db_construct_qpa (false, 'UPDATE artifact SET status_id=$1', array ($status_id)) ;
850 if ($closingTime && $status_id != 1) {
852 $qpa = db_construct_qpa ($qpa, ', close_date=$1 ', array ($time)) ;
854 $qpa = db_construct_qpa ($qpa,
855 'WHERE artifact_id=$1 AND group_artifact_id=$2',
856 array ($this->getID(), $artifact_type_id)) ;
857 $result=db_query_qpa($qpa);
859 if (!$result || db_affected_rows($result) < 1) {
860 $this->setError('Error - update failed!'.db_error());
864 if (!$this->fetchData($this->getID())) {
877 * update - update the fields in this artifact.
879 * @param int The artifact priority.
880 * @param int The artifact status ID.
881 * @param int The person to which this artifact is to be assigned.
882 * @param string The artifact summary.
883 * @param int The canned response.
884 * @param string Attaching another comment.
885 * @param int Allows you to move an artifact to another type.
886 * @param array Array of extra fields like: array(15=>'foobar',22=>'1');
887 * @param string The description.
888 * @return boolean success.
890 function update($priority,$status_id,
891 $assigned_to,$summary,$canned_response,$details,$new_artifact_type_id,
892 $extra_fields=array(), $description='') {
895 Field-level permission checking
897 if (!forge_check_perm ('tracker', $this->ArtifactType->getID(), 'manager')) {
898 // Non-managers cannot modify these fields
899 $priority=$this->getPriority();
900 $summary=htmlspecialchars_decode($this->getSummary());
901 $description=htmlspecialchars_decode($this->getDetails());
902 $canned_response=100;
903 $new_artifact_type_id=$this->ArtifactType->getID();
904 $assigned_to=$this->getAssignedTo();
906 if (!forge_check_perm ('tracker', $this->ArtifactType->getID(), 'tech')) {
907 $this->setPermissionDeniedError();
912 // They may be using an extra field "status" box so we have to remap
913 // the status_id based on the extra field - this keeps the counters
916 if (count($extra_fields) > 0) {
917 $status_id=$this->ArtifactType->remapStatus($status_id,$extra_fields);
919 if (!$this->getID()) {
920 $this->setMissingParamsError('ID');
924 $this->setMissingParamsError(_('Assigned to'));
928 $this->setMissingParamsError(_('State'));
931 if (!$canned_response) {
932 $this->setMissingParamsError(_('Canned Response'));
935 if (!$new_artifact_type_id) {
936 $this->setMissingParamsError(_('Data Type'));
940 // Check that assigned_to is a tech for the tracker
941 if ($assigned_to != 100) {
942 if (!forge_check_perm_for_user ($assigned_to, 'tracker', $this->ArtifactType->getID(), 'tech')) {
943 $this->setError(_("Invalid assigned_to (assigned person is not a technician)"));
948 // Array to record which properties were changed
955 // Get a lock on this row in the database
957 $lock = db_query_params ('SELECT * FROM artifact WHERE artifact_id=$1 FOR UPDATE',
958 array ($this->getID())) ;
959 $artifact_type_id = $this->ArtifactType->getID();
961 // Attempt to move this Artifact to a new ArtifactType
962 // need to instantiate new ArtifactType obj and test perms
964 if ($new_artifact_type_id != $artifact_type_id) {
965 $newArtifactType= new ArtifactType($this->ArtifactType->getGroup(), $new_artifact_type_id);
966 if (!is_object($newArtifactType) || $newArtifactType->isError()) {
967 $this->setError(_('Could not move to new Artifact Type'). $newArtifactType->getErrorMessage());
971 // do they have perms for new ArtifactType?
972 if (!forge_check_perm ('tracker', $newArtifactType->getID(), 'manager')) {
973 $this->setPermissionDeniedError();
978 // Add a message to explain that the tracker was moved.
979 $message = 'Moved from '.$this->ArtifactType->getName().' to '.$newArtifactType->getName();
980 $this->addHistory('type', $this->ArtifactType->getName());
981 $this->addMessage($message,'',0);
983 // Fake change to send a mail when moved.
984 $changes['Type'] = 1;
986 // Try to remap extra_fields values when possible.
987 // If there is an extra_field with the same alias
988 // and if the value exist in the new one, then recode
989 // the value to keep it.
990 $new_extra_fields = array();
991 $ef = $this->ArtifactType->getExtraFields();
992 $ef_new = $newArtifactType->getExtraFields();
993 foreach($extra_fields as $extra_id => $value) {
994 $alias = preg_replace('/^@/', '', $ef[$extra_id]['alias']);
995 $type = $ef[$extra_id]['field_type'];
997 // Search if there is an extra field with the same alias.
999 foreach($ef_new as $id => $arr) {
1000 if (preg_replace('/^@/', '', $arr['alias']) == $alias) {
1005 // If we found one, copy for simple fields or
1006 // search if there is the same value.
1008 if ($type == ARTIFACT_EXTRAFIELDTYPE_TEXT ||
1009 $type == ARTIFACT_EXTRAFIELDTYPE_INTEGER ||
1010 $type == ARTIFACT_EXTRAFIELDTYPE_TEXTAREA ||
1011 $type == ARTIFACT_EXTRAFIELDTYPE_RELATION) {
1012 $new_extra_fields[$new_id] = $value;
1014 $values = $newArtifactType->getExtraFieldElements($new_id);
1015 if (is_array($value)) {
1016 foreach($value as $v) {
1017 $v = $this->ArtifactType->getElementName($v);
1018 foreach($values as $ev) {
1019 if ($ev['element_name'] == $v) {
1020 $new_extra_fields[$new_id][] = $ev['element_id'];
1025 $value = $this->ArtifactType->getElementName($value);
1026 foreach($values as $ev) {
1027 if ($ev['element_name'] == $value) {
1028 $new_extra_fields[$new_id] = $ev['element_id'];
1036 // Special case if moving to a tracker with custom status (previous has not).
1037 $custom_status_id = $newArtifactType->getCustomStatusField();
1038 if ($custom_status_id && !$new_extra_fields[$custom_status_id]) {
1039 $atw = new ArtifactWorkflow($newArtifactType, $custom_status_id);
1040 $nodes = $atw->getNextNodes(100);
1042 $new_extra_fields[$custom_status_id] = $nodes[0];
1046 $extra_fields = $new_extra_fields;
1048 $res = db_query_params ('DELETE FROM artifact_extra_field_data WHERE artifact_id=$1',
1049 array ($this->getID()));
1051 $this->setError(_('Removal of old artifact_extra_field_data failed: ').db_error());
1056 // Check that assigned_to is a tech in the new tracker
1057 if ($assigned_to != 100) {
1058 if (!forge_check_perm ('tracker', $newArtifactType->getID(), 'tech')) {
1063 //can't send a canned response when changing ArtifactType
1064 $canned_response=100;
1065 $this->ArtifactType =& $newArtifactType;
1069 $qpa = db_construct_qpa();
1070 $qpa = db_construct_qpa($qpa, 'UPDATE artifact SET');
1073 // handle audit trail
1076 if ($this->getStatusID() != $status_id) {
1077 $this->addHistory('status_id',$this->getStatusID());
1078 $qpa = db_construct_qpa($qpa, ' status_id=$1,', array($status_id));
1079 $changes['status'] = 1;
1082 if ($status_id != 1) {
1083 $qpa = db_construct_qpa($qpa, ' close_date=$1,', array($now));
1085 $qpa = db_construct_qpa($qpa, ' close_date=$1,', array(0));
1087 $this->addHistory('close_date', $this->getCloseDate());
1089 if ($this->getPriority() != $priority) {
1090 $this->addHistory('priority',$this->getPriority());
1091 $qpa = db_construct_qpa($qpa, ' priority=$1,', array($priority));
1092 $changes['priority'] = 1;
1096 if ($this->getAssignedTo() != $assigned_to) {
1097 $this->addHistory('assigned_to',$this->getAssignedTo());
1098 $qpa = db_construct_qpa($qpa, ' assigned_to=$1,', array($assigned_to));
1099 $changes['assigned_to'] = 1;
1102 if ($summary && ($this->getSummary() != htmlspecialchars($summary))) {
1103 $this->addHistory('summary', $this->getSummary());
1104 $qpa = db_construct_qpa($qpa, ' summary=$1,', array(htmlspecialchars($summary)));
1105 $changes['summary'] = 1;
1108 if ($description && ($this->getDetails() != htmlspecialchars($description))) {
1109 $this->addHistory('details', $this->getDetails());
1110 $qpa = db_construct_qpa($qpa, ' details=$1,', array(htmlspecialchars($description)));
1111 $changes['details'] = 1;
1115 $this->addMessage($details,'',0);
1116 $changes['details'] = 1;
1121 Finally, update the artifact itself
1124 $qpa = db_construct_qpa($qpa, ' group_artifact_id=$1
1125 WHERE artifact_id=$2 AND group_artifact_id=$3',
1126 array($new_artifact_type_id,
1127 $this->getID(), $artifact_type_id));
1128 $result = db_query_qpa($qpa);
1130 if (!$result || db_affected_rows($result) < 1) {
1131 $this->setError(_('Error - update failed!').db_error());
1135 if (!$this->fetchData($this->getID())) {
1142 //extra field handling
1144 if (!$this->updateExtraFields($extra_fields,$changes)) {
1145 //TODO - see if anything actually did change
1151 handle canned responses
1153 Instantiate ArtifactCanned and get the body of the message
1155 if ($canned_response != 100) {
1156 //don't care if this response is for this group - could be hacked
1157 $acr=new ArtifactCanned($this->ArtifactType,$canned_response);
1158 if (!$acr || !is_object($acr)) {
1159 $this->setError(_('Could Not Create Canned Response Object'));
1160 } elseif ($acr->isError()) {
1161 $this->setError($acr->getErrorMessage());
1163 $body = $acr->getBody();
1165 if (!$this->addMessage(util_unconvert_htmlspecialchars($body),'',0)) {
1172 $this->setError(_('Unable to Use Canned Response'));
1178 if ($update || $send_message){
1179 if (!empty($changes)) {
1180 // Send the email with changes
1181 $this->mailFollowupEx($now, 2, false, $changes);
1186 //nothing changed, so cancel the transaction
1187 $this->setError(_('Nothing Changed - Update Cancelled'));
1195 * updateLastModifiedDate - update the last_modified_date attribute of this artifact.
1197 * @return true on success / false on failure
1199 function updateLastModifiedDate() {
1200 $res = db_query_params ('UPDATE artifact SET last_modified_date=EXTRACT(EPOCH FROM now())::integer WHERE artifact_id=$1',
1201 array ($this->getID()));
1206 * assignToMe - assigns this artifact to current user
1208 * @return true on success / false on failure
1210 function assignToMe() {
1211 if (!session_loggedin() || !($this->ArtifactType->userIsAdmin() || $this->ArtifactType->userIsTechnician())) {
1212 $this->setPermissionDeniedError();
1216 $user_id = user_getid();
1217 $res = db_query_params ('UPDATE artifact SET assigned_to=$1 WHERE artifact_id=$2',
1218 array ($user_id, $this->getID())) ;
1220 $this->setError(_('Error updating assigned_to in artifact: ').db_error());
1223 $this->fetchData($this->getID());
1229 * updateExtraFields - updates the extra data elements for this artifact
1230 * e.g. the extra fields created and defined by the admin.
1232 * @param array Array of extra fields like: array(15=>'foobar',22=>'1');
1233 * @param array Array where changes to the extra fields should be logged
1234 * @return true on success / false on failure
1236 function updateExtraFields($extra_fields,&$changes){
1238 This is extremely complex code - we have take the passed array
1239 and see if we need to insert it into the db, and may have to
1240 add history rows for the audit trail
1242 start by getting all the available extra fields from ArtifactType
1243 For each field from ArtifacType, check the passed array -
1244 This prevents someone from passing bogus extra field entries - they will be ignored
1245 if the passed entry is blank, may have to force a default value
1246 if the passed array is different from the existing data in db,
1247 delete old entry and insert new entries, along with possible audit trail
1249 skip it and continue to next item
1254 //get a list of extra fields for this artifact_type
1255 $ef = $this->ArtifactType->getExtraFields();
1256 $efk=array_keys($ef);
1258 if (empty($extra_fields) && empty($ef)) {
1262 // If there is a status field, then check against the workflow.
1263 // Unless if we change type.
1264 if (! isset($changes['Type']) || !$changes['Type']) {
1265 for ($i=0; $i<count($efk); $i++) {
1267 $type=$ef[$efid]['field_type'];
1268 if ($type == ARTIFACT_EXTRAFIELDTYPE_STATUS) {
1269 // Get previous value.
1270 $res = db_query_params ('SELECT field_data FROM artifact_extra_field_data
1271 WHERE artifact_id=$1 AND extra_field_id=$2',
1272 array($this->getID(),
1274 $old = (db_numrows($res)>0) ? db_result($res,0,'field_data') : 100;
1275 if ($old != $extra_fields[$efid]) {
1276 $atw = new ArtifactWorkflow($this->ArtifactType, $efid);
1277 if (!$atw->checkEvent($old, $extra_fields[$efid])) {
1278 $this->setError('Workflow error: You are not authorized to change the Status ('.$old.' => '.$extra_fields[$efid].')');
1286 //now we'll update this artifact for each extra field
1287 for ($i=0; $i<count($efk); $i++) {
1289 $type=$ef[$efid]['field_type'];
1291 // check required fields
1292 if ($ef[$efid]['is_required']) {
1293 if (!array_key_exists($efid, $extra_fields)) {
1294 if ($type == ARTIFACT_EXTRAFIELDTYPE_STATUS) {
1295 $this->setError(_('Status Custom Field Must Be Set'));
1298 $this->setMissingParamsError($ef[$efid]['field_name']);
1303 if ($extra_fields[$efid] === '') {
1304 if ($type == ARTIFACT_EXTRAFIELDTYPE_STATUS) {
1305 $this->setError(_('Status Custom Field Must Be Set'));
1308 $this->setMissingParamsError($ef[$efid]['field_name']);
1313 if (($type == ARTIFACT_EXTRAFIELDTYPE_SELECT || $type == ARTIFACT_EXTRAFIELDTYPE_RADIO) &&
1314 $extra_fields[$efid] == '100') {
1315 $this->setMissingParamsError($ef[$efid]['field_name']);
1318 elseif (($type == ARTIFACT_EXTRAFIELDTYPE_MULTISELECT || $type == ARTIFACT_EXTRAFIELDTYPE_CHECKBOX) &&
1319 (count($extra_fields[$efid]) == 1 && $extra_fields[$efid][0] == '100')) {
1320 $this->setMissingParamsError($ef[$efid]['field_name']);
1327 // Force each field to have some value if it is a numeric field
1328 // text fields will just be purged and skipped
1330 if (!array_key_exists($efid, $extra_fields) || $extra_fields[$efid] === '') {
1331 if (($type == ARTIFACT_EXTRAFIELDTYPE_SELECT) || ($type == ARTIFACT_EXTRAFIELDTYPE_RADIO)) {
1332 $extra_fields[$efid]='100';
1333 } elseif (($type == ARTIFACT_EXTRAFIELDTYPE_MULTISELECT) || ($type == ARTIFACT_EXTRAFIELDTYPE_CHECKBOX)) {
1334 $extra_fields[$efid]=array('100');
1336 $resdel = db_query_params ('DELETE FROM artifact_extra_field_data WHERE artifact_id=$1 AND extra_field_id=$2',
1337 array ($this->getID(),
1344 // get the old rows of data
1346 $resd = db_query_params ('SELECT * FROM artifact_extra_field_data WHERE artifact_id=$1 AND extra_field_id=$2',
1347 array ($this->getID(),
1349 $rows=db_numrows($resd);
1350 if ($resd && $rows) {
1352 //POTENTIAL PROBLEM - no entry was there before, but adding one now - may need history
1355 // Compare for history purposes
1358 // these types have arrays associated to them, so they need
1359 // special handling to check for differences
1360 if ($type == ARTIFACT_EXTRAFIELDTYPE_MULTISELECT || $type == ARTIFACT_EXTRAFIELDTYPE_CHECKBOX) {
1361 // check the differences between the old values and the new values
1362 $old_values = util_result_column_to_array($resd,"field_data");
1364 $added_values = array_diff($extra_fields[$efid], $old_values);
1365 $deleted_values = array_diff($old_values, $extra_fields[$efid]);
1367 if (!empty($added_values) || !empty($deleted_values)) { // there are differences...
1368 $field_name = $ef[$efid]['field_name'];
1369 if (!preg_match('/^@/', $ef[$efid]['alias'])) {
1370 $changes["extra_fields"][$efid] = 1;
1373 $this->addHistory($field_name, $this->ArtifactType->getElementName(array_reverse($old_values)));
1376 $resdel = db_query_params ('DELETE FROM artifact_extra_field_data WHERE artifact_id=$1 AND extra_field_id=$2',
1377 array ($this->getID(),
1382 } elseif (db_result($resd,0,'field_data') == htmlspecialchars($extra_fields[$efid])) {
1383 //element did not change
1386 //element DID change - do a history entry
1387 $field_name = $ef[$efid]['field_name'];
1388 if (!preg_match('/^@/', $ef[$efid]['alias'])) {
1389 $changes["extra_fields"][$efid] = 1;
1391 $resdel = db_query_params ('DELETE FROM artifact_extra_field_data WHERE artifact_id=$1 AND extra_field_id=$2',
1392 array ($this->getID(),
1395 // Adding history with previous value.
1396 if (($type == ARTIFACT_EXTRAFIELDTYPE_SELECT) || ($type == ARTIFACT_EXTRAFIELDTYPE_RADIO) || ($type == ARTIFACT_EXTRAFIELDTYPE_STATUS)) {
1397 $this->addHistory($field_name,$this->ArtifactType->getElementName(db_result($resd,0,'field_data')));
1399 $this->addHistory($field_name, db_result($resd,0,'field_data'));
1405 //no history for this extra field exists
1410 // Some rewrite & consistency checks on the relation type field.
1412 // 1) Convert syntax [#NNN] to NNN
1413 // 2) Allow multiple spaces as separator.
1414 // 3) Ensure that only integers are given.
1415 // 4) Ensure that id corresponds to valid tracker id.
1417 if ($type == ARTIFACT_EXTRAFIELDTYPE_RELATION) {
1418 $value = preg_replace('/\[\#(\d+)\]/', "\\1", trim($extra_fields[$efid]));
1419 $value = preg_replace('/\\s+/', ' ', $value);
1421 foreach (explode(' ',$value) as $id) {
1422 if (preg_match('/^(\d+)$/', $id)) {
1423 // Control that the id is present in the db
1425 $res = db_query_params ('SELECT artifact_id FROM artifact WHERE artifact_id=$1',
1427 if (db_numrows($res) == 1) {
1430 $this->setError('Illegal id '.$id.', it\'s not a valid tracker id for field: '.$ef[$efid]['field_name'].'.'); // @todo: lang
1434 $this->setError('Illegal value '.$id.', only trackers id are allowed for field: '.$ef[$efid]['field_name'].'.'); // @todo: lang
1438 $extra_fields[$efid] = trim($new);
1441 // Ensure that only integer are allowed for type ARTIFACT_EXTRAFIELDTYPE_INTEGER
1442 if ($type == ARTIFACT_EXTRAFIELDTYPE_INTEGER) {
1443 $extra_fields[$efid] = trim($extra_fields[$efid]);
1444 if (!preg_match('/^[-+]?(\d+)$/', $extra_fields[$efid])) {
1445 $this->setError('Illegal value '.$extra_fields[$efid].' for field '.$ef[$efid]['field_name'].': Only integer is allowed.');
1448 if ($extra_fields[$efid] < -2147483648 || $extra_fields[$efid] > 2147483647) {
1449 $this->setError('Illegal value '.$extra_fields[$efid].' for field '.$ef[$efid]['field_name'].': Integer out of range (-2147483648 to +2147483647).');
1452 $extra_fields[$efid] = intval($extra_fields[$efid]);
1456 // See if anything was even passed for this extra_field_id
1458 if ($extra_fields[$efid] === '') {
1459 //nothing in field to update - text fields may be blank
1461 //determine the type of field and whether it should have multiple rows supporting it
1462 $type=$ef[$efid]['field_type'];
1463 if (($type == ARTIFACT_EXTRAFIELDTYPE_CHECKBOX) || ($type==ARTIFACT_EXTRAFIELDTYPE_MULTISELECT)) {
1465 $count=count($extra_fields[$efid]);
1466 for ($fin=0; $fin<$count; $fin++) {
1467 $res = db_query_params ('INSERT INTO artifact_extra_field_data (artifact_id,extra_field_id,field_data) VALUES ($1,$2,$3)',
1468 array ($this->getID(),
1470 $extra_fields[$efid][$fin])) ;
1472 $this->setError(db_error());
1479 $res = db_query_params ('INSERT INTO artifact_extra_field_data (artifact_id,extra_field_id,field_data) VALUES ($1,$2,$3)',
1480 array ($this->getID(),
1482 htmlspecialchars($extra_fields[$efid]))) ;
1484 $this->setError(db_error());
1491 unset($this->extra_field_data);
1494 $this->updateLastModifiedDate();
1500 * getExtraFieldData - get an array of data for the extra fields associated with this artifact
1502 * @return array array of data
1504 function &getExtraFieldData() {
1505 if (!isset($this->extra_field_data)) {
1506 $this->extra_field_data = array();
1507 $res = db_query_params ('SELECT * FROM artifact_extra_field_data WHERE artifact_id=$1 ORDER BY extra_field_id',
1508 array ($this->getID())) ;
1509 $ef = $this->ArtifactType->getExtraFields();
1510 while ($arr = db_fetch_array($res)) {
1511 $type=$ef[$arr['extra_field_id']]['field_type'];
1512 if (($type == ARTIFACT_EXTRAFIELDTYPE_CHECKBOX) || ($type==ARTIFACT_EXTRAFIELDTYPE_MULTISELECT)) {
1513 //accumulate a sub-array of values in cases where you may have multiple rows
1514 if (!array_key_exists($arr['extra_field_id'], $this->extra_field_data) || !is_array($this->extra_field_data[$arr['extra_field_id']])) {
1515 $this->extra_field_data[$arr['extra_field_id']] = array();
1517 $this->extra_field_data[$arr['extra_field_id']][]=$arr['field_data'];
1519 $this->extra_field_data[$arr['extra_field_id']]=$arr['field_data'];
1523 return $this->extra_field_data;
1527 * marker - adds the > symbol to fields that have been modified for the email message
1531 function marker($prop_name,$changes,$extra_field_id=0) {
1532 if ($prop_name == 'extra_fields' && isset($changes[$prop_name][$extra_field_id])) {
1534 } elseif ($prop_name != 'extra_fields' && isset($changes[$prop_name])) {
1542 * mailFollowupEx - send out an email update for this artifact.
1544 * @param time_t Time of the change
1545 * @param int (1) initial/creation (2) update.
1546 * @param array Array of additional addresses to mail to.
1547 * @param array Array of fields changed in this update .
1549 * @return boolean success.
1551 function mailFollowupEx($tm,$type,$more_addresses=false,$changes='') {
1553 $monitor_ids = array();
1559 $sess = session_get_user() ;
1560 if ($type == 1) { // Initial opening
1562 $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 () ;
1564 $body = $this->ArtifactType->Group->getUnixName() . '-' . $this->ArtifactType->getName() ." item #". $this->getID() .", was opened at ". date( _('Y-m-d H:i'), $this->getOpenDate() ) ;
1568 $body = $this->ArtifactType->Group->getUnixName() . '-' . $this->ArtifactType->getName() .
1569 " item #" . $this->getID() .
1570 " was changed at " .
1571 date(_('Y-m-d H:i'), $tm) . " by " .
1572 $sess->getRealName();
1574 $body = $this->ArtifactType->Group->getUnixName() . '-' . $this->ArtifactType->getName() .
1575 " item #" . $this->getID() .
1576 " was changed at " .
1577 date(_('Y-m-d H:i'), $tm);
1582 $body .= "\nYou can respond by visiting: ".
1583 "\n".util_make_url ('/tracker/?func=detail&atid='. $this->ArtifactType->getID() .
1584 "&aid=". $this->getID() .
1585 "&group_id=". $this->ArtifactType->Group->getID()) .
1586 "\nOr by replying to this e-mail entering your response between the following markers: ".
1587 "\n".ARTIFACT_MAIL_MARKER.
1588 "\n(enter your response here, only in plain text format)".
1589 "\n".ARTIFACT_MAIL_MARKER.
1591 $this->marker('status',$changes).
1592 "Status: ". $this->getStatusName() ."\n".
1593 $this->marker('priority',$changes).
1594 "Priority: ". $this->getPriority() ."\n".
1595 "Submitted By: ". $this->getSubmittedRealName() .
1596 " (". $this->getSubmittedUnixName(). ")"."\n".
1597 $this->marker('assigned_to',$changes).
1598 "Assigned to: ". $this->getAssignedRealName() .
1599 " (". $this->getAssignedUnixName(). ")"."\n".
1600 $this->marker('summary',$changes).
1601 "Summary: ". util_unconvert_htmlspecialchars( $this->getSummary() )." \n";
1603 // Now display the extra fields
1604 $efd = $this->getExtraFieldDataText();
1605 foreach ($efd as $efid => $ef) {
1606 $body .= $this->marker('extra_fields', $changes, $efid);
1607 $body .= $ef["name"].": ".$ef["value"]."\n";
1610 $subject='['. $this->ArtifactType->Group->getUnixName() . '-' . $this->ArtifactType->getName() . '][' . $this->getID() .'] '. util_unconvert_htmlspecialchars( $this->getSummary() );
1613 // get all the email addresses that are monitoring this request or the ArtifactType
1614 $monitor_ids = $this->getMonitorIds();
1616 // initial creation, we just get the users monitoring the ArtifactType
1617 $monitor_ids = $this->ArtifactType->getMonitorIds();
1621 if ($more_addresses) {
1622 $emails[] = $more_addresses;
1624 //we don't email the current user
1625 if ($this->getAssignedTo() != user_getid()) {
1626 $monitor_ids[] = $this->getAssignedTo();
1628 if ($this->getSubmittedBy() != user_getid()) {
1629 $monitor_ids[] = $this->getSubmittedBy();
1631 //initial submission
1633 //if an email is set for this ArtifactType
1634 //add that address to the BCC: list
1635 if ($this->ArtifactType->getEmailAddress()) {
1636 $emails[] = $this->ArtifactType->getEmailAddress();
1640 if ($this->ArtifactType->emailAll()) {
1641 $emails[] = $this->ArtifactType->getEmailAddress();
1645 $body .= "\n\nInitial Comment:".
1646 "\n".util_unconvert_htmlspecialchars( $this->getDetails() ) .
1647 "\n\n----------------------------------------------------------------------";
1651 Now include the followups
1653 $result2=$this->getMessages();
1655 $rows=db_numrows($result2);
1657 if ($result2 && $rows > 0) {
1658 for ($i=0; $i<$rows; $i++) {
1660 // for messages posted by non-logged-in users,
1661 // we grab the email they gave us
1663 // otherwise we use the confirmed one from the users table
1665 if (db_result($result2,$i,'user_id') == 100) {
1666 $emails[] = db_result($result2,$i,'from_email');
1668 $monitor_ids[] = db_result($result2,$i,'user_id');
1674 $body .= $this->marker('details',$changes);
1676 $body .= "Comment By: ". db_result($result2,$i,'realname') . " (".db_result($result2,$i,'user_name').")".
1677 "\nDate: ". date( _('Y-m-d H:i'),db_result($result2,$i,'adddate') ).
1679 "\n".util_unconvert_htmlspecialchars( db_result($result2,$i,'body') ).
1680 "\n\n----------------------------------------------------------------------";
1686 $body .= "\n\nYou can respond by visiting: ".
1687 "\n".util_make_url ('/tracker/?func=detail&atid='. $this->ArtifactType->getID() .
1688 "&aid=". $this->getID() .
1689 "&group_id=". $this->ArtifactType->Group->getID());
1691 //only send if some recipients were found
1692 if (count($emails) < 1 && count($monitor_ids) < 1) {
1696 if (count($monitor_ids) < 1) {
1697 $monitor_ids=array();
1699 $monitor_ids=array_unique($monitor_ids);
1702 $from = $this->ArtifactType->getReturnEmailAddress();
1703 $extra_headers = 'Reply-to: '.$from;
1705 // load the e-mail addresses of the users
1706 $users =& user_get_objects($monitor_ids);
1707 if (count($users) > 0) {
1708 foreach ($users as $user) {
1709 if ($user->getStatus() == "A") { //we are only sending emails to active users
1710 $emails[] = $user->getEmail();
1715 //now remove all duplicates from the email list
1716 if (count($emails) > 0) {
1717 $BCC=implode(',',array_unique($emails));
1718 util_send_message('',$subject,$body,$from,$BCC,'',$extra_headers);
1721 $this->sendSubjectMsg = $subject;
1722 $this->sendBodyMsg = $body;
1724 //util_handle_message($monitor_ids,$subject,$body,$BCC);
1730 * getExtraFieldDataText - Return the extra fields' data in a human-readable form.
1732 * @return array Array containing field ID => field name and value associated to it for
1735 function getExtraFieldDataText() {
1736 // First we get the list of extra fields and the data
1737 // associated to the fields
1738 $efs = $this->ArtifactType->getExtraFields();
1739 $efd = $this->getExtraFieldData();
1743 foreach ($efs as $efid => $ef) {
1744 $name = $ef["field_name"];
1745 $type = $ef["field_type"];
1747 // Get the value according to the type
1750 // for these types, the associated value comes straight
1751 case ARTIFACT_EXTRAFIELDTYPE_TEXT:
1752 case ARTIFACT_EXTRAFIELDTYPE_TEXTAREA:
1753 case ARTIFACT_EXTRAFIELDTYPE_RELATION:
1754 case ARTIFACT_EXTRAFIELDTYPE_INTEGER:
1755 if (isset($efd[$efid])) {
1756 $value = $efd[$efid];
1762 // the other types have and ID or an array of IDs associated to them
1764 if (isset($efd[$efid])) {
1765 $value = $this->ArtifactType->getElementName($efd[$efid]);
1771 $return[$efid] = array("name" => $name, "value" => $value, 'type' => $type);
1778 class ArtifactComparator {
1779 var $criterion = 'artifact_id' ;
1780 var $order = 'ASC' ;
1782 function Compare ($a, $b) {
1783 if ($this->order == 'DESC') {
1784 $c = $a ; $a = $b ; $b = $c ;
1786 switch ($this->criterion) {
1788 $namecmp = strcoll ($a->getSummary(),
1790 if ($namecmp != 0) {
1795 $namecmp = strcoll (user_get_object($a->getAssignedTo())->getRealName(),
1796 user_get_object($b->getAssignedTo())->getRealName()) ;
1797 if ($namecmp != 0) {
1801 case 'submitted_by':
1802 $namecmp = strcoll (user_get_object($a->getSubmittedBy())->getRealName(),
1803 user_get_object($b->getSubmittedBy())->getRealName()) ;
1804 if ($namecmp != 0) {
1809 $a_date = $a->getOpenDate() ;
1810 $b_date = $b->getOpenDate() ;
1811 return ($a_date < $b_date) ? -1 : 1;
1814 $a_date = $a->getCloseDate() ;
1815 $b_date = $b->getCloseDate() ;
1816 return ($a_date < $b_date) ? -1 : 1;
1818 case 'last_modified_date':
1819 $a_date = $a->getLastModifiedDate() ;
1820 $b_date = $b->getLastModifiedDate() ;
1821 return ($a_date < $b_date) ? -1 : 1;
1824 $a_prority = $a->getPriority() ;
1825 $b_prority = $b->getPriority() ;
1826 return ($a_prority < $b_prority) ? -1 : 1;
1829 $aa=$a->getExtraFieldDataText();
1830 $ba=$b->getExtraFieldDataText();
1831 if(!isset($this->criterion) || empty($this->criterion)) {
1835 $criterion = $this->criterion;
1837 $af=$aa[$criterion]['value'];
1838 $bf=$ba[$criterion]['value'];
1839 $namecmp = strcoll ($af,$bf) ;
1840 if ($namecmp != 0) {
1846 // When in doubt, sort on artifact ID
1847 $aid = $a->getID() ;
1848 $bid = $b->getID() ;
1852 return ($aid < $bid) ? -1 : 1;
1856 function sortArtifactList (&$list, $criterion='name', $order='ASC') {
1857 $cmp = new ArtifactComparator () ;
1858 $cmp->criterion = $criterion ;
1859 $cmp->order = $order ;
1861 return usort ($list, array ($cmp, 'Compare')) ;
1866 // c-file-style: "bsd"