<?php
require_once ('user-validation.php');

// All Pages
$advancenewsPages = array(
    array(
        'PageName' => 'Dashboard',
        'PageLink' => 'index.php',
        'PageID' => 'IndexPage',
        'PageIcon' => 'bi bi-house-door',
    ),
    array(
        'PageName' => 'Media Library',
        'PageID' => 'MediaLibrary',
        'PageLink' => 'MediaLibrary_tt',
        'PageIcon' => 'bi bi-images',
        'PageChild' =>  array(
            array(
                'PageName' => 'Add Media',
                'PageLink' => 'add-media.php',
                'PageID' => 'AddMedia',
                'SidebarHide' => true,
            ),
            array(
                'PageName' => 'All Media',
                'PageLink' => 'media-library.php',
            ),
        ),
    ),
    array(
      'MenuTitle' => 'Content',
    ),
    array(
        'PageName' => 'Article',
        'PageID' => 'tt_Article',
        'PageLink' => 'tt_Article',
        'PageIcon' => 'bi bi-vector-pen',
        'PageChild' =>  array(
            array(
                'PageName' => 'New Article',
                'PageLink' => 'article-new.php',
                'PageID' => 'NewArticle',
            ),
            array(
                'PageName' => 'Article',
                'PageLink' => 'article.php',
                'PageID' => 'AllArticle',
            ),
            array(
                'PageName' => 'Published Article',
                'PageLink' => 'article.php?from=published',
                'PageID' => 'AllArticle',
            ),
            array(
                'PageName' => 'Draft Article',
                'PageLink' => 'article.php?from=draft',
                'PageID' => 'AllArticle',
            ),
            array(
                'PageName' => 'Users Article',
                'PageLink' => 'article.php?from=users',
                'PageID' => 'AllArticle',
            ),
            array(
                'PageName' => 'Pending Article',
                'PageLink' => 'article.php?from=pending',
                'PageID' => 'AllArticle',
            ),
            array(
                'PageName' => 'Rejected Article',
                'PageLink' => 'article.php?from=rejected',
                'PageID' => 'AllArticle',
            ),
            array(
                'PageName' => 'Category',
                'PageLink' => 'category.php',
                'PageID' => 'ttCategory',
            ),
        ),
    ),
    array(
    'PageName' => 'Auto News',
    'PageID'   => 'AutoNews',
    'PageLink' => 'auto-news.php',
    'PageIcon' => 'bi bi-lightning-charge-fill',
),
    array(
        'PageName' => 'Live TV',
        'PageID'   => 'LiveTV_Settings',
        'PageLink' => 'option-livetv.php',
        'PageIcon' => 'bi bi-broadcast',
    ),
    array(
    'PageName' => 'Audio News',
    'PageID' => 'AudioNews',
    'PageLink' => 'audio-news-settings.php',
    'PageIcon' => 'bi bi-headphones',
    'PageChild' =>  array(
        array(
            'PageName' => 'TTS Settings',
            'PageLink' => 'audio-news-settings.php',
            'PageID' => 'AudioNewsSettings',
        ),
        array(
            'PageName' => 'Player Color',
            'PageLink' => 'audio-news-color.php',
            'PageID' => 'AudioNewsColor',
        ),
    ),
),

    array(
        'PageName' => 'Photo Story',
        'PageID' => 'PhotoAtoryTT',
        'PageLink' => 'PhotoAtoryTT',
        'PageIcon' => 'bi bi-files-alt',
        'PageChild' =>  array(
            array(
                'PageName' => 'New Story',
                'PageLink' => 'photo-stories-new.php',
                'PageID' => 'NewshotoStories',
            ),
            array(
                'PageName' => 'All Story',
                'PageLink' => 'photo-stories.php',
                'PageID' => 'allNewshotoStories',
            ),
            array(
                'PageName' => 'Story Settings',
                'PageLink' => 'option-stories.php',
                'PageID' => 'optionStories',
            ),
        ),
    ),
    array(
        'PageName' => 'Photo Gallery',
        'PageID' => 'PhotoGallery',
        'PageLink' => 'PhotoGallery',
        'PageIcon' => 'bi bi-images',
        'PageChild' =>  array(
            array(
                'PageName' => 'New Gallery',
                'PageLink' => 'photo-gallery-addnew.php',
                'PageID' => 'NewPhotoGallery',
            ),
            array(
                'PageName' => 'All Gallery',
                'PageLink' => 'photo-gallery.php',
                'PageID' => 'allPhotoGallery',
            ),
        ),
    ),
    array(
        'PageName' => 'Video Gallery',
        'PageID' => 'VideoGallery',
        'PageLink' => 'video.php',
        'PageIcon' => 'bi bi-youtube',
    ),
    array(
        'PageName' => 'Poll',
        'PageID' => 'Poll',
        'PageLink' => 'POLL',
        'PageIcon' => 'bi bi-pie-chart-fill',
        'PageChild' =>  array(
            array(
                'PageName' => 'New Poll',
                'PageLink' => 'poll-addnew.php',
                'PageID' => 'NewNew',
            ),
            array(
                'PageName' => 'All Poll',
                'PageLink' => 'poll.php',
                'PageID' => 'allPole',
            ),
            array(
                'PageName' => 'Poll Settings',
                'PageLink' =>  'option-poll.php',
                'PageID' => 'OptionPole',
            ),
        ),
    ),
    array(
        'PageName' => 'Reactions & Ratings',
        'PageID'   => 'ReactionsRatings',
        'PageLink' => 'reactions-ratings.php',
        'PageIcon' => 'bi bi-emoji-heart-eyes',
    ),
    array(
        'PageName' => 'Pages',
        'PageID' => 'Page_TT',
        'PageLink' => 'Page_TT_ALL',
        'PageIcon' => 'bi bi-file-earmark-fill',
        'PageChild' =>  array(
            array(
                'PageName' => 'All Page',
                'PageLink' => 'page.php',
                'PageID' => 'allPage',
            ),
        ),
    ),
    array(
        'MenuTitle' => 'Customization',
    ),
    array(
        'PageName' => 'Header and Footer',
        'PageID' => 'Header_Settings',
        'PageLink' => 'Header_Settings',
        'PageIcon' => 'bi bi-archive-fill',
        'PageChild' =>  array(
            array(
                'PageName' => 'Header Settings',
                'PageLink' => 'option-header.php',
            ),
            array(
                'PageName' => 'Off Canvas Sidebar',
                'PageLink' => 'option-off-canvas-sidebar.php',
            ),
            array(
                'PageName' => 'Footer Options',
                'PageLink' => 'option-footer.php',
            ),
        ),
    ),
    array(
        'PageName' => 'Homepage Settings',
        'PageID' => 'Homepage_Options',
        'PageLink' => 'Homepage_Options',
        'PageIcon' => 'bi bi-house-gear-fill',
        'PageChild' =>  array(
            array(
                'PageName' => 'Home Post Block',
                'PageLink' => 'option-home-post.php',
            ),
            array(
                'PageName' => 'Highlight News',
                'PageLink' => 'option-highlight-news.php',
            ),
            array(
                'PageName' => 'Quick Category',
                'PageLink' => 'option-quick-category.php',
            ),
            array(
                'PageName' => 'Homepage TV',
                'PageLink' => 'option-homepage-tv.php',
            ),
        ),
    ),
    array(
        'PageName' => 'Post Settings',
        'PageID' => 'Postpage_Options',
        'PageLink' => 'Postpage_Options',
        'PageIcon' => 'bi bi-database-fill-gear',
        'PageChild' =>  array(
            array(
                'PageName' => 'Global Post Options',
                'PageLink' => 'option-post-global.php',
            ),
            array(
                'PageName' => 'Post page Settings',
                'PageLink' => 'option-post-setting.php',
            ),
        ),
    ),
    array(
        'PageName' => 'Advertisement ',
        'PageID' => 'Others_Pages',
        'PageLink' => 'Others_Pages',
        'PageIcon' => 'bi-badge-ad-fill',
        'PageChild' =>  array(
            array(
                'PageName' => 'Home Page  Ads',
                'PageLink' => 'option-home-ads.php',
            ),
            array(
                'PageName' => 'Popup Ads',
                'PageLink' => 'option-popup-ads.php',
            ),
            array(
                'PageName' => 'Post Page Ads',
                'PageLink' => 'option-post-ads.php',
            ),
            array(
                'PageName' => 'Category Page',
                'PageLink' => 'option-page-category.php',
            ),
                array(
                    'PageName' => 'Topic Page',
                    'PageLink' => 'option-page-topic.php',
                ),
            array(
                'PageName' => 'Search Page',
                'PageLink' => 'option-page-search.php',
            ),

            array(
                'PageName' => 'Country News Page',
                'PageLink' => 'option-page-country-news.php',
            ),

            array(
                'PageName' => 'Author Page',
                'PageLink' => 'option-page-author.php',
            ),
        ),
    ),
    array(
        'PageName' => 'Menu',
        'PageID' => 'Menu_Settings',
        'PageLink' => 'Menu_Settings',
        'PageIcon' => 'bi bi-menu-app',
        'PageChild' =>  array(
            array(
              'PageName' => 'Main Menu',
              'PageLink' => 'menu.php',
            ),
            array(
              'PageName' => 'Offcanvas Menu',
              'PageLink' => 'menu-offcanvas.php',
            ),
            array(
              'PageName' => 'Secondary  Menu',
              'PageLink' => 'menu-secondary.php',
            ),
        ),
    ),
    array(
        'PageName' => 'Photo Card',
        'PageID' => 'PhotoCard_Settings',
        'PageLink' => 'PhotoCard_Settings',
        'PageIcon' => 'bi bi-postcard',
        'PageChild' =>  array(
            array(
              'PageName' => 'All Template',
              'PageLink' => 'photocard.php',
            ),
            array(
              'PageName' => 'New Template',
              'PageLink' => 'photocard-new.php',
            ),
            array(
              'PageName' => 'Facebook Auto Sharing',
              'PageLink' => 'photocard-fb-settings.php',
            ),
        ),
    ),

    array(
        'MenuTitle' => 'Advance',
    ),
    array(
        'PageName' => 'Writers Account',
        'PageID' => 'WriterACC',
        'PageLink' => 'WriterACC',
        'PageIcon' => 'bi bi-people-fill',
        'PageChild' =>  array(
            array(
                'PageName' => 'All Writers',
                'PageLink' => 'writer.php',
            ),
            array(
                'PageName' => 'ID Cards',
                'PageLink' => 'writer-id-cards.php',
            ),
            array(
                'PageName' => 'Writer Settings',
                'PageLink' => 'option-account-writer.php',
            ),
            array(
                'PageName' => 'Our Family',
                'PageLink' => 'mahamudfutureit-family.php',
            ),
        ),
    ),
    array(
        'PageName' => 'Settings',
        'PageID' => 'Settings_tt',
        'PageLink' => 'Settings',
        'PageIcon' => 'bi bi-gear',
        'PageChild' =>  array(
            array(
                'PageName' => 'General Settings',
                'PageLink' => 'option-general.php',
            ),
            array(
                'PageName' => 'Social Media',
                'PageLink' => 'option-social.php',
            ),
        ),
    ),
    array(
        'PageName' => 'Developer Zone',
        'PageID' => 'Developer_Zone',
        'PageLink' => 'Developer_Zone',
        'PageIcon' => 'bi bi-code-slash',
        'PageChild' =>  array(
            array(
                'PageName' => 'Custome Code',
                'PageLink' => 'option-developer-custome-code.php',
            ),
            array(
                'PageName' => 'Custome CSS',
                'PageLink' => 'option-developer-custome-css.php',
            ),
            array(
                'PageName' => 'Custome JavaScript',
                'PageLink' => 'option-developer-custome-js.php',
            ),
            array(
                'PageName' => 'Schema & Sitemap',
                'PageLink' => 'option-developer-schema.php',
            ),
            array(
                'PageName' => 'API Services',
                'PageLink' => 'option-developer-api.php',
            ),
        ),
    ),
    array(
        'PageName' => 'Web Access',
        'PageID' => 'accessRole',
        'PageLink' => 'web-administration.php',
        'PageIcon' => 'bi bi-person-bounding-box',
    ),
    array(
        'PageName' => 'Security',
        'PageID' => 'accessRole',
        'PageLink' => 'security.php',
        'PageIcon' => 'bi bi-person-fill-lock',
    ),
);
// Active Page Current Page
$cur_page_link = basename($_SERVER['SCRIPT_NAME']);

// Page Role Name and Access
$pageAccess = array(
  'Admin' => array(
    // Media Library
    'MediaLibrary_tt','media-library.php','add-media.php','upload.php',

    // @Content //
    // Article
    'tt_Article','article.php','article-server.php','article-new.php','article-edit.php','category.php','article.php?from=published','article.php?from=draft','article.php?from=users','article.php?from=pending','article.php?from=rejected',
    // Pages
    'Page_TT_ALL','page.php','page-new.php','page-edit.php',
    // Photo Story
    'PhotoAtoryTT','photo-stories.php','photo-stories-new.php','photo-stories-edit.php','option-stories.php',
    // Photo Gallery
    'PhotoGallery','photo-gallery.php','photo-gallery-addnew.php','photo-gallery-edit.php', 'video.php',
    // Poll
    'POLL','poll-addnew.php','poll.php','poll-addnew-edit.php', 'option-poll.php',
    // @Customization //
    // Header & Footer
    'Header_Settings','option-header.php','option-off-canvas-sidebar.php','option-footer.php',
    // Homepage Settings
    'Homepage_Options','option-home-post.php','option-highlight-news.php','option-quick-category.php','option-homepage-tv.php',
    // Post Settings
    'Postpage_Options','option-post-global.php','option-post-setting.php',
    // Advertisement
    'Others_Pages','option-popup-ads.php','option-post-ads.php','option-home-ads.php','option-page-category.php','option-page-topic.php','option-page-search.php','option-page-country-news.php','option-page-author.php',
    // Menu Settings
    'Menu_Settings','menu.php','menu-offcanvas.php','menu-secondary.php',
    // Photocard
    'PhotoCard_Settings', 'photocard.php', 'photocard-new.php', 'photocard-edit.php', 'photocard-fb-settings.php',

    // @Advance //
    // Writers Account
    'WriterACC','writer.php','option-account-writer.php','writer-id-cards.php', 'writer-id-card-new.php', 'mahamudfutureit-family.php',
    // Settings
    'Settings','option-general.php','option-social.php',
    // Developer Zone
    'Developer_Zone','option-developer-custome-code.php','option-developer-custome-css.php','option-developer-custome-js.php','option-developer-schema.php','option-developer-api.php',
    // Reactions & Ratings
    'ReactionsRatings','reactions-ratings.php',
  ),
  'Editor' => array(
    // Media Library
    'MediaLibrary_tt','media-library.php','add-media.php','upload.php',

    // @Content //
    // Article
    'tt_Article','article.php','article-server.php','article-new.php','article-edit.php','category.php','article.php?from=published','article.php?from=draft','article.php?from=users','article.php?from=pending','article.php?from=rejected',
    // Pages
    'Page_TT_ALL','page.php','page-new.php','page-edit.php',
    // Photo Story
    'PhotoAtoryTT','photo-stories.php','photo-stories-new.php','photo-stories-edit.php',
    // Photo Gallery
    'PhotoGallery','photo-gallery.php','photo-gallery-addnew.php','photo-gallery-edit.php', 'video.php',

    // Poll
    'POLL','poll-addnew.php','poll.php','poll-addnew-edit.php',
  )
);

// Page All Have Access
$global_access_pages = array(
  'index.php','404.php','login.php','log-out.php','security.php','MediaLibrary_tt','media-library.php' , 'add-media.php',
);

// Current User Access
$curent_user_page_role = $the_user['admin_access'];

$accessible_pages  = array();

// SUper Admin Have All Access
if ($curent_user_page_role != 'Super Admin') {

  // Merge global access pages and user specific access pages
  $user_specific_pages = isset($pageAccess[$curent_user_page_role]) ? $pageAccess[$curent_user_page_role] : array();
  $accessible_pages = array_merge($global_access_pages, $user_specific_pages);

  // Remove duplicates in case of any
  $accessible_pages = array_unique($accessible_pages);

  // Check if current page is in the accessible pages list
  if (!in_array($cur_page_link, $accessible_pages)) {
      header('Location:404.php');
      exit();
  }
}

// Remove Edit Permission From admin_ud_post deactivet User
if ($the_user['admin_ud_post'] != 'active') {
  $avoid_admin_ud_pages = array('article-edit.php','page-edit.php','photo-stories-edit.php');
  if (in_array($cur_page_link, $avoid_admin_ud_pages)) {
    header('Location:404.php');
    exit();
  }
}

// Get Page Information From Array
foreach ($advancenewsPages as $page) {
    // Check Parent Data
    if (isset($page['PageLink'])) {
        if($cur_page_link == $page['PageLink']){
          $page_link = $page['PageLink'];
          $page_title = $page['PageName'];
          $page_id = $childPage['PageID'];
        }
        // Check Child Data
        if (isset($page['PageChild']) && is_array($page['PageChild'])) {
            foreach ($page['PageChild'] as $childPage) {
                if($cur_page_link == $childPage['PageLink']){
                  $page_link = $childPage['PageLink'];
                  $page_title = $childPage['PageName'];
                  $page_id = $childPage['PageID'];
                }
            }
        }
    }
}
?>
