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_api_error
.php
');
33 require_once('./includes
/class_notification
.php
');
34 require_once('./includes
/api_attachment
.php
');
35 require_once('./includes
/api_comment
.php
');
37 APIError(array(new API_Error_Handler($message), 'user_cumulative
'));
39 if (isset($input->in['attachmentid
']))
41 $attachment = $db->queryFirst("SELECT * FROM " . TABLE_PREFIX . "attachment WHERE attachmentid = " . $input->inputClean('attachmentid
', TYPE_UINT));
44 $message->error(L_INVALID_ID);
48 $bug = $db->queryFirst("SELECT * FROM " . TABLE_PREFIX . "bug WHERE bugid = " . (($attachment['attachmentid
']) ? $attachment['bugid
'] : $input->inputClean('bugid
', TYPE_UINT)));
51 $message->error(L_INVALID_ID);
54 if (!check_bug_permissions($bug))
56 $message->errorPermission();
59 require_once('./includes
/class_logging
.php
');
61 $notif = new NotificationCenter;
62 $notif->set_bug_data($bug);
64 // ###################################################################
66 if ($_POST['do'] == 'insert
')
68 $attachapi = new AttachmentAPI($bugsys);
69 $attachapi->set('bugid
', $input->in['bugid
']);
71 if (!can_perform('canputattach
', $bug['product
']))
73 $message->errorPermission();
77 $var = $db->queryFirst("SHOW VARIABLES LIKE 'max_allowed_packet
'");
78 BSApp::debug("max_allowed_packet = $var[Value]");
81 $FILE =& $_FILES['attachment
'];
84 switch ($FILE['error
'])
87 case 1: $message->addError(T('PHP said the file you uploaded was too big
.')); break;
88 case 2: $message->addError(T('The file exceeds the allowed upload size
.')); break;
89 case 3: $message->addError(T('The file was only partially uploaded
.')); break;
90 case 4: $message->addError(T('The file was not uploaded at all
.')); break;
91 case 6: $message->addError(T('PHP could not find the
/tmp directory
.')); break;
95 if (!is_uploaded_file($FILE['tmp_name
']))
97 $message->addError(T('The file you specified did not upload
.'));
100 // TODO - put some MIME-type validation here
102 if (filesize($FILE['tmp_name
']) > $var['Value
'])
104 $message->addError(T('The file you specified exceeds MySQL\'s maximum allowed packet
.'));
107 $attachapi->set('attachment
', file_get_contents($FILE['tmp_name
']));
108 $attachapi->set('filename
', $FILE['name
']);
109 $attachapi->set('mimetype
', $FILE['type
']);
110 $attachapi->set('filesize
', $FILE['size
']);
111 $attachapi->set('description
', $input->in['description
']);
112 $attachapi->set('userid
', bugdar::$userinfo['userid
']);
114 // insert an attachment
115 if (!$message->hasErrors())
117 $attachapi->insert();
119 $obsoletes = $input->inputClean('obsoletes
', TYPE_UINT);
121 $notif->send_new_attachment_notice($attachapi->values, $obsoletes, $attachapi->insertid);
124 if (is_array($obsoletes) AND sizeof($obsoletes) > 0)
126 $db->query("UPDATE " . TABLE_PREFIX . "attachment SET obsolete = 1 WHERE attachmentid IN (" . implode(',', $obsoletes) . ") AND !obsolete AND bugid = $bug[bugid]");
128 foreach ($obsoletes AS $attachmentid)
131 $log->set_bugid($bug['bugid
']);
132 $log->set_attachmentid($attachmentid);
133 $log->add_data(true, array('obsolete
' => 0), array('obsolete
'), false, 'attachment
');
134 $log->add_data(false, array('obsolete
' => 1), array('obsolete
'), false, 'attachment
');
135 $log->update_history();
139 // handle comment stuff
140 if (can_perform('canpostcomments
', $bug['product
']) AND trim($input->in['comment
']))
142 $comment = new CommentAPI($bugsys);
143 $comment->set('bugid
', $input->in['bugid
']);
144 $comment->set('userid
', bugdar::$userinfo['userid
']);
145 $comment->set('comment
', $input->in['comment
']);
146 $comment->set('dateline
', $attachapi->values['dateline
']);
149 $notif->send_new_comment_notice($comment->values);
152 // update the last post data
153 $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]");
157 $message->redirect(T('The attachment has been added to the bug
.'), "showreport.php?bugid=$bug[bugid]");
161 $show['errors
'] = true;
162 $_REQUEST['do'] = 'add
';
166 // ###################################################################
168 if ($_REQUEST['do'] == 'add
')
170 if (!can_perform('canputattach
', $bug['product
']))
172 $message->errorPermission();
175 $MAXFILESIZE = BSFunctions::fetch_max_php_file_size();
177 $show['addcomment
'] = ((can_perform('canpostcomments
', $bug['product
'])) ? true : false);
178 $show['obsoletes
'] = false;
180 $obsoletes_fetch = $db->query("SELECT * FROM " . TABLE_PREFIX . "attachment WHERE bugid = $bug[bugid] AND !obsolete");
182 foreach ($obsoletes_fetch as $obsolete)
184 $show['obsoletes
'] = true;
185 $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";
188 eval('$template->flush("' . $template->fetch('newattach') . '");');
191 // ###################################################################
193 if ($_POST['do'] == 'update
')
195 if (!(can_perform('caneditattach
', $bug['product
']) OR ($attachment['userid
'] == bugdar::$userinfo['userid
'] AND can_perform('canputattach
', $bug['product
']))))
197 $message->errorPermission();
200 $attachapi = new AttachmentAPI($bugsys);
201 $attachapi->set('attachmentid
', $input->in['attachmentid
']);
202 $attachapi->dorelations = array();
203 $attachapi->set_condition();
205 if ($input->in['__delete__
'] != '')
207 if (!(can_perform('caneditattach
', $bug['product
']) AND can_perform('candeletedata
', $bug['productid
'])))
209 $message->errorPermission();
212 $attachapi->delete();
214 $message->redirect(T('The attachment was successfully deleted
.'), "showreport.php?bugid=$bug[bugid]");
219 $log->set_bugid($bug['bugid
']);
220 $log->set_attachmentid($input->in['attachmentid
']);
224 $log->add_data(true, $attachapi->record, array('attachment
'), true, 'attachment
');
226 $attachapi->set('description
', $input->in['description
']);
227 $attachapi->set('obsolete
', $input->in['obsolete
']);
228 $attachapi->update();
230 $log->add_data(false, $attachapi->values, array('attachment
'), true, 'attachment
');
232 $log->update_history();
234 $message->redirect(T('The attachment was successfully modified
.'), "showreport.php?bugid=$bug[bugid]");
238 // ###################################################################
240 if ($_REQUEST['do'] == 'edit
')
242 if (!(can_perform('caneditattach
', $bug['product
']) OR ($attachment['userid
'] == bugdar::$userinfo['userid
'] AND can_perform('canputattach
', $bug['product
']))))
244 $message->errorPermission();
247 $show['delete
'] = (can_perform('caneditattach
', $bug['product
']) AND can_perform('candeletedata
', $bug['productid
']));
249 eval('$template->flush("' . $template->fetch('editattach') . '");');
252 /*=====================================================================*\
253 || ###################################################################
256 || ###################################################################
257 \*=====================================================================*/