2 /*=====================================================================*\
3 || ###################################################################
5 || # Copyright (c)2004-2008 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(
28 $focus['showreport'] = 'focus';
30 require_once('./global.php');
31 require_once('./includes/class_notification.php');
32 require_once('./includes/api_attachment.php');
33 require_once('./includes/api_comment.php');
35 if (isset($input->in
['attachmentid']))
37 $attachment = $db->queryFirst("SELECT * FROM " . TABLE_PREFIX
. "attachment WHERE attachmentid = " . $input->inputClean('attachmentid', TYPE_UINT
));
40 $message->error(L_INVALID_ID
);
44 $bug = $db->queryFirst("SELECT * FROM " . TABLE_PREFIX
. "bug WHERE bugid = " . (($attachment['attachmentid']) ?
$attachment['bugid'] : $input->inputClean('bugid', TYPE_UINT
)));
47 $message->error(L_INVALID_ID
);
50 if (!check_bug_permissions($bug))
52 $message->errorPermission();
55 require_once('./includes/class_logging.php');
57 $notif = new NotificationCenter();
58 $notif->setBugData($bug);
60 // ###################################################################
62 if ($_POST['do'] == 'insert')
64 $attachapi = new AttachmentAPI();
65 $attachapi->set('bugid', $input->in
['bugid']);
67 if (!can_perform('canputattach', $bug['product']))
69 $message->errorPermission();
73 $var = $db->queryFirst("SHOW VARIABLES LIKE 'max_allowed_packet'");
74 BSApp
::debug("max_allowed_packet = $var[Value]");
77 $FILE = &$_FILES['attachment'];
80 switch ($FILE['error'])
83 case 1: $message->addError(T('PHP said the file you uploaded was too big.')); break;
84 case 2: $message->addError(T('The file exceeds the allowed upload size.')); break;
85 case 3: $message->addError(T('The file was only partially uploaded.')); break;
86 case 4: $message->addError(T('The file was not uploaded at all.')); break;
87 case 6: $message->addError(T('PHP could not find the /tmp directory.')); break;
91 if (!is_uploaded_file($FILE['tmp_name']))
93 $message->addError(T('The file you specified did not upload.'));
96 // TODO - put some MIME-type validation here
98 if (filesize($FILE['tmp_name']) > $var['Value'])
100 $message->addError(T('The file you specified exceeds MySQL\'s maximum allowed packet.'));
103 $attachapi->set('attachment', file_get_contents($FILE['tmp_name']));
104 $attachapi->set('filename', $FILE['name']);
105 $attachapi->set('mimetype', $FILE['type']);
106 $attachapi->set('filesize', $FILE['size']);
107 $attachapi->set('description', $input->in
['description']);
108 $attachapi->set('userid', bugdar
::$userinfo['userid']);
110 // insert an attachment
111 if (!$message->hasErrors())
113 $attachapi->insert();
115 $obsoletes = $input->inputClean('obsoletes', TYPE_UINT
);
117 $notif->sendNewAttachmentNotice($attachapi->values
, $obsoletes, $attachapi->insertid
);
120 if (is_array($obsoletes) AND sizeof($obsoletes) > 0)
122 $db->query("UPDATE " . TABLE_PREFIX
. "attachment SET obsolete = 1 WHERE attachmentid IN (" . implode(',', $obsoletes) . ") AND !obsolete AND bugid = $bug[bugid]");
124 foreach ($obsoletes as $attachmentid)
127 $log->setBugId($bug['bugid']);
128 $log->setAttachmentId($attachmentid);
129 $log->addData(true
, array('obsolete' => 0), array('obsolete'), false
, 'attachment');
130 $log->addData(false
, array('obsolete' => 1), array('obsolete'), false
, 'attachment');
131 $log->updateHistory();
135 // handle comment stuff
136 if (can_perform('canpostcomments', $bug['product']) AND trim($input->in
['comment']))
138 $comment = new CommentAPI();
139 $comment->set('bugid', $input->in
['bugid']);
140 $comment->set('userid', bugdar
::$userinfo['userid']);
141 $comment->set('comment', $input->in
['comment']);
142 $comment->set('dateline', $attachapi->values
['dateline']);
145 $notif->sendNewCommentNotice($comment->values
);
148 // update the last post data
149 $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]");
153 $message->redirect(T('The attachment has been added to the bug.'), "showreport.php?bugid=$bug[bugid]");
157 $show['errors'] = true
;
158 $_REQUEST['do'] = 'add';
162 // ###################################################################
164 if ($_REQUEST['do'] == 'add')
166 if (!can_perform('canputattach', $bug['product']))
168 $message->errorPermission();
171 $MAXFILESIZE = BSFunctions
::fetch_max_php_file_size();
173 $show['addcomment'] = ((can_perform('canpostcomments', $bug['product'])) ? true
: false
);
174 $show['obsoletes'] = false
;
176 $obsoletes_fetch = $db->query("SELECT * FROM " . TABLE_PREFIX
. "attachment WHERE bugid = $bug[bugid] AND !obsolete");
178 foreach ($obsoletes_fetch as $obsolete)
180 $show['obsoletes'] = true
;
181 $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";
184 $tpl = new BSTemplate('newattach');
187 'message' => $message,
188 'MAXFILESIZE' => $MAXFILESIZE,
189 'obsoletes' => $obsoletes,
192 $tpl->evaluate()->flush();
195 // ###################################################################
197 if ($_POST['do'] == 'update')
199 if (!(can_perform('caneditattach', $bug['product']) OR ($attachment['userid'] == bugdar
::$userinfo['userid'] AND can_perform('canputattach', $bug['product']))))
201 $message->errorPermission();
204 $attachapi = new AttachmentAPI();
205 $attachapi->set('attachmentid', $input->in
['attachmentid']);
207 if ($input->in
['__delete__'] != '')
209 if (!(can_perform('caneditattach', $bug['product']) AND can_perform('candeletedata', $bug['productid'])))
211 $message->errorPermission();
214 $attachapi->remove();
216 $message->redirect(T('The attachment was successfully deleted.'), "showreport.php?bugid=$bug[bugid]");
220 $log = new Logging();
221 $log->setBugId($bug['bugid']);
222 $log->setAttachmentId($input->in
['attachmentid']);
226 $log->addData(true
, $attachapi->record
, array('attachment'), true
, 'attachment');
228 $attachapi->set('description', $input->in
['description']);
229 $attachapi->set('obsolete', $input->in
['obsolete']);
230 $attachapi->update();
232 $log->addData(false
, $attachapi->values
, array('attachment'), true
, 'attachment');
234 $log->updateHistory();
236 $message->redirect(T('The attachment was successfully modified.'), "showreport.php?bugid=$bug[bugid]");
240 // ###################################################################
242 if ($_REQUEST['do'] == 'edit')
244 if (!(can_perform('caneditattach', $bug['product']) OR ($attachment['userid'] == bugdar
::$userinfo['userid'] AND can_perform('canputattach', $bug['product']))))
246 $message->errorPermission();
249 $show['delete'] = (can_perform('caneditattach', $bug['product']) AND can_perform('candeletedata', $bug['productid']));
251 $tpl = new BSTemplate('editattach');
253 'attachment' => $attachment,
256 $tpl->evaluate()->flush();