<?php
/**
* Provides a simple json array of the BU state info for the UI to poll changes.
*/
function getbu_list_state(){
global $g_database_path;
$db = new SQLite3($g_database_path, SQLITE3_OPEN_READONLY );
error_log( '$g_database_path = ' . $g_database_path );
$bu_state = array();
$results = $db->query('SELECT BUID, BuRunning FROM BULIST');
while ($row = $results->fetchArray()) {
array_push( $bu_state, array( $row['BUID'], $row['BuRunning'] ) );
}
return $bu_state;
}
/**
* Retrieve all database rows ordered by the next run time in ascending order. Note that the null date/times will
* be listed first.
*/
function getbu_list_all( &$allRows, &$colIdxs=null ){
global $g_database_path;
$db = new SQLite3($g_database_path, SQLITE3_OPEN_READONLY );
if($colIdxs!==null){
$i=0;
$colIdxs = array();
$colIdxs['BUID'] = $i++;
$colIdxs['BUName'] = $i++;
$colIdxs['Dir_Src'] = $i++;
$colIdxs['Dir_Dest'] = $i++;
$colIdxs['Files_Ex'] = $i++;
$colIdxs['BuType'] = $i++;
$colIdxs['BuRunning'] = $i++;
$colIdxs['BU_DATE'] = $i++;
$colIdxs['BU_TIME'] = $i++;
$colIdxs['BU_REPEAT'] = $i++;
$colIdxs['BuError'] = $i++;
$colIdxs['LastRunDt'] = $i++;
}
$html_rows='';
$results = $db->query('SELECT BUID, BUName, Dir_Src, Dir_Dest, Files_Ex, BuType, BuRunning, BU_DATE, BU_TIME, BU_REPEAT, BuError, LastRunDt FROM BULIST order by BU_DATE desc, BU_TIME desc');
while ($row = $results->fetchArray()) {
$allRows[ $row['BUID'] ] = array(
$row['BUID'],
$row['BUName'],
$row['Dir_Src'],
$row['Dir_Dest'],
$row['Files_Ex'],
$row['BuType'],
$row['BuRunning'],
$row['BU_DATE'],
$row['BU_TIME'],
$row['BU_REPEAT'],
$row['BuError'],
$row['LastRunDt']
);
}
}
/**
* Returns the main backup list page.
*/
function getbu_list_content(){
global $g_database_path;
$db = new SQLite3($g_database_path, SQLITE3_OPEN_READONLY );
$html_rows='';
$results = $db->query('SELECT * FROM BULIST');
while ($row = $results->fetchArray()) {
//var_dump($row);
$view_type = 'edit-file-bu';
if($row['BuType']==1){
$view_type = 'edit-db-bu';
}
$html_row = '<tr>';
$html_row .= '<td>'.$row['BUID'].'</td>';
$html_row .= "<td class='td_icon' title='edit' ><img class=\"btn_mse\" onclick=\"btn_clk_nav(this, '$view_type', {$row['BUID']})\" src='img/edit-icon-24x24.png'></td>"; // edit icon
$html_row .= "<td class='td_icon' title='delete' ><img class=\"btn_mse\" onclick=\"btn_clk_nav(this, 'delete-bu', {$row['BUID']})\" src='img/trash-bin-red-24x24.png'></td>"; // trash icon
$html_row .= "<td class=\"btn_mse\" onclick=\"btn_clk_nav(this, '$view_type', {$row['BUID']})\" >{$row['BUName']}</td>";
$but = $row['BuType']==1?'DB':'F';
$html_row .= "<td>$but</td>";
if($row['BuError']!=''){
$html_row .= "<td><span style='color:red;'>!! </span>{$row['LastRunDt']}</td>";
}else{
$html_row .= "<td>{$row['LastRunDt']}</td>";
}
if( $row['BU_REPEAT']=='N' ){
$html_row .= "<td title='edit schedule' ><img src=\"img/red-cross.png\" class=\" btn_mse\" onclick=\"btn_clk_nav(this, 'sched', {$row['BUID']})\" ></td>";
}else{
$html_row .= "<td title='edit schedule' ><button class=\"btn_mse btn_exec btn_small\" onclick=\"btn_clk_nav(this, 'sched', {$row['BUID']})\" >Edit</button> {$row['BU_REPEAT']}</td>";
}
if($row['BuRunning']){
$html_row .= '<td><img src="img/green-tick.png"></td>';
}else{
$html_row .= "<td id=\"td_run_{$row['BUID']}\" ><button class=\"btn_mse btn_exec btn_small\" onclick=\"btn_clk_nav(this, 'btn_run_bu noTest', {$row['BUID']})\" >Run Now</button></td>";
}
$html_row .= '</tr>';
$html_rows .= $html_row;
}
$content = <<<'EOD'
<div class="section_header" >Backup Config List</div>
<div class="content_section_text" style="min-height: 350px;" >
<br>
<table class="tblcenter" >
<tr>
<th>ID</th>
<th></th>
<th></th>
<th>Name</th>
<th>Type</th>
<th>Last Run (UTC)</th>
<th>Scheduled</th>
<th>Running</th>
</tr>
--INSERT-ROWS--
<tr class="high-row-style">
<td></td>
<td></td>
<td></td>
<td class="td_label_bkup" >Database backup</td>
<td> <button class="btn_mse btn_exec" onclick="btn_clk_nav(this, 'new-db-bu')">Create</button> </td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td class="td_label_bkup" >Files backup</td>
<td> <button class="btn_mse btn_exec" onclick="btn_clk_nav(this, 'new-file-bu' )">Create</button> </td>
</tr>
</table>
<div><button class="btn_exec" onclick="btn_clk_nav(this, 'btn_test_1')" >Test</button></div>
</div>
EOD;
return str_replace('--INSERT-ROWS--', $html_rows, $content);
}
?>