<?php

// $Revision: 3830 $
/************************************************************************/
/* Openads 2.0                                                          */
/* ===========                                                          */
/*                                                                      */
/* Copyright (c) 2000-2007 by the Openads developers                    */
/* For more information visit: http://www.openads.org                   */
/*                                                                      */
/* This program is free software. You can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 2 of the License.       */
/************************************************************************/
// Prevent full path disclosure
if (!defined('phpAds_path')) {
    die;
}
if ($phpAds_config['updates_enabled']) {
    include phpAds_path . '/libraries/lib-openadssync.inc.php';
    $res = phpAds_checkForUpdates(0, true);
    if ($res[0] != 0 && $res[0] != 800) {
        phpAds_userlogAdd(phpAds_actionOpenadsSync, "Openads Sync error ({$res['0']}): {$res['1']}");
    }
}
if (phpAds_isUser(phpAds_Admin)) {
    // Check accordingly to user preferences
    switch ($phpAds_config['updates_frequency']) {
        case -1:
            $update_check = false;
            break;
        case 0:
            $update_check = true;
            break;
        default:
            $update_check = $phpAds_config['updates_timestamp'] + $phpAds_config['updates_frequency'] * 60 * 60 * 24 <= time();
            break;
    }
    if ($update_check) {
        include 'lib-updates.inc.php';
        $update_check = phpAds_checkForUpdates($phpAds_config['updates_last_seen']);
        if ($update_check[0]) {
            $update_check = false;
        }
    }
    phpAds_SessionDataRegister('update_check', $update_check);
    phpAds_SessionDataStore();
    // Add Product Update redirector
    if ($update_check) {
        Header("Content-Type: application/x-javascript");
        if ($Session['update_check'][1]['security_fix']) {
            echo "\t\t\talert('" . $strUpdateAlertSecurity . "');\n";
        } else {
            echo "\t\t\tif (confirm('" . $strUpdateAlert . "'))\n\t";
        }
        echo "\t\tdocument.location.replace('maintenance-updates.php');\n";
if ($row = phpAds_dbFetchArray($res)) {
    $current .= '&nbsp;' . $row['version'];
}
$current .= '.';
if (!isset($Session['maint_update'])) {
    if (function_exists('xml_parser_create')) {
        // Show wait please text with rotating logo
        echo "<br>";
        echo "<table border='0' cellspacing='1' cellpadding='2'><tr><td>";
        echo "<img src='images/install-busy.gif' width='16' height='16'>";
        echo "</td><td class='install'>" . $strSearchingUpdates . "</td></tr></table>";
        phpAds_PageFooter();
        // Send the output to the browser
        flush();
        // Get updates info and store them into a session var
        $res = phpAds_checkForUpdates();
        phpAds_SessionDataRegister('maint_update', $res);
        phpAds_SessionDataStore();
        echo "<script language='JavaScript'>\n";
        echo "<!--\n";
        echo "document.location.replace('maintenance-updates.php');\n";
        echo "//-->\n";
        echo "</script>\n";
        exit;
    } else {
        echo "<br>" . $strNotAbleToCheck . "<br><br>";
        phpAds_ShowBreak();
        echo $current;
        echo "<br><br>" . $strForUpdatesLookOnWebsite . "<br><br>";
        echo "<b><img src='images/caret-r.gif'>&nbsp;<a href='http://" . $phpAds_producturl . "' target='_blank'>" . $strClickToVisitWebsite . "</a></b>";
    }