<?php
session_start();
global $upload_folder_path;
if($_POST)
{
	include_once( 'wp-load.php' );
	include_once(ABSPATH.'wp-includes/registration.php');
	
	$proprty_name = stripslashes($_POST['proprty_name']);
	$proprty_desc = stripslashes($_POST['proprty_desc']);
	$address = stripslashes($_POST['address']);
	$geo_latitude = $_POST['geo_latitude'];
	$geo_longitude = $_POST['geo_longitude'];
	$map_view = $_POST['map_view'];
	$stdate = $_POST['stdate'];
	$sttime = $_POST['sttime'];
	$enddate = $_POST['enddate'];
	$endtime = $_POST['endtime'];
	$video = $_POST['video'];
	$phone = stripslashes($_POST['phone']);
	$email = $_POST['email'];
	$website = $_POST['website'];
	$twitter = $_POST['twitter'];
	$facebook = $_POST['facebook'];	
	$reg_desc = stripslashes($_POST['reg_desc']);
	$organizer_name = stripslashes($_POST['organizer_name']);
	$organizer_email = stripslashes($_POST['organizer_email']);
	$organizer_address = stripslashes($_POST['organizer_address']);
	$organizer_contact = stripslashes($_POST['organizer_contact']);
	$organizer_website = stripslashes($_POST['organizer_website']);
	$organizer_mobile = stripslashes($_POST['organizer_mobile']);
	$organizer_desc = stripslashes($_POST['organizer_desc']);
	
	$st_date = $_POST['stdate'];
	$end_date = $_POST['enddate'];
	$st_time = $_POST['sttime'];
	$end_time = $_POST['endtime'];
	
	$_SESSION['property_info'] = $_POST;
	
	$_SESSION['error'] = '';
	if($_POST['user_login_or_not']=='new_user')
	{
		$user_login = $_POST['user_email'];
		$user_email = $_POST['user_email'];
		// Check the username
		if ( $user_login == '' )
		$_SESSION['error']=__('Please enter a username.');
		elseif ( !validate_username( $user_login ) ) {
			$_SESSION['error']= __('The publisher Name is invalid.  Please enter a valid username.');
			$user_login = '';
		} elseif ( username_exists( $user_login ) )
			$_SESSION['error']=__('The publisher Name is already registered, please choose another one.');
	
		// Check the e-mail address
		if ($user_email == '') {
			$_SESSION['error']= __('Please type publisher Email address.');
		} elseif ( !is_email( $user_email ) ) {
			$_SESSION['error']= __(' The publisher Email address isn&#8217;t correct.');
			$user_email = '';
		} elseif ( email_exists( $user_email ) )
			$_SESSION['error']= __('The publisher Email is already registered, please choose another one.');
		
		if($_SESSION['error'])
		{
			wp_redirect(get_option('siteurl').'/?ptype=post_event&backandedit=1&emsg=invaliduser');
		}
	}
		
	$image_var = 'organizer_logo';
	if($_FILES[$image_var]['name'])
	{
		$src = $_FILES[$image_var]['tmp_name'];
		if($_FILES[$image_var]['name'] && $_FILES[$image_var]['size']>0)
		{
			$wp_upload_dir = wp_upload_dir();
			$path = $wp_upload_dir['path'];
			$url = $wp_upload_dir['url'];
			$subdir = $wp_upload_dir['subdir'];
			$baseurl = $wp_upload_dir['basedir'];
			$destination_path = $path;
			
			if (!file_exists($baseurl)){
			  mkdir($baseurl, 0777);
			}
			$subdir_arr = explode('/',$subdir);
			for($i=0;$i<count($subdir_arr);$i++)
			{
				$baseurl = $baseurl.$subdir_arr[$i]."/";
				if (!file_exists($baseurl)){
				  mkdir($baseurl, 0777);
				}	
			}
			$baseurl = substr($baseurl,0,strlen($baseurl)-1);
			$name = str_replace(',','_',$_FILES[$image_var]['name']);
			$tmp_name = $_FILES[$image_var]['tmp_name'];
			$target_path = $baseurl. '/' . $name;
			if(move_uploaded_file($tmp_name, $target_path)) 
			{
				$logurl = $url . "/" . $name;
				$_SESSION['property_info']['organizer_logo'] = $logurl;
			}
		}		
	}
	$organizer_logo = $_SESSION['property_info']['organizer_logo'];
}else
{
	$catid_info_arr = get_property_cat_id_name($_REQUEST['pid']);
	$post_info = get_post_info($_REQUEST['pid']);
	$proprty_name = stripslashes($post_info['post_title']);
	$proprty_desc = stripslashes($post_info['post_content']);
	$proprty_feature = stripslashes($post_info['proprty_feature']);	
	$post_meta = get_post_meta($_REQUEST['pid'], '',false);
	$address = stripslashes($post_meta['address'][0]);
	$geo_latitude = $post_meta['geo_latitude'][0];
	$geo_longitude = $post_meta['geo_longitude'][0];
	$map_view = $post_meta['map_view'][0];
	$st_date = $post_meta['st_date'][0];
	$st_time = $post_meta['st_time'][0];
	$end_date = $post_meta['end_date'][0];
	$end_time = $post_meta['end_time'][0];
	$phone = $post_meta['phone'][0];
	$email = $post_meta['email'][0];
	$website = $post_meta['website'][0];
	$twitter = $post_meta['twitter'][0];
	$facebook = $post_meta['facebook'][0];	
	$organizer_name = $post_meta['organizer_name'][0];
	$organizer_email = $post_meta['organizer_email'][0];
	$organizer_address = $post_meta['organizer_address'][0];
	$organizer_contact = $post_meta['organizer_contact'][0];
	$organizer_website = $post_meta['organizer_website'][0];
	$organizer_mobile = $post_meta['organizer_mobile'][0];
	$organizer_logo = $post_meta['organizer_logo'][0];
	$organizer_desc = $post_meta['organizer_desc'][0];	
	$reg_desc = stripslashes($post_meta['reg_desc'][0]);
	$reg_fees = $post_meta['reg_fees'][0];
	
	$st_date = $post_meta['st_date'][0];
	$end_date = $post_meta['end_date'][0];
	$st_time = $post_meta['st_time'][0];
	$end_time = $post_meta['end_time'][0];
	
	if($_REQUEST['pid'])
	{
		$is_delet_property = 1;
	}
}
global $upload_folder_path;
if($_SESSION["file_info"])
{
	$tmppath = $upload_folder_path.'tmp/';
	foreach($_SESSION["file_info"] as $image_id=>$val)
	{
		 
		 $image_src =  get_option('siteurl').'/'.$tmppath.$image_id.'.jpg';
		 break;
	}
}else
{
	$image_src = $thumb_img_arr[0];
	if($_REQUEST['pid']){
	$large_img_arr = bdw_get_images($_REQUEST['pid'],'medium');
	$thumb_img_arr = bdw_get_images($_REQUEST['pid'],'thumb');
	}
	$image_src = $large_img_arr[0];
}
if($_REQUEST['pid'])
{
	$large_img_arr = bdw_get_images($_REQUEST['pid'],'medium');
	$thumb_img_arr = bdw_get_images($_REQUEST['pid'],'thumb');
}

if(function_exists('pt_check_captch_cond') && $_REQUEST['pid']==''){
if(!pt_check_captch_cond())
{
wp_redirect(get_option('siteurl').'/?ptype=post_event&backandedit=1&emsg=captch');
exit;
}
}
?>
<?php get_header(); ?>

<div id="wrapper" class="clearfix">
     <div id="content" class="clearfix" >
<?php include (TEMPLATEPATH . "/library/includes/preview_buttons_event.php");?>    	
        <?php if ( get_option( 'ptthemes_breadcrumbs' )) {  ?>
        <div class="breadcrumb clearfix">
            <div class="breadcrumb_in"><?php yoast_breadcrumb('','');  ?></div>
        </div>
    <?php } ?>
        	<h1><?php echo $proprty_name; ?></h1>  
      
      <div class="event_information">      	
        <div class="date_info">
         <p>
         <?php if($st_date){?>
         <span><?php _e('Start Date');?> :</span> <?php echo get_formated_date($st_date);?> <br />
         <?php }?>
         <?php if($end_date){?>
        <span><?php _e('End Date');?>  :</span> <?php echo get_formated_date($end_date);?>  <br />
        <?php }?>
        <?php if($st_time && $end_time){?><span><?php _e('Time');?>  : </span> <?php echo get_formated_time($st_time)?> <?php _e('to');?> <?php echo get_formated_time($end_time)?><?php }?> </p>
		 <p> 
          <?php if($phone){ ?>
         <span><?php _e('Phone');?> :</span> <?php echo $phone;?>  <br /> 
         <?php }?>  
         <?php if($email){ ?>           
		<span><?php _e('Email');?> :</span> <?php echo $email;?></p>	
         <?php }?>
          </div> 

          <div class="location">
          	<?php if($address){ ?>
            <p> 
            <span><?php _e('Location');?>  : </span>   <br />
           <?php echo $address;?></p>
            <?php }?>
            <?php if($website){ ?>
            <p><a href="<?php echo $website;?>"><?php _e('Website');?></a></p>
             <?php }?>
          </div>
      </div>
<script type="text/javascript">
function show_hide_tabs(type)
{
	if(type=='map')
	{
		document.getElementById('pikachoose').style.display='none';
		document.getElementById('detail_google_map_id').style.display='block';
		document.getElementById('li_location_map').className='active';
		document.getElementById('li_image_gallery').className='';
	}else if(type=='gallery')
	{
		document.getElementById('pikachoose').style.display='block';
		document.getElementById('detail_google_map_id').style.display='none';
		document.getElementById('li_location_map').className='';
		document.getElementById('li_image_gallery').className='active';
	}
}
</script>
      
       <div class="tabber">
   		 <ul class="tab">
            <li id="li_location_map" class="active"> <a href="javascript:void(0):" onclick="show_hide_tabs('map');"><?php _e('Location Map');?></a></li>
            <li id="li_image_gallery" class="" > <a href="javascript:void(0):" onclick="show_hide_tabs('gallery');"><?php _e('Image Gallery');?></a></li>
         </ul>
       </div>
             <script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/library/js/jquery-1.4.2.js"></script>
			<script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/library/js/jquery.pikachoose.js"></script>
            
            <script language="javascript" type="text/javascript">
            $(document).ready(
                function (){
                    $("#pikame").PikaChoose();            
                });
            </script>
           
                <div class="pikachoose" id="pikachoose" style="display:none" >
                 <?php if($_SESSION["file_info"] || $thumb_img_arr){?>
                <ul id="pikame" class="jcarousel-skin-pika">
                <?php
				$thumb_img_counter = 0;
				if($_SESSION["file_info"])
				{
					$thumb_img_counter = $thumb_img_counter+count($_SESSION["file_info"]);
					$image_path = get_image_phy_destination_path();
						
					$tmppath = "/".$upload_folder_path."tmp/";
						
					foreach($_SESSION["file_info"] as $image_id=>$val)
					{
						$thumb_image = get_option('siteurl').$tmppath.$image_id.'.jpg';
					?>
					  <li>
                        <img src="<?php echo $thumb_image;?>" alt=""    />
                    </li>
					<?php
					$thumb_img_counter++;
					}
				}
				if($thumb_img_arr)
				{
					$thumb_img_counter = $thumb_img_counter+count($thumb_img_arr);
					for($i=0;$i<count($thumb_img_arr);$i++)
					{
						$thumb_image = $thumb_img_arr[$i];
					?>
					 <li>
                        <img src="<?php echo $thumb_img_arr[$i];?>" alt=""    />
                    </li>
				<?php
					}
				}
				?>
               </ul>
               <?php }else
			   {
				   _e('No image gallery uploaded');
			   }?>
         </div>
  
   
       
<div class="google_map" id="detail_google_map_id">
<?php 
include_once (TEMPLATEPATH . '/library/map/google_map_detail.php');?>
</div>  <!-- google map #end -->
                
<h3><?php _e('Description');?></h3>
<?php echo $proprty_desc; ?>

<?php $author_info = get_author_info($post_author_id);?>
<h3><?php _e('Organized by');?></h3>
<?php
global $thumb_url;	 
$thumb_url1 = $thumb_url.get_image_cutting_edge($args);
?>
<?php if($organizer_logo){?>
 <img src="<?php echo bloginfo('template_url'); ?>/thumb.php?src=<?php echo $organizer_logo;?>&amp;w=105&amp;h=105&amp;zc=1&amp;q=80<?php echo $thumb_url1;?>" alt="" class="organized_logo"  title=""  />
<?php }?>
        	<div class="organized_content" >
              <p> <?php _e('Organized by');?>  <a href="<?php echo get_author_link($echo = false, $post->post_author);?>"><?php echo $author_info->display_name;?></a></p> 
              <p> <?php if($organizer_name){?>
             <?php echo $organizer_name;?>, <br />
              <?php }?>
<?php echo $organizer_address;?> </p>
<p>
<?php echo $organizer_desc;?>
<?php if($organizer_contact  && get_option('ptthemes_contact_on_detailpage')=='Yes'){?>
<?php _e('Tel');?>: <?php echo $organizer_contact;?> <br />
<?php }?>
<?php if($organizer_mobile){?>
<?php _e('Mobile');?>: <?php echo $organizer_mobile;?><br />
<?php }?>
<?php if($organizer_email  && get_option('ptthemes_email_on_detailpage')=='Yes'){?>
<?php _e('Email');?>: <?php echo $organizer_email;?><br />
<?php }?>
<?php if($organizer_website){?>
<?php _e('Website');?>: <a href=" <?php echo $organizer_website;?>"><?php echo $organizer_website;?></a>
<?php }?>
</p> 
<a class="b_contact" href="#" ><?php _e('Contact the Organizer');?></a>
</div>
<?php if($reg_desc){?>
 	<div class="register_msg clearfix" ><?php echo stripslashes($reg_desc);?> </div>
<?php }?>
<div style="clear:both;"></div>
<?php include (TEMPLATEPATH . "/library/includes/preview_buttons_event.php");?>                   
   </div> <!-- content #end -->
<?php get_sidebar(); ?>
</div> <!-- wrapper #end -->
<div id="bottom"></div>  
<?php get_footer(); ?>