<?
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";

//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);

//loginbox
loginbox( $login );



//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  ;
}

@mysql_free_result($selectnewdivan);



//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);

//getcat info

$username = $_COOKIE[traidusername];
$password = $_COOKIE[traiduserpassword];
$userid = $_COOKIE[traiduserid];


$subtitle = "&nbsp;&nbsp;&nbsp;-&nbsp;&nbsp;لوحة التحكم   ";

echo $tpl->display("headerinclude.html");
//header
echo $tpl->display("header.html");
//endheader
 echo $tpl->display("bodyinclude.html");

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

if(($username)==('')){
$message = "من فضلك قم بتسجيل الدخول";
@setcookie('traidusername',$username,time()-36000);
echo $tpl->display("message.html");
traidntright();
echo $tpl->display("footer.html");
exit();
}


$getuser = mysql_db_query("$dbName", "SELECT * FROM  `users` WHERE `user_name` = '$username' and `user_password` = '$password' and `user_id` = '$userid' ;") ;
$find = mysql_affected_rows();
if(($find)==('0')){

$message = "عفوا قم باعاده تسجيل الدخول";
@setcookie('traidusername',$username,time()-36000);
echo $tpl->display("message.html");
traidntright();
echo $tpl->display("footer.html");
exit();
}

while  ($info = mysql_fetch_array($getuser)){
$usermail = $info[user_mail];
$userpassword =   $info[user_password];
$userid =    $info[user_id];
}
 //

if(($_GET['go'])==('')){
echo "<br>".$tpl->display("usercp.html");
}else{
$oldpassword = trim($_POST[oldpassword]);
$oldpassword = mysql_real_escape_string($oldpassword);
$newpassword = trim($_POST[newpassword]);
$newpassword = mysql_real_escape_string($newpassword);
$newmail = trim($_POST['mail']);
$newmail = mysql_real_escape_string($newmail);
$md5old = md5($oldpassword);
 if(($newmail)!=($usermail)){
 $tgh = 1;
$cmail = @mysql_db_query("$dbName", "SELECT * FROM `users` WHERE `user_mail` = '$mail' ") ;
$num = mysql_affected_rows();
      }else{
      $tgh = 0;
      }
	if(($md5old)!=($userpassword)){
    $message = "عفوا كلمات المرور القديمة غير صحيحة";
    echo $tpl->display("message.html");
    traidntright();
	echo $tpl->display("footer.html");
    exit();
	}elseif(($newmail)==('')){
	$message = "عفوا لم تقم بادخال البريد الالكتروني";
	echo $tpl->display("message.html");
	    traidntright();
	echo $tpl->display("footer.html");
    exit();
	}elseif(($tgh)==(1)){
     if(($num)==(1)){
     		$message = "عفوا البريد الالكتروني مستخدم لدينا من قبل";
			echo $tpl->display("message.html");
     	}
	}

     if(($newpassword)==('')){
     $password = $md5old;
     }else{
     	$password = md5($newpassword);
     	}
        $updateuser = mysql_db_query("$dbName", "UPDATE `users` SET `user_password` = '$password',`user_mail` = '$newmail' WHERE `users`.`user_id` ='$userid' LIMIT 1 ;") ;
        if($updateuser){
        	$message = "تم تعديل البيانات بنجاح";
			echo $tpl->display("message.html");
        	}else{
             $message = "عفوا البريد الالكتروني مستخدم من قبل";
			echo $tpl->display("message.html");

     	}


}



//page body
//page left
//get most divan visit

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

ob_end_flush();
?>