<? 


function dateSub($date_c,$format='-',$to_sub=0)
{
	$date_parts_c=explode($format,$date_c);
	$mon_c=$date_parts_c[1];
	$day_c=$date_parts_c[2];
	$yr_c=$date_parts_c[0];
	$date_c_jd=GregorianToJD($mon_c,$day_c,$yr_c);
	$date_o_jd=$date_c_jd+$to_sub;
	$date_o=JDToGregorian($date_o_jd);
	return $date_o;
}
function confirm_reg($c_code)
{
	$sql_creg="update evendi_users set status='1' where ccode='$c_code'";
	mysql_query($sql_creg);
	$x=mysql_affected_rows();
	if($x>0)
	{
		return;
	}
	else
	{
		echo _INFO_NOT_AVAILABLE_;
		exit();
	}
}

function subcat_display($cat_id)
{
	$sql_scat="select * from evendi_category where top=$cat_id";
	$res_scat=mysql_query($sql_scat);
	while($row_scat=mysql_fetch_object($res_scat))
	{
?>
	<a href="category.php?top=<?=$row_scat->id; ?>"><?=$row_scat->category; ?></a>,
<?
	}
	echo "...";
}

/*function getinfo()
{
	$sql="select * from evendi_users where uname='".$_SESSION['uname']."' and password='".$_SESSION['upwd']."'";
	$res=mysql_query($sql);
	$row=mysql_fetch_object($res);
	return($row);
}*/

function getnewmembers($nmem)
{
	$sql="select * from evendi_users where uname!='".$_SESSION['uname']."' order by id desc limit 5";
	$res=mysql_query($sql);
	return $res;
}

/*function outbox($su_id,$ru_id,$sub,$msg)
{
	$today = date("Y-m-d g:i:s A");
	$insert="insert into inbox values('','$su_id','$ru_id','$sub','$today','$msg','0')";
	$x=@mysql_query($insert);
	return $x;
}*/
function DatePurifier($dtti)
	{
		list($dt,$ti) = split(" ",$dtti);

		$monArray=array(
			"01"=>"Jan","02"=>"Feb","03"=>"Mar","04"=>"Apr","05"=>"May","06"=>"Jun","07"=>"Jul","08"=>"Aug","09"=>"Sep","10"=>"Oct","11"=>"Nov","12"=>"Dec"
		);

		list($y,$m,$d)=split('-',$dt);

		$formattedDate="$d ".$monArray[$m].", $y $ti" ; 
		//$formattedDate="$m/$d/$y";
		return $formattedDate;
	}
function getUser($uname)
{
	$sql="select * from user where uname = '$uname'";
	$res=mysql_query($sql);
	$row=mysql_fetch_object($res);
	return $row;
}

function getUserById($uid)
{
	$sql="select * from user where id=$uid";
	$res=mysql_query($sql);
	$row=mysql_fetch_object($res);
	return $row;
}

/*function getCatUsers($cat)
{
	$query="select * from evendi_users where cat_id='$cat'";
	$result=mysql_query(dopaging($query,20));
	return $result;
}*/

function checkpayment($uid)
	{
		$sql="select id from transactions where plan_name='$uid'";
		$q=mysql_query($sql) or die(mysql_error());
		$r=mysql_fetch_object($q);
		$count=mysql_num_rows($q);
		if($r->id==0)
		{
			header("location:payment.php");
		}
	}

function getAdminDetails()
{
	if($_SESSION['aname']=='' || $_SESSION['apwd']=='')
	{
		redirect("index.php","");
	}
	else
	{
		$sql="select * from evendi_admin";
		$res=mysql_query($sql);
		$row=mysql_fetch_object($res);
		return $row;
	}
}

function profilevisited($visited,$visitor)
{
	if(!isset($_SESSION['profilevisits']))
		$_SESSION['profilevisits']='';
	if(strstr($_SESSION['profilevisits'],"_".$visited."_"))
		return 1;
	else
		$_SESSION['profilevisits'].="_".$visited."_";
	$sql="select * from evendi_profile_nomail where uid='$visited'";
	$res=mysql_query($sql);
	if(mysql_num_rows($res)==0)
	{
		require_once("vars.inc.php");
		list($vdun,$vdcmail)=mysql_fetch_array(mysql_query("select uname,com_email from evendi_users where id='$visited'"));
		list($vrun,$vrcname,$vrid)=mysql_fetch_array(mysql_query("select uname,com_name,id from evendi_users where id='$visitor'"));
		$to=$vdcmail;
		$utype=getUserCategory($vrid);
		$utype=ucwords($utype);
		$sub="Your profile visited!";
		$hdr="From:e-vendi@online.de\nContent-Type: text/html; charset=iso-8859-1";
		$body  = "<HTML><head>
<base href="<?=_BASEURL_?>/" /><TITLE>Your Profile @ Evendi.com has been visited!</TITLE></HEAD><body>
			Dear ".ucwords($vdun)."!<br>
			<P ALIGN='JUSTIFY'>We want to inform you that your profile at our website "._BASEURL_." has been visited by ".ucwords($vrcname).".<br>
			The User Belongs to $utype Category!<br>
			If you want to visit his/her profile, please follow the link given below<br>
		<center><a href='"._BASEURL_."/personaldtls.php?id=$vrid'>"._BASEURL_."/personaldtls.php?id=$vrid</a></center>
			<br>Thank You!<br>Evendi Team!</P></BODY></HTML>";
		@mail($to,$sub,$body,$hdr);
	}
}

function getUserCategory($uid)
{
		$userdetails=getUserById($uid);
		$sql_cat="select category from evendi_category where id=".$userdetails->cat_id;
		$res_cat=mysql_query($sql_cat);
		$row_cat=mysql_fetch_object($res_cat);
		return $row_cat->category;
}

function mySellLeads($uid)
{
	$sql="select count(id) as np from evendi_products where uid='$uid' and leadtype='1'";
	$res=mysql_query($sql);
	$row=mysql_fetch_object($res);
	return $row->np;
}

function myBuyLeads($uid)
{
	$sql="select count(id) as np from evendi_products where uid='$uid' and leadtype='0'";
	$res=mysql_query($sql);
	$row=mysql_fetch_object($res);
	return $row->np;	
}

function myContacts($uid)
{
	$sql="select count(mem_id) as mem_id from evendi_toconfirm where user_id='$uid' and confirm=1";
	$res=mysql_query($sql);
	$row=mysql_fetch_object($res);
	return $row->mem_id;
}

?>