<?php
defined('IN_YA') OR die ('Access denied reactive MAXIMUS directly...');
defined('MAXIMUS') OR header("Location: index.php");

    $check_num = trim($check_num);
    $time = $GLOBALS['db']->XMFnum($time);
    $result = $GLOBALS['db']->sql_query("SELECT * FROM `".TABLE_USERS_REDO."` WHERE `check_num`='$check_num' AND `time`='$time'");
    if ($GLOBALS['db']->sql_numrows($result) == 1) {
        $row = $GLOBALS['db']->sql_fetchrow($result);
        $uid = stripslashes($row['user_id']);
        $user_email = stripslashes($row['user_email']);
        $user_email = ya_fixtext($user_email);
        $last_ip = get_ip();
        if (strpos($last_ip, ', ')) {
          $last_ips = explode(', ', $last_ip);
          if($last_ips[0] != 'unknown' AND $last_ips[0] != 'none' AND $last_ips[0] != '127.0.0.1' AND $last_ips[0] != '') {
            $last_ip = $last_ips[0];
          } else {
            $last_ip = $last_ips[1];
          }
        }
        $GLOBALS['db']->sql_query("LOCK TABLES `".TABLE_USERS."` WRITE");
        $GLOBALS['db']->sql_query("UPDATE `".TABLE_USERS."` SET `user_email`='$user_email', `user_level`='1', `user_active`='1' WHERE `user_id`='$uid'");
        $GLOBALS['db']->sql_query("UNLOCK TABLES");
        $GLOBALS['db']->sql_query("DELETE FROM `".TABLE_USERS_REDO."` WHERE `check_num`='$check_num' AND `time`='$time'");
        $GLOBALS['db']->sql_query("OPTIMIZE TABLE `".TABLE_USERS_REDO."`");
        incoh();
        title(""._REACTIVATIONYES."");
        Max_OpenTable();
            echo "<center>"._ACCTREACTIVATED."</center><br />";
        Max_CloseTable();
        incof();
        die();
    } else {
        incoh();
        title(""._REACTIVATIONERROR."");
        Max_OpenTable();
        echo "<center>"._ACTERROR."</center>";
        Max_CloseTable();
        incof();
        die();
    }