<?php
/**
* Retrieve all database rows.
*
* This method will only fill $allRows if it is supplied empty.
*
* The colIdxs are in the same order as the fields in the resultant table.
*
*/
function getbu_list_all( &$allRows, &$colIdxs, $orderby ){
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++;
}
if( count($allRows)>0) return;
$html_rows='';
$cnt=0;
$results = $db->query('SELECT BUID, BUName, Dir_Src, Dir_Dest, Files_Ex, BuType, BuRunning, BU_DATE, BU_TIME, BU_REPEAT, BuError, LastRunDt FROM BULIST '.$orderby);
while ($row = $results->fetchArray()) {
//debug_println("found buid = ({$row['BUID']})", DEBUG_MED );
$allRows[ $cnt++ ] = 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']
);
}
}
/**
* Return a single row. Indexes are the same as the above function and must have been retrieved first.
*/
function getbu_row( $buid, $colIdxs ){
global $g_database_path;
$buid = (int)$buid;
$db = new SQLite3($g_database_path, SQLITE3_OPEN_READONLY );
$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 where BUID='.$buid);
if($row = $results->fetchArray()) {
return 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']
);
}
}
/**
* 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 );
$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;
}
?>