Project

General

Profile

1
<?php
2
/**
3
 *
4
 * @category        admin
5
 * @package         pages
6
 * @author          Ryan Djurovich, WebsiteBaker Project
7
 * @copyright       2009-2013, WebsiteBaker Org. e.V.
8
 * @link            http://www.websitebaker.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 2076 2014-01-06 23:30:25Z darkviper $
13
 * @filesource      $HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/admin/pages/sections.php $
14
 * @lastmodified    $Date: 2014-01-07 00:30:25 +0100 (Tue, 07 Jan 2014) $
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
// Include the WB functions file
41
if(!function_exists('directory_list')) { require(WB_PATH.'/framework/functions.php'); }
42
$mLang = Translate::getinstance();
43
$mLang->enableAddon('admin\pages');
44
$oDb = WbDatabase::getInstance();
45
$action = 'show';
46
// Get page id
47
$requestMethod = '_'.strtoupper($_SERVER['REQUEST_METHOD']);
48
$page_id = intval((isset(${$requestMethod}['page_id'])) ? ${$requestMethod}['page_id'] : 0);
49
$action = ($page_id ? 'show' : $action);
50
// Get section id if there is one
51
$requestMethod = '_'.strtoupper($_SERVER['REQUEST_METHOD']);
52
$section_id = ((isset(${$requestMethod}['section_id'])) ? ${$requestMethod}['section_id']  : 0);
53
$action = ($section_id ? 'delete' : $action);
54
// Get module if there is one
55
$requestMethod = '_'.strtoupper($_SERVER['REQUEST_METHOD']);
56
$module = ((isset(${$requestMethod}['module'])) ? ${$requestMethod}['module']  : 0);
57
$action = ($module != '' ? 'add' : $action);
58
$admin_header = true;
59
$backlink = ADMIN_URL.'/pages/sections.php?page_id='.(int)$page_id;
60

    
61
switch ($action):
62
	case 'delete' :
63
        if($admin->get_permission('pages_delete') == false)
64
        {
65
			$admin->print_header();
66
			$admin->print_error($module.' '.mb_strtolower($mLang->MESSAGE_PAGES_INSUFFICIENT_PERMISSIONS, 'UTF-8'), $backlink);
67
        }
68

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

    
75
		$action = 'show';
76
	    $sql = 'SELECT `module` FROM `'.$oDb->TablePrefix.'sections` '
77
	         . 'WHERE `section_id` ='.$section_id;
78
        if ((($modulname = $oDb->getOne($sql)) == $module) && ($section_id > 0 ) ) {
79
			// Include the modules delete file if it exists
80
			if(file_exists(WB_PATH.'/modules/'.$modulname.'/delete.php'))
81
		    {
82
				require(WB_PATH.'/modules/'.$modulname.'/delete.php');
83
			}
84
		    $sql = 'DELETE FROM `'.$oDb->TablePrefix.'sections` '
85
		         . 'WHERE `section_id` ='.(int)$section_id.' LIMIT 1';
86
			if (!$oDb->doQuery($sql)) {
87
				if($admin_header) { $admin->print_header(); }
88
				$admin->print_error($oDb->get_error(),$backlink);
89
			} else {
90
				require_once(WB_PATH.'/framework/class.order.php');
91
				$order = new order($oDb->TablePrefix.'sections', 'position', 'section_id', 'page_id');
92
				$order->clean($page_id);
93
				$format = $mLang->TEXT_SECTION.' %d  %s %s '.mb_strtolower($mLang->TEXT_DELETED, 'UTF-8');
94
				$message = sprintf ($format,$section_id, mb_strtoupper($modulname, 'UTF-8'),mb_strtolower($mLang->TEXT_SUCCESS, 'UTF-8'));
95
				if($admin_header) { $admin->print_header(); }
96
				$admin_header = false;
97
				unset($_POST);
98
				$admin->print_success($message, $backlink );
99
			}
100
        } else {
101
			if($admin_header) { $admin->print_header(); }
102
			$admin->print_error($module.' '.mb_strtolower($mLang->TEXT_NOT_FOUND, 'UTF-8'),$backlink);
103
        }
104

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

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

    
149
switch ($action):
150
	default:
151

    
152
		if($admin_header) { $admin->print_header(); }
153
		// Get perms
154
		$sql  = 'SELECT `admin_groups`,`admin_users` FROM `'.$oDb->TablePrefix.'pages` '
155
		      . 'WHERE `page_id` = '.$page_id;
156
		$oPage = $oDb->doQuery($sql);
157
		$aPageRights = $oPage->fetchRow(MYSQL_ASSOC);
158
    // Get user permisions
159
        if (!$admin->ami_group_member($aPageRights['admin_groups']) && !$admin->is_group_match($admin->get_user_id(), $aPageRights['admin_users'])) {
160
			$admin->print_header();
161
			$admin->print_error($mLang->MESSAGE_PAGES_INSUFFICIENT_PERMISSIONS);
162
        }
163
//		$old_admin_groups = explode(',', $results_array['admin_groups']);
164
//		$old_admin_users = explode(',', $results_array['admin_users']);
165
//		$in_old_group = FALSE;
166
//		foreach($admin->get_groups_id() as $cur_gid)
167
//		{
168
//			if (in_array($cur_gid, $old_admin_groups))
169
//		    {
170
//				$in_old_group = TRUE;
171
//			}
172
//		}
173
//		if((!$in_old_group) && !is_numeric(array_search($admin->get_user_id(), $old_admin_users)))
174
//		{
175
//			$admin->print_header();
176
//			$admin->print_error($mLang->MESSAGE_PAGES_INSUFFICIENT_PERMISSIONS);
177
//		}
178
		// Get page details
179
		$sql  = 'SELECT * FROM `'.$oDb->TablePrefix.'pages` ';
180
		$sql .= 'WHERE `page_id` = '.$page_id;
181
		$results = $oDb->doQuery($sql);
182

    
183
		if($oDb->is_error())
184
		{
185
			// $admin->print_header();
186
			$admin->print_error($oDb->get_error());
187
		}
188
		if($results->numRows() == 0)
189
		{
190
			// $admin->print_header();
191
			$admin->print_error($mLang->MESSAGE_PAGES_NOT_FOUND);
192
		}
193
		$results_array = $results->fetchRow();
194

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

    
204
		// Set module permissions
205
		$module_permissions = $_SESSION['MODULE_PERMISSIONS'];
206

    
207
		// Unset block var
208
		unset($block);
209
		// Include template info file (if it exists)
210
		if($results_array['template'] != '')
211
		{
212
			$template_location = WB_PATH.'/templates/'.$results_array['template'].'/info.php';
213
		} else {
214
			$template_location = WB_PATH.'/templates/'.DEFAULT_TEMPLATE.'/info.php';
215
		}
216
		if(file_exists($template_location))
217
		{
218
			require($template_location);
219
		}
220
    // check block settings from template/info.php
221
       if(isset($block) && is_array($block) && sizeof($block) > 0) {
222
           if(isset($block[0])) {
223
           throw new AppException('Invalid index 0 for $block[] in '.str_replace(WB_PATH,'',$template_location).'. '
224
                                . 'The list must start with $block[1]. Please correct it!');
225
           }
226
           foreach($block as $iIndex=>$sBlockTitle) {
227
               if(trim($sBlockTitle) == '' ) {
228
                $block[$iIndex] = $mLang->TEXT_BLOCK.'_'.$iIndex;
229
               }
230
           }
231
       }else {
232
           // Make our own menu list
233
           $block = array(1 => $mLang->TEXT_MAIN);
234
       }
235
		/*-- load css files with jquery --*/
236
		// include jscalendar-setup
237
		$jscal_use_time = true; // whether to use a clock, too
238
		require_once(WB_PATH."/include/jscalendar/wb-setup.php");
239

    
240
		// Setup template object, parse vars to it, then parse it
241
		// Create new template object
242
		$tpl = new Template(dirname($admin->correct_theme_source('pages_sections.htt')));
243
		// $template->debug = true;
244
		$tpl->set_file('page', 'pages_sections.htt');
245
		$tpl->set_block('page', 'main_block', 'main');
246
		$tpl->set_block('main_block', 'module_block', 'module_list');
247
		$tpl->set_block('main_block', 'section_block', 'section_list');
248
		$tpl->set_block('section_block', 'block_block', 'block_list');
249
		$tpl->set_block('main_block', 'calendar_block', 'calendar_list');
250
		$tpl->set_var('FTAN', $admin->getFTAN());
251

    
252
		// set first defaults and messages
253
		$tpl->set_var(array(
254
						'PAGE_ID' => $results_array['page_id'],
255
						// 'PAGE_IDKEY' => $admin->getIDKEY($results_array['page_id']),
256
						'PAGE_IDKEY' => $results_array['page_id'],
257
						'TEXT_PAGE' => $mLang->TEXT_PAGE,
258
						'PAGE_TITLE' => ($results_array['page_title']),
259
						'MENU_TITLE' => ($results_array['menu_title']),
260
						'TEXT_CURRENT_PAGE' => $mLang->TEXT_CURRENT_PAGE,
261
						'TEXT_LAST_MODIFIED' => $mLang->TEXT_LAST_UPDATED_BY,
262
						'HEADING_MANAGE_SECTIONS' => $mLang->HEADING_MANAGE_SECTIONS,
263
						'HEADING_MODIFY_PAGE' => $mLang->HEADING_MODIFY_PAGE,
264
						'TEXT_CHANGE_SETTINGS' => $mLang->TEXT_CHANGE_SETTINGS,
265
						'TEXT_ADD_SECTION' => $mLang->TEXT_ADD_SECTION,
266
						'TEXT_SECTION' => $mLang->TEXT_SECTION,
267
						'TEXT_ID' => 'ID',
268
						'TEXT_TYPE' => $mLang->TEXT_TYPE,
269
						'TEXT_BLOCK' => $mLang->TEXT_BLOCK,
270
						'TEXT_PUBL_START_DATE' => $mLang->TEXT_PUBL_START_DATE,
271
						'TEXT_PUBL_END_DATE' => $mLang->TEXT_PUBL_END_DATE,
272
						'TEXT_ACTIONS' => $mLang->TEXT_ACTIONS,
273
						'MODIFIED_BY'          => $user['display_name'],
274
						'MODIFIED_BY_USERNAME' => $user['username'],
275
						'MODIFIED_WHEN'        => $modified_ts,
276
						'ADMIN_URL' => ADMIN_URL,
277
						'WB_URL' => WB_URL,
278
						'THEME_URL' => THEME_URL
279
						)
280
					);
281
// check modify page permission
282
	if( $admin->get_permission('pages_modify') )
283
	{
284
		$tpl->set_var(array(
285
				'MODIFY_LINK_BEFORE' => '<a href="'.ADMIN_URL.'/pages/modify.php?page_id='.$results_array['page_id'].'">',
286
				'MODIFY_LINK_AFTER' => '</a>',
287
				'DISPLAY_MANAGE_MODIFY' => 'link',
288
				));
289
	} else {
290
		$tpl->set_var(array(
291
				'MODIFY_LINK_BEFORE' => '<span class="bold grey">',
292
				'MODIFY_LINK_AFTER' => '</span>',
293
				'DISPLAY_MANAGE_MODIFY' => 'link',
294
				));
295
	}
296

    
297
// check settings page permission
298
	if( $admin->get_permission('pages_settings') )
299
	{
300
		$tpl->set_var(array(
301
				'SETTINGS_LINK_BEFORE' => '<a href="'.ADMIN_URL.'/pages/settings.php?page_id='.$results_array['page_id'].'">',
302
				'SETTINGS_LINK_AFTER' => '</a>',
303
				'DISPLAY_MANAGE_SETTINGS' => 'link',
304
				));
305
	} else {
306
		$tpl->set_var(array(
307
				'SETTINGS_LINK_BEFORE' => '<span class="bold grey">',
308
				'SETTINGS_LINK_AFTER' => '</span>',
309
				'DISPLAY_MANAGE_SECTIONS' => 'link',
310
				));
311
	}
312

    
313
		// Insert variables
314
		$tpl->set_var(array(
315
						'PAGE_ID' => $results_array['page_id'],
316
						// 'PAGE_IDKEY' => $admin->getIDKEY($results_array['page_id']),
317
						'PAGE_IDKEY' => $results_array['page_id'],
318
						'VAR_PAGE_TITLE' => $results_array['page_title'],
319
						'SETTINGS_LINK' => ADMIN_URL.'/pages/settings.php?page_id='.$results_array['page_id'],
320
						'MODIFY_LINK' => ADMIN_URL.'/pages/modify.php?page_id='.$results_array['page_id']
321
						)
322
					);
323
// setting trash only if more than one section exists
324
		$tpl->set_block('section_block', 'delete_block', 'delete');
325
        $sql = 'SELECT COUNT(*) FROM `'.$oDb->TablePrefix.'sections` '
326
             . 'WHERE `page_id`='.$page_id;
327
		$bSectionCanDelete = ($oDb->getOne($sql) > 1);
328
		$sql = 'SELECT `section_id`,`module`,`position`,`block`,`publ_start`,`publ_end` '
329
		     . 'FROM `'.$oDb->TablePrefix.'sections` '
330
		     . 'WHERE `page_id` = '.$page_id.' '
331
		     . 'ORDER BY `position` ASC';
332
		$query_sections = $oDb->doQuery($sql);
333
        $num_sections = $query_sections->numRows();
334
        while ($section = $query_sections->fetchRow(MYSQL_ASSOC)) {
335
            if (!is_numeric(array_search($section['module'], $module_permissions))) {
336
                // Get the modules real name
337
                $sql = 'SELECT `name` FROM `'.$oDb->TablePrefix.'addons` '
338
                     . 'WHERE `directory` = "'.$section['module'].'"';
339
                if (!$oDb->getOne($sql) || !file_exists(WB_PATH.'/modules/'.$section['module'])) {
340
                    $edit_page = '<span class="module_disabled">'.$section['module'].'</span>';
341
                } else {
342
                    $edit_page = '';
343
                }
344
                $sSectionIdPrefix = ( defined( 'SEC_ANCHOR' ) && ( SEC_ANCHOR != '' )  ? SEC_ANCHOR : 'Sec');
345
                $edit_page_0 = '<a id="sid'.$section['section_id'].'" href="'.ADMIN_URL.'/pages/modify.php?page_id='.$results_array['page_id'];
346
                $edit_page_1  = ($sSectionIdPrefix!='') ? '#'.$sSectionIdPrefix.$section['section_id'].'">' : '">';
347
                $edit_page_1 .= $section['module'].'</a>';
348
                if (SECTION_BLOCKS) {
349
                    if ($edit_page == '') {
350
                        if (defined('EDIT_ONE_SECTION') && EDIT_ONE_SECTION) {
351
                            $edit_page = $edit_page_0.'&amp;wysiwyg='.$section['section_id'].$edit_page_1;
352
                        } else {
353
                            $edit_page = $edit_page_0.$edit_page_1;
354
                        }
355
                    }
356
                    $input_attribute = 'input_normal';
357
                    $tpl->set_var(array(
358
                            'STYLE_DISPLAY_SECTION_BLOCK' => ' style="visibility:visible;"',
359
                            'NAME_SIZE' => 300,
360
                            'INPUT_ATTRIBUTE' => $input_attribute,
361
                            'VAR_SECTION_ID' => $section['section_id'],
362
                            'VAR_SECTION_IDKEY' => $admin->getIDKEY($section['section_id']),
363
                            // 'VAR_SECTION_IDKEY' => $section['section_id'],
364
                            'VAR_POSITION' => $section['position'],
365
                            'LINK_MODIFY_URL_VAR_MODUL_NAME' => $edit_page,
366
                            'SELECT' => '',
367
                            'SET_NONE_DISPLAY_OPTION' => ''
368
                            )
369
                        );
370
                    // Add block options to the section_list
371
                    $tpl->clear_var('block_list');
372
                    foreach ($block AS $number => $name) {
373
                        $tpl->set_var('NAME', htmlentities(strip_tags($name)));
374
                        $tpl->set_var('VALUE', $number);
375
                        $tpl->set_var('SIZE', 1);
376
                        if ($section['block'] == $number) {
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
                        $edit_page = $edit_page_0.'#wb_'.$edit_page_1;
386
                    }
387
                    $input_attribute = 'input_normal';
388
                    reset($block);
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(key($block))),
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
                    $tpl->set_var('VALUE_PUBL_START', '');
414
                } else {
415
                    $tpl->set_var('VALUE_PUBL_START', date($jscal_format, $section['publ_start']+TIMEZONE));
416
                }
417
                // set calendar start values
418
                if ($section['publ_end']==0) {
419
                    $tpl->set_var('VALUE_PUBL_END', '');
420
                } else {
421
                    $tpl->set_var('VALUE_PUBL_END', date($jscal_format, $section['publ_end']+TIMEZONE));
422
                }
423
                // Insert icons up and down
424
                if ($section['position'] != 1 ) {
425
                    $tpl->set_var(
426
                                'VAR_MOVE_UP_URL',
427
                                '<a href="'.ADMIN_URL.'/pages/move_up.php?page_id='.$page_id.'&amp;section_id='.$section['section_id'].'">
428
                                <img src="'.THEME_URL.'/images/up_16.png" alt="{TEXT_MOVE_UP}" />
429
                                </a>' );
430
                } else {
431
                    $tpl->set_var(array(
432
                                'VAR_MOVE_UP_URL' => ''
433
                                )
434
                            );
435
                }
436
                if ($section['position'] != $num_sections ) {
437
                    $tpl->set_var(
438
                                'VAR_MOVE_DOWN_URL',
439
                                '<a href="'.ADMIN_URL.'/pages/move_down.php?page_id='.$page_id.'&amp;section_id='.$section['section_id'].'">
440
                                <img src="'.THEME_URL.'/images/down_16.png" alt="{TEXT_MOVE_DOWN}" />
441
                                </a>' );
442
                } else {
443
                    $tpl->set_var(array(
444
                                'VAR_MOVE_DOWN_URL' => ''
445
                                )
446
                            );
447
                }
448
            } else { continue; }
449
            $tpl->set_var(array(
450
                            'DISPLAY_DEBUG' => ' style="visibility:visible;"',
451
                            'TEXT_SID' => 'SID',
452
                            'DEBUG_COLSPAN_SIZE' => 9
453
                            )
454
                        );
455
            if ($debug) {
456
                $tpl->set_var(array(
457
                                'DISPLAY_DEBUG' => ' style="visibility:visible;"',
458
                                'TEXT_PID' => 'PID',
459
                                'TEXT_SID' => 'SID',
460
                                'POSITION' => $section['position']
461
                                )
462
                            );
463
            } else {
464
                $tpl->set_var(array(
465
                                'DISPLAY_DEBUG' => ' style="display:none;"',
466
                                'TEXT_PID' => '',
467
                                'POSITION' => ''
468
                                )
469
                            );
470
            }
471
            if ($bSectionCanDelete) {
472
                $tpl->parse('delete', 'delete_block', false);
473
            } else {
474
                $tpl->parse('delete', '', false);
475
            }
476
            $tpl->parse('section_list', 'section_block', true);
477
		}
478

    
479
		// now add the calendars -- remember to to set the range to [1970, 2037] if the date is used as timestamp!
480
		// the loop is simply a copy from above.
481
		$sql = 'SELECT `section_id`,`module` FROM `'.$oDb->TablePrefix.'sections` '
482
		     . 'WHERE page_id = '.$page_id.' '
483
		     . 'ORDER BY `position` ASC';
484
		$query_sections = $oDb->doQuery($sql);
485

    
486
		if ($query_sections->numRows() > 0) {
487
			$num_sections = $query_sections->numRows();
488
			while ($section = $query_sections->fetchRow()) {
489
				// Get the modules real name
490
		        $sql = 'SELECT `name` FROM `'.$oDb->TablePrefix.'addons` '
491
		             . 'WHERE `directory` = "'.$section['module'].'"';
492
		        $module_name = $oDb->getOne($sql);
493
				if (!is_numeric(array_search($section['module'], $module_permissions))) {
494
					$tpl->set_var(array(
495
								'jscal_ifformat' => $jscal_ifformat,
496
								'jscal_firstday' => $jscal_firstday,
497
								'jscal_today' => $jscal_today,
498
								'start_date' => 'start_date'.$section['section_id'],
499
								'end_date' => 'end_date'.$section['section_id'],
500
								'trigger_start' => 'trigger_start'.$section['section_id'],
501
								'trigger_end' => 'trigger_stop'.$section['section_id']
502
								)
503
							);
504
					if (isset($jscal_use_time) && $jscal_use_time==TRUE) {
505
						$tpl->set_var(array(
506
								'showsTime' => "true",
507
								'timeFormat' => "24"
508
								)
509
							);
510
					} else {
511
						$tpl->set_var(array(
512
								'showsTime' => "false",
513
								'timeFormat' => "24"
514
								)
515
							);
516
					}
517
				}
518
				$tpl->parse('calendar_list', 'calendar_block', true);
519
			}
520
		}
521

    
522
		// Work-out if we should show the "Add Section" form
523
		$sql = 'SELECT `section_id` FROM `'.$oDb->TablePrefix.'sections` '
524
		     . 'WHERE `page_id` = '.$page_id.' AND `module` = "menu_link"';
525
		$query_sections = $oDb->doQuery($sql);
526
		$tpl->set_var('TEXT_PLEASE_SELECT', $mLang->TEXT_NONE);
527
		if ($query_sections->numRows() == 0) {
528
			$tpl->set_var('TEXT_PLEASE_SELECT', $mLang->TEXT_PLEASE_SELECT);
529
			// Modules list
530
		    $sql = 'SELECT `name`,`directory`,`type` FROM `'.$oDb->TablePrefix.'addons` '
531
		         . 'WHERE `type` = "module" AND `function` = "page" AND `directory` != "menu_link" '
532
		         . 'ORDER BY `name`';
533
		    $result = $oDb->doQuery($sql);
534
		// if(DEBUG && $oDb->is_error()) { $admin->print_error($oDb->get_error()); }
535
			if ($result->numRows() > 0) {
536
				while ($module = $result->fetchRow()) {
537
					// Check if user is allowed to use this module   echo  $module['directory'],'<br />';
538
					if (!is_numeric(array_search($module['directory'], $module_permissions))) {
539
						$tpl->set_var('VALUE', $module['directory']);
540
						$tpl->set_var('NAME', $module['name']);
541
						if ($module['directory'] == 'wysiwyg') {
542
							$tpl->set_var('SELECTED', ' selected="selected"');
543
						} else {
544
							$tpl->set_var('SELECTED', '');
545
						}
546
						$tpl->parse('module_list', 'module_block', true);
547
					} else {
548
					  continue;
549
					}
550
				}
551
			}
552
		}
553
		// Insert language text and messages
554
		$tpl->set_var(array(
555
							'TEXT_MANAGE_SECTIONS' => $mLang->HEADING_MANAGE_SECTIONS,
556
							'TEXT_ARE_YOU_SURE' => $mLang->TEXT_ARE_YOU_SURE,
557
							'TEXT_TYPE' => $mLang->TEXT_TYPE,
558
							'TEXT_ADD' => $mLang->TEXT_ADD,
559
							'TEXT_SAVE' =>  $mLang->TEXT_SAVE,
560
							'TEXTLINK_MODIFY_PAGE' => $mLang->HEADING_MODIFY_PAGE,
561
							'TEXT_CALENDAR' => $mLang->TEXT_CALENDAR,
562
							'TEXT_DELETE_DATE' => $mLang->TEXT_DELETE_DATE,
563
							'TEXT_ADD_SECTION' => $mLang->TEXT_ADD_SECTION,
564
							'TEXT_MOVE_UP' => $mLang->TEXT_MOVE_UP,
565
							'TEXT_MOVE_DOWN' => $mLang->TEXT_MOVE_DOWN
566
							)
567
						);
568
		$tpl->parse('main', 'main_block', false);
569
		$tpl->pparse('output', 'page');
570
		// include the required file for Javascript admin
571
		if(file_exists(WB_PATH.'/modules/jsadmin/jsadmin_backend_include.php')) {
572
			include(WB_PATH.'/modules/jsadmin/jsadmin_backend_include.php');
573
		}
574
		break;
575
endswitch;
576
// Print admin footer
577
$admin->print_footer();
(21-21/25)