3 * Project Admin: Edit Multimedia Data
5 * Portions Copyright 1999-2001 (c) VA Linux Systems
6 * The rest Copyright 2002-2004 (c) GForge Team
9 * This file is part of GForge.
11 * GForge is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * GForge is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with GForge; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 require_once('../../env.inc.php');
31 require_once $gfwww.'include/pre.php';
32 require_once $gfwww.'project/admin/project_admin_utils.php';
34 if (!forge_get_config('use_project_multimedia')) {
38 $group_id = getIntFromRequest('group_id');
39 session_require(array('group'=>$group_id,'admin_flags'=>'A'));
41 function check_file_size($size) {
44 if (($size > 20) && ($size < 256000)) {
48 $feedback .= _('ERROR - file must be > 20 bytes and < 256000 bytes in length').' <br />';
53 function store_file($id, $input_file) {
58 if (!util_check_fileupload($input_file)) {
59 exit_error("Error","Invalid filename");
62 $filename = $input_file['tmp_name'];
63 $size = $input_file['size'];
64 $dimensions = @getimagesize($filename);
65 $data = addslashes(base64_encode(fread( fopen($filename, 'rb'), $size)));
66 $width=$dimensions[0];
67 $height=$dimensions[1];
69 if (check_file_size($size)) {
71 $width = ((!$width) ? "0" : $width);
72 $height = ((!$height) ? "0" : $height);
74 $res = db_query_params("INSERT INTO db_images
75 (group_id,description,bin_data,
76 filename, filesize, filetype,
77 width,height,upload_date,version)
79 ($1, $2, $3, $4, $5, $6, $7, $8, $9, 1)",
80 array($group_id, $description, $data, $input_file['name'],
81 $size, $input_file['type'], $width, $height, $curtime));
83 $res = db_query_params("UPDATE db_images
95 array($description, $data, $input_file['name'], $size,
96 $input_file['type'], $width, $height, $curtime, $group_id, $id));
100 if (!$res || db_affected_rows($res) < 1) {
101 $feedback .= 'ERROR: DB: Cannot store multimedia file<br />';
104 $feedback .= _('Multimedia File Uploaded');
109 if (getStringFromRequest('submit')) {
110 $input_file = getUploadedFile('input_file');
111 $id = getIntFromRequest('id');
112 $description = getStringFromRequest('description');
113 $filetype = getStringFromRequest('filetype');
115 if (!util_check_fileupload($input_file)) {
116 exit_error("Error","Invalid filename");
119 if (getStringFromRequest('add')) {
120 if (!$input_file['tmp_name'] || $description == "") {
121 $feedback .= _('Both file name and description are required');
123 //see if they have too many data in the system
124 $res=db_query_params ('SELECT sum(filesize) WHERE group_id=$1',
126 if (db_result($res,0,'sum') < $QUOTA) {
127 store_file(0, $input_file);
129 $feedback .= ' Sorry - you are over your '.$QUOTA.' quota ';
133 } else if (getStringFromRequest('remove')) {
135 $res=db_query_params ('DELETE FROM db_images WHERE id=$1 AND group_id=$2',
139 if (!$res || db_affected_rows($res) < 1) {
140 $feedback .= 'ERROR: DB: Cannot delete multimedia file<br />';
143 $feedback .= _('Multimedia File Deleted');
146 } else if (getStringFromRequest("edit")) {
147 if ($description == "") {
148 $feedback .= _('File description is required').'<b />';
150 if (!$input_file['tmp_name']) {
152 // Just replace description/mime type
154 $res = db_query_params ('UPDATE db_images
164 if (!$res || db_affected_rows($res) < 1) {
165 $feedback .= 'ERROR: DB: Cannot update multimedia file<br />';
168 $feedback .= _('Multimedia File Properties Updated').'<br />';
173 // new version of the file is uploaded
174 // use new description, but not user-input
177 //see if they have too many data in the system
178 $res=db_query_params (' SELECT sum(filesize)
184 $size = $input_file['size'];
185 if (db_result($res,0,'sum')+$size < $QUOTA) {
187 store_file($id, $input_file);
191 $feedback .= ' Sorry - you are over your 1MB quota ';
200 project_admin_header(array('title'=>_('Edit Multimedia Data')));
203 <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>
207 $mode = getStringFromGet("mode");
208 if ($mode == "edit") {
209 $result=db_query_params (' SELECT *
216 if (!$result || db_numrows($result)!=1) {
217 $feedback .= "Cannot edit multimedia file<br />";
218 project_admin_footer(array());
222 echo '</p><h4>'._('Edit Multimedia Data').'</h4>
224 <form action="'. getStringFromServer('PHP_SELF') .'" method="post" enctype="multipart/form-data">
225 <input type="hidden" name="group_id" value="'.$group_id.'" />
226 <input type="hidden" name="id" value="'.$id.'" />
228 <strong>'._('Replace with new file (optional)').':</strong><br />
229 <input type="file" name="input_file" size="30" />
232 <strong>'._('Description').':</strong><br />
233 <input type="text" name="description" size="40" maxlength="255" value="'.db_result($result,$i,'description').'" />
236 <strong>'._('MIME Type').':</strong><br />
237 <input type="text" name="filetype" size="40" maxlength="255" value="'.db_result($result,$i,'filetype').'" />
239 <input type="hidden" name="edit" value="1" />
241 <input type="submit" value="'._('Submit').'" name="submit" />
242 <input type="reset" value="'._('Reset').'" /><br />
246 $result=db_query_params (' SELECT *
252 echo '<h4>'._('Add Multimedia Data').'</h4>
254 <form action="'. getStringFromServer('PHP_SELF') .'" method="post" enctype="multipart/form-data">
255 <input type="hidden" name="group_id" value="'.$group_id.'" />
256 <strong>'._('Local filename').':</strong>'.utils_requiredField().'<br />
257 <input type="file" name="input_file" size="30" />
259 <strong>'._('Description').':</strong>'.utils_requiredField().'<br />
260 <input type="text" name="description" size="40" maxlength="255" /></p><p>
261 <input type="hidden" name="add" value="1" />
262 <input type="submit" value="'._('Add File').'" name="submit" /><br /></p>
270 $arr[]=_('Uploaded');
272 $arr[]=_('MIME Type');
275 $arr[]=_('Description');
277 echo $GLOBALS['HTML']->listTableTop($arr);
279 $rows=db_numrows($result);
280 for ($i=0; $i<$rows; $i++) {
282 // Show dimensions only for images
283 $w = db_result($result,$i,'width');
284 $h = db_result($result,$i,'height');
286 $dims = '('.$w.'x'.$h.')';
292 <tr '. $GLOBALS['HTML']->boxGetAltRowStyle($i) .'>'
293 .'<td style="text-align:center">'
294 .'<a href="'. getStringFromServer('PHP_SELF') .'?submit=1&group_id='.$group_id.'&remove=1&id='
295 .db_result($result,$i,'id').'">'
296 .'['._('Del').']'.'</a>'
297 .'<a href="'. getStringFromServer('PHP_SELF') .'?submit=1&group_id='.$group_id.'&mode=edit&id='
298 .db_result($result,$i,'id').'"> '
299 .'['._('Edit').']'.'</a>'
302 .'<td>'.db_result($result,$i,'id').'</td>'
304 .'<td>'.date('Y-m-d', db_result($result, $i, 'upload_date')).'</td>'
306 .'<td>'.util_make_link ('/dbimage.php?id='.db_result($result,$i,'id'), stripslashes(db_result($result,$i,'filename'))).'</td>'
307 .'<td>'.db_result($result,$i,'filetype').'</td>'
308 .'<td style="text-align:right">'.db_result($result,$i,'filesize').'</td>'
309 .'<td style="text-align:right">'.$dims.'</td>'
310 .'<td>'.stripslashes(db_result($result,$i,'description')).'</td>'
314 echo $GLOBALS['HTML']->listTableBottom();
316 project_admin_footer(array());
320 // c-file-style: "bsd"