<?php
/*
+===========================================+
|      ArabPortal V2.2.x Copyright © 2009   |
|   -------------------------------------   |
|                     BY                    |
|              Arab Portal Team             |
|   -------------------------------------   |
|      Web: http://www.ArabPortal.Info      |
|   -------------------------------------   |
|  Last Updated: 25/08/2008 Time: 03:35 AM  |
+===========================================+
*/

require_once('global.php');

unset($ads_head,$ads_foot);

$menu = new menu;
$menu->menuid       =  $apt->getsettings("index_menuid");
$right_menu   = $menu->_menu(1);
$middle_menu =  $menu->middle_menu();

$perpagelist = 30;
////////////////login //////////////

if (isset($apt->post[username]) && isset($apt->post[userpass]))
{
    @extract($HTTP_POST_VARS);
    $apt->setoutcookie();
    $username = $apt->format_data($username);

    $userpass = $apt->format_data(md5($userpass));

    $fullarr =  array($username,$userpass);
    
    if (!$apt->full($fullarr))
    {
        $apt->errmsg(LANG_ERROR_VALIDATE);
    }

    $result = $apt->query("SELECT * FROM rafia_users WHERE
                              (username ='$username') AND
                              (password ='$userpass')");

    if ($row = $apt->dbnumrows($result) == 0)
    {
        $apt->errmsg(LANG_ERROR_LOGIN);
    }

    $row = $apt->dbarray($result);

    if ($row["allowpost"] == "no")
    {
        $apt->errmsg(LANG_ERROR_YOU_STOPPING);
    }

    if (($row["allowpost"] == "wit") or ($row["allowpost"] == "swt"))
    {
        $apt->errmsg(LANG_ERROR_NON_ACTIVATES);
    }

    if (($row["username"] == $username) &&($row["password"] == $userpass))
    {
        @extract($row);
        $activate   = $apt->makeactivate();
        $userip     = $apt->ip;
        $lastlogin  = time();
        $cookie     = serialize(array('arabportal', $activate, $userid, $apt->time,session_id()));
        $apt->set_cookie ("",base64_encode($cookie));
        
        $_SESSION["sessid"]      = $userid;
        $_SESSION["sessname"]    = $username;
        $_SESSION["sessadmin"]   = $useradmin;
        $_SESSION["sessgroup"]   = $usergroup;
        $_SESSION["sesstheme"]   = $usertheme;
        $_SESSION["selastvisit"] = $lastlogin;

// Added By MaaSTaaR
      $X_url = explode('/',$_SERVER['HTTP_HOST']);
	$Y_url = explode('/',$_SERVER['HTTP_REFERER']);
	$goto = ($X_url[0] != $Y_url[2]) ? $goto = 'index.php' : $goto = $apt->refe;
// MaaSTaaR End
        $apt->query("update rafia_users set userip='$userip',lastlogin='$lastlogin',activate='$activate' WHERE userid='$userid'");
        $apt->bodymsg(LANG_MSG_LOGED_IN . $username, $goto);  // Added by MaaSTaaR
    }

}
if ($apt->get['action']=="info")
{

    $apt->GroupAllow('view_site');
    
    checkcookie();

    $apt->head(LANG_TITLE_PERSONAL_FILE);

    $member_lang_head = LANG_TITLE_PERSONAL_FILE;
    
    $userid =  intval( $apt->get['userid']);
    
    $result = $apt->query("SELECT username,email,homepage,avatar,allposts,datetime,viewemail,showemail FROM rafia_users WHERE userid='$userid'");

    $row    = $apt->dbarray($result);
    
    @extract($row);

    $username     =  $apt->format_data_out($username);
    $homepage     =  $apt->format_data_out($homepage);
    $email        =  $apt->format_data_out($email);
    $usertitles   =  explode("-", $apt->userRating($allposts));
    $usertitle    =  $usertitles[1];
    $date         =  $apt->Hijri($datetime);

    if($viewemail == 0)
    {
        $email ="لا يرغب في عرضة";
    }
    if($showemail == 0)
    {
        $showemail = 'no';
    }
    else
    {
        $showemail = '<a href="mail.php?action=sendtousers&userid='.$userid.'">ارسال رسالة على البريد</a>';
    }
    if($avatar == 0){
        $avatar_pic = "<img src=images/no_pic.gif>";
    }else{
        $avatarfile = $apt->upload_path."/".$userid.".".'avatar';
        if(file_exists($avatarfile)){
        $avatar_pic = "<img src=filemanager.php?action=avatar&userid=".$userid.">";
        }else{
        $avatar_pic = "<img src=images/no_pic.gif>";
        }	
    }

    $showemail =  $apt->adminset($showemail);
    
     if($allposts >0)
     {
         $newsPosts  = $apt->dbnumquery("rafia_news","userid=".$userid);
         $forumPosts = $apt->dbnumquery("rafia_forum","userid=".$userid);
         
         if($newsPosts >0){
             $newsPosts = " <a href=\"news.php?action=byuser&userid=$userid\"> عرض مشاركات الاخبار</a>";
         }else{$newsPosts = "";}

         if($forumPosts > 0){
             $forumPosts = " || <a href=\"forum.php?action=byuser&userid=$userid\">عرض مشاركات المنتدى</a>";
         }else{$forumPosts = "";}

     }
    
    eval("\$index_middle = \" " . $apt->gettemplate ( 'member_info' ) . "\";");

    $apt->html_Output($left_menu);

}
elseif ($apt->get['action']=="cp")
{
    $apt->GroupAllow('view_site');

    checkcookie();

    $apt->head(LANG_TITLE_PERSONAL_FILE);

    $member_lang_head = LANG_TITLE_PERSONAL_FILE;

    $result = $apt->query("SELECT * FROM rafia_users WHERE userid='".$apt->cookie['cid']."'");
    $row    = $apt->dbarray($result);
    @extract($row);

    $username     =  $apt->format_data_out($username);
    $homepage     =  $apt->format_data_out($homepage);
    $email            =  $apt->format_data_out($email);
    $usertitles   =  explode("-", $apt->userRating($allposts));
    $usertitle    =  $usertitles[1];
    $date            =  $apt->Hijri($datetime);

    if($showemail == 0){
        $showemail = 'no';
    }else{
        $showemail = 'yes';
    }

    $showemail =  $apt->adminset($showemail);

    if($avatar == 0){
        $avatar_pic = "<img src=images/no_pic.gif>";
    }else{
        $avatarfile = $apt->upload_path."/".$apt->cookie['cid'].".".'avatar';
        if(file_exists($avatarfile)){
        $avatar_pic = "<img src=filemanager.php?action=avatar&userid=".$apt->cookie['cid'].">";
        }else{
        $avatar_pic = "<img src=images/no_pic.gif>";
        }	
    }

    eval("\$index_middle = \" " . $apt->gettemplate ( 'members_link' ) . "\";");

    eval("\$index_middle .= \" " . $apt->gettemplate ( 'member_cp' ) . "\";");

    $apt->html_Output($left_menu);
}
elseif ($apt->get['action']=="changepass")
{
    $apt->GroupAllow('view_site');
    checkcookie();

    $apt->head(LANG_TITLE_CHANGE_PASSWORD);
    $result = $apt->query("SELECT * FROM rafia_users WHERE userid='".$apt->cookie['cid']."'");
    $row    = $apt->dbarray($result);
    @extract($row);
     $fo = new form;
    eval("\$index_middle = \" " . $apt->gettemplate ( 'members_link' ) . "\";");
    $form .=  $fo->inputform  ($apt->lang_form['24'],"password", "opassword","*");
    $form .=  $fo->inputform  ($apt->lang_form['12'],"password", "npassword","*");
    $form .=  $fo->inputform  ($apt->lang_form['13'],"password", "npassword2","*");

    $image = "themes/".$GLOBALS[themepath]."/do.gif";
    $output = array("action"      => "$PHP_SELF?action=UP",
                    "title"      => LANG_TITLE_CHANGE_PASSWORD,
                    "method"     => '',
                    "name"       => '',
                    "content"    => $form,
                    "image"      => $image
                   );
    $index_middle .= $fo->formtable($output);
    $apt->html_Output($left_menu);

}
else if ($apt->get['action']=="UP")
{
    $apt->GroupAllow('view_site');
    checkcookie();
    
    @extract($HTTP_POST_VARS);
    
    if ($apt->txtcounmxs($npassword,4))
    {
        $apt->errmsg(LANG_ERROR_PASS_MUST_MORE);
    }
    if ($npassword != $npassword2)
    {
        $apt->errmsg (LANG_ERROR_PASS_EQUAL);
    }

    $result = $apt->query("SELECT password FROM rafia_users WHERE userid='".$apt->cookie['cid']."'");

    $row    = $apt->dbarray($result);

    if ( md5($opassword) != $row["password"] )
    {
        $apt->errmsg(LANG_ERROR_PASS);
    }

    $npassword = $apt->format_data(md5($npassword));

    $result    = $apt->query("update rafia_users set
                              password='$npassword'
                              WHERE userid='".$apt->cookie['cid']."'");
    if ($result)
    {
        $apt->setoutcookie ();
        
        $apt->bodymsg(LANG_MSG_PASSWORD_HAS_CHANGED,"$PHP_SELF?action=cp");
          
     }
     else
    {
        $apt->bodymsg(LANG_ERROR_ADD_DB,"$PHP_SELF?action=cp");
    }
}
if ($apt->get['action']=="edit")
{
    $apt->GroupAllow('view_site');
    checkcookie();

    $apt->head(LANG_TITLE_EDIT_OPTIONS);

    $result = $apt->query("SELECT * FROM rafia_users WHERE userid='".$apt->cookie['cid']."'");

    $row = $apt->dbarray($result);
    @extract($row);

    $homepage   = $apt->format_data_out($homepage);
    $email      = $apt->format_data_out($email);

    eval("\$index_middle = \" " . $apt->gettemplate ( 'members_link' ) . "\";");
    if($avatar == 0){
        $avatar_pic = 'لا يوجد<input type=hidden value=0 name=avatar>';
    }else{
        $avatarfile = $apt->upload_path."/".$apt->cookie['cid'].".".'avatar';
        if(file_exists($avatarfile)){
        $avatar_pic = "<input type=hidden value=1 name=avatar><img src=filemanager.php?action=avatar&userid=".$apt->cookie['cid'].">";
        }else{
        $avatar_pic = 'لا يوجد<input type=hidden value=0 name=avatar>';
        }	
    }

    $fo = new form;
    $fo->use_smiles =0;
    $form .= $fo->inputform($apt->lang_form['15'],"text", "homepage","","$homepage",40);
    $form .= $fo->inputform($apt->lang_form['14'],"text","email","*","$email",30);
    $form .= $fo->yesorno($apt->lang_form['37'], "viewemail", $viewemail);
    $form .= $fo->yesorno($apt->lang_form['32'], "showemail", $showemail);
    $form .= $fo->yesorno    ($apt->lang_form['31'], "html_msg", $html_msg);
    $form .= $fo->selectstheme ($usertheme);
    $form .= "<tr><td nowrap class=\"info_bar\">الصورة الرمزيه الحالية : <br><a href=members.php?action=delavatar>حذف الصورة الشخصية</a></td>
		  <td align=right width=\"100%\">$avatar_pic</td></tr>";
    $form .= $fo->inputform  ("ارفق صورة رمزية جديدة<br>(اصغر من 100*100)","file","avfile","");
    $fo->countpost  = $apt->getsettings("txtcount7");
    $form .= $fo->txtcount();
    eval("\$formcode = \"" . $apt->gettemplate ( 'form_code' ) . "\";");
    $formcode = str_replace('showButtons','signshowButtons',$formcode);
    $form .= "<tr><td nowrap class=\"info_bar\">محرر التوقيع : </td>
		  <td align=right width=\"100%\">$formcode</td></tr>";
    $form .= $fo->textarea($apt->lang_form['17'],"post",$signature,7);


    $image = "themes/".$GLOBALS[themepath]."/do.gif";
    $output = array("action"      => "$PHP_SELF?action=update",
                    "title"      => LANG_TITLE_EDIT_OPTIONS,
                    "method"     => '',
                    "name"       => '',
                    "content"    => $form,
                    "image"      => $image
                   );

         $index_middle .= $fo->formtable($output);
    $apt->html_Output($left_menu);

}
else if ($apt->get['action']=="delavatar")
{
    $avatarfile = $apt->upload_path."/".$apt->cookie['cid'].".".'avatar';
    if (! @unlink($avatarfile))
    {
        $apt->errmsg("عفوا لم يتم حذف الصورة الشخصية");
    }else{
	  $apt->bodymsg("تم حذف الصورة الشخصية بنجاح","$PHP_SELF?action=cp");
    }
}
else if ($apt->get['action']=="update")
{
    $apt->GroupAllow('view_site');
    checkcookie();
    @extract($HTTP_POST_VARS);
    
    if (!$apt->check_email($email))
    {
        $apt->errmsg(LANG_ERROR_VALID_EMIAL);
    }
    
    if (!$apt->txtcounmxs($post,$apt->getsettings("txtcount7")))
    {
        $apt->errmsg(LANG_ERROR_LETTER_MAX);
    }
    $apt->set_cookie ("logintheme",$usertheme);
    $_SESSION["sesstheme"]   = $usertheme;
    
    $homepage  =   $apt->format_data($homepage);
    $email     =   $apt->format_data($email);
    $signature =   $apt->format_post($post);
    $showemail =   intval($apt->format_data($showemail));
    $usertheme =   $apt->format_data($usertheme);
    $html_msg  =   intval($apt->format_data($html_msg));
    $avatar  =   intval($apt->format_data($avatar));

    if ($apt->files["avfile"]["tmp_name"] != ''){
    $size_limit = 30;
    $allow_ext = array('.gif','.png','.jpg');
    $allow_types = array('image/jpeg', 'image/jpg', 'image/pjpeg', 'image/png', 'image/x-png', 'image/gif');
    $file 	= $apt->files["avfile"]["tmp_name"];
    $size 	= $apt->files["avfile"]["size"];
    $type 	= $apt->files["avfile"]["type"];
    $rname 	= $apt->files["avfile"]["name"];
    $ext  	= strtolower(strrchr($rname,'.'));
    $size = @intval($size / 1024);
    $allow_e = in_array($ext,$allow_ext);
    $allow_t = in_array($type,$allow_types);
    $imsize = getimagesize($file);
    $x = $imsize[0];
    $y = $imsize[1];
    $wt_avatar =  $apt->getsettings("wt_avatar");
    $ht_avatar =  $apt->getsettings("ht_avatar");

    if($x > $wt_avatar){
    $apt->errmsg("عفوا ... لا يسمح بتحميل صورة عرضها اكبر من $wt_avatar");
    }elseif($y > $ht_avatar){
    $apt->errmsg("عفوا ... لا يسمح بتحميل صورة ارتفاعها اكبر من $ht_avatar");
    }elseif(!$allow_e){
    $apt->errmsg("عفوا ... لا يسمح بتحميل هذا الامتداد من الملفات");
    }elseif(!$allow_t){
    $apt->errmsg("عفوا ... لا يسمح بتحميل هذا النوع من الملفات");
    }elseif($size > $size_limit){
    $apt->errmsg("عفوا ... الملف الذي تحاول رفعه اكبر من الحجم المسموح به<br>الحجم المسموح به هو $size_limit كيلوبايت");
    }else{
    if(@is_uploaded_file($file)){
    $avatarfile = $apt->upload_path."/".$apt->cookie['cid'].".".'avatar';
    $do = @move_uploaded_file($file,"$avatarfile");}
    }
    if($do){$newavatar = 1;}else{$newavatar = 0;}
    }else{
    if($avatar == 1){
    $newavatar = 1;}else{
    $newavatar = 0;}
    }

    if (!$apt->is_Str($usertheme))
    {
        $usertheme ="arabportal";  
    }

    $result    =   $apt->query("update rafia_users set homepage='$homepage',
                                                         email='$email',
                                                         viewemail='$viewemail',
                                                         showemail='$showemail',
                                                         html_msg='$html_msg',
                                                         usertheme='$usertheme',
                                                         signature='$signature',
                                                         avatar='$newavatar'
                                                         WHERE userid='".$apt->cookie['cid']."'");

     if ($result)
    {

        $apt->bodymsg(LANG_MSG_INFORMATION_HAS_MODIFIED,"$PHP_SELF?action=cp");
    }
    else
    {
        $apt->bodymsg(LANG_ERROR_ADD_DB,"$PHP_SELF?action=cp");
    }
}
else if ($apt->get['action']=="signup")
{
    if ($apt->getsettings("newuserallow") == 'no')
    {
        $apt->errmsg(LANG_ERROR_REGISTER_CLOSED);
    }

    if ( $apt->cookie['cid'] == $apt->Guestid)
    {
        session_unset();
        session_destroy();
       $apt->setoutcookie();
        $apt->head(LANG_TITLE_REGISTRATION,1);
        $reg_rules = $apt->getsettings("reg_rules");
        eval("\$index_middle = \" " . $apt->gettemplate ( 'register_policy' ) . "\";");

        $fo = new form;
        $fo->countpost = $apt->getsettings("txtcount7");
        $fo->use_smiles = 0;
        $form .= $fo->inputform  ($apt->lang_form['11'],"text", "username","*");
        $form .= $fo->inputform  ($apt->lang_form['12'],"password", "password","*");
        $form .= $fo->inputform  ($apt->lang_form['13'],"password", "password2","*");
        $form .= $fo->inputform  ($apt->lang_form['14'],"text", "email","*","","30");
        $form .= $fo->inputform  ($apt->lang_form['38'].$apt->lang_form['14'],"text", "email2","*","","30");
        $form .= $fo->inputform  ($apt->lang_form['15'],"text", "homepage","","http://","30");  // Edited by Myrosy
        $form .= $fo->yesorno($apt->lang_form['37'], "viewemail", 0);
        $form .= $fo->yesorno    ($apt->lang_form['32'], "showemail", 1);
        $form .= $fo->yesorno    ($apt->lang_form['31'], "html_msg", 0);
        $form .= $fo->selectstheme ($apt->theme);
        $form .= $fo->hiddenform  ("spam","1");
        $form .= $fo->txtcount   ();
        $form .= $fo->textarea   ($apt->lang_form['17'],"post",$signature,"6");

        $image = "themes/".$GLOBALS[themepath]."/do.gif";

        $output = array("action"      => "members.php?action=insert",
                        "title"      => LANG_TITLE_REGISTRATION,
                        "method"     => 'post',
                        "name"       => '',
                        "content"    => $form,
                        "image"      => $image
                       );
                       
         $index_middle .= $fo->formtable($output,1,'regnotspam');
         $apt->html_Output($left_menu);
    }
    else
    {
        $apt->head(LANG_TITLE_REGISTRATION);
        $apt->errmsg(LANG_ERROR_MEMBER_REGISTER_REACCESS);
    }
}
else if ($apt->get['action']=="insert")
{
    $newuserallow = $apt->getsettings("newuserallow");
    
    if ($newuserallow == 'no')
    {
        $apt->errmsg($error_member[8]);
    }
    @extract($HTTP_POST_VARS);

    $this_url = explode('/',$_SERVER['HTTP_HOST']);
    $reff_url = explode('/',$_SERVER['HTTP_REFERER']);

    if($this_url[0] !== $reff_url[2]){
    $apt->bodymsg('عفوا ... لا يمكنك تسجيل مستخدم من خارج الموقع',"members.php?action=signup");
    }

    if($spam !== 'regnotspam'){
    $apt->bodymsg('عفوا ... كود التأكيد غير متطابق',"members.php?action=signup");
    exit;
    }

    $fullarr =  array($username,$password,$email);

    if (!$apt->full($fullarr))
    {
        $apt->errmsg(LANG_ERROR_VALIDATE);
    }

    if ($apt->check_name($username))
    {
        $apt->errmsg (LANG_ERROR_USERNAME_MUST_BE);
    }
    
    if ($apt->txtcounmxs($username,2))
    {
        $apt->errmsg(LANG_ERROR_USERNAME_MUST_MORE);
    }
    
  if (!$apt->checkifues("username",$username))
    {
        $apt->errmsg (LANG_ERROR_USERNAME_EXISTED);
    }

    if ($apt->txtcounmxs($password,3))
    {
        $apt->errmsg(LANG_ERROR_PASS_MUST_MORE);
    }

    if ($password != $password2)
    {
        $apt->errmsg (LANG_ERROR_PASS_EQUAL);
    }

  if (!$apt->check_email($email))
    {
        $apt->errmsg(LANG_ERROR_VALID_EMIAL);
    }
    if ($email != $email2)
    {
        $apt->errmsg (LANG_ERROR_EMAIL_EQUAL);
    }
    if (!$apt->checkifues("email",$email))
    {
        $apt->errmsg (LANG_ERROR_EMIAL_EXISTED);
    }

    if (!$apt->txtcounmxs($post,$apt->getsettings("txtcount7")))
    {
        $apt->errmsg(LANG_ERROR_LETTER_MAX);
    }


    $username  = $apt->format_data($username);
    $password  = $apt->format_data(md5($password));
    $homepage  = $apt->format_data($homepage);
    $email     = $apt->format_data($email);
    $signature = $apt->format_post($post);
    $activate  = $apt->makeactivate();
    $viewemail = $apt->format_data($viewemail);
    $showmail  = intval($apt->format_data($showmail));
    $usertheme = $apt->format_data($usertheme);
    $html_msg  = intval($apt->format_data($html_msg));

    if (!$apt->is_Str($usertheme)){$usertheme = $apt->theme;}

    $datetime  = time();

    $result=$apt->query("insert into rafia_users (username,
                                                    password,
                                                    usergroup,
                                                    email,
                                                    homepage,
                                                    viewemail,
                                                    showemail,
                                                    signature,
                                                    datetime,
                                                    allowpost,
                                                    activate,
                                                    usertheme,
                                                    html_msg)
                                              values
                                                    ('$username',
                                                    '$password',
                                                    '4',
                                                    '$email',
                                                    '$homepage',
                                                    '$viewemail',
                                                    '$showemail',
                                                    '$signature',
                                                    '$datetime',
                                                    '$newuserallow',
                                                    '$activate',
                                                    '$usertheme',
                                                    '$html_msg')");

   if ($result)
   {
   	   $Counter->increment('usersCount');
   	   
       if($newuserallow == "wit")
       {
           $url       = $apt->getsettings("siteURL")."/members.php?action=activate&allowid=$activate";
           $sitetitle = $apt->getsettings("sitetitle");
           $sitemail  = $apt->getsettings("sitemail");
           eval("\$subject = \" " . $apt->getsettings("subject_activate") . "\";");

           $replace   =  array(  "{username}"  => $apt->post['username'] ,
                                 "{sitetitle}" => $sitetitle,
                                 "{url}"       => $url,
                                 "{sitemail}"  => $delaleurl);
           $mail = new email;
           $message = $apt->getmessage('msg_activate',0,$replace);
           $mail->send($email,
           $subject,
           $message,
           $sitetitle,
           $sitemail,
           0);
           
           $apt->head($title);

          $index_middle = LANG_MSG_YOUR_REGISTRATION_WHIT_APPROVED;

          $apt->html_Output($left_menu);
        }elseif($newuserallow == "swt"){
            $index_middle = LANG_MSG_YOUR_REGISTRATION_WHIT_APPROVED_BYCP;
        }
        else
        {
            $apt->bodymsg(LANG_MSG_YOUR_REGISTRATION_SUCCESSFULLY,"index.php");
        }
   }
   else
   {
        $apt->bodymsg(LANG_ERROR_ADD_DB,"index.php");
   }
}
else if ($apt->get['action']=="logout")
{
    session_unset();
    session_destroy();
    $apt->setoutcookie();
    header("Refresh: 0;url=".$apt->refe);
    $apt->bodymsg(LANG_MSG_LOGED_OUT,$apt->refe);
}
else if ($apt->get['action']=="lostpass")
{
    if(!isset($HTTP_GET_VARS['code']))
    {
        $apt->errmsg(LANG_ERROR_URL);
    }
    $code = $apt->format_data($HTTP_GET_VARS['code']);

    $result = $apt->query("SELECT email,username FROM rafia_users WHERE activate='$code' and useradmin !='1'");

    if($apt->dbnumrows($result)>0)
    {
         $apt->head (LANG_TITLE_SEND_MESSAGE_TO_MEMBER);
         $fo = new form;


       $form .= $fo->hiddenform ("code","$code");
       $form .= $fo->hiddenform ("action","uppass");
       $form .= $fo->inputform  ("رقم العضوية","text", "myuserid","*");
       $form .= $fo->inputform  ("كلمة المرور الجديدة ","text", "mynewpass","*");
       $form .= $fo->inputform  ("تاكيد  كلمة المرور الجديدة ","text", "mynewpass2","*");
       $image = "themes/".$GLOBALS[themepath]."/do.gif";

        $output = array("action"      => "$PHP_SELF?action=uppass",
                        "title"       => "تعيين كلمة مرور جديدة",
                        "method"      => '',
                        "name"        => '',
                        "content"     => $form,
                        "image"       => $image
                       );
         $index_middle  = $fo->formtable($output);
         $right_menu    =  $menu->_menu(1);
         $apt->html_Output("");

    }
    else
    {
        $apt->errmsg("لا يمكن تغيير كلمة المرور الرجاء مراجعة إدارة الموقع");
    }
}
else if ($apt->get['action']=="uppass")
{
     $arr_post_vars = array($apt->post['action'],
                            $apt->post['code'],
                            $apt->post['myuserid'],
                            $apt->post['mynewpass'],
                            $apt->post['mynewpass2']);
                            
     if (!$apt->full($arr_post_vars))
     {
         $apt->errmsg(LANG_ERROR_VALIDATE);
     }
     if ($apt->post['mynewpass'] != $apt->post['mynewpass2'])
    {
        $apt->errmsg (LANG_ERROR_PASS_EQUAL);
    }

    if ($apt->txtcounmxs($apt->post['mynewpass'],4))
    {
        $apt->errmsg(LANG_ERROR_PASS_MUST_MORE);
    }

    $mynewpass = $apt->format_data(md5($apt->post['mynewpass']));

    $result    = $apt->query("update rafia_users set
                                password='$mynewpass'
                                WHERE activate='".$apt->post['code']."'
                                and userid='".$apt->post['myuserid']."'
                                and useradmin !='1'");
    if ($result)
    {
        $apt->setoutcookie ();

        $apt->bodymsg(LANG_MSG_PASSWORD_HAS_CHANGED,"$PHP_SELF?action=cp");

     }
     else
    {
        $apt->bodymsg(LANG_ERROR_ADD_DB,"index.php");
    }
}
else if ($apt->get['action']=="activate")
{
    $get_activate = $apt->format_data($HTTP_GET_VARS['allowid']);

    $result = $apt->query("SELECT allowpost FROM rafia_users WHERE
                           activate='$get_activate'");


    $row = $apt->dbarray($result);

    @extract($row);

    if ($allowpost == "no")
    {
        $apt->head(LANG_TITLE_REGISTRATION);

        $index_middle = LANG_ERROR_YOU_STOPPING;

       $apt->html_Output($left_menu);

    }
    elseif (( $allowpost == "wit") || ($allowpost == "yes"))
    {
        $result = $apt->query("update rafia_users set allowpost='yes' WHERE activate='$get_activate'");

        if ($result)
        {
            $apt->head(LANG_TITLE_REGISTRATION);
            $index_middle = '<b>'.LANG_MSG_YOUR_ACCOUNT_HAS_APPROVED;
            $index_middle .='<a href="members.php?action=cp"><br><font color="#FF0000">لوحة التحكم</a>';
            $apt->html_Output($left_menu);
        }
        else
        {
            $apt->bodymsg(LANG_ERROR_ADD_DB,"index.php");
        }
    }
}
else if ($apt->get['action']=="delale")
{
checkcookie();
$userid = $apt->cookie['cid'];

$news_id = (int) $_GET[news_id];
$thread_id = (int) $_GET[thread_id];
$down_id = (int) $_GET[down_id];

    if ($news_id !="0")
    {
        $result = $apt->query("delete from  rafia_alert
                                              WHERE news_id='$news_id'
                                              and userid='$userid'");
    }
    elseif ($thread_id !="0")
    {
        $result = $apt->query("delete from  rafia_alert
                                              WHERE thread_id='$thread_id'
                                              and userid='$userid'");
    }
    elseif ($down_id !="0")
    {
        $result = $apt->query("delete from  rafia_alert
                                              WHERE down_id='$down_id'
                                              and userid='$userid'");
    }
    if ($result)
    {
         $apt->bodymsg('',"index.php");
    }
    else
    {
         $apt->bodymsg(LANG_ERROR_ADD_DB."index.php");
    }
}
else if ($apt->get['action']=="chngthem"){
$apt->GroupAllow('view_site');
$userid = $apt->cookie['cid'];
if($userid == $apt->Guestid)$apt->errmsg("عفوا ... عضوية الزائر ليس لها حق في اختيار التصميم");
checkcookie();
$utheme = addslashes(trim($apt->get['utheme']));
$result = $apt->query("update rafia_users set usertheme='$utheme' where userid='$userid'");
$apt->set_cookie ("logintheme",$utheme);
$_SESSION["sesstheme"]   = $utheme;
$apt->bodymsg("سوف يتم نقلك الى الصفحة السابقة الان ..انتظر قليلا", $apt->refe);
}
elseif($apt->get['action']=="")
{
     $apt->GroupAllow('view_site');
     $apt->GroupAllow('allow_members_list');    
     $apt->head(LANG_TITLE_MEMBERS);


    if ($apt->get[morder] =='userid')
    {
        $order = "userid";
    }
    elseif($apt->get[morder] =='username')
    {
        $order = "username";
    }
    elseif($apt->get[morder] =='usergroup')
    {
        $order = "usergroup";
    }
	 elseif($apt->get[morder] =='topics')
    {
        $order = "allposts";
    }
	 elseif($apt->get[morder] =='regdate')
    {
       $order = "datetime";
    }
    else
    {
        $order = "userid";
    }
    
    
    if ((empty($apt->get[msort])) || ($apt->get[msort] == 'ASC'))
    {
        $sort = ASC;
    }
    else
    {
         $sort = DESC;
    }
	
	// Search Members by letters Added by KHR2003
	// Here is the English letters array
	$letter_eng = 'A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z';
	$letter_eng = explode('|', $letter_eng);
	foreach ($letter_eng as $key => $val)
	$letter_eng[$key] = '<td class="lettercell" align="center"><a href="members.php?action=msearch&by=' . $val . '">' . $val . '</a></td>';
	$english_letters = implode($letter_eng);
	
// here is the arabic letters array
	$letter_ara = 'ا|ب|ت|ث|ج|ح|خ|د|ذ|ر|ز|س|ش|ص|ض|ط|ظ|ع|غ|ف|ق|ك|ل|م|ن|ه|و|ي';
	$letter_ara = explode('|', $letter_ara);
	foreach ($letter_ara as $key => $val)
	$letter_ara[$key] = '<td class="lettercell"><a href="members.php?action=msearch&by=' . $val . '">' . $val . '</a></td>';
	$arabic_letters = implode($letter_ara);
	
					
     $result   = $apt->query("SELECT * FROM rafia_users WHERE userid >'0' and userid != $apt->Guestid ORDER BY $order $sort LIMIT $start,$perpagelist");   // Edited By Myrosy

     $page_result = $apt->query("SELECT userid FROM rafia_users");
      $apt->numrows  = $apt->dbnumrows($page_result);

    if($avatar == 0){
        $avatar_pic = "غير متوافرة";
    }else{
        $avatarfile = $apt->upload_path."/".$userid.".".'avatar';
        if(file_exists($avatarfile)){
        $avatar_pic = "<img src=members.php?action=image&userid=".$userid.">";
        }else{
        $avatar_pic = "غير متوافرة";
        }	
    }         

     while($row = $apt->dbarray($result))
	 {
         @extract($row);
         $homepage = $apt->addToURL ($homepage);
         $username = $apt->format_data_out($username);
         $email    = $apt->format_data_out($email);
		 $regdate  = $apt->Hijri($datetime); 
         $apt->color($color);
         eval("\$show_members_list .= \" " . $apt->gettemplate ( 'show_members_list' ) . "\";"); // Added By Myrosy

     }
eval("\$index_middle .= \" " . $apt->gettemplate ( 'show_members' ) . "\";"); // Added By Myrosy

     $index_middle .= $apt->pagenum($perpagelist,"&member=$member&morder=".$apt->get[morder]."&msort=".$apt->get[msort]);
     
     $apt->html_Output($left_menu);


}
else if ($apt->get['action']=="msearch")
{
// member search and arrange by letter hack by KHR2003
     $apt->GroupAllow('view_site');
     $apt->GroupAllow('allow_members_list');    
     $apt->head(LANG_TITLE_MEMBERS);

     $member_lang_head = LANG_TITLE_MEMBERS;

	
	if ($apt->get['by']) {
		$by = $apt->get['by'];
	}elseif ($apt->post['membername'] == '') {
	    $apt->errmsg(LANG_ERROR_SCOPE_SEARCH);
    }else{
		$by = $apt->post['membername'];
	}
   
   if ($apt->get[morder] =='userid')
    {
        $order = "userid";
    }
    elseif($apt->get[morder] =='username')
    {
        $order = "username";
    }
    elseif($apt->get[morder] =='usergroup')
    {
        $order = "usergroup";
    }
	 elseif($apt->get[morder] =='topics')
    {
        $order = "allposts";
    }
	 elseif($apt->get[morder] =='regdate')
    {
       $order = "datetime";
    }
    else
    {
        $order = "userid";
    }
    
    
    if ((empty($apt->get[msort])) || ($apt->get[msort] == 'DESC'))
    {
        $sort = DESC;
    }
    else
    {
         $sort = ASC;
    }
    
	// Here is the English letters array
	$letter_eng = 'A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z';
	$letter_eng = explode('|', $letter_eng);
	foreach ($letter_eng as $key => $val)
	$letter_eng[$key] = '<td class="lettercell" align="center"><a href="members.php?action=msearch&by=' . $val . '">' . $val . '</a></td>';
	$english_letters = implode($letter_eng);
	
// here is the arabic letters array
	$letter_ara = 'ا|ب|ت|ث|ج|ح|خ|د|ذ|ر|ز|س|ش|ص|ض|ط|ظ|ع|غ|ف|ق|ك|ل|م|ن|ه|و|ي';
	$letter_ara = explode('|', $letter_ara);
	foreach ($letter_ara as $key => $val)
	$letter_ara[$key] = '<td class="lettercell"><a href="members.php?action=msearch&by=' . $val . '">' . $val . '</a></td>';
	$arabic_letters = implode($letter_ara);
	
	// Here is the search part
     $result   = $apt->query("SELECT * FROM rafia_users WHERE username REGEXP '^$by' AND userid >'0' and userid != $apt->Guestid ORDER BY $order $sort LIMIT $start,$perpagelist");   // Edited By Myrosy

   //  $page_result = $apt->query("SELECT * FROM rafia_users ");
      $apt->numrows  = $apt->dbnumrows($result);

    if($avatar == 0){
        $avatar_pic = "غير متوافرة";
    }else{
        $avatarfile = $apt->upload_path."/".$userid.".".'avatar';
        if(file_exists($avatarfile)){
        $avatar_pic = "<img src=members.php?action=image&userid=".$userid.">";
        }else{
        $avatar_pic = "غير متوافرة";
        }	
    }         

     while($row = $apt->dbarray($result))
	 {
         @extract($row);
         $homepage = $apt->addToURL ($homepage);
         $username = $apt->format_data_out($username);
         $email    = $apt->format_data_out($email);
		 $regdate  = $apt->Hijri($datetime); 
         $apt->color($color);
         eval("\$show_members_list .= \" " . $apt->gettemplate ( 'show_members_list' ) . "\";"); // Added By Myrosy

     }
eval("\$index_middle .= \" " . $apt->gettemplate ( 'show_members' ) . "\";"); // Added By Myrosy

     $index_middle .= $apt->pagenum($perpagelist,"&member=$member&morder=".$apt->get[morder]."&msort=".$apt->get[msort]);
     
     $apt->html_Output($left_menu);

}

if(isset($fo))
{
    print $apt->script->post_java();
}
$apt->foot($pageft);

?>