This repository has been archived on 2024-11-28. You can view files and clone it, but cannot push or open issues or pull requests.
Incam_SGD/plugins/WemagSidebarManagement/admin/portlets.php

267 lines
7.4 KiB
PHP
Raw Permalink Normal View History

<?php
/**
* This file is part of Wemag Sidebar Management.
*
* Wemag Sidebar Management is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Wemag Sidebar Management is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Wemag Sidebar Management.
* If not, see <http://www.gnu.org/licenses/>.
*
* Copyright 2008 Aart-Jan Boor <aart-jan@wemag.nl>
* Wemag Advisering <http://www.wemag.nl>
*/
require_once(KT_LIB_DIR . '/dispatcher.inc.php');
/**
* Logic behind document and folder portlets management
*
*/
class PortletsAdminDispatcher extends KTAdminDispatcher {
//Vars are defined in folder_portlets.php and document_portlets.php
var $type;
var $portlets_page_title;
var $portlets_edit_page_title;
var $config_file;
var $about_portlet_title;
var $actions_portlet_title;
/**
* Constructor, call parent constructor
*
* @return PortletsAdminDispatcher dispatcher
*/
function PortletsAdminDispatcher(){
return parent::KTAdminDispatcher();
}
/**
* Figure out what to show
*
* @return HTML for page content
*/
function do_main(){
//Are we editing an indiviual portlet?
if($_GET['action']=='editPortlet'){
//Yes, check for submits
if($_POST['submit']){
$this->doPortletEdit();
}
return $this->showPortletEdit();
}else{
//No, show list
return $this->showPortletList();
}
}
/**
* Uses the KT portlet registry to find installed portlets
* Additionally, the two main portlets (About,actions) are added manually
* because the don't reside in the registry.
*
* @return array list with portlets
*/
function _getPortletList(){
$oPRegistry =& KTPortletRegistry::getSingleton();
$aPortlets = $oPRegistry->getPortletsForPage(array(array('action'=>'browse')));
$actionsPortlet = new stdClass();
$actionsPortlet->bActive = true;
$actionsPortlet->oPlugin = new stdClass();
$actionsPortlet->oPlugin->sFriendlyName = "Core Application Functionality";
$actionsPortlet->sTitle = $this->actions_portlet_title;
$aboutPortlet = new stdClass();
$aboutPortlet->bActive = true;
$aboutPortlet->oPlugin = new stdClass();
$aboutPortlet->oPlugin->sFriendlyName = "Core Application Functionality";
$aboutPortlet->sTitle = $this->about_portlet_title;
$aPortlets[] = $actionsPortlet;
$aPortlets[] = $aboutPortlet;
return $aPortlets;
}
/**
* Show list with available portlets
*
* @return string HTML for page
*/
function showPortletList(){
//set breadcrumbs
$this->oPage->setBreadcrumbDetails(_kt($this->portlets_page_title));
//find list of available portlets
$aPortlets = $this->_getPortletList();
//encode titles
foreach($aPortlets as $oPortlet){
$oPortlet->sTitleURL = urlencode($oPortlet->sTitle);
}
//render template
$oTemplating =& KTTemplating::getSingleton();
$oTemplate = $oTemplating->loadTemplate("portlets_list");
return $oTemplate->render(array('portlets' => $aPortlets,
'type'=>$this->type));
}
/**
* Process the submited portlet edit information
*
*/
function doPortletEdit(){
//find current configuration
$config = $this->_getConfig();
//set up config entry if required
if($config[$_POST['cfgtitle']] == ""){
$config[$_POST['cfgtitle']] = new stdClass();
}
//swap active value
if($_POST['active'] == 1){
$_POST['active'] = 0;
}else{
$_POST['active'] = 1;
}
//write config values
$config[$_POST['cfgtitle']]->delete = $_POST['delete'];
$config[$_POST['cfgtitle']]->active = $_POST['active'];
$config[$_POST['cfgtitle']]->order = $_POST['order'];
$config[$_POST['cfgtitle']]->disabled_actions = $_POST['disabled'];
//save the configuration file
$this->_saveConfig($config);
}
/**
* Show the portlet edit form
*
* @return string HTML for page
*/
function showPortletEdit(){
//set breadcrubms
$this->oPage->setBreadcrumbDetails($this->portlets_edit_page_title);
//set up vars
$portlet = $_GET['portlet'];
$current_portlet = "";
$current_config = new stdClass();
$current_actions = null;
$aPortlets = $this->_getPortletList();
//first check if the portlet actually exists
foreach($aPortlets as $oPortlet){
if($oPortlet->sTitle == $portlet || urlencode($oPortlet->sTitle) == $portlet ){
$current_portlet = $oPortlet;
break;
}
}
if($current_portlet == ""){
die("Portlet does not exist");
}
//now check if there is a custom configuration available for this portlet
$config = $this->_getConfig();
$key = md5($current_portlet->sTitle);
if($config[$key]!= null){
//config found
$current_config = $config[$key];
}else{
//set up default config
$current_config->active = $current_portlet->bActive;
$current_config->order = 0;
}
$current_config->cfgtitle = $key;
//some logic to check the right form checkboxes
if($current_config->active == false){
$current_config->active_checked = "checked='checked'";
}
if($current_config->delete == true){
$current_config->delete_checked = "checked='checked'";
}
//set up the actions if necessary
if($current_portlet->sTitle == $this->actions_portlet_title ||
$current_portlet->sTitle == $this->about_portlet_title){
//get actions from KT action registry
$oR =& KTActionRegistry::getSingleton();
if($current_portlet->sTitle == $this->actions_portlet_title){
$current_actions = $oR->getActions($this->type."action");
}else{
$current_actions = $oR->getActions($this->type."info");
}
//walk trough actions to find names etc.
$new_actions = array();
foreach($current_actions as $action){
//construct action class
$new_action = $oR->initializeAction($action[2],$this->oUser);
//don't show any system actions
if($new_action->systemAction != true){
//find action display names
$action[5] = $new_action->getDisplayName();
if($action[5] == ''){
$action[5] = $new_action->getName();
}
//is action disabled in our config?
if($current_config->disabled_actions[$action[2]] == true){
$action[6]="checked='checked'";
}
$new_actions[] = $action;
}
}
$current_actions = $new_actions;
}
//render template
$oTemplating =& KTTemplating::getSingleton();
$oTemplate = $oTemplating->loadTemplate("edit_portlet");
return $oTemplate->render(array('cfg' => $current_config,
'oPortlet' => $current_portlet,
'actions' => $current_actions));
}
/**
* Retrieve configuration values from file
*
* @return array config
*/
function _getConfig(){
return unserialize(file_get_contents($this->config_file));
}
/**
* Save configuration to file
*
* @param array $cfg array with config values
*/
function _saveConfig($cfg){
$h = fopen($this->config_file,"wb");
fwrite($h,serialize($cfg));
fclose($h);
}
}
?>