/** * Class Constructor * @param $name Name of the widget */ public function __construct($name) { parent::__construct($name); $this->widget = new GtkFileChooserButton(TAdiantiCoreTranslator::translate('Open'), GTK::FILE_CHOOSER_ACTION_OPEN); parent::add($this->widget); $this->setSize(200); }
/** * method onSave() * Executed whenever the user clicks at the save button */ function onSave() { try { // open a transaction with database 'sample' TTransaction::open('sample'); // get the form data into an active record Usuario $object = $this->form->getData('Usuario'); $this->form->validate(); // form validation $object->senha = md5($object->senha); $object->store(); // stores the object $this->form->setData($object); // keep form data TTransaction::close(); // close the transaction // shows the success message new TMessage('info', TAdiantiCoreTranslator::translate('Record saved')); } catch (Exception $e) { // shows the exception error message new TMessage('error', '<b>Error</b> ' . $e->getMessage()); $this->form->setData($this->form->getData()); // keep form data // undo all pending operations TTransaction::rollback(); } }
/** * 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(TAdiantiCoreTranslator::translate('Class ^1 not found in ^2', $controller, $xml_file)); } } else { throw new Exception(TAdiantiCoreTranslator::translate('File not found') . ': ' . $xml_file); } }
/** * method onSave() * Executed whenever the user clicks at the save button */ function onSave() { try { TTransaction::open('app'); // open a transaction // get the form data into an active record SystemUser $object = $this->form->getData('StdClass'); $this->form->validate(); // form validation $senhaatual = $object->current; $senhanova = $object->password; $confirmacao = $object->confirmation; $usuario = new SystemUser(TSession::getValue("userid")); if ($usuario->password == md5($senhaatual)) { if ($senhanova == $confirmacao) { $usuario->password = md5($senhanova); $usuario->store(); new TMessage('info', TAdiantiCoreTranslator::translate('Record saved')); } else { new TMessage('error', "A nova senha deve ser igual a sua confirmação."); } } else { new TMessage('error', "A senha atual não confere."); } TTransaction::close(); // close the transaction // shows the success message } catch (Exception $e) { // in case of exception new TMessage('error', '<b>Error</b> ' . $e->getMessage()); // shows the exception error message TTransaction::rollback(); // undo all pending operations } }
public function onSave($param) { try { $this->form->validate(); $object = $this->form->getData(); TTransaction::open('permission'); $user = SystemUser::newFromLogin(TSession::getValue('login')); $user->name = $object->name; $user->email = $object->email; if ($object->password1) { if ($object->password1 != $object->password2) { throw new Exception(_t('The passwords do not match')); } $user->password = md5($object->password1); } else { unset($user->password); } $user->store(); $this->form->setData($object); new TMessage('info', TAdiantiCoreTranslator::translate('Record saved')); TTransaction::close(); } catch (Exception $e) { new TMessage('error', $e->getMessage()); } }
/** * 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(TAdiantiCoreTranslator::translate('The field ^1 can not be greater than ^2 characters', $label, $length)); } }
/** * Validate the login */ function onLogin() { try { TTransaction::open('library'); $data = $this->form->getData('StdClass'); // validate form data $this->form->validate(); $language = $data->language ? $data->language : 'en'; TAdiantiCoreTranslator::setLanguage($language); TApplicationTranslator::setLanguage($language); $auth = User::autenticate($data->{'user'}, $data->{'password'}); if ($auth) { TSession::setValue('logged', TRUE); TSession::setValue('login', $data->{'user'}); TSession::setValue('language', $data->language); // reload page TApplication::executeMethod('SetupPage', 'onSetup'); } TTransaction::close(); // finaliza a transação } catch (Exception $e) { TSession::setValue('logged', FALSE); // exibe a mensagem gerada pela exceção new TMessage('error', '<b>Erro</b> ' . $e->getMessage()); // desfaz todas alterações no banco de dados TTransaction::rollback(); } }
/** * Constructor Method */ function __construct() { parent::__construct(); parent::set_size_request(840, 640); parent::set_position(GTK::WIN_POS_CENTER); parent::connect_simple('delete-event', array($this, 'onClose')); parent::connect_simple('destroy', array('Gtk', 'main_quit')); parent::set_title(self::APP_TITLE); parent::set_icon(GdkPixbuf::new_from_file('favicon.png')); $gtk = GtkSettings::get_default(); $gtk->set_long_property("gtk-button-images", TRUE, 0); $gtk->set_long_property("gtk-menu-images", TRUE, 0); self::$inst = $this; $ini = parse_ini_file('application.ini'); $lang = $ini['language']; TAdiantiCoreTranslator::setLanguage($lang); TApplicationTranslator::setLanguage($lang); date_default_timezone_set($ini['timezone']); $this->content = new GtkFixed(); $vbox = new GtkVBox(); parent::add($vbox); $vbox->pack_start(GtkImage::new_from_file('app/images/pageheader-gtk.png'), false, false); $MenuBar = TMenuBar::newFromXML('menu.xml'); $vbox->pack_start($MenuBar, false, false); $vbox->pack_start($this->content, true, true); parent::show_all(); }
/** * 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 $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(TAdiantiCoreTranslator::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', "serialform=(\$('#{$this->formName}').serialize());\n ajaxLookup('{$string_action}&'+serialform, this)"); } } else { // make the field read-only $this->tag->readonly = "1"; $this->tag->{'class'} = 'tfield_disabled'; // CSS } // show the tag $this->tag->show(); }
/** * Class Constructor * @param $name Name of the widget */ public function __construct($name) { $this->wname = $name; $this->validations = array(); parent::__construct(TAdiantiCoreTranslator::translate('Open'), GTK::FILE_CHOOSER_ACTION_OPEN); parent::set_size_request(200, -1); }
/** * 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 (max value) */ public function validate($label, $value, $parameters = NULL) { $maxvalue = $parameters[0]; if ($value > $maxvalue) { throw new Exception(TAdiantiCoreTranslator::translate('The field ^1 can not be greater than ^2', $label, $maxvalue)); } }
/** * Show the widget */ public function show() { $this->tag->name = $this->name; // tag name $this->setProperty('style', "width:{$this->size}px", FALSE); //aggregate style info if ($this->height) { $this->setProperty('style', "height:{$this->height}px", FALSE); //aggregate style info } // check if the field is not editable if (!parent::getEditable()) { // make the widget read-only $this->tag->readonly = "1"; $this->tag->{'class'} = 'tfield_disabled'; // CSS } if (isset($this->exitAction)) { if (!TForm::getFormByName($this->formName) instanceof TForm) { throw new Exception(TAdiantiCoreTranslator::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', "serialform=(\$('#{$this->formName}').serialize());\n ajaxLookup('{$string_action}&'+serialform, this)"); } // add the content to the textarea $this->tag->add(htmlspecialchars($this->value)); // show the tag $this->tag->show(); }
/** * 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(TAdiantiCoreTranslator::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(TAdiantiCoreTranslator::translate('The field ^1 has not a valid CNPJ', $label)); } }
/** * method onSave() * Executed whenever the user clicks at the save button */ 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', TAdiantiCoreTranslator::translate('Record saved')); 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', '<b>Error</b> ' . $e->getMessage()); // undo all pending operations TTransaction::rollback(); } }
/** * Constructor method * * @param $path HTML resource path */ public function __construct($path) { if (!file_exists($path)) { throw new Exception(TAdiantiCoreTranslator::translate('File not found') . ': ' . $path); } $this->path = $path; $this->enabledSections = array(); }
/** * 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(TAdiantiCoreTranslator::translate('Method ^1 must receive a paremeter of type ^2', __METHOD__, 'Callback') . ' <br> ' . TAdiantiCoreTranslator::translate('Check if the action (^1) exists', $action_string)); } }
/** * Opens a database connection * * @param $database Name of the database (an INI file). * @return A PDO object if the $database exist, * otherwise, throws an exception * @exception Exception * if the $database is not found * @author Pablo Dall'Oglio */ public static function open($database) { // check if the database configuration file exists if (file_exists("app/config/{$database}.ini")) { // read the INI and retuns an array $db = parse_ini_file("app/config/{$database}.ini"); } else { // if the database doesn't exists, throws an exception throw new Exception(TAdiantiCoreTranslator::translate('File not found') . ': ' . "'{$database}.ini'"); } // read the database properties $user = isset($db['user']) ? $db['user'] : NULL; $pass = isset($db['pass']) ? $db['pass'] : NULL; $name = isset($db['name']) ? $db['name'] : NULL; $host = isset($db['host']) ? $db['host'] : NULL; $type = isset($db['type']) ? $db['type'] : NULL; $port = isset($db['port']) ? $db['port'] : NULL; // each database driver has a different instantiation process switch ($type) { case 'pgsql': $port = $port ? $port : '5432'; $conn = new PDO("pgsql:dbname={$name};user={$user}; password={$pass};host={$host};port={$port}"); break; case 'mysql': $port = $port ? $port : '3306'; $conn = new PDO("mysql:host={$host};port={$port};dbname={$name}", $user, $pass); break; case 'sqlite': $conn = new PDO("sqlite:{$name}"); $conn->query('PRAGMA foreign_keys = ON'); // referential integrity must be enabled break; case 'ibase': $name = isset($host) ? "{$host}:{$name}" : $name; $conn = new PDO("firebird:dbname={$name}", $user, $pass); break; case 'oracle': $port = $port ? $port : '1521'; $conn = new PDO("oci:dbname={$host}:{$port}/{$name}", $user, $pass); break; case 'mssql': if (OS == 'WIN') { $conn = new PDO("sqlsrv:Server={$host};Database={$name}", $user, $pass); } else { $conn = new PDO("dblib:host={$host};dbname={$name}", $user, $pass); } break; case 'dblib': $conn = new PDO("dblib:host={$host},1433;dbname={$name}", $user, $pass); break; } // define wich way will be used to report errors (EXCEPTION) $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // return the PDO object return $conn; }
public function show() { if ($this->changeaction) { if (empty($this->formName)) { throw new Exception(TAdiantiCoreTranslator::translate('You must pass the ^1 (^2) as a parameter to ^3', __CLASS__, $this->label, 'TForm::setFields()')); } // get the action as URL $url = $this->changeaction->serialize(FALSE); $wait_message = TAdiantiCoreTranslator::translate('Loading'); // define the button's action (ajax post) $action = "\n \$.blockUI({ \n message: '<h1>{$wait_message}</h1>',\n css: { \n border: 'none', \n padding: '15px', \n backgroundColor: '#000', \n 'border-radius': '5px 5px 5px 5px',\n opacity: .5, \n color: '#fff' \n }\n });\n {$this->function};\n \$.post('engine.php?{$url}',\n \$('#{$this->formName}').serialize(),\n function(result)\n {\n __adianti_load_html(result);\n \$.unblockUI();\n });\n return false;"; } // define the tag properties $this->tag->name = $this->name; // tag name $this->tag->style = "width:{$this->size}px"; // size in pixels $this->tag->onChange = $action; // creates an empty <option> tag $option = new TElement('option'); $option->add(''); $option->value = ''; // tag value // add the option tag to the combo $this->tag->add($option); if ($this->items) { // iterate the combobox items foreach ($this->items as $chave => $item) { if (substr($chave, 0, 3) == '>>>') { $optgroup = new TElement('optgroup'); $optgroup->label = $item; // add the option to the combo $this->tag->add($optgroup); } else { // creates an <option> tag $option = new TElement('option'); $option->value = $chave; // define the index $option->add($item); // add the item label // verify if this option is selected if ($chave == $this->value and $this->value !== NULL) { // mark as selected $option->selected = 1; } if (isset($optgroup)) { $optgroup->add($option); } else { $this->tag->add($option); } } } } // shows the combobox $this->tag->show(); }
/** * Constructor Method * Creates the page, the search form and the listing */ public function __construct() { parent::__construct(); // 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'); // keeps the field's value $display_field->setValue(TSession::getValue('tstandardseek_display_value')); // add a row for the filter field $row = $table->addRow(); $row->addCell(new TLabel('Field:')); $row->addCell($display_field); // create the action button $find_button = new TButton('busca'); // define the button action $find_button->setAction(new TAction(array($this, 'onSearch')), TAdiantiCoreTranslator::translate('Search')); $find_button->setImage('ico_find.png'); // add a row for the button in the table $row = $table->addRow(); $row->addCell($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', 'Field', 'left', 220); // 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); }
/** * Class Constructor * @param $name Name of the widget */ public function __construct($name) { parent::__construct(); $this->wname = $name; $this->mask = 'yyyy-mm-dd'; $this->validations = array(); // creates the entry field $this->entry = new TEntry($name); $this->entry->setSize(200); //set_size_request(200, 24); $this->setMask($this->mask); parent::add($this->entry); // creates a button with a calendar image $button = new GtkButton(); $button->set_relief(GTK::RELIEF_NONE); $imagem = GtkImage::new_from_file('lib/adianti/images/tdate-gtk.png'); $button->set_image($imagem); // define the button's callback $button->connect_simple('clicked', array($this, 'onCalendar')); parent::add($button); // creates the calendar window $this->popWindow = new GtkWindow(Gtk::WINDOW_POPUP); // creates the calendar $this->calendar = new GtkCalendar(); // define the action when the user selects a date $this->calendar->connect_simple('day-selected-double-click', array($this, 'onSelectDate')); $this->month = new TCombo('tdate-month'); $this->month->addItems(array(TAdiantiCoreTranslator::translate('January'), TAdiantiCoreTranslator::translate('February'), TAdiantiCoreTranslator::translate('March'), TAdiantiCoreTranslator::translate('April'), TAdiantiCoreTranslator::translate('May'), TAdiantiCoreTranslator::translate('June'), TAdiantiCoreTranslator::translate('July'), TAdiantiCoreTranslator::translate('August'), TAdiantiCoreTranslator::translate('September'), TAdiantiCoreTranslator::translate('October'), TAdiantiCoreTranslator::translate('November'), TAdiantiCoreTranslator::translate('December'))); $this->month->setCallback(array($this, 'onChangeMonth')); $this->month->setSize(70); for ($n = date('Y') - 10; $n <= date('Y') + 10; $n++) { $years[$n] = $n; } $this->year = new TCombo('tdate-year'); $this->year->addItems($years); $this->year->setCallback(array($this, 'onChangeMonth')); $this->year->setSize(70); $hbox = new GtkHBox(); $hbox->pack_start($this->month); $hbox->pack_start($this->year); $bt_today = new GtkButton(TAdiantiCoreTranslator::translate('Today')); $bt_close = new GtkButton(TAdiantiCoreTranslator::translate('Close')); $bt_today->connect_simple('clicked', array($this, 'selectToday')); $inst = $this->popWindow; $bt_close->connect_simple('clicked', array($inst, 'hide')); $hbox2 = new GtkHBox(); $hbox2->pack_start($bt_today); $hbox2->pack_start($bt_close); $vbox = new GtkVBox(); $vbox->pack_start($hbox, FALSE, FALSE); $vbox->pack_start($this->calendar); $vbox->pack_start($hbox2, FALSE, FALSE); // shows the window $this->popWindow->add($vbox); }
/** * 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(TAdiantiCoreTranslator::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; } }
/** * 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(TAdiantiCoreTranslator::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; } }
/** * 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 { exec("{$viewer} {$file} >NULL &"); } } else { throw new Exception(TAdiantiCoreTranslator::translate('File not found') . ': ' . $viewer); } }
/** * 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(TAdiantiCoreTranslator::translate('File not found') . ': ' . $viewer); } }
public static function run($debug = FALSE) { new TSession(); $lang = TSession::getValue('language') ? TSession::getValue('language') : 'en'; TAdiantiCoreTranslator::setLanguage($lang); TApplicationTranslator::setLanguage($lang); if ($_REQUEST) { $class = isset($_REQUEST['class']) ? $_REQUEST['class'] : ''; if (!TSession::getValue('logged') and $class !== 'LoginForm') { echo TPage::getLoadedCSS(); echo TPage::getLoadedJS(); new TMessage('error', 'Not logged'); return; } parent::run($debug); } }
/** * Class Constructor * @param $action Callback to be executed */ public function __construct($action) { if (is_callable($action)) { $this->action = $action; } else { if (is_string($action)) { $action_string = $action; } else { if (is_array($action)) { if (is_object($action[0])) { $action_string = get_class($action[0]) . '::' . $action[1]; } else { $action_string = $action[0] . '::' . $action[1]; } } } throw new Exception(TAdiantiCoreTranslator::translate('Method ^1 must receive a paremeter of type ^2', __METHOD__, 'Callback') . ' <br> ' . TAdiantiCoreTranslator::translate('Check if the action (^1) exists', $action_string)); } }
/** * Adiciona uma nova célula na linha atual da tabela * @param $content conteúdo da célula * @param $align alinhamento da célula * @param $stylename nome do estilo a ser utilizado * @param $colspan quantidade de células a serem mescladas */ public function addCell($content, $align, $stylename, $colspan = 1) { if (is_null($stylename) or !isset($this->styles[$stylename])) { throw new Exception(TAdiantiCoreTranslator::translate('Style ^1 not found in ^2', $stylename, __METHOD__)); } $width = 0; // calcula a largura da célula (incluindo as mescladas) for ($n = $this->colcounter; $n < $this->colcounter + $colspan; $n++) { $width += $this->widths[$n]; } // adiciona a célula na linha corrente $cell = $this->currentRow->addCell($content); $cell->align = $align; $cell->width = $width - 2; $cell->colspan = $colspan; // atribui o estilo if ($stylename) { $cell->{"class"} = $stylename; } $this->colcounter++; }
/** * Add a new cell inside the current row * @param $content cell content * @param $align cell align * @param $stylename style to be used * @param $colspan colspan (merge) */ public function addCell($content, $align, $stylename, $colspan = 1) { if (is_null($stylename) or !isset($this->styles[$stylename])) { throw new Exception(TAdiantiCoreTranslator::translate('Style ^1 not found in ^2', $stylename, __METHOD__)); } // obtém a fonte e a cor de preenchimento $font = $this->styles[$stylename]['font']; $fillcolor = $this->styles[$stylename]['bgcolor']; if (utf8_encode(utf8_decode($content)) !== $content) { $content = utf8_encode($content); } // escreve o conteúdo na célula utilizando a fonte e alinhamento $this->table->writeToCell($this->rowcounter, $this->colcounter, $content, $font, new PHPRtfLite_ParFormat($align)); // define a cor de fundo para a célula $this->table->setBackgroundForCellRange($fillcolor, $this->rowcounter, $this->colcounter, $this->rowcounter, $this->colcounter); if ($colspan > 1) { // mescla as células caso necessário $this->table->mergeCellRange($this->rowcounter, $this->colcounter, $this->rowcounter, $this->colcounter + $colspan - 1); } $this->colcounter++; }
/** * Show the widget at the screen */ public function show() { if ($this->action) { if (empty($this->formName)) { throw new Exception(TAdiantiCoreTranslator::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); $wait_message = TAdiantiCoreTranslator::translate('Loading'); // define the button's action (ajax post) $action = "\n \$.blockUI({ \n message: '<h1>{$wait_message}</h1>',\n css: { \n border: 'none', \n padding: '15px', \n backgroundColor: '#000', \n 'border-radius': '5px 5px 5px 5px',\n opacity: .5, \n color: '#fff' \n }\n });\n {$this->function};\n \$.post('engine.php?{$url}',\n \$('#{$this->formName}').serialize(),\n function(result)\n {\n __adianti_load_html(result);\n \$.unblockUI();\n });\n return false;"; $button = new TElement('button'); $button->{'class'} = 'btn btn-small'; $button->onclick = $action; $button->id = $this->name; $button->name = $this->name; $action = ''; } else { $action = $this->function; // creates the button using a div $button = new TElement('div'); $button->id = $this->name; $button->name = $this->name; $button->{'class'} = 'btn btn-small'; $button->onclick = $action; } $span = new TElement('span'); if ($this->image) { if (file_exists('lib/adianti/images/' . $this->image)) { $image = new TImage('lib/adianti/images/' . $this->image); } else { $image = new TImage('app/images/' . $this->image); } $image->{'style'} = 'padding-right:4px'; $span->add($image); } $span->add($this->label); $button->add($span); $button->show(); }
/** * 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); // Retorna falso se houver letras no cpf if (!preg_match("/[0-9]/", $cpf)) { throw new Exception(TAdiantiCoreTranslator::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(TAdiantiCoreTranslator::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(TAdiantiCoreTranslator::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(TAdiantiCoreTranslator::translate('The field ^1 has not a valid CPF', $label)); } }