public static function render_page_process($PATH)
    {
        if (PHOROMATIC_USER_IS_VIEWER) {
            return;
        }
        $is_new = true;
        if (!empty($PATH[0]) && $PATH[0] == 'all') {
            $main = '<h1>Past Benchmark Tickets</h1>';
            $stmt = phoromatic_server::$db->prepare('SELECT * FROM phoromatic_benchmark_tickets WHERE AccountID = :account_id AND State >= 0 ORDER BY TicketIssueTime DESC');
            $stmt->bindValue(':account_id', $_SESSION['AccountID']);
            $result = $stmt->execute();
            $main .= '<ol>';
            if ($result) {
                $row = $result->fetchArray();
                if (!empty($row)) {
                    do {
                        $main .= '<li><a href="?benchmark/' . $row['TicketID'] . '">' . $row['Title'] . '</a></li>';
                    } while ($row = $result->fetchArray());
                }
            } else {
                $main .= '<li>No Benchmark Tickets Found</li>';
            }
            $main .= '</ol>';
        } else {
            if (!empty($PATH[0]) && is_numeric($PATH[0])) {
                $stmt = phoromatic_server::$db->prepare('SELECT * FROM phoromatic_benchmark_tickets WHERE AccountID = :account_id AND TicketID = :ticket_id');
                $stmt->bindValue(':account_id', $_SESSION['AccountID']);
                $stmt->bindValue(':ticket_id', $PATH[0]);
                $result = $stmt->execute();
                $row = $result->fetchArray();
                if (!empty($row)) {
                    if (isset($_GET['remove'])) {
                        $stmt = phoromatic_server::$db->prepare('DELETE FROM phoromatic_benchmark_tickets WHERE AccountID = :account_id AND TicketID = :ticket_id');
                        $stmt->bindValue(':account_id', $_SESSION['AccountID']);
                        $stmt->bindValue(':ticket_id', $PATH[0]);
                        $result = $stmt->execute();
                        header('Location: /?benchmark');
                    } else {
                        if (isset($_GET['repeat'])) {
                            $stmt = phoromatic_server::$db->prepare('UPDATE phoromatic_benchmark_tickets SET TicketIssueTime = :new_ticket_time, State = 1 WHERE AccountID = :account_id AND TicketID = :ticket_id');
                            $stmt->bindValue(':account_id', $_SESSION['AccountID']);
                            $stmt->bindValue(':ticket_id', $PATH[0]);
                            $stmt->bindValue(':new_ticket_time', time());
                            $result = $stmt->execute();
                        } else {
                            if (isset($_GET['disable'])) {
                                $stmt = phoromatic_server::$db->prepare('UPDATE phoromatic_benchmark_tickets SET State = 0 WHERE AccountID = :account_id AND TicketID = :ticket_id');
                                $stmt->bindValue(':account_id', $_SESSION['AccountID']);
                                $stmt->bindValue(':ticket_id', $PATH[0]);
                                $result = $stmt->execute();
                            }
                        }
                    }
                    $main = null;
                    $main .= '<h1>' . $row['Title'] . '</h1>';
                    $main .= '<h3>' . $row['Description'] . '</h3>';
                    $main .= '<p>This benchmark ticket was created on <strong>' . date('j F Y \\a\\t H:i', strtotime($row['LastModifiedOn'])) . '</strong> by <strong>' . $row['LastModifiedBy'] . '. The ticket was last issued for testing at ' . date('j F Y \\a\\t H:i', $row['TicketIssueTime']) . '</strong>.';
                    $main .= '<p> <a href="/?benchmark/' . $PATH[0] . '/&repeat">Repeat Ticket</a> &nbsp; &nbsp; &nbsp; <a href="/?benchmark/' . $PATH[0] . '/&remove">Remove Ticket</a>' . (!isset($_GET['disable']) && $row['State'] > 0 ? ' &nbsp; &nbsp; &nbsp; <a href="/?benchmark/' . $PATH[0] . '/&disable">End Ticket</a>' : null) . '</p>';
                    $main .= '<hr /><h1>System Targets</h1><ol>';
                    foreach (explode(',', $row['RunTargetSystems']) as $system_id) {
                        $main .= '<li><a href="?systems/' . $system_id . '">' . phoromatic_server::system_id_to_name($system_id) . '</a></li>';
                    }
                    $main .= '</ol>';
                    $main .= '<hr /><h1>Ticket Payload</h1>';
                    $main .= '<p>This ticket runs the <strong>' . $row['SuiteToRun'] . '</strong> test suite:</p>';
                    $main .= '<div style="max-height: 400px; overflow-y: scroll;">';
                    $xml_path = phoromatic_server::phoromatic_account_suite_path($_SESSION['AccountID'], $row['SuiteToRun']) . 'suite-definition.xml';
                    if (is_file($xml_path)) {
                        $test_suite = new pts_test_suite($xml_path);
                        //	$main .= '<h2>' . $test_suite->get_title() . '</h2>';
                        //	$main .= '<p><strong>' . $test_suite->get_maintainer() . '</strong></p>';
                        //	$main .= '<p><em>' . $test_suite->get_description() . '</em></p>';
                        foreach ($test_suite->get_contained_test_result_objects() as $tro) {
                            $main .= '<h3>' . $tro->test_profile->get_title() . ' [' . $tro->test_profile->get_identifier() . ']</h3>';
                            $main .= '<p>' . $tro->get_arguments_description() . '</p>';
                        }
                        //$main .= '<hr />';
                    }
                    $main .= '</div><hr />';
                    $main .= '<div class="pts_phoromatic_info_box_area">';
                    $main .= '<div style="margin: 0 5%;"><ul style="max-height: 100%;"><li><h1>Test Results</h1></li>';
                    $stmt = phoromatic_server::$db->prepare('SELECT Title, SystemID, ScheduleID, PPRID, UploadTime, TimesViewed FROM phoromatic_results WHERE AccountID = :account_id AND BenchmarkTicketID = :ticket_id ORDER BY UploadTime DESC');
                    $stmt->bindValue(':account_id', $_SESSION['AccountID']);
                    $stmt->bindValue(':ticket_id', $PATH[0]);
                    $test_result_result = $stmt->execute();
                    $results = 0;
                    while ($test_result_row = $test_result_result->fetchArray()) {
                        $main .= '<a onclick=""><li id="result_select_' . $test_result_row['PPRID'] . '"><input type="checkbox" id="result_compare_checkbox_' . $test_result_row['PPRID'] . '" onclick="javascript:phoromatic_checkbox_toggle_result_comparison(\'' . $test_result_row['PPRID'] . '\');" onchange="return false;"></input> <span onclick="javascript:phoromatic_window_redirect(\'?result/' . $test_result_row['PPRID'] . '\');">' . $test_result_row['Title'] . '</span><br /><table><tr><td>' . phoromatic_system_id_to_name($test_result_row['SystemID']) . '</td><td>' . phoromatic_user_friendly_timedate($test_result_row['UploadTime']) . '</td><td>' . $test_result_row['TimesViewed'] . ' Times Viewed</td></table></li></a>';
                        $results++;
                    }
                    if ($results == 0) {
                        $main .= '<li class="light" style="text-align: center;">No Results Found</li>';
                    } else {
                        if ($results > 3) {
                            $main .= '<a onclick=""><li id="global_bottom_totals"><input type="checkbox" id="global_checkbox" onclick="javascript:phoromatic_toggle_checkboxes_on_page(this);" onchange="return false;"></input> <strong>' . $results . ' Results</strong></li></a>';
                        }
                    }
                    $main .= '</ul></div>';
                    $main .= '</div>';
                }
            } else {
                if (isset($_POST['benchmark_title']) && !empty($_POST['benchmark_title'])) {
                    $title = phoromatic_get_posted_var('benchmark_title');
                    $description = phoromatic_get_posted_var('benchmark_description');
                    $result_identifier = phoromatic_get_posted_var('benchmark_identifier');
                    $suite_to_run = phoromatic_get_posted_var('suite_to_run');
                    if (strlen($title) < 3) {
                        echo '<h2>Title must be at least three characters.</h2>';
                        exit;
                    }
                    if (strlen($result_identifier) < 3) {
                        echo '<h2>Identifier must be at least three characters.</h2>';
                        exit;
                    }
                    if (strlen($suite_to_run) < 3) {
                        echo '<h2>You must specify a suite to run.</h2>';
                        exit;
                    }
                    $run_target_systems = phoromatic_get_posted_var('run_on_systems', array());
                    $run_target_groups = phoromatic_get_posted_var('run_on_groups', array());
                    if (!is_array($run_target_systems)) {
                        $run_target_systems = array();
                    }
                    if (!is_array($run_target_groups)) {
                        $run_target_groups = array();
                    }
                    $run_target_systems = implode(',', $run_target_systems);
                    $run_target_groups = implode(',', $run_target_groups);
                    if ($is_new) {
                        do {
                            $ticket_id = rand(10, 999999);
                            $matching_tickets = phoromatic_server::$db->querySingle('SELECT TicketID FROM phoromatic_benchmark_tickets WHERE TicketID = \'' . $ticket_id . '\'');
                        } while (!empty($matching_tickets));
                    }
                    $env_vars = array();
                    if (is_numeric($_POST['PTS_CONCURRENT_TEST_RUNS']) && $_POST['PTS_CONCURRENT_TEST_RUNS'] > 0) {
                        array_push($env_vars, 'PTS_CONCURRENT_TEST_RUNS=' . $_POST['PTS_CONCURRENT_TEST_RUNS']);
                    }
                    if (is_numeric($_POST['TOTAL_LOOP_TIME']) && $_POST['TOTAL_LOOP_TIME'] > 0) {
                        array_push($env_vars, 'TOTAL_LOOP_TIME=' . $_POST['TOTAL_LOOP_TIME']);
                    }
                    $env_vars = implode(';', $env_vars);
                    // Add benchmark
                    $stmt = phoromatic_server::$db->prepare('INSERT OR REPLACE INTO phoromatic_benchmark_tickets (AccountID, TicketID, TicketIssueTime, Title, ResultIdentifier, SuiteToRun, Description, State, LastModifiedBy, LastModifiedOn, RunTargetGroups, RunTargetSystems, EnvironmentVariables) VALUES (:account_id, :ticket_id, :ticket_time, :title, :result_identifier, :suite_to_run, :description, :state, :modified_by, :modified_on, :run_target_groups, :run_target_systems, :environment_variables)');
                    $stmt->bindValue(':account_id', $_SESSION['AccountID']);
                    $stmt->bindValue(':ticket_id', $ticket_id);
                    $stmt->bindValue(':ticket_time', time());
                    $stmt->bindValue(':title', $title);
                    $stmt->bindValue(':result_identifier', $result_identifier);
                    $stmt->bindValue(':suite_to_run', $suite_to_run);
                    $stmt->bindValue(':description', $description);
                    $stmt->bindValue(':state', 1);
                    $stmt->bindValue(':modified_by', $_SESSION['UserName']);
                    $stmt->bindValue(':modified_on', phoromatic_server::current_time());
                    $stmt->bindValue(':public_key', $public_key);
                    $stmt->bindValue(':run_target_groups', $run_target_groups);
                    $stmt->bindValue(':run_target_systems', $run_target_systems);
                    $stmt->bindValue(':environment_variables', $env_vars);
                    $result = $stmt->execute();
                    phoromatic_add_activity_stream_event('benchmark', $benchmark_id, $is_new ? 'added' : 'modified');
                    if ($result) {
                        header('Location: ?benchmark/' . $schedule_id);
                    }
                }
                $main = '
			<h2>' . ($is_new ? 'Create' : 'Edit') . ' A Benchmark</h2>
			<p>This page allows you to run a test suite -- consisting of a single or multiple test suites -- on a given set/group of systems right away at their next earliest possibility. This benchmark mode is an alternative to the <a href="?schedules">benchmark schedules</a> for reptitive/routine testing.</p>';
                $local_suites = pts_file_io::glob(phoromatic_server::phoromatic_account_suite_path($_SESSION['AccountID']) . '*/suite-definition.xml');
                if (empty($local_suites)) {
                    $main .= '<p><strong>Before you can create a benchmark ticket you must first <a href="?build_suite">create a test suite</a> with the tests you wish to run.</strong></p>';
                } else {
                    $main .= '<form action="' . $_SERVER['REQUEST_URI'] . '" name="run_benchmark" id="run_benchmark" method="post" enctype="multipart/form-data" onsubmit="return validate_run_benchmark();">
				<h3>Title:</h3>
				<p>The title is the name of the result file for this test run.</p>
				<p><input type="text" name="benchmark_title" value="' . (!$is_new ? $e_schedule['Title'] : null) . '" /></p>
				<h3>Test Run Identifier:</h3>
				<p>The test run identifier is the per-system name for the system(s) being benchmarked. The following variables may be used: <strong>.SYSTEM</strong>, <strong>.GROUP</strong>. Any custom per-user system variables set via the individual system pages can also be used.</p>
				<p><input type="text" name="benchmark_identifier" value="' . (!$is_new ? $e_schedule['Identifier'] : null) . '" /></p>
				<h3>Test Suite To Run:</h3>
				<p><a href="?build_suite">Build a suite</a> to add/select more tests to run or <a href="?local_suites">view local suites</a> for more information on a particular suite. A test suite is a set of test profiles to run in a pre-defined manner.</p>';
                    $main .= '<p><select name="suite_to_run">';
                    foreach ($local_suites as $xml_path) {
                        $id = basename(dirname($xml_path));
                        $test_suite = new pts_test_suite($xml_path);
                        $main .= '<option value="' . $id . '">' . $test_suite->get_title() . ' - ' . $id . '</option>';
                    }
                    $main .= '</select></p>';
                    $main .= '<h3>Description:</h3>
				<p>The description is an optional way to add more details about the intent or objective of this test run.</p>
				<p><textarea name="benchmark_description" id="benchmark_description" cols="50" rows="3">' . (!$is_new ? $e_schedule['Description'] : null) . '</textarea></p>
				<hr /><h3>System Targets:</h3>
				<p>Select the systems that should be benchmarked at their next earliest convenience.</p>
				<p style="white-space: nowrap;">';
                    $stmt = phoromatic_server::$db->prepare('SELECT Title, SystemID FROM phoromatic_systems WHERE AccountID = :account_id AND State >= 0 ORDER BY Title ASC');
                    $stmt->bindValue(':account_id', $_SESSION['AccountID']);
                    $result = $stmt->execute();
                    if (!$is_new) {
                        $e_schedule['RunTargetSystems'] = explode(',', $e_schedule['RunTargetSystems']);
                        $e_schedule['RunTargetGroups'] = explode(',', $e_schedule['RunTargetGroups']);
                    }
                    if ($row = $result->fetchArray()) {
                        $main .= '<h4>Systems: ';
                        do {
                            $main .= '<input type="checkbox" name="run_on_systems[]" value="' . $row['SystemID'] . '" ' . (!$is_new && in_array($row['SystemID'], $e_schedule['RunTargetSystems']) ? 'checked="checked" ' : null) . '/> ' . $row['Title'] . ' ';
                        } while ($row = $result->fetchArray());
                        $main .= '</h4>';
                    }
                    $stmt = phoromatic_server::$db->prepare('SELECT GroupName FROM phoromatic_groups WHERE AccountID = :account_id ORDER BY GroupName ASC');
                    $stmt->bindValue(':account_id', $_SESSION['AccountID']);
                    $result = $stmt->execute();
                    if ($row = $result->fetchArray()) {
                        $main .= '<h4>Groups: ';
                        do {
                            $main .= '<input type="checkbox" name="run_on_groups[]" value="' . $row['GroupName'] . '" ' . (!$is_new && in_array($row['GroupName'], $e_schedule['RunTargetGroups']) ? 'checked="checked" ' : null) . '/> ' . $row['GroupName'] . ' ';
                        } while ($row = $result->fetchArray());
                        $main .= '</h4>';
                    }
                    $main .= '</p>
				<hr /><h3>Environment Options</h3>
				<h4>Stress Testing</h4>
				<p>If you wish to test systems for stability/reliability rather than performance, use this option and specify the number of tests to run concurrently (two or more) and (optionally) for the total period of time to continue looping the benchmarks. These options are intended to just stress the system and will not record any benchmark results. From the command-line this testing mode can be used via the <em>phoronix-test-suite stress-run</em> sub-command.</p>
				<p><strong>Concurrent Number Of Test Processes:</strong> <select name="PTS_CONCURRENT_TEST_RUNS"><option value="0">Disabled</option>';
                    for ($i = 2; $i <= 24; $i++) {
                        $main .= '<option value="' . $i . '">' . $i . '</option>';
                    }
                    $main .= '</select></p>
				<p><strong>Force Loop Time:</strong> <select name="TOTAL_LOOP_TIME"><option value="0">Disabled</option>';
                    $s = true;
                    for ($i = 60; $i <= 60 * 24 * 90; $i += 60) {
                        if ($i > 10080) {
                            // 7 days
                            if ($i % 1440 != 0) {
                                continue;
                            }
                        } else {
                            if ($i > 480) {
                                $s = !$s;
                                if (!$s) {
                                    continue;
                                }
                            }
                        }
                        $main .= '<option value="' . $i . '">' . pts_strings::format_time($i, 'MINUTES') . '</option>';
                    }
                    $main .= '</select></p>

				<h4>System Monitoring</h4>
				<p>The Phoronix Test Suite system monitor module allows for select hardware/software sensors to be logged in real-time while running the selected test suite. The supported sensors are then shown within the result file upon the test\'s completion.</p>';
                    foreach (phodevi::available_sensors() as $sensor) {
                        $main .= '<input type="checkbox" name="MONITOR" value="' . phodevi::sensor_identifier($sensor) . '" /> ' . phodevi::sensor_name($sensor) . ' &nbsp; ';
                    }
                    $main .= '<hr /><p align="left"><input name="submit" value="' . ($is_new ? 'Run' : 'Edit') . ' Benchmark" type="submit" onclick="return pts_rmm_validate_schedule();" /></p>
					</form>';
                }
            }
        }
        $stmt = phoromatic_server::$db->prepare('SELECT * FROM phoromatic_benchmark_tickets WHERE AccountID = :account_id AND State >= 0 AND TicketIssueTime > :time_cutoff ORDER BY TicketIssueTime DESC LIMIT 30');
        $stmt->bindValue(':account_id', $_SESSION['AccountID']);
        $stmt->bindValue(':time_cutoff', time() - 60 * 60 * 24 * 14);
        $result = $stmt->execute();
        $right = '<ul><li>Benchmark Tickets</li>';
        if ($result) {
            $row = $result->fetchArray();
            if (!empty($row)) {
                do {
                    $right .= '<li><a href="?benchmark/' . $row['TicketID'] . '">' . $row['Title'] . '</a></li>';
                } while ($row = $result->fetchArray());
            }
        }
        $right .= '<li><em><a href="?benchmark/all">View All Past Tickets</a></em></li>';
        $right .= '</ul>';
        echo phoromatic_webui_header_logged_in();
        echo phoromatic_webui_main($main, phoromatic_webui_right_panel_logged_in($right));
        echo phoromatic_webui_footer();
    }
    public static function render_page_process($PATH)
    {
        if (PHOROMATIC_USER_IS_VIEWER) {
            return;
        }
        $is_new = true;
        if (!empty($PATH[0]) && is_numeric($PATH[0])) {
            $stmt = phoromatic_server::$db->prepare('SELECT * FROM phoromatic_schedules WHERE AccountID = :account_id AND ScheduleID = :schedule_id');
            $stmt->bindValue(':account_id', $_SESSION['AccountID']);
            $stmt->bindValue(':schedule_id', $PATH[0]);
            $result = $stmt->execute();
            $e_schedule = $result->fetchArray();
            if (!empty($e_schedule)) {
                $is_new = false;
            }
        }
        if (isset($_POST['schedule_title']) && !empty($_POST['schedule_title'])) {
            $title = phoromatic_get_posted_var('schedule_title');
            $description = phoromatic_get_posted_var('schedule_description');
            $pre_install_context = phoromatic_get_posted_var('pre_install_set_context');
            $post_install_context = phoromatic_get_posted_var('post_install_set_context');
            $pre_run_context = phoromatic_get_posted_var('pre_run_set_context');
            $post_run_context = phoromatic_get_posted_var('post_run_set_context');
            $system_all = phoromatic_get_posted_var('system_all');
            $run_target_systems = phoromatic_get_posted_var('run_on_systems', array());
            $run_target_groups = phoromatic_get_posted_var('run_on_groups', array());
            if (!is_array($run_target_systems)) {
                $run_target_systems = array();
            }
            if (!is_array($run_target_groups)) {
                $run_target_groups = array();
            }
            $run_target_systems = implode(',', $run_target_systems);
            $run_target_groups = implode(',', $run_target_groups);
            $schedule_hour = phoromatic_get_posted_var('schedule_hour');
            $schedule_minute = phoromatic_get_posted_var('schedule_minute');
            $days_active = phoromatic_get_posted_var('days_active');
            $context_files = array('SetContextPreInstall' => 'pre_install_set_context', 'SetContextPostInstall' => 'post_install_set_context', 'SetContextPreRun' => 'pre_run_set_context', 'SetContextPostRun' => 'post_run_set_context');
            foreach ($context_files as $i => $context) {
                ${$context} = $is_new ? null : $e_schedule[$i];
            }
            foreach ($context_files as $context) {
                ${$context} = null;
                if ($_FILES[$context]['error'] == 0 && $_FILES[$context]['size'] > 0) {
                    $sha1_hash = sha1_file($_FILES[$context]['tmp_name']);
                    if (!is_file(phoromatic_server::phoromatic_account_path($_SESSION['AccountID']) . 'context_' . $sha1_hash)) {
                        move_uploaded_file($_FILES[$context]['tmp_name'], phoromatic_server::phoromatic_account_path($_SESSION['AccountID']) . 'context_' . $sha1_hash);
                    }
                    ${$context} = $sha1_hash;
                }
            }
            // TODO XXX: Validation of input
            // Need a unique schedule ID
            if ($is_new) {
                do {
                    $schedule_id = rand(10, 9999);
                    $matching_schedules = phoromatic_server::$db->querySingle('SELECT ScheduleID FROM phoromatic_schedules WHERE AccountID = \'' . $_SESSION['AccountID'] . '\' AND ScheduleID = \'' . $schedule_id . '\'');
                } while (!empty($matching_schedules));
                // Need a unique public ID
                do {
                    $public_key = pts_strings::random_characters(12, true);
                    $matching_schedules = phoromatic_server::$db->querySingle('SELECT ScheduleID FROM phoromatic_schedules WHERE AccountID = \'' . $_SESSION['AccountID'] . '\' AND PublicKey = \'' . $public_key . '\'');
                } while (!empty($matching_schedules));
            } else {
                $schedule_id = $e_schedule['ScheduleID'];
                $public_key = $e_schedule['PublicKey'];
            }
            // Add schedule
            $stmt = phoromatic_server::$db->prepare('INSERT OR REPLACE INTO phoromatic_schedules (AccountID, ScheduleID, Title, Description, State, ActiveOn, RunAt, SetContextPreInstall, SetContextPostInstall, SetContextPreRun, SetContextPostRun, LastModifiedBy, LastModifiedOn, PublicKey, RunTargetGroups, RunTargetSystems) VALUES (:account_id, :schedule_id, :title, :description, :state, :active_on, :run_at, :context_pre_install, :context_post_install, :context_pre_run, :context_post_run, :modified_by, :modified_on, :public_key, :run_target_groups, :run_target_systems)');
            $stmt->bindValue(':account_id', $_SESSION['AccountID']);
            $stmt->bindValue(':schedule_id', $schedule_id);
            $stmt->bindValue(':title', $title);
            $stmt->bindValue(':description', $description);
            $stmt->bindValue(':state', 1);
            $stmt->bindValue(':active_on', implode(',', $days_active));
            $stmt->bindValue(':run_at', $schedule_hour . '.' . $schedule_minute);
            $stmt->bindValue(':context_pre_install', $pre_install_set_context);
            $stmt->bindValue(':context_post_install', $post_install_set_context);
            $stmt->bindValue(':context_pre_run', $pre_run_set_context);
            $stmt->bindValue(':context_post_run', $post_run_set_context);
            $stmt->bindValue(':modified_by', $_SESSION['UserName']);
            $stmt->bindValue(':modified_on', phoromatic_server::current_time());
            $stmt->bindValue(':public_key', $public_key);
            $stmt->bindValue(':run_target_groups', $run_target_groups);
            $stmt->bindValue(':run_target_systems', $run_target_systems);
            $result = $stmt->execute();
            phoromatic_add_activity_stream_event('schedule', $schedule_id, $is_new ? 'added' : 'modified');
            if ($result) {
                header('Location: ?schedules/' . $schedule_id);
            }
        }
        echo phoromatic_webui_header_logged_in();
        $main = '
		<hr />
		<h2>' . ($is_new ? 'Create' : 'Edit') . ' A Schedule</h2>
		<p>A test schedule is used to facilitate automatically running a set of test(s)/suite(s) on either a routine timed basis or whenever triggered by an external script or process, e.g. Git/VCS commit, manually triggered, etc.</p>';
        $main .= '<form action="' . $_SERVER['REQUEST_URI'] . '" name="add_test" id="add_test" method="post" enctype="multipart/form-data" onsubmit="return validate_schedule();">
		<h3>Title:</h3>
		<p><input type="text" name="schedule_title" value="' . (!$is_new ? $e_schedule['Title'] : null) . '" /></p>
		<h3><sup>1</sup> Pre-Install Set Context Script:</h3>
		<p><input type="file" name="pre_install_set_context" /></p>
		<h3><sup>1</sup> Post-Install Set Context Script:</h3>
		<p><input type="file" name="post_install_set_context" /></p>
		<h3><sup>1</sup> Pre-Run Set Context Script:</h3>
		<p><input type="file" name="pre_run_set_context" /></p>
		<h3><sup>1</sup>Post-Run Set Context Script:</h3>
		<p><input type="file" name="post_run_set_context" /></p>
		<h3>System Targets:</h3>
		<p>';
        $stmt = phoromatic_server::$db->prepare('SELECT Title, SystemID FROM phoromatic_systems WHERE AccountID = :account_id AND State >= 0 ORDER BY Title ASC');
        $stmt->bindValue(':account_id', $_SESSION['AccountID']);
        $result = $stmt->execute();
        if (!$is_new) {
            $e_schedule['RunTargetSystems'] = explode(',', $e_schedule['RunTargetSystems']);
            $e_schedule['RunTargetGroups'] = explode(',', $e_schedule['RunTargetGroups']);
        }
        if ($row = $result->fetchArray()) {
            $main .= '<h4>Systems: ';
            do {
                $main .= '<input type="checkbox" name="run_on_systems[]" value="' . $row['SystemID'] . '" ' . (!$is_new && in_array($row['SystemID'], $e_schedule['RunTargetSystems']) ? 'checked="checked" ' : null) . '/> ' . $row['Title'] . ' ';
            } while ($row = $result->fetchArray());
            $main .= '</h4>';
        }
        $stmt = phoromatic_server::$db->prepare('SELECT GroupName FROM phoromatic_groups WHERE AccountID = :account_id ORDER BY GroupName ASC');
        $stmt->bindValue(':account_id', $_SESSION['AccountID']);
        $result = $stmt->execute();
        if ($row = $result->fetchArray()) {
            $main .= '<h4>Groups: ';
            do {
                $main .= '<input type="checkbox" name="run_on_groups[]" value="' . $row['GroupName'] . '" ' . (!$is_new && in_array($row['GroupName'], $e_schedule['RunTargetGroups']) ? 'checked="checked" ' : null) . '/> ' . $row['GroupName'] . ' ';
            } while ($row = $result->fetchArray());
            $main .= '</h4>';
        }
        $main .= '</p>
		<h3>Description:</h3>
		<p><textarea name="schedule_description" id="schedule_description" cols="50" rows="3">' . (!$is_new ? $e_schedule['Description'] : null) . '</textarea></p>
		<table class="pts_phoromatic_schedule_type">
<tr>
  <td><h3>Time-Based Testing</h3><em>Time-based testing allows tests to automatically commence at a given time on a defined cycle each day/week. This option is primarly aimed for those wishing to run a set of benchmarks every morning or night or at another defined period.</em></td>
  <td><h3>Run Time:</h3>
			<p><select name="schedule_hour" id="schedule_hour">';
        if (!$is_new) {
            $run_at = explode('.', $e_schedule['RunAt']);
            $days_active = !empty($e_schedule['ActiveOn']) ? explode(',', $e_schedule['ActiveOn']) : array();
        }
        for ($i = 0; $i <= 23; $i++) {
            $i_f = strlen($i) == 1 ? '0' . $i : $i;
            $main .= '<option value="' . $i_f . '"' . (!$is_new && $run_at[0] == $i ? 'selected="selected" ' : null) . '>' . $i_f . '</option>';
        }
        $main .= '</select> <select name="schedule_minute" id="schedule_minute">';
        for ($i = 0; $i < 60; $i += 10) {
            $i_f = strlen($i) == 1 ? '0' . $i : $i;
            $main .= '<option value="' . $i_f . '"' . (!$is_new && $run_at[1] == $i ? 'selected="selected" ' : null) . '>' . $i_f . '</option>';
        }
        $main .= '</select><h3>Active On:</h3><p>';
        $week = array('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday');
        foreach ($week as $index => $day) {
            $main .= '<input type="checkbox" name="days_active[]" value="' . $index . '"' . (!$is_new && in_array($index, $days_active) ? 'checked="checked" ' : null) . '/> ' . $day;
        }
        $main .= '</p></td>
</tr>
<tr>
  <td><h3>Trigger-Based Testing</h3><em>To carry out trigger-based testing, you can simply have an external process/script trigger (&quot;ping&quot;) a specialized URL whenever an event occurs to commence a new round of testing. This is the most customizable approach to having Phoromatic run tests on a system if you wish to have it occur whenever a Git/SVN commit takes place or other operations.</em></td>
  <td><h3>Once creating the test schedule there will be a specialized URL you can use for &quot;pinging&quot; where you can pass it a Git commit hash, SVN revision number, date, or other unique identifiers to externally trigger the test schedules and systems to begin testing. This custom trigger is passed to any of the used context scripts for setting up the system in an appropriate state.</h3></td>
</tr>
<tr>
  <td><h3>One-Time / Manual Testing</h3><em>Carrying out Phoromatic-controlled benchmark on no routine schedule, similar to the trigger-based testing.</em></td>
  <td><h3>If you wish to only run a set of tests once on a given system or to do so seldom with the same set of tests, simply proceed with creating the test schedule without setting any run time / active days. When going to the web page for this test schedule there will be a button to trigger the tests to run on all affected systems.</h3></td>
</tr>
</table>

			<p><sup>1</sup> <em>Indicates optional field.</em></p>
			<p align="right"><input name="submit" value="' . ($is_new ? 'Create' : 'Edit') . ' Schedule" type="submit" onclick="return pts_rmm_validate_schedule();" /></p>
			</form>';
        echo phoromatic_webui_main($main, phoromatic_webui_right_panel_logged_in());
        echo phoromatic_webui_footer();
    }