<?php


function run_manual_program($name, $path_to_root)
{
    
    
    $access_code = $_POST['access_code'];
    if(validate_admin_functions_access_code($access_code) !== true){
        display_error("Access code entered is not valid.");
        return;
    }

    switch ($name) {
        case 'delete_fi_batches':
            include_once($path_to_root . "/admin/includes/custom_programs/custom_program_delete_fi_batches.inc");
            cp_delete_fi_batches($path_to_root);
            break;
        
        case 'delete_gl_batches':
            include_once($path_to_root . "/admin/includes/custom_programs/custom_program_delete_gl_batches.inc");
            cp_delete_gl_batches($path_to_root);
            break;
        
        
        case '':
            display_error("No program name entered");
            break;
        default :
            display_error("Unknown program name");
            break;
    }


}



function write_custom_program_log($log_filename, $message="")
{

    global $installed_path;
      
    $log_filename .= ".txt"; 
    $log_filepathname = $installed_path . '/tmp/custom_program_logs/'.$log_filename;
    file_put_contents($log_filepathname, format_microtime('Y-m-d H:i:s.u')."\r\n",FILE_APPEND);
    file_put_contents($log_filepathname, $message."\r\n"."\r\n",FILE_APPEND);
            
}


function cp_display_run_custom_program_edit_controls()
{
    start_table(TABLESTYLE); 
    //custom_values_list_row("Script", 'custom_script', $values_array, null, "");
    text_row("Program Name:", 'program_name', null, 100, 200);
    password_row(_("Access Code:"), 'access_code', '');
    
    end_table(); 
    
}


function cp_display_custom_edit_controls($name)
{
    global $path_to_root;

    
    
    switch ($name) {
        case 'delete_fi_batches':
            include_once($path_to_root . "/admin/includes/custom_programs/custom_program_delete_fi_batches.inc");
            cp_display_delete_fi_batches_custom_edit_controls($path_to_root);
            break;
        
        case 'delete_gl_batches':
            include_once($path_to_root . "/admin/includes/custom_programs/custom_program_delete_gl_batches.inc");
            cp_display_delete_gl_batches_custom_edit_controls($path_to_root);
            break;
        
        
        case '':
            display_error("No program name entered");
            break;
        default :
            display_error("Unknown program name");
            break;
    }
    
}