5 * Copyright 1999-2001 (c) VA Linux Systems
6 * Copyright 2002-2004 (c) GForge Team
7 * Copyright 2012, Franck Villaume - TrivialDev
8 * http://fusionforge.org/
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.
32 // Create the ArtifactType object
34 $ath = new ArtifactTypeHtml($group, $atid);
36 if (!$ath || !is_object($ath)) {
37 exit_error(_('ArtifactType could not be created'),'tracker');
39 if ($ath->isError()) {
40 if($ath->isPermissionDeniedError()) {
41 exit_permission_denied($ath->getErrorMessage(),'tracker');
43 exit_error($ath->getErrorMessage(),'tracker');
46 switch (getStringFromRequest('func')) {
49 if (!forge_check_perm ('tracker',$ath->getID(),'submit')) {
50 exit_permission_denied('tracker');
52 include $gfcommon.'tracker/actions/add.php';
56 if (!form_key_is_valid(getStringFromRequest('form_key'))) {
57 exit_form_double_submit('tracker');
60 $user_email = getStringFromRequest('user_email');
61 $artifact_group_id = getIntFromRequest('artifact_group_id');
62 $summary = getStringFromRequest('summary');
63 $details = getStringFromRequest('details');
64 $assigned_to = getStringFromRequest('assigned_to');
65 $priority = getStringFromRequest('priority');
66 $extra_fields = getStringFromRequest('extra_fields');
71 $ah=new ArtifactHtml($ath);
72 if (!$ah || !is_object($ah)) {
73 form_release_key(getStringFromRequest('form_key'));
74 exit_error(_('Artifact Could Not Be Created'),'tracker');
75 } elseif (!forge_check_perm ('tracker',$ath->getID(),'submit')) {
76 exit_permission_denied('tracker');
79 if (empty($user_email)) {
82 if (!validate_email($user_email)) {
83 form_release_key(getStringFromRequest('form_key'));
84 exit_error(_('Invalid Email Address') . htmlspecialchars($user_email),'tracker');
88 $details = "Anonymous message posted by $user_email\n\n".$details;
91 if (!$ah->create($summary,$details,$assigned_to,$priority,$extra_fields)) {
92 $error_msg = $ah->getErrorMessage();
93 form_release_key(getStringFromRequest('form_key'));
94 include $gfcommon.'tracker/actions/add.php';
96 $feedback .= sprintf(_('Item %s successfully created'),'[#'.$ah->getID().']');
99 // Attach files to this Artifact.
101 for ($i=0; $i<5; $i++) {
102 $f = getUploadedFile("input_file$i");
103 $error = $f['error'];
104 if (isset($error) && $error > 0) {
106 if ($error === 1 || $error === 2) {
107 // UPLOAD_ERR_INI_SIZE or UPLOAD_ERR_FORM_SIZE
108 $error_msg = sprintf(_('Error on attached file %1$d, file is too large (maximum: %2$s).'),
109 $n, ini_get('upload_max_filesize'));
110 } elseif ($error === 3) {
111 // UPLOAD_ERR_PARTIAL
112 $error_msg = sprintf(_('Error on attached file %1$d, transfert interrupted.'), $n);
116 $file_name = $f['name'];
117 $tmp_name = $f['tmp_name'];
120 if (!is_uploaded_file($tmp_name)) {
124 $afh=new ArtifactFileHtml($ah);
125 if (!$afh || !is_object($afh)) {
126 $error_msg .= _('Could Not Create File Object');
127 } elseif ($afh->isError()) {
128 $error_msg .= $afh->getErrorMessage();
130 if (!util_check_fileupload($tmp_name)) {
131 $error_msg = _('Invalid filename');
133 if (!$afh->upload($tmp_name,$file_name,$type,' ')) {
134 $error_msg = _('Could Not Attach File to Item: '.$afh->getErrorMessage());
138 session_redirect('/tracker/?group_id='.$group_id.'&atid='.$atid.'&aid='.$aid);
142 case 'massupdate' : {
143 if (!form_key_is_valid(getStringFromRequest('form_key'))) {
144 exit_form_double_submit('tracker');
147 $artifact_id_list = getArrayFromRequest('artifact_id_list');
148 $priority = getStringFromRequest('priority');
149 $status_id = getIntFromRequest('status_id');
150 $artifact_group_id = getIntFromRequest('artifact_group_id');
151 $resolution_id = getIntFromRequest('resolution_id');
152 $assigned_to = getStringFromRequest('assigned_to');
153 $canned_response = getIntFromRequest("canned_response");
154 $extra_fields = getArrayFromRequest('extra_fields');
157 $count=count($artifact_id_list);
159 session_require_perm ('tracker', $ath->getID(), 'manager') ;
161 $artifact_type_id=$ath->getID();
163 for ($i=0; $i < $count; $i++) {
164 $ah=new Artifact($ath,$artifact_id_list[$i]);
165 if (!$ah || !is_object($ah)) {
166 $feedback .= ' ID: '.$artifact_id_list[$i].'::Artifact Could Not Be Created';
167 } elseif ($ah->isError()) {
168 $feedback .= ' ID: '.$artifact_id_list[$i].'::'.$ah->getErrorMessage();
171 $_priority=(($priority != 100) ? $priority : $ah->getPriority());
172 $_status_id=(($status_id != 100) ? $status_id : $ah->getStatusID());
173 //yikes, we want the ability to mass-update to "un-assigned", which is the ID=100, which
174 //conflicts with the "no change" ID! Sorry for messy use of 100.1
175 $_assigned_to=(($assigned_to != '100.1') ? $assigned_to : $ah->getAssignedTo());
178 // get existing extra field data
179 // we will then override individual elements if needed
181 $ef = $ah->getExtraFieldData();
182 $keys = array_keys($ef);
183 foreach ($keys as $efid) {
184 if (is_array($ef[$efid])) {
185 $f = $extra_fields[$efid];
186 // in this case, if $extra_fields is not setted, it
187 // means no option was selected, so we have to delete
188 // the original values
189 if (!is_array($f) || count($f) == 0) {
190 $ef[$efid] = array();
191 } elseif (in_array('100', $extra_fields[$efid])) { // "No change" option selected?
194 $ef[$efid] = $f; // replace old values with new values
197 // in some cases (ie: textfields) the value is not passed, but
198 // this doesn't mean we must delete the existing value
199 if (array_key_exists($efid, $extra_fields)) {
200 $f = $extra_fields[$efid];
207 $ef[$efid] = addslashes($ef[$efid]);
212 if (!$ah->update($_priority,$_status_id,$_assigned_to,$_summary,$canned_response,'',$artifact_type_id,$ef)) {
217 $error_msg .= ' ID: '.$artifact_id_list[$i].'::'.$ah->getErrorMessage();
225 $feedback = _('Updated Successfully'); }
227 unset ($extra_fields_choice);
228 include $gfcommon.'tracker/actions/browse.php';
232 $artifact_id = getIntFromRequest('artifact_id');
233 $priority = getIntFromRequest('priority');
234 $status_id = getIntFromRequest('status_id');
235 $artifact_group_id = getIntFromRequest('artifact_group_id');
236 $resolution_id = getIntFromRequest('resolution_id');
237 $assigned_to = getStringFromRequest('assigned_to');
238 $summary = getStringFromRequest('summary');
239 $canned_response = getStringFromRequest('canned_response');
240 $details = getStringFromRequest('details');
241 $description = getStringFromRequest('description');
242 $new_artifact_type_id = getIntFromRequest('new_artifact_type_id');
243 $extra_fields = getStringFromRequest('extra_fields');
244 $user_email = getStringFromRequest('user_email', false);
248 Technicians can modify limited fields - to be certain
249 no one is hacking around, we override any fields they don't have
250 permission to change.
252 if (!form_key_is_valid(getStringFromRequest('form_key'))) {
253 exit_form_double_submit('tracker');
256 $ah=new ArtifactHtml($ath,$artifact_id);
257 if (!$ah || !is_object($ah)) {
258 exit_error(_('Artifact Could Not Be Created'),'tracker');
259 } elseif ($ah->isError()) {
260 exit_error($ah->getErrorMessage(),'tracker');
261 } elseif (!forge_check_perm ('tracker',$ath->getID(),'submit')) {
262 exit_permission_denied('tracker');
265 $remlink = getArrayFromRequest('remlink');
266 if (count($remlink) > 0 && forge_check_perm ('tracker_admin', $ah->ArtifactType->Group->getID())) {
267 require_once $gfcommon.'pm/ProjectTask.class.php';
268 foreach ($remlink as $tid) {
269 $pt = &projecttask_get_object($tid);
270 if (!$pt || $pt->isError())
271 exit_error(_('Error'), sprintf(_('Could not get Project Task for %d'), $tid));
272 if (!$pt->removeRelatedArtifacts(array($artifact_id)))
273 exit_error($tid."->removeRelatedArtifacts(".$artifact_id.")", $pt->getErrorMessage());
277 The following logic causes fields to be overridden
278 in the event that someone tampered with the HTML form
280 if (forge_check_perm ('tracker', $ath->getID(), 'tech')
281 || forge_check_perm ('tracker', $ath->getID(), 'manager')) {
282 //admin and techs can do everything
283 //techs will have certain fields overridden inside the update() function call
284 if (!$ah->update($priority,$status_id,
285 $assigned_to,$summary,$canned_response,$details,$new_artifact_type_id,$extra_fields, $description)) {
286 form_release_key(getStringFromRequest('form_key'));
287 $error_msg .= _('Tracker Item'). ': '.$ah->getErrorMessage();
294 // Everyone else can add comments
296 if ($ah->addMessage($details,$user_email,true)) {
297 $feedback=_('Comment added');
299 if ( (strlen($details)>0) ) { //if there was no message, then it's not an error but addMessage returns false and sets missing params error
300 //some kind of error in creation
301 exit_error($ah->getErrorMessage(),'tracker');
303 // we have to unset the error if the user added a file ( add a file and no comment)
304 if ( (getStringFromRequest('add_file')) ) {
312 //everyone else can only add comments
315 if ($ah->addMessage($details,$user_email,true)) {
316 $feedback=_('Comment added');
318 //some kind of error in creation
319 exit_error($ah->getErrorMessage(),'tracker');
324 // Admin, Techs and Submitter can add files.
325 if (forge_check_perm ('tracker', $ath->getID(), 'tech')
326 || forge_check_perm ('tracker', $ath->getID(), 'manager')
327 || (session_loggedin() && ($ah->getSubmittedBy() == user_getid()))) {
329 // Attach files to this Artifact.
332 for ($i=0; $i<5; $i++) {
333 $f = getUploadedFile("input_file$i");
334 $error = $f['error'];
335 if (isset($error) && $error > 0) {
337 if ($error === 1 || $error === 2) {
338 // UPLOAD_ERR_INI_SIZE or UPLOAD_ERR_FORM_SIZE
339 $ext_feedback .= "<br />" .
340 sprintf(_("ERROR: Skipping attachment %d: file is too large."), $n);
341 } elseif ($error === 3) {
342 // UPLOAD_ERR_PARTIAL
343 $ext_feedback .= "<br />" .
344 sprintf(_("ERROR: Skipping attachment %d: transfer interrupted."), $n);
348 $file_name = $f['name'];
349 $tmp_name = $f['tmp_name'];
353 if (!is_uploaded_file($tmp_name)) {
357 $afh=new ArtifactFileHtml($ah);
358 if (!$afh || !is_object($afh)) {
359 $error_msg .= _('Could Not Create File Object');
360 } elseif ($afh->isError()) {
361 $error_msg .= $afh->getErrorMessage();
363 if (!util_check_fileupload($tmp_name)) {
364 form_release_key(getStringFromRequest('form_key'));
365 exit_error(_('Invalid filename'),'tracker');
367 if (!$afh->upload($tmp_name,$file_name,$type,' ')) {
368 $error_msg .= ' <br />'._('File Upload: Error').':'.$afh->getErrorMessage();
371 $feedback .= ' <br />'._('File Upload: Successful');
376 // Admin and Techs can delete files.
377 if (forge_check_perm ('tracker', $ath->getID(), 'tech')
378 || forge_check_perm ('tracker', $ath->getID(), 'manager')) {
380 // Delete list of files from this artifact
382 $delete_file = getStringFromRequest('delete_file');
384 $count=count($delete_file);
385 for ($i=0; $i<$count; $i++) {
386 $afh=new ArtifactFileHtml($ah,$delete_file[$i]);
387 if (!$afh || !is_object($afh)) {
388 $error_msg .= _('Could Not Create File Object::').$delete_file[$i];
389 } elseif ($afh->isError()) {
390 $error_msg .= $afh->getErrorMessage().'::'.$delete_file[$i];
392 if (!$afh->delete()) {
393 $error_msg .= ' <br />'._('File Delete:').': '.$afh->getErrorMessage();
396 $feedback .= ' <br />'._('File Delete: Successful');
404 // Show just one feedback entry if no errors
407 $feedback = sprintf(_('Item %s successfully updated'),'[#'.$ah->getID().']');
409 $feedback .= $ext_feedback;
410 include $gfcommon.'tracker/actions/browse.php';
416 if (!session_loggedin()) {
417 exit_permission_denied();
419 $start = getIntFromRequest('start');
420 $stop = getIntFromRequest('stop');
421 $artifact_id = getIntFromRequest('artifact_id');
423 // Fix to prevent collision with the start variable used in browse.
427 $ah=new ArtifactHtml($ath,$artifact_id);
428 if (!$ah || !is_object($ah)) {
429 exit_error(_('Artifact Could Not Be Created'),'tracker');
430 } elseif ($ah->isError()) {
431 exit_error($ah->getErrorMessage(),'tracker');
433 if ($start && $ah->isMonitoring())
434 $feedback = _('Monitoring Started');
435 elseif ($stop && !$ah->isMonitoring())
436 $feedback = _('Monitoring Deactivated');
439 $error_msg = $ah->getErrorMessage();
441 include $gfcommon.'tracker/actions/browse.php';
444 $at=new ArtifactType($group,$atid);
445 if (!$at || !is_object($at)) {
446 exit_error(_('Artifact Could Not Be Created'),'tracker');
447 } elseif ($at->isError()) {
448 exit_error($at->getErrorMessage(),'tracker');
450 if ($start && $at->isMonitoring())
451 $feedback = _('Monitoring Started');
452 elseif ($stop && !$at->isMonitoring())
453 $feedback = _('Monitoring Deactivated');
456 $feedback=$at->getErrorMessage();
459 include $gfcommon.'tracker/actions/browse.php';
469 case 'deleteartifact' : {
470 session_require_perm ('tracker', $ath->getID(), 'manager') ;
472 $aid = getIntFromRequest('aid');
473 $ah= new ArtifactHtml($ath,$aid);
474 if (!$ah || !is_object($ah)) {
475 exit_error(_('Artifact Could Not Be Created'),'tracker');
476 } elseif ($ah->isError()) {
477 exit_error($ah->getErrorMessage(),'tracker');
479 include $gfcommon.'tracker/actions/deleteartifact.php';
484 // Handle the actual delete
487 case 'postdeleteartifact' : {
488 if (!form_key_is_valid(getStringFromRequest('form_key'))) {
489 exit_form_double_submit('tracker');
491 session_require_perm ('tracker', $ath->getID(), 'manager') ;
493 $aid = getStringFromRequest('aid');
494 $ah= new ArtifactHtml($ath,$aid);
495 if (!$ah || !is_object($ah)) {
496 exit_error(_('Artifact Could Not Be Created'),'tracker');
497 } elseif ($ah->isError()) {
498 exit_error($ah->getErrorMessage(),'tracker');
500 if (!getStringFromRequest('confirm_delete')) {
501 $warning_msg .= _('Confirmation failed. Artifact not deleted');
504 if (!$ah->delete(true)) {
505 $error_msg .= _('Artifact Delete Failed') . ': '.$ah->getErrorMessage();
507 $feedback .= _('Artifact Deleted Successfully');
510 include $gfcommon.'tracker/actions/browse.php';
516 include $gfcommon.'tracker/actions/taskmgr.php';
520 include $gfcommon.'tracker/actions/browse.php';
524 include $gfcommon.'tracker/actions/query.php';
528 include $gfcommon.'tracker/actions/csv.php';
531 case 'format_csv' : {
532 include $gfcommon.'tracker/actions/format_csv.php';
535 case 'downloadcsv' : {
536 include $gfcommon.'tracker/actions/downloadcsv.php';
540 $aid = getIntFromRequest('aid');
541 session_redirect('/tracker/download.php?group_id='.$group_id.'&atid='.$atid.'&aid='.$aid.'&file_id='.$file_id);
545 $aid = getIntFromRequest('aid');
548 // users can modify their own tickets in a limited way if they submitted them
549 // even if they are not artifact admins
551 $ah=new ArtifactHtml($ath,$aid);
552 if (!$ah || !is_object($ah)) {
553 exit_error(_('Artifact Could Not Be Created'),'tracker');
554 } elseif ($ah->isError()) {
555 exit_error($ah->getErrorMessage(),'tracker');
557 if (forge_check_perm ('tracker', $ath->getID(), 'manager')) {
558 include $gfcommon.'tracker/actions/mod.php';
559 } elseif (forge_check_perm ('tracker', $ath->getID(), 'tech')) {
560 include $gfcommon.'tracker/actions/mod-limited.php';
562 include $gfcommon.'tracker/actions/detail.php';
568 include $gfcommon.'tracker/actions/browse.php';
575 // c-file-style: "bsd"