2 /*=====================================================================*\
3 || ###################################################################
5 || # Copyright ©2002-2007 Blue Static
7 || # This program is free software; you can redistribute it and/or modify
8 || # it under the terms of the GNU General Public License as published by
9 || # the Free Software Foundation; version 2 of the License.
11 || # This program is distributed in the hope that it will be useful, but
12 || # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 || # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 || # You should have received a copy of the GNU General Public License along
17 || # with this program; if not, write to the Free Software Foundation, Inc.,
18 || # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 || ###################################################################
20 \*=====================================================================*/
22 $fetchtemplates = array(
27 define('SVN', '$Id$');
29 $focus['showreport'] = 'focus';
31 require_once('./global.php');
32 require_once('./includes/class_notification.php');
33 require_once('./includes/api_attachment.php');
34 require_once('./includes/api_comment.php');
36 if (isset($input->in
['attachmentid']))
38 $attachment = $db->queryFirst("SELECT * FROM " . TABLE_PREFIX
. "attachment WHERE attachmentid = " . $input->inputClean('attachmentid', TYPE_UINT
));
41 $message->error(L_INVALID_ID
);
45 $bug = $db->queryFirst("SELECT * FROM " . TABLE_PREFIX
. "bug WHERE bugid = " . (($attachment['attachmentid']) ?
$attachment['bugid'] : $input->inputClean('bugid', TYPE_UINT
)));
48 $message->error(L_INVALID_ID
);
51 if (!check_bug_permissions($bug))
53 $message->errorPermission();
56 require_once('./includes/class_logging.php');
58 $notif = new NotificationCenter();
59 $notif->set_bug_data($bug);
61 // ###################################################################
63 if ($_POST['do'] == 'insert')
65 $attachapi = new AttachmentAPI();
66 $attachapi->set('bugid', $input->in
['bugid']);
68 if (!can_perform('canputattach', $bug['product']))
70 $message->errorPermission();
74 $var = $db->queryFirst("SHOW VARIABLES LIKE 'max_allowed_packet'");
75 BSApp
::debug("max_allowed_packet = $var[Value]");
78 $FILE = &$_FILES['attachment'];
81 switch ($FILE['error'])
84 case 1: $message->addError(T('PHP said the file you uploaded was too big.')); break;
85 case 2: $message->addError(T('The file exceeds the allowed upload size.')); break;
86 case 3: $message->addError(T('The file was only partially uploaded.')); break;
87 case 4: $message->addError(T('The file was not uploaded at all.')); break;
88 case 6: $message->addError(T('PHP could not find the /tmp directory.')); break;
92 if (!is_uploaded_file($FILE['tmp_name']))
94 $message->addError(T('The file you specified did not upload.'));
97 // TODO - put some MIME-type validation here
99 if (filesize($FILE['tmp_name']) > $var['Value'])
101 $message->addError(T('The file you specified exceeds MySQL\'s maximum allowed packet.'));
104 $attachapi->set('attachment', file_get_contents($FILE['tmp_name']));
105 $attachapi->set('filename', $FILE['name']);
106 $attachapi->set('mimetype', $FILE['type']);
107 $attachapi->set('filesize', $FILE['size']);
108 $attachapi->set('description', $input->in
['description']);
109 $attachapi->set('userid', bugdar
::$userinfo['userid']);
111 // insert an attachment
112 if (!$message->hasErrors())
114 $attachapi->insert();
116 $obsoletes = $input->inputClean('obsoletes', TYPE_UINT
);
118 $notif->send_new_attachment_notice($attachapi->values
, $obsoletes, $attachapi->insertid
);
121 if (is_array($obsoletes) AND sizeof($obsoletes) > 0)
123 $db->query("UPDATE " . TABLE_PREFIX
. "attachment SET obsolete = 1 WHERE attachmentid IN (" . implode(',', $obsoletes) . ") AND !obsolete AND bugid = $bug[bugid]");
125 foreach ($obsoletes as $attachmentid)
128 $log->set_bugid($bug['bugid']);
129 $log->set_attachmentid($attachmentid);
130 $log->add_data(true
, array('obsolete' => 0), array('obsolete'), false
, 'attachment');
131 $log->add_data(false
, array('obsolete' => 1), array('obsolete'), false
, 'attachment');
132 $log->update_history();
136 // handle comment stuff
137 if (can_perform('canpostcomments', $bug['product']) AND trim($input->in
['comment']))
139 $comment = new CommentAPI();
140 $comment->set('bugid', $input->in
['bugid']);
141 $comment->set('userid', bugdar
::$userinfo['userid']);
142 $comment->set('comment', $input->in
['comment']);
143 $comment->set('dateline', $attachapi->values
['dateline']);
146 $notif->send_new_comment_notice($comment->values
);
149 // update the last post data
150 $db->query("UPDATE " . TABLE_PREFIX
. "bug SET lastposttime = " . $attachapi->values
['dateline'] . ", hiddenlastposttime = " . $attachapi->values
['dateline'] . ", lastpostby = " . bugdar
::$userinfo['userid'] . ", hiddenlastpostby = " . bugdar
::$userinfo['userid'] . " WHERE bugid = $bug[bugid]");
154 $message->redirect(T('The attachment has been added to the bug.'), "showreport.php?bugid=$bug[bugid]");
158 $show['errors'] = true
;
159 $_REQUEST['do'] = 'add';
163 // ###################################################################
165 if ($_REQUEST['do'] == 'add')
167 if (!can_perform('canputattach', $bug['product']))
169 $message->errorPermission();
172 $MAXFILESIZE = BSFunctions
::fetch_max_php_file_size();
174 $show['addcomment'] = ((can_perform('canpostcomments', $bug['product'])) ? true
: false
);
175 $show['obsoletes'] = false
;
177 $obsoletes_fetch = $db->query("SELECT * FROM " . TABLE_PREFIX
. "attachment WHERE bugid = $bug[bugid] AND !obsolete");
179 foreach ($obsoletes_fetch as $obsolete)
181 $show['obsoletes'] = true
;
182 $obsoletes .= "<div><input name=\"obsoletes[]\" type=\"checkbox\" value=\"$obsolete[attachmentid]\"" . (is_array($input->in
['obsoletes']) AND in_array($obsolete['attachmentid'], $input->in
['obsoletes']) ?
' checked="checked"' : '') . " /> $obsolete[filename]" . ($obsolete['description'] ?
" [$obsolete[description]]" : '') . "</div>\n";
185 $tpl = new BSTemplate('newattach');
188 'message' => $message,
189 'MAXFILESIZE' => $MAXFILESIZE,
190 'obsoletes' => $obsoletes,
193 $tpl->evaluate()->flush();
196 // ###################################################################
198 if ($_POST['do'] == 'update')
200 if (!(can_perform('caneditattach', $bug['product']) OR ($attachment['userid'] == bugdar
::$userinfo['userid'] AND can_perform('canputattach', $bug['product']))))
202 $message->errorPermission();
205 $attachapi = new AttachmentAPI();
206 $attachapi->set('attachmentid', $input->in
['attachmentid']);
208 if ($input->in
['__delete__'] != '')
210 if (!(can_perform('caneditattach', $bug['product']) AND can_perform('candeletedata', $bug['productid'])))
212 $message->errorPermission();
215 $attachapi->delete();
217 $message->redirect(T('The attachment was successfully deleted.'), "showreport.php?bugid=$bug[bugid]");
221 $log = new Logging();
222 $log->set_bugid($bug['bugid']);
223 $log->set_attachmentid($input->in
['attachmentid']);
227 $log->add_data(true
, $attachapi->record
, array('attachment'), true
, 'attachment');
229 $attachapi->set('description', $input->in
['description']);
230 $attachapi->set('obsolete', $input->in
['obsolete']);
231 $attachapi->update();
233 $log->add_data(false
, $attachapi->values
, array('attachment'), true
, 'attachment');
235 $log->update_history();
237 $message->redirect(T('The attachment was successfully modified.'), "showreport.php?bugid=$bug[bugid]");
241 // ###################################################################
243 if ($_REQUEST['do'] == 'edit')
245 if (!(can_perform('caneditattach', $bug['product']) OR ($attachment['userid'] == bugdar
::$userinfo['userid'] AND can_perform('canputattach', $bug['product']))))
247 $message->errorPermission();
250 $show['delete'] = (can_perform('caneditattach', $bug['product']) AND can_perform('candeletedata', $bug['productid']));
252 $tpl = new BSTemplate('editattach');
254 'attachment' => $attachment,
257 $tpl->evaluate()->flush();
260 /*=====================================================================*\
261 || ###################################################################
264 || ###################################################################
265 \*=====================================================================*/