5 // get the Group object
7 $group =& group_get_object($group_id);
8 if (!$group || !is_object($group)) {
11 if ($group->isError()) {
12 if($group->isPermissionDeniedError()) {
13 exit_permission_denied($group->getErrorMessage());
15 exit_error(_('Error'), $group->getErrorMessage());
19 // Create the ArtifactType object
21 $ath = new ArtifactTypeHtml($group,$atid);
23 if (!$ath || !is_object($ath)) {
24 exit_error('Error','ArtifactType could not be created');
26 if ($ath->isError()) {
27 if($ath->isPermissionDeniedError()) {
28 exit_permission_denied($group->getErrorMessage());
30 exit_error(_('Error'), $ath->getErrorMessage());
33 switch (getStringFromRequest('func')) {
36 if (!$ath->allowsAnon() && !session_loggedin()) {
37 exit_permission_denied();
39 include $gfwww.'tracker/add.php';
44 if (!form_key_is_valid(getStringFromRequest('form_key'))) {
45 exit_form_double_submit();
48 $user_email = getStringFromRequest('user_email');
49 $category_id = getIntFromRequest('category_id');
50 $artifact_group_id = getIntFromRequest('artifact_group_id');
51 $summary = getStringFromRequest('summary');
52 $details = getStringFromRequest('details');
53 $assigned_to = getStringFromRequest('assigned_to');
54 $priority = getStringFromRequest('priority');
55 $extra_fields = getStringFromRequest('extra_fields');
61 $ah=new ArtifactHtml($ath);
63 if (!$ah || !is_object($ah)) {
64 form_release_key(getStringFromRequest('form_key'));
65 exit_error('ERROR','Artifact Could Not Be Created');
66 } else if (!$ath->allowsAnon() && !session_loggedin()) {
67 exit_error('ERROR',_('Artifact: This ArtifactType Does Not Allow Anonymous Submissions. Please Login.'));
69 if (empty($user_email)) {
72 if (!validate_email($user_email)) {
73 form_release_key(getStringFromRequest('form_key'));
74 exit_error('ERROR', _('Invalid Email Address'));
78 $details = "Anonymous message posted by $user_email\n\n".
81 if (!$ah->create($summary,$details,$assigned_to,$priority,$extra_fields)) {
82 form_release_key(getStringFromRequest('form_key'));
83 exit_error('ERROR',$ah->getErrorMessage());
86 // Attach files to this Artifact.
89 for ($i=0; $i<5; $i++) {
90 $f = getUploadedFile("input_file$i");
92 if (isset($error) && $error > 0) {
94 if ($error === 1 || $error === 2) {
95 // UPLOAD_ERR_INI_SIZE or UPLOAD_ERR_FORM_SIZE
96 $ext_feedback .= "<br />ERROR: Skipping attachement $n: file is too large.";
97 } elseif ($error === 3) {
99 $ext_feedback .= "<br />ERROR: Skipping attachement $n: transfert interrupted.";
103 $file_name = $f['name'];
104 $tmp_name = $f['tmp_name'];
107 if (!is_uploaded_file($tmp_name)) {
111 $afh=new ArtifactFileHtml($ah);
112 if (!$afh || !is_object($afh)) {
113 $feedback .= 'Could Not Create File Object';
114 } elseif ($afh->isError()) {
115 $feedback .= $afh->getErrorMessage();
117 if (!util_check_fileupload($tmp_name)) {
118 form_release_key(getStringFromRequest('form_key'));
119 //delete the artifact
121 exit_error("Error","Invalid filename");
123 if (!$afh->upload($tmp_name,$file_name,$type,' ')) {
124 form_release_key(getStringFromRequest('form_key'));
125 //delete the artifact
127 exit_error(' Could Not Attach File to Item: '.$afh->getErrorMessage());
131 $feedback .= _('Item Successfully Created');
132 $feedback .= $ext_feedback;
133 include $gfwww.'tracker/browse.php';
138 case 'massupdate' : {
139 if (!form_key_is_valid(getStringFromRequest('form_key'))) {
140 exit_form_double_submit();
143 $artifact_id_list = getArrayFromRequest('artifact_id_list');
144 $priority = getStringFromRequest('priority');
145 $status_id = getStringFromRequest('status_id');
146 $category_id = getStringFromRequest('category_id');
147 $artifact_group_id = getStringFromRequest('artifact_group_id');
148 $resolution_id = getStringFromRequest('resolution_id');
149 $assigned_to = getStringFromRequest('assigned_to');
150 $canned_response = getIntFromRequest("canned_response");
151 $extra_fields = getArrayFromRequest('extra_fields');
153 $count=count($artifact_id_list);
155 if (!$ath->userIsAdmin()) {
156 exit_permission_denied();
159 $artifact_type_id=$ath->getID();
161 for ($i=0; $i < $count; $i++) {
162 $ah=new Artifact($ath,$artifact_id_list[$i]);
163 if (!$ah || !is_object($ah)) {
164 $feedback .= ' ID: '.$artifact_id_list[$i].'::Artifact Could Not Be Created';
165 } else if ($ah->isError()) {
166 $feedback .= ' ID: '.$artifact_id_list[$i].'::'.$ah->getErrorMessage();
168 $_priority=(($priority != 100) ? $priority : $ah->getPriority());
169 $_status_id=(($status_id != 100) ? $status_id : $ah->getStatusID());
170 //yikes, we want the ability to mass-update to "un-assigned", which is the ID=100, which
171 //conflicts with the "no change" ID! Sorry for messy use of 100.1
172 $_assigned_to=(($assigned_to != '100.1') ? $assigned_to : $ah->getAssignedTo());
175 // get existing extra field data
176 // we will then override individual elements if needed
178 $ef = $ah->getExtraFieldData();
179 $keys = array_keys($ef);
180 foreach ($keys as $efid) {
181 if (is_array($ef[$efid])) {
182 $f = $extra_fields[$efid];
183 // in this case, if $extra_fields is not setted, it
184 // means no option was selected, so we have to delete
185 // the original values
186 if (!is_array($f) || count($f) == 0) {
187 $ef[$efid] = array();
188 } else if (in_array('100', $extra_fields[$efid])) { // "No change" option selected?
191 $ef[$efid] = $f; // replace old values with new values
194 // in some cases (ie: textfields) the value is not passed, but
195 // this doesn't mean we must delete the existing value
196 if (array_key_exists($efid, $extra_fields)) {
197 $f = $extra_fields[$efid];
204 $ef[$efid] = addslashes($ef[$efid]);
209 if (!$ah->update($_priority,$_status_id,$_assigned_to,$_summary,$canned_response,'',$artifact_type_id,$ef)) {
214 $feedback .= ' ID: '.$artifact_id_list[$i].'::'.$ah->getErrorMessage();
222 $feedback = _('Updated Successfully'); }
224 unset ($extra_fields_choice);
225 include $gfwww.'tracker/browse.php';
229 $artifact_id = getIntFromRequest('artifact_id');
230 $priority = getIntFromRequest('priority');
231 $status_id = getIntFromRequest('status_id');
232 $category_id = getIntFromRequest('category_id');
233 $artifact_group_id = getIntFromRequest('artifact_group_id');
234 $resolution_id = getIntFromRequest('resolution_id');
235 $assigned_to = getStringFromRequest('assigned_to');
236 $summary = getStringFromRequest('summary');
237 $canned_response = getStringFromRequest('canned_response');
238 $details = getStringFromRequest('details');
239 $description = getStringFromRequest('description');
240 $new_artifact_type_id = getIntFromRequest('new_artifact_type_id');
241 $extra_fields = getStringFromRequest('extra_fields');
242 $user_email = getStringFromRequest('user_email', false);
246 Technicians can modify limited fields - to be certain
247 no one is hacking around, we override any fields they don't have
248 permission to change.
250 if (!form_key_is_valid(getStringFromRequest('form_key'))) {
251 exit_form_double_submit();
254 $ah=new ArtifactHtml($ath,$artifact_id);
255 if (!$ah || !is_object($ah)) {
256 exit_error('ERROR', _('Artifact Could Not Be Created'));
257 } else if ($ah->isError()) {
258 exit_error('ERROR',$ah->getErrorMessage());
259 } else if (!$ath->allowsAnon() && !session_loggedin()) {
260 exit_error('ERROR',_('Artifact: This ArtifactType Does Not Allow Anonymous Submissions. Please Login.'));
265 The following logic causes fields to be overridden
266 in the event that someone tampered with the HTML form
269 if ($ath->userIsAdmin() || $ath->userIsTechnician()) {
271 //admin and techs can do everything
272 //techs will have certain fields overridden inside the update() function call
273 if (!$ah->update($priority,$status_id,
274 $assigned_to,$summary,$canned_response,$details,$new_artifact_type_id,$extra_fields, $description)) {
275 form_release_key(getStringFromRequest('form_key'));
276 $error_msg .= _('Tracker Item'). ': '.$ah->getErrorMessage();
283 // Everyone else can add comments
285 if ($ah->addMessage($details,$user_email,true)) {
286 $feedback=_('Comment added');
288 if ( (strlen($details)>0) ) { //if there was no message, then it's not an error but addMessage returns false and sets missing params error
289 //some kind of error in creation
290 exit_error($ah->getErrorMessage(),$feedback);
292 // we have to unset the error if the user added a file ( add a file and no comment)
293 if ( (getStringFromRequest('add_file')) ) {
301 //everyone else can only add comments
304 if ($ah->addMessage($details,$user_email,true)) {
305 $feedback=_('Comment added');
307 //some kind of error in creation
308 exit_error('ERROR',$ah->getErrorMessage());
313 // Admin, Techs and Submitter can add files.
314 if ($ath->userIsAdmin() || $ath->userIsTechnician() ||
315 (session_loggedin() && ($ah->getSubmittedBy() == user_getid()))) {
317 // Attach files to this Artifact.
320 for ($i=0; $i<5; $i++) {
321 $f = getUploadedFile("input_file$i");
322 $error = $f['error'];
323 if (isset($error) && $error > 0) {
325 if ($error === 1 || $error === 2) {
326 // UPLOAD_ERR_INI_SIZE or UPLOAD_ERR_FORM_SIZE
327 $ext_feedback .= "<br />" .
328 sprintf(_("ERROR: Skipping attachment %d: file is too large."), $n);
329 } elseif ($error === 3) {
330 // UPLOAD_ERR_PARTIAL
331 $ext_feedback .= "<br />" .
332 sprintf(_("ERROR: Skipping attachment %d: transfer interrupted."), $n);
336 $file_name = $f['name'];
337 $tmp_name = $f['tmp_name'];
341 if (!is_uploaded_file($tmp_name)) {
345 $afh=new ArtifactFileHtml($ah);
346 if (!$afh || !is_object($afh)) {
347 $feedback .= 'Could Not Create File Object';
348 } elseif ($afh->isError()) {
349 $feedback .= $afh->getErrorMessage();
351 if (!util_check_fileupload($tmp_name)) {
352 form_release_key(getStringFromRequest('form_key'));
353 exit_error("Error","Invalid filename");
355 if (!$afh->upload($tmp_name,$file_name,$type,' ')) {
356 $feedback .= ' <br />'._('File Upload: Error').':'.$afh->getErrorMessage();
359 $feedback .= ' <br />'._('File Upload: Successful');
364 // Admin and Techs can delete files.
365 if ($ath->userIsAdmin() || $ath->userIsTechnician()) {
367 // Delete list of files from this artifact
369 $delete_file = getStringFromRequest('delete_file');
371 $count=count($delete_file);
372 for ($i=0; $i<$count; $i++) {
373 $afh=new ArtifactFileHtml($ah,$delete_file[$i]);
374 if (!$afh || !is_object($afh)) {
375 $feedback .= 'Could Not Create File Object::'.$delete_file[$i];
376 } elseif ($afh->isError()) {
377 $feedback .= $afh->getErrorMessage().'::'.$delete_file[$i];
379 if (!$afh->delete()) {
380 $feedback .= ' <br />'._('File Delete:').': '.$afh->getErrorMessage();
383 $feedback .= ' <br />'._('File Delete: Successful');
391 // Show just one feedback entry if no errors
394 $feedback = _('Updated successfully');
396 $feedback .= $ext_feedback;
397 include $gfwww.'tracker/browse.php';
403 if (!session_loggedin()) {
404 exit_permission_denied();
406 $start = getIntFromRequest('start');
407 $stop = getIntFromRequest('stop');
408 $artifact_id = getIntFromRequest('artifact_id');
410 // Fix to prevent collision with the start variable used in browse.
414 $ah=new ArtifactHtml($ath,$artifact_id);
415 if (!$ah || !is_object($ah)) {
416 exit_error('ERROR','Artifact Could Not Be Created');
417 } else if ($ah->isError()) {
418 exit_error('ERROR',$ah->getErrorMessage());
420 if ($start && $ah->isMonitoring())
421 $feedback = _('Monitoring Started');
422 elseif ($stop && !$ah->isMonitoring())
423 $feedback = _('Monitoring Deactivated');
426 $feedback=$ah->getErrorMessage();
428 include $gfwww.'tracker/browse.php';
431 $at=new ArtifactType($group,$atid);
432 if (!$at || !is_object($at)) {
433 exit_error('ERROR','Artifact Could Not Be Created');
434 } else if ($at->isError()) {
435 exit_error('ERROR',$at->getErrorMessage());
437 if ($start && $at->isMonitoring())
438 $feedback = _('Monitoring Started');
439 elseif ($stop && !$at->isMonitoring())
440 $feedback = _('Monitoring Deactivated');
443 $feedback=$at->getErrorMessage();
446 include $gfwww.'tracker/browse.php';
456 case 'deleteartifact' : {
457 if ($ath->userIsAdmin()) {
458 $aid = getStringFromRequest('aid');
459 $ah= new ArtifactHtml($ath,$aid);
460 if (!$ah || !is_object($ah)) {
461 exit_error('ERROR','Artifact Could Not Be Created');
462 } elseif ($ah->isError()) {
463 exit_error('ERROR',$ah->getErrorMessage());
465 include $gfwww.'tracker/deleteartifact.php';
467 exit_permission_denied();
473 // Handle the actual delete
476 case 'postdeleteartifact' : {
477 if (!form_key_is_valid(getStringFromRequest('form_key'))) {
478 exit_form_double_submit();
480 if ($ath->userIsAdmin()) {
481 $aid = getStringFromRequest('aid');
482 $ah= new ArtifactHtml($ath,$aid);
483 if (!$ah || !is_object($ah)) {
484 exit_error('ERROR','Artifact Could Not Be Created');
485 } elseif ($ah->isError()) {
486 exit_error('ERROR',$ah->getErrorMessage());
488 if (!getStringFromRequest('confirm_delete')) {
489 $feedback .= _('Confirmation failed. Artifact not deleted');
492 if (!$ah->delete(true)) {
493 $feedback .= _('Artifact Delete Failed') . ': '.$ah->getErrorMessage();
495 $feedback .= _('Artifact Deleted Successfully');
498 include $gfwww.'tracker/browse.php';
500 exit_permission_denied();
507 include $gfwww.'tracker/taskmgr.php';
511 include $gfwww.'tracker/browse.php';
515 include $gfwww.'tracker/query.php';
518 case 'downloadcsv' : {
519 include $gfwww.'tracker/downloadcsv.php';
523 $aid = getIntFromRequest('aid');
524 Header("Redirect: ".util_make_url ("/tracker/download.php?group_id=$group_id&atid=$atid&aid=$aid&file_id=$file_id"));
528 $aid = getIntFromRequest('aid');
531 // users can modify their own tickets in a limited way if they submitted them
532 // even if they are not artifact admins
534 $ah=new ArtifactHtml($ath,$aid);
535 if (!$ah || !is_object($ah)) {
536 exit_error('ERROR','Artifact Could Not Be Created');
537 } else if ($ah->isError()) {
538 exit_error('ERROR',$ah->getErrorMessage());
540 if ($ath->userIsAdmin()) {
541 include $gfwww.'tracker/mod.php';
542 } elseif ($ath->userIsTechnician()) {
543 include $gfwww.'tracker/mod-limited.php';
545 include $gfwww.'tracker/detail.php';
551 include $gfwww.'tracker/browse.php';
558 // c-file-style: "bsd"