Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

ezimagecatalogue/user/categoryedit.php
Go to the documentation of this file.
1 <?php
3 //
4 // $Id: categoryedit.php 9450 2002-04-22 12:58:55Z jhe $
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
28 // include_once( "classes/INIFile.php" );
29 // include_once( "classes/eztemplate.php" );
30 // include_once( "classes/ezlog.php" );
31 // include_once( "classes/ezhttptool.php" );
32
33 // include_once( "ezuser/classes/ezuser.php" );
34 // include_once( "ezuser/classes/ezpermission.php" );
35 // include_once( "ezuser/classes/ezobjectpermission.php" );
36
37 // include_once( "ezimagecatalogue/classes/ezimage.php" );
38 // include_once( "ezimagecatalogue/classes/ezimagecategory.php" );
39
40 // include_once( "ezsitemanager/classes/ezsection.php" );
41
42 if ( isset( $Cancel ) )
43 {
44 eZHTTPTool::header( "Location: /imagecatalogue/image/list/" );
45 exit();
46 }
47
48 $user =& eZUser::currentUser();
49
50 if ( !$user )
51 {
52 eZHTTPTool::header( "Location: /error/403/" );
53 exit();
54 }
55
56 $ini =& eZINI::instance( 'site.ini' );
57
58 $Language = $ini->variable( "eZImageCatalogueMain", "Language" );
59
60 $t = new eZTemplate( "kernel/ezimagecatalogue/user/" . $ini->variable( "eZImageCatalogueMain", "TemplateDir" ),
61 "kernel/ezimagecatalogue/user/intl/", $Language, "categoryedit.php" );
62
63 $t->set_file( "category_edit_tpl", "categoryedit.tpl" );
64
65 $t->setAllStrings();
66
67 $t->set_block( "category_edit_tpl", "value_tpl", "value" );
68 $t->set_block( "category_edit_tpl", "errors_tpl", "errors" );
69
70 $t->set_block( "category_edit_tpl", "write_group_item_tpl", "write_group_item" );
71 $t->set_block( "category_edit_tpl", "read_group_item_tpl", "read_group_item" );
72 $t->set_block( "category_edit_tpl", "upload_group_item_tpl", "upload_group_item" );
73
74 $t->set_var( "errors", "" );
75 $t->set_var( "category_name", "$Name" );
76 $t->set_var( "category_description", "$Description" );
77
78 $t->set_block( "errors_tpl", "error_write_permission", "error_write" );
79 $t->set_var( "error_write", "" );
80
81 $t->set_block( "errors_tpl", "error_name_tpl", "error_name" );
82 $t->set_var( "error_name", "&nbsp;" );
83
84 $t->set_block( "errors_tpl", "error_parent_check_tpl", "error_parent_check" );
85 $t->set_var( "error_parent_check", "&nbsp;" );
86
87 $t->set_block( "errors_tpl", "error_description_tpl", "error_description" );
88 $t->set_var( "error_description", "&nbsp;" );
89
90 $t->set_block( "errors_tpl", "error_read_everybody_permission_tpl", "error_read_everybody_permission" );
91 $t->set_var( "error_read_everybody_permission", "&nbsp;" );
92
93 $t->set_block( "errors_tpl", "error_write_everybody_permission_tpl", "error_write_everybody_permission" );
94 $t->set_var( "error_write_everybody_permission", "&nbsp;" );
95
96 $error = false;
97 $permissionCheck = true;
98 $nameCheck = true;
99 $descriptionCheck = true;
100
101 if ( $Action == "Insert" || $Action == "Update" )
102 {
103 // Check if the user have write access to the category
104 if ( $permissionCheck )
105 {
106 // Parent is null, need only check for write to root
107 if ( $ParentID == 0 )
108 {
109 if ( !eZPermission::checkPermission( $user, "eZImageCatalogue", "WriteToRoot" ) )
110 $error = true;
111 }
112 else
113 {
114 // new category, check parent permissions
115 if ( $CategoryID == 0 && !eZObjectPermission::hasPermission( $ParentID, "imagecatalogue_category", "w", $user ) &&
116 !eZObjectPermission::hasPermission( $ParentID, "imagecatalogue_category", 'u', $user ) )
117 $error = true;
118
119 if ( $Action == "Update" && !eZObjectPermission::hasPermission( $CategoryID, "imagecatalogue_category", 'w' ) &&
120 eZImageCategory::isOwner($user, $CategoryID) )
121 $error = true;
122 }
123 if ( $error )
124 $t->parse( "error_write", "error_write_permission" );
125 }
126
127 // Check if parent is the same as category.
128 if ( $Action == "Update" )
129 {
130 if ( $ParentID == $CategoryID )
131 {
132 $t->parse( "error_parent_check", "error_parent_check_tpl" );
133 $error = true;
134 }
135 }
136
137 // Check if name is empty.
138 if ( $nameCheck )
139 {
140 if ( empty( $Name ) )
141 {
142 $t->parse( "error_name", "error_name_tpl" );
143 $error = true;
144 }
145 }
146
147 // Check if description is empty.
148 if ( $descriptionCheck )
149 {
150 if ( empty( $Description ) )
151 {
152 $t->parse( "error_description", "error_description_tpl" );
153 $error = true;
154 }
155 }
156
157 // Check if there was any errors.
158
159 if ( $error )
160 {
161 $t->parse( "errors", "errors_tpl" );
162 }
163 }
164
165 // Insert or update a category
166 if ( ( $Action == "Insert" || $Action == "Update" ) && $error == false )
167 {
168 if ( $Action == "Insert" )
169 {
170 $category = new eZImageCategory();
171 $category->setUser( $user );
172 }
173 else
174 {
175 $category = new eZImageCategory( $CategoryID );
176 }
177
178 $category->setName( $Name );
179 $category->setDescription( $Description );
180
181
182 $parent = new eZImageCategory( $ParentID );
183 $category->setParent( $parent );
184
185 // Set section id.
186 if ( $ParentID > 0 )
187 {
188 $sectionID = $parent->sectionID( $ParentID );
189 }
190 else
191 {
192 $sectionID = $ini->variable( "eZImageCatalogueMain", "DefaultSection" );
193 }
194 $category->setSectionID( $sectionID );
195
196 $category->store();
197 $CategoryID = $category->id();
198 changePermissions( $CategoryID, $ReadGroupArrayID, 'r' );
199 changePermissions( $CategoryID, $WriteGroupArrayID, 'w' );
200 changePermissions( $CategoryID, $UploadGroupArrayID, 'u' );
201
202 // check if user uploaded a dir and had upload permission only and is not owner.
203 if ( $Action == "Insert" && eZObjectPermission::hasPermission( $ParentID, "imagecatalogue_category", 'w' ) == false &&
204 $parent->user( false ) != $user->id() )
205 {
206 changePermissions( $CategoryID, eZObjectPermission::getGroups( $ParentID, "imagecatalogue_category", 'r', false ), 'r' );
207 changePermissions( $CategoryID, eZObjectPermission::getGroups( $ParentID, "imagecatalogue_category", 'w', false ), 'w' );
208 changePermissions( $CategoryID, eZObjectPermission::getGroups( $ParentID, "imagecatalogue_category", 'u', false ), 'u' );
209 $category->setUser( $parent->user() );
210 $category->store();
211 }
212 // if update and moving into a category that has upload permission and not owner of that category
213 // TODO: this part has to be extended on imagefolder to support images in multiple categories..
214 // update is not possible anymore...
215 /*
216 if ( $Action == "Update" && eZObjectPermission::hasPermission( $ParentID, "imagecatalogue_category", 'w' ) == false
217 && $parent->user( false ) != $user->id() )
218 {
219 // recursivly edit permissions on all file and folders...
220 $categories = array();
221 $categories[] = $folder; // set permission on self.
222 $images = array();
223 getImagesAndCategories( $categories, $images, $category );
224
225 // set permissions on all these files and dirs..
226 foreach ( $categories as $categoryItem )
227 {
228 eZObjectPermission::removePermissions( $categoryItem->id(), "imagecatalogue_category", 'w' ); // no write
229 eZObjectPermission::removePermissions( $categoryItem->id(), "imagecatalogue_category", 'r' ); // all read
230 eZObjectPermission::removePermissions( $categoryItem->id(), "imagecatalogue_category", 'u' ); // all upload
231 eZObjectPermission::setPermission( -1, $categoryItem->id(), "imagecatalogue_category", 'r' );
232 eZObjectPermission::setPermission( -1, $categoryItem->id(), "imagecatalogue_category", 'u' );
233 $categoryItem->setUser( $parent->user() );
234 $categoryItem->store();
235 }
236 foreach ( $images as $imageItem )
237 {
238 eZObjectPermission::removePermissions( $imageItem->id(), "imagecatalogue_image", 'w' ); // no write
239 eZObjectPermission::removePermissions( $imageItem->id(), "imagecatalogue_image", 'r' ); // all read
240 eZObjectPermission::setPermission( -1, $imageItem->id(), "imagecatalogue_image", 'r' );
241 $imageItem->setUser( $parent->user() );
242 $imageItem->store();
243 }
244 }
245 */
246 eZHTTPTool::header( "Location: /imagecatalogue/image/list/$ParentID" );
247 exit();
248 }
249
250 // Delete the selected categories.
251 if ( $Action == "Delete" && $error == false )
252 {
253 if ( count( $CategoryArrayID ) > 0 )
254 {
255 foreach ( $CategoryArrayID as $CategoryID )
256 {
257 $category = new eZImageCategory( $CategoryID );
258 $category->delete();
259 }
260 }
261 }
262
263 // Insert default values when creating a new category.
264 if ( $Action == "New" || $error )
265 {
266 $t->set_var( "action_value", "insert" );
267 $t->set_var( "category_id", "" );
268 $readGroupArrayID[0] = -1;
269 $writeGroupArrayID[0] = -1;
270 $uploadGroupArrayID[0] = -1;
271 }
272
273 // Insert the category values when editing.
274 if ( $Action == "Edit" )
275 {
276 $category = new eZImageCategory( $CategoryID );
277
278 $t->set_var( "category_name", $category->name() );
279 $t->set_var( "category_id", $category->id() );
280 $t->set_var( "category_description", $category->description() );
281
282 $parent =& $category->parent();
283 $sectionID = $category->sectionID();
284 if ( $parent )
285 $CurrentCategoryID = $parent->id();
286
287 $t->set_var( "action_value", "update" );
288
289 $readGroupArrayID =& eZObjectPermission::getGroups( $category->id(), "imagecatalogue_category", "r", false );
290 $writeGroupArrayID =& eZObjectPermission::getGroups( $category->id(), "imagecatalogue_category", "w", false );
291 $uploadGroupArrayID =& eZObjectPermission::getGroups( $category->id(), "imagecatalogue_category", "u", false );
292 }
293
294 // Print out all the groups.
295 $groups = eZUserGroup::getAll();
296 foreach ( $groups as $group )
297 {
298 $t->set_var( "group_id", $group->id() );
299 $t->set_var( "group_name", $group->name() );
300
301 $t->set_var( "is_write_selected1", "" );
302 $t->set_var( "is_read_selected1", "" );
303 $t->set_var( "is_upload_selected1", "" );
304
305 if ( in_array( $group->id(), $readGroupArrayID ) )
306 {
307 $t->set_var( "is_read_selected1", "selected" );
308 }
309 elseif ( in_array( -1, $readGroupArrayID ) )
310 {
311 $t->set_var( "read_everybody", "selected" );
312 }
313 else
314 {
315 $t->set_var( "is_read_selected1", "" );
316 }
317 $t->parse( "read_group_item", "read_group_item_tpl", true );
318
319 if ( in_array( $group->id(), $writeGroupArrayID ) )
320 {
321 $t->set_var( "is_write_selected1", "selected" );
322 }
323 elseif ( in_array( -1, $writeGroupArrayID ) )
324 {
325 $t->set_var( "write_everybody", "selected" );
326 }
327 else
328 {
329 $t->set_var( "is_write_selected1", "" );
330 }
331 $t->parse( "write_group_item", "write_group_item_tpl", true );
332
333 if ( in_array( $group->id(), $uploadGroupArrayID ) )
334 {
335 $t->set_var( "is_upload_selected1", "selected" );
336 }
337 elseif ( in_array( -1, $uploadGroupArrayID ) )
338 {
339 $t->set_var( "upload_everybody", "selected" );
340 }
341 else
342 {
343 $t->set_var( "is_upload_selected1", "" );
344 }
345 $t->parse( "upload_group_item", "upload_group_item_tpl", true );
346 }
347
348 $category = new eZImageCategory() ;
349
350 $categoryList =& $category->getTree( );
351
352 if ( count( $categoryList ) == 0 )
353 {
354 $t->set_var( "value", "" );
355 }
356
357 // Print out the categories.
358 foreach ( $categoryList as $categoryItem )
359 {
360 if ( eZObjectPermission::hasPermission( $categoryItem[0]->id(), "imagecatalogue_category", 'w' ) ||
361 eZObjectPermission::hasPermission( $categoryItem[0]->id(), "imagecatalogue_category", 'u' ) ||
362 eZImageCategory::isOwner( eZUser::currentUser(), $categoryItem[0]->id() ) )
363 {
364 $t->set_var( "option_name", $categoryItem[0]->name() );
365 $t->set_var( "option_value", $categoryItem[0]->id() );
366
367 if ( $categoryItem[1] > 0 )
368 $t->set_var( "option_level", str_repeat( "&nbsp;", $categoryItem[1] ) );
369 else
370 $t->set_var( "option_level", "" );
371
372 $t->set_var( "is_selected", "" );
373
374 if ( $CurrentCategoryID != 0 )
375 {
376 if ( $categoryItem[0]->id() == $CurrentCategoryID )
377 {
378 $t->set_var( "is_selected", "selected" );
379 }
380 else
381 {
382 $t->set_var( "is_selected", "" );
383 }
384 }
385
386 $t->parse( "value", "value_tpl", true );
387 }
388 }
389
390 if ( !$sectionID )
391 $sectionID = $ini->variable( "eZImageCatalogueMain", "DefaultSection" );
392
393 $section = new eZSection( $sectionID );
394 $t->set_var( "section_name", $section->name() );
395
396 $t->pparse( "output", "category_edit_tpl" );
397
398 /******* FUNCTIONS ****************************/
399 function changePermissions( $objectID, $groups, $permission )
400 {
401 eZObjectPermission::removePermissions( $objectID, "imagecatalogue_category", $permission );
402 if ( count( $groups ) > 0 )
403 {
404 foreach ( $groups as $groupItem )
405 {
406 if ( $groupItem == 0 )
407 $group = -1;
408 else
409 $group = new eZUserGroup( $groupItem );
410
411 eZObjectPermission::setPermission( $group, $objectID, "imagecatalogue_category", $permission );
412 }
413 }
414 }
415
416 // get all the images and categories of a category recursivly.
417 function getImagesAndCategores( &$folderArray, &$fileArray, $fromFolder )
418 {
419 $result = eZImageCatalogue::getByParent( $fromFolder );
420 $folderArray = array_merge( $result, $folderArray );
421 $files = $fromFolder->images();
422 $fileArray = array_merge( $files, $fileArray );
423
424 foreach ( $result as $child )
425 {
426 getImagesAndCategories( $folderArray, $fileArray, $child );
427 }
428 }
429
430 ?>
$CategoryID
$CategoryID
Definition: admin/articleedit.php:53
$group
$group
Definition: admin/articleedit.php:799
$Description
$Description
Definition: articlelistrss.php:38
$files
$files
Definition: articlepreview.php:91
eZHTTPTool\header
static header( $string)
Definition: ezhttptool.php:96
eZImageCategory
Definition: ezimagecategory.php:43
eZImageCategory\isOwner
static isOwner( $user, $imageCategory=false)
Definition: ezimagecategory.php:480
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
Definition: ezsection.php:45
eZTemplate
Definition: eztemplate.php:107
eZUserGroup
Definition: ezusergroup.php:66
eZUserGroup\getAll
static & getAll( $as_object=true)
Definition: ezusergroup.php:197
eZUser\currentUser
static & currentUser()
Definition: ezuser.php:896
$result
$result
Definition: companysearch.php:94
$Action
$Action
Definition: companysearch.php:80
$permission
$permission
Definition: eventedit.php:315
getImagesAndCategories
getImagesAndCategories(&$folderArray, &$fileArray, $fromFolder)
Definition: ezimagecatalogue/admin/categoryedit.php:446
$CurrentCategoryID
$CurrentCategoryID
Definition: ezimagecatalogue/admin/imageedit.php:35
$user
if(isset( $Cancel)) $user
Definition: ezimagecatalogue/user/categoryedit.php:48
$t
$t
Definition: ezimagecatalogue/user/categoryedit.php:60
$descriptionCheck
$descriptionCheck
Definition: ezimagecatalogue/user/categoryedit.php:99
$groups
if( $Action=="Insert"|| $Action=="Update") if(( $Action=="Insert"|| $Action=="Update") && $error==false) if( $Action=="Delete" && $error==false) if( $Action=="New"|| $error) if( $Action=="Edit") $groups
Definition: ezimagecatalogue/user/categoryedit.php:295
$ini
if(! $user) $ini
Definition: ezimagecatalogue/user/categoryedit.php:56
$category
foreach( $groups as $group) $category
Definition: ezimagecatalogue/user/categoryedit.php:348
getImagesAndCategores
getImagesAndCategores(&$folderArray, &$fileArray, $fromFolder)
Definition: ezimagecatalogue/user/categoryedit.php:417
$Language
$Language
Definition: ezimagecatalogue/user/categoryedit.php:58
$permissionCheck
$permissionCheck
Definition: ezimagecatalogue/user/categoryedit.php:97
$nameCheck
$nameCheck
Definition: ezimagecatalogue/user/categoryedit.php:98
$categoryList
$categoryList
Definition: ezimagecatalogue/user/categoryedit.php:350
$section
$section
Definition: ezimagecatalogue/user/categoryedit.php:393
changePermissions
changePermissions( $objectID, $groups, $permission)
Definition: ezimagecatalogue/user/categoryedit.php:399
$error
$error
Definition: ezimagecatalogue/user/categoryedit.php:96
$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+.