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/api_attachment.php');
33 require_once('./includes/api_comment.php');
35 if (isset($bugsys->in
['attachmentid']))
37 $attachment = $db->query_first("SELECT * FROM " . TABLE_PREFIX
. "attachment WHERE attachmentid = " . intval($bugsys->in
['attachmentid']));
40 $message->error($lang->getlex('error_invalid_id'));
44 $bug = $db->query_first("SELECT * FROM " . TABLE_PREFIX
. "bug WHERE bugid = " . (($attachment['attachmentid']) ?
$attachment['bugid'] : intval($bugsys->in
['bugid'])));
47 $message->error($lang->getlex('error_invalid_id'));
50 require_once('./includes/class_logging.php');
52 // ###################################################################
54 if ($_POST['do'] == 'insert')
56 $attachapi = new AttachmentAPI($bugsys);
57 $attachapi->set('bugid', $bugsys->in
['bugid']);
59 if (!can_perform('canputattach', $bug['productid']))
61 $message->error_permission();
65 $var = $db->query_first("SHOW VARIABLES LIKE 'max_allowed_packet'");
66 $bugsys->debug("max_allowed_packet = $var[Value]");
69 $FILE =& $_FILES['attachment'];
72 switch ($FILE['error'])
75 case 1: $message->items
[] = $lang->string('PHP said the file you uploaded was too big.'); break;
76 case 2: $message->items
[] = $lang->string('The file exceeds the allowed upload size.'); break;
77 case 3: $message->items
[] = $lang->string('The file was only partially uploaded.'); break;
78 case 4: $message->items
[] = $lang->string('The file was not uploaded at all.'); break;
79 case 6: $message->items
[] = $lang->string('PHP could not find the /tmp directory.'); break;
83 if (!is_uploaded_file($FILE['tmp_name']))
85 $message->items
[] = $lang->string('The file you specified did not upload.');
88 // #*# put some MIME-type validation here
90 if (filesize($FILE['tmp_name']) > $var['Value'])
92 $message->items
[] = $lang->string('The file you specified exceeds MySQL\'s maximum allowed packet.');
95 $attachapi->set('attachment', file_get_contents($FILE['tmp_name']));
96 $attachapi->set('filename', $FILE['name']);
97 $attachapi->set('mimetype', $FILE['type']);
98 $attachapi->set('filesize', $FILE['size']);
99 $attachapi->set('description', $bugsys->in
['description']);
100 $attachapi->set('userid', $bugsys->userinfo
['userid']);
102 // insert an attachment
103 if (!$message->items
)
105 $attachapi->insert();
108 $obsoletes = $bugsys->input_clean('obsoletes', TYPE_UINT
);
109 if (count($obsoletes) > 0)
111 $db->query("UPDATE " . TABLE_PREFIX
. "attachment SET obsolete = 1 WHERE attachmentid IN (" . implode(',', $obsoletes) . ") AND !obsolete AND bugid = $bug[bugid]");
113 foreach ($obsoletes AS $attachmentid)
116 $log->set_bugid($bug['bugid']);
117 $log->set_attachmentid($attachmentid);
118 $log->add_data(true
, array('obsolete' => 0), array('obsolete'), false
, 'attachment');
119 $log->add_data(false
, array('obsolete' => 1), array('obsolete'), false
, 'attachment');
120 $log->update_history();
124 // handle comment stuff
125 if (can_perform('canpostcomments', $bug['productid']) AND trim($bugsys->in
['comment']))
127 $comment = new CommentAPI($bugsys);
128 $comment->set('bugid', $bugsys->in
['bugid']);
129 $comment->set('userid', $bugsys->userinfo
['userid']);
130 $comment->set('comment', $bugsys->in
['comment']);
131 $comment->set('dateline', $attachapi->values
['dateline']);
135 // update the last post data
136 $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]");
138 $message->redirect($lang->string('The attachment has been added to the bug.'), "showreport.php?bugid=$bug[bugid]");
142 $show['errors'] = true
;
143 $_REQUEST['do'] = 'add';
144 $message->error_list_process();
148 // ###################################################################
150 if ($_REQUEST['do'] == 'add')
152 if (!can_perform('canputattach', $bug['productid']))
154 $message->error_permission();
157 $MAXFILESIZE = $funct->fetch_max_attachment_size();
159 $show['addcomment'] = ((can_perform('canpostcomments', $bug['productid'])) ? true
: false
);
160 $show['obsoletes'] = false
;
162 $obsoletes_fetch = $db->query("SELECT * FROM " . TABLE_PREFIX
. "attachment WHERE bugid = $bug[bugid] AND !obsolete");
164 while ($obsolete = $db->fetch_array($obsoletes_fetch))
166 $show['obsoletes'] = true
;
167 $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";
170 eval('$template->flush("' . $template->fetch('newattach') . '");');
173 // ###################################################################
175 if ($_POST['do'] == 'update')
177 if (!(can_perform('caneditattach', $bug['productid']) OR ($attachment['userid'] == $bugsys->userinfo
['userid'] AND can_perform('canputattach', $bug['productid']))))
179 $message->error_permission();
183 $log->set_bugid($bug['bugid']);
184 $log->set_attachmentid($bugsys->in
['attachmentid']);
186 $attachapi = new AttachmentAPI($bugsys);
187 $attachapi->set('attachmentid', $bugsys->in
['attachmentid']);
188 $attachapi->set_condition();
189 $attachapi->dorelations
= array();
192 $log->add_data(true
, $attachapi->objdata
, array('attachment'), true
, 'attachment');
194 $attachapi->set('description', $bugsys->in
['description']);
195 $attachapi->set('obsolete', $bugsys->in
['obsolete']);
196 $attachapi->update();
198 $log->add_data(false
, $attachapi->values
, array('attachment'), true
, 'attachment');
200 $log->update_history();
202 $message->redirect($lang->string('The attachment was successfully modified.'), "showreport.php?bugid=$bug[bugid]");
205 // ###################################################################
207 if ($_REQUEST['do'] == 'edit')
209 if (!(can_perform('caneditattach', $bug['productid']) OR ($attachment['userid'] == $bugsys->userinfo
['userid'] AND can_perform('canputattach', $bug['productid']))))
211 $message->error_permission();
214 $show['delete'] = ((can_perform('caneditattach', $bug['productid'])) ? true
: false
);
216 eval('$template->flush("' . $template->fetch('editattach') . '");');
219 /*=====================================================================*\
220 || ###################################################################
223 || ###################################################################
224 \*=====================================================================*/