<?

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,$btmtophtml,
$top_bottom,$getcityval, $popctgr, $top_rightcol, $tmltads, $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)."&";
 
}

if ($_REQUEST[$schopt]!=""){$ltstcityv="&city=".checkgetfld($_REQUEST[$schopt]);}
else{$ltstcityv="";}

get_tm_tags($titleclpg,"");
echo $html_header;
echo "
$javastl

<center>
 <table width='$top_page_width' bgcolor='$tbclr_4' border=0 cellspacing=1 cellpadding=1 >
<tr>
<td width='150' bgcolor='$tbclr_1'  valign='top'>
<p>
".getlink_topads2()."
 

".getevent_cl()."

<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>
 
<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='BLACK'  size=-1>
&nbsp;  <a href='index.php?ct=&md=browse&mds=search&before=$tmltads".$ltstcityv."' >  
<b>".$msg['latest_ads1']." </b></font>
</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> 
<TABLE  border='0' cellspacing=0 cellpadding=0 WIDTH='100%'><tr><td> 
<font FACE='ARIAL, HELVETICA' color='$tbclr_4' size=-1>
&nbsp; <b>".$msg['categories']."</b>
 
</font> 
</td><td align=right valign=center>
<font FACE='ARIAL, HELVETICA' color='$tbclr_4' size=-1 >
".get_total_count()." ".$msg['ads_t']." 
&nbsp; &nbsp; &nbsp;
</font>
&nbsp; <font FACE='ARIAL, HELVETICA' size=-1 style='color:#ffffff; TEXT-DECORATION: underline; cursor: pointer;' 
 OnClick=\"displ('schf');\"><b>".$msg['Search']."</b></font>
&nbsp;  <font FACE='ARIAL, HELVETICA' size=-1 style='color:#ffffff; TEXT-DECORATION: underline; cursor: pointer;' 
 OnClick=\"displ('pstnad');\"><b>".$msg['post_new_ad']."</b></font>
&nbsp;&nbsp;
</td></tr></table>      
<TABLE  bgcolor='$tbclr_4' border='0' cellspacing=0 cellpadding='0' WIDTH='100%' >
<tr><td>
 &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>  
$cityhtml
 <center>

<TABLE  bgcolor='$tbclr_4' border='0' cellspacing=4 cellpadding='4' WIDTH='100%' >
<tr><td valign=top width='33%'>
";

$popctgr=""; $divkey1="1"; $kvl1="0";
foreach ($categories as $key => $value)
{
 
$aa1=split("_",$key);
if ($aa1[0]=='newcolumn'){$kvl1="0"; echo "</font></TD></TR></table></td><td valign=top width='33%'>";}
else {
if($aa1[0] == 'title')
{
$ctdv1='th'.$aa1[1];
 
if($kvl1=="0"){$kvl1="1";} else { echo " </font></TD></TR></table><p>";}
echo "
<TABLE BORDER=0 WIDTH='95%' bgcolor=$tbclr_4 cellspacing=0 cellpadding=0 >
<TR><td  style='BORDER-BOTTOM: $tbclr_2 2px solid;' cellspacing=0 cellpadding=0  >
<font FACE='ARIAL, HELVETICA' size=-1 color='$fntclr_1' >
&nbsp;<b>".$categories[$key].":
</b></font></TD></TR><tr><td> 
<font FACE='ARIAL, HELVETICA' size=-1 color='$fntclr_1' style='line-height: 1.7' >

";
}else 
{
if($kvl1=="0"){$kvl1="1"; 
echo "
<TABLE BORDER=0 WIDTH='95%' bgcolor=$tbclr_4 cellspacing=0 cellpadding=0 ><tr><td>
<font FACE='ARIAL, HELVETICA' size=-1 color='$fntclr_1' >
<p style='line-height: 1.7'>
";
}
if (($categories[$key][2] != 'h') and ($key != 'evntcl')){print_cat_name($key);}
 
}

}
}

echo "</font></TD></TR></TABLE> </TD></TR></TABLE>  </center>&nbsp;<br>";
echo "</td></tr></TABLE>
".nb_best_ads()."  
</td></tr></TABLE>    
</center></td>
";

if ($setctlntp == 'yes'){

echo "<td width='200' valign=top bgcolor='$tbclr_1'>";

if ($schopt != ''){print_location();}

echo "</td>";

}


echo "
</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' >
<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 "
 <nobr><a href='index.php?".$getcityval."ct=$key'   title='$dtupd'>
".$categories[$key][0]."</a> <font size=-2><b>(".get_cat_count($key).")</b></font></nobr> <br>

";
}


function print_location()
{
global $slctcntr,  $HTTP_GET_VARS, $ads_fields,$choosecntr ;
if ($slctcntr=='yes'){print_location2();}
else{print_location1();}
}


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

echo " 
<center>
<table  width='100%'  border=0 bgcolor='$tbclr_2' cellspacing=0 cellpadding=1>
<tr><td>
<font FACE='ARIAL, HELVETICA' COLOR='$tbclr_4' size='-1'>
&nbsp;<b>".$msg['choosecity']." ".$ads_fields[$schopt][0].": </b> </font>
<table  width='100%' border=0 bgcolor='$tbclr_1' cellspacing=0 cellpadding=2>
<tr><td><p style='line-height: 1.8' align='justify'><font FACE='ARIAL, HELVETICA' size=-2><b>
";

$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'><b>".$msg['all_cities']."</b></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 "
</b></font></td></tr></table></td></tr></table></center>
";
}

function print_location2()
{
global $HTTP_GET_VARS, $ads_fields, $adrghtcol,$fslct, $adrghtcol, $choose_one1, 
$choosecntr, $citdrdwn ;
 
$fld3v=$ads_fields['country'][7];

$chckvll=$choosecntr; if($HTTP_GET_VARS['country']!="")
                       {$chckvll=$HTTP_GET_VARS['country']; $chckvll2=$chckvll; $divval='block';}
                       else{$divval='none';}

$dflt_value=$HTTP_GET_VARS['city'];
if ($citdrdwn=='yes'){$ifheight=40; $scrlvl="no";}else{$ifheight=450; $scrlvl="auto";} 
echo "
<script language='JavaScript'><!--
 function displ2(nmdiv){if (document.getElementById){
if (document.getElementById(nmdiv).style.display=='none') document.getElementById(nmdiv).style.display ='block';
 } else if (document.all) { if(document.all[nmdiv].style.display=='none') document.all[nmdiv].style.display ='block';}}
--></script>
 <form action='index.php' method='GET' name='ctcity'>
&nbsp;<select name='country' size='".$ads_fields['country'][0]."' class=formst STYLE='font-family: 
Verdana,Geneva,Arial; font-size: 9pt; FONT-WEIGHT: bold;'  
onChange=\"document.getElementById('f$fld3v').src='index.php?md=slct3&fld=country&fld3=$fld3v&vl='+this.value; displ2('cts1');\"
>
<option value='$chckvll2'>$chckvll<checked>".sllist2('country')."</select>
</font>
<input type='hidden' name='city' id='tcity' value=''> 
<DIV id=cts1 style='DISPLAY: $divval'>
<iframe src='index.php?md=slct3&fld=".$ads_fields['city'][7]."&fld3=city&dvalue=$dflt_value&vl=$chckvll' id='fcity' frameborder=0   scrolling=$scrlvl
marginwidth='0' marginheight='0'  height='$ifheight' width='100%'></iframe>
</div>
</form>
$adrghtcol
";

}


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> 
<font FACE='ARIAL, HELVETICA' color='#ffffff' size='-1'>
 &nbsp;  <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>
<font FACE='ARIAL, HELVETICA' COLOR='BLACK'  size=-1>
   $most_vrt   </font>
</td></tr>
<tr><td>
<font FACE='ARIAL, HELVETICA' COLOR='BLACK'  size=-1>
  $most_cmmnt  </font>
</td></tr>
<tr><td>
<font FACE='ARIAL, HELVETICA' COLOR='BLACK'  size=-1>
  $most_cnt  </font>
</td></tr>
<tr><td>
<font FACE='ARIAL, HELVETICA' COLOR='BLACK'  size=-1>
  $most_vst   </font>
</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= "
<p>
<table width='100%'  bgcolor='$tbclr_2' border=0 cellspacing='0' cellpadding='0'>
<tr><td> 
 &nbsp; <font FACE='ARIAL, HELVETICA'  size='-1'  color='$tbclr_4'><b>".$msg['events']."</b></font>
<TABLE  WIDTH='100%'   border='0' cellspacing='1' cellpadding='4' >
<tr><td bgcolor='$tbclr_4'>
<font FACE='ARIAL, HELVETICA' COLOR='BLACK'  size=-1>
&nbsp;  <a href='index.php?".$getcityval."ct=evntcl' ><b>".$categories['evntcl'][0]."</b></a> 
<font size=-2>  <b> (".get_cat_count('evntcl').") </b></font>
</font>
</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;
}

?>