/** * Verifica se a senha fornecida por um usuário é válida * utilizando autenticação challenge-response. * * @param int $userId * @param string $challenge * @param string $response * @return boolean */ public function authenticate($userId, $challenge, $response) { Manager::logMessage("[LOGIN] Authenticating {$userId} LdapMD5"); $login = NULL; try { if ($this->validate($userId, $challenge, $response)) { $user = Manager::getModelMAD('user'); $user->getByLogin($userId); $profile = $user->getProfileAtual(); $user->getByProfile($profile); $login = new MLogin($user); if (Manager::getOptions("dbsession")) { $session = Manager::getModelMAD('session'); $session->lastAccess($login); $session->registerIn($login); } $this->setLogin($login); $this->setLoginLogUserId($user->getId()); $this->setLoginLog($login->getLogin()); Manager::logMessage("[LOGIN] Authenticated {$userId} LdapMD5"); return true; } } catch (Exception $e) { Manager::logMessage("[LOGIN] {$userId} NOT Authenticated LdapMD5 - " . $e->getMessage()); } Manager::logMessage("[LOGIN] {$userId} NOT Authenticated LdapMD5"); return false; }
public function apply($request, $response) { $response->status = MStatusCode::INTERNAL_ERROR; $format = $request->format; $response->setContentType($response->getMimeType("xx." + format)); $this->tracestack = str_replace('#', '<br>#', $this->exception->trace); $errorHtml = "Not found"; try { $template = new MTemplate(); $template->context('result', $this->exception); $language = Manager::getOptions('language'); $errorHtml = $template->fetch("errors/{$language}/" . $response->status . "." . ($format == null ? "html" : $format)); if ($request->isAjax() && $format == "html") { if ($this->ajax->isEmpty()) { $this->ajax->setId('error'); $this->ajax->setType('page'); $this->ajax->setData($errorHtml); } $response->out = $this->ajax->returnData(); } else { $response->out = $errorHtml; } } catch (Exception $e) { throw new EMException($e); } }
public static function getInstance() { if (self::$instance == NULL) { self::$instance = new MKrono(); self::$instance->baseDate = '02/01/00'; // For day/month names self::$instance->localeConv = localeConv(); self::$instance->separator = Manager::getOptions('separatorDate'); self::$instance->formatDate = Manager::getOptions('formatDate'); self::$instance->formatTimestamp = Manager::getOptions('formatTimestamp'); self::$instance->timeZone = Manager::getOptions('timezone'); } return self::$instance; }
private function _getNextValue($sequence = 'admin') { $transaction = $this->db->beginTransaction(); $table = $this->db->getConfig('sequence.table'); $name = $this->db->getConfig('sequence.name'); $field = $this->db->getConfig('sequence.value'); $sql = new \Maestro\Database\MSQL($field, $table, "({$name} = '{$sequence}')"); $sql->setForUpdate(true); $result = $this->db->query($sql); $value = \Manager::getOptions('fetchStyle') == \FETCH_NUM ? $result[0][0] : $result[0][$field]; $nextValue = $value + 1; $this->db->execute($sql->update($nextValue), $nextValue); $transaction->commit(); return $value; }
public function apply($request, $response) { $response->status = MStatusCode::NOT_FOUND; $format = $request->format; if ($request->isAjax() && $format == "html") { $format = "json"; } $response->setContentType($response->getMimeType("xx." + format)); $errorHtml = "Not found"; try { $template = new MTemplate(); $template->context('result', $this); $language = Manager::getOptions('language'); $errorHtml = $template->fetch("errors/{$language}/404.html"); if ($request->isAjax()) { $this->ajax->setResponse('html', $errorHtml); $response->out = $this->ajax->returnData(); } else { $response->out = $errorHtml; } } catch (EMException $e) { } }
public function asCSV($showColumnName = false) { $this->getResult(); $result = $this->result; if ($showColumnName) { for ($i = 0; $i < $this->columnCount; $i++) { $columns[] = ucfirst($this->metadata['fieldname'][$i]); } array_unshift($result, $columns); } $id = uniqid(md5(uniqid(""))); // generate a unique id to avoid name conflicts $fileCSV = \Manager::getFilesPath($id . '.csv', true); $csvDump = new \MCSVDump(\Manager::getOptions('csv')); $csvDump->save($result, basename($fileCSV)); return $fileCSV; }
/** * Define template and template variables */ public function setTemplate() { $path = Manager::getThemePath(); $this->template = new MTemplate($path); $this->template->context('manager', Manager::getInstance()); $this->template->context('page', $this); $this->template->context('charset', Manager::getOptions('charset')); $this->template->context('layout', $this->layout); $this->template->context('template', $this->template); }
public function init() { $this->dumpping = Manager::getOptions('dump'); // if it is a AJAX call, initialize MAjax if (Manager::isAjaxCall()) { Manager::$ajax = new MAjax(); Manager::$ajax->initialize(Manager::getOptions('charset')); } $this->addApplicationConf(); $this->addApplicationActions(); $this->addApplicationMessages(); Manager::getPage(); $this->controllerAction = ''; $this->forward = ''; }
function fillCSV($array, $fileInput, $fileOutput, $fileType, $parameters, $classPath, $save) { $params = $this->prepareParameters($parameters); $params->put('REPORT_LOCALE', new Java("java.util.Locale", 'pt', 'BR')); $extension = substr($fileInput, strrpos($fileInput, '.')); try { $sJfm = new JavaClass("net.sf.jasperreports.engine.JasperFillManager"); if ($extension == ".jrxml") { $s1 = new JavaClass("net.sf.jasperreports.engine.xml.JRXmlLoader"); $jasperDesign = $s1->load($fileInput); $sJcm = new JavaClass("net.sf.jasperreports.engine.JasperCompileManager"); $report = $sJcm->compileReport($jasperDesign); } else { $report = $fileInput; } $csvDump = new MCSVDump(Manager::getOptions('csv'), MCSVDump::WINDOWS_EOL); $fileCSV = str_replace('.pdf', '.csv', $fileOutput); $csvDump->save($array, basename($fileCSV)); $sJds = new Java("net.sf.jasperreports.engine.data.JRCsvDataSource", $fileCSV, 'UTF8'); $sJds->setFieldDelimiter(Manager::getOptions('csv')); $print = $sJfm->fillReport($report, $params, $sJds); $sJem = new JavaClass("net.sf.jasperreports.engine.JasperExportManager"); $output = \Manager::getDownloadURL('report', basename($this->fileOutput), true); $sJem->exportReportToPdfFile($print, $fileOutput); } catch (Exception $e) { dump_java_exception($e); } return $output; }
public function __construct($request) { $this->isCore = false; if (is_string($request)) { $path = $request; $this->url = $path; } else { $this->request = $request; if ($this->request->querystring != '') { parse_str($this->request->querystring, $this->vars); } $path = $this->request->getPathInfo(); $this->url = $this->request->path; } mtrace('Context path: ' . $path); $pathParts = explode('/', $path); $app = array_shift($pathParts); if ($app != '') { if ($app == 'core') { $this->isCore = true; $app = array_shift($pathParts); } $this->app = $app; $part = array_shift($pathParts); // check for module $namespace = $this->getNamespace($this->app, $part); if ($part && Manager::existsNS($namespace)) { $this->module = $part; $part = array_shift($pathParts); } else { $this->module = ''; } // check for controller/component/service $ctlr = $part; $controller = $component = $service = ''; while ($part && ($controller == '' && $component == '' && $service == '')) { $namespace = $this->getNamespace($this->app, $this->module, '', 'controllers'); $ns = $namespace . $part . 'Controller.php'; if (Manager::existsNS($ns)) { $controller = $part; $part = array_shift($pathParts); } else { $namespace = $this->getNamespace($this->app, $this->module, '', 'services'); $ns = $namespace . $part . 'Service.php'; if (Manager::existsNS($ns)) { $service = $part; $part = array_shift($pathParts); } else { $namespace = $this->getNamespace($this->app, $this->module, '', 'components'); $ns = $namespace . $part . '.php'; if (Manager::existsNS($ns)) { $component = $part; $part = array_shift($pathParts); } else { $part = array_shift($pathParts); } } } } } else { $this->app = Manager::getOptions('startup'); $controller = 'main'; } if ($controller) { $this->controller = $controller; } elseif ($service) { $this->service = $service; } elseif ($component) { $this->component = $component; } else { throw new ENotFoundException(_M("App: [%s], Module: [%s], Controller: [%s] : Not found!", array($this->app, $this->module, $ctlr))); } $this->action = $part ?: ($component == '' ? 'main' : ''); $this->actionTokens[0] = $this->controller; $this->actionTokens[1] = $this->action; $this->currentToken = 1 + ($this->module ? 1 : 0); if ($n = count($pathParts)) { for ($i = 0; $i < $n; $i++) { $this->actionTokens[$i + 2] = $this->vars[$pathParts[$i]] = $pathParts[$i]; } } $this->id = $this->vars['item'] ?: $this->actionTokens[2]; if ($this->id !== '') { $_REQUEST['id'] = $this->id; } Manager::getInstance()->application = $this->app; mtrace('Context app: ' . $this->app); mtrace('Context module: ' . $this->module); mtrace('Context controller: ' . $this->controller); mtrace('Context service: ' . $this->service); mtrace('Context component: ' . $this->component); mtrace('Context action: ' . $this->action); mtrace('Context id: ' . $this->id); }
public function renderJSON($json = '') { if (!Manager::isAjaxCall()) { Manager::$ajax = new MAjax(); Manager::$ajax->initialize(Manager::getOptions('charset')); } $ajax = Manager::getAjax(); $ajax->setData($this->data); $this->setResult(new MRenderJSON($json)); }
public function __construct($datetime = NULL, $format = '') { parent::__construct($datetime, $format ?: Manager::getOptions('formatTimestamp')); }
public function __construct() { $this->host = $_SERVER['SERVER_NAME']; $this->path = $this->getPathInfo(); mtrace('MRequest path = ' . $this->path); $this->querystring = $this->getQueryString(); $this->method = $this->getRequestType(); $this->domain = $this->getServerName(); $this->remoteAddress = $this->getUserHostAddress(); $this->contentType = isset($_SERVER['CONTENT_TYPE']) ? $_SERVER['CONTENT_TYPE'] : ''; $this->port = $this->getPort(); $this->secure = $this->getIsSecureConnection(); $this->headers = $_SERVER; $this->cookies = isset($_COOKIES) ? $_COOKIES : ''; $dispatch = Manager::getOptions('dispatch'); /* $p = strpos($this->path,$dispatch); if ($p !== false) { $this->path = str_replace($dispatch, '', $this->path); } $this->baseUrl = Manager::getConf('url.base'); $p = ($this->path && $this->baseUrl) ? strpos($this->path,$this->baseUrl) : false; if (($this->baseUrl != '') && ($p !== false)) { $this->path = str_replace($this->baseUrl, '', $this->path); } * */ $this->baseUrl = $this->getBaseUrl(); $this->date = Manager::getSysTime(); $this->isNew = true; $this->user = ''; $this->password = ''; $this->isLoopback = $this->remoteAddress == '127.0.0.1'; $this->params = $_REQUEST; $this->url = $this->getUrl(); $this->dispatch = $this->getBase() . $dispatch; $this->resolveFormat(); $auth = isset($_SERVER['AUTH_TYPE']) ? $_SERVER['AUTH_TYPE'] : ''; if ($auth != '' && substr($auth, 0, 6) == "Basic ") { $this->user = $_SERVER['PHP_AUTH_USER']; $this->password = $_SERVER['PHP_AUTH_PW']; } //mtrace('MRequest path = ' . $this->path); //mtrace('MRequest base = ' . $this->getBase()); //mtrace('MRequest baseURL = ' . $this->getBaseURL()); //mtrace('MRequest url = ' . $this->url); }
public function getFullName($dayOfWeek = false) { $locale = \Manager::getOptions('locale'); $prefix = $dayOfWeek ? $this->getDayName() . ', ' : ''; if ($locale[0] == 'pt_BR') { return $prefix . $this->getDay('j') . ' de ' . $this->getMonthName() . ' de ' . $this->getYear(); } else { return $prefix . $this->getMonthName() . ' ' . $this->getDay('j') . ',' . $this->getYear(); } }
public static function getURL($action = 'main/main', $args = array()) { if (strtoupper(substr($action, 0, 4)) == 'HTTP') { return $action; } if (Manager::getOptions('compatibility')) { $action = str_replace(':', '/', $action); } $url = self::$instance->getContext()->buildURL($action, $args); return $url; }
public function reverseMySQL() { $script = new MReverseMySQL(); $baseDir = Manager::getOptions('basePath'); $script->setBaseDir($baseDir); $script->setFile($this->data->script); $script->setDatabaseName($this->data->database); $script->setAppName($this->data->app); $script->setModuleName($this->data->module); $script->generate(); if (count($script->errors)) { $this->renderPrompt('error', $script->errors); } else { $this->renderPrompt('information', 'Arquivos gerados com sucesso em ' . $baseDir); } }
public function __construct($separator = '', $eol = '') { $this->separator = $separator ?: Manager::getOptions('csv'); $this->eol = $eol ?: $this->_define_newline(); }
public function save() { if ($this->getPassMD5() == '') { $this->setPassMD5(md5(\Manager::getOptions('defaultPassword'))); } if ($this->getTheme() == '') { $this->setTheme('default'); } parent::save(); }
/** * Encodes an arbitrary variable into JSON format * * @param mixed $var any number, boolean, string, array, or object to be encoded. * If var is a string, it will be converted to UTF-8 format first before being encoded. * @return string JSON string representation of input var */ public static function encode($var) { switch (gettype($var)) { case 'boolean': return $var ? 'true' : 'false'; case 'NULL': return 'null'; case 'integer': return (int) $var; case 'double': case 'float': return str_replace(',', '.', (double) $var); // locale-independent representation // locale-independent representation case 'string': if (($enc = strtoupper(Manager::getOptions('charset'))) !== 'UTF-8') { $var = iconv($enc, 'UTF-8', $var); } if (substr($var, 0, 2) == '@@') { return substr($var, 2); } if (function_exists('json_encode')) { $cleanString = iconv($enc, "UTF-8//IGNORE", $var); return json_encode($cleanString); } // STRINGS ARE EXPECTED TO BE IN ASCII OR UTF-8 FORMAT $ascii = ''; $strlen_var = strlen($var); /* * Iterate over every character in the string, * escaping with a slash or encoding to UTF-8 where necessary */ for ($c = 0; $c < $strlen_var; ++$c) { $ord_var_c = ord($var[$c]); switch (true) { case $ord_var_c == 0x8: $ascii .= '\\b'; break; case $ord_var_c == 0x9: $ascii .= '\\t'; break; case $ord_var_c == 0xa: $ascii .= '\\n'; break; case $ord_var_c == 0xc: $ascii .= '\\f'; break; case $ord_var_c == 0xd: $ascii .= '\\r'; break; case $ord_var_c == 0x22: case $ord_var_c == 0x2f: case $ord_var_c == 0x5c: // double quote, slash, slosh $ascii .= '\\' . $var[$c]; break; case $ord_var_c >= 0x20 && $ord_var_c <= 0x7f: // characters U-00000000 - U-0000007F (same as ASCII) $ascii .= $var[$c]; break; case ($ord_var_c & 0xe0) == 0xc0: // characters U-00000080 - U-000007FF, mask 110XXXXX // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 $char = pack('C*', $ord_var_c, ord($var[$c + 1])); $c += 1; $utf16 = self::utf8ToUTF16BE($char); $ascii .= sprintf('\\u%04s', bin2hex($utf16)); break; case ($ord_var_c & 0xf0) == 0xe0: // characters U-00000800 - U-0000FFFF, mask 1110XXXX // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 $char = pack('C*', $ord_var_c, ord($var[$c + 1]), ord($var[$c + 2])); $c += 2; $utf16 = self::utf8ToUTF16BE($char); $ascii .= sprintf('\\u%04s', bin2hex($utf16)); break; case ($ord_var_c & 0xf8) == 0xf0: // characters U-00010000 - U-001FFFFF, mask 11110XXX // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 $char = pack('C*', $ord_var_c, ord($var[$c + 1]), ord($var[$c + 2]), ord($var[$c + 3])); $c += 3; $utf16 = self::utf8ToUTF16BE($char); $ascii .= sprintf('\\u%04s', bin2hex($utf16)); break; case ($ord_var_c & 0xfc) == 0xf8: // characters U-00200000 - U-03FFFFFF, mask 111110XX // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 $char = pack('C*', $ord_var_c, ord($var[$c + 1]), ord($var[$c + 2]), ord($var[$c + 3]), ord($var[$c + 4])); $c += 4; $utf16 = self::utf8ToUTF16BE($char); $ascii .= sprintf('\\u%04s', bin2hex($utf16)); break; case ($ord_var_c & 0xfe) == 0xfc: // characters U-04000000 - U-7FFFFFFF, mask 1111110X // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 $char = pack('C*', $ord_var_c, ord($var[$c + 1]), ord($var[$c + 2]), ord($var[$c + 3]), ord($var[$c + 4]), ord($var[$c + 5])); $c += 5; $utf16 = self::utf8ToUTF16BE($char); $ascii .= sprintf('\\u%04s', bin2hex($utf16)); break; } } return '"' . $ascii . '"'; case 'array': /* * As per JSON spec if any array key is not an integer * we must treat the the whole array as an object. We * also try to catch a sparsely populated associative * array with numeric keys here because some JS engines * will create an array with empty indexes up to * max_index which can cause memory issues and because * the keys, which may be relevant, will be remapped * otherwise. * * As per the ECMA and JSON specification an object may * have any string as a property. Unfortunately due to * a hole in the ECMA specification if the key is a * ECMA reserved word or starts with a digit the * parameter is only accessible using ECMAScript's * bracket notation. */ // treat as a JSON object if (is_array($var) && count($var) && array_keys($var) !== range(0, sizeof($var) - 1)) { return '{' . join(',', array_map(array('MJSON', 'nameValue'), array_keys($var), array_values($var))) . '}'; } // treat it like a regular array return '[' . join(',', array_map(array('MJSON', 'encode'), $var)) . ']'; case 'object': if ($var instanceof Traversable) { $vars = array(); foreach ($var as $k => $v) { $vars[$k] = $v; } } else { $vars = get_object_vars($var); } return '{' . join(',', array_map(array('MJSON', 'nameValue'), array_keys($vars), array_values($vars))) . '}'; default: return ''; } }
public function generate() { if ($this->property->actionUpdate) { $this->addTool(_M("Save"), $this->property->actionUpdate, "icon-save"); } if ($this->property->actionDelete) { $this->addTool(_M("Delete"), $this->property->actionDelete, "icon-remove"); } if ($this->property->actionInsert) { $this->addTool(_M("Insert"), $this->property->actionDelete, "icon-add"); } if ($this->property->actionSelect) { $this->property->checkbox = true; } foreach ($this->property->columns as $column) { $column->style->width = $column->style->width ?: '0'; $column->field = \Manager::getOptions('fetchStyle') == \FETCH_NUM ? strtoupper($column->field) : $column->field; } if ($this->property->checkbox) { $column = new MDatagridColumn(); $column->field = $this->id . 'Check'; $column->type = "check"; array_unshift($this->property->columns, $column); } $custom = new \StdClass(); $events = new \StdClass(); foreach ($this->options as $option => $value) { if (substr($option, 0, 2) == 'on') { $events->{$option} = (object) $value; } else { $custom->{$option} = $value; } } $this->generateData(); //$this->generateJsData(); if ($this->property->url) { $custom->url = $this->property->url; } if ($this->property->singleSelect) { $custom->singleSelect = $this->property->singleSelect; } if ($this->property->pageLength) { $custom->pagination = true; $custom->pageSize = $this->property->pageLength; $custom->pageList = array(5, 10, 15, 20, 30, 50); } else { $custom->pagination = false; } if ($this->property->idField != '') { if (preg_match('/^[0-9]/', $this->property->idField)) { $this->property->idField = 'F' . $this->property->idField; } $custom->idField = \Manager::getOptions('fetchStyle') == \FETCH_NUM ? strtoupper($this->property->idField) : $this->property->idField; } $toolbar = ''; if ($this->property->toolbar) { $custom->toolbar = "#{$this->property->toolbar->id}"; $toolbar = $this->painter->mdiv($this->property->toolbar); } $custom->border = isset($this->style->border) ? $this->style->border : true; $fields = array(); foreach ($this->property->columns as $column) { $field = new StdClass(); $field->field = $column->field; $field->title = $column->title; $field->hidden = $column->visible === false; $field->idGrid = $this->id; if ($column->action) { $field->action = $column->action; } if ($column->style->width) { $field->width = $column->style->width; } if ($column->align) { $field->align = $column->align; } if ($column->align) { $field->halign = $column->halign; } $field->type = $column->type ?: 'label'; if ($column->property->options) { $field->options = $column->property->options; } if ($column->render) { $field->render = $column->render; } if ($column->stylizer) { $field->stylizer = $column->stylizer; } if ($column->index) { $field->field = 'F' . $column->index; } if ($column->type == "control") { $controls = $column->getControls(); $firstControl = current($controls); $htmlControl = MJSON::encode($firstControl->generate()); $field->idControl = $firstControl->id; $this->page->addJsCode("\$('#{$this->id}').data('{$field->idControl}', {$htmlControl});\n"); } if ($column->type == "check") { $field->checkbox = true; } if ($column->type == "icon") { $field->icon = $column->icon; $field->alt = $column->alt; if ($column->field == '') { $field->field = substr(uniqid(), -6); } } $fields[] = $field; } $paramJson = MJSON::encode((object) ['custom' => $custom, 'columns' => $fields]); $eventJson = MJSON::encode((object) ['events' => $events]); $this->page->onLoad("theme.datagrid('{$this->property->id}','{$paramJson}', {$eventJson}, '{$this->property->data}');"); $this->property->idHidden = $this->property->id . '_data'; $idField = $this->property->idField; if ($idField != '') { $this->property->manager['idField'] = $idField; } $attributes = $this->painter->getAttributes($this); if ($this->property->head != '') { $thead = <<<EOT <thead> <tr> {$this->property->head} </tr> </thead> EOT; } $grid = <<<EOT <input type="hidden" id="{$this->property->idHidden}" name="{$this->property->idHidden}" value=""/> <table {$attributes}> {$thead} </table> EOT; if (!$this->form instanceof \MForm) { // Todos os grids precisam estar dentro de um form $formId = $baseId . '_form'; $grid = <<<EOT <form id="{$formId}" name="{$formId}" method="POST"> {$grid} </form> EOT; $this->property->form->id = $formId; } $this->result = $grid . $toolbar; return $this->result; }
public function logout($forced = '') { if (Manager::getOptions('dbsession')) { //$session = $this->manager->getBusinessMAD('session'); //$session->registerOut($this->getLogin()); } $this->setLogin(NULL); Manager::getSession()->destroy(); }
public function getExtension($lang) { $valor = $this->getValue(); if (strpos($valor, ",") > 0) { // retira o ponto de milhar, se tiver $valor = str_replace(".", "", $valor); // troca a virgula decimal por ponto decimal $valor = str_replace(",", ".", $valor); } //obtem o arquivo de configuração e linguagem $lang = Manager::getOptions('language'); $file = 'messages.' . ($lang ? $lang . '.' : '') . 'php'; $file = Manager::getFrameworkPath('conf/' . $file); $currencyExt = file_exists($file) ? require $file : array(); $currencyExt = $currencyExt['currencyExtension']; $singular = $currencyExt['classSingular']; $plural = $currencyExt['classPlural']; $c = $currencyExt['orderHundred']; $d = $currencyExt['orderDozen']; $d10 = $currencyExt['firstDozen']; $u = $currencyExt['orderUnit']; $z = 0; $ot = $currencyExt['other']; $valor = number_format($valor, 2, ".", "."); $inteiro = explode(".", $valor); $cont = count($inteiro); for ($i = 0; $i < $cont; $i++) { for ($ii = strlen($inteiro[$i]); $ii < 3; $ii++) { $inteiro[$i] = "0" . $inteiro[$i]; } } $fim = $cont - ($inteiro[$cont - 1] > 0 ? 1 : 2); $rt = ''; for ($i = 0; $i < $cont; $i++) { $valor = $inteiro[$i]; $rc = $valor > 100 && $valor < 200 ? $ot[1] : $c[$valor[0]]; $rd = $valor[1] < 2 ? "" : $d[$valor[1]]; $ru = $valor > 0 ? $valor[1] == 1 ? $d10[$valor[2]] : $u[$valor[2]] : ""; $r = $rc . ($rc && ($rd || $ru) ? " " . $ot[2] . " " : "") . $rd . ($rd && $ru ? " " . $ot[2] . " " : "") . $ru; $t = $cont - 1 - $i; $r .= $r ? " " . ($valor > 1 ? $plural[$t] : $singular[$t]) : ""; if ($valor == "000") { $z++; } elseif ($z > 0) { $z--; } if ($t == 1 && $z > 0 && $inteiro[0] > 0) { $r .= ($z > 1 ? " " . $ot[3] . " " : "") . $plural[$t]; } if ($r) { $rt = $rt . ($i > 0 && $i <= $fim && $inteiro[0] > 0 && $z < 1 ? $i < $fim ? ", " : " " . $ot[2] . " " : " ") . $r; } } return $rt ? $rt : $ot[0]; }