<?php
/*
* Copyright 2008 Blandware (http://www.blandware.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Actions for browsers.
*
* @package AtleapLite
* @author Roman Puchkovskiy
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
*/
/**
*/
require_once 'include/actions/page.php';
require_once 'include/actions/resource.php';
/**
* Shows page browser.
*/
function browsePages() {
global $smarty, $perPage, $pagerDelta;
if ($_GET['opening'] == 'true') {
$_SESSION['browserMenuItemsToRemove'] = array();
}
processGridParams('pagesBrowserGrid', array('layout' => -1, 'language' => -1, 'page_active' => -1));
$queryInfo = buildDefaultQueryInfo();
$queryInfo['additionalSelect'] = array("(published AND ('" . getNowDate() . "' BETWEEN publication_date AND expiration_date)) as page_active");
$partial = loadPages($queryInfo, 'pagesBrowserGrid');
$total = $partial['total'];
$pages = $partial['rows'];
$pager = getPager(array('totalItems' => $total));
exportPagerData($pager, $smarty, $pages);
assignSortDirs('pagesBrowserGrid', $smarty, getPageDescriptor());
assignFilters($smarty, 'pagesBrowserGrid');
$smarty->setDisplayLayout(getLayout(BROWSER_LAYOUT));
$smarty->assign('template', 'browser/pages.tpl');
$smarty->assign('title', getMessage('browser.pages.title'));
$smarty->initGrid('pagesBrowserGrid', getPageDescriptor(), $_GET['action']);
$smarty->assign('layouts', getLayoutsForSelect(true));
$smarty->assign('languagesForSelect', getLanguagesForSelect(true));
$smarty->assign('allYesNoList', getAllYesNoList());
$smarty->assign('browserMenu', removeBrowserMenuItems(getBrowserMenu(), $_SESSION['browserMenuItemsToRemove']));
$smarty->assign('dontNeedMdelButton', true);
$smarty->assign('currentMenuItemId', 'pages');
}
/**
* Shows one of resource browsers.
*/
function browseResources($gridName, $resourceType, $template, $titleKey,
$currentMenuItemId, $idsToRemove) {
global $smarty, $perPage, $pagerDelta;
if ($_GET['opening'] == 'true') {
$_SESSION['browserMenuItemsToRemove'] = $idsToRemove;
}
processGridParams($gridName, array('resource_active' => -1));
$queryInfo = buildDefaultQueryInfo();
$queryInfo['select'] = getSelectForResourceList();
$queryInfo['additionalSelect'] = array("(published AND ('" . getNowDate() . "' BETWEEN publication_date AND expiration_date)) as resource_active");
$queryInfo['fields'] = array('type' => $resourceType);
$partial = loadResources($queryInfo, $gridName);
$total = $partial['total'];
$resources = $partial['rows'];
$pager = getPager(array('totalItems' => $total));
exportPagerData($pager, $smarty, $resources);
assignSortDirs($gridName, $smarty, getResourceDescriptor());
assignFilters($smarty, $gridName);
$smarty->setDisplayLayout(getLayout(BROWSER_LAYOUT));
$smarty->assign('template', $template);
$smarty->assign('title', getMessage($titleKey));
$smarty->initGrid($gridName, getResourceDescriptor(), $_GET['action']);
$smarty->assign('allYesNoList', getAllYesNoList());
$smarty->assign('browserMenu', removeBrowserMenuItems(getBrowserMenu(), $_SESSION['browserMenuItemsToRemove']));
$smarty->assign('dontNeedMdelButton', true);
$smarty->assign('currentMenuItemId', $currentMenuItemId);
}
/**
* Shows file browser.
*/
function browseFiles() {
browseResources('filesBrowserGrid', RESOURCE_TYPE_FILE, 'browser/files.tpl',
'browser.files.title', 'files', array('pages', 'images'));
}
/**
* Shows image browser.
*/
function browseImages() {
browseResources('imagesBrowserGrid', RESOURCE_TYPE_IMAGE, 'browser/images.tpl',
'browser.images.title', 'images', array('pages', 'files'));
}
/**
* Removes some menu items from browser menu.
*
* @param array $menu browser menu
* @param array $idsToRemove list of IDs of items to remove
*/
function removeBrowserMenuItems($menu, $idsToRemove) {
$result = array();
if (is_array($idsToRemove)) {
foreach ($menu as $k => $item) {
if (array_search($item['id'], $idsToRemove) === false) {
$result[$k] = $item;
}
}
}
return $result;
}
?>