Source for file pnadmin.php
Documentation is available at pnadmin.php
* Zikula Application Framework
* @copyright (c) 2001, Zikula Development Team
* @link http://www.zikula.org
* @version $Id: pnadmin.php 24342 2008-06-06 12:03:14Z markwest $
* @license GNU/GPL - http://www.gnu.org/copyleft/gpl.html
* @package Zikula_System_Modules
* the main administration function
* @return string HTML output string
* @return string HTML output string
// generate an authorisation key for the links
// set some default variables
// we can easily count the number of blocks using count() rather than
// calling the api function
$numrows = count($blocks);
// create an empty arrow to hold the processed items
// get all possible block positions
$blockspositions = pnModAPIFunc('Blocks', 'user', 'getallpositions');
// build assoc array for easier usage later on
foreach($blockspositions as $blocksposition) {
$allbposarray[$blocksposition['pid']] = $blocksposition['name'];
// loop round each item calculating the additional information
foreach ($blocks as $key => $block) {
// set the module that holds the block
if ($block['mid'] == 0) {
$block['modname'] = 'Legacy';
$block['modname'] = $modinfo['displayname'];
// set the blocks language
if (empty($block['blanguage'])) {
$block['language'] = _ALL;
$block['language'] = $block['blanguage'];
$thisblockspositions = pnModAPIFunc('Blocks', 'user', 'getallblockspositions', array('bid' => $block['bid']));
foreach($thisblockspositions as $singleblockposition){
$bposarray[] = $allbposarray[$singleblockposition['pid']];
$block['positions'] = implode(', ', $bposarray);
// calculate what options the user has over this block
$block['options'] = array();
$block['options'][] = array('url' => pnModURL('Blocks', 'admin', 'deactivate',
array('bid' => $block['bid'], 'authid' => $authid)),
'image' => 'folder_grey.gif',
$block['options'][] = array ('url' => pnModURL('Blocks', 'admin', 'activate',
array('bid' => $block['bid'], 'authid' => $authid)),
'image' => 'folder_green.gif',
$block['options'][] = array('url' => pnModURL('Blocks', 'admin', 'modify', array('bid' => $block['bid'])),
$block['options'][] = array('url' => pnModURL('Blocks', 'admin', 'delete', array('bid' => $block['bid'])),
'image' => '14_layer_deletelayer.gif',
$pnRender->assign('blocks', $blocksitems);
// get the block positions
// Loop through each returned item adding in the options that the user has over the item
foreach ($items as $key => $item) {
$options[] = array('url' => pnModURL('Blocks', 'admin', 'modifyposition', array('pid' => $item['pid'])),
$options[] = array('url' => pnModURL('Blocks', 'admin', 'deleteposition', array('pid' => $item['pid'])),
'image' => '14_layer_deletelayer.gif',
// Add the calculated menu options to the item array
$items[$key]['options'] = $options;
// Assign the items to the template
$pnRender->assign('positions', $items);
// Return the output that has been generated by this function
return $pnRender->fetch('blocks_admin_view.htm');
* @return string HTML output string
* @return string HTML output string
* @param int $bid block id
* @return string HTML output string
// Confirm authorisation code
if (pnModAPIFunc('Blocks', 'admin', 'deactivate', array('bid' => $bid))) {
* @param int $bid block id
* @return string HTML output string
// Confirm authorisation code
if (pnModAPIFunc('Blocks', 'admin', 'activate', array('bid' => $bid))) {
* @param int $bid block ind
* @return string HTML output string
// Get details on current block
// check the blockinfo array
// get the block placements
$blockinfo['placements'] = array();
foreach ($placements as $placement) {
$blockinfo['placements'][] = $placement['pid'];
if (!pnBlockLoad($modinfo['name'], $blockinfo['bkey'])) {
$pnRender->add_core_data();
// Title - putting a title ad the head of each page reminds the user what
if (!empty($modinfo['name'])) {
$pnRender->assign('modtitle', "$modinfo[name]/$blockinfo[bkey]");
$pnRender->assign('modtitle', "Core/$blockinfo[bkey]");
$modinfo['name'] = 'Legacy';
// Add hidden block id to form
$pnRender->assign('bid', $bid);
// check for a valid set of filtering rules
if (!isset ($blockinfo['filter']) || empty($blockinfo['filter'])) {
$blockinfo['filter']['modules'] = array();
$blockinfo['filter']['type'] = '';
$blockinfo['filter']['functions'] = '';
$blockinfo['filter']['customargs'] = '';
// invert the filter array so that the output is in a useful form for the template
if (isset ($blockinfo['filter']['modules']) && is_array($blockinfo['filter']['modules'])) {
$blockinfo['filter']['modules'] = array_flip($blockinfo['filter']['modules']);
$pnRender->assign($blockinfo);
// assign the list of modules
// assign block positions
$positions = pnModAPIFunc('Blocks', 'user', 'getallpositions');
$block_positions = array();
foreach ($positions as $position) {
$block_positions[$position['pid']] = $position['name'];
$pnRender->assign('block_positions', $block_positions);
$modfunc = $usname . '_' . $blockinfo['bkey'] . 'block_modify';
$blockoutput = $modfunc($blockinfo);
$blocks_modules = $GLOBALS['blocks_modules'][$blockinfo['mid']];
if (!empty($blocks_modules[$blockinfo['bkey']]) && !empty($blocks_modules[$blockinfo['bkey']]['func_edit'])) {
$blockoutput = $blocks_modules[$blockinfo['bkey']]['func_edit'](array_merge($_GET, $_POST, $blockinfo));
if (!isset ($GLOBALS['blocks_modules'][$blockinfo['mid']][$blockinfo['bkey']]['admin_tableless'])) {
$GLOBALS['blocks_modules'][$blockinfo['mid']][$blockinfo['bkey']]['admin_tableless'] = false;
$pnRender->assign($GLOBALS['blocks_modules'][$blockinfo['mid']][$blockinfo['bkey']]);
$pnRender->assign('blockoutput', $blockoutput);
$pnRender->assign('blockrefreshtimes' , $refreshtimes);
// Return the output that has been generated by this function
return $pnRender->fetch('blocks_admin_modify.htm');
* @see blocks_admin_modify()
* @param int $bid block id to update
* @param string $title the new title of the block
* @param array $positions the new position(s) of the block
* @param array $modules the modules to display the block on
* @param string $url the new URL of the block
* @param string $language the new language of the block
* @param string $content the new content of the block
* @return bool true if succesful, false otherwise
if (isset ($redirect) && !empty($redirect)) {
// Confirm authorisation code
// Get and update block info
$blockinfo['title'] = $title;
$blockinfo['bid'] = $bid;
$blockinfo['language'] = $language;
$blockinfo['collapsable'] = $collapsable;
$blockinfo['defaultstate'] = $defaultstate;
$blockinfo['content'] = $content;
$blockinfo['refresh'] = $refresh;
$blockinfo['positions'] = $positions;
$blockinfo['filter'] = $filter;
if (!pnBlockLoad($modinfo['name'], $blockinfo['bkey'])) {
// Do block-specific update
if (empty($modinfo['name'])) {
$modinfo['name'] = 'Legacy';
$updatefunc = $usname . '_' . $blockinfo['bkey'] . 'block_update';
$blockinfo = $updatefunc($blockinfo);
$blocks_modules = $GLOBALS['blocks_modules'][$blockinfo['mid']];
if (!empty($blocks_modules[$blockinfo['bkey']]) && !empty($blocks_modules[$blockinfo['bkey']]['func_update'])) {
$blockinfo = $blocks_modules[$blockinfo['bkey']]['func_update'](array_merge($_POST, $blockinfo));
if (pnModAPIFunc('Blocks', 'admin', 'update', $blockinfo)) {
if (isset ($redirect) && !empty($redirect)) {
if (!empty($returntoblock)) {
// load the block config again
array('bid' => $returntoblock)));
* display form for a new block
* @return string HTML output string
$pnRender->add_core_data();
// Load all blocks (trickier than it sounds)
foreach ($blocks as $moduleblocks) {
foreach ($moduleblocks as $block) {
$modinfo = array('displayname' => _LEGACY);
$blockinfo[$block['mid'] . ':' . $block['bkey']] = $modinfo['displayname'] . '/' . $block['text_type_long'];
$pnRender->assign('blockids', $blockinfo);
// assign block positions
$positions = pnModAPIFunc('Blocks', 'user', 'getallpositions');
$block_positions = array();
foreach ($positions as $position) {
$block_positions[$position['pid']] = $position['name'];
$pnRender->assign('block_positions', $block_positions);
// Return the output that has been generated by this function
return $pnRender->fetch('blocks_admin_new.htm');
* @see blocks_admin_new()
* @param string $title the new title of the block
* @param int $blockid block id to create
* @param string $language the language to assign to the block
* @param string $position the position of the block
* @return bool true if successful, false otherwise
list ($mid, $bkey) = split(':', $blockid);
// Confirm authorisation code
$blockinfo = array('bkey' => $bkey,
'positions' => $positions,
'collapsable' => $collapsable,
'defaultstate' => $defaultstate);
$bid = pnModAPIFunc('Blocks', 'admin', 'create', $blockinfo);
* @param int bid the block id
* @param bool confirm to delete block
* @return string HTML output string
// Get details on current block
if ($blockinfo == false) {
// Check for confirmation
if (empty($confirmation)) {
// No confirmation yet - get one
if (!empty($modinfo['name'])) {
$pnRender->assign('blockname', "$modinfo[name]/$blockinfo[bkey]");
$pnRender->assign('blockname', "Core/$blockinfo[bkey]");
$pnRender->assign('bid', $bid);
// Return the output that has been generated by this function
return $pnRender->fetch('blocks_admin_delete.htm');
// Confirm authorisation code
* display a form to create a new block position
// Return the output that has been generated by this function
return $pnRender->fetch('blocks_admin_newposition.htm');
* display a form to create a new block position
if (!isset ($position['name']) || !preg_match('/^[a-z0-9_-]*$/i', $position['name']) || !isset ($position['description'])) {
// Confirm authorisation code
// add the new block position
if (pnModAPIFunc('Blocks', 'admin', 'createposition', array('name' => $position['name'], 'description' => $position['description']))) {
* display a form to create a new block position
// get the block position
$position = pnModAPIFunc('Blocks', 'user', 'getposition', array('pid' => $pid));
$pnRender->assign($position);
// get all blocks in the position
$block_placements = pnModAPIFunc('blocks', 'user', 'getblocksinposition', array('pid' => $pid));
// get all defined blocks
$allblocks = pnModAPIFunc('Blocks', 'user', 'getall', array('inactive' => true));
foreach($allblocks as $key => $allblock) {
// set the module that holds the block
if ($allblock['mid'] == 0) {
$allblocks[$key]['modname'] = 'Legacy';
$allblocks[$key]['modname'] = $modinfo['name'];
// loop over arrays forming a list of blocks not in the block positon and obtaining
// full details on those that are
foreach ($block_placements as $blockplacement) {
$block['order'] = $blockplacement['order'];
foreach($allblocks as $key => $allblock) {
if ($allblock['bid'] == $blockplacement['bid']) {
$block['modname'] = $allblock['modname'];
$pnRender->assign('assignedblocks', $blocks);
$pnRender->assign('unassignedblocks', $allblocks);
// Return the output that has been generated by this function
return $pnRender->fetch('blocks_admin_modifyposition.htm');
* display a form to create a new block position
if (!isset ($position['pid']) || !isset ($position['name']) || !isset ($position['description'])) {
// Confirm authorisation code
array('pid' => $position['pid'], 'name' => $position['name'], 'description' => $position['description']))) {
* delete a block position
* @param int $args['pid'] the id of the position to be deleted
* @param int $args['objectid'] generic object id maps to pid if present
* @param bool $args['confirmation'] confirmation that this item can be deleted
* @return mixed HTML string if confirmation is null, true if delete successful, false otherwise
$objectid = FormUtil::getPassedValue('objectid', isset ($args['objectid']) ? $args['objectid'] : null, 'REQUEST');
$item = pnModAPIFunc('Blocks', 'user', 'getposition', array('pid' => $pid));
// Check for confirmation.
if (empty($confirmation)) {
$pnRender->assign('pid', $pid);
return $pnRender->fetch('blocks_admin_deleteposition.htm');
if (pnModAPIFunc('Blocks', 'admin', 'deleteposition', array('pid' => $pid))) {
* Any config options would likely go here in the future
* @return string HTML output string
// assign all the module vars
// Return the output that has been generated by this function
return $pnRender->fetch('blocks_admin_modifyconfig.htm');
* @return string bool true if successful, false otherwise
if (!isset ($collapseable) || !is_numeric($collapseable)) {
// Let any other modules know that the modules configuration has been updated
pnModCallHooks('module','updateconfig','Blocks', array('module' => 'Blocks'));
// the module configuration has been updated successfuly
|