/**
  * Class constructor
  * Creates the page, the form and the listing
  */
 public function __construct()
 {
     parent::__construct();
     parent::setDatabase('log');
     // defines the database
     parent::setActiveRecord('SystemAccessLog');
     // defines the active record
     parent::setDefaultOrder('id', 'asc');
     // defines the default order
     parent::addFilterField('login', 'like');
     // add a filter field
     parent::setLimit(20);
     // creates the form, with a table inside
     $this->form = new TQuickForm('form_search_SystemAccessLog');
     $this->form->class = 'tform';
     // CSS class
     $this->form->setFormTitle('Access Log');
     // create the form fields
     $login = new TEntry('login');
     // add the fields
     $this->form->addQuickField(_t('Login'), $login, '80%');
     // keep the form filled during navigation with session data
     $this->form->setData(TSession::getValue('SystemAccessLog_filter_data'));
     // add the search form actions
     $this->form->addQuickAction(_t('Find'), new TAction(array($this, 'onSearch')), 'ico_find.png');
     // creates a DataGrid
     $this->datagrid = new TQuickGrid();
     $this->datagrid->style = 'width: 100%';
     $this->datagrid->setHeight(320);
     // creates the datagrid columns
     $id = $this->datagrid->addQuickColumn('id', 'id', 'left');
     $sessionid = $this->datagrid->addQuickColumn('sessionid', 'sessionid', 'left');
     $login = $this->datagrid->addQuickColumn(_t('Login'), 'login', 'left');
     $login_time = $this->datagrid->addQuickColumn('login_time', 'login_time', 'left');
     $logout_time = $this->datagrid->addQuickColumn('logout_time', 'logout_time', 'left');
     // create the datagrid model
     $this->datagrid->createModel();
     // create the page navigation
     $this->pageNavigation = new TPageNavigation();
     $this->pageNavigation->setAction(new TAction(array($this, 'onReload')));
     $this->pageNavigation->setWidth($this->datagrid->getWidth());
     $container = new TVBox();
     $container->style = 'width: 97%';
     $container->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
     $container->add($this->form);
     $container->add($this->datagrid);
     $container->add($this->pageNavigation);
     parent::add($container);
 }
Ejemplo n.º 2
0
 /**
  * Class constructor
  * Creates the page, the form and the listing
  */
 public function __construct()
 {
     parent::__construct();
     // security check
     if (TSession::getValue('logged') !== TRUE) {
         throw new Exception(_t('Not logged'));
     }
     // security check
     TTransaction::open('changeman');
     if (Member::newFromLogin(TSession::getValue('login'))->role_mnemonic !== 'ADMINISTRATOR' and Member::newFromLogin(TSession::getValue('login'))->role_mnemonic !== 'MANAGER') {
         throw new Exception(_t('Permission denied'));
     }
     TTransaction::close();
     // defines the database
     parent::setDatabase('changeman');
     // defines the active record
     parent::setActiveRecord('Member');
     // defines the filter field
     parent::setFilterField('name');
     parent::setLimit(50);
     // creates the form
     $this->form = new TForm('form_search_Member');
     // creates a table
     $table = new TTable();
     $table->width = '100%';
     // add the table inside the form
     $this->form->add($table);
     $this->form->class = 'tform';
     $table->addRowSet(new TLabel(_t('Members')), '')->class = 'tformtitle';
     // create the form fields
     $filter = new TEntry('name');
     $filter->setSize(400);
     $filter->setValue(TSession::getValue('Member_name'));
     // add a row for the filter field
     $row = $table->addRow();
     $row->addCell(new TLabel(_t('Name') . ': '));
     $row->addCell($filter);
     // create two action buttons to the form
     $find_button = new TButton('find');
     $new_button = new TButton('new');
     // define the button actions
     $find_button->setAction(new TAction(array($this, 'onSearch')), _t('Find'));
     $find_button->setImage('ico_find.png');
     $class = 'MemberForm';
     $new_button->setAction(new TAction(array($class, 'onEdit')), _t('New'));
     $new_button->setImage('ico_new.png');
     $buttons = new THBox();
     $buttons->add($find_button);
     $buttons->add($new_button);
     $row = $table->addRow();
     $row->class = 'tformaction';
     $cell = $row->addCell($buttons);
     $cell->colspan = 2;
     // define wich are the form fields
     $this->form->setFields(array($filter, $find_button, $new_button));
     // creates a DataGrid
     $this->datagrid = new TQuickGrid();
     $this->datagrid->setHeight(320);
     // creates the datagrid columns
     $this->datagrid->addQuickColumn('ID', 'id', 'right', 50, new TAction(array($this, 'onReload')), array('order', 'id'));
     $this->datagrid->addQuickColumn(_t('Name'), 'name', 'left', 160, new TAction(array($this, 'onReload')), array('order', 'name'));
     $this->datagrid->addQuickColumn(_t('Role'), 'role_description', 'left', 140, new TAction(array($this, 'onReload')), array('order', 'id_role'));
     $this->datagrid->addQuickColumn('Login', 'login', 'left', 100, new TAction(array($this, 'onReload')), array('order', 'login'));
     $this->datagrid->addQuickColumn('Email', 'email', 'left', 100, new TAction(array($this, 'onReload')), array('order', 'email'));
     $this->datagrid->addQuickColumn(_t('Active'), 'is_active', 'left', 70, new TAction(array($this, 'onReload')), array('order', 'active'));
     // add the actions to the datagrid
     $class = 'MemberForm';
     $this->datagrid->addQuickAction(_t('Edit'), new TDataGridAction(array($class, 'onEdit')), 'id', 'ico_edit.png');
     $this->datagrid->addQuickAction(_t('Delete'), new TDataGridAction(array($this, 'onDelete')), 'id', 'ico_delete.png');
     // create the datagrid model
     $this->datagrid->createModel();
     // creates the page navigation
     $this->pageNavigation = new TPageNavigation();
     $this->pageNavigation->setAction(new TAction(array($this, 'onReload')));
     $this->pageNavigation->setWidth($this->datagrid->getWidth());
     // creates the page structure using a vbox
     $container = new TVBox();
     $container->add($this->form);
     $container->add($this->datagrid);
     $container->add($this->pageNavigation);
     // add the vbox inside the page
     parent::add($container);
 }
 public function __construct()
 {
     parent::__construct();
     parent::setDatabase('log');
     parent::setActiveRecord('SystemChangeLog');
     parent::addFilterField('tablename');
     parent::addFilterField('login');
     parent::setLimit(20);
     $this->form = new TQuickForm('form_table_logger');
     $this->form->{'class'} = 'tform';
     // CSS class
     $this->form->setFormTitle('Table change log');
     // cria os campos do formulário
     $tablename = new TEntry('tablename');
     $login = new TEntry('login');
     $this->form->addQuickField(_t('Table'), $tablename);
     $this->form->addQuickField('Login', $login);
     $tablename->setSize('80%');
     $login->setSize('80%');
     $this->form->addQuickAction(_t('Search'), new TAction(array($this, 'onSearch')), 'ico_find.png');
     $this->formgrid = new TForm();
     // instancia objeto DataGrid
     $this->datagrid = new TDataGrid();
     $this->datagrid->style = 'width: 100%';
     $this->datagrid->datatable = 'true';
     $this->datagrid->setHeight(320);
     parent::setTransformer(array($this, 'onBeforeLoad'));
     // datagrid inside form
     $this->formgrid->add($this->datagrid);
     // instancia as colunas da DataGrid
     $id = new TDataGridColumn('pkvalue', 'PK', 'center');
     $date = new TDataGridColumn('logdate', _t('Date'), 'center');
     $login = new TDataGridColumn('login', 'Login', 'center');
     $name = new TDataGridColumn('tablename', _t('Table'), 'left');
     $column = new TDataGridColumn('columnname', _t('Column'), 'left');
     $operation = new TDataGridColumn('operation', _t('Operation'), 'left');
     $oldvalue = new TDataGridColumn('oldvalue', _t('Old value'), 'left');
     $newvalue = new TDataGridColumn('newvalue', _t('New value'), 'left');
     $operation->setTransformer(function ($value, $object, $row) {
         if ($value == 'created') {
             return "<span style='color:green'>{$value}</span>";
         } else {
             if ($value == 'deleted') {
                 return "<span style='color:red'>{$value}</span>";
             } else {
                 if ($value == 'changed') {
                     return "<span style='color:blue'>{$value}</span>";
                 }
             }
         }
         return $value;
     });
     $order1 = new TAction(array($this, 'onReload'));
     $order2 = new TAction(array($this, 'onReload'));
     $order3 = new TAction(array($this, 'onReload'));
     $order4 = new TAction(array($this, 'onReload'));
     $order5 = new TAction(array($this, 'onReload'));
     $order1->setParameter('order', 'pkvalue');
     $order2->setParameter('order', 'logdate');
     $order3->setParameter('order', 'login');
     $order4->setParameter('order', 'tablename');
     $order5->setParameter('order', 'columnname');
     $id->setAction($order1);
     $date->setAction($order2);
     $login->setAction($order3);
     $name->setAction($order4);
     $column->setAction($order5);
     // adiciona as colunas à DataGrid
     $this->datagrid->addColumn($id);
     $this->datagrid->addColumn($date);
     $this->datagrid->addColumn($login);
     $this->datagrid->addColumn($name);
     $this->datagrid->addColumn($column);
     $this->datagrid->addColumn($operation);
     $this->datagrid->addColumn($oldvalue);
     $this->datagrid->addColumn($newvalue);
     // cria o modelo da DataGrid, montando sua estrutura
     $this->datagrid->createModel();
     // cria o paginador
     $this->pageNavigation = new TPageNavigation();
     $this->pageNavigation->setAction(new TAction(array($this, 'onReload')));
     $this->pageNavigation->setWidth($this->datagrid->getWidth());
     $container = new TVBox();
     $container->style = 'width: 97%';
     $container->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
     $container->add($this->form);
     $container->add($this->formgrid);
     $container->add($this->pageNavigation);
     parent::add($container);
 }