2 /*=====================================================================*\
3 || ################################################################### ||
4 || # Bugdar [#]version[#]
5 || # --------------------------------------------------------------- # ||
6 || # Copyright ©2002-[#]year[#] by Iris Studios, Inc. All Rights Reserved. # ||
7 || # This file may not be reproduced in any way without permission. # ||
8 || # --------------------------------------------------------------- # ||
9 || # User License Agreement at http://www.iris-studios.com/license/ # ||
10 || ################################################################### ||
11 \*=====================================================================*/
13 $fetchtemplates = array(
18 define('SVN', '$Id$');
20 $focus['showreport
'] = 'focus
';
22 require_once('./global.php
');
24 if (isset($bugsys->in['attachmentid
']))
26 $attachment = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "attachment WHERE attachmentid = " . intval($bugsys->in['attachmentid
']));
29 $message->error($lang->getlex('error_invalid_id
'));
33 $bug = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "bug WHERE bugid = " . (($attachment['attachmentid
']) ? $attachment['bugid
'] : intval($bugsys->in['bugid
'])));
36 $message->error($lang->getlex('error_invalid_id
'));
40 require_once('./includes
/class_history
.php
');
42 $log->bugid = $bug['bugid
'];
44 // ###################################################################
46 if ($_POST['do'] == 'insert
')
48 if (!can_perform('canputattach
', $bug['productid
']))
50 $message->error_permission();
54 $var = $db->query_first("SHOW VARIABLES LIKE 'max_allowed_packet
'");
55 $bugsys->debug("max_allowed_packet = $var[Value]");
58 $FILE =& $_FILES['attachment
'];
61 switch ($FILE['error
'])
64 case 1: $message->items[] = $lang->string('PHP said the file you uploaded was too big
.'); break;
65 case 2: $message->items[] = $lang->string('The file exceeds the allowed upload size
.'); break;
66 case 3: $message->items[] = $lang->string('The file was only partially uploaded
.'); break;
67 case 4: $message->items[] = $lang->string('The file was not uploaded at all
.'); break;
68 case 6: $message->items[] = $lang->string('PHP could not find the
/tmp directory
.'); break;
72 if (!is_uploaded_file($FILE['tmp_name
']))
74 $message->items[] = $lang->string('The file you specified did not upload
.');
77 // #*# put some MIME-type validation here
79 if (filesize($FILE['tmp_name
']) > $var['Value
'])
81 $message->items[] = $lang->string('The file you specified exceeds MySQL\'s maximum allowed packet
.');
84 // insert an attachment
87 $filedata = $bugsys->escape(file_get_contents($FILE['tmp_name
']), true, true);
91 INSERT INTO " . TABLE_PREFIX . "attachment
92 (bugid, filename, mimetype, filesize,
93 attachment, description, dateline, userid)
95 ($bug[bugid], '" . $bugsys->escape($FILE['name']) . "',
96 '" . $bugsys->escape($FILE['type']) . "', " . intval($FILE['size
']) . ",
97 '$filedata', '" . $bugsys->in['description
'] . "', $time,
98 " . $bugsys->userinfo['userid'] . "
103 $obsoletes = $_POST['obsoletes'];
104 if (count($obsoletes) > 0)
106 array_walk($obsoletes, 'intval');
107 $db->query("UPDATE
" . TABLE_PREFIX . "attachment SET obsolete
= 1 WHERE attachmentid
IN (" . implode(',', $obsoletes) . ") AND !obsolete
AND bugid
= $bug[bugid
]");
109 foreach ($obsoletes AS $attachmentid)
111 $log->attachmentid = $attachmentid;
112 $log->log($log->diff('obsolete', 0, 1));
116 // handle comment stuff
117 if (can_perform('canpostcomments', $bug['productid']) AND trim($bugsys->in['comment']))
119 $bugsys->in['comment_parsed'] = $bugsys->in['comment'];
121 if (!$bugsys->options['allowhtml'])
123 $bugsys->in['comment_parsed'] = $bugsys->sanitize($bugsys->in['comment_parsed']);
127 INSERT INTO
" . TABLE_PREFIX . "comment
128 (bugid
, userid
, dateline
, comment
, comment_parsed
)
130 ($bug[bugid
], " . $bugsys->userinfo['userid'] . ",
131 $time, '" . $bugsys->in['comment
'] . "',
132 '" . nl2br($bugsys->in['comment_parsed
']) . "'
137 // update the last post data
138 $db->query("UPDATE
" . TABLE_PREFIX . "bug SET lastposttime
= $time, lastpostby
= " . $bugsys->userinfo['userid'] . " WHERE bugid
= $bug[bugid
]");
140 $message->redirect($lang->string('The attachment has been added to the bug.'), "showreport
.php
?bugid
=$bug[bugid
]");
144 $show['errors'] = true;
145 $_REQUEST['do'] = 'add';
146 $message->error_list_process();
150 // ###################################################################
152 if ($_REQUEST['do'] == 'add')
154 if (!can_perform('canputattach', $bug['productid']))
156 $message->error_permission();
159 $MAXFILESIZE = $funct->fetch_max_attachment_size();
161 $show['addcomment'] = ((can_perform('canpostcomments', $bug['productid'])) ? true : false);
162 $show['obsoletes'] = false;
164 $obsoletes_fetch = $db->query("SELECT
* FROM
" . TABLE_PREFIX . "attachment WHERE bugid
= $bug[bugid
] AND !obsolete
");
166 while ($obsolete = $db->fetch_array($obsoletes_fetch))
168 $show['obsoletes'] = true;
169 $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";
172 eval('$template->flush("' . $template->fetch('newattach
') . '");');
175 // ###################################################################
177 if ($_POST['do'] == 'update')
179 if (!(can_perform('caneditattach', $bug['productid']) OR ($attachment['userid'] == $bugsys->userinfo['userid'] AND can_perform('canputattach', $bug['productid']))))
181 $message->error_permission();
185 UPDATE
" . TABLE_PREFIX . "attachment
186 SET description
= '" . $bugsys->in['description
'] . "',
187 obsolete
= " . intval($bugsys->in['obsolete']) . "
188 WHERE attachmentid
= " . intval($bugsys->in['attachmentid'])
191 $hist[1] = $db->query_first("SELECT
* FROM
" . TABLE_PREFIX . "attachment WHERE attachmentid
= $attachment[attachmentid
]");
193 $diff[0] = array_diff_assoc($attachment, $hist[1]);
194 $diff[1] = array_diff_assoc($hist[1], $attachment);
196 $log->attachmentid = $attachment['attachmentid'];
197 $log->log($log->diff('description', $diff[0]['description'], $diff[1]['description']));
198 $log->log($log->diff('obsolete', $diff[0]['obsolete'], $diff[1]['obsolete']));
200 $message->redirect($lang->string('The attachment was successfully modified.'), "showreport
.php
?bugid
=$bug[bugid
]");
203 // ###################################################################
205 if ($_REQUEST['do'] == 'edit')
207 if (!(can_perform('caneditattach', $bug['productid']) OR ($attachment['userid'] == $bugsys->userinfo['userid'] AND can_perform('canputattach', $bug['productid']))))
209 $message->error_permission();
212 $show['delete'] = ((can_perform('caneditattach', $bug['productid'])) ? true : false);
214 eval('$template->flush("' . $template->fetch('editattach
') . '");');
217 /*=====================================================================*\
218 || ###################################################################
221 || ###################################################################
222 \*=====================================================================*/