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 Ephemerids
  11.  */
  12.  
  13. /**
  14.  * the main administration function
  15.  * This function is the default function, and is called whenever the
  16.  * module is initiated without defining arguments.  As such it can
  17.  * be used for a number of things, but most commonly it either just
  18.  * shows the module menu and returns or calls whatever the module
  19.  * designer feels should be the default function (often this is the
  20.  * view() function)
  21.  * @author Mark West
  22.  * @return string HTML string
  23.  */
  24. {
  25.     // Security check
  26.     if (!SecurityUtil::checkPermission('Ephemerids::''::'ACCESS_EDIT)) {
  27.         return LogUtil::registerPermissionError();
  28.     }
  29.  
  30.     // Create output object
  31.     $pnRender pnRender::getInstance('Ephemerids'false);
  32.  
  33.     // Return the output that has been generated by this function
  34.     return $pnRender->fetch('ephemerids_admin_main.htm');
  35. }
  36.  
  37. /**
  38.  * Add a new ephemerid
  39.  * This is a standard function that is called whenever an administrator
  40.  * wishes to create a new module item
  41.  * @author Mark West
  42.  * @return string HTML string
  43.  */
  44. {
  45.     // Security check
  46.     if (!SecurityUtil::checkPermission('Ephemerids::Item''::'ACCESS_ADD)) {
  47.         return LogUtil::registerPermissionError();
  48.     }
  49.  
  50.     // Create output object
  51.     $pnRender pnRender::getInstance('Ephemerids'false);
  52.  
  53.     // Assign the default language
  54.     $pnRender->assign('language'pnUserGetLang());
  55.  
  56.     // Return the output that has been generated by this function
  57.     return $pnRender->fetch('ephemerids_admin_new.htm');
  58. }
  59.  
  60. /**
  61.  * This is a standard function that is called with the results of the
  62.  * form supplied by Ephemerids_admin_new() to create a new item
  63.  * @author Mark West
  64.  * @param 'Date_Day' the day of the emphererid
  65.  * @param 'Date_Month' the month of the emphererid
  66.  * @param 'Date_Year' the year of the emphererid
  67.  * @param 'content' the ephmerid description
  68.  * @param 'language' the language of the ephemerid
  69.  * @return mixed ephemerid id on success, false on failiure
  70.  */
  71. function Ephemerids_admin_create($args)
  72. {
  73.     // Get parameters from whatever input we need
  74.     $ephemerid FormUtil::getPassedValue('ephemerid'isset($args['ephemerid']$args['ephemerid'null'POST');
  75.  
  76.     // Confirm authorisation code.
  77.     if (!SecurityUtil::confirmAuthKey()) {
  78.         return LogUtil::registerAuthidError (pnModURL('Ephemerids''admin''view'));
  79.     }
  80.  
  81.     // Notable by its absence there is no security check here.  This is because
  82.     // the security check is carried out within the API function
  83.  
  84.     // Create the ephemerid via the API
  85.     $eid pnModAPIFunc('Ephemerids''admin''create',
  86.                         array('did' => $ephemerid['Date_Day'],
  87.                               'mid' => $ephemerid['Date_Month'],
  88.                               'yid' => $ephemerid['Date_Year'],
  89.                               'content' => $ephemerid['content'],
  90.                               'language' => isset($ephemerid['language']$ephemerid['language'''));
  91.  
  92.     if ($eid != false{
  93.         // Success
  94.     }
  95.  
  96.     return pnRedirect(pnModURL('Ephemerids''admin''view'));
  97. }
  98.  
  99. /**
  100.  * Modify an ephemerid
  101.  * This is a standard function that is called whenever an administrator
  102.  * wishes to modify a current module item
  103.  * @author Mark West
  104.  * @param 'eid' the id of the item to be modified
  105.  * @param 'objectid' generic object id maps to eid if presents
  106.  * @return string HTML string
  107.  */
  108. function Ephemerids_admin_modify($args)
  109. {
  110.     $eid FormUtil::getPassedValue('eid'isset($args['eid']$args['eid'null'GET');
  111.     $objectid FormUtil::getPassedValue('objectid'isset($args['objectid']$args['objectid'null'GET');
  112.  
  113.     if (!empty($objectid)) {
  114.         $eid $objectid;
  115.     }
  116.  
  117.     $item pnModAPIFunc('Ephemerids''user''get'array('eid' => $eid));
  118.     if ($item == false{
  119.         return LogUtil::registerError (_NOSUCHITEM404);
  120.     }
  121.  
  122.     // Security check
  123.     if (!SecurityUtil::checkPermission('Ephemerids::'"$item[content]::$eid"ACCESS_EDIT)) {
  124.         return LogUtil::registerPermissionError();
  125.     }
  126.  
  127.     // calulate date for use in template
  128.     $item['date'$item['yid''-' $item['mid''-' $item['did'];
  129.  
  130.     // Create output object
  131.     $pnRender pnRender::getInstance('Ephemerids'false);
  132.  
  133.     // assign the item to the template
  134.     $pnRender->assign$item);
  135.  
  136.     // Return the output that has been generated by this function
  137.     return $pnRender->fetch('ephemerids_admin_modify.htm');
  138. }
  139.  
  140. /**
  141.  * This is a standard function that is called with the results of the
  142.  * form supplied by Ephemerids_admin_modify() to update a current item
  143.  * @author Mark West
  144.  * @param 'eid' the id of the ephemerid
  145.  * @param 'objectid' generic object id maps to eid if present
  146.  * @param 'Date_Day' the day of the emphererid
  147.  * @param 'Date_Month' the month of the emphererid
  148.  * @param 'Date_Year' the year of the emphererid
  149.  * @param 'content' the ephmerid description
  150.  * @param 'language' the language of the ephemerid
  151.  * @return bool true on update success, false on failiure
  152.  */
  153. function Ephemerids_admin_update($args)
  154. {
  155.     // Get parameters from whatever input we need
  156.     $ephemerid FormUtil::getPassedValue('ephemerid'isset($args['ephemerid']$args['ephemerid'null'POST');
  157.     if (!empty($ephemerid['objectid'])) {
  158.         $ephemerid['eid'$ephemerid['objectid'];
  159.     }
  160.  
  161.     // Confirm authorisation code.
  162.     if (!SecurityUtil::confirmAuthKey()) {
  163.         return LogUtil::registerAuthidError (pnModURL('Ephemerids''admin''view'));
  164.     }
  165.  
  166.     // Notable by its absence there is no security check here.  This is because
  167.     // the security check is carried out within the API function
  168.  
  169.     // Update the ephemerid
  170.     if (pnModAPIFunc('Ephemerids''admin''update',
  171.                     array('eid' => $ephemerid['eid'],
  172.                           'did' => $ephemerid['Date_Day'],
  173.                           'mid' => $ephemerid['Date_Month'],
  174.                           'yid' => $ephemerid['Date_Year'],
  175.                           'content' => $ephemerid['content'],
  176.                           'language' => isset($ephemerid['language']$ephemerid['language'''))) {
  177.         // Success
  178.     }
  179.  
  180.     return pnRedirect(pnModURL('Ephemerids''admin''view'));
  181. }
  182.  
  183. /**
  184.  * Delete an ephemerid
  185.  * This is a standard function that is called whenever an administrator
  186.  * wishes to delete a current module item.  Note that this function is
  187.  * the equivalent of both of the modify() and update() functions above as
  188.  * it both creates a form and processes its output.  This is fine for
  189.  * simpler functions, but for more complex operations such as creation and
  190.  * modification it is generally easier to separate them into separate
  191.  * functions.  There is no requirement in the Zikula MDG to do one or the
  192.  * other, so either or both can be used as seen appropriate by the module
  193.  * developer
  194.  * @author Mark West
  195.  * @param 'eid' the id of the ephemerid to be deleted
  196.  * @param 'objectid' generic object id maps to eid if present
  197.  * @param 'confirmation' confirmation that this item can be deleted
  198.  * @return mixed HTML string if no confirmation, true if delete successful, false otherwise
  199.  */
  200. function Ephemerids_admin_delete($args)
  201. {
  202.     $eid FormUtil::getPassedValue('eid'isset($args['eid']$args['eid'null'REQUEST');
  203.     $objectid FormUtil::getPassedValue('objectid'isset($args['objectid']$args['objectid'null'REQUEST');
  204.     $confirmation FormUtil::getPassedValue('confirmation'null'POST');
  205.     if (!empty($objectid)) {
  206.         $eid $objectid;
  207.     }
  208.  
  209.     $item pnModAPIFunc('Ephemerids''user''get'array('eid' => $eid));
  210.  
  211.     if ($item == false{
  212.         return LogUtil::registerError (_NOSUCHITEM404);
  213.     }
  214.  
  215.     // Security check
  216.     if (!SecurityUtil::checkPermission('Ephemerids::Item'"$item[content]::$eid"ACCESS_DELETE)) {
  217.         return LogUtil::registerPermissionError();
  218.     }
  219.  
  220.     // Check for confirmation.
  221.     if (empty($confirmation)) {
  222.         // No confirmation yet - display a suitable form to obtain confirmation
  223.         // of this action from the user
  224.  
  225.         // Create output object
  226.         $pnRender pnRender::getInstance('Ephemerids'false);
  227.  
  228.         // Ephemerid ID
  229.         $pnRender->assign('eid'$eid);
  230.  
  231.         // Return the output that has been generated by this function
  232.         return $pnRender->fetch('ephemerids_admin_delete.htm');
  233.     }
  234.  
  235.     // If we get here it means that the user has confirmed the action
  236.  
  237.     // Confirm authorisation code.
  238.     if (!SecurityUtil::confirmAuthKey()) {
  239.         return LogUtil::registerAuthidError (pnModURL('Ephemerids''admin''view'));
  240.     }
  241.  
  242.     // Delete the ephemerid
  243.     if (pnModAPIFunc('Ephemerids''admin''delete'array('eid' => $eid))) {
  244.         // Success
  245.     }
  246.  
  247.     return pnRedirect(pnModURL('Ephemerids''admin''view'));
  248. }
  249.  
  250. /**
  251.  * View ephemerids
  252.  * This is a standard function called to present the administrator with a list
  253.  * of all items held by the module.
  254.  * @author Mark West
  255.  * @return string HTML string
  256.  */
  257. {
  258.     // Security check
  259.     if (!SecurityUtil::checkPermission('Ephemerids::''::'ACCESS_EDIT)) {
  260.         return LogUtil::registerPermissionError();
  261.     }
  262.  
  263.     $startnum FormUtil::getPassedValue('startnum'isset($args['startnum']$args['startnum'null'GET');
  264.  
  265.     // Create output object
  266.     $pnRender pnRender::getInstance('Ephemerids'false);
  267.  
  268.     // The user API function is called.  This takes the number of items
  269.     // required and the first number in the list of all items, which we
  270.     // obtained from the input and gets us the information on the appropriate
  271.     // items.
  272.     $items pnModAPIFunc('Ephemerids''user''getall',
  273.                           array('startnum' => $startnum,
  274.                                 'numitems' => pnModGetVar('Ephemerids''itemsperpage')));
  275.  
  276.     $ephemerids array();
  277.     if (isset($items&& is_array($items)) {
  278.         foreach ($items as $item{
  279.             $row array();
  280.             if (SecurityUtil::checkPermission('Ephemerids::'"$item[content]::$item[eid]"ACCESS_READ)) {
  281.                 $options array();
  282.                 if (SecurityUtil::checkPermission('Ephemerids::'"$item[content]::$item[eid]"ACCESS_EDIT)) {
  283.                     $options[array('url' => pnModURL('Ephemerids''admin''modify'array('eid' => $item['eid'])),
  284.                                        'image' => 'xedit.gif',
  285.                                        'title' => _EDIT);
  286.                     if (SecurityUtil::checkPermission('Ephemerids::'"$item[content]::$item[eid]"ACCESS_DELETE)) {
  287.                         $options[array('url' => pnModURL('Ephemerids''admin''delete'array('eid' => $item['eid'])),
  288.                                            'image' => '14_layer_deletelayer.gif',
  289.                                            'title' => _DELETE);
  290.                     }
  291.                 }
  292.                 $item['options'$options;
  293.                 $item['datetime'DateUtil::formatDatetime(mktime(000$item['mid']$item['did']$item['yid'])_DATELONG);
  294.                 $ephemerids[$item;
  295.             }
  296.         }
  297.     }
  298.     $pnRender->assign('ephemerids'$ephemerids);
  299.  
  300.     // Assign the values for the smarty plugin to produce a pager
  301.     $pnRender->assign('pager'array('numitems' => pnModAPIFunc('Ephemerids''user''countitems'),
  302.                                      'itemsperpage' => pnModGetVar('Ephemerids''itemsperpage')));
  303.  
  304.     return $pnRender->fetch('ephemerids_admin_view.htm');
  305. }
  306.  
  307. /**
  308.  * This is a standard function to modify the configuration parameters of the
  309.  * module
  310.  * @author Mark West
  311.  * @return stringHTML string
  312.  */
  313. {
  314.     // Security check
  315.     if (!SecurityUtil::checkPermission('Ephemerids::''::'ACCESS_ADMIN)) {
  316.         return LogUtil::registerPermissionError();
  317.     }
  318.  
  319.     // Create output object
  320.     $pnRender pnRender::getInstance('Ephemerids'false);
  321.  
  322.     // Number of items to display per page
  323.     $pnRender->assign(pnModGetVar('Ephemerids'));
  324.  
  325.     // Return the output that has been generated by this function
  326.     return $pnRender->fetch('ephemerids_admin_modifyconfig.htm');
  327. }
  328.  
  329. /**
  330.  * This is a standard function to update the configuration parameters of the
  331.  * module given the information passed back by the modification form
  332.  * @author Mark West
  333.  * @return bool true if update successful, false otherwise
  334.  */
  335. {
  336.     // Security check
  337.     if (!SecurityUtil::checkPermission('Ephemerids::''::'ACCESS_ADMIN)) {
  338.         return LogUtil::registerPermissionError();
  339.     }
  340.  
  341.     // Confirm authorisation code
  342.     if (!SecurityUtil::confirmAuthKey()) {
  343.         return LogUtil::registerAuthidError (pnModURL('Ephemerids''admin''view'));
  344.     }
  345.  
  346.     $itemsperpage FormUtil::getPassedValue('itemsperpage'25'POST');
  347.     pnModSetVar('Ephemerids''itemsperpage'$itemsperpage);
  348.  
  349.     // Let any other modules know that the modules configuration has been updated
  350.     pnModCallHooks('module','updateconfig','Ephemerids'array('module' => 'Ephemerids'));
  351.  
  352.     // the module configuration has been updated successfuly
  353.  
  354.     return pnRedirect(pnModURL('Ephemerids''admin''view'));
  355. }

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