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. $row[ $colIdxs['Res_User']],
  29. $row[ $colIdxs['Res_Pwd']]
  30. );
  31. }
  32.  
  33.  
  34. /**
  35. * This page provides the UI for a backup item for both new items and editing items for both
  36. * database style and files. So there are 4 combinations:
  37. *
  38. * $bDbStyle = true, $db_id = 0: Create new database backup item
  39. * $bDbStyle = false, $db_id = 0: Create new files backup item
  40. * $bDbStyle = true, $db_id != 0: Edit an existing database backup item
  41. * $bDbStyle = false, $db_id != 0: Edit an existing files backup item
  42. *
  43. */
  44. function getbu_cf_content( $bDbStyle = false, $db_id = 0 ){
  45. $id_line='';
  46. $header_cont='';
  47. $lab1_cont = '';
  48. $exfiles_cont = '';
  49. $btn_new_bu = '';
  50. $item_data = null;
  51. $bu_name_value = '';
  52. $bu_src_value = '';
  53. $bu_dest_value = '';
  54. $bu_ex_files = '';
  55. $lastRunTime = '';
  56. $bu_error_list = '';
  57. if($db_id>0){
  58. $id_line = "<div>ID</div><div>$db_id</div>";
  59. $item_data = get_bu_item( $db_id ); // [ BUName, Dir_Src, Dir_Dest, Files_Ex, Bu_Type, BuRunning, BuError, LastRunDt, Res_User, Res_Pwd ]
  60. $bu_name_value = "value='{$item_data[0]}'";
  61. $bu_src_value = "value='{$item_data[1]}'";
  62. $bu_dest_value = "value='{$item_data[2]}'";
  63. $bu_ex_files = $item_data[3];
  64. $db_usr_name_value = "value='{$item_data[8]}'";
  65. $db_usr_pwd_value = "value='{$item_data[9]}'";
  66. $bu_error_list = str_replace( "\n", '<br>', $item_data[6]);
  67. $bu_error_list = "<div>Errors</div><div>$bu_error_list</div>";
  68. $lastRunTime = "<div>Last Run (UTC)</div><div>{$item_data[7]}</div>";
  69. }
  70. if($bDbStyle){
  71. if($db_id>0){
  72. $header_cont = '<div class="section_header" >Edit Database Backup Item</div>';
  73. $btn_new_bu = "btn_edit_bu_db','$db_id";
  74. }else{
  75. $header_cont = '<div class="section_header" >Create New Database Backup Item</div>';
  76. $btn_new_bu = 'btn_new_bu_db';
  77. }
  78. $db_usr_pwd = '<div>DB User Name</div>';
  79. $db_usr_pwd .= "<div><input id=\"db_usr_name\" type=\"text\" $db_usr_name_value ></div>";
  80. $db_usr_pwd .= '<div>DB Password</div>';
  81. $db_usr_pwd .= "<div><input id=\"db_usr_pwd\" type=\"password\" $db_usr_pwd_value ></div>";
  82. $lab1_cont = '<div>Database name</div>';
  83. $test_row_html = '';
  84. $test_btn_html = '';
  85. }else{
  86. if($db_id>0){
  87. $header_cont = '<div class="section_header" >Edit File Backup Item</div>';
  88. $btn_new_bu = "btn_edit_bu_file','$db_id";
  89. }else{
  90. $header_cont = '<div class="section_header" >Create New File Backup Item</div>';
  91. $btn_new_bu = 'btn_new_bu_file';
  92. }
  93. $lab1_cont = '<div>Source File/Dir</div>';
  94. $exfiles_cont = "<div>Exclude Files</div><div><textarea id=\"new_bu_exf\" rows=\"4\" >$bu_ex_files</textarea></div>";
  95. $test_row_html = '<div>Test output</div><div><textarea id="ta_testoutput" rows="8" readonly ></textarea></div>';
  96. $test_btn_html = "<button class=\"btn_exec\" onclick=\"btn_clk_nav(this, 'btn_run_bu')\" >Test</button>";
  97. }
  98. $content = <<<'EOD'
  99.  
  100. $header_cont
  101. <div class="content_section_text" style="min-height: 350px;" >
  102. <div class="two-col-panel">
  103. $id_line
  104. <div>Backup Name</div>
  105. <div><input id="new_bu_name" type="text" $bu_name_value > (optional)</div>
  106. $db_usr_pwd
  107. $lab1_cont
  108. <div><input id="new_bu_source" type="text" $bu_src_value ></div>
  109.  
  110. <div>Destination Dir</div>
  111. <div><input id="new_bu_dest" type="text" $bu_dest_value ></div>
  112.  
  113. $exfiles_cont
  114.  
  115. <div></div>
  116. <div>
  117. $test_btn_html
  118. <button class="btn_exec" onclick="btn_clk_nav(this, '$btn_new_bu')" >Save</button>
  119. <button class="btn_exec" onclick="btn_clk_nav(this, 'btn_cancel_new_bu')" >Cancel</button>
  120. </div>
  121. $test_row_html
  122. $lastRunTime
  123. $bu_error_list
  124.  
  125. </div>
  126.  
  127. </div>
  128. EOD;
  129. $content = str_replace('$db_usr_pwd', $db_usr_pwd, $content);
  130. $content = str_replace('$test_btn_html', $test_btn_html, $content);
  131. $content = str_replace('$test_row_html', $test_row_html, $content);
  132. $content = str_replace('$bu_error_list', $bu_error_list, $content);
  133. $content = str_replace('$lastRunTime', $lastRunTime, $content);
  134. $content = str_replace('btn_run_bu\'', "btn_run_bu', $db_id", $content);
  135. $content = str_replace('$bu_name_value', $bu_name_value, $content);
  136. $content = str_replace('$bu_src_value', $bu_src_value, $content);
  137. $content = str_replace('$bu_dest_value', $bu_dest_value, $content);
  138. $content = str_replace('$id_line', $id_line, $content);
  139. $content = str_replace('$btn_new_bu', $btn_new_bu, $content);
  140. $content = str_replace('$exfiles_cont', $exfiles_cont, $content);
  141. $content = str_replace('$lab1_cont', $lab1_cont, $content);
  142. $content = str_replace('$header_cont', $header_cont, $content);
  143. return $content;
  144. }
  145.  
  146. ?>