|
From: Benjamin C. <bc...@us...> - 2003-08-31 04:44:12
|
Update of /cvsroot/phpbt/phpbt
In directory sc8-pr-cvs1:/tmp/cvs-serv7227
Modified Files:
Tag: htmltemplates
attachment.php
Log Message:
Switching to html templates and gettext
Index: attachment.php
===================================================================
RCS file: /cvsroot/phpbt/phpbt/attachment.php,v
retrieving revision 1.21.4.1
retrieving revision 1.21.4.2
diff -u -r1.21.4.1 -r1.21.4.2
--- attachment.php 30 Aug 2003 22:07:11 -0000 1.21.4.1
+++ attachment.php 31 Aug 2003 04:44:09 -0000 1.21.4.2
@@ -2,7 +2,7 @@
// attachment.php - Adding, deleting, and displaying attachments
// ------------------------------------------------------------------------
-// Copyright (c) 2001, 2002 The phpBugTracker Group
+// Copyright (c) 2001 - 2003 The phpBugTracker Group
// ------------------------------------------------------------------------
// This file is part of phpBugTracker
//
@@ -25,82 +25,86 @@
include 'include.php';
function del_attachment($attachid) {
- global $db, $HTTP_SERVER_VARS;
+ global $db;
if (list($filename, $mimetype) = grab_attachment($attachid)) {
$db->query("delete from ".TBL_ATTACHMENT." where attachment_id = $attachid");
unlink($filename);
- header("Location: {$HTTP_SERVER_VARS['HTTP_REFERER']}");
+ header("Location: {$_SERVER['HTTP_REFERER']}");
}
}
function grab_attachment($attachid) {
- global $db, $STRING;
+ global $db;
if (!is_numeric($attachid)) {
- show_text($STRING['bad_attachment'], true);
+ show_text(translate("That attachment does not exist"), true);
return false;
}
- $ainfo = $db->getRow("select a.bug_id, file_name, mime_type, project_id"
- ." from ".TBL_ATTACHMENT." a, ".TBL_BUG." b"
- ." where attachment_id = $attachid and a.bug_id = b.bug_id");
+ $ainfo = $db->getRow("select a.bug_id, file_name, mime_type, project_id"." from ".TBL_ATTACHMENT." a, ".TBL_BUG." b"." where attachment_id = $attachid and a.bug_id = b.bug_id");
if (empty($ainfo)) {
- show_text($STRING['bad_attachment'], true);
+ show_text(translate("That attachment does not exist"), true);
return false;
}
$filename = join('/',array(ATTACHMENT_PATH,
$ainfo['project_id'], "{$ainfo['bug_id']}-{$ainfo['file_name']}"));
if (!is_readable($filename)) {
- show_text($STRING['bad_attachment'], true);
+ show_text(translate("That attachment does not exist"), true);
return false;
}
return array($filename, $ainfo['mime_type']);
}
function add_attachment($bugid, $description) {
- global $db, $HTTP_POST_FILES, $now, $u, $STRING, $t, $_pv;
+ global $db, $now, $u, $t;
- if (!isset($HTTP_POST_FILES['attachment']) ||
- $HTTP_POST_FILES['attachment']['tmp_name'] == 'none') {
- show_attachment_form($bugid, $STRING['give_attachment']);
+ if (!isset($_FILES['attachment'])) {
+ show_attachment_form($bugid, translate("Please specify a file to upload"));
+ return;
+ }
+
+ if ($_FILES['attachment']['tmp_name'] == 'none') {
+ if (empty($_FILES['attachment']['name'])) {
+ show_attachment_form($bugid, translate("Please specify a file to upload"));
+ } else {
+ show_attachment_form($bugid, sprintf(translate("The file you specified is larger than %s bytes"), number_format(ATTACHMENT_MAX_SIZE)));
+ }
return;
}
// Check the upload size. If the size was greater than the max in
// php.ini, the file won't even be set and will fail at the check above
- if ($HTTP_POST_FILES['attachment']['size'] > ATTACHMENT_MAX_SIZE) {
- show_attachment_form($bugid, $STRING['attachment_too_large']);
+ if ($_FILES['attachment']['size'] > ATTACHMENT_MAX_SIZE) {
+ show_attachment_form($bugid, printf(translate("The file you specified is larger than %d bytes"), number_format(ATTACHMENT_MAX_SIZE)));
return;
}
$projectid = $db->getOne("select project_id from ".TBL_BUG." where bug_id = $bugid");
if (!$projectid) {
- show_text($STRING['nobug'], true);
+ show_text(translate("That bug does not exist"), true);
return;
}
// Check for a previously-uploaded attachment with the same name, bug, and project
- $rs = $db->query("select a.bug_id, project_id from ".TBL_ATTACHMENT." a, ".
- TBL_BUG." b where file_name = '{$HTTP_POST_FILES['attachment']['name']}' ".
- "and a.bug_id = b.bug_id");
+ $rs = $db->query("select a.bug_id, project_id from ".TBL_ATTACHMENT." a, ".TBL_BUG." b where file_name = '{$_FILES['attachment']['name']}' and a.bug_id = b.bug_id");
while ($rs->fetchInto($ainfo)) {
if ($bugid == $ainfo['bug_id'] && $projectid == $ainfo['project_id']) {
- show_attachment_form($bugid, $STRING['dupe_attachment']);
+ show_attachment_form($bugid, translate("That attachment already exists for this bug"));
return;
}
}
$filepath = ATTACHMENT_PATH;
- $tmpfilename = $HTTP_POST_FILES['attachment']['tmp_name'];
- $filename = "$bugid-{$HTTP_POST_FILES['attachment']['name']}";
+ $tmpfilename = $_FILES['attachment']['tmp_name'];
+ $filename = "$bugid-{$_FILES['attachment']['name']}";
if (!is_dir($filepath)) {
- show_attachment_form($bugid, $STRING['no_attachment_save_path']);
+ show_attachment_form($bugid, translate("Couldn't find where to save the file!"));
return;
}
if (!is_writeable($filepath)) {
- show_attachment_form($bugid, $STRING['attachment_path_not_writeable']);
+ show_attachment_form($bugid, translate("Couldn't create a file in the save path"));
return;
}
@@ -108,39 +112,33 @@
@mkdir("$filepath/$projectid", 0775);
}
- if (!@move_uploaded_file($HTTP_POST_FILES['attachment']['tmp_name'],
+ if (!@move_uploaded_file($_FILES['attachment']['tmp_name'],
"$filepath/$projectid/$filename")) {
- show_attachment_form($bugid, $STRING['attachment_move_error']);
+ show_attachment_form($bugid, translate("There was an error moving the uploaded file"));
return;
}
@chmod("$filepath/$projectid/$filename", 0766);
- $db->query("insert into ".TBL_ATTACHMENT." (attachment_id, bug_id, file_name, ".
- "description, file_size, mime_type, created_by, created_date) values (".
- join(', ', array($db->nextId(TBL_ATTACHMENT), $bugid,
- $db->quote($HTTP_POST_FILES['attachment']['name']),
- $db->quote(stripslashes($description)),
- $HTTP_POST_FILES['attachment']['size'],
- $db->quote($HTTP_POST_FILES['attachment']['type']), $u, $now)).")");
+ $db->query("insert into ".TBL_ATTACHMENT." (attachment_id, bug_id, file_name, description, file_size, mime_type, created_by, created_date) values (".join(', ', array($db->nextId(TBL_ATTACHMENT), $bugid, $db->quote($_FILES['attachment']['name']), $db->quote(stripslashes($description)), $_FILES['attachment']['size'], $db->quote($_FILES['attachment']['type']), $u, $now)).")");
- if ($_pv['use_js']) {
- $t->display('admin/edit-submit.html');
+ if ($_POST['use_js']) {
+ $t->render('admin/edit-submit.html');
} else {
header("Location: bug.php?op=show&bugid=$bugid");
}
}
function show_attachment_form($bugid, $error = '') {
- global $db, $t, $STRING;
+ global $db, $t;
if (!is_numeric($bugid)) {
- show_text($STRING['nobug'], true);
+ show_text(translate("That bug does not exist"), true);
return;
}
$bugexists = $db->getOne("select count(*) from ".TBL_BUG." where bug_id = $bugid");
if (!$bugexists) {
- show_text($STRING['nobug'], true);
+ show_text(translate("That bug does not exist"), true);
return;
}
@@ -153,20 +151,21 @@
? number_format(ini_get('upload_max_filesize'))
: number_format(ATTACHMENT_MAX_SIZE)
));
- $t->render('bugattachmentform.html', translate('Add Attachment'), 'wrap-popup.html');
+ $t->render('bugattachmentform.html', translate("Add Attachment"),
+ !empty($_REQUEST['use_js']) ? 'wrap-popup.html' : 'wrap.html');
}
-if (isset($_gv['del'])) {
+if (isset($_GET['del'])) {
if (!$perm->have_perm('Administrator')) {
- show_text($STRING['bad_permission']);
+ show_text(translate("You do not have the permissions required for that function"));
} else {
- del_attachment($_gv['del']);
+ del_attachment($_GET['del']);
}
-} elseif (isset($_pv['submit'])) {
+} elseif (isset($_POST['submit'])) {
$perm->check('Editbug');
- add_attachment($_pv['bugid'], $_pv['description']);
-} elseif (isset($_gv['attachid'])) {
- if (list($filename, $mimetype) = grab_attachment($_gv['attachid'])) {
+ add_attachment($_POST['bugid'], $_POST['description']);
+} elseif (isset($_GET['attachid'])) {
+ if (list($filename, $mimetype) = grab_attachment($_GET['attachid'])) {
$base = basename($filename);
header("Content-Disposition: attachment; filename=\"$base\"");
header("Content-Type: $mimetype");
@@ -178,7 +177,7 @@
}
} else {
$perm->check('Editbug');
- show_attachment_form($_gv['bugid']);
+ show_attachment_form($_GET['bugid']);
}
?>
|