Zikula_System_Modules
[ class tree: Zikula_System_Modules ] [ index: Zikula_System_Modules ] [ 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_System_Modules
  10.  * @subpackage Admin_Messages
  11.  * @license http://www.gnu.org/copyleft/gpl.html
  12.  */
  13.  
  14. /**
  15.  * the main administration function
  16.  * This function is the default function, and is called whenever the
  17.  * module is initiated without defining arguments.  As such it can
  18.  * be used for a number of things, but most commonly it either just
  19.  * shows the module menu and returns or calls whatever the module
  20.  * designer feels should be the default function (often this is the
  21.  * view() function)
  22.  * @author Mark West
  23.  * @return string HTML output string
  24.  */
  25. {
  26.     // Security check
  27.     if (!SecurityUtil::checkPermission('Admin_Messages::''::'ACCESS_EDIT)) {
  28.         return LogUtil::registerPermissionError ();
  29.     }
  30.  
  31.     // Create output object
  32.     $pnRender pnRender::getInstance('Admin_Messages'false);
  33.  
  34.     // Return the output that has been generated by this function
  35.     return $pnRender->fetch('admin_messages_admin_main.htm');
  36. }
  37.  
  38. /**
  39.  * add a new admin message
  40.  * This is a standard function that is called whenever an administrator
  41.  * wishes to create a new module item
  42.  * @author Mark West
  43.  * @return string HTML output string
  44.  */
  45. {
  46.     // Security check
  47.     if (!SecurityUtil::checkPermission('Admin_Messages::''::'ACCESS_ADD)) {
  48.         return LogUtil::registerPermissionError ();
  49.     }
  50.  
  51.     // Create output object
  52.     $pnRender pnRender::getInstance('Admin_Messages'false);
  53.  
  54.     // Assign the default language
  55.     $pnRender->assign('language'pnUserGetLang());
  56.  
  57.     // Return the output that has been generated by this function
  58.     return $pnRender->fetch('admin_messages_admin_new.htm');
  59. }
  60.  
  61. /**
  62.  * This is a standard function that is called with the results of the
  63.  * form supplied by Admin_Messages_admin_new() to create a new item
  64.  * @author Mark West
  65.  * @see Admin_Messages_admin_new()
  66.  * @param string $args['title'] the title of the admin message
  67.  * @param string $args['content'] the text of the admin message
  68.  * @param string $args['language'] the language of the admin message
  69.  * @param int $args['active'] active status of the admin message
  70.  * @param int $args['expire'] the expiry date of the message
  71.  * @param int $args['view'] who can view the message
  72.  * @return bool true if creation successful, false otherwiise
  73.  */
  74. {
  75.     $message FormUtil::getPassedValue('message'isset($args['message']$args['message'null'POST');
  76.  
  77.     // Confirm authorisation code.
  78.     if (!SecurityUtil::confirmAuthKey()) {
  79.         return LogUtil::registerAuthidError ();
  80.     }
  81.  
  82.     // Notable by its absence there is no security check here.
  83.     // Create the admin message
  84.     $mid pnModAPIFunc('Admin_Messages''admin''create',
  85.                          array('title' => $message['title'],
  86.                                'content' => $message['content'],
  87.                                'language' => isset($message['language']$message['language''',
  88.                                'active' => $message['active'],
  89.                                'expire' => $message['expire'],
  90.                                'view' => $message['view']));
  91.  
  92.     // The return value of the function is checked
  93.     if ($mid != false{
  94.         // Success
  95.         LogUtil::registerStatus (pnML('_CREATEITEMSUCCEDED'array('i' => _ADMINMESSAGES_MESSAGE)));
  96.     }
  97.  
  98.     // This function generated no output, and so now it is complete we redirect
  99.     // the user to an appropriate page for them to carry on their work
  100.     return pnRedirect(pnModURL('Admin_Messages''admin''view'));
  101. }
  102.  
  103. /**
  104.  * modify an Admin Message
  105.  * This is a standard function that is called whenever an administrator
  106.  * wishes to modify a current module item
  107.  * @author Mark West
  108.  * @param int $args['mid'] the id of the admin message to modify
  109.  * @param int $args['objectid'] generic object id maps to mid if present
  110.  * @return string HTML output string
  111.  */
  112. {
  113.     $mid FormUtil::getPassedValue('mid'isset($args['mid']$args['mid'null'GET');
  114.     $objectid FormUtil::getPassedValue('objectid'isset($args['objectid']$args['objectid'null'GET');
  115.  
  116.     if (!empty($objectid)) {
  117.         $mid $objectid;
  118.     }
  119.  
  120.     // Create output object
  121.     $pnRender pnRender::getInstance('Admin_Messages'false);
  122.  
  123.     // Get the admin message
  124.     $item pnModAPIFunc('Admin_Messages''user''get'array('mid' => $mid));
  125.  
  126.     if ($item == false{
  127.         return LogUtil::registerError(pnML('_NOSUCHITEMFOUND'array('i' => _ADMINMESSAGES_MESSAGE))404);
  128.     }
  129.  
  130.     // Security check.
  131.     if (!SecurityUtil::checkPermission('Admin_Messages::item'"$item[title]::$mid"ACCESS_EDIT)) {
  132.         return LogUtil::registerPermissionError ();
  133.     }
  134.  
  135.     // Assign the item
  136.     $pnRender->assign($item);
  137.  
  138.     // Return the output that has been generated by this function
  139.     return $pnRender->fetch('admin_messages_admin_modify.htm');
  140. }
  141.  
  142.  
  143. /**
  144.  * This is a standard function that is called with the results of the
  145.  * form supplied by Admin_Messages_admin_modify() to update a current item
  146.  * @author Mark West
  147.  * @see Admin_Messages_admin_modify()
  148.  * @param int $args['mid'] the id of the admin message to update
  149.  * @param int $args['objectid'] generic object id maps to mid if present
  150.  * @param string $args['title'] the title of the admin message
  151.  * @param string $args['content'] the text of the admin message
  152.  * @param string $args['language'] the language of the admin message
  153.  * @param int $args['active'] active status of the admin message
  154.  * @param int $args['expire'] the expiry date of the message
  155.  * @param int $args['view'] who can view the message
  156.  * @return bool true if successful, false otherwise
  157.  */
  158. {
  159.     $message FormUtil::getPassedValue('message'isset($args['message']$args['message'null'POST');
  160.     if (!empty($message['objectid'])) {
  161.         $message['mid'$message['objectid'];
  162.     }
  163.  
  164.     // Confirm authorisation code.
  165.     if (!SecurityUtil::confirmAuthKey()) {
  166.         return LogUtil::registerAuthidError ();
  167.     }
  168.  
  169.     // Notable by its absence there is no security check here.
  170.     // Update the admin message
  171.     if (pnModAPIFunc('Admin_Messages''admin''update',
  172.                     array('mid' => $message['mid'],
  173.                           'title' => $message['title'],
  174.                           'content' => $message['content'],
  175.                           'language' => isset($message['language']$message['language''',
  176.                           'active' => $message['active'],
  177.                           'expire' => $message['expire'],
  178.                           'oldtime' => $message['oldtime'],
  179.                           'changestartday' => $message['changestartday'],
  180.                           'view' => $message['view']))) {
  181.         // Success
  182.         LogUtil::registerStatus (pnML('_UPDATEITEMSUCCEDED'array('i' => _ADMINMESSAGES_MESSAGE)));
  183.     }
  184.  
  185.     // This function generated no output, and so now it is complete we redirect
  186.     // the user to an appropriate page for them to carry on their work
  187.     return pnRedirect(pnModURL('Admin_Messages''admin''view'));
  188. }
  189.  
  190. /**
  191.  * delete item
  192.  * This is a standard function that is called whenever an administrator
  193.  * wishes to delete a current module item.  Note that this function is
  194.  * the equivalent of both of the modify() and update() functions above as
  195.  * it both creates a form and processes its output.  This is fine for
  196.  * simpler functions, but for more complex operations such as creation and
  197.  * modification it is generally easier to separate them into separate
  198.  * functions.  There is no requirement in the Zikula MDG to do one or the
  199.  * other, so either or both can be used as seen appropriate by the module
  200.  * developer
  201.  * @author Mark West
  202.  * @param int $args['mid'] the id of the admin message to delete
  203.  * @param int $args['objectid'] generic object id maps to mid if present
  204.  * @param bool $args['confirmation'] confirmation of the deletion
  205.  * @return mixed HTML output string if no confirmation, true if succesful, false otherwise
  206.  */
  207. {
  208.     $mid FormUtil::getPassedValue('mid'isset($args['mid']$args['mid'null'REQUEST');
  209.     $objectid FormUtil::getPassedValue('objectid'isset($args['objectid']$args['objectid'null'REQUEST');
  210.     $confirmation FormUtil::getPassedValue('confirmation'null'POST');
  211.      if (!empty($objectid)) {
  212.          $mid $objectid;
  213.      }
  214.  
  215.     // Get the existing admin message
  216.     $item pnModAPIFunc('Admin_Messages''user''get'array('mid' => $mid));
  217.  
  218.     if ($item == false{
  219.         return LogUtil::registerError(pnML('_NOSUCHITEMFOUND'array('i' => _ADMINMESSAGES_MESSAGE))404);
  220.     }
  221.  
  222.     // Security check
  223.     if (!SecurityUtil::checkPermission('Admin_Messages::'"$item[title]::$mid"ACCESS_DELETE)) {
  224.         return LogUtil::registerPermissionError ();
  225.     }
  226.  
  227.     // Check for confirmation.
  228.     if (empty($confirmation)) {
  229.         // No confirmation yet
  230.         // Create output object
  231.         $pnRender pnRender::getInstance('Admin_Messages'false);
  232.  
  233.         // Add the message id
  234.         $pnRender->assign('mid'$mid);
  235.  
  236.         // Return the output that has been generated by this function
  237.         return $pnRender->fetch('admin_messages_admin_delete.htm');
  238.     }
  239.  
  240.     // If we get here it means that the user has confirmed the action
  241.  
  242.     // Confirm authorisation code.
  243.     if (!SecurityUtil::confirmAuthKey()) {
  244.         return LogUtil::registerAuthidError (pnModURL('Admin_Messages''admin''view'));
  245.     }
  246.  
  247.     // Delete the admin message
  248.     // The return value of the function is checked
  249.     if (pnModAPIFunc('Admin_Messages''admin''delete',
  250.                      array('mid' => $mid))) {
  251.         // Success
  252.         LogUtil::registerStatus (pnML('_DELETEITEMSUCCEDED'array('i' => _ADMINMESSAGES_MESSAGE)));
  253.     }
  254.  
  255.     // This function generated no output, and so now it is complete we redirect
  256.     // the user to an appropriate page for them to carry on their work
  257.     return pnRedirect(pnModURL('Admin_Messages''admin''view'));
  258. }
  259.  
  260. /**
  261.  * view items
  262.  * @author Mark West
  263.  * @param int $startnum the start item id for the pager
  264.  * @return string HTML output string
  265.  */
  266. {
  267.     // Security check
  268.     if (!SecurityUtil::checkPermission('Admin_Messages::''::'ACCESS_EDIT)) {
  269.         return LogUtil::registerPermissionError ();
  270.     }
  271.  
  272.     $startnum FormUtil::getPassedValue('startnum'isset($args['startnum']$args['startnum'null'GET');
  273.  
  274.     // Create output object
  275.     $pnRender pnRender::getInstance('Admin_Messages'false);
  276.  
  277.     // The user API function is called.  This takes the number of items
  278.     // required and the first number in the list of all items, which we
  279.     // obtained from the input and gets us the information on the appropriate
  280.     // items.
  281.     $items pnModAPIFunc('Admin_Messages''user''getall',
  282.                            array('startnum' => $startnum,
  283.                                  'numitems' => pnModGetVar('Admin_Messages''itemsperpage')));
  284.  
  285.     if (!$items)
  286.         $items array();
  287.  
  288.     $rows array();
  289.     foreach ($items as $item{
  290.  
  291.         if (SecurityUtil::checkPermission('Admin_Messages::'"$item[title]::$item[mid]"ACCESS_READ)) {
  292.  
  293.             $fullitem pnModAPIFunc('Admin_Messages''user''get',
  294.                                       array('mid' => $item['mid']));
  295.  
  296.             if ($fullitem['language'== ''{
  297.                 $fullitem['language'_ALL;
  298.             }
  299.  
  300.             $row[$fullitem['language'];
  301.  
  302.             if (!isset($fullitem['view'])) $fullitem['view'_ADMINMESSAGES_ALL;
  303.             switch ($fullitem['view']{
  304.                 case '1':
  305.                     $fullitem['view'_ADMINMESSAGES_ALL;
  306.                     break;
  307.                 case '2':
  308.                     $fullitem['view'_ADMINMESSAGES_USERS;
  309.                     break;
  310.                 case '3':
  311.                     $fullitem['view'_ADMINMESSAGES_ANON;
  312.                     break;
  313.                 case '4':
  314.                     $fullitem['view'_ADMINMESSAGES_ADMIN;
  315.                     break;
  316.             }
  317.             $row[$fullitem['view'];
  318.  
  319.             if ($fullitem['active'== 1{
  320.                 $active _YES;
  321.             else {
  322.                 $active _NO;
  323.             }
  324.  
  325.             if ($fullitem['expire'== 0{
  326.                 $expire _ADMINMESSAGES_UNLIMITED;
  327.             else if ($fullitem['expire']/86400 == 1{
  328.                 $expire $fullitem['expire']/86400 ' ' _DAY;
  329.             else {
  330.                 $expire $fullitem['expire']/86400 ' ' _DAYS;
  331.             }
  332.  
  333.             if ($fullitem['expire'== 0{
  334.                 $expiredate _ADMINMESSAGES_NOEXPIRE;
  335.             else {
  336.                 $expiredate ml_ftime(_DATETIMEBRIEF$fullitem['date'$fullitem['expire']);
  337.             }
  338.  
  339.             // Options for the item.  Note that each item has the appropriate
  340.             // levels of authentication checked to ensure that it is suitable
  341.             // for display
  342.             $options array();
  343.             if (SecurityUtil::checkPermission('Admin_Messages::'"$item[title]::$item[mid]"ACCESS_EDIT)) {
  344.                 $options[array('url' => pnModURL('Admin_Messages''admin''modify'array('mid' => $item['mid'])),
  345.                                    'image' => 'xedit.gif',
  346.                                    'title' => _EDIT);
  347.                 if (SecurityUtil::checkPermission('Admin_Messages::'"$item[title]::$item[mid]"ACCESS_DELETE)) {
  348.                     $options[array('url' => pnModURL('Admin_Messages''admin''delete'array('mid' => $item['mid'])),
  349.                                        'image' => '14_layer_deletelayer.gif',
  350.                                        'title' => _DELETE);
  351.                 }
  352.             }
  353.             $rows[array'mid' => $item['mid'],
  354.                              'title' => $item['title'],
  355.                              'language' => $fullitem['language'],
  356.                              'view' => $fullitem['view'],
  357.                              'active' => $active,
  358.                              'expire' => $expire,
  359.                              'expiredate' => $expiredate,
  360.                              'options' => $options);
  361.  
  362.         }
  363.     }
  364.     $pnRender->assign('items'$rows);
  365.  
  366.     // Assign the information required to create the pager
  367.     $pnRender->assign('pager'array('numitems' => pnModAPIFunc('Admin_Messages''user''countitems'),
  368.                                      'itemsperpage' => pnModGetVar('Admin_Messages''itemsperpage')));
  369.  
  370.     // Return the output that has been generated by this function
  371.     return $pnRender->fetch('admin_messages_admin_view.htm');
  372. }
  373.  
  374. /**
  375.  * This is a standard function to modify the configuration parameters of the
  376.  * module
  377.  * @author Mark West
  378.  * @return string HTML output string
  379.  */
  380. {
  381.     // Security check
  382.     if (!SecurityUtil::checkPermission('Admin_Messages::''::'ACCESS_ADMIN)) {
  383.         return LogUtil::registerPermissionError ();
  384.     }
  385.  
  386.     // Create output object
  387.     $pnRender pnRender::getInstance('Admin_Messages'false);
  388.  
  389.     // Number of items to display per page
  390.     $pnRender->assign(pnModGetVar('Admin_Messages'));
  391.  
  392.     // Return the output that has been generated by this function
  393.     return $pnRender->fetch('admin_messages_admin_modifyconfig.htm');
  394. }
  395.  
  396. /**
  397.  * This is a standard function to update the configuration parameters of the
  398.  * module given the information passed back by the modification form
  399.  * @author Mark West
  400.  * @see Admin_Messages_admin_modifyconfig()
  401.  * @param int $itemsperpage the number messages per page in the admin panel
  402.  * @return bool true if successful, false otherwise
  403.  */
  404. {
  405.     // Security check
  406.     if (!SecurityUtil::checkPermission('Admin_Messages::''::'ACCESS_ADMIN)) {
  407.         return LogUtil::registerPermissionError ();
  408.     }
  409.  
  410.     // Confirm authorisation code.
  411.     if (!SecurityUtil::confirmAuthKey()) {
  412.         return LogUtil::registerAuthidError (pnModURL('Admin_Messages''admin''view'));
  413.     }
  414.  
  415.     // Update module variables.
  416.     $itemsperpage = (int)FormUtil::getPassedValue('itemsperpage'25'POST');
  417.     if ($itemsperpage 1$itemsperpage 25;
  418.     pnModSetVar('Admin_Messages''itemsperpage'$itemsperpage);
  419.  
  420.     $allowsearchinactive = (bool)FormUtil::getPassedValue('allowsearchinactive'false'POST');
  421.     pnModSetVar('Admin_Messages''allowsearchinactive'$allowsearchinactive);
  422.  
  423.     // Let any other modules know that the modules configuration has been updated
  424.     pnModCallHooks('module','updateconfig','Admin_Messages'array('module' => 'Admin_Messages'));
  425.  
  426.     // the module configuration has been updated successfuly
  427.  
  428.     // This function generated no output, and so now it is complete we redirect
  429.     // the user to an appropriate page for them to carry on their work
  430.     return pnRedirect(pnModURL('Admin_Messages''admin''view'));
  431. }

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