<?php

Doo::loadClass('auth');
Doo::loadClass('attfile');
Doo::loadClass('profile');

/**
 * MainController
 * Feel free to delete the methods and replace them with your own code.
 *
 * @author darkredz
 */
class MainController extends DooController {

    private $data, $auth, $attfile, $profile;

    public function __construct() {
	$this->auth = new Auth();
	$this->attfile = new attFile();
	$this->profile = new Profile();
	$this->data['rootUrl'] = Doo::conf()->APP_URL;
	$this->data['currChannle'] = 'p';
    }

    public function welcome() {
//	if (!$this->auth->isLoggedIn())
//	    return Doo::conf()->APP_URL;
	if ($this->profile->getProWithUid($_SESSION['uid'])['userid'])
	    return Doo::conf()->APP_URL . 'project/index';
	if (isset($_POST['welform'])) {
	    $profileUserArray = $_POST;
	    $profileUserArray['userid'] = $_SESSION['uid'];
	    $this->profile->insertProfile($profileUserArray); // 无自增字段返回0
	    return Doo::conf()->APP_URL . 'project/list';
	}
	$this->render('welcome', $this->data);
    }

    public function prolist() {
//	if (!$this->auth->isLoggedIn())
//	    return Doo::conf()->APP_URL;
	$proArray = new stdClass();
//	$jsonpath = pathinfo($this->attfile->getMaxRow()['filepath']);
//	$extPathdir = Doo::conf()->SITE_PATH . $jsonpath['dirname'] . '/' . $jsonpath['filename'];
//	if ($handle = opendir($extPathdir)) {
//	    while (false !== ($file = readdir($handle))) {
//		$filename = pathinfo($file);
//		if ($filename['extension'] == 'json')
//		    $proArray = json_decode(file_get_contents($extPathdir . '/' . $file));
//	    }
//	    closedir($handle);
//	}
	$this->data['proArray'] = $proArray;
	$this->render('s-project', $this->data);
    }

}

?>