<?
session_start();
ob_start("ob_gzhandler");
include("./includes/config.php");
include("./lang/arabic.php");
include("./includes/function.php");
include("./includes/online.php");
include("./includes/easytemplate.php");
include("./includes/inquiry.php");
$PhpGroup_style['def_style'] = "designs/$style";
$stylepath= $PhpGroup_style['def_style'];
$tpl = new EasyTemplate;
$tpl->Temp = $PhpGroup_style['def_style'];
$tpl->Cache = "easycache";
$subtitle = "&nbsp;&nbsp;&nbsp;-&nbsp;&nbsp;تسجيل عضوية جديدة";
echo $tpl->display("headerinclude.html");
//start qurey
//get the last new poem
$selectnewdivan = mysql_db_query("$dbName", "SELECT * FROM `divan`  WHERE `divan_group` = '1' ORDER BY `divan_id` DESC LIMIT 10 ") ;
while ($ndivan =  @mysql_fetch_assoc($selectnewdivan)){
$nd[] =   $ndivan  ;
}


echo $tpl->display("header.html");
echo $tpl->display("bodyinclude.html");
//cheak site close
if (($close) == ('yes')){
echo $tpl->display("message.html");
traidntright();
echo $tpl->display("footer.html");
exit();
}

//cheak rigistar close
if (($register) == ('no')){
$message = $lang[disalowrigister];
echo $tpl->display("message.html");
traidntright();
echo $tpl->display("footer.html");
exit();
}


//statistics
$selectcount= mysql_db_query("$dbName", "SELECT * FROM  cat;") ;
$totalcat = mysql_affected_rows();
@mysql_free_result($selectcount);
$selectcount= mysql_db_query("$dbName", "SELECT * FROM  divan;") ;
$totaldivan = mysql_affected_rows();
@mysql_free_result($selectcount);
$selectcount= mysql_db_query("$dbName", "SELECT * FROM  users;") ;
$totalusers = mysql_affected_rows();
@mysql_free_result($selectcount);


//loginbox
loginbox( $login );

//get the can name in the right page
$selectc = @mysql_db_query("$dbName", "SELECT * FROM `cat`  WHERE `cat_group` = '1' ORDER BY `cat`.`cat_display` ASC  ") ;
while ($s =  @mysql_fetch_assoc($selectc)){
$cat[] =   $s  ;
}
@mysql_free_result($selectc);

echo"<br>";
if(($_GET['do'])==('')){
echo $tpl->display("register.html");
}elseif(($_GET['do'])==('adduser')){
$user = trim($_POST['username']);
$username = strip_tags($user);
$pass = trim($_POST['password']);
$password = md5($pass);
$mail = trim($_POST['vmail']);
$cp = $_SESSION['key'];
$mcode =  md5($_POST[vcode]);

if(($mcode)!=($cp)){
$message = "<p align='center'>عفوا كود التحقق خاطئ <br><a href='javascript:history.back()'>اضغط هنا للعودة</a></p>";
print $tpl->display("message.html");
}elseif(($username) == ("")){

}else{
$cuser = @mysql_db_query("$dbName", "SELECT * FROM `users` WHERE `user_name` = '$username' ") ;
$num = mysql_affected_rows();
@mysql_free_result($cuser);
if(($num) != ('0')){
 $message = "<p align='center'> عفوا اسم المستخدم مستخدم من قبل برجاء اختيار اسم آخر   <br><a href='javascript:history.back()'>اضغط هنا للعودة</a></p>";
print $tpl->display("message.html");
}else{
$cmail = @mysql_db_query("$dbName", "SELECT * FROM `users` WHERE `user_mail` = '$mail' ") ;
$num = mysql_affected_rows();
@mysql_free_result($cmail);
if(($num) != ('0')){
 $message = "<p align='center'> عفوا  البريد الالكتروني مستخدم من قبل برجاء اختيار بريد آخر   <br><a href='javascript:history.back()'>اضغط هنا للعودة</a></p>";
print $tpl->display("message.html");
}else{

$visit = date('d-m-Y');
$addnewuser = @mysql_db_query("$dbName", "INSERT INTO `users` ( `user_id` , `user_name` , `user_password` , `user_mail` , `user_visit` , `user_group` )
VALUES (NULL , '$username', '$password', '$mail', '$visit', '2'); ") ;
@mysql_free_result($addnewuser);
if($addnewuser){
$message = "<p align=center >تم تسجيل عضويتكم بنجاح<br>عضويتكم الآن بنتظار التفعيل من الادارة</p>";
print $tpl->display("message.html");
}else{
$message = "<p align='center'> عفوا هناك مشكلة بالتسجيل برجاء الاتصال بالادارة </p>";
print $tpl->display("message.html");
}

}
}



}



}else{
$message = "<p align='center'> عفوا اتبعت رابط خاطئ برجاء  </p>";
print $tpl->display("message.html");

}


echo"<br>";
traidntright();
echo $tpl->display("footer.html");
//page footer

ob_end_flush();
?>