2 /*=====================================================================*\
3 || ################################################################### ||
4 || # Bugdar [#]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 ($_POST['do'] == 'insert
')
48 if (!can_perform('canputattach
', $bug['productid
']))
50 $message->error_permission();
54 $FILE =& $_FILES['attachment
'];
57 switch ($FILE['error
'])
60 case 1: $message->error($lang->string('PHP said the file you uploaded was too big
.')); break;
61 case 2: $message->error($lang->string('The file exceeds the allowed upload size
.')); break;
62 case 3: $message->error($lang->string('The file was only partially uploaded
.')); break;
63 case 4: $message->error($lang->string('The file was not uploaded at all
.')); break;
64 case 6: $message->error($lang->string('PHP could not find the
/tmp directory
.')); break;
68 if (!is_uploaded_file($FILE['tmp_name
']))
70 $message->error($lang->string('The file you specified did not upload
.'));
73 // #*# put some MIME-type validation here
75 $filedata = $bugsys->escape(file_get_contents($FILE['tmp_name
']), true, true);
78 // insert an attachment
80 INSERT INTO " . TABLE_PREFIX . "attachment
81 (bugid, filename, mimetype, filesize,
82 attachment, description, dateline, userid)
84 ($bug[bugid], '" . $bugsys->escape($FILE['name']) . "',
85 '" . $bugsys->escape($FILE['type']) . "', " . intval($FILE['size
']) . ",
86 '$filedata', '" . $bugsys->in['description
'] . "', $time,
87 " . $bugsys->userinfo['userid'] . "
92 $obsoletes = $_POST['obsoletes'];
93 if (count($obsoletes) > 0)
95 array_walk($obsoletes, 'intval');
96 $db->query("UPDATE
" . TABLE_PREFIX . "attachment SET obsolete
= 1 WHERE attachmentid
IN (" . implode(',', $obsoletes) . ") AND !obsolete
AND bugid
= $bug[bugid
]");
98 foreach ($obsoletes AS $attachmentid)
100 $log->attachmentid = $attachmentid;
101 $log->log($log->diff('obsolete', 0, 1));
105 // handle comment stuff
106 if (can_perform('canpostcomments', $bug['productid']) AND trim($bugsys->in['comment']))
108 $bugsys->in['comment_parsed'] = $bugsys->in['comment'];
110 if (!$bugsys->options['allowhtml'])
112 $bugsys->in['comment_parsed'] = $bugsys->sanitize($bugsys->in['comment_parsed']);
116 INSERT INTO
" . TABLE_PREFIX . "comment
117 (bugid
, userid
, dateline
, comment
, comment_parsed
)
119 ($bug[bugid
], " . $bugsys->userinfo['userid'] . ",
120 $time, '" . $bugsys->in['comment
'] . "',
121 '" . nl2br($bugsys->in['comment_parsed
']) . "'
126 // update the last post data
127 $db->query("UPDATE
" . TABLE_PREFIX . "bug SET lastposttime
= $time, lastpostby
= " . $bugsys->userinfo['userid'] . " WHERE bugid
= $bug[bugid
]");
129 $message->redirect($lang->string('The attachment has been added to the bug.'), "showreport
.php
?bugid
=$bug[bugid
]");
132 // ###################################################################
134 if ($_REQUEST['do'] == 'add')
136 if (!can_perform('canputattach', $bug['productid']))
138 $message->error_permission();
141 $MAXFILESIZE = $funct->fetch_max_attachment_size();
143 $show['addcomment'] = ((can_perform('canpostcomments', $bug['productid'])) ? true : false);
144 $show['obsoletes'] = false;
146 $obsoletes_fetch = $db->query("SELECT
* FROM
" . TABLE_PREFIX . "attachment WHERE bugid
= $bug[bugid
] AND !obsolete
");
148 while ($obsolete = $db->fetch_array($obsoletes_fetch))
150 $show['obsoletes'] = true;
151 $obsoletes .= "<div
><input name
=\"obsoletes
[]\" type
=\"checkbox\" value
=\"$obsolete[attachmentid
]\" /> $obsolete[filename
] [$obsolete[description
]]</div
>\n";
154 eval('$template->flush("' . $template->fetch('newattach
') . '");');
157 // ###################################################################
159 if ($_POST['do'] == 'update')
161 if (!(can_perform('caneditattach', $bug['productid']) OR ($attachment['userid'] == $bugsys->userinfo['userid'] AND can_perform('canputattach', $bug['productid']))))
163 $message->error_permission();
167 UPDATE
" . TABLE_PREFIX . "attachment
168 SET description
= '" . $bugsys->in['description
'] . "',
169 obsolete
= " . intval($bugsys->in['obsolete']) . "
170 WHERE attachmentid
= " . intval($bugsys->in['attachmentid'])
173 $hist[1] = $db->query_first("SELECT
* FROM
" . TABLE_PREFIX . "attachment WHERE attachmentid
= $attachment[attachmentid
]");
175 $diff[0] = array_diff_assoc($attachment, $hist[1]);
176 $diff[1] = array_diff_assoc($hist[1], $attachment);
178 $log->attachmentid = $attachment['attachmentid'];
179 $log->log($log->diff('description', $diff[0]['description'], $diff[1]['description']));
180 $log->log($log->diff('obsolete', $diff[0]['obsolete'], $diff[1]['obsolete']));
182 $message->redirect($lang->string('The attachment was successfully modified.'), "showreport
.php
?bugid
=$bug[bugid
]");
185 // ###################################################################
187 if ($_REQUEST['do'] == 'edit')
189 if (!(can_perform('caneditattach', $bug['productid']) OR ($attachment['userid'] == $bugsys->userinfo['userid'] AND can_perform('canputattach', $bug['productid']))))
191 $message->error_permission();
194 $show['delete'] = ((can_perform('caneditattach', $bug['productid'])) ? true : false);
196 eval('$template->flush("' . $template->fetch('editattach
') . '");');
199 /*=====================================================================*\
200 || ###################################################################
203 || ###################################################################
204 \*=====================================================================*/