<?

include('funcs2.php');
 
function print_categories()
{ 
global $html_header, $html_footer, $categories,$ad_ind_width,$schopt,$ads_fields,$subcnmb,$javastl,$hghltcat,
$catl_width, $top_page_info,  $top_page_width, $topsearchfields, $top_leftcol,$catcols,$_REQUEST,$hdhctgrs,
$tbclr_1, $tbclr_2, $tbclr_3, $tbclr_4, $fntclr_1, $msg, $top_rightcol,$btmtophtml,
$top_bottom,$getcityval, $popctgr, $top_rightcol,$fntclr_1, $use_gl_map, $titleclpg, $setctlntp;

global $rmmbrloc;
if ($_REQUEST[$schopt]!=''){  

$cityhtml="<p>
<font FACE='ARIAL, HELVETICA' color='$fntclr_1' >
&nbsp; &nbsp; <b>".$ads_fields[$schopt][0].":  $_REQUEST[$schopt]
&nbsp; &nbsp;&nbsp; &nbsp;  <font size='-2'>(<a href='index.php?allc=1'>".$msg['all_cities']."</a> $rmmbrloc)</font></b></font>
 
<br>
";

$citgtv1=$_REQUEST[$schopt];
$getcityval="$schopt=".checkgetfld($citgtv1)."&";
 
}

get_tm_tags($titleclpg,"");
echo $html_header;
echo "
$javastl
  
<script language='JavaScript'>
<!--
var val1='dvid1';
function ctdispl(nmdiv){
if (document.getElementById){
if (document.getElementById(nmdiv).style.display=='none') 
{document.getElementById(nmdiv).style.display ='block';
  document.getElementById(val1).style.display ='none';
}
else document.getElementById(nmdiv).style.display ='none';
} 
else if (document.all)
{ if(document.all[nmdiv].style.display=='none') 
{document.all[nmdiv].style.display ='block';
document.getElementById(val1).style.display ='none';
}
else document.all[nmdiv].style.display ='none';}
if (val1!=nmdiv) {val1=nmdiv;} else val1='dvid1';
}
-->
</script><div id=dvid1></div>
<STYLE type=text/css>
table{FONT-FAMILY: ARIAL, HELVETICA; FONT-SIZE: 12px; COLOR: $fntclr_1;
       FONT-WEIGHT: normal;}
.st1{FONT-SIZE: 11px;}
</style>
";

if ($use_gl_map=='yes') {echo getmapjsp();}

echo "
<center>
 <table width='$top_page_width' bgcolor='$tbclr_4' border=0 cellspacing=1 cellpadding=1>
<tr>
<td width='150' bgcolor='$tbclr_1'  valign='top'>

<table width='100%'  bgcolor='$tbclr_2' border=0 cellspacing='0' cellpadding='0'>
<tr><td> 
<font color='$tbclr_4'>
 &nbsp; <b>".$msg['cat_themes']."</b>
</font>
<TABLE  WIDTH='100%'   border='0' cellspacing='1' cellpadding='4' >
<tr><td bgcolor='$tbclr_4'><center> 
 <TABLE  WIDTH='90%'   border='0' cellspacing='1' cellpadding='2' >
";
 
foreach ($categories as $key => $value)
{$aa1=split("_",$key);
if($aa1[0] == 'title'){
$ctdv1='th'.$aa1[1];
echo "<tr><td>
  <font style='color:#0000ee; TEXT-DECORATION: underline; cursor: pointer;' 
 OnClick=\"ctdispl('$ctdv1');\"><b>".$categories[$key]."</b></font> 
</td></tr>
"; 
}
}

echo "
</td></tr></table></center> </td></tr></table></td></tr></table>
<p>
".getevent_cl()."
".getlink_topads2()."


<p>
<table width='100%'  bgcolor='$tbclr_2' border=0 cellspacing='0' cellpadding='0'>
<tr><td>
<TABLE  WIDTH='100%'   border='0' cellspacing='1' cellpadding='4' >
<tr><td bgcolor='$tbclr_4'>
 <font FACE='ARIAL, HELVETICA' COLOR='$fntclr_1' size=-1><b>
&nbsp; <a href='index.php?md=editlogin'>".$msg['edit_ad']."</a>
</b></font>

</td></tr></table></td></tr></table>

 
<p>
$top_leftcol
</td>
<td valign='top' bgcolor='$tbclr_4'  > 
  
 <center>
<table width='100%' bgcolor='$tbclr_2' border=0 cellspacing=0 cellpadding=1>
<tr><td> 
<font color='$tbclr_4'> 
&nbsp; <b>".$msg['categories']."</b> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
 ".get_total_count()." ".$msg['ads_t']." 
</font>     
<TABLE  bgcolor='$tbclr_4' border='0' cellspacing=0 cellpadding='0' WIDTH='100%' >
<tr><td>&nbsp; &nbsp; 

";
if (($schopt != '') and ($setctlntp=="yes")){echo "
<font FACE='Verdana, ARIAL, HELVETICA' size=1 style='color:#0000ee; TEXT-DECORATION: underline; cursor: pointer;' 
 OnClick=\"displ('prlc');\"><b>".$msg['choosecity']."  ".$ads_fields[$schopt][0]."</b></font>
";  
}
echo "
 &nbsp; <font FACE='Verdana, ARIAL, HELVETICA' size=1 style='color:#0000ee; TEXT-DECORATION: underline; cursor: pointer;' 
 OnClick=\"displ('schf');\"><b>".$msg['Search']."</b></font>
&nbsp;  <font FACE='Verdana, ARIAL, HELVETICA' size=1 style='color:#0000ee; TEXT-DECORATION: underline; cursor: pointer;' 
 OnClick=\"displ('pstnad');\"><b>".$msg['post_new_ad']."</b></font>
 &nbsp; &nbsp;".print_fav_ads_ind()."
<DIV id=pstnad style='DISPLAY: none'>
".choose_categ()."
</div>
<DIV id=schf style='DISPLAY: none'>
".get_search_form()."
</div>  
";

if ($setctlntp=="yes"){
if ($schopt != ''){print_location();}
echo "
$cityhtml
";
}

echo "<TABLE  border='0' cellspacing=6 cellpadding=10 WIDTH='100%'><tr><td>";
 

$popctgr=""; $divkey1="1";
foreach ($categories as $key => $value)
{
 
  
$aa1=split("_",$key);
if ($aa1[0]=='newcolumn'){echo "</table></td><td valign='top' width='50%'><table width='100%' cellspacing=2 cellpadding=4 >";}
else {
if($aa1[0] == 'title')
{
$ctdv1='th'.$aa1[1];
if ($divkey1!='1'){echo "</table></TD></TR></TABLE><p></div>";}
echo "
<DIV id=$ctdv1 style='DISPLAY: none'>
<TABLE BORDER=0 WIDTH='100%' bgcolor=$tbclr_4 cellspacing=2 cellpadding=0 >
<TR><td  style='BORDER-BOTTOM: $tbclr_2 2px solid;' cellspacing=0 cellpadding=0  >
 
&nbsp;<b>".$categories[$key].":
</b></TD></TR></TABLE><div></div>
<TABLE  border='0'  WIDTH='100%' >
<tr><td valign='top' width='50%'>
<table width='100%' cellspacing=2 cellpadding=4 >
";
$divkey1="0";
}
else{ if (($categories[$key][2] != 'h') and ($key != 'evntcl')) {print_cat_name($key);}}
}
}

echo "</table></TD></TR></TABLE><p></div>";
 

if ($hghltcat!=""){
foreach ($hghltcat as $key => $value)
{
echo " 
<TABLE  WIDTH='100%' bgcolor=$tbclr_4 cellspacing=2  >
<TR><td  style='BORDER-BOTTOM: $tbclr_2 2px solid;' >
&nbsp;<b> $key </b></TD></TR></TABLE>
<TABLE width='100%'><tr><td width='50%' valign='top'>
<table width='100%' cellspacing=2 cellpadding=4 >
";

$popctgr="pc";
foreach ($value as $value2){
if($value2=='new_column'){ echo "</table></td><td width='50%' valign='top'><table width='100%' cellspacing=2 cellpadding=4  >";}
else{print_cat_name($value2);  }
}

echo "</table></td></tr></table>";
}
}
 
echo " </td></tr></table>";
echo "</td></tr></TABLE>
".nb_best_ads()."
</td></tr></TABLE> 

".get_ltop_ads()."

 $btmtophtml
</center></td>$top_rightcol</tr></TABLE></center>
";

echo $html_footer;
exit;
}

function choose_categ()
{ 
global $categories, $msg, $tbclr_1, $fntclr_1;

$vhtml="

<script language='javascript'>
<!--
function addfrmsb(){

if(document.forms['chsct'].elements['ct'].value==''){
alert(\"".$msg['js_choose_corr_cat']."\");
return false; 
}

document.forms['chsct'].submit();
}
--></script>


<table width='100%' bgcolor='$tbclr_1' border=0 cellspacing=0 cellpadding=0 ><tr><td align='right'> <center>
<form action='index.php' name='chsct' method='get' target='_blank'>
<input type='hidden' name='md' value='add_form'>
<font FACE='Verdana, ARIAL, HELVETICA' size=-2 color='$fntclr_1' ><b>".$msg['post_new_ad'].": &nbsp; </b></font><select name='ct' size='1'  class=formst STYLE='font-family: 
Verdana,Geneva,Arial; font-size: 8pt;' onchange=\"addfrmsb();\"  >
<option value=''>".$msg['choose_category']."<checked>
";

foreach ($categories as $key => $value)
{
$aa1=split("_",$key);

if ($aa1[0]== 'title')
{
$vhtml=$vhtml."<option value=''><option value=''>--".$categories[$key]."--";
}

if (($categories[$key][2] != 'h') and ($key != 'evntcl') and ($aa1[0]!= 'title') and ($aa1[0]!= 'newcolumn'))
{
$vhtml=$vhtml."<option value='$key'>".$categories[$key][0];
}
}
$vhtml=$vhtml."</select>
</center></td></tr></table>
</form>
";

return $vhtml;
}

 
function print_cat_name($key)
{
global $categories, $fntclr_1, $msg, $subcnmb, $getcityval,$popctgr;

$dtupd=get_date_update($key);
if ($dtupd!=''){$dtupd=", ".$msg['updated_t'].": ".$dtupd;}
$trgtval="ct".$key;
echo "<tr><td>
&#149;&nbsp; <b><a href='index.php?".$getcityval."ct=$key' >
".$categories[$key][0]."</a></b><br>
&nbsp; <font class='st1'>(".get_cat_count($key)." ".$msg['ads_t']."$dtupd)  
&nbsp; ".print_subcat($key)." </font>
 </td></tr>
";
}


function print_subcat($key)
{
global $categories, $fntclr_1, $msg, $ads_fields, $subcnmb, $getcityval,$popctgr;

if (($categories[$key][2] != 'h') and ($key != 'evntcl') and ($categories[$key][2] != ''))
{

$sctgv='sct'.$popctgr.$key;
$htmlv= " &nbsp;
<font   style='color:#0000ee; TEXT-DECORATION: underline; cursor: pointer;' 
 OnClick=\"displ('$sctgv');\">".$msg['subcategories']."</font>
";

$vr1=split(',',$categories[$key][2]);
$htmlv=$htmlv."<DIV id=$sctgv style='DISPLAY: none'>
<table width='95%' class=st1>";
foreach ($vr1 as $key1){

$ads_fields[$key1][7]=ereg_replace("\n", '', $ads_fields[$key1][7]);
$ads_fields[$key1][7]=ereg_replace("\r", '', $ads_fields[$key1][7]);
$vr2=split('<option>',$ads_fields[$key1][7]);

$htmlv=$htmlv."<tr><td valign='top' width='10%' align='right'>
".$ads_fields[$key1][0].":  
</td><td valign='top' width='90%'>
";

if ($subcnmb=='yes'){$sctnbmass=subctadsnumb($key, $key1);}

$b11='';
foreach ($vr2 as $key2){
if($key2!=''){
if (($subcnmb=='yes') and ($sctnbmass[$key2]=='') ){$sctnbmass[$key2]='(0)';}
$trgtval="sct".$key;
$htmlv=$htmlv."$b11 <nobr><a href='index.php?".$getcityval."ct=$key&$key1=".checkgetfld($key2)."' >$key2</a>".$sctnbmass[$key2]."</nobr>"; $b11=',';

}

}
$htmlv=$htmlv.".</td></tr>";
}
$htmlv=$htmlv."</table><p></div>";
}

return $htmlv;
}

function subctadsnumb($ctg, $fld)
{

global $table_ads, $schopt, $_REQUEST;
if ($_REQUEST[$schopt]!=''){$wrvl="and $schopt='".$_REQUEST[$schopt]."'";};
$sql_query="select $fld, count(idnum) from $table_ads where visible=1 and catname='$ctg' $wrvl group by $fld ";
$sql_res=mysql_query("$sql_query"); 
while ($row = mysql_fetch_row($sql_res))
{$fldn=$row[0];  
$fmass[$fldn]="(".$row[1].")";
}
return $fmass;
}

function print_location()
{
global $ads_fields, $schopt, $tbclr_2, $tbclr_4,$tbclr_1, $msg, $subcnmb;

echo " 
<DIV id=prlc style='DISPLAY: none'><center>
<table  width='95%' bgcolor='$tbclr_2' border=0  cellspacing=0 cellpadding=1>
<tr><td>
&nbsp;<font color='$tbclr_4'><b>".$msg['choosecity']." ".$ads_fields[$schopt][0].": </b></font> 
<table  width='100%' border=0 bgcolor='$tbclr_1' cellspacing=0 cellpadding=2 class='st1'>
<tr><td><p align='justify' style='line-height: 1.4'>
";

$ads_fields[$schopt][7]=ereg_replace("\n", '', $ads_fields[$schopt][7]);
$ads_fields[$schopt][7]=ereg_replace("\r", '', $ads_fields[$schopt][7]);
$vr2=split('<option>',$ads_fields[$schopt][7]);
 
if ($subcnmb=='yes'){$lnbmass=locadsnumb();}

echo "
&nbsp;<a href='index.php?allc=1'>".$msg['all_cities']."</a>
";

foreach ($vr2 as $key2){
if($key2!=''){
if (($subcnmb=='yes') and ($lnbmass[$key2]=='')){$lnbmass[$key2]='(0)';}
echo "  <nobr>&nbsp;<a href='index.php?$schopt=".checkgetfld($key2)."'>$key2</a>".$lnbmass[$key2].",</nobr> ";}
}

echo "
</td></tr></table></td></tr></table></center></div>
";
}

function locadsnumb()
{ 
global $table_ads, $schopt;
 
$sql_query="select $schopt, count(idnum) from $table_ads $wrvl where visible=1 group by $schopt ";
$sql_res=mysql_query("$sql_query"); 
while ($row = mysql_fetch_row($sql_res))
{$loct=$row[0];  $loct=ereg_replace("’", '&#146;', $loct);
$lmass[$loct]="(".$row[1].")";
}
return $lmass;
}


function checkgetfld($value)
{
$value=ereg_replace(' ', '+', $value);
$value=ereg_replace('@', '%40', $value);
$value=ereg_replace('!', '%21', $value);
$value=ereg_replace("'", '%27', $value);
$value=ereg_replace("\"", '%27', $value);

return $value;
}

function getlink_topads2()
{
global $plcntdtl, $plcntpml, $ct, $voterate, $HTTP_GET_VARS, $topcmmnt, $msg,$tbclr_2,$tbclr_4,
$pltopratedln, $pltopcontln, $pltopvisitln;

if (($plcntpml=="yes") and ($pltopcontln=='yes')){$most_cnt="
<a href='index.php?ct=$ct&md=browse&mds=search&adsordtp=pml' >".$msg['top_contacted_ads']."</a>";}

if ($topcmmnt=="yes"){$most_cmmnt="
<a href='index.php?ct=$ct&md=browse&mds=search&adsordtp=cmmnt' >".$msg['top_commented_ads']."</a>";}

if (($plcntdtl=="yes") and ($pltopvisitln=='yes')){$most_vst="
<a href='index.php?ct=$ct&md=browse&mds=search&adsordtp=vis' >".$msg['top_visited_ads']."</a>";}

if (($plcntdtl=="yes") and ($pltopratedln=='yes')){$most_vrt="  
<a href='index.php?ct=$ct&md=browse&mds=search&adsordtp=vote' >".$msg['top_rated_ads']."</a>";}

$res_link="
<table width='100%'  bgcolor='$tbclr_2' border=0 cellspacing='0' cellpadding='0'>
<tr><td> 
 &nbsp; <font color='$tbclr_4'><b>".$msg['top_ads']."</b></font>
<TABLE  WIDTH='100%'   border='0' cellspacing='1' cellpadding='4' >
<tr><td bgcolor='$tbclr_4'>
<center> 
 <TABLE  WIDTH='100%'   border='0' cellspacing='1' cellpadding='2' >
<tr><td>
 <b> $most_vrt </b>  
</td></tr>
<tr><td>
<b> $most_cmmnt </b>
</td></tr>
<tr><td>
<b> $most_cnt </b> 
</td></tr>
<tr><td>
<b> $most_vst  </b> 
</td></tr>
</table></center>
</td></tr></table></td></tr></table>
";
return $res_link;
}

function getevent_cl()
{
global $plcntdtl, $plcntpml, $ct, $voterate, $HTTP_GET_VARS, $topcmmnt, $msg,$tbclr_2,$tbclr_4,
$pltopratedln, $pltopcontln, $pltopvisitln, $categories,$getcityval;

if ($categories['evntcl']!="") {
$res_link="
<table width='100%'  bgcolor='$tbclr_2' border=0 cellspacing='0' cellpadding='0'>
<tr><td> 
 &nbsp; <font color='$tbclr_4'><b>".$msg['events']."</b></font>
<TABLE  WIDTH='100%'   border='0' cellspacing='1' cellpadding='4' >
<tr><td bgcolor='$tbclr_4'>
&nbsp;  <a href='index.php?".$getcityval."ct=evntcl' ><b>".$categories['evntcl'][0]."</b></a> 
   (".get_cat_count('evntcl').") 
</td></tr></table></td></tr></table>
<p>
";
  
} else {$res_link="";}

return $res_link;

}


function get_total_count()
{
global $cat_fields, $table_ads, $ct, $page, $adsonpage, $html_header, 
$html_footer; 
 
$sql_query="select count(idnum) from $table_ads where 
visible=1 ";
if( !($sql_res=@mysql_query("$sql_query")))
{echo $html_header;
echo "
<center>
<font FACE='ARIAL, HELVETICA'  COLOR='#bb0000' size=-1><b>
Error in connecting to ads MySQL table <font color='#000099'>'$table_ads'</font>.
<br> Seems, this table is not created, 
<a href='createtb.php'>click here </a> to create this table.
</b></font></center>
";
echo $html_footer;
exit;
}

$row=mysql_fetch_row($sql_res);
$count=$row[0];
return $count;
}


function get_ltop_ads()
{

global $cat_fields, $table_ads, $ct, $page, $adsonpage, $html_header, 
$html_footer, $tbclr_2, $tbclr_4, $cat_fields, $table_ads,$ct, $page, $adsonpage, 
$ratedads, $plhltads, $HTTP_GET_VARS, $vstminnmbr, $evnt_cat, $adsontoppage,$javastl,
$keyrtt, $msg, $_REQUEST, $numadstop, $schopt; 

$sql_query="select count(idnum) from $table_ads where 
visible=1 and adrate > 9 "; $sql_res=mysql_query("$sql_query"); 
$row=mysql_fetch_row($sql_res); $scount=$row[0];

$thtml=print_layerjavas();

if ($scount>0){
$thtml=$thtml." <p>
<table width='99%' bgcolor='$tbclr_2' border=0 cellspacing=0 cellpadding=1>
<tr><td> 
<font FACE='ARIAL, HELVETICA' color='$tbclr_4' size=-1>
&nbsp; <b>".$msg['sponsored_ads'].":</b>
</font>
</td></tr></table>   
";


$sql_query="select * from $table_ads where visible=1 and adrate > 9 
order by adrate desc, idnum desc ";

#echo "$sql_query"; exit;

$sql_res=mysql_query("$sql_query");
 
$thtml=$thtml.print_tp_ads($sql_res);
}


if ($adsontoppage>0)
{
$htmtads=" <p>
<table width='99%' bgcolor='$tbclr_2' border=0 cellspacing=0 cellpadding=1>
<tr><td> 
<font FACE='ARIAL, HELVETICA' color='$tbclr_4' size=-1>
&nbsp; <b>".$msg['latest_ads1'].":</b>
</font>
</td></tr></table>   
";

if ($_REQUEST[$schopt]!=""){$city_qr=" and city='".$_REQUEST[$schopt]."' ";}
else {$city_qr="";}
$sql_query="select * from $table_ads where visible=1  and ISNULL(replyid) $city_qr 
order by idnum desc limit 0, $adsontoppage";

$sql_res=mysql_query("$sql_query");

$keyrtt=2;
$numadstop=0;
$htmtads=$htmtads.print_tp_ads($sql_res);
}

if ($numadstop>0){$thtml=$thtml.$htmtads;}
return $thtml;

}

function print_tp_ads($sql_res)
{
global $tbclr_1, $tbclr_4, $tbclr_2, $fntclr_1, $tbclhlads, 
$coltblayer, $keyrtt, $numadstop, $use_gl_map, $clmnmap, $msg;
$html_ads="
<table width='99%'  border=0 cellspacing=2 cellpadding=2>
";
$key1=0;
while ($row = mysql_fetch_array ($sql_res))
{
  $numadstop=1;
$capt1_hltads="";
$coltblayer=$tbclr_2;
if($row['adrate']>0)
{
$colr1_hltads=$colr_hltads;
$capt1_hltads=$capt_hltads;
$coltblayer=$tbclhlads;
}
if ($key1==0){$key1=1; $bgcol=$tbclr_4;}
else {$key1=0; $bgcol=$tbclr_1;}
$time1=$row['time'];
$ad_date=get_short_date($time1);
$idnum=$row['idnum'];

if ($row['adphotos']=="yes"){$pic_title="<font size=-2 color=$fntclr_1>".$msg['pictvl']."</font>";}
else{$pic_title="<font size=-2 color=$fntclr_1>-</font>";}

$ad_entry="
<tr><td bgcolor='$bgcol' width=70%>&nbsp;<b> ".$row['replyid']."
<a href='index.php?ct=$ctval&md=details&id=$idnum' 
 title='#$idnum' ".print_layerlink($idnum).">
".$row['title']."</a></b> ".print_layerads($row)." 
</td><td bgcolor='$bgcol' align='center'>
<nobr>".$row['city']."</nobr> 
</td><td align='center' bgcolor='$bgcol'>
<nobr>$ad_date</nobr>
</td><td width='10' bgcolor='$bgcol' align=center>
$pic_title
</td>
 
";

if ($use_gl_map=='yes' and  $clmnmap=='yes'){

$ad_entry=$ad_entry."
<td width='10' bgcolor='$bgcol' align=center> 
<font FACE='ARIAL, HELVETICA' size='-2' $colr1_hltads>
<nobr>".adsjsp($row['addrmap'],$idnum)."</nobr>
</font> 
</td>
";
}

$ad_entry=$ad_entry."</tr>";

if (($keyrtt==2) and ($row['adrate']>9)) {$ad_entry="";}
$html_ads=$html_ads.$ad_entry;
} 
$html_ads=$html_ads."</table>";

return $html_ads;
}


?>