Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

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