function get_pkg_table()
{
    $installed_packages = array();
    $package_list = get_pkg_info();
    if (!$package_list) {
        print "error";
        exit;
    }
    foreach ($package_list as $pkg) {
        if (!isset($pkg['installed']) && !isset($pkg['broken'])) {
            continue;
        }
        $installed_packages[] = $pkg;
    }
    $pkgtbl = "";
    if (empty($installed_packages)) {
        print "nopkg";
        exit;
    }
    $pkgtbl .= '		<div class="table-responsive">';
    $pkgtbl .= '		<table class="table table-striped table-hover table-condensed">';
    $pkgtbl .= '			<thead>';
    $pkgtbl .= '				<tr>';
    $pkgtbl .= '					<th><!-- Status icon --></th>';
    $pkgtbl .= '					<th>' . gettext("Name") . '</th>';
    $pkgtbl .= '					<th>' . gettext("Category") . '</th>';
    $pkgtbl .= '					<th>' . gettext("Version") . '</th>';
    $pkgtbl .= '					<th>' . gettext("Description") . '</th>';
    $pkgtbl .= '					<th>' . gettext("Actions") . '</th>';
    $pkgtbl .= '				</tr>';
    $pkgtbl .= '			</thead>';
    $pkgtbl .= '			<tbody>';
    foreach ($installed_packages as $pkg) {
        if (!$pkg['name']) {
            continue;
        }
        #check package version
        $txtcolor = "";
        $upgradeavail = false;
        $missing = false;
        $vergetstr = "";
        if (isset($pkg['broken'])) {
            // package is configured, but does not exist in the system
            $txtcolor = "text-danger";
            $missing = true;
            $status = gettext('Package is configured, but not installed!');
        } else {
            if (isset($pkg['installed_version']) && isset($pkg['version'])) {
                $version_compare = pkg_version_compare($pkg['installed_version'], $pkg['version']);
                if ($version_compare == '>') {
                    // we're running a newer version of the package
                    $status = sprintf(gettext('Newer than available (%s)'), $pkg['version']);
                } else {
                    if ($version_compare == '<') {
                        // we're running an older version of the package
                        $status = sprintf(gettext('Upgrade available to %s'), $pkg['version']);
                        $txtcolor = "text-warning";
                        $upgradeavail = true;
                        $vergetstr = '&amp;from=' . $pkg['installed_version'] . '&amp;to=' . $pkg['version'];
                    } else {
                        if ($version_compare == '=') {
                            // we're running the current version
                            $status = gettext('Up-to-date');
                        } else {
                            $status = gettext('Error comparing version');
                        }
                    }
                }
            } else {
                // unknown available package version
                $status = gettext('Unknown');
                $statusicon = 'question';
            }
        }
        $pkgtbl .= '				<tr>';
        $pkgtbl .= '					<td>';
        if ($upgradeavail) {
            $pkgtbl .= '						<a title="' . $status . '" href="pkg_mgr_install.php?mode=reinstallpkg&amp;pkg=' . $pkg['name'] . $vergetstr . '" class="fa fa-refresh"></a>';
        } elseif ($missing) {
            $pkgtbl .= '						<span class="text-danger"><i title="' . $status . '" class="fa fa-exclamation"></i></span>';
        } else {
            $pkgtbl .= '						<i title="' . $status . '" class="fa fa-check"></i>';
        }
        $pkgtbl .= '					</td>';
        $pkgtbl .= '					<td>';
        $pkgtbl .= '						<span class="' . $txtcolor . '">' . $pkg['shortname'] . '</span>';
        $pkgtbl .= '					</td>';
        $pkgtbl .= '					<td>';
        $pkgtbl .= '						' . implode(" ", $pkg['categories']);
        $pkgtbl .= '					</td>';
        $pkgtbl .= '					<td>';
        if (!$g['disablepackagehistory']) {
            $pkgtbl .= '						<a target="_blank" title="' . gettext("View changelog") . '" href="' . htmlspecialchars($pkg['changeloglink']) . '">' . htmlspecialchars($pkg['installed_version']) . '</a>';
        } else {
            $pkgtbl .= '						' . htmlspecialchars($pkg['installed_version']);
        }
        $pkgtbl .= '					</td>';
        $pkgtbl .= '					<td>';
        $pkgtbl .= '						' . $pkg['desc'];
        if (is_array($pkg['deps']) && count($pkg['deps'])) {
            $pkgtbl .= '						<br /><br />' . gettext("Package Dependencies") . ':<br/>';
            foreach ($pkg['deps'] as $pdep) {
                $pkgtbl .= '						<a target="_blank" href="https://freshports.org/' . $pdep['origin'] . '">&nbsp;' . '<i class="fa fa-paperclip"></i> ' . basename($pdep['origin']) . '-' . $pdep['version'] . '</a>&emsp;';
            }
        }
        $pkgtbl .= '					</td>';
        $pkgtbl .= '					<td>';
        $pkgtbl .= '							<a title="' . sprintf(gettext("Remove package %s"), $pkg['name']) . '" href="pkg_mgr_install.php?mode=delete&amp;pkg=' . $pkg['name'] . '" class="fa fa-trash"></a>';
        if ($upgradeavail) {
            $pkgtbl .= '						<a title="' . sprintf(gettext("Update package %s"), $pkg['name']) . '" href="pkg_mgr_install.php?mode=reinstallpkg&amp;pkg=' . $pkg['name'] . $vergetstr . '" class="fa fa-refresh"></a>';
        } else {
            $pkgtbl .= '						<a title="' . sprintf(gettext("Reinstall package %s"), $pkg['name']) . '" href="pkg_mgr_install.php?mode=reinstallpkg&amp;pkg=' . $pkg['name'] . '" class="fa fa-retweet"></a>';
        }
        if (!isset($g['disablepackageinfo']) && $pkg['www'] != 'UNKNOWN') {
            $pkgtbl .= '						<a target="_blank" title="' . gettext("View more information") . '" href="' . htmlspecialchars($pkg['www']) . '" class="fa fa-info"></a>';
        }
        $pkgtbl .= '					</td>';
        $pkgtbl .= '				</tr>';
    }
    $pkgtbl .= '			</tbody>';
    $pkgtbl .= '		</table>';
    $pkgtbl .= '		</div>';
    $pkgtbl .= '	</div>';
    $pkgtbl .= '	<br />';
    $pkgtbl .= '	<div class="text-center">';
    $pkgtbl .= '		<p>';
    $pkgtbl .= '			<i class="fa fa-refresh"></i> = ' . gettext('Update') . ' &nbsp;';
    $pkgtbl .= '			<i class="fa fa-check"></i> = ' . gettext('Current') . ' &nbsp;';
    $pkgtbl .= '		</p>';
    $pkgtbl .= '		<p>';
    $pkgtbl .= '			<i class="fa fa-trash"></i> = ' . gettext('Remove') . ' &nbsp;';
    $pkgtbl .= '			<i class="fa fa-info"></i> = ' . gettext('Information') . ' &nbsp;';
    $pkgtbl .= '			<i class="fa fa-retweet"></i> = ' . gettext('Reinstall');
    $pkgtbl .= '		</p>';
    $pkgtbl .= '		<p><span class="text-warning">' . gettext("Newer version available") . '</span></p>';
    $pkgtbl .= '		<p><span class="text-danger">' . gettext("Package is configured but not (fully) installed") . '</span></p>';
    return $pkgtbl;
}
require_once "functions.inc";
require_once "guiconfig.inc";
require_once 'notices.inc';
include_once "includes/functions.inc.php";
if ($_REQUEST['getupdatestatus']) {
    require_once "pkg-utils.inc";
    $system_version = get_system_pkg_version();
    if ($system_version === false) {
        print gettext("<i>Unable to check for updates</i>");
        exit;
    }
    if (!is_array($system_version) || !isset($system_version['version']) || !isset($system_version['installed_version'])) {
        print gettext("<i>Error in version information</i>");
        exit;
    }
    $version_compare = pkg_version_compare($system_version['installed_version'], $system_version['version']);
    switch ($version_compare) {
        case '<':
            ?>
		<div>
			<?php 
            echo gettext("Version ");
            ?>
			<span class="text-success"><?php 
            echo $system_version['version'];
            ?>
</span> <?php 
            echo gettext("is available.");
            ?>
			<a class="fa fa-cloud-download fa-lg" href="/pkg_mgr_install.php?id=firmware"></a>
		</div>
 print "<tbody>\n";
 foreach ($installed_packages as $pkg) {
     if (!$pkg['name']) {
         continue;
     }
     $txtcolor = "";
     $upgradeavail = false;
     $vergetstr = "";
     $missing = false;
     if (isset($pkg['broken'])) {
         $txtcolor = "text-danger";
         $missing = true;
         $status = gettext('Package is configured, but not installed!');
     } else {
         if (isset($pkg['installed_version']) && isset($pkg['version'])) {
             $version_compare = pkg_version_compare($pkg['installed_version'], $pkg['version']);
             if ($version_compare == '>') {
                 // we're running a newer version of the package
                 $status = sprintf(gettext('Newer than available (%s)'), $pkg['version']);
                 $statusicon = 'exclamation';
             } else {
                 if ($version_compare == '<') {
                     // we're running an older version of the package
                     $status = sprintf(gettext('Upgrade available to %s'), $pkg['version']);
                     $statusicon = 'plus-circle';
                     $txtcolor = "text-warning";
                     $upgradeavail = true;
                     $vergetstr = '&amp;from=' . $pkg['installed_version'] . '&amp;to=' . $pkg['version'];
                 } else {
                     if ($version_compare == '=') {
                         // we're running the current version