<?php

//启用某个序列号
if( isset($_GET['key']) )
{ 
  $licensekey = $_GET['key'];    
}
else
{	
  print_r("-1");
  exit;
}
if( isset($_GET['ctrl']) )
{ 
  $ctrl = $_GET['ctrl'];    
}
else
{	
  print_r("-1");
  exit;
}

if( isset($_GET['mail']) )
{ 
  $email = $_GET['mail'];    
}
else
{
  //print_r("-1");
  //exit;
}

if (strcmp($ctrl,'enable')==0) 
{
  //print_r("启用序列号!");
  $Expired=0;
}

if (strcmp($ctrl,'disable')==0) 
{
 // print_r("禁用序列号!");
  $Expired=1;
}


//连接MySQL
$conn = @mysql_connect("localhost", "gili0512", "nIJ9qatVBLKS");

if($conn == FALSE)
{	
  print_r("-1");
  exit;
}

//选择数据库
mysql_select_db("gili0512_livecheck");



//删除指定的key，前提是这个key的邮箱至少一个要是对的。
//$result = @mysql_query("SELECT * FROM gsemailinfo where Email='$email' and RegKey='$licensekey'");

$result = @mysql_query("SELECT * FROM gsemailinfo where RegKey='$licensekey'");

if(mysql_num_rows($result) > 0)
{
  mysql_free_result($result);
  if (strcmp($ctrl,'delete')==0) 
  {
    //print_r("删除序列号!");

   
    $result = @mysql_query("DELETE FROM gsemailinfo where RegKey='$licensekey'");
    //mysql_free_result($result);

    $result = @mysql_query("DELETE FROM gslicenseinfo where RegKey='$licensekey'");
    //mysql_free_result($result);

    mysql_close();
    print_r("0");
    exit; 
  }

}
else
{
 mysql_free_result($result);
 print_r("-1");
}



//执行SQL
$result = @mysql_query("SELECT * FROM gslicenseinfo where RegKey='$licensekey'");

if(mysql_num_rows($result) > 0)
{
  While($row = mysql_fetch_array($result))
  {
     // print_r($row["id"].",".$row["RegCode"].",".$row["Activations"].",".$row["IsExpired"]);
     //print_r("<br />");

     $RegCode=$row["RegKey"];
     //print_r($Activations);
     
     $result = mysql_query("UPDATE gslicenseinfo SET IsExpired = '$Expired' WHERE RegKey = '$RegCode'");

     if(mysql_affected_rows() > 0)
     {
       print_r("1");
     } 
  }
}
else
{
  print_r("-1");
}

//释放结果集
mysql_free_result($result);

//关闭连接
mysql_close();


?> 
