5 * Copyright 1999-2001 (c) VA Linux Systems
6 * Copyright 2002-2004 (c) GForge Team
7 * http://fusionforge.org/
9 * This file is part of FusionForge. FusionForge is free software;
10 * you can redistribute it and/or modify it under the terms of the
11 * GNU General Public License as published by the Free Software
12 * Foundation; either version 2 of the Licence, or (at your option)
15 * FusionForge is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License along
21 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
29 // get the Group object
31 $group =& group_get_object($group_id);
32 if (!$group || !is_object($group)) {
35 if ($group->isError()) {
36 if($group->isPermissionDeniedError()) {
37 exit_permission_denied($group->getErrorMessage(),'tracker');
39 exit_error($group->getErrorMessage(),'tracker');
44 // Create the ArtifactType object
46 $ath = new ArtifactTypeHtml($group,$atid);
48 if (!$ath || !is_object($ath)) {
49 exit_error(_('ArtifactType could not be created'),'tracker');
51 if ($ath->isError()) {
52 if($ath->isPermissionDeniedError()) {
53 exit_permission_denied($ath->getErrorMessage(),'tracker');
55 exit_error($ath->getErrorMessage(),'tracker');
58 switch (getStringFromRequest('func')) {
61 if (!$ath->allowsAnon() && !session_loggedin()) {
62 exit_permission_denied('tracker');
64 include $gfcommon.'tracker/actions/add.php';
68 if (!form_key_is_valid(getStringFromRequest('form_key'))) {
69 exit_form_double_submit('tracker');
72 $user_email = getStringFromRequest('user_email');
73 $category_id = getIntFromRequest('category_id');
74 $artifact_group_id = getIntFromRequest('artifact_group_id');
75 $summary = getStringFromRequest('summary');
76 $details = getStringFromRequest('details');
77 $assigned_to = getStringFromRequest('assigned_to');
78 $priority = getStringFromRequest('priority');
79 $extra_fields = getStringFromRequest('extra_fields');
85 $ah=new ArtifactHtml($ath);
87 if (!$ah || !is_object($ah)) {
88 form_release_key(getStringFromRequest('form_key'));
89 exit_error(_('Artifact Could Not Be Created'),'tracker');
90 } else if (!$ath->allowsAnon() && !session_loggedin()) {
91 exit_error(_('Artifact: This ArtifactType Does Not Allow Anonymous Submissions. Please Login.'),'tracker');
93 if (empty($user_email)) {
96 if (!validate_email($user_email)) {
97 form_release_key(getStringFromRequest('form_key'));
98 exit_error(_('Invalid Email Address') . htmlspecialchars($user_email),'tracker');
102 $details = "Anonymous message posted by $user_email\n\n".
105 if (!$ah->create($summary,$details,$assigned_to,$priority,$extra_fields)) {
106 form_release_key(getStringFromRequest('form_key'));
107 exit_error($ah->getErrorMessage(),'tracker');
110 // Attach files to this Artifact.
113 for ($i=0; $i<5; $i++) {
114 $f = getUploadedFile("input_file$i");
115 $error = $f['error'];
116 if (isset($error) && $error > 0) {
118 if ($error === 1 || $error === 2) {
119 // UPLOAD_ERR_INI_SIZE or UPLOAD_ERR_FORM_SIZE
120 $ext_feedback .= "<br />ERROR: Skipping attachement $n: file is too large.";
121 } elseif ($error === 3) {
122 // UPLOAD_ERR_PARTIAL
123 $ext_feedback .= "<br />ERROR: Skipping attachement $n: transfert interrupted.";
127 $file_name = $f['name'];
128 $tmp_name = $f['tmp_name'];
131 if (!is_uploaded_file($tmp_name)) {
135 $afh=new ArtifactFileHtml($ah);
136 if (!$afh || !is_object($afh)) {
137 $error_msg .= _('Could Not Create File Object');
138 } elseif ($afh->isError()) {
139 $error_msg .= $afh->getErrorMessage();
141 if (!util_check_fileupload($tmp_name)) {
142 form_release_key(getStringFromRequest('form_key'));
143 //delete the artifact
145 exit_error(_('Invalid filename'),'tracker');
147 if (!$afh->upload($tmp_name,$file_name,$type,' ')) {
148 form_release_key(getStringFromRequest('form_key'));
149 //delete the artifact
151 exit_error(_('Could Not Attach File to Item: '.$afh->getErrorMessage()),'tracker');
155 $feedback .= sprintf(_('Item %s successfully created'),'[#'.$ah->getID().']');
156 $feedback .= $ext_feedback;
157 include $gfcommon.'tracker/actions/browse.php';
162 case 'massupdate' : {
163 if (!form_key_is_valid(getStringFromRequest('form_key'))) {
164 exit_form_double_submit('tracker');
167 $artifact_id_list = getArrayFromRequest('artifact_id_list');
168 $priority = getStringFromRequest('priority');
169 $status_id = getIntFromRequest('status_id');
170 $category_id = getIntFromRequest('category_id');
171 $artifact_group_id = getIntFromRequest('artifact_group_id');
172 $resolution_id = getIntFromRequest('resolution_id');
173 $assigned_to = getStringFromRequest('assigned_to');
174 $canned_response = getIntFromRequest("canned_response");
175 $extra_fields = getArrayFromRequest('extra_fields');
178 $count=count($artifact_id_list);
180 session_require_perm ('tracker', $ath->getID(), 'manager') ;
182 $artifact_type_id=$ath->getID();
184 for ($i=0; $i < $count; $i++) {
185 $ah=new Artifact($ath,$artifact_id_list[$i]);
186 if (!$ah || !is_object($ah)) {
187 $feedback .= ' ID: '.$artifact_id_list[$i].'::Artifact Could Not Be Created';
188 } else if ($ah->isError()) {
189 $feedback .= ' ID: '.$artifact_id_list[$i].'::'.$ah->getErrorMessage();
192 $_priority=(($priority != 100) ? $priority : $ah->getPriority());
193 $_status_id=(($status_id != 100) ? $status_id : $ah->getStatusID());
194 //yikes, we want the ability to mass-update to "un-assigned", which is the ID=100, which
195 //conflicts with the "no change" ID! Sorry for messy use of 100.1
196 $_assigned_to=(($assigned_to != '100.1') ? $assigned_to : $ah->getAssignedTo());
199 // get existing extra field data
200 // we will then override individual elements if needed
202 $ef = $ah->getExtraFieldData();
203 $keys = array_keys($ef);
204 foreach ($keys as $efid) {
205 if (is_array($ef[$efid])) {
206 $f = $extra_fields[$efid];
207 // in this case, if $extra_fields is not setted, it
208 // means no option was selected, so we have to delete
209 // the original values
210 if (!is_array($f) || count($f) == 0) {
211 $ef[$efid] = array();
212 } else if (in_array('100', $extra_fields[$efid])) { // "No change" option selected?
215 $ef[$efid] = $f; // replace old values with new values
218 // in some cases (ie: textfields) the value is not passed, but
219 // this doesn't mean we must delete the existing value
220 if (array_key_exists($efid, $extra_fields)) {
221 $f = $extra_fields[$efid];
228 $ef[$efid] = addslashes($ef[$efid]);
233 if (!$ah->update($_priority,$_status_id,$_assigned_to,$_summary,$canned_response,'',$artifact_type_id,$ef)) {
238 $error_msg .= ' ID: '.$artifact_id_list[$i].'::'.$ah->getErrorMessage();
246 $feedback = _('Updated Successfully'); }
248 unset ($extra_fields_choice);
249 include $gfcommon.'tracker/actions/browse.php';
253 $artifact_id = getIntFromRequest('artifact_id');
254 $priority = getIntFromRequest('priority');
255 $status_id = getIntFromRequest('status_id');
256 $category_id = getIntFromRequest('category_id');
257 $artifact_group_id = getIntFromRequest('artifact_group_id');
258 $resolution_id = getIntFromRequest('resolution_id');
259 $assigned_to = getStringFromRequest('assigned_to');
260 $summary = getStringFromRequest('summary');
261 $canned_response = getStringFromRequest('canned_response');
262 $details = getStringFromRequest('details');
263 $description = getStringFromRequest('description');
264 $new_artifact_type_id = getIntFromRequest('new_artifact_type_id');
265 $extra_fields = getStringFromRequest('extra_fields');
266 $user_email = getStringFromRequest('user_email', false);
270 Technicians can modify limited fields - to be certain
271 no one is hacking around, we override any fields they don't have
272 permission to change.
274 if (!form_key_is_valid(getStringFromRequest('form_key'))) {
275 exit_form_double_submit('tracker');
278 $ah=new ArtifactHtml($ath,$artifact_id);
279 if (!$ah || !is_object($ah)) {
280 exit_error(_('Artifact Could Not Be Created'),'tracker');
281 } else if ($ah->isError()) {
282 exit_error($ah->getErrorMessage(),'tracker');
283 } else if (!$ath->allowsAnon() && !session_loggedin()) {
284 exit_error(_('Artifact: This ArtifactType Does Not Allow Anonymous Submissions. Please Login.'),'tracker');
287 $remlink = getArrayFromRequest('remlink');
288 if (count($remlink) > 0 && forge_check_perm ('tracker_admin', $ah->ArtifactType->Group->getID())) {
289 require_once $gfcommon.'pm/ProjectTask.class.php';
290 foreach ($remlink as $tid) {
291 $pt = &projecttask_get_object($tid);
292 if (!$pt || $pt->isError())
293 exit_error(_('Error'), sprintf(_('Could not get Project Task for %d'), $tid));
294 if (!$pt->removeRelatedArtifacts(array($artifact_id)))
295 exit_error($tid."->removeRelatedArtifacts(".$artifact_id.")", $pt->getErrorMessage());
300 The following logic causes fields to be overridden
301 in the event that someone tampered with the HTML form
304 if (forge_check_perm ('tracker', $ath->getID(), 'tech')
305 || forge_check_perm ('tracker', $ath->getID(), 'manager')) {
306 //admin and techs can do everything
307 //techs will have certain fields overridden inside the update() function call
308 if (!$ah->update($priority,$status_id,
309 $assigned_to,$summary,$canned_response,$details,$new_artifact_type_id,$extra_fields, $description)) {
310 form_release_key(getStringFromRequest('form_key'));
311 $error_msg .= _('Tracker Item'). ': '.$ah->getErrorMessage();
318 // Everyone else can add comments
320 if ($ah->addMessage($details,$user_email,true)) {
321 $feedback=_('Comment added');
323 if ( (strlen($details)>0) ) { //if there was no message, then it's not an error but addMessage returns false and sets missing params error
324 //some kind of error in creation
325 exit_error($ah->getErrorMessage(),'tracker');
327 // we have to unset the error if the user added a file ( add a file and no comment)
328 if ( (getStringFromRequest('add_file')) ) {
336 //everyone else can only add comments
339 if ($ah->addMessage($details,$user_email,true)) {
340 $feedback=_('Comment added');
342 //some kind of error in creation
343 exit_error($ah->getErrorMessage(),'tracker');
348 // Admin, Techs and Submitter can add files.
349 if (forge_check_perm ('tracker', $ath->getID(), 'tech')
350 || forge_check_perm ('tracker', $ath->getID(), 'manager')
351 || (session_loggedin() && ($ah->getSubmittedBy() == user_getid()))) {
353 // Attach files to this Artifact.
356 for ($i=0; $i<5; $i++) {
357 $f = getUploadedFile("input_file$i");
358 $error = $f['error'];
359 if (isset($error) && $error > 0) {
361 if ($error === 1 || $error === 2) {
362 // UPLOAD_ERR_INI_SIZE or UPLOAD_ERR_FORM_SIZE
363 $ext_feedback .= "<br />" .
364 sprintf(_("ERROR: Skipping attachment %d: file is too large."), $n);
365 } elseif ($error === 3) {
366 // UPLOAD_ERR_PARTIAL
367 $ext_feedback .= "<br />" .
368 sprintf(_("ERROR: Skipping attachment %d: transfer interrupted."), $n);
372 $file_name = $f['name'];
373 $tmp_name = $f['tmp_name'];
377 if (!is_uploaded_file($tmp_name)) {
381 $afh=new ArtifactFileHtml($ah);
382 if (!$afh || !is_object($afh)) {
383 $error_msg .= _('Could Not Create File Object');
384 } elseif ($afh->isError()) {
385 $error_msg .= $afh->getErrorMessage();
387 if (!util_check_fileupload($tmp_name)) {
388 form_release_key(getStringFromRequest('form_key'));
389 exit_error(_('Invalid filename'),'tracker');
391 if (!$afh->upload($tmp_name,$file_name,$type,' ')) {
392 $error_msg .= ' <br />'._('File Upload: Error').':'.$afh->getErrorMessage();
395 $feedback .= ' <br />'._('File Upload: Successful');
400 // Admin and Techs can delete files.
401 if (forge_check_perm ('tracker', $ath->getID(), 'tech')
402 || forge_check_perm ('tracker', $ath->getID(), 'manager')) {
404 // Delete list of files from this artifact
406 $delete_file = getStringFromRequest('delete_file');
408 $count=count($delete_file);
409 for ($i=0; $i<$count; $i++) {
410 $afh=new ArtifactFileHtml($ah,$delete_file[$i]);
411 if (!$afh || !is_object($afh)) {
412 $error_msg .= _('Could Not Create File Object::').$delete_file[$i];
413 } elseif ($afh->isError()) {
414 $error_msg .= $afh->getErrorMessage().'::'.$delete_file[$i];
416 if (!$afh->delete()) {
417 $error_msg .= ' <br />'._('File Delete:').': '.$afh->getErrorMessage();
420 $feedback .= ' <br />'._('File Delete: Successful');
428 // Show just one feedback entry if no errors
431 $feedback = sprintf(_('Item %s successfully updated'),'[#'.$ah->getID().']');
433 $feedback .= $ext_feedback;
434 include $gfcommon.'tracker/actions/browse.php';
440 if (!session_loggedin()) {
441 exit_permission_denied();
443 $start = getIntFromRequest('start');
444 $stop = getIntFromRequest('stop');
445 $artifact_id = getIntFromRequest('artifact_id');
447 // Fix to prevent collision with the start variable used in browse.
451 $ah=new ArtifactHtml($ath,$artifact_id);
452 if (!$ah || !is_object($ah)) {
453 exit_error(_('Artifact Could Not Be Created'),'tracker');
454 } else if ($ah->isError()) {
455 exit_error($ah->getErrorMessage(),'tracker');
457 if ($start && $ah->isMonitoring())
458 $feedback = _('Monitoring Started');
459 elseif ($stop && !$ah->isMonitoring())
460 $feedback = _('Monitoring Deactivated');
463 $error_msg = $ah->getErrorMessage();
465 include $gfcommon.'tracker/actions/browse.php';
468 $at=new ArtifactType($group,$atid);
469 if (!$at || !is_object($at)) {
470 exit_error(_('Artifact Could Not Be Created'),'tracker');
471 } else if ($at->isError()) {
472 exit_error($at->getErrorMessage(),'tracker');
474 if ($start && $at->isMonitoring())
475 $feedback = _('Monitoring Started');
476 elseif ($stop && !$at->isMonitoring())
477 $feedback = _('Monitoring Deactivated');
480 $feedback=$at->getErrorMessage();
483 include $gfcommon.'tracker/actions/browse.php';
493 case 'deleteartifact' : {
494 session_require_perm ('tracker', $ath->getID(), 'manager') ;
496 $aid = getIntFromRequest('aid');
497 $ah= new ArtifactHtml($ath,$aid);
498 if (!$ah || !is_object($ah)) {
499 exit_error(_('Artifact Could Not Be Created'),'tracker');
500 } elseif ($ah->isError()) {
501 exit_error($ah->getErrorMessage(),'tracker');
503 include $gfcommon.'tracker/actions/deleteartifact.php';
508 // Handle the actual delete
511 case 'postdeleteartifact' : {
512 if (!form_key_is_valid(getStringFromRequest('form_key'))) {
513 exit_form_double_submit('tracker');
515 session_require_perm ('tracker', $ath->getID(), 'manager') ;
517 $aid = getStringFromRequest('aid');
518 $ah= new ArtifactHtml($ath,$aid);
519 if (!$ah || !is_object($ah)) {
520 exit_error(_('Artifact Could Not Be Created'),'tracker');
521 } elseif ($ah->isError()) {
522 exit_error($ah->getErrorMessage(),'tracker');
524 if (!getStringFromRequest('confirm_delete')) {
525 $warning_msg .= _('Confirmation failed. Artifact not deleted');
528 if (!$ah->delete(true)) {
529 $error_msg .= _('Artifact Delete Failed') . ': '.$ah->getErrorMessage();
531 $feedback .= _('Artifact Deleted Successfully');
534 include $gfcommon.'tracker/actions/browse.php';
540 include $gfcommon.'tracker/actions/taskmgr.php';
544 include $gfcommon.'tracker/actions/browse.php';
548 include $gfcommon.'tracker/actions/query.php';
552 include $gfcommon.'tracker/actions/csv.php';
555 case 'format_csv' : {
556 include $gfcommon.'tracker/actions/format_csv.php';
559 case 'downloadcsv' : {
560 include $gfcommon.'tracker/actions/downloadcsv.php';
564 $aid = getIntFromRequest('aid');
565 session_redirect('/tracker/download.php?group_id='.$group_id.'&atid='.$atid.'&aid='.$aid.'&file_id='.$file_id);
569 $aid = getIntFromRequest('aid');
572 // users can modify their own tickets in a limited way if they submitted them
573 // even if they are not artifact admins
575 $ah=new ArtifactHtml($ath,$aid);
576 if (!$ah || !is_object($ah)) {
577 exit_error(_('Artifact Could Not Be Created'),'tracker');
578 } else if ($ah->isError()) {
579 exit_error($ah->getErrorMessage(),'tracker');
581 if (forge_check_perm ('tracker', $ath->getID(), 'manager')) {
582 include $gfcommon.'tracker/actions/mod.php';
583 } elseif (forge_check_perm ('tracker', $ath->getID(), 'tech')) {
584 include $gfcommon.'tracker/actions/mod-limited.php';
586 include $gfcommon.'tracker/actions/detail.php';
592 include $gfcommon.'tracker/actions/browse.php';
599 // c-file-style: "bsd"