<?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/miscellaneous.class.php");

$page		= isset($_REQUEST['page'])	?	trim($_REQUEST['page'])	:	"1";
$id			= isset($_REQUEST['id'])	?	trim($_REQUEST['id'])	:	"0";
$message	= "";

if (!$objDB) {
	$message	= "Unable to Locate Database Server.";
} else {
	$objM		= new miscellaneous($objDB);
	$objM->set_success_story(array_merge($_POST, $_FILES));
	if (isset($_POST['SaveNow'])) {
		$message	= $objM->save_success_story($id);
		if ($message == "") {
			header("Location: stories.php?page=$page&act=1");
			exit;
		}
	} elseif (isset($_POST['BackNow'])) {
		if ($message == "") {
			header("Location: stories.php?page=$page");
			exit;
		}
	}else {
		$array	= $objM->get_success_story($id);
		$objM->set_success_story($array);
	}
}

include_once('title.inc.php');
?>
<script type="text/javascript" src="../js/jquery.js"></script>
<script type="text/javascript" src="../js/jquery.autocomplete.js"></script>
<link href="../js/style.css" rel="stylesheet" type="text/css">
<script language="javascript" type="text/javascript">
function validate()
{
	var frm	= document.frmUser;
	
	if (frm.vStory_Title.value == "") {
		alert("Please enter title of the message.");
		frm.vStory_Title.focus();
		return false;
	}
	if (frm.tStory.value == "") {
		alert("Please enter message.");
		frm.tStory.focus();
		return false;
	}
	return true;
}
</script>
<link href="../js/facebox.css" media="screen" rel="stylesheet" type="text/css"/>
<script src="../js/facebox.js" type="text/javascript"></script>
<script type="text/javascript">
    jQuery(document).ready(function($) {
      $('a[rel*=facebox]').facebox()
    })
  </script>
<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"><?php include_once('tophtml.php');?>
			<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">Manage Success Story</td>
                <td width="59%" class="headings1">&nbsp;</td>
              </tr>
            </table></td>
          </tr>
        </table>
		<form action="" method="post" enctype="multipart/form-data" name="frmUser" 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 (is_resource($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%" valign="top" class="maintext2">User (Loginname)</td>
                  <td width="70%" valign="top" class="maintext2"><input name="vLogin" id="ac_me" type="text" value="<?php echo htmlspecialchars($objM->vLogin)?>" size="40" maxlength="100" class="textbox"></td>
  				</tr>
                 <tr align="left">
                  <td class="maintext2">&nbsp;</td>
                  <td valign="top" class="maintext2">Story Title</td>
                  <td valign="top" class="maintext2"><input name="vStory_Title" type="text" value="<?php echo htmlspecialchars($objM->vStory_Title)?>" size="40" maxlength="100" class="textbox"></td>
                 </tr>
                <tr align="left">
                  <td class="maintext2">&nbsp;</td>
                  <td valign="top" class="maintext2">Story Content</td>
                  <td valign="top" class="maintext2"><textarea name="tStory" cols="70" rows="14" class="textbox_textarea"><?php echo $objM->tStory?></textarea></td>
                </tr>
				<?php if ($id > 0) { ?>
                <tr align="left">
                  <td class="maintext2">&nbsp;</td>
                  <td valign="top" class="maintext2">Current Story Image</td>
                  <td valign="top" class="maintext2"><a href="<?php echo $objM->vPicURL <> "" ? STORY_IMAGE_URL."/".$objM->vPicURL : STORY_IMAGE_URL."/nophoto_big.gif"?>" rel="facebox"><img src="<?php echo $objM->vPicURL <> "" ? STORY_IMAGE_URL."/sthumb_".$objM->vPicURL : STORY_IMAGE_URL."/nophoto_big.gif"?>" border="0"></a></td>
                </tr>
                <tr align="left">
                  <td class="maintext2">&nbsp;</td>
                  <td valign="top" class="maintext2">Manage Story Image</td>
                  <td valign="top" class="maintext2"><input type="file" name="file" class="textbox"></td>
                </tr>	
				<?php } else { ?>
                <tr align="left">
                  <td class="maintext2">&nbsp;</td>
                  <td width="27%" valign="top" class="maintext2">Story Image</td>
                  <td width="70%" valign="top" class="maintext2"><input type="file" name="file" class="textbox"></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 (is_resource($objDB)) 
					  { 
					?>
                      <table width="100%"  border="0" cellspacing="0" cellpadding="5">
                      <tr>
                        <td align="center"><table width="10%"  border="0" cellspacing="0" cellpadding="0">
                            <tr>
                              <td><input name="SaveNow" type="submit" class="loginbutton" 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="submit" class="signupbutton" value="Back"><input type="hidden" name="vPicURL" value="<?php echo $objM->vPicURL?>"></td>
							  <?php }//end if?>
                              </tr>
                        </table></td>
                      </tr>
                    </table>
					<?php 		
						}//end first if
				?></td>
                  </tr>
                </table></td>
            </tr>
          </table></form></td>
        </tr>
    </table>      
    </td>
  </tr>
</table>
<?php include_once('bottomhtml.php');?>