<?php
require_once ("../config.inc.php");
require_once ("../includes/adminlogincheck.inc.php");
require_once ("../includes/mysql.inc.php");
require_once ("../includes/arrays.inc.php");
require_once ("../classes/users.class.php");
require_once ("../classes/check.class.php");

$page		= isset($_REQUEST['page'])	?	trim($_REQUEST['page'])	:	"1";
$id			= isset($_REQUEST['id'])	?	trim($_REQUEST['id'])	:	"0";
$message	= "";
$objC		= new check();
if (!$objDB) {
	$message	= "Unable to Locate Database Server.";
} else {
	$objU		= new users($objDB);
	$objU->set_message($_POST);
	if (isset($_POST['SaveNow'])) {
		$message	= $objU->save_message($id);
		if ($message == "") {
			header("Location: messages.php?page=$page&act=1");
			exit;
		}
	} elseif (isset($_POST['BackNow'])) {
		if ($message == "") {
			header("Location: messages.php?page=$page");
			exit;
		}
	} else {
		$array	= $objU->get_message($id);
		$objU->set_message($array);
	}
}

include_once('title.inc.php');
?>
<script type="text/javascript" src="../date/date-picker.js"></script>
<style type="text/css">
  div.calendar_widget { position: absolute; top: 0px; left: 0px; width:140px; height: 200px; display: none; }
</style>
<script language="javascript" type="text/javascript">
function validate()
{
	var frm	= document.frmUser;
	
	if (frm.vTitle.value == "") {
		alert("Please enter title of the message.");
		frm.vTitle.focus();
		return false;
	}
	if (frm.tContent.value == "") {
		alert("Please enter message.");
		frm.tContent.focus();
		return false;
	}
}
</script>
<?php include_once('tophtml.php');?>
<table width="100%"  border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td valign="top" class="white"><table width="100%"  border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="72%" valign="top">
			<table width="100%"  border="0" cellspacing="0" cellpadding="5">
          <tr>
            <td><table width="100%"  border="0" cellspacing="0" cellpadding="5">
              <tr>
                <td width="41%" class="headings1" colspan="2">Message Details</td>
              </tr>
            </table>
			<div class="bordernew padding2">
				<form name="frmUser" method="post" action="" onSubmit="return validate();">
          <table width="100%"  border="0" cellspacing="0" cellpadding="5">
            <tr>
              <td><table width="100%"  border="0" cellspacing="0" cellpadding="0">
				<?php if ($objDB) 
					  { 
				?>
					<?php 	if(isset($message) && $message!='')
							{
					?>
                <tr align="left">
                  <td align="center" class="maintext2">&nbsp;</td>
                  <td colspan="2" class="maintext2 warning"><?php echo $message;?></td>
                  </tr>
					<?php  	}//end if?>
  				<tr align="left">
                                    
                  <td width="3%" class="maintext2">&nbsp;</td>
                  <td width="27%" class="maintext2">Message Title</td>
                  <td width="70%" class="maintext2"><?php echo htmlspecialchars($objU->vTitle)?></td>
  				</tr>
                  <tr align="left">
                  <td valign="top" class="maintext2">&nbsp;</td>
                  <td valign="top" class="maintext2">From</td>
                  <td valign="top" class="maintext2"><?php echo $objU->vLogin_From?></td>
                 </tr>
                 <tr align="left">
                  <td valign="top" class="maintext2">&nbsp;</td>
                  <td valign="top" class="maintext2">To</td>
                  <td valign="top" class="maintext2"><?php echo $objU->vLogin_To?></td>
                 </tr>
                                
                 <tr align="left">
                  <td valign="top" class="maintext2">&nbsp;</td>
                  <td valign="top" class="maintext2">Message Content</td>
                  <td valign="top" class="maintext2"><?php echo $objU->tContent?></td>
                 </tr>
               <!-- <tr align="left">
                  <td class="maintext2">&nbsp;</td>
                  <td class="maintext2">Read</td>
                  <td class="maintext2"><input type="checkbox" name="vStatus" value="RN" <?php echo $objU->vStatus == "RN" ? "checked" : ""?>></td>
                </tr>-->
				<?php 			
						}//end first if
				?>
              </table>
                <table width="100%"  border="0" cellspacing="0" cellpadding="0">
                  <tr>
                    <td align="right"><table width="100%"  border="0" cellspacing="0" cellpadding="0">
                      <tr>
                        <td>&nbsp;</td>
                      </tr>
                    </table>
                      <?php if ($objDB) 
					  { 
					?>
                      <table width="100%"  border="0" cellspacing="0" cellpadding="5">
                      <tr>
                        <td align="left"><table width="100%"  border="0" cellspacing="0" cellpadding="0">
                            <tr>
							<td width="30%">&nbsp;</td>
                              <td><!--<input type="submit" class="loginbutton" name="SaveNow" value="Save">-->
                                      <input type="hidden" name="page" value="<?php echo $page?>">
                                      <input type="hidden" name="id" value="<?php echo $id?>"></td>
								<?php if ($id > 0) { ?>
                                                        <td><input name="BackNow" type="button" class="back-btn" value="Back" onclick="window.location='messages.php?page=<?php echo $page?>'"></td>
								<?php } ?>
                              </tr>
                        </table></td>
                      </tr>
                    </table>
					<?php 		
						}//end first if
				?></td>
                  </tr>
                </table></td>
            </tr>
          </table></form>
			</div>
			</td>
          </tr>
        </table>
		</td>
        </tr>
    </table>      
    </td>
  </tr>
</table>
<div class="calendar_widget" id="calendar_widget" style="display:none "><iframe id='calendar_widget_iframe' name='calendar_widget_iframe' style="border: none;" width=100% height=100% src="../date/calendar_widget.html" /></div>
<?php include_once('bottomhtml.php');?>