Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

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