<?
require("config.php");
require("mb_conf.php");
require("mb_fn1.php");

$msgs_fl="msg1_".$intlang.".php"; require("$msgs_fl");
$msgs_fl="msg2_".$intlang.".php"; require("$msgs_fl");
 
$html_header=$mbhtml_header;
$html_footer=$mbhtml_footer;
$adsonpage=$mbadsonpage;
$ad_second_width=$mbad_second_width;
$ad_ind_width=$mbad_ind_width;

$cat_fields=$mb_fields;
start();

if ($pscmd=="sc") 
{
if($admpassw1 != $adm_passw){
$inc_passw="incorrect password !"; 
printpasswordform1($inc_passw);
exit;
}
setcookie("admcookpassw", $admpassw1);
$admcookpassw= $admpassw1;
}

if($admcookpassw != $adm_passw){
if ($admcookpassw != ""){
$inc_passw= "Incorrect password or cookies does not work"; 
}
printpasswordform1($inc_passw);
exit;
}

 
if (($md=="browse") or ($md=="")){browse_ads();} 
if ($md=="details"){include("mb_det.php"); ad_details();} 
if ($md=="add_form") {include("mb_forms.php"); print_add_form();} 
if ($md=="editlogin"){ include("mb_forms.php"); edit_login(" ");}
if ($md=="editform"){ include("mb_forms.php");   edit_form();}
if ($md=="submitad") {include("mb_subm.php"); submit_ad();}
if ($md=="edit") {include("mb_subm.php"); edit_ad();}

 
function  printpasswordform1($inc_passw)
{
global $html_header, $html_footer;

echo $html_header; 
echo "
<center>
<table width='500' bgcolor='#dddddd' border=0 cellspacing=0 cellpadding=1>
<tr><td> 
<font FACE='ARIAL, HELVETICA' >
<center><b> Admin Interface </b></center> 
</font>
</td></tr></table>
<p>
<font FACE='ARIAL, HELVETICA' COLOR='#990000'  >
<b> $inc_passw </b>
</font>
<p>
<form action='mbind.php?pscmd=sc' method='post'>
<font FACE='ARIAL, HELVETICA' COLOR='#000099' size='-1'>
<b>
Input admin password : </b></font>
<input type='text' name='admpassw1'>
<input type='submit' value='Submit'>
</form>
<font FACE='ARIAL, HELVETICA' COLOR='#000099' size='-2'>
<br><b>(Cookies must be set up)
 </b></font>
 
<p>
<hr size=1 width='500'>
</center>
";
echo $html_footer;
exit;
}

function browse_ads()
{
global $ads_count, $html_header, $html_footer, $ct, $mds, 
$categories, $ad_ind_width, $text_userinfo, $cat_fields;
echo $html_header;

if ($mds=="search") 
{$count_info="<font color='#aa0000'>$ads_count ads match your query</font>";}
else {$count_info="$ads_count entries";}  
echo "

<font FACE='ARIAL, HELVETICA' COLOR='#000099' font size='-1'><b>
<a href='mbadm.php'>Top:</a>
</b></font>
<table width='$ad_ind_width'  bgcolor='#dddddd' border=0 cellspacing='0' cellpadding='0'>
<tr><td> 

<TABLE  WIDTH='100%'   border='0' cellspacing='1' cellpadding='0' >
<tr><td bgcolor='#ffffff'> 
<font FACE='ARIAL, HELVETICA' COLOR='#000099'><b>
Membership Database
</b></font> 
<TABLE BORDER=0 COLS=1 WIDTH='100%' bgcolor='#ddeedd' 
border=0 cellspacing=0 cellpadding=0>
<TR>
<TD width='33%' height='16'>
<FONT FACE='Verdana,Geneva,Arial' SIZE=1>
".pages_next_prev()."&nbsp;

</font>
</td><td align='center' width='33%'>
<FONT FACE='Verdana,Geneva,Arial' SIZE=1>
$count_info 
</td><td align='right' width='33%'>
&nbsp;
";
 
echo "
<FONT FACE='Verdana,Geneva,Arial' SIZE=1>
[<a href='mbind.php?ct=$ct&md=add_form' >Submit new member</a>]
</font>
";

echo "
</td></tr></table>
</td></tr>
</table>
</td></tr>
</table>
 
<table width='$ad_ind_width'  bgcolor='#dddddd' border=0 cellspacing=0 cellpadding=0>
<tr><td>
<table width='100%'  border=0 cellspacing=1 cellpadding=1>
".get_ads_captions().get_ads()."
</table> 
</table> 
<table width='$ad_ind_width' bgcolor='#ddeedd' border=0 cellspacing=0 cellpadding=0>
<tr><td>
<FONT FACE='Verdana,Geneva,Arial' SIZE=1>
".ads_pages_list()."
 </font></td>
</td></tr></table>
<br>
<table width='$ad_ind_width' bgcolor='#ffffff' border=0 cellspacing=0 cellpadding=0>
<tr><td>
".get_search_form()."
</td></tr>
</table>
 
 
 
</center>
";

echo $html_footer;
exit;
}

function get_search_form()
{
global $cat_fields, $ct, $HTTP_GET_VARS, $bgschcol ;

foreach ($HTTP_GET_VARS as $key2 => $value2 )
{
$HTTP_GET_VARS[$key2]=stripslashes($HTTP_GET_VARS[$key2]);
$HTTP_GET_VARS[$key2]=ereg_replace('\'', '&#039;', $HTTP_GET_VARS[$key2]);
}
$bgschcol='#eeeeee';
if ($HTTP_GET_VARS['onlywithphoto']=='yes'){$onlyphocheck="checked";}
 $srch_html=$srch_html."
<table width='100%' border=0 cellspacing=0 cellpadding=0><tr><td> 
<FORM action='mbind.php' method='get'> 
<input type='hidden' name='ct' value='$ct' >
<input type='hidden' name='md' value='browse'>
<input type='hidden' name='mds' value='search'>
<table  width='100%' bgcolor='#dddddd' border=0  cellspacing=1 cellpadding=1>
<tr><td>
<font FACE='ARIAL, HELVETICA' COLOR='#000099' size='-1'>
<b> Search: </b> </font>
<table  width='100%' border=0  cellspacing=1 cellpadding=2>
<tr><td bgcolor='$bgschcol'>
<font FACE='ARIAL, HELVETICA' COLOR='#000099' size='-2'>
<b>Keyword:</b>
</font>
</td><td bgcolor='$bgschcol'>
<font FACE='ARIAL, HELVETICA' COLOR='#000099' size='-1'>
<input type='text' name='brief_key'  value='".$HTTP_GET_VARS['brief_key']."' size=15 STYLE='font-family: 
Verdana,Geneva,Arial; font-size: 8pt;' >
</font>
</td>
<td bgcolor='$bgschcol' colspan='2' >
<font FACE='ARIAL, HELVETICA' COLOR='#000099' size='-2'>
<b>Only  for last 
<select name='before' STYLE='font-family: 
Verdana,Geneva,Arial; font-size: 8pt;'>
<option>".$HTTP_GET_VARS['before']."<checked><option><option>1<option>3<option>5<option>10<option>20<option>40<option>60<option>100</select>
days &nbsp; 
</b></font> </td></tr>
";
$s346='0';
foreach ($cat_fields as $keysch => $value )
{
if (($cat_fields[$keysch][2] == 'keyword') or ($cat_fields[$keysch][2] == 'minmax'))
{
if($s346 != '1')
{ 
$s346='1';
$srch_html=$srch_html."<TR><TD bgcolor='$bgschcol' VALIGN=TOP>";
$srch_html=$srch_html.print_sch_field($keysch);
$srch_html=$srch_html."</TD>\n";
}
else
{ $s346='0';
$srch_html=$srch_html."<TD bgcolor='$bgschcol'  VALIGN=TOP>";
$srch_html=$srch_html.print_sch_field($keysch);
$srch_html=$srch_html."</TD></TR>\n";
}
}
 
}
if($s346 == '1'){ 
$srch_html=$srch_html."<td bgcolor='$bgschcol' colspan=2>.</TD></TR>";
}
$srch_html=$srch_html."
</table> 
</td></tr></table>
";

$srch_html=$srch_html."
<font FACE='ARIAL, HELVETICA' COLOR='#000099' size='-2'>
<INPUT type='submit' value=' Search ' STYLE='font-family: 
Verdana,Geneva,Arial; font-size: 8pt;'>
<font FACE='ARIAL, HELVETICA' COLOR='#0000aa' size='-2'>
<b> If search field is empty it means any value
of this field matches query  
  </b>
</font>
</FORM>
</td></tr></table>
";
if ($HTTP_GET_VARS['idemail']!="") {$srch_html="";}
return  $srch_html;
}


function print_sch_field($keysch)
{
global  $cat_fields, $HTTP_GET_VARS,$bgschcol;

if ( ( $cat_fields[$keysch][4] == 'select') and ($cat_fields[$keysch][2] == 'keyword'))
{ 
 $srch_html=$srch_html."
<font FACE='ARIAL, HELVETICA' COLOR='#000099' size='-2'>
<b>".$cat_fields[$keysch][0].":</b>
</font>
</td><td bgcolor='$bgschcol'>
<font FACE='ARIAL, HELVETICA' COLOR='#000099' size='-2'>
<select name='$keysch' size='".$cat_fields[$keysch][0]."'  STYLE='font-family: 
Verdana,Geneva,Arial; font-size: 8pt;'>
<option>".$HTTP_GET_VARS[$keysch]."<checked>
<option>".$cat_fields[$keysch][7]."</select>
</font>
";
}

if ( ( $cat_fields[$keysch][4] == 'checkbox') and ($cat_fields[$keysch][2] == 'keyword'))
{ 
 $srch_html=$srch_html."
<font FACE='ARIAL, HELVETICA' COLOR='#000099' size='-2'>
<b>".$cat_fields[$keysch][0].":</b>
</font>
</td><td bgcolor='$bgschcol'>
<font FACE='ARIAL, HELVETICA' COLOR='#000099' size='-2'>
<select name='$keysch' size='".$cat_fields[$keysch][0]."'  STYLE='font-family: 
Verdana,Geneva,Arial; font-size: 8pt;'>
<option>".$HTTP_GET_VARS[$keysch]."<checked>
<option>".$cat_fields[$keysch][7]."</select>
</font>
";
}


if ( ( ($cat_fields[$keysch][4] == 'text') or ($cat_fields[$keysch][4] == 'textarea'))

 and ($cat_fields[$keysch][2] == 'keyword'))
{  
$srch_html=$srch_html."
<font FACE='ARIAL, HELVETICA' COLOR='#000099' size='-2'>
<b>".$cat_fields[$keysch][0].":</b>
</font>
</td><td bgcolor='$bgschcol'>
<font FACE='ARIAL, HELVETICA' COLOR='#000099' size='-2'>
<input type='text' name='$keysch' size=15 value='".$HTTP_GET_VARS[$keysch]."' 
STYLE='font-family: Verdana,Geneva,Arial; font-size: 8pt;'>
</font>
";
}

if ( ($cat_fields[$keysch][4] == 'text') and ($cat_fields[$keysch][2] == 'minmax'))
{
$flmin=$keysch.'1';
$flmax=$keysch.'2';
$srch_html=$srch_html."
<font FACE='ARIAL, HELVETICA' COLOR='#000099' size='-2'>
<b>".$cat_fields[$keysch][0].":</b>
</font>
</td><td bgcolor='$bgschcol'>
 <font FACE='ARIAL, HELVETICA' COLOR='#000099' size='-2'>
min:<input type='text' name='$flmin' size='5' value='".$HTTP_GET_VARS[$flmin]."' STYLE='font-family: 
Verdana,Geneva,Arial; font-size: 8pt;' >
max:<input type='text' name='$flmax' size='5' value='".$HTTP_GET_VARS[$flmax]."' STYLE='font-family: 
Verdana,Geneva,Arial; font-size: 8pt;'>
</font>
";
}

 
return  $srch_html;
}


function get_ads_captions()
{

global $cat_fields, $ads_count, $ct, $photos_count, $incl_prevphoto;
$bgcol21="#eeeeee";
$bgcol22="#aa0000";

$captions="<tr>";

$captions=$captions."
<td align='center' bgcolor='$bgcol21' width='2%'>
<font FACE='ARIAL, HELVETICA'  COLOR='$bgcol22' size=-2>
<b>ID</b>
</font>
</td>
<td align='center' bgcolor='$bgcol21' width='7%'>
<font FACE='ARIAL, HELVETICA'  COLOR='$bgcol22' size=-2>
<b>Posted</b>
</font>
</td>
<td align='center' bgcolor='$bgcol21' width='7%'>
<font FACE='ARIAL, HELVETICA'  COLOR='$bgcol22' size=-2>
<b>Expire</b>
</font>
</td>
";

foreach ($cat_fields as $key => $value)
{
$ik++;
if (ereg('1', $cat_fields[$key][1]))
{
$captions=$captions." 
<td align='center' bgcolor='$bgcol21'>
<font FACE='ARIAL, HELVETICA'  COLOR='$bgcol22' size=-2>
<b> ".$cat_fields[$key][0]."</b>
 </font>
 </td>
";
}
}

$captions=$captions."
<td align='center' bgcolor='$bgcol21'>
<font FACE='ARIAL, HELVETICA'  COLOR='$bgcol22' size=-2>
Member's ads
</font>
</td>
<td align='center' bgcolor='$bgcol21'>
<font FACE='ARIAL, HELVETICA'  COLOR='$bgcol22' size=-2>
Details
</font>
</td>
</tr>
";



 

if($ads_count == 0) $captions="";
return $captions;
}

function print_ad ($row)
{
global $cat_fields, $photos_count, $ct, $categories, $incl_prevphoto,
$previewphoto_url, $previewphoto_path, $prphotolimits, $pr_lim_height, $pr_lim_width;
$row=check_row($row);
$html_ad="<tr>";
$time1=$row['time'];
$time2exp=$row['exptime'];
$ad_date=get_short_date($time1);
$ad_expdate=get_short_date($time2exp);
$idnum=$row['idnum'];

$ctval=$ct;

$html_ad=$html_ad."
 <td bgcolor='#ffffff'  align='center' width='5%'>
<font FACE='ARIAL, HELVETICA' size='-2'  >
<b>$idnum</b></font> </td>
<td bgcolor='#ffffff'  align='center' width='7%'> 
<font FACE='ARIAL, HELVETICA' size='-2'>
<b>$ad_date </b>
</font>
</td>
<td bgcolor='#ffffff'  align='center' width='7%'> 
<font FACE='ARIAL, HELVETICA' size='-2'>
<b>
$ad_expdate
</b>
</font>
</td>
";


foreach ($cat_fields as $key => $value) 
{
if (ereg('1', $cat_fields[$key][1]))
{
if ($key == 'title'){$html_ad=$html_ad."
<td bgcolor='#ffffff' valign='center' width='40%'>
<font FACE='ARIAL, HELVETICA' size='-1'>
<b>$row[$key]</b>  </font></td>";}
else {
$html_ad=$html_ad."
<td bgcolor='#ffffff' align='center'>
<font FACE='ARIAL, HELVETICA' size='-1'>
$row[$key]  </font></td>";}
}

}


$html_ad=$html_ad."
<td bgcolor='#ffffff' align='center'  > 
<font FACE='ARIAL, HELVETICA' size='-1'>
<a href='index.php?md=browse&mblogin=".$row['login']."&visunvis=1' target='all".$row['idnum']."'>
Ads(".getmbadsnum($row['login']).")</a>
</font>
</td>
<td bgcolor='#ffffff' align='center' width='2%'> 
<font FACE='ARIAL, HELVETICA' size='-2'>
<a href='mbind.php?ct=$ctval&md=details&id=$idnum'>
<b>Details</b></a>
</font>
</td></tr>
";
 
return $html_ad;
}

function check_row($row)
{
global $cat_fields, $select_text,$real_format;
foreach ($cat_fields as $key => $value) 
{
if (($row[$key]=="") or ($row[$key]==$select_text) or ($row[$key]=='http://')
or ($row[$key]=='NULL') or ($row[$key]=='null')) 
{$row[$key]="--";}
else {
if ($cat_fields[$key][6]=='real') {$row[$key]=sprintf($real_format, $row[$key]);}
}
}
return $row;
}
?>