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 echo 'alert: bad attachment';
30 $bug = $db->query_first("SELECT * FROM " . TABLE_PREFIX
. "bug WHERE bugid = " . (($attachment['attachmentid']) ?
$attachment['bugid'] : intval($bugsys->in
['bugid'])));
33 echo 'alert: bad bug';
38 require_once('./includes/class_history.php');
40 $log->bugid
= $bug['bugid'];
42 // ###################################################################
44 if ($_REQUEST['do'] == 'kill')
46 if (!can_perform('caneditattach'))
48 echo 'alert: no permission';
52 $db->query("DELETE FROM " . TABLE_PREFIX
. "attachment WHERE attachmentid = $attachment[attachmentid]");
54 $log->language
= 'log_kill_attachment';
55 $log->arguments
= array($attachment['attachmentid']);
56 $log->allowempty
= true
;
59 echo "<a href=\"showreport.php?bugid=$bug[bugid]\">attachment removed</a>";
62 // ###################################################################
64 if ($_REQUEST['do'] == 'delete')
66 if (!can_perform('caneditattach'))
68 echo 'alert: no permission';
72 echo "are you sure you want to delete this attachment? <a href=\"attachment.php?do=kill&attachmentid=$attachment[attachmentid]\">yes</a>";
75 // ###################################################################
77 if ($_POST['do'] == 'insert')
79 if (!can_perform('canputattach'))
81 echo 'alert: no permission';
86 $FILE =& $_FILES['attachment'];
89 switch ($FILE['error'])
92 case 1: echo 'PHP said the file you uploaded was too big.'; exit; break;
93 case 2: echo 'The file exceeds the allowed upload size.'; exit; break;
94 case 3: echo 'The file was only partially uploaded.'; exit; break;
95 case 4: echo 'The file was not uploaded at all.'; exit; break;
96 case 6: echo 'PHP could not find the /tmp directory.'; exit; break;
100 if (!is_uploaded_file($FILE['tmp_name']))
102 echo 'The file you specified did not upload.';
106 // #*# put some MIME-type validation here
108 if (!$bugsys->in
['description'])
110 echo 'you need a file description!';
114 $filedata = $bugsys->escape(file_get_contents($FILE['tmp_name']), true
, true
);
117 // insert an attachment
119 INSERT INTO attachment
120 (bugid, filename, mimetype, filesize,
121 attachment, description, dateline, userid)
123 ($bug[bugid], '" . $bugsys->escape($FILE['name']) . "',
124 '" . $bugsys->escape($FILE['type']) . "', " . intval($FILE['size']) . ",
125 '$filedata', '" . $bugsys->in
['description'] . "', $time,
126 " . $bugsys->userinfo
['userid'] . "
130 $attachmentid = $db->insert_id();
131 $log->language
= 'log_new_attachment';
132 $log->arguments
= array($FILE['name'], $attachmentid);
133 $log->allowempty
= true
;
137 $obsoletes = $_POST['obsoletes'];
138 if (count($obsoletes) > 0)
140 array_walk($obsoletes, 'intval');
141 $db->query("UPDATE " . TABLE_PREFIX
. "attachment SET obsolete = 1 WHERE attachmentid IN (" . implode(',', $obsoletes) . ") AND !obsolete AND bugid = $bug[bugid]");
143 $log->language
= 'log_mark_obsoletes';
144 $log->arguments
= array($attachmentid, $FILE['name'], implode(', ', $obsoletes));
145 $log->log($log->diff('obsoleted attachments', '', implode(', ', $obsoletes)));
148 // handle comment stuff
149 if (can_perform('canpostcomments') AND trim($bugsys->in
['comment']))
151 $bugsys->in
['comment_parsed'] = $bugsys->in
['comment'];
153 if (!$bugsys->options
['allowhtml'])
155 $bugsys->in
['comment_parsed'] = $bugsys->sanitize($bugsys->in
['comment_parsed']);
159 INSERT INTO " . TABLE_PREFIX
. "comment
160 (bugid, userid, dateline, comment, comment_parsed)
162 ($bug[bugid], " . $bugsys->userinfo
['userid'] . ",
163 $time, '" . $bugsys->in
['comment'] . "',
164 '" . nl2br($bugsys->in
['comment_parsed']) . "'
168 $commentid = $db->insert_id();
170 $log->language
= 'log_new_attachment_comment';
171 $log->arguments
= array($attachmentid, $commentid);
172 $log->allowempty
= true
;
176 // update the last post data
177 $db->query("UPDATE " . TABLE_PREFIX
. "bug SET lastposttime = $time, lastpostby = " . $bugsys->userinfo
['userid'] . " WHERE bugid = $bug[bugid]");
179 echo "<a href=\"showreport.php?bugid=$bug[bugid]\">attachment added</a>";
182 // ###################################################################
184 if ($_REQUEST['do'] == 'add')
186 if (!can_perform('canputattach'))
188 echo 'alert: no permission';
192 $MAXFILESIZE = $funct->fetch_max_attachment_size();
194 $show['addcomment'] = ((can_perform('canpostcomments')) ? true
: false
);
195 $show['obsoletes'] = false
;
197 $obsoletes_fetch = $db->query("SELECT * FROM " . TABLE_PREFIX
. "attachment WHERE bugid = $bug[bugid] AND !obsolete");
199 while ($obsolete = $db->fetch_array($obsoletes_fetch))
201 $show['obsoletes'] = true
;
202 $obsoletes .= "<div><input name=\"obsoletes[]\" type=\"checkbox\" value=\"$obsolete[attachmentid]\" /> $obsolete[filename] [$obsolete[description]]</div>\n";
205 eval('$template->flush("' . $template->fetch('newattach') . '");');
208 // ###################################################################
210 if ($_POST['do'] == 'update')
212 if (!(can_perform('caneditattach') OR ($attachment['userid'] == $bugsys->userinfo
['userid'] AND can_perform('canputattach'))))
214 echo 'alert: no permssion';
219 UPDATE " . TABLE_PREFIX
. "attachment
220 SET description = '" . $bugsys->in
['description'] . "',
221 obsolete = " . intval($bugsys->in
['obsolete']) . "
222 WHERE attachmentid = " . intval($bugsys->in
['attachmentid'])
225 $hist[1] = $db->query_first("SELECT * FROM " . TABLE_PREFIX
. "attachment WHERE attachmentid = $attachment[attachmentid]");
227 $diff[0] = array_diff_assoc($attachment, $hist[1]);
228 $diff[1] = array_diff_assoc($hist[1], $attachment);
230 $log->language
= 'log_update_attachment';
231 $log->arguments
= array($attachment['attachmentid']);
232 $log->log($log->diff('description', $diff[0]['description'], $diff[1]['description']));
233 $log->log($log->diff('obsolete', $diff[0]['obsolete'], $diff[1]['obsolete']));
235 echo "<a href=\"showreport.php?bugid=$bug[bugid]\">attachment updated</a>";
238 // ###################################################################
240 if ($_REQUEST['do'] == 'edit')
242 if (!(can_perform('caneditattach') OR ($attachment['userid'] == $bugsys->userinfo
['userid'] AND can_perform('canputattach'))))
244 echo 'alert: no permssion';
248 $show['delete'] = ((can_perform('caneditattach')) ? true
: false
);
250 eval('$template->flush("' . $template->fetch('editattach') . '");');
253 /*=====================================================================*\
254 || ###################################################################
257 || ###################################################################
258 \*=====================================================================*/