<?php
if(IN_IQQOL){
    if($_COOKIE['iQQol_Administrator']!=IQQOL_SPPASS)
    {
        $style->assign("state",'COOKIE失效');
        $style->display('admin/index.html');exit();
    }
    else if(isset($_GET['id']) and !isset($_POST['settingsubmit'])){
        $group=iqqol_parameter::get_dir_glob('template','name',true);
        if(!in_array($_GET['id'],$group))
        {
            $style->assign("state",'模板不存在');
            $tem_url_return='admin.php?action=styles';
            $style->display('admin/status.html');exit();
        }
        else
        {
            if($_GET['f']=='lang'){
            $fp=fopen("template/{$_GET['id']}/lang.inc.php",'r');
            $get=fread($fp,filesize("template/{$_GET['id']}/lang.inc.php"));
            $style->display('admin/styles/edit.html');
            }
            elseif($_GET['f']=='info'){
            $fp=fopen("template/{$_GET['id']}/info.php",'r');
            $get=fread($fp,filesize("template/{$_GET['id']}/info.php"));
            $style->display('admin/styles/edit.html');
            }
            else{
            $state='未定义';
            $tem_url_return='admin.php?action=styles';
            $style->display('admin/status.html');
            }
        }
    }
    else if(isset($_POST['settingsubmit'])){
        if($_GET['f']=='lang'){
        $fp=fopen("template/{$_GET['id']}/lang.inc.php",'w+');
        $write=fwrite($fp,stripslashes($_POST['info']));
        }
        elseif($_GET['f']=='info'){
        $fp=fopen("template/{$_GET['id']}/info.php",'w+');
        $write=fwrite($fp,stripslashes($_POST['info']));
        }
        else{
            $state='未定义';
            $tem_url_return='admin.php?action=styles';
            $style->display('admin/status.html');
        }
        if($write){
            $state='修改成功';
            $tem_url_return='admin.php?action=styles';
            $style->display('admin/status.html');
        }
        else{
            $state='修改失败';
            $tem_url_return='admin.php?action=styles';
            $style->display('admin/status.html');
        }
    }
    else {
        header('location:admin.php?action=styles');
    }
}