TaskManager.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <?php
  2. Lib::loadClass('RouteBase');
  3. Lib::loadClass('ProcesHelper');
  4. Lib::loadClass('Config');
  5. Lib::loadClass('UI');
  6. Lib::loadClass('Request');
  7. Lib::loadClass('ProcesHelper');
  8. Lib::loadClass('Response');
  9. Lib::loadClass('DBG');
  10. Lib::loadClass('Api_WfsNs');
  11. class Route_UrlAction_TaskManager extends RouteBase {// TODO: UrlActionBase @see Route_UrlAction
  12. public function getStatsAjaxAction() {
  13. try {
  14. $id = V::get('ID', 0, $_GET, 'int');
  15. if ($id <= 0) throw new Exception("ID is not set.");
  16. $sqlId = DB::getPDO()->quote($id, PDO::PARAM_INT);
  17. $type = V::get('TYPE', 0, $_GET, 'string');
  18. $rows = null;
  19. if ($type == "PROBLEM") {
  20. $rows = DB::getPDO()->fetchAll("
  21. SELECT * FROM _SYNC_TASK_PERCENT WHERE ID_TASK = {$sqlId} AND ID_PROJECT = 0
  22. ");
  23. }
  24. if ($type == "PROJECT") {
  25. $rows = DB::getPDO()->fetchAll("
  26. SELECT * FROM _SYNC_TASK_PERCENT WHERE ID_PROJECT = {$sqlId} AND ID_TASK = 0
  27. ");
  28. }
  29. Response::sendJsonExit($rows);
  30. } catch (Exception $e) {
  31. UI::alert('danger', "Error: " . $e->getMessage());
  32. }
  33. }
  34. public function handleAuth() {
  35. if (!User::logged()) {
  36. User::authByRequest();
  37. }
  38. }
  39. public function reinstallAction() {
  40. try {
  41. $dropTableSql = "DROP TABLE `_SYNC_TASK_PERCENT`";
  42. DBG::nicePrint($dropTableSql, '$dropTableSql');
  43. DB::getPDO()->query($dropTableSql);
  44. } catch (Exception $e) {
  45. // SQLSTATE[42000]: Syntax error or access violation: 1305 PROCEDURE SES_USERS2.PROBLEMS__SYNC_PERCENT does not exist
  46. }
  47. $createTableSql = file_get_contents(__FILE__ . '.create__SYNC_TASK_PERCENT.sql');
  48. DBG::nicePrint($createTableSql, '$createTableSql');
  49. DB::getPDO()->query($createTableSql);
  50. try {
  51. $dropProcedureSql = "DROP PROCEDURE `PROBLEMS__SYNC_PERCENT`";
  52. DBG::nicePrint($dropProcedureSql, '$dropProcedureSql');
  53. DB::getPDO()->query($dropProcedureSql);
  54. } catch (Exception $e) {
  55. // SQLSTATE[42000]: Syntax error or access violation: 1305 PROCEDURE SES_USERS2.PROBLEMS__SYNC_PERCENT does not exist
  56. }
  57. $createProcedureSql = file_get_contents(__FILE__ . '.problems_sync_percent.sql');
  58. DBG::nicePrint($createProcedureSql, '$createProcedureSql');
  59. DB::getPDO()->query($createProcedureSql);
  60. }
  61. public function defaultAction() {
  62. UI::gora();
  63. UI::menu();
  64. try {
  65. DB::getPDO()->query("CALL `PROBLEMS__SYNC_PERCENT`();");// TODO: BUG zamula
  66. $id = 0;
  67. $type = "";
  68. if (!empty(V::get('ID_PROBLEM', 0, $_REQUEST, 'int'))) {
  69. $id = V::get('ID_PROBLEM', 0, $_REQUEST, 'int');
  70. $type = "PROBLEM";
  71. }
  72. if (!empty(V::get('ID_PROJECT', 0, $_REQUEST, 'int'))) {
  73. $id = V::get('ID_PROJECT', 0, $_REQUEST, 'int');
  74. $type = "PROJECT";
  75. }
  76. if ($id <= 0) throw new Exception("Wrong ID");
  77. $this->showManager($id, $type);
  78. } catch (Exception $e) {
  79. UI::alert('danger', "Error: " . $e->getMessage());
  80. }
  81. UI::dol();
  82. }
  83. public function showManager($id, $type) {
  84. echo "<div class=container-fluid>";
  85. echo "<div class=row>";
  86. echo "<div class='col-lg-9 col-lg-push-3' id=right>";
  87. echo "</div>";
  88. echo "<div class='col-lg-3 col-lg-pull-9' id=left>";
  89. echo "</div>";
  90. echo "</div>";
  91. echo "</div>";
  92. echo '<link rel="stylesheet" type="text/css" href="static/sweetalert2.min.css">';
  93. // echo '<link rel="stylesheet" href="static/task.css?'.time().'" type="text/css" />';
  94. UI::startTag('style', ['type' => "text/css"]);
  95. echo file_get_contents(__FILE__ . '.task.css');
  96. UI::endTag('style');
  97. echo '<script src="static/sweetalert2.min.js"></script>';
  98. echo '<script src="static/jquery.ui.autocomplete.js"></script>';
  99. echo '<script src="static/jquery.ui.menu.js"></script>';
  100. // echo "<script>var BASE_URL = '".Request::getPathUri()."';var TASK = ".$id.";var USER = '".User::getLogin()."';var TYPE='".$type."'; var ProblemsTableId=".ProcesHelper::getZasobTableID('PROBLEMS').";var ProjectsTableId=".ProcesHelper::getZasobTableID('IN7_MK_BAZA_DYSTRYBUCJI')."</script>";
  101. // echo '<script src="static/task.js?'.time().'"></script>';
  102. UI::inlineJS(__FILE__ . '.task.js', [
  103. 'BASE_URL' => Request::getPathUri(),
  104. 'BASE_WFS_URL' => Api_WfsNs::getBaseWfsUri(),
  105. 'TASK' => $id,
  106. 'USER' => User::getLogin(),
  107. 'TYPE' => $type,
  108. 'ProblemsTableId' => ProcesHelper::getZasobTableID('PROBLEMS'),
  109. 'ProjectsTableId' => ProcesHelper::getZasobTableID('IN7_MK_BAZA_DYSTRYBUCJI'),
  110. ]);
  111. }
  112. }