Mariusz Muszyński пре 8 година
родитељ
комит
c0d0267658
1 измењених фајлова са 90 додато и 17 уклоњено
  1. 90 17
      SE/se-lib/Route/UrlAction/BiAuditGenerate.php

+ 90 - 17
SE/se-lib/Route/UrlAction/BiAuditGenerate.php

@@ -41,6 +41,16 @@ class Route_UrlAction_BiAuditGenerate extends RouteBase {
 		return $uploader->getDestLocalPath(true);
 	}
 
+	private function getUrl($table, $id) {
+		$folderConf = FoldersConfig::getAll($table.'_COLUMN');
+		$record = new stdClass;
+		$record->ID = $id;
+		$uploader = new FileUploader($table.'_COLUMN', $record);
+		$errMsg = "";
+		if (!$uploader->setConfig($folderConf, $errMsg)) throw new HttpException("Błąd danych konfiguracyjnych<br>\n{$$errMsg}", 404);
+		return $uploader->getFolderWeb() . "/" . $uploader->getDestFolder(true);
+	}
+
 	private function getMainDirectory() {
 		$folderConf = FoldersConfig::getAll('BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_COLUMN');
 		if (!isset($folderConf['mount_point'])) throw new HttpException("Błąd danych konfiguracyjnych<br>\n{$errMsg}", 404);
@@ -234,10 +244,46 @@ function toggle(source) {
 	}
 
 	private function showPowiazania() {
-//		$powiazanieDirLocation = $this->getDirectory('BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA', $this->powiazanie['ID']);
-//		$xmlFile = "{$powiazanieDirLocation}/relations.xml";
-//		echo "<pre>" . htmlentities(file_get_contents($xmlFile)) . "</pre>";
-		echo "Statystyki znalezionych powiązań [TODO]";
+//		echo "Statystyki znalezionych powiązań [TODO]";
+		$dir = $this->getDirectory('BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA', $this->powiazanie['ID']);
+		$pdfFile = "{$dir}/relations.pdf";
+		$htmlFile = "{$dir}/html/relations-{$this->powiazanie['ID']}.html";
+		$htmlZipFile = "{$dir}/html.zip";
+		$url = $this->getUrl('BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA', $this->powiazanie['ID']);
+		$pdfUrl = "{$url}/relations.pdf";
+		$htmlUrl = "{$url}/html/relations-{$this->powiazanie['ID']}.html";
+		$htmlZipUrl = "{$url}/html.zip";
+?>
+<div class="container" style="margin-top:20px">
+  <legend>
+    Wygenerowany raport nr <?=$this->powiazanie['ID']?>
+  </legend>
+  <div class="form-group">
+    <div class="col-sm-12">
+<?php
+		if (file_exists($pdfFile)) {
+?>
+      <a href="<?=$pdfUrl?>" target="_blank" class="btn btn-primary">Pokaż raport PDF</a>
+<?php
+		}
+
+		if (file_exists($htmlFile)) {
+?>
+      <a href="<?=$htmlUrl?>" target="_blank" class="btn btn-primary">Pokaż raport HTML</a>
+<?php
+		}
+
+		if (file_exists($htmlZipFile)) {
+?>
+      <a href="<?=$htmlZipUrl?>" target="_blank" download="Raport <?=$this->powiazanie['ID']?>.zip" class="btn btn-primary">Pobierz raport HTML</a>
+<?php
+		}
+?>
+      <br/><br/><a href="<?=$this->REFERER?>" class="btn btn-default">Powrót</a>
+    </div>
+  </div>
+</div>
+<?php
 	}
 
 	private function showPowiazaniaList() {
@@ -993,6 +1039,9 @@ Router::getRoute("UrlAction_BiAuditGenerate")->' . $function . ';
 				$generatePowiazaniaResultFile = "{$tasksDirLocation}/generatePowiazania-{$row['ID']}.result";
 				$generatePowiazaniaPidFile = "{$tasksDirLocation}/generatePowiazania-{$row['ID']}.pid";
 				$generatePowiazaniaPhpFile = "{$tasksDirLocation}/generatePowiazania-{$row['ID']}.php";
+				$generatePowiazaniaPdfFile = "{$tasksDirLocation}/generatePowiazania-{$row['ID']}.pdf";
+				$generatePowiazaniaHtmlDir = "{$tasksDirLocation}/generatePowiazania-{$row['ID']}.html";
+				$generatePowiazaniaHtmlZipFile = "{$tasksDirLocation}/generatePowiazania-{$row['ID']}.zip";
 				$error = false;
 				$success = false;
 				$sqlArr = [];
@@ -1031,21 +1080,17 @@ Router::getRoute("UrlAction_BiAuditGenerate")->' . $function . ';
 						'FILE_STATUS_info' => 'Poprawnie wygenerowano powiązania',
 					];
 					$destXmlFile = "{$powiazanieDirLocation}/relations.xml";
-					rename($xmlFile, $destXmlFile);
+					$destPdfFile = "{$powiazanieDirLocation}/relations.pdf";
+					$destHtmlDir = "{$powiazanieDirLocation}/html";
+					$destHtmlZipFile = "{$powiazanieDirLocation}/html.zip";
 
-					//ant
-					$antDir = "/Library/Server/Web/Data/Sites/Default/SE/schema/WPS_Functions/default_db/recurse_ant/out";
-					$antFilename = "relations-{$row['ID']}.out_task.dita.final_with_RelatedFeatureLoop.xml";
-					$antFile = $antDir . "/" . $antFilename;
-					$pdfFile = "/Library/Server/Web/Data/Sites/Default/SE/schema/WPS_Functions/default_db/CRM_PROCES_tree/temp/relations-{$row['ID']}/pdf/relations-{$row['ID']}.pdf";
-					$pdfDestFile = "{$powiazanieDirLocation}/relations.pdf";
-					if (!file_exists($antDir)) mkdir($antDir, 0755, true);
-					if (!is_dir($antDir)) $sqlArr['FILE_STATUS_info'] .= ", ale nie udało się utworzyć pliku PDF";
-					else {
-						copy($destXmlFile, $antFile);
-						shell_exec("cd /Library/Server/Web/Data/Sites/Default/SE/schema/WPS_Functions/default_db/CRM_PROCES_tree && ant -f build_CRM_PROCES_tree.xml default_db:PROCES_INIT:tree:dita -Duuid=relations-{$row['ID']}");
-						shell_exec("cd \"{$antDir}\" && /Library/Server/Web/Data/Sites/Default/SE/stuff/dita-ot-2.3.3/bin/dita -o pdf -i relations-{$row['ID']}.ditamap -f pdf");
+					rename($xmlFile, $destXmlFile);
+					if (file_exists($generatePowiazaniaPdfFile)) rename($generatePowiazaniaPdfFile, $destPdfFile);
+					if (file_exists($generatePowiazaniaHtmlDir)) {
+						if (file_exists($destHtmlDir)) shell_exec("rm -rf \"{$destHtmlDir}\"");
+						rename($generatePowiazaniaHtmlDir, $destHtmlDir);
 					}
+					if (file_exists($generatePowiazaniaHtmlZipFile)) rename($generatePowiazaniaHtmlZipFile, $destHtmlZipFile);
 				}
 
 				if ($sqlArr) {
@@ -1305,6 +1350,7 @@ Router::getRoute("UrlAction_BiAuditGenerate")->' . $function . ';
 		$tasksDirLocation = $powiazaniaDirLocation . "/.tasks";
 		$resultFile = "{$tasksDirLocation}/generatePowiazania-{$ID}.result";
 		$xmlFile = "{$tasksDirLocation}/generatePowiazania-{$ID}.xml";
+		$pdfFile = "{$tasksDirLocation}/generatePowiazania-{$ID}.pdf";
 		$pidFile = "{$tasksDirLocation}/generatePowiazania-{$ID}.pid";
 		file_put_contents($pidFile, getmypid());
 
@@ -1326,6 +1372,7 @@ Router::getRoute("UrlAction_BiAuditGenerate")->' . $function . ';
 			if (!$BiAuditPowiazania->powiazaniaFound()) throw new Exception("Nie znaleziono żadnych powiązań");
 			file_put_contents($xmlFile, $BiAuditPowiazania->asXml());
 			$BiAuditPowiazania->saveToDb();
+			$BiAuditPowiazania->generatePdfAndHtml($tasksDirLocation);
 /*			$powiazania = $BiAuditPowiazania->asArray('BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA');
 			if (!$powiazania) return false;
 			DB::getPDO()->query($query);
@@ -1643,4 +1690,30 @@ class BiAuditPowiazania {
 		if ($this->results) return true;
 		else return false;
 	}
+
+	public function generatePdfAndHtml($tasksDirLocation) {
+		$xmlFile = "{$tasksDirLocation}/generatePowiazania-{$this->ID}.xml";
+		$pdfDestFile = "{$tasksDirLocation}/generatePowiazania-{$this->ID}.pdf";
+		$htmlDestDir = "{$tasksDirLocation}/generatePowiazania-{$this->ID}.html";
+		$htmlZipDestFile = "{$tasksDirLocation}/generatePowiazania-{$this->ID}.zip";
+		$antDir = "/Library/Server/Web/Data/Sites/Default/SE/schema/WPS_Functions/default_db/recurse_ant/out";
+		$antXmlFilename = "relations-{$this->ID}.out_task.dita.final_with_RelatedFeatureLoop.xml";
+		$antXmlFile = $antDir . "/" . $antXmlFilename;
+		$pdfFile = "/Library/Server/Web/Data/Sites/Default/SE/schema/WPS_Functions/default_db/CRM_PROCES_tree/temp/relations-{$this->ID}/pdf/relations-{$this->ID}.pdf";
+		$htmlDir = "/Library/Server/Web/Data/Sites/Default/SE/schema/WPS_Functions/default_db/CRM_PROCES_tree/temp/relations-{$this->ID}/html";
+		if (!file_exists($antDir)) mkdir($antDir, 0755, true);
+		if (!is_dir($antDir)) $sqlArr['FILE_STATUS_info'] .= ", ale nie udało się utworzyć pliku PDF";
+		else {
+			copy($xmlFile, $antXmlFile);
+			shell_exec("cd /Library/Server/Web/Data/Sites/Default/SE/schema/WPS_Functions/default_db/CRM_PROCES_tree && /opt/local/bin/ant -f build_CRM_PROCES_tree.xml default_db:PROCES_INIT:tree:dita -Duuid=relations-{$this->ID}");
+			shell_exec("cd \"/Library/Server/Web/Data/Sites/Default/SE/schema/WPS_Functions/default_db/CRM_PROCES_tree/temp/relations-{$this->ID}\" && /Library/Server/Web/Data/Sites/Default/SE/stuff/dita-ot-2.3.3/bin/dita -o pdf -i relations-{$this->ID}.ditamap -f pdf");
+			if (file_exists($pdfFile)) rename($pdfFile, $pdfDestFile);
+			shell_exec("cd \"/Library/Server/Web/Data/Sites/Default/SE/schema/WPS_Functions/default_db/CRM_PROCES_tree/temp/relations-{$this->ID}\" && /Library/Server/Web/Data/Sites/Default/SE/stuff/dita-ot-2.3.3/bin/dita -o html -i relations-{$this->ID}.ditamap -f tocjs");
+			if (file_exists($htmlDir) && is_dir($htmlDir)) {
+				shell_exec("cd \"/Library/Server/Web/Data/Sites/Default/SE/schema/WPS_Functions/default_db/CRM_PROCES_tree/temp/relations-{$this->ID}\" && zip -r \"{$htmlZipDestFile}\" html");
+				if (file_exists($htmlDestDir)) shell_exec("rm -rf \"{$htmlDestDir}\"");
+				shell_exec("mv \"{$htmlDir}\" \"{$htmlDestDir}\"");
+			}
+		}
+	}
 }