3 * Project Admin: Edit Multimedia Data
5 * Portions Copyright 1999-2001 (c) VA Linux Systems
6 * The rest Copyright 2002-2004 (c) GForge Team
11 * This file is part of GForge.
13 * GForge is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * GForge is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with GForge; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
32 require_once('../../env.inc.php');
33 require_once('pre.php');
34 require_once('www/project/admin/project_admin_utils.php');
36 if (!$sys_use_project_multimedia) {
40 $group_id = getIntFromRequest('group_id');
41 session_require(array('group'=>$group_id,'admin_flags'=>'A'));
43 function check_file_size($size) {
47 if (($size > 20) && ($size < 256000)) {
51 $feedback .= _('ERROR - file must be > 20 bytes and < 256000 bytes in length').' <br />';
56 function store_file($id, $input_file) {
62 if (!util_check_fileupload($input_file)) {
63 exit_error("Error","Invalid filename");
66 $filename = $input_file['tmp_name'];
67 $size = $input_file['size'];
68 $dimensions = @getimagesize($filename);
69 $data = addslashes(base64_encode(fread( fopen($filename, 'rb'), $size)));
70 $width=$dimensions[0];
71 $height=$dimensions[1];
73 if (check_file_size($size)) {
76 $width = ((!$width) ? "0" : $width);
77 $height = ((!$height) ? "0" : $height);
79 $sql=" INSERT INTO db_images
80 (group_id,description,bin_data,
81 filename,filesize,filetype,
82 width,height,upload_date,version)
84 ('$group_id','$description',
85 '$data','".$input_file['name']."',
86 '$size','".$input_file['type']."',
87 '$width','$height','$curtime',1)";
89 $sql=" UPDATE db_images
90 SET description='$description',
92 filename='".$input_file['name']."',
94 filetype='".$input_file['type']."',
97 upload_date='$curtime',
99 WHERE group_id='$group_id'
103 $res = db_query($sql);
105 if (!$res || db_affected_rows($res) < 1) {
106 $feedback .= 'ERROR: DB: Cannot store multimedia file<br />';
109 $feedback .= _('Multimedia File Uploaded');
114 if (getStringFromRequest('submit')) {
115 $input_file = getUploadedFile('input_file');
116 $id = getIntFromRequest('id');
117 $description = getStringFromRequest('description');
118 $filetype = getStringFromRequest('filetype');
120 if (!util_check_fileupload($input_file)) {
121 exit_error("Error","Invalid filename");
124 if (getStringFromRequest('add')) {
125 if (!$input_file['tmp_name'] || $description == "") {
126 $feedback .= _('Both file name and description are required');
128 //see if they have too many data in the system
129 $res=db_query("SELECT sum(filesize) WHERE group_id='$group_id'");
130 if (db_result($res,0,'sum') < $QUOTA) {
131 store_file(0, $input_file);
133 $feedback .= ' Sorry - you are over your '.$QUOTA.' quota ';
137 } else if (getStringFromRequest('remove')) {
139 $res=db_query("DELETE FROM db_images WHERE id='$id' AND group_id='$group_id'");
141 if (!$res || db_affected_rows($res) < 1) {
142 $feedback .= 'ERROR: DB: Cannot delete multimedia file<br />';
145 $feedback .= _('Multimedia File Deleted');
148 } else if (getStringFromRequest("edit")) {
149 if ($description == "") {
150 $feedback .= _('File description is required').'<b />';
152 if (!$input_file['tmp_name']) {
154 // Just replace description/mime type
156 $res = db_query("UPDATE db_images
157 SET description='$description',
159 WHERE group_id='$group_id'
162 if (!$res || db_affected_rows($res) < 1) {
163 $feedback .= 'ERROR: DB: Cannot update multimedia file<br />';
166 $feedback .= _('Multimedia File Properties Updated').'<br />';
171 // new version of the file is uploaded
172 // use new description, but not user-input
175 //see if they have too many data in the system
176 $res=db_query(" SELECT sum(filesize)
177 WHERE group_id='$group_id'
180 $size = $input_file['size'];
181 if (db_result($res,0,'sum')+$size < $QUOTA) {
183 store_file($id, $input_file);
187 $feedback .= ' Sorry - you are over your 1MB quota ';
196 project_admin_header(array('title'=>_('Edit Multimedia Data')));
199 <p>'.sprintf(_('You can store up to %1$s MB of multimedia data (bitmap and vector graphics, sound clips, 3D models) in the database. Use this page to add/delete your project multimedia data.'), sprintf("%.2f", $QUOTA/(1024*1024))).'</p>
203 $mode = getStringFromGet("mode");
204 if ($mode == "edit") {
205 $result=db_query(" SELECT *
207 WHERE group_id='$group_id'
210 if (!$result || db_numrows($result)!=1) {
211 $feedback .= "Cannot edit multimedia file<br />";
212 project_admin_footer(array());
216 echo '</p><h4>'._('Edit Multimedia Data').'</h4>
218 <form action="'. getStringFromServer('PHP_SELF') .'" method="post" enctype="multipart/form-data">
219 <input type="hidden" name="group_id" value="'.$group_id.'" />
220 <input type="hidden" name="id" value="'.$id.'" />
222 <strong>'._('Replace with new file (optional)').':</strong><br />
223 <input type="file" name="input_file" size="30" />
226 <strong>'._('Description').':</strong><br />
227 <input type="text" name="description" size="40" maxlength="255" value="'.db_result($result,$i,'description').'" />
230 <strong>'._('MIME Type').':</strong><br />
231 <input type="text" name="filetype" size="40" maxlength="255" value="'.db_result($result,$i,'filetype').'" />
233 <input type="hidden" name="edit" value="1" />
235 <input type="submit" value="'._('Submit').'" name="submit" />
236 <input type="reset" value="'._('Reset').'" /><br />
240 $result=db_query(" SELECT *
242 WHERE group_id='$group_id'
245 echo '<h4>'._('Add Multimedia Data').'</h4>
247 <form action="'. getStringFromServer('PHP_SELF') .'" method="post" enctype="multipart/form-data">
248 <input type="hidden" name="group_id" value="'.$group_id.'" />
249 <strong>'._('Local filename').':</strong>'.utils_requiredField().'<br />
250 <input type="file" name="input_file" size="30" />
252 <strong>'._('Description').':</strong>'.utils_requiredField().'<br />
253 <input type="text" name="description" size="40" maxlength="255" /></p><p>
254 <input type="hidden" name="add" value="1" />
255 <input type="submit" value="'._('Add File').'" name="submit" /><br /></p>
263 $arr[]=_('Uploaded');
265 $arr[]=_('MIME Type');
268 $arr[]=_('Description');
270 echo $GLOBALS['HTML']->listTableTop($arr);
272 $rows=db_numrows($result);
273 for ($i=0; $i<$rows; $i++) {
275 // Show dimensions only for images
276 $w = db_result($result,$i,'width');
277 $h = db_result($result,$i,'height');
279 $dims = '('.$w.'x'.$h.')';
285 <tr '. $GLOBALS['HTML']->boxGetAltRowStyle($i) .'>'
286 .'<td align="center">'
287 .'<a href="'. getStringFromServer('PHP_SELF') .'?submit=1&group_id='.$group_id.'&remove=1&id='
288 .db_result($result,$i,'id').'">'
289 .'['._('Del').']'.'</a>'
290 .'<a href="'. getStringFromServer('PHP_SELF') .'?submit=1&group_id='.$group_id.'&mode=edit&id='
291 .db_result($result,$i,'id').'"> '
292 .'['._('Edit').']'.'</a>'
295 .'<td>'.db_result($result,$i,'id').'</td>'
297 .'<td>'.date('Y-m-d', db_result($result, $i, 'upload_date')).'</td>'
299 .'<td><a href="'.$GLOBALS['sys_urlprefix'].'/dbimage.php?id='.db_result($result,$i,'id').'">'
300 .stripslashes(db_result($result,$i,'filename')).'</a></td>'
301 .'<td>'.db_result($result,$i,'filetype').'</td>'
302 .'<td align="right">'.db_result($result,$i,'filesize').'</td>'
303 .'<td align="right">'.$dims.'</td>'
304 .'<td>'.stripslashes(db_result($result,$i,'description')).'</td>'
308 echo $GLOBALS['HTML']->listTableBottom();
310 project_admin_footer(array());