public static function cpu_string()
 {
     $model = phodevi::read_property('cpu', 'model');
     // Append the processor frequency to string
     if (($freq = phodevi::read_property('cpu', 'default-frequency')) > 0) {
         $model = str_replace($freq . 'GHz', null, $model);
         // we'll replace it if it's already in the string
         $model .= ' @ ' . $freq . 'GHz';
     }
     $core_count = phodevi::read_property('cpu', 'core-count');
     return $model . ' (' . pts_strings::plural_handler($core_count, 'Core') . ')';
 }
    public static function render_page_process($PATH)
    {
        echo phoromatic_webui_header_logged_in();
        $main = '<h1>Phoromatic</h1>';
        $main .= phoromatic_systems_needing_attention();
        $main .= '<p>Phoromatic is the remote management and test orchestration component to the <a href="http://www.phoronix-test-suite.com/">Phoronix Test Suite</a>. Phoromatic allows you to take advantage of the Phoronix Test Suite\'s vast feature-set across multiple systems over the LAN/WAN, manage entire test farms of systems for benchmarking via a centralized interface, centrally collect test results, and carry out other enteprise-focused tasks.</p>';
        $main_page_message = phoromatic_server::read_setting('main_page_message');
        if (!PHOROMATIC_USER_IS_VIEWER) {
            $main .= '<p>To get started with your new account, the basic steps to get started include:</p>
				<ol>
					<li>Connect/sync the Phoronix Test Suite client systems (the systems to be benchmarked) to this account. In the simplest form, you just need to run the following command on the test systems: <strong>phoronix-test-suite phoromatic.connect ' . phoromatic_web_socket_server_addr() . '</strong>. For more information view the instructions on the <a href="?systems">systems page</a>.</li>
					<li>Configure your <a href="?settings">account settings</a>.</li>
					<li><a href="?schedules">Create a test schedule</a>. A schedule is for running test(s) on selected system(s) on a routine, timed basis or whenever a custom trigger is passed to the Phoromatic server. A test schedule could be for running benchmarks on a daily basis, whenever a new Git commit is applied to a code-base, or other events occurred. You can also enrich the potential by adding pre/post-test hooks for ensuring the system is set to a proper state for benchmarking. Alternatively, you can <a href="?benchmark">create a benchmark ticket</a> for one-time testing on one or more systems.</li>
					<li>View the automatically generated <a href="?results">test results</a>.</li>';
            if (!empty($main_page_message)) {
                $main .= '<li><strong>' . $main_page_message . '</strong></li>';
            } else {
                $main .= '<li><strong>If you are interested in Phoromatic and the Phoronix Test Suite for enterprise testing, please <a href="http://commercial.phoronix-test-suite.com/">contact us</a> for commercial support, custom test development, custom engineering services, and other professional services. It\'s not without corporate support and sponsorship that we can continue to develop this leading open-source Linux benchmarking software. If you run into any problems with our open-source software or would like to contribute patches, you can do so via our <a href="https://www.github.com/phoronix-test-suite/phoronix-test-suite">GitHub project</a>.</strong></li>
				</ol>';
            }
        } else {
            if (!empty($main_page_message)) {
                $main .= '<p><strong>' . $main_page_message . '</strong></p>';
            }
        }
        $main .= '<hr /><div id="phoromatic_fixed_main_table">';
        $systems_needing_attention = phoromatic_server::systems_appearing_down($_SESSION['AccountID']);
        $systems_idling = phoromatic_server::systems_idling($_SESSION['AccountID']);
        $systems_shutdown = phoromatic_server::systems_shutdown($_SESSION['AccountID']);
        $systems_running_tests = phoromatic_server::systems_running_tests($_SESSION['AccountID']);
        $main .= '<div id="phoromatic_main_table_cell">
			<h2>' . pts_strings::plural_handler(count($systems_running_tests), 'System') . ' Running Tests</h2>
			<h2>' . pts_strings::plural_handler(count($systems_idling), 'System') . ' Idling</h2>
			<h2>' . pts_strings::plural_handler(count($systems_shutdown), 'System') . ' Shutdown</h2>
			<h2>' . pts_strings::plural_handler(count($systems_needing_attention), 'System') . ' Needing Attention</h2>';
        $main .= '<hr /><h2>Systems Running Tests</h2>';
        $stmt = phoromatic_server::$db->prepare('SELECT * FROM phoromatic_systems WHERE AccountID = :account_id AND State >= 0 AND CurrentTask NOT LIKE \'%Idling%\' AND CurrentTask NOT LIKE \'%Shutdown%\' ORDER BY LastCommunication DESC');
        $stmt->bindValue(':account_id', $_SESSION['AccountID']);
        $result = $stmt->execute();
        while ($result && ($row = $result->fetchArray())) {
            $main .= '<div class="phoromatic_overview_box">';
            $main .= '<h1><a href="?systems/' . $row['SystemID'] . '">' . $row['Title'] . '</a></h1>';
            $main .= $row['CurrentTask'] . '<br />';
            if (!empty($row['CurrentProcessSchedule'])) {
                $main .= '<a href="?schedules/' . $row['CurrentProcessSchedule'] . '">' . phoromatic_server::schedule_id_to_name($row['CurrentProcessSchedule']) . '</a><br />';
            }
            $time_remaining = phoromatic_compute_estimated_time_remaining($row['EstimatedTimeForTask'], $row['LastCommunication']);
            if ($time_remaining) {
                $main .= '<em>~ ' . pts_strings::plural_handler($time_remaining, 'Minute') . ' Remaining</em>';
            }
            $main .= '</div>';
        }
        $main .= '</div>';
        $schedules_today = phoromatic_server::schedules_today($_SESSION['AccountID']);
        $schedules_total = phoromatic_server::schedules_total($_SESSION['AccountID']);
        $benchmark_tickets_today = phoromatic_server::benchmark_tickets_today($_SESSION['AccountID']);
        $main .= '<div id="phoromatic_main_table_cell">
		<h2>' . pts_strings::plural_handler(count($schedules_today), 'Schedule') . ' Active Today</h2>
		<h2>' . pts_strings::plural_handler(count($schedules_total), 'Schedule') . ' In Total</h2>
		<h2>' . pts_strings::plural_handler(count($benchmark_tickets_today), 'Active Benchmark Ticket') . '</h2>
		<h2> &nbsp; </h2>';
        $main .= '<hr /><h2>Today\'s Scheduled Tests</h2>';
        foreach ($schedules_today as &$row) {
            $systems_for_schedule = phoromatic_server::systems_associated_with_schedule($_SESSION['AccountID'], $row['ScheduleID']);
            $extra_css = null;
            if (empty($systems_for_schedule)) {
                $extra_css = ' opacity: 0.4;';
            }
            list($h, $m) = explode('.', $row['RunAt']);
            $main .= '<div style="' . $extra_css . '" class="phoromatic_overview_box">';
            $main .= '<h1><a href="?schedules/' . $row['ScheduleID'] . '">' . $row['Title'] . '</a></h1>';
            if (!empty($systems_for_schedule)) {
                if ($row['RunAt'] > date('H.i')) {
                    $run_in_future = true;
                    $main .= '<h3>Runs In ' . pts_strings::format_time($h * 60 + $m - (date('H') * 60 + date('i')), 'MINUTES') . '</h3>';
                } else {
                    $run_in_future = false;
                    $main .= '<h3>Triggered ' . pts_strings::format_time(max(1, date('H') * 60 + date('i') - ($h * 60 + $m)), 'MINUTES') . ' Ago</h3>';
                }
            }
            foreach ($systems_for_schedule as $system_id) {
                $pprid = self::result_match($row['ScheduleID'], $system_id, date('Y-m-d'));
                if ($pprid) {
                    $main .= '<a href="?result/' . $pprid . '">';
                }
                $main .= phoromatic_server::system_id_to_name($system_id);
                if ($pprid) {
                    $main .= '</a>';
                } else {
                    if (!$run_in_future) {
                        $sys_info = self::system_info($system_id);
                        $last_comm_diff = time() - strtotime($sys_info['LastCommunication']);
                        $main .= ' <sup><a href="?systems/' . $system_id . '">';
                        if ($last_comm_diff > 3600) {
                            $main .= '<strong>Last Communication: ' . pts_strings::format_time($last_comm_diff, 'SECONDS', true, 60) . ' Ago</strong>';
                        } else {
                            $main .= $sys_info['CurrentTask'];
                        }
                        $main .= '</a></sup>';
                    }
                }
                $main .= '<br />';
            }
            $main .= '</div>';
        }
        $main .= '</div>';
        $results_today = phoromatic_server::test_results($_SESSION['AccountID'], strtotime('today'));
        $results_this_week = phoromatic_server::test_results($_SESSION['AccountID'], mktime(0, 0, 0, date('n'), date('j') - date('N') + 1));
        $results_total = phoromatic_server::test_results($_SESSION['AccountID'], null);
        $main .= '<div id="phoromatic_main_table_cell">
		<h2>' . pts_strings::plural_handler(count($results_today), 'Test Result') . ' Today</h2>
		<h2>' . pts_strings::plural_handler(count($results_this_week), 'Test Result') . ' This Week</h2>
		<h2>' . pts_strings::plural_handler(count($results_total), 'Test Result') . ' Total</h2>
		<h2>' . pts_strings::plural_handler(phoromatic_server::test_results_benchmark_count($_SESSION['AccountID']), 'Benchmark Result') . ' Total</h2>
		<hr /><h2>Today\'s Results</h2>';
        foreach ($results_today as $result) {
            $main .= '<h3><a href="?result/' . $result['PPRID'] . '">' . $result['Title'] . '</a></h3>';
        }
        $main .= '</div>';
        $main .= '</div>';
        /*
        		$has_flagged_results = false;
        		$stmt = phoromatic_server::$db->prepare('SELECT ScheduleID, GROUP_CONCAT(SystemID,\',\') AS Systems FROM phoromatic_results WHERE AccountID = :account_id AND ScheduleID NOT LIKE 0 GROUP BY ScheduleID ORDER BY UploadTime DESC');
        		$stmt->bindValue(':account_id', $_SESSION['AccountID']);
        		$test_result_result = $stmt->execute();
        		while($test_result_row = $test_result_result->fetchArray())
        		{
        			$systems = array_count_values(explode(',', $test_result_row['Systems']));
        
        			foreach($systems as $system_id => $system_count)
        			{
        				if($system_count < 2)
        					unset($systems[$system_id]);
        			}
        
        			$printed_schedule_name = false;
        			if(!empty($systems))
        			{
        				foreach(array_keys($systems) as $system_id)
        				{
        					$stmt_uploads = phoromatic_server::$db->prepare('SELECT PPRID, UploadID FROM phoromatic_results WHERE AccountID = :account_id AND SystemID = :system_id AND ScheduleID = :schedule_id ORDER BY UploadTime DESC LIMIT 2');
        					$stmt_uploads->bindValue(':account_id', $_SESSION['AccountID']);
        					$stmt_uploads->bindValue(':system_id', $system_id);
        					$stmt_uploads->bindValue(':schedule_id', $test_result_row['ScheduleID']);
        					$result_uploads = $stmt_uploads->execute();
        
        					$result_file = array();
        					$pprids = array();
        					while($result_uploads_row = $result_uploads->fetchArray())
        					{
        						$composite_xml = phoromatic_server::phoromatic_account_result_path($_SESSION['AccountID'], $result_uploads_row['UploadID']) . 'composite.xml';
        						if(is_file($composite_xml))
        						{
        							array_push($result_file, new pts_result_merge_select($composite_xml));
        						}
        						array_push($pprids, $result_uploads_row['PPRID']);
        					}
        					$result_file = array_reverse($result_file);
        
        					if(count($result_file) == 2)
        					{
        						$writer = new pts_result_file_writer(null);
        						$attributes = array();
        						pts_merge::merge_test_results_process($writer, $result_file, $attributes);
        						$result_file = new pts_result_file($writer->get_xml());
        
        						foreach($result_file->get_result_objects('ONLY_CHANGED_RESULTS') as $i => $result_object)
        						{
        							$vari = round($result_object->largest_result_variation(), 3);
        							if(abs($vari) < 0.03)
        								continue;
        							if(!$has_flagged_results)
        							{
        								$main .= '<hr /><h2>Flagged Results</h2>';
        								$main .= '<p>Displayed are results for each system of each scheduled test where there is a measurable change (currently set to a 0.1% threshold) when comparing the most recent result to the previous result for that system for that test schedule. Click on the change to jump to that individualized result file comparison.</p>';
        								$main .= '<span style="font-size: 80%;">';
        								$has_flagged_results = true;
        							}
        							if(!$printed_schedule_name)
        							{
        								$main .= '<h3>' . phoromatic_schedule_id_to_name($test_result_row['ScheduleID']) . '</h3><p>';
        								$printed_schedule_name = true;
        							}
        
        							$pcolor = $vari > 0 ? 'green' : 'red';
        
        							$main .= '<a href="?result/' . implode(',', $pprids) . '#' . $result_object->get_comparison_hash(true, false) . '"><span style="color: ' . $pcolor . ';"><strong>' . phoromatic_system_id_to_name($system_id) . ' - ' . $result_object->test_profile->get_title() . ':</strong> ' . implode(' &gt; ', $result_file->get_system_identifiers()) . ': ' . ($vari * 100) . '%</span></a><br />';
        						}
        					}
        				}
        			}
        			if($printed_schedule_name)
        				$main .= '</p>';
        		}
        		if($has_flagged_results)
        			$main .= '</span>';
        */
        // ACTIVE TEST SCHEDULES
        /*
        $main .= '<div style="float: left; width: 50%;"><ul><li><h1>Active Test Schedules</h1></li>';
        $stmt = phoromatic_server::$db->prepare('SELECT Title, ScheduleID, Description, RunTargetSystems, RunTargetGroups, ActiveOn, RunAt FROM phoromatic_schedules WHERE AccountID = :account_id AND State >= 1 ORDER BY Title ASC');
        $stmt->bindValue(':account_id', $_SESSION['AccountID']);
        $result = $stmt->execute();
        $row = $result->fetchArray();
        
        if($row == false)
        {
        	$main .= '<li class="light" style="text-align: center;">No Schedules Found</li>';
        }
        else
        {
        	do
        	{
        		$group_count = empty($row['RunTargetGroups']) ? 0 : count(explode(',', $row['RunTargetGroups']));
        		$main .= '<a href="?schedules/' . $row['ScheduleID'] . '"><li>' . $row['Title'] . '<br /><table><tr><td>' . pts_strings::plural_handler(count(phoromatic_server::systems_associated_with_schedule($_SESSION['AccountID'], $row['ScheduleID'])), 'System') . '</td><td>' . pts_strings::plural_handler($group_count, 'Group') . '</td><td>' . pts_strings::plural_handler(phoromatic_results_for_schedule($row['ScheduleID']), 'Result') . '</td><td><strong>' . phoromatic_schedule_activeon_string($row['ActiveOn'], $row['RunAt']) . '</strong></td></tr></table></li></a>';
        	}
        	while($row = $result->fetchArray());
        }
        $main .= '</ul></div>';
        */
        echo '<div id="pts_phoromatic_main_area">' . $main . '</div>';
        //echo phoromatic_webui_main($main, phoromatic_webui_right_panel_logged_in());
        echo phoromatic_webui_footer();
    }
 public function test_install_process($test_install_manager)
 {
     $this->test_install_pos = 0;
     $this->test_install_count = $test_install_manager->tests_to_install_count();
     $download_size = 0;
     $download_total = 0;
     $cache_total = 0;
     $cache_size = 0;
     $install_size = 0;
     $download_string_total = null;
     $cache_string_total = null;
     $disk_space_total = null;
     foreach ($test_install_manager->get_test_run_requests() as $test_run_request) {
         $install_size += $test_run_request->test_profile->get_environment_size();
         foreach ($test_run_request->get_download_objects() as $test_file_download) {
             switch ($test_file_download->get_download_location_type()) {
                 case 'IN_DESTINATION_DIR':
                     // We don't really care about these files here since they are good to go
                     break;
                 case 'LOCAL_DOWNLOAD_CACHE':
                 case 'REMOTE_DOWNLOAD_CACHE':
                 case 'LOOKASIDE_DOWNLOAD_CACHE':
                     $cache_size += $test_file_download->get_filesize();
                     $cache_total++;
                     break;
                 default:
                     $download_size += $test_file_download->get_filesize();
                     $download_total++;
                     break;
             }
         }
     }
     if ($download_total > 0) {
         $download_string_total = pts_strings::plural_handler($download_total, 'File');
         if ($download_size > 0) {
             $download_string_total .= ' / ' . self::bytes_to_download_size($download_size) . 'MB';
         }
     }
     if ($cache_total > 0) {
         $cache_string_total = pts_strings::plural_handler($cache_total, 'File');
         if ($cache_size > 0) {
             $cache_string_total .= ' / ' . self::bytes_to_download_size($cache_size) . 'MB';
         }
     }
     if ($install_size > 0) {
         $disk_space_total = ceil($install_size) . 'MB';
     }
     $stats = array('download_total' => $download_string_total, 'cache_total' => $cache_string_total, 'disk_space_total' => $disk_space_total);
     $this->update_install_status($test_install_manager, null, $stats);
 }
function phoromatic_compute_estimated_time_remaining_string($estimated_minutes, $last_comm, $append = 'Remaining')
{
    $remaining = phoromatic_compute_estimated_time_remaining($estimated_minutes, $last_comm);
    return $remaining > 0 ? '~' . pts_strings::plural_handler($remaining, 'Minute') . ' ' . $append : null;
}
 public static function days_ago_format_string($days_ago)
 {
     if ($days_ago < 30) {
         $days_ago = pts_strings::plural_handler($days_ago, 'day');
     } else {
         $days_ago = floor($days_ago / 30);
         if ($days_ago >= 12) {
             $year = floor($days_ago / 12);
             $months = $days_ago % 12;
             $days_ago = pts_strings::plural_handler($year, 'year');
             if ($months > 0) {
                 $days_ago .= ', ' . pts_strings::plural_handler($months, 'month');
             }
         } else {
             $days_ago = pts_strings::plural_handler($days_ago, 'month');
         }
     }
     return $days_ago;
 }
    public static function render_page_process($PATH)
    {
        $main = null;
        echo phoromatic_webui_header_logged_in();
        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();
            $row = $result->fetchArray();
            if (empty($row)) {
                $main = '<h1>Test Schedules</h1>';
                $main .= '<h3>No Resource Found</h3>';
            } else {
                if (!PHOROMATIC_USER_IS_VIEWER) {
                    if (isset($_POST['add_to_schedule_select_test'])) {
                        $name = $_POST['add_to_schedule_select_test'];
                        $args = array();
                        $args_name = array();
                        foreach ($_POST as $i => $v) {
                            if (substr($i, 0, 12) == 'test_option_' && substr($i, -9) != '_selected') {
                                array_push($args, $v);
                                array_push($args_name, $_POST[$i . '_selected']);
                            }
                        }
                        $args_name = implode(' - ', $args_name);
                        $args = implode(' ', $args);
                        if (!empty($name)) {
                            $stmt = phoromatic_server::$db->prepare('INSERT INTO phoromatic_schedules_tests (AccountID, ScheduleID, TestProfile, TestArguments, TestDescription) VALUES (:account_id, :schedule_id, :test_profile, :test_arguments, :test_description)');
                            $stmt->bindValue(':account_id', $_SESSION['AccountID']);
                            $stmt->bindValue(':schedule_id', $PATH[0]);
                            $stmt->bindValue(':test_profile', $name);
                            $stmt->bindValue(':test_arguments', $args);
                            $stmt->bindValue(':test_description', $args_name);
                            $result = $stmt->execute();
                            phoromatic_add_activity_stream_event('tests_for_schedule', $PATH[0], 'added');
                        }
                    } else {
                        if (isset($PATH[1]) && $PATH[1] == 'remove' && !empty($PATH[2])) {
                            // REMOVE TEST
                            $to_remove = explode(PHP_EOL, base64_decode($PATH[2]));
                            $stmt = phoromatic_server::$db->prepare('DELETE FROM phoromatic_schedules_tests WHERE AccountID = :account_id AND ScheduleID = :schedule_id AND TestProfile = :test AND TestArguments = :test_args');
                            $stmt->bindValue(':account_id', $_SESSION['AccountID']);
                            $stmt->bindValue(':schedule_id', $PATH[0]);
                            $stmt->bindValue(':test', $to_remove[0]);
                            $stmt->bindValue(':test_args', $to_remove[1]);
                            $result = $stmt->execute();
                            phoromatic_add_activity_stream_event('tests_for_schedule', $to_remove[0] . ' - ' . $to_remove[1], 'removed');
                        } else {
                            if (isset($PATH[1]) && $PATH[1] == 'delete-trigger' && !empty($PATH[2])) {
                                // REMOVE TRIGGER
                                $trigger = base64_decode($PATH[2]);
                                $stmt = phoromatic_server::$db->prepare('DELETE FROM phoromatic_schedules_triggers WHERE AccountID = :account_id AND Trigger = :trigger AND ScheduleID = :schedule_id');
                                $stmt->bindValue(':account_id', $_SESSION['AccountID']);
                                $stmt->bindValue(':schedule_id', $PATH[0]);
                                $stmt->bindValue(':trigger', $trigger);
                                $result = $stmt->execute();
                                if ($result) {
                                    $main .= '<h2 style="color: red;">Trigger Removed: ' . $trigger . '</h2>';
                                }
                            } else {
                                if (isset($PATH[1]) && in_array($PATH[1], array('activate', 'deactivate'))) {
                                    switch ($PATH[1]) {
                                        case 'deactivate':
                                            $new_state = 0;
                                            break;
                                        case 'activate':
                                        default:
                                            $new_state = 1;
                                            break;
                                    }
                                    // REMOVE TEST
                                    $stmt = phoromatic_server::$db->prepare('UPDATE phoromatic_schedules SET State = :new_state WHERE AccountID = :account_id AND ScheduleID = :schedule_id');
                                    $stmt->bindValue(':account_id', $_SESSION['AccountID']);
                                    $stmt->bindValue(':schedule_id', $PATH[0]);
                                    $stmt->bindValue(':new_state', $new_state);
                                    $result = $stmt->execute();
                                    $row['State'] = $new_state;
                                    phoromatic_add_activity_stream_event('schedule', $PATH[0], $PATH[1]);
                                } else {
                                    if (isset($_POST['do_manual_test_run'])) {
                                        $stmt = phoromatic_server::$db->prepare('INSERT INTO phoromatic_schedules_triggers (AccountID, ScheduleID, Trigger, TriggeredOn) VALUES (:account_id, :schedule_id, :trigger, :triggered_on)');
                                        $stmt->bindValue(':account_id', $_SESSION['AccountID']);
                                        $stmt->bindValue(':schedule_id', $PATH[0]);
                                        $stmt->bindValue(':trigger', $_SESSION['UserName'] . ' - Manual Test Run - ' . date('H:i j M Y'));
                                        $stmt->bindValue(':triggered_on', phoromatic_server::current_time());
                                        $stmt->execute();
                                        $main .= '<h2 style="color: red;">Manual Test Run Triggered</h2>';
                                    } else {
                                        if (isset($_POST['skip_current_ticket'])) {
                                            $stmt = phoromatic_server::$db->prepare('INSERT INTO phoromatic_schedules_trigger_skips (AccountID, ScheduleID, Trigger) VALUES (:account_id, :schedule_id, :trigger)');
                                            $stmt->bindValue(':account_id', $_SESSION['AccountID']);
                                            $stmt->bindValue(':schedule_id', $PATH[0]);
                                            $stmt->bindValue(':trigger', date('Y-m-d'));
                                            $stmt->execute();
                                            $main .= '<h2 style="color: red;">Current Trigger To Be Ignored</h2>';
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                $main .= '<h1>' . $row['Title'] . '</h1>';
                $main .= '<h3>' . $row['Description'] . '</h3>';
                $main .= '<p>This schedule was last modified on <strong>' . date('j F Y \\a\\t H:i', strtotime($row['LastModifiedOn'])) . '</strong> by <strong>' . $row['LastModifiedBy'] . '</strong>.';
                if (!PHOROMATIC_USER_IS_VIEWER) {
                    $main .= '<p><a href="?sched/' . $PATH[0] . '">Edit Schedule</a> | ';
                    if ($row['State'] == 1) {
                        $main .= '<a href="?schedules/' . $PATH[0] . '/deactivate">Deactivate Schedule</a>';
                    } else {
                        $main .= '<a href="?schedules/' . $PATH[0] . '/activate">Activate Schedule</a>';
                    }
                    $main .= '</p>';
                }
                $main .= '<hr />';
                $main .= '<h2>Schedule</h2>';
                if (!empty($row['ActiveOn'])) {
                    $active_days = explode(',', $row['ActiveOn']);
                    $week = array('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday');
                    foreach ($active_days as $i => &$day) {
                        if (!isset($week[$day])) {
                            unset($active_days[$i]);
                        } else {
                            $day = $week[$day];
                        }
                    }
                    switch (count($active_days)) {
                        case 2:
                            $day_show = implode(' and ', $active_days);
                            break;
                        default:
                            $day_show = implode(', ', $active_days);
                            break;
                    }
                    $main .= '<p>This test is scheduled to run every <strong>' . $day_show . '</strong> at <strong>' . str_replace('.', ':', $row['RunAt']) . '</strong>.</p>';
                } else {
                    $main .= '<p>This test schedule is not currently set to run a pre-defined time-based schedule.</p>';
                }
                if (!PHOROMATIC_USER_IS_VIEWER) {
                    $trigger_url = 'http://' . phoromatic_web_socket_server_ip() . '/event.php?type=trigger&user='******'UserName'] . '&public_key=' . $row['PublicKey'] . '&trigger=XXX';
                    $main .= '<p>This test schedule can be manually triggered to run at any time by calling <strong>' . $trigger_url . '</strong> where <em>XXX</em> is the trigger value to be used (if relevant, such as a time-stamp, Git/SVN commit number or hash, etc). There\'s also the option of sub-targeting system(s) part of this schedule. One option is appending <em>&sub_target_this_ip</em> if this URL is being called from one of the client test systems to only sub-target the triggered testing on that client, among other options.</p>';
                    $main .= '<p>If you wish to run this test schedule now, click the following button and the schedule will be run on all intended systems at their next earliest possible convenience.</p>';
                    $main .= '<p><form action="?schedules/' . $PATH[0] . '" name="manual_run" method="post">';
                    $main .= '<input type="hidden" name="do_manual_test_run" value="1" /><input type="submit" value="Run Test Schedule Now" onclick="return confirm(\'Run this test schedule now?\');" />';
                    $main .= '</form></p>';
                    $main .= '<p><form action="?schedules/' . $PATH[0] . '" name="skip_run" method="post">';
                    $main .= '<input type="hidden" name="skip_current_ticket" value="1" /><input type="submit" value="Skip Current Test Ticket" onclick="return confirm(\'Skip any currently active test ticket on all systems?\');" />';
                    $main .= '</form></p>';
                }
                $main .= '<hr />';
                $contexts = array('SetContextPreInstall' => 'Pre-Install', 'SetContextPostInstall' => 'Post-Install', 'SetContextPreRun' => 'Pre-Test-Run', 'SetContextPostRun' => 'Post-Test-Run');
                $scripts = 0;
                foreach ($contexts as $context => $v) {
                    if (isset($row[$context]) && !empty($row[$context]) && is_file(phoromatic_server::phoromatic_account_path($_SESSION['AccountID']) . 'context_' . $row[$context])) {
                        $scripts++;
                        $main .= '<h2>' . $v . ' Context Script</h2>';
                        $main .= '<blockquote>' . str_replace(PHP_EOL, '<br />', htmlentities(file_get_contents(phoromatic_server::phoromatic_account_path($_SESSION['AccountID']) . 'context_' . $row[$context]))) . '</blockquote>';
                    }
                }
                if ($scripts > 0) {
                    $main .= '<hr />';
                }
                $main .= '<h2>Tests To Run</h2>';
                $stmt = phoromatic_server::$db->prepare('SELECT * FROM phoromatic_schedules_tests WHERE AccountID = :account_id AND ScheduleID = :schedule_id ORDER BY TestProfile ASC');
                $stmt->bindValue(':account_id', $_SESSION['AccountID']);
                $stmt->bindValue(':schedule_id', $PATH[0]);
                $result = $stmt->execute();
                $test_count = 0;
                $main .= '<p>';
                while ($row = $result->fetchArray()) {
                    $test_count++;
                    $main .= $row['TestProfile'] . ($row['TestDescription'] != null ? ' - <em>' . $row['TestDescription'] . '</em>' : '') . (!PHOROMATIC_USER_IS_VIEWER ? ' <a href="?schedules/' . $PATH[0] . '/remove/' . base64_encode(implode(PHP_EOL, array($row['TestProfile'], $row['TestArguments']))) . '">Remove Test</a>' : null) . '<br />';
                    /*
                    if(!PHOROMATIC_USER_IS_VIEWER && isset($_REQUEST['make_version_lock_tests']))
                    {
                    	if(strpos($row['TestProfile'], '.') == false)
                    	{
                    		$test_profile = new pts_test_profile($row['TestProfile']);
                    		$full_identifier = $test_profile->get_identifier(true);
                    
                    		$stmt = phoromatic_server::$db->prepare('UPDATE phoromatic_schedules_tests SET TestProfile = :version_locked_tp WHERE AccountID = :account_id AND ScheduleID = :schedule_id AND TestProfile = :test');
                    		$stmt->bindValue(':account_id', $_SESSION['AccountID']);
                    		$stmt->bindValue(':schedule_id', $PATH[0]);
                    		$stmt->bindValue(':test', $row['TestProfile']);
                    		$stmt->bindValue(':version_locked_tp', $full_identifier);
                    		$result2 = $stmt->execute();
                    	}
                    }
                    */
                }
                $main .= '</p>';
                if ($test_count == 0) {
                    $main .= '<h3 style="text-transform: uppercase;">No tests have been added yet for this test schedule.</h3>';
                }
                if (!PHOROMATIC_USER_IS_VIEWER) {
                    $main .= '<hr /><h2>Add A Test</h2>';
                    $main .= '<form action="?schedules/' . $PATH[0] . '" name="add_test" id="add_test" method="post">';
                    $main .= '<select name="add_to_schedule_select_test" id="add_to_schedule_select_test" onchange="phoromatic_schedule_test_details(\'\');">';
                    $dc = pts_strings::add_trailing_slash(pts_client::parse_home_directory(pts_config::read_user_config('PhoronixTestSuite/Options/Installation/CacheDirectory', PTS_DOWNLOAD_CACHE_PATH)));
                    $dc_exists = is_file($dc . 'pts-download-cache.json');
                    foreach (pts_openbenchmarking::available_tests(false, true) as $test) {
                        $cache_checked = false;
                        if ($dc_exists) {
                            $cache_json = file_get_contents($dc . 'pts-download-cache.json');
                            $cache_json = json_decode($cache_json, true);
                            if ($cache_json && isset($cache_json['phoronix-test-suite']['cached-tests'])) {
                                $cache_checked = true;
                                if (!in_array($test, $cache_json['phoronix-test-suite']['cached-tests'])) {
                                    continue;
                                }
                            }
                        }
                        if (!$cache_checked && phoromatic_server::read_setting('show_local_tests_only') && pts_test_install_request::test_files_in_cache($test, true, true) == false) {
                            continue;
                        }
                        $main .= '<option value="' . $test . '">' . $test . '</option>';
                    }
                    $main .= '</select>';
                    $main .= '<p><div id="test_details"></div></p>';
                    $main .= '</form>';
                }
                $systems_in_schedule = phoromatic_server::systems_associated_with_schedule($_SESSION['AccountID'], $PATH[0]);
                if (!empty($systems_in_schedule)) {
                    $main .= '<hr /><h2>Systems In Schedule</h2>';
                    if (!PHOROMATIC_USER_IS_VIEWER) {
                        $main .= '<p>To run this schedule on more systems, <a href="?sched/' . $PATH[0] . '">edit the schedule</a>.</p>';
                    }
                    $main .= '<div class="pts_phoromatic_info_box_area" style="margin: 0 10%;"><ul><li><h1>Systems</h1></li>';
                    foreach ($systems_in_schedule as $system_id) {
                        $row = phoromatic_server::get_system_details($_SESSION['AccountID'], $system_id);
                        $main .= '<a href="?systems/' . $row['SystemID'] . '"><li>' . $row['Title'] . '<br /><table><tr><td>' . $row['LocalIP'] . '</td><td><strong>' . $row['CurrentTask'] . '</strong></td><td><strong>Last Communication:</strong> ' . date('j F Y H:i', strtotime($row['LastCommunication'])) . '</td></tr></table></li></a>';
                    }
                    $main .= '</ul></div><hr />';
                }
                $stmt = phoromatic_server::$db->prepare('SELECT Trigger, TriggeredOn FROM phoromatic_schedules_triggers WHERE AccountID = :account_id AND ScheduleID = :schedule_id ORDER BY TriggeredOn DESC LIMIT 10');
                $stmt->bindValue(':account_id', $_SESSION['AccountID']);
                $stmt->bindValue(':schedule_id', $PATH[0]);
                $test_result_result = $stmt->execute();
                $test_result_row = $test_result_result->fetchArray();
                if ($test_result_row) {
                    $main .= '<div class="pts_phoromatic_info_box_area" style="margin: 0 10%;">';
                    $main .= '<ul><li><h1>Recent Triggers For This Schedule</h1></li>';
                    do {
                        $main .= '<a onclick=""><li>' . $test_result_row['Trigger'] . '<br /><table><tr><td>' . phoromatic_user_friendly_timedate($test_result_row['TriggeredOn']) . '</td><td><a href="?schedules/' . $PATH[0] . '/delete-trigger/' . base64_encode($test_result_row['Trigger']) . '">Remove Trigger</a></td></tr></table></li></a>';
                    } while ($test_result_row = $test_result_result->fetchArray());
                    $main .= '</ul>';
                    $main .= '</div>';
                }
                $stmt = phoromatic_server::$db->prepare('SELECT Title, SystemID, ScheduleID, PPRID, UploadTime FROM phoromatic_results WHERE AccountID = :account_id AND ScheduleID = :schedule_id ORDER BY UploadTime DESC');
                $stmt->bindValue(':account_id', $_SESSION['AccountID']);
                $stmt->bindValue(':schedule_id', $PATH[0]);
                $test_result_result = $stmt->execute();
                $test_result_row = $test_result_result->fetchArray();
                if ($test_result_row) {
                    $main .= '<div class="pts_phoromatic_info_box_area" style="margin: 0 10%;">';
                    $main .= '<ul><li><h1>Recent Test Results For This Schedule</h1></li>';
                    $results = 0;
                    do {
                        $oldest_upload_time = $test_result_row['UploadTime'];
                        if ($results > 100) {
                            continue;
                        }
                        $main .= '<a href="?result/' . $test_result_row['PPRID'] . '"><li>' . $test_result_row['Title'] . '<br /><table><tr><td>' . phoromatic_system_id_to_name($test_result_row['SystemID']) . '</td><td>' . phoromatic_user_friendly_timedate($test_result_row['UploadTime']) . '</td></tr></table></li></a>';
                        $results++;
                    } while ($test_result_row = $test_result_result->fetchArray());
                    $main .= '</ul>';
                    $main .= '</div>';
                }
                $num_results = phoromatic_results_for_schedule($PATH[0]);
                if ($num_results > 1) {
                    $main .= '<p>Jump to the latest results from the past: ';
                    $main .= '<select name="view_results_from_past" id="view_results_from_past" onchange="phoromatic_jump_to_results_from(\'' . $PATH[0] . '\', \'view_results_from_past\');">';
                    $oldest_upload_time = strtotime($oldest_upload_time);
                    $opts = array('Week' => 7, 'Three Weeks' => 21, 'Month' => 30, 'Quarter' => 90, 'Six Months' => 180, 'Year' => 365);
                    foreach ($opts as $str_name => $time_offset) {
                        if ($oldest_upload_time > time() - 86400 * $time_offset) {
                            break;
                        }
                        $main .= '<option value="' . $time_offset . '">' . $str_name . '</option>';
                    }
                    $main .= '<option value="all">All Results</option>';
                    $main .= '</select>';
                    $main .= '</p><hr />';
                }
                $main .= '<p><strong>' . $num_results . ' Test Results Available For This Schedule.</strong></p>';
            }
            echo phoromatic_webui_main($main, phoromatic_webui_right_panel_logged_in());
            echo phoromatic_webui_footer();
            return;
        }
        $main = '<h1>Test Schedules</h1>
			<p>Test schedules are used for tests that are intended to be run on a recurring basis -- either daily or other defined time period -- or whenever a trigger/event occurs, like a new Git commit to a software repository being tracked. Test schedules can be run on any given system(s)/group(s) and can be later edited.</p>';
        if (!PHOROMATIC_USER_IS_VIEWER) {
            $main .= '
				<hr />
				<h2>Create A Schedule</h2>
				<p><a href="?sched">Create a schedule</a> followed by adding tests/suites to run for that schedule on the selected systems.</p>';
        }
        $main .= '<hr /><h2>Current Schedules</h2>';
        $main .= '<div class="pts_phoromatic_info_box_area">
					<ul>
						<li><h1>Active Test Schedules</h1></li>';
        $stmt = phoromatic_server::$db->prepare('SELECT Title, ScheduleID, Description, RunTargetSystems, RunTargetGroups, RunAt, ActiveOn FROM phoromatic_schedules WHERE AccountID = :account_id AND State >= 1 ORDER BY Title ASC');
        $stmt->bindValue(':account_id', $_SESSION['AccountID']);
        $result = $stmt->execute();
        $row = $result->fetchArray();
        if ($row == false) {
            $main .= '<li class="light" style="text-align: center;">No Schedules Found</li>';
        } else {
            do {
                $stmt_tests = phoromatic_server::$db->prepare('SELECT COUNT(*) AS TestCount FROM phoromatic_schedules_tests WHERE AccountID = :account_id AND ScheduleID = :schedule_id ORDER BY TestProfile ASC');
                $stmt_tests->bindValue(':account_id', $_SESSION['AccountID']);
                $stmt_tests->bindValue(':schedule_id', $row['ScheduleID']);
                $result_tests = $stmt_tests->execute();
                $row_tests = $result_tests->fetchArray();
                $test_count = !empty($row_tests) ? $row_tests['TestCount'] : 0;
                $group_count = empty($row['RunTargetGroups']) ? 0 : count(explode(',', $row['RunTargetGroups']));
                $main .= '<a href="?schedules/' . $row['ScheduleID'] . '"><li>' . $row['Title'] . '<br /><table><tr><td>' . pts_strings::plural_handler(count(phoromatic_server::systems_associated_with_schedule($_SESSION['AccountID'], $row['ScheduleID'])), 'System') . '</td><td>' . pts_strings::plural_handler($group_count, 'Group') . '</td><td>' . pts_strings::plural_handler($test_count, 'Test') . '</td><td>' . pts_strings::plural_handler(phoromatic_results_for_schedule($row['ScheduleID']), 'Result') . ' Total</td><td>' . pts_strings::plural_handler(phoromatic_results_for_schedule($row['ScheduleID'], 'TODAY'), 'Result') . ' Today</td><td><strong>' . phoromatic_schedule_activeon_string($row['ActiveOn'], $row['RunAt']) . '</strong></td></tr></table></li></a>';
            } while ($row = $result->fetchArray());
        }
        $main .= '</ul>
			</div>';
        $main .= '<hr /><h2>Schedule Overview</h2>';
        $week = array('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday');
        foreach ($week as $i => $day) {
            $stmt = phoromatic_server::$db->prepare('SELECT Title, ScheduleID, RunAt, RunTargetGroups, RunTargetSystems FROM phoromatic_schedules WHERE AccountID = :account_id AND State >= 1 AND ActiveOn LIKE :active_on ORDER BY RunAt,ActiveOn,Title ASC');
            $stmt->bindValue(':account_id', $_SESSION['AccountID']);
            $stmt->bindValue(':active_on', '%' . $i . '%');
            $result = $stmt->execute();
            $has_matched = false;
            while ($row = $result->fetchArray()) {
                if (!$has_matched) {
                    $main .= '<h3>' . $day . '</h3>' . PHP_EOL . '<p>';
                    $has_matched = true;
                }
                $main .= '<em>' . $row['RunAt'] . '</em> <a href="?schedules/' . $row['ScheduleID'] . '">' . $row['Title'] . '</a>';
                //$main .= $row['RunTargetSystems'] . ' ' . $row['RunTargetGroups'];
                $main .= '<br />';
            }
            if ($has_matched) {
                $main .= '</p>' . PHP_EOL;
            }
        }
        $main .= '<div class="pts_phoromatic_info_box_area">
					<ul>
						<li><h1>Deactivated Test Schedules</h1></li>';
        $stmt = phoromatic_server::$db->prepare('SELECT Title, ScheduleID, Description, RunTargetSystems, RunTargetGroups, RunAt, ActiveOn FROM phoromatic_schedules WHERE AccountID = :account_id AND State < 1 ORDER BY Title ASC');
        $stmt->bindValue(':account_id', $_SESSION['AccountID']);
        $result = $stmt->execute();
        $row = $result->fetchArray();
        if ($row == false) {
            $main .= '<li class="light" style="text-align: center;">No Schedules Found</li>';
        } else {
            do {
                $stmt_tests = phoromatic_server::$db->prepare('SELECT COUNT(*) AS TestCount FROM phoromatic_schedules_tests WHERE AccountID = :account_id AND ScheduleID = :schedule_id ORDER BY TestProfile ASC');
                $stmt_tests->bindValue(':account_id', $_SESSION['AccountID']);
                $stmt_tests->bindValue(':schedule_id', $row['ScheduleID']);
                $result_tests = $stmt_tests->execute();
                $row_tests = $result_tests->fetchArray();
                $test_count = !empty($row_tests) ? $row_tests['TestCount'] : 0;
                $group_count = empty($row['RunTargetGroups']) ? 0 : count(explode(',', $row['RunTargetGroups']));
                $main .= '<a href="?schedules/' . $row['ScheduleID'] . '"><li>' . $row['Title'] . '<br /><table><tr><td>' . pts_strings::plural_handler(count(phoromatic_server::systems_associated_with_schedule($_SESSION['AccountID'], $row['ScheduleID'])), 'System') . '</td><td>' . pts_strings::plural_handler($group_count, 'Group') . '</td><td>' . pts_strings::plural_handler($test_count, 'Test') . '</td><td>' . pts_strings::plural_handler(phoromatic_results_for_schedule($row['ScheduleID']), 'Result') . ' Total</td><td>' . pts_strings::plural_handler(phoromatic_results_for_schedule($row['ScheduleID'], 'TODAY'), 'Result') . ' Today</td><td><strong>' . phoromatic_schedule_activeon_string($row['ActiveOn'], $row['RunAt']) . '</strong></td></tr></table></li></a>';
            } while ($row = $result->fetchArray());
        }
        $main .= '</ul>
			</div>';
        echo '<div id="pts_phoromatic_main_area">' . $main . '</div>';
        echo phoromatic_webui_footer();
    }
    public static function render_page_process($PATH)
    {
        if ($_SESSION['AdminLevel'] != -40) {
            header('Location: /?main');
        }
        if (isset($PATH[0]) && isset($PATH[1])) {
            switch ($PATH[0]) {
                case 'delete':
                    if ($PATH[1] == 'result') {
                        $pprids = explode(',', $PATH[2]);
                        foreach ($pprids as $pprid) {
                            $stmt = phoromatic_server::$db->prepare('DELETE FROM phoromatic_results WHERE PPRID = :pprid');
                            $stmt->bindValue(':pprid', $pprid);
                            $result = $stmt->execute();
                        }
                        /*						$stmt = phoromatic_server::$db->prepare('DELETE FROM phoromatic_results_results WHERE AccountID = :account_id AND UploadID = :upload_id');
                        						$stmt->bindValue(':account_id', $PATH[2]);
                        						$stmt->bindValue(':upload_id', $PATH[3]);
                        						$result = $stmt->execute();
                        						$stmt = phoromatic_server::$db->prepare('DELETE FROM phoromatic_results_systems WHERE AccountID = :account_id AND UploadID = :upload_id');
                        						$stmt->bindValue(':account_id', $PATH[2]);
                        						$stmt->bindValue(':upload_id', $PATH[3]);
                        						$result = $stmt->execute();
                        
                        						$result_dir = phoromatic_server::phoromatic_account_result_path($PATH[2], $PATH[3]);
                        						if(is_dir($result_dir))
                        						{
                        							pts_file_io::delete($result_dir, null, true);
                        						}
                        */
                    } else {
                        if ($PATH[1] == 'schedule') {
                            $stmt = phoromatic_server::$db->prepare('DELETE FROM phoromatic_schedules WHERE AccountID = :account_id AND ScheduleID = :schedule_id');
                            $stmt->bindValue(':account_id', $PATH[2]);
                            $stmt->bindValue(':schedule_id', $PATH[3]);
                            $result = $stmt->execute();
                        } else {
                            if ($PATH[1] == 'system') {
                                $stmt = phoromatic_server::$db->prepare('DELETE FROM phoromatic_systems WHERE AccountID = :account_id AND SystemID = :system_id');
                                $stmt->bindValue(':account_id', $PATH[2]);
                                $stmt->bindValue(':system_id', $PATH[3]);
                                $result = $stmt->execute();
                            } else {
                                if ($PATH[1] == 'ticket') {
                                    $stmt = phoromatic_server::$db->prepare('DELETE FROM phoromatic_benchmark_tickets WHERE AccountID = :account_id AND TicketID = :ticket_id');
                                    $stmt->bindValue(':account_id', $PATH[2]);
                                    $stmt->bindValue(':ticket_id', $PATH[3]);
                                    $result = $stmt->execute();
                                } else {
                                    if ($PATH[1] == 'trigger') {
                                        $stmt = phoromatic_server::$db->prepare('DELETE FROM phoromatic_schedules_triggers WHERE AccountID = :account_id AND ScheduleID = :schedule_id AND Trigger = :trigger');
                                        $stmt->bindValue(':account_id', $PATH[2]);
                                        $stmt->bindValue(':schedule_id', $PATH[3]);
                                        $stmt->bindValue(':trigger', $PATH[4]);
                                        $result = $stmt->execute();
                                        var_dump($result);
                                    }
                                }
                            }
                        }
                    }
                    break;
            }
        }
        $main = '<h1>Phoromatic Server Data</h1>';
        $main .= '<h1>Test Results</h1>';
        $main .= '<a onclick="javascript:phoromatic_generate_comparison(\'public.php?ut=\');"><div id="phoromatic_result_compare_info_box" style="background: #1976d2; border: 1px solid #000;"></div></a> <a onclick="javascript:phoromatic_delete_results(\'?admin_data/delete/result/\'); return false;"><div id="phoromatic_result_delete_box" style="background: #1976d2; border: 1px solid #000;">Delete Selected Results</div></a>';
        $main .= '<div class="pts_phoromatic_info_box_area">';
        $main .= '<div style="height: 500px;"><ul style="max-height: 100%;"><li><h1>Recent Test Results</h1></li>';
        $stmt = phoromatic_server::$db->prepare('SELECT Title, SystemID, ScheduleID, PPRID, UploadTime, TimesViewed, AccountID, UploadID FROM phoromatic_results ORDER BY UploadTime DESC');
        $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(\'public.php?ut=' . $test_result_row['PPRID'] . '\');">' . $test_result_row['Title'] . '</span><br /><table><tr><td>' . phoromatic_system_id_to_name($test_result_row['SystemID'], $test_result_row['AccountID']) . '</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>';
        }
        $main .= '</ul></div>';
        $main .= '</div>';
        $main .= '<hr /><h1>Schedules</h1>';
        $main .= '<h2>Active Test Schedules</h2>';
        $main .= '<div class="pts_phoromatic_info_box_area">
				<ul>
					<li><h1>Active Test Schedules</h1></li>';
        $stmt = phoromatic_server::$db->prepare('SELECT Title, ScheduleID, Description, RunTargetSystems, RunTargetGroups, RunAt, ActiveOn, AccountID FROM phoromatic_schedules WHERE State >= 1 ORDER BY Title ASC');
        $result = $stmt->execute();
        $row = $result->fetchArray();
        if ($row == false) {
            $main .= '<li class="light" style="text-align: center;">No Schedules Found</li>';
        } else {
            do {
                $main .= '<a onclick=""><li>' . $row['Title'] . '<br /><table><tr><td>' . phoromatic_account_id_to_group_name($row['AccountID']) . '</td><td>' . pts_strings::plural_handler(count(phoromatic_server::systems_associated_with_schedule($row['AccountID'], $row['ScheduleID'])), 'System') . '</td><td><strong>' . phoromatic_schedule_activeon_string($row['ActiveOn'], $row['RunAt']) . '</strong></td><td><a onclick="return confirm(\'Permanently remove this schedule?\');" href="/?admin_data/delete/schedule/' . $row['AccountID'] . '/' . $row['ScheduleID'] . '">Permanently Remove</a></td></tr></table></li></a>';
            } while ($row = $result->fetchArray());
        }
        $main .= '</ul></div>';
        $main .= '<hr /><h2>Inactive Test Schedules</h2>';
        $main .= '<div class="pts_phoromatic_info_box_area">
				<ul>
					<li><h1>Active Test Schedules</h1></li>';
        $stmt = phoromatic_server::$db->prepare('SELECT Title, ScheduleID, Description, RunTargetSystems, RunTargetGroups, RunAt, ActiveOn, AccountID FROM phoromatic_schedules WHERE State < 1 ORDER BY Title ASC');
        $result = $stmt->execute();
        $row = $result->fetchArray();
        if ($row == false) {
            $main .= '<li class="light" style="text-align: center;">No Schedules Found</li>';
        } else {
            do {
                $main .= '<a onclick=""><li>' . $row['Title'] . '<br /><table><tr><td>' . phoromatic_account_id_to_group_name($row['AccountID']) . '</td><td>' . pts_strings::plural_handler(count(phoromatic_server::systems_associated_with_schedule($row['AccountID'], $row['ScheduleID'])), 'System') . '</td><td><strong>' . phoromatic_schedule_activeon_string($row['ActiveOn'], $row['RunAt']) . '</strong></td><td><a onclick="return confirm(\'Permanently remove this schedule?\');" href="/?admin_data/delete/schedule/' . $row['AccountID'] . '/' . $row['ScheduleID'] . '">Permanently Remove</a></td></tr></table></li></a>';
            } while ($row = $result->fetchArray());
        }
        $main .= '</ul></div>';
        $main .= '<hr /><h2>Schedule Triggers</h2>';
        $main .= '<div class="pts_phoromatic_info_box_area">
				<ul>
					<li><h1>Triggers</h1></li>';
        $stmt = phoromatic_server::$db->prepare('SELECT Trigger, TriggeredOn, AccountID, ScheduleID FROM phoromatic_schedules_triggers ORDER BY TriggeredOn DESC');
        $result = $stmt->execute();
        $row = $result->fetchArray();
        if ($row == false) {
            $main .= '<li class="light" style="text-align: center;">No Triggers Found</li>';
        } else {
            do {
                $main .= '<a onclick=""><li>' . $row['Trigger'] . '<br /><table><tr><td>' . $row['TriggeredOn'] . '</td><td>' . phoromatic_account_id_to_group_name($row['AccountID']) . '</td><td><a onclick="return confirm(\'Permanently remove this trigger?\');" href="/?admin_data/delete/trigger/' . $row['AccountID'] . '/' . $row['ScheduleID'] . '/' . $row['Trigger'] . '">Permanently Remove</a></td></tr></table></li></a>';
            } while ($row = $result->fetchArray());
        }
        $main .= '</ul></div>';
        $main .= '<hr /><h1>Systems</h1>
			<h2>Active Systems</h2>
			<div class="pts_phoromatic_info_box_area">

					<ul>
						<li><h1>Active Systems</h1></li>';
        $stmt = phoromatic_server::$db->prepare('SELECT Title, SystemID, LocalIP, CurrentTask, LastCommunication, EstimatedTimeForTask, TaskPercentComplete, AccountID FROM phoromatic_systems WHERE State >= 0 ORDER BY LastCommunication DESC');
        $result = $stmt->execute();
        $row = $result->fetchArray();
        $active_system_count = 0;
        if ($row == false) {
            $main .= '<li class="light" style="text-align: center;">No Systems Found</li>';
        } else {
            do {
                $main .= '<a onclick=""><li>' . $row['Title'] . '<br /><table><tr><td>' . phoromatic_account_id_to_group_name($row['AccountID']) . '</td><td>' . $row['LocalIP'] . '</td><td><strong>' . $row['CurrentTask'] . '</strong></td><td><strong>Last Communication:</strong> ' . date('j F Y H:i', strtotime($row['LastCommunication'])) . '</td><td><a onclick="return confirm(\'Permanently remove this system?\');" href="/?admin_data/delete/system/' . $row['AccountID'] . '/' . $row['SystemID'] . '">Permanently Remove</a></td></tr></table></li></a>';
                $active_system_count++;
            } while ($row = $result->fetchArray());
        }
        $main .= '</ul></div>';
        $main .= '<h2>Inactive Systems</h2>
			<div class="pts_phoromatic_info_box_area">

					<ul>
						<li><h1>Inactive Systems</h1></li>';
        $stmt = phoromatic_server::$db->prepare('SELECT Title, SystemID, LocalIP, CurrentTask, LastCommunication, EstimatedTimeForTask, TaskPercentComplete, AccountID FROM phoromatic_systems WHERE State < 0 ORDER BY LastCommunication DESC');
        $result = $stmt->execute();
        $row = $result->fetchArray();
        $active_system_count = 0;
        if ($row == false) {
            $main .= '<li class="light" style="text-align: center;">No Systems Found</li>';
        } else {
            do {
                $main .= '<a onclick=""><li>' . $row['Title'] . '<br /><table><tr><td>' . phoromatic_account_id_to_group_name($row['AccountID']) . '</td><td>' . $row['LocalIP'] . '</td><td><strong>' . $row['CurrentTask'] . '</strong></td><td><strong>Last Communication:</strong> ' . date('j F Y H:i', strtotime($row['LastCommunication'])) . '</td><td><a onclick="return confirm(\'Permanently remove this system?\');" href="/?admin_data/delete/system/' . $row['AccountID'] . '/' . $row['SystemID'] . '">Permanently Remove</a></td></tr></table></li></a>';
                $active_system_count++;
            } while ($row = $result->fetchArray());
        }
        $main .= '</ul></div>';
        $stmt = phoromatic_server::$db->prepare('SELECT * FROM phoromatic_benchmark_tickets ORDER BY TicketIssueTime DESC');
        $result = $stmt->execute();
        $main .= '<hr /><h1>Benchmark Tickets</h1>
			<div class="pts_phoromatic_info_box_area"><ul><li><h1>Tickets</h1></li>';
        while ($result && ($row = $result->fetchArray())) {
            $main .= '<a onclick=""><li>' . $row['Title'] . '<br /><table><tr><td><a onclick="return confirm(\'Permanently remove this system?\');" href="/?admin_data/delete/ticket/' . $row['AccountID'] . '/' . $row['TicketID'] . '">Permanently Remove</a></td></tr></table></li></a>';
        }
        $main .= '</ul></div>';
        echo phoromatic_webui_header_logged_in();
        echo phoromatic_webui_main($main, phoromatic_webui_right_panel_logged_in());
        echo phoromatic_webui_footer();
    }
    public static function render_page_process($PATH)
    {
        echo phoromatic_webui_header_logged_in();
        $main = null;
        if (isset($PATH[0]) && !empty($PATH[0])) {
            ini_set('memory_limit', '4G');
            if (isset($_POST['view_results_from_past']) && is_numeric($_POST['view_results_from_past'])) {
                $cut_duration = $_POST['view_results_from_past'];
            } else {
                $cut_duration = 21;
            }
            $stmt = phoromatic_server::$db->prepare('SELECT UploadID, UploadTime, ScheduleID, Trigger, SystemID FROM phoromatic_results WHERE AccountID = :account_id AND ScheduleID = :schedule_id ORDER BY UploadTime DESC');
            $stmt->bindValue(':account_id', $_SESSION['AccountID']);
            $stmt->bindValue(':schedule_id', $PATH[0]);
            $test_result_result = $stmt->execute();
            $cutoff_time = is_numeric($cut_duration) ? strtotime('today -' . $cut_duration . ' days') : false;
            $show_only_latest_systems = array();
            $result_files = array();
            while ($test_result_result && ($row = $test_result_result->fetchArray())) {
                if ($cutoff_time !== false && strtotime($row['UploadTime']) < $cutoff_time) {
                    break;
                }
                $composite_xml = phoromatic_server::phoromatic_account_result_path($_SESSION['AccountID'], $row['UploadID']) . 'composite.xml';
                if (!is_file($composite_xml)) {
                    continue;
                }
                // Add to result file
                $system_name = phoromatic_server::system_id_to_name($row['SystemID']) . ': ' . $row['Trigger'];
                array_push($result_files, new pts_result_merge_select($composite_xml, null, $system_name));
                if (!isset($show_only_latest_systems[$_SESSION['AccountID'] . $row['SystemID']])) {
                    $show_only_latest_systems[$_SESSION['AccountID'] . $row['SystemID']] = new pts_result_merge_select($composite_xml, null, $system_name);
                }
            }
            if (count($result_files) < 21) {
                $show_only_latest_systems = null;
            }
            $attributes = array('new_result_file_title' => phoromatic_schedule_id_to_name($row['ScheduleID']));
            $result_file = new pts_result_file(null, true);
            $result_file->merge($result_files, $attributes);
            $extra_attributes = array('reverse_result_buffer' => true, 'force_simple_keys' => true, 'force_line_graph_compact' => true, 'force_tracking_line_graph' => true);
            if (isset($_POST['normalize_results']) && $_POST['normalize_results']) {
                $extra_attributes['normalize_result_buffer'] = true;
            }
            $main .= '<h1>' . $result_file->get_title() . '</h1>';
            if ($result_file->get_system_count() == 1 || ($intent = pts_result_file_analyzer::analyze_result_file_intent($result_file, $intent, true))) {
                $table = new pts_ResultFileCompactSystemsTable($result_file, $intent);
            } else {
                $table = new pts_ResultFileSystemsTable($result_file);
            }
            $main .= '<p style="text-align: center; overflow: auto;" class="result_object">' . pts_render::render_graph_inline_embed($table, $result_file, $extra_attributes) . '</p>';
            $table = new pts_ResultFileTable($result_file, $intent);
            $main .= '<p style="text-align: center; overflow: auto;" class="result_object">' . pts_render::render_graph_inline_embed($table, $result_file, $extra_attributes) . '</p>';
            $main .= '<div id="pts_results_area">';
            foreach ($result_file->get_result_objects(isset($_POST['show_only_changed_results']) ? 'ONLY_CHANGED_RESULTS' : -1) as $i => $result_object) {
                $main .= '<h2><a name="r-' . $i . '"></a><a name="' . $result_object->get_comparison_hash(true, false) . '"></a>' . $result_object->test_profile->get_title() . '</h2>';
                $main .= '<p class="result_object">';
                $main .= pts_render::render_graph_inline_embed($result_object, $result_file, $extra_attributes);
                $main .= '</p>';
            }
            $main .= '</div>';
            $right = '<form action="' . $_SERVER['REQUEST_URI'] . '" name="update_result_view" method="post">';
            $right .= '<p>Compare results for the past: ';
            $right .= '<select name="view_results_from_past" id="view_results_from_past">';
            $oldest_upload_time = strtotime(phoromatic_oldest_result_for_schedule($PATH[0]));
            $opts = array('Two Weeks' => 14, 'Three Weeks' => 21, 'One Month' => 30, 'Two Months' => 60, 'Quarter' => 90, 'Six Months' => 180, 'Year' => 365);
            foreach ($opts as $str_name => $time_offset) {
                if ($oldest_upload_time > time() - 86400 * $time_offset) {
                    break;
                }
                $right .= '<option value="' . $time_offset . '">' . $str_name . '</option>';
            }
            $right .= '<option value="all">All Results</option>';
            $right .= '</select>';
            $right .= '</p>';
            $right .= '<p><input type="checkbox" name="normalize_results" value="1" ' . (isset($_POST['normalize_results']) ? 'checked="checked" ' : null) . '/> Normalize Results?</p>';
            $right .= '<p><input type="submit" value="Refresh Results"></p></form>';
        } else {
            if (empty($PATH)) {
                $main .= '<h1>Phoromatic Tracker</h1>
					<p>The Phoromatic Tracker will show result schedules that have enough uploaded test results from the associated systems to begin providing concise overviews of performance over time.</p>
					<div class="pts_phoromatic_info_box_area">
					<ul>
						<li><h1>Trackable Results</h1></li>';
                $stmt = phoromatic_server::$db->prepare('SELECT Title, ScheduleID, Description, RunTargetSystems, RunTargetGroups, RunAt, ActiveOn, (SELECT COUNT(*) FROM phoromatic_results WHERE ScheduleID = phoromatic_schedules.ScheduleID) AS UploadedResultCount FROM phoromatic_schedules WHERE AccountID = :account_id AND State >= 1 ORDER BY Title ASC');
                $stmt->bindValue(':account_id', $_SESSION['AccountID']);
                $result = $stmt->execute();
                $row = $result->fetchArray();
                if ($row == false) {
                    $main .= '<li class="light" style="text-align: center;">No Relevant Schedules Found</li>';
                } else {
                    do {
                        if ($row['UploadedResultCount'] > ($row['RunTargetSystems'] + $row['RunTargetGroups'] + 1) * 7) {
                            $stmt_tests = phoromatic_server::$db->prepare('SELECT COUNT(*) AS TestCount FROM phoromatic_schedules_tests WHERE AccountID = :account_id AND ScheduleID = :schedule_id ORDER BY TestProfile ASC');
                            $stmt_tests->bindValue(':account_id', $_SESSION['AccountID']);
                            $stmt_tests->bindValue(':schedule_id', $row['ScheduleID']);
                            $result_tests = $stmt_tests->execute();
                            $row_tests = $result_tests->fetchArray();
                            $test_count = !empty($row_tests) ? $row_tests['TestCount'] : 0;
                            $group_count = empty($row['RunTargetGroups']) ? 0 : count(explode(',', $row['RunTargetGroups']));
                            $main .= '<a href="?tracker/' . $row['ScheduleID'] . '"><li>' . $row['Title'] . '<br /><table><tr><td>' . pts_strings::plural_handler(count(phoromatic_server::systems_associated_with_schedule($_SESSION['AccountID'], $row['ScheduleID'])), 'System') . '</td><td>' . pts_strings::plural_handler($group_count, 'Group') . '</td><td>' . pts_strings::plural_handler($test_count, 'Test') . '</td><td>' . pts_strings::plural_handler($row['UploadedResultCount'], 'Result') . ' Total</td></tr></table></li></a>';
                        }
                    } while ($row = $result->fetchArray());
                }
                $main .= '</ul>
			</div>';
                $right = null;
            }
        }
        echo phoromatic_webui_main($main, $right);
        echo phoromatic_webui_footer();
    }
    public static function render_page_process($PATH)
    {
        echo phoromatic_webui_header_logged_in();
        $main = null;
        if (!PHOROMATIC_USER_IS_VIEWER && !empty($PATH[0]) && isset($_POST['system_title']) && !empty($_POST['system_title']) && isset($_POST['system_description']) && isset($_POST['system_state'])) {
            $stmt = phoromatic_server::$db->prepare('UPDATE phoromatic_systems SET Title = :title, Description = :description, State = :state, CurrentTask = \'Awaiting Task\', BlockPowerOffs = :block_power_offs WHERE AccountID = :account_id AND SystemID = :system_id');
            $stmt->bindValue(':account_id', $_SESSION['AccountID']);
            $stmt->bindValue(':system_id', $PATH[0]);
            $stmt->bindValue(':title', $_POST['system_title']);
            $stmt->bindValue(':description', $_POST['system_description']);
            $stmt->bindValue(':state', $_POST['system_state']);
            $stmt->bindValue(':block_power_offs', $_POST['block_power_offs']);
            $stmt->execute();
        }
        if (!PHOROMATIC_USER_IS_VIEWER && !empty($PATH[0]) && isset($_POST['maintenance_mode'])) {
            $stmt = phoromatic_server::$db->prepare('UPDATE phoromatic_systems SET MaintenanceMode = :maintenance_mode WHERE AccountID = :account_id AND SystemID = :system_id');
            $stmt->bindValue(':account_id', $_SESSION['AccountID']);
            $stmt->bindValue(':system_id', $PATH[0]);
            $stmt->bindValue(':maintenance_mode', $_POST['maintenance_mode']);
            $stmt->execute();
        }
        if (!PHOROMATIC_USER_IS_VIEWER && !empty($PATH[0]) && isset($_POST['tick_thread_reboot'])) {
            $stmt = phoromatic_server::$db->prepare('UPDATE phoromatic_systems SET TickThreadEvent = :event WHERE AccountID = :account_id AND SystemID = :system_id');
            $stmt->bindValue(':account_id', $_SESSION['AccountID']);
            $stmt->bindValue(':system_id', $PATH[0]);
            $stmt->bindValue(':event', time() . ':reboot');
            $stmt->execute();
        }
        if (!PHOROMATIC_USER_IS_VIEWER && !empty($PATH[0]) && isset($_POST['tick_thread_halt'])) {
            $stmt = phoromatic_server::$db->prepare('UPDATE phoromatic_systems SET TickThreadEvent = :event WHERE AccountID = :account_id AND SystemID = :system_id');
            $stmt->bindValue(':account_id', $_SESSION['AccountID']);
            $stmt->bindValue(':system_id', $PATH[0]);
            $stmt->bindValue(':event', time() . ':halt-testing');
            $stmt->execute();
        }
        if (!PHOROMATIC_USER_IS_VIEWER && !empty($PATH[0]) && isset($_POST['system_var_names']) && isset($_POST['system_var_values'])) {
            $vars = array();
            foreach ($_POST['system_var_names'] as $i => $name) {
                if (isset($_POST['system_var_values'][$i])) {
                    $name = pts_strings::keep_in_string(strtoupper($name), pts_strings::CHAR_LETTER | pts_strings::CHAR_NUMERIC | pts_strings::CHAR_UNDERSCORE);
                    $val = pts_strings::keep_in_string($_POST['system_var_values'][$i], pts_strings::CHAR_LETTER | pts_strings::CHAR_NUMERIC | pts_strings::CHAR_DASH | pts_strings::CHAR_UNDERSCORE | pts_strings::CHAR_COMMA | pts_strings::CHAR_SLASH | pts_strings::CHAR_SPACE | pts_strings::CHAR_DECIMAL | pts_strings::CHAR_PLUS | pts_strings::CHAR_EQUAL);
                    if ($name != null) {
                        $vars[$name] = $val;
                    }
                }
            }
            $var_string = null;
            foreach ($vars as $name => $val) {
                $var_string .= $name . '=' . $val . ';';
            }
            $stmt = phoromatic_server::$db->prepare('UPDATE phoromatic_systems SET SystemVariables = :system_variables WHERE AccountID = :account_id AND SystemID = :system_id');
            $stmt->bindValue(':account_id', $_SESSION['AccountID']);
            $stmt->bindValue(':system_id', $PATH[0]);
            $stmt->bindValue(':system_variables', $var_string);
            $stmt->execute();
        }
        if (!empty($PATH[0])) {
            $stmt = phoromatic_server::$db->prepare('SELECT * FROM phoromatic_systems WHERE AccountID = :account_id AND SystemID = :system_id ORDER BY LastCommunication DESC');
            $stmt->bindValue(':account_id', $_SESSION['AccountID']);
            $stmt->bindValue(':system_id', $PATH[0]);
            $result = $stmt->execute();
            if (!empty($result)) {
                $row = $result->fetchArray();
                if (!PHOROMATIC_USER_IS_VIEWER && isset($PATH[1]) && $PATH[1] == 'edit') {
                    $main = '<h1>' . $row['Title'] . '</h1>';
                    $main .= '<form name="system_form" id="system_form" action="?systems/' . $PATH[0] . '" method="post" onsubmit="return phoromatic_system_edit(this);">
			<p><div style="width: 200px; font-weight: bold; float: left;">System Title:</div> <input type="text" style="width: 400px;" name="system_title" value="' . $row['Title'] . '" /></p>
			<p><div style="width: 200px; font-weight: bold; float: left;">System Description:</div> <textarea style="width: 400px;" name="system_description">' . $row['Description'] . '</textarea></p>
			<p><div style="width: 200px; font-weight: bold; float: left;">System State:</div><select name="system_state" style="width: 200px;"><option value="-1">Disabled</option><option value="1" selected="selected">Enabled</option></select></p>
			<p><div style="width: 200px; font-weight: bold; float: left;">Allow Phoromatic To Power Off System When Testing Complete:</div><select name="block_power_offs" style="width: 200px;"><option value="0">Permitted</option><option value="1">Block Power-Off Signaling For This System</option></select> <sup>Assuming the power-off setting is enabled from the account settings page.</sup></p>
			<p><div style="width: 200px; font-weight: bold; float: left;">&nbsp;</div> <input type="submit" value="Submit" /></p></form>';
                } else {
                    $main = '<h1>' . $row['Title'] . '</h1><p><em>' . ($row['Description'] != null ? $row['Description'] : 'No system description.') . '</em></p>';
                    if (phoromatic_server::system_check_if_down($_SESSION['AccountID'], $row['SystemID'], $row['LastCommunication'], $row['CurrentTask'])) {
                        $main .= '<h3 style="text-align: center; color: red;">This system appears to be offline or inactive and there are pending tests scheduled to be run on this system that have yet to be completed. This system has not communicated with the Phoromatic Server in ' . pts_strings::format_time(time() - strtotime($row['LastCommunication']), 'SECONDS', true, 60) . '.</h3>';
                    }
                    if (!PHOROMATIC_USER_IS_VIEWER) {
                        $main .= '<p><a href="?systems/' . $PATH[0] . '/edit">Edit Task & Enable/Disable System</a></p>';
                    }
                }
                switch ($row['State']) {
                    case -1:
                        $state = 'Disabled';
                        break;
                    case 0:
                        $state = 'Connected; Awaiting Approval';
                        break;
                    case 1:
                        $state = 'Active';
                        break;
                }
                $main .= '<hr />';
                $info_table = array('Status:' => $row['CurrentTask'], 'Last Communication:' => phoromatic_user_friendly_timedate($row['LastCommunication']), 'Estimated Time Left For Task: ' => phoromatic_compute_estimated_time_remaining_string($row['EstimatedTimeForTask'], $row['LastCommunication']), 'State:' => $state, 'Phoronix Test Suite Client:' => $row['ClientVersion'], 'Initial Creation:' => phoromatic_user_friendly_timedate($row['CreatedOn']), 'System ID:' => $row['SystemID'], 'Last IP:' => $row['LastIP'], 'MAC Address:' => $row['NetworkMAC'], 'Wake-On-LAN Information:' => empty($row['NetworkWakeOnLAN']) ? 'N/A' : $row['NetworkWakeOnLAN'], 'Power-Off Sequence Permitted: ' => $row['BlockPowerOffs'] == 1 ? 'Blocked' : 'Permitted');
                $main .= '<h2>System State</h2>' . pts_webui::r2d_array_to_table($info_table, 'auto');
                if (!PHOROMATIC_USER_IS_VIEWER) {
                    if ($row['MaintenanceMode'] == 1) {
                        $mm_str = 'Disable Maintenance Mode';
                        $mm_val = 0;
                        $mm_onclick = 'return true;';
                    } else {
                        $mm_str = 'Enter Maintenance Mode';
                        $mm_val = 1;
                        $mm_onclick = 'return confirm(\'Enter maintenance mode now?\');';
                    }
                    $main .= '<p><form action="' . $_SERVER['REQUEST_URI'] . '" name="update_groups" method="post"><input type="hidden" name="maintenance_mode" value="' . $mm_val . '" /><input type="submit" value="' . $mm_str . '" onclick="' . $mm_onclick . '" style="float: left; margin: 0 20px 5px 0;" /></form> Putting the system into maintenance mode will power up the system (if supported and applicable) and cause the Phoronix Test Suite Phoromatic client to idle and block all testing until the mode has been disabled. If a test is already running on the system, the maintenance mode will not be entered until after the testing has completed. The maintenance mode can be used if wishing to update the system software or carry out other tasks without interfering with the Phoromatic client process. Once disabled, the Phoronix Test Suite will continue to function as normal.</p>';
                    if ($row['CoreVersion'] >= 5730) {
                        $main .= '<p><form action="' . $_SERVER['REQUEST_URI'] . '" name="update_groups" method="post"><input type="hidden" name="tick_thread_reboot" value="1" /><input type="submit" value="Reboot System" style="float: left; margin: 0 20px 5px 0;" /></form> If the system is currently powered up and connected to the Phoromatic Server, this will send a message to the system to issue a reboot -- in case the system is hung on a test or you wish to otherwise manually reboot the server. This feature was added with Phoronix Test Suite 5.8.</p>';
                        $main .= '<p><form action="' . $_SERVER['REQUEST_URI'] . '" name="update_groups" method="post"><input type="hidden" name="tick_thread_halt" value="1" /><input type="submit" value="Halt Testing" style="float: left; margin: 0 20px 5px 0;" /></form> If the system is currently powered up and running a test/benchmark via the Phoromatic Server, this will tell the system to halt the testing prematurely as soon as the currently-active test has finished. The results successfully ran will then be uploaded to the Phoromatic Server. This feature was added with Phoronix Test Suite 5.8.</p>';
                    }
                }
                $main .= '<hr /><h2>System Variables</h2><p>System variables are a new feature of Phoronix Test Suite 5.6 to allow for providing per-system information in an easy-to-use manner for other parts of the Phoromatic system. Initially these named variables can be used for the results identifier when <a href="/?benchmark">creating a benchmark ticket</a> and in the future the system variables may be used elsewhere. Examples of system variables could include providing a <em>.SERIAL</em> variable to acknowledge the system\'s serial number that may not be presented elsewhere by the Phoronix Test Suite, <em>.ADMIN</em> for the system\'s local administrator, etc. Variable names can only be alpha-numeric strings while their values are also alpha-numeric strings but with spaces allowed. System variables are always prefixed by a period. These system variables are also automatically transferred to the Phoromatic clients and set as environment variables prior to running any scheduled tests/process via Phoromatic.</p>';
                $system_variables = explode(';', $row['SystemVariables']);
                $main .= '<form action="' . $_SERVER['REQUEST_URI'] . '" name="update_system_variables" method="post">';
                $main .= '<table width="80%"><tr><th>Variable Name</th><th>Value</th></tr>';
                foreach ($system_variables as $i => $v_string) {
                    $var = explode('=', $v_string);
                    if (count($var) == 2) {
                        $main .= '<tr id="system_var_' . $i . '">';
                        $main .= '<td><span style="font-weight: 800; font-size: 16px;">.</span><input name="system_var_names[]" value="' . $var[0] . '" readonly /></td>';
                        $main .= '<td><input name="system_var_values[]" value="' . $var[1] . '" readonly /></td>';
                        $main .= '</tr>';
                    }
                }
                $main .= '<tr id="system_var_' . ($i + 1) . '">';
                $main .= '<td><span style="font-weight: 800; font-size: 16px;">.</span><input name="system_var_names[]" /></td>';
                $main .= '<td><input name="system_var_values[]" /></td>';
                $main .= '</tr>';
                $main .= '</table>';
                $main .= '<p><input name="submit" value="Update System Variables" type="submit" /></p></form>';
                $main .= '<hr /><h2>System Components</h2><div style="float: left; width: 50%;">';
                $components = pts_result_file_analyzer::system_component_string_to_array($row['Hardware']);
                $main .= pts_webui::r2d_array_to_table($components) . '</div><div style="float: left; width: 50%;">';
                $components = pts_result_file_analyzer::system_component_string_to_array($row['Software']);
                $main .= pts_webui::r2d_array_to_table($components) . '</div>';
                $system_path = phoromatic_server::phoromatic_account_system_path($_SESSION['AccountID'], $row['SystemID']);
                $main .= '<hr />';
                if (is_file($system_path . 'sensors-pool.json')) {
                    $sensors = file_get_contents($system_path . 'sensors-pool.json');
                    $sensors = json_decode($sensors, true);
                    foreach ($sensors as $title => $s) {
                        if (!isset($s['values']) || count($s['values']) < 5 || max($s['values']) == min($s['values'])) {
                            continue;
                        }
                        $graph = new pts_sys_graph(array('title' => $title, 'x_scale' => 'm', 'y_scale' => $s['unit'], 'text_size' => 12, 'reverse_x_direction' => false, 'width' => 920, 'height' => 400));
                        $graph->render_base();
                        $svg_dom = $graph->render_graph_data($s['values']);
                        if ($svg_dom === false) {
                            continue;
                        }
                        $output_type = 'SVG';
                        $graph = $svg_dom->output(null, $output_type);
                        $main .= '<p align="center">' . substr($graph, strpos($graph, '<svg')) . '</p>';
                    }
                } else {
                    if (is_file($system_path . 'sensors.json')) {
                        $sensor_file = file_get_contents($system_path . 'sensors.json');
                        $sensor_file = json_decode($sensor_file, true);
                        if ($sensor_file && isset($sensor_file['sensors']) && !empty($sensor_file['sensors'])) {
                            $i = 0;
                            $col = array(1 => array(), 2 => array(), 3 => array(), 0 => array());
                            foreach ($sensor_file['sensors'] as $name => $sensor) {
                                array_push($col[$i % 4], '<strong>' . $name . ':</strong> ' . $sensor['value'] . ' ' . $sensor['unit']);
                                $i++;
                            }
                            $main .= '<h2>System Sensors</h2>';
                            foreach ($col as $sensors) {
                                $main .= '<div style="float: left; width: 25%;">';
                                foreach ($sensors as $sensor) {
                                    $main .= '<p>' . $sensor . '</p>';
                                }
                                $main .= '</div>';
                            }
                            $main .= '<p><em><strong>Last Updated:</strong>' . date('d F H:i', filemtime(phoromatic_server::phoromatic_account_system_path($_SESSION['AccountID'], $row['SystemID']) . 'sensors.json')) . ' <strong>System Uptime:</strong> ' . $sensor_file['uptime'] . ' Minutes</em></p>';
                        }
                    }
                }
                $log_file = phoromatic_server::phoromatic_account_system_path($_SESSION['AccountID'], $row['SystemID']) . 'phoronix-test-suite.log';
                if (is_file($log_file)) {
                    $main .= '<hr /><h2>Phoronix Test Suite Client Log</h2>';
                    $main .= '<p><textarea style="width: 60%; height: 200px;">' . file_get_contents($log_file) . '</textarea></p>';
                    $main .= '<p><em><strong>Last Updated:</strong>' . date('d F H:i', filemtime($log_file)) . '</em></p>';
                }
                $groups = explode('#', $row['Groups']);
                foreach ($groups as $i => $group) {
                    if (empty($group)) {
                        unset($groups[$i]);
                    }
                }
                $schedules = phoromatic_server::schedules_that_run_on_system($_SESSION['AccountID'], $row['SystemID']);
                if (!empty($groups) || !empty($schedules)) {
                    $main .= '<hr /><h2>Schedules</h2>';
                    if (!empty($groups)) {
                        $group_msg = 'This system belongs to the following groups: <strong>' . implode(', ', $groups) . '</strong>.';
                    } else {
                        $group_msg = 'This system does not currently belong to any groups.';
                    }
                    $main .= '<p>' . $group_msg . ' Manage groups via the <a href="?systems">systems page</a>.</p>';
                    if (!empty($schedules)) {
                        $main .= '<div class="pts_phoromatic_info_box_area" style="margin: 0 10%;"><ul><li><h1>Schedules Running On This System</h1></li>';
                        foreach ($schedules as &$row) {
                            $group_count = empty($row['RunTargetGroups']) ? 0 : count(explode(',', $row['RunTargetGroups']));
                            $main .= '<a href="?schedules/' . $row['ScheduleID'] . '"><li>' . $row['Title'] . '<br /><table><tr><td>' . pts_strings::plural_handler(count(phoromatic_server::systems_associated_with_schedule($_SESSION['AccountID'], $row['ScheduleID'])), 'System') . '</td><td>' . pts_strings::plural_handler($group_count, 'Group') . '</td><td>' . pts_strings::plural_handler(phoromatic_results_for_schedule($row['ScheduleID']), 'Result') . '</td><td><strong>' . phoromatic_schedule_activeon_string($row['ActiveOn'], $row['RunAt']) . '</strong></td></tr></table></li></a>';
                        }
                        $main .= '</ul></div>';
                    }
                }
                $stmt = phoromatic_server::$db->prepare('SELECT Title, SystemID, ScheduleID, PPRID, UploadTime FROM phoromatic_results WHERE AccountID = :account_id AND SystemID = :system_id ORDER BY UploadTime DESC');
                $stmt->bindValue(':account_id', $_SESSION['AccountID']);
                $stmt->bindValue(':system_id', $PATH[0]);
                $test_result_result = $stmt->execute();
                $test_result_row = $test_result_result->fetchArray();
                $results = 0;
                if ($test_result_row != false) {
                    $main .= '<hr /><h2>Test Results</h2>';
                    $main .= '<div class="pts_phoromatic_info_box_area" style="margin: 0 10%;">';
                    $main .= '<ul><li><h1>Recent Test Results</h1></li>';
                    do {
                        if ($results > 20) {
                            break;
                        }
                        $main .= '<a href="?result/' . $test_result_row['PPRID'] . '"><li>' . $test_result_row['Title'] . '<br /><table><tr><td>' . phoromatic_system_id_to_name($test_result_row['SystemID']) . '</td><td>' . phoromatic_user_friendly_timedate($test_result_row['UploadTime']) . '</td></tr></table></li></a>';
                        $results++;
                    } while ($test_result_row = $test_result_result->fetchArray());
                }
                if ($results > 0) {
                    $main .= '</ul></div>';
                }
                // Any System Errors?
                $stmt = phoromatic_server::$db->prepare('SELECT ErrorMessage, UploadTime, SystemID, TestIdentifier FROM phoromatic_system_client_errors WHERE AccountID = :account_id AND SystemID = :system_id ORDER BY UploadTime DESC LIMIT 10');
                $stmt->bindValue(':account_id', $_SESSION['AccountID']);
                $stmt->bindValue(':system_id', $PATH[0]);
                $result = $stmt->execute();
                $row = $result->fetchArray();
                if ($row != false) {
                    $main .= '<hr /><div class="pts_phoromatic_info_box_area" style="margin: 0 10%;"><ul><li><h1>Recent System Warnings &amp; Errors</h1></li>';
                    do {
                        $main .= '<a onclick=""><li>' . $row['ErrorMessage'] . '<br /><table><tr><td>' . $row['UploadTime'] . '</td><td>' . $row['TestIdentifier'] . '</td></tr></table></li></a>';
                    } while ($row = $result->fetchArray());
                    $main .= '	</ul></div>';
                }
            }
        }
        if ($main == null) {
            if (!PHOROMATIC_USER_IS_VIEWER && isset($_POST['new_group']) && !empty($_POST['new_group'])) {
                $group = trim($_POST['new_group']);
                if ($group) {
                    $stmt = phoromatic_server::$db->prepare('INSERT INTO phoromatic_groups (AccountID, GroupName) VALUES (:account_id, :group_name)');
                    $stmt->bindValue(':account_id', $_SESSION['AccountID']);
                    $stmt->bindValue(':group_name', $group);
                    $result = $stmt->execute();
                    phoromatic_add_activity_stream_event('groups', $group, 'added');
                    if (!empty($_POST['systems_for_group']) && is_array($_POST['systems_for_group'])) {
                        foreach ($_POST['systems_for_group'] as $sid) {
                            // Find current groups
                            $stmt = phoromatic_server::$db->prepare('SELECT Groups FROM phoromatic_systems WHERE AccountID = :account_id AND SystemID = :system_id ORDER BY LastCommunication DESC');
                            $stmt->bindValue(':account_id', $_SESSION['AccountID']);
                            $stmt->bindValue(':system_id', $sid);
                            $result = $stmt->execute();
                            $row = $result->fetchArray();
                            $existing_groups = $row != false ? $row['Groups'] : null;
                            // Append new Group
                            $stmt = phoromatic_server::$db->prepare('UPDATE phoromatic_systems SET Groups = :new_group WHERE AccountID = :account_id AND SystemID = :system_id');
                            $stmt->bindValue(':account_id', $_SESSION['AccountID']);
                            $stmt->bindValue(':system_id', $sid);
                            $stmt->bindValue(':new_group', $existing_groups . '#' . $group . '#');
                            $stmt->execute();
                        }
                    }
                }
            } else {
                if (!PHOROMATIC_USER_IS_VIEWER && isset($_POST['system_group_update'])) {
                    $stmt = phoromatic_server::$db->prepare('SELECT SystemID FROM phoromatic_systems WHERE AccountID = :account_id');
                    $stmt->bindValue(':account_id', $_SESSION['AccountID']);
                    $result = $stmt->execute();
                    phoromatic_add_activity_stream_event('groups', null, 'modified');
                    while ($row = $result->fetchArray()) {
                        if (isset($_POST['groups_' . $row['SystemID']])) {
                            $group_string = null;
                            foreach ($_POST['groups_' . $row['SystemID']] as $group) {
                                if ($group != null) {
                                    $group_string .= '#' . $group . '#';
                                }
                            }
                            $stmt1 = phoromatic_server::$db->prepare('UPDATE phoromatic_systems SET Groups = :new_groups WHERE AccountID = :account_id AND SystemID = :system_id');
                            $stmt1->bindValue(':account_id', $_SESSION['AccountID']);
                            $stmt1->bindValue(':system_id', $row['SystemID']);
                            $stmt1->bindValue(':new_groups', $group_string);
                            $stmt1->execute();
                        }
                    }
                } else {
                    if (!PHOROMATIC_USER_IS_VIEWER && isset($_POST['remove_group'])) {
                        $stmt = phoromatic_server::$db->prepare('DELETE FROM phoromatic_groups WHERE AccountID = :account_id AND GroupName = :group_name');
                        $stmt->bindValue(':account_id', $_SESSION['AccountID']);
                        $stmt->bindValue(':group_name', $_POST['remove_group']);
                        $stmt->execute();
                        phoromatic_add_activity_stream_event('groups', $group, 'removed');
                        $stmt = phoromatic_server::$db->prepare('SELECT SystemID, Groups FROM phoromatic_systems WHERE AccountID = :account_id AND Groups LIKE \'%#' . $_POST['remove_group'] . '#%\'');
                        $stmt->bindValue(':account_id', $_SESSION['AccountID']);
                        $result = $stmt->execute();
                        while ($row = $result->fetchArray()) {
                            $revised_groups = str_replace('#' . $_POST['remove_group'] . '#', null, $row['Groups']);
                            $stmt1 = phoromatic_server::$db->prepare('UPDATE phoromatic_systems SET Groups = :new_groups WHERE AccountID = :account_id AND SystemID = :system_id');
                            $stmt1->bindValue(':account_id', $_SESSION['AccountID']);
                            $stmt1->bindValue(':system_id', $row['SystemID']);
                            $stmt1->bindValue(':new_groups', $revised_groups);
                            $stmt1->execute();
                        }
                    }
                }
            }
            $main = '<h1>Test Systems</h1>';
            if (!PHOROMATIC_USER_IS_VIEWER) {
                $main .= phoromatic_systems_needing_attention();
                $main .= '<h2>Add A System</h2>
				<p>To connect a <a href="http://www.phoronix-test-suite.com/">Phoronix Test Suite</a> test system to this account for remotely managing and/or carrying out routine automated benchmarking, follow these simple and quick steps:</p>
				<ol><li>From a system with <em>Phoronix Test Suite 5.4 or newer</em> run <strong>phoronix-test-suite phoromatic.connect ' . phoromatic_web_socket_server_addr() . '</strong>. (The test system must be able to access this server\'s correct IP address / domain name.)</li><li>When you have run the command from the test system, you will need to log into this page on Phoromatic server again where you can approve the system and configure the system settings so you can begin using it as part of this Phoromatic account.</li><li>Repeat the two steps for as many systems as you would like! When you are all done -- if you haven\'t done so already, you can start creating test schedules, groups, and other Phoromatic events.</li></ol>
				<p>Those having to connect many Phoronix Test Suite Phoromatic clients can also attempt <a href="?system_claim">adding the server configuration</a> via SSH or an IP/MAC address claim.</p>
				<p><button onclick="javascript:window.location.replace(\'?system_claim\');">Add Via SSH Or IP/MAC Claim</button></p>';
            }
            $main .= '<hr />

			<h2>Systems</h2>
			<div class="pts_phoromatic_info_box_area" style="margin: 0 10%;">

					<ul>
						<li><h1>Active Systems</h1></li>';
            $stmt = phoromatic_server::$db->prepare('SELECT Title, SystemID, LocalIP, CurrentTask, LastCommunication, EstimatedTimeForTask, TaskPercentComplete FROM phoromatic_systems WHERE AccountID = :account_id AND State >= 0 ORDER BY LastCommunication DESC');
            $stmt->bindValue(':account_id', $_SESSION['AccountID']);
            $result = $stmt->execute();
            $row = $result->fetchArray();
            $active_system_count = 0;
            if ($row == false) {
                $main .= '<li class="light" style="text-align: center;">No Systems Found</li>';
            } else {
                do {
                    $acti = phoromatic_compute_estimated_time_remaining_string($row['EstimatedTimeForTask'], $row['LastCommunication']) . ($row['TaskPercentComplete'] > 0 ? ' [' . $row['TaskPercentComplete'] . '% Complete]' : null);
                    if (empty($acti)) {
                        $next_job_in = phoromatic_server::time_to_next_scheduled_job($_SESSION['AccountID'], $row['SystemID']);
                        if ($next_job_in > 0) {
                            if ($next_job_in > 600) {
                                $next_job_in = round($next_job_in / 60);
                                $next_unit = 'hours';
                            } else {
                                $next_unit = 'minutes';
                            }
                            $acti = 'Next job in ' . $next_job_in . ' ' . $next_unit;
                        }
                    }
                    $main .= '<a href="?systems/' . $row['SystemID'] . '"><li>' . $row['Title'] . '<br /><table><tr><td>' . $row['LocalIP'] . '</td><td><strong>' . $row['CurrentTask'] . '</strong></td><td><strong>' . $acti . '</strong></td><td><strong>Last Communication:</strong> ' . date('j F Y H:i', strtotime($row['LastCommunication'])) . '</td></tr></table></li></a>';
                    $active_system_count++;
                } while ($row = $result->fetchArray());
            }
            $main .= '</ul>';
            $stmt = phoromatic_server::$db->prepare('SELECT Title, SystemID, LocalIP, CurrentTask, LastCommunication, EstimatedTimeForTask, TaskPercentComplete FROM phoromatic_systems WHERE AccountID = :account_id AND State < 0 ORDER BY LastCommunication DESC');
            $stmt->bindValue(':account_id', $_SESSION['AccountID']);
            $result = $stmt->execute();
            $row = $result->fetchArray();
            if ($row != false) {
                $main .= '<ul>
				<li><h1>Inactive Systems</h1></li>';
                do {
                    $main .= '<a href="?systems/' . $row['SystemID'] . '"><li>' . $row['Title'] . '<br /><table><tr><td>' . $row['LocalIP'] . '</td><td><strong>' . $row['CurrentTask'] . '</strong></td><td><strong>Deactivated</strong></td><td><strong>Last Communication:</strong> ' . date('j F Y H:i', strtotime($row['LastCommunication'])) . '</td></tr></table></li></a>';
                } while ($row = $result->fetchArray());
                $main .= '</ul>';
            }
            $main .= '</div>';
            if ($active_system_count > 2) {
                $main .= '<h3 align="center"><a href="/?component_table">System Component Table</a> | <a href="/?maintenance_table">System Maintenance Table</a> | <a href="/?dashboard">System Dashboard</a></h3>';
            }
            if (!PHOROMATIC_USER_IS_VIEWER) {
                $main .= '<hr />
				<h2>System Groups</h2>
				<p>System groups make it very easy to organize multiple test systems for targeting by test schedules. You can always add/remove systems to groups, create new groups, and add systems to multiple groups. After creating a group and adding systems to the group, you can begin targeting tests against a particular group of systems. Systems can always be added/removed from groups later and a system can belong to multiple groups.</p>';
                $main .= '<div style="float: left;"><form name="new_group_form" id="new_group_form" action="?systems" method="post" onsubmit="return phoromatic_new_group(this);">
				<p><div style="width: 200px; font-weight: bold; float: left;">New Group Name:</div> <input type="text" style="width: 300px;" name="new_group" value="" /></p>
				<p><div style="width: 200px; font-weight: bold; float: left;">Select System(s) To Add To Group:</div><select name="systems_for_group[]" multiple="multiple" style="width: 300px;">';
                $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();
                $row = $result->fetchArray();
                if ($row != false) {
                    do {
                        $main .= '<option value="' . $row['SystemID'] . '">' . $row['Title'] . '</option>';
                    } while ($row = $result->fetchArray());
                }
                $main .= '</select></p>
				<p><div style="width: 200px; font-weight: bold; float: left;">&nbsp;</div> <input type="submit" value="Create Group" /></p></form></div>';
                $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();
                $row = $result->fetchArray();
                if ($row != false) {
                    $main .= '<div style="float: left; margin-left: 90px;"><h3>Current System Groups</h3>';
                    do {
                        $stmt_count = phoromatic_server::$db->prepare('SELECT COUNT(SystemID) AS system_count FROM phoromatic_systems WHERE AccountID = :account_id AND State >= 0 AND Groups LIKE \'%#' . $row['GroupName'] . '#%\'');
                        $stmt_count->bindValue(':account_id', $_SESSION['AccountID']);
                        $result_count = $stmt_count->execute();
                        $row_count = $result_count->fetchArray();
                        $row_count['system_count'] = isset($row_count['system_count']) ? $row_count['system_count'] : 0;
                        $main .= '<div style="clear: both;"><div style="width: 200px; float: left; font-weight: bold;">' . $row['GroupName'] . '</div> ' . $row_count['system_count'] . ' System' . ($row_count['system_count'] != 1 ? 's' : '') . '</div>';
                    } while ($row = $result->fetchArray());
                    $main .= '</div>';
                    $main .= '<hr /><a name="group_edit"></a><h2>System Group Editing</h2><div style="text-align: center;"><form action="' . $_SERVER['REQUEST_URI'] . '" name="update_groups" method="post"><input type="hidden" name="system_group_update"  value="1" />';
                    $main .= '<table style="margin: 5px auto; overflow: auto;">';
                    $main .= '<tr>';
                    $main .= '<th></th>';
                    $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();
                    $all_groups = array();
                    while ($row = $result->fetchArray()) {
                        $main .= '<th>' . $row['GroupName'] . '</th>';
                        array_push($all_groups, $row['GroupName']);
                    }
                    $main .= '</tr>';
                    $stmt = phoromatic_server::$db->prepare('SELECT Title, SystemID, Groups FROM phoromatic_systems WHERE AccountID = :account_id AND State >= 0 ORDER BY Title ASC');
                    $stmt->bindValue(':account_id', $_SESSION['AccountID']);
                    $result = $stmt->execute();
                    while ($row = $result->fetchArray()) {
                        $main .= '<tr>';
                        $main .= '<th>' . $row['Title'] . '</th>';
                        $main .= '<input type="hidden" name="groups_' . $row['SystemID'] . '[]" value="" />';
                        foreach ($all_groups as $group) {
                            $checked = stripos($row['Groups'], '#' . $group . '#') !== false ? 'checked="checked" ' : null;
                            $main .= '<td><input type="checkbox" name="groups_' . $row['SystemID'] . '[]" value="' . $group . '" ' . $checked . '/></td>';
                        }
                        $main .= '</tr>';
                    }
                    $main .= '</table><p><input name="submit" value="Update Groups" type="submit" /></p></form></div>';
                    $main .= '<hr /><h2>Remove A Group</h2><p>Removing a group is a permanent action that cannot be undone.</p>';
                    $main .= '<p><form action="' . $_SERVER['REQUEST_URI'] . '" name="remove_group" method="post"><select name="remove_group" id="remove_group">';
                    foreach ($all_groups as $group) {
                        $main .= '<option value="' . $group . '">' . $group . '</option>';
                    }
                    $main .= '</select> <input name="submit" value="Remove Group" type="submit" /></form></p>';
                }
            }
        }
        $right = '<ul><li>Active Systems</li>';
        $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();
        $row = $result->fetchArray();
        if ($row == false) {
            $right .= '</ul><p style="text-align: left; margin: 6px 10px;">No Systems Found</p>';
        } else {
            do {
                $right .= '<li><a href="?systems/' . $row['SystemID'] . '">' . $row['Title'] . '</a></li>';
            } while ($row = $result->fetchArray());
            $right .= '</ul>';
        }
        echo '<div id="pts_phoromatic_main_area">' . $main . '</div>';
        echo phoromatic_webui_footer();
    }
 public static function render_page_process($PATH)
 {
     $test_version = self::$test_profile->get_app_version();
     $test_title = self::$test_profile->get_title() . ($test_version != null ? ' ' . $test_version : null);
     echo '<h1>' . $test_title . '</h1>';
     echo '<div id="test_main_area">';
     echo '<p>' . self::$test_profile->get_description() . '</p>';
     echo '<h4 style="margin-top: 60px;">Run This Test</h4>';
     echo '<div id="pts_add_test_area">';
     $test_settings = array();
     $test_options = self::$test_profile->get_test_option_objects();
     $identifiers = array();
     for ($i = 0; $i < count($test_options); $i++) {
         $o = $test_options[$i];
         $option_count = $o->option_count();
         $test_prefix = 'test_option_';
         $option_name = $o->get_name();
         if ($option_count == 0) {
             $option_value = '<input type="text" id="' . $test_prefix . $o->get_identifier() . '" />';
         } else {
             $option_value = '<select id="' . $test_prefix . $o->get_identifier() . '">';
             for ($j = 0; $j < $option_count; $j++) {
                 $option_value .= '<option value="' . $o->format_option_value_from_input($o->get_option_value($j)) . '">' . $o->get_option_name($j) . '</option>';
             }
             $option_value .= '</select>';
         }
         $identifiers[] = $o->get_identifier();
         echo '<input id="' . $test_prefix . $o->get_identifier() . '_title" type="hidden" value="' . $option_name . '" />';
         $test_settings[] = array($option_name, $option_value);
     }
     $test_settings[] = array('<input type="Submit" value="Add Test To Run Queue" onclick="test_add_to_queue(\'' . (isset($test_prefix) ? $test_prefix : "") . '\', \'' . implode(':', $identifiers) . '\', \'' . self::$test_profile->get_identifier() . '\', \'' . base64_encode(json_encode(self::$test_profile->to_json())) . '\'); return false;" />');
     echo pts_webui::r2d_array_to_table($test_settings);
     echo '</div>';
     echo '</div>';
     echo '<div id="test_side_area">';
     $tabular_info = array(array('Test Profile', self::$test_profile->get_identifier()), array('Maintainer', self::$test_profile->get_maintainer()), array('Test Type', self::$test_profile->get_test_hardware_type()), array('Software Type', self::$test_profile->get_test_software_type()), array('License Type', self::$test_profile->get_license()), array('Test Status', self::$test_profile->get_status()));
     $project_url = self::$test_profile->get_project_url();
     $project_url = parse_url($project_url);
     if ($project_url != null && isset($project_url['host'])) {
         $tabular_info[] = array('Project Site', '<a href="' . self::$test_profile->get_project_url() . '" target="_blank">' . $project_url['host'] . '</a>');
     }
     echo '<h4>Test Profile Information</h4>';
     echo pts_webui::r2d_array_to_table($tabular_info);
     $tabular_info = array();
     if (self::$test_profile->get_estimated_run_time() > 1) {
         $tabular_info[] = array('Estimated Test Run-Time', pts_strings::plural_handler(ceil(self::$test_profile->get_estimated_run_time() / 60), 'Minute'));
     }
     $download_size = self::$test_profile->get_download_size();
     if (!empty($download_size)) {
         $tabular_info[] = array('Download Size', $download_size . ' MB');
     }
     $environment_size = self::$test_profile->get_environment_size();
     if (!empty($environment_size)) {
         $tabular_info[] = array('Environment Size', $environment_size . ' MB');
     }
     if (self::$test_profile->test_installation != false) {
         $last_run = self::$test_profile->test_installation->get_last_run_date();
         $last_run = $last_run == '0000-00-00' ? 'Never' : date('j F Y', strtotime($last_run));
         $avg_time = self::$test_profile->test_installation->get_average_run_time();
         $avg_time = !empty($avg_time) ? pts_strings::format_time($avg_time, 'SECONDS') : null;
         $latest_time = self::$test_profile->test_installation->get_latest_run_time();
         $latest_time = !empty($latest_time) ? pts_strings::format_time($latest_time, 'SECONDS') : 'N/A';
         $tabular_info[] = array('Last Local Run', $last_run);
         if ($last_run != 'Never') {
             if (self::$test_profile->test_installation->get_run_count() > 1) {
                 $tabular_info[] = array('Average Local Run-Time', $avg_time);
             }
             if ($latest_time != null) {
                 $tabular_info[] = array('Latest Local Run-Time', $latest_time);
             }
             if (self::$test_profile->test_installation->get_run_count() > 0) {
                 $tabular_info[] = array('Times Run Locally', self::$test_profile->test_installation->get_run_count());
             }
         }
     }
     echo '<h4>Installation Data</h4>';
     echo pts_webui::r2d_array_to_table($tabular_info);
     $dependencies = self::$test_profile->get_dependency_names();
     if (!empty($dependencies) && !empty($dependencies[0])) {
         array_unshift($dependencies, 'Test Dependencies');
         pts_webui::r1d_array_to_table($dependencies);
     }
     if (self::$test_profile->test_installation == false) {
         $files = pts_test_install_request::read_download_object_list(self::$test_profile);
         if (count($files) > 0) {
             $download_files = array('Test Files');
             foreach ($files as &$file) {
                 $download_files[] = $file->get_filename() . ' [' . max(0.1, round($file->get_filesize() / 1048576, 1)) . 'MB]';
             }
             pts_webui::r1d_array_to_table($download_files);
         }
     }
     echo '</div>';
 }
 public function test_install_process($test_install_manager)
 {
     $this->test_install_pos = 0;
     $this->test_install_count = $test_install_manager->tests_to_install_count();
     echo PHP_EOL;
     echo $this->tab . pts_strings::plural_handler($this->test_install_count, 'Test') . ' To Install' . PHP_EOL;
     $download_size = 0;
     $download_total = 0;
     $cache_total = 0;
     $cache_size = 0;
     $install_size = 0;
     foreach ($test_install_manager->get_test_run_requests() as $test_run_request) {
         $install_size += $test_run_request->test_profile->get_environment_size();
         foreach ($test_run_request->get_download_objects() as $test_file_download) {
             switch ($test_file_download->get_download_location_type()) {
                 case 'IN_DESTINATION_DIR':
                     // We don't really care about these files here since they are good to go
                     break;
                 case 'LOCAL_DOWNLOAD_CACHE':
                 case 'REMOTE_DOWNLOAD_CACHE':
                 case 'LOOKASIDE_DOWNLOAD_CACHE':
                     $cache_size += $test_file_download->get_filesize();
                     $cache_total++;
                     break;
                 default:
                     $download_size += $test_file_download->get_filesize();
                     $download_total++;
                     break;
             }
         }
     }
     if ($download_total > 0) {
         echo $this->tab . $this->tab . pts_strings::plural_handler($download_total, 'File') . ' To Download';
         if ($download_size > 0) {
             echo ' [' . self::bytes_to_download_size($download_size) . 'MB]';
         }
         echo PHP_EOL;
     }
     if ($cache_total > 0) {
         echo $this->tab . $this->tab . pts_strings::plural_handler($cache_total, 'File') . ' In Cache';
         if ($cache_size > 0) {
             echo ' [' . self::bytes_to_download_size($cache_size) . 'MB]';
         }
         echo PHP_EOL;
     }
     if ($install_size > 0) {
         echo $this->tab . $this->tab . ceil($install_size) . 'MB Of Disk Space Is Needed' . PHP_EOL;
     }
     echo PHP_EOL;
 }