tiki-module_controls.php 2.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

rjsmelo's avatar
rjsmelo committed
11
require_once('tiki-setup.php');
12 13 14
$usermoduleslib = TikiLib::lib('usermodules');
$smarty = TikiLib::lib('smarty');
global $tiki_p_configure_modules, $prefs, $user;
changi67's avatar
changi67 committed
15
$check_req = (isset($_REQUEST["mc_unassign"]) || isset($_REQUEST["mc_up"]) || isset($_REQUEST["mc_down"]) || isset($_REQUEST["mc_move"]));
16
if ($tiki_p_configure_modules != 'y' && $check_req) {
17
	$smarty->assign('errortype', 401);
18
	$smarty->assign('msg', tra("You do not have permission to use this feature"));
19
	$smarty->display("error.tpl");
20
	die;
21
}
22
if ($prefs['user_assigned_modules'] != 'y' && $check_req) {
changi67's avatar
changi67 committed
23
	$smarty->assign('msg', tra("This feature is disabled") . ": user_assigned_modules");
24
	$smarty->display("error.tpl");
25
	die;
26
}
rjsmelo's avatar
rjsmelo committed
27
if (! $user && $check_req) {
28
	$smarty->assign('msg', tra("You must log in to use this feature"));
29
	$smarty->display("error.tpl");
30
	die;
31
}
32
$request_uri = $url = isset($_SERVER["REQUEST_URI"]) ? $_SERVER['REQUEST_URI'] : '';
33
if ($check_req) {
changi67's avatar
changi67 committed
34 35 36
	//    global $debugger;
	//    $debugger->msg('Module control clicked: '.$check_req);
	// Make defaults if user still ot configure modules for himself
rjsmelo's avatar
rjsmelo committed
37 38 39
	if (! $usermoduleslib->user_has_assigned_modules($user)) {
		$usermoduleslib->create_user_assigned_modules($user);
	}
changi67's avatar
changi67 committed
40
	// Handle control icon click
rjsmelo's avatar
rjsmelo committed
41 42 43 44 45 46 47 48 49
	if (isset($_REQUEST["mc_up"])) {
		$usermoduleslib->swap_up_user_module($_REQUEST["mc_up"], $user);
	} elseif (isset($_REQUEST["mc_down"])) {
		$usermoduleslib->swap_down_user_module($_REQUEST["mc_down"], $user);
	} elseif (isset($_REQUEST["mc_move"])) {
		$usermoduleslib->move_module($_REQUEST["mc_move"], $user);
	} else {
		$usermoduleslib->unassign_user_module($_REQUEST["mc_unassign"], $user);
	}
changi67's avatar
changi67 committed
50 51 52 53
	// Remove module movemet paramaters from an URL
	// \todo What if 'mc_xxx' arg was not at the end? (if smbd fix URL by hands...)
	//       should I handle this very special (hack?) case?
	$url = preg_replace('/(.*)(\?|&){1}(mc_up|mc_down|mc_move|mc_unassign)=[^&]*/', '\1', $url);
54
}
55
// Fix locaton if parameter was removed...
56 57 58 59
if ($url != $request_uri) {
	$access = TikiLib::lib('access');
	$access->redirect($url);
}
60
$smarty->assign('current_location', $url);
61
$smarty->assign('mpchar', (strpos($url, '?') ? '&' : '?'));