<?php

use Adianti\Widget\Wrapper\TDBCombo;

/**
 * Created by PhpStorm.
 * User: Claudio
 * Date: 15/05/2020
 * Time: 21:18
 */
class EscolheOperador extends TPage
{
    public function __construct($param)
    {
        parent::__construct();
        new TSession;

        // creates the items form and add a table inside
        $this->form_item = new TForm('form');
        $this->form_item->class = 'tform';
        $table_item = new TTable;
        $table_item->width = '100%';
        $this->form_item->add($table_item);

//        var_dump($_SESSION);exit;

        $ponto_view = new TCombo('destino');
        if (in_array('2', TSession::getValue('usergroupids'))) {
            $criteria = new TCriteria();
            $criteria->add(new TFilter('system_group_id', '>', 2));
            $criteria->setProperty('order', 'system_user_id');
            TTransaction::open('jackpot');
            $repository = new TRepository('SystemUserGroup');
            $result = $repository->load($criteria);
            $combo_items = array();
            foreach ($result as $item) {
                $quem = new SystemUser($item->system_user_id);
                if ($quem->active == 'N') {

                } else {
                    $combo_items[$item->system_user_id] = strtoupper($quem->name);
                }
            }
            TTransaction::close();
        } else {
            $combo_items[TSession::getValue('userid')] = strtoupper(TSession::getValue('username'));
        }
        asort($combo_items);
        $ponto_view->additems($combo_items);
        $acao = new TAction(array($this, 'onExitPonto'));
        $ponto_view->setChangeAction($acao);

        // add validators
        $ponto_view->addValidation('Operador', new TRequiredValidator);

        // define some attributes
        $ponto_view->style = 'font-size: 17pt; height: 30px; text-align: center;';

        // add a row for the form title
        $row = $table_item->addRow();
        $row->class = 'tformtitle'; // CSS class
        $row->addCell(new TLabel('ESCOLHA O OPERADOR'))->style = 'text-align: center;';

        // create the field labels
        $lab_cli = new TLabel('OPERADOR');
        $lab_cli->setFontSize(17);
        $lab_cli->setFontFace('Trebuchet MS');

        $table_item->addRowSet($lab_cli)->style = 'text-align: center;';
        $table_item->addRowSet($ponto_view)->style = 'text-align: center;';

        // define the form fields
        $this->form_item->setFields(array($ponto_view));

        // wrap the page content using vertical box
        $vbox = new TVBox;
        $vbox->style = 'width: 100%; text-align: center;';
        $vbox->add($this->form_item);
        parent::add($vbox);
    }

public
static function onExitPonto($param)
{

//        var_dump($param);exit;
    TApplication::loadPage('Semanal', $param['key']);
}
}
