Project

General

Profile

1
<?php
2
/**
3
 *
4
 * @category        admin
5
 * @package         pages
6
 * @author          Ryan Djurovich, 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: sections.php 1849 2013-01-06 19:04:11Z Luisehahne $
13
 * @filesource      $HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/admin/pages/sections.php $
14
 * @lastmodified    $Date: 2013-01-06 20:04:11 +0100 (Sun, 06 Jan 2013) $
15
 *
16
 */
17

    
18
// Include config file
19
if(!defined('WB_URL'))
20
{
21
    $config_file = realpath('../../config.php');
22
    if(file_exists($config_file) && !defined('WB_URL'))
23
    {
24
    	require($config_file);
25
    }
26
}
27

    
28
// Make sure people are allowed to access this page
29
if(MANAGE_SECTIONS != 'enabled')
30
{
31
	header('Location: '.ADMIN_URL.'/pages/index.php');
32
	exit(0);
33
}
34
/* */
35
$debug = true; // to show position
36
If(!defined('DEBUG')) { define('DEBUG',$debug);}
37
// Create new admin object
38
if(!class_exists('admin', false)){ include(WB_PATH.'/framework/class.admin.php'); }
39
$admin = new admin('Pages', 'pages_view', false);
40

    
41
// Include the WB functions file
42
if(!function_exists('directory_list')) { require(WB_PATH.'/framework/functions.php'); }
43

    
44
$action = 'show';
45
// Get page id
46
$requestMethod = '_'.strtoupper($_SERVER['REQUEST_METHOD']);
47
$page_id = intval((isset(${$requestMethod}['page_id'])) ? ${$requestMethod}['page_id'] : 0);
48
$action = ($page_id ? 'show' : $action);
49
// Get section id if there is one
50
$requestMethod = '_'.strtoupper($_SERVER['REQUEST_METHOD']);
51
$section_id = ((isset(${$requestMethod}['section_id'])) ? ${$requestMethod}['section_id']  : 0);
52
$action = ($section_id ? 'delete' : $action);
53
// Get module if there is one
54
$requestMethod = '_'.strtoupper($_SERVER['REQUEST_METHOD']);
55
$module = ((isset(${$requestMethod}['module'])) ? ${$requestMethod}['module']  : 0);
56
$action = ($module != '' ? 'add' : $action);
57
$admin_header = true;
58
$backlink = ADMIN_URL.'/pages/sections.php?page_id='.(int)$page_id;
59

    
60
switch ($action):
61
	case 'delete' :
62
        if($admin->get_permission('pages_delete') == false)
63
        {
64
			$admin->print_header();
65
			$admin->print_error($module.' '.strtolower($MESSAGE['PAGES_INSUFFICIENT_PERMISSIONS']),$backlink);
66
        }
67

    
68
		if( ( !($section_id = intval($admin->checkIDKEY('section_id', 0, $_SERVER['REQUEST_METHOD'])) )) )
69
		{
70
			if($admin_header) { $admin->print_header(); }
71
			$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS'],$backlink);
72
		}
73

    
74
		$action = 'show';
75
	    $sql  = 'SELECT `module` FROM `'.TABLE_PREFIX.'sections` ';
76
	    $sql .= 'WHERE `section_id` ='.$section_id;
77
        if( ( ($modulname = $database->get_one($sql)) == $module) && ($section_id > 0 ) ) {
78
			// Include the modules delete file if it exists
79
			if(file_exists(WB_PATH.'/modules/'.$modulname.'/delete.php'))
80
		    {
81
				require(WB_PATH.'/modules/'.$modulname.'/delete.php');
82
			}
83
		    $sql  = 'DELETE FROM `'.TABLE_PREFIX.'sections` ';
84
		    $sql .= 'WHERE `section_id` ='.(int)$section_id.' LIMIT 1';
85
			if( !$database->query($sql) ) {
86
				if($admin_header) { $admin->print_header(); }
87
				$admin->print_error($database->get_error(),$backlink);
88
			}  else {
89
				require_once(WB_PATH.'/framework/class.order.php');
90
				$order = new order(TABLE_PREFIX.'sections', 'position', 'section_id', 'page_id');
91
				$order->clean($page_id);
92
				$format = $TEXT['SECTION'].' %d  %s %s '.strtolower( $TEXT['DELETED']);
93
				$message = sprintf ($format,$section_id,strtoupper($modulname),strtolower($TEXT['SUCCESS']));
94
				if($admin_header) { $admin->print_header(); }
95
				$admin_header = false;
96
				unset($_POST);
97
				$admin->print_success($message, $backlink );
98
			}
99
        } else {
100
			if($admin_header) { $admin->print_header(); }
101
			$admin->print_error($module.' '.strtolower($TEXT['NOT_FOUND']),$backlink);
102
        }
103

    
104
		break;
105
	case 'add' :
106
        if($admin->get_permission('pages_add') == false)
107
        {
108
			$admin->print_header();
109
			$admin->print_error($module.' '.strtolower($MESSAGE['PAGES_INSUFFICIENT_PERMISSIONS']),$backlink);
110
        }
111
		if (!$admin->checkFTAN())
112
		{
113
			$admin->print_header();
114
			$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS'],$backlink);
115
		}
116
		$action = 'show';
117
		$module = preg_replace('/\W/', '', $module );  // fix secunia 2010-91-4
118
		require_once(WB_PATH.'/framework/class.order.php');
119
		// Get new order
120
		$order = new order(TABLE_PREFIX.'sections', 'position', 'section_id', 'page_id');
121
		$position = $order->get_new($page_id);
122
		// Insert module into DB
123
	    $sql  = 'INSERT INTO `'.TABLE_PREFIX.'sections` SET ';
124
	    $sql .= '`page_id` = '.(int)$page_id.', ';
125
	    $sql .= '`module` = \''.$module.'\', ';
126
	    $sql .= '`position` = '.(int)$position.', ';
127
	    $sql .= '`block` = \'1\', ';
128
        $sql .= '`publ_start` = \'0\',';
129
        $sql .= '`publ_end` = \'0\' ';
130

    
131
        if($database->query($sql)) {
132
			// Get the section id
133
			$section_id = $database->get_one("SELECT LAST_INSERT_ID()");
134
			// Include the selected modules add file if it exists
135
			if(file_exists(WB_PATH.'/modules/'.$module.'/add.php'))
136
		    {
137
				require(WB_PATH.'/modules/'.$module.'/add.php');
138
			}
139
        } elseif ($database->is_error())  {
140
			if($admin_header) { $admin->print_header(); }
141
			$admin->print_error($database->get_error());
142
		}
143
		break;
144
	default:
145
		break;
146
endswitch;
147

    
148
switch ($action):
149
	default:
150

    
151
		if($admin_header) { $admin->print_header(); }
152
		// Get perms
153
		$sql  = 'SELECT `admin_groups`,`admin_users` FROM `'.TABLE_PREFIX.'pages` ';
154
		$sql .= 'WHERE `page_id` = '.$page_id;
155
		$results = $database->query($sql);
156

    
157
		$results_array = $results->fetchRow();
158
		$old_admin_groups = explode(',', $results_array['admin_groups']);
159
		$old_admin_users = explode(',', $results_array['admin_users']);
160
		$in_old_group = FALSE;
161
		foreach($admin->get_groups_id() as $cur_gid)
162
		{
163
			if (in_array($cur_gid, $old_admin_groups))
164
		    {
165
				$in_old_group = TRUE;
166
			}
167
		}
168
		if((!$in_old_group) && !is_numeric(array_search($admin->get_user_id(), $old_admin_users)))
169
		{
170
			$admin->print_header();
171
			$admin->print_error($MESSAGE['PAGES_INSUFFICIENT_PERMISSIONS']);
172
		}
173

    
174
		// Get page details
175
		$sql  = 'SELECT * FROM `'.TABLE_PREFIX.'pages` ';
176
		$sql .= 'WHERE `page_id` = '.$page_id;
177
		$results = $database->query($sql);
178

    
179
		if($database->is_error())
180
		{
181
			// $admin->print_header();
182
			$admin->print_error($database->get_error());
183
		}
184
		if($results->numRows() == 0)
185
		{
186
			// $admin->print_header();
187
			$admin->print_error($MESSAGE['PAGES_NOT_FOUND']);
188
		}
189
		$results_array = $results->fetchRow();
190

    
191
		// Get display name of person who last modified the page
192
			$user=$admin->get_user_details($results_array['modified_by']);
193
		// Convert the unix ts for modified_when to human a readable form
194
			if($results_array['modified_when'] != 0) {
195
				$modified_ts = gmdate(TIME_FORMAT.', '.DATE_FORMAT, $results_array['modified_when']+TIMEZONE);
196
			} else {
197
				$modified_ts = 'Unknown';
198
			}
199

    
200
		// Set module permissions
201
		$module_permissions = $_SESSION['MODULE_PERMISSIONS'];
202

    
203
		// Unset block var
204
		unset($block);
205
		// Include template info file (if it exists)
206
		if($results_array['template'] != '')
207
		{
208
			$template_location = WB_PATH.'/templates/'.$results_array['template'].'/info.php';
209
		} else {
210
			$template_location = WB_PATH.'/templates/'.DEFAULT_TEMPLATE.'/info.php';
211
		}
212
		if(file_exists($template_location))
213
		{
214
			require($template_location);
215
		}
216
		// Check if $menu is set
217
		if(!isset($block[1]) || $block[1] == '')
218
		{
219
			// Make our own menu list
220
			$block[1] = $TEXT['MAIN'];
221
		}
222

    
223
		/*-- load css files with jquery --*/
224
		// include jscalendar-setup
225
		$jscal_use_time = true; // whether to use a clock, too
226
		require_once(WB_PATH."/include/jscalendar/wb-setup.php");
227

    
228
		// Setup template object, parse vars to it, then parse it
229
		// Create new template object
230
		$tpl = new Template(dirname($admin->correct_theme_source('pages_sections.htt')));
231
		// $template->debug = true;
232
		$tpl->set_file('page', 'pages_sections.htt');
233
		$tpl->set_block('page', 'main_block', 'main');
234
		$tpl->set_block('main_block', 'module_block', 'module_list');
235
		$tpl->set_block('main_block', 'section_block', 'section_list');
236
		$tpl->set_block('section_block', 'block_block', 'block_list');
237
		$tpl->set_block('main_block', 'calendar_block', 'calendar_list');
238
		$tpl->set_var('FTAN', $admin->getFTAN());
239

    
240
		// set first defaults and messages
241
		$tpl->set_var(array(
242
						'PAGE_ID' => $results_array['page_id'],
243
						// 'PAGE_IDKEY' => $admin->getIDKEY($results_array['page_id']),
244
						'PAGE_IDKEY' => $results_array['page_id'],
245
						'TEXT_PAGE' => $TEXT['PAGE'],
246
						'PAGE_TITLE' => ($results_array['page_title']),
247
						'MENU_TITLE' => ($results_array['menu_title']),
248
						'TEXT_CURRENT_PAGE' => $TEXT['CURRENT_PAGE'],
249
						'TEXT_LAST_MODIFIED' => $TEXT['LAST_UPDATED_BY'],
250
						'HEADING_MANAGE_SECTIONS' => $HEADING['MANAGE_SECTIONS'],
251
						'HEADING_MODIFY_PAGE' => $HEADING['MODIFY_PAGE'],
252
						'TEXT_CHANGE_SETTINGS' => $TEXT['CHANGE_SETTINGS'],
253
						'TEXT_ADD_SECTION' => $TEXT['ADD_SECTION'],
254
						'TEXT_SECTION' => $TEXT['SECTION'],
255
						'TEXT_ID' => 'ID',
256
						'TEXT_TYPE' => $TEXT['TYPE'],
257
						'TEXT_BLOCK' => $TEXT['BLOCK'],
258
						'TEXT_PUBL_START_DATE' => $TEXT{'PUBL_START_DATE'},
259
						'TEXT_PUBL_END_DATE' => $TEXT['PUBL_END_DATE'],
260
						'TEXT_ACTIONS' => $TEXT['ACTIONS'],
261
						'MODIFIED_BY'          => $user['display_name'],
262
						'MODIFIED_BY_USERNAME' => $user['username'],
263
						'MODIFIED_WHEN'        => $modified_ts,
264
						'ADMIN_URL' => ADMIN_URL,
265
						'WB_URL' => WB_URL,
266
						'THEME_URL' => THEME_URL
267
						)
268
					);
269
// check modify page permission
270
	if( $admin->get_permission('pages_modify') )
271
	{
272
		$tpl->set_var(array(
273
				'MODIFY_LINK_BEFORE' => '<a href="'.ADMIN_URL.'/pages/modify.php?page_id='.$results_array['page_id'].'">',
274
				'MODIFY_LINK_AFTER' => '</a>',
275
				'DISPLAY_MANAGE_MODIFY' => 'link',
276
				));
277
	} else {
278
		$tpl->set_var(array(
279
				'MODIFY_LINK_BEFORE' => '<span class="bold grey">',
280
				'MODIFY_LINK_AFTER' => '</span>',
281
				'DISPLAY_MANAGE_MODIFY' => 'link',
282
				));
283
	}
284

    
285
// check settings page permission
286
	if( $admin->get_permission('pages_settings') )
287
	{
288
		$tpl->set_var(array(
289
				'SETTINGS_LINK_BEFORE' => '<a href="'.ADMIN_URL.'/pages/settings.php?page_id='.$results_array['page_id'].'">',
290
				'SETTINGS_LINK_AFTER' => '</a>',
291
				'DISPLAY_MANAGE_SETTINGS' => 'link',
292
				));
293
	} else {
294
		$tpl->set_var(array(
295
				'SETTINGS_LINK_BEFORE' => '<span class="bold grey">',
296
				'SETTINGS_LINK_AFTER' => '</span>',
297
				'DISPLAY_MANAGE_SECTIONS' => 'link',
298
				));
299
	}
300

    
301
		// Insert variables
302
		$tpl->set_var(array(
303
						'PAGE_ID' => $results_array['page_id'],
304
						// 'PAGE_IDKEY' => $admin->getIDKEY($results_array['page_id']),
305
						'PAGE_IDKEY' => $results_array['page_id'],
306
						'VAR_PAGE_TITLE' => $results_array['page_title'],
307
						'SETTINGS_LINK' => ADMIN_URL.'/pages/settings.php?page_id='.$results_array['page_id'],
308
						'MODIFY_LINK' => ADMIN_URL.'/pages/modify.php?page_id='.$results_array['page_id']
309
						)
310
					);
311
// setting trash only if more than one section exists
312
		$tpl->set_block('section_block', 'delete_block', 'delete');
313
		if( $bSectionCanDelete = ($database->get_one('SELECT COUNT(*) FROM `'.TABLE_PREFIX.'sections` WHERE `page_id`='.$page_id))!=1 ) {
314
		}
315

    
316
		$sql  = 'SELECT `section_id`,`module`,`position`,`block`,`publ_start`,`publ_end` ';
317
		$sql .= 'FROM `'.TABLE_PREFIX.'sections` ';
318
		$sql .= 'WHERE `page_id` = '.$page_id.' ';
319
		$sql .= 'ORDER BY `position` ASC';
320
		$query_sections = $database->query($sql);
321

    
322
		if($query_sections->numRows() > 0)
323
		{
324
			$num_sections = $query_sections->numRows();
325
			while($section = $query_sections->fetchRow())
326
		    {
327
				if(!is_numeric(array_search($section['module'], $module_permissions)))
328
		        {
329
					// Get the modules real name
330
		            $sql = 'SELECT `name` FROM `'.TABLE_PREFIX.'addons` ';
331
		            $sql .= 'WHERE `directory` = "'.$section['module'].'"';
332
		            if(!$database->get_one($sql) || !file_exists(WB_PATH.'/modules/'.$section['module']))
333
					{
334
						$edit_page = '<span class="module_disabled">'.$section['module'].'</span>';
335
					}else
336
					{
337
						$edit_page = '';
338
					}
339
					$sec_anchor = (defined( 'SEC_ANCHOR' ) && ( SEC_ANCHOR != '' )  ? SEC_ANCHOR : 'section_');
340
					$edit_page_0 = '<a id="sid'.$section['section_id'].'" href="'.ADMIN_URL.'/pages/modify.php?page_id='.$results_array['page_id'];
341
					$edit_page_1  = ($sec_anchor!='') ? '#'.$sec_anchor.$section['section_id'].'">' : '">';
342
					$edit_page_1 .= $section['module'].'</a>';
343
					if(SECTION_BLOCKS)
344
		            {
345
						if($edit_page == '')
346
						{
347
							if(defined('EDIT_ONE_SECTION') && EDIT_ONE_SECTION)
348
							{
349
								$edit_page = $edit_page_0.'&amp;wysiwyg='.$section['section_id'].$edit_page_1;
350
							} else {
351
								$edit_page = $edit_page_0.$edit_page_1;
352
							}
353
						}
354
						$input_attribute = 'input_normal';
355
						$tpl->set_var(array(
356
								'STYLE_DISPLAY_SECTION_BLOCK' => ' style="visibility:visible;"',
357
								'NAME_SIZE' => 300,
358
								'INPUT_ATTRIBUTE' => $input_attribute,
359
								'VAR_SECTION_ID' => $section['section_id'],
360
								'VAR_SECTION_IDKEY' => $admin->getIDKEY($section['section_id']),
361
								// 'VAR_SECTION_IDKEY' => $section['section_id'],
362
								'VAR_POSITION' => $section['position'],
363
								'LINK_MODIFY_URL_VAR_MODUL_NAME' => $edit_page,
364
								'SELECT' => '',
365
								'SET_NONE_DISPLAY_OPTION' => ''
366
								)
367
							);
368
						// Add block options to the section_list
369
						$tpl->clear_var('block_list');
370
						foreach($block AS $number => $name)
371
		                {
372
							$tpl->set_var('NAME', htmlentities(strip_tags($name)));
373
							$tpl->set_var('VALUE', $number);
374
							$tpl->set_var('SIZE', 1);
375
							if($section['block'] == $number)
376
		                    {
377
								$tpl->set_var('SELECTED', ' selected="selected"');
378
							} else {
379
								$tpl->set_var('SELECTED', '');
380
							}
381
							$tpl->parse('block_list', 'block_block', true);
382
						}
383
					} else {
384
						if($edit_page == '')
385
						{
386
							$edit_page = $edit_page_0.'#wb_'.$edit_page_1;
387
						}
388
						$input_attribute = 'input_normal';
389
						$tpl->set_var(array(
390
								'STYLE_DISPLAY_SECTION_BLOCK' => ' style="visibility:hidden;"',
391
								'NAME_SIZE' => 300,
392
								'INPUT_ATTRIBUTE' => $input_attribute,
393
								'VAR_SECTION_ID' => $section['section_id'],
394
								'VAR_SECTION_IDKEY' => $admin->getIDKEY($section['section_id']),
395
								// 'VAR_SECTION_IDKEY' => $section['section_id'],
396
								'VAR_POSITION' => $section['position'],
397
								'LINK_MODIFY_URL_VAR_MODUL_NAME' => $edit_page,
398
								'NAME' => htmlentities(strip_tags($block[1])),
399
								'VALUE' => 1,
400
								'SET_NONE_DISPLAY_OPTION' => '<option>&nbsp;</option>'
401
								)
402
							);
403
					}
404
					// Insert icon and images
405
					$tpl->set_var(array(
406
								'CLOCK_16_PNG' => 'clock_16.png',
407
								'CLOCK_DEL_16_PNG' => 'clock_del_16.png',
408
								'DELETE_16_PNG' => 'delete_16.png'
409
								)
410
							);
411
					// set calendar start values
412
					if($section['publ_start']==0)
413
		            {
414
						$tpl->set_var('VALUE_PUBL_START', '');
415
					} else {
416
						$tpl->set_var('VALUE_PUBL_START', date($jscal_format, $section['publ_start']));
417
					}
418
					// set calendar start values
419
					if($section['publ_end']==0)
420
		            {
421
						$tpl->set_var('VALUE_PUBL_END', '');
422
					} else {
423
						$tpl->set_var('VALUE_PUBL_END', date($jscal_format, $section['publ_end']));
424
					}
425
					// Insert icons up and down
426
					if($section['position'] != 1 )
427
		            {
428
						$tpl->set_var(
429
									'VAR_MOVE_UP_URL',
430
									'<a href="'.ADMIN_URL.'/pages/move_up.php?page_id='.$page_id.'&amp;section_id='.$section['section_id'].'">
431
									<img src="'.THEME_URL.'/images/up_16.png" alt="{TEXT_MOVE_UP}" />
432
									</a>' );
433
					} else {
434
						$tpl->set_var(array(
435
									'VAR_MOVE_UP_URL' => ''
436
									)
437
								);
438
					}
439
					if($section['position'] != $num_sections ) {
440
						$tpl->set_var(
441
									'VAR_MOVE_DOWN_URL',
442
									'<a href="'.ADMIN_URL.'/pages/move_down.php?page_id='.$page_id.'&amp;section_id='.$section['section_id'].'">
443
									<img src="'.THEME_URL.'/images/down_16.png" alt="{TEXT_MOVE_DOWN}" />
444
									</a>' );
445
					} else {
446
						$tpl->set_var(array(
447
									'VAR_MOVE_DOWN_URL' => ''
448
									)
449
								);
450
					}
451

    
452
				} else {
453
				  continue;
454
				}
455

    
456
					$tpl->set_var(array(
457
									'DISPLAY_DEBUG' => ' style="visibility:visible;"',
458
									'TEXT_SID' => 'SID',
459
									'DEBUG_COLSPAN_SIZE' => 9
460
									)
461
								);
462
				if($debug)
463
		        {
464
					$tpl->set_var(array(
465
									'DISPLAY_DEBUG' => ' style="visibility:visible;"',
466
									'TEXT_PID' => 'PID',
467
									'TEXT_SID' => 'SID',
468
									'POSITION' => $section['position']
469
									)
470
								);
471
				} else {
472
					$tpl->set_var(array(
473
									'DISPLAY_DEBUG' => ' style="display:none;"',
474
									'TEXT_PID' => '',
475
									'POSITION' => ''
476
									)
477
								);
478
				}
479
				if($bSectionCanDelete) {
480
					$tpl->parse('delete', 'delete_block', false);
481
				} else {
482
					$tpl->parse('delete', '', false);
483
				} 
484
				$tpl->parse('section_list', 'section_block', true);
485
			}
486

    
487
		}
488

    
489
		// now add the calendars -- remember to to set the range to [1970, 2037] if the date is used as timestamp!
490
		// the loop is simply a copy from above.
491
		$sql  = 'SELECT `section_id`,`module` FROM `'.TABLE_PREFIX.'sections` ';
492
		$sql .= 'WHERE page_id = '.$page_id.' ';
493
		$sql .= 'ORDER BY `position` ASC';
494
		$query_sections = $database->query($sql);
495

    
496
		if($query_sections->numRows() > 0)
497
		{
498
			$num_sections = $query_sections->numRows();
499
			while($section = $query_sections->fetchRow())
500
		    {
501
				// Get the modules real name
502
		        $sql  = 'SELECT `name` FROM `'.TABLE_PREFIX.'addons` ';
503
		        $sql .= 'WHERE `directory` = "'.$section['module'].'"';
504
		        $module_name = $database->get_one($sql);
505

    
506
				if(!is_numeric(array_search($section['module'], $module_permissions)))
507
		        {
508
					$tpl->set_var(array(
509
								'jscal_ifformat' => $jscal_ifformat,
510
								'jscal_firstday' => $jscal_firstday,
511
								'jscal_today' => $jscal_today,
512
								'start_date' => 'start_date'.$section['section_id'],
513
								'end_date' => 'end_date'.$section['section_id'],
514
								'trigger_start' => 'trigger_start'.$section['section_id'],
515
								'trigger_end' => 'trigger_stop'.$section['section_id']
516
								)
517
							);
518
					if(isset($jscal_use_time) && $jscal_use_time==TRUE) {
519
						$tpl->set_var(array(
520
								'showsTime' => "true",
521
								'timeFormat' => "24"
522
								)
523
							);
524
					}  else {
525
						$tpl->set_var(array(
526
								'showsTime' => "false",
527
								'timeFormat' => "24"
528
								)
529
							);
530
					}
531
				}
532
				$tpl->parse('calendar_list', 'calendar_block', true);
533
			}
534
		}
535

    
536
		// Work-out if we should show the "Add Section" form
537
		$sql  = 'SELECT `section_id` FROM `'.TABLE_PREFIX.'sections` ';
538
		$sql .= 'WHERE `page_id` = '.$page_id.' AND `module` = "menu_link"';
539
		$query_sections = $database->query($sql);
540
		$tpl->set_var('TEXT_PLEASE_SELECT', $TEXT['NONE']);
541
		if($query_sections->numRows() == 0)
542
		{
543
			$tpl->set_var('TEXT_PLEASE_SELECT', $TEXT['PLEASE_SELECT']);
544
			// Modules list
545
		    $sql  = 'SELECT `name`,`directory`,`type` FROM `'.TABLE_PREFIX.'addons` ';
546
		    $sql .= 'WHERE `type` = "module" AND `function` = "page" AND `directory` != "menu_link" ';
547
		    $sql .= 'ORDER BY `name`';
548
		    $result = $database->query($sql);
549
		// if(DEBUG && $database->is_error()) { $admin->print_error($database->get_error()); }
550

    
551
			if($result->numRows() > 0)
552
		    {
553
				while ($module = $result->fetchRow())
554
		        {
555
					// Check if user is allowed to use this module   echo  $module['directory'],'<br />';
556
					if(!is_numeric(array_search($module['directory'], $module_permissions)))
557
		            {
558
						$tpl->set_var('VALUE', $module['directory']);
559
						$tpl->set_var('NAME', $module['name']);
560
						if($module['directory'] == 'wysiwyg')
561
		                {
562
							$tpl->set_var('SELECTED', ' selected="selected"');
563
						} else {
564
							$tpl->set_var('SELECTED', '');
565
						}
566
						$tpl->parse('module_list', 'module_block', true);
567
					} else {
568
					  continue;
569
					}
570
				}
571
			}
572
		}
573
		// Insert language text and messages
574
		$tpl->set_var(array(
575
							'TEXT_MANAGE_SECTIONS' => $HEADING['MANAGE_SECTIONS'],
576
							'TEXT_ARE_YOU_SURE' => $TEXT['ARE_YOU_SURE'],
577
							'TEXT_TYPE' => $TEXT['TYPE'],
578
							'TEXT_ADD' => $TEXT['ADD'],
579
							'TEXT_SAVE' =>  $TEXT['SAVE'],
580
							'TEXTLINK_MODIFY_PAGE' => $HEADING['MODIFY_PAGE'],
581
							'TEXT_CALENDAR' => $TEXT['CALENDAR'],
582
							'TEXT_DELETE_DATE' => $TEXT['DELETE_DATE'],
583
							'TEXT_ADD_SECTION' => $TEXT['ADD_SECTION'],
584
							'TEXT_MOVE_UP' => $TEXT['MOVE_UP'],
585
							'TEXT_MOVE_DOWN' => $TEXT['MOVE_DOWN']
586
							)
587
						);
588
		$tpl->parse('main', 'main_block', false);
589
		$tpl->pparse('output', 'page');
590
		// include the required file for Javascript admin
591
		if(file_exists(WB_PATH.'/modules/jsadmin/jsadmin_backend_include.php'))
592
		{
593
			include(WB_PATH.'/modules/jsadmin/jsadmin_backend_include.php');
594
		}
595
		break;
596
endswitch;
597

    
598
// Print admin footer
599
$admin->print_footer();
(19-19/23)