- <?php
-
-
- /**
- * Retrieve a backup row from the database using it's ID.
- *
- * Returns the following data as an array:
- *
- * [ BUName, Dir_Src, Dir_Dest, Files_Ex, Bu_Type, BuRunning, BuError, LastRunDt ]
- *
- */
- function get_bu_item( $id ){
-
- if(!is_numeric($id) ) return null;
- $id=(int)$id;
-
- [$table, $colIdxs] = rpc( 'f:getbu_list_all', "where BUID=$id" );
-
- if( count( $table )==0 ) return null;
- $row = $table[0];
-
- return array(
- $row[ $colIdxs['BUName']],
- $row[ $colIdxs['Dir_Src']],
- $row[ $colIdxs['Dir_Dest']],
- $row[ $colIdxs['Files_Ex']],
- $row[ $colIdxs['BuType']],
- $row[ $colIdxs['BuRunning']],
- $row[ $colIdxs['BuError']],
- $row[ $colIdxs['LastRunDt']]
- );
- }
-
-
- /**
- * This page provides the UI for a backup item for both new items and editing items for both
- * database style and files. So there are 4 combinations:
- *
- * $bDbStyle = true, $db_id = 0: Create new database backup item
- * $bDbStyle = false, $db_id = 0: Create new files backup item
- * $bDbStyle = true, $db_id != 0: Edit an existing database backup item
- * $bDbStyle = false, $db_id != 0: Edit an existing files backup item
- *
- */
- function getbu_cf_content( $bDbStyle = false, $db_id = 0 ){
-
- $id_line='';
- $header_cont='';
- $lab1_cont = '';
- $exfiles_cont = '';
- $btn_new_bu = '';
- $item_data = null;
-
- $bu_name_value = '';
- $bu_src_value = '';
- $bu_dest_value = '';
- $bu_ex_files = '';
- $lastRunTime = '';
- $bu_error_list = '';
-
- if($db_id>0){
- $id_line = "<div>ID</div><div>$db_id</div>";
- $item_data = get_bu_item( $db_id ); // [ BUName, Dir_Src, Dir_Dest, Files_Ex, Bu_Type, BuRunning, BuError, LastRunDt ]
-
- $bu_name_value = "value='{$item_data[0]}'";
- $bu_src_value = "value='{$item_data[1]}'";
- $bu_dest_value = "value='{$item_data[2]}'";
- $bu_ex_files = $item_data[3];
-
- $bu_error_list = str_replace( "\n", '<br>', $item_data[6]);
- $bu_error_list = "<div>Errors</div><div>$bu_error_list</div>";
-
- $lastRunTime = "<div>Last Run (UTC)</div><div>{$item_data[7]}</div>";
-
- }
-
- if($bDbStyle){
- if($db_id>0){
- $header_cont = '<div class="section_header" >Edit Database Backup Item</div>';
- $btn_new_bu = "btn_edit_bu_db','$db_id";
-
- }else{
- $header_cont = '<div class="section_header" >Create New Database Backup Item</div>';
- $btn_new_bu = 'btn_new_bu_db';
-
- }
- $lab1_cont = '<div>Database name</div>';
- $test_row_html = '';
- $test_btn_html = '';
-
- }else{
- if($db_id>0){
- $header_cont = '<div class="section_header" >Edit File Backup Item</div>';
- $btn_new_bu = "btn_edit_bu_file','$db_id";
-
- }else{
- $header_cont = '<div class="section_header" >Create New File Backup Item</div>';
- $btn_new_bu = 'btn_new_bu_file';
-
- }
-
- $lab1_cont = '<div>Source File/Dir</div>';
- $exfiles_cont = "<div>Exclude Files</div><div><textarea id=\"new_bu_exf\" rows=\"4\" >$bu_ex_files</textarea></div>";
- $test_row_html = '<div>Test output</div><div><textarea id="ta_testoutput" rows="8" readonly ></textarea></div>';
- $test_btn_html = "<button class=\"btn_exec\" onclick=\"btn_clk_nav(this, 'btn_run_bu')\" >Test</button>";
- }
-
- $content = <<<'EOD'
-
- $header_cont
-
- <div class="content_section_text" style="min-height: 350px;" >
-
- <div class="two-col-panel">
-
- $id_line
-
- <div>Backup Name</div>
- <div><input id="new_bu_name" type="text" $bu_name_value > (optional)</div>
-
- $lab1_cont
- <div><input id="new_bu_source" type="text" $bu_src_value ></div>
-
- <div>Destination Dir</div>
- <div><input id="new_bu_dest" type="text" $bu_dest_value ></div>
-
- $exfiles_cont
-
- <div></div>
- <div>
- $test_btn_html
- <button class="btn_exec" onclick="btn_clk_nav(this, '$btn_new_bu')" >Save</button>
- <button class="btn_exec" onclick="btn_clk_nav(this, 'btn_cancel_new_bu')" >Cancel</button>
- </div>
-
- $test_row_html
- $lastRunTime
- $bu_error_list
-
- </div>
-
- </div>
- EOD;
-
-
-
- $content = str_replace('$test_btn_html', $test_btn_html, $content);
- $content = str_replace('$test_row_html', $test_row_html, $content);
- $content = str_replace('$bu_error_list', $bu_error_list, $content);
- $content = str_replace('$lastRunTime', $lastRunTime, $content);
- $content = str_replace('btn_run_bu\'', "btn_run_bu', $db_id", $content);
- $content = str_replace('$bu_name_value', $bu_name_value, $content);
- $content = str_replace('$bu_src_value', $bu_src_value, $content);
- $content = str_replace('$bu_dest_value', $bu_dest_value, $content);
-
- $content = str_replace('$id_line', $id_line, $content);
- $content = str_replace('$btn_new_bu', $btn_new_bu, $content);
- $content = str_replace('$exfiles_cont', $exfiles_cont, $content);
- $content = str_replace('$lab1_cont', $lab1_cont, $content);
- $content = str_replace('$header_cont', $header_cont, $content);
- return $content;
- }
-
- ?>