1<?php
2/**
3 * @package tikiwiki
4 */
5// (c) Copyright by authors of the Tiki Wiki CMS Groupware Project
6//
7// All Rights Reserved. See copyright.txt for details and a complete list of authors.
8// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
9// $Id$
10
11require_once('tiki-setup.php');
12$themelib = TikiLib::lib('theme');
13$themecontrollib = TikiLib::lib('themecontrol');
14$categlib = TikiLib::lib('categ');
15$access->check_feature('feature_theme_control');
16$access->check_permission('tiki_p_admin');
17
18$auto_query_args = ['find', 'sort_mode', 'offset', 'theme', 'categId'];
19
20//consider preference feature_theme_control_parentcategory setting when displaying list of available categories
21if ($prefs['feature_theme_control_parentcategory'] != "n" && $prefs['feature_theme_control_parentcategory'] != -1) {
22	$parentCategoryId = $prefs['feature_theme_control_parentcategory'];
23	$categoryFilter = [
24		'type' => 'children',
25		'identifier' => $parentCategoryId,
26	];
27} else {
28	$categoryFilter = [
29		'type' => 'all',
30	];
31}
32$categories = $categlib->getCategories($categoryFilter, true, true, false);
33$smarty->assign('categories', $categories);
34
35$smarty->assign('categId', isset($_REQUEST['categId']) ? $_REQUEST['categId'] : 0);
36
37$themes = $themelib->list_themes_and_options();
38$smarty->assign('themes', $themes);
39
40if (isset($_REQUEST['assign'])) {
41	if (isset($_REQUEST['categoryId'])) {
42		check_ticket('theme-control');
43		$themecontrollib->tc_assign_category($_REQUEST['categoryId'], $_REQUEST['theme']);
44	} else {
45		$smarty->assign('msg', tra("Please create a category first"));
46		$smarty->display("error.tpl");
47		die;
48	}
49}
50if (isset($_REQUEST['delete'])) {
51	check_ticket('theme-control');
52	foreach (array_keys($_REQUEST['categoryIds']) as $cat) {
53		$themecontrollib->tc_remove_cat($cat);
54	}
55}
56
57if (! isset($_REQUEST["sort_mode"])) {
58	$sort_mode = 'name_asc';
59} else {
60	$sort_mode = $_REQUEST["sort_mode"];
61}
62if (! isset($_REQUEST["offset"])) {
63	$offset = 0;
64} else {
65	$offset = $_REQUEST["offset"];
66}
67$smarty->assign_by_ref('offset', $offset);
68if (isset($_REQUEST["find"])) {
69	$find = $_REQUEST["find"];
70} else {
71	$find = '';
72}
73$smarty->assign('find', $find);
74$smarty->assign_by_ref('sort_mode', $sort_mode);
75$channels = $themecontrollib->tc_list_categories($offset, $maxRecords, $sort_mode, $find);
76$smarty->assign_by_ref('cant_pages', $channels["cant"]);
77$smarty->assign_by_ref('channels', $channels["data"]);
78ask_ticket('theme-control');
79// Display the template
80$smarty->assign('mid', 'tiki-theme_control.tpl');
81$smarty->display("tiki.tpl");
82