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

Source for file pnuser.php

Documentation is available at pnuser.php

  1. <?php
  2. /**
  3.  * Zikula Application Framework
  4.  *
  5.  * @copyright Robert Gasch
  6.  * @link http://www.zikula.org
  7.  * @version $Id: pnuser.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.  
  14. Loader::loadClass ('HtmlUtil');
  15. Loader::loadClass ('LanguageUtil');
  16. Loader::loadClassFromModule ('Categories''category');
  17.  
  18.  
  19. /**
  20.  * main user function
  21.  */
  22. {
  23.     if (!SecurityUtil::checkPermission('Categories::''::'ACCESS_EDIT)) {
  24.         return LogUtil::registerPermissionError();
  25.     }
  26.  
  27.     $referer pnServerGetVar ('HTTP_REFERER');
  28.     if (strpos ($referer'module=Categories'=== false{
  29.         SessionUtil::setVar('categories_referer'$referer);
  30.     }
  31.  
  32.     $pnRender pnRender::getInstance('Categories'false);
  33.     $pnRender->assign ('allowusercatedit'pnModGetVar('Categories''allowusercatedit'0));
  34.     return $pnRender->fetch('categories_user_editcategories.htm');
  35. }
  36.  
  37. /**
  38.  * edit category for a simple, non-recursive set of categories
  39.  */
  40. function Categories_user_edit ()
  41. {
  42.     $docroot FormUtil::getPassedValue ('dr'0);
  43.     $cid     FormUtil::getPassedValue ('cid'0);
  44.     $url     pnModURL ('Categories''user''edit'array('dr' => $docroot));
  45.  
  46.     if (!SecurityUtil::checkPermission('Categories::category'"ID::$docroot"ACCESS_EDIT)) {
  47.         return LogUtil::registerPermissionError($url);
  48.     }
  49.  
  50.     $referer pnServerGetVar ('HTTP_REFERER');
  51.     if (strpos ($referer'module=Categories'=== false{
  52.         SessionUtil::setVar('categories_referer'$referer);
  53.     }
  54.  
  55.     $rootCat array();
  56.     $allCats array();
  57.     $editCat array();
  58.  
  59.     if (!$docroot{
  60.         return LogUtil::registerError(_CATEGORIES_DOCROOT_INVALIDnull$url);
  61.     }
  62.     if ($docroot == 1{
  63.         return LogUtil::registerError(_CATEGORIES_ROOT_CANT_EDITnull$url);
  64.     }
  65.  
  66.     Loader::loadClass ('CategoryUtil');
  67.  
  68.     if (is_int((int)$docroot&& $docroot 0{
  69.         $rootCat CategoryUtil::getCategoryByID ($docroot);
  70.     else {
  71.         $rootCat CategoryUtil::getCategoryByPath ($docroot);
  72.         if (!$rootCat{
  73.             $rootCat CategoryUtil::getCategoryByPath ($docroot'ipath');
  74.         }
  75.     }
  76.  
  77.     // now check if someone is trying edit another user's categories
  78.     $userRoot pnModGetVar ('Categories''userrootcat'0);
  79.     if ($userRoot{
  80.         $userRootCat CategoryUtil::getCategoryByPath ($userRoot);
  81.         if ($userRootCat{
  82.             $userRootCatIPath $userRootCat['ipath'];
  83.             $rootCatIPath     $rootCat['ipath'];
  84.             if (strpos($rootCatIPath$userRootCatIPath!== false{
  85.                 if (!SecurityUtil::checkPermission('Categories::category'"ID::$docroot"ACCESS_ADMIN)) {
  86.                     $thisUserRootCategoryName pnModAPIFunc ('Categories''user''getusercategoryname');
  87.                     $thisUserRootCatPath      $userRootCat['path''/' $thisUserRootCategoryName;
  88.                     $userRootCatPath          $userRootCat['path'];
  89.                     $rootCatPath              $rootCat['path'];
  90.                     if (strpos($rootCatPath$userRootCatPath=== false{
  91.                         return LogUtil::registerError(_CATEGORIES_EDIT_USER_NOT_OWN" ($docroot)"null$url);
  92.                     }
  93.                 }
  94.             }
  95.         }
  96.     }
  97.  
  98.     if ($cid{
  99.        $editCat CategoryUtil::getCategoryByID ($cid);
  100.        if ($editCat['is_locked']
  101.            return LogUtil::registerError(_CATEGORIES_CATEGORY_IS_LOCKED" ($cid$editCat[name])"null$url);
  102.        }
  103.     }
  104.  
  105.     if (!$rootCat{
  106.         return LogUtil::registerError(_CATEGORIES_DOCROOT_CANT_RETRIEVE " ($docroot)"null$url);
  107.     }
  108.     if ($editCat && !$editCat['is_leaf']{
  109.         return LogUtil::registerError(_CATEGORIES_EDITCAT_NOT_LEAF " ($cid)"null$url);
  110.     }
  111.     if ($editCat && !CategoryUtil::isDirectSubCategory ($rootCat$editCat)) {
  112.         return LogUtil::registerError(_CATEGORIES_EDITCAT_NOT_SUBCAT " ($docroot$cid)"null$url);
  113.     }
  114.  
  115.     $allCats CategoryUtil::getSubCategoriesForCategory ($rootCatfalsefalsefalsetruetrue);
  116.  
  117.     $pnRender pnRender::getInstance('Categories'false);
  118.     $pnRender->assign('rootCat'$rootCat);
  119.     $pnRender->assign('category'$editCat);
  120.     $pnRender->assign('allCats'$allCats);
  121.     $pnRender->assign('languages'LanguageUtil::getLanguages());
  122.     $pnRender->assign('referer'SessionUtil::getVar('categories_referer'));
  123.  
  124.     return $pnRender->fetch('categories_user_edit.htm');
  125. }
  126.  
  127.  
  128. /**
  129.  * edit categories for the currently logged in user
  130.  */
  131. {
  132.     if (!SecurityUtil::checkPermission('Categories::category''::'ACCESS_EDIT)) {
  133.         return LogUtil::registerPermissionError();
  134.     }
  135.  
  136.     if (!pnUserLoggedIn()) {
  137.     }
  138.  
  139.     $allowUserEdit pnModGetVar ('Categories''allowusercatedit'0);
  140.     if (!$allowUserEdit{
  141.     }
  142.  
  143.     $userRoot pnModGetVar ('Categories''userrootcat'0);
  144.     if (!$userRoot{
  145.     }
  146.  
  147.     Loader::loadClass ('CategoryUtil');
  148.     $userRootCat CategoryUtil::getCategoryByPath ($userRoot);
  149.     if (!$userRoot{
  150.         return LogUtil::registerError(_CATEGORIES_USERDOCROOT_INVALID "[$userRoot]");
  151.     }
  152.  
  153.     if ($userRootCat == 1{
  154.     }
  155.  
  156.     $userCatName Categories_user_getusercategoryname ();
  157.     if (!$userCatName{
  158.     }
  159.  
  160.     $thisUserRootCatPath $userRoot '/' $userCatName;
  161.     $thisUserRootCat CategoryUtil::getCategoryByPath ($thisUserRootCatPath);
  162.  
  163.     $dr null;
  164.     if (!$thisUserRootCat{
  165.         $autoCreate pnModGetVar ('Categories''autocreateusercat'0);
  166.         if (!$autoCreate{
  167.             return LogUtil::registerError(_CATEGORIES_USERCAT_NOAUTOCREATE);
  168.         }
  169.  
  170.         require_once ('system/Categories/pninit.php')// need this for Categories_makeDisplayName() && Categories_makeDisplayDesc()
  171.         $cat array('id'               => '',
  172.                      'parent_id'        => $userRootCat['id'],
  173.                      'name'             => $userCatName,
  174.                      'display_name'     => Categories_makeDisplayName($userCatName),
  175.                      'display_desc'     => Categories_makeDisplayDesc(),
  176.                      'security_domain'  => 'Categories::',
  177.                      'path'             => $thisUserRootCatPath,
  178.                      'status'           => 'A');
  179.         if (!($class Loader::loadClassFromModule ('Categories''category'))) {
  180.             return pn_exit ("Unable to load class [category] ...");
  181.         }
  182.  
  183.         $obj new $class ();
  184.         $obj->setData ($cat);
  185.         $obj->insert ();
  186.         // since the original insert can't construct the ipath (since
  187.         // the insert id is not known yet) we update the object here
  188.         $obj->update ();
  189.         $dr $obj->getID ();
  190.  
  191.         $autoCreateDefaultUserCat pnModGetVar ('Categories''autocreateuserdefaultcat'0);
  192.         if ($autoCreateDefaultUserCat{
  193.             $userdefaultcatname pnModGetVar ('Categories''userdefaultcatname'_CATDISP_DEFAULT);
  194.             $cat array('id'               => '',
  195.                          'parent_id'        => $dr,
  196.                          'name'             => $userdefaultcatname,
  197.                          'display_name'     => Categories_makeDisplayName($userdefaultcatname),
  198.                          'display_desc'     => Categories_makeDisplayDesc(),
  199.                          'security_domain'  => 'Categories::',
  200.                          'path'             => $thisUserRootCatPath '/' $userdefaultcatname,
  201.                          'status'           => 'A');
  202.             $obj->setData ($cat);
  203.             $obj->insert ();
  204.             // since the original insert can't construct the ipath (since
  205.             // the insert id is not known yet) we update the object here
  206.             $obj->update ();
  207.         }
  208.     else {
  209.         $dr $thisUserRootCat['id'];
  210.     }
  211.  
  212.     $url pnModURL ('Categories''user''edit'array('dr' => $dr));
  213.     return pnRedirect($url);
  214. }
  215.  
  216. /**
  217.  * refer the user back to the calling page
  218.  */
  219. {
  220.     $referer SessionUtil::getVar ('categories_referer');
  221.     SessionUtil::DelVar ('categories_referer');
  222.     return pnRedirect ($referer);
  223. }
  224.  
  225. /**
  226.  * return the categories for the currently logged in user, really only used for testing purposes
  227.  */
  228. {
  229.     return pnModAPIFunc ('Categories''user''getusercategories');
  230. }
  231.  
  232. /**
  233.  * return the category name for a user, really only used for testing purposes
  234.  */
  235. {
  236.     return pnModAPIFunc ('Categories''user''getusercategoryname');
  237. }

Documentation generated on Fri, 18 Jul 2008 21:54:42 +0200 by phpDocumentor 1.4.1