in['attachmentid'])) { $attachment = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "attachment WHERE attachmentid = " . intval($bugsys->in['attachmentid'])); if (!$attachment) { $message->error($lang->getlex('error_invalid_id')); } } $bug = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "bug WHERE bugid = " . (($attachment['attachmentid']) ? $attachment['bugid'] : intval($bugsys->in['bugid']))); if (!$bug) { $message->error($lang->getlex('error_invalid_id')); } require_once('./includes/class_logging.php'); // ################################################################### if ($_POST['do'] == 'insert') { $attachapi = new AttachmentAPI($bugsys); $attachapi->set('bugid', $bugsys->in['bugid']); if (!can_perform('canputattach', $bug['productid'])) { $message->error_permission(); } // max packet size $var = $db->query_first("SHOW VARIABLES LIKE 'max_allowed_packet'"); $bugsys->debug("max_allowed_packet = $var[Value]"); // create alias $FILE =& $_FILES['attachment']; // PHP errors switch ($FILE['error']) { case 0: break; case 1: $message->items[] = $lang->string('PHP said the file you uploaded was too big.'); break; case 2: $message->items[] = $lang->string('The file exceeds the allowed upload size.'); break; case 3: $message->items[] = $lang->string('The file was only partially uploaded.'); break; case 4: $message->items[] = $lang->string('The file was not uploaded at all.'); break; case 6: $message->items[] = $lang->string('PHP could not find the /tmp directory.'); break; } // did it upload? if (!is_uploaded_file($FILE['tmp_name'])) { $message->items[] = $lang->string('The file you specified did not upload.'); } // #*# put some MIME-type validation here if (filesize($FILE['tmp_name']) > $var['Value']) { $message->items[] = $lang->string('The file you specified exceeds MySQL\'s maximum allowed packet.'); } $attachapi->set('attachment', file_get_contents($FILE['tmp_name'])); $attachapi->set('filename', $FILE['name']); $attachapi->set('mimetype', $FILE['type']); $attachapi->set('filesize', $FILE['size']); $attachapi->set('description', $bugsys->in['description']); $attachapi->set('userid', $bugsys->userinfo['userid']); // insert an attachment if (!$message->items) { $attachapi->insert(); // mark obsoletes $obsoletes = $bugsys->input_clean('obsoletes', TYPE_UINT); if (count($obsoletes) > 0) { $db->query("UPDATE " . TABLE_PREFIX . "attachment SET obsolete = 1 WHERE attachmentid IN (" . implode(',', $obsoletes) . ") AND !obsolete AND bugid = $bug[bugid]"); foreach ($obsoletes AS $attachmentid) { $log = new Logging; $log->set_bugid($bug['bugid']); $log->set_attachmentid($attachmentid); $log->add_data(true, array('obsolete' => 0), array('obsolete'), false, 'attachment'); $log->add_data(false, array('obsolete' => 1), array('obsolete'), false, 'attachment'); $log->update_history(); } } // handle comment stuff if (can_perform('canpostcomments', $bug['productid']) AND trim($bugsys->in['comment'])) { $comment = new CommentAPI($bugsys); $comment->set('bugid', $bugsys->in['bugid']); $comment->set('userid', $bugsys->userinfo['userid']); $comment->set('comment', $bugsys->in['comment']); $comment->set('dateline', $attachapi->values['dateline']); $comment->insert(); } // update the last post data $db->query("UPDATE " . TABLE_PREFIX . "bug SET lastposttime = " . $attachapi->values['dateline'] . ", hiddenlastposttime = " . $attachapi->values['dateline'] . ", lastpostby = " . $bugsys->userinfo['userid'] . ", hiddenlastpostby = " . $bugsys->userinfo['userid'] . " WHERE bugid = $bug[bugid]"); $message->redirect($lang->string('The attachment has been added to the bug.'), "showreport.php?bugid=$bug[bugid]"); } else { $show['errors'] = true; $_REQUEST['do'] = 'add'; $message->error_list_process(); } } // ################################################################### if ($_REQUEST['do'] == 'add') { if (!can_perform('canputattach', $bug['productid'])) { $message->error_permission(); } $MAXFILESIZE = $funct->fetch_max_attachment_size(); $show['addcomment'] = ((can_perform('canpostcomments', $bug['productid'])) ? true : false); $show['obsoletes'] = false; $obsoletes_fetch = $db->query("SELECT * FROM " . TABLE_PREFIX . "attachment WHERE bugid = $bug[bugid] AND !obsolete"); $obsoletes = ''; while ($obsolete = $db->fetch_array($obsoletes_fetch)) { $show['obsoletes'] = true; $obsoletes .= "
in['obsoletes']) ? ' checked="checked"' : '') . " /> $obsolete[filename]" . ($obsolete['description'] ? " [$obsolete[description]]" : '') . "
\n"; } eval('$template->flush("' . $template->fetch('newattach') . '");'); } // ################################################################### if ($_POST['do'] == 'update') { if (!(can_perform('caneditattach', $bug['productid']) OR ($attachment['userid'] == $bugsys->userinfo['userid'] AND can_perform('canputattach', $bug['productid'])))) { $message->error_permission(); } $log = new Logging; $log->set_bugid($bug['bugid']); $log->set_attachmentid($bugsys->in['attachmentid']); $attachapi = new AttachmentAPI($bugsys); $attachapi->set('attachmentid', $bugsys->in['attachmentid']); $attachapi->set_condition(); $attachapi->dorelations = array(); $attachapi->fetch(); $log->add_data(true, $attachapi->objdata, array('attachment'), true, 'attachment'); $attachapi->set('description', $bugsys->in['description']); $attachapi->set('obsolete', $bugsys->in['obsolete']); $attachapi->update(); $log->add_data(false, $attachapi->values, array('attachment'), true, 'attachment'); $log->update_history(); $message->redirect($lang->string('The attachment was successfully modified.'), "showreport.php?bugid=$bug[bugid]"); } // ################################################################### if ($_REQUEST['do'] == 'edit') { if (!(can_perform('caneditattach', $bug['productid']) OR ($attachment['userid'] == $bugsys->userinfo['userid'] AND can_perform('canputattach', $bug['productid'])))) { $message->error_permission(); } $show['delete'] = ((can_perform('caneditattach', $bug['productid'])) ? true : false); eval('$template->flush("' . $template->fetch('editattach') . '");'); } /*=====================================================================*\ || ################################################################### || # $HeadURL$ || # $Id$ || ################################################################### \*=====================================================================*/ ?>