Project

General

Profile

1
<?php
2
/**
3
 *
4
 * @category        admin
5
 * @package         pages
6
 * @author          WebsiteBaker Project
7
 * @copyright       Ryan Djurovich
8
 * @copyright       WebsiteBaker Org. e.V.
9
 * @link            http://websitebaker.org/
10
 * @license         http://www.gnu.org/licenses/gpl.html
11
 * @platform        WebsiteBaker 2.8.3
12
 * @requirements    PHP 5.3.6 and higher
13
 * @version         $Id: sections.php 2 2017-07-02 15:14:29Z Manuela $
14
 * @filesource      $HeadURL: svn://isteam.dynxs.de/wb/2.10.x/branches/main/admin/pages/sections.php $
15
 * @lastmodified    $Date: 2017-07-02 17:14:29 +0200 (Sun, 02 Jul 2017) $
16
 *
17
 */
18

    
19
// Include config file
20
if ( !defined( 'WB_PATH' ) ){ require( dirname(dirname((__DIR__))).'/config.php' ); }
21

    
22
// Make sure people are allowed to access this page
23
if(MANAGE_SECTIONS != 'enabled')
24
{
25
    header('Location: '.ADMIN_URL.'/pages/index.php');
26
    exit(0);
27
}
28
/* */
29
$bDebug = false; // to show position and section_id
30
if(!defined('PAGE_DEBUG')) { define('PAGE_DEBUG',$bDebug);}
31
// Include the WB functions file
32
if ( !function_exists( 'create_access_file' ) ) { require(WB_PATH.'/framework/functions.php'); }
33
// Create new admin object
34
if ( !class_exists('admin', false) ) { require(WB_PATH.'/framework/class.admin.php'); }
35
$admin = new admin('Pages', 'pages_modify', false);
36
$action = 'show';
37
//$echo = $myPath;  //
38
// Get page id
39
$requestMethod = '_'.strtoupper($_SERVER['REQUEST_METHOD']);
40
$page_id = intval((isset(${$requestMethod}['page_id'])) ? ${$requestMethod}['page_id'] : 0);
41
$action = ($page_id ? 'show' : $action);
42
// Get section id if there is one
43
$requestMethod = '_'.strtoupper($_SERVER['REQUEST_METHOD']);
44
$section_id = ((isset(${$requestMethod}['section_id'])) ? ${$requestMethod}['section_id']  : 0);
45
$action = ($section_id ? 'delete' : $action);
46
// Get module if there is one
47
$requestMethod = '_'.strtoupper($_SERVER['REQUEST_METHOD']);
48
$module = ((isset(${$requestMethod}['module'])) ? ${$requestMethod}['module']  : 0);
49
$action = ($module != '' ? 'add' : $action);
50
$admin_header = true;
51
$backlink = ADMIN_URL.'/pages/sections.php?page_id='.(int)$page_id;
52
switch ($action):
53
    case 'delete' :
54
        if( (!($section_id = intval($admin->checkIDKEY('section_id', 0, $_SERVER['REQUEST_METHOD'])))) )
55
        {
56
            if($admin_header) { $admin->print_header(); }
57
            $sInfo = strtoupper(basename(__DIR__).'_'.basename(__FILE__, ''.PAGE_EXTENSION)).'_idkey::';
58
            $sDEBUG=(@DEBUG?$sInfo:'');
59
            $admin->print_error($sDEBUG.$MESSAGE['GENERIC_SECURITY_ACCESS'], $backlink);
60
        }
61
        $action = 'show';
62
        $sql  = 'SELECT `module` FROM `'.TABLE_PREFIX.'sections` ';
63
        $sql .= ' WHERE `section_id` ='.$section_id;
64
        if( ( ($modulname = $database->get_one($sql)) == $module) && ($section_id > 0 ) ) {
65
            // Include the modules delete file if it exists
66
            if(file_exists(WB_PATH.'/modules/'.$modulname.'/delete.php'))
67
            {
68
                require(WB_PATH.'/modules/'.$modulname.'/delete.php');
69
            }
70
            $sql  = 'DELETE FROM `'.TABLE_PREFIX.'sections` ';
71
            $sql .= 'WHERE `section_id` ='.(int)$section_id;
72
            if( !$database->query($sql) ) {
73
                if($admin_header) { $admin->print_header(); }
74
                $admin->print_error($database->get_error(),$backlink);
75
            }  else {
76
                if ( !class_exists( 'order', false ) ) { require(WB_PATH.'/framework/class.order.php'); }
77
                $order = new order(TABLE_PREFIX.'sections', 'position', 'section_id', 'page_id');
78
                $order->clean($page_id);
79
                $format = $TEXT['SECTION'].' %d  %s %s '.strtolower( $TEXT['DELETED']);
80
                $message = sprintf ($format,$section_id,strtoupper($modulname),strtolower($TEXT['SUCCESS']));
81
                if($admin_header) { $admin->print_header(); }
82
                $admin_header = false;
83
                unset($_POST);
84
                $admin->print_success($message, $backlink );
85
            }
86
        } else {
87
            if($admin_header) { $admin->print_header(); }
88
            $admin->print_error($module.' '.strtolower($TEXT['NOT_FOUND']), $backlink);
89
        }
90

    
91
        break;
92
    case 'add' :
93
        if (!$admin->checkFTAN())
94
        {
95
            $admin->print_header();
96
            $sInfo = strtoupper(basename(__DIR__).'_'.basename(__FILE__, ''.PAGE_EXTENSION)).'::';
97
            $sDEBUG=(@DEBUG?$sInfo:'');
98
            $admin->print_error($sDEBUG.$MESSAGE['GENERIC_SECURITY_ACCESS'], $backlink);
99
        }
100
        $action = 'show';
101
        $module = preg_replace('/\W/', '', $module );  // fix secunia 2010-91-4
102
        require_once(WB_PATH.'/framework/class.order.php');
103
        // Get new order
104
        $order = new order(TABLE_PREFIX.'sections', 'position', 'section_id', 'page_id');
105
        $position = $order->get_new($page_id);
106
        // Insert module into DB
107
        $sql  = 'INSERT INTO `'.TABLE_PREFIX.'sections` SET '
108
              . '`page_id` = '.(int)$page_id.', '
109
              . '`module` = \''.$module.'\', '
110
              . '`position` = '.(int)$position.', '
111
              . '`block` = 1';
112
        if($database->query($sql)) {
113
            // Get the section id
114
            $section_id = $database->get_one("SELECT LAST_INSERT_ID()");
115
            // Include the selected modules add file if it exists
116
            if (
117
                file_exists(WB_PATH.'/modules/'.$module.'/addon.php') &&
118
                file_exists(WB_PATH.'/modules/'.$module.'/cmd/cmdModify.inc')
119
            ) { break; }
120
            if(file_exists(WB_PATH.'/modules/'.$module.'/add.php'))
121
            {
122
                require(WB_PATH.'/modules/'.$module.'/add.php');
123
            }
124
        } elseif ($database->is_error())  {
125
            if($admin_header) { $admin->print_header(); }
126
            $admin->print_error($database->get_error());
127
        }
128
        break;
129
    default:
130
        break;
131
endswitch;
132

    
133
switch ($action):
134
    default:
135
        if($admin_header) { $admin->print_header(); }
136
        // Get perms
137
        $sql  = 'SELECT `admin_groups`,`admin_users` FROM `'.TABLE_PREFIX.'pages` '
138
              . 'WHERE `page_id` = '.$page_id;
139
        $oPages = $database->query($sql);
140
        $aPages = $oPages->fetchRow(MYSQLI_ASSOC);
141
        $in_old_group = $admin->is_group_match($aPages['admin_groups'],$admin->get_groups_id());
142
/*
143
        $old_admin_groups = explode(',', $aPages['admin_groups']);
144
        $old_admin_users  = explode(',', $aPages['admin_users']);
145
        $in_old_group = false;
146
        foreach($admin->get_groups_id() as $cur_gid)
147
        {
148
            if (in_array($cur_gid, $old_admin_groups))
149
            {
150
                $in_old_group = true;
151
            }
152
        }
153
*/
154
        if ((!$in_old_group) && !is_numeric(array_search($admin->get_user_id(), $old_admin_users)))
155
        {
156
            $admin->print_header();
157
            $sInfo = strtoupper(basename(__DIR__).'_'.basename(__FILE__, ''.PAGE_EXTENSION)).'::';
158
            $sDEBUG=(@DEBUG?$sInfo:'');
159
            $admin->print_error($sDEBUG.$MESSAGE['PAGES_INSUFFICIENT_PERMISSIONS']);
160
        }
161
        // Get page details
162
        $sql  = 'SELECT * FROM `'.TABLE_PREFIX.'pages` '
163
              . 'WHERE `page_id` = '.$page_id;
164
        $results = $database->query($sql);
165
        if($database->is_error())
166
        {
167
            // $admin->print_header();
168
            $admin->print_error($database->get_error());
169
        }
170
        if($results->numRows() == 0)
171
        {
172
            // $admin->print_header();
173
            $admin->print_error($MESSAGE['PAGES_NOT_FOUND']);
174
        }
175
        $results_array = $results->fetchRow(MYSQLI_ASSOC);
176
        // Set module permissions
177
        $aAllowedModules = array();
178
        $sAllowedModules = '';
179
        $module_permissions = $_SESSION['MODULE_PERMISSIONS'];
180
        $sAllowedModules = implode(', ',
181
                           array_map(function(&$item) use ($database){
182
                                         return '\''.$database->escapeString($item) .'\'';
183
                                     }, $module_permissions));
184
        $sqlAddons  = 'SELECT * FROM `'.TABLE_PREFIX.'addons` '
185
                    . 'WHERE `type` = \'module\' '
186
                    .   ($sAllowedModules?'AND `directory` NOT IN ('.$sAllowedModules.')' :'')
187
                    . 'ORDER BY `name`';
188
        if($oAddons = $database->query($sqlAddons))
189
        {
190
            while($aAddons = $oAddons->fetchRow(MYSQLI_ASSOC))
191
            {
192
               $aAllowedModules[] = $aAddons['directory'];
193
            }
194
        }
195

    
196
        $sAllowedModules = '';
197
        $sAllowedModules = implode(', ',
198
                           array_map(function(&$item) use ($database){
199
                                         return '\''.$database->escapeString($item) .'\'';
200
                                     }, $aAllowedModules));
201
        // Unset block var
202
        unset($block);
203
        // Include template info file (if it exists)
204
        if($results_array['template'] != '')
205
        {
206
            $template_location = WB_PATH.'/templates/'.$results_array['template'].'/info.php';
207
        } else {
208
            $template_location = WB_PATH.'/templates/'.DEFAULT_TEMPLATE.'/info.php';
209
        }
210
        if(file_exists($template_location))
211
        {
212
            require($template_location);
213
        }
214
        // Check if $menu is set
215
        if(!isset($block[1]) || $block[1] == '')
216
        {
217
            // Make our own menu list
218
            $block[1] = $TEXT['MAIN'];
219
        }
220
        // Get display name of person who last modified the page
221
        $user=$admin->get_user_details($results_array['modified_by']);
222
        // Convert the unix ts for modified_when to human a readable form
223
        if($results_array['modified_when'] != 0)
224
        {
225
            $modified_ts = gmdate(TIME_FORMAT.', '.DATE_FORMAT, $results_array['modified_when']+TIMEZONE);
226
        } else {
227
            $modified_ts = 'Unknown';
228
        }
229
        /*-- load css files with jquery --*/
230
        // include jscalendar-setup
231
        $jscal_use_time = true; // whether to use a clock, too
232
        require_once(WB_PATH."/include/jscalendar/wb-setup.php");
233
        // Setup template object, parse vars to it, then parse it
234
        // Create new template object
235
        $tpl = new Template(dirname($admin->correct_theme_source('pages_sections.htt')));
236
        // $template->debug = true;
237
        $tpl->set_file('page', 'pages_sections.htt');
238
        $tpl->set_block('page', 'main_block', 'main');
239
        $tpl->set_block('main_block', 'module_block', 'module_list');
240
        $tpl->set_block('main_block', 'show_section_block', 'show_section');
241
        $tpl->set_block('main_block', 'calendar_block', 'calendar_list');
242
        $tpl->set_var('FTAN', $admin->getFTAN());
243
        // setting trash only if more than one section exists
244
        $tpl->set_block('show_section_block', 'can_delete_block', 'can_delete');
245
        $sql = 'SELECT COUNT(*) FROM `'.TABLE_PREFIX.'sections` '
246
             . 'WHERE `page_id`='.intval($page_id).' '
247
             .   'AND `module` IN ('.$sAllowedModules.')';
248
        $bSectionCanDelete = ($database->get_one($sql) > 1);
249
        // set first defaults and messages
250
        $tpl->set_var(array(
251
                        'PAGE_ID' => $results_array['page_id'],
252
                        // 'PAGE_IDKEY' => $admin->getIDKEY($results_array['page_id']),
253
                        'PAGE_IDKEY' => $results_array['page_id'],
254
                        'TEXT_PAGE' => $TEXT['PAGE'],
255
                        'TIMEZONE' => 'TIMEZONE',
256
                        'PAGE_TITLE' => ($results_array['page_title']),
257
                        'MENU_TITLE' => ($results_array['menu_title']),
258
                        'TEXT_CURRENT_PAGE' => $TEXT['CURRENT_PAGE'],
259
                        'HEADING_MANAGE_SECTIONS' => $HEADING['MANAGE_SECTIONS'],
260
                        'HEADING_MODIFY_PAGE' => $HEADING['MODIFY_PAGE'],
261
                        'TEXT_CHANGE_SETTINGS' => $TEXT['CHANGE_SETTINGS'],
262
                        'TEXT_ADD_SECTION' => $TEXT['ADD_SECTION'],
263
                        'TEXT_ID' => 'ID',
264
                        'TEXT_TYPE' => $TEXT['TYPE'],
265
                        'TEXT_BLOCK' => $TEXT['BLOCK'],
266
                        'TEXT_PUBL_START_DATE' => $TEXT{'PUBL_START_DATE'},
267
                        'TEXT_PUBL_END_DATE' => $TEXT['PUBL_END_DATE'],
268
                        'TEXT_ACTIONS' => $TEXT['ACTIONS'],
269
                        'TEXT_MODIFY' => $TEXT['MODIFY'],
270
                        'TEXT_MODIFY_PAGE' => $HEADING['MODIFY_PAGE'],
271
                        'LAST_MODIFIED' => $MESSAGE['PAGES']['LAST_MODIFIED'],
272
                        'MODIFIED_BY' => $user['display_name'],
273
                        'MODIFIED_BY_USERNAME' => $user['username'],
274
                        'MODIFIED_WHEN' => $modified_ts,
275
                        'ADMIN_URL' => ADMIN_URL,
276
                        'WB_URL' => WB_URL,
277
                        'THEME_URL' => THEME_URL
278
                        )
279
                    );
280
        // Insert variables
281
        $tpl->set_var(array(
282
                        'PAGE_ID' => $results_array['page_id'],
283
                        // 'PAGE_IDKEY' => $admin->getIDKEY($results_array['page_id']),
284
                        'PAGE_IDKEY' => $results_array['page_id'],
285
                        'VAR_PAGE_TITLE' => $results_array['page_title'],
286
                        'SETTINGS_LINK' => ADMIN_URL.'/pages/settings.php?page_id='.$results_array['page_id'],
287
                        'MODIFY_LINK' => ADMIN_URL.'/pages/modify.php?page_id='.$results_array['page_id']
288
                        )
289
                    );
290
        $tpl->set_block('show_section_block', 'section_list_block', 'section_list');
291
        $tpl->set_block('show_section_block', 'section_title_block', 'section_title');
292
        $sqlSections  = 'SELECT * FROM `'.TABLE_PREFIX.'sections` '
293
                      . 'WHERE `page_id` = '.(int)$page_id.' '
294
                      . 'ORDER BY `position`';
295
//        $query_sections = $database->query($sql);
296
        if ($query_sections = $database->query($sqlSections))
297
        {
298
            $num_sections = $query_sections->numRows();
299
            $section = array();
300
            while($section = $query_sections->fetchRow(MYSQLI_ASSOC))
301
            {
302
                if(!is_numeric(array_search($section['module'], $module_permissions)))
303
                {
304
                    // Get the modules real name
305
                    $sql = 'SELECT `name` FROM `'.TABLE_PREFIX.'addons` '
306
                         . 'WHERE `directory` = "'.$section['module'].'"';
307
                    if(!$database->get_one($sql) || !file_exists(WB_PATH.'/modules/'.$section['module']))
308
                    {
309
                        $edit_page = '<span class="module_disabled">'.$section['module'].'</span>';
310
                        $section['title'] = $MESSAGE['GENERIC_NOT_INSTALLED'];
311
                    }else
312
                    {
313
                        $edit_page = '';
314
                    }
315
                    $sec_anchor = (defined( 'SEC_ANCHOR' ) && ( SEC_ANCHOR != '' )  ? SEC_ANCHOR : '');
316
                    $edit_page_0 = '<a id="sid'.$section['section_id'].'" href="'.ADMIN_URL.'/pages/modify.php?page_id='.$results_array['page_id'];
317
                    $edit_page_1  = ($sec_anchor!='') ? '#'.$sec_anchor.$section['section_id'].'">' : '">';
318
                    $edit_page_1 .= $section['module'].'</a>';
319

    
320
                    if ($section['title']!='') {
321
                        $sSectionTitle  =  ((mb_strlen($section['title']) > 35) ? mb_substr($section['title'], 0, 34).'…' : $section['title']);
322
                        $tpl->set_var('SECTION_TITLE', $sSectionTitle);
323
                        $tpl->set_var('SEC_TAG_TITLE', $section['title']);
324
                        $tpl->parse('section_title', 'section_title_block', false);
325
                    } else {
326
                        $tpl->parse('section_title', '');
327
                    }
328

    
329
                    if(SECTION_BLOCKS)
330
                    {
331
                        if($edit_page == '')
332
                        {
333
                            if(defined('EDIT_ONE_SECTION') && EDIT_ONE_SECTION)
334
                            {
335
                                $edit_page = $edit_page_0.'&amp;wysiwyg='.$section['section_id'].$edit_page_1;
336
                            } else {
337
                                $edit_page = $edit_page_0.$edit_page_1;
338
                            }
339
                        }
340
                        $input_attribute = 'input_normal';
341
                        $tpl->set_var(array(
342
                                'STYLE_DISPLAY_SECTION_BLOCK' => ' style="visibility:visible;"',
343
                                'NAME_SIZE' => 300,
344
                                'INPUT_ATTRIBUTE' => $input_attribute,
345
                                'VAR_SECTION_ID' => $section['section_id'],
346
                                'VAR_SECTION_IDKEY' => $admin->getIDKEY($section['section_id']),
347
                                // 'VAR_SECTION_IDKEY' => $section['section_id'],
348
                                'VAR_POSITION' => $section['position'],
349
                                'LINK_MODIFY_URL_VAR_MODUL_NAME' => $edit_page,
350
                                'SELECT' => '',
351
                                'SET_NONE_DISPLAY_OPTION' => ''
352
                                )
353
                            );
354
                        // Add block options to the section_list
355
                        $tpl->clear_var('section_list');
356

    
357
                        foreach($block AS $number => $name)
358
                        {
359
                            $tpl->set_var('NAME', htmlentities(strip_tags($name)));
360
                            $tpl->set_var('VALUE', $number);
361
                            $tpl->set_var('SIZE', 1);
362
                            if($section['block'] == $number)
363
                            {
364
                                $tpl->set_var('SELECTED', ' selected="selected"');
365
                            } else {
366
                                $tpl->set_var('SELECTED', '');
367
                            }
368
                            $tpl->parse('section_list', 'section_list_block', true);
369
                        }
370
                    } else {
371
                        if($edit_page == '')
372
                        {
373
                            $edit_page = $edit_page_0.'#wb_'.$edit_page_1;
374
                        }
375

    
376
                        $input_attribute = 'input_normal';
377
                        $tpl->set_var(array(
378
                                'STYLE_DISPLAY_SECTION_BLOCK' => ' style="visibility:hidden;"',
379
                                'NAME_SIZE' => 300,
380
                                'INPUT_ATTRIBUTE' => $input_attribute,
381
                                'VAR_SECTION_ID' => $section['section_id'],
382
                                'VAR_SECTION_IDKEY' => $admin->getIDKEY($section['section_id']),
383
                                // 'VAR_SECTION_IDKEY' => $section['section_id'],
384
                                'VAR_POSITION' => $section['position'],
385
                                'LINK_MODIFY_URL_VAR_MODUL_NAME' => $edit_page,
386
                                'NAME' => htmlentities(strip_tags($block[1])),
387
                                'VALUE' => 1,
388
                                'SET_NONE_DISPLAY_OPTION' => ''
389
                                )
390
                            );
391
                    }
392
                    // Insert icon and images
393
                    $tpl->set_var(array(
394
                                'CLOCK_16_PNG' => 'clock_16.png',
395
                                'CLOCK_DEL_16_PNG' => 'clock_del_16.png',
396
                                'DELETE_16_PNG' => 'delete_16.png'
397
                                )
398
                            );
399
                    // set calendar start values
400
                    if($section['publ_start']==0)
401
                    {
402
                        $tpl->set_var('VALUE_PUBL_START', '');
403
                    } else {
404
                        $tpl->set_var('VALUE_PUBL_START', date($jscal_format, $section['publ_start']+TIMEZONE));
405
                    }
406
                    // set calendar start values
407
                    if($section['publ_end']==0)
408
                    {
409
                        $tpl->set_var('VALUE_PUBL_END', '');
410
                    } else {
411
                        $tpl->set_var('VALUE_PUBL_END', date($jscal_format, $section['publ_end']+TIMEZONE));
412
                    }
413
                    // Insert icons up and down
414
                    if($section['position'] != 1 )
415
                    {
416
                        $tpl->set_var(
417
                                    'VAR_MOVE_UP_URL',
418
                                    '<a href="'.ADMIN_URL.'/pages/move_up.php?page_id='.$page_id.'&amp;section_id='.$section['section_id'].'">
419
                                    <img src="'.THEME_URL.'/images/up_16.png" alt="up" />
420
                                    </a>' );
421
                    } else {
422
                        $tpl->set_var(array(
423
                                    'VAR_MOVE_UP_URL' => ''
424
                                    )
425
                                );
426
                    }
427
                    if($section['position'] != $num_sections ) {
428
                        $tpl->set_var(
429
                                    'VAR_MOVE_DOWN_URL',
430
                                    '<a href="'.ADMIN_URL.'/pages/move_down.php?page_id='.$page_id.'&amp;section_id='.$section['section_id'].'">
431
                                    <img src="'.THEME_URL.'/images/down_16.png" alt="down" />
432
                                    </a>' );
433
                    } else {
434
                        $tpl->set_var(array(
435
                                    'VAR_MOVE_DOWN_URL' => ''
436
                                    )
437
                                );
438
                    }
439
                } else {
440
                  continue;
441
                }
442
                    $tpl->set_var(array(
443
                                    'DISPLAY_DEBUG' => ' style="visibility="visible;"',
444
                                    'TEXT_SID' => 'SID',
445
                                    'DEBUG_COLSPAN_SIZE' => 9
446
                                    )
447
                                );
448
                if($bDebug)
449
                {
450
                    $tpl->set_var(array(
451
                                    'DISPLAY_DEBUG' => ' style="visibility="visible;"',
452
                                    'TEXT_PID' => 'PID',
453
                                    'TEXT_SID' => 'SID',
454
                                    'POSITION' => $section['position']
455
                                    )
456
                                );
457
                } else {
458
                    $tpl->set_var(array(
459
                                    'DISPLAY_DEBUG' => ' style="display:none;"',
460
                                    'TEXT_PID' => '',
461
                                    'POSITION' => ''
462
                                    )
463
                                );
464
                }
465
            if($bSectionCanDelete) {
466
                $tpl->parse('can_delete', 'can_delete_block', false);
467
            } else {
468
//                $tpl->parse('can_delete', '', false);
469
                $tpl->set_block('can_delete_block', '');
470
            }
471
            $tpl->parse('show_section', 'show_section_block', true);
472
            }
473
        }
474

    
475
        // now add the calendars -- remember to to set the range to [1970, 2037] if the date is used as timestamp!
476
        // the loop is simply a copy from above.
477
        $sql  = 'SELECT `section_id`,`module` FROM `'.TABLE_PREFIX.'sections` ';
478
        $sql .= 'WHERE page_id = '.$page_id.' ';
479
        $sql .= 'ORDER BY `position` ASC';
480
        $query_sections = $database->query($sql);
481

    
482
        if($query_sections->numRows() > 0)
483
        {
484
            $num_sections = $query_sections->numRows();
485
            while($section = $query_sections->fetchRow())
486
            {
487
                // Get the modules real name
488
                $sql  = 'SELECT `name` FROM `'.TABLE_PREFIX.'addons` '
489
                      . 'WHERE `directory` = "'.$section['module'].'"';
490
                $module_name = $database->get_one($sql);
491

    
492
                if(!is_numeric(array_search($section['module'], $module_permissions)))
493
                {
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 `'.TABLE_PREFIX.'sections` '
524
              . 'WHERE `page_id` = '.$page_id.' AND `module` = "menu_link"';
525
        $query_sections = $database->query($sql);
526
        if($query_sections->numRows() == 0)
527
        {
528
            // Modules list
529
            $sql  = 'SELECT `name`,`directory`,`type` FROM `'.TABLE_PREFIX.'addons` '
530
                  . 'WHERE `type` = \'module\' '
531
                  .   'AND `function` = \'page\' '
532
                  .   'AND `directory` != \'menu_link\' '
533
                  . 'ORDER BY `name`';
534
            $result = $database->query($sql);
535
        // if(DEBUG && $database->is_error()) { $admin->print_error($database->get_error()); }
536
            if($result->numRows() > 0)
537
            {
538
                while ($module = $result->fetchRow(MYSQLI_ASSOC))
539
                {
540
                    // Check if user is allowed to use this module   echo  $module['directory'],'<br />';
541
                    if(!is_numeric(array_search($module['directory'], $module_permissions)))
542
                    {
543
                        $tpl->set_var('VALUE', $module['directory']);
544
                        $tpl->set_var('NAME', $module['name']);
545
                        if($module['directory'] == 'wysiwyg')
546
                        {
547
                            $tpl->set_var('SELECTED', ' selected="selected"');
548
                        } else {
549
                            $tpl->set_var('SELECTED', '');
550
                        }
551
                        $tpl->parse('module_list', 'module_block', true);
552
                    } else {
553
                      continue;
554
                    }
555
                }
556
            }
557
        }
558
        // Insert language text and messages
559
        $tpl->set_var(array(
560
                            'TEXT_MANAGE_SECTIONS' => $HEADING['MANAGE_SECTIONS'],
561
                            'TEXT_ARE_YOU_SURE' => $TEXT['ARE_YOU_SURE'],
562
                            'TEXT_TYPE' => $TEXT['TYPE'],
563
                            'TEXT_ADD' => $TEXT['ADD'],
564
                            'TEXT_SAVE' =>  $TEXT['SAVE'],
565
                            'TEXTLINK_MODIFY_PAGE' => $HEADING['MODIFY_PAGE'],
566
                            'TEXT_CALENDAR' => $TEXT['CALENDAR'],
567
                            'TEXT_DELETE_DATE' => $TEXT['DELETE_DATE'],
568
                            'TEXT_ADD_SECTION' => $TEXT['ADD_SECTION'],
569
                            'TEXT_MOVE_UP' => $TEXT['MOVE_UP'],
570
                            'TEXT_MOVE_DOWN' => $TEXT['MOVE_DOWN']
571
                            )
572
                        );
573
        $tpl->set_block('main_block', 'show_settings_block', 'show_settings');
574
        if ($admin->get_permission('pages_settings')) {
575
            $tpl->parse('show_settings', 'show_settings_block', true);
576
        } else {
577
            $tpl->set_block('show_settings', '');
578
        }
579
        $tpl->parse('main', 'main_block', false);
580
        $tpl->pparse('output', 'page');
581
        // include the required file for Javascript admin
582
        if(file_exists(WB_PATH.'/modules/jsadmin/jsadmin_backend_include.php'))
583
        {
584
            include(WB_PATH.'/modules/jsadmin/jsadmin_backend_include.php');
585
        }
586
        break;
587
endswitch;
588

    
589
// Print admin footer
590
$admin->print_footer();
(19-19/25)