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.  * @copyright (c) 2001, Zikula Development Team
  5.  * @link http://www.zikula.org
  6.  * @version $Id: pnadmin.php 24342 2008-06-06 12:03:14Z markwest $
  7.  * @license GNU/GPL - http://www.gnu.org/copyleft/gpl.html
  8.  * @package Zikula_System_Modules
  9.  * @subpackage Blocks
  10.  */
  11.  
  12. /**
  13.  * the main administration function
  14.  *
  15.  * view() function)
  16.  * @author Jim McDonald
  17.  * @return string HTML output string
  18.  */
  19. function blocks_admin_main()
  20. {
  21.     // Security check
  22.     if (!SecurityUtil::checkPermission('Blocks::''::'ACCESS_EDIT)) {
  23.         return LogUtil::registerPermissionError();
  24.     }
  25.  
  26.     return pnRedirect(pnModURL('Blocks''admin''view'));
  27. }
  28.  
  29. /**
  30.  * View all blocks
  31.  * @author Jim McDonald
  32.  * @return string HTML output string
  33.  */
  34. function blocks_admin_view()
  35. {
  36.     // Security check
  37.     if (!SecurityUtil::checkPermission('Blocks::''::'ACCESS_EDIT)) {
  38.         return LogUtil::registerPermissionError();
  39.     }
  40.  
  41.     // Create output object
  42.     $pnRender pnRender::getInstance('Blocks'false);
  43.  
  44.     // generate an authorisation key for the links
  45.     $authid SecurityUtil::generateAuthKey();
  46.  
  47.     // set some default variables
  48.     $rownum 1;
  49.     $lastpos '';
  50.  
  51.     // Get all blocks
  52.     $blocks pnModAPIFunc('Blocks''user''getall');
  53.  
  54.     // we can easily count the number of blocks using count() rather than
  55.     // calling the api function
  56.     $numrows count($blocks);
  57.  
  58.     // create an empty arrow to hold the processed items
  59.     $blockitems array();
  60.  
  61.     // get all possible block positions
  62.     $blockspositions pnModAPIFunc('Blocks''user''getallpositions');
  63.     // build assoc array for easier usage later on
  64.     foreach($blockspositions as $blocksposition{
  65.         $allbposarray[$blocksposition['pid']] $blocksposition['name'];
  66.     }
  67.     // loop round each item calculating the additional information
  68.     foreach ($blocks as $key => $block{
  69.  
  70.         // set the module that holds the block
  71.         if ($block['mid'== 0{
  72.             $block['modname''Legacy';
  73.         else {
  74.             $modinfo pnModGetInfo($block['mid']);
  75.             $block['modname'$modinfo['displayname'];
  76.         }
  77.  
  78.         // set the blocks language
  79.         if (empty($block['blanguage'])) {
  80.             $block['language'_ALL;
  81.         else {
  82.             $block['language'$block['blanguage'];
  83.         }
  84.         $thisblockspositions pnModAPIFunc('Blocks''user''getallblockspositions'array('bid' => $block['bid']));
  85.         $bposarray array();
  86.         foreach($thisblockspositions as $singleblockposition){
  87.             $bposarray[$allbposarray[$singleblockposition['pid']];
  88.         }
  89.         $block['positions'implode(', '$bposarray);
  90.         unset($bposarray);
  91.  
  92.         // calculate what options the user has over this block
  93.         $block['options'array();
  94.         if ($block['active']{
  95.             $block['options'][array('url' => pnModURL('Blocks''admin''deactivate',
  96.                                                  array('bid' => $block['bid']'authid' => $authid)),
  97.                                         'image' => 'folder_grey.gif',
  98.                                         'title' => _DEACTIVATE,
  99.                                         'noscript' => true);
  100.         else {
  101.             $block['options'][array ('url' => pnModURL('Blocks''admin''activate',
  102.                                                   array('bid' => $block['bid']'authid' => $authid)),
  103.                                          'image' => 'folder_green.gif',
  104.                                          'title' => _ACTIVATE,
  105.                                          'noscript' => true);
  106.         }
  107.  
  108.         $block['options'][array('url' => pnModURL('Blocks''admin''modify'array('bid' => $block['bid'])),
  109.                                     'image' => 'xedit.gif',
  110.                                     'title' => _EDIT,
  111.                                     'noscript' => false);
  112.         $block['options'][array('url' => pnModURL('Blocks''admin''delete'array('bid' => $block['bid'])),
  113.                                     'image' => '14_layer_deletelayer.gif',
  114.                                     'title' => _DELETE,
  115.                                     'noscript' => false);
  116.  
  117.         $blocksitems[$block;
  118.  
  119.     }
  120.     $pnRender->assign('blocks'$blocksitems);
  121.  
  122.     // get the block positions
  123.     $items pnModAPIFunc('Blocks''user''getallpositions');
  124.  
  125.     // Loop through each returned item adding in the options that the user has over the item
  126.     foreach ($items as $key => $item{
  127.         if (SecurityUtil::checkPermission('Blocks::'"$item[name]::"ACCESS_READ)) {
  128.             $options array();
  129.             if (SecurityUtil::checkPermission('Blocks::'"$item[name]::$"ACCESS_EDIT)) {
  130.                 $options[array('url'   => pnModURL('Blocks''admin''modifyposition'array('pid' => $item['pid'])),
  131.                                    'image' => 'xedit.gif',
  132.                                    'title' => _EDIT);
  133.                 if (SecurityUtil::checkPermission('Blocks::'"$item[name]::"ACCESS_DELETE)) {
  134.                     $options[array('url'   => pnModURL('Blocks''admin''deleteposition'array('pid' => $item['pid'])),
  135.                                        'image' => '14_layer_deletelayer.gif',
  136.                                        'title' => _DELETE);
  137.                 }
  138.             }
  139.                  // Add the calculated menu options to the item array
  140.             $items[$key]['options'$options;
  141.         }
  142.     }
  143.  
  144.     // Assign the items to the template
  145.     ksort($items);
  146.     $pnRender->assign('positions'$items);
  147.  
  148.     // Return the output that has been generated by this function
  149.     return $pnRender->fetch('blocks_admin_view.htm');
  150. }
  151.  
  152. /**
  153.  * show all blocks
  154.  * @author Jim McDonald
  155.  * @return string HTML output string
  156.  */
  157. {
  158.     SessionUtil::setVar('blocks_show_all'1);
  159.     return pnRedirect(pnModURL('Blocks''admin''view'));
  160. }
  161.  
  162. /**
  163.  * show active blocks
  164.  * @author Jim McDonald
  165.  * @return string HTML output string
  166.  */
  167. {
  168.     SessionUtil::delVar('blocks_show_all');
  169.     return pnRedirect(pnModURL('Blocks''admin''view'));
  170. }
  171.  
  172. /**
  173.  * deactivate a block
  174.  * @author Jim McDonald
  175.  * @param int $bid block id
  176.  * @return string HTML output string
  177.  */
  178. {
  179.     // Get parameters
  180.     $bid FormUtil::getPassedValue('bid');
  181.  
  182.     // Confirm authorisation code
  183.     if (!SecurityUtil::confirmAuthKey()) {
  184.         return LogUtil::registerAuthidError (pnModURL('Blocks','admin','view'));
  185.     }
  186.  
  187.     // Pass to API
  188.     if (pnModAPIFunc('Blocks''admin''deactivate'array('bid' => $bid))) {
  189.         // Success
  190.     }
  191.  
  192.     // Redirect
  193.     return pnRedirect(pnModURL('Blocks''admin''view'));
  194. }
  195.  
  196. /**
  197.  * activate a block
  198.  * @author Jim McDonald
  199.  * @param int $bid block id
  200.  * @return string HTML output string
  201.  */
  202. {
  203.     // Get parameters
  204.     $bid FormUtil::getPassedValue('bid');
  205.  
  206.     // Confirm authorisation code
  207.     if (!SecurityUtil::confirmAuthKey()) {
  208.         return LogUtil::registerAuthidError (pnModURL('Blocks','admin','view'));
  209.     }
  210.  
  211.     // Pass to API
  212.     if (pnModAPIFunc('Blocks''admin''activate'array('bid' => $bid))) {
  213.         // Success
  214.     }
  215.  
  216.     // Redirect
  217.     return pnRedirect(pnModURL('Blocks''admin''view'));
  218. }
  219.  
  220. /**
  221.  * modify a block
  222.  * @author Jim McDonald
  223.  * @param int $bid block ind
  224.  * @return string HTML output string
  225.  */
  226. {
  227.     // Get parameters
  228.     $bid FormUtil::getPassedValue('bid');
  229.  
  230.     // Get details on current block
  231.     $blockinfo pnBlockGetInfo($bid);
  232.  
  233.     // Security check
  234.     if (!SecurityUtil::checkPermission('Blocks::'"$blockinfo[bkey]:$blockinfo[title]:$blockinfo[bid]"ACCESS_EDIT)) {
  235.         return LogUtil::registerPermissionError();
  236.     }
  237.  
  238.     // check the blockinfo array
  239.     if (empty($blockinfo)) {
  240.         return LogUtil::registerError(pnML('_NOSUCHITEMFOUND'array('i' => _BLOCKS_BLOCK))404);
  241.     }
  242.  
  243.     // get the block placements
  244.     $where "WHERE pn_bid = '" DataUtil::formatForStore($bid"'";
  245.     $placements DBUtil::selectObjectArray('block_placements'$where'pn_order'-1-1''null);
  246.     $blockinfo['placements']  array();
  247.     foreach ($placements as $placement{
  248.         $blockinfo['placements'][$placement['pid'];
  249.     }
  250.  
  251.     // Load block
  252.     $modinfo pnModGetInfo($blockinfo['mid']);
  253.     if (!pnBlockLoad($modinfo['name']$blockinfo['bkey'])) {
  254.         return LogUtil::registerError(pnML('_NOSUCHITEMFOUND'array('i' => _BLOCKS_BLOCK))404);
  255.     }
  256.  
  257.     // Create output object
  258.     $pnRender pnRender::getInstance('Blocks'false);
  259.     $pnRender->add_core_data();
  260.  
  261.     // Title - putting a title ad the head of each page reminds the user what
  262.     // they are doing
  263.     if (!empty($modinfo['name'])) {
  264.         $pnRender->assign('modtitle'"$modinfo[name]/$blockinfo[bkey]");
  265.     else {
  266.         $pnRender->assign('modtitle'"Core/$blockinfo[bkey]");
  267.         $modinfo['name''Legacy';
  268.     }
  269.  
  270.     // Add hidden block id to form
  271.     $pnRender->assign('bid'$bid);
  272.  
  273.     // check for a valid set of filtering rules
  274.     if (!isset($blockinfo['filter']|| empty($blockinfo['filter'])) {
  275.         $blockinfo['filter']['modules'array();
  276.         $blockinfo['filter']['type''';
  277.         $blockinfo['filter']['functions''';
  278.         $blockinfo['filter']['customargs''';
  279.     }
  280.  
  281.     // invert the filter array so that the output is in a useful form for the template
  282.     if (isset($blockinfo['filter']['modules']&& is_array($blockinfo['filter']['modules'])) {
  283.         $blockinfo['filter']['modules'array_flip($blockinfo['filter']['modules']);
  284.     }
  285.  
  286.     // assign the block
  287.     $pnRender->assign($blockinfo);
  288.  
  289.     // assign the list of modules
  290.     $pnRender->assign('mods'pnModGetAllMods());
  291.  
  292.     // assign block positions
  293.     $positions pnModAPIFunc('Blocks''user''getallpositions');
  294.     $block_positions array();
  295.     foreach ($positions as $position{
  296.         $block_positions[$position['pid']] $position['name'];
  297.     }
  298.     $pnRender->assign('block_positions'$block_positions);
  299.  
  300.     // Block-specific
  301.  
  302.     // New way
  303.     $usname preg_replace('/ /''_'$modinfo['name']);
  304.     $modfunc $usname '_' $blockinfo['bkey''block_modify';
  305.     $blockoutput '';
  306.     if (function_exists($modfunc)) {
  307.         $blockoutput $modfunc($blockinfo);
  308.     else {
  309.         // Old way
  310.         $blocks_modules $GLOBALS['blocks_modules'][$blockinfo['mid']];
  311.         if (!empty($blocks_modules[$blockinfo['bkey']]&& !empty($blocks_modules[$blockinfo['bkey']]['func_edit'])) {
  312.             if (function_exists($blocks_modules[$blockinfo['bkey']]['func_edit'])) {
  313.                 $blockoutput $blocks_modules[$blockinfo['bkey']]['func_edit'](array_merge($_GET$_POST$blockinfo));
  314.             }
  315.         }
  316.     }
  317.     if (!isset($GLOBALS['blocks_modules'][$blockinfo['mid']][$blockinfo['bkey']]['admin_tableless'])) {
  318.         $GLOBALS['blocks_modules'][$blockinfo['mid']][$blockinfo['bkey']]['admin_tableless'false;
  319.     }
  320.     $pnRender->assign($GLOBALS['blocks_modules'][$blockinfo['mid']][$blockinfo['bkey']]);
  321.     $pnRender->assign('blockoutput'$blockoutput);
  322.  
  323.     // Refresh
  324.     $refreshtimes array1800 => DataUtil::formatForDisplay(_BLOCKS_HALFHOUR),
  325.                            3600 => DataUtil::formatForDisplay(_BLOCKS_HOUR),
  326.                            7200 => DataUtil::formatForDisplay(_BLOCKS_TWOHOURS),
  327.                           14400 => DataUtil::formatForDisplay(_BLOCKS_FOURHOURS),
  328.                           43200 => DataUtil::formatForDisplay(_BLOCKS_TWELVEHOURS),
  329.                           86400 => DataUtil::formatForDisplay(_BLOCKS_ONEDAY),
  330.                          172800 => DataUtil::formatForDisplay(_BLOCKS_TWODAY),
  331.                          259200 => DataUtil::formatForDisplay(_BLOCKS_THREEDAY),
  332.                          345600 => DataUtil::formatForDisplay(_BLOCKS_FOURDAY),
  333.                          432000 => DataUtil::formatForDisplay(_BLOCKS_FIVEDAY),
  334.                          518400 => DataUtil::formatForDisplay(_BLOCKS_SIXDAY),
  335.                          604800 => DataUtil::formatForDisplay(_BLOCKS_SEVENDAY));
  336.     $pnRender->assign('blockrefreshtimes' $refreshtimes);
  337.  
  338.     // Return the output that has been generated by this function
  339.     return $pnRender->fetch('blocks_admin_modify.htm');
  340. }
  341.  
  342. /**
  343.  * update a block
  344.  * @author Jim McDonald
  345.  * @see blocks_admin_modify()
  346.  * @param int $bid block id to update
  347.  * @param string $title the new title of the block
  348.  * @param array $positions the new position(s) of the block
  349.  * @param array $modules the modules to display the block on
  350.  * @param string $url the new URL of the block
  351.  * @param string $language the new language of the block
  352.  * @param string $content the new content of the block
  353.  * @return bool true if succesful, false otherwise
  354.  */
  355. {
  356.     // Get parameters
  357.     $bid           FormUtil::getPassedValue('bid');
  358.     $title         FormUtil::getPassedValue('title');
  359.     $language      FormUtil::getPassedValue('language');
  360.     $collapsable   FormUtil::getPassedValue('collapsable'0);
  361.     $defaultstate  FormUtil::getPassedValue('defaultstate'1);
  362.     $content       FormUtil::getPassedValue('content');
  363.     $refresh       FormUtil::getPassedValue('refresh');
  364.     $positions     FormUtil::getPassedValue('positions');
  365.     $filter        FormUtil::getPassedValue('filter'array());
  366.     $returntoblock FormUtil::getPassedValue('returntoblock');
  367.     // not stored in a block
  368.     $redirect      FormUtil::getPassedValue('redirect'null);
  369.     $cancel        FormUtil::getPassedValue('cancel'null);
  370.     if (isset($cancel)) {
  371.         if (isset($redirect&& !empty($redirect)) {
  372.             return pnRedirect(urldecode($redirect));
  373.         }
  374.         return pnRedirect(pnModURL('Blocks''admin''view'));
  375.     }
  376.     
  377.  
  378.     // Fix for null language
  379.     if (!isset($language)) {
  380.         $language '';
  381.     }
  382.  
  383.     // Confirm authorisation code
  384.     if (!SecurityUtil::confirmAuthKey()) {
  385.         return LogUtil::registerAuthidError (pnModURL('Blocks','admin','view'));
  386.     }
  387.  
  388.     // Get and update block info
  389.     $blockinfo pnBlockGetInfo($bid);
  390.     $blockinfo['title'$title;
  391.     $blockinfo['bid'$bid;
  392.     $blockinfo['language'$language;
  393.     $blockinfo['collapsable'$collapsable;
  394.     $blockinfo['defaultstate'$defaultstate;
  395.     $blockinfo['content'$content;
  396.     $blockinfo['refresh'$refresh;
  397.     $blockinfo['positions'$positions;
  398.     $blockinfo['filter'$filter;
  399.  
  400.     // Load block
  401.     $modinfo pnModGetInfo($blockinfo['mid']);
  402.     if (!pnBlockLoad($modinfo['name']$blockinfo['bkey'])) {
  403.         return LogUtil::registerError(pnML('_NOSUCHITEMFOUND'array('i' => _BLOCKS_BLOCK))404);
  404.     }
  405.  
  406.     // Do block-specific update
  407.     if (empty($modinfo['name'])) {
  408.         $modinfo['name''Legacy';
  409.     }
  410.     $usname preg_replace('/ /''_'$modinfo['name']);
  411.     $updatefunc $usname '_' $blockinfo['bkey''block_update';
  412.     if (function_exists($updatefunc)) {
  413.         $blockinfo $updatefunc($blockinfo);
  414.         if (!$blockinfo{
  415.             return pnRedirect(pnModURL('Blocks''admin''modify'array('bid' => $bid)));
  416.         }
  417.     else {
  418.         // Old way
  419.         $blocks_modules $GLOBALS['blocks_modules'][$blockinfo['mid']];
  420.         if (!empty($blocks_modules[$blockinfo['bkey']]&& !empty($blocks_modules[$blockinfo['bkey']]['func_update'])) {
  421.             if (function_exists($blocks_modules[$blockinfo['bkey']]['func_update'])) {
  422.                 $blockinfo $blocks_modules[$blockinfo['bkey']]['func_update'](array_merge($_POST$blockinfo));
  423.             }
  424.         }
  425.     }
  426.  
  427.     // Pass to API
  428.     if (pnModAPIFunc('Blocks''admin''update'$blockinfo)) {
  429.         // Success
  430.         LogUtil::registerStatus (pnML('_UPDATEITEMSUCCEDED'array('i' => _BLOCKS_BLOCK)));
  431.     }
  432.  
  433.     if (isset($redirect&& !empty($redirect)) {
  434.         return pnRedirect(urldecode($redirect));
  435.     }
  436.  
  437.     if (!empty($returntoblock)) {
  438.         // load the block config again
  439.         return pnRedirect(pnModURL('Blocks''admin''modify',
  440.                                    array('bid' => $returntoblock)));
  441.     }
  442.     return pnRedirect(pnModURL('Blocks''admin''view'));
  443. }
  444.  
  445. /**
  446.  * display form for a new block
  447.  * @author Jim McDonald
  448.  * @return string HTML output string
  449.  */
  450. function blocks_admin_new()
  451. {
  452.     // Security check
  453.     if (!SecurityUtil::checkPermission('Blocks::''::'ACCESS_ADD)) {
  454.         return LogUtil::registerPermissionError();
  455.     }
  456.  
  457.     // Create output object
  458.     $pnRender pnRender::getInstance('Blocks'false);
  459.     $pnRender->add_core_data();
  460.  
  461.     // Block
  462.     // Load all blocks (trickier than it sounds)
  463.     $blocks pnBlockLoadAll();
  464.     if (!$blocks{
  465.         return LogUtil::registerError(pnML('_GETITEMSFAILED'array('i' => _BLOCKS_BLOCKS)));
  466.     }
  467.  
  468.     $blockinfo array();
  469.     foreach ($blocks as $moduleblocks{
  470.         foreach ($moduleblocks as $block{
  471.             $modinfo pnModGetInfo(pnModGetIDFromName($block['module']));
  472.             if (!$modinfo{
  473.                 $modinfo array('displayname' => _LEGACY);
  474.             }
  475.             $blockinfo[$block['mid'':' $block['bkey']] =   $modinfo['displayname''/' $block['text_type_long'];
  476.         }
  477.     }
  478.     $pnRender->assign('blockids'$blockinfo);
  479.  
  480.     // assign block positions
  481.     $positions pnModAPIFunc('Blocks''user''getallpositions');
  482.     $block_positions array();
  483.     foreach ($positions as $position{
  484.         $block_positions[$position['pid']] $position['name'];
  485.     }
  486.     $pnRender->assign('block_positions'$block_positions);
  487.  
  488.     // Return the output that has been generated by this function
  489.     return $pnRender->fetch('blocks_admin_new.htm');
  490. }
  491.  
  492. /**
  493.  * create a new block
  494.  * @author Jim McDonald
  495.  * @see blocks_admin_new()
  496.  * @param string $title the new title of the block
  497.  * @param int $blockid block id to create
  498.  * @param string $language the language to assign to the block
  499.  * @param string $position the position of the block
  500.  * @return bool true if successful, false otherwise
  501.  */
  502. {
  503.     // Get parameters
  504.     $title        FormUtil::getPassedValue('title');
  505.     $blockid      FormUtil::getPassedValue('blockid');
  506.     $language     FormUtil::getPassedValue('language');
  507.     $collapsable   FormUtil::getPassedValue('collapsable'0);
  508.     $defaultstate  FormUtil::getPassedValue('defaultstate'1);
  509.     $positions     FormUtil::getPassedValue('positions');
  510.  
  511.     list($mid$bkeysplit(':'$blockid);
  512.  
  513.     // Fix for null language
  514.     if (!isset($language)) {
  515.         $language '';
  516.     }
  517.  
  518.     // Confirm authorisation code
  519.     if (!SecurityUtil::confirmAuthKey()) {
  520.         return LogUtil::registerAuthidError (pnModURL('Blocks','admin','view'));
  521.     }
  522.  
  523.     $blockinfo array('bkey'         => $bkey,
  524.                        'title'        => $title,
  525.                        'positions'    => $positions,
  526.                        'mid'          => $mid,
  527.                        'language'     => $language,
  528.                        'collapsable'  => $collapsable,
  529.                        'defaultstate' => $defaultstate);
  530.  
  531.     // Pass to API
  532.     $bid pnModAPIFunc('Blocks''admin''create'$blockinfo);
  533.     if ($bid != false{
  534.         LogUtil::registerStatus (pnML('_CREATEITEMSUCCEDED'array('i' => _BLOCKS_BLOCK)));
  535.         return pnRedirect(pnModURL('Blocks''admin''modify'array('bid' => $bid)));
  536.     }
  537.  
  538.     return pnRedirect(pnModURL('Blocks''admin''view'));
  539. }
  540.  
  541. /**
  542.  * delete a block
  543.  * @author Jim McDonald
  544.  * @param int bid the block id
  545.  * @param bool confirm to delete block
  546.  * @return string HTML output string
  547.  */
  548. {
  549.     // Get parameters
  550.     $bid          FormUtil::getPassedValue('bid');
  551.     $confirmation FormUtil::getPassedValue('confirmation');
  552.  
  553.     // Get details on current block
  554.     $blockinfo pnBlockGetInfo($bid);
  555.  
  556.     // Security check
  557.     if (!SecurityUtil::checkPermission('Blocks::'"$blockinfo[bkey]:$blockinfo[title]:$blockinfo[bid]"ACCESS_DELETE)) {
  558.         return LogUtil::registerPermissionError();
  559.     }
  560.  
  561.     if ($blockinfo == false{
  562.         return LogUtil::registerError(pnML('_NOSUCHITEMFOUND'array('i' => _BLOCKS_BLOCK))404);
  563.     }
  564.  
  565.     // Check for confirmation
  566.     if (empty($confirmation)) {
  567.         // No confirmation yet - get one
  568.         // Create output object
  569.         $pnRender pnRender::getInstance('Blocks'false);
  570.  
  571.         // get the module info
  572.         $modinfo pnModGetInfo($blockinfo['mid']);
  573.  
  574.         if (!empty($modinfo['name'])) {
  575.             $pnRender->assign('blockname'"$modinfo[name]/$blockinfo[bkey]");
  576.         else {
  577.             $pnRender->assign('blockname'"Core/$blockinfo[bkey]");
  578.         }
  579.  
  580.         // add the block id
  581.         $pnRender->assign('bid'$bid);
  582.  
  583.         // Return the output that has been generated by this function
  584.         return $pnRender->fetch('blocks_admin_delete.htm');
  585.     }
  586.  
  587.     // Confirm authorisation code
  588.     if (!SecurityUtil::confirmAuthKey()) {
  589.         return LogUtil::registerAuthidError (pnModURL('Blocks','admin','view'));
  590.     }
  591.  
  592.     // Pass to API
  593.     if (pnModAPIFunc('Blocks''admin''delete',
  594.                      array('bid' => $bid))) {
  595.         // Success
  596.         LogUtil::registerStatus (pnML('_DELETEITEMSUCCEDED'array('i' => _BLOCKS_BLOCK)));
  597.     }
  598.  
  599.     return pnRedirect(pnModURL('Blocks''admin''view'));
  600. }
  601.  
  602. /**
  603.  * display a form to create a new block position
  604.  *
  605.  * @author Mark West
  606.  */
  607. {
  608.     // Security check
  609.     if (!SecurityUtil::checkPermission('Blocks::''::'ACCESS_ADMIN)) {
  610.         return LogUtil::registerError(_MODULENOAUTH403);
  611.     }
  612.  
  613.     // Create output object
  614.     $pnRender pnRender::getInstance('Blocks'false);
  615.  
  616.     // Return the output that has been generated by this function
  617.     return $pnRender->fetch('blocks_admin_newposition.htm');
  618. }
  619.  
  620. /**
  621.  * display a form to create a new block position
  622.  *
  623.  * @author Mark West
  624.  */
  625. {
  626.     // Security check
  627.     if (!SecurityUtil::checkPermission('Blocks::position''::'ACCESS_ADMIN)) {
  628.         return LogUtil::registerError(_MODULENOAUTH403);
  629.     }
  630.  
  631.     // Get parameters
  632.     $position FormUtil::getPassedValue('position');
  633.  
  634.     // check our vars
  635.     if (!isset($position['name']|| !preg_match('/^[a-z0-9_-]*$/i'$position['name']|| !isset($position['description'])) {
  636.         return pnRedirect(pnModURL('Blocks''admin''view'));
  637.     }
  638.  
  639.     // Confirm authorisation code
  640.     if (!SecurityUtil::confirmAuthKey()) {
  641.         return LogUtil::registerAuthidError (pnModURL('Blocks','admin','view'));
  642.     }
  643.  
  644.     // add the new block position
  645.     if (pnModAPIFunc('Blocks''admin''createposition'array('name' => $position['name']'description' => $position['description']))) {
  646.         LogUtil::registerStatus (pnML('_CREATEITEMSUCCEDED'array('i' => _BLOCKS_BLOCKPOSITION)));
  647.     }
  648.  
  649.     // all done
  650.     return pnRedirect(pnModURL('Blocks''admin''view'));
  651. }
  652.  
  653. /**
  654.  * display a form to create a new block position
  655.  *
  656.  * @author Mark West
  657.  */
  658. {
  659.     // get our input
  660.     $pid FormUtil::getPassedValue('pid');
  661.  
  662.     // get the block position
  663.     $position pnModAPIFunc('Blocks''user''getposition'array('pid' => $pid));
  664.  
  665.     // Security check
  666.     if (!SecurityUtil::checkPermission("Blocks::$position[name]"'::'ACCESS_ADMIN)) {
  667.         return LogUtil::registerError(_MODULENOAUTH403);
  668.     }
  669.  
  670.     // Create output object
  671.     $pnRender pnRender::getInstance('Blocks'false);
  672.  
  673.     // assign the item
  674.     $pnRender->assign($position);
  675.  
  676.     // get all blocks in the position
  677.     $block_placements pnModAPIFunc('blocks''user''getblocksinposition'array('pid' => $pid));
  678.  
  679.     // get all defined blocks
  680.     $allblocks pnModAPIFunc('Blocks''user''getall'array('inactive' => true));
  681.     foreach($allblocks as $key => $allblock{
  682.         // set the module that holds the block
  683.         if ($allblock['mid'== 0{
  684.             $allblocks[$key]['modname''Legacy';
  685.         else {
  686.             $modinfo pnModGetInfo($allblock['mid']);
  687.             $allblocks[$key]['modname'$modinfo['name'];
  688.         }
  689.     }
  690.  
  691.     
  692.     // loop over arrays forming a list of blocks not in the block positon and obtaining
  693.     // full details on those that are
  694.     $blocks array();
  695.     foreach ($block_placements as $blockplacement{
  696.         $block pnBlockGetInfo($blockplacement['bid']);
  697.         $block['order'$blockplacement['order'];
  698.         foreach($allblocks as $key => $allblock{
  699.             if ($allblock['bid'== $blockplacement['bid']{
  700.                 unset($allblocks[$key]);
  701.                 $block['modname'$allblock['modname'];
  702.             }
  703.         }
  704.         $blocks[$block;
  705.     }
  706.  
  707.     $pnRender->assign('assignedblocks'$blocks);
  708.     $pnRender->assign('unassignedblocks'$allblocks);
  709.  
  710.     // Return the output that has been generated by this function
  711.     return $pnRender->fetch('blocks_admin_modifyposition.htm');
  712. }
  713.  
  714. /**
  715.  * display a form to create a new block position
  716.  *
  717.  * @author Mark West
  718.  */
  719. {
  720.     // Get parameters
  721.     $position FormUtil::getPassedValue('position');
  722.  
  723.     // check our vars
  724.     if (!isset($position['pid']|| !isset($position['name']|| !isset($position['description'])) {
  725.         return pnRedirect(pnModURL('Blocks''admin''view'));
  726.     }
  727.  
  728.     // Confirm authorisation code
  729.     if (!SecurityUtil::confirmAuthKey()) {
  730.         return LogUtil::registerAuthidError (pnModURL('Blocks','admin','view'));
  731.     }
  732.  
  733.     // update the position
  734.     if (pnModAPIFunc('Blocks''admin''updateposition',
  735.                      array('pid' => $position['pid']'name' => $position['name']'description' => $position['description']))) {
  736.         // all done
  737.         LogUtil::registerStatus (pnML('_UPDATEITEMSUCCEDED'array('i' => _BLOCKS_BLOCKPOSITION)));
  738.     }
  739.  
  740.     return pnRedirect(pnModURL('Blocks''admin''view'));
  741. }
  742.  
  743. /**
  744.  * delete a block position
  745.  *
  746.  * @author Mark West
  747.  * @param int $args['pid'] the id of the position to be deleted
  748.  * @param int $args['objectid'] generic object id maps to pid if present
  749.  * @param bool $args['confirmation'] confirmation that this item can be deleted
  750.  * @return mixed HTML string if confirmation is null, true if delete successful, false otherwise
  751.  */
  752. {
  753.     $pid FormUtil::getPassedValue('pid'isset($args['pid']$args['pid'null'REQUEST');
  754.     $objectid FormUtil::getPassedValue('objectid'isset($args['objectid']$args['objectid'null'REQUEST');
  755.     $confirmation FormUtil::getPassedValue('confirmation'null'POST');
  756.     if (!empty($objectid)) {
  757.         $pid $objectid;
  758.     }
  759.  
  760.     $item pnModAPIFunc('Blocks''user''getposition'array('pid' => $pid));
  761.  
  762.     if ($item == false{
  763.         return LogUtil::registerError(pnML('_NOSUCHITEMFOUND'array('i' => _BLOCKS_BLOCKPOSITION))404);
  764.     }
  765.  
  766.     if (!SecurityUtil::checkPermission('Blocks::position'"$item[name]::$pid"ACCESS_DELETE)) {
  767.         return LogUtil::registerPermissionError();
  768.     }
  769.  
  770.     // Check for confirmation.
  771.     if (empty($confirmation)) {
  772.         // No confirmation yet
  773.         $pnRender pnRender::getInstance('Blocks'false);
  774.         $pnRender->assign('pid'$pid);
  775.         return $pnRender->fetch('blocks_admin_deleteposition.htm');
  776.     }
  777.  
  778.     if (!SecurityUtil::confirmAuthKey()) {
  779.         return LogUtil::registerAuthidError (pnModURL('Blocks','admin','view'));
  780.     }
  781.  
  782.     if (pnModAPIFunc('Blocks''admin''deleteposition'array('pid' => $pid))) {
  783.         // Success
  784.         LogUtil::registerStatus (pnML('_DELETEITEMSUCCEDED'array('i' => _BLOCKS_BLOCKPOSITION)));
  785.     }
  786.  
  787.     return pnRedirect(pnModURL('Blocks''admin''view'));
  788. }
  789.  
  790. /**
  791.  * Any config options would likely go here in the future
  792.  * @author Jim McDonald
  793.  * @return string HTML output string
  794.  */
  795. {
  796.     // Security check
  797.     if (!SecurityUtil::checkPermission('Blocks::''::'ACCESS_ADMIN)) {
  798.         return LogUtil::registerPermissionError();
  799.     }
  800.  
  801.     // Create output object
  802.     $pnRender pnRender::getInstance('Blocks'false);
  803.  
  804.     // assign all the module vars
  805.     $pnRender->assign(pnModGetVar('Blocks'));
  806.  
  807.     // Return the output that has been generated by this function
  808.     return $pnRender->fetch('blocks_admin_modifyconfig.htm');
  809. }
  810.  
  811. /**
  812.  * Set config variable(s)
  813.  * @author Jim McDonald
  814.  * @return string bool true if successful, false otherwise
  815.  */
  816. {
  817.     // Security check
  818.     if (!SecurityUtil::checkPermission('Blocks::''::'ACCESS_ADMIN)) {
  819.         return LogUtil::registerPermissionError();
  820.     }
  821.  
  822.     $collapseable FormUtil::getPassedValue('collapseable');
  823.  
  824.     if (!SecurityUtil::confirmAuthKey()) {
  825.         return LogUtil::registerAuthidError (pnModURL('Blocks','admin','main'));
  826.     }
  827.  
  828.     if (!isset($collapseable|| !is_numeric($collapseable)) {
  829.         $collapseable 0;
  830.     }
  831.  
  832.     pnModSetVar('Blocks''collapseable'$collapseable);
  833.  
  834.     // Let any other modules know that the modules configuration has been updated
  835.     pnModCallHooks('module','updateconfig','Blocks'array('module' => 'Blocks'));
  836.  
  837.     // the module configuration has been updated successfuly
  838.  
  839.     return pnRedirect(pnModURL('Blocks''admin''main'));
  840. }

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