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 require_once('./global.php');
20 if (isset($bugsys->in
['attachmentid']))
22 $attachment = $db->query_first("SELECT * FROM " . TABLE_PREFIX
. "attachment WHERE attachmentid = " . intval($bugsys->in
['attachmentid']));
25 $message->error('alert: bad attachment');
29 $bug = $db->query_first("SELECT * FROM " . TABLE_PREFIX
. "bug WHERE bugid = " . (($attachment['attachmentid']) ?
$attachment['bugid'] : intval($bugsys->in
['bugid'])));
32 $message->error('alert: bad bug');
36 require_once('./includes/class_history.php');
38 $log->bugid
= $bug['bugid'];
40 // ###################################################################
42 if ($_REQUEST['do'] == 'kill')
44 if (!can_perform('caneditattach'))
46 $message->error_permission();
49 $db->query("DELETE FROM " . TABLE_PREFIX
. "attachment WHERE attachmentid = $attachment[attachmentid]");
51 $log->language
= 'log_kill_attachment';
52 $log->arguments
= array($attachment['attachmentid']);
53 $log->allowempty
= true
;
56 echo "<a href=\"showreport.php?bugid=$bug[bugid]\">attachment removed</a>";
59 // ###################################################################
61 if ($_REQUEST['do'] == 'delete')
63 if (!can_perform('caneditattach'))
65 $message->error_permission();
68 echo "are you sure you want to delete this attachment? <a href=\"attachment.php?do=kill&attachmentid=$attachment[attachmentid]\">yes</a>";
71 // ###################################################################
73 if ($_POST['do'] == 'insert')
75 if (!can_perform('canputattach'))
77 $message->error_permission();
81 $FILE =& $_FILES['attachment'];
84 switch ($FILE['error'])
87 case 1: $message->error('PHP said the file you uploaded was too big.'); break;
88 case 2: $message->error('The file exceeds the allowed upload size.'); break;
89 case 3: $message->error('The file was only partially uploaded.'); break;
90 case 4: $message->error('The file was not uploaded at all.'); break;
91 case 6: $message->error('PHP could not find the /tmp directory.'); break;
95 if (!is_uploaded_file($FILE['tmp_name']))
97 $message->error('The file you specified did not upload.');
100 // #*# put some MIME-type validation here
102 if (!$bugsys->in
['description'])
104 $message->error('you need a file description!');
107 $filedata = $bugsys->escape(file_get_contents($FILE['tmp_name']), true
, true
);
110 // insert an attachment
112 INSERT INTO attachment
113 (bugid, filename, mimetype, filesize,
114 attachment, description, dateline, userid)
116 ($bug[bugid], '" . $bugsys->escape($FILE['name']) . "',
117 '" . $bugsys->escape($FILE['type']) . "', " . intval($FILE['size']) . ",
118 '$filedata', '" . $bugsys->in
['description'] . "', $time,
119 " . $bugsys->userinfo
['userid'] . "
123 $attachmentid = $db->insert_id();
124 $log->language
= 'log_new_attachment';
125 $log->arguments
= array($FILE['name'], $attachmentid);
126 $log->allowempty
= true
;
130 $obsoletes = $_POST['obsoletes'];
131 if (count($obsoletes) > 0)
133 array_walk($obsoletes, 'intval');
134 $db->query("UPDATE " . TABLE_PREFIX
. "attachment SET obsolete = 1 WHERE attachmentid IN (" . implode(',', $obsoletes) . ") AND !obsolete AND bugid = $bug[bugid]");
136 $log->language
= 'log_mark_obsoletes';
137 $log->arguments
= array($attachmentid, $FILE['name'], implode(', ', $obsoletes));
138 $log->log($log->diff('obsoleted attachments', '', implode(', ', $obsoletes)));
141 // handle comment stuff
142 if (can_perform('canpostcomments') AND trim($bugsys->in
['comment']))
144 $bugsys->in
['comment_parsed'] = $bugsys->in
['comment'];
146 if (!$bugsys->options
['allowhtml'])
148 $bugsys->in
['comment_parsed'] = $bugsys->sanitize($bugsys->in
['comment_parsed']);
152 INSERT INTO " . TABLE_PREFIX
. "comment
153 (bugid, userid, dateline, comment, comment_parsed)
155 ($bug[bugid], " . $bugsys->userinfo
['userid'] . ",
156 $time, '" . $bugsys->in
['comment'] . "',
157 '" . nl2br($bugsys->in
['comment_parsed']) . "'
161 $commentid = $db->insert_id();
163 $log->language
= 'log_new_attachment_comment';
164 $log->arguments
= array($attachmentid, $commentid);
165 $log->allowempty
= true
;
169 // update the last post data
170 $db->query("UPDATE " . TABLE_PREFIX
. "bug SET lastposttime = $time, lastpostby = " . $bugsys->userinfo
['userid'] . " WHERE bugid = $bug[bugid]");
172 echo "<a href=\"showreport.php?bugid=$bug[bugid]\">attachment added</a>";
175 // ###################################################################
177 if ($_REQUEST['do'] == 'add')
179 if (!can_perform('canputattach'))
181 $message->error_permission();
184 $MAXFILESIZE = $funct->fetch_max_attachment_size();
186 $show['addcomment'] = ((can_perform('canpostcomments')) ? true
: false
);
187 $show['obsoletes'] = false
;
189 $obsoletes_fetch = $db->query("SELECT * FROM " . TABLE_PREFIX
. "attachment WHERE bugid = $bug[bugid] AND !obsolete");
191 while ($obsolete = $db->fetch_array($obsoletes_fetch))
193 $show['obsoletes'] = true
;
194 $obsoletes .= "<div><input name=\"obsoletes[]\" type=\"checkbox\" value=\"$obsolete[attachmentid]\" /> $obsolete[filename] [$obsolete[description]]</div>\n";
197 eval('$template->flush("' . $template->fetch('newattach') . '");');
200 // ###################################################################
202 if ($_POST['do'] == 'update')
204 if (!(can_perform('caneditattach') OR ($attachment['userid'] == $bugsys->userinfo
['userid'] AND can_perform('canputattach'))))
206 $message->error_permission();
210 UPDATE " . TABLE_PREFIX
. "attachment
211 SET description = '" . $bugsys->in
['description'] . "',
212 obsolete = " . intval($bugsys->in
['obsolete']) . "
213 WHERE attachmentid = " . intval($bugsys->in
['attachmentid'])
216 $hist[1] = $db->query_first("SELECT * FROM " . TABLE_PREFIX
. "attachment WHERE attachmentid = $attachment[attachmentid]");
218 $diff[0] = array_diff_assoc($attachment, $hist[1]);
219 $diff[1] = array_diff_assoc($hist[1], $attachment);
221 $log->language
= 'log_update_attachment';
222 $log->arguments
= array($attachment['attachmentid']);
223 $log->log($log->diff('description', $diff[0]['description'], $diff[1]['description']));
224 $log->log($log->diff('obsolete', $diff[0]['obsolete'], $diff[1]['obsolete']));
226 echo "<a href=\"showreport.php?bugid=$bug[bugid]\">attachment updated</a>";
229 // ###################################################################
231 if ($_REQUEST['do'] == 'edit')
233 if (!(can_perform('caneditattach') OR ($attachment['userid'] == $bugsys->userinfo
['userid'] AND can_perform('canputattach'))))
235 $message->error_permission();
238 $show['delete'] = ((can_perform('caneditattach')) ? true
: false
);
240 eval('$template->flush("' . $template->fetch('editattach') . '");');
243 /*=====================================================================*\
244 || ###################################################################
247 || ###################################################################
248 \*=====================================================================*/