<?php


    # Menu and page structure
    include_once 'data_connect.php';

    
    # Clear error buffer and disable errors
    libxml_clear_errors();
    libxml_use_internal_errors(true);
    
    
    # Enable the save button in these pages only
    $enabled = ['general.php','plugins.php','generaluser.php','advanced.php'];
    
    
    # Get the settings
    $xmls = getXMLSettings();

    
    # Account info 
    $log_info = get_log();
    
    if (!isset($acc_info))
        $acc_info = get_account($_SESSION['userID']);
    
    $monrights = $acc_info['rights'];
    $user = $_SESSION['username'];
    $urlicon = '../images/'.$acc_info['urlicon'];
    $usericon = is_file($urlicon) ? $urlicon : $acc_info['icon'];
    
    
    $c = $monrights == 'administrator' ? $log_info['posts'] : myPosts()[0];
    $d = $log_info['pages'];

    $lgparam = (get_included_files());
    
    $plg = get_plugins();
    
    foreach($plg as $key=>$val)
        if ($val[0] == 'on' && ($monrights == 'administrator' || $val[3] == '../plugins/user')) {
            $plico = '<span class="indic" title="Plugins active">&nbsp;&nbsp;&bull;</span>';
            break;
        }


    
?>
<div class="topbar topbg"></div>
<div id="top">
    <!-- Left section -->
    <div class="editbar">
        <div id="dropdown" class="wico">
            <div id="dropdown-content" class="dropcon">
        
        <span class="dropdown-title menu-separator">&nbsp;:::</span>        
                <!-- Navigation menu -->

                <a href="opensaved.php" id="posts" class="dropdown-title" title="Posts"><span class="text">Posts<?php print '<span class="dinf" title="Total number of posts">'.$c.'</span>' ?></span></a>
                <a href="newpage.php" id="newpost" class="dropdown-title" title="Write a new post"><span class="text">Write post</span></a>
                <a href="category.php" id="categories" class="dropdown-title" title="Categories"><span class="text">Categories</span></a>
                <div class="clear clearmenu"></div>


                <?php if ($monrights == 'administrator') : ?>

                <a href="createpage.php" id="newpage" class="dropdown-title" title="New page"><span class="text">New page</span></a>
                <a href="pages.php?showpub=1" id="allpages" class="dropdown-title" title="All pages"><span class="text">All pages<?php print '<span class="dinf" title="Total number of pages">'.$d.'</span>' ?></span></a>
                <div class="clear clearmenu"></div>
                <a href="accmanage.php" id="accounts" class="dropdown-title" title="User accounts"><span class="text">Accounts</span></a>
                <div class="clear clearmenu"></div>
                <a href="general.php" id="settings" class="dropdown-title" title="Settings"><span class="text">Settings</span></a>
                <a href="advanced.php" id="advanced" class="dropdown-title" title="Advanced settings"><span class="text">Advanced</span></a>
                <div class="clear clearmenu"></div>
                <a href="uploads.php" id="images" class="dropdown-title" title="Images"><span class="text">Images</span></a>
                <a href="plugins.php" id="plugins" class="dropdown-title" title="Plugins"><span class="text">Plugins<?php if(isset($plico)) print $plico ?></span></a>
                <?php else : ?>
                <a href="generaluser.php" id="settings" class="dropdown-title" title="Settings"><span class="text">Settings</span></a>
                <div class="clear clearmenu">
                </div><a href="uploads.php" id="images" class="dropdown-title" title="Images"><span class="text">Images</span></a>
                <a href="plugins.php" id="plugins" class="dropdown-title" title="Plugins"><span class="text">Plugins<?php if(isset($plico)) print $plico ?></span></a>
                <?php endif ?>
                <span class="dropdown-title menu-separator">&nbsp;:::</span>
            </div>    
        </div>
        <!-- logo -->
        <div class="logo">
            <a href="../" id="logolink" title="Visit website" target="_blank"><?php print $xmls['title'] ?>&nbsp;</a>
        </div>
    </div>        
    
    <div class="user-info">
        <div class="panelicon">
        <?php
        
            if (is_file($usericon))
                print '<img class="plimg" src="'.$usericon.'" title="'.$user.'">';
            else
                echo '<span class="plimg" title="'.$user.'"> &nbsp; &times;</span>';
                
                $enab = ' disabled';
                foreach (get_included_files() as $val) {
                    $cscr = basename($val);
                    if (in_array($cscr,$enabled)) {
                        $enab = '';
                        break;
                    }
                }
                
                
        
        ?>
        </div>
        <div class="useradmin">
            <input id="general-submit" type="submit" value="Save" onmousedown="this.blur()" title="Save" name="submitted" form="MONform"<?php print $enab ?>>
            <a id="lgcon" href="?logout=1" onclick="this.blur()" ondragstart="this.blur()" title="Logout">Logout</a>
            <span id="user">
                <span class="username" title="Username"><?php print $user ?></span>
            </span>
        </div>
    </div>
</div>