| [ Index ] |
|
Code source de b2evolution 2.1.0-beta |
1 <?php 2 /** 3 * This file implements ther UI controler for chapters management. 4 * 5 * This file is part of the evoCore framework - {@link http://evocore.net/} 6 * See also {@link http://sourceforge.net/projects/evocms/}. 7 * 8 * @copyright (c)2003-2007 by Francois PLANQUE - {@link http://fplanque.net/} 9 * Parts of this file are copyright (c)2005-2006 by PROGIDISTRI - {@link http://progidistri.com/}. 10 * 11 * {@internal License choice 12 * - If you have received this file as part of a package, please find the license.txt file in 13 * the same folder or the closest folder above for complete license terms. 14 * - If you have received this file individually (e-g: from http://evocms.cvs.sourceforge.net/) 15 * then you must choose one of the following licenses before using the file: 16 * - GNU General Public License 2 (GPL) - http://www.opensource.org/licenses/gpl-license.php 17 * - Mozilla Public License 1.1 (MPL) - http://www.opensource.org/licenses/mozilla1.1.php 18 * }} 19 * 20 * @package admin 21 * 22 * {@internal Below is a list of authors who have contributed to design/coding of this file: }} 23 * @author fplanque: Francois PLANQUE. 24 * 25 * @version $Id: chapters.ctrl.php,v 1.4 2007/09/04 13:47:48 fplanque Exp $ 26 */ 27 if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' ); 28 29 30 if( valid_blog_requested() ) 31 { 32 $current_User->check_perm( 'blog_cats', 'edit', true, $blog ); 33 $edited_Blog = & $Blog; 34 } 35 else 36 { 37 $action = 'nil'; 38 } 39 40 $AdminUI->set_path( 'blogs', 'chapters' ); 41 42 43 /** 44 * Delete restrictions 45 */ 46 $delete_restrictions = array( 47 array( 'table'=>'T_categories', 'fk'=>'cat_parent_ID', 'msg'=>T_('%d sub categories') ), 48 array( 'table'=>'T_items__item', 'fk'=>'post_main_cat_ID', 'msg'=>T_('%d posts within category through main cat') ), 49 array( 'table'=>'T_postcats', 'fk'=>'postcat_cat_ID', 'msg'=>T_('%d posts within category through extra cat') ), 50 ); 51 52 $restrict_title = T_('Cannot delete category'); //«%s» 53 54 // mb> Used to know if the element can be deleted, so to display or not display confirm delete dialog (true:display, false:not display) 55 // It must be initialized to false before checking the delete restrictions 56 $checked_delete = false; 57 58 load_class( 'chapters/model/_chaptercache.class.php' ); 59 $GenericCategoryCache = & new ChapterCache(); 60 61 62 /** 63 * Display page header, menus & messages: 64 */ 65 $blogListButtons = $AdminUI->get_html_collection_list( 'blog_cats', 'edit', 66 '?ctrl='.$ctrl.'&blog=%d', 67 T_('List'), '?ctrl=collections&blog=0' ); 68 69 // Restrict to chapters of the specific blog: 70 $subset_ID = $blog; 71 72 $list_view_path = 'chapters/views/_chapter_list.view.php'; 73 $permission_to_edit = $current_User->check_perm( 'blog_cats', '', false, $blog ); 74 75 // The form will be on its own page: 76 $form_below_list = false; 77 $edit_view_path = 'chapters/views/_chapter.form.php'; 78 79 80 81 // fp> TODO: Detect and repair orphan cats. 82 83 84 85 // ---- Below is a modified generic categtory list editor: ----- 86 87 88 // fp> this is an example of where we could benefit from controler classes wich could be derived 89 // fp> we basically need to add a "move" action. 90 /* 91 class Controler 92 { 93 method get_params() // and init object 94 method do_action() 95 method display_payload() 96 } 97 the $AdminUI->foo() structural calls would move to the dispatcher. 98 */ 99 // fp> TODO: find 4 other cases before refactoring this way. (fp) 100 101 param( 'action', 'string', 'list' ); 102 103 // Init fadeout result array: 104 $result_fadeout = array(); 105 106 if( param( $GenericCategoryCache->dbIDname, 'integer', NULL, true, false, false ) ) 107 { 108 if( ($edited_GenericCategory = & $GenericCategoryCache->get_by_ID( ${$GenericCategoryCache->dbIDname}, false, true, $subset_ID )) === false ) 109 { // We could not find the element to edit: 110 unset( $edited_GenericCategory ); 111 $Messages->head = T_('Cannot edit element!'); 112 $Messages->add( T_('Requested element does not exist any longer.'), 'error' ); 113 $action = 'nil'; 114 } 115 } 116 117 if( !is_null( param( $GenericCategoryCache->dbprefix.'parent_ID', 'integer', NULL ) ) ) 118 { 119 if( ( $edited_parent_GenericElement = & $GenericCategoryCache->get_by_ID( ${$GenericCategoryCache->dbprefix.'parent_ID'}, false, true, $subset_ID ) ) === false ) 120 { // Parent generic category doesn't exist any longer. 121 unset( $GenericCategoryCache->dbIDname ); 122 $Messages->head = T_('Cannot edit element!'); 123 $Messages->add( T_('Requested element does not exist any longer.'), 'error' ); 124 $action = 'nil'; 125 } 126 } 127 128 // Init fadeout result array of IDs: 129 $result_fadeout = array(); 130 131 /** 132 * Check locked elements 133 */ 134 if( !empty( $locked_IDs ) 135 && in_array( $action, array( 'edit', 'update', 'delete' ) ) 136 && in_array( $$GenericCategoryCache->dbIDname, $locked_IDs ) ) 137 { 138 $Messages->add( T_('This element is locked and cannot be edited!') ); 139 $action = 'list'; 140 } 141 142 143 /** 144 * Perform action: 145 */ 146 switch( $action ) 147 { 148 case 'new': 149 // New action 150 151 if( ! $permission_to_edit ) 152 { 153 debug_die( 'No permission to edit' ); 154 } 155 156 $edited_GenericCategory = & $GenericCategoryCache->new_obj( NULL, $subset_ID ); 157 158 if( isset( $edited_parent_GenericElement ) ) 159 { 160 $edited_GenericCategory->parent_ID = $edited_parent_GenericElement->ID; 161 $edited_GenericCategory->parent_name = $edited_parent_GenericElement->name; 162 } 163 else 164 { 165 $edited_GenericCategory->parent_name = T_('Root'); 166 } 167 168 break; 169 170 171 case 'move': // EXTENSION 172 if( ! $Settings->get('allow_moving_chapters') ) 173 { 174 debug_die( 'Moving of chapters is disabled' ); 175 } 176 /* NO BREAK */ 177 case 'edit': 178 // Edit element form...: 179 // Make sure we got an ID: 180 param( $GenericCategoryCache->dbIDname, 'integer', true ); 181 182 if( ! $permission_to_edit ) 183 { 184 debug_die( 'No permission to edit' ); 185 } 186 187 // Get the page number we come from: 188 $previous_page = param( 'results'.$GenericCategoryCache->dbprefix.'page', 'integer', 1, true ); 189 190 break; 191 192 193 case 'create': 194 // Insert new element...: 195 196 if( ! $permission_to_edit ) 197 { 198 debug_die( 'No permission to edit' ); 199 } 200 201 $edited_GenericCategory = & $GenericCategoryCache->new_obj( NULL, $subset_ID ); 202 203 // load data from request 204 if( $edited_GenericCategory->load_from_Request() ) 205 { // We could load data from form without errors: 206 // Insert in DB: 207 if( $edited_GenericCategory->dbinsert() !== false ) 208 { 209 $Messages->add( T_('New element created.'), 'success' ); // TODO CHANGES THIS 210 // Add the ID of the new element to the result fadeout 211 $result_fadeout[$edited_GenericCategory->dbIDname][] = $edited_GenericCategory->ID; 212 $action = 'list'; 213 } 214 } 215 break; 216 217 218 case 'update': 219 // Make sure we got an ID: 220 param( $GenericCategoryCache->dbIDname, 'integer', true ); 221 222 if( ! $permission_to_edit ) 223 { 224 debug_die( 'No permission to edit' ); 225 } 226 227 // LOAD FORM DATA: 228 if( $edited_GenericCategory->load_from_Request() ) 229 { // We could load data from form without errors: 230 // Update in DB: 231 if( $edited_GenericCategory->dbupdate() !== false ) 232 { 233 $Messages->add( T_('Element updated.'), 'success' ); //ToDO change htis 234 } 235 // Add the ID of the updated element to the result fadeout 236 $result_fadeout[$edited_GenericCategory->dbIDname][] = $edited_GenericCategory->ID; 237 $action = 'list'; 238 } 239 else 240 { 241 // Get the page number we come from: 242 $previous_page = param( 'results'.$GenericCategoryCache->dbprefix.'page', 'integer', 1, true ); 243 } 244 break; 245 246 247 case 'update_move': 248 // EXTENSION 249 if( ! $Settings->get('allow_moving_chapters') ) 250 { 251 debug_die( 'Moving of chapters is disabled' ); 252 } 253 254 // Make sure we got an ID: 255 param( $GenericCategoryCache->dbIDname, 'integer', true ); 256 257 // Control permission to edit source blog: 258 $edited_Blog = & $edited_GenericCategory->get_Blog(); 259 if( ! $current_User->check_perm( 'blog_cats', '', false, $edited_Blog->ID ) ) 260 { 261 debug_die( 'No permission to edit source collection.' ); 262 /* die */ 263 } 264 265 // Control permission to edit destination blog: 266 param( 'cat_coll_ID', 'integer', true ); 267 if( ! $current_User->check_perm( 'blog_cats', '', false, $cat_coll_ID ) ) 268 { 269 // fp> TODO: prevent move in UI. 270 $Messages->add( 'No permission to edit destination blog.', 'error' ); // NO TRANS b/c temporary 271 break; 272 } 273 274 if( $cat_coll_ID == $edited_Blog->ID ) 275 { 276 $Messages->add( T_('Category has not been moved.'), 'note' ); 277 break; 278 } 279 280 // Do the actual move! (This WILL reset the cache!) 281 $GenericCategoryCache->move_Chapter_subtree( $edited_GenericCategory->ID, $subset_ID, $cat_coll_ID ); 282 283 $dest_Blog = & $BlogCache->get_by_ID( $cat_coll_ID ); 284 $Messages->add( sprintf( T_('The category «%s» has been moved (with children) to «%s»\'s root. You may want to nest it in another parent category below...'), $edited_GenericCategory->dget('name'), $dest_Blog->dget( 'shortname' ) ), 'success' ); 285 286 header_redirect( url_add_param( $admin_url, 'ctrl=chapters&action=edit&blog='.$cat_coll_ID.'&cat_ID='.$cat_ID, '&' ) ); // will save $Messages 287 /* EXIT */ 288 289 // In case we changed the redirect someday: 290 unset($edited_GenericCategory); 291 $cat_ID = NULL; 292 $action = 'list'; 293 break; 294 295 296 case 'delete': 297 // Delete entry: 298 param( $GenericCategoryCache->dbIDname, 'integer', true ); 299 300 if( ! $permission_to_edit ) 301 { 302 debug_die( 'No permission to edit' ); 303 } 304 305 // Set restrictions for element 306 $edited_GenericCategory->delete_restrictions = $delete_restrictions; 307 308 if( param( 'confirm', 'integer', 0 ) ) 309 { // confirmed, Delete from DB: 310 $msg = sprintf( T_('Element «%s» deleted.'), $edited_GenericCategory->dget( 'name' ) ); 311 $GenericCategoryCache->dbdelete_by_ID( $edited_GenericCategory->ID ); 312 unset($edited_GenericCategory); 313 forget_param( $GenericCategoryCache->dbIDname ); 314 $Messages->add( $msg, 'success' ); 315 $action = 'list'; 316 } 317 else 318 { // not confirmed, Check for restrictions: 319 // Get the page number we come from: 320 $previous_page = param( 'results_'.$GenericCategoryCache->dbprefix.'page', 'integer', 1, true ); 321 if( ! $edited_GenericCategory->check_delete( sprintf( T_('Cannot delete element «%s»'), $edited_GenericCategory->dget( 'name' ) ) ) ) 322 { // There are restrictions: 323 $action = 'edit'; 324 } 325 } 326 break; 327 328 } 329 330 331 // Display <html><head>...</head> section! (Note: should be done early if actions do not redirect) 332 $AdminUI->disp_html_head(); 333 334 // Display title, menu, messages, etc. (Note: messages MUST be displayed AFTER the actions) 335 $AdminUI->disp_body_top(); 336 337 338 /** 339 * Display payload: 340 */ 341 switch( $action ) 342 { 343 case 'nil': 344 // Do nothing 345 break; 346 347 case 'move': 348 // EXTENSION TO GENERIC: 349 // Move to another blog: 350 // Begin payload block: 351 $AdminUI->disp_payload_begin(); 352 353 $AdminUI->disp_view( 'chapters/views/_chapter_move.form.php' ); 354 355 // End payload block: 356 $AdminUI->disp_payload_end(); 357 break; 358 359 case 'new': 360 case 'copy': 361 case 'create': 362 case 'edit': 363 case 'update': 364 case 'delete': 365 // Begin payload block: 366 $AdminUI->disp_payload_begin(); 367 368 if( $action == 'delete' ) 369 { // We need to ask for confirmation: 370 $edited_GenericCategory->confirm_delete( 371 sprintf( T_('Delete element «%s»?'), $edited_GenericCategory->dget( 'name' ) ), 372 $action, get_memorized( 'action' ) ); 373 } 374 375 if( $form_below_list ) 376 { 377 // Display list VIEW before form view: 378 if( !empty( $list_view_path ) ) 379 { 380 $AdminUI->disp_view( $list_view_path ); 381 } 382 else 383 { 384 $AdminUI->disp_view( 'generic/_generic_recursive_list.inc.php' ); 385 } 386 } 387 388 // Display category edit form: 389 if( !empty( $edit_view_path ) ) 390 { 391 $AdminUI->disp_view( $edit_view_path ); 392 } 393 else 394 { 395 $AdminUI->disp_view( 'generic/_generic_category.form.php' ); 396 } 397 398 // End payload block: 399 $AdminUI->disp_payload_end(); 400 break; 401 402 case 'list': 403 default: 404 // Begin payload block: 405 $AdminUI->disp_payload_begin(); 406 407 // Display list VIEW: 408 if( !empty( $list_view_path ) ) 409 { 410 $AdminUI->disp_view( $list_view_path ); 411 } 412 else 413 { 414 $AdminUI->disp_view( 'generic/_generic_recursive_list.inc.php' ); 415 } 416 417 // End payload block: 418 $AdminUI->disp_payload_end(); 419 break; 420 } 421 422 423 // Display body bottom, debug info and close </html>: 424 $AdminUI->disp_global_footer(); 425 426 427 /* 428 * $Log: chapters.ctrl.php,v $ 429 * Revision 1.4 2007/09/04 13:47:48 fplanque 430 * fixed fadeout 431 * 432 * Revision 1.3 2007/09/04 13:33:26 fplanque 433 * Fixed display for category screen. 434 * 435 * Revision 1.1 2007/06/25 10:59:24 fplanque 436 * MODULES (refactored MVC) 437 * 438 * Revision 1.19 2007/05/14 02:43:03 fplanque 439 * Started renaming tables. There probably won't be a better time than 2.0. 440 * 441 * Revision 1.18 2007/05/13 18:49:54 fplanque 442 * made autoselect_blog() more robust under PHP4 443 * 444 * Revision 1.17 2007/05/09 01:01:29 fplanque 445 * permissions cleanup 446 * 447 * Revision 1.16 2007/04/26 00:11:07 fplanque 448 * (c) 2007 449 * 450 * Revision 1.15 2007/01/07 05:27:41 fplanque 451 * extended fadeout, but still not fixed everywhere 452 * 453 * Revision 1.14 2006/12/18 03:20:41 fplanque 454 * _header will always try to set $Blog. 455 * controllers can use valid_blog_requested() to make sure we have one 456 * controllers should call set_working_blog() to change $blog, so that it gets memorized in the user settings 457 * 458 * Revision 1.13 2006/12/13 18:17:39 blueyed 459 * Fixed header_redirect() which would only work if b2evo is installed in DOCUMENT_ROOT and would not have been RFC-compliant anyway 460 * 461 * Revision 1.12 2006/12/11 16:53:47 fplanque 462 * controller name cleanup 463 * 464 * Revision 1.11 2006/12/11 00:32:26 fplanque 465 * allow_moving_chapters stting moved to UI 466 * chapters are now called categories in the UI 467 * 468 * Revision 1.10 2006/12/10 22:28:33 fplanque 469 * improved moving chapters a little bit 470 * 471 * Revision 1.9 2006/12/10 01:52:27 fplanque 472 * old cats are now officially dead :> 473 * 474 * Revision 1.8 2006/12/09 17:59:31 fplanque 475 * started "moving chapters accross blogs" feature 476 * 477 * Revision 1.7 2006/11/30 22:34:15 fplanque 478 * bleh 479 * 480 * Revision 1.6 2006/11/24 18:27:22 blueyed 481 * Fixed link to b2evo CVS browsing interface in file docblocks 482 */ 483 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
| Généré le : Thu Nov 29 23:58:50 2007 | par Balluche grâce à PHPXref 0.7 |
|