<?php
require_once "../maincore.php";
require_once THEMES."templates/admin_header.php";

if (!iADMIN || $userdata['user_rights'] == "" || !defined("iAUTH") || !isset($_GET['aid']) || $_GET['aid'] != iAUTH) { redirect("../index.php"); }

$icon_view = false;
$admin_description = false;
if( $settings['admin_icons'] == "1" ) 
    $icon_view = true;
if( $settings['admin_description'] == "1" ) 
    $admin_description = true;

if (isset($_GET['pagenum']) && isnum($_GET['pagenum'])) {
   $breadcrumb_titles = (array($locale['ac0'.$_GET['pagenum']]));
   $breadcrumb_links = (array(FUSION_SELF.$aidlink));
}

// Bestimmte Admin Seite
if (isset($_GET['pagenum']) && isnum($_GET['pagenum'])) {
    opentable($locale['ac0'.$_GET['pagenum']]);
    echo "<a href='#' class='change_desc tip' id='change_".$settings['admin_description']."_".(isset($_GET['pagenum']) ? $_GET['pagenum'] : "0")."' title='".$locale['270']."'>\n";
    echo "<img src='".ADMIN."template/images/desc.png' alt='".$locale['270']."' />\n</a>\n";
    echo "<a href='#' class='change_view tip' id='change_".$settings['admin_icons']."_".(isset($_GET['pagenum']) ? $_GET['pagenum'] : "0")."' title='".$locale['271']."'>\n";
    echo "<img src='".ADMIN."template/images/view.png' alt='".$locale['271']."' />\n</a>\n";
    echo "<div>\n";
        
    $result = dbquery("SELECT * FROM ".DB_ADMIN." WHERE admin_page='".$_GET['pagenum']."' ORDER BY admin_title");
    $rows = dbrows($result);
    if ($rows != 0) {
        echo "<ul id='admin-nav'>\n";
        while ($data = dbarray($result)) {
            if (checkrights($data['admin_rights']) && $data['admin_link'] != "reserved") {
                if ($icon_view) {
                    echo "<li class='no-desc'>\n";
                    echo "<a href='".$data['admin_link'].$aidlink."'".($admin_description && $data['admin_description'] != "" ? " class='tip' title='".$data['admin_description']."'" : "").">\n";
                    echo "<img src='".get_image("ac_".$data['admin_title'])."' alt='' />\n";
                    echo "<div>".$data['admin_title']."</div>\n</a>\n</li>\n";
                } else {                
                    echo "<li class='admin-height'>\n";
                    echo "<a href='".$data['admin_link'].$aidlink."'>\n";
                    echo "<div class='admin-icons'>\n";
                    echo "<img src='".get_image("ac_".$data['admin_title'])."' class='icon' alt='' />\n";
                    echo "</div>\n<div class='admin-desc'>\n";
                    echo "<h3>".$data['admin_title']."</h3>\n";
                    echo "<div class='admin-description".($admin_description ? "" : " no-display")."'>\n".($data['admin_description'] != "" ? $data['admin_description'] : "")."</div>\n";
                    echo "</div>\n</a>\n</li>\n<div class='clear'></div>\n";                                
                }
            }                                    
        }
        echo "</ul>\n<div class='clear'></div>\n";
    }
    echo "</div>\n";
    closetable();
// Admin Hauptseite
} else {
    opentable($locale['global_123']);
    echo "<a href='#' class='change_desc tip' id='change_".$settings['admin_description']."_".(isset($_GET['pagenum']) ? $_GET['pagenum'] : "0")."' title='".$locale['270']."'>\n";
    echo "<img src='".ADMIN."template/images/desc.png' alt='".$locale['270']."' />\n</a>\n";
    echo "<a href='#' class='change_view tip' style='display: none;' id='change_".$settings['admin_icons']."_".(isset($_GET['pagenum']) ? $_GET['pagenum'] : "0")."' title='".$locale['271']."'>\n";
    echo "<img src='".ADMIN."template/images/view.png' alt='".$locale['271']."' />\n</a>\n";
    echo "<div>\n";    
    for ($i = 1; $i <= 5; $i++) {
        $items = false;
        
        $result = dbquery("SELECT * FROM ".DB_ADMIN." WHERE admin_page='".$i."' ORDER BY admin_title");
        while ($data = dbarray($result)) {
           if (checkrights($data['admin_rights']) && $data['admin_link'] != "reserved") {
              $items[$i] = true;
           }
        }
        
        if ($items) {
            echo "<div class='admin-main-panel'>\n";
            echo "<div style='width: 50%;".($i % 3 == 0 ? " float:right;" : " float:left;")."'>\n";
            echo "<div class='admin-main-panel-contener'>\n";
            echo "<h2>".$locale['ac0'.$i]."</h2>\n";
            echo "<div class='admin-main-panel-contener-bg'>\n<ul>\n";
            
            $result = dbquery("SELECT * FROM ".DB_ADMIN." WHERE admin_page='".$i."' ORDER BY admin_title");
            while ($data = dbarray($result)) {
                if (checkrights($data['admin_rights']) && $data['admin_link'] != "reserved") {
                    echo "<li class='no-desc'>\n";
                    echo "<a href='".$data['admin_link'].$aidlink."'".($admin_description && $data['admin_description'] != "" ? " class='tip' title='".$data['admin_description']."'" : "").">\n";
                    echo "<img src='".get_image("ac_".$data['admin_title'])."' alt='' />\n";
                    echo "<div>".$data['admin_title']."</div>\n</a>\n</li>";
                }
            }
            echo "</ul>\n<div class='clear'></div>\n</div>\n</div>\n</div>\n</div>";    
        } 
    }
    echo "<div class='clear'></div>\n";
    
    $members_registered = dbcount("(user_id)", DB_USERS, "user_status<='1' OR user_status='3' OR user_status='5'");
    $members_unactivated = dbcount("(user_id)", DB_USERS, "user_status='2'");
    $members_security_ban = dbcount("(user_id)", DB_USERS, "user_status='4'");
    $members_canceled = dbcount("(user_id)", DB_USERS, "user_status='5'");

    echo "<div class='status'>\n";
    echo "<table cellpadding='0' cellspacing='0' width='100%'>\n<tr>\n";
    echo "<td valign='top' width='33%' class='admin-footer small'>\n<ul>\n";
    if (checkrights("M")) {
        echo "<li><a href='".ADMIN."members.php".$aidlink."'>".$locale['251']."</a> ".$members_registered."</li>\n";
        echo "<li><a href='".ADMIN."members.php".$aidlink."&amp;status=2'>".$locale['252']."</a> ".$members_unactivated."</li>\n";
        echo "<li><a href='".ADMIN."members.php".$aidlink."&amp;status=4'>".$locale['253']."</a> ".$members_security_ban."</li>\n";
        echo "<li><a href='".ADMIN."members.php".$aidlink."&amp;status=5'>".$locale['263']."</a> ".$members_canceled."</li>\n";
        if ($settings['enable_deactivation'] == "1") {
            $time_overdue = time() - (86400 * $settings['deactivation_period']);
            $members_inactive = dbcount("(user_id)", DB_USERS, "user_lastvisit<'$time_overdue' AND user_actiontime='0' AND user_joined<'$time_overdue' AND user_status='0'");
            echo "<li><a href='".ADMIN."members.php".$aidlink."&amp;status=8'>".$locale['264']."</a> ".$members_inactive."</li>\n";
        }
    } else {
        echo "<li>".$locale['251']." ".$members_registered."</li>\n";
        echo "<li>".$locale['252']." ".$members_unactivated."</li>\n";
        echo "<li>".$locale['253']." ".$members_security_ban."</li>\n";
        echo "<li>".$locale['263']." ".$members_canceled."</li>\n";
    }
    echo "</ul>\n</td>\n";
    echo "<td valign='top' width='33%' class='admin-footer small'>\n<ul>\n";
    echo "<li>".(checkrights("SU") ? "<a href='".ADMIN."submissions.php".$aidlink."#news_submissions'>".$locale['254']."</a>" : $locale['254'])." ".dbcount("(submit_id)", DB_SUBMISSIONS, "submit_type='n'")."</li>\n";
    echo "<li>".(checkrights("SU") ? "<a href='".ADMIN."submissions.php".$aidlink."#article_submissions'>".$locale['255']."</a>" : $locale['255'])." ".dbcount("(submit_id)", DB_SUBMISSIONS, "submit_type='a'")."</li>\n";
    echo "<li>".(checkrights("SU") ? "<a href='".ADMIN."submissions.php".$aidlink."#link_submissions'>".$locale['256']."</a>" : $locale['256'])." ".dbcount("(submit_id)", DB_SUBMISSIONS, "submit_type='l'")."</li>\n";
    echo "<li>".(checkrights("SU") ? "<a href='".ADMIN."submissions.php".$aidlink."#photo_submissions'>".$locale['260']."</a>" : $locale['260'])." ".dbcount("(submit_id)", DB_SUBMISSIONS, "submit_type='p'")."</li>\n";
    echo "<li>".(checkrights("SU") ? "<a href='".ADMIN."submissions.php".$aidlink."#download_submissions'>".$locale['265']."</a>" : $locale['265'])." ".dbcount("(submit_id)", DB_SUBMISSIONS, "submit_type='d'")."</li>\n";
    echo "</ul>\n</td>\n";
    echo "<td valign='top' width='33%' class='admin-footer small'>\n<ul>\n";
    echo "<li>".$locale['257']." ".dbcount("(comment_id)", DB_COMMENTS)."</li>\n";
    echo "<li>".$locale['259']." ".dbcount("(post_id)", DB_POSTS)."</li>\n";
    echo "<li>".$locale['261']." ".dbcount("(photo_id)", DB_PHOTOS)."</li>\n";
    echo "</ul>\n</td>\n</tr>\n</table>\n</div>\n</div>\n";
    closetable();                       
}           

require_once THEMES."templates/footer.php";
?>
