48 parent::__construct();
61 $this->basecontrol =
new MLabel(
'');
62 $this->control = array();
234 $args =
new stdClass();
250 $i = $this->grid->currentRow;
251 $row = $this->grid->data[$i];
254 $this->control[$i]->value =
$value;
256 if ( $this->numberFormat )
258 $this->control[$i]->value = number_format(
$value, 2,
',',
'.');
267 $this->control[$i]->addBoxStyle(
'display',
'none');
270 return $this->control[$i];
275 $originalValue = $this->control[$this->grid->currentRow]->value;
277 if ( $this->options )
279 $this->control[$this->grid->currentRow]->value = $this->options[$originalValue];
281 if ( $this->grid->showid )
283 $this->control[$this->grid->currentRow]->value .=
" (" . $originalValue .
")";
295 if (count($this->colorOptions) > 0 && key_exists($valueOfColumn, $this->colorOptions))
297 $badgeLabel =
new MBadge($this->control[$this->grid->currentRow]->value, $this->colorOptions[$valueOfColumn]);
298 $this->control[$this->grid->currentRow]->value = $badgeLabel->generate();
301 else if (count($this->options) == 2 && (key_exists(DB_FALSE, $this->options) && key_exists(DB_TRUE, $this->options)))
307 else if (strlen($valueOfColumn) > 0)
312 if (!empty($badgeLabel))
314 $this->control[$this->grid->currentRow]->value = $badgeLabel->generate();
321 $colunasCep = array_filter($this->grid->columns,
function($column){
322 return ($column->title ==
'CEP');
325 foreach ($colunasCep as $key => $t)
327 if ( $key == $this->index && !empty($this->control[$this->grid->currentRow]->value)
328 && is_numeric($this->control[$this->grid->currentRow]->value)
329 && strlen($this->control[$this->grid->currentRow]->value) == 8 )
331 $mascarado = substr($this->control[$this->grid->currentRow]->value, 0, 5);
333 $mascarado .= substr($this->control[$this->grid->currentRow]->value, 5, 3);
334 $this->control[$this->grid->currentRow]->value = $mascarado;
349 $this->align =
'left';
351 $this->basecontrol =
new Hyperlink(
'',
'',
$href);
352 $this->basecontrol->setClass(
'm-grid-column-link');
357 $i = $this->grid->currentRow;
358 $row = $this->grid->data[$i];
364 for ($r = 0; $r < $n; $r++)
366 $href = str_replace(
"#$r#", trim($row[$r]),
$href);
370 $this->control[$i]->href =
$href;
371 $this->control[$i]->action =
$href;
372 $this->control[$i]->label =
$value;
376 $this->control[$i]->addBoxStyle(
'display',
'none');
379 return $this->control[$i];
398 $i = $this->grid->currentRow;
399 $row = $this->grid->data[$i];
401 $name = $this->control[$i]->getName();
404 if ( strpos(
$name,
"[") ===
false && strpos(
$name,
"]") ===
false )
411 $pos = strpos(
$name,
'%');
414 if ( !$pos ===
false )
416 $rowNumber = substr(
$name, $pos + 1, -2);
417 $name = str_replace(
"%$rowNumber%", trim($row[$rowNumber]),
$name);
421 $this->control[$i]->setName(
$name);
422 $this->control[$i]->setId(
$name);
425 for ( $r = 0; $r < $n; $r++ )
427 $this->control[$i]->setValue(str_replace(
"%$r%", trim($row[$r]), $this->control[$i]->
getValue()));
432 $this->control[$i]->addBoxStyle(
'display',
'none');
435 return $this->control[$i];
456 parent::__construct();
464 $this->valueoff =
$value[1];
468 $this->value = $this->valueoff =
$value;
478 $this->enabled =
true;
483 $this->enabled =
false;
488 $index = $row[$this->grid->index];
489 $href = preg_replace(
'#\$id#',
$index, $this->href);
493 foreach ( (array) $row as $tempKey => $tempValue )
495 $href = str_replace(
"%$tempKey%", urlencode($tempValue),
$href);
499 for ($r = 0; $r < $n; $r++)
501 if( is_object($row[$r]) )
503 $row[$r] = $row[$r]->generate( );
506 $href = str_replace(
"%$r%", urlencode($row[$r]),
$href);
536 $class =
"m-grid-action-icon-{$this->value}-on";
538 preg_match_all(
"#{$class}[\s]*\{[\s]*background-image:[\s]*url\((.*?)\);[\s]*\}#i", $this->grid->css, $match);
540 $this->path = ( isset($match[1][0]) ? $match[1][0] :
null);
546 $class =
"m-grid-action-icon";
550 $path = $this->grid->getImage($this->value);
555 $row = $this->grid->data[$this->grid->currentRow];
556 $href = $this->generateLink($row);
558 $control = ( $this->grid->linktype ==
'hyperlink') ?
562 $control->setTarget( $this->target );
567 $control->setClass(
'm-grid-action-icon-off');
570 $control->setClass($class);
582 $this->
attributes =
"width=\"20\" align=\"center\"";
589 if ( $this->enabled )
591 $row = $this->grid->data[$this->grid->currentRow];
594 for ($r = 0; $r < $n; $r++)
599 $href = $this->generateLink($row);
600 $control = ( $this->grid->linktype ==
'hyperlink') ?
604 $control->setTarget( $this->target );
605 $control->setClass(
'm-grid-link');
609 $control =
new MSpan(
'',
$value,
'm-grid-link-disable');
620 parent::__construct(
$grid,
'select',
null,
null,
null,
true,
$index);
625 $i = $this->grid->currentRow;
626 $row = $this->grid->data[$i];
627 $index = $row[$this->grid->index];
629 if ( $this->grid instanceof SGrid )
631 $primaryKeys = array_values($this->grid->getPrimaryKey());
632 $indexPrimaryKey = $row[str_replace(
"%",
"", $primaryKeys[0])];
634 $index = $this->grid->indexPrimaryKey ? $indexPrimaryKey :
$index;
637 $onclick =
"javascript:gridChk(this,'" . $this->grid->name .
"[$i]" .
"');";
639 $control =
new MCheckBox(
"select" . $this->grid->name .
"[$i]",
$index,
'');
640 $control->addAttribute(
'onclick', $onclick);
643 foreach ( $this->attrs->getItems() as $attr =>
$value )
647 if ( strtolower($attr) ==
'onclick' )
649 $value =
"$onclick $value";
652 $control->addAttribute($attr,
$value);
663 parent::__construct(
$id,
"[$label]",
$href);
680 parent::__construct();
686 $this->control =
null;
691 if ( $this->enabled )
693 $array[] =
new MSpan(
'', $this->label .
' ',
'm-grid-font');
694 $this->control->setValue( ( $this->grid->getFiltered() ) ? $this->value : NULL);
695 $array[] = $this->control->generate();
696 $array[] =
' ';
710 $this->value = $this->page->request($this->control->name) ? $this->page->request($this->control->name) :
$value;
721 $this->control =
new MSelection(
"m-grid-filter-sel-$index",
'',
$label, $options);
722 $this->value = $this->page->request($this->control->name) ? $this->page->request($this->control->name) :
$value;
734 $this->value = $this->page->request($this->control->name) ? $this->page->request($this->control->name) :
$control->value;
780 private $gridMostraTotalNumeric =
false;
785 private $offset = NULL;
790 private $hiddenControls = array();
812 private $generateDataCalled =
false;
840 public function __construct(
$data,
$columns,
$href,
$pageLength=15,
$index=0,
$name=
'', $useSelecteds=TRUE, $useNavigator=TRUE,
$showExport=FALSE, $gridMostraTotalNumeric=
false, $fixedTableHeader=
true)
844 parent::__construct(NULL);
849 $this->headerLinks = array();
852 $this->box =
new MBox(
'',
'backContext',
'');
853 $this->rowmethod =
null;
855 $this->emptyMsg = _M(
'No records found!');
857 $this->rowCount = count($this->data);
858 $this->controls = array();
859 $this->select = NULL;
862 $this->gridMostraTotalNumeric = $gridMostraTotalNumeric;
864 $this->pageNumber =
MUtil::NVL($state->get(
'pn_page', $this->name),
'1');
865 $this->prevPage =
MUtil::NVL($state->get(
'grid_page', $this->name),
'1');
866 $state->set(
'grid_page', $this->pageNumber, $this->name);
870 $this->selecteds = array();
871 $this->selectsreadonly = array();
872 $this->allSelecteds = array();
879 $this->page->addScript(
'm_grid.js');
881 $this->css = file_get_contents($this->manager->getTheme()->getPath() .
'/m_grids.css');
883 $this->actionColumnName = _M(
'Action');
886 if ( $fixedTableHeader )
888 $this->page->addScript(
"../themes/{$MIOLO->getTheme()->getName()}/scripts/fixed_table_header.js");
890 $this->page->addScript(
"../themes/{$MIOLO->getTheme()->getName()}/scripts/sagu.js");
895 $this->isShowHeaders = $show;
908 $state->set(
'grid_page',
$pageNumber, $this->name);
909 $this->prevPage =
MUtil::NVL($state->get(
'grid_page', $this->name),
'1');
919 $url .=
"&orderby={$this->orderby}";
924 if ( strlen($currentOrder) > 0 && ( $this->orderby == $currentOrder ) )
935 $url .=
'&ordermode=' . $orderMode;
941 if ( ( strlen( ( isset($_REQUEST[
'function']) ? $_REQUEST[
'function'] :
null) ) > 0 ) && !preg_match(
'/function=/',
$url) )
943 $url .=
'&function=' . $_REQUEST[
'function'];
966 $this->caption = $this->title =
$title;
986 $this->columns = array();
995 $this->columns[$k] = $c;
996 $this->columns[$k]->index = $k;
997 $this->columns[$k]->grid = $this;
1003 $this->linktype = strtolower(
$linktype);
1013 $this->controls = array_merge($this->controls,
$controls);
1033 $this->rowmethod = array($class, $method);
1039 $this->scrollWidth =
$width;
1040 $this->scrollHeight = $height;
1045 $this->scrollWidth =
$width;
1050 $this->scrollHeight = $height;
1060 $this->columns[$col]->$attr = $value;
1065 $this->data =
$data;
1069 if ( $this->gridMostraTotalNumeric && empty($this->rowCount) && ($this->rowCount >= $this->pageLength || $this->pageLength == 999999999) )
1082 return $this->data[$row][$col];
1087 if ( count($this->data) )
1089 $gridCount = $this->pn->gridCount;
1090 if ( $this->gridMostraTotalNumeric )
1095 $offset = $this->pn->idxFirst >= count($this->data) ? 0 : $this->pn->idxFirst;
1096 return array_slice($this->data, $offset, $gridCount);
1120 $icon = str_replace(array(
'cal.gif'), array(
'calendario.png'), $icon);
1154 $this->filters[
$index] = $f;
1160 $this->filters[
$index] = $f;
1170 return $this->filters[
$index]->value;
1175 return $this->filters[
$index]->control;
1180 $this->filtered = $value;
1185 if ( ( $f = $this->page->Request(
'__filter') ) !=
'' )
1187 $this->filtered = ($f ==
'1');
1200 $this->filter = $status;
1204 foreach ($this->filters as $k => $f)
1206 $this->filters[$k]->enabled = $status;
1215 foreach ($this->filters as $f)
1217 $value[$f->index] = $f->value;
1220 foreach ($this->data as $row)
1224 foreach ($value as $k => $v)
1226 $n = strlen( trim($v) );
1227 $ok = $ok && ( ! strncasecmp($row[$k], $v, $n) );
1233 $this->data =
$data;
1234 $this->rowCount = count($this->data);
1240 $p = $this->columns[$column]->index;
1241 $n = count($this->data[0]);
1243 foreach ($this->data as $key => $row)
1245 for ($i = 0; $i < $n; $i++)
1247 $arr[$i][$key] = $row[$i];
1251 $sortcols =
"\$arr[$p]";
1253 for ($i = 0; $i < $n; $i++)
1257 $sortcols .=
",\$arr[$i]";
1262 if ( $this->orderByDatabase !=
true )
1264 eval(
"array_multisort({$sortcols}, SORT_ASC);");
1267 $this->data = array();
1269 for ($i = 0; $i < $n; $i++)
1271 foreach ($arr[$i] as $key => $row)
1273 $this->data[$key][$i] = $row;
1282 if ( is_array($err) )
1286 $this->errors = array_merge($this->errors, $err);
1290 $this->errors = $err;
1295 $this->errors[] = $err;
1302 $this->showid = $state;
1307 $this->box->setClose(
$action);
1313 $selecteds = $state->get(
'selecteds', $this->name);
1315 $state->set(
'selecteds',
$selecteds, $this->name);
1316 $state->set(
'useselecteds',
true, $this->name);
1322 $state->set(
'useselecteds', $opt, $this->name);
1329 $selecteds = $state->get(
'selecteds', $this->name);
1330 $useSelecteds = $state->get(
'useselecteds', $this->name);
1332 if ( urldecode( $this->page->request(
'gridName') ) == $this->name )
1334 $state->set(
'pn_page', $this->page->request(
'pn_page'), $this->name);
1336 $state->set(
'gridName', $this->name);
1337 $this->pageNumber =
MUtil::NVL($state->get(
'pn_page', $this->name),1);
1338 $this->prevPage =
MUtil::NVL($state->get(
'grid_page', $this->name),1);
1340 $this->selecteds = array();
1346 if (
$select = $this->page->request(
'select'.$this->name))
1353 if ( is_array(
$selecteds[$this->pageNumber]) )
1360 $state->set(
'grid_page', $this->pageNumber, $this->name);
1362 $state->set(
'useselecteds', $useSelecteds, $this->name);
1363 $state->set(
'selecteds',
$selecteds, $this->name);
1368 if ( $this->caption !=
'' )
1370 $this->box->SetCaption($this->caption);
1372 return $this->box->boxTitle->generate();
1383 $links = $this->pn->getPageLinks();
1385 foreach ( $links as $link )
1387 $link->float =
'left';
1390 $d[
'pages'] =
new MDiv(
'', $links);
1391 $d[
'pages']->addStyle(
'float',
'left');
1392 $array[0] = $this->pn->getPageFirst();
1393 $array[1] = $this->pn->getPagePrev();
1394 $array[2] = $this->pn->getPageRange();
1395 $array[3] = $this->pn->getPageNext();
1396 $array[4] = $this->pn->getPageLast();
1398 if ( !is_null($this->showExportAsCSV) )
1403 if ( $this->showExport )
1405 $pn_page = !is_null($_GET[
'pn_page']) ?
"&pn_page=" . $_GET[
'pn_page'] :
"";
1406 if ($this->manager->theme->id ==
'smodern')
1410 $url =
"{$this->pn->action}&gridName=". urlencode($this->name) . $pn_page;
1411 $img =
$MIOLO->getUI()->getImage(NULL,
'csv.png');
1413 $export =
new MLinkButton(
'exportGridAsCSV', _M(
'Export as CSV (Excel)'),
$url);
1414 $export->generateLink();
1415 $export =
new MImageLink(
'exportGridAsCSV', _M(
'Export as CSV (Excel)'), $export->href .
'stopShowLoading();', $img);
1416 $d[
'export'] =
new MDiv(
'exportButtonDiv', array($export),
'm-grid-export-div');
1421 $url =
"{$this->pn->action}&gridName=". urlencode($this->name) . $pn_page;
1422 $img =
$MIOLO->getUI()->getImage(NULL,
'html.png');
1424 $export =
new MLinkButton(
'exportGridAsHTML', _M(
'Export as HTML'),
$url);
1425 $export->target =
'_blank';
1426 $export->generateLink();
1427 $export =
new MImageLink(
'exportGridAsHTML', _M(
'Export as HTML'), $export->href .
'stopShowLoading();', $img);
1428 $d[
'exportHTML'] =
new MDiv(
'exportButtonDiv', array($export),
'm-grid-export-div');
1433 $url =
"{$this->pn->action}&gridName=". urlencode($this->name) . $pn_page;
1434 $img =
$MIOLO->getUI()->getImage(NULL,
'pdf.png');
1436 $export =
new MLinkButton(
'exportGridAsPDF', _M(
'Export as PDF'),
$url);
1437 $export->generateLink();
1438 $export =
new MImageLink(
'exportGridAsPDF', _M(
'Export as PDF'), $export->href .
'stopShowLoading();', $img);
1439 $d[
'exportPDF'] =
new MDiv(
'exportButtonDiv', array($export),
'm-grid-export-div');
1443 $url =
"{$this->pn->action}&gridName=". urlencode($this->name) . $pn_page;
1444 $img =
$MIOLO->getUI()->getImage(NULL,
"xls.png");
1446 $export =
new MLinkButton(
"exportGridAsXLS", _M(
"Exportar como XLS"),
$url .
"&tipoDeExportacao=0");
1447 $export->generateLink();
1448 $export =
new MImageLink(
"exportGridAsXLS", _M(
"Exportar como XLS"), $export->href .
'stopShowLoading();', $img);
1449 $d[
'exportXLS'] =
new MDiv(
'exportButtonDiv', array($export),
'm-grid-export-div');
1453 $url =
"{$this->pn->action}&gridName=". urlencode($this->name) . $pn_page;
1454 $img =
$MIOLO->getUI()->getImage(NULL,
"jrxml.png");
1456 $export =
new MLinkButton(
"exportGridAsJRXML", _M(
"Gerar JRXML"),
$url);
1457 $export->generateLink();
1458 $export =
new MImageLink(
"exportGridAsJRXML", _M(
"Gerar JRXML"), $export->href .
'stopShowLoading();', $img);
1459 $d[
'exportJRXML'] =
new MDiv(
'exportButtonDiv', array($export),
'm-grid-export-div');
1463 $newExport = (version_compare(SAGU_VERSION,
"3.74.05") >= 0);
1464 $exportsList = array(
'PDF',
'XLS',
'HTML',
'JRXML',
'CSV');
1465 foreach ($exportsList as $ex)
1467 $url =
"{$this->pn->action}&gridName=". urlencode($this->name) . $pn_page .
"&typeExport=$ex";
1469 $export->generateLink();
1473 $labelEx = _M(
"Exportar para $ex");
1474 $actionExportUrl = base64_encode($export->href .
'stopShowLoading();');
1475 $actionExport =
"javascript:saguDoAjax('gerarModalExportacao','divExportsM',false,'&labelExport={$labelEx}&rowCount={$this->rowCount}&actionExport={$actionExportUrl}')";
1477 $export =
new MText(
"exportGridAs$ex", _M(
"Exportar para $ex"));
1478 $export->addAttribute(
'onclick', $actionExport);
1479 $export->addAttribute(
'style',
'cursor: pointer; text-decoration: none; font-size: 11px; font-weight: 500; font-style: normal; white-space: normal; text-align:left !important; min-height: 22px !important; padding-left: 18px;');
1480 $linksExport[] = $export;
1484 $linksExport[] =
new MLink(
'lnkExport$ex', _M(
"Exportar para $ex"), $export->href .
'stopShowLoading();',
null);
1488 $d[
'exportDrop'] =
new MDropdownMenu(
'',
' ', $linksExport, $this->manager->getUI()->getImageTheme($this->manager->theme->id,
'export-20x20.png'));
1489 $d[
'exportDrop']->setClass(
'exportIcon');
1490 $d[
'exportDrop']->addAttribute(
'title',
'Exportar');
1491 $this->page->onLoad(
'
1492 $(".exportIcon ul").css("left", $(".exportIcon").prev().width()+"px");
1493 $(".exportIcon").prop("title", "Visualizar exportações disponíveis");
1498 $d[
'nav'] =
new MDiv(
'', $array);
1499 $d[
'nav']->addStyle(
'float',
'right');
1501 $d =
new MDiv(
'', $d,
'm-grid-navigation');
1513 $links = $this->pn->getPageLinks();
1515 foreach ($links as $link)
1517 $link->float =
'left';
1520 $d1 =
new MDiv(
'', $links);
1521 $d1->addStyle(
'float',
'left');
1522 $array[0] = $this->pn->getPageFirst();
1523 $array[1] = $this->pn->getPagePrev();
1524 $array[2] = $this->pn->getPageRange();
1525 $array[3] = $this->pn->getPageNext();
1526 $array[4] = $this->pn->getPageLast();
1528 $d2 =
new MDiv(
'', $array);
1529 $d2->addStyle(
'float',
'right');
1531 $d =
new MDiv(
'', array($d1, $d2),
'm-grid-navigation m-grid-navigation-bottom');
1538 if ( ! count($this->headerLinks) )
1543 foreach ($this->headerLinks as $link)
1545 $link->float =
'left';
1548 $div =
new MDiv(
'', $this->headerLinks,
'm-grid-header-link');
1555 if ( ! count($this->controls) )
1562 foreach ($this->controls as $c)
1564 $array[$i++] = $c->generate();
1565 $array[$i++] =
' ';
1568 return new MDiv(
'', $array,
'm-grid-controls');
1573 if ( ! $this->filter )
1578 foreach ($this->filters as $k => $f)
1580 $array[] = $f->generate();
1583 $button =
new MButton(
'', _M(
'Filter'),
'submit',
'images/button_select.png');
1584 $array[] = $button->generate();
1586 return new MDiv(
'', $array,
'm-grid-filter');
1591 return count($this->errors);
1601 $t->setAttributes(
"class=\"m-prompt-box-error\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"100%\" border=\"0\"");
1602 $t->attributes[
'cell'][0][0] =
"colspan=\"2\" class=\"m-prompt-box-error-title\"";
1604 $t->attributes[
'cell'][1][0] =
"valign=\"top\" width=\"60\"";
1605 $t->cell[1][0] =
new ImageForm(
'',
'',
'images/error.gif');
1606 $t->attributes[
'cell'][1][1] =
"class=\"m-prompt-box-error-text\"";
1607 $leftmargin =
' ';
1609 foreach ($this->errors as $e)
1611 $msg .= $leftmargin .
"- $e<br/>";
1614 $t->cell[1][1] = $msg;
1634 $tbl->attributes[
'row'][0] =
"class=\"m-grid-row-heading\"";
1637 if ( count($this->actions) )
1639 $tbl->attributes[
'cell'][0][$p] =
"width=\"16\" align=\"left\" class=\"m-grid-column-heading\"";
1643 if ( $this->select != NULL )
1646 $this->page->onLoad(
"gridChkEachRow($rowCount,'".$this->name.
"');" );
1647 $tbl->attributes[
'cell'][0][$p] =
"width=\"16\" align=\"center\" class=\"m-grid-column-heading\"";
1648 $tbl->cell[0][$p] =
new CheckBox(
"chkAll",
'chkAction',
'');
1649 $tbl->cell[0][$p++]->AddAttribute(
'onclick',
"javascript:gridChkAll(this,$rowCount,'".$this->name.
"');");
1653 foreach ($this->columns as $k => $col)
1655 if ( (!$col->visible) || (!$col->title) || ($col->hidden) )
1662 $this->orderby = $k;
1663 $colTitle =
new MLinkButton(
'', $col->title, $this->getURL($this->filtered,
true) );
1664 $colTitle->setClass(
'm-grid-column-order');
1665 $colTitle->setGenerateLinkButton( !$this->colSortingCleanURL );
1669 $colTitle = $col->title;
1674 $attr =
" width=\"$col->width\"";
1679 if( $this->scrollable )
1681 $this->manager->logMessage( _M(
"[WARNING] Using scrollable table, it's necessary to inform column width. ") );
1685 $tbl->attributes[
'cell'][0][$p] =
"class=\"m-grid-column-heading\" " . ( isset($attr) ? $attr :
'');
1686 $tbl->cell[0][$p++] = $colTitle;
1694 if ( count($this->actions) )
1696 $tbl->attributes[
'cell'][0][0] =
"width=\"15\" align=\"left\" ";
1697 $tbl->cell[0][0] =
'';
1703 $i = $this->currentRow + 1;
1706 $n = count($this->actions) ? 1 : 0;
1708 if ( $this->gridMostraTotalNumeric && !empty($this->pn->gridCount) && $this->pn->gridCount < $i && ($n || $this->select !=
null) )
1710 $tbl->attributes[
'cell'][$i][] =
"align=\"center\" width=\"0\"";
1711 $tbl->cell[$i][] =
new MDiv(
"{$this->id}_gridActions",
"<span class='m-label'><b>TOTAL DA PÁGINA</b></span>",
'm-grid-actions');
1720 foreach ( $this->actions as $k =>
$action )
1725 if ( is_object($a) )
1727 $a = $a->generate();
1738 $innerTable =
"<table><tr>$actions</tr></table>";
1740 if ( $this->gerarQuebraDeLinhaActions )
1745 $tbl->attributes[
'cell'][$i][] =
"align=\"center\" width=\"0\"";
1746 $tbl->cell[$i][] =
new MDiv(
"{$this->id}_gridActions", $innerTable,
'm-grid-actions');
1749 if ( $this->select != NULL )
1751 $tbl->attributes[
'row'][$i] .=
" id=\"row".$this->name.
"[{$this->currentRow}]\" ";
1752 $tbl->attributes[
'cell'][$i][$n] =
"align=\"center\"";
1753 $select = $this->select->generate();
1754 $select->checked = ( array_search($i-1, $this->selecteds) !== false );
1755 $select->readonly = $this->selectsreadonly[$i-1];
1769 foreach ( $this->columns as $k => $col )
1790 $i = $this->currentRow + 1;
1793 $p = count($this->actions) ? 1 : 0;
1795 if ( $this->select != NULL )
1802 foreach ( $this->columns as $k => $col )
1804 if ( $this->gridMostraTotalNumeric && $k == $firstVisible && !empty($this->pn->gridCount) && $this->pn->gridCount == $this->currentRow && count($this->actions) == 0 && !$this->select )
1806 if ( $col->visible ) {
1815 if (( ! $col->title ) || ( ! $col->visible ))
1834 $attr .=
" nowrap ";
1839 $attr .=
" width=\"$col->width\"";
1844 $attr .=
" align=\"$col->align\"";
1847 $class = $col->getClass();
1848 $tbl->attributes[
'cell'][$i][$p] =
"$attr class=\"$class\"";
1849 $tbl->cell[$i][$p++] = $control;
1855 $div =
new MDiv(
'', $this->emptyMsg,
'gridAttention');
1863 if ( ! $this->data || $this->generateDataCalled )
1868 $this->generateDataCalled =
true;
1870 $this->orderby = $this->page->request(
'orderby');
1871 $isAssociativeGrid = !isset($this->columns[0]);
1873 if ( $this->ordered = isset($this->orderby) && !$isAssociativeGrid )
1876 $this->page->state->set(
'orderby', $this->orderby, $this->name);
1884 if ( $this->pageLength )
1886 $this->pn =
new MGridNavigator( $this->pageLength, $this->rowCount,
1887 $this->
getURL( $this->filtered, $this->ordered ),
1891 if ( $this->offset == NULL )
1893 $this->data = $this->
getPage();
1904 if ( isset($this->rowmethod) )
1907 $row = $this->data[$i];
1909 $myRowClass = is_object($this->rowmethod[0]) ? get_class($this->rowmethod[0]) : $this->rowmethod[0];
1910 $myRowFunction = $this->rowmethod[1];
1912 if (get_class($this) == $myRowClass)
1914 $this->$myRowFunction($i, $row, $this->actions, $this->columns, $this);
1919 $reflectedGrid =
new ReflectionClass($this);
1920 include_once ($reflectedGrid->getFileName());
1922 $gridClass =
new $myRowClass();
1923 $gridClass->$myRowFunction($i, $row, $this->actions, $this->columns, $this);
1931 global
$MIOLO, $SCRIPT_NAME;
1938 $tblData =
new MSimpleTable(
'tbody' . $this->
id,
"cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%\" class=\"m-grid-body\"");
1943 $this->page->onLoad(
1944 "if (typeof $('#{$tbodyId}').stickyTableHeaders == 'function' ) $('#{$tbodyId}').stickyTableHeaders();".
1945 "$('#{$bodyId}').on('scroll', function(){\$('#{$tbodyId}').stickyTableHeaders();});"
1955 foreach ($this->data as $row)
1957 $this->currentRow = $i;
1958 $rowId = ($i % 2) + 1;
1959 $rowClass =
"m-grid-row-$rowId";
1961 $tblData->attributes[
'row'][$i] =
"class=\"$rowClass\"";
1968 $tblData->setRowAttribute(0,
"id",
'tbody'.$this->
id.
'first');
1970 if( $this->scrollable )
1972 $bodyHeader =
new MDiv(
'head'.$this->
id,
null,
'm-grid-head',
'style="'.
1973 'width:'.$this->scrollWidth.
';'.
1974 'overflow-x:hidden;"');
1975 $body =
new MDiv(
'body'.$this->
id, $tblData,
'm-grid-body',
'style="'.
1976 'width:'.$this->scrollWidth.
';'.
1977 'height:'.$this->scrollHeight.
';'.
1980 $body =
new MDiv(
'', array($bodyHeader, $body) );
1992 $footer = is_array($this->footer) ? $this->footer : array($this->footer);
1994 if ( ! $this->data )
2011 $url = $this->icons[$src];
2014 if ( substr($src, 0, 1) ==
'/' ||
2015 substr($src, 0, 5) ==
'http:' ||
2016 substr($src, 0, 6) ==
'https:')
2022 $file = $this->manager->getConf(
'home.themes') .
'/' . $this->manager->getConf(
'theme.main') .
'/images/' . $src;
2024 if ( file_exists($file) )
2026 $url = $this->manager->getUI()->getImageTheme( $this->manager->getConf(
'theme.main'), $src );
2030 $url = $this->manager->getUI()->getImage(
'', $src);
2034 $this->icons[$src] =
$url;
2044 $title = $this->painter->generateToString($this->
generateTitle());
2045 $body = $this->painter->generateToString($this->
generateBody());
2046 $footer = $this->painter->generateToString($this->
generateFooter());
2050 if ( $this->width !=
'' )
2052 $f->addStyle(
'width', $this->width);
2055 return $f->generate();
2063 return $this->offset != NULL;
2068 return $this->offset;
2073 $this->offset = $offset;
2102 public function setQuery($sql = NULL, $dbconf = NULL,
$rowCount = NULL, $returnAllData =
false, $asAssociative =
false, $consultaExportacao =
false)
2112 $db =
$MIOLO->getDatabase($dbconf);
2113 $queryBackup = $sql;
2114 $sql = $this->
normalizaConsulta($sql, $dbconf, $this->gridMostraTotalNumeric, ($consultaExportacao ? $this->columns :
null));
2118 if ( strlen($orderBy) > 0 )
2121 $msql->setDb(
$MIOLO->GetDatabase());
2122 $msql->createFrom($sql);
2123 $msql->clearOrderBy();
2126 ! is_numeric($orderBy) ? : $orderBy += 1;
2127 if (is_numeric($orderBy)) {
2132 $msql->setOrderBy(
'"' . $orderBy .
'" ' .
MIOLO::_REQUEST(
'ordermode'));
2136 $_REQUEST[
'ordermode'] ==
'asc' ? $_REQUEST[
'ordermode'] =
'desc' : $_REQUEST[
'ordermode'] =
'asc';
2137 $sql = $msql->select();
2140 $this->orderByDatabase =
true;
2144 $this->offset = ($this->pageNumber - 1) * $this->pageLength;
2148 $this->query =
$query =
"SELECT *, COUNT(*) OVER () AS rowCount FROM ({$sql}) AS MGRIDTABLE";
2149 $queryBackup =
"SELECT *, COUNT(*) OVER () AS rowCount FROM ({$queryBackup}) AS MGRIDTABLE";
2153 if ( !$returnAllData )
2155 if( !strlen(strstr(
$query,
' LIMIT ')) > 0 && !strlen(strstr(
$query,
' OFFSET ')) > 0 )
2157 $sqlWithLimit =
"{$query} LIMIT $this->pageLength OFFSET $this->offset";
2164 $sql = $sqlWithLimit;
2165 if ( $this->gridMostraTotalNumeric )
2174 $data = $db->query($sql);
2179 if ( $asAssociative )
2182 $columns = $db->query($sqlColumns);
2183 $associativeData = array();
2184 foreach (
$data as $record )
2186 $associativeValue = array();
2187 foreach (
$columns as $key => $column )
2189 $associativeValue[$column[0]] = $record[$key];
2191 $associativeData[] = $associativeValue;
2193 $data = $associativeData;
2196 catch ( Exception $err )
2200 $data = $db->query($queryBackup);
2207 foreach (
$data as $rowKey => $rowInfo)
2209 foreach ($rowInfo as $columnKey => $columnInfo)
2211 if ( SAGU::isDate($columnInfo) )
2213 $data[$rowKey][$columnKey] = SAGU::convertDateToUser($columnInfo);
2218 $this->data =
$data;
2219 $this->idResult = $db->getIdResult();
2220 $this->rowCount =
$rowCount ?? $this->data[0][count($this->data[0]) - 1];
2235 $randConsulta = rand();
2237 CREATE TEMP TABLE consulta_{$randConsulta} ON COMMIT DROP AS (
2241 FROM consulta_{$randConsulta}
2244 FROM somatorioDeValoresDaTabela(NULL::consulta_{$randConsulta})
2261 $randConsulta = rand();
2263 CREATE TEMP TABLE consulta_{$randConsulta} ON COMMIT DROP AS (
2267 FROM information_schema.columns
2268 WHERE table_name = 'consulta_{$randConsulta}' ORDER BY ordinal_position
2282 public static function normalizaConsulta($sql, $dbconf, $gridMostraTotalNumeric =
false, $columnsGrid = array())
2284 if ( $gridMostraTotalNumeric )
2287 $db =
$MIOLO->getDatabase($dbconf);
2290 $msql->considerarTabelasSubSelects =
true;
2291 $msql->setDb(
$MIOLO->GetDatabase());
2292 $msql->createFrom($sql);
2297 foreach ($msql->getColumns() as $key => $column)
2300 if ( count($columnsGrid) > 0 )
2302 $columnVisible =
false;
2303 foreach ( $columnsGrid as $keyAux => $columnAux )
2306 if ( !is_int($keyAux) )
2308 if ( stripos($key, $keyAux) !==
false )
2310 $columnVisible =
true;
2311 if ($columnAux->hidden || !$columnAux->visible || !($columnAux->title))
2313 $columnVisible =
false;
2320 $valueKeyColumn = array_search($key, array_values($msql->getColumns()));
2321 if ( $keyAux == $valueKeyColumn )
2323 $columnVisible =
true;
2324 if ( $columnAux->hidden || !$columnAux->visible || !($columnAux->title) )
2326 $columnVisible =
false;
2333 if ( !$columnVisible )
2340 $auxColumn = ($column ==
'null' || $column ==
'NULL') ?
'NULL::TEXT' : $column;
2341 $column = str_replace(
'null as',
'NULL::TEXT AS', $auxColumn);
2342 $column = str_replace(
'NULL AS',
'NULL::TEXT AS', $column);
2343 $column = str_replace(
'null AS',
'NULL::TEXT AS', $column);
2344 $column = str_replace(
'NULL as',
'NULL::TEXT AS', $column);
2346 $columns[$key .
'_' . $count] = $column;
2347 $explodeColumn = explode(
" as ", strtolower($column));
2348 if (count($explodeColumn) < 2 && $column !=
'*')
2350 $columns[$key .
'_' . $count] = $column .
" AS coluna_" . $count;
2356 $msql->clearColumns();
2358 $sql = $msql->select();
2366 $this->page->addStyleCode(
"table#tbody$this->id td:nth-child($column) {display:none;}");
2374 return $this->idResult;
2382 $this->idResult = $idResult;
2387 return $this->gridMostraTotalNumeric;
2392 $this->gridMostraTotalNumeric = $gridMostraTotalNumeric;
attributes( $mergeDuplicates=false)
setClass( $cssClass, $add=true)
addStyleFile( $styleFile)
__construct($grid, $value, $href, $alt=NULL)
__construct($grid, $index=0)
__construct($grid, $value, $href)
__construct($grid, $type, $alt, $value, $href, $enabled=true, $index=null)
__construct($title='', $align='left', $nowrap=false, $width=0, $visible=true, $options=null, $order=false, $replace=NULL, $numberFormat=false, $colorOptions=array())
setControl($control, $pos=0)
setBasecontrol($basecontrol)
generateColoredLabels($valueOfColumn)
formatSpecificColumnValues()
__construct($control, $title='', $align='left', $nowrap=false, $width=0, $visible=true)
__construct($grid, &$control, $type='text', $index=0, $enabled=false)
__construct($grid, $label, $options=array(), $index=0, $enabled=false)
__construct($grid, $label, $value='', $index=0, $enabled=false)
__construct($grid, $type, $label, $value, $index, $enabled=false)
__construct($title='', $href, $width=0, $visible=true, $options=null, $order=false, $filter=false)
generateNavigationFooter()
correctActionColSpan($tbl)
generateColumnsHeading($tbl)
setScrollHeight($height='99%')
addFilterControl($index, $control, $type='text')
addActionIcon($alt, $icon, $href, $index=null)
addActionDelete($href, $alt='Delete')
getURL($filter=false, $order=false, $item='')
headerLink($id, $label, $href)
setColumnAttr($col, $attr, $value)
setPageLength($pageLength)
setGridMostraTotalNumeric($gridMostraTotalNumeric)
setScrollWidth($width='99%')
generateColumns($tbl, $row=null, $i=null)
isGridMostraTotalNumeric()
addActionText($alt, $text, $href, $index=0)
static obterConsultaComSomatorios($query)
setShowHeaders( $show=true)
static obterConsultaComNomesDasColunas($query)
setCurrentPage($pageNumber)
generateNavigationHeader()
setFiltered($value=false)
setData($data, $rowCount=null)
static normalizaConsulta($sql, $dbconf, $gridMostraTotalNumeric=false, $columnsGrid=array())
$gerarQuebraDeLinhaActions
generateColumnsControls()
setQuery($sql=NULL, $dbconf=NULL, $rowCount=NULL, $returnAllData=false, $asAssociative=false, $consultaExportacao=false)
addFilterSelection($index, $label, $options, $value='')
generateAlignColumn(&$column, $value)
addFilterText($index, $label, $value='')
setRowMethod($class, $method)
__construct($data, $columns, $href, $pageLength=15, $index=0, $name='', $useSelecteds=TRUE, $useNavigator=TRUE, $showExport=FALSE, $gridMostraTotalNumeric=false, $fixedTableHeader=true)
setIsScrollable($scrollable=true, $width='99%', $height='99%')
static _REQUEST( $vars, $from='ALL')
static NVL($value1, $value2)
static getBooleanValue($value)