Exemplo n.º 1
0
 /**
  * Validate a given value
  * @param $label Identifies the value to be validated in case of exception
  * @param $value Value to be validated
  * @param $parameters aditional parameters for validation (min value)
  */
 public function validate($label, $value, $parameters = NULL)
 {
     $minvalue = $parameters[0];
     if ($value < $minvalue) {
         throw new Exception(AdiantiCoreTranslator::translate('The field ^1 can not be less than ^2', $label, $minvalue));
     }
 }
Exemplo n.º 2
0
 /**
  * Class Constructor
  * @param $type    Type of the message (info, error)
  * @param $message Message to be shown
  * @param $action  Action to be processed when closing the dialog
  * @param $title_msg  Dialog Title
  */
 public function __construct($type, $message, TAction $action = NULL, $title_msg = '')
 {
     $this->id = 'tmessage_' . mt_rand(1000000000, 1999999999);
     $modal_wrapper = new TElement('div');
     $modal_wrapper->{'class'} = 'modal';
     $modal_wrapper->{'id'} = $this->id;
     $modal_wrapper->{'style'} = 'padding-top: 10%; z-index:4000';
     $modal_wrapper->{'tabindex'} = '-1';
     $modal_dialog = new TElement('div');
     $modal_dialog->{'class'} = 'modal-dialog';
     $modal_content = new TElement('div');
     $modal_content->{'class'} = 'modal-content';
     $modal_header = new TElement('div');
     $modal_header->{'class'} = 'modal-header';
     if ($type == 'info') {
         $image = new TImage("fa:fa fa-info-circle fa-5x blue");
     } else {
         $image = new TImage("fa:fa fa-exclamation-circle fa-5x red");
     }
     $image->{'style'} = 'float:left; margin-right: 10px;';
     $close = new TElement('button');
     $close->{'type'} = 'button';
     $close->{'class'} = 'close';
     $close->{'data-dismiss'} = 'modal';
     $close->{'aria-hidden'} = 'true';
     $close->add('×');
     $title = new TElement('h4');
     $title->{'class'} = 'modal-title';
     $title->{'style'} = 'display:inline';
     $title->add($title_msg ? $title_msg : ($type == 'info' ? AdiantiCoreTranslator::translate('Information') : AdiantiCoreTranslator::translate('Error')));
     $body = new TElement('div');
     $body->{'style'} = 'text-align:left';
     $body->{'class'} = 'modal-body';
     $body->add($image);
     $span = new TElement('span');
     $span->add($message);
     $body->add($span);
     $button = new TElement('button');
     $button->{'class'} = 'btn btn-default';
     $button->{'data-dismiss'} = 'modal';
     $button->{'onclick'} = "\$( '.modal-backdrop' ).last().remove(); \$('#{$this->id}').modal('hide'); \$('body').removeClass('modal-open');";
     $button->add('OK');
     if ($action) {
         $button->{'onclick'} .= "__adianti_load_page('{$action->serialize()}');";
         $button->{'data-toggle'} = "modal";
     }
     $footer = new TElement('div');
     $footer->{'class'} = 'modal-footer';
     $modal_wrapper->add($modal_dialog);
     $modal_dialog->add($modal_content);
     $modal_content->add($modal_header);
     $modal_header->add($close);
     $modal_header->add($title);
     $modal_content->add($body);
     $modal_content->add($footer);
     $footer->add($button);
     $modal_wrapper->show();
     $callback = 'function () {' . $button->{'onclick'} . '}';
     TScript::create("tdialog_start( '#{$this->id}', {$callback} );");
 }
Exemplo n.º 3
0
 /**
  * Class Constructor
  * @param  $name name of the form field
  * @param  $database name of the database connection
  * @param  $form name of the parent form
  * @param  $model name of the Active Record to be searched
  * @param  $display_field name of the field to be searched and shown
  * @param  $receive_key name of the form field to receive the primary key
  * @param  $receive_display_field name of the form field to receive the "display field"
  * @param  $display_field2 name of the #2 field to be searched and shown
  */
 public function __construct($name, $database, $form, $model, $display_field, $receive_key, $receive_display_field, TCriteria $criteria = NULL, $display_field2 = NULL)
 {
     parent::__construct($name);
     if (empty($database)) {
         throw new Exception(AdiantiCoreTranslator::translate('The parameter (^1) of ^2 is required', 'database', __CLASS__));
     }
     if (empty($model)) {
         throw new Exception(AdiantiCoreTranslator::translate('The parameter (^1) of ^2 is required', 'model', __CLASS__));
     }
     if (empty($display_field)) {
         throw new Exception(AdiantiCoreTranslator::translate('The parameter (^1) of ^2 is required', 'display_field', __CLASS__));
     }
     $obj = new TStandardSeek2();
     // define the action parameters
     $action = new TAction(array($obj, 'onSetup'));
     $action->setParameter('database', $database);
     $action->setParameter('parent', $form);
     $action->setParameter('model', $model);
     $action->setParameter('display_field', $display_field);
     $action->setParameter('receive_key', $receive_key);
     $action->setParameter('receive_field', $receive_display_field);
     $action->setParameter('criteria', base64_encode(serialize($criteria)));
     $action->setParameter('display_field2', $display_field2);
     parent::setAction($action);
 }
Exemplo n.º 4
0
 /**
  * Show the widget at the screen
  */
 public function show()
 {
     // define the tag properties
     $this->tag->name = $this->name;
     // tag name
     $this->tag->value = $this->value;
     // tag value
     $this->tag->type = 'password';
     // input type
     if (strstr($this->size, '%') !== FALSE) {
         $this->setProperty('style', "width:{$this->size};", FALSE);
         //aggregate style info
     } else {
         $this->setProperty('style', "width:{$this->size}px;", FALSE);
         //aggregate style info
     }
     // verify if the field is not editable
     if (parent::getEditable()) {
         if (isset($this->exitAction)) {
             if (!TForm::getFormByName($this->formName) instanceof TForm) {
                 throw new Exception(AdiantiCoreTranslator::translate('You must pass the ^1 (^2) as a parameter to ^3', __CLASS__, $this->name, 'TForm::setFields()'));
             }
             $string_action = $this->exitAction->serialize(FALSE);
             $this->setProperty('onBlur', "__adianti_post_lookup('{$this->formName}', '{$string_action}', this)");
         }
     } else {
         // make the field read-only
         $this->tag->readonly = "1";
         $this->tag->{'class'} = 'tfield_disabled';
         // CSS
     }
     // show the tag
     $this->tag->show();
 }
Exemplo n.º 5
0
 public function onSave()
 {
     try {
         // open a transaction with database
         TTransaction::open($this->database);
         // get the form data
         $object = $this->form->getData($this->activeRecord);
         // validate data
         $this->form->validate();
         // stores the object
         $object->store();
         // fill the form with the active record data
         $this->form->setData($object);
         // close the transaction
         TTransaction::close();
         // shows the success message
         //new TMessage('info', AdiantiCoreTranslator::translate('Record saved'));
         parent::add(new TAlert('info', AdiantiCoreTranslator::translate('Record saved')));
         $this->form->clear();
         return $object;
     } catch (Exception $e) {
         // get the form data
         $object = $this->form->getData($this->activeRecord);
         // fill the form with the active record data
         $this->form->setData($object);
         // shows the exception error message
         new TMessage('error', $e->getMessage());
         // undo all pending operations
         TTransaction::rollback();
     }
 }
 /**
  * Validate a given value
  * @param $label Identifies the value to be validated in case of exception
  * @param $value Value to be validated
  * @param $parameters aditional parameters for validation (length)
  */
 public function validate($label, $value, $parameters = NULL)
 {
     $length = $parameters[0];
     if (strlen($value) > $length) {
         throw new Exception(AdiantiCoreTranslator::translate('The field ^1 can not be greater than ^2 characters', $label, $length));
     }
 }
Exemplo n.º 7
0
 /**
  * Handle paths from a XML file
  * @param $xml_file path for the file
  */
 public function __construct($xml_file, $controller)
 {
     parent::__construct();
     $path = array();
     if (file_exists($xml_file)) {
         $menu_string = file_get_contents($xml_file);
         if (utf8_encode(utf8_decode($menu_string)) == $menu_string) {
             $xml = new SimpleXMLElement($menu_string);
         } else {
             $xml = new SimpleXMLElement(utf8_encode($menu_string));
         }
         foreach ($xml as $xmlElement) {
             $atts = $xmlElement->attributes();
             $label = (string) $atts['label'];
             $action = (string) $xmlElement->action;
             $icon = (string) $xmlElement->icon;
             $this->parse($xmlElement->menu->menuitem, array($label));
         }
         if (isset($this->paths[$controller]) and $this->paths[$controller]) {
             $total = count($this->paths[$controller]);
             parent::addHome($path);
             $count = 1;
             foreach ($this->paths[$controller] as $path) {
                 parent::addItem($path, $count == $total);
                 $count++;
             }
         } else {
             throw new Exception(AdiantiCoreTranslator::translate('Class ^1 not found in ^2', $controller, $xml_file));
         }
     } else {
         throw new Exception(AdiantiCoreTranslator::translate('File not found') . ': ' . $xml_file);
     }
 }
Exemplo n.º 8
0
 /**
  * Validate a given value
  * @param $label Identifies the value to be validated in case of exception
  * @param $value Value to be validated
  * @param $parameters aditional parameters for validation
  */
 public function validate($label, $value, $parameters = NULL)
 {
     $cnpj = preg_replace("@[./-]@", "", $value);
     if (strlen($cnpj) != 14 or !is_numeric($cnpj)) {
         throw new Exception(AdiantiCoreTranslator::translate('The field ^1 has not a valid CNPJ', $label));
     }
     $k = 6;
     $soma1 = "";
     $soma2 = "";
     for ($i = 0; $i < 13; $i++) {
         $k = $k == 1 ? 9 : $k;
         $soma2 += $cnpj[$i] * $k;
         $k--;
         if ($i < 12) {
             if ($k == 1) {
                 $k = 9;
                 $soma1 += $cnpj[$i] * $k;
                 $k = 1;
             } else {
                 $soma1 += $cnpj[$i] * $k;
             }
         }
     }
     $digito1 = $soma1 % 11 < 2 ? 0 : 11 - $soma1 % 11;
     $digito2 = $soma2 % 11 < 2 ? 0 : 11 - $soma2 % 11;
     $valid = ($cnpj[12] == $digito1 and $cnpj[13] == $digito2);
     if (!$valid) {
         throw new Exception(AdiantiCoreTranslator::translate('The field ^1 has not a valid CNPJ', $label));
     }
 }
Exemplo n.º 9
0
 /**
  * Class Constructor
  * @param $action Callback to be executed
  */
 public function __construct($action)
 {
     $this->action = $action;
     if (!is_callable($this->action)) {
         $action_string = $this->toString();
         throw new Exception(AdiantiCoreTranslator::translate('Method ^1 must receive a paremeter of type ^2', __METHOD__, 'Callback') . ' <br> ' . AdiantiCoreTranslator::translate('Check if the action (^1) exists', $action_string));
     }
 }
Exemplo n.º 10
0
 /**
  * method setActiveRecord()
  * Define wich Active Record class will be used
  */
 public function setActiveRecord($activeRecord)
 {
     if (is_subclass_of($activeRecord, 'TRecord')) {
         $this->activeRecord = $activeRecord;
     } else {
         throw new Exception(AdiantiCoreTranslator::translate('The class ^1 must be subclass of ^2', $activeRecord, 'TRecord'));
     }
 }
Exemplo n.º 11
0
 /**
  * Constructor Method
  * Creates the page, the search form and the listing
  */
 public function __construct()
 {
     parent::__construct();
     parent::setTitle(AdiantiCoreTranslator::translate('Search record'));
     parent::setSize(800, 500);
     // creates a new form
     $this->form = new TForm('form_standard_seek');
     // creates a new table
     $table = new TTable();
     // adds the table into the form
     $this->form->add($table);
     // create the form fields
     $display_field = new TEntry('display_field');
     $display_field->setSize(370);
     // keeps the field's value
     $display_field->setValue(TSession::getValue('tstandardseek_display_value'));
     // create the action button
     $find_button = new TButton('busca');
     // define the button action
     $find_button->setAction(new TAction(array($this, 'onSearch')), AdiantiCoreTranslator::translate('Search'));
     $find_button->setImage('ico_find.png');
     // add a row for the filter field
     $table->addRowSet(new TLabel(_t('Search') . ': '), $display_field, $find_button);
     // define wich are the form fields
     $this->form->setFields(array($display_field, $find_button));
     // creates a new datagrid
     $this->datagrid = new TDataGrid();
     // create two datagrid columns
     $id = new TDataGridColumn('id', 'ID', 'right', 70);
     $display = new TDataGridColumn('display_field', AdiantiCoreTranslator::translate('Field'), 'left', 570);
     // add the columns to the datagrid
     $this->datagrid->addColumn($id);
     $this->datagrid->addColumn($display);
     // create a datagrid action
     $action1 = new TDataGridAction(array($this, 'onSelect'));
     $action1->setLabel('Selecionar');
     $action1->setImage('ico_apply.png');
     $action1->setField('id');
     // add the actions to the datagrid
     $this->datagrid->addAction($action1);
     // create the datagrid model
     $this->datagrid->createModel();
     // creates the paginator
     $this->pageNavigation = new TPageNavigation();
     $this->pageNavigation->setAction(new TAction(array($this, 'onReload')));
     $this->pageNavigation->setWidth($this->datagrid->getWidth());
     // creates the container
     $vbox = new TVBox();
     $vbox->add($this->form);
     $vbox->add($this->datagrid);
     $vbox->add($this->pageNavigation);
     // add the container to the page
     parent::add($vbox);
 }
Exemplo n.º 12
0
 /**
  * Add a new cell (TTableCell) to the Table Row
  * @param  $value Cell Content
  * @return TTableCell
  */
 public function addCell($value)
 {
     if (is_null($value)) {
         throw new Exception(AdiantiCoreTranslator::translate('Method ^1 does not accept null values', __METHOD__));
     } else {
         // creates a new Table Cell
         $cell = new TTableCell($value);
         parent::add($cell);
         // returns the cell object
         return $cell;
     }
 }
Exemplo n.º 13
0
 /**
  * Constructor method
  */
 function __construct(Exception $e)
 {
     $error_array = $e->getTrace();
     $table = new TTable();
     $row = $table->addRow();
     $row->addCell('<b>' . $e->getMessage() . '</b><br>');
     $row = $table->addRow();
     $row->addCell('&nbsp;');
     foreach ($error_array as $error) {
         $file = isset($error['file']) ? $error['file'] : '';
         $line = isset($error['line']) ? $error['line'] : '';
         $file = str_replace(PATH, '', $file);
         $row = $table->addRow();
         $row->addCell('File: ' . $file . ' : ' . $line);
         $row = $table->addRow();
         $args = array();
         if ($error['args']) {
             foreach ($error['args'] as $arg) {
                 if (is_object($arg)) {
                     $args[] = get_class($arg) . ' object';
                 } else {
                     if (is_array($arg)) {
                         $array_param = array();
                         foreach ($arg as $value) {
                             if (is_object($value)) {
                                 $array_param[] = get_class($value);
                             } else {
                                 if (is_array($value)) {
                                     $array_param[] = 'array';
                                 } else {
                                     $array_param[] = $value;
                                 }
                             }
                         }
                         $args[] = implode(',', $array_param);
                     } else {
                         $args[] = (string) $arg;
                     }
                 }
             }
         }
         $class = isset($error['class']) ? $error['class'] : '';
         $type = isset($error['type']) ? $error['type'] : '';
         $row->addCell('&nbsp;&nbsp;<i>' . '<font color=green>' . $class . '</font>' . '<font color=olive>' . $type . '</font>' . '<font color=darkblue>' . $error['function'] . '</font>' . '(' . '<font color=maroon>' . implode(',', $args) . '</font>' . ')</i>');
     }
     $scroll = new TScroll();
     $scroll->setSize(690, 390);
     $scroll->add($table);
     ob_start();
     $table->show();
     $content = ob_get_clean();
     new TMessage('error', $content, NULL, AdiantiCoreTranslator::translate('Exception'));
 }
Exemplo n.º 14
0
 /**
  * Add a new cell (TTableCell) to the Table Row
  * @param  $value Cell Content
  * @return TTableCell
  */
 public function addCell($content)
 {
     if (is_null($content)) {
         throw new Exception(AdiantiCoreTranslator::translate('Method ^1 does not accept null values', __METHOD__));
     } else {
         if (is_string($content)) {
             $content = new GtkLabel($content);
         }
         $cell = new TTableCell($content);
         $this->cells[] = $cell;
         return $cell;
     }
 }
Exemplo n.º 15
0
 /**
  * Define the field quantity per row
  * @param $count Field count
  */
 public function setFieldsByRow($count)
 {
     if (is_int($count) and $count >= 1 and $count <= 3) {
         $this->fieldsByRow = $count;
         if (!empty($this->titleCell)) {
             $this->titleCell->{'colspan'} = 2 * $this->fieldsByRow;
         }
         if (!empty($this->actionCell)) {
             $this->actionCell->{'colspan'} = 2 * $this->fieldsByRow;
         }
     } else {
         throw new Exception(AdiantiCoreTranslator::translate('The method (^1) just accept values of type ^2 between ^3 and ^4', __METHOD__, 'integer', 1, 3));
     }
 }
Exemplo n.º 16
0
 /**
  * Open a File Dialog
  * @param $file File Name
  */
 public function openFile($file)
 {
     $ini = parse_ini_file('application.ini');
     $viewer = $ini['viewer'];
     if (file_exists($viewer)) {
         if (OS != 'WIN') {
             exec("{$viewer} {$file} >/dev/null &");
         } else {
             $WshShell = new COM("WScript.Shell");
             $WshShell->Run("{$file}", 0, true);
         }
     } else {
         throw new Exception(AdiantiCoreTranslator::translate('File not found') . ': ' . $viewer);
     }
 }
 public static function run($debug = FALSE)
 {
     $class = isset($_REQUEST['class']) ? $_REQUEST['class'] : '';
     $static = isset($_REQUEST['static']) ? $_REQUEST['static'] : '';
     $method = isset($_REQUEST['method']) ? $_REQUEST['method'] : '';
     $content = '';
     set_error_handler(array('AdiantiCoreApplication', 'errorHandler'));
     if (class_exists($class)) {
         if ($static) {
             $rf = new ReflectionMethod($class, $method);
             if ($rf->isStatic()) {
                 call_user_func(array($class, $method), $_REQUEST);
             } else {
                 call_user_func(array(new $class($_GET), $method), $_REQUEST);
             }
         } else {
             try {
                 $page = new $class($_GET);
                 ob_start();
                 $page->show($_GET);
                 $content = ob_get_contents();
                 ob_end_clean();
             } catch (Exception $e) {
                 ob_start();
                 if ($debug) {
                     new TExceptionView($e);
                     $content = ob_get_contents();
                 } else {
                     new TMessage('error', $e->getMessage());
                     $content = ob_get_contents();
                 }
                 ob_end_clean();
             }
         }
     } else {
         if (function_exists($method)) {
             call_user_func($method, $_REQUEST);
         } else {
             new TMessage('error', AdiantiCoreTranslator::translate('Class ^1 not found', " <b><i><u>{$class}</u></i></b>") . '.<br>' . AdiantiCoreTranslator::translate('Check the class name or the file name') . '.');
         }
     }
     if (!$static) {
         echo TPage::getLoadedCSS();
     }
     echo TPage::getLoadedJS();
     echo $content;
 }
Exemplo n.º 18
0
 /**
  * Class Constructor
  * @param  $name name of the field
  */
 public function __construct($name)
 {
     if (empty($name)) {
         $rc = new ReflectionClass($this);
         $classname = $rc->getShortName();
         throw new Exception(AdiantiCoreTranslator::translate('The parameter (^1) of ^2 constructor is required', 'name', $classname));
     }
     // define some default properties
     self::setEditable(TRUE);
     self::setName(trim($name));
     self::setSize(200);
     // initialize validations array
     $this->validations = array();
     // creates a <input> tag
     $this->tag = new TElement('input');
     $this->tag->{'class'} = 'tfield';
     // classe CSS
 }
Exemplo n.º 19
0
 /**
  * Class Constructor
  * @param  $name     widget's name
  * @param  $database database name
  * @param  $model    model class name
  * @param  $value    table field to be listed in the combo
  * @param  $ordercolumn column to order the fields (optional)
  * @param  $criteria criteria (TCriteria object) to filter the model (optional)
  */
 public function __construct($name, $database, $model, $value, $orderColumn = NULL, TCriteria $criteria = NULL)
 {
     // executes the parent class constructor
     parent::__construct($name);
     if (empty($database)) {
         throw new Exception(AdiantiCoreTranslator::translate('The parameter (^1) of ^2 is required', 'database', __CLASS__));
     }
     if (empty($model)) {
         throw new Exception(AdiantiCoreTranslator::translate('The parameter (^1) of ^2 is required', 'model', __CLASS__));
     }
     if (empty($value)) {
         throw new Exception(AdiantiCoreTranslator::translate('The parameter (^1) of ^2 is required', 'value', __CLASS__));
     }
     $this->minLength = 1;
     $this->database = $database;
     $this->model = $model;
     $this->column = $value;
     $this->operator = 'like';
     $this->orderColumn = isset($orderColumn) ? $orderColumn : NULL;
     $this->criteria = $criteria;
 }
Exemplo n.º 20
0
 /**
  * Class Constructor
  * @param $caption Button caption
  * @param $form    Dialog form body
  * @param $action  Action to be processed when closing the dialog
  * @param $title_msg  Dialog Title
  */
 public function __construct($title_msg, TForm $form, TAction $action = NULL, $caption = '')
 {
     parent::__construct('', NULL, Gtk::DIALOG_MODAL);
     parent::set_position(Gtk::WIN_POS_CENTER);
     parent::set_title($title_msg ? $title_msg : AdiantiCoreTranslator::translate('Input'));
     $actions = array();
     $action_counter = 0;
     if ($form instanceof TQuickForm) {
         $form->delActions();
         $actionButtons = $form->getActionButtons();
         foreach ($actionButtons as $key => $button) {
             parent::add_button($button->getLabel(), $action_counter);
             $actions[] = $button->getAction();
             $action_counter++;
         }
     } else {
         parent::add_button($caption, $action_counter);
         $actions[] = $action;
     }
     $this->vbox->pack_start($form);
     $form->show();
     $this->show_all();
     parent::connect('key_press_event', array($this, 'onClose'));
     $result = parent::run();
     foreach ($actions as $actionIndex => $buttonAction) {
         if ($result == $actionIndex) {
             if ($buttonAction) {
                 $parameters = $buttonAction->getParameters();
                 $data = $form->getData();
                 foreach ($data as $key => $value) {
                     $parameters[$key] = $value;
                 }
                 parent::destroy();
                 call_user_func_array($buttonAction->getAction(), array($parameters));
                 return;
             }
         }
     }
     parent::destroy();
 }
Exemplo n.º 21
0
 /**
  * Validate a given value
  * @param $label Identifies the value to be validated in case of exception
  * @param $value Value to be validated
  * @param $parameters aditional parameters for validation
  */
 public function validate($label, $value, $parameters = NULL)
 {
     // cpfs inválidos
     $nulos = array("12345678909", "11111111111", "22222222222", "33333333333", "44444444444", "55555555555", "66666666666", "77777777777", "88888888888", "99999999999", "00000000000");
     // Retira todos os caracteres que nao sejam 0-9
     $cpf = preg_replace("/[^0-9]/", "", $value);
     if (strlen($cpf) != 11) {
         throw new Exception(AdiantiCoreTranslator::translate('The field ^1 has not a valid CPF', $label));
     }
     // Retorna falso se houver letras no cpf
     if (!preg_match("/[0-9]/", $cpf)) {
         throw new Exception(AdiantiCoreTranslator::translate('The field ^1 has not a valid CPF', $label));
     }
     // Retorna falso se o cpf for nulo
     if (in_array($cpf, $nulos)) {
         throw new Exception(AdiantiCoreTranslator::translate('The field ^1 has not a valid CPF', $label));
     }
     // Calcula o penúltimo dígito verificador
     $acum = 0;
     for ($i = 0; $i < 9; $i++) {
         $acum += $cpf[$i] * (10 - $i);
     }
     $x = $acum % 11;
     $acum = $x > 1 ? 11 - $x : 0;
     // Retorna falso se o digito calculado eh diferente do passado na string
     if ($acum != $cpf[9]) {
         throw new Exception(AdiantiCoreTranslator::translate('The field ^1 has not a valid CPF', $label));
     }
     // Calcula o último dígito verificador
     $acum = 0;
     for ($i = 0; $i < 10; $i++) {
         $acum += $cpf[$i] * (11 - $i);
     }
     $x = $acum % 11;
     $acum = $x > 1 ? 11 - $x : 0;
     // Retorna falso se o digito calculado eh diferente do passado na string
     if ($acum != $cpf[10]) {
         throw new Exception(AdiantiCoreTranslator::translate('The field ^1 has not a valid CPF', $label));
     }
 }
Exemplo n.º 22
0
 /**
  * Class Constructor
  * @param  $name     widget's name
  * @param  $database database name
  * @param  $model    model class name
  * @param  $key      table field to be used as key in the combo
  * @param  $value    table field to be listed in the combo
  * @param  $ordercolumn column to order the fields (optional)
  * @param  $criteria criteria (TCriteria object) to filter the model (optional)
  */
 public function __construct($name, $database, $model, $key, $value, $ordercolumn = NULL, TCriteria $criteria = NULL)
 {
     // executes the parent class constructor
     parent::__construct($name);
     if (empty($database)) {
         throw new Exception(AdiantiCoreTranslator::translate('The parameter (^1) of ^2 is required', 'database', __CLASS__));
     }
     if (empty($model)) {
         throw new Exception(AdiantiCoreTranslator::translate('The parameter (^1) of ^2 is required', 'model', __CLASS__));
     }
     if (empty($key)) {
         throw new Exception(AdiantiCoreTranslator::translate('The parameter (^1) of ^2 is required', 'key', __CLASS__));
     }
     if (empty($value)) {
         throw new Exception(AdiantiCoreTranslator::translate('The parameter (^1) of ^2 is required', 'value', __CLASS__));
     }
     // carrega objetos do banco de dados
     TTransaction::open($database);
     // instancia um repositório de Estado
     $repository = new TRepository($model);
     if (is_null($criteria)) {
         $criteria = new TCriteria();
     }
     $criteria->setProperty('order', isset($ordercolumn) ? $ordercolumn : $key);
     // carrega todos objetos
     $collection = $repository->load($criteria, FALSE);
     // adiciona objetos na combo
     if ($collection) {
         $items = array();
         foreach ($collection as $object) {
             $items[$object->{$key}] = $object->{$value};
         }
         parent::addItems($items);
     }
     TTransaction::close();
 }
 /**
  * Validate a given value
  * @param $label Identifies the value to be validated in case of exception
  * @param $value Value to be validated
  * @param $parameters aditional parameters for validation
  */
 public function validate($label, $value, $parameters = NULL)
 {
     if (is_scalar($value) and trim($value) == '' or is_array($value) and count($value) == 1 and empty($value[0]) or is_array($value) and empty($value)) {
         throw new Exception(AdiantiCoreTranslator::translate('The field ^1 is required', $label));
     }
 }
Exemplo n.º 24
0
 /**
  * Execute the exit action
  */
 public function onExecuteExitAction()
 {
     if (!TForm::getFormByName($this->formName) instanceof TForm) {
         throw new Exception(AdiantiCoreTranslator::translate('You must pass the ^1 (^2) as a parameter to ^3', __CLASS__, $this->wname, 'TForm::setFields()'));
     }
     if (isset($this->changeAction) and $this->changeAction instanceof TAction) {
         $callback = $this->changeAction->getAction();
         $param = (array) TForm::retrieveData($this->formName);
         call_user_func($callback, $param);
     }
 }
Exemplo n.º 25
0
 /**
  * Show the widget at the screen
  */
 public function show()
 {
     if ($this->action) {
         if (empty($this->formName)) {
             throw new Exception(AdiantiCoreTranslator::translate('You must pass the ^1 (^2) as a parameter to ^3', __CLASS__, $this->label, 'TForm::setFields()'));
         }
         // get the action as URL
         $url = $this->action->serialize(FALSE);
         if ($this->action->isStatic()) {
             $url .= '&static=1';
         }
         $wait_message = AdiantiCoreTranslator::translate('Loading');
         // define the button's action (ajax post)
         $action = "Adianti.waitMessage = '{$wait_message}';";
         $action .= "{$this->functions}";
         $action .= "__adianti_post_data('{$this->formName}', '{$url}');";
         $action .= "return false;";
         $button = new TElement('button');
         $button->{'class'} = 'btn btn-sm btn-default';
         $button->onclick = $action;
         $button->id = 'tbutton_' . $this->name;
         $button->name = $this->name;
         $action = '';
     } else {
         $action = $this->functions;
         // creates the button using a div
         $button = new TElement('div');
         $button->id = 'tbutton_' . $this->name;
         $button->name = $this->name;
         $button->{'class'} = 'btn btn-default btn-sm';
         $button->onclick = $action;
     }
     if ($this->properties) {
         foreach ($this->properties as $property => $value) {
             $button->{$property} = $value;
         }
     }
     $span = new TElement('span');
     if ($this->image) {
         $image = new TElement('span');
         if (substr($this->image, 0, 3) == 'bs:') {
             $image = new TElement('i');
             $image->{'class'} = 'glyphicon glyphicon-' . substr($this->image, 3);
         } else {
             if (substr($this->image, 0, 3) == 'fa:') {
                 $image = new TElement('i');
                 $image->{'class'} = 'fa fa-' . substr($this->image, 3);
             } else {
                 if (file_exists('app/images/' . $this->image)) {
                     $image = new TImage('app/images/' . $this->image);
                 } else {
                     if (file_exists('lib/adianti/images/' . $this->image)) {
                         $image = new TImage('lib/adianti/images/' . $this->image);
                     }
                 }
             }
         }
         $image->{'style'} = 'padding-right:4px';
         $span->add($image);
     }
     if ($this->label) {
         $span->add($this->label);
     }
     $button->add($span);
     $button->show();
 }
Exemplo n.º 26
0
 /**
  * Shows the widget at the screen
  */
 public function show()
 {
     // define the tag properties
     $this->tag->name = $this->name;
     // TAG name
     $this->tag->value = $this->value;
     // TAG value
     $this->tag->type = 'text';
     // input type
     //$this->setProperty('style', "width:{$this->size}px", FALSE); //aggregate style info
     if (is_string($this->size)) {
         $this->setProperty('style', "width:{$this->size}", FALSE);
     } else {
         $this->setProperty('style', "width:{$this->size}px", FALSE);
     }
     //aggregate style info
     if ($this->id) {
         $this->tag->{'id'} = $this->id;
     }
     // verify if the widget is non-editable
     if (parent::getEditable()) {
         if (isset($this->exitAction)) {
             if (!TForm::getFormByName($this->formName) instanceof TForm) {
                 throw new Exception(AdiantiCoreTranslator::translate('You must pass the ^1 (^2) as a parameter to ^3', __CLASS__, $this->name, 'TForm::setFields()'));
             }
             $string_action = $this->exitAction->serialize(FALSE);
             $this->setProperty('exitaction', "serialform=(\$('#{$this->formName}').serialize());\n                                                 __adianti_ajax_lookup('{$string_action}&'+serialform, document.{$this->formName}.{$this->name})", FALSE);
             $this->setProperty('onBlur', $this->getProperty('exitaction'), FALSE);
         }
         if ($this->mask) {
             $this->tag->onKeyPress = "return tentry_mask(this,event,'{$this->mask}')";
         }
     } else {
         $this->tag->readonly = "1";
         $this->tag->{'class'} = 'tfield_disabled';
         // CSS
         $this->tag->onmouseover = "style.cursor='default'";
     }
     // shows the tag
     $this->tag->show();
     if (isset($this->completion)) {
         $options = json_encode($this->completion);
         TScript::create(" tentry_autocomplete( '{$this->name}', {$options}); ");
     }
     if ($this->numericMask) {
         TScript::create("tentry_numeric_mask( '{$this->name}', {$this->decimals}, '{$this->decimalsSeparator}', '{$this->thousandSeparator}'); ");
     }
 }
Exemplo n.º 27
0
 /**
  * Show the widget at the screen
  */
 public function show()
 {
     $wrapper = new TElement('div');
     $wrapper->{'mtf_name'} = $this->getName();
     // include the needed libraries and styles
     if ($this->fields) {
         $table = new TTable();
         $mandatories = array();
         // mandatory
         $fields = array();
         $i = 0;
         if ($this->orientation == 'horizontal') {
             $row_label = $table->addRow();
             $row_field = $table->addRow();
         }
         foreach ($this->fields as $name => $obj) {
             if ($this->orientation == 'vertical') {
                 $row = $table->addRow();
                 $row_label = $row;
                 $row_field = $row;
             }
             $label = new TLabel($obj->text);
             if ($obj->mandatory) {
                 $label->setFontColor('red');
             }
             $row_label->addCell($label);
             $row_field->addCell($obj->field);
             $mandatories[] = $obj->mandatory;
             $fields[] = $name;
             $post_fields[$name] = 1;
             $sizes[$name] = $obj->size;
             $obj->field->setName($this->name . '_' . $name);
             if (in_array(get_class($obj->field), array('TComboCombined', 'Adianti\\Widget\\Form\\TComboCombined'))) {
                 $aux_name = $obj->field->getTextName();
                 $aux_full_name = $this->name . '_' . $aux_name;
                 $mandatories[] = 0;
                 $obj->field->setTextName($aux_full_name);
                 $fields[] = $aux_name;
                 $post_fields[$aux_name] = 1;
                 // invert sizes
                 $sizes[$aux_name] = $obj->size;
                 $sizes[$name] = 20;
                 $i++;
             }
             $i++;
         }
         $wrapper->add($table);
     }
     // check whether the widget is non-editable
     if (parent::getEditable()) {
         // create three buttons to control the MultiField
         $add = new TButton("{$this->name}btnStore");
         $add->setLabel(AdiantiCoreTranslator::translate('Register'));
         $add->setImage('fa:angle-double-down');
         $add->addFunction("multifields['{$this->name}'].addRowFromFormFields()");
         $del = new TButton("{$this->name}btnDelete");
         $del->setLabel(AdiantiCoreTranslator::translate('Delete'));
         $del->setImage('fa:trash');
         $can = new TButton("{$this->name}btnCancel");
         $can->setLabel(AdiantiCoreTranslator::translate('Cancel'));
         $can->setImage('fa:times-circle');
         $hbox_buttons = new THBox();
         $hbox_buttons->{'style'} = 'margin-top:3px;margin-bottom:3px';
         $hbox_buttons->add($add);
         $hbox_buttons->add($del);
         $hbox_buttons->add($can);
         $wrapper->add($hbox_buttons);
     }
     // create the MultiField Panel
     $panel = new TElement('div');
     $panel->{'class'} = "multifieldDiv";
     $input = new THidden($this->name);
     $panel->add($input);
     // create the MultiField DataGrid Header
     $table = new TTable();
     $table->{'class'} = 'multifield';
     $table->{'id'} = "{$this->name}mfTable";
     $head = new TElement('thead');
     $table->add($head);
     $row = new TTableRow();
     $head->add($row);
     // fill the MultiField DataGrid
     if ($this->fields) {
         foreach ($this->fields as $obj) {
             $c = $obj->text;
             if (in_array(get_class($obj->field), array('TComboCombined', 'Adianti\\Widget\\Form\\TComboCombined'))) {
                 $cell = $row->addCell('ID');
                 $cell->{'width'} = '20px';
                 $cell->{'class'} = 'multifield_header';
             }
             $cell = $row->addCell($c);
             $cell->{'width'} = $obj->size . 'px';
             $cell->{'class'} = 'multifield_header';
         }
     }
     $body_height = $this->height - 34;
     $body = new TElement('tbody');
     $body->{'style'} = "height: {$body_height}px";
     $body->{'class'} = 'tmultifield_scrolling';
     $table->add($body);
     if ($this->objects) {
         foreach ($this->objects as $obj) {
             if (isset($obj->id)) {
                 $row = new TTableRow();
                 $row->dbId = $obj->id;
                 $body->add($row);
             } else {
                 $row = new TTableRow();
                 $body->add($row);
             }
             if ($fields) {
                 foreach ($fields as $name) {
                     $cellValue = is_null($obj->{$name}) ? '' : $obj->{$name};
                     $original = $cellValue;
                     if (is_array(json_decode($cellValue))) {
                         $content = json_decode($cellValue);
                         $rows = array();
                         foreach ($content as $_row) {
                             $rows[] = implode(':', array_values(get_object_vars($_row)));
                         }
                         $cellValue = implode(',', $rows);
                         $cell = $row->addCell($cellValue);
                         $cell->{'data'} = htmlspecialchars($original);
                     } else {
                         $cell = $row->addCell($cellValue);
                         $cell->{'data'} = $cellValue;
                     }
                     if (isset($sizes[$name])) {
                         $cell->style = 'width:' . $sizes[$name] . 'px;';
                     }
                 }
             }
         }
     }
     $panel->add($table);
     $wrapper->add($panel);
     $wrapper->show();
     $fields_json = json_encode($fields);
     $mandatories_json = json_encode($mandatories);
     TScript::create(" tmultifield_start( '{$this->name}', {$fields_json}, {$mandatories_json}, {$this->width},{$this->height} ) ");
 }
Exemplo n.º 28
0
 /**
  * Shows the widget at the screen
  */
 public function show()
 {
     // define the tag properties
     $this->tag->name = $this->name;
     // TAG name
     $this->tag->value = $this->value;
     // TAG value
     $this->tag->type = 'text';
     // input type
     $this->tag->style = "width:{$this->size}px";
     // size
     if ($this->id) {
         $this->tag->{'id'} = $this->id;
     }
     // verify if the widget is non-editable
     if (parent::getEditable()) {
         $exit_action = 'function() {}';
         if (isset($this->exitAction)) {
             if (!TForm::getFormByName($this->formName) instanceof TForm) {
                 throw new Exception(AdiantiCoreTranslator::translate('You must pass the ^1 (^2) as a parameter to ^3', __CLASS__, $this->name, 'TForm::setFields()'));
             }
             $string_action = $this->exitAction->serialize(FALSE);
             $exit_action = "function() { __adianti_post_lookup('{$this->formName}', '{$string_action}', document.{$this->formName}.{$this->name}) }";
         }
         TScript::create(" tspinner_start( '#{$this->id}', '{$this->value}', '{$this->min}', '{$this->max}', '{$this->step}', {$exit_action}); ");
     } else {
         $this->tag->readonly = "1";
         $this->tag->{'class'} = 'tfield_disabled';
         // CSS
         $this->tag->style = "width:{$this->size}px;" . "-moz-user-select:none;";
         $this->tag->onmouseover = "style.cursor='default'";
     }
     // shows the tag
     $this->tag->show();
 }
Exemplo n.º 29
0
 /**
  * Returns the form data as an object
  * @param $class A string containing the class for the returning object
  */
 public function getData($class = 'StdClass')
 {
     if (!class_exists($class)) {
         throw new Exception(AdiantiCoreTranslator::translate('Class ^1 not found in ^2', $class, __METHOD__));
     }
     $object = new $class();
     foreach ($this->fields as $key => $fieldObject) {
         if (!$fieldObject instanceof TButton) {
             $object->{$key} = $fieldObject->getPostData();
         }
     }
     return $object;
 }
Exemplo n.º 30
0
 /**
  * Return the amount of objects that satisfy a given criteria
  * @param $criteria  An TCriteria object, specifiyng the filters
  * @return           An Integer containing the amount of objects that satisfy the criteria
  */
 public function count(TCriteria $criteria = NULL)
 {
     if (!$criteria) {
         $criteria = isset($this->criteria) ? $this->criteria : new TCriteria();
     }
     // creates a SELECT statement
     $sql = new TSqlSelect();
     $sql->addColumn('count(*)');
     $sql->setEntity($this->getEntity());
     // assign the criteria to the SELECT statement
     $sql->setCriteria($criteria);
     // get the connection of the active transaction
     if ($conn = TTransaction::get()) {
         // register the operation in the LOG file
         TTransaction::log($sql->getInstruction());
         $dbinfo = TTransaction::getDatabaseInfo();
         // get dbinfo
         if (isset($dbinfo['prep']) and $dbinfo['prep'] == '1') {
             $result = $conn->prepare($sql->getInstruction(TRUE), array(PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY));
             $result->execute($criteria->getPreparedVars());
         } else {
             // executes the SELECT statement
             $result = $conn->query($sql->getInstruction());
         }
         if ($result) {
             $row = $result->fetch();
         }
         // returns the result
         return $row[0];
     } else {
         // if there's no active transaction opened
         throw new Exception(AdiantiCoreTranslator::translate('No active transactions') . ': ' . __METHOD__ . ' ' . $this->getEntity());
     }
 }