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
');
33 if (isset($bugsys->in['attachmentid
']))
35 $attachment = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "attachment WHERE attachmentid = " . intval($bugsys->in['attachmentid
']));
38 $message->error($lang->getlex('error_invalid_id
'));
42 $bug = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "bug WHERE bugid = " . (($attachment['attachmentid
']) ? $attachment['bugid
'] : intval($bugsys->in['bugid
'])));
45 $message->error($lang->getlex('error_invalid_id
'));
49 require_once('./includes
/class_history
.php
');
51 $log->bugid = $bug['bugid
'];
53 // ###################################################################
55 if ($_POST['do'] == 'insert
')
57 if (!can_perform('canputattach
', $bug['productid
']))
59 $message->error_permission();
63 $var = $db->query_first("SHOW VARIABLES LIKE 'max_allowed_packet
'");
64 $bugsys->debug("max_allowed_packet = $var[Value]");
67 $FILE =& $_FILES['attachment
'];
70 switch ($FILE['error
'])
73 case 1: $message->items[] = $lang->string('PHP said the file you uploaded was too big
.'); break;
74 case 2: $message->items[] = $lang->string('The file exceeds the allowed upload size
.'); break;
75 case 3: $message->items[] = $lang->string('The file was only partially uploaded
.'); break;
76 case 4: $message->items[] = $lang->string('The file was not uploaded at all
.'); break;
77 case 6: $message->items[] = $lang->string('PHP could not find the
/tmp directory
.'); break;
81 if (!is_uploaded_file($FILE['tmp_name
']))
83 $message->items[] = $lang->string('The file you specified did not upload
.');
86 // #*# put some MIME-type validation here
88 if (filesize($FILE['tmp_name
']) > $var['Value
'])
90 $message->items[] = $lang->string('The file you specified exceeds MySQL\'s maximum allowed packet
.');
93 // insert an attachment
96 $filedata = $bugsys->escape(file_get_contents($FILE['tmp_name
']), true, true);
100 INSERT INTO " . TABLE_PREFIX . "attachment
101 (bugid, filename, mimetype, filesize,
102 attachment, description, dateline, userid)
104 ($bug[bugid], '" . $bugsys->escape($FILE['name']) . "',
105 '" . $bugsys->escape($FILE['type']) . "', " . intval($FILE['size
']) . ",
106 '$filedata', '" . $bugsys->in['description
'] . "', $time,
107 " . $bugsys->userinfo['userid'] . "
112 $obsoletes = $_POST['obsoletes'];
113 if (count($obsoletes) > 0)
115 array_walk($obsoletes, 'intval');
116 $db->query("UPDATE
" . TABLE_PREFIX . "attachment SET obsolete
= 1 WHERE attachmentid
IN (" . implode(',', $obsoletes) . ") AND !obsolete
AND bugid
= $bug[bugid
]");
118 foreach ($obsoletes AS $attachmentid)
120 $log->attachmentid = $attachmentid;
121 $log->log($log->diff('obsolete', 0, 1));
125 // handle comment stuff
126 if (can_perform('canpostcomments', $bug['productid']) AND trim($bugsys->in['comment']))
128 $bugsys->in['comment_parsed'] = $bugsys->in['comment'];
130 if (!$bugsys->options['allowhtml'])
132 $bugsys->in['comment_parsed'] = $bugsys->sanitize($bugsys->in['comment_parsed']);
136 INSERT INTO
" . TABLE_PREFIX . "comment
137 (bugid
, userid
, dateline
, comment
, comment_parsed
)
139 ($bug[bugid
], " . $bugsys->userinfo['userid'] . ",
140 $time, '" . $bugsys->in['comment
'] . "',
141 '" . nl2br($bugsys->in['comment_parsed
']) . "'
146 // update the last post data
147 $db->query("UPDATE
" . TABLE_PREFIX . "bug SET lastposttime
= $time, lastpostby
= " . $bugsys->userinfo['userid'] . " WHERE bugid
= $bug[bugid
]");
149 $message->redirect($lang->string('The attachment has been added to the bug.'), "showreport
.php
?bugid
=$bug[bugid
]");
153 $show['errors'] = true;
154 $_REQUEST['do'] = 'add';
155 $message->error_list_process();
159 // ###################################################################
161 if ($_REQUEST['do'] == 'add')
163 if (!can_perform('canputattach', $bug['productid']))
165 $message->error_permission();
168 $MAXFILESIZE = $funct->fetch_max_attachment_size();
170 $show['addcomment'] = ((can_perform('canpostcomments', $bug['productid'])) ? true : false);
171 $show['obsoletes'] = false;
173 $obsoletes_fetch = $db->query("SELECT
* FROM
" . TABLE_PREFIX . "attachment WHERE bugid
= $bug[bugid
] AND !obsolete
");
175 while ($obsolete = $db->fetch_array($obsoletes_fetch))
177 $show['obsoletes'] = true;
178 $obsoletes .= "<div
><input name
=\"obsoletes
[]\" type
=\"checkbox\" value
=\"$obsolete[attachmentid
]\"" . (in_array($obsolete['attachmentid'], $bugsys->in['obsoletes']) ? ' checked="checked
"' : '') . " /> $obsolete[filename
]" . ($obsolete['description'] ? " [$obsolete[description
]]" : '') . "</div
>\n";
181 eval('$template->flush("' . $template->fetch('newattach
') . '");');
184 // ###################################################################
186 if ($_POST['do'] == 'update')
188 if (!(can_perform('caneditattach', $bug['productid']) OR ($attachment['userid'] == $bugsys->userinfo['userid'] AND can_perform('canputattach', $bug['productid']))))
190 $message->error_permission();
194 UPDATE
" . TABLE_PREFIX . "attachment
195 SET description
= '" . $bugsys->in['description
'] . "',
196 obsolete
= " . intval($bugsys->in['obsolete']) . "
197 WHERE attachmentid
= " . intval($bugsys->in['attachmentid'])
200 $hist[1] = $db->query_first("SELECT
* FROM
" . TABLE_PREFIX . "attachment WHERE attachmentid
= $attachment[attachmentid
]");
202 $diff[0] = array_diff_assoc($attachment, $hist[1]);
203 $diff[1] = array_diff_assoc($hist[1], $attachment);
205 $log->attachmentid = $attachment['attachmentid'];
206 $log->log($log->diff('description', $diff[0]['description'], $diff[1]['description']));
207 $log->log($log->diff('obsolete', $diff[0]['obsolete'], $diff[1]['obsolete']));
209 $message->redirect($lang->string('The attachment was successfully modified.'), "showreport
.php
?bugid
=$bug[bugid
]");
212 // ###################################################################
214 if ($_REQUEST['do'] == 'edit')
216 if (!(can_perform('caneditattach', $bug['productid']) OR ($attachment['userid'] == $bugsys->userinfo['userid'] AND can_perform('canputattach', $bug['productid']))))
218 $message->error_permission();
221 $show['delete'] = ((can_perform('caneditattach', $bug['productid'])) ? true : false);
223 eval('$template->flush("' . $template->fetch('editattach
') . '");');
226 /*=====================================================================*\
227 || ###################################################################
230 || ###################################################################
231 \*=====================================================================*/