Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

ezfilemanager/user/folderedit.php
Go to the documentation of this file.
1 <?php
3 //
4 // $Id: folderedit.php 9793 2003-03-25 08:26:23Z br $
5 //
6 // Created on: <08-Jan-2001 11:13:29 ce>
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/ezhttptool.php" );
31
32 // include_once( "ezuser/classes/ezuser.php" );
33 // include_once( "ezuser/classes/ezpermission.php" );
34 // include_once( "ezuser/classes/ezobjectpermission.php" );
35
36 // include_once( "ezsitemanager/classes/ezsection.php" );
37
38 // include_once( "ezfilemanager/classes/ezvirtualfile.php" );
39 // include_once( "ezfilemanager/classes/ezvirtualfolder.php" );
40
41 $user =& eZUser::currentUser();
42
43 if ( isset( $NewFolder ) )
44 {
45 $Description = false;
46 $Name = false;
47 $readGroupArrayID = array();
48 $writeGroupArrayID = array();
49 $uploadGroupArrayID = array();
50 $sectionID = false;
51 }
52 // check if user has rights to edit the current folder.
53 if ( isset( $FolderID ) && $FolderID != 0 &&
54 !eZObjectPermission::hasPermission( $FolderID, "filemanager_folder", 'w' ) &&
55 !eZVirtualFolder::isOwner( $user, $FolderID ) )
56 {
57 eZHTTPTool::header( "Location: /error/403/" );
58 exit();
59 }
60
61 if ( isset( $Cancel ) )
62 {
63 $folder = new eZVirtualFolder( $FolderID );
64
65 $parent = $folder->parent();
66
67 if ( !isset( $parentID ) )
68 $parentID = "0";
69
70 if ( $parent )
71 $parentID = $parent->id();
72
73 eZHTTPTool::header( "Location: /filemanager/list/" . $parentID );
74 exit();
75 }
76
77 $ini =& eZINI::instance( 'site.ini' );
78
79 $Language = $ini->variable( "eZFileManagerMain", "Language" );
80
81
82 $t = new eZTemplate( "kernel/ezfilemanager/user/" . $ini->variable( "eZFileManagerMain", "TemplateDir" ),
83 "kernel/ezfilemanager/user/intl/", $Language, "folderedit.php" );
84
85 $t->set_file( "folder_edit_tpl", "folderedit.tpl" );
86
87 $t->setAllStrings();
88
89 $t->set_block( "folder_edit_tpl", "value_tpl", "value" );
90 $t->set_block( "folder_edit_tpl", "errors_tpl", "errors" );
91 $t->set_block( "folder_edit_tpl", "write_group_item_tpl", "write_group_item" );
92 $t->set_block( "folder_edit_tpl", "read_group_item_tpl", "read_group_item" );
93 $t->set_block( "folder_edit_tpl", "upload_group_item_tpl", "upload_group_item" );
94 $t->set_block( "folder_edit_tpl", "section_item_tpl", "section_item" );
95
96 $t->set_var( "errors", "" );
97 $t->set_var( "name_value", $Name );
98 $t->set_var( "description_value", $Description );
99
100 $error = false;
101 $permissionCheck = true;
102 $nameCheck = true;
103 $descriptionCheck = false;
104
105 $t->set_block( "errors_tpl", "error_write_permission", "error_write" );
106 $t->set_var( "error_write", "" );
107
108 $t->set_block( "errors_tpl", "error_upload_permission", "error_upload" );
109 $t->set_var( "error_upload", "" );
110
111 $t->set_block( "errors_tpl", "error_name_tpl", "error_name" );
112 $t->set_var( "error_name", "&nbsp;" );
113
114 $t->set_block( "errors_tpl", "error_description_tpl", "error_description" );
115 $t->set_var( "error_description", "&nbsp;" );
116
117 $t->set_block( "errors_tpl", "error_parent_check_tpl", "error_parent_check" );
118 $t->set_var( "error_parent_check", "&nbsp;" );
119
120 $t->set_block( "errors_tpl", "error_read_everybody_permission_tpl", "error_read_everybody_permission" );
121 $t->set_var( "error_read_everybody_permission", "&nbsp;" );
122
123 $t->set_block( "errors_tpl", "error_write_everybody_permission_tpl", "error_write_everybody_permission" );
124 $t->set_var( "error_write_everybody_permission", "&nbsp;" );
125
126
127 if ( $Action == "Insert" || $Action == "Update" )
128 {
129 if ( $permissionCheck )
130 {
131
132 if ( $ParentID == 0 )
133 {
134 if ( eZPermission::checkPermission( $user, "eZFileManager", "WriteToRoot" ) == false )
135 {
136 $t->parse( "error_write", "error_write_permission" );
137 $error = true;
138 }
139 }
140 else
141 {
142 $parentFolder = new eZVirtualFolder( $ParentID );
143 // no write to parent.
144 if ( $FolderID == 0 &&
145 eZObjectPermission::hasPermission( $ParentID, "filemanager_folder", 'w' ) == false &&
146 eZObjectPermission::hasPermission( $ParentID, "filemanager_folder", 'u') == false )
147 {
148 $t->parse( "error_write", "error_write_permission" );
149 $error = true;
150 }
151 // update and not write or owner
152 if ( ! $error && $Action == "Update" &&
153 eZObjectPermission::hasPermission( $FolderID, "filemanager_folder", 'w' ) == false &&
154 eZVirtualFolder::isOwner( $user, $FolderID ) == false )
155 {
156 $t->parse( "error_upload", "error_upload_permission" );
157 $error = true;
158 }
159 }
160 }
161
162 if ( $nameCheck )
163 {
164 if ( empty( $Name ) )
165 {
166 $t->parse( "error_name", "error_name_tpl" );
167 $error = true;
168 }
169 }
170
171 if ( $descriptionCheck )
172 {
173
174 if ( empty( $Description ) )
175 {
176 $t->parse( "error_description", "error_description_tpl" );
177 $error = true;
178 }
179 }
180
181 if ( $Action == "Update" )
182 {
183 if ( $ParentID == $FolderID )
184 {
185 $t->parse( "error_parent_check", "error_parent_check_tpl" );
186 $error = true;
187 }
188 }
189
190 if ( $error )
191 {
192 $t->parse( "errors", "errors_tpl" );
193 }
194 }
195
196 // Insert or update a folder.
197 if ( ( $Action == "Insert" || $Action == "Update" ) && $error == false )
198 {
199 if ( $Action == "Insert" )
200 {
201 $folder = new eZVirtualFolder();
202 $folder->setUser( $user );
203 }
204 else
205 {
206 $folder = new eZVirtualFolder( $FolderID );
207 }
208 $folder->setName( $Name );
209 if ( isset( $Description ) )
210 $folder->setDescription( $Description );
211
212 $folder->setSectionID( $SectionID );
213 $parent = new eZVirtualFolder( $ParentID );
214 $folder->setParent( $parent );
215
216 $folder->store();
217 $FolderID = $folder->id();
218
219 changePermissions( $FolderID, $ReadGroupArrayID, 'r' );
220 changePermissions( $FolderID, $WriteGroupArrayID, 'w' );
221 changePermissions( $FolderID, $UploadGroupArrayID, 'u');
222
223 // check if user uploaded a dir and had upload permission only and is not owner.
224 // TODO: No move, insert takes permissions of parent.
225 if ( $Action == "Insert" &&
226 eZObjectPermission::hasPermission( $ParentID, "filemanager_folder", 'w' ) == false &&
227 $parent->user( false ) != $user->id() )
228 {
229 changePermissions( $FolderID, eZObjectPermission::getGroups( $ParentID, "filemanager_folder", 'r', false ), 'r' );
230 changePermissions( $FolderID, eZObjectPermission::getGroups( $ParentID, "filemanager_folder", 'w', false ), 'w' );
231 changePermissions( $FolderID, eZObjectPermission::getGroups( $ParentID, "filemanager_folder", 'u', false ), 'u' );
232 $folder->setUser( $parent->user() );
233 $folder->store();
234 }
235 // if update and moving into a folder that has upload permission and not owner of that folder
236 // update into a upload dir is NOT allowed unless you have write permission or you are the owner.
237 /*
238 if ( $Action == "Update" &&
239 eZObjectPermission::hasPermission( $ParentID, "filemanager_folder", 'w' ) == false &&
240 $parent->user( false ) != $user->id() )
241 {
242 exit();
243 // recursivly edit permissions on all file and folders...
244 $folders = array();
245 $folders[] = $folder; // set permission on self.
246 $files = array();
247 getFilesAndFolders( $folders, $files, $folder );
248
249 // set permissions on all these files and dirs..
250 foreach ( $folders as $folderItem )
251 {
252 eZObjectPermission::removePermissions( $folderItem->id(), "filemanager_folder", 'w' ); // no write
253 eZObjectPermission::removePermissions( $folderItem->id(), "filemanager_folder", 'r' ); // all read
254 eZObjectPermission::removePermissions( $folderItem->id(), "filemanager_folder", 'u' ); // all upload
255 eZObjectPermission::setPermission( -1, $folderItem->id(), "filemanager_folder", 'r' );
256 eZObjectPermission::setPermission( -1, $folderItem->id(), "filemanager_folder", 'u' );
257 $folderItem->setUser( $parent->user() );
258 $folderItem->store();
259 }
260 foreach ( $files as $fileItem )
261 {
262 eZObjectPermission::removePermissions( $fileItem->id(), "filemanager_file", 'w' ); // no write
263 eZObjectPermission::removePermissions( $fileItem->id(), "filemanager_file", 'r' ); // all read
264 eZObjectPermission::setPermission( -1, $fileItem->id(), "filemanager_file", 'r' );
265 $fileItem->setUser( $parent->user() );
266 $fileItem->store();
267 }
268 }
269 */
270
271 eZHTTPTool::header( "Location: /filemanager/list/" . $ParentID );
272 exit();
273 }
274
275 if ( $Action == "Delete" && $error == false )
276 {
277 if ( count( $FolderArrayID ) > 0 )
278 {
279 foreach ( $FolderArrayID as $FolderID )
280 {
281 $folder = new eZVirtualFolder( $FolderID );
282 $folder->delete();
283 }
284 }
285 }
286
287 $t->set_var( "write_everybody", "" );
288 $t->set_var( "read_everybody", "" );
289 $t->set_var( "upload_everybody", "" );
290 if ( $Action == "New" || $error )
291 {
292 if ( $Action == "New" )
293 {
294 $t->set_var( "action_value", "insert" );
295 $t->set_var( "folder_id", "" );
296 }
297 else
298 {
299 $t->set_var( "action_value", "update" );
300 $t->set_var( "folder_id", $FolderID );
301 }
302 $t->set_var( "write_everybody", "selected" );
303 $t->set_var( "read_everybody", "selected" );
304 $t->set_var( "upload_everybody", "selected" );
305 }
306
307 if ( $Action == "Edit" )
308 {
309 $folder = new eZVirtualFolder( $FolderID );
310
311 $t->set_var( "name_value", $folder->name() );
312 $t->set_var( "folder_id", $folder->id() );
313 $t->set_var( "description_value", $folder->description() );
314
315 $sectionID = $folder->sectionID();
316
317 $parent = $folder->parent();
318
319 if ( $parent )
320 $parentID = $parent->id();
321
322 $readGroupArrayID =& eZObjectPermission::getGroups( $folder->id(), "filemanager_folder", "r", false );
323 $writeGroupArrayID =& eZObjectPermission::getGroups( $folder->id(), "filemanager_folder", "w", false );
324 $uploadGroupArrayID =& eZObjectPermission::getGroups( $folder->id(), "filemanager_folder", "u", false );
325 $t->set_var( "action_value", "update" );
326 }
327
328 $folder = new eZVirtualFolder() ;
329
330 $folderList = $folder->getTree( );
331
332 if ( count( $folderList ) == 0 )
333 {
334 $t->set_var( "option_level", "" );
335 $t->set_var( "value", "" );
336 }
337
338 // Print out all the groups.
339 //$groups = $user->groups();
340 $group = new eZUserGroup();
341 $groups = $group->getAll();
342
343 $t->set_var( "is_write_selected1", "" );
344 $t->set_var( "is_read_selected1", "" );
345 $t->set_var( "is_upload_selected1", "" );
346
347 foreach ( $groups as $group )
348 {
349 $t->set_var( "group_id", $group->id() );
350 $t->set_var( "group_name", $group->name() );
351
352 if ( $readGroupArrayID )
353 {
354 if ( in_array( $group->id(), $readGroupArrayID ) )
355 $t->set_var( "is_read_selected1", "selected" );
356 else
357 $t->set_var( "is_read_selected1", "" );
358
359 if ( in_array( -1, $readGroupArrayID ) )
360 $t->set_var( "read_everybody", "selected" );
361 }
362 $t->parse( "read_group_item", "read_group_item_tpl", true );
363
364 if ( $writeGroupArrayID )
365 {
366 if ( in_array( $group->id(), $writeGroupArrayID ) )
367 $t->set_var( "is_write_selected1", "selected" );
368 else
369 $t->set_var( "is_write_selected1", "" );
370
371 if ( in_array( -1, $writeGroupArrayID ) )
372 $t->set_var( "write_everybody", "selected" );
373 }
374 $t->parse( "write_group_item", "write_group_item_tpl", true );
375
376 if ( $uploadGroupArrayID )
377 {
378 if ( in_array( $group->id(), $uploadGroupArrayID ) )
379 $t->set_var( "is_upload_selected1", "selected" );
380 else
381 $t->set_var( "is_upload_selected1", "" );
382
383 if ( in_array( -1, $uploadGroupArrayID ) )
384 $t->set_var( "upload_everybody", "selected" );
385 }
386 $t->parse( "upload_group_item", "upload_group_item_tpl", true );
387 }
388
389 $sectionList =& eZSection::getAll();
390
391 if ( count( $sectionList ) > 0 )
392 {
393 foreach ( $sectionList as $section )
394 {
395 $t->set_var( "section_id", $section->id() );
396 $t->set_var( "section_name", $section->name() );
397
398 if ( $sectionID == $section->id() )
399 $t->set_var( "section_is_selected", "selected" );
400 else
401 $t->set_var( "section_is_selected", "" );
402
403 $t->parse( "section_item", "section_item_tpl", true );
404 }
405 }
406 else
407 $t->set_var( "section_item", "" );
408
409
410 // Print out all the folders.
411 if( $parentID == 0 || !isset( $parentID ) )
412 $t->set_var( "root_selected", "selected" );
413 else
414 $t->set_var( "root_selected", "" );
415
416 foreach ( $folderList as $folderItem )
417 {
418 if ( eZObjectPermission::hasPermission( $folderItem[0]->id(), "filemanager_folder", 'w' ) ||
419 eZVirtualFolder::isOwner( eZUser::currentUser(), $folderItem[0]->id() ) ||
420 eZObjectPermission::hasPermission( $folderItem[0]->id(), "filemanager_folder", 'u' ) )
421 {
422 $t->set_var( "option_name", $folderItem[0]->name() );
423 $t->set_var( "option_value", $folderItem[0]->id() );
424
425 if ( $folderItem[1] > 0 )
426 $t->set_var( "option_level", str_repeat( "&nbsp;", $folderItem[1] ) );
427 else
428 $t->set_var( "option_level", "" );
429
430 $t->set_var( "selected", "" );
431
432 if ( $folder && !$FolderID )
433 {
434 $FolderID = $folder->id();
435 }
436
437 $selectFolderID = $folderItem[0]->id();
438 if ( $parentID )
439 {
440 if ( $selectFolderID == $parentID )
441 {
442 $t->set_var( "selected", "selected" );
443 }
444 }
445
446 $t->parse( "value", "value_tpl", true );
447 }
448 }
449
450 $t->pparse( "output", "folder_edit_tpl" );
451
452 /******* FUNCTIONS ****************************/
453 function changePermissions( $objectID, $groups, $permission )
454 {
455 eZObjectPermission::removePermissions( $objectID, "filemanager_folder", $permission );
456 if ( count( $groups ) > 0 )
457 {
458 foreach ( $groups as $groupItem )
459 {
460 if ( $groupItem == 0 || $groupItem == -1 )
461 $group = -1;
462 else
463 $group = $groupItem;
464
465 eZObjectPermission::setPermission( $group, $objectID, "filemanager_folder", $permission );
466 // print "set: " . $group . " - " . $objectID . " - " . $permission . "<br>";
467 }
468 }
469 }
470
471 // get all the files and folders of a folder recursivly.
472 // obsolete, kept since we might need it sometime later if we decide to extend the permissions system again.
473 function getFilesAndFolders( &$folderArray, &$fileArray, $fromFolder )
474 {
475 $result = eZVirtualFolder::getByParent( $fromFolder );
476 $folderArray = array_merge( $result, $folderArray );
477 $files = $fromFolder->files( "time", -1, -1 );
478 $fileArray = array_merge( $files, $fileArray );
479
480 foreach ( $result as $child )
481 {
482 getFilesAndFolders( $folderArray, $fileArray, $child );
483 }
484 }
485
486 ?>
$Description
$Description
Definition: articlelistrss.php:38
$files
$files
Definition: articlepreview.php:91
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
eZPermission\checkPermission
static checkPermission( $user, $moduleName, $permissionName)
Definition: ezpermission.php:430
eZSection\getAll
static getAll( $offset=0, $limit=40)
Definition: ezsection.php:177
eZTemplate
Definition: eztemplate.php:107
eZUserGroup
Definition: ezusergroup.php:66
eZUser\currentUser
static & currentUser()
Definition: ezuser.php:896
eZVirtualFolder
Definition: ezvirtualfolder.php:43
eZVirtualFolder\getByParent
& getByParent( $parent)
Definition: ezvirtualfolder.php:241
eZVirtualFolder\isOwner
static isOwner( $user, $folderID)
Definition: ezvirtualfolder.php:421
$result
$result
Definition: companysearch.php:94
$Action
$Action
Definition: companysearch.php:80
$permission
$permission
Definition: eventedit.php:315
$SectionID
$SectionID
Definition: ezfilemanager/user/filelist.php:46
$groups
$groups
Definition: ezfilemanager/user/folderedit.php:341
$ini
if(isset( $NewFolder)) if(isset( $FolderID) && $FolderID !=0 &&!eZObjectPermission::hasPermission( $FolderID, "filemanager_folder", 'w') &&!eZVirtualFolder::isOwner( $user, $FolderID)) if(isset( $Cancel)) $ini
Definition: ezfilemanager/user/folderedit.php:77
getFilesAndFolders
getFilesAndFolders(&$folderArray, &$fileArray, $fromFolder)
Definition: ezfilemanager/user/folderedit.php:473
$t
$t
Definition: ezfilemanager/user/folderedit.php:82
$descriptionCheck
$descriptionCheck
Definition: ezfilemanager/user/folderedit.php:103
$user
$user
Definition: ezfilemanager/user/folderedit.php:41
$Language
$Language
Definition: ezfilemanager/user/folderedit.php:79
$group
if(count( $folderList)==0) $group
Definition: ezfilemanager/user/folderedit.php:340
$permissionCheck
$permissionCheck
Definition: ezfilemanager/user/folderedit.php:101
$nameCheck
$nameCheck
Definition: ezfilemanager/user/folderedit.php:102
$folderList
$folderList
Definition: ezfilemanager/user/folderedit.php:330
changePermissions
changePermissions( $objectID, $groups, $permission)
Definition: ezfilemanager/user/folderedit.php:453
$folder
if( $Action=="New"|| $error) if( $Action=="Edit") $folder
Definition: ezfilemanager/user/folderedit.php:328
$error
$error
Definition: ezfilemanager/user/folderedit.php:100
$sectionList
foreach( $groups as $group) $sectionList
Definition: ezfilemanager/user/folderedit.php:389
$section
$section
Definition: ezimagecatalogue/user/categoryedit.php:393
$ParentID
$ParentID
Definition: eztrade/admin/categorylist.php:171
exit
exit
Definition: folder.php:81
$Name
$Name
Definition: polledit.php:250
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.