Newer
Older
backup-commander / html / svc / db-writes.php
  1. <?php
  2.  
  3.  
  4. function save_bu_schedule( $postVars ){
  5. global $g_database_path;
  6. $db = new SQLite3( $g_database_path );
  7.  
  8. $db_st = $db->prepare('UPDATE BULIST SET BU_DATE=:bud, BU_TIME=:but, BU_REPEAT=:bur where BUID=:buid');
  9. $db_st->bindValue(':buid', $postVars['id'], SQLITE3_INTEGER );
  10. $db_st->bindValue(':bud', $postVars['sched_date'] );
  11. $db_st->bindValue(':but', $postVars['sched_time'] );
  12. $db_st->bindValue(':bur', $postVars['sched_period'] );
  13. $db_st->execute();
  14. if( $db->lastErrorCode()!==0){
  15. return $db->lastErrorCode();
  16. }
  17. return 0;
  18. }
  19.  
  20. /**
  21. * Both inserts as well as edits a single backup item.
  22. */
  23. function save_bu_item( $postVars, $bu_id=0 ){
  24. global $g_database_path;
  25. $db = new SQLite3( $g_database_path );
  26. $db_st = null;
  27. if( $postVars['new_bu_is_dbType'] ){
  28. if($bu_id==0){
  29. $db_st = $db->prepare('INSERT INTO BULIST ( BUName, Dir_Src, Dir_Dest, BuType ) values( :bun, :bus, :bud, 1 )');
  30. }else{
  31. $db_st = $db->prepare('update BULIST set BUName=:bun, Dir_Src=:bus, Dir_Dest=:bud where BUID=:buid');
  32. }
  33. }else{
  34. if($bu_id==0){
  35. $db_st = $db->prepare('INSERT INTO BULIST ( BUName, Dir_Src, Dir_Dest, Files_Ex, BuType ) values( :bun, :bus, :bud, :buex, 0 )');
  36. }else{
  37. $db_st = $db->prepare('update BULIST set BUName=:bun, Dir_Src=:bus, Dir_Dest=:bud, Files_Ex=:buex where BUID=:buid');
  38. }
  39. }
  40. if($bu_id>0){
  41. $db_st->bindValue(':buid', $bu_id );
  42. }
  43. $db_st->bindValue(':bun', $postVars['new_bu_name'] );
  44. $db_st->bindValue(':bus', $postVars['new_bu_source'] );
  45. $db_st->bindValue(':bud', $postVars['new_bu_dest'] );
  46. if( !$postVars['new_bu_is_dbType'] ){
  47. $db_st->bindValue(':buex', $postVars['new_bu_exf'] );
  48. }
  49. $db_st->execute();
  50. if( $db->lastErrorCode()!==0){
  51. return $db->lastErrorCode();
  52. }
  53.  
  54. }
  55.  
  56. /**
  57. * Set the error string in the database.
  58. */
  59. function set_bu_error_db( $buid, $str_errs ){
  60. global $g_database_path;
  61. $db = new SQLite3( $g_database_path );
  62. if($str_errs==''){
  63. return $db->exec("update BULIST set BuError = NULL where BUID=$buid");
  64. }
  65. $p = $db->prepare("update BULIST set BuError=:str_errs where BUID=:buid");
  66. $p->bindValue(':str_errs', $str_errs );
  67. $p->bindValue(':buid', $buid );
  68. $p->execute();
  69. if( $db->lastErrorCode()!==0){
  70. return $db->lastErrorCode();
  71. }
  72. return 0;
  73. }
  74.  
  75. /**
  76. * Set (unset) the running datbase flag. Return true on success.
  77. */
  78. function set_bu_running_db( $id, bool $setit ){
  79. global $g_database_path;
  80. $db = new SQLite3( $g_database_path );
  81. $setit_int = $setit?1:0;
  82. return $db->exec("update BULIST set BuRunning=$setit_int where BUID=$id");
  83. }
  84.  
  85. function set_last_run_date_db( $buid, $str_dt ){
  86.  
  87. global $g_database_path;
  88. $db = new SQLite3( $g_database_path );
  89.  
  90. $p = $db->prepare("update BULIST set LastRunDt=:str_dt where BUID=:buid");
  91. $p->bindValue(':str_dt', $str_dt );
  92. $p->bindValue(':buid', $buid );
  93. $p->execute();
  94. if( $db->lastErrorCode()!==0){
  95. return $db->lastErrorCode();
  96. }
  97. return 0;
  98. }
  99.  
  100.  
  101. function set_sched_date_db( $buid, $dt_new ){
  102. global $g_database_path;
  103. $db = new SQLite3( $g_database_path );
  104. $p = $db->prepare("update BULIST set BU_DATE=:str_dt where BUID=:buid");
  105. $p->bindValue(':str_dt', $dt_new );
  106. $p->bindValue(':buid', $buid );
  107. $p->execute();
  108. if( $db->lastErrorCode()!==0){
  109. return $db->lastErrorCode();
  110. }
  111. return 0;
  112. }
  113.  
  114. function delete_bu_item_db( $id ){
  115. global $g_database_path;
  116. $db = new SQLite3( $g_database_path );
  117.  
  118. $db_st = $db->prepare('delete from BULIST where BUID=:buid');
  119. $db_st->bindValue(':buid', $id );
  120. $db_st->execute();
  121. if( $db->lastErrorCode()!==0){
  122. return $db->lastErrorCode();
  123. }
  124.  
  125. }
  126.  
  127.  
  128. ?>