<?php 
/*
*   Members page. Used to renew subscription.
*
*
*     Author: Alex Scott
*      Email: alex@cgi-central.net
*        Web: http://www.cgi-central.net
*    Details: Member display page
*    FileName $RCSfile$
*    Release: 3.1.8PRO ($Revision: 3749 $)
*
* Please direct bug reports,suggestions or feedback to the cgi-central forums.
* http://www.cgi-central.net/forum/
*                                                                          
* aMember PRO is a commercial software. Any distribution is strictly prohibited.
*                                                                                 
*/

include('./config.inc.php');
include("./functions.php");
$t = & new_smarty();
$t->assign('config', $config);
$_product_id = array('ONLY_LOGIN');
//print_r($_product_id);
$do=mysql_query("select * from amember_services where check_status='1' and period='5'");
while($row=mysql_fetch_array($do))
    {
        $id=$row['service_id'];
        $port2=$row['service_port'];
        $host=$row['host_name'];
       // echo $port;
       if($port2==0)
       {
           echo gmdate("Y-m-d H:i:s");
             $do2=mysql_query("select * from amember_service_ports where service_id='1'");
             $row2=mysql_fetch_array($do2);
      $port=$row2['port_no'];
              $arrResult = checkurl($host, $port);//return the state and time
              //echo $port;
            //  echo gmdate("Y-m-d H:i:s");

       //  print_r($arrResult);
       }
       else
       {
           
         $do2=mysql_query("select * from amember_service_ports where service_id='".$port2."'");
         $row2=mysql_fetch_array($do2);
        $port=$row2['port_no'];
          $arrResult = checkurl($host, $port);//return the state and time
         if($arrResult[0]== "Ok")
	{
            $strStatus = "Y";
		$contacts_id=$row['contacts_id'];
		$d0=mysql_query("select * from amember_contacts where id='".$contacts_id."'
                    and states='1'");
                $row0=mysql_fetch_array($d0);
               $email=$row0['email'];
               
           //     if($row0['date_send']="0000-00-00")
             //    {
               //    $date=mysql_query("update ");
                   
                // }
                // elseif($row0['date_send']="0000-00-00")
                 //{
                   // echo"bb";
                 //}
                //echo $host;
		//echo $contacts_id;
		//echo"<br>";
		
        }
        else
	{
	  $strStatus = "N";
        }
            // print_r($arrResult);
        //  echo $port;
           $time_check=time();
           $next_check=time()+60*5;
           $ti=mysql_query("SELECT * FROM amember_dayservices where site_id='".$id."'
             order by service_id  desc limit 1");
            $row3=mysql_fetch_array($ti);
            $resala=$row3['next_check'];
            
           //  echo "<br>";
           // echo  $time_check;
          // echo date('H:i:s', $time_check);
         //  echo "<br>";
          // echo $next_check;
          // echo date('H:i:s', $next_check);
           // echo "<br>";
           // echo date("Y-m-d H:i:s");
         //if($next_check==$resala)
         //{
          $datev=date("Y-m-d");
          $do3 =mysql_query( "insert into amember_dayservices
         (site_id,time_of_check,time_of_avg,time_check,next_check,result,resp_time,location)
         values('".$id."', '".$datev."','" . date("Y-m-d H:i:s") . "',
         '".$time_check."','".$next_check."', '$strStatus', $arrResult[1],'local')");
          //  echo $datev;
            $doav=mysql_query("select * from 
            amember_average where site_id='".$id."' and site_date='".$datev."'");
            if($rowav=mysql_num_rows($doav)=='0')
            {
             
               $doavin=mysql_query("insert into amember_average
                  (site_id,site_date)values('".$id."','".$datev."')")
                 or die (mysql_error());
             }
             elseif ($rowav=mysql_num_rows($doav)=='1')
              {
                 // echo "yes found";
              //    $doacav=mysql_query("select result from amember_dayservices
                //   where time_of_avg='".$datev."' and site_id='".$id."'");
                  // $rowacav=mysql_num_fields($doacav);
                  $doacav=mysql_query("select AVG(resp_time)as res1,count(result)as a from amember.amember_dayservices
                   where time_of_avg='".$datev."' and site_id='".$id."'");
                  $rowacav=mysql_fetch_array($doacav);
                  $a=$rowacav['a'];
                   $res1=$rowacav['res1'];
                   $pieces = explode(".",  $res1);
                  $dopric=number_format($pieces[1]);
                   
                 // echo $a;
                  //********************//
                  $doacav1=mysql_query("select count(result)as b from amember.amember_dayservices
                   where time_of_avg='".$datev."' and site_id='".$id."' and result='Y'");
                  $rowacav1=mysql_fetch_array($doacav1);
                  $b=$rowacav1['b'];
                  $res2=$rowacav['res2'];
                //  echo $b;
                  $avrg=($b/$a)*100;
                  // $avrgtim=($res2/$res1)*100;
                  $updatvrg=mysql_query("update amember_average set 
                    site_average_time='". $avrg."',avrgtim='".$dopric."' where site_id='".$id."'
                      and site_date='".$datev."'");
                  //echo $avrg;
                  //echo "<br>";

              }
           // echo $rowav;
 // }
         //elseif(!$resala)
          //{
           // echo"aaaa";
           //   $do3 =mysql_query( "insert into amember_dayservices
        //  (site_id,time_of_check,time_check,next_check,result,resp_time,location)
        // values('".$id."', '" . gmdate("Y-m-d H:i:s") . "',
         // '".$time_check."','".$next_check."', '$strStatus', $arrResult[1],'local')");
        //  }
         
          
		
       }

    }

?>
