phpDocumentor pond
[ class tree: pond ] [ index: pond ] [ all elements ]

Source for file chapters.ctrl.php

Documentation is available at chapters.ctrl.php

  1. <?php
  2. /**
  3.  * This file implements ther UI controler for chapters management.
  4.  *
  5.  * This file is part of Quam Plures - {@link http://quamplures.net/}
  6.  * See also {@link https://launchpad.net/quam-plures}.
  7.  *
  8.  * @copyright (c) 2009 - 2011 by the Quam Plures developers - {@link http://quamplures.net/}
  9.  * @copyright (c)2003-2009 by Francois PLANQUE - {@link http://fplanque.net/}
  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 pond
  21.  */
  22. if!defined('QP_MAIN_INIT') ) die'Please, do not access this page directly.' );
  23.  
  24.  
  25. {
  26.     $current_User->check_perm'blog_cats''edit'true$blog );
  27.     $edited_Blog $Blog;
  28. }
  29. else
  30. {
  31.     $action 'nil';
  32. }
  33.  
  34. $AdminUI->set_path'blogs''chapters' );
  35.  
  36.  
  37. /**
  38.  * Delete restrictions
  39.  */
  40. $delete_restrictions array(
  41.         array'table'=>'T_categories''fk'=>'cat_parent_ID''msg'=>T_('%d sub categories') ),
  42.         array'table'=>'T_items__item''fk'=>'post_main_cat_ID''msg'=>T_('%d posts within category through main cat') ),
  43.         array'table'=>'T_postcats''fk'=>'postcat_cat_ID''msg'=>T_('%d posts within category through extra cat') ),
  44.     );
  45.  
  46. $restrict_title T_('Cannot delete category');     //&laquo;%s&raquo;
  47.  
  48. // This must be initialized to false before checking the delete restrictions
  49. $checked_delete false;
  50.  
  51. load_class'chapters/model/_chaptercache.class.php' );
  52. $GenericCategoryCache new ChapterCache();
  53.  
  54.  
  55. /**
  56.  * Display page header, menus & messages:
  57.  */
  58. $AdminUI->set_coll_list_params'blog_cats''edit',
  59.         array'ctrl' => $ctrl ),    T_('List')'?ctrl=collections&amp;blog=0' );
  60.  
  61. // Restrict to chapters of the specific blog:
  62. $subset_ID $blog;
  63.  
  64. $list_view_path 'chapters/views/_chapter_list.view.php';
  65. $permission_to_edit $current_User->check_perm'blog_cats'''false$blog );
  66.  
  67. // The form will be on its own page:
  68. $form_below_list false;
  69. $edit_view_path 'chapters/views/_chapter.form.php';
  70.  
  71.  
  72. // ---- Below is a modified generic categtory list editor: -----
  73.  
  74.  
  75. // fp> this is an example of where we could benefit from controler classes wich could be derived
  76. // fp> we basically need to add a "move" action.
  77. /*
  78. class Controler
  79. {
  80.     method get_params() // and init object
  81.     method do_action()
  82.     method display_payload()
  83. }
  84. the $AdminUI->foo() structural calls would move to the dispatcher.
  85. */
  86. // fp> TODO: find 4 other cases before refactoring this way. (fp)
  87.  
  88. param'action''string''list' );
  89.  
  90. // Init fadeout result array:
  91. $result_fadeout array();
  92.  
  93. ifparam$GenericCategoryCache->dbIDname'integer'NULLtruefalsefalse ) )
  94. {
  95.     if( ($edited_GenericCategory $GenericCategoryCache->get_by_ID${$GenericCategoryCache->dbIDname}falsetrue$subset_ID )) === false )
  96.     {    // We could not find the element to edit:
  97.         unset$edited_GenericCategory );
  98.         $Messages->head T_('Cannot edit element!');
  99.         $Messages->addT_('Requested element does not exist any longer.')'error' );
  100.         $action 'nil';
  101.     }
  102.  
  103. }
  104.  
  105. if!is_nullparam$GenericCategoryCache->dbprefix.'parent_ID''integer'NULL ) ) )
  106. {
  107.     if( ( $edited_parent_GenericElement $GenericCategoryCache->get_by_ID${$GenericCategoryCache->dbprefix.'parent_ID'}falsetrue$subset_ID ) ) === false )
  108.     // Parent generic category doesn't exist any longer.
  109.         unset$GenericCategoryCache->dbIDname );
  110.         $Messages->head T_('Cannot edit element!');
  111.         $Messages->addT_('Requested element does not exist any longer.')'error' );
  112.         $action 'nil';
  113.     }
  114. }
  115.  
  116. // Init fadeout result array of IDs:
  117. $result_fadeout array();
  118.  
  119. /**
  120.  * Check locked elements
  121.  */
  122. if!empty$locked_IDs )
  123.         && in_array$actionarray'edit''update''delete' ) )
  124.         && in_array$$GenericCategoryCache->dbIDname$locked_IDs ) )
  125. {
  126.     $Messages->addT_('This element is locked and cannot be edited!') );
  127.     $action 'list';
  128. }
  129.  
  130.  
  131. /**
  132.  * Perform action:
  133.  */
  134. switch$action )
  135. {
  136.     case 'new':
  137.         // New action
  138.  
  139.         if$permission_to_edit )
  140.         {
  141.             debug_die'No permission to edit' );
  142.         }
  143.  
  144.         $edited_GenericCategory $GenericCategoryCache->new_objNULL$subset_ID );
  145.  
  146.         ifisset$edited_parent_GenericElement ) )
  147.         {
  148.             $edited_GenericCategory->parent_ID $edited_parent_GenericElement->ID;
  149.             $edited_GenericCategory->parent_name $edited_parent_GenericElement->name;
  150.         }
  151.         else
  152.         {
  153.             $edited_GenericCategory->parent_name T_('Root');
  154.         }
  155.  
  156.         break;
  157.  
  158.  
  159.     case 'move'// EXTENSION
  160.          if$Settings->get('allow_moving_chapters') )
  161.          {
  162.             debug_die'Moving of chapters is disabled' );
  163.         }
  164.         /* NO BREAK */
  165.     case 'edit':
  166.         // Edit element form...:
  167.         // Make sure we got an ID:
  168.         param$GenericCategoryCache->dbIDname'integer'true );
  169.  
  170.         if$permission_to_edit )
  171.         {
  172.             debug_die'No permission to edit' );
  173.         }
  174.  
  175.         // Get the page number we come from:
  176.         $previous_page param'results'.$GenericCategoryCache->dbprefix.'page''integer'1true );
  177.  
  178.         break;
  179.  
  180.  
  181.     case 'create':
  182.         // Insert new element...:
  183.  
  184.         if$permission_to_edit )
  185.         {
  186.             debug_die'No permission to edit' );
  187.         }
  188.  
  189.         $edited_GenericCategory $GenericCategoryCache->new_objNULL$subset_ID );
  190.  
  191.         // load data from request
  192.         if$edited_GenericCategory->load_from_Request() )
  193.         {    // We could load data from form without errors:
  194.             // Insert in DB:
  195.             if$edited_GenericCategory->dbinsert(!== false )
  196.             {
  197.                 $Messages->addT_('New element created.')'success' )// TODO CHANGES THIS
  198.                 // Add the ID of the new element to the result fadeout
  199.                 $result_fadeout[$edited_GenericCategory->dbIDname][$edited_GenericCategory->ID;
  200.                 $action 'list';
  201.             }
  202.         }
  203.         break;
  204.  
  205.  
  206.     case 'update':
  207.         // Make sure we got an ID:
  208.         param$GenericCategoryCache->dbIDname'integer'true );
  209.  
  210.         if$permission_to_edit )
  211.         {
  212.             debug_die'No permission to edit' );
  213.         }
  214.  
  215.         // LOAD FORM DATA:
  216.         if$edited_GenericCategory->load_from_Request() )
  217.         {    // We could load data from form without errors:
  218.             // Update in DB:
  219.             if$edited_GenericCategory->dbupdate(!== false )
  220.             {
  221.                 $Messages->addT_('Element updated.')'success' )//ToDO change htis
  222.             }
  223.             // Add the ID of the updated element to the result fadeout
  224.             $result_fadeout[$edited_GenericCategory->dbIDname][$edited_GenericCategory->ID;
  225.             $action 'list';
  226.         }
  227.         else
  228.         {
  229.             // Get the page number we come from:
  230.             $previous_page param'results'.$GenericCategoryCache->dbprefix.'page''integer'1true );
  231.         }
  232.         break;
  233.  
  234.  
  235.     case 'update_move':
  236.         // EXTENSION
  237.          if$Settings->get('allow_moving_chapters') )
  238.          {
  239.             debug_die'Moving of chapters is disabled' );
  240.         }
  241.  
  242.         // Make sure we got an ID:
  243.         param$GenericCategoryCache->dbIDname'integer'true );
  244.  
  245.         // Control permission to edit source blog:
  246.        $edited_Blog $edited_GenericCategory->get_Blog();
  247.         if$current_User->check_perm'blog_cats'''false$edited_Blog->ID ) )
  248.         {
  249.             debug_die'No permission to edit source collection.' );
  250.             /* die */
  251.         }
  252.  
  253.          // Control permission to edit destination blog:
  254.         param'cat_coll_ID''integer'true );
  255.         if$current_User->check_perm'blog_cats'''false$cat_coll_ID ) )
  256.         {
  257.             // fp> TODO: prevent move in UI.
  258.             $Messages->add'No permission to edit destination blog.''error' );    // NO TRANS b/c temporary
  259.             break;
  260.         }
  261.  
  262.         if$cat_coll_ID == $edited_Blog->ID )
  263.         {
  264.             $Messages->addT_('Category has not been moved.')'note' );
  265.             break;
  266.         }
  267.  
  268.         // Do the actual move! (This WILL reset the cache!)
  269.         $GenericCategoryCache->move_Chapter_subtree$edited_GenericCategory->ID$subset_ID$cat_coll_ID );
  270.  
  271.         $dest_Blog $BlogCache->get_by_ID$cat_coll_ID );
  272.         $Messages->add/* TRANS: first %s is the moved category's name, the second one the new parent category */ sprintfT_('The category &laquo;%s&raquo; has been moved (with children) to &laquo;%s&raquo;\'s root. You may want to nest it in another parent category below...')$edited_GenericCategory->dget('name')$dest_Blog->dget'shortname' )  )'success' );
  273.  
  274.         header_redirecturl_add_param$admin_url'ctrl=chapters&action=edit&blog='.$cat_coll_ID.'&cat_ID='.$cat_ID'&' ) );    // will save $Messages
  275.         /* EXIT */
  276.  
  277.         // In case we changed the redirect someday:
  278.         unset($edited_GenericCategory);
  279.         $cat_ID NULL;
  280.         $action 'list';
  281.         break;
  282.  
  283.  
  284.     case 'delete':
  285.         // Delete entry:
  286.         param$GenericCategoryCache->dbIDname'integer'true );
  287.  
  288.         if$permission_to_edit )
  289.         {
  290.             debug_die'No permission to edit' );
  291.         }
  292.  
  293.         // Set restrictions for element
  294.         $edited_GenericCategory->delete_restrictions $delete_restrictions;
  295.  
  296.         ifparam'confirm''integer') )
  297.         // confirmed, Delete from DB:
  298.             $msg sprintfT_('Element &laquo;%s&raquo; deleted.')$edited_GenericCategory->dget'name' ) );
  299.             $GenericCategoryCache->dbdelete_by_ID$edited_GenericCategory->ID );
  300.             unset($edited_GenericCategory);
  301.             forget_param$GenericCategoryCache->dbIDname );
  302.             $Messages->add$msg'success' );
  303.             $action 'list';
  304.         }
  305.         else
  306.         {    // not confirmed, Check for restrictions:
  307.             // Get the page number we come from:
  308.             $previous_page param'results_'.$GenericCategoryCache->dbprefix.'page''integer'1true );
  309.             if$edited_GenericCategory->check_deletesprintfT_('Cannot delete element &laquo;%s&raquo;')$edited_GenericCategory->dget'name' ) ) ) )
  310.             {    // There are restrictions:
  311.                 $action 'edit';
  312.             }
  313.         }
  314.         break;
  315.  
  316.     case 'make_default':
  317.         if$permission_to_edit )
  318.         {
  319.             debug_die'No permission to edit' );
  320.         }
  321.  
  322.         $edited_Blog->set_setting'default_cat_ID'$edited_GenericCategory->ID );
  323.         $edited_Blog->dbsave();
  324.  
  325.         break;
  326. }
  327.  
  328.  
  329. // Display <html><head>...</head> section! (Note: should be done early if actions do not redirect)
  330. $AdminUI->disp_html_head();
  331.  
  332. // Display title, menu, messages, etc. (Note: messages MUST be displayed AFTER the actions)
  333. $AdminUI->disp_body_top();
  334.  
  335.  
  336. /**
  337.  * Display payload:
  338.  */
  339. switch$action )
  340. {
  341.     case 'nil':
  342.         // Do nothing
  343.         break;
  344.  
  345.     case 'move':
  346.         // EXTENSION TO GENERIC:
  347.         // Move to another blog:
  348.         // Begin payload block:
  349.         $AdminUI->disp_payload_begin();
  350.  
  351.         $AdminUI->disp_view'chapters/views/_chapter_move.form.php' );
  352.  
  353.         // End payload block:
  354.         $AdminUI->disp_payload_end();
  355.         break;
  356.  
  357.     case 'new':
  358.     case 'copy':
  359.     case 'create':
  360.     case 'edit':
  361.     case 'update':
  362.     case 'delete':
  363.         // Begin payload block:
  364.         $AdminUI->disp_payload_begin();
  365.  
  366.         if$action == 'delete' )
  367.         {    // We need to ask for confirmation:
  368.             $edited_GenericCategory->confirm_delete(
  369.                     sprintfT_('Delete element &laquo;%s&raquo;?'),  $edited_GenericCategory->dget'name' ) ),
  370.                     $actionget_memorized'action' ) );
  371.         }
  372.  
  373.         if$form_below_list )
  374.         {
  375.             // Display list VIEW before form view:
  376.             if!empty$list_view_path ) )
  377.             {
  378.                 $AdminUI->disp_view$list_view_path );
  379.             }
  380.             else
  381.             {
  382.                 $AdminUI->disp_view'generic/_generic_recursive_list.inc.php' );
  383.             }
  384.         }
  385.  
  386.         // Display category edit form:
  387.         if!empty$edit_view_path ) )
  388.         {
  389.             $AdminUI->disp_view$edit_view_path );
  390.         }
  391.         else
  392.         {
  393.             $AdminUI->disp_view'generic/_generic_category.form.php' );
  394.         }
  395.  
  396.         // End payload block:
  397.         $AdminUI->disp_payload_end();
  398.         break;
  399.  
  400.     case 'list':
  401.     default:
  402.         // Begin payload block:
  403.         $AdminUI->disp_payload_begin();
  404.  
  405.         // Display list VIEW:
  406.         if!empty$list_view_path ) )
  407.         {
  408.             $AdminUI->disp_view$list_view_path );
  409.         }
  410.         else
  411.         {
  412.             $AdminUI->disp_view'generic/_generic_recursive_list.inc.php' );
  413.         }
  414.  
  415.         // End payload block:
  416.         $AdminUI->disp_payload_end();
  417.         break;
  418. }
  419.  
  420.  
  421. // Display body bottom, debug info and close </html>:
  422. $AdminUI->disp_global_footer();
  423.  
  424.  
  425. ?>