tiki-directory_admin_sites.php 4.76 KB
Newer Older
1
<?php
2
// (c) Copyright 2002-2013 by authors of the Tiki Wiki CMS Groupware Project
3
// 
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.
6
// $Id$
changi67's avatar
changi67 committed
7

8 9
require_once ('tiki-setup.php');
include_once ('lib/directory/dirlib.php');
10 11
$access->check_feature('feature_directory');

12
// If no parent category then the parent category is 0
13
if (!isset($_REQUEST["parent"])) $_REQUEST["parent"] = 0;
14 15 16 17 18
$smarty->assign('parent', $_REQUEST["parent"]);
$all = 0;
if ($_REQUEST["parent"] == 0) {
	$parent_name = 'Top';
	$all = 1;
19
} else {
20 21
	$parent_info = $dirlib->dir_get_category($_REQUEST['parent']);
	$parent_name = $parent_info['name'];
22
}
23 24 25 26 27 28
$smarty->assign('parent_name', $parent_name);
if (isset($parent_info) && $user) {
	if (in_array($parent_info['editorGroup'], $userlib->get_user_groups($user))) {
		$tiki_p_admin_directory_sites = 'y';
		$smarty->assign('tiki_p_admin_directory_sites', 'y');
	}
29
}
30
$access->check_permission('tiki_p_admin_directory_sites');
31 32
// Now get the path to the parent category
$path = $dirlib->dir_get_category_path_admin($_REQUEST["parent"]);
33
$smarty->assign_by_ref('path', $path);
34
// If no site is being edited set it to zero
35
if (!isset($_REQUEST["siteId"])) $_REQUEST["siteId"] = 0;
36
$smarty->assign('siteId', $_REQUEST["siteId"]);
37 38
// If we are editing an existing category then get the category information
// If not initialize the information to zero
39 40
if ($_REQUEST["siteId"]) {
	$info = $dirlib->dir_get_site($_REQUEST["siteId"]);
41
} else {
42 43 44 45 46 47
	$info = array();
	$info["name"] = '';
	$info["description"] = '';
	$info["url"] = '';
	$info["country"] = 'None';
	$info["isValid"] = 'y';
48
}
49
$smarty->assign_by_ref('info', $info);
50
// Remove a category
51
if (isset($_REQUEST["remove"])) {
52 53
	if (is_array($_REQUEST["remove"])) {
		check_ticket('dir-admin-sites');
54
		foreach ($_REQUEST["remove"] as $remid) {
55 56 57
			$dirlib->dir_remove_site($remid);
		}
	} else {
58 59
		$access->check_authenticity();
		$dirlib->dir_remove_site($_REQUEST["remove"]);
60
	}
61 62
}
// Replace (add or edit) a category
63
if (isset($_REQUEST["save"])) {
64
	check_ticket('dir-admin-sites');
65
	if (empty($_REQUEST["name"])) {
66
		$smarty->assign('msg', tra("Must enter a name to add a site"));
67
		$smarty->display("error.tpl");
68 69 70 71
		die;
	}
	if (empty($_REQUEST["url"])) {
		$smarty->assign('msg', tra("Must enter a url to add a site"));
72
		$smarty->display("error.tpl");
73 74
		die;
	}
75
	if ((substr($_REQUEST["url"], 0, 7) <> 'http://') && (substr($_REQUEST["url"], 0, 8) <> 'https://') && (substr($_REQUEST["url"], 0, 6) <> 'ftp://')) {
76 77 78 79
		$_REQUEST["url"] = 'http://' . $_REQUEST["url"];
	}
	if (!isset($_REQUEST["siteCats"]) || count($_REQUEST["siteCats"]) == 0) {
		$smarty->assign('msg', tra("Must select a category"));
80
		$smarty->display("error.tpl");
81 82
		die;
	}
83 84 85
	if (isset($_REQUEST["isValid"]) && $_REQUEST["isValid"] == 'on') $_REQUEST["isValid"] = 'y';
	else $_REQUEST["isValid"] = 'n';
	$siteId = $dirlib->dir_replace_site($_REQUEST["siteId"], $_REQUEST["name"], $_REQUEST["description"], $_REQUEST["url"], $_REQUEST["country"], $_REQUEST["isValid"]);
86
	$dirlib->remove_site_from_categories($siteId);
87
	foreach ($_REQUEST["siteCats"] as $acat) {
88 89 90 91 92 93 94 95 96
		$dirlib->dir_add_site_to_category($siteId, $acat);
	}
	$info = array();
	$info["name"] = '';
	$info["description"] = '';
	$info["url"] = '';
	$info["country"] = 'United_States';
	$info["isValid"] = 'y';
	$smarty->assign('siteId', 0);
97 98 99
}
// Listing: categories in the parent category
// Pagination resolution
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
if (!isset($_REQUEST["sort_mode"])) {
	$sort_mode = 'created_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);
118
// What are we paginating: items
119 120
if ($all) {
	$items = $dirlib->dir_list_all_sites($offset, $maxRecords, $sort_mode, $find);
121
} else {
122
	$items = $dirlib->dir_list_sites($_REQUEST["parent"], $offset, $maxRecords, $sort_mode, $find, $isValid = '');
123
}
124
$smarty->assign_by_ref('cant_pages', $items["cant"]);
125
$smarty->assign_by_ref('items', $items["data"]);
126
$categs = $dirlib->dir_get_all_categories_accept_sites(0, -1, 'name asc', $find, $_REQUEST["siteId"]);
127
$smarty->assign('categs', $categs);
128
$countries = $tikilib->get_flags();
129
$smarty->assign_by_ref('countries', $countries);
130
// This page should be displayed with Directory section options
131 132
$section = 'directory';
include_once ('tiki-section_options.php');
133
ask_ticket('dir-admin-sites');
134 135
// disallow robots to index page:
$smarty->assign('metatag_robots', 'NOINDEX, NOFOLLOW');
136
// Display the template
137
$smarty->assign('mid', 'tiki-directory_admin_sites.tpl');
138
$smarty->display("tiki.tpl");