|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* PHPPgAdmin v6.0.0-beta.43 |
|
5
|
|
|
*/ |
|
6
|
|
|
|
|
7
|
|
|
namespace PHPPgAdmin; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* @file |
|
11
|
|
|
* A class that adds convenience methods to the container |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* A class that adds convenience methods to the container. |
|
16
|
|
|
* |
|
17
|
|
|
* @package PHPPgAdmin |
|
18
|
|
|
*/ |
|
19
|
|
|
class ContainerUtils |
|
20
|
|
|
{ |
|
21
|
|
|
use \PHPPgAdmin\Traits\HelperTrait; |
|
|
|
|
|
|
22
|
|
|
|
|
23
|
|
|
private $container; |
|
|
|
|
|
|
24
|
|
|
|
|
25
|
|
|
public function __construct($container) |
|
26
|
|
|
{ |
|
27
|
|
|
$this->container = $container; |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
public function getRedirectUrl($subject = '') |
|
|
|
|
|
|
31
|
|
|
{ |
|
32
|
|
|
$query_string = $this->container->requestobj->getUri()->getQuery(); |
|
33
|
|
|
|
|
34
|
|
|
// but if server_id isn't set, then you will be redirected to intro |
|
35
|
|
|
if ($this->container->requestobj->getQueryParam('server') === null) { |
|
36
|
|
|
$destinationurl = \SUBFOLDER . '/src/views/intro'; |
|
37
|
|
|
} else { |
|
38
|
|
|
$destinationurl = \SUBFOLDER . '/src/views/login' . ($query_string ? '?' . $query_string : ''); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
return $destinationurl; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function getDestinationWithLastTab($subject) |
|
45
|
|
|
{ |
|
46
|
|
|
$_server_info = $this->container->misc->getServerInfo(); |
|
47
|
|
|
//$this->prtrace('$_server_info', $_server_info); |
|
48
|
|
|
// If username isn't set in server_info, you should login |
|
49
|
|
|
if (!isset($_server_info['username'])) { |
|
50
|
|
|
$destinationurl = $this->getRedirectUrl(); |
|
51
|
|
|
} else { |
|
52
|
|
|
$url = $this->container->misc->getLastTabURL($subject); |
|
53
|
|
|
//$this->prtrace('getLastTabURL for ' . $subject, $url); |
|
54
|
|
|
// Load query vars into superglobal arrays |
|
55
|
|
|
if (isset($url['urlvars'])) { |
|
56
|
|
|
$urlvars = []; |
|
57
|
|
|
foreach ($url['urlvars'] as $key => $urlvar) { |
|
58
|
|
|
//$this->prtrace($key, $urlvar); |
|
59
|
|
|
$urlvars[$key] = \PHPPgAdmin\Decorators\Decorator::get_sanitized_value($urlvar, $_REQUEST); |
|
60
|
|
|
} |
|
61
|
|
|
$_REQUEST = array_merge($_REQUEST, $urlvars); |
|
62
|
|
|
$_GET = array_merge($_GET, $urlvars); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
$actionurl = \PHPPgAdmin\Decorators\Decorator::actionurl($url['url'], $_GET); |
|
66
|
|
|
$destinationurl = $actionurl->value($_GET); |
|
67
|
|
|
} |
|
68
|
|
|
$destinationurl = str_replace('views/?', "views/{$subject}?", $destinationurl); |
|
69
|
|
|
//$this->prtrace('destinationurl for ' . $subject, $destinationurl); |
|
70
|
|
|
return $destinationurl; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
public function addError($errormsg) |
|
74
|
|
|
{ |
|
75
|
|
|
$errors = $this->container->get('errors'); |
|
76
|
|
|
$errors[] = $errormsg; |
|
77
|
|
|
$this->container->offsetSet('errors', $errors); |
|
78
|
|
|
|
|
79
|
|
|
return $this->container; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
} |
|
83
|
|
|
|