| 1 | 
        
            2
         | 
        
            Manuela
         | 
        <?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$
  | 
      
      
        | 14 | 
        
         | 
        
         | 
         * @filesource      $HeadURL$
  | 
      
      
        | 15 | 
        
         | 
        
         | 
         * @lastmodified    $Date$
  | 
      
      
        | 16 | 
        
         | 
        
         | 
         *
  | 
      
      
        | 17 | 
        
         | 
        
         | 
         */
  | 
      
      
        | 18 | 
        
         | 
        
         | 
        /* ****************************************************************** */
  | 
      
      
        | 19 | 
        
         | 
        
         | 
        // Function to fix page trail of subs
  | 
      
      
        | 20 | 
        
         | 
        
         | 
        function fix_page_trail($parent,$root_parent)
  | 
      
      
        | 21 | 
        
         | 
        
         | 
        {
 | 
      
      
        | 22 | 
        
         | 
        
         | 
            // Get objects and vars from outside this function
  | 
      
      
        | 23 | 
        
         | 
        
         | 
            global $admin, $template, $database, $TEXT, $MESSAGE;
  | 
      
      
        | 24 | 
        
         | 
        
         | 
            // Get page list from database
  | 
      
      
        | 25 | 
        
         | 
        
         | 
            // $database = new database();
  | 
      
      
        | 26 | 
        
         | 
        
         | 
            $sql = 'SELECT `page_id` FROM `'.TABLE_PREFIX.'pages` '
  | 
      
      
        | 27 | 
        
         | 
        
         | 
                 . 'WHERE `parent`='.(int)$parent;
  | 
      
      
        | 28 | 
        
         | 
        
         | 
            // Insert values into main page list
  | 
      
      
        | 29 | 
        
         | 
        
         | 
            if (($get_pages = $database->query($sql))) {
 | 
      
      
        | 30 | 
        
         | 
        
         | 
            // Insert values into main page list
  | 
      
      
        | 31 | 
        
         | 
        
         | 
                while($page = $get_pages->fetchRow(MYSQLI_ASSOC)) {
 | 
      
      
        | 32 | 
        
         | 
        
         | 
                    // Fix page trail
  | 
      
      
        | 33 | 
        
         | 
        
         | 
                    $sql = 'UPDATE `'.TABLE_PREFIX.'pages` '
  | 
      
      
        | 34 | 
        
         | 
        
         | 
                         . 'SET `page_trail`=\''.get_page_trail($page['page_id']).'\' '
  | 
      
      
        | 35 | 
        
         | 
        
         | 
                         .     ($root_parent != 0 ? ',`root_parent`='.(int)$root_parent.' ' : '')
  | 
      
      
        | 36 | 
        
         | 
        
         | 
                         . 'WHERE `page_id`='.(int)$page['page_id'];
  | 
      
      
        | 37 | 
        
         | 
        
         | 
                    $database->query($sql);
  | 
      
      
        | 38 | 
        
         | 
        
         | 
                    // Run this query on subs
  | 
      
      
        | 39 | 
        
         | 
        
         | 
                    fix_page_trail($page['page_id'],$root_parent);
  | 
      
      
        | 40 | 
        
         | 
        
         | 
                }
  | 
      
      
        | 41 | 
        
         | 
        
         | 
            }
  | 
      
      
        | 42 | 
        
         | 
        
         | 
        }
  | 
      
      
        | 43 | 
        
         | 
        
         | 
        /* ****************************************************************** */
  | 
      
      
        | 44 | 
        
         | 
        
         | 
        // inherit settings to subpages
  | 
      
      
        | 45 | 
        
         | 
        
         | 
        // <Subpages should inherit settings.>
  | 
      
      
        | 46 | 
        
         | 
        
         | 
        /*
  | 
      
      
        | 47 | 
        
         | 
        
         | 
         * inheritable settings:
  | 
      
      
        | 48 | 
        
         | 
        
         | 
         *   template
  | 
      
      
        | 49 | 
        
         | 
        
         | 
         *   language
  | 
      
      
        | 50 | 
        
         | 
        
         | 
         *   menu
  | 
      
      
        | 51 | 
        
         | 
        
         | 
         *   searching
  | 
      
      
        | 52 | 
        
         | 
        
         | 
         *   visibility
  | 
      
      
        | 53 | 
        
         | 
        
         | 
         *   - admin_groups
  | 
      
      
        | 54 | 
        
         | 
        
         | 
         *   - admin_users
  | 
      
      
        | 55 | 
        
         | 
        
         | 
         *   - viewing_groups
  | 
      
      
        | 56 | 
        
         | 
        
         | 
         *   - viewing_users
  | 
      
      
        | 57 | 
        
         | 
        
         | 
         */
  | 
      
      
        | 58 | 
        
         | 
        
         | 
        
  | 
      
      
        | 59 | 
        
         | 
        
         | 
        function doInheritSettings($database, $page_id, array $aSettings)
  | 
      
      
        | 60 | 
        
         | 
        
         | 
        {
 | 
      
      
        | 61 | 
        
         | 
        
         | 
            // deactivate doInheritSettings
  | 
      
      
        | 62 | 
        
         | 
        
         | 
            if (sizeof($aSettings)==0){return false;}
 | 
      
      
        | 63 | 
        
         | 
        
         | 
            $sqlSet = '';
  | 
      
      
        | 64 | 
        
         | 
        
         | 
            foreach ($aSettings as $sFieldname=>$sValue) {
 | 
      
      
        | 65 | 
        
         | 
        
         | 
                $sqlSet .= '`'.$sFieldname.'`=\''.$database->escapeString($sValue).'\', ';
  | 
      
      
        | 66 | 
        
         | 
        
         | 
            }
  | 
      
      
        | 67 | 
        
         | 
        
         | 
            $sqlSet = rtrim($sqlSet, ' ,');
  | 
      
      
        | 68 | 
        
         | 
        
         | 
            if ($sqlSet) {
 | 
      
      
        | 69 | 
        
         | 
        
         | 
                $aListOfChildren = array();
  | 
      
      
        | 70 | 
        
         | 
        
         | 
                $aMatches = array($page_id);
  | 
      
      
        | 71 | 
        
         | 
        
         | 
                // search all children
  | 
      
      
        | 72 | 
        
         | 
        
         | 
                do {
 | 
      
      
        | 73 | 
        
         | 
        
         | 
                    $sql = 'SELECT `page_id` FROM `'.TABLE_PREFIX.'pages` '
  | 
      
      
        | 74 | 
        
         | 
        
         | 
                         . 'WHERE `parent` IN('.implode(',', $aMatches).')';
 | 
      
      
        | 75 | 
        
         | 
        
         | 
                    if (($oChildren = $database->query($sql))) {
 | 
      
      
        | 76 | 
        
         | 
        
         | 
                        $aMatches = array();
  | 
      
      
        | 77 | 
        
         | 
        
         | 
                        while (($aChild = $oChildren->fetchRow(MYSQL_ASSOC))) {
 | 
      
      
        | 78 | 
        
         | 
        
         | 
                            $aMatches[] = $aChild['page_id'];
  | 
      
      
        | 79 | 
        
         | 
        
         | 
                        }
  | 
      
      
        | 80 | 
        
         | 
        
         | 
                        $aListOfChildren = array_merge($aListOfChildren, $aMatches);
  | 
      
      
        | 81 | 
        
         | 
        
         | 
                    }
  | 
      
      
        | 82 | 
        
         | 
        
         | 
                } while (sizeof($aMatches) > 0);
  | 
      
      
        | 83 | 
        
         | 
        
         | 
                $sqlSet = 'UPDATE `'.TABLE_PREFIX.'pages` SET '.$sqlSet.' '
  | 
      
      
        | 84 | 
        
         | 
        
         | 
                        . 'WHERE `page_id` IN('.implode(',', $aListOfChildren).')';
 | 
      
      
        | 85 | 
        
         | 
        
         | 
                $database->query($sqlSet);
  | 
      
      
        | 86 | 
        
         | 
        
         | 
            }
  | 
      
      
        | 87 | 
        
         | 
        
         | 
        }
  | 
      
      
        | 88 | 
        
         | 
        
         | 
        /* ****************************************************************** */
  | 
      
      
        | 89 | 
        
         | 
        
         | 
        
  | 
      
      
        | 90 | 
        
         | 
        
         | 
        // Create new admin object and print admin header
  | 
      
      
        | 91 | 
        
         | 
        
         | 
        if ( !defined( 'WB_PATH' ) ){ require( dirname(dirname((__DIR__))).'/config.php' ); }
 | 
      
      
        | 92 | 
        
         | 
        
         | 
        if ( !class_exists('admin', false) ) { require(WB_PATH.'/framework/class.admin.php'); }
 | 
      
      
        | 93 | 
        
         | 
        
         | 
        // suppress to print the header, so no new FTAN will be set
  | 
      
      
        | 94 | 
        
         | 
        
         | 
        $admin = new admin('Pages', 'pages_settings',false);
 | 
      
      
        | 95 | 
        
         | 
        
         | 
        // Get page id
  | 
      
      
        | 96 | 
        
         | 
        
         | 
        if(!isset($_POST['page_id']) || !is_numeric($_POST['page_id']))
  | 
      
      
        | 97 | 
        
         | 
        
         | 
        {
 | 
      
      
        | 98 | 
        
         | 
        
         | 
            $admin->print_header();
  | 
      
      
        | 99 | 
        
         | 
        
         | 
            $admin->print_error($MESSAGE['PAGES_NOT_FOUND']);
  | 
      
      
        | 100 | 
        
         | 
        
         | 
        } else {
 | 
      
      
        | 101 | 
        
         | 
        
         | 
            $page_id = (int)$_POST['page_id'];
  | 
      
      
        | 102 | 
        
         | 
        
         | 
        }
  | 
      
      
        | 103 | 
        
         | 
        
         | 
        $target_url = ADMIN_URL.'/pages/settings.php?page_id='.$page_id;
  | 
      
      
        | 104 | 
        
         | 
        
         | 
        $pagetree_url = ADMIN_URL.'/pages/index.php';
  | 
      
      
        | 105 | 
        
         | 
        
         | 
        $bBackLink = isset($_POST['pagetree']);
  | 
      
      
        | 106 | 
        
         | 
        
         | 
        /*
  | 
      
      
        | 107 | 
        
         | 
        
         | 
        if( (!($page_id = $admin->checkIDKEY('page_id', 0, $_SERVER['REQUEST_METHOD']))) )
 | 
      
      
        | 108 | 
        
         | 
        
         | 
        {
 | 
      
      
        | 109 | 
        
         | 
        
         | 
            $admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS']);
  | 
      
      
        | 110 | 
        
         | 
        
         | 
        }
  | 
      
      
        | 111 | 
        
         | 
        
         | 
        */
  | 
      
      
        | 112 | 
        
         | 
        
         | 
        if (!$admin->checkFTAN())
  | 
      
      
        | 113 | 
        
         | 
        
         | 
        {
 | 
      
      
        | 114 | 
        
         | 
        
         | 
            $admin->print_header();
  | 
      
      
        | 115 | 
        
         | 
        
         | 
            $sInfo = strtoupper(basename(__DIR__).'_'.basename(__FILE__, ''.PAGE_EXTENSION)).'::';
  | 
      
      
        | 116 | 
        
         | 
        
         | 
            $sDEBUG=(@DEBUG?$sInfo:'');
  | 
      
      
        | 117 | 
        
         | 
        
         | 
            $admin->print_error($sDEBUG.$MESSAGE['GENERIC_SECURITY_ACCESS'], $target_url);
  | 
      
      
        | 118 | 
        
         | 
        
         | 
        }
  | 
      
      
        | 119 | 
        
         | 
        
         | 
        // After FTAN check print the header
  | 
      
      
        | 120 | 
        
         | 
        
         | 
        $admin->print_header();
  | 
      
      
        | 121 | 
        
         | 
        
         | 
        // Include the WB functions file
  | 
      
      
        | 122 | 
        
         | 
        
         | 
        if ( !function_exists( 'create_access_file' ) ) { require(WB_PATH.'/framework/functions.php'); }
 | 
      
      
        | 123 | 
        
         | 
        
         | 
        // Get values
  | 
      
      
        | 124 | 
        
         | 
        
         | 
        $page_title = $admin->StripCodeFromText($admin->get_post('page_title'));
 | 
      
      
        | 125 | 
        
         | 
        
         | 
        $menu_title = $admin->StripCodeFromText($admin->get_post('menu_title'));
 | 
      
      
        | 126 | 
        
         | 
        
         | 
        $seo_title = $admin->StripCodeFromText($admin->get_post('seo_title'));
 | 
      
      
        | 127 | 
        
         | 
        
         | 
        $page_code = intval($admin->get_post('page_code')) ;
 | 
      
      
        | 128 | 
        
         | 
        
         | 
        $description = $admin->StripCodeFromText($admin->get_post('description'));
 | 
      
      
        | 129 | 
        
         | 
        
         | 
        $keywords = $admin->StripCodeFromText($admin->get_post('keywords'));
 | 
      
      
        | 130 | 
        
         | 
        
         | 
        $parent = intval($admin->get_post('parent')); // fix secunia 2010-91-3
 | 
      
      
        | 131 | 
        
         | 
        
         | 
        $visibility = $admin->StripCodeFromText($admin->get_post('visibility'));
 | 
      
      
        | 132 | 
        
         | 
        
         | 
        if (!in_array($visibility, array('public', 'private', 'registered', 'hidden', 'none'))) {$visibility = 'public';} // fix secunia 2010-93-3
 | 
      
      
        | 133 | 
        
         | 
        
         | 
        $template = preg_replace('/[^a-z0-9_-]/i', "", $admin->get_post('template')); // fix secunia 2010-93-3
 | 
      
      
        | 134 | 
        
         | 
        
         | 
        $template = (($template == DEFAULT_TEMPLATE ) ? '' : $template);
  | 
      
      
        | 135 | 
        
         | 
        
         | 
        $target = preg_replace("/\W/", "", $admin->get_post('target'));
 | 
      
      
        | 136 | 
        
         | 
        
         | 
        $admin_groups = ($admin->get_post('admin_groups'));
 | 
      
      
        | 137 | 
        
         | 
        
         | 
        $viewing_groups = ($admin->get_post('viewing_groups'));
 | 
      
      
        | 138 | 
        
         | 
        
         | 
        $searching = intval($admin->get_post('searching'));
 | 
      
      
        | 139 | 
        
         | 
        
         | 
        $language = $admin->StripCodeFromText(strtoupper($admin->get_post('language')));
 | 
      
      
        | 140 | 
        
         | 
        
         | 
        $language = (preg_match('/^[A-Z]{2}$/', $language) ? $language : DEFAULT_LANGUAGE);
 | 
      
      
        | 141 | 
        
         | 
        
         | 
        $menu = intval($admin->get_post('menu')); // fix secunia 2010-91-3
 | 
      
      
        | 142 | 
        
         | 
        
         | 
        // Validate data
  | 
      
      
        | 143 | 
        
         | 
        
         | 
        if($menu_title == '' || substr($menu_title,0,1)=='.'){
 | 
      
      
        | 144 | 
        
         | 
        
         | 
            $admin->print_error($MESSAGE['PAGES_BLANK_MENU_TITLE']);
  | 
      
      
        | 145 | 
        
         | 
        
         | 
        }
  | 
      
      
        | 146 | 
        
         | 
        
         | 
        if ( $page_title  == '' || substr( $page_title, 0, 1) == '.') { $page_title = $menu_title; }
 | 
      
      
        | 147 | 
        
         | 
        
         | 
        if ( $seo_title   == '' || substr( $seo_title, 0, 1)  == '.') { $seo_title  = $menu_title; }
 | 
      
      
        | 148 | 
        
         | 
        
         | 
        // fetch old datas
  | 
      
      
        | 149 | 
        
         | 
        
         | 
        $sql = 'SELECT `level`,`root_parent`, `parent`,`page_trail`,`link`,`position`,`admin_groups`,`admin_users` FROM `'.TABLE_PREFIX.'pages` '
  | 
      
      
        | 150 | 
        
         | 
        
         | 
             . 'WHERE `page_id`='.$page_id;
  | 
      
      
        | 151 | 
        
         | 
        
         | 
        $oPages = $database->query($sql);
  | 
      
      
        | 152 | 
        
         | 
        
         | 
        $results_array = $oPages->fetchRow(MYSQLI_ASSOC);
  | 
      
      
        | 153 | 
        
         | 
        
         | 
        $old_parent   = $results_array['parent'];
  | 
      
      
        | 154 | 
        
         | 
        
         | 
        $old_link     = $results_array['link'];
  | 
      
      
        | 155 | 
        
         | 
        
         | 
        $old_position = $results_array['position'];
  | 
      
      
        | 156 | 
        
         | 
        
         | 
        $old_admin_groups = explode(',', str_replace('_', '', $results_array['admin_groups']));
 | 
      
      
        | 157 | 
        
         | 
        
         | 
        $old_admin_users  = explode(',', str_replace('_', '', $results_array['admin_users']));
 | 
      
      
        | 158 | 
        
         | 
        
         | 
        // Work-out if we should check for existing page_code
  | 
      
      
        | 159 | 
        
         | 
        
         | 
        $field_set = $database->field_exists(TABLE_PREFIX.'pages', 'page_code');
  | 
      
      
        | 160 | 
        
         | 
        
         | 
        $in_old_group = FALSE;
  | 
      
      
        | 161 | 
        
         | 
        
         | 
        foreach($admin->get_groups_id() as $cur_gid){
 | 
      
      
        | 162 | 
        
         | 
        
         | 
            if (in_array($cur_gid, $old_admin_groups)) { $in_old_group = TRUE; }
 | 
      
      
        | 163 | 
        
         | 
        
         | 
        }
  | 
      
      
        | 164 | 
        
         | 
        
         | 
        if ((!$in_old_group) && !is_numeric(array_search($admin->get_user_id(), $old_admin_users))){
 | 
      
      
        | 165 | 
        
         | 
        
         | 
            $admin->print_error($MESSAGE['PAGES_INSUFFICIENT_PERMISSIONS'], $target_url );
  | 
      
      
        | 166 | 
        
         | 
        
         | 
        }
  | 
      
      
        | 167 | 
        
         | 
        
         | 
        // Setup admin groups
  | 
      
      
        | 168 | 
        
         | 
        
         | 
        $admin_groups[] = 1;
  | 
      
      
        | 169 | 
        
         | 
        
         | 
        //if(!in_array(1, $admin->get_groups_id())) {
 | 
      
      
        | 170 | 
        
         | 
        
         | 
        //    $admin_groups[] = implode(",",$admin->get_groups_id());
 | 
      
      
        | 171 | 
        
         | 
        
         | 
        //}
  | 
      
      
        | 172 | 
        
         | 
        
         | 
        $admin_groups = preg_replace("/[^\d,]/", "", implode(',', $admin_groups));
 | 
      
      
        | 173 | 
        
         | 
        
         | 
        // Setup viewing groups
  | 
      
      
        | 174 | 
        
         | 
        
         | 
        $viewing_groups[] = 1;
  | 
      
      
        | 175 | 
        
         | 
        
         | 
        //if(!in_array(1, $admin->get_groups_id())) {
 | 
      
      
        | 176 | 
        
         | 
        
         | 
        //    $viewing_groups[] = implode(",",$admin->get_groups_id());
 | 
      
      
        | 177 | 
        
         | 
        
         | 
        //}
  | 
      
      
        | 178 | 
        
         | 
        
         | 
        $viewing_groups = preg_replace("/[^\d,]/", "", implode(',', $viewing_groups));
 | 
      
      
        | 179 | 
        
         | 
        
         | 
        // If needed, get new order
  | 
      
      
        | 180 | 
        
         | 
        
         | 
        if($parent != $old_parent){
 | 
      
      
        | 181 | 
        
         | 
        
         | 
            // Include ordering class
  | 
      
      
        | 182 | 
        
         | 
        
         | 
        if ( !class_exists( 'order', false ) ) { require(WB_PATH.'/framework/class.order.php'); }
 | 
      
      
        | 183 | 
        
         | 
        
         | 
            $order = new order(TABLE_PREFIX.'pages', 'position', 'page_id', 'parent');
  | 
      
      
        | 184 | 
        
         | 
        
         | 
            // Get new order
  | 
      
      
        | 185 | 
        
         | 
        
         | 
            $position = $order->get_new($parent);
  | 
      
      
        | 186 | 
        
         | 
        
         | 
            // Clean new order
  | 
      
      
        | 187 | 
        
         | 
        
         | 
            $order->clean($parent);
  | 
      
      
        | 188 | 
        
         | 
        
         | 
        } else {
 | 
      
      
        | 189 | 
        
         | 
        
         | 
            $position = $old_position;
  | 
      
      
        | 190 | 
        
         | 
        
         | 
        }
  | 
      
      
        | 191 | 
        
         | 
        
         | 
        
  | 
      
      
        | 192 | 
        
         | 
        
         | 
        // Work out level and root parent
  | 
      
      
        | 193 | 
        
         | 
        
         | 
        $level = '0';
  | 
      
      
        | 194 | 
        
         | 
        
         | 
        $root_parent = '0';
  | 
      
      
        | 195 | 
        
         | 
        
         | 
        if ($parent!='0'){
 | 
      
      
        | 196 | 
        
         | 
        
         | 
            $level = level_count($parent)+1;
  | 
      
      
        | 197 | 
        
         | 
        
         | 
            $root_parent = root_parent($parent);
  | 
      
      
        | 198 | 
        
         | 
        
         | 
        }
  | 
      
      
        | 199 | 
        
         | 
        
         | 
        // Work-out what the link should be
  | 
      
      
        | 200 | 
        
         | 
        
         | 
        if($parent == '0'){
 | 
      
      
        | 201 | 
        
         | 
        
         | 
            $link = '/'.page_filename( $seo_title);
  | 
      
      
        | 202 | 
        
         | 
        
         | 
        //    $link = '/'.page_filename($menu_title);
  | 
      
      
        | 203 | 
        
         | 
        
         | 
            // rename menu titles: index && intro to prevent clashes with intro page feature and WB core file /pages/index.php
  | 
      
      
        | 204 | 
        
         | 
        
         | 
            if($link == '/index' || $link == '/intro')
  | 
      
      
        | 205 | 
        
         | 
        
         | 
            {
 | 
      
      
        | 206 | 
        
         | 
        
         | 
                $filename = WB_PATH.PAGES_DIRECTORY.'/'.page_filename($seo_title).'_'.$page_id .PAGE_EXTENSION;
  | 
      
      
        | 207 | 
        
         | 
        
         | 
                $link .= '_' .$page_id;
  | 
      
      
        | 208 | 
        
         | 
        
         | 
            } else {
 | 
      
      
        | 209 | 
        
         | 
        
         | 
                $filename = WB_PATH.PAGES_DIRECTORY.'/'.page_filename($seo_title).PAGE_EXTENSION;
  | 
      
      
        | 210 | 
        
         | 
        
         | 
            }
  | 
      
      
        | 211 | 
        
         | 
        
         | 
        } else {
 | 
      
      
        | 212 | 
        
         | 
        
         | 
            $parent_section = '';
  | 
      
      
        | 213 | 
        
         | 
        
         | 
            $parent_titles = array_reverse(get_parent_titles($parent));
  | 
      
      
        | 214 | 
        
         | 
        
         | 
            foreach($parent_titles as $parent_title) {
 | 
      
      
        | 215 | 
        
         | 
        
         | 
                $parent_section .= page_filename($parent_title).'/';
  | 
      
      
        | 216 | 
        
         | 
        
         | 
            }
  | 
      
      
        | 217 | 
        
         | 
        
         | 
            if( $parent_section == '/' ) { $parent_section = ''; }
 | 
      
      
        | 218 | 
        
         | 
        
         | 
            $link = '/'.$parent_section.page_filename($seo_title);
  | 
      
      
        | 219 | 
        
         | 
        
         | 
            $filename = WB_PATH.PAGES_DIRECTORY.'/'.$parent_section.page_filename($seo_title).PAGE_EXTENSION;
  | 
      
      
        | 220 | 
        
         | 
        
         | 
        }
  | 
      
      
        | 221 | 
        
         | 
        
         | 
        
  | 
      
      
        | 222 | 
        
         | 
        
         | 
        // Check if a page with same page filename exists $oGetSamePage
  | 
      
      
        | 223 | 
        
         | 
        
         | 
        $sql = 'SELECT  COUNT(*) FROM `'.TABLE_PREFIX.'pages` '
  | 
      
      
        | 224 | 
        
         | 
        
         | 
             . 'WHERE `link` = "'.$database->escapeString($link).'" '
  | 
      
      
        | 225 | 
        
         | 
        
         | 
             .       'AND `page_id` != '.(int)$page_id;
  | 
      
      
        | 226 | 
        
         | 
        
         | 
        if( $database->get_one($sql) > 0 ) {
 | 
      
      
        | 227 | 
        
         | 
        
         | 
            $admin->print_error( $MESSAGE['PAGES_PAGE_EXISTS'] );
  | 
      
      
        | 228 | 
        
         | 
        
         | 
        }
  | 
      
      
        | 229 | 
        
         | 
        
         | 
        // Update page with new order
  | 
      
      
        | 230 | 
        
         | 
        
         | 
        $sql = 'UPDATE `'.TABLE_PREFIX.'pages` '
  | 
      
      
        | 231 | 
        
         | 
        
         | 
             . 'SET `parent`='.(int)$parent.', `position`='.(int)$position.' '
  | 
      
      
        | 232 | 
        
         | 
        
         | 
             . 'WHERE `page_id`='.(int)$page_id;
  | 
      
      
        | 233 | 
        
         | 
        
         | 
        // $database = new database();
  | 
      
      
        | 234 | 
        
         | 
        
         | 
        $database->query($sql);
  | 
      
      
        | 235 | 
        
         | 
        
         | 
        // Get page trail
  | 
      
      
        | 236 | 
        
         | 
        
         | 
        $page_trail = get_page_trail($page_id);
  | 
      
      
        | 237 | 
        
         | 
        
         | 
        $target_url = ADMIN_URL.'/pages/settings.php?page_id='.$page_id;
  | 
      
      
        | 238 | 
        
         | 
        
         | 
        // Update page settings in the pages table
  | 
      
      
        | 239 | 
        
         | 
        
         | 
        $sql  = 'UPDATE `'.TABLE_PREFIX.'pages` SET '
  | 
      
      
        | 240 | 
        
         | 
        
         | 
              . '`parent` = '.(int)$parent.', '
  | 
      
      
        | 241 | 
        
         | 
        
         | 
              . '`page_title` = \''.$database->escapeString($page_title).'\', '
  | 
      
      
        | 242 | 
        
         | 
        
         | 
              . '`menu_title` = \''.$database->escapeString($menu_title).'\', '
  | 
      
      
        | 243 | 
        
         | 
        
         | 
              . '`menu` = '.(int)$menu.', '
  | 
      
      
        | 244 | 
        
         | 
        
         | 
              . '`level` = '.(int)$level.', '
  | 
      
      
        | 245 | 
        
         | 
        
         | 
              . '`page_trail` = \''.$database->escapeString($page_trail).'\', '
  | 
      
      
        | 246 | 
        
         | 
        
         | 
              . '`root_parent` = '.(int)$root_parent.', '
  | 
      
      
        | 247 | 
        
         | 
        
         | 
              . '`link` = \''.$database->escapeString($link).'\', '
  | 
      
      
        | 248 | 
        
         | 
        
         | 
              . '`template` = \''.$database->escapeString($template).'\', '
  | 
      
      
        | 249 | 
        
         | 
        
         | 
              . '`target` = \''.$database->escapeString($target).'\', '
  | 
      
      
        | 250 | 
        
         | 
        
         | 
              . '`description` = \''.$database->escapeString($description).'\', '
  | 
      
      
        | 251 | 
        
         | 
        
         | 
              . '`keywords` = \''.$database->escapeString($keywords).'\', '
  | 
      
      
        | 252 | 
        
         | 
        
         | 
              . '`position` = '.(int)$position.', '
  | 
      
      
        | 253 | 
        
         | 
        
         | 
              . '`visibility` = \''.$database->escapeString($visibility).'\', '
  | 
      
      
        | 254 | 
        
         | 
        
         | 
              . '`searching` = '.(int)$searching.', '
  | 
      
      
        | 255 | 
        
         | 
        
         | 
              . '`language` = \''.$database->escapeString($language).'\', '
  | 
      
      
        | 256 | 
        
         | 
        
         | 
              . '`admin_groups` = \''.$database->escapeString($admin_groups).'\', '
  | 
      
      
        | 257 | 
        
         | 
        
         | 
              . '`viewing_groups` = \''.$database->escapeString($viewing_groups).'\' '
  | 
      
      
        | 258 | 
        
         | 
        
         | 
              .  (defined('PAGE_LANGUAGES') && PAGE_LANGUAGES && $field_set  ? ', `page_code` = '.(int)$page_code.' ' : ' ')
 | 
      
      
        | 259 | 
        
         | 
        
         | 
              . 'WHERE `page_id` = '.(int)$page_id;
  | 
      
      
        | 260 | 
        
         | 
        
         | 
        if(!$database->query($sql)) {
 | 
      
      
        | 261 | 
        
         | 
        
         | 
            if($database->is_error())
  | 
      
      
        | 262 | 
        
         | 
        
         | 
            {
 | 
      
      
        | 263 | 
        
         | 
        
         | 
                $admin->print_error($database->get_error(), $target_url );
  | 
      
      
        | 264 | 
        
         | 
        
         | 
            }
  | 
      
      
        | 265 | 
        
         | 
        
         | 
        }
  | 
      
      
        | 266 | 
        
         | 
        
         | 
        /* *** inherit settings to subpages ********************************* */
  | 
      
      
        | 267 | 
        
         | 
        
         | 
        if (isset($_POST['inherit'])) {
 | 
      
      
        | 268 | 
        
         | 
        
         | 
            // make sure, $aPost is am array
  | 
      
      
        | 269 | 
        
         | 
        
         | 
            $aPost = (is_array($_POST['inherit'])
  | 
      
      
        | 270 | 
        
         | 
        
         | 
                      // use the array itself
  | 
      
      
        | 271 | 
        
         | 
        
         | 
                      ? $_POST['inherit']
  | 
      
      
        | 272 | 
        
         | 
        
         | 
                      // split the string into an array
  | 
      
      
        | 273 | 
        
         | 
        
         | 
                      : preg_split("/[\s,;\|]+/", $_POST['inherit'], -1, PREG_SPLIT_NO_EMPTY));
 | 
      
      
        | 274 | 
        
         | 
        
         | 
            // define possible fields to inherit
  | 
      
      
        | 275 | 
        
         | 
        
         | 
            $aInherit = array('template','menu','language','searching','visibility');
 | 
      
      
        | 276 | 
        
         | 
        
         | 
            // define additional fields to 'visibility'
  | 
      
      
        | 277 | 
        
         | 
        
         | 
            $aVisibilities = array('admin_groups','admin_users','viewing_groups','viewing_users');
 | 
      
      
        | 278 | 
        
         | 
        
         | 
            // if 'all' is not selected
  | 
      
      
        | 279 | 
        
         | 
        
         | 
            if (!in_array('all', $aPost)) {
 | 
      
      
        | 280 | 
        
         | 
        
         | 
                // remove all not selected fields
  | 
      
      
        | 281 | 
        
         | 
        
         | 
                $aInherit = array_intersect($aInherit, $aPost);
  | 
      
      
        | 282 | 
        
         | 
        
         | 
            }
  | 
      
      
        | 283 | 
        
         | 
        
         | 
            // if 'visibility' is selected
  | 
      
      
        | 284 | 
        
         | 
        
         | 
            if (in_array('visibility', $aInherit)) {
 | 
      
      
        | 285 | 
        
         | 
        
         | 
                // add the additional fields
  | 
      
      
        | 286 | 
        
         | 
        
         | 
                $aInherit = array_merge($aInherit, $aVisibilities);
  | 
      
      
        | 287 | 
        
         | 
        
         | 
            }
  | 
      
      
        | 288 | 
        
         | 
        
         | 
            // flip array and set all values to ''
  | 
      
      
        | 289 | 
        
         | 
        
         | 
            $aInherit = array_fill_keys($aInherit, '');
  | 
      
      
        | 290 | 
        
         | 
        
         | 
            // iterate all existing fields
  | 
      
      
        | 291 | 
        
         | 
        
         | 
            foreach ($aInherit as $key=>$value) {
 | 
      
      
        | 292 | 
        
         | 
        
         | 
                // fill with real values (i.e.  $aInherit['template'] = $template)
  | 
      
      
        | 293 | 
        
         | 
        
         | 
                $aInherit[$key] = isset(${$key}) ? ${$key} : '';
 | 
      
      
        | 294 | 
        
         | 
        
         | 
            }
  | 
      
      
        | 295 | 
        
         | 
        
         | 
            // update database
  | 
      
      
        | 296 | 
        
         | 
        
         | 
            doInheritSettings($database, $page_id, array());// $aInherit
  | 
      
      
        | 297 | 
        
         | 
        
         | 
        }
  | 
      
      
        | 298 | 
        
         | 
        
         | 
        /* ****************************************************************** */
  | 
      
      
        | 299 | 
        
         | 
        
         | 
        
  | 
      
      
        | 300 | 
        
         | 
        
         | 
        // Clean old order if needed
  | 
      
      
        | 301 | 
        
         | 
        
         | 
        if($parent != $old_parent)
  | 
      
      
        | 302 | 
        
         | 
        
         | 
        {
 | 
      
      
        | 303 | 
        
         | 
        
         | 
            $order->clean($old_parent);
  | 
      
      
        | 304 | 
        
         | 
        
         | 
        }
  | 
      
      
        | 305 | 
        
         | 
        
         | 
        /* BEGIN page "access file" code */
  | 
      
      
        | 306 | 
        
         | 
        
         | 
        // Create a new file in the /pages dir if title changed
  | 
      
      
        | 307 | 
        
         | 
        
         | 
        if(!is_writable(WB_PATH.PAGES_DIRECTORY.'/'))
  | 
      
      
        | 308 | 
        
         | 
        
         | 
        {
 | 
      
      
        | 309 | 
        
         | 
        
         | 
            $admin->print_error($MESSAGE['PAGES_CANNOT_CREATE_ACCESS_FILE']);
  | 
      
      
        | 310 | 
        
         | 
        
         | 
        } else {
 | 
      
      
        | 311 | 
        
         | 
        
         | 
        
  | 
      
      
        | 312 | 
        
         | 
        
         | 
            $old_filename = WB_PATH.PAGES_DIRECTORY.$old_link.PAGE_EXTENSION;
  | 
      
      
        | 313 | 
        
         | 
        
         | 
            // First check if we need to create a new file
  | 
      
      
        | 314 | 
        
         | 
        
         | 
            if(($old_link != $link) || (!file_exists($old_filename)))
  | 
      
      
        | 315 | 
        
         | 
        
         | 
            {
 | 
      
      
        | 316 | 
        
         | 
        
         | 
                // Delete old file
  | 
      
      
        | 317 | 
        
         | 
        
         | 
                $old_filename = WB_PATH.PAGES_DIRECTORY.$old_link.PAGE_EXTENSION;
  | 
      
      
        | 318 | 
        
         | 
        
         | 
                if(file_exists($old_filename))
  | 
      
      
        | 319 | 
        
         | 
        
         | 
                {
 | 
      
      
        | 320 | 
        
         | 
        
         | 
                    @unlink($old_filename);
  | 
      
      
        | 321 | 
        
         | 
        
         | 
                }
  | 
      
      
        | 322 | 
        
         | 
        
         | 
                // Create access file
  | 
      
      
        | 323 | 
        
         | 
        
         | 
                create_access_file($filename,$page_id,$level);
  | 
      
      
        | 324 | 
        
         | 
        
         | 
                // Move a directory for this page
  | 
      
      
        | 325 | 
        
         | 
        
         | 
                if(file_exists(WB_PATH.PAGES_DIRECTORY.$old_link.'/') && is_dir(WB_PATH.PAGES_DIRECTORY.$old_link.'/'))
  | 
      
      
        | 326 | 
        
         | 
        
         | 
                {
 | 
      
      
        | 327 | 
        
         | 
        
         | 
                    @rename(WB_PATH.PAGES_DIRECTORY.$old_link.'/', WB_PATH.PAGES_DIRECTORY.$link.'/');
  | 
      
      
        | 328 | 
        
         | 
        
         | 
                }
  | 
      
      
        | 329 | 
        
         | 
        
         | 
                // Update any pages that had the old link with the new one
  | 
      
      
        | 330 | 
        
         | 
        
         | 
                $old_link_len = strlen($old_link);
  | 
      
      
        | 331 | 
        
         | 
        
         | 
                $sql = 'SELECT `page_id`,`link`,`level` FROM `'.TABLE_PREFIX.'pages` '
  | 
      
      
        | 332 | 
        
         | 
        
         | 
                     . 'WHERE `link` LIKE \'%'.addcslashes($old_link, '%_').'/%\' '
  | 
      
      
        | 333 | 
        
         | 
        
         | 
                     . 'ORDER BY `level` ASC';
  | 
      
      
        | 334 | 
        
         | 
        
         | 
                if (($query_subs = $database->query($sql))) {
 | 
      
      
        | 335 | 
        
         | 
        
         | 
                    while($sub = $query_subs->fetchRow(MYSQLI_ASSOC))
  | 
      
      
        | 336 | 
        
         | 
        
         | 
                    {
 | 
      
      
        | 337 | 
        
         | 
        
         | 
                        // Double-check to see if it contains old link
  | 
      
      
        | 338 | 
        
         | 
        
         | 
                        if(substr($sub['link'], 0, $old_link_len) == $old_link)
  | 
      
      
        | 339 | 
        
         | 
        
         | 
                        {
 | 
      
      
        | 340 | 
        
         | 
        
         | 
                            // Get new link
  | 
      
      
        | 341 | 
        
         | 
        
         | 
                            $replace_this = $old_link;
  | 
      
      
        | 342 | 
        
         | 
        
         | 
                            $old_sub_link_len =strlen($sub['link']);
  | 
      
      
        | 343 | 
        
         | 
        
         | 
                            $new_sub_link = $link.'/'.substr($sub['link'],$old_link_len+1,$old_sub_link_len);
  | 
      
      
        | 344 | 
        
         | 
        
         | 
                            // Work out level
  | 
      
      
        | 345 | 
        
         | 
        
         | 
                            $new_sub_level = level_count($sub['page_id']);
  | 
      
      
        | 346 | 
        
         | 
        
         | 
                            // Update level and link
  | 
      
      
        | 347 | 
        
         | 
        
         | 
                            $sql  = 'UPDATE `'.TABLE_PREFIX.'pages` SET '
  | 
      
      
        | 348 | 
        
         | 
        
         | 
                                  . '`link` = \''.$database->escapeString($new_sub_link).'\', '
  | 
      
      
        | 349 | 
        
         | 
        
         | 
                                  . '`level` = '.(int)$new_sub_level.' '
  | 
      
      
        | 350 | 
        
         | 
        
         | 
                                  . 'WHERE `page_id` = '.(int)$sub['page_id'];
  | 
      
      
        | 351 | 
        
         | 
        
         | 
                            $database->query( $sql );
  | 
      
      
        | 352 | 
        
         | 
        
         | 
                            // Re-write the access file for this page
  | 
      
      
        | 353 | 
        
         | 
        
         | 
                            $old_subpage_file = WB_PATH.PAGES_DIRECTORY.$new_sub_link.PAGE_EXTENSION;
  | 
      
      
        | 354 | 
        
         | 
        
         | 
                            if(file_exists($old_subpage_file))
  | 
      
      
        | 355 | 
        
         | 
        
         | 
                            {
 | 
      
      
        | 356 | 
        
         | 
        
         | 
                                @unlink($old_subpage_file);
  | 
      
      
        | 357 | 
        
         | 
        
         | 
                            }
  | 
      
      
        | 358 | 
        
         | 
        
         | 
                            create_access_file(WB_PATH.PAGES_DIRECTORY.$new_sub_link.PAGE_EXTENSION, $sub['page_id'], $new_sub_level);
  | 
      
      
        | 359 | 
        
         | 
        
         | 
                        }
  | 
      
      
        | 360 | 
        
         | 
        
         | 
                    }
  | 
      
      
        | 361 | 
        
         | 
        
         | 
                }
  | 
      
      
        | 362 | 
        
         | 
        
         | 
            }
  | 
      
      
        | 363 | 
        
         | 
        
         | 
        }
  | 
      
      
        | 364 | 
        
         | 
        
         | 
        
  | 
      
      
        | 365 | 
        
         | 
        
         | 
        // Fix sub-pages page trail
  | 
      
      
        | 366 | 
        
         | 
        
         | 
        fix_page_trail($page_id,$root_parent);
  | 
      
      
        | 367 | 
        
         | 
        
         | 
        
  | 
      
      
        | 368 | 
        
         | 
        
         | 
        /* END page "access file" code */
  | 
      
      
        | 369 | 
        
         | 
        
         | 
        
  | 
      
      
        | 370 | 
        
         | 
        
         | 
        // Check if there is a db error, otherwise say successful
  | 
      
      
        | 371 | 
        
         | 
        
         | 
        if($database->is_error())
  | 
      
      
        | 372 | 
        
         | 
        
         | 
        {
 | 
      
      
        | 373 | 
        
         | 
        
         | 
            $admin->print_error($database->get_error(), $target_url );
  | 
      
      
        | 374 | 
        
         | 
        
         | 
        } elseif ( $bBackLink ) {
 | 
      
      
        | 375 | 
        
         | 
        
         | 
            $admin->print_success($MESSAGE['PAGES_SAVED_SETTINGS'], $pagetree_url );
  | 
      
      
        | 376 | 
        
         | 
        
         | 
        } else {
 | 
      
      
        | 377 | 
        
         | 
        
         | 
            $admin->print_success($MESSAGE['PAGES_SAVED_SETTINGS'], $target_url );
  | 
      
      
        | 378 | 
        
         | 
        
         | 
        }
  | 
      
      
        | 379 | 
        
         | 
        
         | 
        
  | 
      
      
        | 380 | 
        
         | 
        
         | 
        // Print admin footer
  | 
      
      
        | 381 | 
        
         | 
        
         | 
        $admin->print_footer();
  |