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

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

// Make sure people are allowed to access this page
if(MANAGE_SECTIONS != 'enabled')
{
    header('Location: '.ADMIN_URL.'/pages/index.php');
    exit(0);
}
/* */
$bDebug = false; // to show position and section_id
if(!defined('PAGE_DEBUG')) { define('PAGE_DEBUG',$bDebug);}
// Include the WB functions file
if ( !function_exists( 'create_access_file' ) ) { require(WB_PATH.'/framework/functions.php'); }
// Create new admin object
if ( !class_exists('admin', false) ) { require(WB_PATH.'/framework/class.admin.php'); }
$admin = new admin('Pages', 'pages_modify', false);
$action = 'show';
//$echo = $myPath;  //
// Get page id
$requestMethod = '_'.strtoupper($_SERVER['REQUEST_METHOD']);
$page_id = intval((isset(${$requestMethod}['page_id'])) ? ${$requestMethod}['page_id'] : 0);
$action = ($page_id ? 'show' : $action);
// Get section id if there is one
$requestMethod = '_'.strtoupper($_SERVER['REQUEST_METHOD']);
$section_id = ((isset(${$requestMethod}['section_id'])) ? ${$requestMethod}['section_id']  : 0);
$action = ($section_id ? 'delete' : $action);
// Get module if there is one
$requestMethod = '_'.strtoupper($_SERVER['REQUEST_METHOD']);
$module = ((isset(${$requestMethod}['module'])) ? ${$requestMethod}['module']  : 0);
$action = ($module != '' ? 'add' : $action);
$admin_header = true;
$backlink = ADMIN_URL.'/pages/sections.php?page_id='.(int)$page_id;
switch ($action):
    case 'delete' :
        if( (!($section_id = intval($admin->checkIDKEY('section_id', 0, $_SERVER['REQUEST_METHOD'])))) )
        {
            if($admin_header) { $admin->print_header(); }
            $sInfo = strtoupper(basename(__DIR__).'_'.basename(__FILE__, ''.PAGE_EXTENSION)).'_idkey::';
            $sDEBUG=(@DEBUG?$sInfo:'');
            $admin->print_error($sDEBUG.$MESSAGE['GENERIC_SECURITY_ACCESS'], $backlink);
        }
        $action = 'show';
        $sql  = 'SELECT `module` FROM `'.TABLE_PREFIX.'sections` ';
        $sql .= ' WHERE `section_id` ='.$section_id;
        if( ( ($modulname = $database->get_one($sql)) == $module) && ($section_id > 0 ) ) {
            // Include the modules delete file if it exists
            if(file_exists(WB_PATH.'/modules/'.$modulname.'/delete.php'))
            {
                require(WB_PATH.'/modules/'.$modulname.'/delete.php');
            }
            $sql  = 'DELETE FROM `'.TABLE_PREFIX.'sections` ';
            $sql .= 'WHERE `section_id` ='.(int)$section_id;
            if( !$database->query($sql) ) {
                if($admin_header) { $admin->print_header(); }
                $admin->print_error($database->get_error(),$backlink);
            }  else {
                if ( !class_exists( 'order', false ) ) { require(WB_PATH.'/framework/class.order.php'); }
                $order = new order(TABLE_PREFIX.'sections', 'position', 'section_id', 'page_id');
                $order->clean($page_id);
                $format = $TEXT['SECTION'].' %d  %s %s '.strtolower( $TEXT['DELETED']);
                $message = sprintf ($format,$section_id,strtoupper($modulname),strtolower($TEXT['SUCCESS']));
                if($admin_header) { $admin->print_header(); }
                $admin_header = false;
                unset($_POST);
                $admin->print_success($message, $backlink );
            }
        } else {
            if($admin_header) { $admin->print_header(); }
            $admin->print_error($module.' '.strtolower($TEXT['NOT_FOUND']), $backlink);
        }

        break;
    case 'add' :
        if (!$admin->checkFTAN())
        {
            $admin->print_header();
            $sInfo = strtoupper(basename(__DIR__).'_'.basename(__FILE__, ''.PAGE_EXTENSION)).'::';
            $sDEBUG=(@DEBUG?$sInfo:'');
            $admin->print_error($sDEBUG.$MESSAGE['GENERIC_SECURITY_ACCESS'], $backlink);
        }
        $action = 'show';
        $module = preg_replace('/\W/', '', $module );  // fix secunia 2010-91-4
        require_once(WB_PATH.'/framework/class.order.php');
        // Get new order
        $order = new order(TABLE_PREFIX.'sections', 'position', 'section_id', 'page_id');
        $position = $order->get_new($page_id);
        // Insert module into DB
        $sql  = 'INSERT INTO `'.TABLE_PREFIX.'sections` SET '
              . '`page_id` = '.(int)$page_id.', '
              . '`module` = \''.$module.'\', '
              . '`position` = '.(int)$position.', '
              . '`block` = 1';
        if($database->query($sql)) {
            // Get the section id
            $section_id = $database->get_one("SELECT LAST_INSERT_ID()");
            // Include the selected modules add file if it exists
            if (
                file_exists(WB_PATH.'/modules/'.$module.'/addon.php') &&
                file_exists(WB_PATH.'/modules/'.$module.'/cmd/cmdModify.inc')
            ) { break; }
            if(file_exists(WB_PATH.'/modules/'.$module.'/add.php'))
            {
                require(WB_PATH.'/modules/'.$module.'/add.php');
            }
        } elseif ($database->is_error())  {
            if($admin_header) { $admin->print_header(); }
            $admin->print_error($database->get_error());
        }
        break;
    default:
        break;
endswitch;

switch ($action):
    default:
        if($admin_header) { $admin->print_header(); }
        // Get perms
        $sql  = 'SELECT `admin_groups`,`admin_users` FROM `'.TABLE_PREFIX.'pages` '
              . 'WHERE `page_id` = '.$page_id;
        $oPages = $database->query($sql);
        $aPages = $oPages->fetchRow(MYSQLI_ASSOC);
        $in_old_group = $admin->is_group_match($aPages['admin_groups'],$admin->get_groups_id());
/*
        $old_admin_groups = explode(',', $aPages['admin_groups']);
        $old_admin_users  = explode(',', $aPages['admin_users']);
        $in_old_group = false;
        foreach($admin->get_groups_id() as $cur_gid)
        {
            if (in_array($cur_gid, $old_admin_groups))
            {
                $in_old_group = true;
            }
        }
*/
        if ((!$in_old_group) && !is_numeric(array_search($admin->get_user_id(), $old_admin_users)))
        {
            $admin->print_header();
            $sInfo = strtoupper(basename(__DIR__).'_'.basename(__FILE__, ''.PAGE_EXTENSION)).'::';
            $sDEBUG=(@DEBUG?$sInfo:'');
            $admin->print_error($sDEBUG.$MESSAGE['PAGES_INSUFFICIENT_PERMISSIONS']);
        }
        // Get page details
        $sql  = 'SELECT * FROM `'.TABLE_PREFIX.'pages` '
              . 'WHERE `page_id` = '.$page_id;
        $results = $database->query($sql);
        if($database->is_error())
        {
            // $admin->print_header();
            $admin->print_error($database->get_error());
        }
        if($results->numRows() == 0)
        {
            // $admin->print_header();
            $admin->print_error($MESSAGE['PAGES_NOT_FOUND']);
        }
        $results_array = $results->fetchRow(MYSQLI_ASSOC);
        // Set module permissions
        $aAllowedModules = array();
        $sAllowedModules = '';
        $module_permissions = $_SESSION['MODULE_PERMISSIONS'];
        $sAllowedModules = implode(', ',
                           array_map(function(&$item) use ($database){
                                         return '\''.$database->escapeString($item) .'\'';
                                     }, $module_permissions));
        $sqlAddons  = 'SELECT * FROM `'.TABLE_PREFIX.'addons` '
                    . 'WHERE `type` = \'module\' '
                    .   ($sAllowedModules?'AND `directory` NOT IN ('.$sAllowedModules.')' :'')
                    . 'ORDER BY `name`';
        if($oAddons = $database->query($sqlAddons))
        {
            while($aAddons = $oAddons->fetchRow(MYSQLI_ASSOC))
            {
               $aAllowedModules[] = $aAddons['directory'];
            }
        }

        $sAllowedModules = '';
        $sAllowedModules = implode(', ',
                           array_map(function(&$item) use ($database){
                                         return '\''.$database->escapeString($item) .'\'';
                                     }, $aAllowedModules));
        // Unset block var
        unset($block);
        // Include template info file (if it exists)
        if($results_array['template'] != '')
        {
            $template_location = WB_PATH.'/templates/'.$results_array['template'].'/info.php';
        } else {
            $template_location = WB_PATH.'/templates/'.DEFAULT_TEMPLATE.'/info.php';
        }
        if(file_exists($template_location))
        {
            require($template_location);
        }
        // Check if $menu is set
        if(!isset($block[1]) || $block[1] == '')
        {
            // Make our own menu list
            $block[1] = $TEXT['MAIN'];
        }
        // Get display name of person who last modified the page
        $user=$admin->get_user_details($results_array['modified_by']);
        // Convert the unix ts for modified_when to human a readable form
        if($results_array['modified_when'] != 0)
        {
            $modified_ts = gmdate(TIME_FORMAT.', '.DATE_FORMAT, $results_array['modified_when']+TIMEZONE);
        } else {
            $modified_ts = 'Unknown';
        }
        /*-- load css files with jquery --*/
        // include jscalendar-setup
        $jscal_use_time = true; // whether to use a clock, too
        require_once(WB_PATH."/include/jscalendar/wb-setup.php");
        // Setup template object, parse vars to it, then parse it
        // Create new template object
        $tpl = new Template(dirname($admin->correct_theme_source('pages_sections.htt')));
        // $template->debug = true;
        $tpl->set_file('page', 'pages_sections.htt');
        $tpl->set_block('page', 'main_block', 'main');
        $tpl->set_block('main_block', 'module_block', 'module_list');
        $tpl->set_block('main_block', 'show_section_block', 'show_section');
        $tpl->set_block('main_block', 'calendar_block', 'calendar_list');
        $tpl->set_var('FTAN', $admin->getFTAN());
        // setting trash only if more than one section exists
        $tpl->set_block('show_section_block', 'can_delete_block', 'can_delete');
        $sql = 'SELECT COUNT(*) FROM `'.TABLE_PREFIX.'sections` '
             . 'WHERE `page_id`='.intval($page_id).' '
             .   'AND `module` IN ('.$sAllowedModules.')';
        $bSectionCanDelete = ($database->get_one($sql) > 1);
        // set first defaults and messages
        $tpl->set_var(array(
                        'PAGE_ID' => $results_array['page_id'],
                        // 'PAGE_IDKEY' => $admin->getIDKEY($results_array['page_id']),
                        'PAGE_IDKEY' => $results_array['page_id'],
                        'TEXT_PAGE' => $TEXT['PAGE'],
                        'TIMEZONE' => 'TIMEZONE',
                        'PAGE_TITLE' => ($results_array['page_title']),
                        'MENU_TITLE' => ($results_array['menu_title']),
                        'TEXT_CURRENT_PAGE' => $TEXT['CURRENT_PAGE'],
                        'HEADING_MANAGE_SECTIONS' => $HEADING['MANAGE_SECTIONS'],
                        'HEADING_MODIFY_PAGE' => $HEADING['MODIFY_PAGE'],
                        'TEXT_CHANGE_SETTINGS' => $TEXT['CHANGE_SETTINGS'],
                        'TEXT_ADD_SECTION' => $TEXT['ADD_SECTION'],
                        'TEXT_ID' => 'ID',
                        'TEXT_TYPE' => $TEXT['TYPE'],
                        'TEXT_BLOCK' => $TEXT['BLOCK'],
                        'TEXT_PUBL_START_DATE' => $TEXT{'PUBL_START_DATE'},
                        'TEXT_PUBL_END_DATE' => $TEXT['PUBL_END_DATE'],
                        'TEXT_ACTIONS' => $TEXT['ACTIONS'],
                        'TEXT_MODIFY' => $TEXT['MODIFY'],
                        'TEXT_MODIFY_PAGE' => $HEADING['MODIFY_PAGE'],
                        'LAST_MODIFIED' => $MESSAGE['PAGES']['LAST_MODIFIED'],
                        'MODIFIED_BY' => $user['display_name'],
                        'MODIFIED_BY_USERNAME' => $user['username'],
                        'MODIFIED_WHEN' => $modified_ts,
                        'ADMIN_URL' => ADMIN_URL,
                        'WB_URL' => WB_URL,
                        'THEME_URL' => THEME_URL
                        )
                    );
        // Insert variables
        $tpl->set_var(array(
                        'PAGE_ID' => $results_array['page_id'],
                        // 'PAGE_IDKEY' => $admin->getIDKEY($results_array['page_id']),
                        'PAGE_IDKEY' => $results_array['page_id'],
                        'VAR_PAGE_TITLE' => $results_array['page_title'],
                        'SETTINGS_LINK' => ADMIN_URL.'/pages/settings.php?page_id='.$results_array['page_id'],
                        'MODIFY_LINK' => ADMIN_URL.'/pages/modify.php?page_id='.$results_array['page_id']
                        )
                    );
        $tpl->set_block('show_section_block', 'section_list_block', 'section_list');
        $tpl->set_block('show_section_block', 'section_title_block', 'section_title');
        $sqlSections  = 'SELECT * FROM `'.TABLE_PREFIX.'sections` '
                      . 'WHERE `page_id` = '.(int)$page_id.' '
                      . 'ORDER BY `position`';
//        $query_sections = $database->query($sql);
        if ($query_sections = $database->query($sqlSections))
        {
            $num_sections = $query_sections->numRows();
            $section = array();
            while($section = $query_sections->fetchRow(MYSQLI_ASSOC))
            {
                if(!is_numeric(array_search($section['module'], $module_permissions)))
                {
                    // Get the modules real name
                    $sql = 'SELECT `name` FROM `'.TABLE_PREFIX.'addons` '
                         . 'WHERE `directory` = "'.$section['module'].'"';
                    if(!$database->get_one($sql) || !file_exists(WB_PATH.'/modules/'.$section['module']))
                    {
                        $edit_page = '<span class="module_disabled">'.$section['module'].'</span>';
                        $section['title'] = $MESSAGE['GENERIC_NOT_INSTALLED'];
                    }else
                    {
                        $edit_page = '';
                    }
                    $sec_anchor = (defined( 'SEC_ANCHOR' ) && ( SEC_ANCHOR != '' )  ? SEC_ANCHOR : '');
                    $edit_page_0 = '<a id="sid'.$section['section_id'].'" href="'.ADMIN_URL.'/pages/modify.php?page_id='.$results_array['page_id'];
                    $edit_page_1  = ($sec_anchor!='') ? '#'.$sec_anchor.$section['section_id'].'">' : '">';
                    $edit_page_1 .= $section['module'].'</a>';

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

                    if(SECTION_BLOCKS)
                    {
                        if($edit_page == '')
                        {
                            if(defined('EDIT_ONE_SECTION') && EDIT_ONE_SECTION)
                            {
                                $edit_page = $edit_page_0.'&amp;wysiwyg='.$section['section_id'].$edit_page_1;
                            } else {
                                $edit_page = $edit_page_0.$edit_page_1;
                            }
                        }
                        $input_attribute = 'input_normal';
                        $tpl->set_var(array(
                                'STYLE_DISPLAY_SECTION_BLOCK' => ' style="visibility:visible;"',
                                'NAME_SIZE' => 300,
                                'INPUT_ATTRIBUTE' => $input_attribute,
                                'VAR_SECTION_ID' => $section['section_id'],
                                'VAR_SECTION_IDKEY' => $admin->getIDKEY($section['section_id']),
                                // 'VAR_SECTION_IDKEY' => $section['section_id'],
                                'VAR_POSITION' => $section['position'],
                                'LINK_MODIFY_URL_VAR_MODUL_NAME' => $edit_page,
                                'SELECT' => '',
                                'SET_NONE_DISPLAY_OPTION' => ''
                                )
                            );
                        // Add block options to the section_list
                        $tpl->clear_var('section_list');

                        foreach($block AS $number => $name)
                        {
                            $tpl->set_var('NAME', htmlentities(strip_tags($name)));
                            $tpl->set_var('VALUE', $number);
                            $tpl->set_var('SIZE', 1);
                            if($section['block'] == $number)
                            {
                                $tpl->set_var('SELECTED', ' selected="selected"');
                            } else {
                                $tpl->set_var('SELECTED', '');
                            }
                            $tpl->parse('section_list', 'section_list_block', true);
                        }
                    } else {
                        if($edit_page == '')
                        {
                            $edit_page = $edit_page_0.'#wb_'.$edit_page_1;
                        }

                        $input_attribute = 'input_normal';
                        $tpl->set_var(array(
                                'STYLE_DISPLAY_SECTION_BLOCK' => ' style="visibility:hidden;"',
                                'NAME_SIZE' => 300,
                                'INPUT_ATTRIBUTE' => $input_attribute,
                                'VAR_SECTION_ID' => $section['section_id'],
                                'VAR_SECTION_IDKEY' => $admin->getIDKEY($section['section_id']),
                                // 'VAR_SECTION_IDKEY' => $section['section_id'],
                                'VAR_POSITION' => $section['position'],
                                'LINK_MODIFY_URL_VAR_MODUL_NAME' => $edit_page,
                                'NAME' => htmlentities(strip_tags($block[1])),
                                'VALUE' => 1,
                                'SET_NONE_DISPLAY_OPTION' => ''
                                )
                            );
                    }
                    // Insert icon and images
                    $tpl->set_var(array(
                                'CLOCK_16_PNG' => 'clock_16.png',
                                'CLOCK_DEL_16_PNG' => 'clock_del_16.png',
                                'DELETE_16_PNG' => 'delete_16.png'
                                )
                            );
                    // set calendar start values
                    if($section['publ_start']==0)
                    {
                        $tpl->set_var('VALUE_PUBL_START', '');
                    } else {
                        $tpl->set_var('VALUE_PUBL_START', date($jscal_format, $section['publ_start']+TIMEZONE));
                    }
                    // set calendar start values
                    if($section['publ_end']==0)
                    {
                        $tpl->set_var('VALUE_PUBL_END', '');
                    } else {
                        $tpl->set_var('VALUE_PUBL_END', date($jscal_format, $section['publ_end']+TIMEZONE));
                    }
                    // Insert icons up and down
                    if($section['position'] != 1 )
                    {
                        $tpl->set_var(
                                    'VAR_MOVE_UP_URL',
                                    '<a href="'.ADMIN_URL.'/pages/move_up.php?page_id='.$page_id.'&amp;section_id='.$section['section_id'].'">
                                    <img src="'.THEME_URL.'/images/up_16.png" alt="up" />
                                    </a>' );
                    } else {
                        $tpl->set_var(array(
                                    'VAR_MOVE_UP_URL' => ''
                                    )
                                );
                    }
                    if($section['position'] != $num_sections ) {
                        $tpl->set_var(
                                    'VAR_MOVE_DOWN_URL',
                                    '<a href="'.ADMIN_URL.'/pages/move_down.php?page_id='.$page_id.'&amp;section_id='.$section['section_id'].'">
                                    <img src="'.THEME_URL.'/images/down_16.png" alt="down" />
                                    </a>' );
                    } else {
                        $tpl->set_var(array(
                                    'VAR_MOVE_DOWN_URL' => ''
                                    )
                                );
                    }
                } else {
                  continue;
                }
                    $tpl->set_var(array(
                                    'DISPLAY_DEBUG' => ' style="visibility="visible;"',
                                    'TEXT_SID' => 'SID',
                                    'DEBUG_COLSPAN_SIZE' => 9
                                    )
                                );
                if($bDebug)
                {
                    $tpl->set_var(array(
                                    'DISPLAY_DEBUG' => ' style="visibility="visible;"',
                                    'TEXT_PID' => 'PID',
                                    'TEXT_SID' => 'SID',
                                    'POSITION' => $section['position']
                                    )
                                );
                } else {
                    $tpl->set_var(array(
                                    'DISPLAY_DEBUG' => ' style="display:none;"',
                                    'TEXT_PID' => '',
                                    'POSITION' => ''
                                    )
                                );
                }
            if($bSectionCanDelete) {
                $tpl->parse('can_delete', 'can_delete_block', false);
            } else {
//                $tpl->parse('can_delete', '', false);
                $tpl->set_block('can_delete_block', '');
            }
            $tpl->parse('show_section', 'show_section_block', true);
            }
        }

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

        if($query_sections->numRows() > 0)
        {
            $num_sections = $query_sections->numRows();
            while($section = $query_sections->fetchRow())
            {
                // Get the modules real name
                $sql  = 'SELECT `name` FROM `'.TABLE_PREFIX.'addons` '
                      . 'WHERE `directory` = "'.$section['module'].'"';
                $module_name = $database->get_one($sql);

                if(!is_numeric(array_search($section['module'], $module_permissions)))
                {
                    $tpl->set_var(array(
                                'jscal_ifformat' => $jscal_ifformat,
                                'jscal_firstday' => $jscal_firstday,
                                'jscal_today' => $jscal_today,
                                'start_date' => 'start_date'.$section['section_id'],
                                'end_date' => 'end_date'.$section['section_id'],
                                'trigger_start' => 'trigger_start'.$section['section_id'],
                                'trigger_end' => 'trigger_stop'.$section['section_id']
                                )
                            );
                    if(isset($jscal_use_time) && $jscal_use_time==TRUE) {
                        $tpl->set_var(array(
                                'showsTime' => "true",
                                'timeFormat' => "24"
                                )
                            );
                    }  else {
                        $tpl->set_var(array(
                                'showsTime' => "false",
                                'timeFormat' => "24"
                                )
                            );
                    }
                }
                $tpl->parse('calendar_list', 'calendar_block', true);
            }
        }

        // Work-out if we should show the "Add Section" form
        $sql  = 'SELECT `section_id` FROM `'.TABLE_PREFIX.'sections` '
              . 'WHERE `page_id` = '.$page_id.' AND `module` = "menu_link"';
        $query_sections = $database->query($sql);
        if($query_sections->numRows() == 0)
        {
            // Modules list
            $sql  = 'SELECT `name`,`directory`,`type` FROM `'.TABLE_PREFIX.'addons` '
                  . 'WHERE `type` = \'module\' '
                  .   'AND `function` = \'page\' '
                  .   'AND `directory` != \'menu_link\' '
                  . 'ORDER BY `name`';
            $result = $database->query($sql);
        // if(DEBUG && $database->is_error()) { $admin->print_error($database->get_error()); }
            if($result->numRows() > 0)
            {
                while ($module = $result->fetchRow(MYSQLI_ASSOC))
                {
                    // Check if user is allowed to use this module   echo  $module['directory'],'<br />';
                    if(!is_numeric(array_search($module['directory'], $module_permissions)))
                    {
                        $tpl->set_var('VALUE', $module['directory']);
                        $tpl->set_var('NAME', $module['name']);
                        if($module['directory'] == 'wysiwyg')
                        {
                            $tpl->set_var('SELECTED', ' selected="selected"');
                        } else {
                            $tpl->set_var('SELECTED', '');
                        }
                        $tpl->parse('module_list', 'module_block', true);
                    } else {
                      continue;
                    }
                }
            }
        }
        // Insert language text and messages
        $tpl->set_var(array(
                            'TEXT_MANAGE_SECTIONS' => $HEADING['MANAGE_SECTIONS'],
                            'TEXT_ARE_YOU_SURE' => $TEXT['ARE_YOU_SURE'],
                            'TEXT_TYPE' => $TEXT['TYPE'],
                            'TEXT_ADD' => $TEXT['ADD'],
                            'TEXT_SAVE' =>  $TEXT['SAVE'],
                            'TEXTLINK_MODIFY_PAGE' => $HEADING['MODIFY_PAGE'],
                            'TEXT_CALENDAR' => $TEXT['CALENDAR'],
                            'TEXT_DELETE_DATE' => $TEXT['DELETE_DATE'],
                            'TEXT_ADD_SECTION' => $TEXT['ADD_SECTION'],
                            'TEXT_MOVE_UP' => $TEXT['MOVE_UP'],
                            'TEXT_MOVE_DOWN' => $TEXT['MOVE_DOWN']
                            )
                        );
        $tpl->set_block('main_block', 'show_settings_block', 'show_settings');
        if ($admin->get_permission('pages_settings')) {
            $tpl->parse('show_settings', 'show_settings_block', true);
        } else {
            $tpl->set_block('show_settings', '');
        }
        $tpl->parse('main', 'main_block', false);
        $tpl->pparse('output', 'page');
        // include the required file for Javascript admin
        if(file_exists(WB_PATH.'/modules/jsadmin/jsadmin_backend_include.php'))
        {
            include(WB_PATH.'/modules/jsadmin/jsadmin_backend_include.php');
        }
        break;
endswitch;

// Print admin footer
$admin->print_footer();
