Newer
Older
backup-commander / html / svc / db-reads.php
  1. <?php
  2.  
  3. /**
  4. * Retrieve all database rows.
  5. *
  6. * This method will only fill $allRows if it is supplied empty.
  7. *
  8. * The colIdxs are in the same order as the fields in the resultant table.
  9. *
  10. */
  11. function getbu_list_all( &$allRows, &$colIdxs, $orderby ){
  12.  
  13. global $g_database_path;
  14. $db = new SQLite3($g_database_path, SQLITE3_OPEN_READONLY );
  15.  
  16. if($colIdxs!==null){
  17. $i=0;
  18. $colIdxs = array();
  19. $colIdxs['BUID'] = $i++;
  20. $colIdxs['BUName'] = $i++;
  21. $colIdxs['Dir_Src'] = $i++;
  22. $colIdxs['Dir_Dest'] = $i++;
  23. $colIdxs['Files_Ex'] = $i++;
  24. $colIdxs['BuType'] = $i++;
  25. $colIdxs['BuRunning'] = $i++;
  26. $colIdxs['BU_DATE'] = $i++;
  27. $colIdxs['BU_TIME'] = $i++;
  28. $colIdxs['BU_REPEAT'] = $i++;
  29. $colIdxs['BuError'] = $i++;
  30. $colIdxs['LastRunDt'] = $i++;
  31. $colIdxs['Res_User'] = $i++;
  32. $colIdxs['Res_Pwd'] = $i++;
  33. }
  34. if( count($allRows)>0) return;
  35. $html_rows='';
  36. $cnt=0;
  37. $results = $db->query('SELECT BUID, BUName, Dir_Src, Dir_Dest, Files_Ex, BuType, BuRunning, BU_DATE, BU_TIME, BU_REPEAT, BuError, LastRunDt, Res_User, Res_Pwd FROM BULIST '.$orderby);
  38. while ($row = $results->fetchArray()) {
  39.  
  40. //debug_println("found buid = ({$row['BUID']})", DEBUG_MED );
  41.  
  42. $allRows[ $cnt++ ] = array(
  43. $row['BUID'],
  44. $row['BUName'],
  45. $row['Dir_Src'],
  46. $row['Dir_Dest'],
  47. $row['Files_Ex'],
  48. $row['BuType'],
  49. $row['BuRunning'],
  50. $row['BU_DATE'],
  51. $row['BU_TIME'],
  52. $row['BU_REPEAT'],
  53. $row['BuError'],
  54. $row['LastRunDt'],
  55. $row['Res_User'],
  56. $row['Res_Pwd']
  57. );
  58. }
  59. }
  60.  
  61. /**
  62. * Return a single row. Indexes are the same as the above function and must have been retrieved first.
  63. */
  64. function getbu_row( $buid, $colIdxs ){
  65.  
  66. global $g_database_path;
  67. $buid = (int)$buid;
  68. $db = new SQLite3($g_database_path, SQLITE3_OPEN_READONLY );
  69. $html_rows='';
  70. $results = $db->query('SELECT BUID, BUName, Dir_Src, Dir_Dest, Files_Ex, BuType, BuRunning, BU_DATE, BU_TIME, BU_REPEAT, BuError, LastRunDt, Res_User, Res_Pwd FROM BULIST where BUID='.$buid);
  71. if($row = $results->fetchArray()) {
  72. return array(
  73. $row['BUID'],
  74. $row['BUName'],
  75. $row['Dir_Src'],
  76. $row['Dir_Dest'],
  77. $row['Files_Ex'],
  78. $row['BuType'],
  79. $row['BuRunning'],
  80. $row['BU_DATE'],
  81. $row['BU_TIME'],
  82. $row['BU_REPEAT'],
  83. $row['BuError'],
  84. $row['LastRunDt'],
  85. $row['Res_User'],
  86. $row['Res_Pwd']
  87.  
  88. );
  89. }
  90. }
  91.  
  92.  
  93. /**
  94. * Provides a simple json array of the BU state info for the UI to poll changes.
  95. */
  96. function getbu_list_state(){
  97.  
  98. global $g_database_path;
  99.  
  100. $db = new SQLite3($g_database_path, SQLITE3_OPEN_READONLY );
  101. $bu_state = array();
  102. $results = $db->query('SELECT BUID, BuRunning FROM BULIST');
  103. while ($row = $results->fetchArray()) {
  104. array_push( $bu_state, array( $row['BUID'], $row['BuRunning'] ) );
  105. }
  106. return $bu_state;
  107. }
  108.  
  109.  
  110. ?>