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