From efca6c480eeb7db672f17d4e990965428cc584dd Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sat, 20 May 2006 17:50:00 +0000 Subject: [PATCH] r832: Attachments are now handled using the API --- attachment.php | 97 +++++++++++++++++++++++--------------------------- 1 file changed, 45 insertions(+), 52 deletions(-) diff --git a/attachment.php b/attachment.php index 7b00a7d..8e347f2 100755 --- a/attachment.php +++ b/attachment.php @@ -29,6 +29,8 @@ define('SVN', '$Id$'); $focus['showreport'] = 'focus'; require_once('./global.php'); +require_once('./includes/api_attachment.php'); +require_once('./includes/api_comment.php'); if (isset($bugsys->in['attachmentid'])) { @@ -45,15 +47,15 @@ if (!$bug) $message->error($lang->getlex('error_invalid_id')); } -// setup logging -require_once('./includes/class_history.php'); -$log = new History(); -$log->bugid = $bug['bugid']; +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(); @@ -89,62 +91,49 @@ if ($_POST['do'] == 'insert') { $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) { - $filedata = $bugsys->escape(file_get_contents($FILE['tmp_name']), true, true); - $time = TIMENOW; - - $db->query(" - INSERT INTO " . TABLE_PREFIX . "attachment - (bugid, filename, mimetype, filesize, - attachment, description, dateline, userid) - VALUES - ($bug[bugid], '" . $bugsys->escape($FILE['name']) . "', - '" . $bugsys->escape($FILE['type']) . "', " . intval($FILE['size']) . ", - '$filedata', '" . $bugsys->in['description'] . "', $time, - " . $bugsys->userinfo['userid'] . " - )" - ); + $attachapi->insert(); // mark obsoletes - $obsoletes = $_POST['obsoletes']; + $obsoletes = $bugsys->input_clean('obsoletes', TYPE_UINT); if (count($obsoletes) > 0) { - array_walk($obsoletes, 'intval'); $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->attachmentid = $attachmentid; - $log->log($log->diff('obsolete', 0, 1)); + $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'])) { - $bugsys->in['comment_parsed'] = $bugsys->in['comment']; - - if (!$bugsys->options['allowhtml']) - { - $bugsys->in['comment_parsed'] = $bugsys->sanitize($bugsys->in['comment_parsed']); - } - - $db->query(" - INSERT INTO " . TABLE_PREFIX . "comment - (bugid, userid, dateline, comment, comment_parsed) - VALUES - ($bug[bugid], " . $bugsys->userinfo['userid'] . ", - $time, '" . $bugsys->in['comment'] . "', - '" . nl2br($bugsys->in['comment_parsed']) . "' - )" - ); + $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 = $time, lastpostby = " . $bugsys->userinfo['userid'] . " WHERE bugid = $bug[bugid]"); + $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]"); } @@ -175,7 +164,7 @@ if ($_REQUEST['do'] == 'add') while ($obsolete = $db->fetch_array($obsoletes_fetch)) { $show['obsoletes'] = true; - $obsoletes .= "
in['obsoletes']) ? ' checked="checked"' : '') . " /> $obsolete[filename]" . ($obsolete['description'] ? " [$obsolete[description]]" : '') . "
\n"; + $obsoletes .= "
in['obsoletes']) ? ' checked="checked"' : '') . " /> $obsolete[filename]" . ($obsolete['description'] ? " [$obsolete[description]]" : '') . "
\n"; } eval('$template->flush("' . $template->fetch('newattach') . '");'); @@ -190,21 +179,25 @@ if ($_POST['do'] == 'update') $message->error_permission(); } - $db->query(" - UPDATE " . TABLE_PREFIX . "attachment - SET description = '" . $bugsys->in['description'] . "', - obsolete = " . intval($bugsys->in['obsolete']) . " - WHERE attachmentid = " . intval($bugsys->in['attachmentid']) - ); + $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'); - $hist[1] = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "attachment WHERE attachmentid = $attachment[attachmentid]"); + $attachapi->set('description', $bugsys->in['description']); + $attachapi->set('obsolete', $bugsys->in['obsolete']); + $attachapi->update(); - $diff[0] = array_diff_assoc($attachment, $hist[1]); - $diff[1] = array_diff_assoc($hist[1], $attachment); + $log->add_data(false, $attachapi->values, array('attachment'), true, 'attachment'); - $log->attachmentid = $attachment['attachmentid']; - $log->log($log->diff('description', $diff[0]['description'], $diff[1]['description'])); - $log->log($log->diff('obsolete', $diff[0]['obsolete'], $diff[1]['obsolete'])); + $log->update_history(); $message->redirect($lang->string('The attachment was successfully modified.'), "showreport.php?bugid=$bug[bugid]"); } -- 2.22.5