tiki-directory_browse.php 4.4 KB
Newer Older
1
<?php
changi67's avatar
changi67 committed
2 3 4
/**
 * @package tikiwiki
 */
5
// (c) Copyright 2002-2016 by authors of the Tiki Wiki CMS Groupware Project
rjsmelo's avatar
rjsmelo committed
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$
changi67's avatar
changi67 committed
10

11
$section = 'directory';
rjsmelo's avatar
rjsmelo committed
12 13
require_once('tiki-setup.php');
include_once('lib/directory/dirlib.php');
14 15
$access->check_feature('feature_directory');
$access->check_permission('tiki_p_view_directory');
16
//get_strings tra('Browse Directory')
17
// If no parent category then the parent category is 0
rjsmelo's avatar
rjsmelo committed
18 19 20
if (! isset($_REQUEST["parent"])) {
	$_REQUEST["parent"] = 0;
}
21 22 23 24 25
$smarty->assign('parent', $_REQUEST["parent"]);
$all = 0;
if ($_REQUEST["parent"] == 0) {
	$parent_name = 'Top';
	$all = 1;
changi67's avatar
changi67 committed
26
	$smarty->assign('parent_info', "");
27
} else {
28
	$parent_info = $dirlib->dir_get_category($_REQUEST['parent']);
29
	$smarty->assign('parent_info', $parent_info);
30
	$parent_name = $parent_info['name'];
31
}
32 33
$smarty->assign('parent_name', $parent_name);
$smarty->assign('parent', $_REQUEST['parent']);
34
$smarty->assign('addtocat', $_REQUEST['parent']);
35 36 37
$dirlib->dir_add_category_hit($_REQUEST['parent']);
// Now get the path to the parent category
$path = $dirlib->dir_get_category_path_browse($_REQUEST["parent"]);
38
$smarty->assign_by_ref('path', $path);
39
$crumbs[] = new Breadcrumb(tra('Directory'), '', 'tiki-directory_browse.php?parent=0', 'Directory', tra('How to use Directory'));
40
// Now append the path to the parent category
41
array_splice($crumbs, count($crumbs), 0, $dirlib->dir_build_breadcrumb_trail($_REQUEST["parent"]));
42
$smarty->assign('trail', $crumbs);
43
$headtitle = breadcrumb_buildHeadTitle($crumbs);
44
$smarty->assign_by_ref('headtitle', $headtitle);
45
// Now get the sub categories from this parent category
46
$categs = $dirlib->dir_list_categories($_REQUEST['parent'], 0, -1, 'name_asc', '');
47 48
$temp_max = count($categs['data']);
for ($i = 0; $i < $temp_max; $i++) {
rjsmelo's avatar
rjsmelo committed
49
	$categs['data'][$i]['subcats'] = [];
50 51
	if ($categs['data'][$i]['childrenType'] == 'c' && $categs['data'][$i]['viewableChildren'] > 0) {
		// Generate the subcategories with most hist as the subcategories to show.
52
		$subcats = $dirlib->dir_list_categories($categs['data'][$i]['categId'], 0, $categs['data'][$i]['viewableChildren'], 'hits_desc', '');
53 54 55 56
		$categs['data'][$i]['subcats'] = $subcats['data'];
	}
	if ($categs['data'][$i]['childrenType'] == 'd' && $categs['data'][$i]['viewableChildren'] > 0) {
		// Generate the subcategories with most hist as the subcategories to show.
rjsmelo's avatar
rjsmelo committed
57 58
		$categs['data'][$i]['subcats'] = [
			[
59
				"name" => $categs['data'][$i]['description']
rjsmelo's avatar
rjsmelo committed
60 61
			]
		];
62 63
	}
	if ($categs['data'][$i]['childrenType'] == 'r' && $categs['data'][$i]['viewableChildren'] > 0) {
changi67's avatar
changi67 committed
64
		$categs['data'][$i]['subcats'] = $dirlib->get_random_subcats($categs['data'][$i]['categId'], $categs['data'][$i]['viewableChildren']);
65
	}
66
}
67
$smarty->assign_by_ref('categs', $categs['data']);
68
$smarty->assign('cols', $prefs['directory_columns']);
69
// Now if needed get sites
70 71 72 73 74 75 76
$categ_info = $dirlib->dir_get_category($_REQUEST['parent']);
$smarty->assign_by_ref('categ_info', $categ_info);
if ($user) {
	if (in_array($categ_info['editorGroup'], $userlib->get_user_groups($user))) {
		$tiki_p_admin_directory_sites = 'y';
		$smarty->assign('tiki_p_admin_directory_sites', 'y');
	}
77
}
78
if ($categ_info['allowSites'] == 'y') {
rjsmelo's avatar
rjsmelo committed
79
	if (! isset($_REQUEST["sort_mode"])) {
80 81 82 83
		$sort_mode = 'hits_desc';
	} else {
		$sort_mode = $_REQUEST["sort_mode"];
	}
rjsmelo's avatar
rjsmelo committed
84
	if (! isset($_REQUEST["offset"])) {
85 86 87 88 89 90 91 92 93 94 95 96
		$offset = 0;
	} else {
		$offset = $_REQUEST["offset"];
	}
	if (isset($_REQUEST["find"])) {
		$find = $_REQUEST["find"];
	} else {
		$find = '';
	}
	$smarty->assign_by_ref('offset', $offset);
	$smarty->assign_by_ref('sort_mode', $sort_mode);
	$smarty->assign('find', $find);
97 98
	$items = $dirlib->dir_list_sites($_REQUEST['parent'], $offset, $prefs['directory_links_per_page'], $sort_mode, '', 'y');
	$smarty->assign_by_ref('cant_pages', $items["cant"]);
99
	$smarty->assign_by_ref('items', $items["data"]);
100
}
rjsmelo's avatar
rjsmelo committed
101
include_once('tiki-section_options.php');
102
// Related categs
103
$related = $dirlib->dir_list_related_categories($_REQUEST['parent'], 0, -1, 'name_asc', '');
104
$smarty->assign_by_ref('related', $related['data']);
105
$stats = $dirlib->dir_stats();
106
$smarty->assign_by_ref('stats', $stats);
107
ask_ticket('dir-browse');
108
$smarty->assign('mid', 'tiki-directory_browse.tpl');
sylvieg's avatar
sylvieg committed
109 110 111 112 113 114
if (isset($_REQUEST['print'])) {
	$smarty->display('tiki-print.tpl');
	$smarty->assign('print', 'y');
} else {
	$smarty->display('tiki.tpl');
}