<?php
 if ($R['saveReport']) { $OK=1; include("index_okToFinish.php"); if (!$okToFinish) { $showMessage['warning'] = $allWarnings; $OK=0; } if ($OK) { if ($S['adminReport']['filters']) $reportFiltersStr=serialize($S['adminReport']['filters']); else $reportFiltersStr=''; if ($S['adminReport']['customFilters']) $reportCustomFiltersStr=serialize($S['adminReport']['customFilters']); else $reportCustomFiltersStr=''; $reportColumnsArr=$S['adminReport']['columns']; if (!$reportColumnsArr) $reportColumnsArr= []; foreach($reportColumnsArr as $colKey=>$colDet) { if (!$colDet['n']) unset($reportColumnsArr[$colKey]['n']); if (!$reportColumnsArr[$colKey]) unset($reportColumnsArr[$colKey]); } if ($reportColumnsArr) $reportColumnsStr=serialize($reportColumnsArr); else $reportColumnsStr=''; if ($S['adminReport']['customColumns']) { $reportCustomColumnsArr=$S['adminReport']['customColumns']; foreach($reportCustomColumnsArr as $idx=>$col) { if (substr($col['f'], 0, 7)=='remark:') { $reportCustomColumnsArr[$idx]['type']='remark'; $colDet=explode(':', $col['f']); $reportCustomColumnsArr[$idx]['rmSrc']=$colDet[1]; $reportCustomColumnsArr[$idx]['rmVar']=$colDet[2]; unset($reportCustomColumnsArr[$idx]['t']); unset($reportCustomColumnsArr[$idx]['f']); } elseif (substr($col['f'], 0, 11)=='arrayValue:') { $reportCustomColumnsArr[$idx]['type']='arrayValue'; $colDet=explode(':', $col['f']); $reportCustomColumnsArr[$idx]['arrSrc']=$colDet[1]; $reportCustomColumnsArr[$idx]['arrKey']=$colDet[2]; unset($reportCustomColumnsArr[$idx]['t']); unset($reportCustomColumnsArr[$idx]['f']); } elseif (substr($col['f'], 0, 7)=='entity:') { list(,$entType, $idEnt, $attr)=explode(':', $col['f']); $reportCustomColumnsArr[$idx]['type']='entity'; $reportCustomColumnsArr[$idx]['entType']=$entType; $reportCustomColumnsArr[$idx]['idEnt']=$idEnt; $reportCustomColumnsArr[$idx]['attr']=$attr; unset($reportCustomColumnsArr[$idx]['f']); } elseif (substr($col['f'], 0, 12)=='entityValue:') { list(,$entType, $idEnt, $attr)=explode(':', $col['f']); $reportCustomColumnsArr[$idx]['type']='entityValue'; $reportCustomColumnsArr[$idx]['entType']=$entType; $reportCustomColumnsArr[$idx]['idEnt']=$idEnt; $reportCustomColumnsArr[$idx]['attr']=$attr; unset($reportCustomColumnsArr[$idx]['f']); } else { $reportCustomColumnsArr[$idx]['type']='math'; } } $reportCustomColumnsStr=serialize($reportCustomColumnsArr); } else { $reportCustomColumnsStr=''; } if ($S['adminReport']['columnsOrder']) { $reportColumnsOrderArr=$S['adminReport']['columnsOrder']; $reportColumnsOrderStr=serialize($reportColumnsOrderArr); } else { $reportColumnsOrderStr=''; } if ($S['adminReport']['sorting']) $reportSortingStr=serialize($S['adminReport']['sorting']); else $reportSortingStr=''; if ($S['adminReport']['pivots']) $reportPivotTablesStr=serialize($S['adminReport']['pivots']); else $reportPivotTablesStr=''; if ($S['adminReport']['extraOptions']['emailRecipients']) $reportEmailRecipientsStr=serialize($S['adminReport']['extraOptions']['emailRecipients']); else $reportEmailRecipientsStr=''; if ($S['adminReport']['extraOptions']['autoGenerate']['active']) { unset($S['adminReport']['extraOptions']['autoGenerate']['active']); $reportAutoGenerateStr=serialize($S['adminReport']['extraOptions']['autoGenerate']); } else { $reportAutoGenerateStr=''; } if ($S['adminReport']['extraOptions']['reportSummary']['active']) { unset($S['adminReport']['extraOptions']['reportSummary']['active']); if ($S['adminReport']['extraOptions']['reportSummary']['options']) $reportSummaryStr=serialize($S['adminReport']['extraOptions']['reportSummary']['options']); else $reportSummaryStr=''; } else { $reportSummaryStr=''; } if ($reportAutoGenerateStr) { $nextAutoGenTime = calculateNextAutoGenTime($S['adminReport']['extraOptions']['autoGenerate']); } else { $nextAutoGenTime = 0; } if (isset($S['adminReport']['updateIdReport']) and $S['adminReport']['updateIdReport']>0) { $addReportSQL="
				UPDATE `$DBTReports`
				SET
					idCategory='".$S['adminReport']['idCategory']."',
					source='".$S['adminReport']['source']."',
					name='".$S['adminReport']['name']."',
					style='".$S['adminReport']['style']."',
					format='".$S['adminReport']['format']."',
					fileNameTemplate='".$S['adminReport']['fileNameTemplate']."',
					extension='".$S['adminReport']['extension']."',
					platform='".$S['adminReport']['platform']."',
					description='".$S['adminReport']['description']."',
					filters='".$reportFiltersStr."',
					customFilters='".$reportCustomFiltersStr."',
					columns='".$reportColumnsStr."',
					customColumns='".$reportCustomColumnsStr."',
					columnsOrder='".$reportColumnsOrderStr."',
					sorting='".$reportSortingStr."',
					pivotTables='".$reportPivotTablesStr."',
					emailRecipients='".$reportEmailRecipientsStr."',
					autoGenerate='".$reportAutoGenerateStr."',
					nextAutoGenTime='{$nextAutoGenTime}',
					summary='".$reportSummaryStr."',
					idUpdateUser='".$S['auth']['idUser']."',
					lastUpdateTime='".TIMESTAMP."',
					updatesCount=updatesCount+1
				WHERE id='".$S['adminReport']['updateIdReport']."'
			"; } if (!isset($S['adminReport']['updateIdReport'])) { $addReportSQL="
				INSERT INTO `$DBTReports` (
					deleted, idCategory, source,
					name, description,
					format, fileNameTemplate, extension, style, platform,
					filters, customFilters, columns, customColumns, columnsOrder, sorting,
					pivotTables, emailRecipients, autoGenerate, nextAutoGenTime, summary,
					idAddUser, addTime
				) VALUES (
					'0', '".$S['adminReport']['idCategory']."', '".$S['adminReport']['source']."',
					'".$S['adminReport']['name']."', '".$S['adminReport']['description']."',
					'".$S['adminReport']['format']."', '".$S['adminReport']['fileNameTemplate']."', '".$S['adminReport']['extension']."', '".$S['adminReport']['style']."', '".$S['adminReport']['platform']."',
					'".$reportFiltersStr."', '".$reportCustomFiltersStr."', '".$reportColumnsStr."', '".$reportCustomColumnsStr."', '".$reportColumnsOrderStr."', '".$reportSortingStr."',
					'".$reportPivotTablesStr."', '".$reportEmailRecipientsStr."', '".$reportAutoGenerateStr."', '0', '".$reportSummaryStr."',
					'".$S['auth']['idUser']."', '".TIMESTAMP."'
				)
			"; } $addReportEx=$db->Execute($addReportSQL); if (!$addReportEx) { writeLog("Could not save report. SQL: ".$addReportSQL, 'events', 10); $showMessage['error'] = $_LANG['reportsManagement']['admin']['finish']['reportSaveBad']; } else { if (!isset($S['adminReport']['updateIdReport'])) { $thisReportId=$db->Insert_ID(); } else { $thisReportId=$S['adminReport']['updateIdReport']; } $updateReportAccessEx_delete=true; if (isset($S['adminReport']['updateIdReport'])) { $updateReportAccessSQL_delete="DELETE FROM `$DBTReportsAccess` WHERE idReport='".$thisReportId."'"; $updateReportAccessEx_delete=$db->Execute($updateReportAccessSQL_delete); if (!$updateReportAccessEx_delete) writeLog("Could not delete report old accesses.", 'events', 9); } if ($updateReportAccessEx_delete) { $updateReportAccessSQL_insert="INSERT INTO `$DBTReportsAccess` (idReport, idUser) VALUES "; $accessesList= []; foreach($S['adminReport']['accessUsers'] as $idUser=>$active) { $accessesList[]="('".$thisReportId."', '".$idUser."')"; } $updateReportAccessSQL_insert.=implode(", ", $accessesList); $updateReportAccessEx_insert=$db->Execute($updateReportAccessSQL_insert); if (!$updateReportAccessEx_insert) writeLog("Could not add report new accesses.", 'events', 9); } $showMessage['success'] = $_LANG['reportsManagement']['admin']['finish']['reportSaveOk']; $closePopup=1; $reportSavedOk=true; if ($S['adminReport']['updateIdReport']) $userTrailItem->updateActionOld("reportEditOk"); else $userTrailItem->updateActionOld("reportAddOk"); $userTrailItem->updateEntityOld("report", $thisReportId); unset($S['adminReport']); } } } ?>