<?php

class admin_etao extends adminPage{
    public $workground = 'sale';
    
   public function index() {
        $this->path[] = array('text'=>__('一淘商品接入'));

        $this->pagedata['uname'] = $this->system->getConf('app.etao.uname');
        $this->pagedata['vfile'] = file_exists(BASE_DIR.'/etao_domain_verify.txt');
        $this->pagedata['shop_url'] = $this->system->base_url();
        $this->pagedata['pid'] = $this->system->getConf('app.etao.alipay.pid');
        $this->pagedata['key'] = $this->system->getConf('app.etao.alipay.key');
        
        $tmpl = 'file:'.dirname(__FILE__).'/view/conf.html';
        $this->page($tmpl);
    }
    
    // 上传验证文件
    public function conf(){
        $this->begin('index.php?ctl=plugins/etao');
    
        if( $_FILES['vfile'] && 'etao_domain_verify.txt' != $_FILES['vfile']['name'] ) {
            $this->end(false,"上传文件名错误");
        }

        // 保存验证文件
        move_uploaded_file($_FILES['vfile']['tmp_name'], BASE_DIR.'/etao_domain_verify.txt');
        
        if($_POST['pid'] && $_POST['key']){
            $this->system->setConf('app.etao.alipay.pid',$_POST['pid']);
            $this->system->setConf('app.etao.alipay.key',$_POST['key']);
        }
        $this->system->setConf('app.etao.uname',$_POST['uname']);
        $lastmodify = 0;//+$this->system->getConf('app.etao.lastmodify');
        $this->system->setConf('app.etao.lastmodify',NOW);

        // 产生feed
        include dirname(__FILE__).'/etao_mdl_feed.php';
        $etaoMdl = new etao_mdl_feed();
        $etaoMdl->genfeedfull();
        $etaoMdl->genfeedinc();
        
        $this->end(true, __('提交成功'));
    }
}

