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

Source for file pnuser.php

Documentation is available at pnuser.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: pnuser.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 user function
  15.  *
  16.  * This function is the default function, and is called whenever the module is
  17.  * initiated without defining arguments.  As such it can be used for a number
  18.  * of things, but most commonly it either just shows the module menu and
  19.  * returns or calls whatever the module designer feels should be the default
  20.  * function (often this is the view() function)
  21.  *
  22.  * @author       The Zikula Development Team
  23.  * @return       output       The main module page
  24.  */
  25. function FAQ_user_main()
  26. {
  27.     // Security check
  28.     if (!SecurityUtil::checkPermission'FAQ::''::'ACCESS_OVERVIEW)) {
  29.         return LogUtil::registerPermissionError();
  30.     }
  31.  
  32.     // Create output object
  33.     $pnRender pnRender::getInstance('FAQ');
  34.  
  35.     // load the categories system
  36.     if (pnModGetVar('FAQ''enablecategorization')) {
  37.         if (!($class Loader::loadClass('CategoryUtil')) || !($class Loader::loadClass('CategoryRegistryUtil'))) {
  38.             pn_exit (pnML('_UNABLETOLOADCLASS'array('s' => 'CategoryUtil | CategoryRegistryUtil')));
  39.         }
  40.         $catregistry CategoryRegistryUtil::getRegisteredModuleCategories('FAQ''faqanswer');
  41.         $categories array();
  42.         $ak array_keys($catregistry);
  43.         foreach ($ak as $k{
  44.             $categories[$kCategoryUtil::getCategoryByID($catregistry[$k]);
  45.             $categories[$k]['path'.= '/';
  46.             $categories[$k]['subcategories'CategoryUtil::getCategoriesByParentID($catregistry[$k]);
  47.         }
  48.         $pnRender->assign('categories'$categories);
  49.     }
  50.  
  51.     $pnRender->assign('lang'pnUserGetLang());
  52.     $pnRender->assign(pnModGetVar('FAQ'));
  53.     $pnRender->assign('shorturls'pnConfigGetVar('shorturls'));
  54.     $pnRender->assign('shorturlstype'pnConfigGetVar('shorturlstype'));
  55.  
  56.     // Return the output that has been generated by this function
  57.     return $pnRender->fetch('faq_user_main.htm');
  58. }
  59.  
  60. /**
  61.  * view items
  62.  *
  63.  * This is a standard function to provide an overview of all of the items
  64.  * available from the module.
  65.  *
  66.  * @author       The Zikula Development Team
  67.  * @param        integer      $startnum    (optional) The number of the start item
  68.  * @return       output       The overview page
  69.  */
  70. function FAQ_user_view()
  71. {
  72.     // Security check
  73.     if (!SecurityUtil::checkPermission'FAQ::''::'ACCESS_OVERVIEW)) {
  74.         return LogUtil::registerPermissionError();
  75.     }
  76.  
  77.     $startnum = (int)FormUtil::getPassedValue('startnum'isset($args['startnum']$args['startnum'1'GET');
  78.     $cat      = (string)FormUtil::getPassedValue('cat'isset($args['cat']$args['cat'null'GET');
  79.     $prop     = (string)FormUtil::getPassedValue('prop'isset($args['prop']$args['prop'null'GET');
  80.     $func     = (string)FormUtil::getPassedValue('func');
  81.  
  82.     // defaults and input validation
  83.     if (!is_numeric($startnum|| $startnum 0{
  84.         $startnum 1;
  85.     }
  86.  
  87.     // get all module vars for later use
  88.     $modvars pnModGetVar('FAQ');
  89.  
  90.     // check if categorisation is enabled
  91.     // and if its requested to list the recent faqs
  92.     if ($modvars['enablecategorization'&& !empty($prop&& !empty($cat)) {
  93.         if (!($class Loader::loadClass('CategoryUtil')) || !($class Loader::loadClass('CategoryRegistryUtil'))) {
  94.             pn_exit (pnML('_UNABLETOLOADCLASS'array('s' => 'CategoryUtil | CategoryRegistryUtil')));
  95.         }
  96.         // get the categories registered for the Pages
  97.         $catregistry CategoryRegistryUtil::getRegisteredModuleCategories('FAQ''faqanswer');
  98.         $properties  array_keys($catregistry);
  99.  
  100.         // if the property and the category are specified
  101.         // means that we'll list the FAQs that belongs to that category
  102.         if (in_array($prop$properties)) {
  103.             if (!is_numeric($cat)) {
  104.                 $rootCat CategoryUtil::getCategoryByID($catregistry[$prop]);
  105.                 $cat CategoryUtil::getCategoryByPath($rootCat['path'].'/'.$cat);
  106.             else {
  107.                 $cat CategoryUtil::getCategoryByID($cat);
  108.             }
  109.             if (!empty($cat&& isset($cat['path'])) {
  110.                 // include all it's subcategories and build the filter
  111.                 $categories categoryUtil::getCategoriesByPath($cat['path']'''path');
  112.                 $catstofilter array();
  113.                 foreach ($categories as $category{
  114.                     $catstofilter[$category['id'];
  115.                 }
  116.                 $catFilter array($prop => $catstofilter)
  117.             else {
  118.                 LogUtil::registerError(_NOTAVALIDCATEGORY);
  119.             }
  120.         }
  121.     }
  122.  
  123.     // get all faqs
  124.     $items pnModAPIFunc('FAQ''user''getall',
  125.                           array('startnum' => $startnum,
  126.                                 'numitems' => $modvars['itemsperpage'],
  127.                                 'answered' => true,
  128.                                 'category' => isset($catFilter$catFilter null,
  129.                                 'catregistry' => isset($catregistry$catregistry null));
  130.  
  131.     // Create output object
  132.     $pnRender pnRender::getInstance('FAQ'false);
  133.  
  134.     // assign various useful template variables
  135.     $pnRender->assign('startnum'$startnum);
  136.     $pnRender->assign('category'$cat);
  137.     $pnRender->assign('property'$prop);
  138.     $pnRender->assign('lang'pnUserGetLang());
  139.     $pnRender->assign($modvars);
  140.     $pnRender->assign('shorturls'pnConfigGetVar('shorturls'));
  141.     $pnRender->assign('shorturlstype'pnConfigGetVar('shorturlstype'));
  142.  
  143.     // Loop through each item getting the rendered output from the item template
  144.     $faqitems array();
  145.     $faqs array();
  146.     foreach ($items as $item{
  147.         if (SecurityUtil::checkPermission'FAQ::'"$item[faqid]::"ACCESS_OVERVIEW)) {
  148.             $pnRender->assign($item);
  149.             $faqitems[$pnRender->fetch('faq_user_row_read.htm'$item['faqid']);
  150.             $faqs[$item;
  151.         }
  152.     }
  153.  
  154.     // Display the entries
  155.     $pnRender->assign('items'$faqitems);
  156.     $pnRender->assign('faqs'$faqs);
  157.     $pnRender->assign('func'$func);
  158.  
  159.     // assign the start number
  160.     $pnRender->assign('startnum'$startnum);
  161.  
  162.     // assign the values for the smarty plugin to produce a pager
  163.     $pnRender->assign('pager'array('numitems'     => pnModAPIFunc('FAQ''user''countitems'array('category' => isset($catFilter$catFilter null)),
  164.                                      'itemsperpage' => pnModGetVar('FAQ''itemsperpage')));
  165.  
  166.     // Return the output that has been generated by this function
  167.     return $pnRender->fetch('faq_user_view.htm');
  168. }
  169.  
  170. /**
  171.  * display item
  172.  *
  173.  * This is a standard function to provide detailed informtion on a single item
  174.  * available from the module.
  175.  *
  176.  * @author       The Zikula Development Team
  177.  * @param        integer      $tid     the ID of the item to display
  178.  * @return       output       The item detail page
  179.  */
  180. function FAQ_user_display($args)
  181. {
  182.     $faqid FormUtil::getPassedValue('faqid'isset($args['faqid']$args['faqid'null'REQUEST');
  183.     $title FormUtil::getPassedValue('title'isset($args['title']$args['title'null'REQUEST');
  184.     $objectid FormUtil::getPassedValue('objectid'isset($args['objectid']$args['objectid'null'REQUEST');
  185.     if (!empty($objectid)) {
  186.         $faqid $objectid;
  187.     }
  188.  
  189.     if (!is_numeric($faqid&& !is_string($title)) {
  190.         return LogUtil::registerError (_MODARGSERROR);
  191.     }
  192.  
  193.     // Create output object
  194.     $pnRender pnRender::getInstance('FAQ');
  195.  
  196.     // set the cache id
  197.     if (isset($faqid&& is_numeric($faqid)) {
  198.         $pnRender->cache_id $faqid;
  199.     else {
  200.         $pnRender->cache_id $faqid;
  201.     }
  202.     
  203.     // check out if the contents are cached.
  204.     if ($pnRender->is_cached('faq_user_display.htm')) {
  205.        return $pnRender->fetch('FAQ_user_display.htm');
  206.     }
  207.  
  208.     // Get the faq
  209.     if (isset($faqid&& is_numeric($faqid)) {
  210.         $item pnModAPIFunc('FAQ''user''get'array('faqid' => $faqid));
  211.     else {
  212.         $item pnModAPIFunc('FAQ''user''get'array('title' => $title));
  213.     }
  214.  
  215.     if (!$item{
  216.         return DataUtil::formatForDisplayHTML(_FAQ_ITEMFAILED);
  217.     }
  218.  
  219.     // set the page title
  220.     PageUtil::setVar('title'$item['question']);
  221.  
  222.     // Assign details of the item.
  223.     $pnRender->assign($item);
  224.  
  225.     // Return the output that has been generated by this function
  226.     return $pnRender->fetch('faq_user_display.htm');
  227. }
  228.  
  229. /**
  230.  * ask a question
  231.  *
  232.  * @author       The Zikula Development Team
  233.  * @return       output       A form to submit a question
  234.  */
  235. function FAQ_user_ask()
  236. {
  237.     // Security check
  238.     if (!SecurityUtil::checkPermission'FAQ::''::'ACCESS_COMMENT)) {
  239.         return LogUtil::registerPermissionError();
  240.     }
  241.  
  242.     // Create output object
  243.     $pnRender pnRender::getInstance('FAQ');
  244.  
  245.     // assign logged in state
  246.     $pnRender->assign('loggedin'pnUserLoggedIn());
  247.  
  248.     // Return the output that has been generated by this function
  249.     return $pnRender->fetch('faq_user_ask.htm');
  250.  
  251. }
  252.  
  253. /**
  254.  * Create an faq
  255.  *
  256.  * @author       The Zikula Development Team
  257.  * @param        question     the question to be submitted
  258.  */
  259. function FAQ_user_create($args)
  260. {
  261.     // Get parameters from whatever input we need
  262.     $faq FormUtil::getPassedValue('faq'isset($args['faq']$args['faq'null'POST');
  263.  
  264.     // Confirm authorisation code
  265.     if (!SecurityUtil::confirmAuthKey()) {
  266.         return LogUtil::registerAuthidError (pnModURL('FAQ''user''view'));
  267.     }
  268.  
  269.     if (pnUserLoggedIn(|| !isset($faq['submittedby'])) {
  270.         $faq['submittedby''';
  271.     }
  272.  
  273.     // Create the FAQ
  274.     $faqid pnModAPIFunc('FAQ''admin''create',
  275.                           array('question' => $faq['question'],
  276.                                 'answer' => '',
  277.                                 'submittedby' => $faq['submittedby']));
  278.  
  279.     if ($faqid != false{
  280.         // Success
  281.         LogUtil::registerStatus (_FAQ_CREATED);
  282.     }
  283.  
  284.     return pnRedirect(pnModURL('FAQ''user''view'));
  285. }

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