<?php
// Set flag that this is a parent file
	defined('_FEXEC') or die();
  	$server_date = getServerDate(true);  	
  	$pID=isset($HTTP_GET_VARS['pID'])?$HTTP_GET_VARS['pID']:$HTTP_POST_VARS['product_id'];  	
  	$events_id=$pID;
  	$check_ID=(tep_db_prepare_input($HTTP_GET_VARS['chk_ID']))?tep_db_prepare_input($HTTP_GET_VARS['chk_ID']):0;
  	$cID=isset($HTTP_GET_VARS['cID'])?tep_db_prepare_input($HTTP_GET_VARS['cID']):0;
  	$ecPath=$cID;  	
  	$action = (isset($HTTP_GET_VARS['action']) ? $HTTP_GET_VARS['action'] : '');  
	$languages = tep_get_languages();
	if($HTTP_GET_VARS['cID']>0){
		$categories_query = tep_db_query("select c.parent_id,c.events_categories_id, cd.events_categories_name, c.events_categories_image, c.sort_order, c.date_added, c.last_modified from  ".TABLE_EVENTS_CATEGORIES."  c,  ".TABLE_EVENTS_CATEGORIES_DESCRIPTION."  cd where c.events_categories_id = cd.events_categories_id and cd.language_id = '" . (int)$languages_id . "' and c.events_categories_id='".(int)$cID."' order by c.sort_order, cd.events_categories_name");				 				
		if(tep_db_num_rows($categories_query)>0){
			$categories=tep_db_fetch_array($categories_query);
			$cInfo=new objectInfo($categories);
		}
	 }
	  if($pID>0 && $action!=""){
		$events_query = tep_db_query("select e.events_id, ed.events_name, e.events_date_available,e.events_date_added,ed.events_description,e.events_image, e.events_tax_class_id, e.events_fees," .
										"e.events_instructor,events_start_time as start_time,time_format(e.events_start_time,'%h:%i %p') as events_start_time,time_format(e.events_end_time,'%h:%i %p') as events_end_time,e.events_location," . 
										"e.events_status,e.events_conditions,e.sessions_select_interval,e.link_service,e.service_id,e.display_instructor from " . TABLE_EVENTS . " e, " . TABLE_EVENTS_DESCRIPTION .
										" ed where e.events_id in (" . tep_db_input($pID) . ") and ed.events_id = e.events_id and ed.language_id = '" . (int)$languages_id . "' order by e.events_start_time,e.events_end_time");
		if(tep_db_num_rows($events_query)>0){
			$events = tep_db_fetch_array($events_query);
			$eInfo = new objectInfo($events);
		} 
	  }
	  if($action=='edit_category' && !$HTTP_GET_VARS['cID'] && $check_ID>0){
		$products_query = tep_db_query("select count(*) as total from ".TABLE_EVENTS." p, ".TABLE_EVENTS_TO_EVENTS_CATEGORIES." p2c where p.events_id = p2c.events_id and p2c.events_categories_id = '" . tep_db_input($check_ID) . "'");			 		
		$products=tep_db_fetch_array($products_query);							
		if($products['total']<=0){
			echo 'new^';
			$action='edit_product';
		}
	  }	
	  if($action=='file_upload'){  
	 	$sql_data_array=array();
		 if($HTTP_POST_VARS['action_type']=="new_category" || $HTTP_POST_VARS['action_type']=="edit_category"){
			 $categories = new upload('events_categories_image');
			 $categories->set_destination(DIR_FS_CATALOG_IMAGES);
			 if ($categories->parse() && $categories->save()) $categories_filename=tep_db_input($categories->filename);
			 
			 $categories_filename=tep_db_input($categories->filename);
			 if($HTTP_POST_VARS['action_type']=='new_category'  ){
					$sql_data_array=array('events_categories_image'=>$categories_filename,'date_added'=>$server_date,'parent_id'=>($HTTP_POST_VARS['main_category']=='Y')?0:$HTTP_POST_VARS['cPath']);
					tep_db_perform(TABLE_EVENTS_CATEGORIES, $sql_data_array);
					$insert_id=tep_db_insert_id();
					echo $insert_id;
					for ($i = 0, $n = sizeof($languages); $i < $n; $i++) {
						$insert_sql_data = array(
							'events_categories_id' => $insert_id,
							'language_id' => $languages[$i]['id']);	
						tep_db_perform(TABLE_EVENTS_CATEGORIES_DESCRIPTION, $insert_sql_data);		
					}
			}else if($HTTP_POST_VARS['action_type']=='edit_category' && $categories_filename!="") tep_db_query("update " . TABLE_EVENTS_CATEGORIES . " set events_categories_image = '" . $categories_filename . "' where events_categories_id = '" . tep_db_input($HTTP_POST_VARS['cPath']) . "'");			  			 				
		}else if($HTTP_POST_VARS['action_type']=="new" || $HTTP_POST_VARS['action_type']=="edit"){

			 $events_image = new upload('events_image');
			 $events_image->set_destination(DIR_FS_CATALOG_IMAGES);
			 if ($events_image->parse() && $events_image->save()) $events_image_filename=$events_image->filename;
			 $events_image_filename=$events_image->filename;
			 if($HTTP_POST_VARS['action_type']=="new"){
				    $sql_data_array=array('events_image'=>$events_image_filename,'events_date_added'=>$server_date);
				
				    tep_db_perform(TABLE_EVENTS, $sql_data_array);
				    $products_id=tep_db_insert_id();
					echo $products_id;
					for ($i = 0, $n = sizeof($languages); $i < $n; $i++) {				    						
		              $language_id=$languages[$i]['id'];	
		              $insert_sql_data = array('events_id' => $products_id,
		                                       'language_id' => $language_id);		              
		              tep_db_perform(TABLE_EVENTS_DESCRIPTION, $insert_sql_data);            
					}
			}else if($HTTP_POST_VARS['action_type']=='edit')				 
				tep_db_query("update ".TABLE_EVENTS." set events_image='".$events_image->filename."' where events_id='".(int)$pID."'");						   				   			 				
		 }
	  }else if($action=='get_category_details'){
 			$product_categories=tep_db_query("select date_format(c.date_added,'%Y-%m-%d') as date_added,date_format(c.last_modified,'%Y-%m-%d') as last_modified,cd.events_categories_id,cd.events_categories_name,c.sort_order,c.events_categories_image from ".TABLE_EVENTS_CATEGORIES."  c, ".TABLE_EVENTS_CATEGORIES_DESCRIPTION." cd where c.events_categories_id=cd.events_categories_id and cd.language_id='".(int)$languages_id."' and c.events_categories_id='".(int)$cID."'");
			if(tep_db_num_rows($product_categories)>0) $product=tep_db_fetch_array($product_categories);
 			echo get_category_details($product);
	  }else if($action=='edit_category'){
	  		echo '<table width="100%" border="0" cellspacing="1" cellpadding="1" class="openContent">'.(($check_ID==0 && !$HTTP_GET_VARS['cID'])?'<tr class="openContent_top"><td class="main" colspan="'.(count($languages)+1).'">' . '</td><td class="main" align="right"><input type="image" border="0"  src="images/template/img_savel.gif">&nbsp;<a style="cursor:pointer" onClick="do_close_new_category();"><img src="images/template/img_closel.gif" alt="close"></a>&nbsp;</td>':'').'</tr>';?>			
 	  	   <tr><td colspan="2" align="right"></td></tr>
 	  	   <?php if($cInfo->events_categories_id<=0) { ?> <tr>
 	  	   			<td colspan="2">
 	  	   				<table border="0" cellspacing="0" cellpadding="0" width="100%">
 	  	   					<tr>
 	  	   						<td width="100%" class="main">&nbsp;&nbsp;<?php echo tep_draw_checkbox_field('main_category','Y').'&nbsp;'.TEXT_MAIN_CATEGORIES;?></td>	
			   				</tr>
 	  	   				</table>
 	  	   			</td>
 	  	   		</tr>
 	  	   <?php  } ?>
		  	<tr><td colspan="2">
		  		<table border="0" cellspacing="3" cellpadding="3" width="100%">
		  			<tr>
		  			<td>
		  				<table border="0" cellspacing="3" cellpadding="3" width="100%">
						   <?php $n=sizeof($languages); 
				   			 for ($i=0; $i<$n; $i++) {
							?>
					          <tr>
					            <td class="main" align="right" width="25%"><?php if ($i == 0) echo TEXT_EDIT_EVENTS_CATEGORIES_NAME ; ?></td>
					            <td class="main" align="center" width="8%"><?php echo tep_image(DIR_WS_CATALOG_LANGUAGES . $languages[$i]['directory'] . '/images/' . $languages[$i]['image'], $languages[$i]['name']);?></td>
								 <td class="main" align="left" width="67%"><?php echo tep_draw_input_field('categories_name[' . $languages[$i]['id'] . ']', (($events_categories_name[$languages[$i]['id']]) ? stripslashes($events_categories_name[$languages[$i]['id']]) : tep_get_events_category_name($cInfo->events_categories_id, $languages[$i]['id'])),'maxlength="32"'); ?></td>
					          </tr> <?php //echo 'S:'.tep_get_events_category_name($cInfo->events_categories_id, $languages[$i]['id']); ?>
					        <?php } ?>
					      </table>  			        
			        <td>
           		 	<table border="0" cellspacing="3" cellpadding="3" width="100%"> 	
			           <?php  for ($i=0; $i<$n; $i++) { ?>
			          	  <tr>
			            	<td class="main" width="25%"><?php if ($i == 0) echo TEXT_EDIT_EVENTS_CATEGORIES_HEADING_TITLE; ?></td>
			            	<td class="main" align="center" width="8%"><?php echo tep_image(DIR_WS_CATALOG_LANGUAGES . $languages[$i]['directory'] . '/images/' . $languages[$i]['image'], $languages[$i]['name']) ;?> </td>
							<td class="main">
							<?php echo tep_draw_input_field('categories_heading_title[' . $languages[$i]['id'] . ']', (($events_categories_name[$languages[$i]['id']]) ? stripslashes($events_categories_name[$languages[$i]['id']]) : tep_get_events_category_heading_title($cInfo->events_categories_id, $languages[$i]['id'])),'maxlength="64"'); ?></td>
			          	  </tr>
			           <?php } ?>
           		   </table>
	       	   	  </td>	  
	       	   	  </tr>      		  	          
	        	</table>	        	
	       	   </td>
	        </tr>	          	           	            	 
          	  	<tr>
            		<td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
          	  	</tr>          	
          	 <tr>
          	 <td colspan="2">
          	 	<div style='width:100%;height:100%;overflow:auto;'>
           		<table border="0" cellspacing="3" cellpadding="3" width="100%">
           		  <tr>           		              		 	            		 	   
		          	<?php  for ($i=0; $i<$n; $i++) { ?> 	
		          	  <td>          	  
		          	  <table border="0" cellspacing="3" cellpadding="3" width="100%">
		          	   <tr>
		                <td class="main" valign="top" width="135"><?php if ($i == 0) echo TEXT_EDIT_EVENTS_CATEGORIES_DESCRIPTION; ?></td>
		            	 <td>
		            		<table border="0" cellspacing="0" cellpadding="0">
				              <tr>
				                <td class="main" valign="top"><?php echo tep_image(DIR_WS_CATALOG_LANGUAGES . $languages[$i]['directory'] . '/images/' . $languages[$i]['image'], $languages[$i]['name']); ?>&nbsp;</td>
				                <td class="main"><?php echo tep_draw_textarea_field('events_categories_description[' . $languages[$i]['id'] . ']', 'soft', '70', '15', (($events_categories_description[$languages[$i]['id']]) ? stripslashes($events_categories_description[$languages[$i]['id']]) : tep_get_events_category_description($cInfo->events_categories_id, $languages[$i]['id']))); ?></td>
				              </tr>
		            		</table>
		            	  </td>
		          	    </tr>
		          	   </table>
		          	  </td>
				<?php } ?>				
			  </tr>   			  
			 </table>
			</div>
		   </td>
		 </tr>		           
		 <tr>
            <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
          </tr>          
		  <tr>
			  <td>
				  <table border="0" cellspacing="0" cellpadding="0" width="100%">
					  <tr>
						<td class="main" valign="top" width="20%" align="right"><?php echo TEXT_EDIT_EVENTS_CATEGORIES_IMAGE; ?></td>
						<td class="main" valign="top" width="30%" align="left"><?php echo tep_draw_separator('pixel_trans.gif','10','1') . tep_draw_file_field('events_categories_image') . '<br>' . tep_draw_separator('pixel_trans.gif', '10', '1') . '&nbsp;' . $cInfo->events_categories_image; ?> </td>
						<td class="main" valign="top" width="10%" align="center"><?php echo tep_draw_separator('pixel_trans.gif','',''); ?></td>
						<td class="main" valign="top" width="40%" align="left"><?Php echo TEXT_CATEGORY_SORT_ORDER .tep_draw_separator('pixel_trans.gif', '10', '1') . tep_draw_input_field('events_categories_sortorder',$cInfo->sort_order);?></td>
					  </tr>			
				  </table>
			  </td>
		  </tr>
		  <tr>
            <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
          </tr>       	
        </table>   
<?php }else if($action=='update_category'){   		
			$categories_id = $cID;
			$current_category_id=(int)$HTTP_POST_VARS['cPath'];
			//$sort_order=$cInfo->sort_order;
			$sort_order =$HTTP_POST_VARS['events_categories_sortorder'];
			
			$sort_query=tep_db_query("select max(sort_order) as sort_order from ".TABLE_EVENTS_CATEGORIES);
			if($HTTP_POST_VARS['events_categories_sortorder']<=0 && tep_db_num_rows($sort_query)>0){
				$sort=tep_db_fetch_array($sort_query);
				$sort_order = $sort['sort_order']+1;
			}
			if($HTTP_POST_VARS['action_type']=='new_category' && $HTTP_POST_VARS['main_category']=='Y') {
				echo 'new_main_category^';
				$current_category_id=0;
			}else echo $HTTP_POST_VARS['action_type'].'^';
			$sql_data_array = array('sort_order' => $sort_order);
			if (!$HTTP_GET_VARS['cID']) {
				 $eve_categories = new upload('events_categories_image');
				 $eve_categories->set_destination(DIR_FS_CATALOG_IMAGES);
				 if ($eve_categories->parse() && $eve_categories->save()) $eve_categories_filename=$eve_categories->filename;
				 $insert_sql_data = array(
					'parent_id' => $current_category_id,
					'date_added' => $server_date,
					'events_categories_image'=>$eve_categories_filename
				);
				$sql_data_array = array_merge($sql_data_array, $insert_sql_data);
				tep_db_perform(TABLE_EVENTS_CATEGORIES, $sql_data_array);
				$insert_id = tep_db_insert_id();												
			} elseif ($HTTP_GET_VARS['cID']>0) {
				$update_sql_data = array('last_modified' => $server_date);
				$sql_data_array = array_merge($sql_data_array, $update_sql_data);
				tep_db_perform(TABLE_EVENTS_CATEGORIES, $sql_data_array, 'update', 'events_categories_id = \'' . $categories_id . '\'');							
			}  // top if closing bracket					
			for ($i = 0, $n = sizeof($languages); $i < $n; $i++) {
				$categories_name_array = str_replace("|||","&",$HTTP_POST_VARS['categories_name']);
				$categories_title_array = $HTTP_POST_VARS['categories_heading_title'];
				$categories_description_array = $HTTP_POST_VARS['events_categories_description'];							
				$language_id = $languages[$i]['id'];
				$sql_data_array = array('events_categories_name' => tep_db_prepare_input($categories_name_array[$language_id]),'events_categories_heading_title'=>tep_db_prepare_input($categories_title_array[$language_id]),'events_categories_description'=>tep_db_prepare_input($categories_description_array[$language_id]));				
				if (!$HTTP_GET_VARS['cID']) {
					$insert_sql_data = array(
						'events_categories_id' => $insert_id,
						'language_id' => $languages[$i]['id']
					);
					$sql_data_array = array_merge($sql_data_array, $insert_sql_data);
					tep_db_perform(TABLE_EVENTS_CATEGORIES_DESCRIPTION, $sql_data_array);
				} elseif ($HTTP_GET_VARS['cID']>0) 
					tep_db_perform(TABLE_EVENTS_CATEGORIES_DESCRIPTION, $sql_data_array, 'update', 'events_categories_id = \'' . $HTTP_GET_VARS['cID'] . '\' and language_id = \'' . $language_id . '\'');
					$insert_id=$HTTP_GET_VARS['cID'];
			}
			if($HTTP_POST_VARS['action_type']=='new_category') echo $insert_id.'{}'.$categories_name_array[$languages_id].'{}'.$current_category_id;
	 		else if($HTTP_POST_VARS['action_type']=='edit_category'){
				echo $categories_id.'{}'.$categories_name_array[$languages_id].'{}';								
 				echo get_category_details($categories);
			} 	
	  tep_reset_seo_cache('events');  
      }else if($action=='delete_category'){
			$contents='<table width="100%" class="openContent" border="0" cellspacing="5" cellpadding="5"><tr><td width="10" align="right">'.tep_image('images/template/img_trash.gif').'</td><td class="main" colspan="4"><b>' . TEXT_DELETE_EVENTS_CATEGORY_INTRO . '</b></td></tr><tr>';
			$contents.='<tr><td></td><td class="main">' . $cInfo->events_categories_name . '</td></tr>';
			$category_childs = tep_childs_in_events_category_count($cInfo->events_categories_id);
			$category_products =tep_events_in_events_category_count($cInfo->events_categories_id);
			if ($category_childs > 0) $contents.='<tr><td></td><td class="main">' . sprintf(TEXT_DELETE_WARNING_CHILDS, $category_childs).'</td></tr>';
			if ($category_products > 0) $contents.='<tr><td></td><td class="main">'. sprintf(TEXT_DELETE_WARNING_EVENTS, $category_products).'</td></tr>';
			$contents.='<tr><td colspan="2">'.tep_draw_separator('pixel_trans.gif', '1', '10').'</td></tr></table>';
			echo $contents;
	  }else if($action=='delete_category_confirm'){
	  	  if ($HTTP_GET_VARS['cID']) {
				$events_categories_id = tep_db_prepare_input($HTTP_GET_VARS['cID']);
				$events_categories = tep_get_events_category_tree($events_categories_id, '', '0', '', true);
				$events = array();
				$events_delete = array();
				for ($i=0, $n=sizeof($events); $i<$n; $i++) {
					$events_ids_query = tep_db_query("SELECT events_id from " . TABLE_EVENTS_TO_EVENTS_CATEGORIES . " where events_categories_id = '" . (int)$events_categories[$i]['id'] . "'");
					while ($events_ids = tep_db_fetch_array($events_ids_query)) 
						$events[$event_ids['events_id']]['events_categories'][] = $events_categories[$i]['id'];					
				}
				reset($events);
				while (list($key, $value) = each($events)) {
					$events_category_ids = '';
					for ($i=0, $n=sizeof($value['events_categories']); $i<$n; $i++)
						$events_category_ids .= "'" . (int)$value['events_categories'][$i] . "', ";
					$events_category_ids = substr($events_category_ids, 0, -2);
					$check_query = tep_db_query("SELECT count(*) as total from " . TABLE_EVENTS_TO_EVENTS_CATEGORIES . " where events_id = '" . (int)$key . "' and events_categories_id not in (" . $events_category_ids . ")");
					$check = tep_db_fetch_array($check_query);
					if ($check['total'] < '1') 
						$events_delete[$key] = $key;
				}
				// removing categories can be a lengthy process
				tep_set_time_limit(0);
				for ($i=0, $n=sizeof($events_categories); $i<$n; $i++) 
					tep_remove_events_category($events_categories[$i]['id']);				
				reset($events_delete);
				while (list($key) = each($events_delete)) 
					tep_remove_event($key);
			echo 'delete_category_success^'.$events_categories_id;		
		}	
	  tep_reset_seo_cache('events');
	  }else if($action=='move_category'){			
			$contents='<table width="100%"  border="0" cellspacing="5" cellpadding="5" class="openContent"><tr><td width="10" class="main">'.tep_image('images/template/img_move.gif').'</td><td class="main" colspan="4"><b>' . sprintf(TEXT_MOVE_EVENTS_CATEGORIES_INTRO, $cInfo->events_categories_name) . '</b></td></tr><tr>';
			$contents.='<tr><td></td><td class="main" align="left">' . sprintf(TEXT_MOVE, $cInfo->events_categories_name) . '&nbsp;' . tep_draw_pull_down_menu('move_to_events_category_id', tep_get_events_category_tree('0', '',$cID), $current_category_id).'</td></tr>';
			$contents.='<tr><td colspan="2">'.tep_draw_separator('pixel_trans.gif', '1', '10').'</td></tr></table>';						
			echo $contents;
	 }else if($action=='move_category_confirm'){				
			if ($cID  && ($cID != $HTTP_POST_VARS['move_to_category_id'])){				
				$events_categories_id = tep_db_prepare_input($cID);
				$new_parent_id = tep_db_prepare_input($HTTP_POST_VARS['move_to_events_category_id']);											
				
				$path = explode('_', tep_get_generated_events_category_path_ids($new_parent_id)); 

				if (in_array($events_categories_id, $path)) {
				 echo 'move_category_failure^'.$events_categories_id;
				} else {
				tep_db_query("update " . TABLE_EVENTS_CATEGORIES . " set parent_id = '" . (int)$new_parent_id . "', last_modified ='". $server_date ."' where events_categories_id = '" . (int)$events_categories_id . "'");
				echo 'move_category_success^'.$new_parent_id;
				}
			}  // top if closing bracket
	  tep_reset_seo_cache('events');	
	  }else if($action=='get_details')  
		  	echo_get_details_result();
	  else if($action=='setflag' && $HTTP_GET_VARS['flag']!="" && $HTTP_GET_VARS['pID']>0)
			tep_set_event_status($HTTP_GET_VARS['pID'], $HTTP_GET_VARS['flag']);
	  else if($action=='delete_product'){
			$session_count =tep_sessions_on_events_count($eInfo->events_id);
		 	$event_categories_string.="<table border='0' cellspacing='2' cellpadding='1' width='100%'><tr><td width='17' align='center'>".tep_image('images/template/img_trash.gif').'</td>';
		 	$event_categories_string.='<td width="500" align="left" class="inner_title">'.TEXT_INFO_HEADING_DELETE_EVENT . '</td></tr>';
			if ($session_count > 0){
				$event_categories_string.='<tr><td></td><td class="main">' . sprintf(TEXT_DELETE_WARNING_SESSIONS, $session_count).'</td></tr>';
				$event_categories_string.='<tr><td></td><td width="500" align="left" class="main"><b>';
			}else{
				$event_categories_string.='<tr><td></td><td width="500" align="left" class="main">'.TEXT_DELETE_EVENT_INTRO. '</td></tr>';
				$event_categories_string.='<tr><td></td><td width="500" align="left" class="main"><b>'.$eInfo->events_name. '</b></td></tr>';				      
				$event_categories_string.='<tr><td></td><td width="500" align="left" class="main"><b>';
				$event_categories = tep_generate_events_category_path($eInfo->events_id, 'event');
				for ($i = 0, $n = sizeof($event_categories); $i < $n; $i++) {
				  $category_path = '';
				  for ($j = 0, $k = sizeof($event_categories[$i]); $j < $k; $j++) {
					$category_path .= $event_categories[$i][$j]['text'] . '&nbsp;&gt;&nbsp;';
				  }
				  $category_path = substr($category_path, 0, -16);
				  $event_categories_string .= tep_draw_checkbox_field('event_categories[]', $event_categories[$i][sizeof($event_categories[$i])-1]['id'], true) . '&nbsp;' . $category_path . '<br>';
				}
				$event_categories_string = substr($event_categories_string, 0, -4);
				$event_categories_string.='</b></td></tr>';
			}
			$event_categories_string.='<tr><td colspan="2">'.tep_draw_separator('pixel_trans.gif',50,10).'</td></tr></table>';
	        echo $event_categories_string;               
	 	}else if($action=='delete_confirm'){						 
		 	 if (isset($HTTP_POST_VARS['event_categories']) && is_array($HTTP_POST_VARS['event_categories'])) {
				  tep_set_time_limit(100);
		          $event_categories = $HTTP_POST_VARS['event_categories'];		
		          for ($i=0, $n=sizeof($event_categories); $i<$n; $i++)
		           	 tep_db_query("delete from " . TABLE_EVENTS_TO_EVENTS_CATEGORIES . " where events_id = '" . (int)$pID . "' and events_categories_id = '" . (int)$event_categories[$i] . "'");		          	
		          $event_categories_query = tep_db_query("select count(*) as total from " . TABLE_EVENTS_TO_EVENTS_CATEGORIES . " where events_id = '" . (int)$pID . "'");
		          $event_categories = tep_db_fetch_array($event_categories_query);		          	
		          if ($event_categories['total'] == '0')  
		             tep_remove_event($pID);		          
		          echo 'delete_success^' . $HTTP_GET_VARS['cID'];
			}
		tep_reset_seo_cache('events');
		}else if($action=='move_product'){			
			$move_to .="<table border='0' cellspacing='2' cellpadding='2' width='100%'><tr><td width='17' align='center'>".tep_image('images/template/img_move.gif').'</td>';
			$move_to .='<td width="500" align="left" class="inner_title">'.TEXT_INFO_HEADING_MOVE_EVENT . '</td></tr>';  
			$move_to .='<tr><td></td><td width="500" align="left" class="main">'. TEXT_INFO_CURRENT_EVENTS_CATEGORIES.'&nbsp;&nbsp;'.'<b>'.tep_output_generated_events_category_path($eInfo->events_id, 'event'). '</b></td></tr>';
			$move_to .='<tr><td></td><td width="500" align="left" class="main">'. sprintf(TEXT_MOVE_EVENTS_INTRO, $eInfo->events_name). '</td></tr>'; 
			$move_to .= '<tr><td></td><td width="500" align="left" class="main">'. sprintf(TEXT_MOVE, $eInfo->events_name).tep_draw_separator('pixel_trans.gif',50,10) . tep_draw_pull_down_menu('move_to_category_id',tep_get_events_category_tree(), $current_events_category_id). '</td></tr>';
			$move_to .= '<tr><td colspan="2">'.tep_draw_separator('pixel_trans.gif',50,10).'</td></tr></table>';
			echo $move_to;
		}else if($action=='move_confirm'){
			$events_id = tep_db_prepare_input($HTTP_GET_VARS['pID']);
        	$new_parent_id = tep_db_prepare_input($HTTP_POST_VARS['move_to_category_id']);
			$current_category_id = $ecPath;

        	$duplicate_check_query = tep_db_query("select count(*) as total from " . TABLE_EVENTS_TO_EVENTS_CATEGORIES . " where events_id = '" . (int)$events_id . "' and events_categories_id = '" . (int)$new_parent_id . "'");
        	$duplicate_check = tep_db_fetch_array($duplicate_check_query);
        	if ($duplicate_check['total'] < 1) tep_db_query("update " . TABLE_EVENTS_TO_EVENTS_CATEGORIES . " set events_categories_id = '" . (int)$new_parent_id . "' where events_id = '" . (int)$events_id . "' and events_categories_id = '" . (int)$current_category_id . "'");
        	echo 'move_success^'.$new_parent_id;
        	//else echo 'move_internal^'.$new_parent_id;
		}else if($action=='copy_product'){
	 		$copy_to .='<table  border="0" cellpadding="2" cellspacing="2" width="100%"><tr><td width="35" align="center">'.tep_image('images/template/img_copy.gif').'</td>';
			$copy_to .= '<td width="500" align="left" class="inner_title">'.TEXT_INFO_HEADING_COPY_TO . '</td><td></td></tr>'; 
			$copy_to .= '<tr><td></td><td width="500" align="left" class="main">'.TEXT_INFO_CURRENT_EVENTS_CATEGORIES .'&nbsp;&nbsp;'.'<b>'.  tep_output_generated_events_category_path($eInfo->events_id, 'event'). '</b></td><td></td></tr>';
			$copy_to .= '<tr><td></td><td colspan="2" align="left" class="main">'.TEXT_INFO_COPY_TO_INTRO. '</td><td></td></tr>'; 
			$copy_to .= '<tr><td></td><td width="500" align="left" class="main">'.TEXT_EVENTS_CATEGORIES .tep_draw_separator('pixel_trans.gif',50,10) . tep_draw_pull_down_menu('categories_id', tep_get_event_category_tree(), $cID).  '</td><td></td></tr>';	
			$copy_to .= '<tr><td></td><td width="500" align="left" class="main" nowrap>'.TEXT_HOW_TO_COPY . tep_draw_separator('pixel_trans.gif',47,10) . tep_draw_radio_field('copy_as', 'link', true,'','onclick=javascript:set_copy_as_val(this);') . ' ' . TEXT_COPY_AS_LINK . ' '. tep_draw_radio_field('copy_as', 'duplicate','','','onclick=javascript:set_copy_as_val(this);') . ' ' . TEXT_COPY_AS_DUPLICATE . tep_draw_hidden_field('copy_as_val','link') . '</td></tr>'; 
			$copy_to .= '<tr><td></td><td width="500" align="left" class="main" nowrap>'. tep_draw_checkbox_field('copy_sessions', 'yes', true) . ' ' . TEXT_COPY_SESSIONS;
	        $copy_to .= tep_draw_checkbox_field('copy_messages', 'yes') . ' ' . TEXT_COPY_MESSAGES;
    	    $copy_to .= tep_draw_checkbox_field('copy_surveys', 'yes') . ' ' . TEXT_COPY_SURVEYS;
			$copy_to .= '<tr><td colspan="2">'.tep_draw_separator('pixel_trans.gif',50,10).'</td></tr></table>';
			echo $copy_to;
		}else if($action=='copy_confirm'){
			$events_id =$HTTP_GET_VARS['pID'];
			$error="";
			$categories_id = tep_db_prepare_input($HTTP_POST_VARS['categories_id']);
			if ($HTTP_POST_VARS['copy_as'] == 'link') {
				if ($categories_id != $current_category_id) {
					 $check_query = tep_db_query("select count(*) as total from " . TABLE_EVENTS_TO_EVENTS_CATEGORIES . " where events_id = '" . (int)$events_id . "' and events_categories_id = '" . (int)$categories_id . "'");
					$check = tep_db_fetch_array($check_query);
					if ($check['total'] < '1') {
					 tep_db_query("insert into " . TABLE_EVENTS_TO_EVENTS_CATEGORIES . " (events_id, events_categories_id) values ('" . (int)$events_id . "', '" . (int)$categories_id . "')");
					}
				} else {
				  	$error=ERROR_CANNOT_LINK_TO_SAME_CATEGORY;
				}
          } elseif ($HTTP_POST_VARS['copy_as'] == 'duplicate') {
								  // This is for Diveabout
					$event_sql = "SELECT events_image, events_date_available, events_status, events_max_reserve,events_overbook_reserve,subscription_overbook_reserve,events_fees,events_tax_class_id,"
												. "events_start_time,events_end_time,events_instructor,events_backup_instructor,events_payment,refund_percentage1,refund_percentage2,refund_percentage3,events_location, "
												. "events_wait_list,priority_vip,priority_firstcome,priority_custom,priority_question,sessions_select_count,sessions_select_interval,sessions_date_count,waitsize_vip, "
												. "waitsize_firstcome,waitsize_custom,events_conditions,waitfee_vip,waitfee_firstcome,waitfee_custom,events_forward_period,events_forward_length,events_pending_period, "
												. "events_renewal_start,events_renewal_end ,session_gaps,session_reduction,session_style,instructors_rate_type,instructors_rate,instructors_base_rate, "
												. "events_group_bookings,events_group_min,events_group_max,link_service,service_id,display_instructor "
												. " from " . TABLE_EVENTS . " where events_id = '" . (int)$events_id . "'";
					$event_query = tep_db_query($event_sql);
					$event = tep_db_fetch_array($event_query);
					$insert_q = "insert into " . TABLE_EVENTS . " (events_image, events_date_added, events_date_available, events_status, events_max_reserve,"
																. " events_overbook_reserve,subscription_overbook_reserve,events_fees,events_tax_class_id,events_start_time,"
																. " events_end_time,events_instructor,events_backup_instructor,events_location,events_payment,"
																. " refund_percentage1,refund_percentage2,refund_percentage3,events_wait_list,priority_vip,"
																. " priority_firstcome,priority_custom,priority_question,sessions_select_count,sessions_select_interval, "
																. " sessions_date_count,waitsize_vip,waitsize_firstcome,waitsize_custom,events_conditions,"
																. " waitfee_vip,waitfee_firstcome,waitfee_custom,events_forward_period,events_forward_length,"
																. " events_pending_period,events_renewal_start,events_renewal_end,session_gaps,session_reduction,"
																. " session_style,instructors_rate_type,instructors_rate,instructors_base_rate,events_group_bookings,"
																. " events_group_min,events_group_max,link_service,service_id,display_instructor) "
																. " values ('" . tep_db_input($event['events_image']) . "','".  getServerDate(true) ."', '" . tep_db_input($event['events_date_available'])
																. "', '" . tep_db_input($event['events_status']) . "', '" . tep_db_input($event['events_max_reserve']) . "', '" . tep_db_input($event['events_overbook_reserve']) 
																. "', '" . tep_db_input($event['subscription_overbook_reserve'])  . "', '" . tep_db_input($event['events_fees']) . "', '" . tep_db_input($event['events_tax_class_id'])
																. "', '" .  tep_db_input($event['events_start_time']) . "', '" . tep_db_input($event['events_end_time']) . "', '" . tep_db_input($event['events_instructor'])
																. "', '" . tep_db_input($event['events_backup_instructor']) . "', '" . tep_db_input($event['events_location']) . "', '" . tep_db_input($event['events_payment'])
																.  "', '" . tep_db_input($event['refund_percentage1']) . "', '" . tep_db_input($event['refund_percentage2'])
																. "', '" . tep_db_input($event['refund_percentage3']) . "', '" . tep_db_input($event['events_wait_list']) . "', '" . tep_db_input($event['priority_vip'])
																. "', '" . tep_db_input($event['priority_firstcome']) . "','" . tep_db_input($event['priority_custom']) . "','" . tep_db_input($event['priority_question'])
																. "', '" . tep_db_input($event['sessions_select_count']) . "', '" . tep_db_input($event['sessions_select_interval']) . "','" . tep_db_input($event['sessions_date_count'])
																. "', '" . tep_db_input($event['waitsize_vip']) . "', '" . tep_db_input($event['waitsize_firstcome']) . "', '" . tep_db_input($event['waitsize_custom'])
																. "', '" . tep_db_input($event['events_conditions']) . "', '" . tep_db_input($event['waitfee_vip']) . "', '" . tep_db_input($event['waitfee_firstcome'])
																. "', '" . tep_db_input($event['waitfee_custom']) . "', '" . tep_db_input($event['events_forward_period']) . "', '" . tep_db_input($event['events_forward_length'])
																. "', '" . tep_db_input($event['events_pending_period']) . "', '" . tep_db_input($event['events_renewal_start']) . "', '" . tep_db_input($event['events_renewal_end'])
																. "', '" . tep_db_input($event['session_gaps']) . "', '" . tep_db_input($event['session_reduction']) . "', '" . tep_db_input($event['session_style'])
																. "', '" . tep_db_input($event['instructors_rate_type']) . "', '" . tep_db_input($event['instructors_rate']) . "', '" . tep_db_input($event['instructors_base_rate'])
																. "', '" . tep_db_input($event['events_group_bookings']) . "', '" . tep_db_input($event['events_group_min']) . "', '" . tep_db_input($event['events_group_max'])
																. "', '" . tep_db_input($event['link_service']) . "','".tep_db_input($event['service_id'])."','" .  tep_db_input($event['display_instructor']). "')";
					tep_db_query($insert_q);
					$dup_events_id = tep_db_insert_id();
		            if (isset($HTTP_POST_VARS['copy_messages'])){
						//copy the messages
						$message_query=tep_db_query("SELECT message_send,message_subject,message_reply_to,message_text,message_format,events_id,message_type from " . TABLE_EVENTS_MESSAGES . " where events_id='" . (int)$events_id . "'");
						while($message_result=tep_db_fetch_array($message_query)){
							$message_result["events_id"]=$dup_events_id;
							tep_db_perform(TABLE_EVENTS_MESSAGES,$message_result);
						}
						//copy the messages
						$message_query=tep_db_query("SELECT message_send,message_subject,message_text,events_id,message_type from " . TABLE_EVENTS_SMS_MESSAGES . " where events_id='" . (int)$events_id . "'");
						while($message_result=tep_db_fetch_array($message_query)){
							$message_result["events_id"]=$dup_events_id;
							tep_db_perform(TABLE_EVENTS_SMS_MESSAGES,$message_result);
						}
					}
					//copy surveys
					if (isset($HTTP_POST_VARS['copy_surveys'])){
						$survey_query=tep_db_query("SELECT * from " . TABLE_EVENTS_SURVEYS . " where events_id='" . (int)$events_id . "'");
						while($survey_result=tep_db_fetch_array($survey_query)){
							$old_survey_id=$survey_result["survey_id"];
							$survey_result["events_id"]=$dup_events_id;
							unset($survey_result["survey_id"]);
							tep_db_perform(TABLE_EVENTS_SURVEYS,$survey_result);
							$new_survey_id=tep_db_insert_id();
							$question_query=tep_db_query("SELECT * from " . TABLE_EVENTS_SURVEYS_QUESTION . " where survey_id='" . (int)$old_survey_id . "'");
							while($question_result=tep_db_fetch_array($question_query)){
								$old_question_id=$question_result["question_id"];
								$question_result["survey_id"]=$new_survey_id;
								unset($question_result["question_id"]);
								tep_db_perform(TABLE_EVENTS_SURVEYS_QUESTION,$question_result);
								$new_question_id=tep_db_insert_id();
								if ($question_result["question_type"]<=3){
									$choice_query=tep_db_query("SELECT * from " . TABLE_EVENTS_SURVEYS_CHOICE . " where question_id='" . (int)$old_question_id . "'");
									while($choice_result=tep_db_fetch_array($choice_query)){
										$choice_result["question_id"]=$new_question_id;
										unset($choice_result["choice_id"]);
										tep_db_perform(TABLE_EVENTS_SURVEYS_CHOICE,$choice_result);
									}
								}
							}
						}
					}
					$description_query = tep_db_query("SELECT language_id, events_name, events_description,events_url from " . TABLE_EVENTS_DESCRIPTION . " where events_id = '" . (int)$events_id . "'");
					while ($description = tep_db_fetch_array($description_query)) {
						tep_db_query("insert into " . TABLE_EVENTS_DESCRIPTION . " (events_id, language_id, events_name, events_description, events_url, events_viewed) values ('" . (int)$dup_events_id . "', '" . (int)$description['language_id'] . "', '" . tep_db_input($description['events_name']) . "', '" . tep_db_input($description['events_description']) . "', '" . tep_db_input($description['events_url']) . "', '0')");
					}
					tep_db_query("insert into " . TABLE_EVENTS_TO_EVENTS_CATEGORIES . " (events_id, events_categories_id) values ('" . (int)$dup_events_id . "', '" . (int)$categories_id . "')");
						//copy the sessions details
					if (isset($HTTP_POST_VARS['copy_sessions'])){
						//copy recursive sessions
						$recursive_query=tep_db_query("SELECT recursive_sessions_id,events_id,sessions_start_date,sessions_end_date,sessions_type,sessions_type_option,sessions_type_daily_days,sessions_type_weekly_weeks,sessions_type_weekly_days," . 
													"sessions_type_monthly_days,sessions_type_monthly_months,sessions_type_monthly_weeks,sessions_type_monthly_weekdays,sessions_type_monthly_weekmonths,sessions_type_yearly_months," .
													"sessions_type_yearly_monthdays,sessions_type_yearly_weeks,sessions_type_yearly_weekdays,sessions_type_yearly_weekmonths " .
													" from " . TABLE_RECURSIVE_SESSIONS . " where events_id='" .(int)$events_id . "'");
						if (tep_db_num_rows($recursive_query)>0){
							while ($recursive_result=tep_db_fetch_array($recursive_query)){
								$old_id=$recursive_result["recursive_sessions_id"];
								unset($recursive_result["recursive_sessions_id"]);
								$recursive_result['events_id']=$dup_events_id;
								tep_db_perform(TABLE_RECURSIVE_SESSIONS,$recursive_result);
								$recursive_id=tep_db_insert_id();
			
								$session_query=tep_db_query("SELECT events_id,start_date,sessions_type,recursive_sessions_id from " . TABLE_EVENTS_SESSIONS . " where events_id='" . (int)$events_id . "' and recursive_sessions_id='" . $old_id . "'");
								while($session_result=tep_db_fetch_array($session_query)){
									$session_result['events_id']=$dup_events_id;
									$session_result['recursive_sessions_id']=$recursive_id;
									tep_db_perform(TABLE_EVENTS_SESSIONS,$session_result);	
								}
							}
						} else {
							//copy single sessions
							$session_query=tep_db_query("SELECT events_id,start_date,sessions_type,recursive_sessions_id from " . TABLE_EVENTS_SESSIONS . " where events_id='" . (int)$events_id . "' and sessions_type='S'");
							while($session_result=tep_db_fetch_array($session_query)){
								$session_result['events_id']=$dup_events_id;
								tep_db_perform(TABLE_EVENTS_SESSIONS,$session_result);
							}
						}
						tep_set_event_limit_dates($dup_events_id);
					}
			}
         	 if($error!="") echo 'copy_error^'.$error;
		 	 else echo "copy_success^".$categories_id;
		  }else if($action=='update_product'){ 
					if($HTTP_POST_VARS['action_type']=='new') echo $HTTP_POST_VARS['action_type'].'_product^';
					if ($HTTP_GET_VARS['pID']) $events_id = tep_db_prepare_input($HTTP_GET_VARS['pID']);
						$events_date_available = ($HTTP_POST_VARS['events_date_available'])?tep_convert_date_raw(tep_db_prepare_input($HTTP_POST_VARS['events_date_available'])):$server_date;												
						$hours=(int)$HTTP_POST_VARS['start_time_hours'];
						$minute=(int)$HTTP_POST_VARS['start_time_minutes'];
						$day_session=$HTTP_POST_VARS['start_time_session'];
						if ($day_session=='PM' && $hours<12) $hours=$hours+12;						
						$start_time=$hours . ":" . $minute ;
						$hours=(int)$HTTP_POST_VARS['end_time_hours'];
						$minute=(int)$HTTP_POST_VARS['end_time_minutes'];
						$day_session=$HTTP_POST_VARS['end_time_session'];
						if ($day_session=='PM' && $hours<12) $hours=$hours+12;
						$end_time=$hours . ":" . $minute ;
						$session_gaps=(isset($HTTP_POST_VARS["session_gaps"])?$HTTP_POST_VARS["session_gaps"]:'N');
						$session_reduction=(isset($HTTP_POST_VARS["session_reduction"])?$HTTP_POST_VARS["session_reduction"]:'N');
						$session_style=(isset($HTTP_POST_VARS["session_style_val"])?$HTTP_POST_VARS["session_style_val"]:'S');
						$events_group_bookings=(($HTTP_POST_VARS["events_group_bookings"]!="")?'Y':'N');
						$events_group_min=(int)$HTTP_POST_VARS["events_group_min"];
						$events_group_max=(int)$HTTP_POST_VARS["events_group_max"];
						$link_service=(isset($HTTP_POST_VARS['link_service_val'])?$HTTP_POST_VARS['link_service_val']:'L');
						$events_location=(isset($HTTP_POST_VARS['events_location'])?$HTTP_POST_VARS['events_location']:'');
						$service_id=(isset($HTTP_POST_VARS['sel_services'])?$HTTP_POST_VARS['sel_services']:'');
						$events_max_reserve=(isset($HTTP_POST_VARS['events_max_reserve'])?tep_db_prepare_input($HTTP_POST_VARS['events_max_reserve']):'0');
						$display_instructor=(isset($HTTP_POST_VARS['display_instructor'])?$HTTP_POST_VARS['display_instructor']:'N');
						$rate_type='GP';
						$rate=0;$base_rate=0;$events_instructor=0;$events_backup_instructor=0;
						if($display_instructor=='Y') {
							$rate_type=(isset($HTTP_POST_VARS["instructors_rate_type"])?$HTTP_POST_VARS["instructors_rate_type"]:'GP');
							$rate=(isset($HTTP_POST_VARS["instructors_rate"])?$HTTP_POST_VARS["instructors_rate"]:0);
							$base_rate=(isset($HTTP_POST_VARS["instructors_base_rate"])?$HTTP_POST_VARS["instructors_base_rate"]:0);
							$events_instructor=(isset($HTTP_POST_VARS["events_instructor"])?$HTTP_POST_VARS["events_instructor"]:0);
							$events_backup_instructor=(isset($HTTP_POST_VARS["events_backup_instructor"])?$HTTP_POST_VARS["events_backup_instructor"]:0);
						}
						if($link_service=='S')
							$events_location='0';
						else
							$service_id='';						
						if($events_max_reserve=='') $events_max_reserve='0';
						$events_wait_list=$HTTP_POST_VARS['events_wait_list'];
						$events_forward_period=$HTTP_POST_VARS['events_forward_period'];							
						if ($events_wait_list!='Y') $events_wait_list='N';
						if ($events_forward_period!='Y') $events_forward_period='N';						
						$event_fees_net=$HTTP_POST_VARS['events_fees_net'];
						if($event_fees_net=='') $event_fees_net='0';
						$events_overbook_reserve=$HTTP_POST_VARS['events_overbook_reserve'];
						if($events_overbook_reserve=='') $events_overbook_reserve='0';
						$subscription_overbook_reserve=$HTTP_POST_VARS['subscription_overbook_reserve'];
						if($subscription_overbook_reserve=='') $subscription_overbook_reserve='0';						
						$event_forward_length=$HTTP_POST_VARS['events_forward_length'];
						if($event_forward_length=='') $event_forward_length='0';						
						$event_pending_period=$HTTP_POST_VARS['events_pending_period'];
						if($event_pending_period=='') $event_pending_period='0';						
						$events_renewal_end=$HTTP_POST_VARS['events_renewal_end'];
						if($events_renewal_end=='') $events_renewal_end='0';						
						if($service_id=='') $service_id='0';
						$selected_events_catids = $HTTP_POST_VARS['events_categories_ids'];						
						$sql_data_array = array('events_date_available' => $events_date_available,
												'events_start_time'=>$start_time,
												'events_end_time'=>$end_time,
												'events_location'=>$events_location,
												'events_instructor'=>tep_db_prepare_input($events_instructor),
												'events_backup_instructor'=>tep_db_prepare_input($events_backup_instructor),				  
												'events_fees'=>tep_db_prepare_input($event_fees_net),
												'events_tax_class_id'=>tep_db_prepare_input($HTTP_POST_VARS['events_tax_class_id']),
												'events_max_reserve' => $events_max_reserve,
												'events_overbook_reserve'=>tep_db_prepare_input($events_overbook_reserve),
												'subscription_overbook_reserve'=>tep_db_prepare_input($subscription_overbook_reserve),
												'events_payment'=>tep_db_prepare_input($HTTP_POST_VARS['events_payment']),
												'refund_percentage1'=>tep_db_prepare_input($HTTP_POST_VARS['refund_percentage1']),
												'refund_percentage2'=>tep_db_prepare_input($HTTP_POST_VARS['refund_percentage2']),
												'refund_percentage3'=>tep_db_prepare_input($HTTP_POST_VARS['refund_percentage3']),
												'events_status' => tep_db_prepare_input($HTTP_POST_VARS['events_status']),
												'events_wait_list'=>tep_db_prepare_input($events_wait_list),
												'priority_vip'=>tep_db_prepare_input($HTTP_POST_VARS['priority_vip']),
												'priority_firstcome'=>tep_db_prepare_input($HTTP_POST_VARS['priority_firstcome']),
												'priority_custom'=>tep_db_prepare_input($HTTP_POST_VARS['priority_custom']),
												'priority_question'=>tep_db_prepare_input($HTTP_POST_VARS['priority_question']),
												'waitsize_vip'=>(int)tep_db_prepare_input($HTTP_POST_VARS['waitsize_vip']),
												'waitsize_firstcome'=>(int)tep_db_prepare_input($HTTP_POST_VARS['waitsize_firstcome']),
												'waitsize_custom'=>(int)tep_db_prepare_input($HTTP_POST_VARS['waitsize_custom']),
												'events_conditions'=>tep_db_prepare_input($HTTP_POST_VARS['events_conditions']),
												'waitfee_vip'=>(int)tep_db_prepare_input($HTTP_POST_VARS['waitfee_vip']),
												'waitfee_firstcome'=>(int)tep_db_prepare_input($HTTP_POST_VARS['waitfee_firstcome']),
												'waitfee_custom'=>(int)tep_db_prepare_input($HTTP_POST_VARS['waitfee_custom']),
												'events_forward_period'=>tep_db_prepare_input($events_forward_period),
												'events_forward_length'=>tep_db_prepare_input($event_forward_length),
												'events_renewal_start'=>tep_db_prepare_input($HTTP_POST_VARS['events_renewal_start']),
												'events_pending_period'=>tep_db_prepare_input($event_pending_period),
												'events_renewal_end'=>tep_db_prepare_input($events_renewal_end),
												'session_gaps'=>tep_db_prepare_input($session_gaps),
												'session_reduction'=>tep_db_prepare_input($session_reduction),
												'session_style'=>tep_db_prepare_input($session_style),
												'instructors_rate_type'=>tep_db_prepare_input($rate_type),
												'instructors_rate'=>tep_db_prepare_input($rate),
												'instructors_base_rate'=>tep_db_prepare_input($base_rate),
												'events_group_bookings'=>tep_db_prepare_input($events_group_bookings),
												'events_group_min'=>tep_db_prepare_input($events_group_min),
												'events_group_max'=>tep_db_prepare_input($events_group_max),
												'link_service' => tep_db_prepare_input($link_service),
												'service_id' =>tep_db_prepare_input($service_id),
												'display_instructor' =>tep_db_prepare_input($display_instructor)
							);	
							
				//		print_r($sql_data_array);	
																		
						if(count($selected_events_catids)>0){	
							if (!$HTTP_GET_VARS['pID']) {
								$insert_sql_data = array('events_date_added' => $server_date);						
								$sql_data_array = array_merge($sql_data_array, $insert_sql_data);						
								tep_db_perform(TABLE_EVENTS, $sql_data_array);
								$events_id = tep_db_insert_id();
							} elseif ($HTTP_GET_VARS['pID']) {
								$update_sql_data = array('events_last_modified' => $server_date);						
								$sql_data_array = array_merge($sql_data_array, $update_sql_data);						
								tep_db_perform(TABLE_EVENTS, $sql_data_array, 'update', "events_id = '" . (int)$events_id . "'");							
								tep_db_query("delete from " . TABLE_EVENTS_TO_SUBSCRIPTIONS . " where events_id='" . (int)$events_id . "' ");            
								if ((int)$HTTP_POST_VARS['old_max_reserve']!=(int)$HTTP_POST_VARS['events_max_reserve']){
									tep_check_waiting_list($events_id);}
								#PR Algozone: delete categories saved in the tables
								tep_db_query("delete from " . TABLE_EVENTS_TO_EVENTS_CATEGORIES . " where events_id = '". (int)$events_id . "'");
					        }
						/*$update_sql_data = array('events_last_modified' => $server_date);
						$sql_data_array = array_merge($sql_data_array, $update_sql_data);
						tep_db_perform(TABLE_EVENTS, $sql_data_array, 'update', "events_id = '" . (int)$events_id . "'");
						tep_db_query("delete from " . TABLE_EVENTS_TO_SUBSCRIPTIONS . " where events_id='" . $events_id . "' ");
						if ((int)$HTTP_POST_VARS['old_max_reserve']!=(int)$HTTP_POST_VARS['events_max_reserve']){
							tep_check_waiting_list($events_id);}
						tep_db_query("delete from " . TABLE_EVENTS_TO_EVENTS_CATEGORIES . " where events_id = '". (int)$events_id . "'");
						*/
						//check if exists										       
						$subscription_categories_array_selected=$HTTP_POST_VARS['subscription_categories_ids'];
						if ($subscription_categories_array_selected)
						{
							foreach ($subscription_categories_array_selected as $current_sub_id)
							{
								tep_db_query("insert into " . TABLE_EVENTS_TO_SUBSCRIPTIONS . " (events_id, subscription_id) values ('" . (int)$events_id . "', '" . (int)$current_sub_id . "')");
							}
						}
						
						$differ_category_found=true;
						if ($selected_events_catids)
						{
							foreach ($selected_events_catids as $current_events_category_id)
							{	
								if($ecPath==$current_events_category_id) $differ_category_found=false;
								if($ecPath!=$current_events_category_id) $differ_category=$current_events_category_id;
								tep_db_query("insert into " . TABLE_EVENTS_TO_EVENTS_CATEGORIES . " (events_id, events_categories_id) values ('" . (int)$events_id . "', '" . (int)$current_events_category_id . "')");
								$ecPath=$current_events_category_id;
							}
						}
							
				$languages = tep_get_languages();
				for ($i=0, $n=sizeof($languages); $i<$n; $i++) {
					$language_id = $languages[$i]['id'];
					$sql_data_array = array('events_name' => tep_db_prepare_input($HTTP_POST_VARS['events_name'][$language_id]),
											'events_description' => tep_db_prepare_input($HTTP_POST_VARS['events_description'][$language_id]),
											'events_url' => tep_db_prepare_input($HTTP_POST_VARS['events_url'][$language_id]));
						if (!$HTTP_GET_VARS['pID']) {
								$insert_sql_data = array('events_id' => $events_id,
														 'language_id' => $language_id);							
								$sql_data_array = array_merge($sql_data_array, $insert_sql_data);						
								tep_db_perform(TABLE_EVENTS_DESCRIPTION, $sql_data_array);
						}elseif ($HTTP_GET_VARS['pID'])  
							tep_db_perform(TABLE_EVENTS_DESCRIPTION, $sql_data_array, 'update', "events_id = '" . (int)$events_id . "' and language_id = '" . (int)$language_id . "'");						
				}		
				if($differ_category_found) echo 'diff_category^'.$differ_category.'#';
				echo_get_details_result();
			  }
	tep_reset_seo_cache('events');
	 }else if($action=='edit_product'){
	      	$event_query = tep_db_query("SELECT ed.events_name, ed.events_description, ed.events_url, e.events_id, e.events_image, e.events_location," .
                                   "e.events_date_added, e.events_last_modified, date_format(e.events_date_available, '%Y-%m-%d') " .
								   "as events_date_available, e.events_status,  e.events_tax_class_id,e.refund_percentage1,e.refund_percentage2,e.refund_percentage3," .
								   "e.events_max_reserve,e.events_overbook_reserve,e.subscription_overbook_reserve,time_format(e.events_start_time,'%h:%i:%p') as events_start_time,time_format(e.events_end_time,'%h:%i:%p') as events_end_time,e.events_instructor,e.events_backup_instructor ,e.events_fees,e.events_tax_class_id,e.events_payment," .
								   "e.events_wait_list,e.priority_vip,e.priority_firstcome,e.priority_custom,e.priority_question,e.waitsize_vip,e.waitsize_firstcome,e.waitsize_custom,e.events_conditions,e.waitfee_vip,e.waitfee_firstcome,e.waitfee_custom,e.events_forward_period,e.events_forward_length,e.events_pending_period,e.events_renewal_start,e.events_renewal_end,e.session_gaps,e.session_reduction,e.session_style,e.instructors_rate_type,e.instructors_rate, " .
								   "e.instructors_base_rate,e.events_group_bookings,e.events_group_min,e.events_group_max,e.link_service,service_id,e.display_instructor from " . 
								   TABLE_EVENTS . " e, " . TABLE_EVENTS_DESCRIPTION . " ed where e.events_id=ed.events_id " .
								   " and e.events_id = '" . (int)$pID . "' and ed.language_id = '" . (int)$languages_id . "'");
								   
								   

			$event = tep_db_fetch_array($event_query);
			if(tep_db_num_rows($event_query)>0) $eInfo = new objectInfo($event);
			# get selected categories
			$events_percent_array=array();
			for($icnt=5;$icnt<=100;$icnt+=5)
			  $events_percent_array[]=array('id'=>$icnt,'text'=>$icnt);
			#get instructor descriptions to display in instructor selection
			$instructor_array=array();
			$instructor_query=tep_db_query("SELECT a.admin_id,a.admin_firstname,a.admin_lastname from " . TABLE_ADMIN . " a, " . TABLE_ADMIN_GROUPS . " ag where a.admin_groups_id=ag.admin_groups_id and ag.admin_groups_name='" . TEXT_INSTRUCTOR_ENTRY . "' order by a.admin_firstname,a.admin_lastname");
			while ($instructorfetch = tep_db_fetch_array($instructor_query)) {
			  $instructor_array[] = array('id' => $instructorfetch['admin_id'],
											'text' => $instructorfetch['admin_firstname'] . '&nbsp;' . $instructorfetch['admin_lastname']);
			}
			$services_array=array();
			$services_array = array(array('id' => '-1', 'text' => TEXT_SELECT));
			$services_query=tep_db_query("select op.products_id,op.products_name from ".TABLE_SERVICES ." s, ".TABLE_ORDERS ." o, ".TABLE_ORDERS_PRODUCTS ." op, ".TABLE_SERVICES_DESCRIPTION ." sd where s.service_id=sd.service_id and o.orders_id=op.orders_id and op.products_type='V' and lcase(o.payment_method) like '%internal only%' and op.products_id=s.service_id");
			while($services_result=tep_db_fetch_array($services_query)){
				$services_array[]=array('id' => $services_result['products_id'],
										'text' => $services_result['products_name']);
			}
		# get selected categories
		$events_categories_query_selected = tep_db_query("SELECT events_categories_id from " . TABLE_EVENTS_TO_EVENTS_CATEGORIES . " where events_id = '" . (int)$HTTP_GET_VARS['eID'] . "'");
		$events_categories_array_selected = array(array('id' => ''));
		$sel_cat = $cID;
		if (!$sel_cat && $check_ID)
			$sel_cat = $check_ID;
		$events_categories_array_selected = array (array ('id' => $sel_cat));
		if ($action == 'edit_product' && $HTTP_GET_VARS['pID']) {
			while ($events_categories = tep_db_fetch_array($events_categories_query_selected))
		  		$events_categories_array_selected[] = array('id' => $events_categories['events_categories_id']);
		}		
		$eventsubs=tep_db_query("select * from ".TABLE_EVENTS_TO_SUBSCRIPTIONS ." where events_id='" .(int)$pID ."'");
		while($eventsubsres=tep_db_fetch_array($eventsubs)) {
			$subscription_categories_array_selected[]=array('id' => $eventsubsres['subscription_id']);
		}
		$events_categories_array = array(array('id' => '', 'text' => TEXT_NONE));
		#PR Algozone: Categories list displays only for one languge (Deafault is English)
		$language_id = 1;
		$events_categories_array = tep_get_events_category_tree(); 
		$priority_array=array();
		$priority_array[]=array('id'=>'1','text'=>'1');
		$priority_array[]=array('id'=>'2','text'=>'2');
		$priority_array[]=array('id'=>'3','text'=>'3');
    
		$questions_array=array(array('id'=>0,'text'=>'None'));
		$questions_query=tep_db_query("SELECT question_id,question_title from " . TABLE_POP_QUESTIONS);

		while($questions=tep_db_fetch_array($questions_query))
		   $questions_array[]=array('id'=>$questions['question_id'],'text'=>$questions['question_title']);
	
		$form_action = ($HTTP_GET_VARS['eID']) ? 'update_event' : 'insert_event';
	
		$status_array=array(array('id'=>1,'text'=>TEXT_HIDE_NONE),
						array('id'=>0,'text'=>TEXT_HIDE_ALWAYS),
						array('id'=>2,'text'=>TEXT_HIDE_START),
						array('id'=>3,'text'=>TEXT_HIDE_END));
						
    if (!isset($eInfo->events_status)) $eInfo->events_status = '0';
    $events_payment_array=array(array('id'=>'none','text'=> TEXT_NONE));
    for($icnt=0;$icnt<sizeof($selection);$icnt++){
      $events_payment_array[]=array('id'=>$selection[$icnt]['id'],'text'=>$selection[$icnt]['module']);}
     $current_date=getServerDate();
    $hour_array=array();
    for($icnt=1;$icnt<=12;$icnt++){
      if ($icnt<10) $hour_array[]=array('id'=>$icnt,'text'=>'0' . $icnt);
      else $hour_array[]=array('id'=>$icnt,'text'=>$icnt);
    }
    $minute_array=array();
    for($icnt=0;$icnt<=59;$icnt=$icnt+5){
      if ($icnt<10) $minute_array[]=array('id'=>$icnt,'text'=>'0' . $icnt);
      else $minute_array[]=array('id'=>$icnt,'text'=>$icnt);
    }
    $day_session_array[]=array('id'=>'AM','text'=>'AM');
    $day_session_array[]=array('id'=>'PM','text'=>'PM');

	$languages = tep_get_languages();
    $location_query=tep_db_query("SELECT * from " . TABLE_EVENTS_LOCATIONS . ' order by location_name');
    $location_array=array();
    while($location_result=tep_db_fetch_array($location_query)){
       $location_array[]=array('id'=>$location_result['location_id'],'text'=>$location_result['location_name'],'seats'=>$location_result["location_seats"]);
    }
	
    $service_location_query=tep_db_query("SELECT sl.*,s.service_id from " . TABLE_SERVICES." s, ". TABLE_SERVICES_LOCATIONS . ' sl where s.service_location=sl.service_location_id order by service_location_name');
    $service_location_array=array();
    while($service_location_result=tep_db_fetch_array($service_location_query)){
       $service_location_array[]=array('id'=>$service_location_result['service_id'],'seats'=>$service_location_result["service_location_seats"]);
    }
	#get tax descriptions to display in tax selection
	$tax_class_array = array(array('id' => '0', 'text' => TEXT_NONE));
	$tax_class_query = tep_db_query("SELECT tax_class_id, tax_class_title from " . TABLE_TAX_CLASS . " order by tax_class_title");
	while ($tax_class = tep_db_fetch_array($tax_class_query)) {
	  $tax_class_array[] = array('id' => $tax_class['tax_class_id'],
								 'text' => $tax_class['tax_class_title']);
	}   
	
	$rate_type_array=array(	array('id'=>'GP','text'=>TEXT_RATE_TYPE_GP),
							array('id'=>'MU','text'=>TEXT_RATE_TYPE_MU),
							array('id'=>'FL','text'=>TEXT_RATE_TYPE_FL));
							
    $renewal_array=array(array('id'=>'FLS','text'=>TEXT_FLS),
                                   array('id'=>'SLS','text'=>TEXT_SLS),
                                   array('id'=>'DLS','text'=>TEXT_DLS),
								   array('id'=>'OBS','text'=>TEXT_OBS),
								   array('id'=>'TBS','text'=>TEXT_TBS));
		?>
    <table border="0" width="100%" cellspacing="0" cellpadding="2" class="openContent">
		<tr>
			<td>
			<table border="0" cellspacing="0" cellpadding="2">
				<tr>
					<td>
					<table border=0 cellpadding="0" cellspacing="0">
						<tr>
							<td class="main" width="150" valign="top"><?php echo TEXT_EVENTS_STATUS; ?></td>
							<td class="main" width="200" valign="top"><?php echo tep_draw_pull_down_menu('events_status', $status_array, ($pID!='' && $pID>0)?$eInfo->events_status:1); ?></td>
							<?php $_array=array('d','m','Y');  $replace_array=array('DD','MM','YYYY'); 	$date_format=str_replace($_array,$replace_array,EVENTS_DATE_FORMAT);?>
							<td class="main" width="150" valign="top"><?php echo TEXT_EVENTS_DATE_AVAILABLE; ?><br><small>(<?php echo $date_format;?>)</small></td>
							<td class="main" width="200" valign="top"><?php echo tep_draw_input_field("events_date_available",(tep_not_null($eInfo->events_date_available)?format_date($eInfo->events_date_available):format_date($current_date)),"size=10",false,'text',false);?>
							<a href="javascript:show_calendar('new_product.events_date_available',null,null,'<?php echo $date_format;?>');" onmouseover="window.status='Date Picker';return true;" onmouseout="window.status='';return true;"><img border="none" src="images/icon_calendar.gif"/>  
							</a>
						</tr>
					</table>
					</td>
				</tr>
				<tr>
					<td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
				</tr>
				<tr>
					<td>
					<table border="0" cellpadding="0" cellspacing="0">
						<tr>
							<td class="main" width="150" valign="top"><?php echo TEXT_EVENTS_CATEGORIES; ?></td>
							<td valign="top"><?php
						$categories_query_selected = tep_db_query("select events_categories_id from " . TABLE_EVENTS_TO_EVENTS_CATEGORIES . " where events_id = '" . (int)$HTTP_GET_VARS['pID'] . "'");
						$categories_selected=array();
						 while ($categories = tep_db_fetch_array($categories_query_selected)) 
						 	$category_selected[]=array('id'=>$categories['events_categories_id']);
						 
						 $cat_query = tep_db_query("select cd.events_categories_name,cd.events_categories_id from " . TABLE_EVENTS_CATEGORIES . " c," . TABLE_EVENTS_CATEGORIES_DESCRIPTION . " cd where c.events_categories_id=cd.events_categories_id and cd.language_id='" . (int)$language_id  ."'" );
						 $categories_array=array();
						 	while($cat_array=tep_db_fetch_array($cat_query))
								$categories_array[]=array('id'=>$cat_array['events_categories_id'],'text'=>$cat_array['events_categories_name']);

						 ?>
							</td><td valign="top">
						<?php echo tep_draw_mselect_checkbox('events_categories_ids[]',$categories_array,$category_selected); ?>
						</td>
						<td class="main" width="200">&nbsp;</td>
						</tr>
					</table>
					</td>
				</tr>
				<tr>
					<td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
				</tr>
				<?php tep_content_title_top("General"); ?>
				<tr>
					<td>
					<table border="0" cellpadding="4" cellspacing="0">
						<tr>
							<td>
							<table border="0" cellpadding="0" cellspacing="0">
							  <?php for ($i=0, $n=sizeof($languages); $i<$n; $i++) {?>
										<tr height="30">
											<td class="main" width="150"><?php if ($i == 0) echo TEXT_EVENTS_NAME; ?></td>
											<td class="main"><?php echo tep_image(DIR_WS_CATALOG_LANGUAGES . $languages[$i]['directory'] . '/images/' . $languages[$i]['image'], $languages[$i]['name']);?></td>
											<td class="main"><?php echo tep_draw_input_field('events_name[' . $languages[$i]['id'] . ']', (isset($events_name[$languages[$i]['id']]) ? $events_name[$languages[$i]['id']] : tep_get_events_name($eInfo->events_id, $languages[$i]['id'])),' size=40');?></td>
										</tr>
								<?php
								}?>
							</table>
							</td>
						</tr>
						<tr>
							<td>
							<table border="0" cellpadding="0" cellspacing="0">
								<?php for ($i=0, $n=sizeof($languages); $i<$n; $i++) { ?>
									<tr>
										<td class="main" valign="top" width="150"><?php if ($i == 0) echo TEXT_EVENTS_DESCRIPTION; ?></td>
										<td class="main" valign="top"><?php echo tep_image(DIR_WS_CATALOG_LANGUAGES . $languages[$i]['directory'] . '/images/' . $languages[$i]['image'], $languages[$i]['name']); ?>&nbsp;</td>
										<td>
										<table border="0" cellspacing="0" cellpadding="0">
											<tr>
												<td class="main" valign=""><?php echo tep_draw_textarea_field('events_description[' . $languages[$i]['id'] . ']', 'soft', '80', '24', (isset($events_description[$languages[$i]['id']]) ? $events_description[$languages[$i]['id']] : tep_get_events_description($eInfo->events_id, $languages[$i]['id'])),'id="events_description[' . $languages[$i]['id'] . ']"'); ?></td>
											</tr>
										</table>
										</td>
									</tr>
									<tr height="10"></tr>
								<?php } ?>
							</table>
							</td>
						</tr>
						<tr>
							<td width="100%">
							<table border="0" cellpadding="0" cellspacing="0" width="100%">
								<?php
								for ($i=0, $n=sizeof($languages); $i<$n; $i++) {
								?>
									<tr height="30">
										<td class="main" width="100%">
										<table border="0" cellpadding="0" cellspacing="0" width="100%">
											<tr>
												<td class="main" width="25%" nowrap="nowrap"><?php if ($i == 0) echo TEXT_EVENTS_URL . tep_draw_separator('pixel_trans.gif', '2', '10') . '<br><small>' . TEXT_EVENTS_URL_WITHOUT_HTTP . '</small>' . tep_draw_separator('pixel_trans.gif', '10', '10'); ?></td>
												<td class="main" align="right" width="10%"><?php echo tep_image(DIR_WS_CATALOG_LANGUAGES . $languages[$i]['directory'] . '/images/' . $languages[$i]['image'], $languages[$i]['name']);?></td>
												<td class="main" align="right" valign="middle" width="65%"><?php echo tep_draw_input_field('events_url[' . $languages[$i]['id'] . ']', (isset($events_url[$languages[$i]['id']]) ? $events_url[$languages[$i]['id']] : tep_get_events_url($eInfo->events_id, $languages[$i]['id'])),'size=40');?></td>
											</tr>
										</table>
										</td>
										<?php if($i==0){ ?>
										<td class="main" colspan="2" nowrap="nowrap" valign="middle"><?php echo "&nbsp;&nbsp;" . TEXT_EVENTS_IMAGE . "&nbsp;&nbsp;" . tep_draw_file_field('events_image') . '&nbsp;&nbsp;' . $eInfo->events_image . tep_draw_hidden_field('events_previous_image', $eInfo->events_image); ?></td>
										<?php }else{echo "<td class='main' colspan='2'>&nbsp;</td>";}?>
									</tr>
								<?php
								}
								?>
								<tr>
									<td colspan="4"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
								</tr>		  
								<tr>
									<?php $time_split=explode(":",$eInfo->events_start_time); 
									if ($time_split[2]=='PM' && $time_split[0]>12) $time_split[0]=$time_split[0]-12;?>
										<td class="main" width="350" nowrap="nowrap">
													<?php echo TEXT_EVENTS_START_TIME . '&nbsp;'; 
													 echo tep_draw_pull_down_menu('start_time_hours',$hour_array,$time_split[0]) . ' : ' . tep_draw_pull_down_menu('start_time_minutes',$minute_array,$time_split[1]) . ' ' . tep_draw_pull_down_menu('start_time_session',$day_session_array,$time_split[2]); ?></td>
													<?php $time_split=explode(":",$eInfo->events_end_time); 
															if ($time_split[2]=='PM' && $time_split[0]>12) $time_split[0]=$time_split[0]-12;?>
											
										<td class="main"  align="left" nowrap="nowrap">
										<?php echo tep_draw_radio_field('link_service','L',($eInfo->link_service=='L')?true:false,'','onClick="javascript:do_change(this);"').'&nbsp;'.TEXT_CHOOSE_LOCATIONS.'&nbsp;'.tep_draw_radio_field('link_service','S',($eInfo->link_service=='S')?true:false,'','onClick="javascript:do_change(this);"').'&nbsp;'.TEXT_LINK_SERVICES;
											echo tep_draw_hidden_field('link_service_val',$eInfo->link_service);?></td>
								</tr>
								<tr>
									<td colspan="4"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
								</tr>
								<tr>
									<td class="main" width="350" nowrap="nowrap"><?php //echo tep_draw_separator('pixel_trans.gif','90','10')?><?php echo TEXT_EVENTS_END_TIME . "&nbsp;&nbsp;"; ?>
									<?php echo tep_draw_pull_down_menu('end_time_hours',$hour_array,$time_split[0]) . ' : ' . tep_draw_pull_down_menu('end_time_minutes',$minute_array,$time_split[1]) . '  ' . tep_draw_pull_down_menu('end_time_session',$day_session_array,$time_split[2]); ?></td>
									<td class="main"  align="left">
										<table border="0"  cellpadding="0" cellspacing="0">
											<tr>
												<td class="main" id="locations" <?php echo ($eInfo->link_service=='L')?'style="display:;"':'style="display:none;"'; ?> align="left"><?php 
												echo '&nbsp;'.TEXT_EVENTS_LOCATION;
												echo tep_draw_separator('pixel_trans.gif', '15', '10') . tep_draw_pull_down_menu('events_location', $location_array,$eInfo->events_location);?>
												</td>
												<td  id="customers" <?php echo ($eInfo->link_service=='S')?'style="display:;"':'style="display:none;"'; ?> class="main"><?php
												echo TEXT_CHOOSE_CUSTOMER;
												$service_customer_selected=0;
												$default_customer_query=tep_db_query("select o.customers_id from ".TABLE_ORDERS." o, ".TABLE_ORDERS_PRODUCTS." op, ". TABLE_CUSTOMERS ." c where c.customers_id=o.customers_id and o.orders_id=op.orders_id and op.products_id='".(int)$eInfo->service_id."' and op.products_type='V' and lcase(o.payment_method) like '%internal only%' group by o.customers_id");
												if(tep_db_num_rows($default_customer_query)>0){
												$default_customer_array=tep_db_fetch_array($default_customer_query);
												$service_customer_selected=$default_customer_array['customers_id'];
												}	
																				
												$customer_query=tep_db_query("select o.customers_id,o.customers_name from ".TABLE_ORDERS." o, ".TABLE_ORDERS_PRODUCTS." op, ". TABLE_CUSTOMERS ." c where c.customers_id=o.customers_id and o.orders_id=op.orders_id and op.products_type='V' and lcase(o.payment_method) like '%internal only%' group by o.customers_id");
												$customers_array=array();	
												$customers_array[]=array('id'=>'-1','text'=>'-- Select --');												
												while($customer_array=tep_db_fetch_array($customer_query))
													$customers_array[]=array('id'=>$customer_array['customers_id'],'text'=>$customer_array['customers_name']);									
												
												echo tep_draw_separator('pixel_trans.gif', '35', '10') .'<span id="sel_customers_id">'. tep_draw_pull_down_menu('sel_customers',$customers_array,$service_customer_selected,'onChange=javascript:do_submit(this.value);').'</span>';
												?>
												</td>
											</tr>
										</table>
								</tr>	
								<tr>
									<td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
								</tr>		
								<tr id="services" <?php echo ($eInfo->link_service=='S')?'style="display:;"':'style="display:none;"'; ?>>
									<td class="main" width="350"><?php echo TEXT_CHOOSE_SERVICE;?>
									<?php echo tep_draw_separator('pixel_trans.gif', '1', '10') .'<span id="sel_services_id">'. tep_draw_pull_down_menu('sel_services',$services_array,$eInfo->service_id);?></td>
								</tr>	
								<tr>
									<td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
								</tr>
								<tr>
									<td class="main" nowrap="nowrap"><?php echo TEXT_EVENTS_MAX_RESERVE; ?>
									<?php 
										echo tep_draw_input_field('events_max_reserve',(tep_not_null($eInfo->events_max_reserve) ? $eInfo->events_max_reserve:'1'),' onKeyPress="return keyRestrict(event)" size=10 maxlength=6');
										echo tep_draw_hidden_field('old_max_reserve',$eInfo->events_max_reserve);
									?>
									</td>
									<td class="main" nowrap="nowrap" align="left"><?php echo  TEXT_EVENTS_OVERBOOK_RESERVE . "&nbsp;"; ?>
									<?php 
										echo tep_draw_input_field('events_overbook_reserve',(tep_not_null($eInfo->events_overbook_reserve) ? $eInfo->events_overbook_reserve:0),' onKeyPress="return keyRestrict(event)" size=10 maxlength=6');
									?>
									</td>
								</tr>
							</table>
							</td>
						</tr>
					</table>
					</td>
				</tr>
				<?php tep_content_title_bottom(); ?>
				<?php tep_content_title_top("Costs"); ?>
					<tr>
						<td>
						<table border="0"  cellpadding="4" cellspacing="0" width="100%">
							
							<tr>
								<td class="main"><?php 
								 	  $price=$eInfo->events_fees;
			           				  if(strpos($price,".") && substr($price,strpos($price,"."))<=0) $price=(int)$price;
								 	  echo TEXT_EVENTS_TAX_CLASS .tep_draw_separator('pixel_trans.gif',10,10) . tep_draw_pull_down_menu('events_tax_class_id', $tax_class_array, $eInfo->events_tax_class_id, 'onchange="updateGross()"');
									  echo tep_draw_separator('pixel_trans.gif',30,10).TEXT_EVENTS_FEES_NET_INFO . tep_draw_separator('pixel_trans.gif',10,10). tep_draw_input_field('events_fees_net', (tep_not_null($price) ? $price:'1'), 'onKeyUp="updateGross()"'); 
									  echo tep_draw_separator('pixel_trans.gif',30,10).TEXT_EVENTS_FEES_GROSS_INFO .tep_draw_separator('pixel_trans.gif',10,10). tep_draw_input_field('events_fees_gross', $eInfo->events_fees, 'OnKeyUp="updateNet()"');
								?>
								</td>
							</tr>
							<tr>
								
								<td class="main"><?php echo TEXT_EVENTS_REFUND_PAYMENT; 
								 $events_refund_pay = $events_payment_array;
									  $events_refund_length = count($events_refund_pay);
								      for($k=0;$k<$events_refund_length;$k++)
										  $events_refund_pay[$k]['text'] = strip_tags($events_refund_pay[$k]['text']);
								 echo tep_draw_separator('pixel_trans.gif',10,10).tep_draw_pull_down_menu('events_payment', $events_refund_pay,$eInfo->events_payment); ?></td>
							</tr>
						</table>
						</td>
					</tr>
				<?php tep_content_title_bottom(); ?>	  
				
				<?php tep_content_title_top("Instructor"); ?>
				<tr>
					<td>
					<table border="0"  cellspacing="0" cellpadding="4" width="70%">
						<tr>
							<td class="main"><?php echo tep_draw_checkbox_field('display_instructor','Y',($eInfo->display_instructor=='Y'?true:false),'','onClick="hide_instruct(this.checked)"') . '&nbsp;' . TEXT_DISPLAY_INSTRUCTOR;?></td>
						</tr>	
						<tr>
							
							<td align=left class="main" ><?php
							 echo TEXT_RATE_TYPE .tep_draw_separator('pixel_trans.gif',10,10) .tep_draw_pull_down_menu('instructors_rate_type',$rate_type_array,$eInfo->instructors_rate_type);
							 echo tep_draw_separator('pixel_trans.gif',20,10).TEXT_RATE .tep_draw_separator('pixel_trans.gif',10,10). tep_draw_input_field('instructors_rate',number_format($eInfo->instructors_rate,2),'onKeyPress="return keyRestrict(event)" size=10 maxlength=10');
							 echo tep_draw_separator('pixel_trans.gif',20,10).TEXT_BASE_RATE .tep_draw_separator('pixel_trans.gif',10,10). tep_draw_input_field('instructors_base_rate',number_format($eInfo->instructors_base_rate,2),' onKeyPress="return keyRestrict(event)" size=10 maxlength=10');?>
							</td>
						</tr>
						<tr>
							<td class="main" ><?php 
							echo TEXT_EVENTS_INSTRUCTOR .tep_draw_separator('pixel_trans.gif',10,10). tep_draw_pull_down_menu('events_instructor', $instructor_array, $eInfo->events_instructor);
							echo tep_draw_separator('pixel_trans.gif',20,10).TEXT_EVENTS_BACKUP_INSTRUCTOR . tep_draw_separator('pixel_trans.gif',10,10).tep_draw_pull_down_menu('events_backup_instructor', $instructor_array, $eInfo->events_backup_instructor); ?>
							</td>
						</tr>
					</table>
					</td>
				</tr>
				<?php tep_content_title_bottom(); ?>	
				<?php tep_content_title_top("WaitingList"); ?>
				<tr>
					<td>
					<table border="0" width=100% cellspacing="0" cellpadding="4">
						<tr>
							<td class="main" align=left colspan="2"><?php echo tep_draw_checkbox_field('events_wait_list','Y',($eInfo->events_wait_list=='Y'?true:false),'','onClick="doCheck(this.checked)"') . TEXT_PRESENT_WAITLIST; ?></td>
						</tr>
						<tr>
							<td class="main" align="left" colspan="2"><?php echo TEXT_WAITLIST_STYLE . tep_draw_separator('pixel_trans.gif', '24', '1') . tep_draw_radio_field('session_style','S',($eInfo->session_style=="S"?true:false),'',' onclick=javascript:set_session_style(this);') . TEXT_STYLE_SESSION . '&nbsp;' . tep_draw_radio_field('session_style','E',($eInfo->session_style=="E"?true:false),'',' onclick=javascript:set_session_style(this);') . TEXT_STYLE_EVENT;
									echo tep_draw_hidden_field('session_style_val',$eInfo->session_style);?></td>
						</tr>
						<tr>
							<td colspan="2">
							<table border="0" width=100% cellspacing="0" cellpadding="4">
								<tr valign=top>
									<td class="main" align=left width=20%><?php echo '<b>' . HEADING_TYPE . '</b>'; ?></td>
									<td class="main" align=left><?php echo '<b>' . HEADING_PRIORITY . '</b>'; ?></td>
									<td class="main" align=left><?php echo '<b>' . HEADING_SIZE . '</b>'; ?></td>
									<td class="main" align=left><?php echo '<b>' . HEADING_FEE . '</b>'; ?></td>
									<td class="main" align=left><?php echo '<b>' . HEADING_APPLY_TO . '</b>'; ?></td>
									<td class="main" align=left><?php echo '<b>' . HEADING_DESCRIPTION . '</b>'; ?></td>
								</tr>	
								<tr><td><?php echo tep_draw_separator('pixel_trans.gif', '1', '5'); ?></td></tr>
								<tr  valign=top>
									<td class="main"><?php echo TEXT_PRIORITY_VIP; ?></td>
									<td class="main"><?php echo tep_draw_pull_down_menu('priority_vip',$priority_array,((int)$eInfo->priority_vip!=0)?$eInfo->priority_vip:'1'); ?></td>
									<td class="main"><?php echo tep_draw_input_field('waitsize_vip',(tep_not_null($eInfo->waitsize_vip) ? $eInfo->waitsize_vip:'0'),' onKeyPress="return keyRestrict(event)" size=5 maxlength=6'); ?></td>
									<td class="main"><?php echo tep_draw_input_field('waitfee_vip',(tep_not_null($eInfo->waitfee_vip) ? $eInfo->waitfee_vip:'0'),' onKeyPress="return keyRestrict(event)" size=5 maxlength=6 onKeyUp="change_waitfee(this)"'); ?></td>
									<td class="main"><?php echo APPLY_TO_VIP ?></td>
									<td class="main" align=justify><?php echo DESCRIPTION_VIP ?></td>
								</tr>
								<tr><td><?php echo tep_draw_separator('pixel_trans.gif', '1', '5'); ?></td></tr>
								<tr  valign=top><td class="main"><?php echo TEXT_PRIORITY_FIRSTCOME; ?></td>
									<td class="main"><?php echo tep_draw_pull_down_menu('priority_firstcome',$priority_array,((int)$eInfo->priority_firstcome!=0)?$eInfo->priority_firstcome:'2'); ?></td>
									<td class="main"><?php echo tep_draw_input_field('waitsize_firstcome',(tep_not_null($eInfo->waitsize_firstcome) ? $eInfo->waitsize_firstcome:'0'),' onKeyPress="return keyRestrict(event)" size=5 maxlength=6'); ?></td>
									<td class="main"><?php echo tep_draw_input_field('waitfee_firstcome',(tep_not_null($eInfo->waitfee_firstcome) ? $eInfo->waitfee_firstcome:'0'),' onKeyPress="return keyRestrict(event)" size=5 maxlength=6 onKeyUp="change_waitfee(this)"'); ?></td>
									<td class="main"><?php echo APPLY_TO_FIRSTCOME ?></td>
									<td class="main" align=justify><?php echo DESCRIPTION_FIRSTCOME ?></td>
								</tr>
								<tr><td><?php echo tep_draw_separator('pixel_trans.gif', '1', '5'); ?></td></tr>
								<tr  valign=top>
									<td class="main"><?php echo TEXT_PRIORITY_CUSTOM; ?></td>
									<td class="main"><?php echo tep_draw_pull_down_menu('priority_custom',$priority_array,((int)$eInfo->priority_custom!=0)?$eInfo->priority_custom:'3');?></td>
									<td class="main"><?php echo tep_draw_input_field('waitsize_custom',(tep_not_null($eInfo->waitsize_custom) ? $eInfo->waitsize_custom:'0'),' onKeyPress="return keyRestrict(event)" size=5 maxlength=6'); ?></td>
									<td class="main"><?php echo tep_draw_input_field('waitfee_custom',(tep_not_null($eInfo->waitfee_custom) ? $eInfo->waitfee_custom:'0'),' onKeyPress="return keyRestrict(event)" size=5 maxlength=6 onKeyUp="change_waitfee(this)"'); ?></td>
									<td class="main"><?php echo tep_draw_pull_down_menu('priority_question',$questions_array,$eInfo->priority_question); ?></td>
									<td class="main" align=justify><?php echo DESCRIPTION_CUSTOM ?></td>
								</tr>
							</table>
							</td>
						</tr>
					</table>
        			</td>
				</tr>
				<?php tep_content_title_bottom(); ?>	  
				
				<?php tep_content_title_top("Conditions"); ?>
				<tr>
					<td>
					<table border="0"  width=100% cellspacing="0" cellpadding="4">
						<tr>
							<td>
							<table border="0" cellspacing="0" cellpadding="0">
								<tr>
									<td class="main" width="150"><?php echo TEXT_PENDING_PERIOD . '&nbsp;'; ?></td>
									<td class="main"><?php echo tep_draw_input_field('events_pending_period',(tep_not_null($eInfo->events_pending_period) ? $eInfo->events_pending_period:'0'),' onKeyPress="return keyRestrict(event)" size=7 maxlength=6')  . TEXT_DAYS; ?></td>
								</tr>
								<tr>
									<td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
								</tr>
								<tr>
									<td align=left class="main" valign="top"><?php echo TEXT_RENEWAL_START; ?></td>
									<td align=left class="main" valign="top"><?php echo tep_draw_pull_down_menu('events_renewal_start',$renewal_array,$eInfo->events_renewal_start); ?></td>
								</tr>
								<tr>
									<td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
								</tr>
								<tr>
									<td align=left class="main" valign="top"><?php echo TEXT_RENEWAL_END; ?></td>
									<td align=left class="main" valign="top"><?php echo tep_draw_input_field('events_renewal_end',$eInfo->events_renewal_end,' onKeyPress="return keyRestrict(event)" size=10 maxlength=6')  . TEXT_DAYS; ?></td>
								</tr>
								<tr>
									<td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
								</tr>
								<tr>
									<td class="main"><?php echo TEXT_EVENTS_REFUND_PERCENTAGE; ?></td>
									<td class="main">
										<?php echo TEXT_EVENTS_REFUND_PERCENTAGE1 . '&nbsp;' . tep_draw_pull_down_menu('refund_percentage1',$events_percent_array,(tep_not_null($eInfo->refund_percentage1) ? $eInfo->refund_percentage1:'10')) . '%'
												. '&nbsp;' . TEXT_EVENTS_REFUND_PERCENTAGE2 . '&nbsp;' . tep_draw_pull_down_menu('refund_percentage2',$events_percent_array,(tep_not_null($eInfo->refund_percentage2) ? $eInfo->refund_percentage2:'30')) . '%'
												. '&nbsp;' . TEXT_EVENTS_REFUND_PERCENTAGE3 . '&nbsp;' . tep_draw_pull_down_menu('refund_percentage3',$events_percent_array,(tep_not_null($eInfo->refund_percentage3) ? $eInfo->refund_percentage3:'50')) . '%'; 
										?>
									</td>
								</tr>
							</table>
							</td>
						</tr>
						<tr>
							<td>
							<table border="0" cellspacing="0" cellpadding="0">
								<tr>
									<td align="left" class="main" valign="top" width="150">&nbsp;</td>
									<td align="left" class="main" valign="top">
										<?php 	echo tep_draw_checkbox_field('session_gaps','Y',($eInfo->session_gaps=='Y'?true:false)) . '&nbsp;' . TEXT_SESSION_GAPS;
												echo '&nbsp;' . tep_draw_checkbox_field('session_reduction','Y',($eInfo->session_reduction=='Y'?true:false));
												echo '&nbsp;' . TEXT_SESSION_REDUCTION;
										?>
									</td>
								</tr>
								<tr>
									<td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
								</tr>
								<tr>
									<td align="left" class="main" valign="top" width="150">&nbsp;</td>
									<td class="main">
										<?php echo tep_draw_checkbox_field('events_forward_period','Y',($eInfo->events_forward_period=='Y'?true:false),'','onClick=""') . TEXT_FORWARD_PERIOD;
											echo '.&nbsp;&nbsp;&nbsp;' . TEXT_PERIOD_LENGTH . '&nbsp;' .  tep_draw_input_field('events_forward_length',$eInfo->events_forward_length,' onKeyPress="return keyRestrict(event)" size=7 maxlength=6') . TEXT_DAYS; ?>
									</td>
								</tr>
							</table>
							</td>
						</tr>
						<tr>
							<td>
							<table border="0" cellspacing="0" cellpadding="0">
								<tr>
								    <td align=left class="main"  valign="top" colspan="2">
								    <?php echo tep_draw_checkbox_field('events_group_bookings','Y',($eInfo->events_group_bookings=="Y"?true:false),false,'onClick="javascript:enableGroup();"') . TEXT_ALLOW_GROUP_BOOKINGS;?>
								    </td>
								</tr>
								<tr> 
								   <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
								</tr>
								<tr>
								    <td align=left class="main" valign="top"><?php echo TEXT_MIN_GROUP_SIZE ;?>
									<?php 
									echo tep_draw_separator('pixel_trans.gif', '10', '5') . tep_draw_input_field('events_group_min',(tep_not_null($eInfo->events_group_min) ? $eInfo->events_group_min:'0'),' onKeyPress="return keyRestrict(event)" size=7 maxlength=6');?></td>
									
								   <td align=left class="main" valign="top"><?php echo tep_draw_separator('pixel_trans.gif', '40', '10') . TEXT_MAX_GROUP_SIZE;?>
								  <?php echo tep_draw_separator('pixel_trans.gif', '10', '5') .tep_draw_input_field('events_group_max',(tep_not_null($eInfo->events_group_max) ? $eInfo->events_group_max:'0'),' onKeyPress="return keyRestrict(event)" size=7 maxlength=6');?></td>
								</tr>
								
								<tr>
								    <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
								</tr> 
								<tr>
									<td align=left class="main"  valign="top"><?php echo TEXT_CONDITION_DESC;?></td>
									<td class="main"><?php echo tep_draw_textarea_field('events_conditions','soft','100%',10,$eInfo->events_conditions); ?></td>

								</tr>
							</table>
							</td>
						</tr>
					</table>
					</td>
	  
				</tr>
				<?php tep_content_title_bottom(); ?>
				<?php tep_content_title_top("Subscription"); ?>
				<tr>
					<td>
					<table border=0 cellpadding="4" cellspacing="0" width="50%">
						<tr>
							<td class="main" width="150" valign="top"><?php echo TEXT_SUBSCRIPTION_CATEGORIES; ?></td>
							<td class="main" width="200"><?php 
							$events_link=true;				
							echo tep_draw_subscription_select_menu('subscription_categories_ids[]',$subscription_array, $subscription_categories_array_selected[0]['id'], 'size=10 id=subscription_categories_ids style="width:350"',false,0,false);
							?></td>
						</tr>
						<tr>
							<td class="main" nowrap="nowrap" width="150"><?php echo TEXT_SUBSCRIPTION_OVERBOOK_RESERVE; ?></td>
							<td class="main" align="left">
							<?php 
								echo tep_draw_input_field('subscription_overbook_reserve',(tep_not_null($eInfo->subscription_overbook_reserve) ? $eInfo->subscription_overbook_reserve:0),'size=10 maxlength=6');
							?>
							</td>
						</tr>
					</table>
					</td>
				</tr>	  
				<?php tep_content_title_bottom(); ?>
				<tr>
					<td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
				</tr>
				<tr>
					<td class="main" align="right"><?php echo tep_draw_hidden_field('events_date_added', (tep_not_null($eInfo->events_date_added) ? $eInfo->events_date_added : getServerDate())); ?></td>
				</tr>
				<tr align="right"><td width='1200' align='right'><input type='image' src='images/template/img_savel.gif' alt='save' title='save' border='0'>&nbsp;&nbsp;<a href='javascript:expand_category(0,1,0)'><img src='images/template/img_closel.gif' alt='close' title='close' border='0'></a>&nbsp;&nbsp;</td></tr>
		</table>       
	<?php
  	}
    
 function tep_get_event_daytext($session_result)
   {
     $type=$session_result['sessions_type_option'];
     $result_text='';
     $days_array=array('1'=>'Monday','2'=>'Tuesday','3'=>'Wednesday','4'=>'Thursday','5'=>'Friday','6'=>'Saturday','7'=>'Sunday');
     $count_array=array('1'=>'first','2'=>'second','3'=>'third','4'=>'fourth');
     $months_array=array('1'=>'January','2'=>'February','3'=>'March','4'=>'April','5'=>'May','6'=>'June','7'=>'July','8'=>'August','9'=>'September','10'=>'October','11'=>'November','12'=>'December');
	switch($type)
     {
        case 'DD':
		  if ($session_result['sessions_type_daily_days']<=1){
			$result_text=TEXT_DAILY_DAY;}
		  else
			$result_text=sprintf(TEXT_DAILY_DAYS,$session_result['sessions_type_daily_days']);
		  break;
        case 'WW':
		  $temp_string=$session_result['sessions_type_weekly_days'];
		  $day_string="";
		  for ($icnt=0;$icnt<strlen($temp_string);$icnt++){
			 if (substr($temp_string,$icnt,1)=='1'){
			   if ($day_string!='') $day_string=$day_string . ", ";
			   $day_string=$day_string . $days_array[$icnt+1];
			 }
		  }
		  if ($session_result['sessions_type_weekly_weeks']<=1)
			$result_text=sprintf(TEXT_WEEKLY_WEEK,$day_string);
		  else
			$result_text=sprintf(TEXT_WEEKLY_WEEKS,$session_result['sessions_type_weekly_weeks'],$day_string);
		  break;
		case 'MD':
		  if ($session_result['sessions_type_monthly_months']>1)
			$result_text=sprintf(TEXT_MONTHLY_DAYS,$session_result['sessions_type_monthly_months'],$session_result['sessions_type_monthly_days']);
			  else
			$result_text=sprintf(TEXT_MONTHLY_DAY,$session_result['sessions_type_monthly_days']);
		  break;
        case 'MM':
		  if ($session_result['sessions_type_monthly_weekmonths']>1)
			  $result_text=sprintf(TEXT_MONTHLY_WEEKS,$session_result['sessions_type_monthly_weekmonths'],$count_array[$session_result['sessions_type_monthly_weeks']],$days_array[$session_result['sessions_type_monthly_weekdays']]);
			  else
			  $result_text=sprintf(TEXT_MONTHLY_WEEK,$count_array[$session_result['sessions_type_monthly_weeks']],$days_array[$session_result['sessions_type_monthly_weekdays']]);	  
		  break;
        case 'YM':
		  $result_text=sprintf(TEXT_YEARLY_MONTHS,$months_array[$session_result['sessions_type_yearly_months']],$session_result['sessions_type_yearly_monthdays']);
		  break;
        case 'YY':
	  $result_text=sprintf(TEXT_YEARLY_WEEKS,$count_array[$session_result['sessions_type_yearly_weeks']],$days_array[$session_result['sessions_type_yearly_weekdays']],$months_array[$session_result['sessions_type_yearly_weekmonths']]);
	  break;
     }
     return $result_text;   
   }

function echo_get_details_result()
{
	global $currencies,$events_id,$languages_id,$HTTP_POST_VARS,$cID,$HTTP_GET_VARS;
		$str_vals="";
		$product_categories = tep_db_query("select cd.events_categories_id,cd.events_categories_name from " . TABLE_EVENTS_CATEGORIES . " c," . TABLE_EVENTS_CATEGORIES_DESCRIPTION . " cd where c.events_categories_id=cd.events_categories_id and cd.language_id='" . (int) $languages_id . "' and c.events_categories_id='" . (int) $HTTP_GET_VARS['cID'] . "'");		
		if (tep_db_num_rows($product_categories) > 0) {
			$categories = tep_db_fetch_array($product_categories);
			while (list (, $vals) = each($categories)) 
				$str_vals .= $vals . '{}';
		}
		/*$events_query = tep_db_query("select e.events_id, ed.events_name, e.events_date_available,e.events_date_added,ed.events_description,e.events_image, e.events_tax_class_id, e.events_fees," .
										"e.events_instructor,events_start_time as start_time,time_format(e.events_start_time,'%h:%i %p') as events_start_time,time_format(e.events_end_time,'%h:%i %p') as events_end_time,e.events_location," . 
										"e.events_status,e.events_conditions,e.sessions_select_interval,e.link_service,e.service_id from " . TABLE_EVENTS . " e, " . TABLE_EVENTS_DESCRIPTION .
										" ed where e.events_id in (" . $pID . ") and ed.events_id = e.events_id and ed.language_id = '" . (int)$languages_id . "' order by e.events_start_time,e.events_end_time");*/		
		//pd.products_id,pd.products_name, pd.products_description, p.products_quantity,p.products_tax_class_id,p.products_price,date_format(p.products_date_added,'%Y-%m-%d') as products_date_added, date_format(p.products_last_modified,'%Y-%m-%d') as products_last_modified,p.products_status,p.products_image_1,p.products_sort_order,date_format(p.products_date_available,'%Y-%m-%d') as products_date_available
		$events_query = tep_db_query("select e.events_id, ed.events_name, ed.events_description,e.events_tax_class_id, e.events_fees,date_format(e.events_date_added,'%Y-%m-%d') as events_date_added,date_format(e.events_last_modified,'%Y-%m-%d') as events_last_modified,e.events_status,e.events_image,date_format(e.events_date_available,'%Y-%m-%d') as events_date_available," .
										"e.events_instructor,events_start_time as start_time,time_format(e.events_start_time,'%h:%i %p') as events_start_time,time_format(e.events_end_time,'%h:%i %p') as events_end_time,e.events_location," . 
										"e.events_status,e.events_conditions,e.sessions_select_interval,e.link_service,e.service_id,e.display_instructor from " . TABLE_EVENTS . " e, " . TABLE_EVENTS_DESCRIPTION .
										" ed where e.events_id in (" . (int)$events_id . ") and ed.events_id = e.events_id and ed.language_id = '" . (int)$languages_id . "' order by e.events_start_time,e.events_end_time");										
		if(tep_db_num_rows($events_query)>0)  $events = tep_db_fetch_array($events_query);			
		    if(isset($events)){
				// Get the session details of event
				$session_query=tep_db_query("SELECT * from " . TABLE_RECURSIVE_SESSIONS . " where events_id='" . (int)$events["events_id"] . "'");				
				if(tep_db_num_rows($session_query)>0) $session_result=tep_db_fetch_array($session_query);
				$event_text=tep_get_event_daytext($session_result);
				// Get the location details of event
				if($events['link_service']=='L')
					$location_query=tep_db_query("SELECT location_name,location_details from " . TABLE_EVENTS_LOCATIONS . " where location_id='" . (int)$events["events_location"] . "'");
				else if($events['link_service'] == 'S')
					$location_query=tep_db_query("SELECT sl.service_location_name as location_name,sl.service_location_details as location_details from " . TABLE_SERVICES." s, ".TABLE_SERVICES_LOCATIONS ." sl where  s.service_location=sl.service_location_id and s.service_id='".(int)$events["service_id"] ."'");
				if($location_query!="" && tep_db_num_rows($location_query)>0) $location_info=tep_db_fetch_array($location_query);
				// Get the instructor details of event
				$instructor_query=tep_db_query("SELECT concat(admin_firstname,' ',admin_lastname) as instructor_name from " . TABLE_ADMIN . " where admin_id='" . (int)$events["events_instructor"] . "'");
				if($instructor_query!="" && tep_db_num_rows($instructor_query)>0) $instructor_info=tep_db_fetch_array($instructor_query);
				// calculate event fees
				$interval=($events["sessions_select_interval"]>0?$events["sessions_select_interval"]:1);
				$fees=$interval*tep_add_tax($events["events_fees"],tep_get_tax_rate($events["events_tax_class_id"]));
				$info=TEXT_FEES_INFO_SINGLE;
				if ($interval>1) $info=TEXT_FEES_INFO;
				$amount=$currencies->format($fees) . sprintf($info,$interval);
				$events_name=tep_get_events_display_text($events["events_name"],$events["start_time"],$location_info["location_name"]);
				$str_vals.=$events["events_id"] . '{}' . $events_name . '{}' .str_replace("\n","",$events['events_description'] . '{}').'{}'.$amount.'{}'.format_date($events['events_date_added']).'{}'.format_date($events['events_last_modified']).'{}'.$events['events_status'].'{}'.$events['events_image'] .'{}{}';				
				$str_vals.=$event_text . " " . strtolower($events["events_start_time"]) . " - " . strtolower($events["events_end_time"]) . '{}';
				$str_vals.=$location_info["location_name"] . '{}';
				$str_vals.=$instructor_info["instructor_name"] .'{}';
				//$str_vals.=$amount . '{}' . (($HTTP_POST_VARS['events_status']!="")?tep_db_prepare_input($HTTP_POST_VARS['events_status']):$events["events_status"]);
		    }else $str_vals="No Record Found";
			echo (($HTTP_POST_VARS['action_type'] == 'new') ? '' : 'get_details^') . $str_vals;
}
if($action!="") exit;
	?>