* Copyright 2009, Roland Mas
* Copyright 2009, Alcatel-Lucent
*
- * This file is part of FusionForge.
+ * This file is part of FusionForge. FusionForge is free software;
+ * you can redistribute it and/or modify it under the terms of the
+ * GNU General Public License as published by the Free Software
+ * Foundation; either version 2 of the Licence, or (at your option)
+ * any later version.
*
- * FusionForge is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published
- * by the Free Software Foundation; either version 2 of the License,
- * or (at your option) any later version.
- *
- * FusionForge is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
+ * FusionForge is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
*
- * You should have received a copy of the GNU General Public License
- * along with FusionForge; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
- * USA
+ * You should have received a copy of the GNU General Public License along
+ * with FusionForge; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
/*
* TOGETHER WITH THE SOFTWARE TO WHICH THE CONTRIBUTION RELATES OR ON A STAND
* ALONE BASIS."
*/
-
require_once $gfcommon.'include/Error.class.php';
require_once $gfcommon.'tracker/ArtifactMessage.class.php';
require_once $gfcommon.'tracker/ArtifactExtraField.class.php';
// This string is used when sending the notification mail for identifying the
// user response
-define('ARTIFACT_MAIL_MARKER', '#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+');
+define('ARTIFACT_MAIL_MARKER', '#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+');
/**
* Factory method which creates an Artifact from an artifact ID
- *
+ *
* @param int The artifact ID
* @param array The result array, if it's passed in
* @return object Artifact object
$ARTIFACT_OBJ["_".$artifact_id."_"]=false;
return false;
}
- $data =& db_fetch_array($res);
+ $data = db_fetch_array($res);
}
$ArtifactType =& artifactType_get_object($data["group_artifact_id"]);
$ARTIFACT_OBJ["_".$artifact_id."_"]= new Artifact($ArtifactType,$data);
}
return $ARTIFACT_OBJ["_".$artifact_id."_"];
- }
+ }
class Artifact extends Error {
*
* @var object $ArtifactType.
*/
- var $ArtifactType;
+ var $ArtifactType;
/**
* Array of artifact data.
*
* @var array $files
*/
- var $files;
+ var $files;
/**
* Database result set of related tasks
* @var result $relatedtasks
*/
var $relatedtasks;
-
+
/**
* Artifact - constructor.
*
* @param object The ArtifactType object.
- * @param integer (primary key from database OR complete assoc array)
+ * @param integer (primary key from database OR complete assoc array)
* ONLY OPTIONAL WHEN YOU PLAN TO IMMEDIATELY CALL ->create()
* @return boolean success.
*/
function Artifact(&$ArtifactType, $data=false) {
- $this->Error();
+ $this->Error();
$this->ArtifactType =& $ArtifactType;
//was ArtifactType legit?
if (!$ArtifactType || !is_object($ArtifactType)) {
- $this->setError('Artifact: No Valid ArtifactType');
+ $this->setError(_('No Valid Artifact Type'));
return false;
}
//did ArtifactType have an error?
if ($ArtifactType->isError()) {
- $this->setError('Artifact: '.$ArtifactType->getErrorMessage());
+ $this->setError($ArtifactType->getErrorMessage());
return false;
}
// make sure this person has permission to view artifacts
//
if (!forge_check_perm ('tracker', $this->ArtifactType->getID(), 'read')) {
- $this->setError(_('Artifact: Only group members can view private artifact types'));
+ $this->setError(_('Only project members can view private artifact types'));
return false;
}
}
}
-
/**
* create - construct a new Artifact in the database.
*
* @param int The ID of the user to which this artifact is to be assigned.
* @param int The artifacts priority.
* @param array Array of extra fields like: array(15=>'foobar',22=>'1');
+ * @param array Array of data to change submitter and time of submit like: array('user' => 127, 'time' => 1234556789)
* @return id on success / false on failure.
*/
- function create( $summary, $details, $assigned_to=100, $priority=3, $extra_fields=array()) {
+ function create( $summary, $details, $assigned_to=100, $priority=3, $extra_fields=array(), $importData = array()) {
//
// make sure this person has permission to add artifacts
//
+
if (!$this->ArtifactType->isPublic()) {
//
// Only admins can post/modify private artifacts
//
// ape: Disabled, private means only restricted to members. So, no special rules #2503.
// if (!forge_check_perm ('tracker_admin', $this->ArtifactType->Group->getID()) {
-// $this->setError(_('Artifact: Only Artifact Admins Can Modify Private ArtifactTypes'));
+// $this->setError(_('Only Artifact Admins Can Modify Private Artifact Types'));
// return false;
// }
}
//
// get the user_id
//
- if (session_loggedin()) {
- $user=user_getid();
+ if(array_key_exists('user', $importData)){
+ $user = $importData['user'];
} else {
- if ($this->ArtifactType->allowsAnon()) {
- $user=100;
+ if (session_loggedin()) {
+ $user=user_getid();
} else {
- $this->setError(_('Artifact: This ArtifactType Does Not Allow Anonymous Submissions. Please Login.'));
- return false;
+ if ($this->ArtifactType->allowsAnon()) {
+ $user=100;
+ } else {
+ $this->setError(_('This Artifact Type Does Not Allow Anonymous Submissions. Please Login.'));
+ return false;
+ }
}
}
// data validation
//
if (!$summary) {
- $this->setError(_('Artifact: Message Summary Is Required'));
+ $this->setError(_('Message Summary Is Required'));
return false;
}
if (!$details) {
- $this->setError(_('Artifact: Message Body Is Required'));
+ $this->setError(_('Message Body Is Required'));
return false;
}
if (!$assigned_to) {
//
$status_id=$this->ArtifactType->remapStatus($status_id,$extra_fields);
if (!$status_id) {
- $this->setError(_('Artifact: Error remapping status'));
+ $this->setError(_('Error remapping status'));
return false;
}
db_begin();
-
- $res = db_query_params ('INSERT INTO artifact
+ if (array_key_exists('time',$importData)){
+ $time = $importData['time'];
+ } else {
+ $time = time();
+ }
+ $res = db_query_params ('INSERT INTO artifact
(group_artifact_id,status_id,priority,
- submitted_by,assigned_to,open_date,summary,details)
+ submitted_by,assigned_to,open_date,summary,details)
VALUES ($1,$2,$3,$4,$5,$6,$7,$8)',
array ($this->ArtifactType->getID(),
$status_id,
$priority,
$user,
$assigned_to,
- time(),
+ $time,
htmlspecialchars($summary),
htmlspecialchars($details))) ;
if (!$res) {
- $this->setError('Artifact: '.db_error());
+ $this->setError(db_error());
db_rollback();
return false;
}
-
+
$artifact_id=db_insertid($res,'artifact','artifact_id');
if (!$res || !$artifact_id) {
- $this->setError('Artifact: '.db_error());
+ $this->setError(db_error());
db_rollback();
return false;
} else {
//
// now send an email if appropriate
//
- $this->mailFollowup(1);
+ $this->mailFollowupEx(0, 1);
db_commit();
return $artifact_id;
}
}
-
+
/**
* fetchData - re-fetch the data for this Artifact from the database.
*
array ($artifact_id,
$this->ArtifactType->getID())) ;
if (!$res || db_numrows($res) < 1) {
- $this->setError('Artifact: Invalid ArtifactID');
+ $this->setError(_('Invalid Artifact ID'));
return false;
}
- $this->data_array =& db_fetch_array($res);
+ $this->data_array = db_fetch_array($res);
db_free_result($res);
return true;
}
function &getArtifactType() {
return $this->ArtifactType;
}
-
+
/**
* getID - get this ArtifactID.
*
return $this->data_array['artifact_id'];
}
+ /**
+ * getStringID - get a string display for this ArtifactID.
+ *
+ * @return string The artifact_id #.
+ */
+ function getStringID() {
+ return '[#'.$this->data_array['artifact_id'].']';
+ }
+
/**
* getStatusID - get open/closed/deleted flag.
*
*/
function delete($sure) {
if (!$sure) {
- $this->setMissingParamsError();
+ $this->setMissingParamsError(_('Please tick all checkboxes.'));
return false;
}
if (!forge_check_perm ('tracker_admin', $this->ArtifactType->Group->getID())) {
$res = db_query_params ('DELETE FROM artifact_extra_field_data WHERE artifact_id=$1',
array ($this->getID())) ;
if (!$res) {
- $this->setError('Error deleting extra field data: '.db_error());
+ $this->setError(_('Error deleting extra field data: ').db_error());
db_rollback();
return false;
}
$res = db_query_params ('DELETE FROM artifact_file WHERE artifact_id=$1',
array ($this->getID())) ;
if (!$res) {
- $this->setError('Error deleting file from db: '.db_error());
+ $this->setError(_('Error deleting file from db: ').db_error());
db_rollback();
return false;
}
$res = db_query_params ('DELETE FROM artifact_message WHERE artifact_id=$1',
array ($this->getID())) ;
if (!$res) {
- $this->setError('Error deleting message: '.db_error());
+ $this->setError(_('Error deleting message: ').db_error());
db_rollback();
return false;
}
$res = db_query_params ('DELETE FROM artifact_history WHERE artifact_id=$1',
array ($this->getID())) ;
if (!$res) {
- $this->setError('Error deleting history: '.db_error());
+ $this->setError(_('Error deleting history: ').db_error());
db_rollback();
return false;
}
$res = db_query_params ('DELETE FROM artifact_monitor WHERE artifact_id=$1',
array ($this->getID())) ;
if (!$res) {
- $this->setError('Error deleting monitor: '.db_error());
+ $this->setError(_('Error deleting monitor: ').db_error());
db_rollback();
return false;
}
$res = db_query_params ('DELETE FROM artifact WHERE artifact_id=$1',
array ($this->getID())) ;
if (!$res) {
- $this->setError('Error deleting artifact: '.db_error());
+ $this->setError(_('Error deleting artifact: ').db_error());
db_rollback();
return false;
}
-
+
if ($this->getStatusID() == 1) {
$res = db_query_params ('UPDATE artifact_counts_agg SET count=count-1,open_count=open_count-1
WHERE group_artifact_id=$1',
array ($this->getID())) ;
if (!$res) {
- $this->setError('Error updating artifact_counts_agg (1): '.db_error());
+ $this->setError(_('Error updating artifact counts: ').db_error());
db_rollback();
return false;
}
WHERE group_artifact_id=$1',
array ($this->getID())) ;
if (!$res) {
- $this->setError('Error updating artifact_counts_agg (2): '.db_error());
+ $this->setError(_('Error updating artifact counts: ').db_error());
db_rollback();
return false;
}
} else {
- $this->setError(_('SetMonitor::Valid Email Address Required'));
+ $this->setError(_('Valid Email Address Required'));
return false;
}
}
} else {
//already monitoring - remove their monitor
- db_query_params ('DELETE FROM artifact_monitor
+ db_query_params ('DELETE FROM artifact_monitor
WHERE artifact_id=$1
AND user_id=$2',
array ($this->getID(),
*
* @return database result set.
*/
- function getMessages() {
- return db_query_params ('SELECT * FROM artifact_message_user_vw WHERE artifact_id=$1 ORDER BY adddate DESC',
+ function getMessages($asc=false) {
+ return db_query_params ('SELECT * FROM artifact_message_user_vw WHERE artifact_id=$1 ORDER BY adddate ' . ($asc ? 'ASC' : 'DESC'),
array ($this->getID())) ;
}
*/
function getRelatedTasks() {
if (!$this->relatedtasks) {
- $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
- FROM project_task pt, project_group_list pgl
- WHERE pt.group_project_id = pgl.group_project_id AND
- EXISTS (SELECT project_task_id FROM project_task_artifact
+ $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
+ FROM project_task pt, project_group_list pgl, project_status ps
+ WHERE pt.group_project_id = pgl.group_project_id
+ AND ps.status_id = pt.status_id
+ AND EXISTS (SELECT project_task_id FROM project_task_artifact
WHERE project_task_id=pt.project_task_id
AND artifact_id = $1)',
array ($this->getID())) ;
$user_id=user_getid();
$user =& user_get_object($user_id);
if (!$user || !is_object($user)) {
- $this->setError('ERROR - Logged In User Bug Could Not Get User Object');
+ $this->setError('ERROR - Logged In User But Could Not Get User Object');
return false;
}
- // we'll store this email even though it will likely never be used -
+ // we'll store this email even though it will likely never be used -
// since we have their correct user_id, we can join the USERS table to get email
$by=$user->getEmail();
} elseif (!$this->ArtifactType->allowsAnon()) {
- $this->setError(_('Artifact: This ArtifactType Does Not Allow Anonymous Submissions. Please Login.'));
+ $this->setError(_('This Artifact Type Does Not Allow Anonymous Submissions. Please Login.'));
return false;
} else {
$user_id=100;
}
}
+ $now = time();
$res = db_query_params ('INSERT INTO artifact_message (artifact_id,submitted_by,from_email,adddate,body) VALUES ($1,$2,$3,$4,$5)',
array ($this->getID(),
$user_id,
$by,
- time(),
+ $now,
htmlspecialchars($body))) ;
+
+ $this->updateLastModifiedDate();
+
if ($send_followup) {
- $this->mailFollowup(2,false);
+ $this->mailFollowupEx($now, 2, false);
}
return $res;
}
*
* @param string The name of the field in the database being modified.
* @param string The former value of this field.
+ * @param array Array of data to change submitter and time of submit like: array('user' => 127, 'time' => 1234556789)
* @access private
* @return boolean success.
*/
- function addHistory($field_name,$old_value) {
- if (!session_loggedin()) {
- $user=100;
+ function addHistory($field_name,$old_value, $importData = array()) {
+ if (array_key_exists('user', $importData)){
+ $user = $importData['user'];
+ } else {
+ if (!session_loggedin()) {
+ $user=100;
+ } else {
+ $user=user_getid();
+ }
+ }
+ if (array_key_exists('time',$importData)){
+ $time = $importData['time'];
} else {
- $user=user_getid();
+ $time = time();
}
return db_query_params ('INSERT INTO artifact_history(artifact_id,field_name,old_value,mod_by,entrydate) VALUES ($1,$2,$3,$4,$5)',
array ($this->getID(),
$field_name,
- addslashes($old_value),
+ $old_value,
$user,
- time())) ;
+ $time)) ;
+ }
+
+ /**
+ * setStatus - set the status of this artifact.
+ *
+ * @param int The artifact status ID.
+ * @param int Closing date if status = 1
+ *
+ * @return boolean success.
+ */
+ function setStatus($status_id, $closingTime=False) {
+ db_begin();
+ $qpa = db_construct_qpa (false, 'UPDATE artifact SET status_id=$1', array ($status_id)) ;
+ if ($closingTime && $status_id != 1) {
+ $time=$closingTime;
+ $qpa = db_construct_qpa ($qpa, ', close_date=$1 ', array ($time)) ;
+ }
+ $qpa = db_construct_qpa ($qpa,
+ 'WHERE artifact_id=$1 AND group_artifact_id=$2',
+ array ($this->getID(), $artifact_type_id)) ;
+ $result=db_query_qpa($qpa);
+
+ if (!$result || db_affected_rows($result) < 1) {
+ $this->setError('Error - update failed!'.db_error());
+ db_rollback();
+ return false;
+ } else {
+ if (!$this->fetchData($this->getID())) {
+ db_rollback();
+ return false;
+ }
+ }
+
+
+ //commiting changes
+ db_commit();
+ return true;
}
/**
if (count($extra_fields) > 0) {
$status_id=$this->ArtifactType->remapStatus($status_id,$extra_fields);
}
- if (!$this->getID()
- || !$assigned_to
- || !$status_id
- || !$canned_response
- || !$new_artifact_type_id) {
- $this->setMissingParamsError();
+ if (!$this->getID()) {
+ $this->setMissingParamsError('ID');
+ return false;
+ }
+ if (!$assigned_to) {
+ $this->setMissingParamsError(_('Assigned to'));
+ return false;
+ }
+ if (!$status_id) {
+ $this->setMissingParamsError(_('State'));
+ return false;
+ }
+ if (!$canned_response) {
+ $this->setMissingParamsError(_('Canned Response'));
+ return false;
+ }
+ if (!$new_artifact_type_id) {
+ $this->setMissingParamsError(_('Data Type'));
return false;
}
-
// Check that assigned_to is a tech for the tracker
if ($assigned_to != 100) {
- if (!forge_check_perm ('tracker', $this->ArtifactType->getID(), 'tech')) {
- $this->setError("Invalid assigned_to (assigned person is not a technician)");
+ if (!forge_check_perm_for_user ($assigned_to, 'tracker', $this->ArtifactType->getID(), 'tech')) {
+ $this->setError(_("Invalid assigned_to (assigned person is not a technician)"));
return false;
}
}
// Array to record which properties were changed
$changes = array();
$update = false;
-
+
db_begin();
//
if ($new_artifact_type_id != $artifact_type_id) {
$newArtifactType= new ArtifactType($this->ArtifactType->getGroup(), $new_artifact_type_id);
if (!is_object($newArtifactType) || $newArtifactType->isError()) {
- $this->setError('Artifact: Could not move to new ArtifactType'. $newArtifactType->getErrorMessage());
+ $this->setError(_('Could not move to new Artifact Type'). $newArtifactType->getErrorMessage());
db_rollback();
return false;
}
db_rollback();
return false;
}
-
+
// Add a message to explain that the tracker was moved.
$message = 'Moved from '.$this->ArtifactType->getName().' to '.$newArtifactType->getName();
$this->addHistory('type', $this->ArtifactType->getName());
$ef = $this->ArtifactType->getExtraFields();
$ef_new = $newArtifactType->getExtraFields();
foreach($extra_fields as $extra_id => $value) {
- $alias = $ef[$extra_id]['alias'];
+ $alias = preg_replace('/^@/', '', $ef[$extra_id]['alias']);
$type = $ef[$extra_id]['field_type'];
// Search if there is an extra field with the same alias.
$new_id = 0;
foreach($ef_new as $id => $arr) {
- if ($arr['alias'] == $alias) {
+ if (preg_replace('/^@/', '', $arr['alias']) == $alias) {
$new_id = $id;
}
}
}
}
}
-
+
// Special case if moving to a tracker with custom status (previous has not).
$custom_status_id = $newArtifactType->getCustomStatusField();
if ($custom_status_id && !$new_extra_fields[$custom_status_id]) {
$new_extra_fields[$custom_status_id] = $nodes[0];
}
}
+
$extra_fields = $new_extra_fields;
$res = db_query_params ('DELETE FROM artifact_extra_field_data WHERE artifact_id=$1',
array ($this->getID()));
if (!$res) {
- $this->setError('Removal of old artifact_extra_field_data failed: '.db_error());
+ $this->setError(_('Removal of old artifact_extra_field_data failed: ').db_error());
db_rollback();
return false;
}
//
// handle audit trail
//
+ $now = time();
if ($this->getStatusID() != $status_id) {
$this->addHistory('status_id',$this->getStatusID());
$qpa = db_construct_qpa($qpa, ' status_id=$1,', array($status_id));
$update = true;
if ($status_id != 1) {
- $qpa = db_construct_qpa($qpa, ' close_date=$1,', array(time()));
+ $qpa = db_construct_qpa($qpa, ' close_date=$1,', array($now));
} else {
$qpa = db_construct_qpa($qpa, ' close_date=$1,', array(0));
}
$result = db_query_qpa($qpa);
if (!$result || db_affected_rows($result) < 1) {
- $this->setError('Error - update failed!'.db_error());
+ $this->setError(_('Error - update failed!').db_error());
db_rollback();
return false;
} else {
db_rollback();
return false;
}
-
+
/*
handle canned responses
//don't care if this response is for this group - could be hacked
$acr=new ArtifactCanned($this->ArtifactType,$canned_response);
if (!$acr || !is_object($acr)) {
- $this->setError('Artifact: Could Not Create Canned Response Object');
+ $this->setError(_('Could Not Create Canned Response Object'));
} elseif ($acr->isError()) {
- $this->setError('Artifact: '.$acr->getErrorMessage());
+ $this->setError($acr->getErrorMessage());
} else {
- $body = addslashes($acr->getBody());
+ $body = $acr->getBody();
if ($body) {
if (!$this->addMessage(util_unconvert_htmlspecialchars($body),'',0)) {
db_rollback();
$send_message=true;
}
} else {
- $this->setError('Artifact: Unable to Use Canned Response');
+ $this->setError(_('Unable to Use Canned Response'));
return false;
}
}
if ($update || $send_message){
if (!empty($changes)) {
// Send the email with changes
- $this->mailFollowup(2, false, $changes);
+ $this->mailFollowupEx($now, 2, false, $changes);
}
db_commit();
return true;
db_rollback();
return false;
}
-
+
+ }
+
+ /**
+ * updateLastModifiedDate - update the last_modified_date attribute of this artifact.
+ *
+ * @return true on success / false on failure
+ */
+ function updateLastModifiedDate() {
+ $res = db_query_params ('UPDATE artifact SET last_modified_date=EXTRACT(EPOCH FROM now())::integer WHERE artifact_id=$1',
+ array ($this->getID()));
+ return (!$res);
+ }
+
+ /**
+ * assignToMe - assigns this artifact to current user
+ *
+ * @return true on success / false on failure
+ */
+ function assignToMe() {
+ if (!session_loggedin() || !($this->ArtifactType->userIsAdmin() || $this->ArtifactType->userIsTechnician())) {
+ $this->setPermissionDeniedError();
+ return false;
+ }
+
+ $user_id = user_getid();
+ $res = db_query_params ('UPDATE artifact SET assigned_to=$1 WHERE artifact_id=$2',
+ array ($user_id, $this->getID())) ;
+ if (!$res) {
+ $this->setError(_('Error updating assigned_to in artifact: ').db_error());
+ return false;
+ }
+ $this->fetchData($this->getID());
+
+ return true;
}
/**
function updateExtraFields($extra_fields,&$changes){
/*
This is extremely complex code - we have take the passed array
- and see if we need to insert it into the db, and may have to
+ and see if we need to insert it into the db, and may have to
add history rows for the audit trail
start by getting all the available extra fields from ArtifactType
- For each field from ArtifacType, check the passed array -
+ For each field from ArtifacType, check the passed array -
This prevents someone from passing bogus extra field entries - they will be ignored
if the passed entry is blank, may have to force a default value
- if the passed array is different from the existing data in db,
+ if the passed array is different from the existing data in db,
delete old entry and insert new entries, along with possible audit trail
else
skip it and continue to next item
if (empty($extra_fields)) {
return true;
}
+ $update = false;
+
//get a list of extra fields for this artifact_type
$ef = $this->ArtifactType->getExtraFields();
$efk=array_keys($ef);
// If there is a status field, then check against the workflow.
- for ($i=0; $i<count($efk); $i++) {
- $efid=$efk[$i];
- $type=$ef[$efid]['field_type'];
- if ($type == ARTIFACT_EXTRAFIELDTYPE_STATUS) {
- // Get previous value.
-
- $res = db_query_params ('SELECT field_data FROM artifact_extra_field_data
- WHERE artifact_id=$1 AND extra_field_id=$2',
- array($this->getID(),
- $efid));
- $old = (db_numrows($res)>0) ? db_result($res,0,'field_data') : 100;
- if ($old != $extra_fields[$efid]) {
- $atw = new ArtifactWorkflow($this->ArtifactType, $efid);
- if (!$atw->checkEvent($old, $extra_fields[$efid])) {
- $this->setError('Workflow error: You are not authorized to change the Status');
- return false;
+ // Unless if we change type.
+ if (! isset($changes['Type']) || !$changes['Type']) {
+ for ($i=0; $i<count($efk); $i++) {
+ $efid=$efk[$i];
+ $type=$ef[$efid]['field_type'];
+ if ($type == ARTIFACT_EXTRAFIELDTYPE_STATUS) {
+ // Get previous value.
+ $res = db_query_params ('SELECT field_data FROM artifact_extra_field_data
+ WHERE artifact_id=$1 AND extra_field_id=$2',
+ array($this->getID(),
+ $efid));
+ $old = (db_numrows($res)>0) ? db_result($res,0,'field_data') : 100;
+ if ($old != $extra_fields[$efid]) {
+ $atw = new ArtifactWorkflow($this->ArtifactType, $efid);
+ if (!$atw->checkEvent($old, $extra_fields[$efid])) {
+ $this->setError('Workflow error: You are not authorized to change the Status ('.$old.' => '.$extra_fields[$efid].')');
+ return false;
+ }
}
}
}
}
-
+
//now we'll update this artifact for each extra field
for ($i=0; $i<count($efk); $i++) {
$efid=$efk[$i];
if ($ef[$efid]['is_required']) {
if (!array_key_exists($efid, $extra_fields)) {
if ($type == ARTIFACT_EXTRAFIELDTYPE_STATUS) {
- $this->setError('Status Custom Field Must Be Set');
+ $this->setError(_('Status Custom Field Must Be Set'));
}
else {
$this->setMissingParamsError($ef[$efid]['field_name']);
else {
if ($extra_fields[$efid] === '') {
if ($type == ARTIFACT_EXTRAFIELDTYPE_STATUS) {
- $this->setError('Status Custom Field Must Be Set');
+ $this->setError(_('Status Custom Field Must Be Set'));
}
else {
$this->setMissingParamsError($ef[$efid]['field_name']);
continue;
}
}
+
//
// get the old rows of data
//
//
// Compare for history purposes
//
-
+
// these types have arrays associated to them, so they need
// special handling to check for differences
if ($type == ARTIFACT_EXTRAFIELDTYPE_MULTISELECT || $type == ARTIFACT_EXTRAFIELDTYPE_CHECKBOX) {
// check the differences between the old values and the new values
$old_values = util_result_column_to_array($resd,"field_data");
-
+
$added_values = array_diff($extra_fields[$efid], $old_values);
$deleted_values = array_diff($old_values, $extra_fields[$efid]);
-
+
if (!empty($added_values) || !empty($deleted_values)) { // there are differences...
$field_name = $ef[$efid]['field_name'];
if (!preg_match('/^@/', $ef[$efid]['alias'])) {
}
$this->addHistory($field_name, $this->ArtifactType->getElementName(array_reverse($old_values)));
+ $update = true;
$resdel = db_query_params ('DELETE FROM artifact_extra_field_data WHERE artifact_id=$1 AND extra_field_id=$2',
array ($this->getID(),
} else {
continue;
}
- } elseif (addslashes(db_result($resd,0,'field_data')) == htmlspecialchars($extra_fields[$efid])) {
+ } elseif (db_result($resd,0,'field_data') == htmlspecialchars($extra_fields[$efid])) {
//element did not change
continue;
} else {
} else {
$this->addHistory($field_name, db_result($resd,0,'field_data'));
}
+ $update = true;
}
} else {
$this->setError(db_error());
return false;
}
+ $update = true;
}
}
}
unset($this->extra_field_data);
+
+ if ($update)
+ $this->updateLastModifiedDate();
+
return true;
}
$type=$ef[$arr['extra_field_id']]['field_type'];
if (($type == ARTIFACT_EXTRAFIELDTYPE_CHECKBOX) || ($type==ARTIFACT_EXTRAFIELDTYPE_MULTISELECT)) {
//accumulate a sub-array of values in cases where you may have multiple rows
- if (!is_array($this->extra_field_data[$arr['extra_field_id']])) {
+ if (!array_key_exists($arr['extra_field_id'], $this->extra_field_data) || !is_array($this->extra_field_data[$arr['extra_field_id']])) {
$this->extra_field_data[$arr['extra_field_id']] = array();
}
$this->extra_field_data[$arr['extra_field_id']][]=$arr['field_data'];
} else {
return '';
}
- }
+ }
/**
- * mailFollowup - send out an email update for this artifact.
+ * mailFollowupEx - send out an email update for this artifact.
*
+ * @param time_t Time of the change
* @param int (1) initial/creation (2) update.
* @param array Array of additional addresses to mail to.
* @param array Array of fields changed in this update .
* @access private
* @return boolean success.
*/
- function mailFollowup($type, $more_addresses=false, $changes='') {
+ function mailFollowupEx($tm,$type,$more_addresses=false,$changes='') {
$monitor_ids = array();
if (!$changes) {
$changes=array();
}
-
+
$sess = session_get_user() ;
if ($type == 1) { // Initial opening
if ($sess) {
}
} else {
if ($sess) {
- $body = $this->ArtifactType->getName() ." item #". $this->getID() .", was changed at ". date( _('Y-m-d H:i'), $this->getOpenDate() ) . " by " . $sess->getRealName ();
+ $body = $this->ArtifactType->getName() .
+ " item #" . $this->getID() .
+ " was changed at " .
+ date(_('Y-m-d H:i'), $tm) . " by " .
+ $sess->getRealName();
} else {
- $body = $this->ArtifactType->getName() ." item #". $this->getID() .", was changed at ". date( _('Y-m-d H:i'), $this->getOpenDate() ) ;
+ $body = $this->ArtifactType->getName() .
+ " item #" . $this->getID() .
+ " was changed at " .
+ date(_('Y-m-d H:i'), $tm);
}
}
-
+
$body .= "\nYou can respond by visiting: ".
"\n".util_make_url ('/tracker/?func=detail&atid='. $this->ArtifactType->getID() .
" (". $this->getAssignedUnixName(). ")"."\n".
$this->marker('summary',$changes).
"Summary: ". util_unconvert_htmlspecialchars( $this->getSummary() )." \n";
-
+
// Now display the extra fields
$efd = $this->getExtraFieldDataText();
foreach ($efd as $efid => $ef) {
$body .= $this->marker('extra_fields', $changes, $efid);
$body .= $ef["name"].": ".$ef["value"]."\n";
}
-
+
$subject='['. $this->ArtifactType->Group->getUnixName() . '-' . $this->ArtifactType->getName() . '][' . $this->getID() .'] '. util_unconvert_htmlspecialchars( $this->getSummary() );
if ($type > 1) {
// get all the email addresses that are monitoring this request or the ArtifactType
- $monitor_ids =& $this->getMonitorIds();
+ $monitor_ids = $this->getMonitorIds();
} else {
// initial creation, we just get the users monitoring the ArtifactType
- $monitor_ids =& $this->ArtifactType->getMonitorIds();
+ $monitor_ids = $this->ArtifactType->getMonitorIds();
}
$emails = array();
$result2=$this->getMessages();
$rows=db_numrows($result2);
-
+
if ($result2 && $rows > 0) {
for ($i=0; $i<$rows; $i++) {
//
- // for messages posted by non-logged-in users,
+ // for messages posted by non-logged-in users,
// we grab the email they gave us
//
// otherwise we use the confirmed one from the users table
"\n\nMessage:".
"\n".util_unconvert_htmlspecialchars( db_result($result2,$i,'body') ).
"\n\n----------------------------------------------------------------------";
- }
+ }
}
}
} else {
$monitor_ids=array_unique($monitor_ids);
}
-
+
$from = $this->ArtifactType->getReturnEmailAddress();
$extra_headers = 'Reply-to: '.$from;
-
+
// load the e-mail addresses of the users
$users =& user_get_objects($monitor_ids);
if (count($users) > 0) {
}
}
}
-
+
//now remove all duplicates from the email list
if (count($emails) > 0) {
$BCC=implode(',',array_unique($emails));
- util_send_message('',$subject,$body,$from,$BCC,'',$extra_headers);
+ util_send_message('',$subject,$body,$from,$BCC,'',$extra_headers);
}
-
+
$this->sendSubjectMsg = $subject;
$this->sendBodyMsg = $body;
-
+
//util_handle_message($monitor_ids,$subject,$body,$BCC);
-
+
return true;
}
-
+
/**
* getExtraFieldDataText - Return the extra fields' data in a human-readable form.
*
// associated to the fields
$efs = $this->ArtifactType->getExtraFields();
$efd = $this->getExtraFieldData();
-
+
$return = array();
foreach ($efs as $efid => $ef) {
$name = $ef["field_name"];
$type = $ef["field_type"];
-
+
// Get the value according to the type
switch ($type) {
-
+
// for these types, the associated value comes straight
case ARTIFACT_EXTRAFIELDTYPE_TEXT:
case ARTIFACT_EXTRAFIELDTYPE_TEXTAREA:
$value = '';
}
break;
-
+
// the other types have and ID or an array of IDs associated to them
default:
if (isset($efd[$efid])) {
$value = 'None';
}
}
-
+
$return[$efid] = array("name" => $name, "value" => $value, 'type' => $type);
}
-
+
return $return;
}
+}
+
+class ArtifactComparator {
+ var $criterion = 'artifact_id' ;
+ var $order = 'ASC' ;
+
+ function Compare ($a, $b) {
+ if ($this->order == 'DESC') {
+ $c = $a ; $a = $b ; $b = $c ;
+ }
+ switch ($this->criterion) {
+ case 'summary':
+ $namecmp = strcoll ($a->getSummary(),
+ $b->getSummary()) ;
+ if ($namecmp != 0) {
+ return $namecmp ;
+ }
+ break ;
+ case 'assigned_to':
+ $namecmp = strcoll (user_get_object($a->getAssignedTo())->getRealName(),
+ user_get_object($b->getAssignedTo())->getRealName()) ;
+ if ($namecmp != 0) {
+ return $namecmp ;
+ }
+ break ;
+ case 'submitted_by':
+ $namecmp = strcoll (user_get_object($a->getSubmittedBy())->getRealName(),
+ user_get_object($b->getSubmittedBy())->getRealName()) ;
+ if ($namecmp != 0) {
+ return $namecmp ;
+ }
+ break ;
+ case 'open_date':
+ $a_date = $a->getOpenDate() ;
+ $b_date = $b->getOpenDate() ;
+ return ($a_date < $b_date) ? -1 : 1;
+ break;
+ case 'close_date':
+ $a_date = $a->getCloseDate() ;
+ $b_date = $b->getCloseDate() ;
+ return ($a_date < $b_date) ? -1 : 1;
+ break;
+ case 'last_modified_date':
+ $a_date = $a->getLastModifiedDate() ;
+ $b_date = $b->getLastModifiedDate() ;
+ return ($a_date < $b_date) ? -1 : 1;
+ break;
+ case 'priority':
+ $a_prority = $a->getPriority() ;
+ $b_prority = $b->getPriority() ;
+ return ($a_prority < $b_prority) ? -1 : 1;
+ break;
+ default:
+ $aa=$a->getExtraFieldDataText();
+ $ba=$b->getExtraFieldDataText();
+ $af=$aa[$this->criterion]['value'];
+ $bf=$ba[$this->criterion]['value'];
+ $namecmp = strcoll ($af,$bf) ;
+ if ($namecmp != 0) {
+ return $namecmp ;
+ }
+ break ;
+ }
+
+ // When in doubt, sort on artifact ID
+ $aid = $a->getID() ;
+ $bid = $b->getID() ;
+ if ($aid == $bid) {
+ return 0;
+ }
+ return ($aid < $bid) ? -1 : 1;
+ }
+}
+
+function sortArtifactList (&$list, $criterion='name', $order='ASC') {
+ $cmp = new ArtifactComparator () ;
+ $cmp->criterion = $criterion ;
+ $cmp->order = $order ;
+ return usort ($list, array ($cmp, 'Compare')) ;
}
// Local Variables: