2 /*=====================================================================*\
3 || ###################################################################
4 || # Bugdar [#]version[#]
5 || # Copyright ©2002-[#]year[#] Iris Studios, Inc.
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 [#]gpl[#] 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/api_attachment.php');
34 require_once('./includes/api_comment.php');
36 APIError(array(new API_Error_Handler($message), 'user_cumulative'));
38 if (isset($bugsys->in
['attachmentid']))
40 $attachment = $db->query_first("SELECT * FROM " . TABLE_PREFIX
. "attachment WHERE attachmentid = " . intval($bugsys->in
['attachmentid']));
43 $message->error($lang->getlex('error_invalid_id'));
47 $bug = $db->query_first("SELECT * FROM " . TABLE_PREFIX
. "bug WHERE bugid = " . (($attachment['attachmentid']) ?
$attachment['bugid'] : intval($bugsys->in
['bugid'])));
50 $message->error($lang->getlex('error_invalid_id'));
53 require_once('./includes/class_logging.php');
55 // ###################################################################
57 if ($_POST['do'] == 'insert')
59 $attachapi = new AttachmentAPI($bugsys);
60 $attachapi->set('bugid', $bugsys->in
['bugid']);
62 if (!can_perform('canputattach', $bug['productid']))
64 $message->error_permission();
68 $var = $db->query_first("SHOW VARIABLES LIKE 'max_allowed_packet'");
69 $bugsys->debug("max_allowed_packet = $var[Value]");
72 $FILE =& $_FILES['attachment'];
75 switch ($FILE['error'])
78 case 1: $message->add_error($lang->string('PHP said the file you uploaded was too big.')); break;
79 case 2: $message->add_error($lang->string('The file exceeds the allowed upload size.')); break;
80 case 3: $message->add_error($lang->string('The file was only partially uploaded.')); break;
81 case 4: $message->add_error($lang->string('The file was not uploaded at all.')); break;
82 case 6: $message->add_error($lang->string('PHP could not find the /tmp directory.')); break;
86 if (!is_uploaded_file($FILE['tmp_name']))
88 $message->add_error($lang->string('The file you specified did not upload.'));
91 // #*# put some MIME-type validation here
93 if (filesize($FILE['tmp_name']) > $var['Value'])
95 $message->add_error($lang->string('The file you specified exceeds MySQL\'s maximum allowed packet.'));
98 $attachapi->set('attachment', file_get_contents($FILE['tmp_name']));
99 $attachapi->set('filename', $FILE['name']);
100 $attachapi->set('mimetype', $FILE['type']);
101 $attachapi->set('filesize', $FILE['size']);
102 $attachapi->set('description', $bugsys->in
['description']);
103 $attachapi->set('userid', $bugsys->userinfo
['userid']);
105 // insert an attachment
106 if (!$message->items
)
108 $attachapi->insert();
111 $obsoletes = $bugsys->input_clean('obsoletes', TYPE_UINT
);
112 if (is_array($obsoletes) AND sizeof($obsoletes) > 0)
114 $db->query("UPDATE " . TABLE_PREFIX
. "attachment SET obsolete = 1 WHERE attachmentid IN (" . implode(',', $obsoletes) . ") AND !obsolete AND bugid = $bug[bugid]");
116 foreach ($obsoletes AS $attachmentid)
119 $log->set_bugid($bug['bugid']);
120 $log->set_attachmentid($attachmentid);
121 $log->add_data(true
, array('obsolete' => 0), array('obsolete'), false
, 'attachment');
122 $log->add_data(false
, array('obsolete' => 1), array('obsolete'), false
, 'attachment');
123 $log->update_history();
127 // handle comment stuff
128 if (can_perform('canpostcomments', $bug['productid']) AND trim($bugsys->in
['comment']))
130 $comment = new CommentAPI($bugsys);
131 $comment->set('bugid', $bugsys->in
['bugid']);
132 $comment->set('userid', $bugsys->userinfo
['userid']);
133 $comment->set('comment', $bugsys->in
['comment']);
134 $comment->set('dateline', $attachapi->values
['dateline']);
138 // update the last post data
139 $db->query("UPDATE " . TABLE_PREFIX
. "bug SET lastposttime = " . $attachapi->values
['dateline'] . ", hiddenlastposttime = " . $attachapi->values
['dateline'] . ", lastpostby = " . $bugsys->userinfo
['userid'] . ", hiddenlastpostby = " . $bugsys->userinfo
['userid'] . " WHERE bugid = $bug[bugid]");
141 $message->redirect($lang->string('The attachment has been added to the bug.'), "showreport.php?bugid=$bug[bugid]");
145 $show['errors'] = true
;
146 $_REQUEST['do'] = 'add';
147 $message->error_list_process();
151 // ###################################################################
153 if ($_REQUEST['do'] == 'add')
155 if (!can_perform('canputattach', $bug['productid']))
157 $message->error_permission();
160 $MAXFILESIZE = $funct->fetch_max_attachment_size();
162 $show['addcomment'] = ((can_perform('canpostcomments', $bug['productid'])) ? true
: false
);
163 $show['obsoletes'] = false
;
165 $obsoletes_fetch = $db->query("SELECT * FROM " . TABLE_PREFIX
. "attachment WHERE bugid = $bug[bugid] AND !obsolete");
167 while ($obsolete = $db->fetch_array($obsoletes_fetch))
169 $show['obsoletes'] = true
;
170 $obsoletes .= "<div><input name=\"obsoletes[]\" type=\"checkbox\" value=\"$obsolete[attachmentid]\"" . (in_array($obsolete['attachmentid'], (array)$bugsys->in
['obsoletes']) ?
' checked="checked"' : '') . " /> $obsolete[filename]" . ($obsolete['description'] ?
" [$obsolete[description]]" : '') . "</div>\n";
173 eval('$template->flush("' . $template->fetch('newattach') . '");');
176 // ###################################################################
178 if ($_POST['do'] == 'update')
180 if (!(can_perform('caneditattach', $bug['productid']) OR ($attachment['userid'] == $bugsys->userinfo
['userid'] AND can_perform('canputattach', $bug['productid']))))
182 $message->error_permission();
186 $log->set_bugid($bug['bugid']);
187 $log->set_attachmentid($bugsys->in
['attachmentid']);
189 $attachapi = new AttachmentAPI($bugsys);
190 $attachapi->set('attachmentid', $bugsys->in
['attachmentid']);
191 $attachapi->set_condition();
192 $attachapi->dorelations
= array();
195 $log->add_data(true
, $attachapi->objdata
, array('attachment'), true
, 'attachment');
197 $attachapi->set('description', $bugsys->in
['description']);
198 $attachapi->set('obsolete', $bugsys->in
['obsolete']);
199 $attachapi->update();
201 $log->add_data(false
, $attachapi->values
, array('attachment'), true
, 'attachment');
203 $log->update_history();
205 $message->redirect($lang->string('The attachment was successfully modified.'), "showreport.php?bugid=$bug[bugid]");
208 // ###################################################################
210 if ($_REQUEST['do'] == 'edit')
212 if (!(can_perform('caneditattach', $bug['productid']) OR ($attachment['userid'] == $bugsys->userinfo
['userid'] AND can_perform('canputattach', $bug['productid']))))
214 $message->error_permission();
217 $show['delete'] = ((can_perform('caneditattach', $bug['productid'])) ? true
: false
);
219 eval('$template->flush("' . $template->fetch('editattach') . '");');
222 /*=====================================================================*\
223 || ###################################################################
226 || ###################################################################
227 \*=====================================================================*/