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

Source for file pnadmin.php

Documentation is available at pnadmin.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: pnadmin.php 24342 2008-06-06 12:03:14Z markwest $
  8.  * @license GNU/GPL - http://www.gnu.org/copyleft/gpl.html
  9.  * @package Zikula_Value_Addons
  10.  * @subpackage FAQ
  11.  */
  12.  
  13. /**
  14.  * the main administration function
  15.  *
  16.  * @author       The Zikula Development Team
  17.  * @return       output       The main module admin page.
  18.  */
  19. function FAQ_admin_main()
  20. {
  21.     // Security check
  22.     if (!SecurityUtil::checkPermission'FAQ::''::'ACCESS_EDIT)) {
  23.         return LogUtil::registerPermissionError();
  24.     }
  25.  
  26.     // Create output object
  27.     $pnRender pnRender::getInstance('FAQ'false);
  28.  
  29.     // Return the output that has been generated by this function
  30.     return $pnRender->fetch('faq_admin_main.htm');
  31. }
  32.  
  33. /**
  34.  * form to add new faq
  35.  *
  36.  * @author       The Zikula Development Team
  37.  * @return       output       The main module admin page.
  38.  */
  39. function FAQ_admin_new()
  40. {
  41.     // Security check
  42.     if (!SecurityUtil::checkPermission'FAQ::''::'ACCESS_ADD)) {
  43.         return LogUtil::registerError(_MODULENOAUTH403);
  44.     }
  45.  
  46.     // Get the module vars
  47.     $modvars pnModGetVar('FAQ');
  48.  
  49.     // Create output object
  50.     $pnRender pnRender::getInstance('FAQ'false);
  51.  
  52.     if ($modvars['enablecategorization']{
  53.         // load the categories system
  54.         if (!($class Loader::loadClass('CategoryRegistryUtil'))) {
  55.             pn_exit (pnML('_UNABLETOLOADCLASS'array('s' => 'CategoryRegistryUtil')));
  56.         }
  57.         $catregistry CategoryRegistryUtil::getRegisteredModuleCategories ('FAQ''faqanswer');
  58.  
  59.         $pnRender->assign('catregistry'$catregistry);
  60.     }
  61.  
  62.     // Assign the module vars to the template
  63.     $pnRender->assign($modvars);
  64.  
  65.     // Return the output that has been generated by this function
  66.     return $pnRender->fetch('faq_admin_new.htm');
  67. }
  68.  
  69. /**
  70.  * Create an faq
  71.  *
  72.  * @author       The Zikula Development Team
  73.  * @param        name         the name of the item to be created
  74.  * @param        number       the number of the item to be created
  75.  */
  76. function FAQ_admin_create($args)
  77. {
  78.     // Get parameters from whatever input we need
  79.     $faq FormUtil::getPassedValue('faq'isset($args['faq']$args['faq'null'POST');
  80.  
  81.     // Confirm authorisation code
  82.     if (!SecurityUtil::confirmAuthKey()) {
  83.         return LogUtil::registerAuthidError (pnModURL('FAQ''admin''view'));
  84.     }
  85.  
  86.     // Create the FAQ
  87.     $faqid pnModAPIFunc('FAQ''admin''create'$faq);
  88.  
  89.     if ($faqid != false{
  90.         // Success
  91.     }
  92.  
  93.     return pnRedirect(pnModURL('FAQ''admin''view'));
  94. }
  95.  
  96. /**
  97.  * modify an faq
  98.  *
  99.  * @author       The Zikula Development Team
  100.  * @param        tid          the id of the item to be modified
  101.  * @return       output       the modification page
  102.  */
  103. function FAQ_admin_modify($args)
  104. {
  105.     $faqid FormUtil::getPassedValue('faqid'isset($args['faqid']$args['faqid'null'GET');
  106.     $objectid FormUtil::getPassedValue('objectid'isset($args['objectid']$args['objectid'null'GET');
  107.  
  108.     if (!empty($objectid)) {
  109.         $faqid $objectid;
  110.     }
  111.  
  112.     $item pnModAPIFunc('FAQ''user''get'array('faqid' => $faqid));
  113.     if (!$item{
  114.         return LogUtil::registerError (_NOSUCHITEM404);
  115.     }
  116.  
  117.     // Security check
  118.     if (!SecurityUtil::checkPermission'FAQ::'"$faqid::"ACCESS_EDIT)) {
  119.         return LogUtil::registerPermissionError();
  120.     }
  121.  
  122.     // Create output object
  123.     $pnRender pnRender::getInstance('FAQ'false);
  124.  
  125.     // Assign the item
  126.     $pnRender->assign($item);
  127.  
  128.     // load the categories system
  129.     if (!($class Loader::loadClass('CategoryRegistryUtil'))) {
  130.         pn_exit (pnML('_UNABLETOLOADCLASS'array('s' => 'CategoryRegistryUtil')));
  131.     }
  132.  
  133.     $categories CategoryRegistryUtil::getRegisteredModuleCategories ('FAQ''faqanswer');
  134.     $pnRender->assign('categories'$categories);
  135.  
  136.     $pnRender->assign(pnModGetVar('FAQ'));
  137.  
  138.     // Return the output that has been generated by this function
  139.     return $pnRender->fetch('faq_admin_modify.htm');
  140. }
  141.  
  142. /**
  143.  * update the faq
  144.  *
  145.  * @author       The Zikula Development Team
  146.  * @param        tid          the id of the item to be modified
  147.  * @param        name         the name of the item to be updated
  148.  * @param        number       the number of the item to be updated
  149.  */
  150. function FAQ_admin_update($args)
  151. {
  152.     $faq FormUtil::getPassedValue('faq'isset($args['faq']$args['faq'null'POST');
  153.     if (!empty($faq['objectid'])) {
  154.         $faq['faqid'$faq['objectid'];
  155.     }
  156.  
  157.     // Confirm authorisation code
  158.     if (!SecurityUtil::confirmAuthKey()) {
  159.         return LogUtil::registerAuthidError (pnModURL('FAQ''admin''view'));
  160.     }
  161.  
  162.     // Update FAQ
  163.     if (pnModAPIFunc('FAQ''admin''update'$faq)) {
  164.         // Success
  165.     }
  166.  
  167.     return pnRedirect(pnModURL('FAQ''admin''view'));
  168. }
  169.  
  170. /**
  171.  * delete an faq
  172.  *
  173.  * @author       The Zikula Development Team
  174.  * @param        tid            the id of the item to be modified
  175.  * @param        confirmation   confirmation that this item can be deleted
  176.  */
  177. function FAQ_admin_delete($args)
  178. {
  179.     $faqid FormUtil::getPassedValue('faqid'isset($args['faqid']$args['faqid'null'REQUEST');
  180.     $objectid FormUtil::getPassedValue('objectid'isset($args['objectid']$args['objectid'null'REQUEST');
  181.     $confirmation FormUtil::getPassedValue('confirmation'null'POST');
  182.     if (!empty($objectid)) {
  183.         $faqid $objectid;
  184.     }
  185.  
  186.     // Get the current FAQ
  187.     $item pnModAPIFunc('FAQ''user''get'array('faqid' => $faqid));
  188.  
  189.     if (!$item{
  190.         return LogUtil::registerError (_NOSUCHITEM404);
  191.     }
  192.  
  193.     // Security check
  194.     if (!SecurityUtil::checkPermission'FAQ::'"$faqid::"ACCESS_DELETE)) {
  195.         return LogUtil::registerPermissionError();
  196.     }
  197.  
  198.     // Check for confirmation.
  199.     if (empty($confirmation)) {
  200.         // No confirmation yet
  201.  
  202.         // Create output object
  203.         $pnRender pnRender::getInstance('FAQ'false);
  204.  
  205.         // Add a hidden field for the item ID to the output
  206.         $pnRender->assign('faqid'$faqid);
  207.  
  208.         // Return the output that has been generated by this function
  209.         return $pnRender->fetch('faq_admin_delete.htm');
  210.     }
  211.  
  212.     // If we get here it means that the user has confirmed the action
  213.  
  214.     // Confirm authorisation code
  215.     if (!SecurityUtil::confirmAuthKey()) {
  216.         return LogUtil::registerAuthidError (pnModURL('FAQ''admin''view'));
  217.     }
  218.  
  219.     // delete the faq
  220.     if (pnModAPIFunc('FAQ''admin''delete'array('faqid' => $faqid))) {
  221.         // Success
  222.     }
  223.  
  224.     return pnRedirect(pnModURL('FAQ''admin''view'));
  225. }
  226.  
  227. /**
  228.  * view items
  229.  *
  230.  * This function shows all items and lists the administration
  231.  * options.
  232.  *
  233.  * @author       The Zikula Development Team
  234.  * @param        startnum     The number of the first item to show
  235.  * @return       output       The main module admin page
  236.  */
  237. function FAQ_admin_view($args)
  238. {
  239.     // Security check
  240.     if (!SecurityUtil::checkPermission'FAQ::''::'ACCESS_EDIT)) {
  241.         return LogUtil::registerPermissionError();
  242.     }
  243.  
  244.     $startnum FormUtil::getPassedValue('startnum'isset($args['startnum']$args['startnum'null'GET');
  245.     $property FormUtil::getPassedValue('faq_property'isset($args['faq_property']$args['faq_property'null'POST');
  246.     $category FormUtil::getPassedValue("faq_{$property}_category"isset($args["faq_{$property}_category"]$args["faq_{$property}_category"null'POST');
  247.     $clear    FormUtil::getPassedValue('clear'false'POST');
  248.     if ($clear{
  249.         $property null;
  250.         $category null;
  251.     }
  252.  
  253.     // get module vars for later use
  254.     $modvars pnModGetVar('FAQ');
  255.  
  256.     if ($modvars['enablecategorization']{
  257.         // load the category registry util
  258.         if (!($class Loader::loadClass('CategoryRegistryUtil'))) {
  259.             pn_exit (pnML('_UNABLETOLOADCLASS'array('s' => 'CategoryRegistryUtil')));
  260.         }
  261.         $catregistry  CategoryRegistryUtil::getRegisteredModuleCategories('FAQ''faqanswer');
  262.         $properties array_keys($catregistry);
  263.  
  264.         // Validate and build the category filter - mateo
  265.         if (!empty($property&& in_array($property$properties&& !empty($category)) {
  266.             $catFilter array($property => $category);
  267.         }
  268.  
  269.         // Assign a default property - mateo
  270.         if (empty($property|| !in_array($property$properties)) {
  271.             $property $properties[0];
  272.         }
  273.  
  274.         // plan ahead for ML features
  275.         $propArray array();
  276.         foreach ($properties as $prop{
  277.             $propArray[$prop$prop;
  278.         }
  279.     }
  280.  
  281.     // get all faq's
  282.     $items pnModAPIFunc('FAQ''user''getall'
  283.                           array('startnum' => $startnum
  284.                                 'numitems' => $modvars['itemsperpage'],
  285.                                 'category' => isset($catFilter$catFilter null,
  286.                                 'catregistry'  => isset($catregistry$catregistry null));
  287.  
  288.     foreach ($items as $key => $item{
  289.         $options array();
  290.         if (SecurityUtil::checkPermission'FAQ::'"$item[faqid]::"ACCESS_EDIT)) {
  291.             $options[array('url'   => pnModURL('FAQ''admin''modify'array('faqid' => $item['faqid'])),
  292.                                'image' => 'xedit.gif',
  293.                                'title' => _EDIT);
  294.             if (SecurityUtil::checkPermission'FAQ::'"$item[faqid]::"ACCESS_DELETE)) {
  295.                 $options[array('url'   => pnModURL('FAQ''admin''delete'array('faqid' => $item['faqid'])),
  296.                                    'image' => '14_layer_deletelayer.gif',
  297.                                    'title' => _DELETE);
  298.             }
  299.         }
  300.  
  301.         // Add the calculated menu options to the item array
  302.         $items[$key]['options'$options;
  303.     }
  304.  
  305.     // Create output object
  306.     $pnRender pnRender::getInstance('FAQ'false);
  307.  
  308.     // Assign the items and modvars to the template
  309.     $pnRender->assign('faqs'$items);
  310.     $pnRender->assign($modvars);
  311.  
  312.     // Assign the default language
  313.     $pnRender->assign('lang'pnUserGetLang());
  314.  
  315.     // Assign the categories information if enabled
  316.     if ($modvars['enablecategorization']{
  317.         $pnRender->assign('catregistry'$catregistry);
  318.         $pnRender->assign('numproperties'count($propArray));
  319.         $pnRender->assign('properties'$propArray);
  320.         $pnRender->assign('property'$property);
  321.         $pnRender->assign("category"$category);
  322.     }
  323.  
  324.     // assign the values for the smarty plugin to produce a pager
  325.     $pnRender->assign('pager'array('numitems' => pnModAPIFunc('FAQ''user''countitems'array('category' => isset($catFilter$catFilter null)),
  326.                                      'itemsperpage' => $modvars['itemsperpage']));
  327.  
  328.     // Return the output that has been generated by this function
  329.     return $pnRender->fetch('faq_admin_view.htm');
  330. }
  331.  
  332. /**
  333.  * Modify configuration
  334.  *
  335.  * This is a standard function to modify the configuration parameters of the
  336.  * module
  337.  *
  338.  * @author       The Zikula Development Team
  339.  * @return       output       The configuration page
  340.  */
  341. {
  342.     // Security check
  343.     if (!SecurityUtil::checkPermission'FAQ::''::'ACCESS_ADMIN)) {
  344.         return LogUtil::registerPermissionError();
  345.     }
  346.  
  347.     // Create output object
  348.     $pnRender pnRender::getInstance('FAQ'false);
  349.  
  350.     // Assign all module vars
  351.     $pnRender->assign(pnModGetVar('FAQ'));
  352.  
  353.     // Return the output that has been generated by this function
  354.     return $pnRender->fetch('faq_admin_modifyconfig.htm');
  355. }
  356.  
  357. /**
  358.  * Update the configuration
  359.  *
  360.  * This is a standard function to update the configuration parameters of the
  361.  * module given the information passed back by the modification form
  362.  * Modify configuration
  363.  *
  364.  * @author       The Zikula Development Team
  365.  * @param        itemsperpage   number of items per page
  366.  */
  367. {
  368.     // Security check
  369.     if (!SecurityUtil::checkPermission'FAQ::''::'ACCESS_ADMIN)) {
  370.         return LogUtil::registerPermissionError();
  371.     }
  372.  
  373.     // Confirm authorisation code
  374.     if (!SecurityUtil::confirmAuthKey()) {
  375.         return LogUtil::registerAuthidError (pnModURL('FAQ''admin''view'));
  376.     }
  377.  
  378.     // Update module variables
  379.     $itemsperpage FormUtil::getPassedValue('itemsperpage'25'POST');
  380.     pnModSetVar('FAQ''itemsperpage'$itemsperpage);
  381.     $enablecategorization = (bool)FormUtil::getPassedValue('enablecategorization'false'POST');
  382.     pnModSetVar('FAQ''enablecategorization'$enablecategorization);
  383.     $addcategorytitletopermalink = (bool)FormUtil::getPassedValue('addcategorytitletopermalink'false'POST');
  384.     pnModSetVar('FAQ''addcategorytitletopermalink'$addcategorytitletopermalink);
  385.  
  386.     // The configuration has been changed, so we clear all caches for this module.
  387.     $pnRender pnRender::getInstance('FAQ');
  388.     $pnRender->clear_all_cache();
  389.  
  390.    // Let any other modules know that the modules configuration has been updated
  391.     pnModCallHooks('module','updateconfig','FAQ'array('module' => 'FAQ'));
  392.  
  393.     // the module configuration has been updated successfuly
  394.  
  395.     return pnRedirect(pnModURL('FAQ''admin''view'));
  396. }

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