<?php
 refreshReportStatus('extractMainDataFromDb', 'composingSQL', 0); $columnsValuesList= []; foreach($tableColumns as $thisCol=>$colDet) { switch ($thisCol) { case 'id': $columnsValuesList[$thisCol]='repoGenHis.id';break; case 'idUser': $columnsValuesList[$thisCol]='repoGenHis.idUser';break; case 'idReport': $columnsValuesList[$thisCol]='repoGenHis.idReport';break; case 'idCategory': $columnsValuesList[$thisCol]='reports.idCategory';break; case 'sourceCode': $columnsValuesList[$thisCol]='reports.source';break; case 'name': $columnsValuesList[$thisCol]='reports.name';break; case 'description': $columnsValuesList[$thisCol]='reports.description';break; case 'platformCode': $columnsValuesList[$thisCol]='reports.platform';break; case 'formatCode': $columnsValuesList[$thisCol]='reports.format';break; case 'extension': $columnsValuesList[$thisCol]='reports.extension';break; case 'startTime': $columnsValuesList[$thisCol]='IF(repoGenHis.startTime, FROM_UNIXTIME(repoGenHis.startTime), NULL)';break; case 'endTime': $columnsValuesList[$thisCol]='IF(repoGenHis.endTime, FROM_UNIXTIME(repoGenHis.endTime), NULL)';break; case 'executionTime': $columnsValuesList[$thisCol]='repoGenHis.endTime-repoGenHis.startTime';break; case 'expireTime': $columnsValuesList[$thisCol]='IF(repoGenHis.expireTime, FROM_UNIXTIME(repoGenHis.expireTime), NULL)';break; case 'addTime': $columnsValuesList[$thisCol]='FROM_UNIXTIME(repoGenHis.addTime)';break; } } $populateTableSQL="INSERT INTO `$reportTable` ( "; $idx=0; foreach($columnsValuesList as $colName=>$colValue) { $idx++; if ($idx>1) $populateTableSQL.=", "; $populateTableSQL.="$colName"; } $populateTableSQL.=") "; $populateTableSQL.="
	SELECT "; $idx=0; foreach($columnsValuesList as $colName=>$colValue) { $idx++; if ($idx>1) $populateTableSQL.=", "; $populateTableSQL.="$colValue"; } $populateTableSQL.="
	FROM `$DBTReportsGenHistory` AS repoGenHis
"; if( $columnsValuesList['idCategory'] || $columnsValuesList['sourceCode'] || $columnsValuesList['name'] || $columnsValuesList['description'] || $columnsValuesList['platformCode'] || $columnsValuesList['formatCode'] || $columnsValuesList['extension'] ){ $populateTableSQL.="
		LEFT JOIN `$DBTReports` AS reports ON
			repoGenHis.`idReport`=reports.`id`
	"; } if($reportFilters['idOffice'] && !$reportFilters['idUser']){ $populateTableSQL.="
		LEFT JOIN `$DBTUsers` AS users ON
			repoGenHis.`idUser`=users.`id`
			AND users.`idOffice`='{$reportFilters['idOffice']}'
	"; } $populateTableSQL.="
	WHERE 1
"; if ( $reportFilters['addTime']['startDate'] ) $populateTableSQL.=" AND repoGenHis.addTime>='".$reportFilters['addTime']['startDateStamp']."'"; if ( $reportFilters['addTime']['endDate'] ) $populateTableSQL.=" AND repoGenHis.addTime<='".$reportFilters['addTime']['endDateStamp']."'"; if($reportFilters['idUser']) $populateTableSQL.=" AND repoGenHis.idUser='{$reportFilters['idUser']}'"; elseif($reportFilters['idOffice']) $populateTableSQL.=" AND users.`id` IS NOT NULL"; refreshReportStatus('extractMainDataFromDb', 'runningMainSQL', 0); $populateTableEx=$db->Execute($populateTableSQL); if ($db->ErrorNo()) { killReport("Could not run report SQL: ".$populateTableSQL); } ?>