b2evolution

Multilingual multiuser multiblog engine

b2evolution Technical Documentation (0.9.x) [ class tree: admin ] [ index: admin ] [ all elements ]

Source for file b2categories.php

Documentation is available at b2categories.php

  1. <?php
  2. /**
  3.  * Editing the categories
  4.  *
  5.  * b2evolution - {@link http://b2evolution.net/}
  6.  * Released under GNU GPL License - {@link http://b2evolution.net/about/license.html}
  7.  * @copyright (c)2003-2005 by Francois PLANQUE - {@link http://fplanque.net/}
  8.  *
  9.  * @package admin
  10.  */
  11.  
  12. /**
  13.  * Includes:
  14.  */
  15. require_oncedirname(__FILE__'/_header.php' );
  16. $admin_tab 'cats';
  17. $admin_pagetitle T_('Categories for blog:');
  18. param'action''string' );
  19.  
  20. /** 
  21.  * Local use
  22.  *
  23.  * {@internal cats_display_blog_list(-) }}
  24.  *
  25.  * @access private
  26.  */
  27. function cats_display_blog_list()
  28. {
  29.     global $blog$current_User;
  30.     for$curr_blog_ID blog_list_start();
  31.                 $curr_blog_ID != false;
  32.                 $curr_blog_ID blog_list_next() )
  33.     {
  34.         if$current_User->check_perm'blog_cats'''false$curr_blog_ID ) )
  35.         {    // Current user is not allowed to edit cats...
  36.             continue;
  37.         }
  38.         if$blog == )
  39.         {    // If no selected blog yet, select this one:
  40.             $blog $curr_blog_ID;
  41.         }
  42.         ?>
  43.         <a href="b2categories.php?blog=<?php echo $curr_blog_ID ?>" class="<?php echo $curr_blog_ID == $blog 'CurrentBlog' 'OtherBlog' ?>"><?php blog_list_iteminfo('shortname'?></a>
  44.         <?php
  45.     }
  46. }
  47.  
  48. switch($action
  49. {
  50.     case 'newcat':
  51.         // New category form:
  52.         param'parent_cat_ID''integer' );
  53.         if!empty($parent_cat_ID) )
  54.         {
  55.             $blog get_catblog($parent_cat_ID);
  56.         }
  57.         
  58.         require(dirname(__FILE__).'/_menutop.php');
  59.         cats_display_blog_list();
  60.         require(dirname(__FILE__).'/_menutop_end.php');
  61.     
  62.         // check permissions:
  63.         $current_User->check_perm'blog_cats'''true$blog );
  64.  
  65.         echo "<div class=\"panelblock\">\n";
  66.     
  67.         if!empty($parent_cat_ID) )
  68.         {    // We are creating a subcat
  69.             $parent_cat_name get_catname($parent_cat_ID);
  70.             ?>
  71.         <h2><?php printfT_('New sub-category in category: %s')$parent_cat_name )?></h2>
  72.         <form name="addcat" action="b2categories.php" method="post">
  73.             <input type="hidden" name="parent_cat_ID" value="<?php echo $parent_cat_ID ?>" />
  74.             <?php 
  75.         }
  76.         else
  77.         // We are creating a new base cat
  78.             $blogparams get_blogparams_by_ID$blog );
  79.             ?>
  80.         <h2><?php printfT_('New category in blog: %s')$blogparams->blog_name )?></h2>
  81.         <form name="addcat" action="b2categories.php" method="post">
  82.             <input type="hidden" name="cat_blog_ID" value="<?php echo $blog ?>" />
  83.             <?php 
  84.         }
  85.         ?>
  86.             <input type="hidden" name="action" value="addcat" />
  87.             <p><?php echo T_('New category name'?>: <input type="text" name="cat_name" /></p>
  88.             <input type="submit" name="submit" value="<?php echo T_('Create category'?>" class="search" />
  89.         </form>
  90.         </div>
  91.         <?php
  92.         // List the cats:
  93.         requiredirname(__FILE__).'/_cats_list.php' )
  94.         break;
  95.     
  96.     
  97.     case 'addcat':
  98.         // INSERT new cat into db
  99.         param'cat_name''string'true );
  100.         param'parent_cat_ID''integer' );
  101.         if!empty($parent_cat_ID) )
  102.         {    // We are creating a subcat
  103.             $cat_blog_ID get_catblog($parent_cat_ID);
  104.         }
  105.         else
  106.         {
  107.             param'cat_blog_ID''integer'true );
  108.         }
  109.  
  110.         // check permissions:
  111.         $current_User->check_perm'blog_cats'''true$cat_blog_ID );
  112.     
  113.         if!empty($parent_cat_ID) )
  114.         {    // We are creating a subcat
  115.             // INSERT INTO DB
  116.             $new_cat_ID cat_create$cat_name$parent_cat_ID );
  117.         }
  118.         else
  119.         // We are creating a new base cat
  120.             // INSERT INTO DB
  121.             $new_cat_ID cat_create$cat_name'NULL'$cat_blog_ID );
  122.         }
  123.         
  124.         header("Location: b2categories.php?blog=$cat_blog_ID");
  125.     
  126.         break;
  127.     
  128.     
  129.     case 'Delete':
  130.         // Delete cat from DB:
  131.         param'cat_ID''integer' );
  132.         $blog get_catblog($cat_ID);
  133.  
  134.         require(dirname(__FILE__).'/_menutop.php');
  135.         cats_display_blog_list();
  136.         require(dirname(__FILE__).'/_menutop_end.php');
  137.     
  138.         // check permissions:
  139.         $current_User->check_perm'blog_cats'''true$blog );
  140.     
  141.         $cat_name get_catname($cat_ID);
  142.  
  143.         echo "<div class=\"panelinfo\">\n";
  144.         echo '<h3>'sprintfT_('Deleting category #%d : %s ...',$cat_IDformat_to_output$cat_name'htmlbody') )"</h3>\n";
  145.  
  146.         // DELETE FROM DB:
  147.         $result cat_delete$cat_ID );    
  148.         if$result !== )
  149.         {    // We got an error message!
  150.             echo '<p class="error">'T_('ERROR')': '$result"</p>\n";
  151.         }
  152.         else
  153.         {
  154.             echo '<p>'.T_('Category deleted.').'</p>';
  155.         }
  156.         echo "</div>\n";
  157.         // List the cats:
  158.         requiredirname(__FILE__).'/_cats_list.php' )
  159.     
  160.         break;
  161.         
  162.         
  163.     case 'Edit':
  164.         // ---------- Cat edit form: ----------
  165.         param'cat_ID''integer' );
  166.         $blog get_catblog($cat_ID);
  167.  
  168.         require(dirname(__FILE__).'/_menutop.php');
  169.         cats_display_blog_list();
  170.         require(dirname(__FILE__).'/_menutop_end.php');
  171.     
  172.         // check permissions:
  173.         $current_User->check_perm'blog_cats'''true$blog );
  174.  
  175.         $cat_name get_catname($cat_ID);
  176.         $cat_parent_ID get_catparent($cat_ID);
  177.         ?>
  178.         <div class="panelblock">
  179.         <h2><?php echo T_('Properties for category:')' 'format_to_output$cat_name'htmlbody' ?></h2>
  180.         <form name="renamecat" action="b2categories.php" method="post">
  181.             <?php echo T_('Name'?>:
  182.             <input type="hidden" name="action" value="editedcat" />
  183.             <input type="hidden" name="cat_ID" value="<?php echo $cat_ID ?>" />
  184.             <input type="text" name="cat_name" value="<?php echo format_to_output$cat_name'formvalue' ?>" />
  185.             <h3><?php echo T_('New parent category'?>:</h3>
  186.         <?php        
  187.         // ----------------- START RECURSIVE CAT LIST ----------------
  188.         cat_query();    // make sure the caches are loaded
  189.  
  190.         function cat_move_before_first$parent_cat_ID$level )
  191.         {    // callback to start sublist
  192.             echo "\n<ul>\n";
  193.         }
  194.  
  195.         function cat_move_before_each$curr_cat_ID$level )
  196.         {    // callback to display sublist element
  197.             global $cat_ID;    // This is the category being currently edited !!
  198.             global $cat_parent_ID;    // This is the old parent ID
  199.             if$curr_cat_ID == $cat_ID )
  200.             {    // We have reached current category.
  201.                 // This branch cannot become a parent!
  202.                 return -1;
  203.             }
  204.             $cat get_the_category_by_ID$curr_cat_ID );
  205.             echo "<li>"?>
  206.             <input type="radio" id="cat_parent_ID<?php echo $curr_cat_ID?>" name="cat_parent_ID" value="<?php echo $curr_cat_ID ?>
  207.             <?php 
  208.                 if$cat_parent_ID == $curr_cat_ID echo 'checked="checked"';
  209.             ?>
  210.             />
  211.             <label for="cat_parent_ID<?php echo $curr_cat_ID?>"><strong><?php echo $cat['cat_name']?></strong></label>
  212.             <?php    
  213.             if$cat_parent_ID == $curr_cat_ID echo ' &lt;= 'T_('Old Parent');
  214.         }
  215.  
  216.         function cat_move_after_each$curr_cat_ID$level )
  217.         {    // callback after each sublist element
  218.             echo "</li>\n";
  219.         }
  220.  
  221.         function cat_move_after_last$parent_cat_ID$level )
  222.         {    // callback to end sublist
  223.             echo "</ul>\n";
  224.         }
  225.     
  226.         if$allow_moving_chapters )
  227.         {    // If moving cats between blogs is allowed:
  228.             foreach$cache_blogs as $i_blog )
  229.             // run recursively through the cats of each blog
  230.                 $current_blog_ID $i_blog->blog_ID;
  231.                 if$current_User->check_perm'blog_cats'''false$current_blog_ID ) ) continue;
  232.                 echo "<h4>".$i_blog->blog_name."</h4>\n";
  233.  
  234.             ?>
  235.             <input type="radio" id="cat_parent_none_<?php echo $current_blog_ID ?>" name="cat_parent_ID" value="0_<?php echo $current_blog_ID ?>"
  236.               <?php
  237.                   if( ($cat_parent_ID&& ($current_blog_ID == $blog) ) echo 'checked="checked"';
  238.               ?>
  239.               />
  240.               <label for="cat_parent_none_<?php echo $current_blog_ID ?>"><strong><?php echo T_('Root (No parent)'?></strong></label>
  241.               <?php
  242.               if( ($cat_parent_ID&& ($current_blog_ID == $blog) )
  243.         {
  244.           echo ' &lt;= 'T_('Old Parent');
  245.         }
  246.             // RECURSE:
  247.                 cat_children$cache_categories$current_blog_IDNULL'cat_move_before_first''cat_move_before_each''cat_move_after_each''cat_move_after_last' );
  248.             }
  249.  
  250.       echo '<p class="extracatnote">'.T_('Note: Moving categories across blogs is enabled. Use with caution.').'</p> ';
  251.         }
  252.         else
  253.         {    // Moving cats between blogs is disabled
  254.           ?>
  255.           <input type="radio" id="cat_parent_none_<?php echo $blog ?>" name="cat_parent_ID" value="0_<?php echo $blog ?>"
  256.             <?php
  257.                 if$cat_parent_ID echo 'checked="checked"';
  258.             ?>
  259.             />
  260.             <label for="cat_parent_none_<?php echo $blog ?>"><strong><?php echo T_('Root (No parent)'?></strong></label>
  261.             <?php
  262.             if$cat_parent_ID echo ' &lt;= 'T_('Old Parent');
  263.           // RECURSE:
  264.           cat_children$cache_categories$blogNULL'cat_move_before_first''cat_move_before_each''cat_move_after_each''cat_move_after_last' );
  265.  
  266.        echo '<p class="extracatnote">'.T_('Note: Moving categories across blogs is disabled.').'</p> ';
  267.     }
  268.  
  269.         // ----------------- END RECURSIVE CAT LIST ----------------
  270.     ?>        
  271.             <input type="submit" name="submit" value="<?php echo T_('Edit category!'?>" class="search" />
  272.         </form>
  273.         </div>
  274.     
  275.         <?php
  276.         // List the cats:
  277.         requiredirname(__FILE__).'/_cats_list.php' )
  278.         break;
  279.     
  280.     
  281.     case 'editedcat':
  282.     //
  283.         // Update cat in db:
  284.     //
  285.         param'cat_name''string'true );
  286.  
  287.         param'cat_ID''integer'true );
  288.         //echo $cat_ID;
  289.         $cat_blog_ID get_catblog($cat_ID);
  290.  
  291.          param'cat_parent_ID''string'true );
  292.     $cat_parent_ID_parts explode'_'$cat_parent_ID );
  293.     $cat_parent_ID $cat_parent_ID_parts[0];
  294.     settype$cat_parent_ID'integer' );
  295.         if$cat_parent_ID != )
  296.         // We have a new parent cat
  297.             $parent_cat_blog_ID get_catblog($cat_parent_ID);
  298.         }
  299.     else
  300.     // We are moving to a blog root
  301.       $parent_cat_blog_ID $cat_parent_ID_parts[1];
  302.       settype$parent_cat_blog_ID'integer' );
  303.     }
  304.  
  305.         // check permissions on source:
  306.         $current_User->check_perm'blog_cats'''true$cat_blog_ID );
  307.  
  308.         if$cat_blog_ID != $parent_cat_blog_ID )
  309.     // We are moving to a different blog
  310.       if$allow_moving_chapters )
  311.       {
  312.               die'Moving chapters between blogs is disabled. Cat and parent must be in the same blog!' );
  313.       }
  314.           // check permissions on destination:
  315.           $current_User->check_perm'blog_cats'''true$parent_cat_blog_ID );
  316.         }
  317.  
  318.         cat_update$cat_ID$cat_name$cat_parent_ID$parent_cat_blog_ID );
  319.     
  320.         header("Location: b2categories.php?blog=$cat_blog_ID");
  321.         break;
  322.  
  323.  
  324.     default:
  325.         // Just display cat list for this blog
  326.         require(dirname(__FILE__'/_menutop.php');
  327.         cats_display_blog_list();
  328.         require(dirname(__FILE__'/_menutop_end.php');
  329.  
  330.         if$blog == || $current_User->check_perm'blog_cats'''false$blog ) )
  331.         {    // No blog could be selected
  332.             ?>
  333.             <div class="panelinfo">
  334.             <p>
  335.             <?php echo T_('Sorry, you have no permission to edit/view any category\'s properties.' ?></p>
  336.             </div>
  337.             <?php
  338.             break;
  339.         }
  340.  
  341.         // List the cats:
  342.         requiredirname(__FILE__).'/_cats_list.php' )
  343. }
  344.  
  345. requiredirname(__FILE__).'/_footer.php' )
  346.  
  347. ?>

Documentation generated on Tue, 20 May 2008 01:51:19 +0200 by phpDocumentor 1.4.2