<?php
// Set flag that this is a parent file
	defined('_FEXEC') or die();
	
include(DIR_WS_CLASSES . 'order.php');

$step=isset($HTTP_POST_VARS['step'])?(int)$HTTP_POST_VARS['step']:2;


$events_id=isset($HTTP_POST_VARS['events_name'])?(int)$HTTP_POST_VARS['events_name']:0;
$start_date=isset($HTTP_POST_VARS['start_date'])?tep_db_prepare_input($HTTP_POST_VARS['start_date']):'';
$sessions_id=isset($HTTP_POST_VARS['sessions_id'])?(int)$HTTP_POST_VARS['sessions_id']:0;
$no_attendees=isset($HTTP_POST_VARS["no_attendees"])?(int)$HTTP_POST_VARS['no_attendees']:0;

if (isset($HTTP_GET_VARS["check"])){
	$events_id=isset($HTTP_GET_VARS['param_1'])?(int)$HTTP_GET_VARS['param_1']:0;
	$sessions_id=isset($HTTP_GET_VARS['param_2'])?(int)$HTTP_GET_VARS['param_2']:0;
	$step=3;
}
if(isset($HTTP_GET_VARS['opID']) && $HTTP_GET_VARS['opID']>0){
	tep_db_query("delete from ".TABLE_ORDERS_EDIT_PRODUCTS." where orders_products_id='".(int)$HTTP_GET_VARS['opID']."'");
}
$override=(isset($HTTP_POST_VARS["override_reserve"])?true:false);
$overbook=(isset($HTTP_POST_VARS["overbook_reserve"])?true:false);
echo "new_event||";
?>
<table border="0" width="100%" cellspacing="2" cellpadding="2">
<tr>
<!-- body_text //-->
    	<td width="100%" valign="top">
			<?php echo tep_draw_form("select_session",FILENAME_ADDEVENTS_NEW,$page_params);?>
			<table border="0" width="100%" cellspacing="0" cellpadding="0">
			<tr>
				<td width="100%"><table border="0" width="100%" cellspacing="0" cellpadding="0">
				  <tr >
					<td class="main"><B><?php echo EVENT_ADDING_TITLE; ?></b> </td>
					<?php	print '<td id="show_event_save_icon_up" width=10% nowrap style="display:none" colspan=3 class="main" align="right" style="padding-left:10px;padding-right:10px;padding-top:3px;"><a href="javascript:do_page_fetch(\'event_submit\');">' . tep_image(DIR_WS_IMAGES .  'template/img_savel.gif') .'</a>&nbsp;
								<a href="javascript:do_page_fetch(\'ajx_close_event_new\');">' . tep_image(DIR_WS_IMAGES .  'template/img_closel.gif') . '</a>
							   </td>';?>
				  </tr>
				</table></td>
			  </tr>
    			<tr>
					<td>
						<table border="0" width=100% cellspacing="0" cellpadding="1">
							<tr>
								<td id='new_event_step1'>
								<table border="0" cellpadding="2" cellspacing="0">
								 <tr valign="middle">
										<td class="dataTableContent" align=left height="20"><b><?php echo EVENT_STEP1; ?></b></td>
								</tr>
								<tr>
									<td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
								 </tr>
								<tr>
										<td class="dataTableContent" width="100" valign="top"><?php echo TEXT_EVENT_NAME;?></td>
										<?php  // if the mode is not edit then displa the event select box
										if (!$edit_mode) {?>
										<td class="dataTableContent" align=left valign="middle" width="550">
											<?php $events_array=tep_get_events_info_tree($customer_id);
												  customEventListBox('events_name',$events_array,$events_id,"100%","100px");											
												  ?>
										</td>
										<td align="center" class="main" valign="bottom">
										<table border="0" cellpadding="5" cellspacing="0">
											<?php $get_reservation_query=tep_db_query("select admin_groups_id from admin_files where TRIM(admin_files_name)='override reservation' or TRIM(admin_files_name)='overbook reservation'");
												  $result_array=array();
												  while($result_reservation=tep_db_fetch_array($get_reservation_query)){
												    $result_array[]=array('id'=>"," . $result_reservation['admin_groups_id'] . ",");
												  }
											 if (strpos($result_array[0]['id'],"," . $login_groups_id . ",")!==false) { ?>
												<tr>
													<td class="main" nowrap><?php echo tep_draw_checkbox_field('override_reserve','Y',$override) . TEXT_OVERRIDE_RESERVE;?></td>
												</tr>
											<?php } 
											if(strpos($result_array[1]['id'],"," .$login_groups_id .",")!==false){?>
												<tr>
													<td class="main" nowrap><?php echo tep_draw_checkbox_field('overbook_reserve','Y',$overbook) . TEXT_OVERBOOK_RESERVE;?></td>
												</tr>
											<?php }?>
												<tr>
													<td class="main" nowrap><?php echo '<a href="javascript:do_page_fetch(\'new_event_step2\')">' . tep_image_button('button_select.gif','','align=absmiddle') . '</a>&nbsp;';?><span id="event_process_show" style="display:none"><?php echo tep_image(DIR_WS_IMAGES . '24-1.gif');?></span></td>
												</tr>
										<?php } else {?>
												<td class="main" nowrap><b>
													<?php 
														echo tep_get_events_name($events_id);
													?></b>
												</td>
													<input type="hidden" name="events_name" value="<?php echo $events_id;?>">
										<?php } ?>
										</table>
									</tr>
								</table>
								</td>
							</tr>
							<tr><td colspan='3' id='new_event_step2'></td></tr>
							<tr><td colspan='3' id='show_attendees'></td></tr>
							<?php
							print '<tr ><td id="show_event_save_icon_down" style="display:none" colspan=3 class="main" align="right" style="padding-left:10px;padding-right:10px;padding-top:3px;"><a href="javascript:do_page_fetch(\'event_submit\');">' . tep_image(DIR_WS_IMAGES .  'template/img_savel.gif') .'</a>&nbsp;
							<a href="javascript:do_page_fetch(\'ajx_close_event_new\');">' . tep_image(DIR_WS_IMAGES .  'template/img_closel.gif') . '</a>
						   </td></tr>';
							?>
						</table>
					</form>
				</td></tr></table>

<?php 
/*function user_compare($a, $b) 
{
    if ($a['date'] == $b['date']) {
        return 0;
    }
    return ($a['date'] < $b['date']) ? -1 : 1;
}*/
function customEventListBox($name,&$list,$selected,$width,$height){
	$selIndex=0;
	
	echo '<div id="' . $name . '_box" style="border-color: #7b9ebd; border-style: solid; border-width: 1px;overflow:auto;width:' . $width . ';height:' . $height . '">' . "\n";
	echo '<table border="0" cellspacing="0" cellpadding="2" width="100%" valign="middle" align="center" class="BoxTable">' . "\n";
	for ($icnt=0;$icnt<sizeof($list);$icnt++){
		if ($list[$icnt]['mode']=='E') {
			if ($selected==0) $selected=$list[$icnt]['id'];
			echo  '<tr class="attributes-even"><td nowrap bgcolor="' . ($selected==$list[$icnt]['id']?"#D8EDFB":"#FFFFFF") . '" valign="middle" width="100%" id="' . $name . $list[$icnt]['id'] . '" onClick="javascript:selectEventItem(\'' . $name . '\',\'' . $list[$icnt]['id'] .  '\',' . $icnt .')" class="BoxTd">' . "\n";
			echo  $list[$icnt]['text'] .'</td></tr>' ."\n";
			if ($selected==$list[$icnt]['id']) $selIndex=$icnt;
		} else {
			echo  '<tr class="attributes-even"><td nowrap bgcolor="#FFFFFF" valign="middle" width="100%" class="BoxTd">' . "\n";
			echo  $list[$icnt]['text'] .'</td></tr>' ."\n";
		}
	}
	echo '</table></div>' . "\n";
	echo '<input type="hidden" name="' . $name . '" value="' . $selected . '">';
	echo '<input type="hidden" name="' . $name . '_index" value="' . $selIndex . '">';
}

?>