<?php
    if (!defined('MAX_PATH')) { exit; }
    OA_GUI_getHtmlForDbLoader('Checking system parameters...');
?>

    <br />
    <table border='0' cellpadding='0' cellspacing='0' width='100%'>
    <tr>
        <td valign='top'>
            <img src='<?php echo $imgPath; ?>images/install-welcome.gif'></td><td width='100%' valign='top'>
            <br />
            <span class='tab-s'><?php echo $strSystemCheck; ?></span>
            <br />
            <img src='<?php echo $imgPath; ?>images/break-el.gif' width='100%' height='1' vspace='8'>
            <span class='install'><?php echo $strSystemCheckIntro; ?></span>
        </td>
    </tr>
    </table>
    <br />
    <form id="frmOpenads" name="frmOpenads" method="POST" action="install.php">
    <table border='0' width='100%' cellpadding='0' cellspacing='0'>
        <tr>
            <td height='25' colspan='4'><img src='<?php echo $imgPath; ?>images/icon-setup.gif' width='16' height='16' align='absmiddle'>&nbsp;<b>System Checks</b></td>
        </tr>
        <tr height='1'>
            <td bgcolor='#888888' width='30'><img src='images/break.gif' height='1' width='30'></td>
            <td bgcolor='#888888' width='250'><img src='images/break.gif' height='1' width='250'></td>
            <td bgcolor='#888888' width='100%'><img src='images/break.gif' height='1' width='1'></td>
            <td bgcolor='#888888' width='30'><img src='images/break.gif' height='1' width='30'></td>
        </tr>
        <tr>
            <td height='10' colspan='4'><img src='images/spacer.gif' width='30' height='1'></td>
        </tr>
        <tr>

        <?php
            $errorImage = "<img src='".$imgPath."images/icon-x.gif' width='10' height='9'>";
            $warnImage = "<img src='".$imgPath."images/icon-warning.gif' width='12' height='12'>";
            $passImage = "<img src='".$imgPath."images/icon-checkmark.gif' width='10' height='9'>";

            // Setup list of all timezones, calculate selected timezone
            require_once('../../lib/OA/Admin/Timezones.php');
            $aTimezone = OA_Admin_Timezones::getTimezone();

            $sysinfoarray = $aSysInfo['PHP'];

            // Remove date.timezone from the array, set the timezone as the detected TZ
            unset($sysinfoarray['actual']['date.timezone']);
            $sysinfoarray['actual']['timezone'] = $aTimezone['tz'];

            // If TZ was calculated, display a warning
            if ($aTimezone['calculated'])
            {
                if (version_compare($sysinfoarray['actual']['version'],'5.1', ">"))
                {
                    $docLink = "http://" . OX_PRODUCT_DOCSURL . "/install/timezone/php5/";
                }
                else
                {
                    $docLink = "http://" . OX_PRODUCT_DOCSURL . "/install/timezone/php4/";
                }
                $finalTimezoneDocs = str_replace(
                    '%DOCS%',
                    '<a href="' . $docLink . '" target="_blank">' . $strTimezoneDocumentation . '</a>',
                    $strTimezoneSeeDocs
                );

                $sysinfoarray['actual']['timezone'] .= ' ' . $warnImage;
                $sysinfoarray['warning']['tz'] = $strTimezoneGuessedValue . '.<br>' . $finalTimezoneDocs;
            }
            else
            {
                $sysinfoarray['actual']['timezone'] .= ' ' . $passImage;
            }

            $sysinfoarray['actual']['version'] = ($sysinfoarray['warning'][OA_ENV_ERROR_PHP_VERSION] ? $sysinfoarray['actual']['version'].' '.$warnImage : $sysinfoarray['actual']['version'].' '.$passImage );

            $sysinfoarray['actual']['memory_limit'] = ($sysinfoarray['actual']['memory_limit']!='' ? $sysinfoarray['actual']['memory_limit'] : 'Not Set');
            if(is_numeric($sysinfoarray['actual']['memory_limit'])) {
                // convert into MB
                $sysinfoarray['actual']['memory_limit'] = $sysinfoarray['actual']['memory_limit'] / 1048576;
                $sysinfoarray['actual']['memory_limit'] .= ' MB';
            }
            $sysinfoarray['actual']['memory_limit'] = ($sysinfoarray['error'][OA_ENV_ERROR_PHP_MEMORY] ? $sysinfoarray['actual']['memory_limit'].' '.$errorImage : $sysinfoarray['actual']['memory_limit'].' '.$passImage );

            $sysinfoarray['actual']['safe_mode'] = ($sysinfoarray['actual']['safe_mode']==0 ? 'OFF '.$passImage : 'ON '.$errorImage);
            $sysinfoarray['actual']['magic_quotes_runtime'] = ($sysinfoarray['actual']['magic_quotes_runtime']==0 ? 'OFF '.$passImage : 'ON '.$errorImage);
            $sysinfoarray['actual']['file_uploads'] = $sysinfoarray['actual']['file_uploads'] == 0 ? 'OFF ' . $errorImage : 'ON ' . $passImage;

            // Only warn if register_argc_argv is off
            if ($sysinfoarray['actual']['register_argc_argv'] == 0) {
                $sysinfoarray['actual']['register_argc_argv'] = 'OFF ' . $warnImage;
                $sysinfoarray['warning']['register_arc_argv'] = $strWarningRegisterArgcArv;
            } else {
                $sysinfoarray['actual']['register_argc_argv'] = 'ON ' . $passImage;
            }

            $sysinfoarray['actual']['pcre'] = ($sysinfoarray['actual']['pcre'] == false ? 'NOT LOADED ' . $errorImage : 'LOADED ' .$passImage);
            $sysinfoarray['actual']['xml']  = ($sysinfoarray['actual']['xml']  == false ? 'NOT LOADED ' . $errorImage : 'LOADED ' .$passImage);
            $sysinfoarray['actual']['zlib'] = ($sysinfoarray['actual']['zlib'] == false ? 'NOT LOADED ' . $errorImage : 'LOADED ' .$passImage);
            $halt = (($halt) || ($sysinfoarray['error']));

            $sysinfoheading = (!$sysinfoarray['error']? $passImage . ' PHP - no errors' : $errorImage . ' <span class="red">PHP - errors detected</span>');
            include MAX_PATH . '/www/admin/templates/install-sysinfosection.html';

            $sysinfoarray = $aSysInfo['PERMS'];
            foreach ($sysinfoarray['actual'] as $key => $val) {
                if ($val != 'OK') {
                    $sysinfoarray['actual'][$key] = $val.' '.$errorImage;
                } else {
                    $sysinfoarray['actual'][$key] = $val.' '.$passImage;
                }
            }

            $halt = (($halt) || ($sysinfoarray['error']));
            $sysinfoheading = (!$sysinfoarray['error']? $passImage . ' File Permissions - no errors' : $errorImage . ' <span class="red">File Permissions - errors detected</span>');
            include MAX_PATH . '/www/admin/templates/install-sysinfosection.html';
        ?>
        </tr>
        </table>
        <br /><br />
