Zikula_Value_Addons
[ class tree: Zikula_Value_Addons ] [ index: Zikula_Value_Addons ] [ 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_Value_Addons
  10.  * @subpackage FAQ
  11.  */
  12.  
  13. /**
  14.  * create a new FAQ
  15.  *
  16.  * @param    $args['question']      name of the item
  17.  * @param    $args['answer']        number of the item
  18.  * @param    $args['submittedby']   name of the submitter (if anonymous) (optional)
  19.  * @param    $args['submittedbyid'] id of the submitter (if logged in) (optional)
  20.  * @param    $args['answeredbyid']  id of the answerer (optional)
  21.  * @return   mixed                  FAQ ID on success, false on failure
  22.  */
  23. function FAQ_adminapi_create($faq)
  24. {
  25.     // Argument check
  26.     if (!isset($faq['question']||
  27.         !isset($faq['answer'])) {
  28.         return LogUtil::registerError (_MODARGSERROR);
  29.     }
  30.  
  31.     // optional arguments
  32.     if (!isset($faq['submittedby'])) {
  33.         $faq['submittedby''';
  34.     }
  35.     if (!isset($faq['submittedbyid'])) {
  36.         $faq['submittedbyid'pnUserGetVar('uid');
  37.     }
  38.     if (!isset($faq['answeredbyid'])) {
  39.         if (strlen($faq['answer']0{
  40.             $faq['answeredbyid'$faq['submittedbyid'];
  41.         else {
  42.             $faq['answeredbyid''';
  43.         }
  44.     }
  45.  
  46.     // define the permalink title if not present
  47.     if (!isset($faq['urltitle']|| empty($faq['urltitle'])) {
  48.         $faq['urltitle'DataUtil::formatPermalink($faq['question']);
  49.     }
  50.  
  51.     // Security check
  52.     if (!SecurityUtil::checkPermission'FAQ::''::'ACCESS_COMMENT)) {
  53.         return LogUtil::registerPermissionError();
  54.     }
  55.  
  56.     if (!DBUtil::insertObject($faq'faqanswer''faqid')) {
  57.         return LogUtil::registerError (_CREATEFAILED);
  58.     }
  59.  
  60.     // Let any hooks know that we have created a new item
  61.     pnModCallHooks('item''create'$faq['faqid']array('module' => 'FAQ'));
  62.  
  63.     // Return the id of the newly created item to the calling process
  64.     return $faq['faqid'];
  65. }
  66.  
  67. /**
  68.  * delete an faq
  69.  *
  70.  * @param    $args['faqid']   ID of the item
  71.  * @return   bool           true on success, false on failure
  72.  */
  73. function FAQ_adminapi_delete($args)
  74. {
  75.     // Argument check 
  76.     if (!isset($args['faqid']|| !is_numeric($args['faqid'])) {
  77.         return LogUtil::registerError (_MODARGSERROR);
  78.     }
  79.  
  80.     // Get the current faq
  81.     $item pnModAPIFunc('FAQ''user''get'array('faqid' => $args['faqid']));
  82.  
  83.     if (!$item{
  84.         return LogUtil::registerError (_NOSUCHITEM);
  85.     }
  86.  
  87.     // Security check
  88.     if (!SecurityUtil::checkPermission'FAQ::'"$args[faqid]::"ACCESS_DELETE)) {
  89.         return LogUtil::registerPermissionError();
  90.     }
  91.  
  92.     if (!DBUtil::deleteObjectByID('faqanswer'$args['faqid']'faqid')) {
  93.         return LogUtil::registerError (_DELETEFAILED);
  94.     }
  95.  
  96.     // Let any hooks know that we have deleted an item
  97.     pnModCallHooks('item''delete'$args['faqid']array('module' => 'FAQ'));
  98.  
  99.     // The item has been deleted, so we clear all cached pages of this item.
  100.     $pnRender pnRender::getInstance('FAQ');
  101.     $pnRender->clear_cache(null$args['faqid']);
  102.  
  103.     return true;
  104. }
  105.  
  106. /**
  107.  * update an item
  108.  *
  109.  * @param    $args['faqid']         the ID of the item
  110.  * @param    $args['question']      the new name of the item
  111.  * @param    $args['answer']        the new number of the item
  112.  * @param    $args['submittedby']   name of the submitter (if anonymous)
  113.  * @param    $args['submittedbyid'] id of the submitter (if logged in)
  114.  * @param    $args['answeredbyid']  id of the answerer (optional)
  115.  * @return   bool             true on success, false on failure
  116.  */
  117. function FAQ_adminapi_update($faq)
  118. {
  119.     // Argument check
  120.     if (!isset($faq['question']||
  121.         !isset($faq['answer']||
  122.         !isset($faq['faqid']|| !is_numeric($faq['faqid'])) {
  123.         return LogUtil::registerError (_MODARGSERROR);
  124.     }
  125.  
  126.     // optional arguments
  127.     if (!isset($faq['answeredbyid'])) {
  128.         if (strlen($faq['answer']0{
  129.             $faq['answeredbyid'pnUserGetVar('uid');
  130.         else {
  131.             $faq['answeredbyid''';
  132.         }
  133.     }
  134.  
  135.     // define the permalink title if not present
  136.     if (!isset($faq['urltitle']|| empty($faq['urltitle'])) {
  137.         $faq['urltitle'DataUtil::formatPermalink($faq['question']);
  138.     }
  139.  
  140.     // Get the current faq
  141.     $item pnModAPIFunc('FAQ''user''get'array('faqid' => $faq['faqid']));
  142.  
  143.     if (!$item{
  144.         return LogUtil::registerError (_NOSUCHITEM);
  145.     }
  146.  
  147.     // Security check.
  148.     if (!SecurityUtil::checkPermission'FAQ::'"$faq[faqid]::"ACCESS_EDIT)) {
  149.         return LogUtil::registerPermissionError();
  150.     }
  151.  
  152.     if (!DBUtil::updateObject($faq'faqanswer''''faqid')) {
  153.         return LogUtil::registerError (_UPDATEFAILED);
  154.     }
  155.  
  156.     // The item has been modified, so we clear all cached pages of this item.
  157.     $pnRender pnRender::getInstance('FAQ');
  158.     $pnRender->clear_cache(null$faq['faqid']);
  159.  
  160.     // Let any hooks know that we have updated an item
  161.     pnModCallHooks('item''update'$faq['faqid']array('module' => 'FAQ'));
  162.  
  163.     return true;
  164. }
  165.  
  166. /**
  167.  * get available admin panel links
  168.  *
  169.  * @author Mark West
  170.  * @return array array of admin links
  171.  */
  172. {
  173.     $links array();
  174.  
  175.     pnModLangLoad('FAQ''admin');
  176.  
  177.     if (SecurityUtil::checkPermission('FAQ::''::'ACCESS_READ)) {
  178.         $links[array('url' => pnModURL('FAQ''admin''view')'text' => _FAQ_VIEW);
  179.     }
  180.     if (SecurityUtil::checkPermission('FAQ::''::'ACCESS_ADD)) {
  181.         $links[array('url' => pnModURL('FAQ''admin''new')'text' => _FAQ_CREATE);
  182.     }
  183.     if (SecurityUtil::checkPermission('FAQ::''::'ACCESS_ADMIN)) {
  184.         $links[array('url' => pnModURL('FAQ''admin''modifyconfig')'text' => _MODIFYCONFIG);
  185.     }
  186.  
  187.     return $links;
  188. }

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