2 /*=====================================================================*\
3 || ################################################################### ||
4 || # BugStrike [#]version[#]
5 || # --------------------------------------------------------------- # ||
6 || # Copyright ©2002-[#]year[#] by Iris Studios, Inc. All Rights Reserved. # ||
7 || # This file may not be reproduced in any way without permission. # ||
8 || # --------------------------------------------------------------- # ||
9 || # User License Agreement at http://www.iris-studios.com/license/ # ||
10 || ################################################################### ||
11 \*=====================================================================*/
13 $fetchtemplates = array(
18 define('SVN', '$Id$');
20 $focus['showreport'] = 'focus';
22 require_once('./global.php');
24 if (isset($bugsys->in
['attachmentid']))
26 $attachment = $db->query_first("SELECT * FROM " . TABLE_PREFIX
. "attachment WHERE attachmentid = " . intval($bugsys->in
['attachmentid']));
29 $message->error($lang->getlex('error_invalid_id'));
33 $bug = $db->query_first("SELECT * FROM " . TABLE_PREFIX
. "bug WHERE bugid = " . (($attachment['attachmentid']) ?
$attachment['bugid'] : intval($bugsys->in
['bugid'])));
36 $message->error($lang->getlex('error_invalid_id'));
40 require_once('./includes/class_history.php');
42 $log->bugid
= $bug['bugid'];
44 // ###################################################################
46 if ($_REQUEST['do'] == 'kill')
48 if (!can_perform('caneditattach'))
50 $message->error_permission();
53 $db->query("DELETE FROM " . TABLE_PREFIX
. "attachment WHERE attachmentid = $attachment[attachmentid]");
55 $log->arguments
= array($attachment['attachmentid']);
56 $log->allowempty
= true
;
59 $message->redirect($lang->string('The attachment has been removed.'), "showreport.php?bugid=$bug[bugid]");
62 // ###################################################################
64 if ($_REQUEST['do'] == 'delete')
66 if (!can_perform('caneditattach'))
68 $message->error_permission();
71 $message->message(sprintf($lang->string('Are you sure want to delete this attachment (id: %1$s)? <a href="attachment.php?do=kill&attachmentid=%1$s">Yes</a>'), $attachment['attachmentid']));
74 // ###################################################################
76 if ($_POST['do'] == 'insert')
78 if (!can_perform('canputattach'))
80 $message->error_permission();
84 $FILE =& $_FILES['attachment'];
87 switch ($FILE['error'])
90 case 1: $message->error($lang->string('PHP said the file you uploaded was too big.')); break;
91 case 2: $message->error($lang->string('The file exceeds the allowed upload size.')); break;
92 case 3: $message->error($lang->string('The file was only partially uploaded.')); break;
93 case 4: $message->error($lang->string('The file was not uploaded at all.')); break;
94 case 6: $message->error($lang->string('PHP could not find the /tmp directory.')); break;
98 if (!is_uploaded_file($FILE['tmp_name']))
100 $message->error($lang->string('The file you specified did not upload.'));
103 // #*# put some MIME-type validation here
105 if (!$bugsys->in
['description'])
107 $message->error($lang->string('You need to specify a file description.'));
110 $filedata = $bugsys->escape(file_get_contents($FILE['tmp_name']), true
, true
);
113 // insert an attachment
115 INSERT INTO attachment
116 (bugid, filename, mimetype, filesize,
117 attachment, description, dateline, userid)
119 ($bug[bugid], '" . $bugsys->escape($FILE['name']) . "',
120 '" . $bugsys->escape($FILE['type']) . "', " . intval($FILE['size']) . ",
121 '$filedata', '" . $bugsys->in
['description'] . "', $time,
122 " . $bugsys->userinfo
['userid'] . "
127 $obsoletes = $_POST['obsoletes'];
128 if (count($obsoletes) > 0)
130 array_walk($obsoletes, 'intval');
131 $db->query("UPDATE " . TABLE_PREFIX
. "attachment SET obsolete = 1 WHERE attachmentid IN (" . implode(',', $obsoletes) . ") AND !obsolete AND bugid = $bug[bugid]");
133 $log->arguments
= array($attachmentid, $FILE['name'], implode(', ', $obsoletes));
134 $log->log($log->diff($lang->string('Obsoleted attachments'), '', implode(', ', $obsoletes)));
137 // handle comment stuff
138 if (can_perform('canpostcomments') AND trim($bugsys->in
['comment']))
140 $bugsys->in
['comment_parsed'] = $bugsys->in
['comment'];
142 if (!$bugsys->options
['allowhtml'])
144 $bugsys->in
['comment_parsed'] = $bugsys->sanitize($bugsys->in
['comment_parsed']);
148 INSERT INTO " . TABLE_PREFIX
. "comment
149 (bugid, userid, dateline, comment, comment_parsed)
151 ($bug[bugid], " . $bugsys->userinfo
['userid'] . ",
152 $time, '" . $bugsys->in
['comment'] . "',
153 '" . nl2br($bugsys->in
['comment_parsed']) . "'
158 // update the last post data
159 $db->query("UPDATE " . TABLE_PREFIX
. "bug SET lastposttime = $time, lastpostby = " . $bugsys->userinfo
['userid'] . " WHERE bugid = $bug[bugid]");
161 $message->redirect($lang->string('The attachment has been added to the bug.'), "showreport.php?bugid=$bug[bugid]");
164 // ###################################################################
166 if ($_REQUEST['do'] == 'add')
168 if (!can_perform('canputattach'))
170 $message->error_permission();
173 $MAXFILESIZE = $funct->fetch_max_attachment_size();
175 $show['addcomment'] = ((can_perform('canpostcomments')) ? true
: false
);
176 $show['obsoletes'] = false
;
178 $obsoletes_fetch = $db->query("SELECT * FROM " . TABLE_PREFIX
. "attachment WHERE bugid = $bug[bugid] AND !obsolete");
180 while ($obsolete = $db->fetch_array($obsoletes_fetch))
182 $show['obsoletes'] = true
;
183 $obsoletes .= "<div><input name=\"obsoletes[]\" type=\"checkbox\" value=\"$obsolete[attachmentid]\" /> $obsolete[filename] [$obsolete[description]]</div>\n";
186 eval('$template->flush("' . $template->fetch('newattach') . '");');
189 // ###################################################################
191 if ($_POST['do'] == 'update')
193 if (!(can_perform('caneditattach') OR ($attachment['userid'] == $bugsys->userinfo
['userid'] AND can_perform('canputattach'))))
195 $message->error_permission();
199 UPDATE " . TABLE_PREFIX
. "attachment
200 SET description = '" . $bugsys->in
['description'] . "',
201 obsolete = " . intval($bugsys->in
['obsolete']) . "
202 WHERE attachmentid = " . intval($bugsys->in
['attachmentid'])
205 $hist[1] = $db->query_first("SELECT * FROM " . TABLE_PREFIX
. "attachment WHERE attachmentid = $attachment[attachmentid]");
207 $diff[0] = array_diff_assoc($attachment, $hist[1]);
208 $diff[1] = array_diff_assoc($hist[1], $attachment);
210 $log->arguments
= array($attachment['attachmentid']);
211 $log->log($log->diff('description', $diff[0]['description'], $diff[1]['description']));
212 $log->log($log->diff('obsolete', $diff[0]['obsolete'], $diff[1]['obsolete']));
214 $message->redirect($lang->string('The attachment was successfully modified.'), "showreport.php?bugid=$bug[bugid]");
217 // ###################################################################
219 if ($_REQUEST['do'] == 'edit')
221 if (!(can_perform('caneditattach') OR ($attachment['userid'] == $bugsys->userinfo
['userid'] AND can_perform('canputattach'))))
223 $message->error_permission();
226 $show['delete'] = ((can_perform('caneditattach')) ? true
: false
);
228 eval('$template->flush("' . $template->fetch('editattach') . '");');
231 /*=====================================================================*\
232 || ###################################################################
235 || ###################################################################
236 \*=====================================================================*/