<?
include("funcs2.php");

function ad_details()
{
global $cat_fields, $photos_count, $html_header, $html_footer, $id,
$ct, $categories, $ad_second_width, $left_width_sp, $exp_period,$exp_perdhlt, $privacy_mail,
$schallusrads, $detl_leftcol, $tbclr_1, $tbclr_2, $tbclr_3, $tbclr_4, $fntclr_1, $evnt_cat,
$fntclr_3, $plcntdtl, $plcntpml, $reply_catg, $pladddp, $hltadsf, $msg, 
$det_cnt, $prphscnd, $use_gl_map, $row;

if ($plcntdtl=='yes'){adscounter($id, 'vis');}

$row=get_ad_details($id);
$row=check_row($row);
if($ct==""){$ct=$row['catname']; $cat_fields=""; getfldlst();}

$repl_cmminf="";
if ($reply_catg[$ct] !="")
{ $replcn_val=check_replcmm($id,$row); $repl_cmminf=repl_commt($row,$replcn_val);}

if ($row['adcommkey']==1){
$view_intad="
<a href='index.php?md=details&id=".$row['replyid']."' >
<font FACE='Verdana,Geneva,Arial' SIZE=1 $colr1_hltads> 
<b>  ".$msg['View_initia_ad']."(#".$row['replyid'].")</b></font></a>
<br>
";
}


if ($schallusrads=='yes')
{
$useradsnum=getuseradsnum($row['email']);
if ($useradsnum > 1)
{
$all_ads_user="
<font FACE='Verdana,Geneva,Arial' SIZE=1>
<br><a href='index.php?md=browse&idemail=".$row['idnum']."'  >
<b>".$msg['browse_ads_by_user']."</b></a> ($useradsnum ".$msg['ads_d'].")

</font>
";
}

if ($plcntdtl=='yes'){
$det_cnt="
".$row['cntvstr']." ".$msg['visits_d']."
";
}

if ($plcntpml=='yes'){
if ($row['cntemll']==0){
$det_pml="&nbsp; <font FACE='ARIAL, HELVETICA' COLOR='BLACK' size='-2'><b>
(".$msg['no_one_email_sent'].")</b></font>";
}
else{
if ($row['cntemll']>1){$eml_msg=$msg['email_snt'];}  else {$eml_msg=$msg['email_snt_one'];}
$det_pml="&nbsp;&nbsp; (".$row['cntemll']." $eml_msg
 ".$msg['was_sent_to_owner'].")";
}
}
 

if ($row['login']!='')
{

if ($pladddp=='yes')
{
$addt_info="<p>".getadditinfo($row['login'], $id);
}

$mbadsnum=getmbadsnum($row['login']);

if ($mbadsnum > 1)
{
$all_ads_user="
<font FACE='Verdana,Geneva,Arial' SIZE=1>
<br><a href='index.php?md=browse&mblogin=".$row['login']."'  >
<b>".$msg['browse_ads_by_member']." '".$row['login']."'</b></a> ($mbadsnum 
".$msg['ads_d'].")
</font>
";
}
}

}

$time1=$row['time'];
$date_posted=get_date($time1); 
$time2=$time1+$exp_period*86400;
if ($row['adrate'] > 0){$time2=$time1+$exp_perdhlt*86400;}
$expire_date=get_date($time2);

if ($privacy_mail=='yes') {
$cont_email="<a href='index.php?ct=$ct&md=privacy_mail&idnum=$id'>
 ".$msg['privacy_mail']."</a>";}
else{
$cont_email="<a href='mailto:".$row['email']."'>".$row['email']."</a>";
}

$homepg_info="";
if ($row['homeurl']!="--"){
$homepg_info="<li>".$msg['Home_Page_d'].": <a href='".$row['homeurl']."' target='_blank'>".$row['homeurl']."</a></li>";
}

$contemail_info="";
if ($row['email']!="--" and $row['email']!=""){
$contemail_info="<li>".$msg['contact_email'].": $cont_email <br>$det_pml</li>";
}

$idnum=$row['idnum'];

$sdtpcol="$tbclr_4";
$sdtpcol1="$tbclr_3";
$ad_sec_rt=$ad_second_width-$left_width_sp-1;

$repltitle="<title>".$row['title'].".  ";
$html_header=ereg_replace('<title>', $repltitle, $html_header);

if ($hltadsf=='yes'){
if (($row['adrate'] < 1) or ($row['adrate']=="")){
$hltadsinfo="
<a href='highlight.php?id=$idnum' target='hlttad'>
".$msg['Highlight_this_ad']."</a> 
";
}
}
else{$hltadsinfo="";}

get_tm_tags($row['title'],$row);

echo "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>";
echo $html_header;
echo " 
 
<TABLE BORDER=0 WIDTH='100%'   cellspacing=0 cellpadding=0 >
<TR><td  style='BORDER-BOTTOM: $tbclr_2 2px solid;' cellspacing=0 cellpadding=0  >&nbsp;</td></tr></table>
<p>
<center>
<table width='$ad_second_width'  border=0 cellspacing=1 cellpadding=0><tr>
$detl_leftcol
<td valign='top' align='left'>
<TABLE WIDTH='100%'  border=0 BGCOLOR='$tbclr_4' cellspacing='1' cellpadding='10' > 
<tr>
<TD  VALIGN=TOP>
<font FACE='ARIAL, HELVETICA' COLOR='BLACK'> <font size=-1>
<a href='index.php'>".$msg['top'].":</a> 
<b><a href='index.php?md=browse&ct=$ct'>".$categories[$ct][0]."</a></b>
</font> 
<table width='100%' border=0 cellspacing=3 cellpadding=3>
<tr>
<td bgcolor='$tbclr_1'>
<font FACE='ARIAL, HELVETICA' color='$fntclr_1' >
&nbsp;&nbsp; <b>".$row['title']."</b></font>
</td>
</tr>
</table>
$view_intad
";
if ($row['login']!="")
{
echo "
<font FACE='ARIAL, HELVETICA' COLOR='#000088'' size='-2'><b>
".$msg['ad_posted_member']."  '".$row['login']."'
</font></b><br>";
}
echo "
".lrg_photo($idnum)."
<table width='100%'  bgcolor='$tbclr_4' cellspacing=5 cellpadding=5>
<tr><td>
<font FACE='ARIAL, HELVETICA' COLOR='BLACK' size='-2'><b>
<font color='#007700' >&nbsp;".$msg['adsid'].": </font><font color='#aa0000'>
$idnum
</font>; 
&nbsp;
<font color='#007700' >  ".$msg['date_posted_d'].": </font> <font color='#aa0000' >
 $date_posted</font>;
&nbsp;
";
if ($evnt_cat[$ct] !="yes"){
echo "
<font color='#007700' >".$msg['expire_date_d'].": </font>
<font color='#aa0000' >$expire_date</font>;
";
}
echo "
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  $det_cnt   </b></font> 
<table width='100%'  border=0 bordercolor='#ffffff' cellspacing=5 cellpadding=0>
<tr><td valign='top' width='80%'>

<table width='100%'  border=0 bordercolor='$tbclr_4' cellspacing=0 cellpadding=4>
";


foreach ( $cat_fields as $key => $value )
{ 

if($row[$key]==""){$row[$key]='--';}
if ( ($cat_fields[$key][1] == '2' or $cat_fields[$key][1] == '12') and !($key=='initialad' and $row[$key]=='--') )

{
$tarrk11=""; if ($cat_fields[$key][4] == 'textarea'){$tarrk11="<p ALIGN='JUSTIFY'>&nbsp;";}
echo "
 
";
if ($cat_fields[$key][4] == 'textarea'){
echo "
<tr><td bgcolor='$sdtpcol' colspan='2' class='tdsp'>
<font FACE='ARIAL, HELVETICA' COLOR='$fntclr_3' size='-1'>
<p ALIGN='JUSTIFY'> &nbsp; ".$cat_fields[$key][0].":</font> &nbsp;&nbsp;
<font FACE='ARIAL, HELVETICA' COLOR='$fntclr_1' size='-1'>
 ".$row[$key]." &nbsp; </td></tr>
 ";
}
else {
echo "
<tr><td bgcolor='$sdtpcol' width='30%' class='tdsp'>
<font FACE='ARIAL, HELVETICA' COLOR='$fntclr_3' size='-1'>
&nbsp; ".$cat_fields[$key][0].":</font>
</td><td bgcolor='$sdtpcol' width='70%' class='tdsp'> $tarrk11
<font FACE='ARIAL, HELVETICA' COLOR='$fntclr_1' size='-1'>
 ".$row[$key]." &nbsp; </td></tr>
 ";
}
}

}

echo "
 
</table>
 
<p>
<font FACE='ARIAL, HELVETICA' COLOR='$fntclr_3' size='-1'>
<ul> $contemail_info $homepg_info </ul>

 ".print_multimed($idnum)."

</b></font>

<font FACE='ARIAL, HELVETICA' COLOR='BLACK' size='-1'>

$addt_info
<p> 
$all_ads_user
";

if ($use_gl_map=='yes'){echo dt_map($row['addrmap']);}

echo "
</td><td valign='top' width='$prphscnd'>
".print_photos($idnum, $row)." 
</td>
</tr></table>
</td></tr></table>";
 

if ($row['adcommkey']!=1){
echo " 
".adsvtrform($row)." 
";
}

echo "$repl_cmminf";

if ($row['adcommkey']!=1){
echo "
<table width='100%' bgcolor='$tbclr_1' border=0 cellspacing=0 cellpadding=0> 
<tr><td>  ".print_fvrt_dtl()."</td></tr>
</table>
";
}

echo "<br> <center>";
 
if ($row['adcommkey']!=1){
echo "
<font FACE='ARIAL, HELVETICA' COLOR='BLACK' size='-2'><b>
$hltadsinfo
</b></font>
";
}
echo "  
 <font FACE='ARIAL, HELVETICA' COLOR='BLACK' size='-2'>
<b>
  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  
<a href='' onClick='self.close()'>".$msg['close_window_d']."</a> 
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  
<a href='index.php?ct=$ct&md=editlogin&id=$idnum'>edit ad</a>
 
</b>
</font>
</center> 
</td></tr></table>
</td></tr></table>
</center> 
";

echo $html_footer;
exit;
}


function lrg_photo($idnum)
{
global  $_REQUEST, $photos_url, $photos_path, $photo_path, $photo_url, $photos_count,$multim_link;

$lrgphprez="";
 
if ($_REQUEST['lrgphp']=='1')
{
$lnph=$_REQUEST['lnph'];
get_jpg_path($idnum);

global $maximgswith; $imgsize1=GetImageSize($photo_path[$lnph]);
$imgwidth1=""; if ($imgsize1[0] > $maximgswith){ $imgwidth1="width='$maximgswith'";}
 
$lrgphprez="
<center><p>
<img src='$photo_url[$lnph]' $imgwidth1 >   
</center>
";
}

return $lrgphprez;
}


function print_photos($idnum, $row)
{
global  $ct, $photos_url, $photos_path, $photo_path, $photo_url, 
$photos_count,$multim_link, $prphscnd, $msg, $urlphtn1;
$pho1="";
get_jpg_path($idnum);
for($i=1; $i<=$photos_count; $i++)
{
if (file_exists($photo_path[$i])){$pho1="1";} 
 
}
 
if ($pho1==""){return;}

$html="
<center>
 <font size=-2 FACE='ARIAL, HELVETICA' COLOR='#999999'>
<b>".$msg['Click_ph_to_enlarge']." </b>
</font>
</center>
";
for($i=1; $i<=$photos_count; $i++)
{
if (file_exists($photo_path[$i])){
$photokey="photocaption$i";
$photocapt=$row[$photokey];
$html=$html."
<font FACE='ARIAL, HELVETICA' COLOR='#000099' size='-1'>
<font size='-2'>".$msg['photo_d']." $i 
<center>
<a href='index.php?ct=$ct&md=details&id=$idnum&lrgphp=1&lnph=$i&'>
<img src='".$urlphtn1."sph.php?id=$idnum&wd=$prphscnd&np=$i' border=0></a> <br> $photocapt 
</font>
</center>
";
}
}


global $dsplhltpht, $row;
if (($dsplhltpht=="yes") and (($row['adrate'] < 1) or ($row['adrate']==""))){
if (file_exists($photo_path[1])){
$html="
<center>
<img src='".$urlphtn1."sph.php?id=$idnum&wd=$prphscnd&np=1' border=0> 
</center>
";

}
}

return $html;
}

function print_multimed($idnum)
{
global $incl_mtmdfile,$multimedia_path, $multimedia_url, $multim_link, $msg, $row;
$mm_link="";  
if ($incl_mtmdfile=='yes')
{
get_att_path($idnum);

if (file_exists($multimedia_path)) 
{
$attflsz1=round(filesize($multimedia_path)/1000);
if ($attflsz1==0){$attflsz1=1;}
$mm_link="
<p><li>".$msg['multimedia_file'].": 
<a href='$multimedia_url'>".$row['attfltl']." (".$row['attflext'].", ".$attflsz1."Kb)</a></li>
";
 
}

if (($row['flsrvur1']!="") and ($row['flsrvur1']!="http://")){
$mm_link=$mm_link."<p> 
<li><a href='".$row['flsrvur1']."' target='_blank'>".$row['flsrvtl1']."</a></li>
 ";
}

if (($row['flsrvur2']!="") and ($row['flsrvur2']!="http://")){
$mm_link=$mm_link."<p> 
<li><a href='".$row['flsrvur2']."' target='_blank'>".$row['flsrvtl2']."</a></li>
 ";
}
if ($row['embdcod']!=""){$mm_link=$mm_link."<p> ".$row['embdcod'];}
}

global $dsplhltpht;
if (($dsplhltpht=="yes") and (($row['adrate'] < 1) or ($row['adrate']==""))){$mm_link="";}
 
return  $mm_link;
}

function repl_commt($row, $replcn_val)
{
global $table_ads, $fntclr_1, $tbclr_1, $maxrepldt, $reply_catg, $ct, $msg;

$ridnum=$row['idnum'];
$html_comm="
<table width='100%' bgcolor='$tbclr_1' border=0 cellspacing=0 cellpadding=0> 
<tr><td>
<font FACE='ARIAL, HELVETICA' COLOR='$fntclr_1' size='-1'>
<b> ".$msg['Comments_d'].": </b></font>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
<FONT FACE='Verdana,Geneva,Arial' SIZE=1 color='#000099'><b>
<a href='index.php?ct=".$reply_catg[$ct]."&md=add_form&replid=$ridnum'  >
(".$msg['post_your_comment'].")</a></b>
</td></tr></table>
<p><font FACE='ARIAL, HELVETICA' COLOR='BLACK' font size=-1>
";

if ($replcn_val > 0){
$sql_query="select * from $table_ads where replyid=$ridnum and visible=1  
order by $ord_ratedads idnum desc limit $maxrepldt";
$sql_res=mysql_query("$sql_query");

while ($rowrpl = mysql_fetch_array ($sql_res))
{
$time1=$rowrpl['time'];
$cdate_posted=get_date($time1); 

$pstby="";
if ($rowrpl['login'] != ""){$pstby="by <a href='index.php?md=browse&mblogin=".$rowrpl['login']."'>".$rowrpl['login']."</a>";}
$html_comm=$html_comm."
<a href='index.php?md=details&id=".$rowrpl['idnum']."'  >
<b>".$rowrpl['title']."</b></a> 
&nbsp;&nbsp;<font size=-2><b> (#".$rowrpl['idnum']."; &nbsp; ".$msg['posted_c'].": $cdate_posted $pstby) </b></font>
<br>
".$rowrpl['comment']." <font size=-2><b>&nbsp;&nbsp;
<a href='index.php?md=details&id=".$rowrpl['idnum']."'  >
".$msg['More_c']."</a></b></font>
<p>
";
} 

}

if (($replcn_val > 0) and ($replcn_val > $maxrepldt))
{
$catnmrpl=$row['catname'];
$ctrepl=$reply_catg[$catnmrpl];
$rpidnm=$row['idnum'];
$html_comm=$html_comm."

<FONT FACE='Verdana,Geneva,Arial' SIZE=1 color='#000099'>
<b><a href='index.php?ct=$ctrepl&md=browse&replyid=$rpidnm'>".$msg['view_all_comments']."($replcn_val)</a>
</b></font> 
<p>
";
}

$html_comm=$html_comm."</font>";

return $html_comm;
}

function check_replcmm($id, $row)
{
global $table_ads;

$sql_query="select count(idnum) from $table_ads where replyid=$id and visible=1 ";

$sql_res=mysql_query("$sql_query");
$row=mysql_fetch_row($sql_res);
$rpcount=$row[0];
if ($row['replcnts'] !=$rpcount)
{
$sql_query="update $table_ads set replcnts=$rpcount where idnum=$id ";
mysql_query("$sql_query");
}
return $rpcount;
}

function getadditinfo($mbblogin, $id)
{  
global   $privacy_mail, $msg;

$sdtpcol="#ffffff";
$sdtpcol1="#dddddd";

include("mb_conf.php");

$sql_query="select * from $table_mb where login='$mbblogin'";
$sql_res=mysql_query("$sql_query");
$row = mysql_fetch_array ($sql_res);
$row=check_row($row);

if ($privacy_mail=='yes') {
$row['email']="<a href='index.php?ct=$ct&md=privacy_mail&idnum=$id&emltp=mblg&emllogin=$mbblogin'>
".$msg['privacy_mail']."</a>";}
else{
$row['email']="<a href='mailto:".$row['email']."'>".$row['email']."</a>";
}

$rslt="
<font FACE='ARIAL, HELVETICA' COLOR='#000088' size='-1'>
 ".$msg['members_information'].": 
</font>
<table width='100%'  border=0 bordercolor='#ffffff' cellspacing=3 cellpadding=0>
";

$keyffl="0";
foreach ( $mb_fields as $key => $value )
{
if ((ereg('3', $mb_fields[$key][1])) and ($row[$key]!=""))
{$keyffl="1";
if ($key=="homeurl")
{$row[$key]="<a href='".$row[$key]."'  >$row[$key]</a>";}

$rslt=$rslt."
 
<tr><td bgcolor='$sdtpcol' width='25%'>
<font FACE='ARIAL, HELVETICA' COLOR='#000088' size='-1'>
&nbsp; ".$mb_fields[$key][0].":</font>
</td><td bgcolor='$sdtpcol' width='75%'>
<font FACE='ARIAL, HELVETICA' COLOR='BLACK' size='-1'>
 ".$row[$key]." &nbsp; </td></tr>
 
";
}

}

$rslt=$rslt."
 
</table>
";

if ($keyffl!="1"){$rslt="";}
return $rslt;

}

?>