function ExportToExcel($rs, $nPageSize, $eventObj, $cipherer, $pageObj) { if ($eventObj->exists("ListFetchArray")) { $row = $eventObj->ListFetchArray($rs, $pageObj); } else { $row = $cipherer->DecryptFetchedArray($pageObj->connection->fetch_array($rs)); } $tmpArr = array(); $totals = array(); $arrLabel = array(); $arrTotal = array(); $arrFields = array(); $arrTmpTotal = array(); $arrColumnWidth = array(); $arrTotalMessage = array(); $tmpArr = $pageObj->pSet->getExportFields(); foreach ($tmpArr as $value) { if ($pageObj->pSet->appearOnExportPage($value)) { $arrFields[] = $value; } } $arrTmpTotal = $pageObj->pSet->getTotalsFields(); $pageObj->viewControls->forExport = "excel"; foreach ($arrFields as $value) { $arrLabel[$value] = GetFieldLabel(GoodFieldName($pageObj->tName), GoodFieldName($value)); $arrColumnWidth[$value] = 10; $totals[$value] = array("value" => 0, "numRows" => 0); $totalsType = ""; foreach ($arrTmpTotal as $tvalue) { if ($tvalue["fName"] == $value) { $totalsType = $tvalue["totalsType"]; $totalsFields[] = array('fName' => $value, 'totalsType' => $totalsType, 'viewFormat' => $pageObj->pSet->getViewFormat($value)); } } } // write data rows $iNumberOfRows = 0; $objPHPExcel = ExportExcelInit($arrLabel, $arrColumnWidth); while ((!$nPageSize || $iNumberOfRows < $nPageSize) && $row) { countTotals($totals, $totalsFields, $row); $values = array(); $arrData = array(); $arrDataType = array(); foreach ($arrFields as $field) { if (IsBinaryType($pageObj->pSet->getFieldType($field))) { $values[$field] = $row[$field]; } else { $values[$field] = $pageObj->getExportValue($field, $row); } } $eventRes = true; if ($eventObj->exists('BeforeOut')) { $eventRes = $eventObj->BeforeOut($row, $values, $pageObj); } if ($eventRes) { $iNumberOfRows++; $i = 0; foreach ($arrFields as $field) { if (IsBinaryType($pageObj->pSet->getFieldType($field))) { $arrDataType[$field] = "binary"; } elseif ($pageObj->pSet->getViewFormat($field) == FORMAT_DATE_SHORT || $pageObj->pSet->getViewFormat($field) == FORMAT_DATE_LONG || $pageObj->pSet->getViewFormat($field) == FORMAT_DATE_TIME) { $arrDataType[$field] = "date"; } elseif ($pageObj->pSet->getViewFormat($field) == FORMAT_FILE_IMAGE) { $arrDataType[$field] = "file"; } else { $arrDataType[$field] = ""; } $arrData[$field] = $values[$field]; } ExportExcelRecord($arrData, $arrDataType, $iNumberOfRows, $objPHPExcel, $pageObj); } if ($eventObj->exists("ListFetchArray")) { $row = $eventObj->ListFetchArray($rs, $pageObj); } else { $row = $cipherer->DecryptFetchedArray($pageObj->connection->fetch_array($rs)); } } if (count($arrTmpTotal)) { foreach ($arrFields as $fName) { $value = array(); foreach ($arrTmpTotal as $tvalue) { if ($tvalue["fName"] == $fName) { $value = $tvalue; } } $total = ""; $totalMess = ""; if ($value["totalsType"]) { if ($value["totalsType"] == "COUNT") { $totalMess = "Count" . ": "; } elseif ($value["totalsType"] == "TOTAL") { $totalMess = "Total" . ": "; } elseif ($value["totalsType"] == "AVERAGE") { $totalMess = "Average" . ": "; } $total = GetTotals($fName, $totals[$fName]["value"], $value["totalsType"], $totals[$fName]["numRows"], $value["viewFormat"], "export"); } $arrTotal[$fName] = $total; $arrTotalMessage[$fName] = $totalMess; } } ExportExcelTotals($arrTotal, $arrTotalMessage, ++$iNumberOfRows, $objPHPExcel); $extExcel = ".xlsx"; $formatExcel = "Excel2007"; if (@$_REQUEST["type"] == "excel5") { $formatExcel = "Excel5"; $extExcel = ".xls"; } ExportExcelSave(GoodFieldName($pageObj->tName) . $extExcel, $formatExcel, $objPHPExcel); }
/** * Build and shows totals info on page * * @param array $totals info abount totals */ function buildTotals(&$totals) { if (count($this->totalsFields)) { // process totals $this->xt->assign("totals_row", true); $totals_records = array("data" => array()); for ($j = 0; $j < $this->colsOnPage; $j++) { $record = array(); if ($j == 0) { for ($i = 0; $i < count($this->totalsFields); $i++) { // show totals $total = GetTotals($this->totalsFields[$i]['fName'], $totals[$this->totalsFields[$i]['fName']], $this->totalsFields[$i]['totalsType'], $this->totalsFields[$i]['numRows'], $this->totalsFields[$i]['viewFormat'], PAGE_LIST); $total = "<span id=\"total" . $this->id . "_" . GoodFieldName($this->totalsFields[$i]['fName']) . "\">" . $total . "</span>"; $this->xt->assign(GoodFieldName($this->totalsFields[$i]['fName']) . "_total", $total); $record[GoodFieldName($this->totalsFields[$i]['fName']) . "_showtotal"] = true; $record[GoodFieldName($this->totalsFields[$i]['fName']) . "_class"] .= $this->fieldClass($this->totalsFields[$i]['fName']); } } if ($j < $this->colsOnPage - 1) { $record["endrecordtotals_block"] = true; } $totals_records["data"][] = $record; } $this->xt->assignbyref("totals_record", $totals_records); if (!$this->rowsFound) { $this->xt->assign("totals_attr", "style='display:none;'"); } } }
/** * @param Mixed rs * @param Number nPageSize */ protected function WriteTableData($rs, $nPageSize) { $exportFields = $this->pSet->getExportFields(); $totalFieldsData = $this->pSet->getTotalsFields(); if ($this->eventsObject->exists("ListFetchArray")) { $row = $this->eventsObject->ListFetchArray($rs, $this); } else { $row = $this->cipherer->DecryptFetchedArray($this->connection->fetch_array($rs)); } // write header echo "<tr>"; if ($_REQUEST["type"] == "excel") { foreach ($exportFields as $field) { echo '<td style="width: 100" x:str>' . PrepareForExcel($this->pSet->label($field)) . '</td>'; } } else { foreach ($exportFields as $field) { echo "<td>" . $this->pSet->label($field) . "</td>"; } } echo "</tr>"; $totals = array(); $totalsFields = array(); foreach ($totalFieldsData as $data) { if (!in_array($data["fName"], $exportFields)) { continue; } $totals[$data["fName"]] = array("value" => 0, "numRows" => 0); $totalsFields[] = array('fName' => $data["fName"], 'totalsType' => $data["totalsType"], 'viewFormat' => $this->pSet->getViewFormat($data["fName"])); } // write data rows $iNumberOfRows = 0; $this->viewControls->forExport = "export"; while ((!$nPageSize || $iNumberOfRows < $nPageSize) && $row) { countTotals($totals, $totalsFields, $row); $values = array(); foreach ($exportFields as $field) { $fType = $this->pSet->getFieldType($field); if (IsBinaryType($fType)) { $values[$field] = "código binario demasiado grande – no puede ser desplegado"; } else { $values[$field] = $this->getViewControl($field)->getExportValue($row, ""); } } $eventRes = true; if ($this->eventsObject->exists('BeforeOut')) { $eventRes = $this->eventsObject->BeforeOut($row, $values, $this); } if ($eventRes) { $iNumberOfRows++; echo "<tr>"; foreach ($exportFields as $field) { $fType = $this->pSet->getFieldType($field); if (IsCharType($fType)) { if ($_REQUEST["type"] == "excel") { echo '<td x:str>'; } else { echo '<td>'; } } else { echo '<td>'; } $editFormat = $this->pSet->getEditFormat($field); if ($editFormat == EDIT_FORMAT_LOOKUP_WIZARD) { if ($this->pSet->NeedEncode($field)) { if ($_REQUEST["type"] == "excel") { echo PrepareForExcel($values[$field]); } else { echo $values[$field]; } } else { echo $values[$field]; } } elseif (IsBinaryType($fType)) { echo $values[$field]; } else { if ($editFormat == FORMAT_CUSTOM || $this->pSet->isUseRTE($field)) { echo $values[$field]; } elseif (NeedQuotes($field)) { if ($_REQUEST["type"] == "excel") { echo PrepareForExcel($values[$field]); } else { echo $values[$field]; } } else { echo $values[$field]; } } echo '</td>'; } echo "</tr>"; } if ($this->eventsObject->exists("ListFetchArray")) { $row = $this->eventsObject->ListFetchArray($rs, $this); } else { $row = $this->cipherer->DecryptFetchedArray($this->connection->fetch_array($rs)); } } if (count($totalFieldsData)) { echo "<tr>"; foreach ($totalFieldsData as $data) { if (!in_array($data["fName"], $exportFields)) { continue; } echo "<td>"; if (strlen($data["totalsType"])) { if ($data["totalsType"] == "COUNT") { echo "Contar" . ": "; } elseif ($data["totalsType"] == "TOTAL") { echo "Total" . ": "; } elseif ($data["totalsType"] == "AVERAGE") { echo "Promedio" . ": "; } echo runner_htmlspecialchars(GetTotals($data["fName"], $totals[$data["fName"]]["value"], $data["totalsType"], $totals[$data["fName"]]["numRows"], $this->pSet->getViewFormat($data["fName"]), PAGE_EXPORT)); } echo "</td>"; } echo "</tr>"; } }
protected function showTotals() { if ($this->totalsFields) { return; } $record = array(); $this->pageBody["totals_record"] = true; foreach ($this->totalsFields as $tf) { $total = GetTotals($tf["fName"], $this->totals[$tf["fName"]]["value"], $tf["totalsType"], $totals[$tf["fName"]]["numRows"], $tf["viewFormat"], PAGE_PRINT); $this->pageBody[GoodFieldName($this->totalsFields[$i]['fName']) . "_total"] = $total; $record[GoodFieldName($this->totalsFields[$i]['fName']) . "_showtotal"] = true; } $this->pageBody["totals_row"] = array("data" => array(0 => $record)); }
function ExportToExcel() { global $rs, $nPageSize, $strTableName, $conn, $eventObj; if ($eventObj->exists("ListFetchArray")) { $row = $eventObj->ListFetchArray($rs); } else { $row = db_fetch_array($rs); } // if(!$row) // return; $arrLabel = array(); $arrColumnWidth = array(); $arrTotal = array(); $arrTotalMessage = array(); $totals = array(); $arrFields = array(); $arrTmpTotal = array(); $arrFields = GetFieldsList($strTableName); $arrTmpTotal = GetTableData($strTableName, ".totalsFields", array()); foreach ($arrFields as $value) { $arrLabel[$value] = label($value, $strTableName); $arrColumnWidth[$value] = 10; $totals[$value] = 0; $totalsType = ""; foreach ($arrTmpTotal as $tvalue) { if ($tvalue["fName"] == $value) { $totalsType = $tvalue["totalsType"]; } } $totalsFields[] = array('fName' => $value, 'totalsType' => $totalsType, 'viewFormat' => ViewFormat($value, $strTableName)); } // write data rows $iNumberOfRows = 0; $objPHPExcel = ExportExcelInit($arrLabel, $arrColumnWidth); while ((!$nPageSize || $iNumberOfRows < $nPageSize) && $row) { countTotals($totals, $totalsFields, $row); $values = array(); $arrData = array(); $arrDataType = array(); foreach ($arrFields as $value) { if (GetEditFormat($value, $strTableName) == EDIT_FORMAT_LOOKUP_WIZARD || GetEditFormat($value, $strTableName) == EDIT_FORMAT_RADIO) { $values[$value] = ""; if (strlen($row[$value])) { $values[$value] = DisplayLookupWizard($value, $row[$value], $row, "", MODE_EXPORT); } } elseif (IsBinaryType(GetFieldType($value, $strTableName))) { $values[$value] = $row[$value]; } else { if (ViewFormat($value, $strTableName) != FORMAT_FILE_IMAGE && ViewFormat($value, $strTableName) != FORMAT_FILE && ViewFormat($value, $strTableName) != FORMAT_HYPERLINK && ViewFormat($value, $strTableName) != FORMAT_EMAILHYPERLINK && ViewFormat($value, $strTableName) != FORMAT_CHECKBOX) { $format = ViewFormat($value, $strTableName); } else { $format = FORMAT_NONE; } $values[$value] = GetData($row, $value, $format); } } $eventRes = true; if ($eventObj->exists('BeforeOut')) { $eventRes = $eventObj->BeforeOut($row, $values, $arrColumnWidth, $iNumberOfRows + 1, $objPHPExcel); } if ($eventRes) { $iNumberOfRows++; $i = 0; foreach ($arrFields as $value) { if (IsBinaryType(GetFieldType($value, $strTableName))) { $arrDataType[$value] = "binary"; } elseif (ViewFormat($value, $strTableName) == FORMAT_FILE_IMAGE) { $arrDataType[$value] = "file"; } elseif (ViewFormat($value, $strTableName) == FORMAT_DATE_SHORT || ViewFormat($value, $strTableName) == FORMAT_DATE_LONG || ViewFormat($value, $strTableName) == FORMAT_DATE_TIME) { $arrDataType[$value] = "date"; } else { $arrDataType[$value] = ""; } $arrData[$value] = $values[$value]; } ExportExcelRecord($arrData, $arrDataType, $iNumberOfRows, $objPHPExcel); } if ($eventObj->exists("ListFetchArray")) { $row = $eventObj->ListFetchArray($rs); } else { $row = db_fetch_array($rs); } } if (count($arrTmpTotal)) { foreach ($arrFields as $fName) { $value = array(); foreach ($arrTmpTotal as $tvalue) { if ($tvalue["fName"] == $fName) { $value = $tvalue; } } $total = ""; $totalMess = ""; if ($value["totalsType"]) { if ($value["totalsType"] == "COUNT") { $totalMess = "Count" . ": "; } elseif ($value["totalsType"] == "TOTAL") { $totalMess = "Total" . ": "; } elseif ($value["totalsType"] == "AVERAGE") { $totalMess = "Average" . ": "; } $total = GetTotals($fName, $totals[$fName], $value["totalsType"], $iNumberOfRows, $value["viewFormat"]); } $arrTotal[$fName] = $total; $arrTotalMessage[$fName] = $totalMess; } } ExportExcelTotals($arrTotal, $arrTotalMessage, ++$iNumberOfRows, $objPHPExcel); $formatExcel = "Excel2007"; $extExcel = ".xlsx"; if (@$_REQUEST["type"] == "excel5") { $formatExcel = "Excel5"; $extExcel = ".xls"; } ExportExcelSave(GoodFieldName($strTableName) . $extExcel, $formatExcel, $objPHPExcel); }