Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

fileupload.php
Go to the documentation of this file.
1 <?php
3 //
4 // $Id: fileupload.php 9448 2002-04-22 08:35:46Z jhe $
5 //
6 // Created on: <10-Dec-2000 15:49:57 bf>
7 //
8 // This source file is part of Exponential Basic, publishing software.
9 //
10 // Copyright (C) 1999-2001 eZ Systems. All rights reserved.
11 //
12 // This program is free software; you can redistribute it and/or
13 // modify it under the terms of the GNU General Public License
14 // as published by the Free Software Foundation; either version 2
15 // of the License, or (at your option) any later version.
16 //
17 // This program is distributed in the hope that it will be useful,
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 // GNU General Public License for more details.
21 //
22 // You should have received a copy of the GNU General Public License
23 // along with this program; if not, write to the Free Software
24 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, US
25 //
26
27 // include_once( "classes/INIFile.php" );
28 // include_once( "classes/eztemplate.php" );
29 // include_once( "classes/ezlog.php" );
30 // include_once( "classes/ezfile.php" );
31 // include_once( "classes/ezhttptool.php" );
32
33 // include_once( "ezuser/classes/ezuser.php" );
34 // include_once( "ezuser/classes/ezobjectpermission.php" );
35 // include_once( "ezfilemanager/classes/ezvirtualfile.php" );
36 // include_once( "ezfilemanager/classes/ezvirtualfolder.php" );
37
38 if ( isSet( $UpdateFiles ) )
39 {
40 $Action = "UpdateFiles";
41 }
42
43 if ( isset( $NewFile ) )
44 {
45 $Action = "New";
46 $Description = false;
47 $Name = false;
48 $readGroupArrayID = array();
49 $writeGroupArrayID = array();
50 $uploadGroupArrayID = array();
51 $sectionID = false;
52 }
53 if ( isset( $NewFolder ) )
54 {
55 eZHTTPTool::header( "Location: /filemanager/folder/new/$FolderID" );
56 exit();
57 }
58
59 if ( isset( $DeleteFiles ) )
60 {
61 $Action = "DeleteFiles";
62 }
63
64 if ( isset( $Delete ) )
65 {
66 $Action = "Delete";
67 }
68
69 if ( isset( $DeleteFolders ) )
70 {
71 $Action = "DeleteFolders";
72 }
73
74 if ( isset( $Cancel ) )
75 {
76 eZHTTPTool::header( "Location: /filemanager/list/" . $parentID );
77 exit();
78 }
79
80 if ( isset( $Download ) )
81 {
82 $file = new eZVirtualFile( $FileID );
83
84 if ( $ini->variable( "eZFileManagerMain", "DownloadOriginalFilename" ) == "true" )
85 $fileName = $file->originalFileName();
86 else
87 $fileName = $file->name();
88
89 eZHTTPTool::header( "Location: /filemanager/download/$FileID/$fileName" );
90 exit();
91 }
92
93 $user =& eZUser::currentUser();
94
95 if ( !$user )
96 {
97 eZHTTPTool::header( "Location: /error/403/" );
98 exit();
99 }
100
101 $ini =& eZINI::instance( 'site.ini' );
102
103 $Language = $ini->variable( "eZFileManagerMain", "Language" );
104
105
106 $t = new eZTemplate( "kernel/ezfilemanager/user/" . $ini->variable( "eZFileManagerMain", "TemplateDir" ),
107 "kernel/ezfilemanager/user/intl/", $Language, "fileupload.php" );
108
109 $t->set_file( "file_upload_tpl", "fileupload.tpl" );
110
111 $t->setAllStrings();
112
113 $t->set_block( "file_upload_tpl", "value_tpl", "value" );
114 $t->set_block( "file_upload_tpl", "errors_tpl", "errors" );
115
116 $t->set_block( "file_upload_tpl", "write_group_item_tpl", "write_group_item" );
117 $t->set_block( "file_upload_tpl", "read_group_item_tpl", "read_group_item" );
118
119 $t->set_var( "errors", "&nbsp;" );
120
121 $t->set_var( "name_value", $Name );
122 $t->set_var( "description_value", $Description );
123
124 $error = false;
125 $nameCheck = true;
126 $descriptionCheck = false;
127 $folderPermissionCheck = true;
128 $readCheck = true;
129 $fileCheck = true;
130
131 $t->set_block( "errors_tpl", "error_write_permission", "write_permission" );
132 $t->set_var( "write_permission", "" );
133
134 $t->set_block( "errors_tpl", "error_upload_permission", "upload_permission" );
135 $t->set_var( "upload_permission", "" );
136
137 $t->set_block( "errors_tpl", "error_name_tpl", "error_name" );
138 $t->set_var( "error_name", "" );
139
140 $t->set_block( "errors_tpl", "error_file_upload_tpl", "error_file_upload" );
141 $t->set_var( "error_file_upload", "" );
142
143 $t->set_block( "errors_tpl", "error_description_tpl", "error_description" );
144 $t->set_var( "error_description", "" );
145
146 $t->set_block( "errors_tpl", "error_read_everybody_permission_tpl", "error_read_everybody_permission" );
147 $t->set_var( "error_read_everybody_permission", "" );
148
149 $t->set_block( "errors_tpl", "error_write_everybody_permission_tpl", "error_write_everybody_permission" );
150 $t->set_var( "error_write_everybody_permission", "" );
151
152
153 if ($Action == "UpdateFiles")
154 {
155 $oldFolder = 0;
156 for ( $i = 0; $i < count( $FileUpdateIDArray ); $i++ )
157 {
158 $file = new eZVirtualFile($FileUpdateIDArray[$i]);
159 if ($NewDescriptionArray[$i] != $file->description() )
160 $file->setDescription( $NewDescriptionArray[$i] );
161 $oldParent = $file->folder();
162 if ( $oldParent )
163 $oldFolder = $oldParent->id();
164 $file->store();
165 }
166 eZHTTPTool::header( "Location: /filemanager/list/$oldFolder/" );
167 exit();
168 }
169 if ( isset( $Action ) && $Action == "Insert" || isset( $Action ) && $Action == "Update" )
170 {
171 if ( $folderPermissionCheck )
172 {
173 $folder = new eZVirtualFolder( $FolderID );
174 // must upload to a folder
175 if ( !isset( $FolderID ) || $FolderID == 0 )
176 {
177 $t->parse( "write_permission", "error_write_permission" );
178 $error = true;
179 }
180 // if not write or upload to folder...
181 if ( ( !eZObjectPermission::hasPermission( $folder->id(), "filemanager_folder", "w", $user ) &&
182 !eZObjectPermission::hasPermission( $folder->id(), "filemanager_folder", "u", $user ) ) &&
183 !eZVirtualFolder::isOwner( $user, $FolderID ) )
184 {
185 $t->parse( "write_permission", "error_write_permission" );
186 $error = true;
187 }
188 // if update but not owner or write.
189 if ( isset( $Action ) && $Action == "Update" &&
190 !eZObjectPermission::hasPermission( $folder->id(), "filemanager_folder", "w", $user ) &&
191 !eZVirtualFolder::isOwner( $user, $FolderID ) )
192 {
193 $t->parse( "upload_permission", "error_upload_permission" );
194 $error = true;
195 }
196 }
197
198 if ( $descriptionCheck )
199 {
200 if ( empty( $Description ) )
201 {
202 $t->parse( "error_description", "error_description_tpl" );
203 $error = true;
204 }
205 }
206
207 if ( $fileCheck )
208 {
209 $file = new eZFile();
210 if ( $file->getUploadedFile( "userfile" ) == false )
211 {
212 if ( isset( $Action ) && $Action == "Insert" )
213 {
214 $error = true;
215 $t->parse( "error_file_upload", "error_file_upload_tpl" );
216 }
217 }
218 }
219
220 if ( $error )
221 {
222 $t->parse( "errors", "errors_tpl" );
223 }
224 }
225
226 if ( isset( $Action ) && $Action == "Insert" && !$error )
227 {
228 $uploadedFile = new eZVirtualFile();
229 $uploadedFile->setDescription( $Description );
230 $uploadedFile->setUser( $user );
231 $uploadedFile->setFile( $file );
232
233 if ( empty( $Name ) )
234 $Name = $uploadedFile->originalFileName();
235
236 if ( !$ini->variable( "eZFileManagerMain", "DownloadOriginalFilename" ) == "true" )
237 {
238 $extension = strrchr( $uploadedFile->originalFileName(), "." );
239 if ( strrchr( $Name, "." ) != $extension )
240 $Name .= $extension;
241 }
242
243 $uploadedFile->setName( $Name );
244 $uploadedFile->store();
245 $FileID = $uploadedFile->id();
246 $folder = new eZVirtualFolder( $FolderID );
247
248 if ( eZObjectPermission::hasPermission( $FolderID, "filemanager_folder", 'w' ) ||
249 eZVirtualFolder::isOwner( $user, $FolderID ) )
250 {
251 changePermissions( $FileID, $ReadGroupArrayID, 'r' );
252 changePermissions( $FileID, $WriteGroupArrayID, 'w' );
253 }
254 else // user had upload permission only, change ownership, set special rights..
255 {
256 // eZObjectPermission::removePermissions( $FileID, "filemanager_file", "wr" ); // no write/read
257 // eZObjectPermission::setPermission( -1, $FileID, "filemanager_file", 'r' );
258 // $uploadedFile->setUser( $folder->user() );
259
260 changePermissions( $FileID, $ReadGroupArrayID, 'r' );
261 changePermissions( $FileID, $WriteGroupArrayID, 'w' );
262
263 $uploadedFile->store();
264 }
265
266 $folder->addFile( $uploadedFile );
267
268 eZPBLog::writeNotice( "File added to file manager from IP: $REMOTE_ADDR" );
269 eZHTTPTool::header( "Location: /filemanager/list/$FolderID/" );
270 exit();
271 }
272
273 if ( isset( $Action ) && $Action == "Update" && $error == false )
274 {
275 $file = new eZFile();
276
277 $uploadedFile = new eZVirtualFile( $FileID );
278
279 $uploadedFile->setName( $Name );
280 $uploadedFile->setDescription( $Description );
281
282 if ( $file->getUploadedFile( "userfile" ) )
283 {
284 $uploadedFile->setFile( $file );
285 }
286
287 $uploadedFile->store();
288 changePermissions( $FileID, $ReadGroupArrayID, 'r' );
289 changePermissions( $FileID, $WriteGroupArrayID, 'w' );
290
291 $folder = new eZVirtualFolder( $FolderID );
292
293 $uploadedFile->removeFolders();
294
295 $folder->addFile( $uploadedFile );
296
297 eZPBLog::writeNotice( "File added to file manager from IP: $REMOTE_ADDR" );
298 eZHTTPTool::header( "Location: /filemanager/list/$FolderID/" );
299 }
300
301 if ( isset( $Action ) && $Action == "DeleteFiles" )
302 {
303 $oldFolder = 0;
304 if ( count( $FileArrayID ) != 0 )
305 {
306 foreach ( $FileArrayID as $ID )
307 {
308 $file = new eZVirtualFile( $ID );
309 $oldParent = $file->folder();
310
311 if ( $oldParent )
312 $oldFolder = $oldParent->id();
313
314 $file->delete();
315 }
316 }
317
318 eZHTTPTool::header( "Location: /filemanager/list/$oldFolder/" );
319 exit();
320 }
321
322 if ( isset( $Action ) && $Action == "Delete" )
323 {
324 $file = new eZVirtualFile( $FileID );
325 $oldParent = $file->folder();
326
327 if ( $oldParent )
328 $oldFolder = $oldParent->id();
329
330 $file->delete();
331
332 eZHTTPTool::header( "Location: /filemanager/list/$oldFolder/" );
333 exit();
334 }
335
336 if ( isset( $Action ) && $Action == "DeleteFolders" )
337 {
338 $oldFolder = 0;
339 if ( count( $FolderArrayID ) > 0 )
340 {
341 foreach ( $FolderArrayID as $FolderID )
342 {
343 $folder = new eZVirtualFolder( $FolderID );
344 $oldParent = $folder->parent();
345
346 if ( $oldParent )
347 $oldFolder = $oldParent->id();
348
349 $folder->delete();
350 }
351 }
352
353 eZHTTPTool::header( "Location: /filemanager/list/$oldFolder/" );
354 exit();
355 }
356
357
358 $t->set_var( "write_everybody", "" );
359 $t->set_var( "read_everybody", "" );
360 if ( isset( $Action ) && $Action == "New" || $error )
361 {
362 $t->set_var( "action_value", "insert" );
363 $t->set_var( "file_id", "" );
364 if ( $FolderID )
365 {
366 $readGroupArrayID =& eZObjectPermission::getGroups( $FolderID, "filemanager_folder", "r", false );
367 $writeGroupArrayID =& eZObjectPermission::getGroups( $FolderID, "filemanager_folder", "w", false );
368 }
369 else
370 {
371 $t->set_var( "write_everybody", "selected" );
372 $t->set_var( "read_everybody", "selected" );
373 }
374 }
375
376 if ( isset( $Action ) && $Action == "Edit" )
377 {
378 $file = new eZVirtualFile( $FileID );
379
380 if ( !( eZObjectPermission::hasPermission( $file->id(), "filemanager_file", "r", $user ) &&
381 ( eZObjectPermission::hasPermission( $file->folder( false ), "filemanager_folder", "r", $user ) ||
382 eZVirtualFolder::isOwner( $user, $file->folder( false ) ) ) ) )
383 {
384 eZHTTPTool::header( "Location: /error/403/" );
385 exit();
386 }
387
388 $t->set_var( "name_value", $file->name() );
389 $t->set_var( "description_value", $file->description() );
390 $t->set_var( "file_id", $file->id() );
391
392 $folder = $file->folder();
393
394 if ( $folder )
395 $FolderID = $folder->id();
396
397 $readGroupArrayID =& eZObjectPermission::getGroups( $file->id(), "filemanager_file", "r", false );
398 $writeGroupArrayID =& eZObjectPermission::getGroups( $file->id(), "filemanager_file", "w", false );
399
400 $t->set_var( "action_value", "update" );
401 }
402
403 // Print out all the groups.
404
405 $group = new eZUserGroup();
406 $groups = $group->getAll();
407
408 foreach ( $groups as $group )
409 {
410 $t->set_var( "group_id", $group->id() );
411 $t->set_var( "group_name", $group->name() );
412
413 $t->set_var( "is_read_selected1", "" );
414 $t->set_var( "is_write_selected1", "" );
415
416 if ( $readGroupArrayID )
417 {
418 foreach ( $readGroupArrayID as $readGroup )
419 {
420 if ( $readGroup == $group->id() )
421 {
422 $t->set_var( "is_read_selected1", "selected" );
423 }
424 elseif ( $readGroup == -1 )
425 {
426 $t->set_var( "read_everybody", "selected" );
427 }
428 else
429 {
430 $t->set_var( "is_read_selected", "" );
431 }
432 }
433
434 }
435
436 if ( $writeGroupArrayID )
437 {
438 foreach ( $writeGroupArrayID as $writeGroup )
439 {
440 if ( $writeGroup == $group->id() )
441 {
442 $t->set_var( "is_write_selected1", "selected" );
443 }
444 elseif ( $writeGroup == -1 )
445 {
446 $t->set_var( "write_everybody", "selected" );
447 }
448 else
449 {
450 $t->set_var( "is_write_selected", "" );
451 }
452 }
453 }
454
455 $t->parse( "write_group_item", "write_group_item_tpl", true );
456 $t->parse( "read_group_item", "read_group_item_tpl", true );
457 }
458
459
460 $folder = new eZVirtualFolder() ;
461
462 $folderList = $folder->getTree();
463
464 foreach ( $folderList as $folderItem )
465 {
466 if ( eZObjectPermission::hasPermission( $folderItem[0]->id(), "filemanager_folder", 'w' ) ||
467 eZVirtualFolder::isOwner( eZUser::currentUser(), $folderItem[0]->id() ) ||
468 eZObjectPermission::hasPermission( $folderItem[0]->id(), "filemanager_folder", 'u' ))
469 {
470 $t->set_var( "option_name", $folderItem[0]->name() );
471 $t->set_var( "option_value", $folderItem[0]->id() );
472
473 if ( $folderItem[1] > 0 )
474 $t->set_var( "option_level", str_repeat( "&nbsp;", $folderItem[1] ) );
475 else
476 $t->set_var( "option_level", "" );
477
478 $t->set_var( "selected", "" );
479
480 if ( $folder && !$FolderID )
481 {
482 $FolderID = $folder->id();
483 }
484
485 if ( $FolderID )
486 {
487 if ( $folderItem[0]->id() == $FolderID )
488 {
489 $t->set_var( "selected", "selected" );
490 }
491 }
492
493 $t->parse( "value", "value_tpl", true );
494 }
495 }
496
497 $t->pparse( "output", "file_upload_tpl" );
498
499 /******* FUNCTIONS ****************************/
500 function changePermissions( $objectID, $groups, $permission )
501 {
502 eZObjectPermission::removePermissions( $objectID, "filemanager_file", $permission );
503 if ( count( $groups ) > 0 )
504 {
505 foreach ( $groups as $groupItem )
506 {
507 if ( $groupItem == 0 )
508 $group = -1;
509 else
510 $group = new eZUserGroup( $groupItem );
511
512 eZObjectPermission::setPermission( $group, $objectID, "filemanager_file", $permission );
513 }
514 }
515 }
516
517 ?>
$i
$i
Definition: admin/adlist.php:91
$Description
$Description
Definition: articlelistrss.php:38
eZFile
Tool class which has convencience functions for files and directories.
Definition: ezfile.php:19
eZHTTPTool\header
static header( $string)
Definition: ezhttptool.php:96
eZObjectPermission\hasPermission
static hasPermission( $objectID, $moduleTable, $permission, $user=false)
Definition: ezobjectpermission.php:76
eZObjectPermission\getGroups
static getGroups( $objectID, $moduleTable, $permission, $GroupReturn=true)
Definition: ezobjectpermission.php:365
eZObjectPermission\setPermission
static setPermission( $group, $objectID, $moduleTable, $permission)
Definition: ezobjectpermission.php:236
eZObjectPermission\removePermissions
static removePermissions( $objectID, $moduleTable, $permission)
Definition: ezobjectpermission.php:320
eZPBLog\writeNotice
static writeNotice( $notice)
Definition: ezpblog.php:166
eZTemplate
Definition: eztemplate.php:107
eZUserGroup
Definition: ezusergroup.php:66
eZUser\currentUser
static & currentUser()
Definition: ezuser.php:896
eZVirtualFile
Definition: ezvirtualfile.php:42
eZVirtualFolder
Definition: ezvirtualfolder.php:43
eZVirtualFolder\isOwner
static isOwner( $user, $folderID)
Definition: ezvirtualfolder.php:421
$Action
$Action
Definition: companysearch.php:80
$permission
$permission
Definition: eventedit.php:315
$fileName
if(eZObjectPermission::hasPermission( $file->id(), "filemanager_file", "r", $user)==false) $fileName
Definition: ezfilemanager/user/filedownload.php:43
$file
$file
Definition: ezfilemanager/user/filedownload.php:35
$readCheck
$readCheck
Definition: fileupload.php:128
$groups
$groups
Definition: fileupload.php:406
$t
$t
Definition: fileupload.php:106
$descriptionCheck
$descriptionCheck
Definition: fileupload.php:126
$ini
if(! $user) $ini
Definition: fileupload.php:101
$group
if(isset( $Action) && $Action=="New"|| $error) if(isset( $Action) && $Action=="Edit") $group
Definition: fileupload.php:405
$Language
$Language
Definition: fileupload.php:103
$user
if(isSet( $UpdateFiles)) if(isset( $NewFile)) if(isset( $NewFolder)) if(isset( $DeleteFiles)) if(isset( $Delete)) if(isset( $DeleteFolders)) if(isset( $Cancel)) if(isset( $Download)) $user
Definition: fileupload.php:93
$nameCheck
$nameCheck
Definition: fileupload.php:125
$folderList
$folderList
Definition: fileupload.php:462
changePermissions
changePermissions( $objectID, $groups, $permission)
Definition: fileupload.php:500
$fileCheck
$fileCheck
Definition: fileupload.php:129
$error
$error
Definition: fileupload.php:124
$folder
foreach( $groups as $group) $folder
Definition: fileupload.php:460
$folderPermissionCheck
$folderPermissionCheck
Definition: fileupload.php:127
exit
exit
Definition: folder.php:81
$Name
$Name
Definition: polledit.php:250
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.