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_Messages
  11.  */
  12.  
  13. /**
  14.  * create a new Admin_Messages item
  15.  * @author Mark West
  16.  * @param string $args['title'] title of the admin message
  17.  * @param string $args['content'] text of the admin message
  18.  * @param string $args['language'] the language of the message
  19.  * @param int $args['active'] activation status of the message
  20.  * @param int $args['expire'] expiry date of the message
  21.  * @param int $args['view'] who can view the message
  22.  * @return mixed Admin_Messages item ID on success, false on failure
  23.  */
  24. {
  25.     // Argument check
  26.     if (!isset($args['title'])    ||
  27.         !isset($args['content'])  ||
  28.         !isset($args['language']||
  29.         !isset($args['active'])   ||
  30.         !isset($args['expire'])   ||
  31.         !isset($args['view'])) {
  32.         return LogUtil::registerError (_MODARGSERROR);
  33.     }
  34.     if (empty($args['title']&& empty($args['content'])) {
  35.         return LogUtil::registerError (_MODARGSERROR);
  36.     }
  37.  
  38.     // Security check
  39.     if (!SecurityUtil::checkPermission('Admin_Messages::''::'ACCESS_ADD)) {
  40.         return LogUtil::registerPermissionError ();
  41.     }
  42.  
  43.     // create the item array
  44.     $item array('title' => $args['title']'content' => $args['content'],
  45.                   'language' => $args['language']'active' => $args['active']'view' => $args['view']);
  46.  
  47.     // add some additional modified values
  48.     if ($args['expire'0{
  49.         $args['expire'0;
  50.     }
  51.     $item['expire'$args['expire'86400// turns days into seconds
  52.     $item['date'time();
  53.  
  54.     if (!DBUtil::insertObject($item'message''mid')) {
  55.         return LogUtil::registerError (_CREATEFAILED);
  56.     }
  57.  
  58.     // Let any hooks know that we have created a new item.
  59.     pnModCallHooks('item''create'$item['mid']array('module' => 'Admin_Messages'));
  60.  
  61.     // Return the id of the newly created item to the calling process
  62.     return $item['mid'];
  63. }
  64.  
  65. /**
  66.  * delete an Admin_Messages item
  67.  * @author Mark West
  68.  * @param int $args['mid'] ID of the admin message to delete
  69.  * @return bool true on success, false on failure
  70.  */
  71. {
  72.     // Argument check
  73.     if (!isset($args['mid'])) {
  74.         return LogUtil::registerError (_MODARGSERROR);
  75.     }
  76.  
  77.     // Get the existing admin message
  78.     $item pnModAPIFunc('Admin_Messages''user''get'array('mid' => $args['mid']));
  79.  
  80.     if ($item == false{
  81.         return LogUtil::registerError (_NOSUCHITEM);
  82.     }
  83.  
  84.     // Security check
  85.     if (!SecurityUtil::checkPermission('Admin_Messages::'"$item[title]::$args[mid]"ACCESS_DELETE)) {
  86.         return LogUtil::registerPermissionError ();
  87.     }
  88.  
  89.     if (!DBUtil::deleteObjectByID('message'$args['mid']'mid')) {
  90.         return LogUtil::registerError (_DELETEFAILED);
  91.     }
  92.  
  93.     // Let any hooks know that we have deleted an item.
  94.     pnModCallHooks('item''delete'$args['mid']array('module' => 'Admin_Messages'));
  95.  
  96.     // The item has been modified, so we clear all cached pages of this item.
  97.     $pnRender pnRender::getInstance('Admin_Messages');
  98.     $pnRender->clear_cache(nullpnUserGetVar('uid'));
  99.  
  100.     // Let the calling process know that we have finished successfully
  101.     return true;
  102. }
  103.  
  104. /**
  105.  * update a Admin_Messages item
  106.  * @author Mark West
  107.  * @param int $args['mid'] the ID of the item
  108.  * @param sting $args['title'] title of the admin message
  109.  * @param string $args['content'] text of the admin message
  110.  * @param string $args['language'] the language of the message
  111.  * @param int $args['active'] activation status of the message
  112.  * @param int $args['expire'] expiry date of the message
  113.  * @param int $args['view'] who can view the message
  114.  * @return bool true if successful, false otherwise
  115.  */
  116. {
  117.     // Argument check
  118.     if (!isset($args['mid'])            ||
  119.         !isset($args['title'])          ||
  120.         !isset($args['content'])        ||
  121.         !isset($args['language'])       ||
  122.         !isset($args['active'])         ||
  123.         !isset($args['expire'])         ||
  124.         !isset($args['oldtime'])        ||
  125.         !isset($args['changestartday']||
  126.         !isset($args['view'])) {
  127.         return LogUtil::registerError (_MODARGSERROR);
  128.     }
  129.  
  130.     // Get the existing admin message
  131.     $item pnModAPIFunc('Admin_Messages''user''get'array('mid' => $args['mid']));
  132.  
  133.     if ($item == false{
  134.         return LogUtil::registerError (_NOSUCHITEM);
  135.     }
  136.  
  137.     // Security check
  138.     if (!SecurityUtil::checkPermission('Admin_Messages::'"$item[title]::$args[mid]"ACCESS_EDIT)) {
  139.         return LogUtil::registerPermissionError ();
  140.     }
  141.  
  142.     // check value of change start day to today and set time
  143.     if ($args['changestartday'== 1{
  144.         $time time();
  145.     else {
  146.         $time $args['oldtime'];
  147.     }
  148.  
  149.     // check for an invalid expiry
  150.     if ($args['expire'0{
  151.         $expire 0;
  152.     }
  153.  
  154.     // create the item array
  155.     $item array('mid' => $args['mid']'title' => $args['title']'content' => $args['content'],
  156.                   'language' => $args['language']'active' => $args['active']'view' => $args['view']);
  157.  
  158.     // add some additional modified values
  159.     $args['expire'$args['expire'86400// turns days into seconds
  160.     $args['date'$time;
  161.  
  162.     if (!DBUtil::updateObject($args'message''''mid')) {
  163.         return LogUtil::registerError (_UPDATEFAILED);
  164.     }
  165.  
  166.     // New hook functions
  167.     pnModCallHooks('item''update'$args['mid']array('module' => 'Admin_Messages'));
  168.  
  169.     // The item has been modified, so we clear all cached pages of this item.
  170.     $pnRender pnRender::getInstance('Admin_Messages');
  171.     $pnRender->clear_cache(nullpnUserGetVar('uid'));
  172.  
  173.     // Let the calling process know that we have finished successfully
  174.     return true;
  175. }
  176.  
  177. /**
  178.  * get available admin panel links
  179.  *
  180.  * @author Mark West
  181.  * @return array array of admin links
  182.  */
  183. {
  184.     $links array();
  185.  
  186.     pnModLangLoad('Admin_Messages''admin');
  187.  
  188.     if (SecurityUtil::checkPermission('Admin_Messages::''::'ACCESS_READ)) {
  189.         $links[array('url' => pnModURL('Admin_Messages''admin''view')'text' => _ADMINMESSAGES_VIEWMESSAGES);
  190.     }
  191.     if (SecurityUtil::checkPermission('Admin_Messages::''::'ACCESS_ADD)) {
  192.         $links[array('url' => pnModURL('Admin_Messages''admin''new')'text' => _ADMINMESSAGES_CREATEMESSAGE);
  193.     }
  194.     if (SecurityUtil::checkPermission('Admin_Messages::''::'ACCESS_ADMIN)) {
  195.         $links[array('url' => pnModURL('Admin_Messages''admin''modifyconfig')'text' => _MODIFYCONFIG);
  196.     }
  197.  
  198.     return $links;
  199. }

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