Zikula_Core
[ class tree: Zikula_Core ] [ index: Zikula_Core ] [ all elements ]

Source for file pnadmin.php

Documentation is available at pnadmin.php

  1. <?php
  2. /**
  3.  * Zikula Application Framework
  4.  *
  5.  * @copyright Robert Gasch
  6.  * @link http://www.zikula.org
  7.  * @version $Id: pnadmin.php 24342 2008-06-06 12:03:14Z markwest $
  8.  * @license GNU/GPL - http://www.gnu.org/copyleft/gpl.html
  9.  * @author Robert Gasch rgasch@gmail.com
  10.  * @package Zikula_Core
  11.  */
  12.  
  13. Loader::loadClass ('CategoryUtil');
  14. Loader::loadClass ('HtmlUtil');
  15. Loader::loadClassFromModule ('Categories''category');
  16.  
  17. /**
  18.  * main admin function
  19.  */
  20. {
  21.     if (!SecurityUtil::checkPermission('Categories::''::'ACCESS_ADMIN)) {
  22.         return LogUtil::registerPermissionError();
  23.     }
  24.  
  25.     return Categories_admin_view();
  26. }
  27.  
  28. /**
  29.  * view categories
  30.  */
  31. function Categories_admin_view ()
  32. {
  33.      $layersMenuPath 'javascript/phplayersmenu/lib';
  34.      Loader::loadFile ('PHPLIB.php'$layersMenuPath);
  35.      Loader::loadFile ('layersmenu-common.inc.php'$layersMenuPath);
  36.      Loader::loadFile ('layersmenu.inc.php'$layersMenuPath);
  37.      Loader::loadFile ('treemenu.inc.php'$layersMenuPath);
  38.  
  39.     $root_id FormUtil::getPassedValue ('dr'1);
  40.  
  41.     if (!SecurityUtil::checkPermission('Categories::category'"ID::$root_id"ACCESS_EDIT)) {
  42.         return LogUtil::registerPermissionError();
  43.     }
  44.  
  45.     if (!SecurityUtil::checkPermission('Categories::category''::'ACCESS_EDIT)) {
  46.         return LogUtil::registerPermissionError();
  47.     }
  48.  
  49.     $cats    CategoryUtil::getSubCategories ($root_idtruetruetruetruetrue);
  50.     $menuTxt CategoryUtil::getCategoryTreeJS ($cats);
  51.  
  52.     $pnRender pnRender::getInstance('Categories'false);
  53.     $pnRender->assign('menuTxt'$menuTxt);
  54.     return $pnRender->fetch('categories_admin_view.htm');
  55. }
  56.  
  57. /**
  58.  * display configure module page
  59.  */
  60. {
  61.     if (!SecurityUtil::checkPermission('Categories::'"::"ACCESS_ADMIN)) {
  62.         return LogUtil::registerPermissionError();
  63.     }
  64.  
  65.     $pnRender pnRender::getInstance('Categories'false);
  66.     return $pnRender->fetch('categories_admin_config.htm');
  67. }
  68.  
  69. /**
  70.  * edit category
  71.  */
  72. function Categories_admin_edit ()
  73. {
  74.     $cid      FormUtil::getPassedValue ('cid'0);
  75.     $root_id  FormUtil::getPassedValue ('dr'1);
  76.     $mode     FormUtil::getPassedValue ('mode''new');
  77.     $allCats  '';
  78.     $editCat  '';
  79.  
  80.     Loader::loadClass ('LanguageUtil');
  81.     $languages LanguageUtil::getLanguages();
  82.  
  83.     // indicates that we're editing
  84.     if ($mode == 'edit')
  85.     {
  86.         if (!SecurityUtil::checkPermission('Categories::category'"::"ACCESS_ADMIN)) {
  87.             return LogUtil::registerPermissionError();
  88.         }
  89.  
  90.         if (!$cid{
  91.             return LogUtil::registerError ('Unable to determine valid [cid] for edit mode in Categories_admin_edit ...');
  92.         }
  93.  
  94.         $category new PNCategory();
  95.         $editCat  $category->select ($cid);
  96.         if ($editCat == false{
  97.             return LogUtil::registerError (_NOSUCHITEM404);
  98.         }
  99.     }
  100.     else
  101.     {
  102.         // new category creation
  103.         if (!SecurityUtil::checkPermission('Categories::category''::'ACCESS_ADD)) {
  104.             return LogUtil::registerPermissionError();
  105.         }
  106.  
  107.         // since we inherit the domain settings from the parent, we get
  108.         // the inherited (and merged) object from session
  109.         if (isset($_SESSION['newCategory']&& $_SESSION['newCategory']{
  110.             $editCat $_SESSION['newCategory'];
  111.             unset ($_SESSION['newCategory']);
  112.             $category new PNCategory()// need this for validation info
  113.         }
  114.         // if we're back from validation get the object from input
  115.         else
  116.         if (FormUtil::getValidationErrors()) {
  117.             $category new PNCategory('V')// need this for validation info
  118.             $editCat  $category->get ();
  119.         }
  120.         // someone just pressen 'new' -> populate defaults
  121.         else {
  122.             $category new PNCategory()// need this for validation info
  123.             $editCat['sort_value''0';
  124.         }
  125.     }
  126.  
  127.     $reloadOnCatChange ($mode != 'edit');
  128.     $allCats  CategoryUtil::getSubCategories ($root_idtruetruetruefalsetrue);
  129.  
  130.     // now remove the categories which are below $editCat ... 
  131.     // you should not be able to set these as a parent category as it creates a circular hierarchy (see bug #4992)
  132.     if (isset($editCat['ipath'])) {
  133.         $cSlashEdit StringUtil::countInstances ($editCat['ipath']'/');
  134.         foreach ($allCats as $k=>$v{
  135.             $cSlashCat StringUtil::countInstances ($v['ipath']'/');
  136.             if ($cSlashCat >= $cSlashEdit && strpos ($v['ipath']$editCat['ipath']!== false{
  137.                 unset ($allCats[$k]);
  138.             }
  139.         }
  140.     }
  141.  
  142.     $selector CategoryUtil::getSelector_Categories ($allCats'id'(isset($editCat['parent_id']$editCat['parent_id'0)'category[parent_id]'isset($defaultValue$defaultValue nullnull$reloadOnCatChange);
  143.  
  144.     $attributes = isset($editCat['__ATTRIBUTES__']$editCat['__ATTRIBUTES__'array();
  145.  
  146.     Loader::loadClass ('LanguageUtil');
  147.  
  148.     $pnRender pnRender::getInstance('Categories'false);
  149.     $pnRender->assign('mode'$mode);
  150.     $pnRender->assign('category'$editCat);
  151.     $pnRender->assign('attributes'$attributes);
  152.     $pnRender->assign('languages'$languages);
  153.     $pnRender->assign('categorySelector'$selector);
  154.     $pnRender->assign('validation'$category->_objValidation);
  155.     if ($mode == 'edit'{
  156.         $pnRender->assign('haveSubcategories'CategoryUtil::haveDirectSubcategories ($cid));
  157.         $pnRender->assign('haveLeafSubcategories'CategoryUtil::haveDirectSubcategories ($cidfalsetrue));
  158.     }
  159.  
  160.     return $pnRender->fetch('categories_admin_edit.htm');
  161. }
  162.  
  163. {
  164.     if (!SecurityUtil::checkPermission('Categories::'"::"ACCESS_ADMIN)) {
  165.         return LogUtil::registerPermissionError();
  166.     }
  167.  
  168.     $root_id  FormUtil::getPassedValue ('dr'1);
  169.     $id       FormUtil::getPassedValue ('id'0);
  170.     $ot       FormUtil::getPassedValue ('ot''category_registry');
  171.  
  172.     if (!($class Loader::loadClassFromModule ('Categories'$ot))) {
  173.         return pn_exit ("Unable to load class [$ot] ...");
  174.     }
  175.     if (!($arrayClass Loader::loadArrayClassFromModule ('Categories'$ot))) {
  176.         return pn_exit ("Unable to load class [$ot] ...");
  177.     }
  178.  
  179.     $obj  new $class ();
  180.     $data $obj->getDataFromInput ();
  181.     if (!$data{
  182.         $data $obj->getFailedValidationData ();
  183.         if (!$data{
  184.             $data array();
  185.         }
  186.     }
  187.  
  188.     $where    '';
  189.     $sort     'crg_modname, crg_property';
  190.     $objArray new $arrayClass ();
  191.     $dataA    $objArray->get($where$sort);
  192.  
  193.     $pnRender pnRender::getInstance('Categories'false);
  194.     $pnRender->assign('objectArray'$dataA);
  195.     $pnRender->assign('newobj'$data);
  196.     $pnRender->assign('root_id'$root_id);
  197.     $pnRender->assign('id'$id);
  198.     $pnRender->assign('validation'$obj->_objValidation);
  199.  
  200.     return $pnRender->fetch('categories_admin_registry_edit.htm');
  201. }
  202.  
  203. /**
  204.  * display new category form
  205.  */
  206. function Categories_admin_new ()
  207. {
  208.     $_POST['mode''new';
  209.     return Categories_admin_edit ();
  210. }
  211.  
  212.  
  213. /*
  214.  * Generic function to handle copy, delete and move operations
  215.  */
  216. function Categories_admin_op ()
  217. {
  218.     $cid      FormUtil::getPassedValue ('cid'1);
  219.     $root_id  FormUtil::getPassedValue ('dr'1);
  220.     $op       FormUtil::getPassedValue ('op''NOOP');
  221.  
  222.     if (!SecurityUtil::checkPermission('Categories::category'"ID::$cid"ACCESS_DELETE)) {
  223.         return LogUtil::registerPermissionError();
  224.     }
  225.  
  226.     $category new PNCategory();
  227.     $category    $category->select ($cid);
  228.     $subCats     CategoryUtil::getSubCategories ($cidfalsefalse);
  229.     $allCats     CategoryUtil::getSubCategories ($root_idtruetruetruefalsetrue$cid);
  230.     $selector    CategoryUtil::getSelector_Categories ($allCats);
  231.  
  232.     $pnRender pnRender::getInstance('Categories');
  233.     $pnRender->caching false;
  234.     $pnRender->assign('category'$category);
  235.     $pnRender->assign('numSubcats'count($subCats));
  236.     $pnRender->assign('categorySelector'$selector);
  237.  
  238.     $tplName 'categories_admin_' $op '.htm';
  239.     return $pnRender->fetch($tplName);
  240. }
  241.  
  242. /*
  243.  * Global module preferences
  244.  */
  245. {
  246.     if (!SecurityUtil::checkPermission('Categories::preferences''::'ACCESS_ADMIN)) {
  247.         return LogUtil::registerPermissionError();
  248.     }
  249.  
  250.     $pnRender pnRender::getInstance('Categories'false);
  251.     $pnRender->assign ('userrootcat'pnModGetVar('Categories''userrootcat''/__SYSTEM__'));
  252.     $pnRender->assign ('allowusercatedit'pnModGetVar('Categories''allowusercatedit'0));
  253.     $pnRender->assign ('autocreateusercat'pnModGetVar('Categories''autocreateusercat'0));
  254.     $pnRender->assign ('autocreateuserdefaultcat'pnModGetVar('Categories''autocreateuserdefaultcat'0));
  255.     $pnRender->assign ('userdefaultcatname'pnModGetVar('Categories''userdefaultcatname'0));
  256.     $pnRender->assign ('permissionsall'pnModGetVar('Categories''permissionsall'0));
  257.  
  258.     return $pnRender->fetch('categories_admin_preferences.htm');
  259. }

Documentation generated on Fri, 18 Jul 2008 21:51:35 +0200 by phpDocumentor 1.4.1