Project

General

Profile

1 1397 Luisehahne
<?php
2
/**
3
 *
4
 * @category        admin
5
 * @package         start
6 1804 Luisehahne
 * @author          Ryan Djurovich (2004-2009), WebsiteBaker Project
7 1711 Luisehahne
 * @copyright       2009-2012, WebsiteBaker Org. e.V.
8 1397 Luisehahne
 * @link			http://www.websitebaker2.org/
9
 * @license         http://www.gnu.org/licenses/gpl.html
10
 * @platform        WebsiteBaker 2.8.x
11
 * @requirements    PHP 5.2.2 and higher
12
 * @version         $Id$
13
 * @filesource		$HeadURL$
14
 * @lastmodified    $Date$
15
 *
16 1711 Luisehahne
 */
17
//$string = "pages,pages_view,pages_add,pages_add_l0,pages_settings,pages_modify,pages_intro,pages_delete,media,media_view,media_upload,media_rename,media_delete,media_create,addons,modules,modules_view,modules_install,modules_uninstall,templates,templates_view,templates_install,templates_uninstall,languages,languages_view,languages_install,languages_uninstall,settings,settings_basic,settings_advanced,access,users,users_view,users_add,users_modify,users_delete,groups,groups_view,groups_add,groups_modify,groups_delete,admintools
18
//media,media_create,media_upload,media_view,preferences,preferences_view,pages,pages_modify,pages_view";
19
//$regex = "/(pages)+[a-z]*[_]([a-z_0-9]+)[^,]/im";
20
//preg_match_all ($regex, $string, $output);
21
//
22 1804 Luisehahne
23
$config_file = realpath('../../config.php');
24
if(file_exists($config_file) && !defined('WB_URL'))
25
{
26
	require_once($config_file);
27
}
28
29
if(!class_exists('admin', false)){ include(WB_PATH.'/framework/class.admin.php'); }
30
31 1397 Luisehahne
$admin = new admin('Start','start');
32 1479 Luisehahne
// ---------------------------------------
33 1711 Luisehahne
//	$database = WbDatabase::getInstance();
34 1560 Luisehahne
35 1479 Luisehahne
if(defined('FINALIZE_SETUP')) {
36
	require_once(WB_PATH.'/framework/functions.php');
37
	$dirs = array( 'modules'   => WB_PATH.'/modules/',
38
	               'templates' => WB_PATH.'/templates/',
39
	               'languages' => WB_PATH.'/languages/'
40
	             );
41
	foreach($dirs AS $type => $dir) {
42
		if( ($handle = opendir($dir)) ) {
43
			while(false !== ($file = readdir($handle))) {
44
				if($file != '' AND substr($file, 0, 1) != '.' AND $file != 'admin.php' AND $file != 'index.php') {
45
					// Get addon type
46
					if($type == 'modules') {
47
						load_module($dir.'/'.$file, true);
48
						// Pretty ugly hack to let modules run $admin->set_error
49
						// See dummy class definition admin_dummy above
50
						if(isset($admin->error) && $admin->error != '') {
51
							$admin->print_error($admin->error);
52
						}
53
					} elseif($type == 'templates') {
54
						load_template($dir.'/'.$file);
55
					} elseif($type == 'languages') {
56
						load_language($dir.'/'.$file);
57
					}
58
				}
59
			}
60
		closedir($handle);
61
		}
62
	}
63
	$sql = 'DELETE FROM `'.TABLE_PREFIX.'settings` WHERE `name`=\'FINALIZE_SETUP\'';
64 1560 Luisehahne
	if($database->query($sql)) { }
65 1479 Luisehahne
}
66
// ---------------------------------------
67 1560 Luisehahne
// check if it is neccessary to start the uograde-script
68 1778 Luisehahne
$msg  = '';
69
$msg .= (is_readable(WB_PATH.'/install/')) ?  $MESSAGE['START_INSTALL_DIR_EXISTS'].'<br />' : $msg;
70
$msg .= (is_readable(WB_PATH.'/upgrade-script.php')) ?  $MESSAGE['START_UPGRADE_SCRIPT_EXISTS'].'<br />' : '';
71
//$msg .= ''.$MESSAGE['START_UPGRADE_SCRIPT_EXISTS'].'<br />';
72 1711 Luisehahne
73
// ---------------------------------------
74
// check if it is neccessary to start the uograde-script
75
// ---------------------------------------
76 1562 Luisehahne
if(($admin->get_user_id()==1) && file_exists(WB_PATH.'/upgrade-script.php')) {
77 1561 Luisehahne
	// check if it is neccessary to start the uograde-script
78
	$sql = 'SELECT `value` FROM `'.TABLE_PREFIX.'settings` WHERE `name`=\'wb_revision\'';
79
	if($wb_revision=$database->get_one($sql)) {
80 1589 Luisehahne
	}
81
	if (version_compare($wb_revision, REVISION ) < 0) {
82
		if(!headers_sent()) {
83
			header('Location: '.WB_URL.'/upgrade-script.php');
84
		    exit;
85 1562 Luisehahne
		} else {
86 1589 Luisehahne
		    echo "<p style=\"text-align:center;\"> The <strong>upgrade script</strong> could not be start automatically.\n" .
87
		         "Please click <a style=\"font-weight:bold;\" " .
88
		         "href=\"".WB_URL."/upgrade-script.php\">on this link</a> to start the script!</p>\n";
89
		    exit;
90 1560 Luisehahne
		}
91
	}
92
}
93 1711 Luisehahne
// ---------------------------------------
94
// workout to upgrade the groups system_permissions
95
// ---------------------------------------
96
if( ($admin->get_user_id()==1) &&
97 1770 Luisehahne
	file_exists(ADMIN_PATH.'/groups/upgradePermissions.php') && !defined('GROUPS_UPDATED') )
98 1711 Luisehahne
{
99
	// check if it is neccessary to start the uograde-script
100
	$sql = 'SELECT `value` FROM `'.TABLE_PREFIX.'settings` WHERE `name`=\'wb_revision\'';
101
	if($wb_revision = $database->get_one($sql)) {
102 1560 Luisehahne
103 1711 Luisehahne
	}
104 1727 Luisehahne
105
	if ((version_compare($wb_revision, '1800' )  < 0)&& !defined('GROUPS_UPDATED')) {
106 1711 Luisehahne
		require_once (ADMIN_PATH.'/groups/upgradePermissions.php');
107
		// build new or changed $sTempPermissions
108
		if(upgrade_group_system_permissions()){
109
			$cfg = array(
110
				'groups_updated' => time()
111
			);
112
			if(db_update_key_value( 'settings', $cfg )) {
113
			    echo "<div class=\"note center rounded\"><h3>Hello Systemadministrator!</h3>".
114
				     "<p style=\"text-align:center;\">".
115
				     "The <strong>Administrator Groups Rights </strong> were updated automatically.\n" .
116
			         "Please click <a style=\"font-weight:bold;\" " .
117
			         "href=\"".ADMIN_URL."/logout/index.php\">on this link</a> to login again!</p>\n".
118
			         "<h3>Upgrading only start, if groups rights are not up to date!</h3></div>";
119
				// Print admin footer
120
				$admin->print_footer();
121
			    exit(0);
122
123
			}
124
		}
125
	}
126
}
127
128 1804 Luisehahne
/**
129
 * delete Outdated Confirmations
130
 */
131
$sql = 'DELETE FROM `'.TABLE_PREFIX.'users` WHERE `confirm_timeout` BETWEEN 1 AND '.time();
132
WbDatabase::getInstance()->query($sql);
133
134 1809 Luisehahne
/**
135
 * delete Outdated Confirmations
136
 */
137
$sql = 'UPDATE `'.TABLE_PREFIX.'users` SET `login_ip` = \'\' WHERE `login_when` < '.(time()-(60*84600));
138
WbDatabase::getInstance()->query($sql);
139
140 1711 Luisehahne
// ---------------------------------------
141 1529 Luisehahne
// Setup template object, parse vars to it, then parse it
142
// Create new template object
143 1711 Luisehahne
$oTpl = new Template(dirname($admin->correct_theme_source('start.htt')),'keep');
144
$oTpl->set_file('page', 'start.htt');
145
$oTpl->set_block('page', 'main_block', 'main');
146 1397 Luisehahne
147
// Insert values into the template object
148 1711 Luisehahne
$oTpl->set_var(array(
149
					'WELCOME_MESSAGE' => $MESSAGE['START_WELCOME_MESSAGE'],
150
					'CURRENT_USER' => $MESSAGE['START_CURRENT_USER'],
151 1457 Luisehahne
					'DISPLAY_NAME' => $admin->get_display_name(),
152 1777 Luisehahne
                    'DISPLAY_WARNING' => '',
153 1778 Luisehahne
                    'WARNING' => '',
154 1457 Luisehahne
					'ADMIN_URL' => ADMIN_URL,
155
					'WB_URL' => WB_URL,
156
					'THEME_URL' => THEME_URL,
157 1711 Luisehahne
					'WB_VERSION' => WB_VERSION,
158
					'NO_CONTENT' => ''
159 1457 Luisehahne
				)
160
			);
161 1397 Luisehahne
162
// Insert permission values into the template object
163 1711 Luisehahne
$oTpl->set_block('main_block', 'show_pages_block', 'show_pages');
164 1397 Luisehahne
if($admin->get_permission('pages') != true)
165
{
166 1711 Luisehahne
	$oTpl->set_block('show_pages', '');
167
} else {
168
	$oTpl->parse('show_pages', 'show_pages_block', true);
169 1397 Luisehahne
}
170 1711 Luisehahne
171
$oTpl->set_block('main_block', 'show_addons_block', 'show_addons');
172
if($admin->get_permission('addons') != true)
173
{
174
	$oTpl->set_block('show_addons', '');
175
} else {
176
	$oTpl->parse('show_addons', 'show_addons_block', true);
177
}
178
179
$oTpl->set_block('main_block', 'show_settings_block', 'show_settings');
180
if($admin->get_permission('settings') != true)
181
{
182
	$oTpl->set_block('show_settings', '');
183
} else {
184
	$oTpl->parse('show_settings', 'show_settings_block', true);
185
}
186
187
$oTpl->set_block('main_block', 'show_access_block', 'show_access');
188
if($admin->get_permission('access') != true)
189
{
190
	$oTpl->set_block('show_access', '');
191
} else {
192
	$oTpl->parse('show_access', 'show_access_block', true);
193
}
194
195
$oTpl->set_block('main_block', 'show_media_block', 'show_media');
196 1397 Luisehahne
if($admin->get_permission('media') != true)
197
{
198 1711 Luisehahne
	$oTpl->set_block('show_media', '');
199
} else {
200
	$oTpl->parse('show_media', 'show_media_block', true);
201 1397 Luisehahne
}
202 1711 Luisehahne
203
$oTpl->set_block('main_block', 'show_admintools_block', 'show_admintools');
204
if($admin->get_permission('admintools') != true)
205
{
206
	$oTpl->set_block('show_admintools', '');
207
} else {
208
	$oTpl->parse('show_admintools', 'show_admintools_block', true);
209
}
210
211
$oTpl->set_block('main_block', 'show_preferences_block', 'show_preferences');
212
if($admin->get_permission('preferences') != true)
213
{
214
	$oTpl->set_block('show_preferences', '');
215
} else {
216
	$oTpl->parse('show_preferences', 'show_preferences_block', true);
217
}
218
219
220
/*
221
if($admin->get_permission('pages') != true)
222
{
223
	$oTpl->set_var('DISPLAY_PAGES', 'display:none;');
224
}
225
if($admin->get_permission('media') != true)
226
{
227
	$oTpl->set_var('DISPLAY_MEDIA', 'display:none;');
228
}
229 1397 Luisehahne
if($admin->get_permission('addons') != true)
230
{
231 1711 Luisehahne
	$oTpl->set_var('DISPLAY_ADDONS', 'display:none;');
232 1397 Luisehahne
}
233
if($admin->get_permission('access') != true)
234
{
235 1711 Luisehahne
	$oTpl->set_var('DISPLAY_ACCESS', 'display:none;');
236 1397 Luisehahne
}
237
if($admin->get_permission('settings') != true)
238
{
239 1711 Luisehahne
	$oTpl->set_var('DISPLAY_SETTINGS', 'display:none;');
240 1397 Luisehahne
}
241
if($admin->get_permission('admintools') != true)
242
{
243 1711 Luisehahne
	$oTpl->set_var('DISPLAY_ADMINTOOLS', 'display:none;');
244 1397 Luisehahne
}
245 1711 Luisehahne
*/
246 1397 Luisehahne
247 1414 Luisehahne
248 1778 Luisehahne
$oTpl->set_block('main_block', 'show_install_block', 'show_install');
249
if($admin->get_user_id() != 1)
250
{
251
	$oTpl->parse('show_install', '');
252 1397 Luisehahne
} else {
253 1778 Luisehahne
254
    // Check if installation directory still exists
255
    if(file_exists(WB_PATH.'/install/') || file_exists(WB_PATH.'/upgrade-script.php') ) {
256
    	// Check if user is part of Adminstrators group
257
    	if($admin->get_user_id()==1)
258
        {
259
    		$oTpl->set_var('WARNING', $msg );
260
    	} else {
261
    		$oTpl->set_var('DISPLAY_WARNING', 'display:none;');
262
    	}
263
    } else {
264
    	$oTpl->set_var('DISPLAY_WARNING', 'display:none;');
265
    }
266
267
	$oTpl->parse('show_install', 'show_install_block', true);
268 1397 Luisehahne
}
269
270
// Insert "Add-ons" section overview (pretty complex compared to normal)
271
$addons_overview = $TEXT['MANAGE'].' ';
272
$addons_count = 0;
273
if($admin->get_permission('modules') == true)
274
{
275
	$addons_overview .= '<a href="'.ADMIN_URL.'/modules/index.php">'.$MENU['MODULES'].'</a>';
276
	$addons_count = 1;
277
}
278
if($admin->get_permission('templates') == true)
279
{
280
	if($addons_count == 1) { $addons_overview .= ', '; }
281
	$addons_overview .= '<a href="'.ADMIN_URL.'/templates/index.php">'.$MENU['TEMPLATES'].'</a>';
282
	$addons_count = 1;
283
}
284
if($admin->get_permission('languages') == true)
285
{
286
	if($addons_count == 1) { $addons_overview .= ', '; }
287
	$addons_overview .= '<a href="'.ADMIN_URL.'/languages/index.php">'.$MENU['LANGUAGES'].'</a>';
288
}
289
290
// Insert "Access" section overview (pretty complex compared to normal)
291
$access_overview = $TEXT['MANAGE'].' ';
292
$access_count = 0;
293
if($admin->get_permission('users') == true) {
294
	$access_overview .= '<a href="'.ADMIN_URL.'/users/index.php">'.$MENU['USERS'].'</a>';
295
	$access_count = 1;
296
}
297
if($admin->get_permission('groups') == true) {
298
	if($access_count == 1) { $access_overview .= ', '; }
299
	$access_overview .= '<a href="'.ADMIN_URL.'/groups/index.php">'.$MENU['GROUPS'].'</a>';
300
	$access_count = 1;
301
}
302
303
// Insert section names and descriptions
304 1711 Luisehahne
$oTpl->set_var(array(
305 1457 Luisehahne
					'PAGES' => $MENU['PAGES'],
306
					'MEDIA' => $MENU['MEDIA'],
307
					'ADDONS' => $MENU['ADDONS'],
308
					'ACCESS' => $MENU['ACCESS'],
309
					'PREFERENCES' => $MENU['PREFERENCES'],
310
					'SETTINGS' => $MENU['SETTINGS'],
311
					'ADMINTOOLS' => $MENU['ADMINTOOLS'],
312
					'HOME_OVERVIEW' => $OVERVIEW['START'],
313
					'PAGES_OVERVIEW' => $OVERVIEW['PAGES'],
314
					'MEDIA_OVERVIEW' => $OVERVIEW['MEDIA'],
315
					'ADDONS_OVERVIEW' => $addons_overview,
316
					'ACCESS_OVERVIEW' => $access_overview,
317
					'PREFERENCES_OVERVIEW' => $OVERVIEW['PREFERENCES'],
318
					'SETTINGS_OVERVIEW' => $OVERVIEW['SETTINGS'],
319
					'ADMINTOOLS_OVERVIEW' => $OVERVIEW['ADMINTOOLS']
320
				)
321
			);
322 1397 Luisehahne
323
// Parse template object
324 1711 Luisehahne
$oTpl->parse('main', 'main_block', false);
325
$oTpl->pparse('output', 'page');
326 1397 Luisehahne
327
// Print admin footer
328
$admin->print_footer();