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

require_once('global.php');
$menu = new menu;
$middle_menu =  $menu->middle_menu();

if ( $apt->get['action'] == "" )
{
    $arr_subject = explode ("\n",$apt->getsettings('mailsubject'));

    $apt->head(LANG_TITLE_CONTACT_US);

    $fo = new form;
    $form .= $fo->inputform($apt->lang_form['16'], "text", "fromname","*");
    $form .= $fo->inputform($apt->lang_form['14'], "text", "fromail","*");
    $form .= $fo->selectsform($apt->lang_form['22']);
    $form .= $fo->textarea($apt->lang_form['23'],"message","","8");
    $form .= $fo->hiddenform  ("spam","1");
    $image = "themes/".$GLOBALS[themepath]."/do.gif";

        $output = array("action"      => "$PHP_SELF?action=sended",
                        "title"      => LANG_TITLE_CONTACT_US,
                        "method"     => '',
                        "name"       => '',
                        "content"    => $form,
                        "image"      => $image
                       );
         $index_middle  = $fo->formtable($output,1,'mailnotspam');

    $right_menu    =  $menu->_menu(1);
    $apt->html_Output("");
    
}elseif ( $apt->get['action'] == "report" ){
    checkcookie();
    $apt->head('الابلاغ عن مشاركة سيئة');
    $fo = new form;
    $form .= $fo->hiddenform("fromname",$apt->cookie['cname']);
    $form .= $fo->hiddenform("id",intval($apt->get[id]));
    $form .= $fo->hiddenform("comment",intval($apt->get[comment]));
    $form .= $fo->textarea($apt->lang_form['23'],"message","","10");
    $form .= $fo->hiddenform  ("spam","1");
    $image = "themes/".$GLOBALS[themepath]."/do.gif";

        $output = array("action"      => "$PHP_SELF?action=sendreport",
                        "title"      => 'الابلاغ عن مشاركة سيئة',
                        "method"     => '',
                        "name"       => '',
                        "content"    => $form,
                        "image"      => $image
                       );
         $index_middle  = $fo->formtable($output,1,'mailnotspam');

    $right_menu    =  $menu->_menu(1);
    $apt->html_Output("");

}elseif ( $apt->get['action'] == "maillist" ){
$posttybe  = $apt->format_data($apt->post['posttybe']);
     if ($posttybe=="add")
     {
         if (!$apt->check_email($apt->post['email']))
         {
             $apt->errmsg(LANG_ERROR_VALID_EMIAL);
         }
         @extract($HTTP_POST_VARS);

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

         $result = $apt->query("SELECT * FROM rafia_email WHERE email ='$email'");

       if ($apt->dbnumrows($result) < 1){
             $email  = $apt->format_data($apt->post['email']);
             $result = $apt->query("insert into rafia_email (email) values ('$email')");
             if ($result)
             {
                 $apt->bodymsg(LANG_MSG_ADDEMAIL_OK,"index.php");
             }
             else
             {
                 $apt->bodymsg(LANG_ERROR_ADD_DB,"index.php");
             }
         }
         else
         {
             $apt->bodymsg(LANG_ERROR_EMIAL_EXISTED,"index.php");
         }
     }
     elseif($posttybe=="delete")
     {
         @extract($HTTP_POST_VARS);
         
         if (!$apt->check_email($apt->post['email']))
         {
             $apt->errmsg(LANG_ERROR_VALID_EMIAL);
         }
         
         $email  = $apt->format_data($apt->post['email']);
         
         $result = $apt->query("SELECT * FROM rafia_email WHERE email ='$email'");
         
         if ($apt->dbnumrows($result) < 1)
         {
             $apt->bodymsg(LANG_ERROR_VALID_EMIAL,"index.php");
         }
         else
         {
             $result = $apt->query("delete from  rafia_email where email='$email'");

             if ($result)
             {
                 $apt->bodymsg(LANG_MSG_DELEMAIL_OK,"index.php");
             }
             else
             {
                 $apt->bodymsg(LANG_ERROR_ADD_DB,"index.php");
             }
         }
     }
 }
else if($apt->get['action']=="send")
{
    @extract($HTTP_POST_VARS);

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

    if (!$apt->check_email($apt->post['tomail']))
       {
           $apt->errmsg(LANG_ERROR_VALID_EMIAL);
       }

    if (!$apt->check_email($apt->post['fromail']))
       {
           $apt->errmsg(LANG_ERROR_VALID_EMIAL);
       }

       $mail = new email;

       $mail->send($tomail,@constant($apt->getsettings("sendpage")),$message,$fromname,$fromail,0);


    $apt->bodymsg($lang_form['41'],"index.php");
}
else if($apt->get['action']=="sendreport")
{
    @extract($HTTP_POST_VARS);

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

    $fromname = $apt->format_post($apt->post[fromname]);
    $message = $apt->format_post($apt->post[message]);

    $replace     =  array(  "{name}"      => $fromname,
                            "{url}"       => $apt->getsettings("siteURL")."forum.php?action=view&id=$id#comment$comment",
                            "{message}"  => $message,
                            "{sitetitle}" => $apt->getsettings("sitetitle"));
    eval ("\$allmessage = \"".$apt->getmessage("msg_report",0,$replace)."\";");

    $mail = new email;
    $result = $apt->query("SELECT `email` FROM `rafia_users` WHERE `usergroup` = '1' or `usergroup` = '2'");
    while($row = $apt->dbarray($result)){
    @extract($row);
    $mail->send($email,"ابلاغ عن مشاركة سيئة",$allmessage,$fromname,$apt->getsettings("sitemail"),0);
    }
    $apt->bodymsg($lang_form['41'],"index.php");
}
else if($apt->get['action']=="sendpage")
{
    $apt->head(LANG_TITLE_TEL_FRIEND);
    $fo = new form;
    $form .= $fo->inputform ($apt->lang_form['20'], "text", "tomail","*");
    $form .= $fo->inputform ($apt->lang_form['16'], "text", "fromname","*");
    $form .= $fo->inputform ($apt->lang_form['14'], "text", "fromail","*");
    
    if ( empty ($apt->refe) )
    {
        $pageurl = $apt->getsettings("siteURL");
    }
    else
    {
        $pageurl = $apt->refe;
    }

   
    $form .=$fo->textarea($lang_form['23'],"message","السلام عليكم ورحمة الله\nصديقي العزيز .. أرجوا ان تزور هذا الموقع \n\n\r".$apt->refe,"8");
    
    $image = "themes/".$GLOBALS[themepath]."/do.gif";

        $output = array("action"      => "$PHP_SELF?action=send",
                        "title"      => LANG_TITLE_TEL_FRIEND,
                        "method"     => '',
                        "name"       => '',
                        "content"    => $form,
                        "image"      => $image
                       );
         $index_middle  = $fo->formtable($output);
         
    
    $right_menu    =  $menu->_menu(1);
    
    $apt->html_Output("");
}
else if($apt->get['action']=="sended")
{
    @extract($HTTP_POST_VARS);

    if($CONF['mach_ip'] == 1){
    $this_url = explode('/',$_SERVER['HTTP_HOST']);
    $reff_url = explode('/',$_SERVER['HTTP_REFERER']);

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

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

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

    if (!$apt->check_email($fromail))
       {$apt->errmsg(LANG_ERROR_VALID_EMIAL);}

if($apt->getsettings('sendme_by') == 'mail'){
       $mail = new email;
       $mail->send($apt->getsettings("sitemail"),$subject,$message,$fromname,$fromail,0);
}else{
$msgdate   = $apt->time;
$fromname = $apt->format_post($apt->post[fromname]);
$fromail = $apt->format_post($apt->post[fromail]);
$subject = $apt->format_post($apt->post[subject]);
$message   = $fromail."=^+^=".$apt->format_post($apt->post[message]);
$ufromid   = $apt->format_data($apt->cookie['cid']);

$apt->query("INSERT INTO rafia_messages
(mailus,msgbox,msgdate,msgisread,msgtitle,message,ufromid,fromname)
VALUES
('1','1','$msgdate','1','$subject','$message','$ufromid','$fromname')");

}
       $url = $apt->getsettings("siteURL");
       if(substr($url,-1) != '/'){$url = $url . '/';}
	 $admin_url = $url.'admin/';
       $mail = new email;
       $mail->send($apt->getsettings("sitemail"),"رساله الى مدير الموقع","لقد وصلت رسالة لك بصفتك مدير الموقع \n لقراءتها قم بفتح لوحة التحكم و اضغط على قراءة رسائل الموقع \n $admin_url",$apt->getsettings("sitetitle"),$apt->getsettings("sitemail"),0);

       $apt->bodymsg($lang_form['41'],"index.php");
}
else if($apt->get['action']=="sendtouser")
{
    @extract($HTTP_POST_VARS);

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

    if(!$apt->check_email($fromail))
    {
        $apt->errmsg(LANG_ERROR_VALID_EMIAL);
    }

       $mail = new email;

       $mail->send($tomail,$subject,$message,$fromname,$fromail,0);

    header("Refresh: 1;url=index.php");
}
else if($apt->get['action']=="sendtousers")
{
$userid = $apt->setid('userid');
   $result = $apt->query("SELECT showemail,email,username FROM
                            rafia_users where userid='$userid'");

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

   @extract($row);

   if($showemail=="1")
   {
       $apt->head (LANG_TITLE_SEND_MESSAGE_TO_MEMBER);
       $fo = new form;
       $form .= $fo->hiddenform ("tomail","$email");
       $form .= $fo->inputform  ($apt->lang_form['16'],"text", "fromname","*");
       $form .= $fo->inputform  ($apt->lang_form['14'],"text", "fromail","*");
       $form .= $fo->inputform  ($apt->lang_form['22'],"text", "subject","*");
       $form .= $fo->textarea   ($apt->lang_form['23'],"message"," السلام عليكم ورحمة الله وبركاته\n  إلى الاخ  $username\n","8");

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

        $output = array("action"      => "$PHP_SELF?action=sendtouser",
                        "title"      => LANG_TITLE_SEND_MESSAGE_TO_MEMBER,
                        "method"     => '',
                        "name"       => '',
                        "content"    => $form,
                        "image"      => $image
                       );
         $index_middle  = $fo->formtable($output);
         $right_menu    =  $menu->_menu(1);
         $apt->html_Output("");
   }
   else
   {
       $apt->errmsg ($username ." , لايستقبل رسائل على بريدة" );
   }
}

$apt->foot($pageft);
?>