<?
include("includes/site_info.php");
include_once __INCLUDE_CLASS_PATH."/class.ItemManager.php";
$option_manager = new OptionManager();
$approved=$option_manager->GetValue('authorisecomment');
if(!isset($_REQUEST['submitcomment'])){
include(__INCLUDE_CLASS_PATH.'/class.StaticProfile.php');
}
$my_friends=$option_manager->GetValue('my_friends');
$my_articles=$option_manager->GetValue('my_articles');
$my_blogs=$option_manager->GetValue('my_blogs');
$my_essays=$option_manager->GetValue('essay_enable');
$pathh = $skin->Path;

include('languages/english.php');
include('functions.php');
$db = & db::getInstance();


 if(isset($_REQUEST['submitcomment'])){
include(__INCLUDE_CLASS_PATH.'/class.StaticProfile.php');



 $submitcomment = $_REQUEST['submitcomment']; 
if($submitcomment) { 
    
        if(get_magic_quotes_gpc()) { 
            $submitcomment = $_REQUEST['submitcomment']; 
        }else{ 
            $submitcomment = addslashes($_REQUEST['submitcomment']); 
        } 
	
       // $submitcomment;
$query="Insert into profile_comment(mem_id, com_memid, comment, com_approved, com_time) VALUES('".form_get('userid')."','".form_get('commentid')."','$submitcomment','$approved',now())";
$comment_prof = mysql_query($query) or die(mysql_error());
if($comment_prof){
echo COMMENT_APPROVAL;
}


   }

}






 if(isset($_REQUEST['do'])){
 $do = $_REQUEST['do']; 
if($do) { 
    
        if(get_magic_quotes_gpc()) { 
            $username = $_REQUEST['do']; 
        }else{ 
            $username = addslashes($_REQUEST['do']); 
        } 
        $count = mysql_num_rows(mysql_query("SELECT * FROM `members` WHERE `mem_username`='".$username."'")); 
       
        if($count > 0) { 
            echo USERNAME_EXIST; 
        }
		else if(strlen($do)<5){
			echo "Username must be 5 character long!";
		}
		else{ ?>
            <font color='Green'><? echo USERNAME_AVAILABLE; ?></font> 
        <? 
        } 
      } 
   else{ 
        echo 'Error, Can\'t be blank!'; 
   }

}
###################

if(isset($_REQUEST['email'])){
 $email = $_REQUEST['email']; 
if($email) { 
    
        if(get_magic_quotes_gpc()) { 
            $email = $_REQUEST['email']; 
        }else{ 
            $email = addslashes($_REQUEST['email']); 
        } 
        $count = mysql_num_rows(mysql_query("SELECT * FROM `members` WHERE `mem_email`='".$email."'")); 
       
        if($count > 0) { 
            echo EMAIL_EXIST; 
        }
		else if (empty( $email ) ||!ereg( "^[-a-zA-Z0-9_\\.]+\\@([0-9A-Za-z][0-9A-Za-z-]+\\.)+[A-Za-z]{2,5}\$", $email)){
            echo "Invalid Email"; 
		}
				else if(strlen($email)<5){
			echo "Email must be at least 5 character long!";
		} else{ 
            echo "<font color='Green'>This Email address is available</font>"; 
         } 
      } 
   else{ 
        echo 'Error, Can\'t be blank!'; 
   }

}



#######################


if(isset($_REQUEST['me']))
{
$username = $_REQUEST['me']; 
if($username) 
{ 
     
        include_once __INCLUDE_CLASS_PATH."/class.Audio.php";
		$audio = new Audio(); 
		$aAudios = $audio->GetListByMember($username);
		$resultaud = count($aAudios);
		if($resultaud>0)
		{
			 $i=0;
			 foreach ($aAudios as $Audios_row)
			 {
				if(($i%4)==0)
					{
					print "<br style='clear:both'>";
					}
			print "<table cellspacing='10' border='0' width='160px' align='left'><tr><td>&nbsp;</td></tr><tr><td align=center class=normal><div align=center>
	<input type=image src=$SKIN_IMAGE_PATH/audio_latest.jpg border=0  value=$Audios_row->aud_id onClick='useraud(this.value);' name='My Audio' width='100'/>
	<div align='center'>$Audios_row->title</div>
	</td></tr></table></div>";
		 $i++;
		   }
		print "<br style='clear:both'>";
	  }
    else 
	{
	?><div align='left' class='normal' style='font-weight:100; padding:15px'><?=AUDIO_NOT_UPDATED?></div>
<?	}
}
}

if(isset($_REQUEST['comment'])){
 $comment = $_REQUEST['comment']; 
if($comment) { 
    
        if(get_magic_quotes_gpc()) { 
            $comment = $_REQUEST['comment']; 
        }else{ 
            $comment = addslashes($_REQUEST['comment']); 
        } 
 $count1 = mysql_query("SELECT * FROM `adverts` WHERE `adv_userid`='".$comment."'"); 
     
        $adv=mysql_fetch_object($count1);
	if($adv->adv_comment!=''){?>
		<div align='left' class='normal' style='font-weight:100; padding:15px'><?=stripslashes($adv->adv_comment)?></div> 
	<?	}
	else
	{?>
	<div align='left' class='normal' style='font-weight:100; padding:15px'><?=COMMENT_NOT_UPDATED?></div>
	<? }	
}
}

if(isset($_REQUEST['video']))
{
	 $video = $_REQUEST['video'];
	if($video) 
	{ 
		$query=mysql_query("SELECT * FROM youtube WHERE you_userid ='$video'");
		$count=mysql_num_rows($query);
		if($count>0)
		{
			 $i=0;
			 while($result=mysql_fetch_object($query))
			 {
				if(($i%4)==0)
					{
					print "<table><tr><td>&nbsp;</td></tr>
					<tr>";
					} 
				 print "<td width=180px align=left class=normal><div align=left>
				<input type=image src=$SKIN_IMAGE_PATH/you.png border=0   value=$result->you_id onClick='uservideo(this.value);' name='My Youtube' width='100'/></td>";
			$i++;
			}
			print "</tr></table>";
	   }
else{?>
		<div align='left' class='normal' style='font-weight:100; padding:15px'><?=VIDEO_NOT_UPDATED?></div>
<? }
	}
}

##########################################



##########################################

 if(isset($_REQUEST['gallery'])){
include_once __INCLUDE_CLASS_PATH."/class.Gallery.php";
	include_once __INCLUDE_CLASS_PATH."/class.GalleryItem.php";
  
 $gallery1 = $_REQUEST['gallery']; 

    
        if(get_magic_quotes_gpc()) { 
            $gallery1 = $_REQUEST['gallery']; 
        }else{ 
            $gallery1 = addslashes($_REQUEST['gallery']); 
        }  
 

$gallery = new Gallery();

$aGallery = $gallery->GetListByMember($gallery1);

print_r($aGallery);
?>

	<script type="text/javascript">

/***********************************************
* Scrollable Menu Links- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* Visit http://www.dynamicDrive.com for hundreds of DHTML scripts
* This notice must stay intact for legal use
***********************************************/
<!--
//configure path for left and right arrows
var goleftimage='pointer2.gif'
var gorightimage='pointer.gif'
//configure menu width (in px):
var menuwidth=300
//configure menu height (in px):
var menuheight=100
//Specify scroll buttons directions ("normal" or "reverse"):
var scrolldir="normal"
//configure scroll speed (1-10), where larger is faster
var scrollspeed=6
//specify menu content
//var menucontents='<nobr><a href="http://www.dynamicdrive.com">Dynamic Drive</a> | <a href="http://www.javascriptkit.com">JavaScript Kit</a> | <a href="http://www.codingforums.com">CodingForums.com</a> | <a href="http://www.builder.com">Builder.com</a> | <a href="http://freewarejava.com">Freewarejava.com</a></nobr>'
var menucontents='<nobr><? foreach ($aGallery as $gallery_row){

$aItems = $gallery->GetItemList($gallery_row->Gallery_ID);
print_r($aItems);
$indx=0;
	foreach ($aItems as $item_row){
	$item = new GalleryItem();

    $item->Init($item_row);
    $indx++;
//    dump($item);

	if ($item->Type == 'Image') {
       // $src = $item->File->getInfo('small');
       $src_full = $item->File->getInfo();
echo $link= "includes$src_full->Path";
     
	} ?><img border="1" width="100" height="100" src="<?=$link?>">&nbsp;<? }}?></nobr>'

////NO NEED TO EDIT BELOW THIS LINE////////////

var iedom=document.all||document.getElementById
var leftdircode='onMouseover="moveleft()" onMouseout="clearTimeout(lefttime)"'
var rightdircode='onMouseover="moveright()" onMouseout="clearTimeout(righttime)"'
if (scrolldir=="reverse"){
var tempswap=leftdircode
leftdircode=rightdircode
rightdircode=tempswap
}
if (iedom)
document.write('<span id="temp" style="visibility:hidden;position:absolute;top:-100;left:-5000">'+menucontents+'</span>')
var actualwidth=''

var cross_scroll, ns_scroll
var loadedyes=0
function fillup(){
if (iedom){
cross_scroll=document.getElementById? document.getElementById("test2") : document.all.test2
cross_scroll.innerHTML=menucontents
actualwidth=document.all? cross_scroll.offsetWidth : document.getElementById("temp").offsetWidth
}
else if (document.layers){
ns_scroll=document.ns_scrollmenu.document.ns_scrollmenu2
ns_scroll.document.write(menucontents)
ns_scroll.document.close()
actualwidth=ns_scroll.document.width
}
loadedyes=1
}
window.onload=fillup

function moveleft(){
if (loadedyes){
if (iedom&&parseInt(cross_scroll.style.left)>(menuwidth-actualwidth)){
cross_scroll.style.left=parseInt(cross_scroll.style.left)-scrollspeed+"px"
}
else if (document.layers&&ns_scroll.left>(menuwidth-actualwidth))
ns_scroll.left-=scrollspeed
}
lefttime=setTimeout("moveleft()",50)
}

function moveright(){
if (loadedyes){
if (iedom&&parseInt(cross_scroll.style.left)<0)
cross_scroll.style.left=parseInt(cross_scroll.style.left)+scrollspeed+"px"
else if (document.layers&&ns_scroll.left<0)
ns_scroll.left+=scrollspeed
}
righttime=setTimeout("moveright()",50)
}


if (iedom||document.layers){
with (document){
write('<table border="0" cellspacing="0" cellpadding="2">')
write('<td valign="middle"><a href="#" '+leftdircode+'><img src="'+goleftimage+'"border=0></a> </td>')
write('<td width="'+menuwidth+'px" valign="top">')
if (iedom){
write('<div style="position:relative;width:'+menuwidth+'px;height:'+menuheight+'px;overflow:hidden;">')
write('<div id="test2" style="position:absolute;left:0;top:0">')
write('</div></div>')
}
else if (document.layers){
write('<ilayer width='+menuwidth+' height='+menuheight+' name="ns_scrollmenu">')
write('<layer name="ns_scrollmenu2" left=0 top=0></layer></ilayer>')
}
write('</td>')
write('<td valign="middle"> <a href="#" '+rightdircode+'>')
write('<img src="'+gorightimage+'"border=0></a>')
write('</td></table>')
}
}
-->
</script>
<? }
###################################

#Profile View Code

###################################



if(isset($_REQUEST['profile'])){
 $profile = $_REQUEST['profile']; 
if($profile) { 
    
        if(get_magic_quotes_gpc()) { 
            $profile = $_REQUEST['profile']; 
        }else{ 
            $profile = addslashes($_REQUEST['profile']); 
        } 




 $result=mysql_query("



    SELECT



        *,



        (YEAR(CURDATE())-YEAR(adv_dob)) - (RIGHT(CURDATE(),5) < RIGHT(adv_dob,5)) AS age,



        mem_lastvisit



    FROM adverts



    LEFT JOIN members ON (adv_userid=mem_userid)



    LEFT JOIN geo_country ON (adv_countryid = gcn_countryid)



    LEFT JOIN geo_city ON (adv_cityid = gct_cityid)



    LEFT JOIN geo_state ON (adv_stateid = gst_stateid)



    WHERE adv_userid = $profile"



    ,$link);
	
$sql_array=mysql_fetch_object($result);	
$cm = $sql_array->adv_height;
                 if (is_numeric($cm)) {
                    $in_inches = round($cm/2.54);
                    $in_feets = floor($cm/30.48);
                    if ($in_inches-$in_feets*12 == 12) $in_feets++;
                    $cur_i = $in_feets."'".($in_inches-$in_feets*12)."&quot;";
                    $height = $cur_i." (".$cm.ADVERTISE_CM.")";
                } else $height = PRGAMENDAD_NOT_STATED;
	?>
	            <table width="660px" border="0" cellpadding="4" cellspacing="0" >
                <tr>
                <td width="34%" nowrap bgcolor="#eef2fd" ><div align="left"><strong><span class="blue"><?php echo ADVERTISE_AGE ?>:</span></strong></div></td>
                <td width="66%" nowrap bgcolor="#dae5f9" class="normal" > <?php
                print($sql_array->age);
         ?>                </td>
              </tr>
              <tr>
                <td nowrap bgcolor="#eef2fd" ><div align="left"><strong><span class="blue"><?php echo ADVERTISE_SIGN ?>:</span></strong></div></td>
                <td nowrap bgcolor="#dae5f9" class="normal"> <?php
                print(get_sign($sql_array->adv_dob));
         ?>                </td>
              </tr>
              <tr>
                <td nowrap bgcolor="#eef2fd" ><div align="left"><strong><span class="blue"><?php echo CUPID_REGION?>:</span></strong></div></td>
                <td nowrap bgcolor="#dae5f9" class="normal"><?=$sql_array->gcn_name?>                </td>
              </tr>
              <tr>
                <td nowrap bgcolor="#eef2fd" ><div align="left"><strong><span class="blue"><?php echo GENERAL_CITY?>:</span></strong></div></td>
                <td nowrap bgcolor="#dae5f9" class="normal"><?php echo $sql_array->gct_name?> </td>
              </tr>
			  <? 
			 $sql="SELECT DISTINCT lst_type,name,qOrder from vlistbox GROUP BY qOrder";
			 $resultvalue=mysql_query($sql) or die(mysql_error());
			 $i=0;
			while($rowvalue=mysql_fetch_array($resultvalue))
			{
			?>
			<tr>
	  		<?
			$lowelcase = strtolower($rowvalue['name']);
			$newphrase9 = str_replace(" ","", $lowelcase);
			$tablefield = "adv_$newphrase9";
			//echo $tablefield;
			$res=mysql_query("SELECT * FROM adverts_dropdown");
			$fields = mysql_num_fields($res);
			for ($j = 0; $j < $fields; $j++) 
			{
				$fname=mysql_field_name($res, $j);
				//$newphrase10 = str_replace("_","", $fname);
				//$newphrase11 = str_replace("adv","", $newphrase10);
				//$dropvalue = ucfirst($newphrase11);
				//print "" . $fname . "<br>";
				//echo $newphrase11;
				if($tablefield == $fname)
				{ ?>
				<td nowrap bgcolor="#eef2fd" ><div align="left"><strong><span class="blue"><?=$rowvalue['name'];?></span></strong></div></td>
				
			<?	
				$str_query = mysql_query("select $tablefield from adverts_dropdown where adv_userid = $profile");
				while($rst_query = mysql_fetch_object($str_query))
					{ 
					?>
					<td nowrap bgcolor="#dae5f9" class="normal"><?=stripslashes($rst_query->$fname);?></td>
					
				<?	}
			  }
				
		  }
			
			?>
			 </tr>
			<?
		 }
			 ?>
              <tr>
                <td nowrap bgcolor="#eef2fd" ><div align="left"><strong><span class="blue"><?php echo GENERAL_HEIGHT?>:</span></strong></div></td>
                <td nowrap bgcolor="#dae5f9" class="normal"><?
                print("$height");
                ?>                </td>
              </tr>
              <tr >
                <td bgcolor="#eef2fd" ><div align="left"><strong><span class="blue"><?php echo PRGRETUSER_LASTVISIT?>:</span></strong></div></td>
                <td bgcolor="#dae5f9" class="normal" ><?=$sql_array->mem_lastvisit?></td>
              </tr>
</table>


	<?

}
}


if(isset($_REQUEST['mymatch'])){
 $mymatch = $_REQUEST['mymatch']; 
if($mymatch) { 
    
       
$mymatch1 = mysql_query("SELECT mym_comment FROM `mymatch` WHERE `mym_userid`='".$mymatch."'"); 



       
        $adv=mysql_fetch_object($mymatch1);
		if($adv->mym_comment!=''){?>
		<div align='left' class='normal' style='font-weight:100; padding:15px'><?=stripslashes($adv->mym_comment)?></div>
		<? }
		else{
		?><div align='left' class='normal' style='font-weight:100; padding:15px'><?=NOTHING_TO_DISPLAY?></div>
	<?	}
		
}}

####################

####################

?><div><? 
if(isset($_REQUEST['leavecomment'])){
$leavecomment = $_REQUEST['leavecomment']; 
//echo $leavecomment ;
if($leavecomment) { 

    ?>

	<div>
	<form name="FrmComment" method="post" style="margin:0px; padding:0px">
	<table border="0" cellpadding="0" cellspacing="0" align="center">
	<tr><td align="center"><textarea name="comment" id="comment_id" value="<?=$leavecomment?>" cols="60" rows="4"></textarea></td></tr>
	<tr><td align="center"><input name="savecomment" type="button" value="Save" onClick="abc();"></td></tr>
	<tr><td align="center" class="text11 blue"><?=MAX_CHAR?></td></tr>
	</table>
</form></div>
	
	<?
        
        
   }

}?></div><?

####################

if(isset($_REQUEST['delcomment'])){
 $delcomment = $_REQUEST['delcomment']; 
if($delcomment) { 


$del=mysql_query("DELETE from profile_comment where comment_id='$delcomment'");

   if($del){ echo COM_DELETED;




}
        
        
   }

}



##########################

if(isset($_REQUEST['banner'])){
echo $banner = $_REQUEST['banner']; 

echo "UPDATE bannercodes SET hits = hits + 1 WHERE banner_id = '$banner'";
$upd=mysql_query("UPDATE bannercodes SET hits = hits + 1 WHERE banner_id = '$banner'");


}


#############################

//ini_set("display_errors",1);
if(isset($_REQUEST['myfriends'])){

if($my_friends==1){
$myfriends=$_REQUEST['myfriends'];

include_once __INCLUDE_CLASS_PATH."/class.Picture.php";
$picture = new Picture();


 $query="SELECT DISTINCT*
			FROM my_friends 
			LEFT join adverts
			ON(friend_uid=adv_userid)
			WHERE uid='$myfriends' and approved='1'";
					
					

	
$rs=mysql_query($query);



//$pager = new PS_Pagination($link,$query,$record_per_page,5);
//$rs = $pager->paginate();
//$result=$db->get_results($rs.$limit);


?>



  	<table width="100%" align="center" border="0" cellspacing="0" cellpadding="0">
	<tr><td height="10px"></td></tr>


          <tr><a name="blog">
            <td style="border-left:1px solid #ededed; border-right:1px solid #ededed;" >
			<table width="100%" border="0" cellspacing="0" cellpadding="0">
              
            <? if(mysql_num_rows($rs) > 0){?>  
              <tr>
           
                <?php 



//$pro=mysql_query("select * from adverts order by rand() limit 4");
			
	 $i=0;
	 while ($ret_pic = mysql_fetch_object($rs)) {

$photo_query=mysql_query("SELECT * FROM pictures WHERE pic_userid = '$ret_pic->friend_uid' and pic_default='Y'") or die(mysql_error());
$pics_count = mysql_num_rows($photo_query);
$aPicture = mysql_fetch_object($photo_query);
if ($pics_count > 0) {
	$medium = $aPicture->pic_picture."_ps.".$aPicture->ext;
	$male1_picture1 = "members/$ret_pic->adv_username/picture/$medium";
             }else{
$male1_picture1=$picture->GetProfilePicture($ret_pic->friend_uid);
}
		$male1_country1 = $ret_pic->adv_country;
		
		$male1_name1= $ret_pic->adv_username;
		
		$male1_age= $ret_pic->age;
if(($i%4)==0)
	{ 
	print "<tr><td>&nbsp;</td></tr>
	<tr>";
}
?>
                
                   <td> <div align="center"  class="photobg"><? if(isset($Sess_UserId)){?><a href="<?=$CONST_LINK_ROOT?>/user_profile.php?userid=<?=base64_encode($ret_pic->adv_userid)?>"><img src="<?=$CONST_LINK_ROOT?>/<?=$male1_picture1?>" width="110" height="110" border="1" style="border-color:#666666" title="Name:&nbsp;<?=$male1_name1?>"/></a> <? if($myfriends==$Sess_UserId){?><div align="center" style="margin-top:-2px">
		<a href="#blog" class="blue" onclick="return remove_fren(<?=$ret_pic->friend_uid?>);">Remove</a></div><? }?><? }else{?><a href="<?=$CONST_LINK_ROOT?>/profile_view.php?userid=<?=base64_encode($ret_pic->adv_userid)?>"><img src="<?=$CONST_LINK_ROOT?>/<?=$male1_picture1?>" width="110" height="110" border="1" style="border-color:#666666" title="Name:&nbsp;<?=$male1_name1?>"/></a><? }?></div></td>
                
                <? 
				$i++;
				} ?></tr> <? }else{?>
				<div align='left' class='normal' style='font-weight:100; padding:15px'><?=MEMBER_NO_FRIENDS?></div>
				<? } ?>
            </table></td>
          </a></tr>
		  


        </table><? }else{ ?><div align='left' class='normal' style='font-weight:100; padding:15px'><?=FEATURE_DISABLE?></div> 

<? }}

##############################
if(isset($_REQUEST['removal'])){
$removal=$_REQUEST['removal'];
$del=mysql_query("DELETE from my_friends where uid='$Sess_UserId' AND friend_uid='$removal'");
//$_REQUEST['approve']='2';
?><font size='+1'><?=FREN_REMOVED?>...</font>

<? }




##############################
if(isset($_REQUEST['myblogs'])){
if($my_blogs==1){
//ini_set("display_errors", 1);
include_once __INCLUDE_CLASS_PATH."/class.DB.php";
$db = & db::getInstance();
$myblogs=$_REQUEST['myblogs'];
$result = $db->get_results("
		        SELECT *, UNIX_TIMESTAMP(blg_datetime) as blgdate
		        FROM blogs LEFT JOIN members ON (mem_userid=blg_userid)
		        WHERE blg_userid = '$myblogs' AND blg_approved='Y'
		        ORDER BY blg_datetime DESC"
            );

?>
<table width="100%" border="0" cellspacing="10" cellpadding="0">
  <!--<tr class="tdodd">
    <td valign="top">&nbsp;</td>
    <td valign="top"><strong>Date:</strong></td>
    <td valign="top"><strong>Title:</strong></td>
    <td valign="top"><strong>Post:</strong></td>
    <td valign="top">&nbsp;</td>
  </tr>-->
   <?php 
   if(count($result)>0){
   foreach($result as $sql_array) {
			
	?>
  
  <tr class="tdodd">
  <? if(!file_exists("blogs/blog_$sql_array->blg_id.jpg")){ $image="$pathh/images/my_blog_post.png" ;}  else {$image="blogs/blog_$sql_array->blg_id.jpg";} ?>
  <td valign="top"><img src="<?=$CONST_LINK_ROOT?>/<?=$image?>"  height="32" width="32"/></td>

	<td valign="top" class="normal"><font size="+1"><strong><?php echo $sql_array->blg_title ?></strong></font><br />
	Posted By <i><?=$sql_array->mem_username?></i> on <?php echo date(" M j, Y",$sql_array->blgdate); ?><br /><br />
    
   
      <?php echo wordwrap(substr(stripslashes($sql_array->blg_message), 0, 100), 120, "<br />\n", true);?>....&#8230;<a href="#blog" class="blue"  onclick="return toggle_readblogs(<?=$sql_array->blg_id?>, <?=$sql_array->blg_userid?>);"><font color="#0c79a0"><?=READ_MORE?></font></a></td></tr>
   
  <? }}else{?>
  <div align='left' class='normal' style='font-weight:100; padding:15px'><?=NO_BLOGS?></div>
  <? }?>
</table><? }else{ ?><div align='left' class='normal' style='font-weight:100; padding:15px'><?=FEATURE_DISABLE?></div> 

<? }}
#############################

if(isset($_REQUEST['readblogs'])){


include_once __INCLUDE_CLASS_PATH."/class.DB.php";
$db = & db::getInstance();
$readblogs=$_REQUEST['readblogs'];
$userblog=$_REQUEST['userblog'];
$result = $db->get_results("
		        SELECT *, UNIX_TIMESTAMP(blg_datetime) as blgdate
		        FROM blogs LEFT JOIN members ON (mem_userid=blg_userid)
		        WHERE blg_id = '$readblogs' AND blg_approved='Y'
		        "
            );
			
				
$user_result = $db->get_results("
		        SELECT *, UNIX_TIMESTAMP(blg_datetime) as blgdate
		        FROM blogs LEFT JOIN members ON (mem_userid=blg_userid)
		        WHERE blg_id != '$readblogs' AND blg_userid = '$userblog' AND blg_approved='Y'
		        ORDER BY blg_datetime DESC"
            );			

?>
<table width="100%" border="0" cellspacing="10" cellpadding="0">
 
   <?php foreach($result as $sql_array) {
			
	?>
  
  <tr class="tdodd"><a name="blog">
  <? if(!file_exists("blogs/blog_$sql_array->blg_id.jpg")){ $image="$pathh/images/my_blog_post.png" ;}  else {$image="blogs/blog_$sql_array->blg_id.jpg";} ?>
  <td valign="top"><img src="<?=$CONST_LINK_ROOT?>/<?=$image?>"  height="32" width="32"/></td>

	<td valign="top" class="normal"><font size="+1"><strong><?php echo $sql_array->blg_title ?></strong></font><br />
	Posted By <i><?=$sql_array->mem_username?></i> on <?php echo date(" M j, Y",$sql_array->blgdate); ?><br /><br />
    
   
      <?=stripslashes($sql_array->blg_message)?></td></a></tr>
   
  <? }?>
</table>

<table width="100%" border="0" cellspacing="10" cellpadding="0">
 
   <?php foreach($user_result as $sql_array) {
			
	?>
  
  <tr class="tdodd"><a name="blog">
  <? if(!file_exists("blogs/blog_$sql_array->blg_id.jpg")){ $image="$pathh/images/my_blog_post.png" ;}  else {$image="blogs/blog_$sql_array->blg_id.jpg";} ?>
  <td valign="top"><img src="<?=$CONST_LINK_ROOT?>/<?=$image?>"  height="32" width="32"/></td>

	<td valign="top" class="normal"><font size="+1"><strong><?php echo $sql_array->blg_title ?></strong></font><br />
	Posted By <i><?=$sql_array->mem_username?></i> on <?php echo date(" M j, Y",$sql_array->blgdate); ?><br /><br />
    
   
      <?php echo wordwrap(substr(stripslashes($sql_array->blg_message), 0, 100), 120, "<br />\n", true);?>....&#8230;<a href="#blog" class="blue"  onclick="return toggle_readblogs(<?=$sql_array->blg_id?>, <?=$sql_array->blg_userid?>);"><font color="#0c79a0"><?=READ_MORE?></font></a></td></a></tr>
   
  <? }?>
</table>


<? }



##############################
if(isset($_REQUEST['myarticles'])){
if($my_articles==1){
include_once __INCLUDE_CLASS_PATH."/class.DB.php";
$db = & db::getInstance();
$myarticles=$_REQUEST['myarticles'];
$result = $db->get_results("
		        SELECT *, UNIX_TIMESTAMP(art_datetime) as artdate
		        FROM articles LEFT JOIN members ON (mem_userid=art_userid)
		        WHERE art_userid = '$myarticles' AND art_approved='Y'
		        ORDER BY art_datetime DESC"
            );

?>
<table width="100%" border="0" cellspacing="10" cellpadding="0">
  <!--<tr class="tdodd">
    <td valign="top">&nbsp;</td>
    <td valign="top"><strong>Date:</strong></td>
    <td valign="top"><strong>Title:</strong></td>
    <td valign="top"><strong>Post:</strong></td>
    <td valign="top">&nbsp;</td>
  </tr>-->
 <?php 
   if(count($result)>0){
   foreach($result as $sql_array) {
			
	?>
  
  <tr class="tdodd">
  <? if(!file_exists("articles/art_$sql_array->art_id.jpg")){ $image="$pathh/images/generic_articles.png" ;}  else {$image="articles/art_$sql_array->art_id.jpg";} ?>
  <td valign="top"><img src="<?=$CONST_LINK_ROOT?>/<?=$image?>"  height="32" width="32"/></td>

	<td valign="top" class="normal"><font size="+1"><strong><?php echo $sql_array->art_title ?></strong></font><br />
	Posted By <i><?=$sql_array->mem_username?></i> on <?php echo date(" M j, Y",$sql_array->artdate); ?><br /><br />
    
   
      <?php echo wordwrap(substr(stripslashes($sql_array->art_message), 0, 100), 120, "<br />\n", true);?> .... <a href="#blog" onclick="return toggle_readarticles(<?=$sql_array->art_id?>, <?=$sql_array->art_userid?>);"><font color="#0c79a0"><?=READ_MORE?></font></a></td></tr>
   
  <? }}else{?>
  <div align='left' class='normal' style='font-weight:100; padding:15px'><?=NO_ARTICLES?></div>
  <? }?>
</table><? }else{ ?><div align='left' class='normal' style='font-weight:100; padding:15px'><?=FEATURE_DISABLE?></div> 

<? }}
#######################

if(isset($_REQUEST['readarticles'])){


include_once __INCLUDE_CLASS_PATH."/class.DB.php";
$db = & db::getInstance();
$readarticles=$_REQUEST['readarticles'];
$userarticles=$_REQUEST['userarticles'];
$result = $db->get_results("
		        SELECT *, UNIX_TIMESTAMP(art_datetime) as artdate
		        FROM articles LEFT JOIN members ON (mem_userid=art_userid)
		        WHERE art_id = '$readarticles' AND art_approved='Y'
		        "
            );
			
				
$user_result = $db->get_results("
		        SELECT *, UNIX_TIMESTAMP(art_datetime) as artdate
		        FROM articles LEFT JOIN members ON (mem_userid=art_userid)
		        WHERE art_id != '$readarticles' AND art_userid = '$userarticles' AND art_approved='Y'
				ORDER BY art_datetime DESC
		        "
            );			

?>
<table width="100%" border="0" cellspacing="10" cellpadding="0">
 
   <?php foreach($result as $sql_array) {	?>
  
  <tr class="tdodd"><a name="blog">
 <? if(!file_exists("articles/art_$sql_array->art_id.jpg")){ $image="$pathh/images/generic_articles.png" ;}  else {$image="articles/art_$sql_array->art_id.jpg";} ?>
  <td valign="top"><img src="<?=$CONST_LINK_ROOT?>/<?=$image?>"  height="32" width="32"/></td>

	<td valign="top" class="normal"><font size="+1"><strong><?php echo $sql_array->art_title ?></strong></font><br />
	Posted By <i><?=$sql_array->mem_username?></i> on <?php echo date(" M j, Y",$sql_array->artdate); ?><br /><br />
    
   
      <?=stripslashes($sql_array->art_message)?></td></a></tr>
   
  <? }?>
</table>

<table width="100%" border="0" cellspacing="10" cellpadding="0">
 
   <?php foreach($user_result as $sql_array) {
			
	?>
  
  <tr class="tdodd">
  <? if(!file_exists("articles/art_$sql_array->art_id.jpg")){ $image="$pathh/images/generic_articles.png" ;}  else {$image="articles/art_$sql_array->art_id.jpg";} ?>
  <td valign="top"><img src="<?=$CONST_LINK_ROOT?>/<?=$image?>"  height="32" width="32"/></td>

	<td valign="top" class="normal"><font size="+1"><strong><?php echo $sql_array->art_title ?></strong></font><br />
	Posted By <i><?=$sql_array->mem_username?></i> on <?php echo date(" M j, Y",$sql_array->artdate); ?><br /><br />
    
   
      <?php echo wordwrap(substr(stripslashes($sql_array->art_message), 0, 100), 120, "<br />\n", true);?> .... <a href="#blog" onclick="return toggle_readarticles(<?=$sql_array->art_id?>, <?=$sql_array->art_userid?>);"><font color="#0c79a0"><?=READ_MORE?></font></a></td></tr>
   
  <? }?>
</table>


<? }
###########################
###########################
# Essay
###########################
###########################

if(isset($_REQUEST['essays'])){
if($my_essays==1){
include_once __INCLUDE_CLASS_PATH."/class.DB.php";
$db = & db::getInstance();
$essays=$_REQUEST['essays'];

			
$result = $db->get_results("
		        SELECT *, UNIX_TIMESTAMP(essay_date) as essdate
		        FROM essay_answers LEFT JOIN members 
				ON (mem_userid=essay_userid)
				LEFT JOIN essay_questions on (essay_id=essays_id)
		        WHERE essay_userid = '$essays' AND approved='1'
		        ORDER BY essay_date DESC"
            );

?>
<table width="100%" border="0" cellspacing="10" cellpadding="0">
  <!--<tr class="tdodd">
    <td valign="top">&nbsp;</td>
    <td valign="top"><strong>Date:</strong></td>
    <td valign="top"><strong>Title:</strong></td>
    <td valign="top"><strong>Post:</strong></td>
    <td valign="top">&nbsp;</td>
  </tr>-->
 <?php 
   if(count($result)>0){
   foreach($result as $sql_array) {
			
	?>
  
  <tr class="tdodd">
 
  
	<td valign="top" class="normal"><font size="+1"><strong><?php echo $sql_array->essay_question ?></strong></font><br />

    
   
    <i> <?=$sql_array->essay_answer?></i></font></a></td></tr>
   
  <? }}else{?>
  <div align='left' class='normal' style='font-weight:100; padding:15px'><?=NO_ESSAYS?></div>
  <? }?>
</table><? }else{ ?><div align='left' class='normal' style='font-weight:100; padding:15px'><?=FEATURE_DISABLE?></div> 

<? }}
#######################

if(isset($_REQUEST['readessays'])){


include_once __INCLUDE_CLASS_PATH."/class.DB.php";
$db = & db::getInstance();
 $readessays=$_REQUEST['readessays'];
 $useressays=$_REQUEST['useressays'];
$result = $db->get_results("
							
		        SELECT *, UNIX_TIMESTAMP(essay_date) as essdate
		        FROM essay_answers LEFT JOIN members ON (mem_userid=essay_userid)
				WHERE ess_id = '$readessays' AND approved='1'
		        
		        "
            );
							
$user_result = $db->get_results("
		        SELECT *, UNIX_TIMESTAMP(essay_date) as essdate
		        FROM essay_answers LEFT JOIN members ON (mem_userid=essay_userid)
				WHERE ess_id != '$readessays' AND essay_userid = '$useressays' AND approved='1'
		        "
            );			

?>
<table width="100%" border="0" cellspacing="10" cellpadding="0">
 
   <?php foreach($result as $sql_array) {	?>
  
  <tr class="tdodd"><a name="blog">
 <? if(!file_exists("articles/art_$sql_array->art_id.jpg")){ $image="$pathh/images/generic_articles.png" ;}  else {$image="articles/art_$sql_array->art_id.jpg";} ?>
  <td valign="top"><img src="<?=$CONST_LINK_ROOT?>/<?=$image?>"  height="32" width="32"/></td>

	<td valign="top" class="normal"><font size="+1"><strong><?php echo $sql_array->art_title ?></strong></font><br />
	Posted By <i><?=$sql_array->mem_username?></i> on <?php echo date(" M j, Y",$sql_array->essdate); ?><br /><br />
    
   
      <?=stripslashes($sql_array->essay_answer)?></td></a></tr>
   
  <? }?>
</table>

<table width="100%" border="0" cellspacing="10" cellpadding="0">
 
   <?php foreach($user_result as $sql_array) {
			
	?>
  
  <tr class="tdodd">
  <? if(!file_exists("articles/art_$sql_array->art_id.jpg")){ $image="$pathh/images/generic_articles.png" ;}  else {$image="articles/art_$sql_array->art_id.jpg";} ?>
  <td valign="top"><img src="<?=$CONST_LINK_ROOT?>/<?=$image?>"  height="32" width="32"/></td>

	<td valign="top" class="normal"><font size="+1"><strong><?php echo $sql_array->art_title ?></strong></font><br />
	Posted By <i><?=$sql_array->mem_username?></i> on <?php echo date(" M j, Y",$sql_array->essdate); ?><br /><br />
    
   
      <?php echo wordwrap(substr(stripslashes($sql_array->essay_answer), 0, 100), 120, "<br />\n", true);?> .... <a href="#blog" onclick="return toggle_readEssays(<?=$sql_array->ess_id?>, <?=$sql_array->essay_userid?>);"><font color="#0c79a0"><?=READ_MORE?></font></a></td></tr>
   
  <? }?>
</table>


<? }





############################
# Admin index stats graph 
############################

if(isset($_REQUEST['graph'])){
$graph=form_get('graph');

$tendayz = time() - (14 * 24 * 60 * 60);
        
$tendayz= date('Y-m-d', $tendayz);

function OutputImage($img1) 
{
	
	imagejpeg($img1, 'admin/simplegraph.jpg', 100);
}
 $curDate=date('Y-m-d');

$query=mysql_query("select * from member_stats where statDate > $tendayz ORDER BY statDate");




function associative_push($arr, $tmp) {
  if (is_array($tmp)) {
    foreach ($tmp as $key => $value) { 
      $arr[$key] = $value;
    }
    return $arr;
  }
  return false;
}


function change2dmy($date)
{
$dtmp = explode("-",$date);
$dadate = mktime(0,0,0,$dtmp[1],$dtmp[2],$dtmp[0]);
return date("m-d",$dadate);
}

	while($statGraph=mysql_fetch_object($query))
    {
	  $StDat=change2dmy($statGraph->statDate);
	  if($graph=='sign'){
	  $StCount=$statGraph->counter_sign;	
	  }else{
	  $StCount=$statGraph->counter;	
	  }
        $myArr = array("$StDat" => "$StCount"); 
		$values = associative_push($values, $myArr);
       
    } 
	
# Graph code starts 	

	$img_width=600;
	$img_height=200; 
	$margins=20;

 
	
	$graph_width=$img_width - $margins * 2;
	$graph_height=$img_height - $margins * 2; 
	$img=imagecreate($img_width,$img_height);

 
	$bar_width=20;
	$total_bars=count($values);
	$gap= ($graph_width- $total_bars * $bar_width ) / ($total_bars +1);

 
	
	$bar_color=imagecolorallocate($img,0,64,128);
	$background_color=imagecolorallocate($img,240,240,255);
	$border_color=imagecolorallocate($img,200,200,200);
	$line_color=imagecolorallocate($img,220,220,220);
 
	
	imagefilledrectangle($img,1,1,$img_width-2,$img_height-2,$border_color);
	imagefilledrectangle($img,$margins,$margins,$img_width-1-$margins,$img_height-1-$margins,$background_color);

 
	
	$max_value=max($values);
	$ratio= $graph_height/$max_value;

 
	
	$horizontal_lines=20;
	$horizontal_gap=$graph_height/$horizontal_lines;

	for($i=1;$i<=$horizontal_lines;$i++){
		$y=$img_height - $margins - $horizontal_gap * $i ;
		imageline($img,$margins,$y,$img_width-$margins,$y,$line_color);
		$v=intval($horizontal_gap * $i /$ratio);
		imagestring($img,0,5,$y-5,$v,$bar_color);

	}
 
 
	
	for($i=0;$i< $total_bars; $i++){ 
		
		list($key,$value)=each($values); 
		$x1= $margins + $gap + $i * ($gap+$bar_width) ;
		$x2= $x1 + $bar_width; 
		$y1=$margins +$graph_height- intval($value * $ratio) ;
		$y2=$img_height-$margins;
		imagestring($img,0,$x1+3,$y1-10,$value,$bar_color);imagestring($img,0,$x1+3,$img_height-15,$key,$bar_color);		
		imagefilledrectangle($img,$x1,$y1,$x2,$y2,$bar_color);
	}
	 OutputImage($img);
	
	?>
	<div align="right"><a href="#gra" onclick="toggle_graph('sign');">Sign Up</a> - <a href="#gra" onclick="toggle_graph('log');">Login</a></div><img src="<?=$CONST_LINK_ROOT?>/admin/simplegraph.jpg">
	 
	<? 
	//header("Content-type:image/png");
	//imagepng($img);
	
# graph code ends	
}

?>