tiki-edit_perspective.php 3.33 KB
Newer Older
lphuberdeau's avatar
lphuberdeau committed
1
<?php
2
// (c) Copyright 2002-2011 by authors of the Tiki Wiki CMS Groupware Project
changi67's avatar
changi67 committed
3
// 
lphuberdeau's avatar
lphuberdeau committed
4 5
// All Rights Reserved. See copyright.txt for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
changi67's avatar
changi67 committed
6
// $Id$
lphuberdeau's avatar
lphuberdeau committed
7 8 9 10

$inputConfiguration = array( array(
	'staticKeyFilters' => array(
		'offset' => 'int',
11
		'id' => 'int',
lphuberdeau's avatar
lphuberdeau committed
12 13 14
		'name' => 'striptags',
		'create' => 'alpha',
		'action' => 'alpha',
15
		'criteria' => 'striptags',
lphuberdeau's avatar
lphuberdeau committed
16 17 18 19 20 21 22
	),
	'staticKeyFiltersForArrays' => array(
		'lm_preference' => 'word',
	),
	'catchAllUnset' => null,
) );

23
$auto_query_args = array( 'offset', 'id', 'cookietab' );
24
$section='admin';
lphuberdeau's avatar
lphuberdeau committed
25

26 27
require_once('tiki-setup.php');
require_once('lib/perspectivelib.php');
lphuberdeau's avatar
lphuberdeau committed
28

29
$access->check_feature( array('feature_perspective', 'feature_jquery_ui') );
lphuberdeau's avatar
lphuberdeau committed
30 31 32

$selectedId = 0;

33 34 35
if( isset( $_REQUEST['id'] ) ) {
	$selectedId = $_REQUEST['id'];
	$objectperms = Perms::get( array( 'type' => 'perspective', 'object' => $_REQUEST['id'] ) );
36
	$cookietab = 3;
lphuberdeau's avatar
lphuberdeau committed
37 38 39 40 41 42 43
}

if( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'remove' && $selectedId && $objectperms->perspective_admin ) {
	check_ticket( 'remove_perspective' );

	$perspectivelib->remove_perspective( $selectedId );
	$selectedId = 0;
44
	$cookietab = '1';
lphuberdeau's avatar
lphuberdeau committed
45 46 47 48 49 50 51 52 53 54 55
}

// Edit perspective
if( isset( $_REQUEST['name'] ) && $selectedId && $objectperms->perspective_edit ) {
	global $prefslib; require_once 'lib/prefslib.php';
	$perspectivelib->replace_perspective( $selectedId, $_REQUEST['name'] );

	$preferences = $_REQUEST['lm_preference'];
	$input = $prefslib->getInput( $jitRequest, $preferences, 'perspective' );

	$perspectivelib->replace_preferences( $selectedId, $input );
56
	$cookietab = '1';
lphuberdeau's avatar
lphuberdeau committed
57 58 59 60 61 62 63 64
}

// Create perspective
if( isset( $_REQUEST['create'], $_REQUEST['name'] ) && $globalperms->create_perspective ) {
	$name = trim( $_REQUEST['name'] );

	if( ! empty( $name ) ) {
		$selectedId = $perspectivelib->replace_perspective( null, $name );
65
		$cookietab = 3;
lphuberdeau's avatar
lphuberdeau committed
66 67 68 69 70
	}
}

$maxRecords = $prefs['maxRecords'];
$offset = isset( $_REQUEST['offset'] ) ? $_REQUEST['offset'] : 0;
71 72
$smarty->assign( 'offset', $offset );
$smarty->assign( 'count', $tikilib->getOne( 'SELECT COUNT(*) FROM tiki_perspectives' ) );
lphuberdeau's avatar
lphuberdeau committed
73 74 75 76 77 78 79

$perspectives = $perspectivelib->list_perspectives( $offset, $maxRecords );

if( $selectedId ) {
	$info = $perspectivelib->get_perspective( $selectedId );

	$smarty->assign( 'perspective_info', $info );
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96

	if( isset( $_REQUEST['criteria'] ) ) {
		global $prefslib; require_once 'lib/prefslib.php';
		require_once 'lib/smarty_tiki/function.preference.php';

		$criteria = $_REQUEST['criteria'];
		$results = $prefslib->getMatchingPreferences( $criteria );
		$results = array_diff( $results, array_keys( $info['preferences'] ) );

		foreach( $results as $name ) {
			echo smarty_function_preference( array(
				'name' => $name,
			), $smarty );
		}

		exit;
	}
lphuberdeau's avatar
lphuberdeau committed
97 98
}

99 100
$headerlib->add_cssfile('css/admin.css');		// to display the prefs properly

101 102 103 104 105 106 107
$headtitle = tra('Perspectives');
$description = tra('Edit Perspectives');
$crumbs[] = new Breadcrumb($headtitle, $description, '', '', '');
$headtitle = breadcrumb_buildHeadTitle($crumbs);
$smarty->assign('headtitle', $headtitle);
$smarty->assign('trail', $crumbs);

108 109 110
if (!isset($cookietab)) { $cookietab = '1'; }
setcookie('tab', $cookietab);

lphuberdeau's avatar
lphuberdeau committed
111 112 113
$smarty->assign( 'perspectives', $perspectives );
$smarty->assign( 'mid', 'tiki-edit_perspective.tpl' );
$smarty->display( 'tiki.tpl' );