public function actionSave() { $object = new CReport(); $object->setAttributes(CRequest::getArray($object::getClassName())); if ($object->validate()) { $object->save(); if ($this->continueEdit()) { $this->redirect("index.php?action=edit&id=" . $object->getId()); } else { $this->redirect("index.php?action=index"); } return true; } $this->setData("object", $object); $this->renderView("_reports/report/edit.tpl"); }
// add fresh vReports CReport::addFreshDefaultReports($vReports, $ownerId); } } } } // create default reports by user request if ($isPost && !empty($_POST['CREATE_DEFAULT'])) { $dReports = call_user_func(array($helperClassName, 'getDefaultReports')); foreach ($dReports as $moduleVer => $vReports) { CReport::addFreshDefaultReports($vReports, $ownerId); } LocalRedirect($arParams['PATH_TO_REPORT_LIST']); } // main action $arResult['list'] = array(); $result = Bitrix\Report\ReportTable::getList(array('order' => array('ID' => 'ASC'), 'select' => array('ID', 'TITLE', 'DESCRIPTION', 'CREATED_DATE'), 'filter' => array('=CREATED_BY' => $USER->GetID(), '=OWNER_ID' => $ownerId))); while ($row = $result->fetch()) { $arResult['list'][] = $row; } // add default reports always if them isn't present if (empty($arResult['list'])) { $dReports = call_user_func(array($helperClassName, 'getDefaultReports')); foreach ($dReports as $moduleVer => $vReports) { CReport::addFreshDefaultReports($vReports, $ownerId); } LocalRedirect($arParams['PATH_TO_REPORT_LIST']); } global $DB; $arResult['dateFormat'] = $DB->DateFormatToPHP(CSite::GetDateFormat("SHORT")); $this->IncludeComponentTemplate();
if ($log_all) { $date = new w2p_Utilities_Date(); $pdf->ezText("\nAll hours as of " . $date->format($df), 8); } else { $sdate = new w2p_Utilities_Date($log_start_date); $edate = new w2p_Utilities_Date($log_end_date); $pdf->ezText("\nHours from " . $sdate->format($df) . ' to ' . $edate->format($df), 8); } $pdf->selectFont($font_dir . '/Helvetica-Bold.afm'); $pdf->ezText("\n" . $AppUI->_('Overall Report'), 12); foreach ($allpdfdata as $company => $data) { $title = $company; $options = array('showLines' => 1, 'showHeadings' => 0, 'fontSize' => 8, 'rowGap' => 2, 'colGap' => 5, 'xPos' => 50, 'xOrientation' => 'right', 'width' => '500', 'cols' => array(0 => array('justification' => 'left', 'width' => 250), 1 => array('justification' => 'right', 'width' => 120))); $pdf->ezTable($data, null, $title, $options); } $w2pReport = new CReport(); if ($fp = fopen($temp_dir . '/' . $w2pReport->getFilename() . '.pdf', 'wb')) { fwrite($fp, $pdf->ezOutput()); fclose($fp); echo '<a href="' . W2P_BASE_URL . '/files/temp/' . $w2pReport->getFilename() . '.pdf" target="pdf">'; echo $AppUI->_('View PDF File'); echo '</a>'; } else { echo 'Could not open file to save PDF. '; if (!is_writable($temp_dir)) { 'The files/temp directory is not writable. Check your file system permissions.'; } } } echo '</td> </tr>
function groupingReportResultHtml(&$arParams, &$arResult, $level = 0, $arRowSet = array()) { $strHtml = ''; $total = array(); $arViewColumns =& $arResult['viewColumns']; $arData =& $arResult['data']; // static variables static $arGroups = array(); static $arColumns = array(); static $nGroups = 0; static $nColumns = 0; static $arValueTypes = array(); static $marginWidth = 20; // initialize static variables if ($level === 0) { foreach ($arViewColumns as $viewColumnIndex => $viewColumn) { if ($viewColumn['grouping']) { $arGroups[$nGroups++] = $viewColumnIndex; } else { $arColumns[$nColumns++] = $viewColumnIndex; } $arValueTypes[$viewColumnIndex] = getResultColumnDataType($viewColumn); } } $nRows = count($arRowSet); $bUseRowSet = $nRows > 0 ? true : false; if (!$bUseRowSet) { $nRows = count($arData); } if ($nGroups > 0) { // grouping table header if ($level === 0) { $bFirstGroup = true; $strHtml .= "\t" . '<table class="reports-grouping-table" cellpadding=2 cellspacing=0>' . PHP_EOL . "\t\t" . '<thead>' . PHP_EOL; foreach ($arGroups as $groupColumnIndex) { $strHtml .= "\t\t\t" . '<tr class="reports-grouping-table-head-row">' . PHP_EOL . "\t\t\t\t" . '<td>' . htmlspecialcharsbx($arViewColumns[$groupColumnIndex]['humanTitle']) . '</td>' . PHP_EOL; if ($bFirstGroup) { $bFirstGroup = false; foreach ($arColumns as $viewColumnIndex) { $strHtml .= "\t\t\t\t" . '<td style="text-align: center;"'; if ($nGroups > 1) { $strHtml .= ' rowspan="' . htmlspecialcharsbx($nGroups) . '"'; } $strHtml .= ' class="report-grouping-sort-column"'; $strHtml .= ' colId="' . $viewColumnIndex . '" defaultSort="' . $arViewColumns[$viewColumnIndex]['defaultSort'] . '">' . htmlspecialcharsbx($arViewColumns[$viewColumnIndex]['humanTitle']) . '</td>' . PHP_EOL; } } $strHtml .= "\t\t\t" . '</tr>' . PHP_EOL; } $strHtml .= "\t\t" . '</thead>' . PHP_EOL; } if ($nRows > 0) { // table header separator if ($level === 0) { $strHtml .= "\t\t" . '<tbody>' . PHP_EOL . "\t\t\t" . '<tr class="reports-grouping-table-row-separator"><td></td></tr>' . PHP_EOL; } // init total if ($nColumns > 0) { foreach (array_keys($arColumns) as $columnIndex) { $total[$columnIndex] = null; } } if ($level < $nGroups) { // fill group arrays $arGroupValues = array(); $arGroupValuesIndexes = array(); $rowNumber = 0; $groupDataType = $arValueTypes[$arGroups[$level]]; $dataIndex = null; reset($arData); while ($rowNumber++ < $nRows) { // get index if ($bUseRowSet) { list(, $dataIndex) = each($arRowSet); } else { list($dataIndex, ) = each($arData); } // fill index and value of group $arGroupValuesIndexes[] = $dataIndex; $groupValue = $arData[$dataIndex][$arViewColumns[$arGroups[$level]]['resultName']]; if ($groupDataType === 'date' || $groupDataType === 'datetime') { $groupValue = MakeTimeStamp($groupValue, CSite::GetDateFormat('SHORT')); } // magic glue if (is_array($groupValue)) { $groupValue = join(' / ', $groupValue); } $arGroupValues[] = $groupValue; } // determine sort options $groupSortOption = SORT_STRING; $groupSortDirection = SORT_ASC; if (in_array($groupDataType, array('date', 'datetime', 'integer', 'float'))) { $groupSortOption = SORT_NUMERIC; } if ($arGroups[$level] == $arResult['sort_id']) { if ($arResult['sort_type'] != 'ASC') { $groupSortDirection = SORT_DESC; } } // sort group array_multisort($arGroupValues, $groupSortOption, $groupSortDirection, $arGroupValuesIndexes, SORT_NUMERIC, SORT_ASC); // recursive scan $prev = null; $newRowSet = array(); $nGroupValues = count($arGroupValues); $nSubRows = 0; for ($i = 0; $i < $nGroupValues; $i++) { $cur = $arGroupValues[$i]; if ($i == 0) { $prev = $cur; } $bLastValue = $nGroupValues - 1 == $i; if ($cur != $prev || $bLastValue) { $n = $bLastValue && $cur != $prev ? 2 : 1; while ($n-- > 0) { if ($bLastValue && $cur == $prev) { $newRowSet[] = $arGroupValuesIndexes[$i]; } $arGroupingResult = groupingReportResultHtml($arParams, $arResult, $level + 1, $newRowSet); $arSubTotal = $arGroupingResult['total']; $strSubHtml = $arGroupingResult['html']; unset($arGroupingResult); $newRowSet = array(); if (!$bLastValue) { $newRowSet[] = $arGroupValuesIndexes[$i]; } $prev = $cur; // show row $groupValueIndex = $bLastValue && $n === 0 ? $i : $i - 1; $groupValueKey = $arViewColumns[$arGroups[$level]]['resultName']; $groupValue = $arData[$arGroupValuesIndexes[$groupValueIndex]][$groupValueKey]; // magic glue if (is_array($groupValue)) { $groupValue = join(' / ', $groupValue); } if ($level == $nGroups - 1) { $rowClass = ' reports-grouping-data-row'; } else { $rowClass = ' reports-grouping-group-row'; } if (!empty($rowClass)) { $rowClass = ' class="' . ltrim($rowClass) . '"'; } $margin = $level > 0 ? ' style="margin-left: ' . $level * $marginWidth . 'px;"' : ''; /*$rowClass .= ' style="mso-outline-level:'.($level+1).'"';*/ $strHtml .= "\t\t\t" . '<tr' . $rowClass . '>' . PHP_EOL . "\t\t\t\t" . '<td><div' . $margin . '>' . $groupValue . '</div></td>' . PHP_EOL; foreach ($arSubTotal as $k => $subValue) { $cellStyle = ''; if ($arResult['settings']['red_neg_vals'] === true) { if (is_numeric($subValue) && $subValue < 0) { $cellStyle .= ' color: red;'; } } // cell align $colAlign = $arViewColumns[$arColumns[$k]]['align']; if ($colAlign === null) { if (CReport::isColumnPercentable($arViewColumns[$arColumns[$k]])) { $cellStyle .= ' text-align: right;'; } } else { if ($colAlign === 'right') { $cellStyle .= ' text-align: right;'; } } if (!empty($cellStyle)) { $cellStyle = ' style="' . ltrim($cellStyle) . '"'; } $bGroupingSubtotal = $arViewColumns[$arColumns[$k]]['grouping_subtotal']; if ($bGroupingSubtotal || $level == $nGroups - 1) { $finalSubValue = $subValue; if (method_exists($arParams['REPORT_HELPER_CLASS'], 'formatResultGroupingTotal')) { // format subtotal value $subValueKey = $arViewColumns[$arColumns[$k]]['resultName']; call_user_func(array($arParams['REPORT_HELPER_CLASS'], 'formatResultGroupingTotal'), array('k' => $subValueKey, 'v' => &$finalSubValue, 'cInfo' => &$arViewColumns[$arColumns[$k]])); } } else { $finalSubValue = ' '; } $strHtml .= "\t\t\t\t" . '<td' . $cellStyle . '>' . $finalSubValue . '</td>' . PHP_EOL; } $strHtml .= "\t\t\t" . '</tr>' . PHP_EOL; $strHtml .= $strSubHtml; // total += subtotal if ($nColumns > 0) { foreach ($arColumns as $columnIndex => $viewColumnIndex) { $columnDataType = $arValueTypes[$viewColumnIndex]; if ($columnDataType === 'integer' || $columnDataType === 'float') { if (is_string($arSubTotal[$columnIndex])) { $arSubTotal[$columnIndex] = str_replace(' ', '', $arSubTotal[$columnIndex]); } $total[$columnIndex] += $arSubTotal[$columnIndex]; } } $nSubRows++; } } // while ($n-- > 0) } else { $newRowSet[] = $arGroupValuesIndexes[$i]; } } // calculate average values if ($nSubRows > 1) { foreach ($arColumns as $columnIndex => $viewColumnIndex) { if ($arViewColumns[$viewColumnIndex]['aggr'] === 'AVG' || $arViewColumns[$viewColumnIndex]['grouping_aggr'] === 'AVG') { $total[$columnIndex] = $total[$columnIndex] / $nSubRows; } } } } else { if ($nColumns > 0) { $rowNumber = 0; while ($rowNumber++ < $nRows) { // get index if ($bUseRowSet) { list(, $dataIndex) = each($arRowSet); } else { list($dataIndex, ) = each($arData); } // total += values foreach ($arColumns as $columnIndex => $viewColumnIndex) { $columnDataType = $arValueTypes[$viewColumnIndex]; if ($nRows == 1) { $dataValueKey = $arViewColumns[$viewColumnIndex]['resultName']; $dataValue = $arData[$dataIndex][$dataValueKey]; if ($columnDataType === 'float' && is_string($dataValue)) { $dataValue = str_replace(' ', '', $dataValue); } $total[$columnIndex] = $dataValue; } else { if ($columnDataType === 'integer' || $columnDataType === 'float') { $dataValue = $arData[$dataIndex][$arViewColumns[$viewColumnIndex]['resultName']]; if (is_string($dataValue)) { $dataValue = str_replace(' ', '', $dataValue); } $total[$columnIndex] += $dataValue; } } } } // calculate average values if ($nRows > 1) { foreach ($arColumns as $columnIndex => $viewColumnIndex) { if ($arViewColumns[$viewColumnIndex]['aggr'] === 'AVG' || $arViewColumns[$viewColumnIndex]['grouping_aggr'] === 'AVG') { $total[$columnIndex] = $total[$columnIndex] / $nRows; } } } } } } // show total if ($level === 0) { if (count($total) > 0) { // show total check $bShowTotal = false; foreach ($total as $k => $v) { if ($arViewColumns[$arColumns[$k]]['grouping_subtotal']) { $bShowTotal = true; break; } } if ($bShowTotal) { $strHtml .= "\t\t\t" . '<tr class="reports-grouping-table-row-separator"><td></td></tr>' . PHP_EOL; $strHtml .= "\t\t\t" . '<tr class="reports-grouping-total-row">' . PHP_EOL . "\t\t\t\t" . '<td>' . htmlspecialcharsbx(GetMessage('REPORT_TOTAL')) . '</td>' . PHP_EOL; foreach ($total as $k => $v) { $cellStyle = ''; if ($arResult['settings']['red_neg_vals'] === true) { if (is_numeric($v) && $v < 0) { $cellStyle .= ' color: red;'; } } // cell align $colAlign = $arViewColumns[$arColumns[$k]]['align']; if ($colAlign === null) { if (CReport::isColumnPercentable($arViewColumns[$arColumns[$k]])) { $cellStyle = ' text-align: right;'; } } else { if ($colAlign === 'right') { $cellStyle = ' text-align: right;'; } } $bGroupingSubtotal = $arViewColumns[$arColumns[$k]]['grouping_subtotal']; if ($bGroupingSubtotal) { $finalTotalValue = $v; if (method_exists($arParams['REPORT_HELPER_CLASS'], 'formatResultGroupingTotal')) { // format subtotal value $subValueKey = $arViewColumns[$arColumns[$k]]['resultName']; call_user_func(array($arParams['REPORT_HELPER_CLASS'], 'formatResultGroupingTotal'), array('k' => $subValueKey, 'v' => &$finalTotalValue, 'cInfo' => &$arViewColumns[$arColumns[$k]])); } } else { $finalTotalValue = ' '; } if (!empty($cellStyle)) { $cellStyle = ' class="' . ltrim($cellStyle) . '"'; } $strHtml .= "\t\t\t\t" . '<td' . $cellStyle . '>' . $finalTotalValue . '</td>' . PHP_EOL; } $strHtml .= "\t\t\t" . '</tr>' . PHP_EOL; } } $strHtml .= "\t\t" . '</tbody>' . PHP_EOL . "\t" . '</table>' . PHP_EOL; } } return array('total' => $total, 'html' => $strHtml); }
<?php $i = 0; foreach ($arResult['viewColumns'] as $col) { ?> <?php $i++; if ($i == 1) { $td_class = 'reports-first-column'; } else { if ($i == count($arResult['viewColumns'])) { $td_class = 'reports-last-column'; } else { $td_class = ''; } } if (CReport::isColumnPercentable($col)) { $td_class .= ' align-right'; } else { $td_class .= ' align-left'; } ?> <td class="adm-list-table-cell <?php echo $td_class; ?> "><?php echo array_key_exists('TOTAL_' . $col['resultName'], $arResult['total']) ? $arResult['total']['TOTAL_' . $col['resultName']] : '—'; ?> </td> <?php } ?>
<?php $r =& CReport::getInstance(); $key = $_SERVER['QUERY_STRING']; if (strlen($key) != 32) { $reportData = $r->getCurrentReport($key); $url = '/report?' . $reportData['RA_KEY']; }
?> </td> </tr><?php $pdfdata[] = array(sprintf('%.1f%%', $project->project_percent_complete), ' ' . $projectName, $contactName, $AppUI->formatTZAwareTime($project->project_start_date, $df), $AppUI->formatTZAwareTime($criticalTasks[0]['task_end_date'], $df), $targetBudget, $actualCost, $w2Pconfig['currency_symbol'] . $diff_total); } if ($log_pdf) { // make the PDF file $temp_dir = W2P_BASE_DIR . '/files/temp'; $output = new w2p_Output_PDFRenderer('A4', 'landscape'); $output->addTitle($AppUI->_('Costs By Project')); $output->addDate($df); $output->addSubtitle($companies[$company_id]); $pdfheaders = array($AppUI->_('Work', UI_OUTPUT_JS), ' ' . $AppUI->_('Project Name', UI_OUTPUT_JS), $AppUI->_('Project Owner', UI_OUTPUT_JS), $AppUI->_('Start Date', UI_OUTPUT_JS), $AppUI->_('Finish Date', UI_OUTPUT_JS), $AppUI->_('Target Budget', UI_OUTPUT_JS), $AppUI->_('Actual Cost', UI_OUTPUT_JS), $AppUI->_('Difference', UI_OUTPUT_JS)); $options = array('showLines' => 1, 'fontSize' => 9, 'rowGap' => 1, 'colGap' => 1, 'xPos' => 50, 'xOrientation' => 'right', 'width' => '500', 'cols' => array(0 => array('justification' => 'center', 'width' => 45), 1 => array('justification' => 'left', 'width' => 175), 2 => array('justification' => 'center', 'width' => 75), 3 => array('justification' => 'center', 'width' => 65), 4 => array('justification' => 'center', 'width' => 65), 5 => array('justification' => 'center', 'width' => 65), 6 => array('justification' => 'center', 'width' => 65), 7 => array('justification' => 'center', 'width' => 65))); $output->addTable($title, $pdfheaders, $pdfdata, $options); $w2pReport = new CReport(); if ($output->writeFile($w2pReport->getFilename())) { echo '<tr><td colspan="13">'; echo '<a href="' . W2P_BASE_URL . '/files/temp/' . $w2pReport->getFilename() . '.pdf" target="pdf">'; echo $AppUI->_('View PDF File'); echo '</a>'; echo '</td></tr>'; } else { echo '<tr><td colspan="13">'; echo 'Could not open file to save PDF. '; if (!is_writable($temp_dir)) { echo 'The files/temp directory is not writable. Check your file system permissions.'; } echo '</td></tr>'; } }
<?php if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED !== true) { die; } IncludeModuleLangFile($_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/intranet/public/crm/reports/.left.menu_ext.php"); $aMenuLinksExt = array(); if (CModule::IncludeModule('crm') && CModule::IncludeModule('report')) { $aMenuLinksExt[] = array(GetMessage("MENU_CRM_REPORT_LIST"), "#SITE_DIR#crm/reports/report/", array(), array(), ""); $CrmPerms = new CCrmPerms($GLOBALS["USER"]->GetID()); if (!$CrmPerms->HavePerm('DEAL', BX_CRM_PERM_NONE, 'READ')) { $aMenuLinksExt[] = array(GetMessage("MENU_CRM_FUNNEL"), "#SITE_DIR#crm/reports/index.php", array(), array(), ""); } $obRep = CReport::GetList('crm'); while ($arRep = $obRep->fetch()) { $aMenuLinksExt[] = array($arRep['TITLE'], CComponentEngine::MakePathFromTemplate("#SITE_DIR#crm/reports/report/view/#report_id#/", array('report_id' => $arRep['ID'])), array(), array(), ""); } } $aMenuLinks = array_merge($aMenuLinks, $aMenuLinksExt);
$arResult['report']['TITLE'] .= ' (' . GetMessage('REPORT_TITLE_COPY') . ')'; } } else { // default preset for new report $arResult['preSettings'] = array('select' => call_user_func(array($arParams['REPORT_HELPER_CLASS'], 'getDefaultColumns'))); } // </editor-fold> } } catch (Exception $e) { //throw $e; if ($e instanceof BXFormException) { $arResult['FORM_ERROR'] = $e->getMessage(); // refill form $arResult['report']['TITLE'] = $reportSettings['title']; unset($reportSettings['title']); CReport::fillFilterReferenceColumns($reportSettings['filter'], $fieldList, $arParams['REPORT_HELPER_CLASS']); $arResult['preSettings'] = $reportSettings; } else { if ($e instanceof BXUserException) { $arResult['ERROR'] = $e->getMessage(); } else { $arResult['ERROR'] = GetMessage('REPORT_UNKNOWN_ERROR'); } } } $this->IncludeComponentTemplate(); // <editor-fold defaultstate="collapsed" desc="tree structure description"> // format fields parameters to chains and build fields tree //array( // array($originalDefinition, $elem, $subTree), // array(str, scalar, null)
foreach ($data as $k => $v) { $data[$k][$alias] = null; } // add values to data foreach ($grcData[$resultName] as $grcIndex => &$row) { $grc_primary_string = ''; foreach ($grcSelectPrimaries as $pResultName => $def) { $grc_primary_string .= (string) $row[$pResultName] . '/'; } $dataIndexes = $grcDataPrimaryPointers[$grc_primary_string]; foreach ($dataIndexes as $dataIndex) { if (!isset($data[$dataIndex][$alias])) { $data[$dataIndex][$alias] = array(); } if (!empty($elem['href']) && strlen($row[$alias])) { $url = CReport::generateValueUrl($elem, $row, $entity); $row['__HREF_' . $alias] = $url; } $data[$dataIndex][$alias][$grcIndex] = $row[$alias]; } } unset($row); } } // end concat grc // </editor-fold> // collect UF values call_user_func_array(array($arParams['REPORT_HELPER_CLASS'], 'collectUFValues'), array(&$data, &$viewColumnsByResultName, $total)); $customChartTotal = $customChartData = array(); // format results call_user_func_array(array($arParams['REPORT_HELPER_CLASS'], 'formatResults'), array(&$data, &$viewColumnsByResultName, $total, &$customChartData));
$res = Bitrix\Report\ReportTable::getList(array('select' => array('ID'), 'filter' => array('=CREATED_BY' => $USER->GetID(), '=OWNER_ID' => CBaseSaleReportHelper::getOwners()))); while ($row = $res->fetch()) { $arID[] = $row['ID']; } unset($res); unset($row); } foreach ($arID as $ID) { if (strlen($ID) <= 0) { continue; } switch ($_REQUEST['action']) { case "delete": @set_time_limit(0); $DB->StartTransaction(); if (!CReport::Delete($ID)) { $DB->Rollback(); if ($ex = $APPLICATION->GetException()) { $lReports->AddGroupError($ex->GetString(), $ID); } else { $lReports->AddGroupError(GetMessage("SALE_REPORT_ERROR_DELREPFROMLIST"), $ID); } } $DB->Commit(); break; } } } // Getting reports list. $dbRepList = Bitrix\Report\ReportTable::getList(array('select' => array('ID', 'TITLE', 'DESCRIPTION', 'CREATED_DATE', 'MARK_DEFAULT'), 'filter' => array('=CREATED_BY' => $USER->GetID(), '=OWNER_ID' => CBaseSaleReportHelper::getOwners()))); $dbRepList = new CAdminResult($dbRepList, $sTableID);
<?php $i = 0; foreach ($arResult['viewColumns'] as $col) { ?> <?php $i++; if ($i == 1) { $td_class = 'reports-first-column'; } else { if ($i == count($arResult['viewColumns'])) { $td_class = 'reports-last-column'; } else { $td_class = ''; } } if (CReport::isColumnPercentable($col, $arResult['helperClassName'])) { $colType = getResultColumnDataType($col, $arResult['customColumnTypes'], $arResult['helperClassName']); if (!in_array($colType, array('string', 'datetime', 'date', 'boolean'), true)) { $td_class .= ' reports-numeric-column'; } } ?> <td class="<?php echo $td_class; ?> "><?php echo array_key_exists('TOTAL_' . $col['resultName'], $arResult['total']) ? $arResult['total']['TOTAL_' . $col['resultName']] : '—'; ?> </td> <?php }
if ($arParams['USE_CHART']) { $reportSettings['chart'] = $chart; } if (is_array($mobile) && count($mobile) > 0) { $reportSettings['mobile'] = $mobile; } if (!empty($formErr)) { throw new BXFormException($formErr); } // save if ($arParams['ACTION'] == 'create' || $arParams['ACTION'] == 'copy') { $ID = CReport::Add($reportSettings); } else { if ($arParams['ACTION'] == 'edit') { $ID = $arParams['REPORT_ID']; CReport::Update($ID, $reportSettings); } } $url = CComponentEngine::MakePathFromTemplate($arParams["PATH_TO_REPORT_VIEW"], array('report_id' => $ID)); LocalRedirect($url); exit; // </editor-fold> } else { // <editor-fold defaultstate="collapsed" desc="initialize default values"> if ($arParams['ACTION'] == 'edit' || $arParams['ACTION'] == 'copy') { $settings = unserialize($arResult['report']['SETTINGS']); call_user_func_array(array($arParams['REPORT_HELPER_CLASS'], 'fillFilterUFColumns'), array(&$settings['filter'], &$fieldList)); call_user_func_array(array($arParams['REPORT_HELPER_CLASS'], 'fillFilterReferenceColumns'), array(&$settings['filter'], &$fieldList)); $arResult['preSettings'] = $settings; // change title if ($arParams['ACTION'] == 'copy') {
function groupingReportResultHtml(&$arParams, &$arResult, $level = 0, $arRowSet = array()) { $strHtml = ''; $total = array(); $arViewColumns =& $arResult['viewColumns']; $arData =& $arResult['data']; // static variables static $arGroups = array(); static $arColumns = array(); static $nGroups = 0; static $nColumns = 0; static $arValueTypes = array(); static $marginWidth = 20; // chart info variables static $bChartGrouping = false; static $arChartColumns = array(); static $chartColumnMaxGroupLevel = -1; static $chartDataRowIndex = -1; static $arChartGroupingValues = array(); // initialize static variables if ($level === 0) { foreach ($arViewColumns as $viewColumnIndex => $viewColumn) { if ($viewColumn['grouping']) { $arGroups[$nGroups++] = $viewColumnIndex; } else { $arColumns[$nColumns++] = $viewColumnIndex; } $arValueTypes[$viewColumnIndex] = getResultColumnDataType($viewColumn, $arResult['customColumnTypes'], $arResult['helperClassName']); } // chart columns if ($arParams['USE_CHART'] && $arResult['settings']['chart']['display']) { $chartSettings = $arResult['settings']['chart']; if (isset($chartSettings['x_column']) && is_array($chartSettings['y_columns'])) { $arChartColumns[] = $chartSettings['x_column']; $arChartColumns = array_merge($arChartColumns, $chartSettings['y_columns']); } // obtain max group level of chart columns foreach ($arChartColumns as $nChartColumn) { foreach ($arGroups as $groupLevel => $nGroup) { if ($nChartColumn == $nGroup) { $bChartGrouping = true; $chartColumnMaxGroupLevel = max($chartColumnMaxGroupLevel, $groupLevel); } } } } } $nRows = count($arRowSet); $bUseRowSet = $nRows > 0 ? true : false; if (!$bUseRowSet) { $nRows = count($arData); } if ($nGroups > 0) { // grouping table header if ($level === 0) { $bFirstGroup = true; $strHtml .= '<div class="reports-grouping-table-wrap">' . PHP_EOL . "\t" . '<table id="report-result-table" class="reports-grouping-table" cellpadding=2 cellspacing=0>' . PHP_EOL . "\t\t" . '<thead>' . PHP_EOL; foreach ($arGroups as $groupColumnIndex) { $strHtml .= "\t\t\t" . '<tr class="adm-list-table-header reports-grouping-table-head-row">' . PHP_EOL . "\t\t\t\t" . '<td class="adm-list-table-cell">' . htmlspecialcharsbx($arViewColumns[$groupColumnIndex]['humanTitle']) . '</td>' . PHP_EOL; if ($bFirstGroup) { $bFirstGroup = false; foreach ($arColumns as $viewColumnIndex) { $strHtml .= "\t\t\t\t" . '<td class="adm-list-table-cell align-center"'; if ($nGroups > 1) { $strHtml .= ' rowspan="' . htmlspecialcharsbx($nGroups) . '"'; } $strHtml .= ' colId="' . $viewColumnIndex . '" defaultSort="' . $arViewColumns[$viewColumnIndex]['defaultSort'] . '">' . htmlspecialcharsbx($arViewColumns[$viewColumnIndex]['humanTitle']) . '</td>' . PHP_EOL; } } $strHtml .= "\t\t\t" . '</tr>' . PHP_EOL; } $strHtml .= "\t\t" . '</thead>' . PHP_EOL; } if ($nRows > 0) { // table header separator if ($level === 0) { $strHtml .= "\t\t" . '<tbody>' . PHP_EOL . "\t\t\t" . '<tr class="reports-grouping-table-row-separator"><td></td></tr>' . PHP_EOL; } // init total if ($nColumns > 0) { foreach (array_keys($arColumns) as $columnIndex) { $total[$columnIndex] = null; } } if ($level < $nGroups) { // fill group arrays $arGroupValues = array(); $arGroupValuesIndexes = array(); $rowNumber = 0; $groupDataType = $arValueTypes[$arGroups[$level]]; $dataIndex = null; reset($arData); while ($rowNumber++ < $nRows) { // get index if ($bUseRowSet) { list(, $dataIndex) = each($arRowSet); } else { list($dataIndex, ) = each($arData); } // fill index and value of group $arGroupValuesIndexes[] = $dataIndex; $groupValue = $arData[$dataIndex][$arViewColumns[$arGroups[$level]]['resultName']]; if ($groupDataType === 'date' || $groupDataType === 'datetime') { $groupValue = MakeTimeStamp($groupValue, CSite::GetDateFormat('SHORT')); } // magic glue if (is_array($groupValue)) { $groupValue = join(' / ', $groupValue); } $arGroupValues[] = $groupValue; } // determine sort options $groupSortOption = SORT_STRING; $groupSortDirection = SORT_ASC; if (in_array($groupDataType, array('date', 'datetime', 'integer', 'float'))) { $groupSortOption = SORT_NUMERIC; } if ($arGroups[$level] == $arResult['sort_id']) { if ($arResult['sort_type'] != 'ASC') { $groupSortDirection = SORT_DESC; } } // sort group array_multisort($arGroupValues, $groupSortOption, $groupSortDirection, $arGroupValuesIndexes, SORT_NUMERIC, SORT_ASC); // recursive scan $prev = null; $newRowSet = array(); $nGroupValues = count($arGroupValues); $nSubRows = 0; for ($i = 0; $i < $nGroupValues; $i++) { $cur = $arGroupValues[$i]; if ($i == 0) { $prev = $cur; } $bLastValue = $nGroupValues - 1 == $i; if ($cur != $prev || $bLastValue) { $n = $bLastValue && $cur != $prev ? 2 : 1; while ($n-- > 0) { // chart values index if ($bChartGrouping && $level == $chartColumnMaxGroupLevel) { $chartDataRowIndex++; } if ($bLastValue && $cur == $prev) { $newRowSet[] = $arGroupValuesIndexes[$i]; } $arGroupingResult = groupingReportResultHtml($arParams, $arResult, $level + 1, $newRowSet); $arSubTotal = $arGroupingResult['total']; $strSubHtml = $arGroupingResult['html']; unset($arGroupingResult); $newRowSet = array(); if (!$bLastValue) { $newRowSet[] = $arGroupValuesIndexes[$i]; } $prev = $cur; // show row $groupValueIndex = $bLastValue && $n === 0 ? $i : $i - 1; $groupValueKey = $arViewColumns[$arGroups[$level]]['resultName']; $groupValue = $arData[$arGroupValuesIndexes[$groupValueIndex]][$groupValueKey]; // magic glue if (is_array($groupValue)) { $groupValue = join(' / ', $groupValue); } // add chart values if ($bChartGrouping && in_array($arGroups[$level], $arChartColumns)) { $tempChartDataRowIndex = $chartDataRowIndex; while ($tempChartDataRowIndex >= 0 && !isset($arChartGroupingValues[$tempChartDataRowIndex][$arGroups[$level]])) { $arChartGroupingValues[$tempChartDataRowIndex--][$arGroups[$level]] = $groupValue; } unset($tempChartDataRowIndex); } // values of groups were processed as normal values /*if (method_exists($arResult['helperClassName'], 'formatResultGroupingValue')) { // format group value call_user_func( array($arResult['helperClassName'], 'formatResultGroupingValue'), array( 'k' => $groupValueKey, 'v' => &$groupValue, 'row' => &$arData[$arGroupValuesIndexes[$groupValueIndex]], 'cInfo' => &$arViewColumns[$arGroups[$level]] ) ); }*/ $cellClassFirstColumn = ''; if ($level == $nGroups - 1) { $rowClass = ' reports-grouping-data-row'; } else { $rowClass = ' reports-grouping-group-row'; $cellClassFirstColumn = 'adm-list-table-cell'; } $cellClassAttr = ''; if (!empty($cellClassFirstColumn)) { $cellClassAttr = ' class="' . $cellClassFirstColumn . '"'; } $margin = $level > 0 ? ' style="margin-left: ' . $level * $marginWidth . 'px;"' : ''; $strHtml .= "\t\t\t" . '<tr class="adm-list-table-header' . $rowClass . '">' . PHP_EOL . "\t\t\t\t" . '<td' . $cellClassAttr . '><div' . $margin . '>' . ($groupValue === '' ? ' ' : $groupValue) . '</div></td>' . PHP_EOL; foreach ($arSubTotal as $k => $subValue) { $cellAlign = ''; $cellClass = $cellClassFirstColumn; if ($arResult['settings']['red_neg_vals'] === true) { if (is_numeric($subValue) && $subValue < 0) { $cellClass .= ' report-red-neg-val'; } } // cell align $colAlign = $arViewColumns[$arColumns[$k]]['align']; if ($colAlign === null) { if (CReport::isColumnPercentable($arViewColumns[$arColumns[$k]], $arResult['helperClassName'])) { $cellAlign = ' align-right'; } } else { if ($colAlign === 'right') { $cellAlign = ' align-right"'; } } if (!empty($cellAlign)) { $cellClass .= $cellAlign; } if (!empty($cellClass)) { $cellClass = ' class="' . ltrim($cellClass) . '"'; } $bGroupingSubtotal = $arViewColumns[$arColumns[$k]]['grouping_subtotal']; if ($bGroupingSubtotal || $level == $nGroups - 1) { $finalSubValue = $subValue; if (method_exists($arResult['helperClassName'], 'formatResultGroupingTotal')) { // format subtotal value $subValueKey = $arViewColumns[$arColumns[$k]]['resultName']; call_user_func(array($arResult['helperClassName'], 'formatResultGroupingTotal'), array('k' => $subValueKey, 'v' => &$finalSubValue, 'cInfo' => &$arViewColumns[$arColumns[$k]])); } } else { $finalSubValue = ''; } $strHtml .= "\t\t\t\t" . '<td' . $cellClass . '>' . ($finalSubValue === '' ? ' ' : $finalSubValue) . '</td>' . PHP_EOL; // add chart values if ($bChartGrouping && $level == $chartColumnMaxGroupLevel && in_array($arColumns[$k], $arChartColumns)) { $arChartGroupingValues[$chartDataRowIndex][$arColumns[$k]] = $finalSubValue; } } $strHtml .= "\t\t\t" . '</tr>' . PHP_EOL; $strHtml .= $strSubHtml; // total += subtotal if ($nColumns > 0) { foreach ($arColumns as $columnIndex => $viewColumnIndex) { $columnDataType = $arValueTypes[$viewColumnIndex]; if ($columnDataType === 'integer' || $columnDataType === 'float') { if (is_string($arSubTotal[$columnIndex])) { $arSubTotal[$columnIndex] = str_replace(' ', '', $arSubTotal[$columnIndex]); } $total[$columnIndex] += $arSubTotal[$columnIndex]; } } $nSubRows++; } } // while ($n-- > 0) } else { $newRowSet[] = $arGroupValuesIndexes[$i]; } } // calculate average values if ($nSubRows > 1) { foreach ($arColumns as $columnIndex => $viewColumnIndex) { if ($arViewColumns[$viewColumnIndex]['aggr'] === 'AVG' || $arViewColumns[$viewColumnIndex]['grouping_aggr'] === 'AVG') { $total[$columnIndex] = $total[$columnIndex] / $nSubRows; } } } } else { if ($nColumns > 0) { $rowNumber = 0; while ($rowNumber++ < $nRows) { // get index if ($bUseRowSet) { list(, $dataIndex) = each($arRowSet); } else { list($dataIndex, ) = each($arData); } // total += values foreach ($arColumns as $columnIndex => $viewColumnIndex) { $columnDataType = $arValueTypes[$viewColumnIndex]; if ($nRows == 1) { $dataValueKey = $arViewColumns[$viewColumnIndex]['resultName']; $dataValue = $arData[$dataIndex][$dataValueKey]; // normal value /*if (method_exists($arResult['helperClassName'], 'formatResultGroupingValue')) { // format result value call_user_func( array($arResult['helperClassName'], 'formatResultGroupingValue'), array( 'k' => $dataValueKey, 'v' => &$dataValue, 'row' => &$arData[$dataIndex], 'cInfo' => &$arViewColumns[$viewColumnIndex] ) ); }*/ if ($columnDataType === 'integer' || $columnDataType === 'float' && is_string($dataValue)) { $dataValue = str_replace(' ', '', $dataValue); } $total[$columnIndex] = $dataValue; } else { if ($columnDataType === 'integer' || $columnDataType === 'float') { $dataValue = $arData[$dataIndex][$arViewColumns[$viewColumnIndex]['resultName']]; if (is_string($dataValue)) { $dataValue = str_replace(' ', '', $dataValue); } $total[$columnIndex] += $dataValue; } } } } // calculate average values if ($nRows > 1) { foreach ($arColumns as $columnIndex => $viewColumnIndex) { if ($arViewColumns[$viewColumnIndex]['aggr'] === 'AVG' || $arViewColumns[$viewColumnIndex]['grouping_aggr'] === 'AVG') { $total[$columnIndex] = $total[$columnIndex] / $nRows; } } } } } } // show total if ($level === 0) { if (count($total) > 0) { // show total check $bShowTotal = false; foreach ($total as $k => $v) { if ($arViewColumns[$arColumns[$k]]['grouping_subtotal']) { $bShowTotal = true; break; } } if ($bShowTotal) { $strHtml .= "\t\t\t" . '<tr class="reports-grouping-table-row-separator"><td></td></tr>' . PHP_EOL; $strHtml .= "\t\t\t" . '<tr class="adm-list-table-header reports-grouping-total-row">' . PHP_EOL . "\t\t\t\t" . '<td class="adm-list-table-cell">' . htmlspecialcharsbx(GetMessage('REPORT_TOTAL')) . '</td>' . PHP_EOL; foreach ($total as $k => $v) { $cellAlign = ''; $cellClass = ''; if ($arResult['settings']['red_neg_vals'] === true) { if (is_numeric($v) && $v < 0) { $cellClass .= ' report-red-neg-val'; } } // cell align $colAlign = $arViewColumns[$arColumns[$k]]['align']; if ($colAlign === null) { if (CReport::isColumnPercentable($arViewColumns[$arColumns[$k]], $arResult['helperClassName'])) { $cellAlign = ' align-right'; } } else { if ($colAlign === 'right') { $cellAlign = ' align-right'; } } if (!empty($cellAlign)) { $cellClass .= $cellAlign; } $bGroupingSubtotal = $arViewColumns[$arColumns[$k]]['grouping_subtotal']; if ($bGroupingSubtotal) { $finalTotalValue = $v; if (method_exists($arResult['helperClassName'], 'formatResultGroupingTotal')) { // format subtotal value $subValueKey = $arViewColumns[$arColumns[$k]]['resultName']; call_user_func(array($arResult['helperClassName'], 'formatResultGroupingTotal'), array('k' => $subValueKey, 'v' => &$finalTotalValue, 'cInfo' => &$arViewColumns[$arColumns[$k]])); } } else { $finalTotalValue = ''; } $strHtml .= "\t\t\t\t" . '<td class="adm-list-table-cell' . $cellClass . '">' . ($finalTotalValue === '' ? ' ' : $finalTotalValue) . '</td>' . PHP_EOL; } $strHtml .= "\t\t\t" . '</tr>' . PHP_EOL; } } $strHtml .= "\t\t" . '</tbody>' . PHP_EOL . "\t" . '</table>' . PHP_EOL . '</div>' . PHP_EOL; } } $result = array('total' => $total, 'html' => $strHtml); // return chart values if ($bChartGrouping && $level === 0) { $result['chart'] = $arChartGroupingValues; $arChartGroupingValues = array(); } return $result; }
<?php $report = CReport::getInstance(); $type = $report->Types(); $typeArray = array(); $frequency = array('Weekly' => 0, 'Monthly' => 1); $i = 1; foreach ($type as $k => $v) { $typeArray[$i] = $v['RT_NAME']; $i++; } ?> <div style="padding-left:10px; width:545px; text-align:left;" id="_archives"> <div class="f_12 bold">Archived Reports</div> <br /> <?php $limit = 5; foreach ($typeArray as $k => $v) { foreach ($frequency as $k2 => $v2) { $archive = $report->Reports($_USER_ID, $k, $k2, $limit); if ($archive != null) { echo '<div id="' . $typeArray[$archive[0]['R_TYPE']] . ' - ' . $archive[0]['R_FREQUENCY'] . '" style="float:left; padding-top:20px; padding-right:20px;" class="f_10 bold"><a href="javascript:toggleDiv(\'' . $typeArray[$archive[0]['R_TYPE']] . ' - ' . $archive[0]['R_FREQUENCY'] . ' - divStart\');">' . $typeArray[$archive[0]['R_TYPE']] . ' - ' . $archive[0]['R_FREQUENCY'] . '</a></div>'; echo '<div style="padding-top:22px;"><a href="/?action=reports.report_archive_all&type=' . $archive[0]['R_TYPE'] . '&freq=' . $archive[0]['R_FREQUENCY'] . '">View All</a></div>'; echo '<br />'; echo '<div id="' . $typeArray[$archive[0]['R_TYPE']] . ' - ' . $archive[0]['R_FREQUENCY'] . ' - divStart" style="display:block;">'; // starts the div for all the reports in this category foreach ($archive as $k3 => $v3) { echo '<div style="padding-top:5px; padding-left:20px;">'; echo '<div style="float:left; width:400px;"><a href="/reports' . $v3['RA_FILENAME'] . '" target="_blank">' . $v3['RA_TITLE'] . '</a></div>'; echo '</div>';