Newer
Older
backup-commander / html / inc / pagemap.php
<?php
/**
 * COPYRIGHT © 2024 JOHN PEARCEY
 * All rights reserved
*/


include_once __DIR__ . "/../shd/common.php";


/**
 * The commands should all return true to indicate that they are valid calls from the client.
 */
function invokeCommand( $cmd, $postvars ){
		
	
	if( $cmd=='bu-test-file-lines' ){
		sendHtmlOk_WithData( rpc( 'f:bu-test-file-lines', $postvars['buid'], $postvars['from-line-num'] ) );
		return true;
	}

	if( $cmd=='backup-list-state' ){		
		sendHtmlOk_WithData( [ 'state', rpc( 'f:getbu_list_state' ) ] );
		return true;
	}

	if( $cmd=='backup-list' ){	
		include_once __DIR__ . "/bu_list_content.php";		
		sendHtmlOk_WithData( [ 'page', getbu_list_content() ] );
		return true;
	}

	if( $cmd=='edit-db-bu' ){	
		include_once __DIR__ . "/new-file-bu.php";
		sendHtmlOk_WithData( [ 'page', getbu_cf_content( true, $postvars['id'] ) ] );
		return true;
	}

	if( $cmd=='edit-file-bu' ){
		include_once __DIR__ . "/new-file-bu.php";
		sendHtmlOk_WithData( [ 'page', getbu_cf_content( false, $postvars['id'] ) ] );
		return true;
	}

	if( $cmd=='new-db-bu' ){
		include_once __DIR__ . "/new-file-bu.php";
		sendHtmlOk_WithData( [ 'page', getbu_cf_content(true) ] );
		return true;
	}

	if( $cmd=='new-file-bu' ){		
		include_once __DIR__ . "/new-file-bu.php";
		sendHtmlOk_WithData( [ 'page', getbu_cf_content() ] );
		return true;
	}

	if( $cmd=='sched' ){		 
		include_once __DIR__ . "/edit-sh-bu.php";		
		sendHtmlOk_WithData( [ 'page', edit_sh_bu_getContent( $postvars['id'] ) ] );
		return true;
	}

	if( $cmd=='btn_run_bu' ){
		
		error_log( "test is " . $postvars['isTest'] );
		
		$res = rpc( 'f:kickoff-backup', $postvars['id'], 'true'===$postvars['isTest'] );
		
		//originally when this was handled by a bash script, the results would have been complex. The return
		//values could have been error, done or running.
		
		//for the moment, we return running or error and handle the blocking case next
		sendHtmlOk_WithData( $res );
		return true;
			
		/*include_once __DIR__ . "/btn_run_bu.php";				
		$res = btn_run_bu( $postvars['id'], $postvars['isTest'] );
		
		if($res[0]=='running'){
			// script kicked off asynchronously
			sendHtmlOk_WithData( $res );
			return true;
		}
		
		if($res[0]=='done'){
			// script ran synchronously and finished			
			sendHtmlOk_WithData( $res );
			return true;
		}

		if($res[0]=='error'){
			sendHtmlError( $res );
			return true;
		}
		sendHtmlError( 'Unknown return value from btn_run_bu' );
		return true;
		*/

		
	}

	if( $cmd=='edit_shed_bu' ){
		
		//include_once __DIR__ . "/edit-sh-bu.php";		
		//$db_err = save_bu_schedule( $postvars );	
	
		[$db_err] = rpc( 'f:save_bu_schedule', $postvars );
	
		if($db_err>0){
			sendHtmlError( "DB error: $db_err" );
			return true;
		}
		
		if($postvars['final-page'] == '' ){
			error_log( "Error: Expecting a final-page for: ". $cmd );
			sendHtmlError( "Error: Expecting a final-page for: $cmd in ". __FILE__ );
			return true;
		}
		return invokeCommand( $postvars['final-page'], $postvars );
	}
			
			
	if( $cmd=='new-item-bu' ){
		
		//include_once __DIR__ . "/new-file-bu.php";
		//$db_err = save_bu_item( $postvars );	
		
		[$db_err] = rpc( 'f:save_bu_item', $postvars );
		
		if($db_err>0){
			sendHtmlError( "DB error: $db_err" );
			return true;
		}
		
		if($postvars['final-page'] == '' ){
			error_log( "Error: Expecting a final-page for: ". $cmd );
			sendHtmlError( "Error: Expecting a final-page for: $cmd in ". __FILE__ );
			return true;
		}
		return invokeCommand( $postvars['final-page'], $postvars );
		
	}
			
	if( $cmd=='edit-item-bu' ){
		
		//include_once __DIR__ . "/new-file-bu.php";
		//$db_err = save_bu_item( $postvars, $postvars['id'] );	
		
		[$db_err] = rpc( 'f:save_bu_item', $postvars, $postvars['id'] );

		if($db_err>0){
			sendHtmlError( "DB error: $db_err" );
			return true;
		}
		
		if($postvars['final-page'] == '' ){
			error_log( "Error: Expecting a final-page for: ". $cmd );
			sendHtmlError( "Error: Expecting a final-page for: $cmd in ". __FILE__ );
			return true;
		}
		return invokeCommand( $postvars['final-page'], $postvars );
		
	}

	if( $cmd=='delete-bu' ){
		
		[$db_err] = rpc( 'f:delete_bu_item', $postvars['id'] );		
		
		if($db_err>0){
			sendHtmlError( "DB error: $db_err" );
			return true;
		}
		
		if($postvars['final-page'] == '' ){
			error_log( "Error: Expecting a final-page for: ". $cmd );
			sendHtmlError( "Error: Expecting a final-page for: $cmd in ". __FILE__ );
			return true;
		}
		return invokeCommand( $postvars['final-page'], $postvars );

	}
			
}
		
?>