tiki-edit_categories.php 2.28 KB
Newer Older
1
<?php
changi67's avatar
changi67 committed
2 3 4
/**
 * @package tikiwiki
 */
5
// (c) Copyright 2002-2015 by authors of the Tiki Wiki CMS Groupware Project
6
//
7 8
// 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.
9
// $Id$
10 11 12

$inputConfiguration = array(array(
	'staticKeyFiltersForArrays' => array(
13
		'filter' => 'text',
14
		'sort_mode' => 'text',
15 16 17 18 19
	),
	'catchAllUnset' => null,
));

require_once 'tiki-setup.php';
20
$categlib = TikiLib::lib('categ');
21
require_once 'lib/tree/BrowseTreeMaker.php';
22 23 24 25

$access->check_feature('feature_categories');

// Generate the category tree {{{
26
$ctall = $categlib->getCategories();
27 28

$tree_nodes = array();
29
foreach ($ctall as $c) {
30
	$url = htmlentities(
31 32 33 34 35 36 37
		'tiki-edit_categories.php?' . http_build_query(
			array(
				'filter~categories' => $c['categId'],
			)
		),
		ENT_QUOTES,
		'UTF-8'
38
	);
39 40 41 42 43 44 45 46 47 48
	$name = htmlentities($c['name'], ENT_QUOTES, 'UTF-8');
	$perms = Perms::get('category', $c['categId']);

	$add = $perms->add_object ? '<span class="control categ-add"></span>' : '';
	$remove = $perms->remove_object ? '<span class="control categ-remove"></span>' : '';

	$body = <<<BODY
$add
$remove
<span class="object-count">{$c['objects']}</span>
49
<a class="catname" href="{$url}" data-categ="{$c['categId']}">{$name}</a>
50 51 52 53 54 55 56 57
BODY;

	$tree_nodes[] = array(
		'id' => $c['categId'],
		'parent' => $c['parentId'],
		'data' => $body,
	);
}
58 59 60 61

$tree_nodes[] = array(
	'id' => 'orphan',
	'parent' => '0',
62
	'data' => '<span class="object-count">' . $orphans['cant'] . '</span><a class="catname" href="tiki-edit_categories.php?filter~categories=orphan"><em>' . tr('Orphans') . '</em></a>',
63 64
);

65
$tm = new BrowseTreeMaker('categ');
66 67 68 69
$res = $tm->make_tree(0, $tree_nodes);
$smarty->assign('tree', $res);
// }}}

70 71
$filter = isset($_REQUEST['filter']) ? $_REQUEST['filter'] : array();
$smarty->assign('filter', $filter);
72

73 74 75
if (count($filter)) {
	$unifiedsearchlib = TikiLib::lib('unifiedsearch');
	$query = $unifiedsearchlib->buildQuery($filter);
76 77 78
	if (isset($_REQUEST['sort_mode']) && $order = Search_Query_Order::parse($_REQUEST['sort_mode'])) {
		$query->setOrder($order);
	}
79 80
	$result = $query->search($unifiedsearchlib->getIndex());
	$smarty->assign('result', $result);
81 82 83 84 85
}
// }}}

$smarty->assign('mid', 'tiki-edit_categories.tpl');
$smarty->display('tiki.tpl');