| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- <?php
- Lib::loadClass('RouteBase');
- Lib::loadClass('UI');
- Lib::loadClass('DBG');
- /**
- * Executes ant build for dita file - creates pdf file
- * - ant build in SE/schema/dita/{object_namespace_to_file_path}/{function_name}/build.xml
- */
- class Route_Dita extends RouteBase {
- public function defaultAction() {
- // Expected Result:
- // ...
- // [echo] OUTPUT_PDF_FILE: out/null1293984876.pdf
- //
- // BUILD SUCCESSFUL
- // ...
- UI::gora();
- UI::tag('h1', [], 'Dita');
- $ditaList = $this->getDitaFunctionList();
- DBG::_(true, true, "\$ditaList", $ditaList, __CLASS__, __FUNCTION__, __LINE__);
- UI::startTag('ul');
- UI::startTag('li');
- UI::tag('a', ['href'=>"index.php?_route=Dita&_task=reinstall"], "Reinstall");
- UI::endTag('li');
- foreach ($ditaList as $ditaPath => $label) {
- $link = "index.php?_route=Dita&_task=generatePdf&ditaPath={$ditaPath}";
- UI::startTag('li');
- UI::tag('a', ['href'=>$link], $label);
- UI::endTag('li');
- }
- UI::endTag('ul');
- }
- public function getDitaFunctionList() {
- return [
- 'default_db-in7_dziennik_koresp/test-druk' => "Test Koresp Dita Druk PDF"
- ];
- }
- public function generatePdfAction() {
- $ditaPath = V::get('ditaPath', '', $_GET);
- $idKoresp = V::get('idKoresp', 0, $_POST, 'int');
- $doExecute = V::get('doExecute', '', $_POST);
- $ditaList = $this->getDitaFunctionList();
- if (!array_key_exists($ditaPath, $ditaList)) throw new Exception("dita path not found", 404);
- UI::gora();
- UI::startContainer();
- try {
- UI::tag('h1', [], "Dita: '{$ditaList[$ditaPath]}'");
- UI::startTag('form', ['action'=>"", 'method'=>"POST", 'class'=>'form-inline']);
- UI::tag('input', ['type'=>'number', 'value'=>$idKoresp, 'class'=>'form-control', 'style'=>'max-width:200px']);
- UI::tag('input', ['type'=>'hidden', 'name'=>'doExecute', 'value'=>'1']);
- UI::tag('input', ['type'=>"submit", 'value'=>"Wykonaj", 'class'=>'btn btn-primary']);
- UI::endTag('form');
- if ($doExecute) {
- // if ($idKoresp <= 0) throw new Exception("Bad Request - missing id koresp");
- if ($idKoresp <= 0) UI::alert('danger', "Missing id koresp - using default file");
- if ($idKoresp > 0) UI::alert('warning', "TODO: generate xml file for id koresp = {$idKoresp}");
- $execPath = APP_PATH_SCHEMA . DS . 'dita' . DS . $ditaPath;
- $ant = APP_PATH_WWW . DS . 'stuff' . DS . 'dita-ot-2.3.3' . DS . 'bin' . DS . 'ant';
- $cmd = "cd {$execPath} && {$ant} 2>&1";// wymaga java jdk
- V::exec($cmd, $out, $ret);
- DBG::_(true, true, "cmd: {$cmd} (return: {$ret})", $out, __CLASS__, __FUNCTION__, __LINE__);
- }
- throw new Exception("TODO: F." . __FUNCTION__ . " . L." . __LINE__);
- } catch (Exception $e) {
- UI::alert('danger', $e->getMessage());
- }
- UI::endContainer();
- UI::dol();
- }
- public function reinstallAction() {
- UI::gora();
- UI::tag('h1', [], 'Reinstall Dita Open Toolkit 2.3.3');
- $stuffPath = APP_PATH_WWW . DS . 'stuff';
- // $cmd[]['rsh']="cd /Library/Server/Web/Data/Sites/Default/SE/stuff && rm dita-ot-2.3.3.zip || echo PASSED";
- // $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 ";
- // $cmd[]['rsh']="cd /Library/Server/Web/Data/Sites/Default/SE/stuff && rm dita-ot-2.3.3 || echo PASSED";
- // $cmd[]['rsh']="cd /Library/Server/Web/Data/Sites/Default/SE/stuff && unzip dita-ot-2.3.3.zip || echo PASSED";
- // $cmd[]['rsh']="cd /Library/Server/Web/Data/Sites/Default/SE/stuff/dita-ot-2.3.3 && ./startcmd.sh || echo PASSED";
- $wget = "/opt/local/bin/wget";
- $unzip = "/usr/bin/unzip";
- // $testCmd = "which unzip";
- // V::exec($testCmd, $out, $ret);
- // DBG::_(true, true, "testCmd: {$testCmd} (return: {$ret})", $out, __CLASS__, __FUNCTION__, __LINE__);
- // $testCmd = "which wget";
- // V::exec($testCmd, $out, $ret);
- // DBG::_(true, true, "testCmd: {$testCmd} (return: {$ret})", $out, __CLASS__, __FUNCTION__, __LINE__);
- $cmd = "cd {$stuffPath} ; [ -f dita-ot-2.3.3.zip ] && rm dita-ot-2.3.3.zip";
- V::exec($cmd, $out, $ret);
- DBG::_(true, true, "cmd: {$cmd} (return: {$ret})", $out, __CLASS__, __FUNCTION__, __LINE__);
- $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";
- V::exec($cmd, $out, $ret);
- DBG::_(true, true, "cmd: {$cmd} (return: {$ret})", $out, __CLASS__, __FUNCTION__, __LINE__);
- $cmd = "cd {$stuffPath}
- [ -f dita-ot-2.3.3.zip ] && rm dita-ot-2.3.3.zip
- {$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
- [ -d dita-ot-2.3.3 ] && rm -rf dita-ot-2.3.3
- {$unzip} dita-ot-2.3.3.zip
- ";
- V::exec($cmd, $out, $ret);
- DBG::_(true, true, "cmd: {$cmd} (return: {$ret})", $out, __CLASS__, __FUNCTION__, __LINE__);
- }
- }
|