<?php
/*
 * PiAnoS (Picture Annotation System), A fingerprint examiner training tool
 * Copyright (C) 2011-2013 University of Lausanne, Switzerland
 * https://ips-labs.unil.ch/pianos
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see http://www.gnu.org/licenses/.
 */
require_once ( "unil/JTableDriver.php" );
class UserCollection extends JTableCollection
{
    function __construct()
    {
        parent::__construct( 'person', array (
                array (
                        'name' => 'id', 
                        'type' => 'int', 
                        'key' => true 
                ), 
                array (
                        'name' => 'username', 
                        'type' => 'text', 
                        'ro' => true, 
                        'validation' => 'required' 
                ), 
                array (
                        'name' => 'name', 
                        'type' => 'text', 
                        'title' => 'Name', 
                        'validation' => 'required' 
                ), 
                array (
                        'name' => 'active', 
                        'type' => 'bool', 
                        'formText' => 'blah' 
                ), 
                array (
                        'name' => 'email', 
                        'type' => 'text', 
                        'validation' => 'custom[email]' 
                ), 
                array (
                        'name' => 'password', 
                        'type' => 'password', 
                        'ro' => true, 
                        'list' => false, 
                        'validation' => 'required' 
                ), 
                array (
                        'name' => 'language', 
                        'type' => 'int', 
                        'fk' => array (
                                'language', 
                                'id', 
                                'name' 
                        ) 
                ) 
        ) );
        $this->setDefaultInsertValues( array (
                'suitability_approach' => 2 
        ) );
    }
    
    // public function getRecords()
    // {
    // $res = Application::instance()->getDB()->query("SELECT * FROM person");
    // return $res;
    // //return array(array('id'=>2, 'name'=>'toto'), array('id'=>12, 'name'=>'tata'));
    // }
}
class MyJTableDriver extends JTableDriver
{
    protected function initCollections()
    {
        $this->addCollection( 'users', new UserCollection() );
    }
}
class MainDriver_LE extends ContentDriver
{
    public function accept()
    {
        return isset( $_SESSION[ 'user' ] );
    }
    protected function doHandleRequest()
    {
        if( ! isset( $_SESSION[ 'user' ] ) )
            throw new Exception( "Assertion failed" );
        
        $action = isset( $_GET[ 'action' ] ) ? $_GET[ 'action' ]: 'main';
        
        switch( $action )
        {
            case 'main':
            default:
                require_once ( "MainFrame.php" );
                $mainFrame = new MainFrame();
                $this->printHtml( $mainFrame );
                break;
        }
    }
}
