Project

General

Profile

1
<?php
2
/**
3
 *
4
 * @category        admin
5
 * @package         start
6
 * @author          Ryan Djurovich (2004-2009), WebsiteBaker Project
7
 * @copyright       2009-2012, WebsiteBaker Org. e.V.
8
 * @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: index.php 1809 2012-11-07 11:19:12Z Luisehahne $
13
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/admin/start/index.php $
14
 * @lastmodified    $Date: 2012-11-07 12:19:12 +0100 (Wed, 07 Nov 2012) $
15
 *
16
 */
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

    
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
$admin = new admin('Start','start');
32
// ---------------------------------------
33
//	$database = WbDatabase::getInstance();
34

    
35
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
	if($database->query($sql)) { }
65
}
66
// ---------------------------------------
67
// check if it is neccessary to start the uograde-script
68
$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

    
73
// ---------------------------------------
74
// check if it is neccessary to start the uograde-script
75
// ---------------------------------------
76
if(($admin->get_user_id()==1) && file_exists(WB_PATH.'/upgrade-script.php')) {
77
	// 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
	}
81
	if (version_compare($wb_revision, REVISION ) < 0) {
82
		if(!headers_sent()) {
83
			header('Location: '.WB_URL.'/upgrade-script.php');
84
		    exit;
85
		} else {
86
		    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
		}
91
	}
92
}
93
// ---------------------------------------
94
// workout to upgrade the groups system_permissions
95
// ---------------------------------------
96
if( ($admin->get_user_id()==1) &&
97
	file_exists(ADMIN_PATH.'/groups/upgradePermissions.php') && !defined('GROUPS_UPDATED') )
98
{
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

    
103
	}
104

    
105
	if ((version_compare($wb_revision, '1800' )  < 0)&& !defined('GROUPS_UPDATED')) {
106
		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
/**
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
/**
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
// ---------------------------------------
141
// Setup template object, parse vars to it, then parse it
142
// Create new template object
143
$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

    
147
// Insert values into the template object
148
$oTpl->set_var(array(
149
					'WELCOME_MESSAGE' => $MESSAGE['START_WELCOME_MESSAGE'],
150
					'CURRENT_USER' => $MESSAGE['START_CURRENT_USER'],
151
					'DISPLAY_NAME' => $admin->get_display_name(),
152
                    'DISPLAY_WARNING' => '',
153
                    'WARNING' => '',
154
					'ADMIN_URL' => ADMIN_URL,
155
					'WB_URL' => WB_URL,
156
					'THEME_URL' => THEME_URL,
157
					'WB_VERSION' => WB_VERSION,
158
					'NO_CONTENT' => ''
159
				)
160
			);
161

    
162
// Insert permission values into the template object
163
$oTpl->set_block('main_block', 'show_pages_block', 'show_pages');
164
if($admin->get_permission('pages') != true)
165
{
166
	$oTpl->set_block('show_pages', '');
167
} else {
168
	$oTpl->parse('show_pages', 'show_pages_block', true);
169
}
170

    
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
if($admin->get_permission('media') != true)
197
{
198
	$oTpl->set_block('show_media', '');
199
} else {
200
	$oTpl->parse('show_media', 'show_media_block', true);
201
}
202

    
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
if($admin->get_permission('addons') != true)
230
{
231
	$oTpl->set_var('DISPLAY_ADDONS', 'display:none;');
232
}
233
if($admin->get_permission('access') != true)
234
{
235
	$oTpl->set_var('DISPLAY_ACCESS', 'display:none;');
236
}
237
if($admin->get_permission('settings') != true)
238
{
239
	$oTpl->set_var('DISPLAY_SETTINGS', 'display:none;');
240
}
241
if($admin->get_permission('admintools') != true)
242
{
243
	$oTpl->set_var('DISPLAY_ADMINTOOLS', 'display:none;');
244
}
245
*/
246

    
247

    
248
$oTpl->set_block('main_block', 'show_install_block', 'show_install');
249
if($admin->get_user_id() != 1)
250
{
251
	$oTpl->parse('show_install', '');
252
} else {
253

    
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
}
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
$oTpl->set_var(array(
305
					'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

    
323
// Parse template object
324
$oTpl->parse('main', 'main_block', false);
325
$oTpl->pparse('output', 'page');
326

    
327
// Print admin footer
328
$admin->print_footer();
    (1-1/1)