1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430
|
<?php
//
// get the Group object
//
$group =& group_get_object($group_id);
if (!$group || !is_object($group)) {
exit_no_group();
}
if ($group->isError()) {
if($group->isPermissionDeniedError()) {
exit_permission_denied($group->getErrorMessage());
} else {
exit_error($Language->getText('general','error'), $group->getErrorMessage());
}
}
//
// Create the ArtifactType object
//
$ath = new ArtifactTypeHtml($group,$atid);
if (!$ath || !is_object($ath)) {
exit_error('Error','ArtifactType could not be created');
}
if ($ath->isError()) {
if($ath->isPermissionDeniedError()) {
exit_permission_denied($group->getErrorMessage());
} else {
exit_error($Language->getText('general','error'), $ath->getErrorMessage());
}
}
switch ($func) {
case 'add' : {
if (!$ath->allowsAnon() && !session_loggedin()) {
exit_error('ERROR',$Language->getText('tracker_artifact','error_no_anonymous'));
} else {
include ('add.php');
}
break;
}
case 'postadd' : {
/*
Create a new Artifact
*/
$ah=new ArtifactHtml($ath);
if (!$ah || !is_object($ah)) {
exit_error('ERROR','Artifact Could Not Be Created');
} else if (!$ath->allowsAnon() && !session_loggedin()) {
exit_error('ERROR',$Language->getText('tracker_artifact','error_no_anonymous'));
} else {
if (empty($user_email)) {
$user_email=false;
} else {
if (!validate_email($user_email)) {
exit_error('ERROR', $Language->getText('general','invalid_email'));
}
}
if (!$ah->create($summary,$details,$assigned_to,$priority,$extra_fields)) {
exit_error('ERROR',$ah->getErrorMessage());
} else {
//
// Attach files to this Artifact.
//
for ($i=0; $i<5; $i++) {
$error=$_FILES['input_file']['error'][$i];
if (isset($error) && $error > 0) {
continue;
}
$file_name=$_FILES['input_file']['name'][$i];
$tmp_name=$_FILES['input_file']['tmp_name'][$i];
if (!is_uploaded_file($tmp_name)) {
continue;
}
$size=$_FILES['input_file']['size'][$i];
$type=$_FILES['input_file']['type'][$i];
$afh=new ArtifactFileHtml($ah);
if (!$afh || !is_object($afh)) {
$feedback .= 'Could Not Create File Object';
// } elseif ($afh->isError()) {
// $feedback .= $afh->getErrorMessage();
} else {
if (!util_check_fileupload($tmp_name)) {
exit_error("Error","Invalid filename");
}
if (!$afh->upload($tmp_name,$file_name,$type,' ')) {
$feedback .= ' Could Not Attach File to Item: '.$afh->getErrorMessage();
}
}
}
$feedback .= $Language->getText('tracker','item_created');
include 'browse.php';
}
}
break;
}
case 'massupdate' : {
$count=count($artifact_id_list);
if (!$ath->userIsAdmin()) {
exit_permission_denied();
}
$artifact_type_id=$ath->getID();
for ($i=0; $i < $count; $i++) {
$ah=new Artifact($ath,$artifact_id_list[$i]);
if (!$ah || !is_object($ah)) {
$feedback .= ' ID: '.$artifact_id_list[$i].'::Artifact Could Not Be Created';
} else if ($ah->isError()) {
$feedback .= ' ID: '.$artifact_id_list[$i].'::'.$ah->getErrorMessage();
} else {
$_priority=(($priority != 100) ? $priority : $ah->getPriority());
$_status_id=(($status_id != 100) ? $status_id : $ah->getStatusID());
//yikes, we want the ability to mass-update to "un-assigned", which is the ID=100, which
//conflicts with the "no change" ID! Sorry for messy use of 100.1
$_assigned_to=(($assigned_to != '100.1') ? $assigned_to : $ah->getAssignedTo());
//
// get existing extra field data
// we will then override individual elements if needed
//
$ef = $ah->getExtraFieldData();
$keys = array_keys($ef);
foreach ($keys as $efid) {
if (is_array($ef[$efid])) {
$f = $extra_fields[$efid];
// in this case, if $extra_fields is not setted, it
// means no option was selected, so we have to delete
// the original values
if (!is_array($f) || count($f) == 0) {
$ef[$efid] = array();
} else if (in_array('100', $extra_fields[$efid])) { // "No change" option selected?
// no change
} else {
$ef[$efid] = $f; // replace old values with new values
}
} else {
// in some cases (ie: textfields) the value is not passed, but
// this doesn't mean we must delete the existing value
if (array_key_exists($efid, $extra_fields)) {
$f = $extra_fields[$efid];
if ($f == '100') {
// no change
} else {
$ef[$efid] = $f;
}
}
}
}
if (!$ah->update($_priority,$_status_id,$_assigned_to,$_summary,$canned_response,'',$artifact_type_id,$ef)) {
$was_error=true;
}
if ($was_error) {
$feedback .= ' ID: '.$artifact_id_list[$i].'::'.$ah->getErrorMessage();
}else {
$was_error=false;
}
}
unset($ah);
if (!$was_error) {
$feedback = $Language->getText('tracker','updated_successful'); }
}
unset ($extra_fields_choice);
include ('browse.php');
break;
}
case 'postmod' : {
/*
Technicians can modify limited fields - to be certain
no one is hacking around, we override any fields they don't have
permission to change.
*/
$ah=new ArtifactHtml($ath,$artifact_id);
if (!$ah || !is_object($ah)) {
exit_error('ERROR','Artifact Could Not Be Created');
} else if ($ah->isError()) {
exit_error('ERROR',$ah->getErrorMessage());
} else if (!$ath->allowsAnon() && !session_loggedin()) {
exit_error('ERROR',$Language->getText('tracker_artifact','error_no_anonymous'));
} else {
/*
The following logic causes fields to be overridden
in the event that someone tampered with the HTML form
*/
if ($ath->userIsAdmin() || $ath->userIsTechnician()) {
//admin and techs can do everything
//techs will have certain fields overridden inside the update() function call
if (!$ah->update($priority,$status_id,
$assigned_to,$summary,$canned_response,$details,$new_artfact_type_id,$extra_fields)) {
$feedback =$Language->getText('tracker','tracker_item'). ': '.$ah->getErrorMessage();
$ah->clearError();
$was_error=true;
}
} else {
if (session_loggedin() && ($ah->getSubmittedBy() == user_getid())) {
//submitter can only add files & comments
$delete_file=false;
if ($ah->addMessage($details,$user_email,true)) {
$feedback=$Language->getText('tracker','comment_added');
} else {
if ( (strlen($details)>0) ) { //if there was no message, then its not an error but addMessage returns false and sets missing params error
//some kind of error in creation
exit_error($ah->getErrorMessage(),$feedback);
} else {
// we have to unset the error if the user added a file ( add a file and no comment)
if ( $add_file ) {
$ah->clearError();
}
}
}
} else {
//everyone else can only add comments
$delete_file=false;
$add_file=false;
if ($ah->addMessage($details,$user_email,true)) {
$feedback=$Language->getText('tracker','comment_added');
} else {
//some kind of error in creation
exit_error('ERROR',$ah->getErrorMessage());
}
}
}
//
// Attach files to this Artifact.
//
for ($i=0; $i<5; $i++) {
$error=$_FILES['input_file']['error'][$i];
if (isset($error) && $error > 0) {
continue;
}
$file_name=$_FILES['input_file']['name'][$i];
$tmp_name=$_FILES['input_file']['tmp_name'][$i];
if (!is_uploaded_file($tmp_name)) {
continue;
}
$size=$_FILES['input_file']['size'][$i];
$type=$_FILES['input_file']['type'][$i];
$afh=new ArtifactFileHtml($ah);
if (!$afh || !is_object($afh)) {
$feedback .= 'Could Not Create File Object';
// } elseif ($afh->isError()) {
// $feedback .= $afh->getErrorMessage();
} else {
if (!util_check_fileupload($tmp_name)) {
exit_error("Error","Invalid filename");
}
if (!$afh->upload($tmp_name,$file_name,$type,' ')) {
$feedback .= ' Could Not Attach File to Item: '.$afh->getErrorMessage();
}
}
}
//
// Delete list of files from this artifact
//
if ($delete_file) {
$count=count($delete_file);
for ($i=0; $i<$count; $i++) {
$afh=new ArtifactFileHtml($ah,$delete_file[$i]);
if (!$afh || !is_object($afh)) {
$feedback .= 'Could Not Create File Object::'.$delete_file[$i];
} elseif ($afh->isError()) {
$feedback .= $afh->getErrorMessage().'::'.$delete_file[$i];
} else {
if (!$afh->delete()) {
$feedback .= ' <br />'.$Language->getText('tracker','file_delete').': '.$afh->getErrorMessage();
$was_error=true;
} else {
$feedback .= ' <br />'.$Language->getText('tracker','file_delete_successful');
}
}
}
}
//
// Show just one feedback entry if no errors
//
if (!$was_error) {
$feedback = $Language->getText('general','update_successful');
}
include ('browse.php');
}
break;
}
case 'monitor' : {
if ($artifact_id) {
$ah=new ArtifactHtml($ath,$artifact_id);
if (!$ah || !is_object($ah)) {
exit_error('ERROR','Artifact Could Not Be Created');
} else if ($ah->isError()) {
exit_error('ERROR',$ah->getErrorMessage());
} else {
$ah->setMonitor();
$feedback=$ah->getErrorMessage();
include 'browse.php';
}
} else {
$at=new ArtifactType($group,$atid);
if (!$at || !is_object($at)) {
exit_error('ERROR','Artifact Could Not Be Created');
} else if ($at->isError()) {
exit_error('ERROR',$at->getErrorMessage());
} else {
$at->setMonitor();
$feedback=$at->getErrorMessage();
$at->clearError();
include 'browse.php';
}
}
break;
}
//
// Show delete form
//
case 'deleteartifact' : {
if ($ath->userIsAdmin()) {
$ah= new ArtifactHtml($ath,$aid);
if (!$ah || !is_object($ah)) {
exit_error('ERROR','Artifact Could Not Be Created');
} elseif ($ah->isError()) {
exit_error('ERROR',$ah->getErrorMessage());
}
include 'deleteartifact.php';
} else {
exit_permission_denied();
}
break;
}
//
// Handle the actual delete
//
case 'postdeleteartifact' : {
if ($ath->userIsAdmin()) {
$ah= new ArtifactHtml($ath,$aid);
if (!$ah || !is_object($ah)) {
exit_error('ERROR','Artifact Could Not Be Created');
} elseif ($ah->isError()) {
exit_error('ERROR',$ah->getErrorMessage());
}
if (!$confirm_delete) {
$feedback .= $Language->getText('tracker_artifact','delete_failed_confirm');
}
else {
if (!$ah->delete(true)) {
$feedback .= $Language->getText('tracker_artifact','delete_failed') . ': '.$ah->getErrorMessage();
} else {
$feedback .= $Language->getText('tracker_artifact','deleted_successfully');
}
}
include 'browse.php';
} else {
exit_permission_denied();
}
break;
}
case 'taskmgr' : {
include 'taskmgr.php';
break;
}
case 'browse' : {
include 'browse.php';
break;
}
case 'query' : {
include ('query.php');
break;
}
case 'downloadcsv' : {
include ('downloadcsv.php');
break;
}
case 'download' : {
Header("Redirect: /tracker/download.php?group_id=$group_id&atid=$atid&aid=$aid&file_id=$file_id");
break;
}
case 'detail' : {
//
// users can modify their own tickets in a limited way if they submitted them
// even if they are not artifact admins
//
$ah=new ArtifactHtml($ath,$aid);
if (!$ah || !is_object($ah)) {
exit_error('ERROR','Artifact Could Not Be Created');
} else if ($ah->isError()) {
exit_error('ERROR',$ah->getErrorMessage());
} else {
if ($ath->userIsAdmin()) {
include 'mod.php';
} elseif ($ath->userIsTechnician()) {
include 'mod-limited.php';
} else {
include 'detail.php';
}
}
break;
}
default : {
include 'browse.php';
break;
}
}
?>
|