<?php 
require_once "../../../maincore.php";
include_once LOCALE.LOCALESET."admin/main.php";
include_once ADMIN."template/locale/".LOCALESET."breadCrumb.locale.php";

if(isset($_POST['do']) && $_POST['do'] == "getPage") {    
    if(isset($_POST['page_id']) && isnum($_POST['page_id']) && $_POST['page_id'] <= 5) {
        if(iADMIN) {
            if ($_POST['aid'] == $aidlink) {
                $opentableTxt = $locale['ac0'.$_POST['page_id']];
                /* Type 1 = NUR Icon View
                 * Type 2 = NUR Beschreibung
                 * Type 3 = Icon View und Beschreibung
                 * Type 4 = Keines von beiden
                 */ 
                $viewType = 4;
                
                if( $settings['admin_icons'] == "1" )
                    $viewType = 1;
                if( $settings['admin_description'] == "1" )
                    $viewType = 2;            
                if( $settings['admin_icons'] == "1" && $settings['admin_description'] == "1" ) 
                    $viewType = 3;  
                
                $result = dbquery("SELECT * FROM ".DB_ADMIN." WHERE admin_page='".$_POST['page_id']."' ORDER BY admin_title");
                $rows = dbrows($result);
                if ($rows != 0) {
                    while ($data = dbarray($result)) {
                        if (checkrights($data['admin_rights']) && $data['admin_link'] != "reserved") {
                            $data['admin_image'] = get_image("ac_".$data['admin_title']); 
                            $data['admin_title'] = html_entity_decode($data['admin_title'], ENT_QUOTES, 'UTF-8');                                                                   
                            $links[] = $data;
                        }
                    }
                } 
                
                if (count($links) != 0 || $_POST['page_id'] == 0) {
                    $out = array("success" => true,
                                 "openTblTxt" => $opentableTxt,
                                 "viewType" => $viewType,
                                 "links" => $links,
                                 "aid" => $aidlink,
                                 "count" => count($links),
                                 "error" => null);                
                } else {
                    $out = array("success" => false,
                                 "error" => $locale['ac_ajax_03']."\"".$opentableTxt."\"".$locale['ac_ajax_04'].$_POST['page_id'].$locale['ac_ajax_05']);                
                }                                                                                                
            } else {
                $out = array("success" => false,
                             "error" => $locale['ac_ajax_06']."<a href='".ADMIN."index.php".$aidlink."&amp;pagenum=".$_POST['page_id']."'>".$locale['ac_ajax_07']."</a>");            
            }            
        } else {
            if(!iMEMBER) {
                $out = array("success" => false,
                             "error" => $locale['ac_ajax_08']."<a href='".BASEDIR."login.php' target='_blank'>".$locale['ac_ajax_09']."</a>");            
            } else {
                $out = array("success" => false,
                             "error" => $locale['ac_ajax_10']);            
            }       
        }    
    } else {
        $out = array("success" => false,
                     "error" => $locale['ac_ajax_11']);
    }
} elseif(isset($_POST['do']) && $_POST['do'] == "changeDesc") {
    if(iADMIN) {
        if ($_POST['aidlink'] == $aidlink) {
            $changeTo = 0;
            if (isset($_POST['changeFrom']) && $_POST['changeFrom'] == "0") { $changeTo = 1; } 
            $result = dbquery("UPDATE ".DB_SETTINGS." SET settings_value='".$changeTo."' WHERE settings_name='admin_description'");
            $array_ = dbarray(dbquery("SELECT settings_value FROM ".DB_SETTINGS." WHERE settings_name='admin_icons'"));
            $changeOt = $array_['settings_value'];
            $out = array("success" => true,
                         "changeTo" => $changeTo,
                         "changeOt" => $changeOt,
                         "error" => $locale['ac_ajax_12']);               
        } else {
            $out = array("success" => false,
                         "error" => $locale['ac_ajax_13']);            
        }
    } else {
        $out = array("success" => false,
                     "error" => $locale['ac_ajax_14']);        
    }    
} elseif(isset($_POST['do']) && $_POST['do'] == "changeView") {
    if(iADMIN) {
        if ($_POST['aidlink'] == $aidlink) {
            $changeTo = 0;
            if (isset($_POST['changeFrom']) && $_POST['changeFrom'] == "0") { $changeTo = 1; }
            $result = dbquery("UPDATE ".DB_SETTINGS." SET settings_value='".$changeTo."' WHERE settings_name='admin_icons'");
            $array_ = dbarray(dbquery("SELECT settings_value FROM ".DB_SETTINGS." WHERE settings_name='admin_description'"));
            $changeOt = $array_['settings_value'];
            $out = array("success" => true,
                         "changeTo" => $changeTo,
                         "changeOt" => $changeOt,
                         "error" => $locale['ac_ajax_12']);
        } else {
            $out = array("success" => false,
                         "error" => $locale['ac_ajax_13']);
        }
    } else {
        $out = array("success" => false,
                     "error" => $locale['ac_ajax_14']);
    }
} else {
    $out = array("success" => false,
                 "error" => $locale['ac_ajax_15']);    
}

echo json_encode($out);
?>
