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('alert
: bad attachment
');
33 $bug = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "bug WHERE bugid = " . (($attachment['attachmentid
']) ? $attachment['bugid
'] : intval($bugsys->in['bugid
'])));
36 $message->error('alert
: bad bug
');
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->language = 'log_kill_attachment
';
56 $log->arguments = array($attachment['attachmentid
']);
57 $log->allowempty = true;
60 $message->redirect('attachment removed
', "showreport.php?bugid=$bug[bugid]");
63 // ###################################################################
65 if ($_REQUEST['do'] == 'delete
')
67 if (!can_perform('caneditattach
'))
69 $message->error_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 $message->error_permission();
85 $FILE =& $_FILES['attachment
'];
88 switch ($FILE['error
'])
91 case 1: $message->error('PHP said the file you uploaded was too big
.'); break;
92 case 2: $message->error('The file exceeds the allowed upload size
.'); break;
93 case 3: $message->error('The file was only partially uploaded
.'); break;
94 case 4: $message->error('The file was not uploaded at all
.'); break;
95 case 6: $message->error('PHP could not find the
/tmp directory
.'); break;
99 if (!is_uploaded_file($FILE['tmp_name
']))
101 $message->error('The file you specified did not upload
.');
104 // #*# put some MIME-type validation here
106 if (!$bugsys->in['description
'])
108 $message->error('you need a file description
!');
111 $filedata = $bugsys->escape(file_get_contents($FILE['tmp_name
']), true, true);
114 // insert an attachment
116 INSERT INTO attachment
117 (bugid, filename, mimetype, filesize,
118 attachment, description, dateline, userid)
120 ($bug[bugid], '" . $bugsys->escape($FILE['name']) . "',
121 '" . $bugsys->escape($FILE['type']) . "', " . intval($FILE['size
']) . ",
122 '$filedata', '" . $bugsys->in['description
'] . "', $time,
123 " . $bugsys->userinfo['userid'] . "
127 $attachmentid = $db->insert_id();
128 $log->language = 'log_new_attachment';
129 $log->arguments = array($FILE['name'], $attachmentid);
130 $log->allowempty = true;
134 $obsoletes = $_POST['obsoletes'];
135 if (count($obsoletes) > 0)
137 array_walk($obsoletes, 'intval');
138 $db->query("UPDATE
" . TABLE_PREFIX . "attachment SET obsolete
= 1 WHERE attachmentid
IN (" . implode(',', $obsoletes) . ") AND !obsolete
AND bugid
= $bug[bugid
]");
140 $log->language = 'log_mark_obsoletes';
141 $log->arguments = array($attachmentid, $FILE['name'], implode(', ', $obsoletes));
142 $log->log($log->diff('obsoleted attachments', '', implode(', ', $obsoletes)));
145 // handle comment stuff
146 if (can_perform('canpostcomments') AND trim($bugsys->in['comment']))
148 $bugsys->in['comment_parsed'] = $bugsys->in['comment'];
150 if (!$bugsys->options['allowhtml'])
152 $bugsys->in['comment_parsed'] = $bugsys->sanitize($bugsys->in['comment_parsed']);
156 INSERT INTO
" . TABLE_PREFIX . "comment
157 (bugid
, userid
, dateline
, comment
, comment_parsed
)
159 ($bug[bugid
], " . $bugsys->userinfo['userid'] . ",
160 $time, '" . $bugsys->in['comment
'] . "',
161 '" . nl2br($bugsys->in['comment_parsed
']) . "'
165 $commentid = $db->insert_id();
167 $log->language = 'log_new_attachment_comment';
168 $log->arguments = array($attachmentid, $commentid);
169 $log->allowempty = true;
173 // update the last post data
174 $db->query("UPDATE
" . TABLE_PREFIX . "bug SET lastposttime
= $time, lastpostby
= " . $bugsys->userinfo['userid'] . " WHERE bugid
= $bug[bugid
]");
176 $message->redirect('attachment added', "showreport
.php
?bugid
=$bug[bugid
]");
179 // ###################################################################
181 if ($_REQUEST['do'] == 'add')
183 if (!can_perform('canputattach'))
185 $message->error_permission();
188 $MAXFILESIZE = $funct->fetch_max_attachment_size();
190 $show['addcomment'] = ((can_perform('canpostcomments')) ? true : false);
191 $show['obsoletes'] = false;
193 $obsoletes_fetch = $db->query("SELECT
* FROM
" . TABLE_PREFIX . "attachment WHERE bugid
= $bug[bugid
] AND !obsolete
");
195 while ($obsolete = $db->fetch_array($obsoletes_fetch))
197 $show['obsoletes'] = true;
198 $obsoletes .= "<div
><input name
=\"obsoletes
[]\" type
=\"checkbox\" value
=\"$obsolete[attachmentid
]\" /> $obsolete[filename
] [$obsolete[description
]]</div
>\n";
201 eval('$template->flush("' . $template->fetch('newattach
') . '");');
204 // ###################################################################
206 if ($_POST['do'] == 'update')
208 if (!(can_perform('caneditattach') OR ($attachment['userid'] == $bugsys->userinfo['userid'] AND can_perform('canputattach'))))
210 $message->error_permission();
214 UPDATE
" . TABLE_PREFIX . "attachment
215 SET description
= '" . $bugsys->in['description
'] . "',
216 obsolete
= " . intval($bugsys->in['obsolete']) . "
217 WHERE attachmentid
= " . intval($bugsys->in['attachmentid'])
220 $hist[1] = $db->query_first("SELECT
* FROM
" . TABLE_PREFIX . "attachment WHERE attachmentid
= $attachment[attachmentid
]");
222 $diff[0] = array_diff_assoc($attachment, $hist[1]);
223 $diff[1] = array_diff_assoc($hist[1], $attachment);
225 $log->language = 'log_update_attachment';
226 $log->arguments = array($attachment['attachmentid']);
227 $log->log($log->diff('description', $diff[0]['description'], $diff[1]['description']));
228 $log->log($log->diff('obsolete', $diff[0]['obsolete'], $diff[1]['obsolete']));
230 echo "<a href
=\"showreport
.php
?bugid
=$bug[bugid
]\">attachment updated
</a
>";
233 // ###################################################################
235 if ($_REQUEST['do'] == 'edit')
237 if (!(can_perform('caneditattach') OR ($attachment['userid'] == $bugsys->userinfo['userid'] AND can_perform('canputattach'))))
239 $message->error_permission();
242 $show['delete'] = ((can_perform('caneditattach')) ? true : false);
244 eval('$template->flush("' . $template->fetch('editattach
') . '");');
247 /*=====================================================================*\
248 || ###################################################################
251 || ###################################################################
252 \*=====================================================================*/