<?php
#################################################################################
#                                                                            
    #
# Mosucker 3.0 PHP Notification Script. Copyright by Geeto (Geeto@flamenap.net) #
#            Translated to PHP from Zeloran's CGI Notfication Script         
    #
#                                                                            
    #
#################################################################################

$parameters = explode("&",getenv("QUERY_STRING"));
foreach ($parameters as $element) {
  list($name, $value) = explode("=",$element);
  $value = str_replace("+"," ",$value);
  $parameter[$name] = $value;
}

$time = explode(":", date("h:i"));

$filename = getenv("DOCUMENT_ROOT")."/mophp/online.txt";
$ip = getenv("REMOTE_ADDR");

if (!file_exists($filename))
{
   $handle = fopen ($filename, "w");
   fclose($handle);
}

$in = fopen ($filename, "r");
$lines = explode("\n",fread($in, filesize ($filename)));
fclose($in);

unset($lines[count($lines)-1]);
$counter = count($lines);
$same = -1;

for($var = 0;$var < $counter;$var++) {
  $information = explode("#", $lines[$var]);
  if($information[2] == $ip){
    $lines1[$var] = 
"$time[0]#$time[1]#$ip#$parameter[port]#$parameter[nick]#$parameter[country]#$parameter[visible]#$parameter[protected]#$parameter[about] 
[Last notify: $time[0]:$time[1]]";
    $same = 1;
  } else {
    $lines1[$var] = $lines[$var];
  }
}

if($same==-1){
  $lines1[count($lines)] = 
"$time[0]#$time[1]#$ip#$parameter[port]#$parameter[nick]#$parameter[country]#$parameter[visible]#$parameter[protected]#$parameter[about] 
[Last notify: $time[0]:$time[1]]";
}

$out = fopen ($filename, "w");
foreach ($lines1 as $element) {
  fwrite($out,$element."\n");
}
fclose($out);

echo "Sweet, Sweet Gwendoline...";
?>
