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

Source for file pnadminapi.php

Documentation is available at pnadminapi.php

  1. <?php
  2. /**
  3.  * Zikula Application Framework
  4.  *
  5.  * @copyright (c) 2002, Zikula Development Team
  6.  * @link http://www.zikula.org
  7.  * @version $Id: pnadminapi.php 24342 2008-06-06 12:03:14Z markwest $
  8.  * @license GNU/GPL - http://www.gnu.org/copyleft/gpl.html
  9.  * @package Zikula_System_Modules
  10.  * @subpackage Admin
  11.  */
  12.  
  13. /**
  14.  * create a admin category
  15.  * @author Mark West
  16.  * @param string $args['catname'] name of the category
  17.  * @param string $args['description'] description of the category
  18.  * @return mixed admin category ID on success, false on failure
  19.  */
  20. function Admin_adminapi_create($args)
  21. {
  22.     // Argument check
  23.     if (!isset($args['catname']||
  24.         !strlen($args['catname']||
  25.         !isset($args['description'])) {
  26.         return LogUtil::registerError (_MODARGSERROR);
  27.     }
  28.  
  29.     // Security check
  30.     if (!SecurityUtil::checkPermission('Admin::Category'"$args[catname]::"ACCESS_ADD)) {
  31.         return LogUtil::registerPermissionError ();
  32.     }
  33.  
  34.     $item array('catname' => $args['catname']'description' => $args['description']);
  35.  
  36.     if (!DBUtil::insertObject($item'admin_category''cid')) {
  37.         return LogUtil::registerError (_CREATEFAILED);
  38.     }
  39.  
  40.     // Let other modules know an item has been created
  41.     pnModCallHooks('item''create'$item['cid']array('module' => 'Admin'));
  42.  
  43.     // Return the id of the newly created item to the calling process
  44.     return $item['cid'];
  45. }
  46.  
  47. /**
  48.  * delete a admin category
  49.  * @author Mark West
  50.  * @param int $args['cid'] ID of the category
  51.  * @return bool true on success, false on failure
  52.  */
  53. function Admin_adminapi_delete($args)
  54. {
  55.     if (!isset($args['cid']|| !is_numeric($args['cid'])) {
  56.         return LogUtil::registerError (_MODARGSERROR);
  57.     }
  58.  
  59.     $item pnModAPIFunc('Admin''admin''get'array('cid' => $args['cid']));
  60.  
  61.     if ($item == false{
  62.         return LogUtil::registerError (_NOSUCHITEM);
  63.     }
  64.  
  65.     if (!SecurityUtil::checkPermission('Admin::Category'"$item[catname]::$args[cid]"ACCESS_DELETE)) {
  66.         return LogUtil::registerPermissionError ();
  67.     }
  68.  
  69.     // Avoid deletion of the default category
  70.     $defaultcategory pnModGetVar('Admin''defaultcategory');
  71.     if ($args['cid'== $defaultcategory{
  72.         return LogUtil::registerError (_ADMIN_DELETEFAILEDDEFAULT);
  73.     }
  74.  
  75.     // Avoid deletion of the start category
  76.     $startcategory pnModGetVar('Admin''startcategory');
  77.     if ($args['cid'== $startcategory{
  78.         return LogUtil::registerError (_ADMIN_DELETEFAILEDSTART);
  79.     }
  80.  
  81.     // move all modules from the category to be deleted into the
  82.     // default category. We can't do this via a simple DBUtil call
  83.     // because it's a non-object based mass update of the key field.
  84.     $pntable pnDBGetTables();
  85.     $column  $pntable['admin_module_column'];
  86.     $where   "WHERE $column[cid] = '. (int)DataUtil::formatForStore($args['cid']"'";
  87.  
  88.     $obj array();
  89.     $obj['cid'$defaultcategory;
  90.     $res DBUtil::updateObject ($obj'admin_module'$where);
  91.     if (!$res{
  92.         return LogUtil::registerError (_DELETEFAILED);
  93.     }
  94.  
  95.     // Now actually delete the category
  96.     if (!DBUtil::deleteObjectByID ('admin_category'$args['cid']'cid')) {
  97.         return LogUtil::registerError (_DELETEFAILED);
  98.     }
  99.  
  100.     // Let any hooks know that we have deleted an item.
  101.     pnModCallHooks('item''delete'$args['cid']array('module' => 'Admin'));
  102.  
  103.     // Let the calling process know that we have finished successfully
  104.     return true;
  105. }
  106.  
  107. /**
  108.  * update a admin category
  109.  * @author Mark West
  110.  * @param int $args['cid'] the ID of the category
  111.  * @param string $args['catname'] the new name of the category
  112.  * @param string $args['description'] the new description of the category
  113.  * @return bool true on success, false on failure
  114.  */
  115. function Admin_adminapi_update($args)
  116. {
  117.     // Argument check
  118.     if (!isset($args['cid']||
  119.         !is_numeric($args['cid']||
  120.         !isset($args['catname']||
  121.         !strlen($args['catname']||
  122.         !isset($args['description'])) {
  123.         return LogUtil::registerError (_MODARGSERROR);
  124.     }
  125.  
  126.     // Get the existing item
  127.     $item pnModAPIFunc('Admin''admin''get'array('cid' => $args['cid']));
  128.  
  129.     if ($item == false{
  130.         return LogUtil::registerError (_NOSUCHITEM);
  131.     }
  132.  
  133.     // Security checks (both old item and updated item)
  134.     if (!SecurityUtil::checkPermission('Admin::Category'"$item[catname]::$args[cid]"ACCESS_EDIT)) {
  135.         return LogUtil::registerPermissionError ();
  136.     }
  137.     if (!SecurityUtil::checkPermission('Admin::Category'"$args[catname]:$args[cid]"ACCESS_EDIT)) {
  138.         return LogUtil::registerPermissionError ();
  139.     }
  140.  
  141.     $item array('cid' => $args['cid']'catname' => $args['catname']'description' => $args['description']);
  142.  
  143.     if (!DBUtil::updateObject($item'admin_category''''cid')) {
  144.         return LogUtil::registerError (_UPDATEFAILED);
  145.     }
  146.  
  147.     // New hook functions
  148.     pnModCallHooks('item''update'$args['cid']array('module' => 'Admin'));
  149.  
  150.     // Let the calling process know that we have finished successfully
  151.     return true;
  152. }
  153.  
  154. /**
  155.  * get all admin categories
  156.  * @author Mark West
  157.  * @param int $args['startnum'] starting record number
  158.  * @param int $args['numitems'] number of items to get
  159.  * @return mixed array of items, or false on failure
  160.  */
  161. function Admin_adminapi_getall($args)
  162. {
  163.     // Optional arguments.
  164.     if (!isset($args['startnum']|| !is_numeric($args['startnum'])) {
  165.         $args['startnum'1;
  166.     }
  167.     if (!isset($args['numitems']|| !is_numeric($args['numitems'])) {
  168.         $args['numitems'= -1;
  169.     }
  170.  
  171.     // argument check
  172.     if (!isset($args['startnum']||
  173.         !isset($args['numitems'])) {
  174.         return LogUtil::registerError (_MODARGSERROR);
  175.     }
  176.  
  177.     $items array();
  178.  
  179.     // Security check
  180.     if (!SecurityUtil::checkPermission('Admin::''::'ACCESS_READ)) {
  181.         return $items;
  182.     }
  183.  
  184.     // get the necessary db information
  185.     pnModDBInfoLoad('Admin''Admin');
  186.     $pntable pnDBGetTables();
  187.     $admincategorycolumn &$pntable['admin_category_column'];
  188.  
  189.     // get all categories the user has permission to see
  190.     $orderBy "ORDER BY $admincategorycolumn[catname]";
  191.     $permFilter array(array('realm'          => 0,
  192.                               'component_left' => 'Admin',
  193.                               'instance_left'  => 'catname',
  194.                               'instance_right' => 'cid',
  195.                               'level'          => ACCESS_READ));
  196.     $result DBUtil::selectObjectArray('admin_category'''$orderBy$args['startnum']-1$args['numitems']''$permFilter);
  197.     if (!$result{
  198.         return false;
  199.     }
  200.  
  201.     return $result;
  202. }
  203.  
  204. /**
  205.  * get a specific category
  206.  * @author Mark West
  207.  * @param int $args['cid'] id of example item to get
  208.  * @return mixed item array, or false on failure
  209.  */
  210. function Admin_adminapi_get($args)
  211. {
  212.     // Argument check
  213.     if (!isset($args['cid'])) {
  214.         return LogUtil::registerError (_MODARGSERROR);
  215.     }
  216.  
  217.     // retrieve the category object
  218.     $result DBUtil::selectObjectByID('admin_category'(int)$args['cid']'cid');
  219.     if (!$result{
  220.         return false;
  221.     }
  222.  
  223.     if (!SecurityUtil::checkPermission('Admin::'"$result[catname]::$result[cid]"ACCESS_READ)) {
  224.         return LogUtil::registerPermissionError ();
  225.     }
  226.  
  227.     // Return the item array
  228.     return $result;
  229. }
  230.  
  231. /**
  232.  * utility function to count the number of items held by this module
  233.  * @author Mark West
  234.  * @return int number of items held by this module
  235.  */
  236. {
  237.     return DBUtil::selectObjectCount('admin_category');
  238. }
  239.  
  240. /**
  241.  * add a module to a category
  242.  * @author Mark West
  243.  * @param string $args['module'] name of the module
  244.  * @param int $args['category'] number of the category
  245.  * @return mixed admin category ID on success, false on failure
  246.  */
  247. {
  248.     if (!isset($args['module']||
  249.         !isset($args['category'])) {
  250.         return LogUtil::registerError (_MODARGSERROR);
  251.     }
  252.  
  253.     // this function is called durung the init process so we have to check in _PNINSTALLVER
  254.     // is set as alternative to the correct permission check
  255.     if (!defined('_PNINSTALLVER'&& !SecurityUtil::checkPermission('Admin::Category'"::"ACCESS_ADD)) {
  256.         return LogUtil::registerPermissionError ();
  257.     }
  258.  
  259.     // get module id
  260.     $mid pnModGetIDFromName($args['module']);
  261.     if (!DBUtil::deleteObjectByID ('admin_module'$mid'mid')) {
  262.         return false;
  263.     }
  264.  
  265.     $values array();
  266.     $values['cid'$args['category'];
  267.     $values['mid'$mid;
  268.     if (!DBUtil::insertObject($values'admin_module')) {
  269.         return false;
  270.     }
  271.  
  272.     // Return success
  273.     return true;
  274. }
  275.  
  276. /**
  277.  * Get the category a module belongs to
  278.  * @author Mark West
  279.  * @param int $args['mid'] id of the module
  280.  * @return mixed category id, or false on failure
  281.  */
  282. {
  283.     // create a static result set to prevent multiple sql queries
  284.     static $catitems array();
  285.  
  286.     // Argument check
  287.     if (!isset($args['mid'])) {
  288.         return LogUtil::registerError (_MODARGSERROR);
  289.     }
  290.  
  291.     // check if we've already worked this query out
  292.     if (isset($catitems[$args['mid']])) {
  293.         return $catitems[$args['mid']];
  294.     }
  295.  
  296.     // retrieve the admin module object array
  297.     $result DBUtil::selectObjectArray('admin_module'''''-1-1'mid');
  298.     if (!$result{
  299.         return false;
  300.     }
  301.  
  302.     $ak array_keys($result);
  303.     foreach ($ak as $val{
  304.         $catitems[$val$result[$val]['cid'];
  305.     }
  306.  
  307.     // Return the category id
  308.     if (isset($catitems[$args['mid']])) {
  309.         return $catitems[$args['mid']];
  310.     }
  311.  
  312.     return false;
  313. }
  314.  
  315. /**
  316.  * Get the category a module belongs to
  317.  * @author Mark West
  318.  * @param int $args['mid'] id of the module
  319.  * @return mixed array of styles if successful, or false on failure
  320.  */
  321. {
  322.     // check our input and get the module information
  323.     if (!isset($args['modname']||
  324.         !is_string($args['modname']||
  325.         !is_array($modinfo pnModGetInfo(pnModGetIDFromName($args['modname'])))) {
  326.         SessionUtil::setVar(_MODARGSERROR);
  327.         return false;
  328.     }
  329.  
  330.     if (!isset($args['exclude']|| !is_array($args['exclude'])) {
  331.        $args['exclude'array();
  332.     }
  333.  
  334.     // create an empty result set
  335.     $styles array();
  336.  
  337.     $osmoddir DataUtil::formatForOS($modinfo['directory']);
  338.     if (is_dir($dir "modules/$osmoddir/pnstyle")) {
  339.         $handle opendir($dir);
  340.         while (false !== ($file readdir($handle))) {
  341.             if (stristr($file'.css'&& !in_array($file$args['exclude'])) {
  342.                 $styles[$file;
  343.             }
  344.         }
  345.     else if (is_dir($dir "system/$osmoddir/pnstyle")) {
  346.         $handle opendir($dir);
  347.         while (false !== ($file readdir($handle))) {
  348.             if (stristr($file'.css'&& !in_array($file$args['exclude'])) {
  349.                 $styles[$file;
  350.             }
  351.         }
  352.     }
  353.  
  354.     // return our results
  355.     return $styles;
  356. }
  357.  
  358. /**
  359.  * get available admin panel links
  360.  *
  361.  * @author Mark West
  362.  * @return array array of admin links
  363.  */
  364. {
  365.     $links array();
  366.  
  367.     pnModLangLoad('Admin''admin');
  368.  
  369.     if (SecurityUtil::checkPermission('Admin::''::'ACCESS_READ)) {
  370.         $links[array('url' => pnModURL('Admin''admin''view')'text' => _MODULECATEGORIESLISTVIEW);
  371.     }
  372.     if (SecurityUtil::checkPermission('Admin::''::'ACCESS_ADD)) {
  373.         $links[array('url' => pnModURL('Admin''admin''new')'text' => _NEWMODULECATEGORY);
  374.     }
  375.     if (SecurityUtil::checkPermission('Admin::''::'ACCESS_ADMIN)) {
  376.         $links[array('url' => pnModURL('Admin''admin''modifyconfig')'text' => _MODIFYADMINPANELCONFIG);
  377.     }
  378.  
  379.     return $links;
  380. }

Documentation generated on Fri, 18 Jul 2008 21:52:10 +0200 by phpDocumentor 1.4.1