<?php

session_start(); // starts new or resumes existing session
Doo::loadModelAt('auser', 'admin');
Doo::loadModelAt('ausers', 'admin');
Doo::loadModelAt('ameasure', 'admin');
Doo::loadModelAt('fileup', 'admin');
Doo::loadModelAt('measureaudit', 'admin');
Doo::loadModelAt('numofper', 'admin');
Doo::loadModel('users');
Doo::loadClass('profile');
Doo::loadClass('PasswordHash');
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 RestoreController extends DooController {

    private $data, $users, $user, $profile, $ph, $userz, $mailer;

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

    public function __construct() {
        $this->users = new AUsers();
        $this->user = new AUser();
        $this->userz = new Users();
        $this->profile = new Profile();
        $this->mailer = new Mailer();
        $this->ph = new PasswordHash(8, FALSE);
        $this->am = new Ameasure();
        $this->ama = new AmeasureAudit();
        $this->af = new Afileup();
        $this->an = new Anumofper();
        $this->data['rootUrl'] = Doo::conf()->APP_URL;
    }

    function restoreList() {
        $mArray = $this->am->getRowAll();
        $this->data['userlist'] = $mArray;
        $this->render('admin-restore', $this->data, TRUE);
    }

    function restoreRedo() {
        /**
         *  存在最新的审批人员列表与最新一期的提交数据不匹配 与其数不匹配问题 （添加判断机制） 
         *  最新一次不显示单选按钮
         *  接口是否也可以更改为当期数数据存在的情况下才显示最新的审批人列表 显示当前期最新的审批人员列表可以这么改
         *  更新全部参与项目是否可以这么修改？哦，应该可以上述问题修改之后，那就可以按照如果不存在这一期数据就返回上一期或者次数数据
         */
        $measureArray = $this->am->getOne(array('where' => 'pmid=?', 'param' => array($this->params['pmid']), 'asArray' => TRUE));
        $numofperArray = $this->an->find(array('where' => 'pmid=?', 'param' => array($this->params['pmid']), 'groupby' => 'numpname', 'asArray' => TRUE));
        foreach ($numofperArray as $key => $value) {
            $tmp = $this->getMaxRowStatus($value['pmid'], $value['numpname']);
            $dd = $this->ama->find(array('where' => 'pmid=? and numpname=? and times=?', 'param' => array($value['pmid'], $value['numpname'], $tmp['times']), 'asArray' => TRUE));
        }
        var_dump($dd);
        $this->data['measurearray'] = $measureArray;
        $this->data['numofperArray'] = $numofperArray;
        $this->render('admin-restore-list', $this->data, TRUE);
    }

    public function getMaxRowStatus($pmid, $numpname) {
        return $this->an->getOne(array('where' => 'pmid=? and numpname=?', 'param' => array($pmid, $numpname), 'desc' => 'times', 'asArray' => TRUE));
    }

}
