]>
src.bluestatic.org Git - bugdar.git/blob - attachment.php
2 /*=====================================================================*\
3 || ################################################################### ||
4 || # BugStrike [#]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 (
20 require_once ( './global.php' );
22 if ( isset ( $bugsys- > in
[ 'attachmentid' ]))
24 $attachment = $db- > query_first ( "SELECT * FROM " . TABLE_PREFIX
. "attachment WHERE attachmentid = " . intval ( $bugsys- > in
[ 'attachmentid' ]));
27 echo 'alert: bad attachment' ;
32 // ###################################################################
34 if ( empty ( $_REQUEST [ 'do' ]))
36 $_REQUEST [ 'do' ] = 'modify' ;
40 $bug = $db- > query_first ( "SELECT * FROM " . TABLE_PREFIX
. "bug WHERE bugid = " . intval ( $bugsys- > in
[ 'bugid' ]));
43 echo 'alert: bad bug' ;
48 // ###################################################################
50 if ( $_REQUEST [ 'do' ] == 'kill' )
52 // run code to remove item in database
55 // ###################################################################
57 if ( $_REQUEST [ 'do' ] == 'delete' )
59 // display delete confirmation message
62 // ###################################################################
64 if ( $_POST [ 'do' ] == 'insert' )
66 if (! can_perform ( 'canputattach' ))
68 echo 'alert: no permission' ;
73 $FILE =& $_FILES [ 'attachment' ];
76 switch ( $FILE [ 'error' ])
79 case 1 : echo 'PHP said the file you uploaded was too big.' ; exit ; break ;
80 case 2 : echo 'The file exceeds the allowed upload size.' ; exit ; break ;
81 case 3 : echo 'The file was only partially uploaded.' ; exit ; break ;
82 case 4 : echo 'The file was not uploaded at all.' ; exit ; break ;
83 case 6 : echo 'PHP could not find the /tmp directory.' ; exit ; break ;
87 if (! is_uploaded_file ( $FILE [ 'tmp_name' ]))
89 echo 'The file you specified did not upload.' ;
93 // put some MIME-type validation here
95 if (! $bugsys- > in
[ 'description' ])
97 echo 'you need a file description!' ;
101 $filedata = $bugsys- > escape ( file_get_contents ( $FILE [ 'tmp_name' ]), true , true );
104 // insert an attachment
106 INSERT INTO attachment
107 (bugid, filename, mimetype, filesize,
108 attachment, description, dateline, userid)
110 ( $bug [bugid], '" . $bugsys- > escape ( $FILE [ 'name' ]) . "',
111 '" . $bugsys- > escape ( $FILE [ 'type' ]) . "', " . intval ( $FILE [ 'size' ]) . ",
112 ' $filedata' , '" . $bugsys- > in
[ 'description' ] . "', $time ,
113 " . $bugsys- > userinfo
[ 'userid' ] . "
118 $obsoletes = $_POST [ 'obsoletes' ];
119 array_walk ( $obsoletes , 'intval' );
120 $db- > query ( "UPDATE " . TABLE_PREFIX
. "attachment SET obsolete = 1 WHERE attachmentid IN (" . implode ( ',' , $obsoletes ) . ") AND !obsolete AND bugid = $bug [bugid]" );
122 // handle comment stuff
123 if ( can_perform ( 'canpostcomments' ) AND trim ( $bugsys- > in
[ 'comment' ]))
125 $bugsys- > in
[ 'comment_parsed' ] = $bugsys- > in
[ 'comment' ];
127 if (! $bugsys- > options
[ 'allowhtml' ])
129 $bugsys- > in
[ 'comment_parsed' ] = $bugsys- > sanitize ( $bugsys- > in
[ 'comment_parsed' ]);
133 INSERT INTO " . TABLE_PREFIX
. "comment
134 (bugid, userid, dateline, comment, comment_parsed)
136 ( $bug [bugid], " . $bugsys- > userinfo
[ 'userid' ] . ",
137 $time , '" . $bugsys- > in
[ 'comment' ] . "',
138 '" . nl2br ( $bugsys- > in
[ 'comment_parsed' ]) . "'
143 // update the last post data
144 $db- > query ( "UPDATE " . TABLE_PREFIX
. "bug SET lastposttime = $time , lastpostby = " . $bugsys- > userinfo
[ 'userid' ] . " WHERE bugid = $bug [bugid]" );
146 echo "<a href= \" showreport.php?bugid= $bug [bugid] \" >attachment added</a>" ;
150 // ###################################################################
152 if ( $_REQUEST [ 'do' ] == 'add' )
154 if (! can_perform ( 'canputattach' ))
156 echo 'alert: no permission' ;
160 $MAXFILESIZE = $funct- > fetch_max_attachment_size ();
162 $show [ 'addcomment' ] = (( can_perform ( 'canpostcomments' )) ? 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] \" /> $obsolete [filename] [ $obsolete [description]]</div> \n " ;
173 eval ( ' $template- >flush("' . $template- > fetch ( 'newattach' ) . '");' );
176 // ###################################################################
178 if ( $_POST [ 'do' ] == 'update' )
180 // run code to update item in database
183 // ###################################################################
185 if ( $_REQUEST [ 'do' ] == 'edit' )
187 // display form to edit item
190 // ###################################################################
192 if ( $_REQUEST [ 'do' ] == 'modify' )
194 if (! can_perform ( 'cangetattach' ))
196 echo 'alert: no permission' ;
203 if ( $funct- > fetch_extension ( $attachment [ 'filename' ]) != 'txt' )
205 header ( "Content-Disposition: inline; filename= $attachment [filename]" );
206 header ( "Content-transfer-encoding: binary" );
210 header ( "Content-Disposition: attachment; filename= $attachment [filename]" );
212 header ( "Content-Length: " . strlen ( $attachment [ 'attachment' ]));
213 header ( "Content-Type: $attachment [mimetype]" );
215 print ( $attachment [ 'attachment' ]);
218 /*=====================================================================*\
219 || ###################################################################
222 || ###################################################################
223 \*=====================================================================*/