<?php
function edit_sh_bu_getContent( $db_id ){
global $g_database_path;
$db = new SQLite3( $g_database_path, SQLITE3_OPEN_READONLY );
$db_st = $db->prepare('SELECT * FROM BULIST where BUID=:buid');
$db_st->bindValue(':buid', $db_id);
$results = $db_st->execute();
$row = $results->fetchArray();
if ( $row===FALSE ) {
return "Item $db_id not found";
}
$bun = $row['BUName'];
$bus = $row['Dir_Src'];
$bu_dt = $row['BU_DATE'];
if($bu_dt==''){
$bu_dt = date("Y-m-d");
}
$bu_t = $row['BU_TIME'];
if($bu_t==''){
$bu_t = '00:00';
}
$bu_r = $row['BU_REPEAT'];
switch($bu_r){
case 'D':
$id_checked = 'id="sched_ip_daily"';
break;
case 'W':
$id_checked = 'id="sched_ip_weekly"';
break;
case 'M':
$id_checked = 'id="sched_ip_monthly"';
break;
case 'N':
default:
$id_checked = 'id="sched_ip_none"';
}
$content = <<<'EOD'
<div class="section_header" >Edit Backup Schedule</div>
<div class="content_section_text" style="min-height: 350px;" >
<div class="two-col-panel">
<div>ID</div>
<div>$db_id</div>
<div>Backup Name</div>
<div>$bun</div>
<div>Data Source</div>
<div>$bus</div>
<div>Next Run Date/Time</div>
<div><input id="sched_date" type="date" value="$bu_dt" ></div>
<div></div>
<div><input id="sched_time" type="time" value="$bu_t"></div>
<div>Repeat</div>
<div>
<input style="width: 25px;" type="radio" name="sched_period" id="sched_ip_none" ><label for="sched_ip_none">None</label><br>
<input style="width: 25px;" type="radio" name="sched_period" id="sched_ip_daily"><label for="sched_ip_daily">Daily</label><br>
<input style="width: 25px;" type="radio" name="sched_period" id="sched_ip_weekly" ><label for="sched_ip_weekly">Weekly</label><br>
<input style="width: 25px;" type="radio" name="sched_period" id="sched_ip_monthly"><label for="sched_ip_monthly">Monthly</label>
</div>
<div></div>
<div>
<button class="btn_exec" onclick="btn_clk_nav(this, 'btn_edit_shed_bu', $db_id)" >Save</button>
<button class="btn_exec" onclick="btn_clk_nav(this, 'btn_cancel')" >Cancel</button>
</div>
</div>
</div>
EOD;
$content = str_replace($id_checked, $id_checked.' checked ', $content );
$content = str_replace('$bus', $bus, $content);
$content = str_replace('$bun', $bun, $content);
$content = str_replace('$bu_dt', $bu_dt, $content);
$content = str_replace('$bu_t', $bu_t, $content);
return str_replace('$db_id', $db_id, $content);
}
function save_bu_schedule( $postVars ){
//error_log( $postVars['id'] );
global $g_database_path;
$db = new SQLite3( $g_database_path );
$db_st = $db->prepare('UPDATE BULIST SET BU_DATE=:bud, BU_TIME=:but, BU_REPEAT=:bur where BUID=:buid');
$db_st->bindValue(':buid', $postVars['id'], SQLITE3_INTEGER );
$db_st->bindValue(':bud', $postVars['sched_date'] );
$db_st->bindValue(':but', $postVars['sched_time'] );
$db_st->bindValue(':bur', $postVars['sched_period'] );
$db_st->execute();
if( $db->lastErrorCode()!==0){
return $db->lastErrorCode();
}
}
?>