<?
ob_start();
require_once("functions.php");
    if(!isset($_COOKIE[$admin])){
        header('Location: index.php');
    }
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<link href="css/style.css" rel="stylesheet" type="text/css" />

</head>

<body onload="clickMenu('menu')">
<!-- outer -->
<div id="outer">
	<!-- header ----------------------------------------------------->
	<div id="header"> <? include("header.php")?> </div>
	<!-- header -->
    
    <!-- content ---------------------------------------------------->
	<div id="content">
        <!-- con_right --------------------------------------->
	   <div id="con_right">
            <div class="title_page">إدارة الرسائل</div>
            <!--<a href="add_father.php"><div class="add_father"><img src="images/add_48.png" /> إضافة قسم</div></a>-->
           
            <div class="path_page">
              مركز الرسائل
                <img src="images/001_27.gif" width="10" height="10" />
                <a href="info.php">الرئيسية</a>
                
                
            </div>
            <div class="conteaner">
                <div class="details_page">
                  هنا يمكنك قراءة الرسالة والرد عليها
                    <br /><br /><hr /><br />
                </div>
                <div class="title_editor">
                    <span class="title">مركز الرسائل</span>
                </div>
                
                <div class="editor">
                    <?
                        //fetch data from db
                        $idd=$_GET['id'];
                        $sel = "select * from message where id=$idd";
                        $query = mysql_query($sel);
                        while($result=mysql_fetch_array($query)){
                            extract($result);
                            $mailcustomer = $mail;
                                
                        }
                        $update="update message set status='1' where id=$idd";
                        $qu=mysql_query($update);
                        
                        //reblay
                        $replay = $_POST['replay'];
                        if($replay){
                            
                            $reblaymsg = $_POST['reblaymsg'];
                            if($reblaymsg != ""){
                                 
                                 //fetch mail admin from db 
                                $sel="select * from users where adm_mem='1'";
                                $query = mysql_query($sel);
                                while($result = mysql_fetch_array($query)){
                                    extract($result);
                                    $mailadmin = $mail;
                                    $nameadmin = $name;
                                }
                                //send reblay
                                $to= $mailcustomer;
                                $subject= "reblay on your message";
                                $message= "$reblaymsg";
                                mail($to, $subject, $message);
                                if($qu){
                                    echo "<font color='green'><b>شكرً لك $nameadmin الآن يتم إرسال ردك</b></font> <img src='images/loading11.gif' />".
                                        "<meta http-equiv='refresh' content='5'>";
                                            
                                }
                                        
                            }else{echo "<font color='red'><b>please insert reblay & tray again</b></font>";}
                        }
                    ?>
                    
                    <form method="post" action="<?$_SERVER['PHP_SELF']?>">
                        <table dir="ltr">
                            <tr>
                                <td align="right"><span><?=$date_time?></span></td>
                                <td class="th_table"><span class='desmsgt'>تاريخ الارسال</span></td>
                            </tr>
                            <tr>
                               <td align="right"><span class='desmsg'><?=$name?></span></td>
                               <td class="th_table"><span class='desmsgt'>الراسل </span></td>
                            </tr>
                            <tr>
                               <td align="right"><span class='desmsg'><?=$company?></span></td>
                               <td class="th_table"><span class='desmsgt'>الشركة</span></td>
                            </tr>
                            <tr>
                               <td align="right"><span class='desmsg'><?=$mailcustomer?></span></td>
                               <td class="th_table"><span class='desmsgt'>البريد</span></td>
                            </tr>
                            <tr>
                               <td align="right"><span class='desmsg'><?=$content?></span></td>
                               <td class="th_table"><span class='desmsgt'>التفاصيل</span></td>
                            </tr>
                            <tr>
                               <td><hr /></td>
                               <td><hr /><hr /></td>
                            </tr>
                            <tr>
                               <td class="th_table"><textarea class="desmsgt" dir="rtl" cols="65" rows="10" name="reblaymsg"></textarea></td>
                               <td class="th_table"><span class='desmsgt'>الرد على الرسالة</span></td>
                            </tr>
                            <tr>
                               <td><span><input class='submit' type="submit" name="replay" value="replay" /></span></td>
                               <td></td>
                            </tr>
                            
                        </table>
                    </form>
                </div>
                
            </div>
       </div>
	   <!-- /con_right -->
       
       <!-- con_left ---------------------------------------->
	   <div id="con_left">
            <!-- menu ---------------------------------->
            <div id="menuall"> <? include("menu.php")?> </div>
            <!-- /menu -->
            
            <!-- calender ------------------------------>
            <div id="calender"><embed src="images/Calender.swf" width="235" height="320" /></embed></div>
            <!-- /calender -->
       </div>
	   <!-- /con_left ---------------------------------------->
    </div>
	<!-- /content -->
    
    <!-- footer ----------------------------------------------------->
	<div id="footer"> <? include("footer.php")?> </div>
	<!-- /footer -->
</div>
<!-- /outer -->
</body>
</html>
<?ob_flush();?>