Source for file pnadmin.php
Documentation is available at pnadmin.php
* Zikula Application Framework
* @copyright (c) 2002, 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
* This function is the default function, and is called whenever the
* module is initiated without defining arguments. As such it can
* be used for a number of things, but most commonly it either just
* shows the module menu and returns or calls whatever the module
* designer feels should be the default function (often this is the
* @return string HTML string
* Add a new admin category
* This is a standard function that is called whenever an administrator
* wishes to create a new module item
* @return string HTML string
// Return the output that has been generated by this function
return $pnRender->fetch('admin_admin_new.htm');
* This is a standard function that is called with the results of the
* form supplied by admin_admin_new() to create a new category
* @param string $args['catname'] the name of the category to be created
* @param string $args['description'] the description of the category to be created
* @return mixed category id if create successful, false otherwise
$category = FormUtil::getPassedValue('category', isset ($args['category']) ? $args['category'] : null, 'POST');
array('catname' => $category['catname'],
'description' => $category['description']));
* This is a standard function that is called whenever an administrator
* wishes to modify an admin category
* @param int $args['cid'] category id
* @param int $args['objectid'] generic object id maps to cid if present
* @return string HTML string
$item = pnModAPIFunc('Admin', 'admin', 'get', array('cid' => $cid));
$pnRender->assign($item);
return $pnRender->fetch('admin_admin_modify.htm');
* This is a standard function that is called with the results of the
* form supplied by template_admin_modify() to update a current item
* @see Admin_admin_modify()
* @param int $args['cid'] the id of the item to be updated
* @param int $args['objectid'] generic object id maps to cid if present
* @param string $args['catname'] the name of the category to be updated
* @param string $args['description'] the description of the item to be updated
* @return bool true if update successful, false otherwise
$category = FormUtil::getPassedValue('category', isset ($args['category']) ? $args['category'] : null, 'POST');
if (!empty($category['objectid'])) {
$category['cid'] = $category['objectid'];
array('cid' => $category['cid'],
'catname' => $category['catname'],
'description' => $category['description']))) {
* This is a standard function that is called whenever an administrator
* wishes to delete a current module item. Note that this function is
* the equivalent of both of the modify() and update() functions above as
* it both creates a form and processes its output. This is fine for
* simpler functions, but for more complex operations such as creation and
* modification it is generally easier to separate them into separate
* functions. There is no requirement in the Zikula MDG to do one or the
* other, so either or both can be used as seen appropriate by the module
* @param int $args['cid'] the id of the category to be deleted
* @param int $args['objectid'] generic object id maps to cid 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('Admin', 'admin', 'get', array('cid' => $cid));
// Check for confirmation.
if (empty($confirmation)) {
// No confirmation yet - display a suitable form to obtain confirmation
// of this action from the user
$pnRender->assign('cid', $cid);
return $pnRender->fetch('admin_admin_delete.htm');
if (pnModAPIFunc('Admin', 'admin', 'delete', array('cid' => $cid))) {
* View all admin categories
* @param int $startnum the starting id to view from - optional
* @return string HTML string
array('startnum' => $startnum,
foreach ($items as $item) {
$options[] = array('url' => pnModURL('Admin', 'admin', 'modify', array('cid' => $item['cid'])),
$options[] = array('url' => pnModURL('Admin', 'admin', 'delete', array('cid' => $item['cid'])),
'image' => '14_layer_deletelayer.gif',
$item['options'] = $options;
$pnRender->assign('items', $rows);
$pnRender->assign('pager', array('numitems' => pnModAPIFunc('Admin', 'admin', 'countitems'),
'itemsperpage' => pnModGetVar('Admin', 'itemsperpage')));
// Return the output that has been generated by this function
return $pnRender->fetch('admin_admin_view.htm');
* Display main admin panel for a category
* @param int $args['acid'] the id of the category to be displayed
* @return string HTML string
// suppress admin display - return to index.
// check if install.php or install folder exist
// check if the Zikula Swiss Army Knife exists
// if either one them is true we show a warning and do not let the admin go to
if ($installexists== true || $psakexists== true) {
$pnRender->assign('installexists', $installexists);
$pnRender->assign('psakexists', $psakexists);
$pnRender->assign('adminpanellink', pnModURL('Admin','admin', 'adminpanel'));
return $pnRender->fetch('admin_admin_warning.htm');
// Now prepare the display of the admin panel by getting the relevant info.
// Get parameters from whatever input we need.
// cid isn't set, so we check the last session var lastcid to see where the admin has been before.
// cid is still not set, go to the default category
// now we know where we are or where the admin wants us to go to, lets store it in a
// session var for later use
// Add category menu to output
// Admin_admin_categorymenu may have changed the acid. In this case it has been
// stored to lastacid so we need to read it again now
// Handle the case where the current/default category does not contain any accessible items
// (the current user may just have admin access to a single module)
// Get Datails on the selected category
// get the default category
$pnRender->assign('category', $category);
// assign all module vars
// get admin capable modules
foreach ($adminmodules as $adminmodule) {
if (($catid == $acid) || (($catid == false) && ($acid == pnModGetVar('Admin', 'defaultcategory')))) {
if ($modinfo['type'] == 2 || $modinfo['type'] == 3) {
$menutexturl = pnModURL($modinfo['name'], 'admin');
$menutext = $modinfo['displayname'];
$menutexttitle = $modinfo['description'];
$modpath = ($modinfo['type'] == 3) ? 'system' : 'modules';
$menutexturl = 'admin.php?module=' . $modinfo['name'];
$menutext = $modinfo['displayname'];
$menutexttitle = $modinfo['description'];
$adminicons = array($modpath . '/' . $osmoddir . '/pnimages/admin.gif',
$modpath . '/' . $osmoddir . '/pnimages/admin.jpg',
$modpath . '/' . $osmoddir . '/pnimages/admin.jpeg',
$modpath . '/' . $osmoddir . '/pnimages/admin.png',
$modpath . '/' . $osmoddir . '/images/admin.gif',
'system/Admin/pnimages/default.gif');
foreach($adminicons as $adminicon) {
$adminlinks[] = array('menutexturl' => $menutexturl,
'menutexttitle' => $menutexttitle,
'modname' => $modinfo['name'],
'adminicon' => $adminicon);
$pnRender->assign('adminlinks', $adminlinks);
// work out what stylesheet is being used to render to the admin panel
// Return the output that has been generated by this function
if ($pnRender->template_exists('admin_admin_adminpanel_'. $cssfile[0]. '.htm')) {
return $pnRender->fetch('admin_admin_adminpanel_'. $cssfile[0]. '.htm');
return $pnRender->fetch('admin_admin_adminpanel.htm');
* This is a standard function to modify the configuration parameters of the
* @return string HTML string
// get admin capable mods
$pnRender->assign('categories', $categories);
// assign all the module vars
$modulecatories = array();
foreach ($adminmodules as $adminmodule) {
// Get the category assigned to this module
$category = pnModAPIFunc('Admin', 'admin', 'getmodcategory',
if ($category === false) {
// it's not set, so we use the default category
// output module category selection
$modulecategories[] = array('displayname' => $adminmodule['displayname'],
'name' => $adminmodule['name'],
'category' => $category);
$pnRender->assign('modulecategories', $modulecategories);
// Return the output that has been generated by this function
return $pnRender->fetch('admin_admin_modifyconfig.htm');
* This is a standard function to update the configuration parameters of the
* module given the information passed back by the modification form
* @see Admin_admin_modifyconfig()
* @param int $modulesperrow the number of modules to display per row in the admin panel
* @param int $admingraphic switch for display of admin icons
* @param int $modulename,... the id of the category to set for each module
* @return string HTML string
// set modules per row module var
// set the ignore installer check module var
pnModSetVar('Admin', 'ignoreinstallercheck', $ignoreinstallercheck);
// set modules per row module var
// set stylesheet to render module
pnModSetVar('Admin', 'modulestylesheet', $modulestylesheet);
// set admin icons config var (should be moved to module var at some point)
// set start category module var
// set default category module var
pnModSetVar('Admin', 'defaultcategory', $defaultcategory);
// set the admin theme module var
foreach ($adminmodules as $adminmodule) {
// Add the module to the category
$result = pnModAPIFunc('Admin', 'admin', 'addmodtocategory',
array('module' => $adminmodule['name'],
'category' => $category));
// Let any other modules know that the modules configuration has been updated
pnModCallHooks('module','updateconfig','Admin', array('module' => 'Admin'));
// the module configuration has been updated successfuly
// This function generated no output, and so now it is complete we redirect
// the user to an appropriate page for them to carry on their work
* @return string HTML string
// get the current category
// cid is still not set, go to the default category
// get admin capable modules
foreach ($adminmodules as $adminmodule) {
$catid = pnModAPIFunc('Admin', 'admin', 'getmodcategory', array('mid' => $adminmodule['id']));
if ($adminmodule['type'] == 2 || $adminmodule['type'] == 3) {
$menutexturl = pnModURL($adminmodule['name'], 'admin');
$menutext = $adminmodule['displayname'];
$menutexttitle = $adminmodule['description'];
$menutexturl = 'admin.php?module=' . $adminmodule['name'];
$menutext = $adminmodule['displayname'];
$menutexttitle = $adminmodule['description'];
$adminlinks[$catid][] = array('menutexturl' => $menutexturl,
'menutexttitle' => $menutexttitle,
'modname' => $adminmodule['name']);
$possible_cids = array();
if (isset ($items) && is_array($items)) {
foreach($items as $item) {
// only categories containing modules where the current user has permissions will
// be shown, all others will be hidden
// admin will see all categories
if ( (isset ($adminlinks[$item['cid']]) && count($adminlinks[$item['cid']]) )
$menuoption = array('url' => pnModURL('Admin','admin','adminpanel', array('acid' => $item['cid'])),
'title' => $item['catname'],
'description' => $item['description'],
if (isset ($adminlinks[$item['cid']])) {
$menuoption['items'] = $adminlinks[$item['cid']];
$menuoption['items'] = array();
$menuoptions[] = $menuoption;
$possible_cids[] = $item['cid'];
if ($acid== $item['cid']) {
// if permission is false we are not allowed to see this category because its
// empty and we are not admin
if ($permission== false) {
// show the first category
$acid = (int) $possible_cids[0];
$pnRender->assign('currentcat', $acid);
$pnRender->assign('menuoptions', $menuoptions);
// zikula baseline security analyzer
// check for magic_quotes
// check for register_globals
// check for config.php beeing writable
// cannot rely on is_writable() because it falsely reports a number of cases - drak
$config_php = @fopen('config/config.php', 'a');
if ($config_php === true) {
$pnRender->assign('config_php', (bool) $config_php);
$pnRender->assign('upgrade_php', $upgrade_php);
$pnRender->assign('legacy_mode', $legacy_mode);
// check for .htaccess in /pnTemp
if ($GLOBALS['PNConfig']['System']['temp']) {
// default installation, check for .htaccess
$pntemp_htaccess = (bool) file_exists($GLOBALS['PNConfig']['System']['temp']. '/.htaccess');
// already customized, admin should know about what he's doing...
$pnRender->assign('pntemp_htaccess', $pntemp_htaccess);
$pnRender->assign('scactive', $scactive);
$pnRender->assign('scenabled', $scenabled);
// check for safehtml outputfilter
$pnRender->assign('safehtml', $safehtml);
// work out what stylesheet is being used to render to the admin panel
// Return the output that has been generated by this function
if ($pnRender->template_exists('admin_admin_categorymenu_'. $cssfile[0]. '.htm')) {
return $pnRender->fetch('admin_admin_categorymenu_'. $cssfile[0]. '.htm');
return $pnRender->fetch('admin_admin_categorymenu.htm');
* display the module help page
return $pnRender->fetch('admin_admin_help.htm');
|