<?php

session_start(); // starts new or resumes existing session
Doo::loadModelAt('aconfig', 'admin');
Doo::loadModelAt('auser', 'admin');
Doo::loadClass('mailer');

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

// 列表停用 编辑 重置密码
// 管理员权限管理
// 管理员修改密码
class SysController extends DooController {

    private $data, $aconfig, $auser, $profile, $ph, $userz, $mailer;

    public function beforeRun($resource, $action) {
        if (!isset($_SESSION['auid'])) {
            return Doo::conf()->APP_URL . 'manage';
        }
    }

    public function __construct() {
        $this->aconfig = new AConfig();
        $this->auser = new AUser();
        $this->mailer = new Mailer();
        $this->data['rootUrl'] = Doo::conf()->APP_URL;
    }

    function sysinfo() {
        if (isset($_POST['proname']) || isset($_POST['aemail'])) {
            if ($_POST['proname']) {
                $this->aconfig->proname = $_POST['proname'];
                $this->aconfig->update(array('where' => 'conid = 1'));
            }
            if ($_POST['aemail'] && filter_var($_POST['aemail'], FILTER_VALIDATE_EMAIL)) {
                $this->auser->aemail = $_POST['aemail'];
                $this->auser->update(array('where' => 'auid = 1'));
                $this->mailer->setEmails($_POST['aemail']);
                $this->mailer->seteTitle('管理员邮箱地址已修改');
                $this->mailer->setClientName($_SESSION['aname']);
                $signupConfigStr = '<h3>管理员邮箱地址已修改</h3><p><h2>' . $_POST['aemail'] . '</h2></p>';
                $this->mailer->setContent($signupConfigStr);
                $this->mailer->send_mail();
            }
            return Doo::conf()->APP_URL . 'manage/sys/info';
        }
        $this->data['proName'] = $this->aconfig->getOne(array('select' => 'proName', 'asArray' => TRUE))['proName'];
        $this->data['aemail'] = $this->auser->getOne(array('select' => 'aemail', 'asArray' => TRUE))['aemail'];
        $this->data['ver'] = DOO::conf()->ver;
        $this->data['aname'] = $_SESSION['aname'];
        $this->data['menu'] = 1;
        $this->render('admin-sysinfo', $this->data, TRUE);
    }

}
