<?php
 if ($OK and $R['generateReport']) { $columnsCount=0; if ( is_array($reportColumns)) { foreach($reportColumns as $colDet) { if ($colDet['s']) $columnsCount++; } } $pivotsCount=0; if ( is_array($pivotTables)) { foreach($pivotTables as $pivDet) { if ($pivDet['s']) $pivotsCount++; } } if (!$columnsCount and !$pivotsCount) { $showMessage['warning'] = $_LANG['reportsGeneration']['startReport']['reportUndefined']; $OK=0; } $generationTimestamp=0; if ($R['triggerReport']!="now" and $R['triggerReport']!="programmed") { $showMessage['warning'] = $_LANG['reportsGeneration']['startReport']['noValidValueForReportTrigger']; $OK=0; } if ($R['triggerReport']=="programmed") { if (!$R['triggerDate'] or !checkValidDate($R['triggerDate'])) { $showMessage['warning'] = $_LANG['reportsGeneration']['startReport']['noDateTimeTrigger']; $OK=0; } if ($OK) { $generationTimestamp=strtotime(standard2mysqlDateConversion($R['triggerDate']).' '.$R['triggerTime']); if ($generationTimestamp<TIMESTAMP+$CFG['reportsGeneration']['generation']['triggerReport']['minTime']) { $showMessage['warning'] = sprintf($_LANG['reportsGeneration']['startReport']['reportTrigger_minTime'], date(MYSQL_FORMAT." H:i:s", TIMESTAMP+$CFG['reportsGeneration']['generation']['triggerReport']['minTime'])); $OK=0; } elseif ($generationTimestamp>TIMESTAMP+$CFG['reportsGeneration']['generation']['triggerReport']['maxTime']) { $showMessage['warning'] = sprintf($_LANG['reportsGeneration']['startReport']['reportTrigger_maxTime'], date(MYSQL_FORMAT." H:i:s", TIMESTAMP+$CFG['reportsGeneration']['generation']['triggerReport']['maxTime'])); $OK=0; } } } if ($OK) { $accessToReportSQL="SELECT idReport FROM `$DBTReportsAccess` WHERE idReport='".$idReport."' AND idUser='".$S['auth']['idUser']."' LIMIT 1"; $accessToReportArr=$db->GetRow($accessToReportSQL); if ($db->ErrorNo()) { writeLog("Could not get report access.", 'events', 10); $showMessage['error'] = $_LANG['reportsGeneration']['startReport']['cantCheckAccessToReport']; $OK=0; } else { if (!$accessToReportArr['idReport']) { $showMessage['warning'] = $_LANG['reportsGeneration']['startReport']['noAccessToReport']; $OK=0; } } } if ($OK) { if (!is_numeric($R['valabilityPeriod']) or $R['valabilityPeriod']<=0) { $showMessage['warning']=$_LANG['reportsGeneration']['startReport']['noValabilityPeriod']; $OK=0; } if (!$R['valabilityMeasureUnit']) { $showMessage['warning']=$_LANG['reportsGeneration']['startReport']['noValabilityMu']; $OK=0; } switch($R['valabilityMeasureUnit']) { case 'minutes': $totalValability=$R['valabilityPeriod'];break; case 'hours': $totalValability=$R['valabilityPeriod']*60;break; case 'days': $totalValability=$R['valabilityPeriod']*1440;break; case 'weeks': $totalValability=$R['valabilityPeriod']*10080;break; default:$totalValability=0;break; } if ($totalValability>$CFG['reportsGeneration']['generation']['valability']['maxDuration']) { $showMessage['warning']=sprintf($_LANG['reportsGeneration']['startReport']['valabilityTooBig'], round($CFG['reportsGeneration']['generation']['valability']['maxDuration']/1440, 2) ); $OK=0; } if (!$totalValability) { $showMessage['warning']=$_LANG['reportsGeneration']['startReport']['valabilityInvalid']; $OK=0; } } if ($OK) { $manualGenerationsPerUser = getGeneratingReports(CURRENT_ID_USER, 'manual'); if (count($manualGenerationsPerUser)>=$CFG['reportsGeneration']['concurrentGeneration']['manualGenerationsPerUser']) { $OK = 0; $showMessage['warning'] = sprintf($_LANG['reportsGeneration']['startReport']['manualGenPerUserLimitMet'], $CFG['reportsGeneration']['concurrentGeneration']['manualGenerationsPerUser']); } $manualGenerationsGlobal = getGeneratingReports(0, 'manual'); if (count($manualGenerationsGlobal)>=$CFG['reportsGeneration']['concurrentGeneration']['manualGenerationsGlobal']) { $OK = 0; $showMessage['warning'] = sprintf($_LANG['reportsGeneration']['startReport']['manualGenGlobalLimitMet'], $CFG['reportsGeneration']['concurrentGeneration']['manualGenerationsGlobal']); } } include("index_startReportGeneration_validateFilters.php"); include('index_startReportGeneration_compatNewReports.php'); if ($OK) { if (!$generationTimestamp) { $expireTime=TIMESTAMP+$totalValability*60; } else { $expireTime=$generationTimestamp+$totalValability*60; } if ($checkCompatibility) { $stdColumnsSer = $compat['stdColumns'] ? json_encode($compat['stdColumns']) : ''; $custColumnsSer = $compat['customColumns'] ? json_encode($compat['customColumns']) : ''; $stdFiltersSer = $compat['stdFilters'] ? json_encode($compat['stdFilters']) : ''; $custFiltersSer = $compat['customFilters'] ? json_encode($compat['customFilters']) : ''; $columnsOrderSer = $compat['columnsOrder'] ? json_encode($compat['columnsOrder']) : ''; } else { $stdColumnsSer = $custColumnsSer = $stdFiltersSer = $custFiltersSer = $columnsOrderSer = ''; } $addReportSQL="
			INSERT INTO `$DBTReportsGenerating` (
				idUser,  idReport, startTime, endTime, viewed, status, expireTime, addTime, setToStartTime,
				source, stdColumns, customColumns, stdFilters, customFilters, columnsOrder, platform, execTrigger
			) VALUES (
				'".CURRENT_ID_USER."', '".$idReport."', '0', '0', '0', 'pending', '".$expireTime."', '".TIMESTAMP."', '".$generationTimestamp."',
				?, ?, ?, ?, ?, ?, ?, ?
			)
		"; $addReportEx=$db->Execute($addReportSQL, [$reportDetails['source'], $stdColumnsSer, $custColumnsSer, $stdFiltersSer, $custFiltersSer, $columnsOrderSer, ($runningPlatform=='cli'?'cli':'browserSync'), 'manual'] ); if (!$addReportEx) { $OK=0; $showMessage['error'] = $_LANG['reportsGeneration']['startReport']['cantAddReportInDb']; writeLog("Could not add report into db. SQL: ".$addReportSQL, 'events', 10); } else { $idReportGenerating=$db->Insert_ID(); if (!$idReportGenerating) { $OK=0; $showMessage['error'] = $_LANG['reportsGeneration']['startReport']['noReportId']; } } } if ($OK) { $currentReportDir=$MODULE_REL_PATH.$CFG['paths']['generatedReports'].$idReportGenerating.'/'; if ( !\Engine\Dir::create($currentReportDir) ) { $OK=0; $showMessage['error'] = $_LANG['reportsGeneration']['startReport']['dirError']; } } if ($OK) { $reportInput= []; $reportInput['idReport']=$idReport; $reportInput['reportSource']=$reportDetails['source']; $reportInput['columns']=$reportColumns; if ($reportCustomColumns) { foreach($reportCustomColumns as $col=>$colDet) { if (!$colDet['v'] and !$colDet['s']) $reportInput['columns'][$col]=$colDet; } } $reportInput['filters']= [];; foreach($reportFilters as $filter=>$filterDet) { $reportInput['filters'][$filter]=$filterDet['value']; } $reportInput['customFilters']= []; foreach($reportCustomFilters as $filter=>$filterDet) { if (strlen($filterDet['minValue'])) $reportInput['customFilters'][$filter]['minValue']=$filterDet['minValue']; if (strlen($filterDet['maxValue'])) $reportInput['customFilters'][$filter]['maxValue']=$filterDet['maxValue']; if (strlen($filterDet['value'])) $reportInput['customFilters'][$filter]['value']=$filterDet['value']; if ($filterDet['startDate']) $reportInput['customFilters'][$filter]['startDate']=$filterDet['startDate']; if ($filterDet['endDate']) $reportInput['customFilters'][$filter]['endDate']=$filterDet['endDate']; if ($filterDet['operation']) $reportInput['customFilters'][$filter]['operation']=$filterDet['operation']; if (strlen($filterDet['text'])) $reportInput['customFilters'][$filter]['text']=$filterDet['text']; if ($filterDet['boolean']) $reportInput['customFilters'][$filter]['boolean']=$filterDet['boolean']; if ($filterDet['valuesList']) $reportInput['customFilters'][$filter]['valuesList']=$filterDet['valuesList']; if ($filterDet['minAnniv_day']) $reportInput['customFilters'][$filter]['minAnniv_day']=$filterDet['minAnniv_day']; if ($filterDet['minAnniv_month']) $reportInput['customFilters'][$filter]['minAnniv_month']=$filterDet['minAnniv_month']; if ($filterDet['maxAnniv_day']) $reportInput['customFilters'][$filter]['maxAnniv_day']=$filterDet['maxAnniv_day']; if ($filterDet['maxAnniv_month']) $reportInput['customFilters'][$filter]['maxAnniv_month']=$filterDet['maxAnniv_month']; if ($filterDet['searchMode']) $reportInput['customFilters'][$filter]['searchMode']=$filterDet['searchMode']; } $reportInput['sorting']=$reportSorting; $reportInput['pivotTables']=$pivotTables; if (is_array($reportInput['pivotTables'])) { foreach($reportInput['pivotTables'] as $idx=>$piv) { if (!$piv['s']) unset($reportInput['pivotTables'][$idx]); } } if ($R['emailRecipients']) $reportInput['emailRecipients']=$R['emailRecipients']; if ($R['triggerReport']=="programmed") { $reportInput['trigger']="programmed"; } else { $reportInput['trigger']="manual"; } if ( !@file_put_contents($currentReportDir.$CFG['reportsGeneration']['generation']['inputDataFileName'], serialize($reportInput)) ) { $OK=0; $showMessage['error'] = $_LANG['reportsGeneration']['startReport']['inputFileError']; } else { if ( !@chmod($currentReportDir.$CFG['reportsGeneration']['generation']['inputDataFileName'], 0777) ) { $OK=0; $showMessage['error'] = $_LANG['reportsGeneration']['startReport']['inputFileAccessError']; } } } if ($OK and $runningPlatform=="cli") { if ( !@file_put_contents($currentReportDir.$CFG['reportsGeneration']['generation']['outputLogFileName'], ' ') ) { $OK=0; $showMessage['error'] = $_LANG['reportsGeneration']['startReport']['outputFileError']; } else { if ( !@chmod($currentReportDir.$CFG['reportsGeneration']['generation']['outputLogFileName'], 0777) ) { $OK=0; $showMessage['error'] = $_LANG['reportsGeneration']['startReport']['outputFileAccessError']; } } } if ($OK) { $reportIsGenerating=true; if ($runningPlatform=="cli" and !$generationTimestamp) { $dir=getcwd(); chdir($APP_REAL_PATH.$MODULE_PATH); $pathToPhp='php'; $mainCommand=$APP_REAL_PATH."reports/reportsGeneration/processReport/index.php"; $outputFile=realpath($APP_REAL_PATH.$CFG['paths']['generatedReports'].$idReportGenerating.'/'.$CFG['reportsGeneration']['generation']['outputLogFileName']); $arguments= [$idReportGenerating, $S['global']['lang']]; execCommand($mainCommand, $pathToPhp, $outputFile, $R['priority'], false, $arguments); chdir($dir); } if ($runningPlatform=="currentPage") { } $userTrailItem->updateActionOld('startReportOk'); } } ?>