<?

function print_menu_crtb()
{
global $opt_header, $opt_footer, $db_name, $table_ads, $table_logs,
$moderating, $categories;
 
echo " 
<p>
<a href='admconf.php'><b>Top:</b></a><br>
<table width='700'    border='0' cellspacing='1' cellpadding='0'> 
<tr><td  class='frmft1'>
 &nbsp; Creation MySQL tables for ads
</td></tr></table> 
<p>
 <font class='fnt2'>
<a href='admconf.php?md=create_tb'>Create MySQL Table for Ads</a>
<p> 
<a href='mbcrtb.php?md=create_tb' target='_blank'>Create MySQL Table for Membership Database</a>
 </font>
";

echo $opt_footer;
exit;
}

function print_sql_tb()
{
global $html_header, $html_footer;
 
echo sql_create_tb()."<p>";
 
 
}

function create_db()
{
global $host_name, $db_user,$db_password, $html_header, 
$html_footer, $db_name, $table_ads;

mysql_connect("$host_name","$db_user","$db_password");
mysql_create_db("$db_name");
echo $html_header;
echo "Database '$db_name' was created";
echo $html_footer;
exit; 
}

function connect_db_conf()
{
global $host_name, $db_user, $db_password,$db_name,  $opt_header, $opt_footer, $md;

if (!(@mysql_connect("$host_name","$db_user","$db_password")))
{
echo "
<font class='fnt2p'> &nbsp;&nbsp; To start script configuring, at first you need to set up  
correct values of <br> host name, user/password,  database name for your MySQL server. <br>

Default values does not match your MySQL server configuration.
<br> 

";

if ($_REQUEST['mdopt']!="optform"){
echo "
<a href='admconf.php?mdopt=optform'>Click here</a> to set up these options.
";
}
echo "
 </font> 
<p>
";
if ($md=="create_tb"){echo $opt_footer; exit; }
return;
}
if (!(@mysql_select_db("$db_name")))
{ 

echo "
 
<font class='fntmsg2'> 
Script can not  connect to  MySQL database. </font>
<br> <font class='fnt2p'>  You need to set up  
correct database name, or create the database with such a name <b>$db_name</b>  <br>
";

if ($_REQUEST['mdopt']!="optform"){
echo "
<a href='admconf.php?mdopt=optform'>Click here</a> to set up database name
";
}
echo "
 </font> 
<p>
";
if ($md=="create_tb"){echo $opt_footer; exit; }
return;
}

}


function create_tb()
{
global $host_name, $db_user,$db_password, $table_logs, 
 $opt_header, $opt_footer, $db_name, $table_ads; 

$sql_query1=sql_create_tb();
 

$result1 = mysql_list_tables ($db_name);
 $i = 0;
 while ($i < mysql_num_rows ($result1)) {
     $tb_names1  = mysql_tablename ($result1, $i);
    if ($tb_names1==$table_ads){mysql_query("DROP TABLE $table_ads;"); }
     $i++;
 }

$sql_rs1=mysql_query("$sql_query1");
if (!($sql_rs1)){
echo "
 
<font class='fntmsg2'> 
Error in creating   MySQL table '$table_ads'. <br> Check  errors
in variable \$ads_fields (file conf_cat.php) for ads fields settings 
";

echo "
 </font> 
<p>
";
 
return;
 
}


$slq_drop2="DROP TABLE $table_logs";
mysql("$db_name","$slq_drop2");
$sql_query2="
create table $table_logs (ltime integer, ltype char(5), lip char(20), lidnum integer ) 
";
$sql_rs2=mysql("$db_name","$sql_query2");
 
if ($sql_rs2 and $sql_rs1)
{
$message="
<font class=fntmsg1>
 Tables '$table_ads' and '$table_logs' was created successfully 
<p>
</font><br>
<img src='http://www.almondsoft.com/logo/logo6.php' height='1' width='1'>";
}

if (!($sql_rs2)){
$message=" $sql_rs2 $sql_rs1 c $slq_drop1
<font FACE='ARIAL, HELVETICA' COLOR='BLACK' font size='+1'>
<b>Table '$table_logs' does not created correctly</b>  
<p>
</font>
";
}
admin_message1($message);
exit; 
}

function sql_create_tb()
{
global $ads_fields, $table_ads,$oldvrsn;
$table_name=$table_ads;
$db_t_fields['idnum']="integer not NULL primary key";
$db_t_fields['time']="integer";
$db_t_fields['exptime']="integer";
$db_t_fields['catname']="text";
$db_t_fields['visible']="integer";
$db_t_fields['adphotos']="char(5)";
$db_t_fields['login']="text";
$db_t_fields['adrate']="integer";
$db_t_fields['ipaddr1']="char(20)";
$db_t_fields['cntemll']="integer";
$db_t_fields['cntvstr']="integer";
$db_t_fields['ratevtcn']="integer";
$db_t_fields['ratevtrt']="real";
$db_t_fields['replyid']="integer";
$db_t_fields['replcnts']="integer";
$db_t_fields['adcommkey']="integer";
$db_t_fields['attflext']="char(10)";
$db_t_fields['attfltl']="text";
$db_t_fields['flsrvtl1']="text";
$db_t_fields['flsrvur1']="text";
$db_t_fields['flsrvtl2']="text";
$db_t_fields['flsrvur2']="text";
$db_t_fields['embdcod']="text";

foreach ($ads_fields as $key => $value)
{
$db_t_fields[$key]=$ads_fields[$key][6];
}

$create_string="";
foreach ($db_t_fields as $db_key => $value)
{
$create_string=$create_string.$db_key." ".$db_t_fields[$db_key].", ";
}
$create_string=corr_sqlstring($create_string);
$sql="create table $table_name ( $create_string ) ";
return $sql;
}

function admin_message1($message)
{
global $cat_fields, $photos_count, $opt_header, $opt_footer, $id,
$ct, $categories, $ad_second_width, $left_width_sp, $exp_period;
  
echo "
<p>
<a href='admconf.php'><b>Top:</b></a><p>
&nbsp; 
<p>
$message
<p>

";
echo $opt_footer;
exit;
}

?>