/** * Retreive the composed table. * If as checkcolumn is present (checkbox >= 0) then a onload script will be loaded to the page header. */ public function getTable() { global $ADODB_FETCH_MODE; $result = ''; $rowCount = 1; $ADODB_FETCH_MODE = ADODB_FETCH_NUM; $coltypes = array(); $columnNames = array(); $resultSet = $this->dbConn->Execute($this->query); if ($resultSet === false) { $result .= "<pre style='color:800'>Cannot read table data with \n\t" . $this->query . " </pre>\n\treason \n\t" . $this->dbConn->ErrorMsg() . " at\n"; stacktrace(1); $result .= "</pre>"; return $result; } $colcount = $resultSet->FieldCount(); $result .= $this->tabledef . "\n"; $result .= "<thead>\n"; if ($this->checkColumn >= 0 && $this->page != null) { $this->page->addHeadText(' <script type="text/javascript"> function checkThem(ref,state){ var checks = document.getElementsByName(ref); var boxLength = checks.length; for ( i=0; i < boxLength; i++ ) { checks[i].checked = state; } }</script> '); $checkRow = "<tr style='background:rgba(255,128,0,0.4)'>"; if ($this->checkColumn > 0) { $checkRow .= "<td colspan='" . $this->checkColumn . "'>"; } $checkBox = "<input name='checkAll' type='checkbox' onclick='javascript:checkThem(\"" . $this->checkName . "\",this.checked)'/> (un)Check all"; $checkRow .= "<td> </td><td colspan='" . ($colcount - $this->checkColumn) . "'style='font-weight:bold;border:none'>{$checkBox}</td>"; $checkRow .= "</tr>\n"; $result .= $checkRow; } $result .= "<th>#</th>"; for ($i = 0; $i < $colcount; $i++) { $field = $resultSet->FetchField($i); $columnNames[$i] = $field->name; $result .= "\t\t<th class='tabledata head' style='text-algin:left;'>" . niceName($field->name) . "</th>\n"; $columntypes[$i] = $resultSet->MetaType($i); } $result .= "</tr>\n</thead>\n<tbody>\n"; $oldValue = ''; $rowColor = $this->rainbow->restart(); if (!$resultSet->EOF) { if ($this->colorChangerColumn >= 0 && isset($resultSet->fields[$this->colorChangerColumn])) { $oldValue = $resultSet->fields[$this->colorChangerColumn]; } } while (!$resultSet->EOF) { if ($this->colorChangerColumn >= 0 && isset($resultSet->fields[$this->colorChangerColumn]) && $oldValue != $resultSet->fields[$this->colorChangerColumn]) { $rowColor = $this->rainbow->getNext(); $oldValue = $resultSet->fields[$this->colorChangerColumn]; } $result .= "\t<tr style='background:{$rowColor}'>\n" . "<td align='right'>" . $rowCount++ . "</td>"; for ($i = 0, $max = $resultSet->FieldCount(); $i < $max; $i++) { $val = isset($resultSet->fields[$i]) ? trim($resultSet->fields[$i]) : ''; if (substr($val, 0, 1) != '<') { $val = $val; } if (substr($val, 0, 1) == '{' && substr($val, -1) == '}') { $val = substr($val, 1, strlen($val) - 2); $val = substr($val, 0, strlen($val) - 2); $a = explode(',', $val); $val = '<td>' . implode('</td><td>', $a) . '</td>'; } $tdclass = 'tabledata'; switch ($columntypes[$i]) { case 'int2': case 'integer': case 'numeric': case 'float': case 'real': case 'N': $tdclass .= ' num'; break; default: break; } $result .= "\t\t<td class='{$tdclass}'>" . $val . "</td>\n"; } $result .= "\t</tr>\n"; $resultSet->MoveNext(); } $result .= "</tbody>\n</table>\n"; $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC; return $result; }
public function parseToTableHeader($pgResultSet, $headers = null) { $result = array(); $colcount = $pgResultSet->FieldCount(); for ($i = 0; $i < $colcount; $i++) { $helper = array(); $fieldName = niceName($pgResultSet->FieldName($i)); $field = $pgResultSet->fields[$i]; if ('{' == substr($field, 0, 1) && '}' == substr($field, -1)) { $s = str_replace('{', 'array(', $field); $s = str_replace('}', ')', $s); //echo $s; $s = eval("\$helper={$s};"); $count = count($helper); $this->columnCellCount[$i] = $count; for ($j = 1; $j <= $count; $j++) { array_push($result, $fieldName . $j); } } else { array_push($result, $fieldName); $this->columnCellCount[$i] = 1; } } return $result; }
function checkTable($dbConn, $query, $rowTriggerColumn, $headColumn, $checkcolumn, $notecolumn, $tabledef = "<table summary='simple table' border='1' style='border-collapse:collapse'>") { $result = ''; $head = "<tr>\n"; $triggerval = ''; global $ADODB_FETCH_MODE; $ADODB_FETCH_MODE = ADODB_FETCH_NUM; $coltypes = array(); $colgroupdef = '<colgroup>' . "\n"; $columnNames = array(); $rowcounter = 0; $resultSet = $dbConn->Execute($query); if ($resultSet === false) { echo "<pre>Cannot read table data with \n\t" . $query . " \n\treason \n\t" . $dbConn->ErrorMsg() . "at\n"; stacktrace(1); echo "</pre>"; } $colcount = $resultSet->FieldCount() - 1; for ($i = 0; $i < $colcount; $i++) { $field = $resultSet->FetchField($i); $columnNames[$i] = $field->name; if ($i != $headColumn && $i != $checkcolumn) { $head .= "\t<th class='tabledata head' style='text-algin:left;'>" . niceName($field->name) . "</th>\n"; $colgroupdef .= "\t<col/>\n"; } } $sessioncount = 0; $present = 0; while (!$resultSet->EOF) { if ($triggerval != $resultSet->fields[$rowTriggerColumn]) { $rowcounter++; if ($result != '') { $result .= "<th align='right' >" . round(100 * $present / $sessioncount, 0) . "%</th></tr>\n"; $present = 0; //$result .= "</tr><!-- new row -->\n"; } $result .= "<tr>\n"; $colcount = $resultSet->FieldCount() - 1; // get row head columns for ($i = 0; $i < $colcount; $i++) { if ($i != $headColumn && $i != $checkcolumn) { $result .= "\t" . '<td>'; if (isset($resultSet->fields[$i])) { $cell = trim($resultSet->fields[$i]); } else { $cell = ' '; } $result .= $cell; $result .= "</td>\n"; } } } $triggerval = $resultSet->fields[$rowTriggerColumn]; if ($rowcounter == 1) { $sessioncount++; $head .= "\t<th title='" . $resultSet->fields[$headColumn] . "'>{$sessioncount}</th>\n"; $colgroupdef .= "\t<col/>\n"; } if (isset($resultSet->fields[$notecolumn])) { $note = " title='" . $resultSet->fields[$notecolumn] . "' class='abs' "; } else { $note = ''; } $result .= "\t<td{$note}>" . $resultSet->fields[$checkcolumn] . "</td>\n"; if (isset($resultSet->fields[$checkcolumn])) { $present += $resultSet->fields[$checkcolumn] == 'P' ? 1 : 0; } // $result .= '<td>'.$resultSet->fields[1]."</td>\n"; $resultSet->MoveNext(); } $result .= "<th align='right' >" . round(100 * $present / $sessioncount, 1) . "</th></tr>\n"; $head .= "<th>% P</th></tr><!-- /head -->\n"; $colgroupdef .= "</colgroup>\n"; $result .= "</table>\n"; $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC; $result = $tabledef . "\n<thead>\n" . $colgroupdef . "\n</thead>\n" . $head . $result; return $result; }