registerTask( 'ws' , 'previewWorksheet' ); $this->registerTask( 'popup' , 'previewPopup' ); $_wsArr = array(); $_formulas = false; } // Build popup preview page function previewPopup() { global $mainframe; $wb_id = Sql2excelParms::get_parm_value('id', 'int', 0); $wbParms = Sql2excelControllerDownload::getWorkbookParms($wb_id,1); $cmpparams = Sql2excelParms::getParms(); $wbRefresh = ''; if ( count($wbParms) ) { echo "\n"; echo "\n"; echo '\n"; echo "\n"; echo '\n"; echo '\n"; $jaCSS = JPATH_SITE.DS.'templates'.DS.'ja_purity'.DS.'css'.DS.'template.css'; if ( file_exists($jaCSS) ) { echo '\n"; } echo '\n"; echo '\n"; echo '\n"; echo ''; echo ''; $wbParms = $wbParms[0]; echo '

' . $wbParms->link_title . '

'; // User Parameters $wbParmsHTML = ''; $wbParmVars = ''; $wbParmVarsAdd = ''; $wbParmvalidate = ''; $wbHiddenParms = ''; $nrWbParms = 0; $wbValidate = ''; $wbMultiTicks = ''; $wbParameters = Sql2excelCommon::getWorkbookParms($wb_id); if ( is_array($wbParameters) ) { $wbParmsHTML = $wbParameters[0]; $wbParmVars = $wbParameters[1]; $wbParmVarsAdd = $wbParameters[2]; $wbHiddenParms = $wbParameters[3]; $nrWbParms = $wbParameters[4]; $wbRefresh = $wbParameters[5]; $wbValidate = $wbParameters[6]; $wbMultiTicks = $wbParameters[7]; } echo $wbParmsHTML; $wsParms = Sql2excelControllerDownload::getWorksSheetParms($wb_id); $nrWorksheets = count($wsParms); echo '
'; echo ''; echo ''; $i=1; foreach ($wsParms as $ws ) { if ( $i == 1 ) { $id = ' id="sheet1" '; $ws1ID = $ws->ws_id; } else { $id=''; } echo ' '; $i++; } echo ''; echo ''; echo ''; $cspan = $nrWorksheets + 1; echo ''; echo ''; echo '
 ' . str_replace(' ', ' ', $ws->sheetname) . ' 
'; echo "\n"; echo "\n"; // Show Download Button? $action = JText::_( 'Download'); $what = JText::_('Spreadsheet'); $sheet = 0; $dlformat = 1; if ( isset($wbParms->dlformat) ) { $dlformat = $wbParms->dlformat; } if ( $dlformat == 3 || ( $dlformat == 1 && Sql2excelParms::get($cmpparams,'dlformat', '2') == 3 ) ) { $what = JText::_('CSV'); $sheet = 1; } elseif ( $dlformat == 4 || ( $dlformat == 1 && Sql2excelParms::get($cmpparams,'dlformat', '2') == 4 ) ) { $what = JText::_(''); $action = JText::_('View Full Report'); $sheet = 1; } // Show Download Button? $wbDLbtn = $wbParms->preview_dl_btn; if ( $wbDLbtn == 'Show' || ( $wbDLbtn == 'Global' && Sql2excelParms::get($cmpparams,'previewdlbutton', 1) == 1 ) ) { $wbRefresh .= "\n"; } echo "

\n"; echo "

\n"; echo "
\n"; echo $wbRefresh; echo "
\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo $wbHiddenParms; echo "
\n"; echo "
\n"; echo "

\n"; echo ''; echo ''; } else { JError::raiseError( 500, JText::_( 'Workbook not found' ) ); } exit; } // Return Ajax data for a worksheet function previewWorksheet() { $useCache = 1; global $mainframe; $id = Sql2excelParms::get_parm_value('wbid', 'int', 0); $wb_id = (int) $id; $id = Sql2excelParms::get_parm_value('id', 'int', 0); $ws_id = (int) $id; $cbaid = Sql2excelParms::get_parm_value('_cba_request_id', 'int', 0); // Workbook Parameters $wbParms = Sql2excelControllerDownload::getWorkbookParms($wb_id,1); if ( count($wbParms) ) { //$cmpParms = &$mainframe->getParams(); $cmpParms = Sql2excelParms::getParms(); $substParms = Sql2excelControllerDownload::getSubstParms(); $wsParms = Sql2excelControllerDownload::getWorksSheetParms($wb_id, $ws_id); $extraParms = array(); $substWBParms = Sql2excelParms::get($cmpParms,'subst_wbparms', '1'); // Workbook Parameters (runtime parms) ? $wbParameters = $wbParms[0]->parms; if ( $wbParameters != '' ) { $wbParametersArr = explode('~@~',$wbParameters); $i=1; foreach ( $wbParametersArr as $parm ) { $parmTokens = explode(',',$parm); if ( count($parmTokens) >= 4 ) { $parmID = 'parm' . $i; $parmName = $parmTokens[0]; $parmVar = $parmTokens[1]; $parmType = $parmTokens[2]; $parmValue = $parmTokens[3]; $parmDB = 1; if ( isset($parmTokens[4]) ) { $parmDB = $parmTokens[4]; } $parmVis = 1; if ( isset($parmTokens[5]) ) { $parmVis = $parmTokens[5]; } if ( $parmType == "Integer" || $parmType == "UnsignedInteger" ) { $parmValue = Sql2excelParms::get_parm_value($parmID, 'int', $parmValue); } elseif ( $parmType == "Real" || $parmType == "UnsignedRealReal") { $parmValue = Sql2excelParms::get_parm_value($parmID, 'float', $parmValue); } elseif ( $parmType == "AlphaNum" ) { $parmValue = Sql2excelParms::get_parm_value($parmID, 'alnum', $parmValue); } elseif ( $parmType == "Username" ) { $parmValue = Sql2excelParms::get_parm_value($parmID, 'username', $parmValue); } elseif ( $parmType == "List" || $parmType == "ListMultiNum" || $parmType == "ListMultiStr") { $parmList = Sql2excelParms::get_parm_value($parmID, 'string', $parmValue); if ( $wbParms[0]->parms_prompt == 0 ) { if ( $parmList != '' ) { $parmList = str_replace('~COMMA~',',',$parmList); $parmList = explode('~NL~',$parmList); $defaultValue = explode(',',$parmList[0]); $defaultValue = $defaultValue[0]; $multiStr = ''; foreach ( $parmList as $lisval ) { $tokens = explode(',',$lisval); if ( sizeof($tokens) > 2 ) { if ( strpos($parmType,'Multi') > 0 ) { if ( $parmType == "ListMultiNum" ) { $pVal = $tokens[0]; } else { $pVal = "'" . $tokens[0] . "'"; } if ( $multiStr == '' ) { $multiStr = $pVal; } else { $multiStr .= ',' . $pVal; } } else { $defaultValue = $tokens[0]; } } } if ( strpos($parmType,'Multi') > 0 && $multiStr) { $parmValue = $multiStr; } else { $parmValue = $defaultValue; } } else { $parmValue = ''; } } else { $parmValue = $parmList; } } elseif ( $parmType == "ListSQL" || $parmType == 'ListSQLMultiNum' || $parmType == 'ListSQLMultiStr' ) { $query = Sql2excelParms::get_parm_value($parmID, 'string', $parmValue); if ( $wbParms[0]->parms_prompt == 0 ) { // Parameter not prompted => getting SQL query passed $query = str_replace('~COMMA~',',',$query); $query = str_replace('~NL~',"\n",$query); $query = str_replace('~NL~',"\n",$query); $query = $this->utf8_strrev($query); if ( $substWBParms ) { $query = writeExcel::replace_vars($query, $substParms,$extraParms); } // Get Database Connection $db = null; $dbType = 1; if ( $parmDB == 1 ) { $db = & JFactory::getDBO(); } else { $jdb = & JFactory::getDBO(); $jdb->setQuery( 'SELECT * FROM #__sql2excel_databases WHERE ID=' . $parmDB ); $dbInfo = $jdb->loadObject(); if ( $dbInfo ) { $db = writeExcel::getDB($dbInfo); $dbType=$dbInfo->db_type; } } if ( $db ) { $rows = writeExcel::getResults($db, $query, $cmpParms, $dbType); if ( is_Array($rows) ) { $colNames = writeExcel::getColumnNames($rows); $firstRow = $rows[0]; if ( strpos($parmType,'Multi') > 0 ) { if ( count($colNames) > 2 ) { $multiStr = ''; foreach ( $rows as $row ) { if ( $row->$colNames[2] != '' ) { if ( $parmType == 'ListSQLMultiStr' ) { $pVal = "'" . $row->$colNames[2] . "'"; } else { $pVal = $row->$colNames[2]; } if ( $multiStr == '' ) { $multiStr = $pVal; } else { $multiStr .= ',' . $pVal; } } } if ( $multiStr != '' ) { $parmValue = $multiStr; } else { $parmValue = $firstRow->$colNames[0]; if ( $parmType == 'ListSQLMultiStr' ) { $parmValue = "'" . $parmValue . "'"; } } } else { $parmValue = $firstRow->$colNames[0]; if ( $parmType == 'ListSQLMultiStr' ) { $parmValue = "'" . $parmValue . "'"; } } } else { if ( count($colNames) > 2 ) { //$parmValue = $firstRow[2]; $parmValue = $firstRow->$colNames[2]; } else { //$parmValue = $firstRow[0]; $parmValue = $firstRow->$colNames[0]; } } } else { $parmValue = ''; } } else { $parmValue = JText::_('ERROR: Workbook Parameter') . ' ' . $parmVar . ' - ' . JText::_('Database Connection Error!'); } // Save this parameter for further substitutions $extraParms[$parmVar]=$parmValue; } else { // Parameter was prompted => getting value directly $parmValue = $query; } } else { $parmValue = Sql2excelParms::get_parm_value($parmID, 'string', $parmValue); } if ( is_string($parmValue) && $substWBParms ) { $parmValue = writeExcel::replace_vars($parmValue, $substParms,$extraParms); } $wbP[$parmVar]=$parmValue; // Save this parameter for further substitutions $extraParms[$parmVar]=$parmValue; $i++; } } if ( $i > 1 ) { $substParms = array_merge($substParms,$wbP); // Don't use cache for Workbooks with parameters $useCache = 0; } } if ( count($wsParms) == 1 ) { // Use Cache ? //$cacheEnabled = $cmpParms->get( 'cache_enabled', 0 ); $cacheEnabled = Sql2excelParms::get($cmpParms,'cache_enabled', 0); //$cacheDir = $cmpParms->get( 'cache_dir', JPATH_COMPONENT.DS.'cache'.DS ); $cacheDir = Sql2excelParms::get($cmpParms,'cache_dir', JPATH_COMPONENT.DS.'cache'.DS); //$cacheTime = $cmpParms->get( 'cache_time', 30 ); $cacheTime = Sql2excelParms::get($cmpParms,'cache_time', 30); $wbCache = $wbParms[0]->cache; $wsData = ''; if ( substr($cacheDir,strlen($cacheDir)-1,1) != DS ) { $cacheDir .= DS; } if ( ( $useCache && ($cacheEnabled && $wbCache == 'Global') ) || ( $useCache && $wbCache == 'Yes' ) ) { if ( file_exists($cacheDir) ) { $cacheFN = $cacheDir . 'preview_' . $wb_id . '_' . $ws_id . '.cache'; if ( file_exists($cacheFN) ) { $fileModified = filemtime($cacheFN); $age = time() - $fileModified; $minutesOld = $age / 60; if ( $cacheTime >= $minutesOld ) { // Server from cache $wsData = file_get_contents($cacheFN); } } } } if ( $wsData == '' ) { $wsParms = $wsParms[0]; $wsData = $this->writeWorksheet($wbParms,$wsParms,$cmpParms,$substParms); if ( ( $useCache && ($cacheEnabled && $wbCache == 'Global') ) || ( $useCache && $wbCache == 'Yes' ) ) { if ( file_exists($cacheDir) ) { // Write cache file $fh = fopen($cacheFN, 'w') or die("Can't write to preview cache file"); fwrite($fh, $wsData); fclose($fh); } } } /* $wsData = str_replace("\r\n",'', $wsData); $wsData = str_replace("\n",'', $wsData); $wsData = str_replace("\\","\\\\", $wsData); $wsData = str_replace('"','\"', $wsData); */ //echo '_cba.ready ( ' . (int) $cbaid . ', { "code" : "' . $wsData . '" } );'; echo $wsData; } else { //echo '_cba.ready ( ' . (int) $cbaid . ', { "code" : "' . JText::_( 'ERROR : Worksheet not found' ) . '" } );'; echo JText::_( 'ERROR : Worksheet not found' ); } } else { //echo '_cba.ready ( ' . (int) $cbaid . ', { "code" : "' . JText::_( 'ERROR : Workbook not found' ) . '" } );'; echo JText::_( 'ERROR : Workbook not found' ); } exit; } function utf8_strrev($str, $reverse_numbers = true){ $pattern = $reverse_numbers ? '/./us' : '/(\d+)?./us'; preg_match_all($pattern, $str, $ar); return join('',array_reverse($ar[0])); } function writeWorksheet($wbParms,$ws,$cmpParms,$substParms) { $downloadLabel = JText::_( 'PLEASE_DL_FULL_REPORT'); $dlformat = 1; if ( isset($wbParms[0]->dlformat) ) { $dlformat = $wbParms[0]->dlformat; } if ( $dlformat == 3 || ( $dlformat == 1 && Sql2excelParms::get($cmpParms,'dlformat', '2') == 3 ) ) { $downloadLabel = JText::_( 'PLEASE_DL_CVS_FULL_REPORT'); } elseif ( $dlformat == 4 || ( $dlformat == 1 && Sql2excelParms::get($cmpParms,'dlformat', '2') == 4 ) ) { $downloadLabel = JText::_( 'PLEASE_DL_HTM_FULL_REPORT'); } $output = ''; $this->_formulas = false; //$maxRows = $cmpParms->get( 'previewmaxrows', '10' ); $maxRows = Sql2excelParms::get($cmpParms,'previewmaxrows', '10'); if ( $ws->preview_rows > 0 ) { $maxRows = $ws->preview_rows; } //$showFormulas = $cmpParms->get( 'formulas_in_preview', 'Label' ); $showFormulas = Sql2excelParms::get($cmpParms,'formulas_in_preview', 'Label'); if ( $ws->preview_formulas != 'Global' ) { $showFormulas = $ws->preview_formulas; } $formulaLabel = JText::_('#FORMULA'); //showExtraCells = $cmpParms->get( 'extracells_in_preview', 'Show' ); $showExtraCells = Sql2excelParms::get($cmpParms,'extracells_in_preview', 'Show'); $pEc = $showExtraCells; if ( $ws->preview_extracells != 'Global' ) { $showExtraCells = $ws->preview_extracells; } //$this->_formulas = $this->contains_formulas($ws); $hideColumns = $ws->preview_hidecols; $hideColumns = explode(',',trim($hideColumns)); $db = & JFactory::getDBO(); $wbParms = $wbParms[0]; $extraParms = array(); // Write Header $fileName = $wbParms->filename; if ( trim($fileName) == '' ) { $fileName = 'download.xls'; } $extraParms['SQL2EXCEL_WB_FN'] = $fileName; $extraParms['SQL2EXCEL_WB_LINK'] = $wbParms->link_title; $extraParms['SQL2EXCEL_WB_DLCNT'] = $wbParms->count; $sheetName = $ws->sheetname; if ( trim($sheetName) == '' ) { $sheetName = 'Sheet [N]'; } $extraParms['SQL2EXCEL_WS_SN'] = $sheetName; $extraParms['SQL2EXCEL_WS_DLCNT'] = $ws->count; $query = $ws->query; $extraParms['SQL2EXCEL_WS_SQL_RAW'] = $query; // Substitute variables in SQL query? $substSQL = Sql2excelParms::get($cmpParms,'subst_sql', '1'); if ( $substSQL ) { $query = writeExcel::replace_vars($query, $substParms); } $extraParms['SQL2EXCEL_WS_SQL'] = $query; $formulas = explode(',', $ws->formulas ); // Get Database Connection unset($db); $db = writeExcel::getDB($ws); // Run query! if ( $db ) { $rows = writeExcel::getResults($db, $query, $cmpParms, $ws->db_type); } else { $rows = JText::_( 'DB_CONNECT_ERROR'); } if ( is_array($rows) ) { $extraParms['SQL2EXCEL_WS_ROWS'] = count($rows) + 1; // Column titles $colNames = writeExcel::getColumnNames($rows); //Number of Columns in user query (exclude JoomFish fields if any) $nrCols = writeExcel::getColumnCount($colNames, $query); // Add Header, if specified $substHeadFoot = Sql2excelParms::get($cmpParms,'subst_head_footer', '1'); $currRow = 0; $header = $ws->header; if ( $header != '' ) { $headertextArr = explode("\n",$header); if ( is_array($headertextArr) ) { foreach ($headertextArr as $headerrow) { $headerrow = trim($headerrow); if ( $substHeadFoot ) { $headerrow = writeExcel::replace_vars($headerrow, $substParms, $extraParms ); } $output .= $this->writeCell($headerrow, '', $currRow, 0); $currRow++; } } } $headerRows = $currRow; // Add column titles $actualCol=0; for ($i=0; $i<$nrCols; $i++) { $currCol = $i+1; if ( !in_array($currCol,$hideColumns) && (!in_array($currCol,$formulas) || ( in_array($currCol,$formulas) && $showFormulas != 'Hide' )) ) { $output .= $this->writeTH($currRow, $actualCol, $colNames[$i]); $actualCol++; } } $colHeadRow = $currRow; // Add all the data $currRow++; $cnt=1; $mindatarow = $currRow + 1; $maxdatarow = $currRow + count($rows); foreach ( $rows as $row ) { if ( $cnt <= $maxRows ) { $actualCol=0; for ( $i=0; $i<$nrCols; $i++) { $currCol = $i+1; if ( !in_array($currCol,$hideColumns) && (!in_array($currCol,$formulas) || ( in_array($currCol,$formulas) && $showFormulas != 'Hide' )) ) { $output .= $this->writeCell($row->$colNames[$i],'',$currRow, $actualCol, $formulas, $showFormulas, $formulaLabel,$mindatarow,$maxdatarow); $actualCol++; } } $currRow++; } $cnt++; } // Add Extra Cells if specified if ( $showExtraCells == 'Show' ) { $this->writeExtraCells($ws, $maxRows+$headerRows, $showFormulas, $formulaLabel, $cmpParms, $formulas, $substSQL, $substParms); } // Add Footer, if specified $footer = $ws->footer; $footertextArr = explode("\n",$footer); $firstFooterRow = $currRow; if ( is_array($footertextArr) ) { foreach ($footertextArr as $footerrow) { $footerrow = trim($footerrow); if ( $substHeadFoot ) { $footerrow = writeExcel::replace_vars($footerrow, $substParms, $extraParms ); } $output .= $this->writeCell($footerrow, '', $currRow, 0); $currRow++; } } // Generate output from the table in memory $output = $this->formatOutput($maxRows, $colHeadRow, $headerRows, $firstFooterRow, $nrCols); // Add truncation / formulas / hidden columns message, if applicable $notes = ''; $hiddenStuff = 0; if ( count($rows) > $maxRows ) { $notes .= '
  • ' . JText::_( 'Preview showing ') . $maxRows . ' ' . JText::_( 'of') . ' ' . count($rows) . ' ' . JText::_( 'records') . '
  • '; } else { $notes .= '
  • ' . JText::_( 'Total Records Found') . ' = ' . count($rows) . '
  • '; } if ( $this->_formulas && ( $showFormulas == 'Show' || $showFormulas == 'Label') ) { $notes .= '
  • ' . JText::_('FORMULAS_NOT_IN_PREVIEW') . '.
  • '; } if ( $this->_formulas && $showFormulas == 'Hide' ) { $notes .= '
  • ' . JText::_('FORMULAS_HIDDEN_IN_PREVIEW') . '.
  • '; } if ( count($hideColumns) > 1 || $hideColumns[0] > 0 ) { $notes .= '
  • ' . JText::_('COLUMNS_HIDDEN_IN_PREVIEW') . '.
  • '; $hiddenStuff = 1; } if ( $showExtraCells == 'Hide' && $ws->extracells != '' ) { $notes .= '
  • ' . JText::_('EXTRACELLS_HIDDEN_IN_PREVIEW') . '.
  • '; $hiddenStuff = 1; } $output .= '


    ' . JText::_( 'Notes') . ':

    '; $wbDLbtn = $wbParms->preview_dl_btn; $dlBtn = 0; if ( $wbDLbtn == 'Show' || ( $wbDLbtn == 'Global' && Sql2excelParms::get($cmpParms,'previewdlbutton', 1) ) ) { $dlBtn=1; } if ( $dlBtn && ( $this->_formulas || count($rows) > $maxRows || $hiddenStuff) ) { $output .= '

    ' . $downloadLabel . '

    '; } } elseif ( $rows == '' ) { // Empty recordset. $errMsg = trim($ws->error_norecords); if (! $errMsg) { $errMsg = JText::_( 'No records found' ); } $output .= '' . $errMsg . ''; $output .= $this->tableEnd(); } elseif ( $rows != '' && is_string($rows) && Sql2excelParms::get($cmpParms,'show_sql_errors', 1) ) { $errMsg = explode("\n", $rows); foreach ( $errMsg as $row ) { $output .= $this->newRow(); $row = trim($row); $output .= $this->writeCell($row); $output .= $this->endRow(); } $output .= $this->tableEnd(); } return $output; } function newRow($extra='') { return ''; } function endRow() { return ''; } function tableEnd() { $retStr = ''; return $retStr; } function writeCell($str, $extra='', $row=0, $col=0, $formulas=0, $showFormulas='Label', $formulaLabel='#FORMULA',$mindatarow=0,$maxdatarow=0) { if ( substr(strtolower($str),0,7) == 'http://' ) { $str = '' . $str . ''; } elseif ( substr(trim($str),0,1) == '=' || substr(trim($str),0,1) == '@' ) { $colUser = $col+1; $rowUser = $row+1; if ( is_array($formulas) & in_array($colUser, $formulas) ) { // Formula! $this->_formulas = true; if ( $showFormulas == 'Label' ) { // Show Generic #FORMULA Label $str = $formulaLabel; } elseif ( $showFormulas == 'Show' ) { // Show Full Formula Syntax // Parse and replace Row and Col ID's $str = writeExcel::replace_row_col_ids($str, $rowUser, $colUser, $mindatarow,$maxdatarow); } else { // Hide Formula return; } } } if ( $str == '' ) { $str=' '; } // Add cell to array if ( isset($this->_wsArr[$row]) ) { $currRowArr = $this->_wsArr[$row]; } else { $currRowArr = array(); } $currRowArr[$col] = $str; $this->_wsArr[$row] = $currRowArr; } function writeTH($row, $col, $str, $extra='') { // Add cell to array if ( isset($this->_wsArr[$row]) ) { $currRowArr = $this->_wsArr[$row]; } else { $currRowArr = array(); } $currRowArr[$col] = $str; $this->_wsArr[$row] = $currRowArr; } function writeExtraCells($ws, $maxRow, $showFormulas, $formulaLabel, $cmpParms, $formulas, $substSQL, $substParms) { // Extra Cells? $extraCells = explode("\n",$ws->extracells); foreach ( $extraCells as $row ) { $cellInfo = explode(',',$row); if ( count($cellInfo) > 6 ) { $cellData = trim($cellInfo[3]); $cellData = str_replace('@~@',',',$cellData); $row = (int) $cellInfo[1]-1; $col = (int) $cellInfo[2]-1; if ( $row < $maxRow ) { if ( $cellInfo[0] == 2 || $cellInfo[0] == 4 ) { // Formula $colUser = $col+1; $this->writeCell($cellData, '', $row, $col, array($colUser), $showFormulas, $formulaLabel); } elseif ( $cellInfo[0] == 6 ) { // SQL query data $extraDB = 1; if ( isset($cellInfo[7]) ) { $extraDB = $cellInfo[7]; } $query = strrev($cellData); if ( $substSQL ) { $query = writeExcel::replace_vars($query, $substParms); } $this->writeExtraSQL($query, $extraDB, $maxRow, $row, $col, $formulas, $showFormulas, $formulaLabel, $cmpParms); } else { // Text $this->writeCell($cellData, '', $row, $col); } } } } } function writeExtraSQL($query, $dbID, $maxRow, $row, $col, $formulas, $showFormulas, $formulaLabel, $cmpParms) { $jdb = & JFactory::getDBO(); $jdb->setQuery("SELECT * FROM #__sql2excel_databases WHERE ID=" . $dbID); $dbInfo = $jdb->loadObject(); if ( $dbInfo ) { $cellDB = writeExcel::getDB($dbInfo); if ( $cellDB ) { $rows = writeExcel::getResults($cellDB, $query, $cmpParms, $dbInfo->db_type); if ( is_array($rows) ) { // Column titles $colNames = writeExcel::getColumnNames($rows); //Number of Columns in user query (exclude JoomFish fields if any) $nrCols = writeExcel::getColumnCount($colNames, $query); $currRow = $row; foreach ( $rows as $row ) { if ( $currRow <= $maxRow ) { for ( $i=0; $i<$nrCols; $i++ ) { $this->writeCell($row->$colNames[$i], '', $currRow, $col+$i, $formulas); } } $currRow++; } } } else { $this->writeCell(JText::_('DB_CONNECT_ERROR'), '', $row, $col); } } } function formatOutput($maxRows, $colHeadRow, $headerRows, $firstFooterRow, $nrDataCols) { // Get max row number $rowMax = max(array_keys($this->_wsArr)); // Get max column number $maxCol = 0; foreach ( $this->_wsArr as $row ) { $col = max(array_keys($row)); if ( $col > $maxCol ) { $maxCol = $col; } } // Max Data Column Number //$nrDataCols--; $nrDataCols = $maxCol; $retStr = ''; $colSpan = $maxCol+1; // Add rows for ( $idx=0; $idx<=$rowMax; $idx++ ) { if ( isset($this->_wsArr[$idx]) ) { $row = $this->_wsArr[$idx]; } else { $row = array(); } $retStr .= ''; $maxRowCol = max(array_keys($row)); //$retStr .= ''; for ( $i=0; $i<=$maxRowCol; $i++ ) { if ( isset($row[$i]) ) { $str = $row[$i]; } else { $str=' '; } if ( $idx == $colHeadRow ) { // Data Column Header // First Column? $extra = ''; if ( $i == 0 ) { $extra .= 'border-left: 1px solid #000;'; } $extra = ' style="' . $extra . '"'; if ( $str != '' ) { $retStr .= ''. $str . ''; } else { $retStr .= ''; } if ( $i == $maxRowCol && $maxCol > $i ) { $rcSpan = $colSpan - $i; $retStr .= ''; } } else if ( ($idx < $headerRows || $idx >= $firstFooterRow) && $i == $maxRowCol ) { $rcSpan = $colSpan - $i; if ( $rcSpan > 1 ) { $retStr .= ''; } else { $retStr .= ''; } } else { // Data Rows or Multiple Cell Header / Footer Rows $extra = ''; // First Column and inside Data? if ( $i == 0 && $idx > $headerRows && $idx < $firstFooterRow ) { $extra .= 'border-left: 1px solid #000;'; } // Last Column? if ( $i == $nrDataCols ) { $extra .= 'border-right: 1px solid #000;'; } // Last Data Row? if ( $idx == $firstFooterRow - 1 ) { $extra .= 'border-bottom: 1px solid #000;'; } $extra = ' style="' . $extra . '"'; $retStr .= ''; if ( $i == $maxRowCol && $i < $maxCol ) { $rcSpan = $colSpan - $i; $retStr .= ''; } } } $retStr .= ''; } $retStr .= '
    '. $maxRowCol . '  ' . $str . ''. $str . ''. $str . ' 
    '; return $retStr; } function contains_formulas($ws) { if ( $ws->formulas != '' ) { return true; } else { // Check Extra Cells for Formulas $extraCells = explode("\n",$ws->extracells); $formulas = false; foreach ( $extraCells as $row ) { $cellInfo = explode(',',$row); if ( count($cellInfo) > 6 ) { if ( $cellInfo[0] == 2 || $cellInfo[0] == 4 ) { // Formula $formulas = true; } } } return $formulas; } } }