<?php
/**
 * Lang.php
 * Created by: Owen
 * Created on: 2020/1/10 17:15
 *
 */

class Lang extends MY_Controller{
    public $postData = array('frombg' => 1, 'lid' => 1, 'sid' => 1);
    public function __construct()
    {
        parent::__construct();
        $this->load->helper('cookie');
        $this->load->library('curl');
    }
    public function index($lang = 'zh',$class = 'LEVEL'){
        $posts = $this->postData;
        $posts['mod']   = 'Lang';
        $posts['act']   = 'getLang';
        $posts['lang']  = $lang;
        $posts['class'] = $class;
        $url = $this->config->item('officialUrl');
        $ret = $this->curl->req($url, $posts);
        $ret = json_decode($ret,true);
        $retData['lang']  = $this->_langList;
        $retData['class'] = $ret['class'];
        $retData['data']  = $ret['data'];
        $retData['curLang']  = $lang;
        $retData['curClass'] = $class;
        $this->load->view('lang/index', $retData);
    }

    public function actionLang(){
        $input = $this->input->post();
        $data  = [
            'lang'  => $input['lang'],
            'class' => $input['class'],
        ];
        foreach ($input['name'] as $key=>$row){
            $lang[] = [
                'name'  => $row,
                'path'  => $input['path'][$key],
                'value' => $input['value'][$key],
            ];
        }
        $data['data'] = $lang??[];
        $posts = $this->postData;
        $posts['mod'] = 'Lang';
        $posts['act'] = 'saveLang';
        $posts['data'] = json_encode($data);
        $url = $this->config->item('officialUrl');
        $retData = $this->curl->req($url, $posts);
        if($retData == 0){
            return $this->response(1, '操作失败');
        }else{
            return $this->response(0, '操作成功');
        }
    }
}