<?
require("mb_conf.php");
require("config.php");
require("mb_fn1.php");
require("mb_subm.php");
$msgs_fl="msg1_".$intlang.".php"; require("$msgs_fl");
$msgs_fl="msg2_".$intlang.".php"; require("$msgs_fl");

 
foreach ($mbfld_lst as $mbfld11)
{ 
$cat_fields[$mbfld11]=$mb_fields[$mbfld11];
}

start();  

check_mblgprf("");

if ($md=='mbactivate'){mb_activate();}

if ($md=="") {edit_form();}
if ($md=="editmba"){editmba();}

function check_mblgprf($md_type)
{
global $ct, $categories, $subscr_url, $cook_login, 
$cook_passw, $f_login, $f_passw, $table_mb, $ch_numtp,
$mb_checktime, $mb_max_nads;

if ($f_login!='')
{
$cook_login=$f_login; 
$cook_passw=$f_passw;
}

if ($cook_login==''){printmblogf2($md_type,'');}
else {check_mb_logp1($cook_login,$cook_passw,$md_type);}
setcookie("cook_login", $cook_login);
setcookie("cook_passw",$cook_passw);
}

function check_mb_logp1($cook_login,$cook_passw,$md_type)
{
global $subscr_url, $cat_fields, $table_mb, $ct, $categories, $msg2; 
 
$sql_query="select count(*) from $table_mb where 
login='$cook_login' and passw='$cook_passw' and visible=1";
$sql_res=mysql_query("$sql_query");
$row=mysql_fetch_row($sql_res);
$count1=$row[0];
if ($count1 < 1)
{
$inc_passw="
<font FACE='ARIAL, HELVETICA' color='#880000' size='+1'>
<b>".$msg2['Incorrect_membership_nick']."</b>
</font>
";
printmblogf2($md_type,$inc_passw);
}

}

function printmblogf2($md_type,$mssg1)
{
global $subscr_url, $cook_login, $cook_passw, $html_header, $html_footer, $categories, $ct, $tbclr_1, $tbclr_2, $tbclr_3, $tbclr_4, $fntclr_1, $msg, $msg2;

echo "
$html_header
<center>
<table width='500' bgcolor='$tbclr_2' border=0 cellspacing=1 cellpadding=0><tr>
  <td valign='top'>
<TABLE WIDTH='100%'  border=0 BGCOLOR='#ffffff' 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='#eeeeee'>
<font FACE='ARIAL, HELVETICA' color='#000088' size=+1>
&nbsp;&nbsp; <b>".$msg2['view_edit_mb_profile']."</b></font>
</td>
</tr>
</table>
<p>
<font FACE='ARIAL, HELVETICA' color='#000088' size=+1>
$mssg1
</font>
<p>
 
<form action='mbprf.php' method='post'>
<table width='100%'>
<tr><td width='50%'>
<table>
<tr><td>
<font FACE='ARIAL, HELVETICA' color='#000088' size=-1>
<b>".$msg2['Nickname_mbe'].":</b>
</font>
</td><td>
<input type='text' name='f_login' size='15' value='$cook_login' class=formst>
</td></tr>
<tr><td>
<font FACE='ARIAL, HELVETICA' color='#000088' size=-1>
<b>".$msg2['Password_mbe'].":</b>
</font>
</td><td> 
<input type='password' name='f_passw' size='15' value='$cook_passw' class=formst>  
</td></tr></table>
<input type='submit' value='".$msg2['Submit_mbe']."' 
class=formst STYLE='FONT-WEIGHT: bold;'>
</form>

</td><td width='50%' valign='top'>
<center>
<font FACE='ARIAL, HELVETICA' color='#000088' size='-1'>

 
<a href='index.php?md=forgmbpassw'>".$msg2['Forgot_mb_password']."</a>
</font>
</center>
</td></tr></table>

</td></tr></table>
</td></tr></table>
</center> 
<p>

";
echo $html_footer;
exit;
}

function get_edit_mbi($cook_login, $cook_passw)
{
global $cat_fields, $table_mb;
$sql_query="select * from $table_mb where login='$cook_login' and passw='$cook_passw'";
$sql_res=mysql_query("$sql_query");
$row = mysql_fetch_array ($sql_res);

foreach ($row as $key => $value)
{
$row[$key]=ereg_replace("'", "&#039;", $row[$key]);
}
return $row; 
}

 function edit_form()
{
global $fields_val, $ed_id, $edit_delete, $ed_passw, $rightform_html, 
$html_edit_form, $adm_passw, $admcookpassw, $cat_fields, $ct, $categories,
$fields_sets, $mb_fields, $cook_login, $cook_passw;

$fields_val=get_edit_mbi($cook_login, $cook_passw);
if ($fields_val['idnum']=="") {echo "No ads with ID# $ed_id"; exit;}
 
 
$rightform_html=$html_edit_form;

 
$ct=$fields_val['catname'];
$a1=$categories[$ct][1];
$a2=$mb_fields;
 
foreach ($a2 as $a2_value => $value_k )
{
if ($cat_fields[$a2_value][4]=="checkbox")
{
$aa5=split('<option>',$cat_fields[$a2_value][7]);
$i_aa5=0;
foreach ($aa5 as $value1)
{
$i_aa5++;
$namechbx=$a2_value.$i_aa5;
if (($value1!="") and (ereg($value1,$fields_val[$a2_value])))
{$fields_val[$namechbx]="checked";}

}
}
}
ad_form("edit");
}

 
function ad_form($ed_add)
{
global $html_header, $html_footer, $cat_fields, $fields_val, $ct, 
$photos_count, $ed_id, $ed_passw, $exp_period, $rightform_html, 
$select_text, $categories, $phptomaxsize, $incl_prevphoto, $prviewphotomax,
 $prphotolimits, $pr_lim_height, $pr_lim_width, $incl_mtmdfile, $multim_link,
$multim_ext, $mtmdfile_maxs, $ad_ind_width,
 $tbclr_1, $tbclr_2, $tbclr_3, $tbclr_4, $fntclr_1, $feembshp, $msg, $msg2;

 
$time1=$fields_val['time'];
$date_posted=get_date($time1); 

 

if ($ed_add=="submitad") { $title_inf="Place New Ad";}
if ($ed_add=="edit") { $title_inf="Edit Ad ( ID# ".$fields_val['idnum'].") ";}
echo $html_header;

$tbl_col=$tbclr_4;
$td_height='10';

$expdateinfo="";
if ($feembshp=='yes') {
$time2=$fields_val['exptime'];
$date_exxpp=get_date($time2); 
$expdateinfo="
<tr>
<td bgcolor='$tbl_col' height='$td_height' width='30%' >
<font FACE='ARIAL, HELVETICA' COLOR='#000099' size='-1'> 
".$msg2['Expire_date_m'].":          
</font>
</td><td bgcolor='$tbl_col' width='70%'>
<font FACE='ARIAL, HELVETICA' COLOR='#000099' size='-1'>
 &nbsp; $date_exxpp 
</font>
</td></tr>
";

}
echo "
<p>
<center> 
<table   ><tr><td valign='top'>

<font FACE='ARIAL, HELVETICA' COLOR='BLACK'> <font size=-1>
<b><a href='index.php'>".$msg['top'].":</a></b></font>
&nbsp; 
 
<hr size='1'>
<font FACE='ARIAL, HELVETICA' COLOR='#000099'> <b> 
 ".$msg2['View_edit_mb_profile']." </b> </font>
<form action='mbprf.php?md=editmba' method='post' >
<input type='hidden' name='mbprf_login' value='".$fields_val['login']."'>
<input type='hidden' name='mbprf_passw' value='".$fields_val['passw']."'>
<input type='hidden' name='ed_id' value='".$fields_val['idnum']."'>
<table   width='550' border=0 bgcolor='$tbclr_2' cellspacing=1 cellpadding=0>
<tr><td>
<table width='100%' border=0 cellspacing=1 cellpadding=1>
<tr>
<td bgcolor='$tbl_col' height='$td_height' width='30%' >
<font FACE='ARIAL, HELVETICA' COLOR='#000099' size='-1'> 
".$msg2['Date_Posted_m'].":          
</font>
</td><td bgcolor='$tbl_col' width='70%'>
<font FACE='ARIAL, HELVETICA' COLOR='#000099' size='-1'>
 &nbsp; $date_posted  
</font>
</td></tr> $expdateinfo
<tr><td bgcolor='$tbl_col'>
<font FACE='ARIAL, HELVETICA' COLOR='#000099' size='-1'>
 <b> ".$msg2['Nickname_mbe'].":</b>
  </font>
</td><td bgcolor='$tbl_col'>
<font FACE='ARIAL, HELVETICA' COLOR='#000099' size='-1'>
 &nbsp;<b> ".$fields_val['login']."</b>
</td></tr>
";



foreach ($cat_fields as $key => $value )
{
if ($key!='login')
{
if (ereg ('url',$key))
{
if ($fields_val[$key]==""){$fields_val[$key]="http://";}
}

if ($cat_fields[$key][5] == '1')
{$cat_fields[$key][0]=$cat_fields[$key][0]."<font color='#cc0000'>* </font>";}

if ($cat_fields[$key][4] == 'select')
{
$aa4=split(':',$cat_fields[$key][3]);
$t_size=$aa4[0];
$t_max=$aa4[1];
if ($fields_val[$key]!=""){$select_text1=$fields_val[$key];}
else {$select_text1=$select_text;}
echo "
<tr>
<td height='$td_height' bgcolor='$tbl_col' >
<font FACE='ARIAL, HELVETICA' COLOR='#000099' size='-1'>
".$cat_fields[$key][0].":
</font>
</td><td bgcolor='$tbl_col'>
<select name='$key' size='$t_size' class=formst>
 <option>$select_text1<checked>
".$cat_fields[$key][7]."</select></td></tr>
";
}

if ($cat_fields[$key][4] == 'checkbox')
{
$aa5=split('<option>',$cat_fields[$key][7]);
echo "
<tr>
<td height='$td_height' bgcolor='$tbl_col' >
<font FACE='ARIAL, HELVETICA' COLOR='#000099' size='-1'>
".$cat_fields[$key][0].":
</font>
</td><td bgcolor='$tbl_col'>
";
$i_aa5=0;
foreach ($aa5 as $value1)
{
$i_aa5++;
if ($value1!=""){
$namechbx=$key.$i_aa5;
echo " 
<input type='checkbox' name='$namechbx' value='$value1' $fields_val[$namechbx]  > $value1 <br>
";
}
}
echo "</select></td></tr>";
}



if ($cat_fields[$key][4] == 'text'){
$aa4=split(':',$cat_fields[$key][3]);
$t_size=$aa4[0];
$t_max=$aa4[1];
echo "
<tr>
<td height='$td_height' bgcolor='$tbl_col' >
<font FACE='ARIAL, HELVETICA' COLOR='#000099' size='-1'>
".$cat_fields[$key][0].":
</font>
</td><td bgcolor='$tbl_col'>
";
 
echo "
<input type='text' name='$key' size='$t_size' value='".$fields_val[$key]."' maxlength='$t_max' class=formst>
</td></tr>
";
 
}
if ($cat_fields[$key][4] == 'textarea'){
$aa4=split(':',$cat_fields[$key][3]);
$t_rows=$aa4[1];
$t_cols=$aa4[0];
$t_max=$aa4[2];
echo "
<tr>
<td height='$td_height' bgcolor='$tbl_col' >
<font FACE='ARIAL, HELVETICA' COLOR='#000099' size='-1'>
".$cat_fields[$key][0].":
<br><font size='-2' color='#aaaaaa'> ".$msg2['not_more_then']." 
 $t_max ".$msg2['chars_ms']."</font>
</font>
</td><td bgcolor='$tbl_col'>
";
if (($cat_fields[$key][7]!="") and ($ed_add=='submitad'))
{
echo "
<b>
<font FACE='ARIAL, HELVETICA' COLOR='#000099' size='-2'>
".$msg2['Delete_unnecessary_options'].":<br>
</b>
</font>
";
 $fields_val[$key]=$cat_fields[$key][7];
}
echo "
<textarea name='$key'   rows='$t_rows' cols='$t_cols' maxsize='$t_max' class=formst>".$fields_val[$key]."</textarea>
</td></tr>
";
}
}
}
 
echo "
</td></tr>
</table></td></tr>
</table>
<font FACE='ARIAL, HELVETICA' color='#000000'  size='-2'>
<b>".$msg2['fields_marked_ms']."
</b></font>
<br>
";

echo "
<input type='submit' value='".$msg2['Save_changes_mb']."' class=formst>
<hr size='1'>
 
 
</form>
</td><td valign='top'>
$rightform_html   
</td></tr></table> </center>
$html_footer
";

}

function editmba()
{
global $ed_passw, $ed_id, $table_mb, $moderating, $adphotos, $mbprf_login, $mbprf_passw, 
$HTTP_POST_VARS, $memb_acc_act, $msg2;
 
$HTTP_POST_VARS['login']=$mbprf_login;
check_fields();

$sql_query="select passw from $table_mb where idnum=$ed_id";
$sql_res=mysql_query("$sql_query");
$row = mysql_fetch_array ($sql_res);
 
if ($row['passw']!="$mbprf_passw")
{
echo " ".$msg2['incorrect_password_mb']." ";
exit;
}

$db_entry=form_sql_entry($ed_id);
$db_entry['idnum']="";
$db_entry['adphotos']=$adphotos;
$db_entry['time']="";
$db_entry['exptime']="";
$db_entry['visible']="0";



$db_entry['visible']="1";
# if ($memb_acc_act=="0")
# {$db_entry['visible']="1";}



$sql_string="";
foreach ($db_entry as $db_key =>$db_value)
{
# $db_entry[$db_key]=~ s/"/'/g;
if ($db_entry[$db_key]!=""){
$sql_string=$sql_string."$db_key='$db_entry[$db_key]', ";
}
}
$sql_string=corr_sqlstring($sql_string);

$sql_query="update $table_mb set $sql_string where idnum=$ed_id";
#echo $sql_query; exit;

mysql_query("$sql_query");

print_subm_mb($ed_id);
exit;
}

function print_subm_mb($ad_idnum)
{
global $cat_fields, $photos_count, $html_header, $html_footer, $id,$HTTP_POST_VARS, $idnum1,
$ct, $categories, $ad_second_width, $left_width_sp, $exp_period, $incl_prevphoto,
$prphotolimits, $pr_lim_width, $pr_lim_height, $previewphoto_path, $previewphoto_url,
$moderating, $savepherr, $memb_acc_act,
$tbclr_1, $tbclr_2, $tbclr_3, $tbclr_4, $fntclr_1, $msg2, $msg;

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

 $row=get_edit_info($ad_idnum);

$time1=$row['time'];
$date_posted=get_date($time1); 
 
$idnum1=$row['idnum'];

 

if ($memb_acc_act=='0') 
{ $info11="
 
".$msg2['memb_info_edited_success']."
";
setcookie("cook_passw",$HTTP_POST_VARS['passw']);
}

if ($memb_acc_act=='e')
{
send_act_ms();
$info11="
  
".$msg2['click_on_activat_link']."
";
}

if ($memb_acc_act=='a') 
{ $info11="
".$msg2['mbacc_activ_asap']."
";
}
 
 
echo $html_header;
echo "
<center><table width='500'><tr><td>
<font FACE='ARIAL, HELVETICA' COLOR='BLACK'> <font size=-1>
<b><a href='index.php'>".$msg['top'].":</a></b></font>
&nbsp; 
<font FACE='ARIAL, HELVETICA' COLOR='#000099'> 
<b>&nbsp; 
<a href='index.php?ct=$ct'>".$categories[$ct][0]."</a>
</b> 
</font> 
<hr size='1'>
<center>
<font FACE='ARIAL, HELVETICA' COLOR='#000099' size='+1'> 
<b> $info11 </b></font>
</center><p>
";
$sdtpcol=$tbclr_4;
echo "
<table width='100%' bgcolor='$tbclr_1' border=0 cellspacing=3 cellpadding=3>
<tr>
<td bgcolor='$tbclr_1'>
<font FACE='ARIAL, HELVETICA' color='#000088' size='-1'>
  &nbsp; <b>".$msg2['Your_membership_info'].":</b></font>
</td>
</tr>
</table>
<table width='100%'  bgcolor='$tbclr_4' cellspacing=5 cellpadding=5>
<tr><td>
<font size=-1>
<font color='#007700' >&nbsp;&nbsp;# : </font><font color='#aa0000'>
".$row['idnum']."
</font>; 
&nbsp;
<font color='#007700' >  ".$msg2['Date_Posted_m']." : </font> <font color='#aa0000' >
 $date_posted </font>;
<table width='100%'  border=0 bordercolor='#ffffff' cellspacing=3 cellpadding=0>
";


foreach ( $cat_fields as $key => $value )
{
echo "
<tr><td colspan='2' height='1' bgcolor='$sdtpcol1'><spacer type='block' height='1' width='1'></td></tr>
<tr><td bgcolor='$sdtpcol' width='40%'>
<font FACE='ARIAL, HELVETICA' COLOR='#000088' size='-1'>
&nbsp; ".$cat_fields[$key][0].":</font>
</td><td bgcolor='$sdtpcol' width='60%'>
<font FACE='ARIAL, HELVETICA' COLOR='BLACK' size='-1'>
 ".$row[$key]." &nbsp; </td></tr>
";
}

echo "
<tr><td colspan='2' height='1' bgcolor='$sdtpcol1'><spacer type='block' height='1' width='1'></td></tr>
</table></td></tr></table>
";

echo "
<p>
<center>
<font FACE='ARIAL, HELVETICA' COLOR='#000088' size='-1'>
 
</font>
</center>
<p>
";

echo  "
<hr size='1'>
</tr></td></table>
";

echo $html_footer;

exit;
}

function send_act_ms()
{
global $HTTP_POST_VARS, $subscr_url, $welc_mb_email, $act_mb_subj, $adm_email, $idnum1;

$pss1=$HTTP_POST_VARS['passw'];
$pss2=crypt($pss1, 'aa');
$pss2=ereg_replace('&', '', $pss2);

$memb_act_link=$subscr_url."?md=mbactivate&id=$idnum1&ps1=$pss1&ps2=$pss2";

$welc_mb_email=ereg_replace('!--member_name--!',$HTTP_POST_VARS['contact_name'],$welc_mb_email);
$welc_mb_email=ereg_replace('!--member_login--!',$HTTP_POST_VARS['login'],$welc_mb_email);
$welc_mb_email=ereg_replace('!--member_password--!',$HTTP_POST_VARS['passw'],$welc_mb_email);
$welc_mb_email=ereg_replace('!--memb_act_link--!', $memb_act_link,$welc_mb_email);

sndmail1($HTTP_POST_VARS['email'], $act_mb_subj, $welc_mb_email, $adm_email);
}

function sndmail1($ml_to, $ml_subj, $ml_info, $ml_from)
{
mail($ml_to, $ml_subj, $ml_info, "From: $ml_from");
}

function sndmail1_bak($ml_to, $ml_subj, $ml_info, $ml_from)
{
echo "
<br>
<br>To : $ml_to
<br>From: $ml_from
<br>Subject: $ml_subj
<br>Info: $ml_info
";
}

function mb_activate()
{
global $table_mb, $html_header, $html_footer, $md, $id, $ps1, $ps2;

$pss2=crypt($ps1,'aa');
$pss2=ereg_replace('&', '', $pss2);

if ($ps2!=$pss2)
{
echo $html_header;
echo "
<center> <font FACE='ARIAL, HELVETICA' COLOR='#000099' font size='+1'>
<b> ".$msg2['Incorrect_activating']." </b>
</font>
</center>
";
echo $html_footer;
exit;
}

$sql_query="update $table_mb set visible=1 where  idnum=$id ";
mysql_query("$sql_query");

echo $html_header;
echo "
<center> <font FACE='ARIAL, HELVETICA' COLOR='#000099' font size='+1'>
".$msg2['mb_act_successfully']."
</font>
</center>
";
echo $html_footer;
exit;
}

?>