GapsXmlController.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703
  1. <?php
  2. require_once(dirname(__FILE__).'/GapsXmlInfoController.php');
  3. require_once(dirname(__FILE__).'/PowerplayController.php');
  4. require_once(dirname(__FILE__).'/MailController.php');
  5. require_once(dirname(__FILE__).'/../models/Logfile.php');
  6. class GapsXmlController
  7. {
  8. /** @var string */
  9. private $today;
  10. private $generateTypes;
  11. private $flagSeperateMail = false;
  12. private $flagSendMail = true;
  13. private $flagGenImages = true;
  14. /** @var string */
  15. private $publishImagePath;
  16. /** @var string */
  17. private $reportPath;
  18. /** @var PowerplayController */
  19. private $pprCtrl;
  20. private $cubePath;
  21. private $mailController;
  22. public static function Run ($argv)
  23. {
  24. $config = parse_ini_file(dirname(__FILE__) . "/../../../GAPS.ini");
  25. if ($argv[1] == "generate") {
  26. GapsXmlController::Generate($config, $argv);
  27. } else if ($argv[1] == "cube-pfad") {
  28. GapsXmlController::UpdateCubePath($config, $argv[2]);
  29. } else {
  30. GapsXmlController::Duration($config, $argv);
  31. }
  32. }
  33. public static function Generate ($config, $argv)
  34. {
  35. if (count($argv) < 3) {
  36. die("Aufruf: php Tools\\generate.php generate GAPS.xml [Benutzer,Mails] [Cubes]");
  37. }
  38. $gapsXmlCtrl = new GapsXmlController($config);
  39. $xml = $argv[2];
  40. if (count($argv) > 3 && ($argv[3] == "mail" || $argv[3] == "pdf")) {
  41. $gapsXmlCtrl->setAction($argv[3]);
  42. array_shift($argv);
  43. }
  44. $userFilter = (count($argv) > 3 && $argv[3] != "") ? explode(",", strtolower($argv[3])) : array("*");
  45. $cubeFilter = (count($argv) > 4 && $argv[4] != "") ? explode(",", strtolower($argv[4])) : array("*");
  46. $gapsXmlCtrl->generateAll($xml, $userFilter, $cubeFilter);
  47. }
  48. public static function Duration ($config, $argv)
  49. {
  50. if (count($argv) < 3) {
  51. die("Aufruf: php Tools\\generate.php [duration|summary] GAPS.xml Logdatei");
  52. }
  53. $action = $argv[1];
  54. $newStructure = (substr($action, -1) != "2");
  55. $xml = $argv[2];
  56. $xmlInfo = pathinfo($xml);
  57. $xmlBasename = $xmlInfo['basename'];
  58. $errorLog = (count($argv) > 3) ? $argv[3] : realpath(dirname(__FILE__) . "\\..\\..\\logs\\" . $xmlBasename . ".log");
  59. $gapsXmlCtrl = new GapsXmlController($config);
  60. switch ($action) {
  61. case "duration":
  62. case "duration2":
  63. $xmlBasename = substr($xmlBasename, 0, -4);
  64. $durationFilename = $gapsXmlCtrl->getPublishImagePath($xml) . $xmlBasename . "\\duration.txt";
  65. if (file_exists($durationFilename)) {
  66. $split = explode(";", file_get_contents($durationFilename));
  67. $runtime = date("d.m.Y H:i", $split[0]);
  68. $duration = ceil(($split[1] - $split[0]) / 60);
  69. $estimate = date("H:i", strtotime("now") + $duration * 60);
  70. echo "Letzte Laufzeit: {$runtime}\r\n";
  71. echo "Geschaetzte Dauer: {$duration} Minuten\r\n";
  72. echo "Geschaetztes Ende: {$estimate}\r\n";
  73. } else {
  74. echo "Letzte Laufzeit: unbekannt\r\n";
  75. }
  76. break;
  77. case "summary":
  78. case "summary2":
  79. default:
  80. $result = $gapsXmlCtrl->getStatistics($xml, $newStructure);
  81. file_put_contents($errorLog, json_encode($result));
  82. if (count($result['errors']) > 0) {
  83. echo "Fehlerhafte Dateien (". count($result['errors']) . "):\r\n";
  84. foreach ($result['errors'] as $e) {
  85. echo $e . "\r\n";
  86. }
  87. echo "\r\nDetails: " . $errorLog ."\r\n";
  88. }
  89. break;
  90. }
  91. }
  92. public static function Summary ($config, $argv) {
  93. GapsXmlController::Duration($config, $argv);
  94. }
  95. public static function UpdateCubePath ($config, $xmlFile) {
  96. $gapsXmlCtrl = new GapsXmlController($config);
  97. $gapsXmlCtrl->changeCubePath($xmlFile);
  98. return;
  99. }
  100. public function __construct ($config)
  101. {
  102. $this->today = strtotime("now") - 12 * 60 * 60;
  103. $this->generateTypes = array(".gif" => "GIFGenerate", ".pdf" => "PDFGenerate", ".xls" => "XLSGenerate"); //".jpg" => "JPGGenerate",
  104. $this->flagSeperateMail = (isset($config['VERSAND_SEPARAT']) && $config['VERSAND_SEPARAT'] != "N");
  105. $this->mailController = new MailController($config);
  106. }
  107. public function setAction ($flag) {
  108. $this->flagGenImages = ($flag != "mail");
  109. $this->flagSendMail = ($flag != "pdf");
  110. }
  111. public function getPublishImagePath ($xml)
  112. {
  113. $xmlInfo = pathinfo($xml);
  114. $xmlBasename = str_replace(".xml", "", $xmlInfo['basename']);
  115. $doc = simplexml_load_string(file_get_contents($xml));
  116. return (string)$doc->General->PublishImagePath;
  117. }
  118. public function getStatistics ($xml, $newFile = true)
  119. {
  120. $xmlInfo = pathinfo($xml);
  121. $xmlBasename = str_replace(".xml", "", $xmlInfo['basename']);
  122. $doc = simplexml_load_string(file_get_contents($xml));
  123. $gxiCtrl = new GapsXmlInfoController();
  124. $reports = $gxiCtrl->getExistingReportFiles($xmlBasename, $doc);
  125. date_default_timezone_set('UTC');
  126. $startTime = 0;
  127. $time = 0;
  128. $duration = "00:01:00";
  129. $result = array('errors' => array(), 'sources' => array(), 'summary' => null);
  130. $this->publishImagePath = (string)$doc->General->PublishImagePath;
  131. $reportPath = (string)$doc->General->ReportPath;
  132. foreach ($doc->Publishes->Publish as $publish) {
  133. /** @var SimpleXMLElement $publish */
  134. $attr = $publish->attributes();
  135. foreach ($publish->Images->Image as $image) {
  136. if ($newFile) {
  137. $pprName = (string)$image->Report;
  138. if (preg_match("/_graf/is", $pprName)) {
  139. $pprName = substr($pprName, 0, -5);
  140. }
  141. $dat = $this->publishImagePath . $xmlBasename . "\\" . $pprName . "_";
  142. } else {
  143. $dat = $this->publishImagePath . (string)$image->Directory . (string)$attr->Name . "\\" . (string)$image->Name;
  144. }
  145. $reportFile = $reportPath . (string)$image->Report;
  146. if (!file_exists($reportFile . ".ppx")) {
  147. $reportFile .= ".ppr";
  148. } else {
  149. $reportFile .= ".ppx";
  150. }
  151. if (stripos($reportFile, "_graf") && !file_exists($reportFile)) {
  152. continue;
  153. }
  154. foreach ($this->generateTypes as $extension => $value) {
  155. if ((string)$image->$value != "J")
  156. continue;
  157. $layer = ($extension == ".pdf") ? (string)$image->PDFImageLayer : (string)$image->ImageLayer;
  158. if ($newFile) {
  159. if ($extension == ".gif") {
  160. if ($layer == 0) {
  161. $layer = 1;
  162. }
  163. $imageFile = $dat . $layer . ".jpg";
  164. $imageFileUtf8 = utf8_decode($imageFile);
  165. } else {
  166. $imageFile = $dat . $layer . $extension;
  167. $imageFileUtf8 = utf8_decode($imageFile);
  168. }
  169. } else {
  170. $imageFile = $dat . $extension;
  171. $imageFileUtf8 = utf8_decode($imageFile);
  172. }
  173. if (file_exists($imageFileUtf8)) {
  174. if ($startTime > 0) {
  175. if (intval(filemtime($imageFileUtf8)) > $time) {
  176. $duration = date("H:i:s", intval(filemtime($imageFileUtf8)) - $time);
  177. }
  178. } else {
  179. $startTime = intval(filemtime($imageFileUtf8));
  180. }
  181. $time = intval(filemtime($imageFileUtf8));
  182. }
  183. if (!file_exists($imageFileUtf8) || filemtime($imageFileUtf8) < $this->today) {
  184. //$duration = (file_exists($imageFileUtf8)) ? "alt" : "fehlt";
  185. $modified = (file_exists($imageFileUtf8)) ? date("d.m.Y H:i", filemtime($imageFileUtf8)) : "fehlt";
  186. $newError = new WorkflowError();
  187. $newError->Filename = $imageFile;
  188. $newError->User = substr((string)$image->Directory, 0, -1);
  189. $newError->Report = (string)$image->Report;
  190. $newError->ReportModified = (file_exists($reportFile)) ? date("d.m.Y H:i", filemtime($reportFile)) : "fehlt";
  191. $newError->Cube = (isset($reports[$newError->Report])) ? $reports[$newError->Report] : "";
  192. $newError->Layer = $layer;
  193. $newError->MailTo = (string)$image->Email;
  194. $newError->Modified = $modified;
  195. $result['errors'][] = $newError;
  196. }
  197. $source = new Source($imageFile);
  198. $source->Report = (string)$image->Report;
  199. $source->Layer = $layer;
  200. $source->Duration = $duration;
  201. $result['sources'][] = $source;
  202. /*
  203. <Name>1.2 Kostenstellenbericht aktueller Monat</Name>
  204. <Description>Kostenstellenbericht aktueller Monat</Description>
  205. <Directory>Global1\</Directory>
  206. <Report>1_2_Kostenstellenbericht_aktueller_Monat_Graf</Report>
  207. <GIFGenerate>J</GIFGenerate>
  208. <JPGGenerate>N</JPGGenerate>
  209. <PDFGenerate>N</PDFGenerate>
  210. <XLSGenerate>N</XLSGenerate>
  211. <Active>N</Active>
  212. <SendEmail>N</SendEmail>
  213. <ImageType>0</ImageType>
  214. <ImageLayer>0</ImageLayer>
  215. <PDFImageType>0</PDFImageType>
  216. <PDFImageLayer>0</PDFImageLayer>
  217. <Ansicht>Client</Ansicht>
  218. <Email />
  219. <ppx>N</ppx>
  220. */
  221. }
  222. }
  223. }
  224. $result['summary'] = new Summary(count($result['sources']), floor(($time - $startTime) / 60) + 1);
  225. $result['summary']->Duration = date("H:i:s", $time - $startTime);
  226. date_default_timezone_set('Europe/Berlin');
  227. return $result;
  228. }
  229. public function generateAll ($xmlFile, $userFilter, $cubeFilter)
  230. {
  231. $doc = $this->readXmlFile($xmlFile);
  232. $xmlShortFileName = substr(basename($xmlFile), 0, -4);
  233. $this->publishImagePath = (string)$doc->General->PublishImagePath . $xmlShortFileName . "\\";
  234. $this->pprCtrl = new PowerplayController($this->publishImagePath);
  235. $this->cubePath = (string)$doc->General->CubePath;
  236. $this->reportPath = (string)$doc->General->ReportPath;
  237. $reportMapping = $this->getReportMapping($doc, $userFilter, $cubeFilter);
  238. $startTime = strtotime("now");
  239. if ($this->flagGenImages) {
  240. $this->generateImages($reportMapping['report']);
  241. }
  242. if ($this->flagSendMail) {
  243. $this->sendMails($reportMapping['mail'], $xmlShortFileName);
  244. }
  245. $scorecardMapping = $this->getScorecardMapping($doc);
  246. if (count($scorecardMapping['report']) > 0) {
  247. $sc = $this->generateScorecards($scorecardMapping);
  248. $this->saveScorecards($sc);
  249. }
  250. $endTime = strtotime("now");
  251. file_put_contents($this->publishImagePath . "duration.txt", $startTime . ";" . $endTime);
  252. }
  253. public function changeCubePath ($xmlFile)
  254. {
  255. $doc = $this->readXmlFile($xmlFile);
  256. $this->cubePath = (string)$doc->General->CubePath;
  257. $this->reportPath = (string)$doc->General->ReportPath;
  258. $this->publishImagePath = (string)$doc->General->PublishImagePath;
  259. $this->pprCtrl = new PowerplayController($this->publishImagePath);
  260. $gxiCtrl = new GapsXmlInfoController();
  261. $reports = $gxiCtrl->getExistingReportFiles("1", $this->reportPath, false, "");
  262. $reportMapping = $this->getReportMapping($doc);
  263. // $reportMapping['report'][$report][$extension] = 1
  264. foreach($reportMapping['report'] as $report => $reportArray) {
  265. $ppxFile = $this->reportPath . $report . ".ppx";
  266. $pprFile = $this->reportPath . $report . ".ppr";
  267. if (file_exists($ppxFile)) {
  268. $this->changeCubePathInFile($ppxFile);
  269. } else if (file_exists($ppxFile)) {
  270. if ($this->pprCtrl->OpenReport($pprFile, $this->cubePath . $reports[$report] . "mdc")) {
  271. $this->pprCtrl->Save();
  272. $this->pprCtrl->CloseReport();
  273. }
  274. }
  275. }
  276. }
  277. private function saveScorecards ($sc)
  278. {
  279. foreach($sc['data'] as $user => $userArray) {
  280. $xml = simplexml_load_string('<?xml version="1.0" encoding="iso-8859-1"?><Daten />');
  281. foreach ($userArray as $id => $idArray) {
  282. $cat = $xml->addChild("Kategorie");
  283. /** @var SimpleXMLElement $cat */
  284. $cat->addAttribute("ID", $id);
  285. $cat->addChild("Publish");
  286. $cat->addChild("Scorecards");
  287. foreach ($idArray as $e) {
  288. $entry = $cat->Scorecards->addChild("Bericht");
  289. /** @var SimpleXMLElement $entry */
  290. $scorecard = $sc['report'][$e[0]][$e[1]][$e[2]];
  291. foreach ($scorecard as $key => $value) {
  292. $entry->addChild($key, $value);
  293. }
  294. }
  295. }
  296. $xml->asXML($this->publishImagePath . $user . ".xml");
  297. }
  298. /*
  299. $header = array("Report","Zeile","Spalte","Datum","Wert");
  300. $recentFile = $this->publishImagePath . "recent.csv";
  301. $scFile = $this->publishImagePath . "scorecards.csv";
  302. $handle = fopen($recentFile, "w+");
  303. fwrite($handle, implode(";", $header) . "\r\n");
  304. foreach ($sc as $row) {
  305. fwrite($handle, implode(";", $row) . "\r\n");
  306. }
  307. fclose($handle);
  308. if (!file_exists($scFile)) {
  309. array_unshift($sc, $header);
  310. }
  311. $handle = fopen($scFile, "a+");
  312. foreach ($sc as $row) {
  313. fwrite($handle, implode(";", $row) . "\r\n");
  314. }
  315. fclose($handle);
  316. */
  317. }
  318. public function getScorecardMapping($doc)
  319. {
  320. $result = array('report' => array(), 'data' => array());
  321. foreach ($doc->Scorecards->Scorecard as $sc) {
  322. /** @var SimpleXMLElement $sc */
  323. $attr = $sc->attributes();
  324. $id = (string)$attr->ID;
  325. $user = substr((string)$attr->Directory, 0, -1);
  326. // $category = (string)$attr->Name;
  327. foreach ($sc->Reports->Report as $cell) {
  328. $report = trim((string)$cell->ReportFile);
  329. $row = (string)$cell->RowData;
  330. $col = (string)$cell->ColData;
  331. $format = (string)$cell->Format;
  332. $result['report'][$report][$row][$col] = array(
  333. 'Titel' => (string)$cell->Name,
  334. 'Beschreibung' => (string)$cell->Description,
  335. 'Wert' => 0,
  336. 'Grafik' => (string)$cell->ReportFile,
  337. 'URL' => "",
  338. 'Format' => $format,
  339. 'HoherZielwert' => (string)$cell->HoherZielwert,
  340. 'NiedrigerWert' => (string)$cell->LowValue,
  341. 'HoherWert' => (string)$cell->HighValue,
  342. 'Koordinaten' => $row . "|" . $col,
  343. 'Toleranz' => (string)$cell->Tolerance,
  344. 'Gewichtung' => (string)$cell->Weight,
  345. 'Akkumulation' => 0,
  346. 'Email' => "",
  347. 'InfoURL' => ""
  348. );
  349. $result['data'][$user][$id][] = array($report, $row, $col);
  350. /* Quelle
  351. <Scorecard ID="36420" Directory="Global1\" Name="_4._Service_">
  352. <Reports>
  353. <Report ID="88670">
  354. <Name>Ergebnis Prognose Monat Service Hannuschka</Name>
  355. <Description>Ergebnis Prognose Monat Service Hannuschka</Description>
  356. <Active>J</Active>
  357. <ReportFile>Prog_Monat_Soll_Ist_Service</ReportFile>
  358. <RowData>1</RowData>
  359. <ColData>18</ColData>
  360. <HoherZielwert>J</HoherZielwert>
  361. <LowValue>0.9</LowValue>
  362. <HighValue>1.0</HighValue>
  363. <Tolerance>0</Tolerance>
  364. <Format>Prozent</Format>
  365. <Weight>0</Weight>
  366. <MonthlyAccumulate>N</MonthlyAccumulate>
  367. <Email/>
  368. <InfoURL/>
  369. */
  370. /*
  371. <Daten>
  372. <_1._Gesamtbetrieb_ ID="36420">
  373. <Scorecards>
  374. <Bericht>
  375. <Titel>Prognose Ergebnis Gesamt</Titel>
  376. <Beschreibung></Beschreibung>
  377. <Wert>109,14 %</Wert>
  378. <Grafik>images/</Grafik>
  379. <URL><![CDATA[http://10.6.174.10/GAPS_BMW/Report/1_15_Monatsprognose]]></URL>
  380. <HoherZielwert>J</HoherZielwert>
  381. <NiedrigerWert>90 %</NiedrigerWert>
  382. <HoherWert>100 %</HoherWert>
  383. <Koordinaten>1|15</Koordinaten>
  384. <Toleranz>0</Toleranz>
  385. <Gewichtung>0</Gewichtung>
  386. <Akkumulation>N</Akkumulation>
  387. <Email>hotline@freicon.de</Email>
  388. <InfoURL>www.freicon.de</InfoURL>
  389. </Bericht>
  390. */
  391. }
  392. }
  393. return $result;
  394. }
  395. private function readXmlFile ($xmlFile)
  396. {
  397. if (!file_exists($xmlFile)) {
  398. throw new InvalidArgumentException("File '{$xmlFile}' not found");
  399. }
  400. return simplexml_load_string(file_get_contents($xmlFile));
  401. }
  402. /**
  403. * @param SimpleXMLElement $doc
  404. * @param array $userFilter
  405. * @param array $cubeFilter
  406. * @return array
  407. */
  408. public function getReportMapping ($doc, $userFilter = array("*"), $cubeFilter = array("*"))
  409. {
  410. $result = array('report' => array(), 'mail' => array());
  411. $infoCtrl = new GapsXmlInfoController();
  412. $reportCubes = array();
  413. if ($cubeFilter[0] != "*") {
  414. $reportCubes = $infoCtrl->getExistingReportFiles("", $doc, false);
  415. }
  416. $flagMailFilter = ($userFilter[0] != "*" && preg_match("/.*@.*\.\w+/", $userFilter[0]));
  417. foreach ($doc->Publishes->Publish as $publish) {
  418. /** @var SimpleXMLElement $publish */
  419. foreach ($publish->Images->Image as $image) {
  420. $user = substr((string)$image->Directory, 0, -1);
  421. $mailAddresses = explode(";", strtolower((string)$image->Email));
  422. foreach ($mailAddresses as $i => $mailAddress) {
  423. $mailAddresses[$i] = trim($mailAddress);
  424. }
  425. if ($flagMailFilter) {
  426. $mailAddresses = array_intersect($mailAddresses, $userFilter);
  427. if (count($mailAddresses) == 0) {
  428. continue;
  429. }
  430. }
  431. $report = trim((string)$image->Report);
  432. if ($cubeFilter[0] != "*" && isset($reportCubes[$report]) && !in_array($reportCubes[$report], $cubeFilter)) {
  433. continue;
  434. }
  435. foreach ($this->generateTypes as $extension => $generateImageType) {
  436. if ((string)$image->$generateImageType != "J")
  437. continue;
  438. $desc = utf8_decode((string)$image->Description);
  439. $layer = ($extension == ".pdf") ? (string)$image->PDFImageLayer : (string)$image->ImageLayer;
  440. $imageFile = utf8_decode("{$report}_{$layer}{$extension}");
  441. $result['report'][$report][$extension][$layer] = 1;
  442. if ((string)$image->SendEmail == "J") {
  443. foreach ($mailAddresses as $mailAddress) {
  444. $result['mail'][$mailAddress][$this->publishImagePath.$imageFile] = array($desc, $mailAddresses);
  445. }
  446. }
  447. }
  448. }
  449. }
  450. return $result;
  451. }
  452. private function generateImages ($reportMapping)
  453. {
  454. // $reportMapping[$report][$extension] = 1
  455. foreach($reportMapping as $report => $reportArray) {
  456. try {
  457. if (!$this->openReport($this->reportPath . $report)) {
  458. continue;
  459. }
  460. if (isset($reportArray['.jpg'])) {
  461. $this->pprCtrl->PublishImages();
  462. }
  463. if (isset($reportArray['.gif'])) {
  464. $this->pprCtrl->PublishImages();
  465. }
  466. if (isset($reportArray['.pdf'])) {
  467. $this->pprCtrl->SaveAsPdf("", array_keys($reportArray['.pdf']));
  468. }
  469. if (isset($reportArray['.xls'])) {
  470. $this->pprCtrl->SaveAsXls();
  471. }
  472. $this->pprCtrl->CloseReport();
  473. } catch (Exception $e) {
  474. echo "Could not export file '" . $report . "'\r\n";
  475. echo $e->getMessage() . "\r\n";
  476. }
  477. }
  478. }
  479. public function generateScorecards ($scorecardMapping)
  480. {
  481. $result = array();
  482. $now = date("Y-m-d");
  483. // $scorecardMapping[$report][$row][$column] = 1
  484. foreach($scorecardMapping['report'] as $report => $reportArray) {
  485. if (!$this->openReport($this->reportPath . $report)) {
  486. continue;
  487. }
  488. foreach ($reportArray as $row => $rowArray) {
  489. foreach ($rowArray as $col => $v) {
  490. $currentValue = $this->pprCtrl->GetCellValue($row, $col);
  491. $result[] = array(
  492. 'report' => $report,
  493. 'row' => $row,
  494. 'column' => $col,
  495. 'date' => $now,
  496. 'value' => $currentValue
  497. );
  498. $scorecardMapping['report'][$report][$row][$col]['Wert'] = $currentValue;
  499. }
  500. }
  501. $this->pprCtrl->CloseReport();
  502. }
  503. return $scorecardMapping;
  504. }
  505. private function openReport ($report)
  506. {
  507. $ppxFile = $report . ".ppx";
  508. $pprFile = $report . ".ppr";
  509. if (!file_exists($ppxFile)) {
  510. if (!file_exists($pprFile)) {
  511. return false;
  512. }
  513. $this->pprCtrl->OpenReport($pprFile);
  514. // $this->pprCtrl->SaveAsPpx();
  515. } else {
  516. $this->changeCubePathInFile($ppxFile);
  517. $this->pprCtrl->OpenReport($ppxFile);
  518. }
  519. return true;
  520. }
  521. public function changeCubePathInFile ($ppxFile)
  522. {
  523. $doc = simplexml_load_file($ppxFile);
  524. /** @var SimpleXMLElement $attr */
  525. $attr = $doc->PowerPlayReport->PPDSConnection->attributes();
  526. if ($this->cubePath != (string)$attr->Path) {
  527. $attr->Path = $this->cubePath;
  528. $doc->saveXML($ppxFile);
  529. }
  530. }
  531. public function getXmlFileParameters ($xmlFile)
  532. {
  533. $doc = $this->readXmlFile($xmlFile);
  534. $infoCtrl = new GapsXmlInfoController();
  535. $reportCubes = $infoCtrl->getExistingReportFiles("", $doc, false);
  536. $reportMapping = $this->getReportMapping($doc);
  537. $reports = array();
  538. $users = array();
  539. $mails = array();
  540. // $reportMapping[$extension][$report][$layer][$user] = ($file, $mail)
  541. foreach ($reportMapping as $ext => $extArray) {
  542. foreach($extArray as $report => $reportArray) {
  543. foreach ($reportArray as $layerArray) {
  544. foreach ($layerArray as $user => $userArray) {
  545. if ($ext != '.gif') {
  546. $reports[$report] = @$reportCubes[$report];
  547. }
  548. $users[$user] = 1;
  549. $m = array_flip(explode(";", $userArray['mail']));
  550. $mails = array_merge($mails, $m);
  551. }
  552. }
  553. }
  554. }
  555. return array('users' => array_keys($users), 'mails' => array_keys($mails), 'cubes' => array_unique(array_values($reports)), 'reports' => array_keys($reports));
  556. }
  557. private function sendMails ($reportMapping, $xmlFile)
  558. {
  559. $xmlFile = str_replace("_", " ", $xmlFile);
  560. $xmlFile = preg_replace("/gaps/i", "GAPS", $xmlFile);
  561. // $reportMapping[$mailAddress][$image] = array($desc, $mailAddresses);
  562. foreach ($reportMapping as $mailAddress => $image) {
  563. if ($mailAddress == "") continue;
  564. echo $mailAddress . "\r\n";
  565. if (!preg_match("/^[a-z0-9_.+-]+@[a-z0-9-]+\.[a-z0-9-.]+$/i", $mailAddress)) {
  566. echo "Keine gueltige E-Mail-Adresse!\r\n";
  567. continue;
  568. }
  569. if ($this->flagSeperateMail) {
  570. foreach ($image as $filename => $desc) {
  571. if (file_exists($filename) && abs(filemtime($filename) - strtotime("now")) < 24 * 60 * 60) {
  572. $sourceFile = "";
  573. preg_match("/(.*)_(\d+)\.\w{3}/", basename($filename), $sourceFile);
  574. $imageFile = $desc[0] . substr($filename, -4);
  575. $imageDate = date("d.m.Y H:i", filemtime($filename));
  576. $attachments = array(realpath($filename), $imageFile);
  577. $descriptions = "<tr><td>{$imageFile}</td><td>{$sourceFile[1]}</td><td>{$sourceFile[2]}</td><td>{$imageDate}</td><td>" . implode("<br/>", $desc[1]) . "</td></tr>";
  578. $this->mailController->sendMail($mailAddress, $desc[0], $this->getMailBody($descriptions), "", array($attachments));
  579. }
  580. }
  581. } else {
  582. $attachments = array();
  583. $descriptions = array();
  584. foreach ($image as $filename => $desc) {
  585. $sourceFile = "";
  586. preg_match("/(.*)_(\d+)\.\w{3}/", basename($filename), $sourceFile);
  587. $imageFile = $desc[0] . substr($filename, -4);
  588. $imageDate = "Heute nicht verf&uuml;gbar.";
  589. if (file_exists($filename) && abs(filemtime($filename) - strtotime("now")) < 24 * 60 * 60) {
  590. $attachments[] = array(realpath($filename), $imageFile);
  591. $imageDate = date("d.m.Y H:i", filemtime($filename));
  592. }
  593. $descriptions[] = "<tr><td>{$imageFile}</td><td>{$sourceFile[1]}</td><td>{$sourceFile[2]}</td><td>{$imageDate}</td><td>" . implode("<br/>", $desc[1]) . "</td></tr>";
  594. }
  595. $count = count($attachments);
  596. $subject = ($count != 1) ? "{$xmlFile}: {$count} Dateien" : $desc[0];
  597. $this->mailController->sendMail($mailAddress, $subject, $this->getMailBody(implode("\r\n", $descriptions)), "", $attachments);
  598. }
  599. }
  600. }
  601. private function getMailBody ($content) {
  602. return "<!DOCTYPE html>\r\n" .
  603. "<html><head>\r\n" .
  604. '<meta content="text/html; charset=utf-8" http-equiv="Content-Type"><style>' .
  605. "\r\n.liste { border: 1px solid #888888; border-collapse: collapse; } \r\n" .
  606. ".liste td, .liste th { padding: 3px 15px; border: 1px solid #888888; } \r\n" .
  607. "</style></head><body>\r\n" .
  608. '<table class="liste"><tr><th>Datei</th><th>Bericht</th><th>Schicht</th><th>Stand</th><th>Empf&auml;nger</th></tr>' .
  609. $content .
  610. "</table></body></html>";
  611. }
  612. }
  613. ?>