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) {
46 if (($size > 20) && ($size < 256000)) {
50 $feedback .= _('ERROR - file must be > 20 bytes and < 256000 bytes in length').' <br />';
55 function store_file($id, $input_file) {
60 if (!util_check_fileupload($input_file)) {
61 exit_error("Error","Invalid filename");
64 $filename = $input_file['tmp_name'];
65 $size = $input_file['size'];
66 $dimensions = @getimagesize($filename);
67 $data = addslashes(base64_encode(fread( fopen($filename, 'rb'), $size)));
68 $width=$dimensions[0];
69 $height=$dimensions[1];
71 if (check_file_size($size)) {
74 $width = ((!$width) ? "0" : $width);
75 $height = ((!$height) ? "0" : $height);
77 $sql=" INSERT INTO db_images
78 (group_id,description,bin_data,
79 filename,filesize,filetype,
80 width,height,upload_date,version)
82 ('$group_id','$description',
83 '$data','".$input_file['name']."',
84 '$size','".$input_file['type']."',
85 '$width','$height','$curtime',1)";
87 $sql=" UPDATE db_images
88 SET description='$description',
90 filename='".$input_file['name']."',
92 filetype='".$input_file['type']."',
95 upload_date='$curtime',
97 WHERE group_id='$group_id'
101 $res = db_query($sql);
103 if (!$res || db_affected_rows($res) < 1) {
104 $feedback .= 'ERROR: DB: Cannot store multimedia file<br />';
107 $feedback .= _('Multimedia File Uploaded');
112 if (getStringFromRequest('submit')) {
113 $input_file = getUploadedFile('input_file');
114 $id = getIntFromRequest('id');
115 $description = getStringFromRequest('description');
116 $filetype = getStringFromRequest('filetype');
118 if (!util_check_fileupload($input_file)) {
119 exit_error("Error","Invalid filename");
122 if (getStringFromRequest('add')) {
123 if (!$input_file['tmp_name'] || $description == "") {
124 $feedback .= _('Both file name and description are required');
126 //see if they have too many data in the system
127 $res=db_query("SELECT sum(filesize) WHERE group_id='$group_id'");
128 if (db_result($res,0,'sum') < $QUOTA) {
129 store_file(0, $input_file);
131 $feedback .= ' Sorry - you are over your '.$QUOTA.' quota ';
135 } else if (getStringFromRequest('remove')) {
137 $res=db_query("DELETE FROM db_images WHERE id='$id' AND group_id='$group_id'");
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("UPDATE db_images
155 SET description='$description',
157 WHERE group_id='$group_id'
160 if (!$res || db_affected_rows($res) < 1) {
161 $feedback .= 'ERROR: DB: Cannot update multimedia file<br />';
164 $feedback .= _('Multimedia File Properties Updated').'<br />';
169 // new version of the file is uploaded
170 // use new description, but not user-input
173 //see if they have too many data in the system
174 $res=db_query(" SELECT sum(filesize)
175 WHERE group_id='$group_id'
178 $size = $input_file['size'];
179 if (db_result($res,0,'sum')+$size < $QUOTA) {
181 store_file($id, $input_file);
185 $feedback .= ' Sorry - you are over your 1MB quota ';
194 project_admin_header(array('title'=>_('Edit Multimedia Data')));
197 <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>
201 $mode = getStringFromGet("mode");
202 if ($mode == "edit") {
203 $result=db_query(" SELECT *
205 WHERE group_id='$group_id'
208 if (!$result || db_numrows($result)!=1) {
209 $feedback .= "Cannot edit multimedia file<br />";
210 project_admin_footer(array());
214 echo '</p><h4>'._('Edit Multimedia Data').'</h4>
216 <form action="'. getStringFromServer('PHP_SELF') .'" method="post" enctype="multipart/form-data">
217 <input type="hidden" name="group_id" value="'.$group_id.'" />
218 <input type="hidden" name="id" value="'.$id.'" />
220 <strong>'._('Replace with new file (optional)').':</strong><br />
221 <input type="file" name="input_file" size="30" />
224 <strong>'._('Description').':</strong><br />
225 <input type="text" name="description" size="40" maxlength="255" value="'.db_result($result,$i,'description').'" />
228 <strong>'._('MIME Type').':</strong><br />
229 <input type="text" name="filetype" size="40" maxlength="255" value="'.db_result($result,$i,'filetype').'" />
231 <input type="hidden" name="edit" value="1" />
233 <input type="submit" value="'._('Submit').'" name="submit" />
234 <input type="reset" value="'._('Reset').'" /><br />
238 $result=db_query(" SELECT *
240 WHERE group_id='$group_id'
243 echo '<h4>'._('Add Multimedia Data').'</h4>
245 <form action="'. getStringFromServer('PHP_SELF') .'" method="post" enctype="multipart/form-data">
246 <input type="hidden" name="group_id" value="'.$group_id.'" />
247 <strong>'._('Local filename').':</strong>'.utils_requiredField().'<br />
248 <input type="file" name="input_file" size="30" />
250 <strong>'._('Description').':</strong>'.utils_requiredField().'<br />
251 <input type="text" name="description" size="40" maxlength="255" /></p><p>
252 <input type="hidden" name="add" value="1" />
253 <input type="submit" value="'._('Add File').'" name="submit" /><br /></p>
261 $arr[]=_('Uploaded');
263 $arr[]=_('MIME Type');
266 $arr[]=_('Description');
268 echo $GLOBALS['HTML']->listTableTop($arr);
270 $rows=db_numrows($result);
271 for ($i=0; $i<$rows; $i++) {
273 // Show dimensions only for images
274 $w = db_result($result,$i,'width');
275 $h = db_result($result,$i,'height');
277 $dims = '('.$w.'x'.$h.')';
283 <tr '. $GLOBALS['HTML']->boxGetAltRowStyle($i) .'>'
284 .'<td style="text-align:center">'
285 .'<a href="'. getStringFromServer('PHP_SELF') .'?submit=1&group_id='.$group_id.'&remove=1&id='
286 .db_result($result,$i,'id').'">'
287 .'['._('Del').']'.'</a>'
288 .'<a href="'. getStringFromServer('PHP_SELF') .'?submit=1&group_id='.$group_id.'&mode=edit&id='
289 .db_result($result,$i,'id').'"> '
290 .'['._('Edit').']'.'</a>'
293 .'<td>'.db_result($result,$i,'id').'</td>'
295 .'<td>'.date('Y-m-d', db_result($result, $i, 'upload_date')).'</td>'
297 .'<td>'util_make_link ('/dbimage.php?id='.db_result($result,$i,'id'), stripslashes(db_result($result,$i,'filename'))).'</td>'
298 .'<td>'.db_result($result,$i,'filetype').'</td>'
299 .'<td style="text-align:right">'.db_result($result,$i,'filesize').'</td>'
300 .'<td style="text-align:right">'.$dims.'</td>'
301 .'<td>'.stripslashes(db_result($result,$i,'description')).'</td>'
305 echo $GLOBALS['HTML']->listTableBottom();
307 project_admin_footer(array());
311 // c-file-style: "bsd"