tiki-directory_browse.php 5.13 KB
Newer Older
1
<?php
2

3
// $Id: /cvsroot/tikiwiki/tiki/tiki-directory_browse.php,v 1.16 2007-10-12 07:55:25 nyloth Exp $
4

5
// Copyright (c) 2002-2007, Luis Argerich, Garland Foster, Eduardo Polidor, et. al.
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
// Initialization
10
$section = 'directory';
11
require_once('tiki-setup.php');
12

13 14
include_once('lib/directory/dirlib.php');

15
if ($prefs['feature_directory'] != 'y') {
16
	$smarty->assign('msg', tra("This feature is disabled").": feature_directory");
17

18
	$smarty->display("error.tpl");
19
	die;
20 21
}

22 23 24
if ($tiki_p_view_directory != 'y') {
	$smarty->assign('msg', tra("Permission denied"));

25
	$smarty->display("error.tpl");
26
	die;
27 28 29
}

// If no parent category then the parent category is 0
30 31 32 33 34 35 36 37 38 39
if (!isset($_REQUEST["parent"]))
	$_REQUEST["parent"] = 0;

$smarty->assign('parent', $_REQUEST["parent"]);
$all = 0;

if ($_REQUEST["parent"] == 0) {
	$parent_name = 'Top';

	$all = 1;
40
} else {
41
	$parent_info = $dirlib->dir_get_category($_REQUEST['parent']);
42
	$smarty->assign('parent_info', $parent_info);
43
	$parent_name = $parent_info['name'];
44
}
45 46 47

$smarty->assign('parent_name', $parent_name);
$smarty->assign('parent', $_REQUEST['parent']);
48
$smarty->assign('addtocat', $_REQUEST['parent']);
49 50 51 52 53

$dirlib->dir_add_category_hit($_REQUEST['parent']);

// Now get the path to the parent category
$path = $dirlib->dir_get_category_path_browse($_REQUEST["parent"]);
54
$smarty->assign_by_ref('path', $path);
55 56 57 58 59 60 61 62 63 64 65
$crumbs[] = new Breadcrumb('Directory',
                            '',
                            'tiki-directory_browse.php?parent=0',
                            'Directory+User',
                            'How to use Directory');
// Now append the path to the parent category
array_splice($crumbs, count($crumbs), 0, $dirlib->dir_build_breadcrumb_trail($_REQUEST["parent"]));
$smarty->assign('trail', $crumbs);     
$headtitle = breadcrumb_buildHeadTitle($crumbs);
$smarty->assign_by_ref('headtitle', $headtitle); 

66 67

// Now get the sub categories from this parent category
68
$categs = $dirlib->dir_list_categories($_REQUEST['parent'], 0, -1, 'name_asc', '');
69

70 71
$temp_max = count($categs['data']);
for ($i = 0; $i < $temp_max; $i++) {
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
	$categs['data'][$i]['subcats'] = array();

	if ($categs['data'][$i]['childrenType'] == 'c' && $categs['data'][$i]['viewableChildren'] > 0) {
		// Generate the subcategories with most hist as the subcategories to show.
		$subcats
			= $dirlib->dir_list_categories($categs['data'][$i]['categId'], 0, $categs['data'][$i]['viewableChildren'], 'hits_desc',
			'');

		$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.
		$categs['data'][$i]['subcats'] = array(array("name" => $categs['data'][$i]['description']));
	}

	if ($categs['data'][$i]['childrenType'] == 'r' && $categs['data'][$i]['viewableChildren'] > 0) {
		$categs['data'][$i]['subcats']
			= $dirlib->get_random_subcats($categs['data'][$i]['categId'], $categs['data'][$i]['viewableChildren']);
	}
92 93
}

94
$smarty->assign_by_ref('categs', $categs['data']);
95
$smarty->assign('cols', $prefs['directory_columns']);
96 97

// Now if needed get sites
98 99 100 101 102 103 104 105 106
$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');
	}
107 108
}

109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
if ($categ_info['allowSites'] == 'y') {
	if (!isset($_REQUEST["sort_mode"])) {
		$sort_mode = 'hits_desc';
	} else {
		$sort_mode = $_REQUEST["sort_mode"];
	}

	if (!isset($_REQUEST["offset"])) {
		$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);
131 132
	$items = $dirlib->dir_list_sites($_REQUEST['parent'], $offset, $prefs['directory_links_per_page'], $sort_mode, '', 'y');
	$cant_pages = ceil($items["cant"] / $prefs['directory_links_per_page']);
133
	$smarty->assign_by_ref('cant_pages', $cant_pages);
134
	$smarty->assign('actual_page', 1 + ($offset / $prefs['directory_links_per_page']));
135

136 137
	if ($items["cant"] > ($offset + $prefs['directory_links_per_page'])) {
		$smarty->assign('next_offset', $offset + $prefs['directory_links_per_page']);
138 139 140 141 142
	} else {
		$smarty->assign('next_offset', -1);
	}

	if ($offset > 0) {
143
		$smarty->assign('prev_offset', $offset - $prefs['directory_links_per_page']);
144 145 146 147 148
	} else {
		$smarty->assign('prev_offset', -1);
	}

	$smarty->assign_by_ref('items', $items["data"]);
149 150
}

151 152
include_once('tiki-section_options.php');

153
// Related categs
154
$related = $dirlib->dir_list_related_categories($_REQUEST['parent'], 0, -1, 'name_asc', '');
155
$smarty->assign_by_ref('related', $related['data']);
156 157

$stats = $dirlib->dir_stats();
158
$smarty->assign_by_ref('stats', $stats);
159
ask_ticket('dir-browse');
160

161
$smarty->assign('mid', 'tiki-directory_browse.tpl');
162
$smarty->display("tiki.tpl");
163

164
?>