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 (!$sys_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)) {
72 $width = ((!$width) ? "0" : $width);
73 $height = ((!$height) ? "0" : $height);
75 $sql=" INSERT INTO db_images
76 (group_id,description,bin_data,
77 filename,filesize,filetype,
78 width,height,upload_date,version)
80 ($1, $2, $3, $4, $5, $6, $7, $8, $9, 1)";
81 $res = db_query_params($sql, array($group_id, $description, $data, $input_file['name'],
82 $size, $input_file['type'], $width, $height, $curtime));
84 $sql=" UPDATE db_images
96 $res = db_query_params($sql, array($description, $data, $input_file['name'], $size,
97 $input_file['type'], $width, $height, $curtime, $group_id, $id);
101 if (!$res || db_affected_rows($res) < 1) {
102 $feedback .= 'ERROR: DB: Cannot store multimedia file<br />';
105 $feedback .= _('Multimedia File Uploaded');
110 if (getStringFromRequest('submit')) {
111 $input_file = getUploadedFile('input_file');
112 $id = getIntFromRequest('id');
113 $description = getStringFromRequest('description');
114 $filetype = getStringFromRequest('filetype');
116 if (!util_check_fileupload($input_file)) {
117 exit_error("Error","Invalid filename");
120 if (getStringFromRequest('add')) {
121 if (!$input_file['tmp_name'] || $description == "") {
122 $feedback .= _('Both file name and description are required');
124 //see if they have too many data in the system
125 $res=db_query_params ('SELECT sum(filesize) WHERE group_id=$1',
127 if (db_result($res,0,'sum') < $QUOTA) {
128 store_file(0, $input_file);
130 $feedback .= ' Sorry - you are over your '.$QUOTA.' quota ';
134 } else if (getStringFromRequest('remove')) {
136 $res=db_query_params ('DELETE FROM db_images WHERE id=$1 AND group_id=$2',
140 if (!$res || db_affected_rows($res) < 1) {
141 $feedback .= 'ERROR: DB: Cannot delete multimedia file<br />';
144 $feedback .= _('Multimedia File Deleted');
147 } else if (getStringFromRequest("edit")) {
148 if ($description == "") {
149 $feedback .= _('File description is required').'<b />';
151 if (!$input_file['tmp_name']) {
153 // Just replace description/mime type
155 $res = db_query_params ('UPDATE db_images
165 if (!$res || db_affected_rows($res) < 1) {
166 $feedback .= 'ERROR: DB: Cannot update multimedia file<br />';
169 $feedback .= _('Multimedia File Properties Updated').'<br />';
174 // new version of the file is uploaded
175 // use new description, but not user-input
178 //see if they have too many data in the system
179 $res=db_query_params (' SELECT sum(filesize)
185 $size = $input_file['size'];
186 if (db_result($res,0,'sum')+$size < $QUOTA) {
188 store_file($id, $input_file);
192 $feedback .= ' Sorry - you are over your 1MB quota ';
201 project_admin_header(array('title'=>_('Edit Multimedia Data')));
204 <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>
208 $mode = getStringFromGet("mode");
209 if ($mode == "edit") {
210 $result=db_query_params (' SELECT *
217 if (!$result || db_numrows($result)!=1) {
218 $feedback .= "Cannot edit multimedia file<br />";
219 project_admin_footer(array());
223 echo '</p><h4>'._('Edit Multimedia Data').'</h4>
225 <form action="'. getStringFromServer('PHP_SELF') .'" method="post" enctype="multipart/form-data">
226 <input type="hidden" name="group_id" value="'.$group_id.'" />
227 <input type="hidden" name="id" value="'.$id.'" />
229 <strong>'._('Replace with new file (optional)').':</strong><br />
230 <input type="file" name="input_file" size="30" />
233 <strong>'._('Description').':</strong><br />
234 <input type="text" name="description" size="40" maxlength="255" value="'.db_result($result,$i,'description').'" />
237 <strong>'._('MIME Type').':</strong><br />
238 <input type="text" name="filetype" size="40" maxlength="255" value="'.db_result($result,$i,'filetype').'" />
240 <input type="hidden" name="edit" value="1" />
242 <input type="submit" value="'._('Submit').'" name="submit" />
243 <input type="reset" value="'._('Reset').'" /><br />
247 $result=db_query_params (' SELECT *
253 echo '<h4>'._('Add Multimedia Data').'</h4>
255 <form action="'. getStringFromServer('PHP_SELF') .'" method="post" enctype="multipart/form-data">
256 <input type="hidden" name="group_id" value="'.$group_id.'" />
257 <strong>'._('Local filename').':</strong>'.utils_requiredField().'<br />
258 <input type="file" name="input_file" size="30" />
260 <strong>'._('Description').':</strong>'.utils_requiredField().'<br />
261 <input type="text" name="description" size="40" maxlength="255" /></p><p>
262 <input type="hidden" name="add" value="1" />
263 <input type="submit" value="'._('Add File').'" name="submit" /><br /></p>
271 $arr[]=_('Uploaded');
273 $arr[]=_('MIME Type');
276 $arr[]=_('Description');
278 echo $GLOBALS['HTML']->listTableTop($arr);
280 $rows=db_numrows($result);
281 for ($i=0; $i<$rows; $i++) {
283 // Show dimensions only for images
284 $w = db_result($result,$i,'width');
285 $h = db_result($result,$i,'height');
287 $dims = '('.$w.'x'.$h.')';
293 <tr '. $GLOBALS['HTML']->boxGetAltRowStyle($i) .'>'
294 .'<td style="text-align:center">'
295 .'<a href="'. getStringFromServer('PHP_SELF') .'?submit=1&group_id='.$group_id.'&remove=1&id='
296 .db_result($result,$i,'id').'">'
297 .'['._('Del').']'.'</a>'
298 .'<a href="'. getStringFromServer('PHP_SELF') .'?submit=1&group_id='.$group_id.'&mode=edit&id='
299 .db_result($result,$i,'id').'"> '
300 .'['._('Edit').']'.'</a>'
303 .'<td>'.db_result($result,$i,'id').'</td>'
305 .'<td>'.date('Y-m-d', db_result($result, $i, 'upload_date')).'</td>'
307 .'<td>'.util_make_link ('/dbimage.php?id='.db_result($result,$i,'id'), stripslashes(db_result($result,$i,'filename'))).'</td>'
308 .'<td>'.db_result($result,$i,'filetype').'</td>'
309 .'<td style="text-align:right">'.db_result($result,$i,'filesize').'</td>'
310 .'<td style="text-align:right">'.$dims.'</td>'
311 .'<td>'.stripslashes(db_result($result,$i,'description')).'</td>'
315 echo $GLOBALS['HTML']->listTableBottom();
317 project_admin_footer(array());
321 // c-file-style: "bsd"