From 87a71f7804290f4de7718a7a13b28ae55cf25471 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sun, 15 Jan 2006 08:18:00 +0000 Subject: [PATCH] r720: Error box implementation --- attachment.php | 111 ++++++++++++++++++++++------------------ templates/newattach.tpl | 11 +++- 2 files changed, 69 insertions(+), 53 deletions(-) diff --git a/attachment.php b/attachment.php index e99c7f4..296cabe 100755 --- a/attachment.php +++ b/attachment.php @@ -26,14 +26,14 @@ if (isset($bugsys->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')); + $message->items[] = $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')); + $message->items[] = $lang->getlex('error_invalid_id'); } // setup logging @@ -57,17 +57,17 @@ if ($_POST['do'] == 'insert') switch ($FILE['error']) { case 0: break; - case 1: $message->error($lang->string('PHP said the file you uploaded was too big.')); break; - case 2: $message->error($lang->string('The file exceeds the allowed upload size.')); break; - case 3: $message->error($lang->string('The file was only partially uploaded.')); break; - case 4: $message->error($lang->string('The file was not uploaded at all.')); break; - case 6: $message->error($lang->string('PHP could not find the /tmp directory.')); 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->error($lang->string('The file you specified did not upload.')); + $message->items[] = $lang->string('The file you specified did not upload.'); } // #*# put some MIME-type validation here @@ -76,57 +76,66 @@ if ($_POST['do'] == 'insert') $time = TIMENOW; // insert an attachment - $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'] . " - )" - ); - - // mark obsoletes - $obsoletes = $_POST['obsoletes']; - if (count($obsoletes) > 0) + if (!$message->items) { - array_walk($obsoletes, 'intval'); - $db->query("UPDATE " . TABLE_PREFIX . "attachment SET obsolete = 1 WHERE attachmentid IN (" . implode(',', $obsoletes) . ") AND !obsolete AND bugid = $bug[bugid]"); + $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'] . " + )" + ); - foreach ($obsoletes AS $attachmentid) + // mark obsoletes + $obsoletes = $_POST['obsoletes']; + if (count($obsoletes) > 0) { - $log->attachmentid = $attachmentid; - $log->log($log->diff('obsolete', 0, 1)); + 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)); + } } - } - - // 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']) + // handle comment stuff + if (can_perform('canpostcomments', $bug['productid']) AND trim($bugsys->in['comment'])) { - $bugsys->in['comment_parsed'] = $bugsys->sanitize($bugsys->in['comment_parsed']); + $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']) . "' + )" + ); } - $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']) . "' - )" - ); + // update the last post data + $db->query("UPDATE " . TABLE_PREFIX . "bug SET lastposttime = $time, lastpostby = " . $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(); } - - // update the last post data - $db->query("UPDATE " . TABLE_PREFIX . "bug SET lastposttime = $time, lastpostby = " . $bugsys->userinfo['userid'] . " WHERE bugid = $bug[bugid]"); - - $message->redirect($lang->string('The attachment has been added to the bug.'), "showreport.php?bugid=$bug[bugid]"); } // ################################################################### @@ -148,7 +157,7 @@ if ($_REQUEST['do'] == 'add') while ($obsolete = $db->fetch_array($obsoletes_fetch)) { $show['obsoletes'] = true; - $obsoletes .= "
$obsolete[filename] [$obsolete[description]]
\n"; + $obsoletes .= "
in['obsoletes']) ? ' checked="checked"' : '') . " /> $obsolete[filename] [$obsolete[description]]
\n"; } eval('$template->flush("' . $template->fetch('newattach') . '");'); diff --git a/templates/newattach.tpl b/templates/newattach.tpl index c098c42..e57f075 100644 --- a/templates/newattach.tpl +++ b/templates/newattach.tpl @@ -10,6 +10,13 @@ $headinclude $header + +
+ {@"The following errors occurred"}: + {$message->process} +
+
+
@@ -21,7 +28,7 @@ $header
-
{@"Description"}:
+
{@"Description"}:
@@ -36,7 +43,7 @@ $header
{@"Add Comment"}:
- +
-- 2.22.5