<?php
/*
  osCommRes, Services Online
  http://www.oscommres.com

  Copyright (c) 2005 osCommRes

  Released under the GNU General Public License
  
  Freeway eCommerce from Zac
http://www.zac-ware.com/freeway

Copyright 2007 ZacWare Pty. Ltd
*/
// Set flag that this is a parent file
	define( '_FEXEC', 1 );
require('includes/application_top.php');

$action=isset($HTTP_POST_VARS["action"])?$HTTP_POST_VARS["action"]:'';
switch($action){
	case 'delete_items':
	$delete_items=isset($HTTP_POST_VARS["entries"])?$HTTP_POST_VARS["entries"]:array();
	$tables='';
	if (count($delete_items)>0){
		for ($icnt=0,$n=count($delete_items);$icnt<$n;$icnt++){
			switch($delete_items[$icnt]){
				case 'products':
					$tables.='categories,categories_description,products,products_attributes,products_attributes_download,products_description,products_options_values_to_products_options,products_to_categories,';
					break;
				case 'events':
					$tables.='events,events_description,events_categories,events_categories_description,events_discounts,events_recursive_sessions,events_sessions,events_to_events_categories,';
					break;
				case 'subscriptions':
					$tables.='subscription_categories,subscription_categories_description,subscription_groups,subscription_to_subscription_categories,subscriptions,subscriptions_description,';
					break;
				case 'services';
					$tables.='services,services_attributes,services_categories,services_categories_description,services_description,services_loadings,services_no_booking_days,services_options_values_to_services_options,services_to_services_categories,services_to_services_resources,';
					break;
			}
		}
		if ($tables!=''){
			$tables_splt=split(",",$tables);
			for ($icnt=0,$n=count($tables_splt)-1;$icnt<$n;$icnt++){
				tep_db_query("DELETE from " . $tables_splt[$icnt]);
				//echo $tables_splt[$icnt] . '<br>';
			}
		}
	}
	tep_redirect(tep_href_link(FILENAME_SHOP_SALE_ITEMS,'mode=success'));
	break;
}

//check if order has any records 
$order_query=tep_db_query("SELECT * from " . TABLE_ORDERS . " limit 1");
?>
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html <?php echo HTML_PARAMS; ?>>
<head>
<meta http-equiv="Content-Type" content="text/html;" charset="<?php echo CHARSET; ?>">
<title><?php echo TITLE; ?></title>
<link rel="stylesheet" type="text/css" href="includes/stylesheet.css">
<script language="javascript">
	function validateForm(){
		var icnt,n;
		var element=document.sale_items.elements['entries[]'];
		var error="<?php echo tep_output_string(ERR_JS_SELECT_SALE);?>";
		for (icnt=0,n=element.length;icnt<n;icnt++){
			if (element[icnt].checked) {
				error='';
				break;
			}
		}
		if (error!=''){
			alert(error);
			return false;
		}
		if (confirm("Are you sure to delete the items")){
			return true;
		} else {
			return false;
		}
		
	}
</script>
</head>
<body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0" bgcolor="#FFFFFF">
<!-- header //-->
<?php require(DIR_WS_INCLUDES . 'header.php'); ?>
<!-- header_eof //-->
<!-- Ajax Work Starts -->
<table border="0" width="100%" cellpadding="3" cellspacing="6">
<tr class="dataTableHeadingRow">
	<td width="100%" class="main"><b><?php echo HEADING_TITLE; ?></b></td>
</tr>
<?php if ($mode=="success") {?>
	<tr height="40">
		<Td class="main">
			Selected Shop sale items are successfully deleted.
		</Td>
	</tr>
<tr>
	<td><?php echo '<a href="' . tep_href_link(FILENAME_SHOP_SALE_ITEMS) . '">' . tep_image_button('button_continue.gif','Continue') . '</a>';?>
</tr>

<?php }  else {?>
<tr height="40">
	<Td class="main">
	<b><?php echo TEXT_SELECT_SALE;?></b>
	</Td>
</tr>
<?php echo tep_draw_form('sale_items',FILENAME_SHOP_SALE_ITEMS,'','post','onSubmit="javascript:return validateForm();"');?>
<input type="hidden" name="action" value="delete_items">
<tr>
	<td class="smallText"><?php echo TEXT_SELECT_SALE_DESC;?></td>
</tr>
<tr>
	<td>
	<table border="0" width="100%" cellpadding="0" cellspacing="0">
		<tr>
			<td class="main"><?php echo tep_draw_checkbox_field('entries[]','products',false,'') . TEXT_DELETE_PRODUCTS;?></td>
		</tr>
		<tr>
			<td class="main"><?php echo tep_draw_checkbox_field('entries[]','events',false,'') . TEXT_DELETE_EVENTS;?></td>
		</tr>
		<tr>
			<td class="main"><?php echo tep_draw_checkbox_field('entries[]','subscriptions',false,'') . TEXT_DELETE_SUBSCRIPTIONS;?></td>
		</tr>
		<tr>
			<td class="main"><?php echo tep_draw_checkbox_field('entries[]','services',false,'') . TEXT_DELETE_SERVICES;?></td>
		</tr>
		<tr>
			<td height="30"></td>
		</tr>
		<?php if (tep_db_num_rows($order_query)>1){ ?>
		<tr>
			<td class="errorText"><?php echo ERR_SELECT_INFO;?>
			</td>
		</tr>
		<?php } else { ?>
		<tr>
			<td><?php echo tep_image_submit('button_delete.gif','Delete Items');?>
		</tr>
		<?php } ?>
	</table>
	</td>
</tr>
</form>
<?php } ?>
</table>
<!-- body_text_eof //-->
<!-- footer //-->
<?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
<!-- footer_eof //-->
</body>
</html>
<?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?>