tiki-directory_add_tiki_site.php 2.5 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.
changi67's avatar
changi67 committed
9 10
// $Id$

11
$section = 'directory';
rjsmelo's avatar
rjsmelo committed
12 13
require_once('tiki-setup.php');
include_once('lib/directory/dirlib.php');
14
$access->check_feature('feature_directory');
15
// Set parent category to 2 ("tiki sites")
16 17 18
$_REQUEST["parent"] = 2;
$smarty->assign('parent', $_REQUEST["parent"]);
$all = 0;
19 20
$parent_info = $dirlib->dir_get_category($_REQUEST['parent']);
$parent_name = $parent_info['name'];
21
$smarty->assign('parent_name', $parent_name);
22 23
// Now get the path to the parent category
$path = $dirlib->dir_get_category_path_admin($_REQUEST["parent"]);
24
$smarty->assign_by_ref('path', $path);
25
// If no site is being edited set it to zero
26 27
$_REQUEST["siteId"] = 0;
$smarty->assign('siteId', $_REQUEST["siteId"]);
28
if (empty($_REQUEST["name"])) {
29
	$smarty->assign('msg', tra("Must enter a name to add a site"));
changi67's avatar
changi67 committed
30
	$smarty->display("error.tpl");
31
	die;
32 33
}
if (empty($_REQUEST["url"])) {
34
	$smarty->assign('msg', tra("Must enter a url to add a site"));
changi67's avatar
changi67 committed
35
	$smarty->display("error.tpl");
36
	die;
37
}
38 39
if ((substr($_REQUEST["url"], 0, 7) <> 'http://') && (substr($_REQUEST["url"], 0, 8) <> 'https://')) {
	$_REQUEST["url"] = 'http://' . $_REQUEST["url"];
40
}
41 42
if ($dirlib->dir_url_exists($_REQUEST['url'])) {
	$smarty->assign('msg', tra("URL already added to the directory. Duplicate site?"));
changi67's avatar
changi67 committed
43
	$smarty->display("error.tpl");
44
	die;
45
}
46 47
if ($prefs['directory_validate_urls'] == 'y') {
	@$fsh = fopen($_REQUEST['url'], 'r');
rjsmelo's avatar
rjsmelo committed
48
	if (! $fsh) {
49
		$smarty->assign('msg', tra("URL cannot be accessed: wrong URL or site is offline and cannot be added to the directory"));
changi67's avatar
changi67 committed
50
		$smarty->display("error.tpl");
51 52
		die;
	}
53
}
54 55
$siteId = $dirlib->dir_replace_site($_REQUEST["siteId"], $_REQUEST["name"], $_REQUEST["description"], $_REQUEST["url"], $_REQUEST["country"], 'n');
$dirlib->dir_add_site_to_category($siteId, $_REQUEST["parent"]);
rjsmelo's avatar
rjsmelo committed
56
$info = [];
57 58 59 60 61 62
$info["name"] = $_REQUEST['name'];
$info["description"] = $_REQUEST['description'];
$info["url"] = $_REQUEST['url'];
$info["country"] = $_REQUEST['country'];
$info["isValid"] = 'n';
$smarty->assign_by_ref('info', $info);
63
$countries = $tikilib->get_flags();
64
$smarty->assign_by_ref('countries', $countries);
rjsmelo's avatar
rjsmelo committed
65
include_once('tiki-section_options.php');
66
$smarty->assign('save', 'y');
67
// Display the template
68
$smarty->assign('mid', 'tiki-register_site.tpl');
69
$smarty->display("tiki.tpl");