Dita.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. Lib::loadClass('RouteBase');
  3. Lib::loadClass('UI');
  4. Lib::loadClass('DBG');
  5. /**
  6. * Executes ant build for dita file - creates pdf file
  7. * - ant build in SE/schema/dita/{object_namespace_to_file_path}/{function_name}/build.xml
  8. */
  9. class Route_Dita extends RouteBase {
  10. public function defaultAction() {
  11. // Expected Result:
  12. // ...
  13. // [echo] OUTPUT_PDF_FILE: out/null1293984876.pdf
  14. //
  15. // BUILD SUCCESSFUL
  16. // ...
  17. UI::gora();
  18. UI::tag('h1', [], 'Dita');
  19. $ditaList = $this->getDitaFunctionList();
  20. DBG::_(true, true, "\$ditaList", $ditaList, __CLASS__, __FUNCTION__, __LINE__);
  21. UI::startTag('ul');
  22. UI::startTag('li');
  23. UI::tag('a', ['href'=>"index.php?_route=Dita&_task=reinstall"], "Reinstall");
  24. UI::endTag('li');
  25. foreach ($ditaList as $ditaPath => $label) {
  26. $link = "index.php?_route=Dita&_task=generatePdf&ditaPath={$ditaPath}";
  27. UI::startTag('li');
  28. UI::tag('a', ['href'=>$link], $label);
  29. UI::endTag('li');
  30. }
  31. UI::endTag('ul');
  32. }
  33. public function getDitaFunctionList() {
  34. return [
  35. 'default_db-in7_dziennik_koresp/test-druk' => "Test Koresp Dita Druk PDF"
  36. ];
  37. }
  38. public function generatePdfAction() {
  39. $ditaPath = V::get('ditaPath', '', $_GET);
  40. $idKoresp = V::get('idKoresp', 0, $_POST, 'int');
  41. $doExecute = V::get('doExecute', '', $_POST);
  42. $ditaList = $this->getDitaFunctionList();
  43. if (!array_key_exists($ditaPath, $ditaList)) throw new Exception("dita path not found", 404);
  44. UI::gora();
  45. UI::startContainer();
  46. try {
  47. UI::tag('h1', [], "Dita: '{$ditaList[$ditaPath]}'");
  48. UI::startTag('form', ['action'=>"", 'method'=>"POST", 'class'=>'form-inline']);
  49. UI::tag('input', ['type'=>'number', 'value'=>$idKoresp, 'class'=>'form-control', 'style'=>'max-width:200px']);
  50. UI::tag('input', ['type'=>'hidden', 'name'=>'doExecute', 'value'=>'1']);
  51. UI::tag('input', ['type'=>"submit", 'value'=>"Wykonaj", 'class'=>'btn btn-primary']);
  52. UI::endTag('form');
  53. if ($doExecute) {
  54. // if ($idKoresp <= 0) throw new Exception("Bad Request - missing id koresp");
  55. if ($idKoresp <= 0) UI::alert('danger', "Missing id koresp - using default file");
  56. if ($idKoresp > 0) UI::alert('warning', "TODO: generate xml file for id koresp = {$idKoresp}");
  57. $execPath = APP_PATH_SCHEMA . DS . 'dita' . DS . $ditaPath;
  58. $ant = APP_PATH_WWW . DS . 'stuff' . DS . 'dita-ot-2.3.3' . DS . 'bin' . DS . 'ant';
  59. $cmd = "cd {$execPath} && {$ant} 2>&1";// wymaga java jdk
  60. V::exec($cmd, $out, $ret);
  61. DBG::_(true, true, "cmd: {$cmd} (return: {$ret})", $out, __CLASS__, __FUNCTION__, __LINE__);
  62. }
  63. throw new Exception("TODO: F." . __FUNCTION__ . " . L." . __LINE__);
  64. } catch (Exception $e) {
  65. UI::alert('danger', $e->getMessage());
  66. }
  67. UI::endContainer();
  68. UI::dol();
  69. }
  70. public function reinstallAction() {
  71. UI::gora();
  72. UI::tag('h1', [], 'Reinstall Dita Open Toolkit 2.3.3');
  73. $stuffPath = APP_PATH_WWW . DS . 'stuff';
  74. // $cmd[]['rsh']="cd /Library/Server/Web/Data/Sites/Default/SE/stuff && rm dita-ot-2.3.3.zip || echo PASSED";
  75. // $cmd[]['rsh']="cd /Library/Server/Web/Data/Sites/Default/SE/stuff && wget https://github.com/dita-ot/dita-ot/releases/download/2.3.3/dita-ot-2.3.3.zip -O dita-ot-2.3.3.zip ";
  76. // $cmd[]['rsh']="cd /Library/Server/Web/Data/Sites/Default/SE/stuff && rm dita-ot-2.3.3 || echo PASSED";
  77. // $cmd[]['rsh']="cd /Library/Server/Web/Data/Sites/Default/SE/stuff && unzip dita-ot-2.3.3.zip || echo PASSED";
  78. // $cmd[]['rsh']="cd /Library/Server/Web/Data/Sites/Default/SE/stuff/dita-ot-2.3.3 && ./startcmd.sh || echo PASSED";
  79. $wget = "/opt/local/bin/wget";
  80. $unzip = "/usr/bin/unzip";
  81. // $testCmd = "which unzip";
  82. // V::exec($testCmd, $out, $ret);
  83. // DBG::_(true, true, "testCmd: {$testCmd} (return: {$ret})", $out, __CLASS__, __FUNCTION__, __LINE__);
  84. // $testCmd = "which wget";
  85. // V::exec($testCmd, $out, $ret);
  86. // DBG::_(true, true, "testCmd: {$testCmd} (return: {$ret})", $out, __CLASS__, __FUNCTION__, __LINE__);
  87. $cmd = "cd {$stuffPath} ; [ -f dita-ot-2.3.3.zip ] && rm dita-ot-2.3.3.zip";
  88. V::exec($cmd, $out, $ret);
  89. DBG::_(true, true, "cmd: {$cmd} (return: {$ret})", $out, __CLASS__, __FUNCTION__, __LINE__);
  90. $cmd = "cd {$stuffPath} ; {$wget} https://github.com/dita-ot/dita-ot/releases/download/2.3.3/dita-ot-2.3.3.zip -O dita-ot-2.3.3.zip";
  91. V::exec($cmd, $out, $ret);
  92. DBG::_(true, true, "cmd: {$cmd} (return: {$ret})", $out, __CLASS__, __FUNCTION__, __LINE__);
  93. $cmd = "cd {$stuffPath}
  94. [ -f dita-ot-2.3.3.zip ] && rm dita-ot-2.3.3.zip
  95. {$wget} https://github.com/dita-ot/dita-ot/releases/download/2.3.3/dita-ot-2.3.3.zip -O dita-ot-2.3.3.zip
  96. [ -d dita-ot-2.3.3 ] && rm -rf dita-ot-2.3.3
  97. {$unzip} dita-ot-2.3.3.zip
  98. ";
  99. V::exec($cmd, $out, $ret);
  100. DBG::_(true, true, "cmd: {$cmd} (return: {$ret})", $out, __CLASS__, __FUNCTION__, __LINE__);
  101. }
  102. }