Issues (4868)

1
<?php
2
/**
3
 * EGroupware index page
4
 *
5
 * Starts all Egw\Applications using $_GET[menuaction]
6
 *
7
 * @link http://www.egroupware.org
8
 * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
9
 * @package api
10
 * @version $Id$
11
 */
12
13
use EGroupware\Api;
14
use EGroupware\Api\Framework;
15
use EGroupware\Api\Egw;
16
17
// support of Mac or iPhone trying to autodetect CalDAV or CardDAV support
18
// if EGroupware is not installed in the docroot, you need either this code in the index.php there,
19
// or an uncoditional redirect to this file or copy groupdav.htaccess to your docroot as .htaccess
20
if ($_SERVER['REQUEST_METHOD'] == 'PROPFIND' || $_SERVER['REQUEST_METHOD'] == 'OPTIONS')
21
{
22
        header('Location: groupdav.php/');
23
        exit;
24
}
25
26
// forward for not existing or empty header to setup
27
if(!file_exists('header.inc.php') || !filesize('header.inc.php'))
28
{
29
	Header('Location: setup/index.php');
30
	exit;
31
}
32
33
if(isset($_GET['hasupdates']) && $_GET['hasupdates'] == 'yes')
34
{
35
	$hasupdates = True;
36
}
37
38
/*
39
	This is the menuaction driver for the multi-layered design
40
*/
41
if(isset($_GET['menuaction']) && preg_match('/^[A-Za-z0-9_]+\.[A-Za-z0-9_\\\\]+\.[A-Za-z0-9_]+$/',$_GET['menuaction']))
42
{
43
	list($app,$class,$method) = explode('.',$_GET['menuaction']);
44
45
	// check if autoloadable class belongs to given app
46
	if (substr($class, 0, 11) == 'EGroupware\\')
47
	{
48
		list(,$app_from_class) = explode('\\', strtolower($class));
49
	}
50
	elseif(strpos($class, '_') !== false)
51
	{
52
		list($app_from_class) = explode('_', $class);
53
	}
54
	if(!$app || !$class || !$method || isset($app_from_class) &&
55
		isset($GLOBALS['egw_info']['apps'][$app_from_class]) && $app_from_class != $app)
56
	{
57
		$invalid_data = True;
58
	}
59
}
60
else
61
{
62
	$app = 'api';
63
	$invalid_data = True;
64
}
65
//error_log(__METHOD__."$app,$class,$method");
66
if($app == 'phpgwapi')
67
{
68
	$app = 'api';
69
	$api_requested = True;
70
}
71
72
$GLOBALS['egw_info'] = array(
73
	'flags' => array(
74
		'noheader'   => True,
75
		'nonavbar'   => True,
76
		'currentapp' => $app
77
	)
78
);
79
include('./header.inc.php');
80
81
// user changed timezone
82
if (isset($_GET['tz']))
83
{
84
	Api\DateTime::setUserPrefs($_GET['tz']);	// throws exception, if tz is invalid
85
86
	$GLOBALS['egw']->preferences->add('common','tz',$_GET['tz']);
87
	$GLOBALS['egw']->preferences->save_repository();
88
89
	if (($referer = Api\Header\Referer::get()))
90
	{
91
		Egw::redirect_link($referer);
92
	}
93
}
94
95
// 	Check if we are using windows or normal webpage
96
$windowed = false;
97
$tpl_info = EGW_SERVER_ROOT . '/phpgwapi/templates/' . basename($GLOBALS['egw_info']['user']['preferences']['common']['template_set']) . '/setup/setup.inc.php';
98
if (!file_exists($tpl_info))
99
{
100
	$tpl_info = EGW_SERVER_ROOT.'/'.basename($GLOBALS['egw_info']['user']['preferences']['common']['template_set']) . '/setup/setup.inc.php';
101
}
102
if(@file_exists($tpl_info))
103
{
104
	include_once($tpl_info);
105
	if($GLOBALS['egw_info']['template'][$GLOBALS['egw_info']['user']['preferences']['common']['template_set']]['windowed'])
106
	{
107
		$windowed = true;
108
	}
109
}
110
111
112
if($app == 'api' && !$class && !$api_requested && !($windowed && $_GET['cd'] == 'yes' && !Api\Header\UserAgent::mobile()) && $GLOBALS['egw_info']['user']['preferences']['common']['template_set'] == 'idots')
113
{
114
	if ($GLOBALS['egw_info']['server']['force_default_app'] && $GLOBALS['egw_info']['server']['force_default_app'] != 'user_choice')
115
	{
116
		$GLOBALS['egw_info']['user']['preferences']['common']['default_app'] = $GLOBALS['egw_info']['server']['force_default_app'];
117
	}
118
	if($GLOBALS['egw_info']['user']['preferences']['common']['default_app'] && !$hasupdates)
119
	{
120
		Egw::redirect(Framework::index($GLOBALS['egw_info']['user']['preferences']['common']['default_app']),$GLOBALS['egw_info']['user']['preferences']['common']['default_app']);
121
	}
122
	else
123
	{
124
		Egw::redirect_link('/home/index.php?cd=yes');
125
	}
126
}
127
128
if($windowed && $_GET['cd'] == 'yes')
129
{
130
	$GLOBALS['egw_info']['flags'] = array(
131
		'noheader'   => False,
132
		'nonavbar'   => False,
133
		'currentapp' => 'eGroupWare'
134
	);
135
	echo $GLOBALS['egw']->framework->header();
136
	echo $GLOBALS['egw']->framework->footer();
137
}
138
else
139
{
140
	if($api_requested)
141
	{
142
		$app = 'phpgwapi';
143
	}
144
145
	if (class_exists($class))
146
	{
147
		$obj = new $class;
148
	}
149
	else
150
	{
151
		$obj = CreateObject($app.'.'.$class);
0 ignored issues
show
Deprecated Code introduced by
The function CreateObject() has been deprecated: use autoloadable class-names and new ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

151
		$obj = /** @scrutinizer ignore-deprecated */ CreateObject($app.'.'.$class);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
152
	}
153
	if((is_array($obj->public_functions) && $obj->public_functions[$method]) && !$invalid_data)
154
	{
155
		$obj->$method();
156
		unset($app);
157
		unset($class);
158
		unset($method);
159
		unset($invalid_data);
160
		unset($api_requested);
161
	}
162
	else
163
	{
164
		if(!$app || !$class || !$method || $invalid_data)
165
		{
166
			if(@is_object($GLOBALS['egw']->log))
167
			{
168
				$GLOBALS['egw']->log->message(array(
169
					'text' => 'W-BadmenuactionVariable, menuaction missing or corrupt: %1',
170
					'p1'   => $menuaction,
171
					'line' => __LINE__,
172
					'file' => __FILE__
173
				));
174
			}
175
		}
176
177
		if(!is_array($GLOBALS[$class]->public_functions) || !$GLOBALS[$class]->public_functions[$method] && $method)
178
		{
179
			if(@is_object($GLOBALS['egw']->log))
180
			{
181
				$GLOBALS['egw']->log->message(array(
182
					'text' => 'W-BadmenuactionVariable, attempted to access private method: %1',
183
					'p1'   => $method,
184
					'line' => __LINE__,
185
					'file' => __FILE__
186
				));
187
			}
188
		}
189
		if(@is_object($GLOBALS['egw']->log))
190
		{
191
			$GLOBALS['egw']->log->commit();
192
		}
193
194
		$GLOBALS['egw']->redirect_link('/home/index.php');
195
	}
196
197
	if(!isset($GLOBALS['egw_info']['nofooter']))
198
	{
199
		echo $GLOBALS['egw']->framework->footer();
200
	}
201
}
202