Newer
Older
backup-commander / html / inc / new-file-bu.php
  1. <?php
  2.  
  3. include_once 'bu-common.php';
  4.  
  5.  
  6. /**
  7. * This page provides the UI for a backup item for both new items and editing items for both
  8. * database style and files. So there are 4 combinations:
  9. *
  10. * $bDbStyle = true, $db_id = 0: Create new database backup item
  11. * $bDbStyle = false, $db_id = 0: Create new files backup item
  12. * $bDbStyle = true, $db_id != 0: Edit an existing database backup item
  13. * $bDbStyle = false, $db_id != 0: Edit an existing files backup item
  14. *
  15. */
  16. function getbu_cf_content( $bDbStyle = false, $db_id = 0 ){
  17. $id_line='';
  18. $header_cont='';
  19. $lab1_cont = '';
  20. $exfiles_cont = '';
  21. $btn_new_bu = '';
  22. $item_data = null;
  23. $bu_name_value = '';
  24. $bu_src_value = '';
  25. $bu_dest_value = '';
  26. $bu_ex_files = '';
  27. $lastRunTime = '';
  28. $bu_error_list = '';
  29. if($db_id>0){
  30. $id_line = "<div>ID</div><div>$db_id</div>";
  31. $item_data = get_bu_item( $db_id ); // [ BUName, Dir_Src, Dir_Dest, Files_Ex, Bu_Type, BuRunning, BuError, LastRunDt ]
  32. $bu_name_value = "value='{$item_data[0]}'";
  33. $bu_src_value = "value='{$item_data[1]}'";
  34. $bu_dest_value = "value='{$item_data[2]}'";
  35. $bu_ex_files = $item_data[3];
  36. $bu_error_list = str_replace( "\n", '<br>', $item_data[6]);
  37. $bu_error_list = "<div>Errors</div><div>$bu_error_list</div>";
  38. $lastRunTime = "<div>Last Run (UTC)</div><div>{$item_data[7]}</div>";
  39. }
  40. if($bDbStyle){
  41. if($db_id>0){
  42. $header_cont = '<div class="section_header" >Edit Database Backup Item</div>';
  43. $btn_new_bu = "btn_edit_bu_db','$db_id";
  44. }else{
  45. $header_cont = '<div class="section_header" >Create New Database Backup Item</div>';
  46. $btn_new_bu = 'btn_new_bu_db';
  47. }
  48. $lab1_cont = '<div>Database name</div>';
  49. }else{
  50. if($db_id>0){
  51. $header_cont = '<div class="section_header" >Edit File Backup Item</div>';
  52. $btn_new_bu = "btn_edit_bu_file','$db_id";
  53. }else{
  54. $header_cont = '<div class="section_header" >Create New File Backup Item</div>';
  55. $btn_new_bu = 'btn_new_bu_file';
  56. }
  57. $lab1_cont = '<div>Source File/Dir</div>';
  58. $exfiles_cont = "<div>Exclude Files</div><div><textarea id=\"new_bu_exf\" rows=\"4\" >$bu_ex_files</textarea></div>";
  59. }
  60. $content = <<<'EOD'
  61.  
  62. $header_cont
  63. <div class="content_section_text" style="min-height: 350px;" >
  64. <div class="two-col-panel">
  65. $id_line
  66. <div>Backup Name</div>
  67. <div><input id="new_bu_name" type="text" $bu_name_value > (optional)</div>
  68. $lab1_cont
  69. <div><input id="new_bu_source" type="text" $bu_src_value ></div>
  70.  
  71. <div>Destination Dir</div>
  72. <div><input id="new_bu_dest" type="text" $bu_dest_value ></div>
  73.  
  74. $exfiles_cont
  75.  
  76. <div></div>
  77. <div>
  78. <button class="btn_exec" onclick="btn_clk_nav(this, 'btn_run_bu')" >Test</button>
  79. <button class="btn_exec" onclick="btn_clk_nav(this, '$btn_new_bu')" >Save</button>
  80. <button class="btn_exec" onclick="btn_clk_nav(this, 'btn_cancel_new_bu')" >Cancel</button>
  81. </div>
  82.  
  83. <div>Test output</div>
  84. <div><textarea id="ta_testoutput" rows="8" readonly ></textarea></div>
  85.  
  86. $lastRunTime
  87. $bu_error_list
  88.  
  89. </div>
  90.  
  91. </div>
  92. EOD;
  93. $content = str_replace('$bu_error_list', $bu_error_list, $content);
  94. $content = str_replace('$lastRunTime', $lastRunTime, $content);
  95. $content = str_replace('btn_run_bu\'', "btn_run_bu', $db_id", $content);
  96. $content = str_replace('$bu_name_value', $bu_name_value, $content);
  97. $content = str_replace('$bu_src_value', $bu_src_value, $content);
  98. $content = str_replace('$bu_dest_value', $bu_dest_value, $content);
  99. $content = str_replace('$id_line', $id_line, $content);
  100. $content = str_replace('$btn_new_bu', $btn_new_bu, $content);
  101. $content = str_replace('$exfiles_cont', $exfiles_cont, $content);
  102. $content = str_replace('$lab1_cont', $lab1_cont, $content);
  103. $content = str_replace('$header_cont', $header_cont, $content);
  104. return $content;
  105. }
  106.  
  107. /**
  108. * Both inserts as well as edits a single backup item.
  109. */
  110. function save_bu_item( $postVars, $bu_id=0 ){
  111. [$err] = rpc( 'f:save_bu_item', $postVars, $bu_id );
  112. return $err;
  113. }
  114.  
  115.  
  116. ?>