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';
37 // ###################################################################
39 if ($_REQUEST['do'] == 'kill')
41 if (!can_perform('caneditattach'))
43 echo 'alert: no permission';
47 $db->query("DELETE FROM " . TABLE_PREFIX
. "attachment WHERE attachmentid = $attachment[attachmentid]");
49 echo "<a href=\"showreport.php?bugid=$bug[bugid]\">attachment removed</a>";
52 // ###################################################################
54 if ($_REQUEST['do'] == 'delete')
56 if (!can_perform('caneditattach'))
58 echo 'alert: no permission';
62 echo "are you sure you want to delete this attachment? <a href=\"attachment.php?do=kill&attachmentid=$attachment[attachmentid]\">yes</a>";
65 // ###################################################################
67 if ($_POST['do'] == 'insert')
69 if (!can_perform('canputattach'))
71 echo 'alert: no permission';
76 $FILE =& $_FILES['attachment'];
79 switch ($FILE['error'])
82 case 1: echo 'PHP said the file you uploaded was too big.'; exit; break;
83 case 2: echo 'The file exceeds the allowed upload size.'; exit; break;
84 case 3: echo 'The file was only partially uploaded.'; exit; break;
85 case 4: echo 'The file was not uploaded at all.'; exit; break;
86 case 6: echo 'PHP could not find the /tmp directory.'; exit; break;
90 if (!is_uploaded_file($FILE['tmp_name']))
92 echo 'The file you specified did not upload.';
96 // #*# put some MIME-type validation here
98 if (!$bugsys->in
['description'])
100 echo 'you need a file description!';
104 $filedata = $bugsys->escape(file_get_contents($FILE['tmp_name']), true
, true
);
107 // insert an attachment
109 INSERT INTO attachment
110 (bugid, filename, mimetype, filesize,
111 attachment, description, dateline, userid)
113 ($bug[bugid], '" . $bugsys->escape($FILE['name']) . "',
114 '" . $bugsys->escape($FILE['type']) . "', " . intval($FILE['size']) . ",
115 '$filedata', '" . $bugsys->in
['description'] . "', $time,
116 " . $bugsys->userinfo
['userid'] . "
121 $obsoletes = $_POST['obsoletes'];
122 array_walk($obsoletes, 'intval');
123 $db->query("UPDATE " . TABLE_PREFIX
. "attachment SET obsolete = 1 WHERE attachmentid IN (" . implode(',', $obsoletes) . ") AND !obsolete AND bugid = $bug[bugid]");
125 // handle comment stuff
126 if (can_perform('canpostcomments') AND trim($bugsys->in
['comment']))
128 $bugsys->in
['comment_parsed'] = $bugsys->in
['comment'];
130 if (!$bugsys->options
['allowhtml'])
132 $bugsys->in
['comment_parsed'] = $bugsys->sanitize($bugsys->in
['comment_parsed']);
136 INSERT INTO " . TABLE_PREFIX
. "comment
137 (bugid, userid, dateline, comment, comment_parsed)
139 ($bug[bugid], " . $bugsys->userinfo
['userid'] . ",
140 $time, '" . $bugsys->in
['comment'] . "',
141 '" . nl2br($bugsys->in
['comment_parsed']) . "'
146 // update the last post data
147 $db->query("UPDATE " . TABLE_PREFIX
. "bug SET lastposttime = $time, lastpostby = " . $bugsys->userinfo
['userid'] . " WHERE bugid = $bug[bugid]");
149 echo "<a href=\"showreport.php?bugid=$bug[bugid]\">attachment added</a>";
153 // ###################################################################
155 if ($_REQUEST['do'] == 'add')
157 if (!can_perform('canputattach'))
159 echo 'alert: no permission';
163 $MAXFILESIZE = $funct->fetch_max_attachment_size();
165 $show['addcomment'] = ((can_perform('canpostcomments')) ? true
: false
);
166 $show['obsoletes'] = false
;
168 $obsoletes_fetch = $db->query("SELECT * FROM " . TABLE_PREFIX
. "attachment WHERE bugid = $bug[bugid] AND !obsolete");
170 while ($obsolete = $db->fetch_array($obsoletes_fetch))
172 $show['obsoletes'] = true
;
173 $obsoletes .= "<div><input name=\"obsoletes[]\" type=\"checkbox\" value=\"$obsolete[attachmentid]\" /> $obsolete[filename] [$obsolete[description]]</div>\n";
176 eval('$template->flush("' . $template->fetch('newattach') . '");');
179 // ###################################################################
181 if ($_POST['do'] == 'update')
183 if (!(can_perform('caneditattach') OR ($attachment['userid'] == $bugsys->userinfo
['userid'] AND can_perform('canputattach'))))
185 echo 'alert: no permssion';
190 UPDATE " . TABLE_PREFIX
. "attachment
191 SET description = '" . $bugsys->in
['description'] . "',
192 obsolete = " . intval($bugsys->in
['obsolete']) . "
193 WHERE attachmentid = " . intval($bugsys->in
['attachmentid'])
196 echo "<a href=\"showreport.php?bugid=$bug[bugid]\">attachment updated</a>";
199 // ###################################################################
201 if ($_REQUEST['do'] == 'edit')
203 if (!(can_perform('caneditattach') OR ($attachment['userid'] == $bugsys->userinfo
['userid'] AND can_perform('canputattach'))))
205 echo 'alert: no permssion';
209 $show['delete'] = ((can_perform('caneditattach')) ? true
: false
);
211 eval('$template->flush("' . $template->fetch('editattach') . '");');
214 /*=====================================================================*\
215 || ###################################################################
218 || ###################################################################
219 \*=====================================================================*/