<?php 
/*
##################################################################
#                       PHP 4&5 MySQL 4&5                        #
##################################################################
#           Copyright (c) 2004-2008 Armia Systems Inc            #
##################################################################
#               This file is part of Cybermatch site             #
##################################################################
#    Developed By: simi (simi@armia.com)                         #

##################################################################
#               Developed On:   03-04-2008                       #
##################################################################
#               Modified By:                                     #
##################################################################
#               Modified On:                                     #
##################################################################
# This script may not be distributed, sold, given away for free  #
# to third party, or used as a part of any internet services 	 #
# such as webdesign etc.                                         #
##################################################################
*/

require_once ("config.inc.php");
require_once ("includes/userlogincheck.inc.php");
require_once ("includes/mysql.inc.php");
require_once ("includes/arrays.inc.php");
require_once ("classes/misc.class.php");
require_once ("classes/userside.class.php");

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

if (!$objDB) {
	$message	= "Unable to Locate Database Server.";
} else {
	$objM		= new misc($objDB);
	$objU		= new userside($objDB);	
        
	$objM->set_success_story(array_merge($_POST, $_FILES));
	if (isset($_POST['SaveNow']) AND trim($_POST['SaveNow']) == "SaveStory") {
           
		$message	= $objM->save_my_success_story($_SESSION['user_id'], $id);
		if ($message == "") {
			header("Location: my_stories.php?page=$page");
			exit;
		}
	}
        if (isset($_POST['BackNow'])) {
		//if ($message == "") {
			header("Location: my_stories.php?page=$page");
			exit;
		//}
	}
        //else {
		$array	= $objM->get_my_success_story($_SESSION['user_id'], $id);
		$objM->set_success_story($array);
	//}
	$script		= $objM->get_script($message);
	$message	= $objM->remove_script($message);
}

include_once ("title.inc.php");
include_once ("tophtml.inc.php");
?>
<link href="js/block.css" rel="stylesheet" type="text/css">
<!--<link href="js/facebox.css" media="screen" rel="stylesheet" type="text/css"/>-->
<script type="text/javascript"  src="js/googlefix.js"></script>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/jquery.blockUI.js"></script>
<script src="js/facebox.js" type="text/javascript"></script>
<script type="text/javascript"> 
    $(function() { 
        //
            $('#AP').click(function() { 
                if(validate()){
                            $.extend($.blockUI.defaults.overlayCSS, { backgroundColor: '#00f' });
                            $.extend($.blockUI.defaults.pageMessageCSS, { width:'520px', margin:'-50px 0 0 -125px', top:'70%', left:'40%',textAlign:'left' });
                            $.blockUI('<h1><img src="images/busy.gif" /> Cybermatch is processing your request.  Please be patient...</h1>');
                            test();
                   }
                    }); 
            $('#UB').click(function() { 
               $.unblockUI();
            }); 
          //}
		
 function test() {
	  if (validate1()) {
	  	document.frmUser.SaveNow.value='SaveStory';
      	$("#frmUser").submit();
		//$.unblockUI();
	  }
 }
   }); 
</script> 
<script type="text/javascript">
    jQuery(document).ready(function($) {
      $('a[rel*=facebox]').facebox()
    })
  </script>
<script language="javascript" type="text/javascript">
function changeCSS(obj, type)
{
	if (type == 'text') {
		obj.className = 'textbox txt-bx01';
	} else if (type == 'textarea') {
		obj.className = 'textbox txt-bx01';
	} else if (type == 'select') {
		obj.className = 'textbox txt-bx01';
	} else {
		obj.className = 'textbox txt-bx01';
	}
}

function validate1()
{ 
	var frm	= document.frmUser;
	if (frm.vStory_Title.value == "") {
		frm.vStory_Title.focus();
		frm.vStory_Title.className ='textbox txt-bx01';
		$.unblockUI();
		return false;
	}
	if (frm.tStory.value == "") {
		frm.tStory.focus();
		frm.tStory.className ='textbox txt-bx01';
		$.unblockUI();
		return false;
	}
	return true;
}

function validate()
{ 
	var frm	= document.frmUser;
	
	if (frm.vStory_Title.value == "") {
		alert("Please enter title of the success story.");
		frm.vStory_Title.focus();
		frm.vStory_Title.className ='textbox txt-bx01';
		$.unblockUI();
		return false;
	}
	if (frm.tStory.value == "") {
		alert("Please enter content of your success story.");
		frm.tStory.focus();
		frm.tStory.className ='textbox_textarea txt-bx01';
		$.unblockUI();
		return false;
	}
	return true;
}
</script>
<div class="row">
	<div class="eight columns">
		<div class="search-rslts">
			<div class="row"><div class="inenr-hd"><h2>My Success Story</h2></div></div>
			<div class="row">
				<h2 class="headings2">My Story</h2>
			</div>
			<div class="row">
				<form method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>" enctype="multipart/form-data" name="frmUser" id="frmUser" >
					<div class="newdesignforinput maintext1">
						<?php
						if (isset($message) && trim($message) != '') {
							?>
						<div class="full_row">
							<div class="maintext1 warning"><?php echo $message; ?></div>
						</div>
						<?php }//end if?>
						
						<div class="full_row">
							<div class="three columns">Story Title</div>
							<div class="five columns margin_R_200">
								<input name="vStory_Title" type="text" class="textbox txt-bx01" onKeyDown="changeCSS(this, 'text');" value="<?php echo htmlspecialchars($objM->vStory_Title) ?>" size="40" maxlength="100">
							</div>
						</div>
						
						<div class="full_row">
							<div class="three columns">Story Content</div>
							<div class="five columns margin_R_200">
								<textarea name="tStory" cols="70" rows="14" class="textbox_textarea txt-bx01" onKeyDown="changeCSS(this, 'textarea');"><?php echo $objM->tStory ?></textarea>
							</div>
						</div>
						<?php if ($objM->vPicURL <> "") { ?>
						<div class="full_row">
							<div class="three columns">Current Image</div>
							<div class="five columns margin_R_200">
								<a href="<?php echo $objM->vPicURL <> "" ? $siteSettings['site_normal_url'].STORY_IMAGE_URL . '/' . $objM->vPicURL : ($objM->vGender == "Male" ? $siteSettings['site_normal_url'].STORY_IMAGE_URL . '/' . "nophotosuccess.gif" : $siteSettings['site_normal_url'].STORY_IMAGE_URL . '/' . "nophotosuccess1.gif") ?>" rel="facebox">
									<img src="<?php echo $objM->vPicURL <> "" ? $siteSettings['site_normal_url'].STORY_IMAGE_URL . '/' . "sthumb_" . $objM->vPicURL : ($objM->vGender == "Male" ? $siteSettings['site_normal_url'].STORY_IMAGE_URL . '/' . "nophotosuccess.gif" : $siteSettings['site_normal_url'].STORY_IMAGE_URL . '/' . "nophotosuccess1.gif") ?>" border="0">
								</a>
							</div>
						</div>
						
						<div class="full_row">
							<div class="three columns">Change Image</div>
							<div class="five columns margin_R_200">
								<input name="file" type="file" class="textbox txt-bx01">
							</div>
						</div>
						<?php } else { ?>
						<div class="full_row">
							<div class="three columns">Story Image</div>
							<div class="five columns margin_R_200">
								<input name="file" type="file" class="textbox txt-bx01">
							</div>
						</div>
						<?php } ?>
						<div class="full_row">
							<div class="three columns">&nbsp;</div>
							<div class="five columns margin_R_200">
								<input name="BackNow" type="submit" class="loginbutton" value="Back"><?php //if ($id > 0) { ?>&nbsp;&nbsp;&nbsp;&nbsp;<input name="AP" type="submit" class="loginbutton" id="AP" value="Save Story" onclick="return validate();">
								<input type="hidden" name="vPicURL" value="<?php echo $objM->vPicURL ?>"><?php //} ?>
								<input type="hidden" name="id" value="<?php echo $id ?>">
								<input type="hidden" name="SaveNow" value="SaveStory">
								<input type="hidden" name="page" value="<?php echo $page ?>">
							</div>
						</div>
					</div>
				</form>
			</div>
			<div id="hide"><?php echo $script ?></div>
		</div>
	</div>
	<div class="four columns right search_result_R"><?php include_once ("left.inc.php"); ?></div>
</div>


<?php include_once('bottomhtml.inc.php');?>
