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
197 if (!$this->ArtifactType->isPublic()) {
199 // Only admins can post/modify private artifacts
203 // ape: Disabled, private means only restricted to members. So, no special rules #2503.
204 // if (!forge_check_perm ('tracker_admin', $this->ArtifactType->Group->getID()) {
205 // $this->setError(_('Only Artifact Admins Can Modify Private Artifact Types'));
213 if(array_key_exists('user', $importData)){
214 $user = $importData['user'];
216 if (session_loggedin()) {
219 if ($this->ArtifactType->allowsAnon()) {
222 $this->setError(_('This Artifact Type Does Not Allow Anonymous Submissions. Please Login.'));
232 $this->setError(_('Message Summary Is Required'));
236 $this->setError(_('Message Body Is Required'));
245 // if (!$status_id) {
246 $status_id=1; // on creation, status is set to "open"
249 // They may be using an extra field "status" box so we have to remap
250 // the status_id based on the extra field - this keeps the counters
253 $status_id=$this->ArtifactType->remapStatus($status_id,$extra_fields);
255 $this->setError(_('Error remapping status'));
260 if (array_key_exists('time',$importData)){
261 $time = $importData['time'];
265 $res = db_query_params ('INSERT INTO artifact
266 (group_artifact_id,status_id,priority,
267 submitted_by,assigned_to,open_date,summary,details)
268 VALUES ($1,$2,$3,$4,$5,$6,$7,$8)',
269 array ($this->ArtifactType->getID(),
275 htmlspecialchars($summary),
276 htmlspecialchars($details))) ;
278 $this->setError(db_error());
283 $artifact_id=db_insertid($res,'artifact','artifact_id');
285 if (!$res || !$artifact_id) {
286 $this->setError(db_error());
291 // Now set up our internal data structures
293 if (!$this->fetchData($artifact_id)) {
297 // the changes to the extra fields will be logged in this array.
298 // (we won't use it however)
299 $extra_field_changes = array();
300 if (!$this->updateExtraFields($extra_fields,$extra_field_changes)) {
306 // now send an email if appropriate
308 $this->mailFollowupEx(0, 1);
316 * fetchData - re-fetch the data for this Artifact from the database.
318 * @param int The artifact ID.
319 * @return boolean success.
321 function fetchData($artifact_id) {
322 $res = db_query_params ('SELECT * FROM artifact_vw WHERE artifact_id=$1 AND group_artifact_id=$2',
324 $this->ArtifactType->getID())) ;
325 if (!$res || db_numrows($res) < 1) {
326 $this->setError(_('Invalid Artifact ID'));
329 $this->data_array = db_fetch_array($res);
330 db_free_result($res);
335 * getArtifactType - get the ArtifactType Object this Artifact is associated with.
337 * @return object ArtifactType.
339 function &getArtifactType() {
340 return $this->ArtifactType;
344 * getID - get this ArtifactID.
346 * @return int The artifact_id #.
349 return $this->data_array['artifact_id'];
353 * getStringID - get a string display for this ArtifactID.
355 * @return string The artifact_id #.
357 function getStringID() {
358 return '[#'.$this->data_array['artifact_id'].']';
362 * getStatusID - get open/closed/deleted flag.
364 * @return int Status: (1) Open, (2) Closed, (3) Deleted.
366 function getStatusID() {
367 return $this->data_array['status_id'];
371 * getStatusName - get open/closed/deleted text.
373 * @return string The status name.
375 function getStatusName() {
376 return $this->data_array['status_name'];
380 * getCustomStatusName - get custom status value text.
382 * @return string The custom status name.
384 function getCustomStatusName() {
385 $custom_status_id = $this->ArtifactType->getCustomStatusField();
386 if ($custom_status_id) {
387 $result = db_query_params ('SELECT element_name FROM artifact_extra_field_elements aefe, artifact_extra_field_data aefd
388 WHERE artifact_id=$1 AND aefd.extra_field_id=$2 AND CAST(aefd.field_data AS INTEGER)=aefe.element_id',
389 array ($this->getID(), $custom_status_id)) ;
391 return db_result($result, 0, 'element_name');
394 return $this->data_array['status_name'];
398 * getPriority - get priority flag.
400 * @return int priority.
402 function getPriority() {
403 return $this->data_array['priority'];
407 * getSubmittedBy - get ID of submitter.
409 * @return int user_id of submitter.
411 function getSubmittedBy() {
412 return $this->data_array['submitted_by'];
416 * getSubmittedEmail - get email of submitter.
418 * @return string The email of submitter.
420 function getSubmittedEmail() {
421 return $this->data_array['submitted_email'];
425 * getSubmittedRealName - get real name of submitter.
427 * @return string The real name of submitter.
429 function getSubmittedRealName() {
430 return $this->data_array['submitted_realname'];
434 * getSubmittedUnixName - get login name of submitter.
436 * @return string The unix name of submitter.
438 function getSubmittedUnixName() {
439 return $this->data_array['submitted_unixname'];
443 * getAssignedTo - get ID of assignee.
445 * @return int user_id of assignee.
447 function getAssignedTo() {
448 return $this->data_array['assigned_to'];
452 * getAssignedEmail - get email of assignee.
454 * @return string The email of assignee.
456 function getAssignedEmail() {
457 return $this->data_array['assigned_email'];
461 * getAssignedRealName - get real name of assignee.
463 * @return string The real name of assignee.
465 function getAssignedRealName() {
466 return $this->data_array['assigned_realname'];
470 * getAssignedUnixName - get login name of assignee.
472 * @return string The unix name of assignee.
474 function getAssignedUnixName() {
475 return $this->data_array['assigned_unixname'];
479 * getOpenDate - get unix time of creation.
481 * @return int unix time.
483 function getOpenDate() {
484 return $this->data_array['open_date'];
488 * getCloseDate - get unix time of closure.
490 * @return int unix time.
492 function getCloseDate() {
493 return $this->data_array['close_date'];
497 * getLastModifiedDate - the last_modified_date of this task.
499 * @return int the last_modified_date.
501 function getLastModifiedDate() {
502 return $this->data_array['last_modified_date'];
506 * getSummary - get text summary of artifact.
508 * @return string The summary (subject).
510 function getSummary() {
511 return $this->data_array['summary'];
515 * getDetails - get text body (message) of artifact.
517 * @return string The body (message).
519 function getDetails() {
520 return $this->data_array['details'];
524 * delete - delete this tracker and all its related data.
526 * @param bool I'm Sure.
527 * @return bool true/false;
529 function delete($sure) {
531 $this->setMissingParamsError(_('Please tick all checkboxes.'));
534 if (!forge_check_perm ('tracker_admin', $this->ArtifactType->Group->getID())) {
535 $this->setPermissionDeniedError();
539 $res = db_query_params ('DELETE FROM artifact_extra_field_data WHERE artifact_id=$1',
540 array ($this->getID())) ;
542 $this->setError(_('Error deleting extra field data: ').db_error());
547 ArtifactStorage::instance()->deleteFromQuery('SELECT id FROM artifact_file WHERE artifact_id=$1',
548 array ($this->getID())) ;
550 $res = db_query_params ('DELETE FROM artifact_file WHERE artifact_id=$1',
551 array ($this->getID())) ;
553 $this->setError(_('Error deleting file from db: ').db_error());
555 ArtifactStorage::instance()->rollback();
558 $res = db_query_params ('DELETE FROM artifact_message WHERE artifact_id=$1',
559 array ($this->getID())) ;
561 $this->setError(_('Error deleting message: ').db_error());
563 ArtifactStorage::instance()->rollback();
566 $res = db_query_params ('DELETE FROM artifact_history WHERE artifact_id=$1',
567 array ($this->getID())) ;
569 $this->setError(_('Error deleting history: ').db_error());
571 ArtifactStorage::instance()->rollback();
574 $res = db_query_params ('DELETE FROM artifact_monitor WHERE artifact_id=$1',
575 array ($this->getID())) ;
577 $this->setError(_('Error deleting monitor: ').db_error());
579 ArtifactStorage::instance()->rollback();
582 $res = db_query_params ('DELETE FROM artifact WHERE artifact_id=$1',
583 array ($this->getID())) ;
585 $this->setError(_('Error deleting artifact: ').db_error());
587 ArtifactStorage::instance()->rollback();
591 if ($this->getStatusID() == 1) {
592 $res = db_query_params ('UPDATE artifact_counts_agg SET count=count-1,open_count=open_count-1
593 WHERE group_artifact_id=$1',
594 array ($this->getID())) ;
596 $this->setError(_('Error updating artifact counts: ').db_error());
598 ArtifactStorage::instance()->rollback();
601 } elseif ($this->getStatusID() == 2) {
602 $res = db_query_params ('UPDATE artifact_counts_agg SET count=count-1
603 WHERE group_artifact_id=$1',
604 array ($this->getID())) ;
606 $this->setError(_('Error updating artifact counts: ').db_error());
608 ArtifactStorage::instance()->rollback();
614 ArtifactStorage::instance()->commit();
619 * setMonitor - user can monitor this artifact.
621 * @return false - always false - always use the getErrorMessage() for feedback
623 function setMonitor() {
624 if (session_loggedin()) {
626 $user_id=user_getid();
627 $user =& user_get_object(user_getid());
630 //we don't want to include the "And email=" because
631 //a logged-in user's email may have changed
636 $this->setError(_('Valid Email Address Required'));
641 $res = db_query_params ('SELECT * FROM artifact_monitor WHERE artifact_id=$1 AND user_id=$2',
642 array ($this->getID(),
645 if (!$res || db_numrows($res) < 1) {
647 $res = db_query_params ('INSERT INTO artifact_monitor (artifact_id,user_id) VALUES ($1,$2)',
648 array ($this->getID(),
651 $this->setError(db_error());
654 $this->setError(_('Now Monitoring Artifact'));
658 //already monitoring - remove their monitor
659 db_query_params ('DELETE FROM artifact_monitor
662 array ($this->getID(),
664 $this->setError(_('Artifact Monitoring Deactivated'));
669 function isMonitoring() {
670 if (!session_loggedin()) {
673 $result = db_query_params ('SELECT count(*) AS count FROM artifact_monitor WHERE user_id=$1 AND artifact_id=$2',
676 $row_count = db_fetch_array($result);
677 return $result && $row_count['count'] > 0;
681 * getMonitorIds - array of email addresses monitoring this Artifact.
683 * @return array of email addresses monitoring this Artifact.
685 function getMonitorIds() {
686 $res = db_query_params ('SELECT user_id FROM artifact_monitor WHERE artifact_id=$1',
687 array ($this->getID())) ;
688 return array_unique(array_merge($this->ArtifactType->getMonitorIds(),util_result_column_to_array($res)));
692 * getHistory - returns a result set of audit trail for this support request.
694 * @return database result set.
696 function getHistory() {
697 return db_query_params ('SELECT * FROM artifact_history_user_vw WHERE artifact_id=$1 ORDER BY entrydate DESC',
698 array ($this->getID())) ;
702 * getMessages - get the list of messages attached to this artifact.
704 * @return database result set.
706 function getMessages($asc=false) {
707 return db_query_params ('SELECT * FROM artifact_message_user_vw WHERE artifact_id=$1 ORDER BY adddate ' . ($asc ? 'ASC' : 'DESC'),
708 array ($this->getID())) ;
712 * getMessageObjects - get an array of message objects.
714 * @return array Of ArtifactMessage objects.
716 function &getMessageObjects() {
717 $res=$this->getMessages();
719 while ($arr = db_fetch_array($res)) {
720 //$return[]=new ArtifactMessage($arr['artifact_id'],$arr);
721 $return[] = new ArtifactMessage($this, $arr);
727 * getFiles - get array of ArtifactFile's.
729 * @return array of ArtifactFile's.
731 function &getFiles() {
732 if (!isset($this->files)) {
733 $res = db_query_params ('SELECT id,artifact_id,description,filename,filesize,' .
734 'filetype,adddate,submitted_by,user_name,realname
735 FROM artifact_file_user_vw WHERE artifact_id=$1',
736 array ($this->getID())) ;
737 $rows=db_numrows($res);
739 for ($i=0; $i < $rows; $i++) {
740 $this->files[$i]=new ArtifactFile($this,db_fetch_array($res));
743 $this->files=array();
750 * getRelatedTasks - get array of related tasks
752 * @return Database result set
754 function getRelatedTasks() {
755 if (!$this->relatedtasks) {
756 $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
757 FROM project_task pt, project_group_list pgl, project_status ps
758 WHERE pt.group_project_id = pgl.group_project_id
759 AND ps.status_id = pt.status_id
760 AND EXISTS (SELECT project_task_id FROM project_task_artifact
761 WHERE project_task_id=pt.project_task_id
762 AND artifact_id = $1)',
763 array ($this->getID())) ;
765 return $this->relatedtasks;
769 * addMessage - attach a text message to this Artifact.
771 * @param string The message being attached.
772 * @param string Email address of message creator.
773 * @param bool Whether to email out a followup.
775 * @return boolean success.
777 function addMessage($body,$by=false,$send_followup=false) {
779 $this->setMissingParamsError();
782 if (session_loggedin()) {
783 $user_id=user_getid();
784 $user =& user_get_object($user_id);
785 if (!$user || !is_object($user)) {
786 $this->setError('ERROR - Logged In User But Could Not Get User Object');
789 // we'll store this email even though it will likely never be used -
790 // since we have their correct user_id, we can join the USERS table to get email
791 $by=$user->getEmail();
792 } elseif (!$this->ArtifactType->allowsAnon()) {
793 $this->setError(_('This Artifact Type Does Not Allow Anonymous Submissions. Please Login.'));
797 if (!$by || !validate_email($by)) {
798 $this->setMissingParamsError();
804 $res = db_query_params ('INSERT INTO artifact_message (artifact_id,submitted_by,from_email,adddate,body) VALUES ($1,$2,$3,$4,$5)',
805 array ($this->getID(),
809 htmlspecialchars($body))) ;
811 $this->updateLastModifiedDate();
813 if ($send_followup) {
814 $this->mailFollowupEx($now, 2, false);
820 * addHistory - add an entry to audit trail.
822 * @param string The name of the field in the database being modified.
823 * @param string The former value of this field.
824 * @param array Array of data to change submitter and time of submit like: array('user' => 127, 'time' => 1234556789)
826 * @return boolean success.
828 function addHistory($field_name,$old_value, $importData = array()) {
829 if (array_key_exists('user', $importData)){
830 $user = $importData['user'];
832 if (!session_loggedin()) {
838 if (array_key_exists('time',$importData)){
839 $time = $importData['time'];
843 return db_query_params ('INSERT INTO artifact_history(artifact_id,field_name,old_value,mod_by,entrydate) VALUES ($1,$2,$3,$4,$5)',
844 array ($this->getID(),
852 * setStatus - set the status of this artifact.
854 * @param int The artifact status ID.
855 * @param int Closing date if status = 1
857 * @return boolean success.
859 function setStatus($status_id, $closingTime=False) {
861 $qpa = db_construct_qpa (false, 'UPDATE artifact SET status_id=$1', array ($status_id)) ;
862 if ($closingTime && $status_id != 1) {
864 $qpa = db_construct_qpa ($qpa, ', close_date=$1 ', array ($time)) ;
866 $qpa = db_construct_qpa ($qpa,
867 'WHERE artifact_id=$1 AND group_artifact_id=$2',
868 array ($this->getID(), $artifact_type_id)) ;
869 $result=db_query_qpa($qpa);
871 if (!$result || db_affected_rows($result) < 1) {
872 $this->setError('Error - update failed!'.db_error());
876 if (!$this->fetchData($this->getID())) {
889 * update - update the fields in this artifact.
891 * @param int The artifact priority.
892 * @param int The artifact status ID.
893 * @param int The person to which this artifact is to be assigned.
894 * @param string The artifact summary.
895 * @param int The canned response.
896 * @param string Attaching another comment.
897 * @param int Allows you to move an artifact to another type.
898 * @param array Array of extra fields like: array(15=>'foobar',22=>'1');
899 * @param string The description.
900 * @return boolean success.
902 function update($priority,$status_id,
903 $assigned_to,$summary,$canned_response,$details,$new_artifact_type_id,
904 $extra_fields=array(), $description='') {
907 Field-level permission checking
909 if (!forge_check_perm ('tracker', $this->ArtifactType->getID(), 'manager')) {
910 // Non-managers cannot modify these fields
911 $priority=$this->getPriority();
912 $summary=htmlspecialchars_decode($this->getSummary());
913 $description=htmlspecialchars_decode($this->getDetails());
914 $canned_response=100;
915 $new_artifact_type_id=$this->ArtifactType->getID();
916 $assigned_to=$this->getAssignedTo();
918 if (!forge_check_perm ('tracker', $this->ArtifactType->getID(), 'tech')) {
919 $this->setPermissionDeniedError();
924 // They may be using an extra field "status" box so we have to remap
925 // the status_id based on the extra field - this keeps the counters
928 if (count($extra_fields) > 0) {
929 $status_id=$this->ArtifactType->remapStatus($status_id,$extra_fields);
931 if (!$this->getID()) {
932 $this->setMissingParamsError('ID');
936 $this->setMissingParamsError(_('Assigned to'));
940 $this->setMissingParamsError(_('State'));
943 if (!$canned_response) {
944 $this->setMissingParamsError(_('Canned Response'));
947 if (!$new_artifact_type_id) {
948 $this->setMissingParamsError(_('Data Type'));
952 // Check that assigned_to is a tech for the tracker
953 if ($assigned_to != 100) {
954 if (!forge_check_perm_for_user ($assigned_to, 'tracker', $this->ArtifactType->getID(), 'tech')) {
955 $this->setError(_("Invalid assigned_to (assigned person is not a technician)"));
960 // Array to record which properties were changed
967 // Get a lock on this row in the database
969 $lock = db_query_params ('SELECT * FROM artifact WHERE artifact_id=$1 FOR UPDATE',
970 array ($this->getID())) ;
971 $artifact_type_id = $this->ArtifactType->getID();
973 // Attempt to move this Artifact to a new ArtifactType
974 // need to instantiate new ArtifactType obj and test perms
976 if ($new_artifact_type_id != $artifact_type_id) {
977 $newArtifactType= new ArtifactType($this->ArtifactType->getGroup(), $new_artifact_type_id);
978 if (!is_object($newArtifactType) || $newArtifactType->isError()) {
979 $this->setError(_('Could not move to new Artifact Type'). $newArtifactType->getErrorMessage());
983 // do they have perms for new ArtifactType?
984 if (!forge_check_perm ('tracker', $newArtifactType->getID(), 'manager')) {
985 $this->setPermissionDeniedError();
990 // Add a message to explain that the tracker was moved.
991 $message = 'Moved from '.$this->ArtifactType->getName().' to '.$newArtifactType->getName();
992 $this->addHistory('type', $this->ArtifactType->getName());
993 $this->addMessage($message,'',0);
995 // Fake change to send a mail when moved.
996 $changes['Type'] = 1;
998 // Try to remap extra_fields values when possible.
999 // If there is an extra_field with the same alias
1000 // and if the value exist in the new one, then recode
1001 // the value to keep it.
1002 $new_extra_fields = array();
1003 $ef = $this->ArtifactType->getExtraFields();
1004 $ef_new = $newArtifactType->getExtraFields();
1005 foreach($extra_fields as $extra_id => $value) {
1006 $alias = preg_replace('/^@/', '', $ef[$extra_id]['alias']);
1007 $type = $ef[$extra_id]['field_type'];
1009 // Search if there is an extra field with the same alias.
1011 foreach($ef_new as $id => $arr) {
1012 if (preg_replace('/^@/', '', $arr['alias']) == $alias) {
1017 // If we found one, copy for simple fields or
1018 // search if there is the same value.
1020 if ($type == ARTIFACT_EXTRAFIELDTYPE_TEXT ||
1021 $type == ARTIFACT_EXTRAFIELDTYPE_INTEGER ||
1022 $type == ARTIFACT_EXTRAFIELDTYPE_TEXTAREA ||
1023 $type == ARTIFACT_EXTRAFIELDTYPE_RELATION) {
1024 $new_extra_fields[$new_id] = $value;
1026 $values = $newArtifactType->getExtraFieldElements($new_id);
1027 if (is_array($value)) {
1028 foreach($value as $v) {
1029 $v = $this->ArtifactType->getElementName($v);
1030 foreach($values as $ev) {
1031 if ($ev['element_name'] == $v) {
1032 $new_extra_fields[$new_id][] = $ev['element_id'];
1037 $value = $this->ArtifactType->getElementName($value);
1038 foreach($values as $ev) {
1039 if ($ev['element_name'] == $value) {
1040 $new_extra_fields[$new_id] = $ev['element_id'];
1048 // Special case if moving to a tracker with custom status (previous has not).
1049 $custom_status_id = $newArtifactType->getCustomStatusField();
1050 if ($custom_status_id && !$new_extra_fields[$custom_status_id]) {
1051 $atw = new ArtifactWorkflow($newArtifactType, $custom_status_id);
1052 $nodes = $atw->getNextNodes(100);
1054 $new_extra_fields[$custom_status_id] = $nodes[0];
1058 $extra_fields = $new_extra_fields;
1060 $res = db_query_params ('DELETE FROM artifact_extra_field_data WHERE artifact_id=$1',
1061 array ($this->getID()));
1063 $this->setError(_('Removal of old artifact_extra_field_data failed: ').db_error());
1068 // Check that assigned_to is a tech in the new tracker
1069 if ($assigned_to != 100) {
1070 if (!forge_check_perm ('tracker', $newArtifactType->getID(), 'tech')) {
1075 //can't send a canned response when changing ArtifactType
1076 $canned_response=100;
1077 $this->ArtifactType =& $newArtifactType;
1081 $qpa = db_construct_qpa();
1082 $qpa = db_construct_qpa($qpa, 'UPDATE artifact SET');
1085 // handle audit trail
1088 if ($this->getStatusID() != $status_id) {
1089 $this->addHistory('status_id',$this->getStatusID());
1090 $qpa = db_construct_qpa($qpa, ' status_id=$1,', array($status_id));
1091 $changes['status'] = 1;
1094 if ($status_id != 1) {
1095 $qpa = db_construct_qpa($qpa, ' close_date=$1,', array($now));
1097 $qpa = db_construct_qpa($qpa, ' close_date=$1,', array(0));
1099 $this->addHistory('close_date', $this->getCloseDate());
1101 if ($this->getPriority() != $priority) {
1102 $this->addHistory('priority',$this->getPriority());
1103 $qpa = db_construct_qpa($qpa, ' priority=$1,', array($priority));
1104 $changes['priority'] = 1;
1108 if ($this->getAssignedTo() != $assigned_to) {
1109 $this->addHistory('assigned_to',$this->getAssignedTo());
1110 $qpa = db_construct_qpa($qpa, ' assigned_to=$1,', array($assigned_to));
1111 $changes['assigned_to'] = 1;
1114 if ($summary && ($this->getSummary() != htmlspecialchars($summary))) {
1115 $this->addHistory('summary', $this->getSummary());
1116 $qpa = db_construct_qpa($qpa, ' summary=$1,', array(htmlspecialchars($summary)));
1117 $changes['summary'] = 1;
1120 if ($description && ($this->getDetails() != htmlspecialchars($description))) {
1121 $this->addHistory('details', $this->getDetails());
1122 $qpa = db_construct_qpa($qpa, ' details=$1,', array(htmlspecialchars($description)));
1123 $changes['details'] = 1;
1127 $this->addMessage($details,'',0);
1128 $changes['details'] = 1;
1133 Finally, update the artifact itself
1136 $qpa = db_construct_qpa($qpa, ' group_artifact_id=$1
1137 WHERE artifact_id=$2 AND group_artifact_id=$3',
1138 array($new_artifact_type_id,
1139 $this->getID(), $artifact_type_id));
1140 $result = db_query_qpa($qpa);
1142 if (!$result || db_affected_rows($result) < 1) {
1143 $this->setError(_('Error - update failed!').db_error());
1147 if (!$this->fetchData($this->getID())) {
1154 //extra field handling
1156 if (!$this->updateExtraFields($extra_fields,$changes)) {
1157 //TODO - see if anything actually did change
1163 handle canned responses
1165 Instantiate ArtifactCanned and get the body of the message
1167 if ($canned_response != 100) {
1168 //don't care if this response is for this group - could be hacked
1169 $acr=new ArtifactCanned($this->ArtifactType,$canned_response);
1170 if (!$acr || !is_object($acr)) {
1171 $this->setError(_('Could Not Create Canned Response Object'));
1172 } elseif ($acr->isError()) {
1173 $this->setError($acr->getErrorMessage());
1175 $body = $acr->getBody();
1177 if (!$this->addMessage(util_unconvert_htmlspecialchars($body),'',0)) {
1184 $this->setError(_('Unable to Use Canned Response'));
1190 if ($update || $send_message){
1191 if (!empty($changes)) {
1192 // Send the email with changes
1193 $this->mailFollowupEx($now, 2, false, $changes);
1198 //nothing changed, so cancel the transaction
1199 $this->setError(_('Nothing Changed - Update Cancelled'));
1207 * updateLastModifiedDate - update the last_modified_date attribute of this artifact.
1209 * @return true on success / false on failure
1211 function updateLastModifiedDate() {
1212 $res = db_query_params ('UPDATE artifact SET last_modified_date=EXTRACT(EPOCH FROM now())::integer WHERE artifact_id=$1',
1213 array ($this->getID()));
1218 * assignToMe - assigns this artifact to current user
1220 * @return true on success / false on failure
1222 function assignToMe() {
1223 if (!session_loggedin() || !($this->ArtifactType->userIsAdmin() || $this->ArtifactType->userIsTechnician())) {
1224 $this->setPermissionDeniedError();
1228 $user_id = user_getid();
1229 $res = db_query_params ('UPDATE artifact SET assigned_to=$1 WHERE artifact_id=$2',
1230 array ($user_id, $this->getID())) ;
1232 $this->setError(_('Error updating assigned_to in artifact: ').db_error());
1235 $this->fetchData($this->getID());
1241 * updateExtraFields - updates the extra data elements for this artifact
1242 * e.g. the extra fields created and defined by the admin.
1244 * @param array Array of extra fields like: array(15=>'foobar',22=>'1');
1245 * @param array Array where changes to the extra fields should be logged
1246 * @return true on success / false on failure
1248 function updateExtraFields($extra_fields,&$changes){
1250 This is extremely complex code - we have take the passed array
1251 and see if we need to insert it into the db, and may have to
1252 add history rows for the audit trail
1254 start by getting all the available extra fields from ArtifactType
1255 For each field from ArtifacType, check the passed array -
1256 This prevents someone from passing bogus extra field entries - they will be ignored
1257 if the passed entry is blank, may have to force a default value
1258 if the passed array is different from the existing data in db,
1259 delete old entry and insert new entries, along with possible audit trail
1261 skip it and continue to next item
1266 //get a list of extra fields for this artifact_type
1267 $ef = $this->ArtifactType->getExtraFields();
1268 $efk=array_keys($ef);
1270 if (empty($extra_fields) && empty($ef)) {
1274 // If there is a status field, then check against the workflow.
1275 // Unless if we change type.
1276 if (! isset($changes['Type']) || !$changes['Type']) {
1277 for ($i=0; $i<count($efk); $i++) {
1279 $type=$ef[$efid]['field_type'];
1280 if ($type == ARTIFACT_EXTRAFIELDTYPE_STATUS) {
1281 // Get previous value.
1282 $res = db_query_params ('SELECT field_data FROM artifact_extra_field_data
1283 WHERE artifact_id=$1 AND extra_field_id=$2',
1284 array($this->getID(),
1286 $old = (db_numrows($res)>0) ? db_result($res,0,'field_data') : 100;
1287 if ($old != $extra_fields[$efid]) {
1288 $atw = new ArtifactWorkflow($this->ArtifactType, $efid);
1289 if (!$atw->checkEvent($old, $extra_fields[$efid])) {
1290 $this->setError('Workflow error: You are not authorized to change the Status ('.$old.' => '.$extra_fields[$efid].')');
1298 //now we'll update this artifact for each extra field
1299 for ($i=0; $i<count($efk); $i++) {
1301 $type=$ef[$efid]['field_type'];
1303 // check required fields
1304 if ($ef[$efid]['is_required']) {
1305 if (!array_key_exists($efid, $extra_fields)) {
1306 if ($type == ARTIFACT_EXTRAFIELDTYPE_STATUS) {
1307 $this->setError(_('Status Custom Field Must Be Set'));
1310 $this->setMissingParamsError($ef[$efid]['field_name']);
1315 if ($extra_fields[$efid] === '') {
1316 if ($type == ARTIFACT_EXTRAFIELDTYPE_STATUS) {
1317 $this->setError(_('Status Custom Field Must Be Set'));
1320 $this->setMissingParamsError($ef[$efid]['field_name']);
1325 if (($type == ARTIFACT_EXTRAFIELDTYPE_SELECT || $type == ARTIFACT_EXTRAFIELDTYPE_RADIO) &&
1326 $extra_fields[$efid] == '100') {
1327 $this->setMissingParamsError($ef[$efid]['field_name']);
1330 elseif (($type == ARTIFACT_EXTRAFIELDTYPE_MULTISELECT || $type == ARTIFACT_EXTRAFIELDTYPE_CHECKBOX) &&
1331 (count($extra_fields[$efid]) == 1 && $extra_fields[$efid][0] == '100')) {
1332 $this->setMissingParamsError($ef[$efid]['field_name']);
1339 // Force each field to have some value if it is a numeric field
1340 // text fields will just be purged and skipped
1342 if (!array_key_exists($efid, $extra_fields) || $extra_fields[$efid] === '') {
1343 if (($type == ARTIFACT_EXTRAFIELDTYPE_SELECT) || ($type == ARTIFACT_EXTRAFIELDTYPE_RADIO)) {
1344 $extra_fields[$efid]='100';
1345 } elseif (($type == ARTIFACT_EXTRAFIELDTYPE_MULTISELECT) || ($type == ARTIFACT_EXTRAFIELDTYPE_CHECKBOX)) {
1346 $extra_fields[$efid]=array('100');
1348 $resdel = db_query_params ('DELETE FROM artifact_extra_field_data WHERE artifact_id=$1 AND extra_field_id=$2',
1349 array ($this->getID(),
1356 // get the old rows of data
1358 $resd = db_query_params ('SELECT * FROM artifact_extra_field_data WHERE artifact_id=$1 AND extra_field_id=$2',
1359 array ($this->getID(),
1361 $rows=db_numrows($resd);
1362 if ($resd && $rows) {
1364 //POTENTIAL PROBLEM - no entry was there before, but adding one now - may need history
1367 // Compare for history purposes
1370 // these types have arrays associated to them, so they need
1371 // special handling to check for differences
1372 if ($type == ARTIFACT_EXTRAFIELDTYPE_MULTISELECT || $type == ARTIFACT_EXTRAFIELDTYPE_CHECKBOX) {
1373 // check the differences between the old values and the new values
1374 $old_values = util_result_column_to_array($resd,"field_data");
1376 $added_values = array_diff($extra_fields[$efid], $old_values);
1377 $deleted_values = array_diff($old_values, $extra_fields[$efid]);
1379 if (!empty($added_values) || !empty($deleted_values)) { // there are differences...
1380 $field_name = $ef[$efid]['field_name'];
1381 if (!preg_match('/^@/', $ef[$efid]['alias'])) {
1382 $changes["extra_fields"][$efid] = 1;
1385 $this->addHistory($field_name, $this->ArtifactType->getElementName(array_reverse($old_values)));
1388 $resdel = db_query_params ('DELETE FROM artifact_extra_field_data WHERE artifact_id=$1 AND extra_field_id=$2',
1389 array ($this->getID(),
1394 } elseif (db_result($resd,0,'field_data') == htmlspecialchars($extra_fields[$efid])) {
1395 //element did not change
1398 //element DID change - do a history entry
1399 $field_name = $ef[$efid]['field_name'];
1400 if (!preg_match('/^@/', $ef[$efid]['alias'])) {
1401 $changes["extra_fields"][$efid] = 1;
1403 $resdel = db_query_params ('DELETE FROM artifact_extra_field_data WHERE artifact_id=$1 AND extra_field_id=$2',
1404 array ($this->getID(),
1407 // Adding history with previous value.
1408 if (($type == ARTIFACT_EXTRAFIELDTYPE_SELECT) || ($type == ARTIFACT_EXTRAFIELDTYPE_RADIO) || ($type == ARTIFACT_EXTRAFIELDTYPE_STATUS)) {
1409 $this->addHistory($field_name,$this->ArtifactType->getElementName(db_result($resd,0,'field_data')));
1411 $this->addHistory($field_name, db_result($resd,0,'field_data'));
1417 //no history for this extra field exists
1422 // Some rewrite & consistency checks on the relation type field.
1424 // 1) Convert syntax [#NNN] to NNN
1425 // 2) Allow multiple spaces as separator.
1426 // 3) Ensure that only integers are given.
1427 // 4) Ensure that id corresponds to valid tracker id.
1429 if ($type == ARTIFACT_EXTRAFIELDTYPE_RELATION) {
1430 $value = preg_replace('/\[\#(\d+)\]/', "\\1", trim($extra_fields[$efid]));
1431 $value = preg_replace('/\\s+/', ' ', $value);
1433 foreach (explode(' ',$value) as $id) {
1434 if (preg_match('/^(\d+)$/', $id)) {
1435 // Control that the id is present in the db
1437 $res = db_query_params ('SELECT artifact_id FROM artifact WHERE artifact_id=$1',
1439 if (db_numrows($res) == 1) {
1442 $this->setError('Illegal id '.$id.', it\'s not a valid tracker id for field: '.$ef[$efid]['field_name'].'.'); // @todo: lang
1446 $this->setError('Illegal value '.$id.', only trackers id are allowed for field: '.$ef[$efid]['field_name'].'.'); // @todo: lang
1450 $extra_fields[$efid] = trim($new);
1453 // Ensure that only integer are allowed for type ARTIFACT_EXTRAFIELDTYPE_INTEGER
1454 if ($type == ARTIFACT_EXTRAFIELDTYPE_INTEGER) {
1455 $extra_fields[$efid] = trim($extra_fields[$efid]);
1456 if (!preg_match('/^[-+]?(\d+)$/', $extra_fields[$efid])) {
1457 $this->setError('Illegal value '.$extra_fields[$efid].' for field '.$ef[$efid]['field_name'].': Only integer is allowed.');
1460 if ($extra_fields[$efid] < -2147483648 || $extra_fields[$efid] > 2147483647) {
1461 $this->setError('Illegal value '.$extra_fields[$efid].' for field '.$ef[$efid]['field_name'].': Integer out of range (-2147483648 to +2147483647).');
1464 $extra_fields[$efid] = intval($extra_fields[$efid]);
1468 // See if anything was even passed for this extra_field_id
1470 if ($extra_fields[$efid] === '') {
1471 //nothing in field to update - text fields may be blank
1473 //determine the type of field and whether it should have multiple rows supporting it
1474 $type=$ef[$efid]['field_type'];
1475 if (($type == ARTIFACT_EXTRAFIELDTYPE_CHECKBOX) || ($type==ARTIFACT_EXTRAFIELDTYPE_MULTISELECT)) {
1477 $count=count($extra_fields[$efid]);
1478 for ($fin=0; $fin<$count; $fin++) {
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 $extra_fields[$efid][$fin])) ;
1484 $this->setError(db_error());
1491 $res = db_query_params ('INSERT INTO artifact_extra_field_data (artifact_id,extra_field_id,field_data) VALUES ($1,$2,$3)',
1492 array ($this->getID(),
1494 htmlspecialchars($extra_fields[$efid]))) ;
1496 $this->setError(db_error());
1503 unset($this->extra_field_data);
1506 $this->updateLastModifiedDate();
1512 * getExtraFieldData - get an array of data for the extra fields associated with this artifact
1514 * @return array array of data
1516 function &getExtraFieldData() {
1517 if (!isset($this->extra_field_data)) {
1518 $this->extra_field_data = array();
1519 $res = db_query_params ('SELECT * FROM artifact_extra_field_data WHERE artifact_id=$1 ORDER BY extra_field_id',
1520 array ($this->getID())) ;
1521 $ef = $this->ArtifactType->getExtraFields();
1522 while ($arr = db_fetch_array($res)) {
1523 $type=$ef[$arr['extra_field_id']]['field_type'];
1524 if (($type == ARTIFACT_EXTRAFIELDTYPE_CHECKBOX) || ($type==ARTIFACT_EXTRAFIELDTYPE_MULTISELECT)) {
1525 //accumulate a sub-array of values in cases where you may have multiple rows
1526 if (!array_key_exists($arr['extra_field_id'], $this->extra_field_data) || !is_array($this->extra_field_data[$arr['extra_field_id']])) {
1527 $this->extra_field_data[$arr['extra_field_id']] = array();
1529 $this->extra_field_data[$arr['extra_field_id']][]=$arr['field_data'];
1531 $this->extra_field_data[$arr['extra_field_id']]=$arr['field_data'];
1535 return $this->extra_field_data;
1539 * marker - adds the > symbol to fields that have been modified for the email message
1543 function marker($prop_name,$changes,$extra_field_id=0) {
1544 if ($prop_name == 'extra_fields' && isset($changes[$prop_name][$extra_field_id])) {
1546 } else if ($prop_name != 'extra_fields' && isset($changes[$prop_name])) {
1554 * mailFollowupEx - send out an email update for this artifact.
1556 * @param time_t Time of the change
1557 * @param int (1) initial/creation (2) update.
1558 * @param array Array of additional addresses to mail to.
1559 * @param array Array of fields changed in this update .
1561 * @return boolean success.
1563 function mailFollowupEx($tm,$type,$more_addresses=false,$changes='') {
1565 $monitor_ids = array();
1571 $sess = session_get_user() ;
1572 if ($type == 1) { // Initial opening
1574 $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 () ;
1576 $body = $this->ArtifactType->Group->getUnixName() . '-' . $this->ArtifactType->getName() ." item #". $this->getID() .", was opened at ". date( _('Y-m-d H:i'), $this->getOpenDate() ) ;
1580 $body = $this->ArtifactType->Group->getUnixName() . '-' . $this->ArtifactType->getName() .
1581 " item #" . $this->getID() .
1582 " was changed at " .
1583 date(_('Y-m-d H:i'), $tm) . " by " .
1584 $sess->getRealName();
1586 $body = $this->ArtifactType->Group->getUnixName() . '-' . $this->ArtifactType->getName() .
1587 " item #" . $this->getID() .
1588 " was changed at " .
1589 date(_('Y-m-d H:i'), $tm);
1594 $body .= "\nYou can respond by visiting: ".
1595 "\n".util_make_url ('/tracker/?func=detail&atid='. $this->ArtifactType->getID() .
1596 "&aid=". $this->getID() .
1597 "&group_id=". $this->ArtifactType->Group->getID()) .
1598 "\nOr by replying to this e-mail entering your response between the following markers: ".
1599 "\n".ARTIFACT_MAIL_MARKER.
1600 "\n(enter your response here, only in plain text format)".
1601 "\n".ARTIFACT_MAIL_MARKER.
1603 $this->marker('status',$changes).
1604 "Status: ". $this->getStatusName() ."\n".
1605 $this->marker('priority',$changes).
1606 "Priority: ". $this->getPriority() ."\n".
1607 "Submitted By: ". $this->getSubmittedRealName() .
1608 " (". $this->getSubmittedUnixName(). ")"."\n".
1609 $this->marker('assigned_to',$changes).
1610 "Assigned to: ". $this->getAssignedRealName() .
1611 " (". $this->getAssignedUnixName(). ")"."\n".
1612 $this->marker('summary',$changes).
1613 "Summary: ". util_unconvert_htmlspecialchars( $this->getSummary() )." \n";
1615 // Now display the extra fields
1616 $efd = $this->getExtraFieldDataText();
1617 foreach ($efd as $efid => $ef) {
1618 $body .= $this->marker('extra_fields', $changes, $efid);
1619 $body .= $ef["name"].": ".$ef["value"]."\n";
1622 $subject='['. $this->ArtifactType->Group->getUnixName() . '-' . $this->ArtifactType->getName() . '][' . $this->getID() .'] '. util_unconvert_htmlspecialchars( $this->getSummary() );
1625 // get all the email addresses that are monitoring this request or the ArtifactType
1626 $monitor_ids = $this->getMonitorIds();
1628 // initial creation, we just get the users monitoring the ArtifactType
1629 $monitor_ids = $this->ArtifactType->getMonitorIds();
1633 if ($more_addresses) {
1634 $emails[] = $more_addresses;
1636 //we don't email the current user
1637 if ($this->getAssignedTo() != user_getid()) {
1638 $monitor_ids[] = $this->getAssignedTo();
1640 if ($this->getSubmittedBy() != user_getid()) {
1641 $monitor_ids[] = $this->getSubmittedBy();
1643 //initial submission
1645 //if an email is set for this ArtifactType
1646 //add that address to the BCC: list
1647 if ($this->ArtifactType->getEmailAddress()) {
1648 $emails[] = $this->ArtifactType->getEmailAddress();
1652 if ($this->ArtifactType->emailAll()) {
1653 $emails[] = $this->ArtifactType->getEmailAddress();
1657 $body .= "\n\nInitial Comment:".
1658 "\n".util_unconvert_htmlspecialchars( $this->getDetails() ) .
1659 "\n\n----------------------------------------------------------------------";
1663 Now include the followups
1665 $result2=$this->getMessages();
1667 $rows=db_numrows($result2);
1669 if ($result2 && $rows > 0) {
1670 for ($i=0; $i<$rows; $i++) {
1672 // for messages posted by non-logged-in users,
1673 // we grab the email they gave us
1675 // otherwise we use the confirmed one from the users table
1677 if (db_result($result2,$i,'user_id') == 100) {
1678 $emails[] = db_result($result2,$i,'from_email');
1680 $monitor_ids[] = db_result($result2,$i,'user_id');
1686 $body .= $this->marker('details',$changes);
1688 $body .= "Comment By: ". db_result($result2,$i,'realname') . " (".db_result($result2,$i,'user_name').")".
1689 "\nDate: ". date( _('Y-m-d H:i'),db_result($result2,$i,'adddate') ).
1691 "\n".util_unconvert_htmlspecialchars( db_result($result2,$i,'body') ).
1692 "\n\n----------------------------------------------------------------------";
1698 $body .= "\n\nYou can respond by visiting: ".
1699 "\n".util_make_url ('/tracker/?func=detail&atid='. $this->ArtifactType->getID() .
1700 "&aid=". $this->getID() .
1701 "&group_id=". $this->ArtifactType->Group->getID());
1703 //only send if some recipients were found
1704 if (count($emails) < 1 && count($monitor_ids) < 1) {
1708 if (count($monitor_ids) < 1) {
1709 $monitor_ids=array();
1711 $monitor_ids=array_unique($monitor_ids);
1714 $from = $this->ArtifactType->getReturnEmailAddress();
1715 $extra_headers = 'Reply-to: '.$from;
1717 // load the e-mail addresses of the users
1718 $users =& user_get_objects($monitor_ids);
1719 if (count($users) > 0) {
1720 foreach ($users as $user) {
1721 if ($user->getStatus() == "A") { //we are only sending emails to active users
1722 $emails[] = $user->getEmail();
1727 //now remove all duplicates from the email list
1728 if (count($emails) > 0) {
1729 $BCC=implode(',',array_unique($emails));
1730 util_send_message('',$subject,$body,$from,$BCC,'',$extra_headers);
1733 $this->sendSubjectMsg = $subject;
1734 $this->sendBodyMsg = $body;
1736 //util_handle_message($monitor_ids,$subject,$body,$BCC);
1742 * getExtraFieldDataText - Return the extra fields' data in a human-readable form.
1744 * @return array Array containing field ID => field name and value associated to it for
1747 function getExtraFieldDataText() {
1748 // First we get the list of extra fields and the data
1749 // associated to the fields
1750 $efs = $this->ArtifactType->getExtraFields();
1751 $efd = $this->getExtraFieldData();
1755 foreach ($efs as $efid => $ef) {
1756 $name = $ef["field_name"];
1757 $type = $ef["field_type"];
1759 // Get the value according to the type
1762 // for these types, the associated value comes straight
1763 case ARTIFACT_EXTRAFIELDTYPE_TEXT:
1764 case ARTIFACT_EXTRAFIELDTYPE_TEXTAREA:
1765 case ARTIFACT_EXTRAFIELDTYPE_RELATION:
1766 case ARTIFACT_EXTRAFIELDTYPE_INTEGER:
1767 if (isset($efd[$efid])) {
1768 $value = $efd[$efid];
1774 // the other types have and ID or an array of IDs associated to them
1776 if (isset($efd[$efid])) {
1777 $value = $this->ArtifactType->getElementName($efd[$efid]);
1783 $return[$efid] = array("name" => $name, "value" => $value, 'type' => $type);
1790 class ArtifactComparator {
1791 var $criterion = 'artifact_id' ;
1792 var $order = 'ASC' ;
1794 function Compare ($a, $b) {
1795 if ($this->order == 'DESC') {
1796 $c = $a ; $a = $b ; $b = $c ;
1798 switch ($this->criterion) {
1800 $namecmp = strcoll ($a->getSummary(),
1802 if ($namecmp != 0) {
1807 $namecmp = strcoll (user_get_object($a->getAssignedTo())->getRealName(),
1808 user_get_object($b->getAssignedTo())->getRealName()) ;
1809 if ($namecmp != 0) {
1813 case 'submitted_by':
1814 $namecmp = strcoll (user_get_object($a->getSubmittedBy())->getRealName(),
1815 user_get_object($b->getSubmittedBy())->getRealName()) ;
1816 if ($namecmp != 0) {
1821 $a_date = $a->getOpenDate() ;
1822 $b_date = $b->getOpenDate() ;
1823 return ($a_date < $b_date) ? -1 : 1;
1826 $a_date = $a->getCloseDate() ;
1827 $b_date = $b->getCloseDate() ;
1828 return ($a_date < $b_date) ? -1 : 1;
1830 case 'last_modified_date':
1831 $a_date = $a->getLastModifiedDate() ;
1832 $b_date = $b->getLastModifiedDate() ;
1833 return ($a_date < $b_date) ? -1 : 1;
1836 $a_prority = $a->getPriority() ;
1837 $b_prority = $b->getPriority() ;
1838 return ($a_prority < $b_prority) ? -1 : 1;
1841 $aa=$a->getExtraFieldDataText();
1842 $ba=$b->getExtraFieldDataText();
1843 $af=$aa[$this->criterion]['value'];
1844 $bf=$ba[$this->criterion]['value'];
1845 $namecmp = strcoll ($af,$bf) ;
1846 if ($namecmp != 0) {
1852 // When in doubt, sort on artifact ID
1853 $aid = $a->getID() ;
1854 $bid = $b->getID() ;
1858 return ($aid < $bid) ? -1 : 1;
1862 function sortArtifactList (&$list, $criterion='name', $order='ASC') {
1863 $cmp = new ArtifactComparator () ;
1864 $cmp->criterion = $criterion ;
1865 $cmp->order = $order ;
1867 return usort ($list, array ($cmp, 'Compare')) ;
1872 // c-file-style: "bsd"