<?php
/*

tep_db_query("select products_model from " . TABLE_PRODUCTS . " where products_id = '" . (int)$products_id . "'");
osCommerce, Open Source E-Commerce Solutions 
http://www.oscommerce.com 

Copyright (c) 2003 osCommerce 

osCommRes, Services Oline 
http://www.oscommres.com 
Copyright (c) 2005 osCommRes 

Freeway eCommerce 
http://www.zac-ware.com/freeway 
Copyright (c) 2007 ZacWare

Released under the GNU General Public License 
*/
// Set flag that this is a parent file
  define( '_FEXEC', 1 );
  require('includes/application_top.php');
  require(DIR_WS_CLASSES . 'split_page_results_event.php');
  require(DIR_WS_CLASSES . 'currencies.php');
  $dis_time_format="";
  if(defined('TIME_FORMAT'))
	$dis_time_format=TIME_FORMAT;
  $command=isset($HTTP_GET_VARS['command'])?$HTTP_GET_VARS['command']:'';
  if($command!=''){
  $orders_id=isset($HTTP_GET_VARS['orders_id'])?(int)$HTTP_GET_VARS['orders_id']:'';
  $status_id=isset($HTTP_GET_VARS['status'])?(int)$HTTP_GET_VARS['status']:'';
  switch($command){
  	case 'orders_page_navigation':
		global $orders_page;
		$orders_page=isset($HTTP_GET_VARS['orders_page'])?$HTTP_GET_VARS['orders_page']:'';
		echo 'orders_page_navigation^^';
		echo load_orders('',$status_id);
		break;
	case 'load_orders_details':
		echo 'load_orders_details^^'.$orders_id.'^^';
		echo load_orders_details($orders_id);
		if($HTTP_GET_VARS['return']){
			echo "^^" . $HTTP_GET_VARS['return'] . "^^" . $HTTP_GET_VARS['type'] . "^^" . $HTTP_GET_VARS['id'] . "^^"  . $HTTP_GET_VARS['dpage']. "^^"  . $HTTP_GET_VARS['mPath'];
		}
		break;
	case 'edit_order_details';
		echo 'edit_order_details^^'.$orders_id.'^^';
		echo edit_order_details($orders_id);
		break;
	case 'save_edit_order_details':
		echo save_edit_order_details();
		echo 'edit_order_details^^'.$HTTP_POST_VARS['oID'].'^^';
		echo edit_order_details($HTTP_POST_VARS['oID']);
		break;
	case 'delete_order':
		echo 'delete_order^^'.$orders_id.'^^';
		echo delete_order($orders_id);
		break;
	case 'delete_confirm':
		$oID=isset($HTTP_POST_VARS['orders_id'])?(int)$HTTP_POST_VARS['orders_id']:'';
		tep_remove_order_events($oID, $HTTP_POST_VARS['restock']);
		echo 'orders_page_navigation^^';
		echo load_orders();
		break;
	case 'change_orders_status':
		$status_id=isset($HTTP_GET_VARS['status_id'])?(int)$HTTP_GET_VARS['status_id']:'';
		$cID=isset($HTTP_GET_VARS['cID'])?(int)$HTTP_GET_VARS['cID']:'';
		echo 'load_orders^^';
		echo load_orders('',$status_id,$cID);
		break;
	case 'order_search':
		$oID=isset($HTTP_GET_VARS['oID'])?(int)$HTTP_GET_VARS['oID']:'';
		$cID=isset($HTTP_GET_VARS['cID'])?(int)$HTTP_GET_VARS['cID']:'';
		echo 'order_search^^';
		echo load_orders($oID,'',$cID);
		echo '<div align="right"><a href="javascript: reset_search();">'.tep_image_button('button_reset.gif', IMAGE_RESET).'</a>&nbsp;&nbsp;</div>';
		echo '^^'.$oID;
		break;
  }
  exit;
  }
  
  tep_get_last_access_file();
  $currencies = new currencies();
  $server_date = getServerDate(true);

  $orders_statuses = array();
  $orders_status_array = array();
  $orders_statuses=tep_get_orders_status();
  $orders_status_query = tep_db_query("select orders_status_id, orders_status_name from " . TABLE_ORDERS_STATUS . " where language_id = '" . (int)$languages_id . "'");
  while ($orders_status = tep_db_fetch_array($orders_status_query)) {
   // $orders_statuses[] = array('id' => $orders_status['orders_status_id'],
   //                            'text' => $orders_status['orders_status_name']);
    $orders_status_array[$orders_status['orders_status_id']] = $orders_status['orders_status_name'];
  }

// BOF: WebMakers.com Added: Additional info for Orders
// Look up things in orders
$the_extra_query= tep_db_query("select * from " . TABLE_ORDERS . " where orders_id = '" . (int)$oID . "'");
$the_extra= tep_db_fetch_array($the_extra_query);
$the_customers_id= $the_extra['customers_id'];
// Look up things in customers
$the_extra_query= tep_db_query("select * from " . TABLE_CUSTOMERS . " where customers_id = '" . (int)$the_customers_id . "'");
$the_extra= tep_db_fetch_array($the_extra_query);
$the_customers_fax= $the_extra['customers_fax'];
// EOF: WebMakers.com Added: Additional info for Orders

include(DIR_WS_CLASSES . 'order.php');
?>

	<?php
	function load_orders($oID='',$status='',$cID=''){
	global $orders_page,$languages_id;
		$search_customers_criteria=""; $status_criteria=""; $orders_search_criteria="";
		if($cID!='')
		    $search_customers_criteria=" and o.customers_id='$cID' ";
		if($status!='')
			$status_criteria=" and s.orders_status_id='$status' ";
		if($oID!='')
			$orders_search_criteria=" and o.orders_id='$oID' ";
	$orders_query_raw = "select o.orders_id, o.payment_return1, o.payment_return2, o.reference_id, op.products_quantity,concat(LTRIM(c.customers_lastname),' ',LTRIM(c.customers_firstname)) as customers_name, o.payment_method, o.date_purchased, o.last_modified, o.currency, o.currency_value, s.orders_status_name, op.products_type, ot.text as order_total from " . TABLE_ORDERS . " o left join " . TABLE_ORDERS_TOTAL . " ot on (o.orders_id = ot.orders_id), " . TABLE_ORDERS_STATUS . " s, " .TABLE_ORDERS_PRODUCTS." op, ".TABLE_CUSTOMERS ." c where o.customers_id=c.customers_id and o.orders_status = s.orders_status_id and o.orders_id=op.orders_id and s.language_id = '" . (int)$languages_id . "' and ot.class = 'ot_total' ".$search_customers_criteria.$status_criteria.$orders_search_criteria." group by o.orders_id order by o.orders_id DESC,customers_name ASC";
	//echo $orders_query_raw;
	$orders_split = new splitPageResultsEvent($orders_page, MAX_DISPLAY_SEARCH_RESULTS, $orders_query_raw, $orders_numrows);	    
    $orders_query = tep_db_query($orders_query_raw);
	echo '<table width="100%" cellpadding="0" cellspacing="0" border="0">';	
	$cnt=0;
		if(tep_db_num_rows($orders_query)<=0)
			echo '<tr><td style="color:#FF0000;" align="center">'.TEXT_NO_ORDERS_DETAILS_FOUND.'</td></tr>';
	  while ($orders = tep_db_fetch_array($orders_query)) {  
	  $class_name=($cnt%2==0)?'dataTableRowOdd':'dataTableRowEven';
        $oInfo = new objectInfo($orders);

	?>
	<tr>
	<td>
		<div id="orders_<?php echo $orders['orders_id']; ?>" onClick="javascript: load_orders_details(<?php echo $orders['orders_id']; ?>);"  class="<?php echo $class_name; ?>" onMouseOver="rowOverEffect(this)" onMouseOut="rowOutEffect(this)">
		<table height="20px;" width="100%" cellpadding="0" cellspacing="0" border="0">
		<tr>
        <td width="25%" class="main">&nbsp;<?php echo tep_image(DIR_WS_IMAGES.'template/icon_active.gif') . '&nbsp;' . $orders['customers_name']; ?></td>
        <td width="25%" class="main" align="right"><?php echo strip_tags($orders['order_total']); ?></td>
        <td width="25%" class="main" align="center"><?php echo date(EVENTS_DATE_FORMAT,strtotime($orders['date_purchased'])); ?></td>
        <td width="25%" class="main" align="right"><?php echo $orders['orders_status_name']; ?></td>
		</tr>
		</table>
		</div>
		<div id="ajax_orders_<?php echo $orders['orders_id']; ?>">
		</div>
	</td>
	</tr>
	<?php
    }
	?>
	<?php
	echo '<tr><td><table width="100%" cellpadding="0" cellspacing="0" border="0"><tr id="display_count"><td class="smalltext" style="padding-left:10px;" width="50%" >'.
	 $orders_split->display_count($orders_numrows, MAX_DISPLAY_SEARCH_RESULTS, $orders_page, TEXT_DISPLAY_NUMBER_OF_ORDERS).
	 '</td><td width="50%" class="smalltext" align="right">'.
  	 $orders_split->display_script_links($orders_numrows, MAX_DISPLAY_SEARCH_RESULTS, MAX_DISPLAY_PAGE_LINKS, $orders_page,1,'orders_page_navigation(\'\'','1').
	 '<td></tr></table>';
	echo '</td></tr></table>';
	}
	
	function delete_order($orders_id){
	global $languages_id;
	$orders_query_raw = "select o.orders_id, o.payment_return1, o.payment_return2, o.reference_id, op.products_quantity,concat(LTRIM(c.customers_lastname),' ',LTRIM(c.customers_firstname)) as customers_name, o.payment_method, o.date_purchased, o.last_modified, o.currency, o.currency_value, s.orders_status_name, op.products_type, ot.text as order_total from " . TABLE_ORDERS . " o left join " . TABLE_ORDERS_TOTAL . " ot on (o.orders_id = ot.orders_id), " . TABLE_ORDERS_STATUS . " s, " .TABLE_ORDERS_PRODUCTS." op, ".TABLE_CUSTOMERS ." c where o.customers_id=c.customers_id and o.orders_status = s.orders_status_id and o.orders_id=op.orders_id and s.language_id = '" . (int)$languages_id . "' and ot.class = 'ot_total' and o.orders_id='" . tep_db_input($orders_id) . "' group by o.orders_id order by o.orders_id DESC,customers_name ASC";
	$orders_query=tep_db_query($orders_query_raw);
	$orders=tep_db_fetch_array($orders_query);
	$oInfo = new objectInfo($orders);
	$packs_query=tep_db_query("select count(*) as activated from " . TABLE_ORDERS_PRODUCTS_SUPPORT_PACKS . " opsp, " . TABLE_SUPPORT_PACKS_LICENSE . " spl where spl.support_packs_id=opsp.support_packs_id and opsp.orders_id='" . tep_db_input($orders_id) . "' and spl.activate='Y'");
	$packs_result=tep_db_fetch_array($packs_query);
	//Support Packs
	if($packs_result['activated']>0){ echo 'error^^';?>
	<table style="padding:10px;" width="100%" cellpadding="2" cellspacing="2" border="0">
		<tr>
			<td class="main" align="center"><?php echo TEXT_INFO_DELETE_INTRO . '&nbsp;&nbsp;'.$oInfo->customers_name; ?></td>
		</tr>
		<tr>
			<td class="main" align="center"><?php echo TEXT_ERR_DELETE_INTRO; ?></td>
		</tr>
	</table>	
	<?php } else {
	
	echo tep_draw_form('delete_orders_form',FILENAME_ORDERS,'','').tep_draw_hidden_field('orders_id',$orders_id);
	?>
	<table style="padding:10px;" width="100%" cellpadding="2" cellspacing="2" border="0">
	<tr>
	<td class="main" align="center"><?php echo TEXT_INFO_DELETE_INTRO . '&nbsp;&nbsp;'.$oInfo->customers_name; ?></td>
	</tr>
	<tr>
	<td class="main" align="center"><?php echo tep_draw_checkbox_field('restock').' ' . TEXT_INFO_RESTOCK_PRODUCT_QUANTITY; ?></td>
	</tr>
	</table>
	</form>
	<?php }
	}
	function load_orders_details($orders_id){
	global $languages_id,$login_groups_type;
	$orders_query_raw = "select o.orders_id, o.payment_return1, o.payment_return2, o.reference_id, o.orders_status,op.products_quantity,concat(LTRIM(c.customers_lastname),' ',LTRIM(c.customers_firstname)) as customers_name, o.payment_method, o.date_purchased, o.last_modified, o.currency, o.currency_value, s.orders_status_name, op.products_type, ot.text as order_total from " . TABLE_ORDERS . " o left join " . TABLE_ORDERS_TOTAL . " ot on (o.orders_id = ot.orders_id), " . TABLE_ORDERS_STATUS . " s, " .TABLE_ORDERS_PRODUCTS." op, ".TABLE_CUSTOMERS ." c where o.customers_id=c.customers_id and o.orders_status = s.orders_status_id and o.orders_id=op.orders_id and s.language_id = '" . (int)$languages_id . "' and ot.class = 'ot_total' and o.orders_id='" . tep_db_input($orders_id) . "' group by o.orders_id order by o.orders_id DESC,customers_name ASC";
	$orders_query=tep_db_query($orders_query_raw);
	$orders=tep_db_fetch_array($orders_query);
	$oInfo = new objectInfo($orders);
	
	?>
	<table border="0" cellpadding="0" cellspacing="0" width="100%" class="openContent">
	<tr class="openContent_top" onClick="do_close('<?php echo $orders_id;?>');">
	<td width="500" class="main"><?php echo tep_image(DIR_WS_IMAGES.'template/icon_active.gif').'&nbsp;'.$oInfo->customers_name; ?></td>
	<td  width="100" align="center">
	<table style="background:#DEE4F5;cursor:pointer;" width="100%" border="0" cellpadding="0" id="header_operation_id" cellspacing="0">
	<tr id="img_ids">
	<td class="cell_bg_popm_left">&nbsp;</td>
	<?php				
		if($login_groups_type!='Demo User Group' || $login_groups_type!='Fulfiller' || $login_groups_type!='Call Centre Staff' || $login_groups_type!='Instructors') echo '<td width="10%" OnClick="javascript:do_hover_change(this,1); do_refund('.$orders_id.','. $oInfo->orders_status .');" onMouseOver="do_hover_change(this,2);" onMouseOut="do_hover_change(this,3);">'.tep_image(DIR_WS_IMAGES.'template/img_move.gif','Refund').'</td>';
		echo '<td width="10%" OnClick="javascript:do_hover_change(this,1); edit_order_details('.$orders_id.');" onMouseOver="do_hover_change(this,2);" onMouseOut="do_hover_change(this,3);">'.tep_image(DIR_WS_IMAGES.'template/img_edit.gif','Edit').'</td>';
		echo '<td width="10%" OnClick="javascript:do_hover_change(this,1); delete_order('.$orders_id.');" onMouseOver="do_hover_change(this,2);" onMouseOut="do_hover_change(this,3);">'.tep_image(DIR_WS_IMAGES.'template/img_trash.gif','Delete').'</td>';
		echo '<td width="10%" OnClick="javascript:do_row_close();"><a href="'.tep_href_link(FILENAME_ORDERS_INVOICE, 'oID=' . $orders_id).'" TARGET="_blank" onMouseOver="do_hover_change(this,2);" onMouseOut="do_hover_change(this,3);">'.tep_image(DIR_WS_IMAGES.'template/img_copy.gif','Invoice').'</a></td>';
		echo '<td width="10%" OnClick="javascript:do_row_close();"><a href="'.tep_href_link(FILENAME_ORDERS_PACKINGSLIP, 'oID=' . $oInfo->orders_id).'" target="_blank" onMouseOver="do_hover_change(this,2);" onMouseOut="do_hover_change(this,3);">'.tep_image(DIR_WS_IMAGES.'template/img_move.gif','Packaging Slip').'</a></td>';
		echo '<td width="10%" OnClick="javascript:do_row_close();"><a href="'.tep_href_link(FILENAME_EVENTS_TICKET, 'oID=' . $oInfo->orders_id).'" target="_blank" onMouseOver="do_hover_change(this,2);" onMouseOut="do_hover_change(this,3);">'.tep_image(DIR_WS_IMAGES.'template/img_sms.gif','Ticket').'</a></td>';
	?>
	<td class="cell_bg_popm_right" width="10">&nbsp;</td>
	</tr></table>
	</td>
	<td width="500" align="right"><?php echo '<span id="orders_operation" style="display:none;cursor:hand;cursor:pointer">'.tep_image(DIR_WS_IMAGES.'template/img_savel.gif','Save','','','onClick="javascript: delete_confirm();"').'</span>'.'&nbsp;&nbsp;<span id="orders_close_button" style="display:none;cursor:hand;cursor:pointer">'.tep_image(DIR_WS_IMAGES.'template/img_closel.gif','Close','','','onclick="javascript: display_preview();"').'</span>'; ?>&nbsp;</td>
	</tr>
	<tr class="main"><td id="span_edit" style="display:none" class="main"></td></tr>
	<tr class="main"><td id="span_delete" style="display:none" class="main"></td></tr>
	<tr>
	<td id="preview_details" colspan="3"><table width="100%" style="padding:10px;" cellpadding="2" cellspacing="2" border="0" align="center">
	<tr>
	<td class="main" width="150" valign="bottom" align="right"><?php echo TEXT_ORDERS_TOTAL; ?></td>
	<td class="main" width="150" valign="bottom"><?php echo $oInfo->order_total; ?></td>
	<td class="main" align="right" valign="bottom" width="150"><?php echo TEXT_DATE_ORDER_CREATED; ?></td>
	<td class="main" valign="bottom" width="100" align="left"><?php echo date(EVENTS_DATE_FORMAT,strtotime($oInfo->date_purchased)); ?></td>
	<td width="200" class="main" align="right" valign="bottom"><?php echo TEXT_INFO_REFERENCE_ID; ?></td>
	<td width="400" class="main" valign="bottom" align="left">&nbsp;<?php echo $oInfo->reference_id; ?></td>
	</tr>
	<tr height="30">
	<td class="main" width="150" valign="bottom" align="right"><?php echo TEXT_ORDERS_STATUS; ?></td>
	<td class="main" width="150" valign="bottom"><b><?php echo $oInfo->orders_status_name; ?></b></td>
	<td class="main" align="right" valign="bottom" width="150"><?php if(tep_not_null($oInfo->last_modified)) echo TEXT_DATE_ORDER_LAST_MODIFIED; ?></td>
	<td class="main" width="150" align="left" valign="bottom"><?php if(tep_not_null($oInfo->last_modified)) echo date(EVENTS_DATE_FORMAT,strtotime($oInfo->last_modified)); ?></td>
	<td width="200" class="main" align="right" valign="bottom"><?php echo TEXT_INFO_PAYMENT_METHOD; ?></td>
	<td width="400" class="main" style="text_align:center;" valign="bottom" align="left">&nbsp;<?php echo $orders["payment_method"]; ?></td>
	</tr>
	<?php
	/*$service_details=tep_get_service_booking_details((int)$oInfo->orders_id);
	 if($service_details){
	 $contents[] = array('text' => '<br>'.TEXT_HEADING_SERVICE);
   	 for($i=0;$i<sizeof($service_details);$i++){
	  	$contents[]=array('text'=>TEXT_OSERVICE_NAME.$service_details[$i]['products_name'].'<br>'. TEXT_OSTART_DATE.format_date($service_details[$i]['start_date']) . '<br>' . TEXT_OEND_DATE .format_date($service_details[$i]['end_date']).'<br>'.TEXT_OSTART_TIME.(($service_details[$i]['start_time'])?date('h:i A',strtotime($service_details[$i]['start_time'])):'').'<br>'.TEXT_OEND_TIME.(($service_details[$i]['end_time'])?date('h:i A',strtotime($service_details[$i]['end_time'])):'').'<br>'.(($service_details[$i]['resource_id']>0)?TEXT_ORESOURCE_NAME . $service_details[$i]['resource_name']:TEXT_OQUANTITY . ' - ' .$service_details[$i]['products_quantity']));
	   }
	  }*/
	?>
	</table></td>
	</tr>
	<tr><td id="ajax_load" style="padding:10px;" colspan="3"></td></tr>
	<tr><td colspan="3"><br></td></tr>
	</table>
	<?php 

	} 
	
	function save_edit_order_details(){
	global $HTTP_POST_VARS,$languages_id,$login_id;
	$server_date = getServerDate(true);
	 $oID = tep_db_prepare_input($HTTP_POST_VARS['oID']);
        $status = tep_db_prepare_input($HTTP_POST_VARS['status']);
        $comments = tep_db_prepare_input($HTTP_POST_VARS['comments']);
		$shipping_date = ($HTTP_POST_VARS['shipping_date'])? tep_convert_date_raw($HTTP_POST_VARS['shipping_date']) : '0000-00-00'; 
		$order_updated = false;
        $check_status_query = tep_db_query("select o.customers_name, o.customers_email_address, o.orders_status, o.date_purchased, op.orders_products_status from " . TABLE_ORDERS . " o," . TABLE_ORDERS_PRODUCTS . " op  where o.orders_id=op.orders_id and o.orders_id = '" . (int)$oID . "'");
        $check_status = tep_db_fetch_array($check_status_query);
		
// BOF: WebMakers.com Added: Downloads Controller
// always update date and time on order_status
// original        if ( ($check_status['orders_status'] != $status) || tep_not_null($comments)) {
			/*if ($status==1){
			  tep_db_query("UPDATE " . TABLE_ORDERS_PRODUCTS . " set events_type='P' where orders_id='" . tep_db_input($oID) . "' and products_type='E'");}
			else{
			  tep_db_query("UPDATE " . TABLE_ORDERS_PRODUCTS . " set events_type='R' where orders_id='" . tep_db_input($oID) . "' and products_type='E'");
			}*/
		  tep_db_query("update " . TABLE_ORDERS . " set shipping_date = '" . tep_db_input($shipping_date) . "', last_modified = '" . getServerDate(true) . "' where orders_id = '" . (int)$oID . "'");
		  
			 
			  if($check_status['orders_status'] != $status)	
	 		  {
	  			if($check_status['orders_status']==1) //if pending
				 {
		   			if($status==2 || $status==3)  // to processing or deliverd
	   		 		 tep_db_query("update " . TABLE_ORDERS . " set date_paid = '" . getServerDate(true) . "' where orders_id = '" . (int)$oID . "'");
		        }
	         }
      if ( ($check_status['orders_status'] != $status) || $comments != '' || ($status ==DOWNLOADS_ORDERS_STATUS_UPDATED_VALUE) ) {
	 // echo $check_status['orders_status'] .'gg1'. $status;
		//exit;
        tep_db_query("update " . TABLE_ORDERS . " set orders_status = '" . tep_db_input($status) . "', last_modified = '" . $server_date . "' where orders_id = '" . (int)$oID . "'");
		tep_db_query("update " . TABLE_ORDERS_PRODUCTS . " set orders_products_status= '" . tep_db_input($status) . "' where orders_id = '" . (int)$oID . "'"); 
        $check_status_query2 = tep_db_query("select customers_name, customers_email_address, orders_status, date_purchased from " . TABLE_ORDERS . " where orders_id = '" . (int)$oID . "'");
        $check_status2 = tep_db_fetch_array($check_status_query2);
      if ( $check_status2['orders_status']==DOWNLOADS_ORDERS_STATUS_UPDATED_VALUE ) {
        tep_db_query("update " . TABLE_ORDERS_PRODUCTS_DOWNLOAD . " set download_maxdays = '" . tep_get_configuration_key_value('DOWNLOAD_MAX_DAYS') . "', download_count = '" . tep_get_configuration_key_value('DOWNLOAD_MAX_COUNT') . "' where orders_id = '" . (int)$oID . "'");
      }
// EOF: WebMakers.com Added: Downloads Controller

          $customer_notified = '0';
          if (isset($HTTP_POST_VARS['notify']) && ($HTTP_POST_VARS['notify'] == 'on')) {
            $notify_comments = '';
// BOF: WebMakers.com Added: Downloads Controller - Only tell of comments if there are comments
            if (isset($HTTP_POST_VARS['notify_comments']) && ($HTTP_POST_VARS['notify_comments'] == 'on')) {
              $notify_comments = sprintf(EMAIL_TEXT_COMMENTS_UPDATE, $comments) . "\n\n";
            }
// EOF: WebMakers.com Added: Downloads Controller
           // $email = STORE_NAME . "\n" . EMAIL_SEPARATOR . "\n" . EMAIL_TEXT_ORDER_NUMBER . ' ' . $oID . "\n" . EMAIL_TEXT_INVOICE_URL . ' ' . tep_catalog_href_link(FILENAME_CATALOG_ACCOUNT_HISTORY_INFO, 'order_id=' . $oID, 'SSL') . "\n" . EMAIL_TEXT_DATE_ORDERED . ' ' . tep_date_long($check_status['date_purchased']) . "\n\n" . $notify_comments . sprintf(EMAIL_TEXT_STATUS_UPDATE, $orders_status_array[$status]);

            //tep_mail($check_status['customers_name'], $check_status['customers_email_address'], EMAIL_TEXT_SUBJECT, $email, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS);
			if($check_status['orders_status'] != $status)
				tep_send_products_status_change_email($oID, $status, '', $notify_comments);

            $customer_notified = '1';
          }
			$user_name=tep_admin_name($login_id);
          tep_db_query("insert into " . TABLE_ORDERS_STATUS_HISTORY . " (orders_id, orders_status_id, date_added, customer_notified, comments,user_added) values ('" . (int)$oID . "', '" . tep_db_input($status) . "', '" . $server_date . "', '" . tep_db_input($customer_notified) . "', '" . tep_db_input($comments)  . "','" . tep_db_input($user_name) . "')");

          $order_updated = true;
        }
	}
	
	function edit_order_details($oID){
	global $languages_id,$currencies,$HTTP_GET_VARS,$dis_time_format;
	include(DIR_WS_CLASSES . 'order.php');
	 $currencies = new currencies();

	$orders_statuses = array();
  	$orders_status_array = array();
	$orders_statuses=tep_get_orders_status();
  	$orders_status_query = tep_db_query("select orders_status_id, orders_status_name from " . TABLE_ORDERS_STATUS . " where language_id = '" . (int)$languages_id . "'");
  	while ($orders_status = tep_db_fetch_array($orders_status_query)) {
    //$orders_statuses[] = array('id' => $orders_status['orders_status_id'],
    //                           'text' => $orders_status['orders_status_name']);
    $orders_status_array[$orders_status['orders_status_id']] = $orders_status['orders_status_name'];
  	}

	?>
	<?php $today_date = getServerDate();
  //if (($action == 'edit') && ($order_exists == true)) { 
    $order = new order($oID);
?>
<?php 
 //getting order date
	$order_date = $order->info['date_purchased'];
	  $split_date = split(' ',$order_date);
	  $order_date = format_date($split_date[0]); 
	  echo tep_draw_form('status', FILENAME_ORDERS,'','post','').tep_draw_hidden_field('oID',$oID);
?>
 
	<table width="100%" cellpadding="0" cellspacing="0" border="0">
      <tr>
        <td width="100%"><table border="0" width="100%" cellspacing="0" cellpadding="0">
          <tr>
            <td class="pageHeading"><?php echo HEADING_TITLE; ?></td>
           <td class="pageHeading" align="right"><?php echo tep_draw_separator('pixel_trans.gif', 1, HEADING_IMAGE_HEIGHT); ?></td>
            <td class="pageHeading" align="right">
				<?php $return=(isset($HTTP_GET_VARS["return"])?$HTTP_GET_VARS["return"]:'');
				      $type=(isset($HTTP_GET_VARS["type"])?$HTTP_GET_VARS["type"]:'P');
					  $id=(isset($HTTP_GET_VARS["id"])?$HTTP_GET_VARS["id"]:'');
					  $dpage=(isset($HTTP_GET_VARS["dpage"])?$HTTP_GET_VARS["dpage"]:'');
					  
					if ($return!=""){
						if($return=='ser')
							$filename=tep_get_service_report_name($return);
						else if($return=='ps')
							$filename=	tep_get_report_name($return) . '&btype='.$type;
						else if($return=='sdc')
							$filename = tep_get_report_name($return) . '&id='.$id . '&page=' . $dpage;
						else 
							$filename=	tep_get_report_name($return);
							
							//echo '<a href="' . (($type=='ser')?tep_get_service_report_name($return):tep_get_report_name($return)) . '">' . tep_image_button("button_back.gif",IMAGE_BACK) . '</a>&nbsp;';
					echo '<a href="' . $filename . '&mPath=' . $HTTP_GET_VARS['mPath'] . '">' . tep_image_button("button_back.gif",IMAGE_BACK) . '</a>&nbsp;';
					} else { 
						//echo '<a href="' . tep_href_link(FILENAME_ORDERS, tep_get_all_get_params(array('action'))) . '">' . tep_image_button('button_back.gif', IMAGE_BACK) . '</a>';
					}
				?>
			</td>
<td class="pageHeading" align="right">
<?php  $multiple_attendees=false; 
	   $orders_length = count($order->products);
for($icnt=0;$icnt<$orders_length;$icnt++){
		if($order->products[$icnt]['qty']>1 && $order->products[$icnt]['products_type']=='E'){
			$multiple_attendees=true;
			break;
		}
} ?>
<?php //echo  tep_image_button('button_edit.gif', IMAGE_EDIT,' style="cursor:hand" onclick="javascript:validate_edit('. $multiple_attendees .');"') .'&nbsp;'; ?>
<?php //echo '<a href="' . tep_href_link(FILENAME_ORDERS, tep_get_all_get_params(array('action'))) . '">' . tep_image_button('button_back.gif', IMAGE_BACK) . '</a>'; ?>
</td>
          </tr>
        </table></td>
      </tr>
      <tr>
        <td><table width="100%" border="0" cellspacing="10" cellpadding="2">
          <tr>
            <td colspan="3"><?php echo tep_draw_separator();?></td>
          </tr>
          <tr>
            <td valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="2">
              <tr>
                <td class="main" valign="top"><b><?php echo ENTRY_CUSTOMER; ?></b></td>
                <td class="main"><?php echo tep_address_format($order->customer['format_id'], $order->customer, 1, '', '<br>'); ?></td>
              </tr>
              <tr>
                <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '5'); ?></td>
              </tr>
              <tr>
			 	<td class="main"><b>Order # </b></td> 
				<td class="main"><?php echo tep_db_input($oID); ?></td>
				
              </tr>
			  <tr>
				<tr>
				<td class="main"><b>Order Date & Time</b></td>
				<td class="main"><?php 
				$date_purchased=date(EVENTS_DATE_FORMAT . ' h:i:s A',strtotime($order->info['date_purchased']));
				if($dis_time_format!="") {
				if($dis_time_format=='24') {
				$date_purchased=date(EVENTS_DATE_FORMAT . ' H:i:s',strtotime($order->info['date_purchased']));
				}
				}
				echo $date_purchased; ?></td>
				</tr>
			  </tr>
         <?php if (ACCOUNT_SECOND_PHONE=='true') { ?>
		 <?php if($order->customer['second_telephone'] != ''){ ?>
              <tr>
                <td class="main"><b><?php echo ENTRY_SECOND_TELEPHONE_NUMBER; ?></b></td>
                <td class="main"><?php echo $order->customer['second_telephone']; ?></td>
              </tr>
		 <?php } ?>
         <?php } ?>
<?php
// BOF: WebMakers.com Added: Downloads Controller - Extra order info
?>
			  <?php if($order->customer['fax'] != ''){ ?>
              <tr>
                <td class="main"><b><?php echo ENTRY_MOBILE_NUMBER ; ?></b></td>
                <td class="main"><?php echo $order->customer['fax']; ?></td>
              </tr>
			  <?php } ?>
<?php
// EOF: WebMakers.com Added: Downloads Controller
?>
             
         <?php if (ACCOUNT_SECOND_EMAIL=='true') { ?>
		 <?php if($order->customer['second_email_address'] != ''){ ?>
              <tr>
                <td class="main"><b><?php echo ENTRY_SECOND_EMAIL_ADDRESS; ?></b></td>
                <td class="main"><?php echo '<a href="mailto:' . $order->customer['second_email_address'] . '"><u>' . $order->customer['second_email_address'] . '</u></a>'; ?></td>
              </tr>
		<?php } ?>
         <?php } ?>
            </table></td>
            <td valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="2">
              <tr>
                <td class="main" valign="top"><b><?php echo ENTRY_SHIPPING_ADDRESS; ?></b></td>
                <td class="main"><?php echo tep_address_format($order->delivery['format_id'], $order->delivery, 1, '', '<br>'); ?></td>
              </tr>
			  <tr>
			  	<td class="main"><b>Customer IP address</b></td> 
				<td class="main"><?php echo $_SERVER['REMOTE_ADDR']; ?></td>
			  </tr>
            </table></td>
            <td valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="2">
              <tr>
                <td class="main" valign="top"><b><?php echo ENTRY_BILLING_ADDRESS; ?></b></td>
                <td class="main"><?php echo tep_address_format($order->billing['format_id'], $order->billing, 1, '', '<br>'); ?></td>
              </tr>
			  <tr>
			  	<td class="main"><b><?php echo ENTRY_TELEPHONE_NUMBER; ?></b></td>
                <td class="main"><?php echo $order->customer['telephone']; ?></td>
			  </tr>
			   <tr>
                <td class="main"><b><?php echo ENTRY_EMAIL_ADDRESS; ?></b></td>
                <td class="main"><?php echo '<a href="mailto:' . $order->customer['email_address'] . '"><u>' . $order->customer['email_address'] . '</u></a>'; ?></td>
              </tr>
			  <tr>
			  
			  </tr>
            </table></td>
          </tr>
        </table></td>
      </tr>
      <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
      </tr>
      <tr>
        <td><table border="0" cellspacing="0" cellpadding="2">
<?php
// BOF: WebMakers.com Added: Show Order Info
?>

<!-- add Order # // -->
<!-- add date/time // -->

<?php
// EOF: WebMakers.com Added: Show Order Info

?>
          <tr>
            <td class="main"><b><?php echo ENTRY_PAYMENT_METHOD; ?></b></td>
            <td class="main"><?php echo $order->info['payment_method']; ?></td>
          </tr>
		  
<?php
    if (tep_not_null($order->info['cc_type']) || tep_not_null($order->info['cc_owner']) || tep_not_null($order->info['cc_number'])) {
?>
          <tr>
            <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
          </tr>
          <tr>
            <td class="main"><?php echo ENTRY_CREDIT_CARD_TYPE; ?></td>
            <td class="main"><?php echo $order->info['cc_type']; ?></td>
          </tr>
          <tr>
            <td class="main"><?php echo ENTRY_CREDIT_CARD_OWNER; ?></td>
            <td class="main"><?php echo $order->info['cc_owner']; ?></td>
          </tr>
          <tr>
            <td class="main"><?php echo ENTRY_CREDIT_CARD_NUMBER; ?></td>
            <td class="main"><?php echo $order->info['cc_number']; ?></td>
          </tr>
          <tr>
            <td class="main"><?php echo ENTRY_CREDIT_CARD_EXPIRES; ?></td>
            <td class="main"><?php echo $order->info['cc_expires']; ?></td>
          </tr>
<?php
    }
?>
        </table></td>
      </tr>
      <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
      </tr>
    <?php /*  <tr>
        <td>
		<table border="0" width="100%" cellspacing="0" cellpadding="2">
          <tr class="dataTableHeadingRow">
            <td class="dataTableHeadingContent" colspan="2"><?php echo TABLE_HEADING_PRODUCTS; ?></td>
            <td class="dataTableHeadingContent"><?php echo TABLE_HEADING_PRODUCTS_MODEL; ?></td>
            <td class="dataTableHeadingContent"><?php echo TABLE_HEADING_PRODUCTS_SKU; ?></td>
            <td class="dataTableHeadingContent" align="right"><?php echo TABLE_HEADING_TAX; ?></td>
            <td class="dataTableHeadingContent" align="right"><?php echo TABLE_HEADING_PRICE_EXCLUDING_TAX; ?></td>
            <td class="dataTableHeadingContent" align="right"><?php echo TABLE_HEADING_PRICE_INCLUDING_TAX; ?></td>
            <td class="dataTableHeadingContent" align="right"><?php echo TABLE_HEADING_TOTAL_EXCLUDING_TAX; ?></td>
            <td class="dataTableHeadingContent" align="right"><?php echo TABLE_HEADING_TOTAL_INCLUDING_TAX; ?></td>
          </tr> */?>
		  <tr>
        		<td>
				<table border="0" width="100%" cellspacing="0" cellpadding="2" style="border:solid 1px #CCCCCC; background:#E6E6E6">
<?php
	$flagp=0;$flage=0;$flagev=0;$flags=0;$flagt=0;
    for ($i=0, $n=sizeof($order->products); $i<$n; $i++) {
		$products_model=$order->products[$i]['model'];
		//if ($order->products[$i]['products_type']=='E') $products_model=format_date($products_model);
		if(($order->products[$i]['products_type']=='P') && ($flagp==0)) {
		?>
			
		          <tr>
        		    <td class="dataTableHeadingContent" colspan="2"><?php echo TABLE_HEADING_PRODUCTS; ?></td>
		            <td class="dataTableHeadingContent"><?php echo TABLE_HEADING_PRODUCTS_MODEL; ?></td>
        		    <td class="dataTableHeadingContent"><?php echo TABLE_HEADING_PRODUCTS_SKU; ?></td>
            		<?php
				  $flagp=1;
								
		}
		if(($order->products[$i]['products_type']=='E') && ($flage==0)) {
		?>
			
		          <tr>
        		    <td class="dataTableHeadingContent" colspan="2"><?php echo TABLE_HEADING_EVENTS; ?></td>
		            <td class="dataTableHeadingContent"><?php echo TABLE_HEADING_EVENTS_SESSIONS;?></td>
        		    <td class="dataTableHeadingContent"></td>
            		<?php
				  $flage=1;
								
		}
		if(($order->products[$i]['products_type']=='S') && ($flags==0)) {
		?>
			
		          <tr>
        		    <td class="dataTableHeadingContent" colspan="2"><?php echo TABLE_HEADING_SUBSCRIPTIONS; ?></td>
		            <td class="dataTableHeadingContent"><?php echo TABLE_HEADING_SUBSCRIPTIONS_TYPE;?></td>
        		    <td class="dataTableHeadingContent"></td>
		            <?php
				  $flags=1;
								
		}
		if(($order->products[$i]['products_type']=='V') && ($flagv==0)) {
		?>
			
		          <tr>
        		    <td class="dataTableHeadingContent" colspan="2"><?php echo TABLE_HEADING_SERVICES; ?></td>
		            <td class="dataTableHeadingContent"><?php echo TABLE_HEADING_SERVICES_RESOURCES; ?></td>
        		    <td class="dataTableHeadingContent"></td>
            		<?php
				  $flagv=1;
								
		}
		if($flagt==0)
		{?>
		
			<td class="dataTableHeadingContent" align="right"><?php echo TABLE_HEADING_TAX; ?></td>
		            <td class="dataTableHeadingContent" align="right"><?php echo TABLE_HEADING_PRICE_EXCLUDING_TAX; ?></td>
        		    <td class="dataTableHeadingContent" align="right"><?php echo TABLE_HEADING_PRICE_INCLUDING_TAX; ?></td>
		            <td class="dataTableHeadingContent" align="right"><?php echo TABLE_HEADING_TOTAL_EXCLUDING_TAX; ?></td>
        		    <td class="dataTableHeadingContent" align="right"><?php echo TABLE_HEADING_TOTAL_INCLUDING_TAX; ?></td>
		        
				  
		<?php $flagt=1;
		}
      echo '            </tr><tr class="dataTableRow">' . "\n" .
           '            <td class="dataTableContent" valign="top" align="right">' . $order->products[$i]['qty'] . '&nbsp;x</td>' . "\n" .
           '            <td class="dataTableContent" valign="top">' . $order->products[$i]['name'];
     
       // for displaying time and resource name
      if (isset($order->products[$i]['others']) && (sizeof($order->products[$i]['others']) > 0)) {
		// for ($jcnt = 0, $k = sizeof($order->products[$i]['others']); $jcnt < $k; $jcnt++) {
		 		$disp_date=$order->products[$i]['others']['end_date'];
		 		$disp_time=$order->products[$i]['others']['end_time'];
				if($disp_date && $disp_time){
					$date_time=strtotime($disp_date.' '.$disp_time)+60;
					$disp_date=date('Y-m-d',$date_time); 
					$disp_time=date('h:i A',$date_time);					
				}	
				$stime="";
				$etime="";
				if($order->products[$i]['others']['start_time']) {
					$stime=date("h:i A",strtotime($order->products[$i]['others']['start_time']));
					if($dis_time_format!="") {
						if($dis_time_format=='24') 
						$stime=date("H:i",strtotime($order->products[$i]['others']['start_time']));
					}
				}
				if($order->products[$i]['others']['end_time']) {
					//$etime=date("h:i A",strtotime($order->products[$i]['others']['end_time'])+60);
					if($dis_time_format!="") {
						if($dis_time_format=='24') $disp_time=date('H:i',$date_time);													
					}
				}
				$disp_date_time=format_date($disp_date).'&nbsp;&nbsp;'.$disp_time;
             echo '<br><nobr><small>&nbsp;<i> -  Start Date: ' . format_date($order->products[$i]['others']['start_date']) . '&nbsp; ' .$stime  .  '<br><nobr>&nbsp; -' . ' End Date: ' . $disp_date_time . '&nbsp;';
             echo '</i></small></nobr>';
			//} 
      }
      if (isset($order->products[$i]['attributes']) && (sizeof($order->products[$i]['attributes']) > 0)) {
        for ($j = 0, $k = sizeof($order->products[$i]['attributes']); $j < $k; $j++) {
          if($order->products[$i]['attributes'][$j]['option'] && $order->products[$i]['attributes'][$j]['value']) echo '<br><nobr><small>&nbsp;<i> - ' . $order->products[$i]['attributes'][$j]['option'] . ': ' . $order->products[$i]['attributes'][$j]['value'];
          if ($order->products[$i]['attributes'][$j]['price'] != '0') 		  echo ' (' . $order->products[$i]['attributes'][$j]['prefix'] . $currencies->format(tep_add_tax($order->products[$i]['attributes'][$j]['price'],$order->products[$i]['tax']) * $order->products[$i]['qty'], true, $order->info['currency'], $order->info['currency_value']) . ')';
          echo '</i></small></nobr>';
        }
      // }
      }
	  //Support Packs
	 
	  if($order->products[$i]['products_type']=='P') {
	  	$packs_query=tep_db_query("select opsp.* from " . TABLE_ORDERS_PRODUCTS_SUPPORT_PACKS . " opsp where opsp.orders_id='" . tep_db_input($oID) . "' and opsp.products_id='" . tep_db_input($order->products[$i]['id']) . "'");
	
		if(tep_db_num_rows($packs_query)>0){
			while($packs_result=tep_db_fetch_array($packs_query)){
				echo '<br><nobr><small>&nbsp;<i>- ' . $packs_result['support_minutes'] . ' minutes ' . $packs_result['subscription_name'] . ' for ' . $packs_result['no_users'] . ' users</i></small></nobr>';
			}
	  	}
	  }
	  //Support Packs
	  
	  // Products with Quantity   - Model  - SKU  - Tax  - Price  - Price (Include Tax)  - Total  - Total (Include Tax)
	  //echo $products_id;
	  
  	  $discount=(isset($order->products[$i]['discount_whole_text']) && $order->products[$i]['discount_whole_text']!='')?'<br>' . $order->products[$i]['discount_whole_text']:'';	  
	  echo $discount;
	   if($order->products[$i]['products_type']=='V') 
	  		echo'</td><td class"dataTableContent" valign="top">'.(($order->products[$i]['others']['resource_name'])?' ' . $order->products[$i]['others']['resource_name']:'').'</td>';
	  	else{
			echo  '</td><td class="dataTableContent" valign="top">' . (($order->products[$i]['products_type']=='E')?format_date($products_model):$products_model) . '</td>' ;
			}
					   
			 $table_content = '<td class="dataTableContent" valign="top">' . (($order->products[$i]['products_type']=='P')?$order->products[$i]['products_sku']:'') . '</td>'. "\n" .    
					  					   
					   '<td class="dataTableContent" align="right" valign="top">' . tep_display_tax_value($order->products[$i]['tax']) . '%</td>' . "\n" .
					   '<td class="dataTableContent" align="right" valign="top"><b>' . $currencies->format($order->products[$i]['final_price'], true, $order->info['currency'], $order->info['currency_value']) . '</b></td>' . "\n" .
					   '<td class="dataTableContent" align="right" valign="top"><b>' . $currencies->format(tep_add_tax($order->products[$i]['final_price'], $order->products[$i]['tax']), true, $order->info['currency'], $order->info['currency_value']) . '</b></td>' . "\n";
	  $table_content .= '<td class="dataTableContent" align="right" valign="top"><b>' . $currencies->format($order->products[$i]['final_price'] * $order->products[$i]['qty'] , true, $order->info['currency'], $order->info['currency_value']) . '</b></td>' . "\n";
      $table_content .= '<td class="dataTableContent" align="right" valign="top"><b>' . $currencies->format(tep_add_tax($order->products[$i]['final_price'], $order->products[$i]['tax']) * $order->products[$i]['qty'], true, $order->info['currency'], $order->info['currency_value']) . '</b></td>' . "\n";
		  // '			<td class="dataTableContent" align="right" valign="top"><b>' . $currencies->format($order->products[$i]["amount_received"]). '<b></td>' . "\n".
		//   '			<td class="dataTableContent" align="right" valign="top"><b>' . $currencies->format($order->products[$i]["tax_received"]) . '<b></td>' . "\n";
      $table_content .= '</tr>' . "\n";
	  echo $table_content;
	  $attendees_name="";
	  if($order->products[$i]['qty']>1 && $order->products[$i]['products_type']=='E'){
	  	
	  	//echo "select customers_firstname,customers_lastname from ".TABLE_CUSTOMERS ." c, ".TABLE_CUSTOMERS_TO_CUSTOMERS ." ctc where ctc.customer_id=c.customers_id and ctc.orders_id='".(int)$oID."' and c.customers_id!='".$order->customer['id']."'"; 
		//echo "select  customers_firstname,customers_lastname from ".TABLE_CUSTOMERS ." c, ".TABLE_CUSTOMERS_TO_CUSTOMERS ." ctc where ctc.customer_id=c.customers_id and ctc.orders_id='".(int)$oID."'"; 
		$attendee_query=tep_db_query("select distinct customers_firstname,customers_lastname from ".TABLE_CUSTOMERS ." c, ".TABLE_CUSTOMERS_TO_CUSTOMERS ." ctc where ctc.customer_id=c.customers_id and ctc.orders_id='".(int)$oID."'");
		while($attendee_result=tep_db_fetch_array($attendee_query)){
			$attendees_name.=$attendee_result['customers_firstname'].' '.$attendee_result['customers_lastname'].',';
		}
		if ($attendees_name!=""){
				//$start_name=strpos($attendees_name,',',1);
				//$attendees_name=substr($attendees_name,$start_name+1,-1);
			    $attendees_name=substr($attendees_name,0,-1);
		}
		echo '<tr class="dataTableRow">'. "\n".
					'<td class="dataTableContent">&nbsp;</td>'.
					'<td colspan="9" class="dataTableContent" align="left" valign="top"><b>' . TEXT_ATTENDEES ."</b></td>".
			 '</tr>';	
		echo '<tr class="dataTableRow">'. "\n".
					'<td class="dataTableContent">&nbsp;</td>'.
					'<td colspan="9" class="dataTableContent" align="left" valign="top">&nbsp;&nbsp;-' . $attendees_name ."</td>".
			 '</tr>';		
	  }
	  
	  /* applying discount,orginal price,discount price */
	 //echo ' <tr><td><table border="0" cellspacing="0" cellpadding="2"><tr><td class="smallText">'. get_discount_details($oID,$order->products[$i]['id']) .'</td></tr></table></td></tr>';

	  
	/*  $prd=$order->products[$i];
	  $pending_amount=((($prd['final_price']+$prd['tax_actual'])*$prd['qty'])-($prd['coupon_amount']+$prd['amount_received']+$prd['tax_received']));
	  $total_pending_amount+=$pending_amount; */
    }
?>

          <tr bgcolor="#EDF1FE">
            <td align="right" colspan="10"><table border="0" cellspacing="0" cellpadding="2">
<?php
 //print_r($order->totals);
    for ($i = 0, $n = sizeof($order->totals); $i < $n; $i++) {
      echo '              <tr>' . "\n" .
           '                <td align="right" class="smallText">' . $order->totals[$i]['title'] . '</td>' . "\n" .
           '                <td align="right" class="smallText">' . $order->totals[$i]['text'] . '</td>' . "\n" .
           '              </tr>' . "\n";
    }
	
?>
            </table></td>
          </tr>
        </table></td>
      </tr>
      <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
      </tr>
      <tr><td class="main"><table width="100%" border="0" cellspacing="0" cellpadding="2">
	<tr bgcolor=white>
	   <td class="main"><?php echo '<b>' . TEXT_CURRENT_STATUS . '</b>' ;?></td></tr>
	<tr><td><?php echo tep_draw_separator('pixel_trans.gif', '1', '3'); ?></td></tr>
        <tr>
        <td class="main"><table border="0" cellspacing="0" cellpadding="3" class="infoBox">
          <tr class="infoBoxContent">
            <td class="smallText" align="center"><b><?php echo TABLE_HEADING_DATE_ADDED; ?></b></td>
            <td class="smallText" align="center"><b><?php echo TABLE_HEADING_CUSTOMER_NOTIFIED; ?></b></td>
            <td class="smallText" align="center"><b><?php echo TABLE_HEADING_STATUS; ?></b></td>
            <td width="518" class="smallText" align="center"><b><?php echo TABLE_HEADING_COMMENTS; ?></b></td>
			<td class="smallText" align="center"><b><?php echo TABLE_HEADING_USER_ADDED; ?></b></td>
          </tr>
<?php
	
    $orders_history_query = tep_db_query("select orders_status_id, date_added, customer_notified, comments,user_added from " . TABLE_ORDERS_STATUS_HISTORY . " where orders_id = '" . (int)$oID . "' order by date_added");
    if (tep_db_num_rows($orders_history_query)) {
      while ($orders_history = tep_db_fetch_array($orders_history_query)) {
	  $date_added_text=date(EVENTS_DATE_FORMAT . ' h:i:s A',strtotime($orders_history['date_added']));
	  if($dis_time_format!="") {
		if($dis_time_format=='24')
			 $date_added_text=date(EVENTS_DATE_FORMAT . ' H:i',strtotime($orders_history['date_added']));
		}	
        echo '          <tr>' . "\n" .
             '            <td class="smallText" align="center">' . $date_added_text . '</td>' . "\n" .
             '            <td class="smallText" align="center">';
        if ($orders_history['customer_notified'] == '1') {
          echo tep_image(DIR_WS_ICONS . 'tick.gif', ICON_TICK) . "</td>\n";
        } else {
          echo tep_image(DIR_WS_ICONS . 'cross.gif', ICON_CROSS) . "</td>\n";
        }
				$comments='';  
						if($orders_status_array[$orders_history['orders_status_id']] == TEXT_DELIVERED) {
								$comments = 'Shipping On :' . format_date($order->info['shipping_date']);
						}	

        echo '            <td class="smallText">' . $orders_status_array[$orders_history['orders_status_id']] . '</td>' . "\n" .
         	 '            <td class="smallText" align="center">' . $orders_history['comments'] . '&nbsp;' . $comments . '</td>' . "\n" .
			 '            <td class="smallText">' . $orders_history['user_added'] . '&nbsp;</td>' . "\n" .
             '          </tr>' . "\n";
      }
    } else {
        echo '          <tr>' . "\n" .
             '            <td class="smallText" colspan="5">' . TEXT_NO_ORDER_HISTORY . '</td>' . "\n" .
             '          </tr>' . "\n";
    }
?>
        </table></td>
      </tr>
      <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '1', '3'); ?></td>
      </tr>
      <tr bgcolor=white>
	<td class="main"><b><?php echo TEXT_MODIFY_STATUS; ?></b></td>
      </tr>
      <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '1', '3'); ?></td>
      </tr>
      <tr>
	  <?php
	  			$current_date=getServerDate();
				$ship_date="";
	  			if(tep_not_null($order->info['shipping_date'])) {
					$ship_date=format_date($order->info['shipping_date']);
				}	
	  ?>
        <td><table border="0" cellspacing="0" cellpadding="2">
		<?php
			$orders_status_load = array();
			$orders_status_query = tep_db_query("select orders_status_id, orders_status_name from " . TABLE_ORDERS_STATUS . " where language_id = '" . (int)$languages_id . "' and lower(orders_status_name)!='refunded' order by orders_status_id");
			while ($orders_status = tep_db_fetch_array($orders_status_query)) {
			if($orders_status['orders_status_id'] >= $order->info['orders_status']){
			$orders_status_load[] = array('id' => $orders_status['orders_status_id'],
			'text' => $orders_status['orders_status_name']);
			}
			}
		 $_array=array('d','m','Y');  $replace_array=array('DD','MM','YYYY'); 	$date_format=str_replace($_array,$replace_array,EVENTS_DATE_FORMAT);?>
              <tr><td class="main"><b><?php echo ENTRY_STATUS; ?></b><td width="200"><?php 
			  	if($order->info['orders_status']=='5')
					echo '<font class="main">Refunded</font>';
				else if($order->info['orders_status']=='4')	
				echo '<font class="main">Backorder</font>';
				else	
				  echo tep_draw_pull_down_menu('status', $orders_status_load, $order->info['orders_status'],'onchange="javascript:void change_status(\'1\');"'); ?></td>
				<td class="main"><b><?php echo ENTRY_NOTIFY_CUSTOMER; ?></b><td width="200"><?php echo tep_draw_checkbox_field('notify', '', true); ?></td>
              	<td class="main"><b><?php echo ENTRY_NOTIFY_COMMENTS; ?></b><td><?php echo tep_draw_checkbox_field('notify_comments', '', true); ?></td>
				  
				</tr>
			<!--  <tr id="refunded" style="display:none;">
			  		<td class="main"><?php /*echo  tep_draw_radio_field('refund','F',true,'','onclick="javascript:do_check_fund()"').'&nbsp;'.TEXT_FULL_REFUND;?></td>
			  		<td class="main"><?php echo tep_draw_radio_field('refund','P','','','onclick="javascript:do_check_fund()"').'&nbsp;'.TEXT_PARTIAL_REFUND;?></td>
			  </tr>
			  <tr id="partial_refund" style="display:none;">
			  	<td class="main"><?php echo  tep_draw_radio_field('r_amount_type','A',true).'&nbsp;'.TEXT_AMOUNT.'&nbsp;'.tep_draw_radio_field('r_amount_type','P').'&nbsp;'.TEXT_PERCENT;?></td>
			  	<td class="main"><?php echo tep_draw_input_field('r_amount','','size=10');*/?></td>
			  </tr>-->
			  <tr id='shipping' style="display:none;">
			  		<td class="main"><b><?php echo ENTRY_SHIPPING_DATE; ?></b><br><small>(<?php echo $date_format; ?>)</small></td>
					<td><?php  echo tep_draw_input_field("shipping_date",(tep_not_null($ship_date)?$ship_date:format_date($current_date)),"size=10",false,'text',false);  ?>
					<a href="javascript:show_calendar('status.shipping_date',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>
					</td></tr>
                 </table>
      </tr>
	      
	      <tr>
		<td class="main" align="right" colspan="2"><?php echo tep_draw_textarea_field('comments', 'soft', '60', '5'); ?></td>
	      </tr>
      <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '1', '3'); ?></td>
      </tr>
      <tr><td><table width="100%" cellpadding="0" cellspacing="0" border="0">
	  <tr>
	  <td width="320">&nbsp;</td>
	  <td align="right">
	  <?php //echo tep_image_submit('button_update.gif', IMAGE_UPDATE);  
	  if($order->info['orders_status']!='5')
	  		  echo '<a href="javascript: formValidate();">'.tep_image_button('button_update.gif' ,'Update','','').'</a>&nbsp;<span id="update_ajax_load"></span>';
	  ?>
	  </td></tr></table></td></tr>
      </table></td>
	   <script>change_status('2'); </script>
      </tr>
           <tr> 
        <td colspan="2" align="left">
			<?php 
			echo '<a href="'.tep_href_link(FILENAME_CREATE_ORDER_NEW,'oID='.$oID.'&cID='.$order->customer['id']).'">'.tep_image_button('button_edit.gif','Edit').'</a>';
			echo '&nbsp;<a href="javascript:popupWindow(\'' .  (HTTP_SERVER . DIR_WS_ADMIN . FILENAME_ORDERS_INVOICE) . '?' . (tep_get_all_get_params(array('oID')) . 'oID=' . $oID) . '\')">' . tep_image_button('button_invoices.gif', IMAGE_ORDERS_INVOICE) . '</a>&nbsp;<a href="javascript:popupWindow(\'' .  (HTTP_SERVER . DIR_WS_ADMIN . FILENAME_ORDERS_PACKINGSLIP) . '?' . (tep_get_all_get_params(array('oID')) . 'oID=' . $oID) . '\')">' . tep_image_button('button_packing_slips.gif', IMAGE_ORDERS_PACKINGSLIP) . '</a>';
			echo '&nbsp;<a href="' . tep_href_link(FILENAME_EVENTS_TICKET,'oID=' . $oID) . '" target="_blank">' . tep_image_button('button_ticket.gif',IMAGE_TICKET) . '</a>&nbsp'; 
			?>
		</td>
     </tr> 

	</table>
	</form>
	<?php
	//} 
	?>
	<?php 	echo '^^'.$order_date.'^^'.$oID.'^^'; 
	$orders_query_raw = "select o.orders_id, o.payment_return1,o.orders_status, o.payment_return2, o.reference_id, op.products_quantity,concat(LTRIM(c.customers_lastname),' ',LTRIM(c.customers_firstname)) as customers_name, o.payment_method, o.date_purchased, o.last_modified, o.currency, o.currency_value, s.orders_status_name, op.products_type, ot.text as order_total from " . TABLE_ORDERS . " o left join " . TABLE_ORDERS_TOTAL . " ot on (o.orders_id = ot.orders_id), " . TABLE_ORDERS_STATUS . " s, " .TABLE_ORDERS_PRODUCTS." op, ".TABLE_CUSTOMERS ." c where o.customers_id=c.customers_id and o.orders_status = s.orders_status_id and o.orders_id=op.orders_id and s.language_id = '" . (int)$languages_id . "' and ot.class = 'ot_total' and o.orders_id='$oID' group by o.orders_id order by o.orders_id DESC,customers_name ASC";
	$orders_query=tep_db_query($orders_query_raw);
	$orders=tep_db_fetch_array($orders_query);
	?>
	<table height="20px;" width="100%" cellpadding="0" cellspacing="0" border="0">
	<tr>
    <td width="25%" class="main">&nbsp;<?php echo tep_image(DIR_WS_IMAGES.'template/icon_active.gif') . '&nbsp;' . $orders['customers_name']; ?></td>
    <td width="25%" class="main" align="right"><?php echo strip_tags($orders['order_total']); ?></td>
    <td width="25%" class="main" align="center"><?php echo date(EVENTS_DATE_FORMAT,strtotime($orders['date_purchased'])); ?></td>
    <td width="25%" class="main" align="right"><?php echo $orders['orders_status_name']; ?></td>
	</tr>
	</table>
	<?php
	echo '^^'.$orders['orders_status'];
	}
	?>
<!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" src="includes/menu.js"></script>
<script language="javascript" src="includes/general.js"></script>
<script language="JavaScript" src="includes/date-picker.js"></script>
<script language="javascript" src="includes/http.js"></script>
<script language="javascript"><!--
function popupWindow(url) {
  window.open(url,'popupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,width=650,height=500,screenX=150,screenY=150,top=150,left=150')
}
var img_src="<?php echo HTTP_SERVER.DIR_WS_ADMIN.'images/';?>";
var ajax_image_load='<?php echo tep_image(DIR_WS_IMAGES.'24-1.gif'); ?>',previous_orders_id='';
var row_expand=false;
	function orders_page_navigation(arg1,agr2,agr3,agr4){
	var page_no=1;
	if(agr2==1) var obj=document.getElementById("page_1");
		else if(agr2==2) var obj=document.getElementById("page_2");
		if(agr2 && agr4){
			if(obj){
 	 			page_no=parseInt(obj.options[obj.selectedIndex].value);
 	 			if(agr4=='next') {
 	 				if(obj.length==obj.selectedIndex+1) return;
 	 				page_no+=1;
 	 			}else if(agr4=='prev') {
	 	 			if(obj.selectedIndex==0) return;
 		 			page_no-=1;
 	 			}
 	 			if(page_no<=1) page_no=1;
 	 		} 	 		
	}		
		var status="";
		if(document.getElementById("status") && document.getElementById("status").options[document.getElementById("status").selectedIndex].value>0) status="&status="+document.getElementById("status").options[document.getElementById("status").selectedIndex].value; 		
		if(agr2==1) command="<?php echo tep_href_link(FILENAME_ORDERS,'command=orders_page_navigation&orders_page='); ?>"+page_no+status;
		else if(agr2==2) command="<?php echo tep_href_link(FILENAME_ORDERS,'command=orders_page_navigation&orders_page='); ?>"+page_no+status;

		if(command!="") do_get_command(command);
	document.getElementById('load_orders').innerHTML=ajax_image_load;
	}
	function load_orders_details(orders_id){
	if(document.getElementById('ajax_orders_'+orders_id)){
	document.getElementById('ajax_orders_'+orders_id).style.display='';
	document.getElementById('ajax_orders_'+orders_id).innerHTML=ajax_image_load;
	do_get_command('<?php echo tep_href_link(FILENAME_ORDERS,'command=load_orders_details&orders_id='); ?>'+orders_id);
		if(previous_orders_id!=''&&previous_orders_id!=orders_id)
			close_orders_details(previous_orders_id);
	
	previous_orders_id=orders_id;
	}
	}
	function close_orders_details(orders_id){
		if(document.getElementById('ajax_orders_'+orders_id) && document.getElementById('orders_'+orders_id)){
		document.getElementById('ajax_orders_'+orders_id).innerHTML='';
		document.getElementById('ajax_orders_'+orders_id).style.display='none';
		document.getElementById('orders_'+orders_id).style.display='';
		previous_orders_id='';
		}
	}
	function edit_order_details(orders_id){
	close_all_orders_panel(); 
	row_expand=true;
	if(expand_orders)
		row_expand=false;
	document.getElementById('span_edit').style.display="";
	document.getElementById('span_delete').style.display="none";
	document.getElementById('ajax_load').innerHTML=ajax_image_load;
	do_get_command('<?php echo tep_href_link(FILENAME_ORDERS,'command=edit_order_details&orders_id='); ?>'+orders_id);
	}
	function close_all_orders_panel(){
	if(document.getElementById('preview_details')) document.getElementById('preview_details').style.display='none';
	if(document.getElementById('orders_close_button')) document.getElementById('orders_close_button').style.display='none';
	}
	function display_preview(){
	row_expand=true;
	document.getElementById('ajax_load').innerHTML='';
	document.getElementById('preview_details').style.display='';
	document.getElementById('orders_operation').style.display='none';
	document.getElementById('orders_close_button').style.display='none';
	var span_edit=document.getElementById("span_edit");				
	var span_delete=document.getElementById("span_delete");
	var img_save = document.getElementById('img_save');
	
	if(span_edit.style.display=="") span_edit.style.display="none";
	if(span_delete.style.display=="") span_delete.style.display="none"; 	 			   	  	 	 			   	  	
	if(img_save) img_save.style.display="none"; 
	
	var tr1=document.getElementById("img_ids");
	var imgsrc;
	var node;
	if(tr1)
	for(var j=0;j<tr1.cells.length;j++){
		td=tr1.cells[j];
		imgsrc='';
		for(var i=0;i<td.childNodes.length;i++){
			node=td.childNodes[i];
			if(node.tagName=='IMG'){
				imgsrc=node.src;
				if(imgsrc==img_src+'template/img_edit_hover.gif')
				   td.childNodes[i].src = img_src+'template/img_edit.gif';
				else if(imgsrc==img_src+'template/img_trash_hover.gif')
				   td.childNodes[i].src = img_src+'template/img_trash.gif';
				break;
			}
		}
	 }			 
  }
  function delete_order(orders_id){
  	row_expand=true;
	document.getElementById('span_edit').style.display="none";
	document.getElementById('span_delete').style.display="";
	document.getElementById('preview_details').style.display='none';
	document.getElementById('ajax_load').innerHTML=ajax_image_load;
	do_get_command('<?php echo tep_href_link(FILENAME_ORDERS,'command=delete_order&orders_id='); ?>'+orders_id);
	}
	function delete_confirm(){row_expand=true;
	document.getElementById('span_edit').style.display="none";
	document.getElementById('span_delete').style.display="";
	do_post_command('delete_orders_form','<?php echo tep_href_link(FILENAME_ORDERS,'command=delete_confirm'); ?>');
	document.getElementById('ajax_load').innerHTML=ajax_image_load;
	}
var order_date;
	function do_result(result){ 
	var token=result.split('^^');
		switch(token[0]){
		case 'orders_page_navigation':
			document.getElementById('load_orders').innerHTML=token[1];
			break;
		case 'load_orders_details': 
			row_expand=false;
			document.getElementById('orders_'+token[1]).style.display='none';
			document.getElementById('ajax_orders_'+token[1]).innerHTML=token[2];
				if(expand_orders==true)
					edit_order_details(token[1]);
				expand_orders=false;
				if(typeof(token[3])!='undefined'){
					if(document.getElementById('preview_details'))document.getElementById('preview_details').style.display='none';
					do_get_command('<?php echo tep_href_link(FILENAME_ORDERS,'command=edit_order_details&orders_id='); ?>'+token[1]+'<?php echo '&return=';?>'+token[3]+'<?php echo '&type=';?>'+token[4]+'<?php echo '&id=';?>'+token[5]+'<?php echo '&dpage=';?>'+token[6]+'<?php echo '&mPath=';?>'+token[7]);
				}
			break;
		case 'edit_order_details':
			document.getElementById('ajax_load').innerHTML=token[2];
			order_date=token[3];
			document.getElementById('orders_'+token[4]).innerHTML=token[5];
			document.getElementById('orders_close_button').style.display='';
				if(token[6]=='<?php echo TEXT_DELIVERED_ID; ?>')
					changing_status();
			document.getElementById('span_edit').style.display="";
			document.getElementById('span_delete').style.display="none";
			if(document.getElementById('display_count'))  document.getElementById('display_count').style.display='none';
			expand_orders=false;
			break;
		case 'delete_order':
			if(token[2]=='error'){
				document.getElementById('ajax_load').innerHTML=token[3];
				document.getElementById('orders_operation').style.display='none';
				//document.getElementById('orders_operation').href="javascript: delete_confirm();";
			} else {
				document.getElementById('ajax_load').innerHTML=token[2];
				document.getElementById('orders_operation').style.display='';
				//document.getElementById('orders_operation').href="javascript: delete_confirm();";
			}
			document.getElementById('orders_close_button').style.display='';
			document.getElementById('span_edit').style.display="none";
			document.getElementById('span_delete').style.display="";
			break;
		case 'load_orders':
			document.getElementById('load_orders').innerHTML=token[1];
			break;
		case 'order_search':
			document.getElementById('load_orders').innerHTML=token[1];
			if(document.getElementById('display_count'))  document.getElementById('display_count').style.display='none';
			load_orders_details(token[2]);
			break;
		}
	}

	 function do_hover_change(element,eve){ 
		 var span_edit=document.getElementById("span_edit");
		 var span_delete=document.getElementById("span_delete");		 
	  	 if(element){		   		    		    
		    var img_get_src=element.childNodes[0];
			if(img_get_src){
			    if(img_get_src.src==img_src+'template/img_edit.gif') {
					if(span_edit && span_edit.style.display=="" && eve==1 || eve==2){
					 	img_get_src.src=img_src+'template/img_edit_hover.gif';
					}  		   		 	 			 	 			
			    }else if(eve==3 && img_get_src.src==img_src+'template/img_edit_hover.gif' && span_edit && span_edit.style.display=="none") img_get_src.src=img_src+'template/img_edit.gif';
			    if(img_get_src.src==img_src+'template/img_trash.gif') {
					if(span_delete && span_delete.style.display=="" && eve==1 || eve==2){
					 	img_get_src.src=img_src+'template/img_trash_hover.gif';
					}  		   		 	 			 	 			
			    }else if(eve==3 && img_get_src.src==img_src+'template/img_trash_hover.gif' && span_delete && span_delete.style.display=="none") img_get_src.src=img_src+'template/img_trash.gif';
			    if(img_get_src.src==img_src+'template/img_move.gif') {
					if(eve==1 || eve==2){
					 	img_get_src.src=img_src+'template/img_move_hover.gif';
					}  		   		 	 			 	 			
			    }else if(eve==3 && img_get_src.src==img_src+'template/img_move_hover.gif') img_get_src.src=img_src+'template/img_move.gif';
			    if(img_get_src.src==img_src+'template/img_copy.gif') {
					if(eve==1 || eve==2){
					 	img_get_src.src=img_src+'template/img_copy_hover.gif';
					}  		   		 	 			 	 			
			    }else if(eve==3 && img_get_src.src==img_src+'template/img_copy_hover.gif') img_get_src.src=img_src+'template/img_copy.gif';
			    if(img_get_src.src==img_src+'template/img_sms.gif') {
					if(eve==1 || eve==2){
					 	img_get_src.src=img_src+'template/img_sms_hover.gif';
					}  		   		 	 			 	 			
			    }else if(eve==3 && img_get_src.src==img_src+'template/img_sms_hover.gif') img_get_src.src=img_src+'template/img_sms.gif';
		  }
		 }		 
	 }  	
	 
	 function do_refund(ids,status){
	 	row_expand=true;
	 	if(status=='5')
			alert('Order Amount already Refunded');
		else {	
		 	if(ids) location.href="<?php echo tep_href_link(FILENAME_ORDERS_REFUND,'preturn=co' ); ?>"+ '&oID=' + ids + '&page=' + page;	 
		}	
	 }
//--></script>
	<script language="javascript">
function validate_edit(val){
 if(val){
   alert("<?php echo ERROR_ATTENDEES;?>");
   return;
 }else {
   location.href="<?php echo tep_href_link(FILENAME_EDIT_ORDERS, tep_get_all_get_params(array('action')));?>";
 }
}

/*function do_check_fund(){
	var refund=document.status.elements["refund"];
	var partial_refund=document.getElementById("partial_refund");
	if(refund) {
		if(refund[0].checked && refund[0].value=='F' && partial_refund) 
			partial_refund.style.display="none";
		else if(refund[1].checked && refund[1].value=='P' && partial_refund)
			partial_refund.style.display="";
	}	
}*/

function change_status(mode){ 
	var statusId=document.status.status.options[document.status.status.selectedIndex].value;
	var statustext=document.status.status.options[document.status.status.selectedIndex].text;
	//var refunded=document.getElementById("refunded");
	//if(statustext=='Refunded' && refunded) refunded.style.display="";	
	if(statusId == '<?php echo TEXT_DELIVERED_ID; ?>'){
			document.getElementById('shipping').style.display='';
		//	document.status.shipping_date.value = '<?php echo format_date($today_date); ?>';
	}
	else {
		document.getElementById('shipping').style.display='none';
		}	
		if(mode!="") {
			if(mode=='1')
				document.status.comments.value="";
		}	
	}
	
	
	function formValidate(){ 
		var statusId;
		var statustext;
		var odate;
		if(document.status.status){
			statusId=document.status.status.options[document.status.status.selectedIndex].value;
			statustext=document.status.status.options[document.status.status.selectedIndex].text;
		}	
	//	var amount_type=document.status.elements["r_amount_type"];
	//	var r_amount=document.status.r_amount.value;				
		if(statusId != '<?php echo TEXT_DELIVERED_ID; ?>')
			document.getElementById('shipping_date').value='';		
		error = false;
		error_result = "<?php echo JS_ERROR; ?>";
	/*	if(statustext=='Refunded' && amount_type && amount_type[1].checked && r_amount>100){ 
			error_result += "<?php echo JS_ERROR_R_PERCENT; ?>";
			error=true;	
		}
		if(statustext=='Refunded'&& (isNaN(r_amount) || r_amount<=0)){  
			error_result += "<?php echo JS_ERROR_R_AMOUNT; ?>";
			error=true;
		}	*/			
		events_date_format = '<?php echo EVENTS_DATE_FORMAT; ?>';
		if(statusId=='<?php echo TEXT_DELIVERED_ID; ?>'){
			if(document.status.shipping_date.value=="") {
			error=false;
			error_result +='<?php echo ERROR_EMPTY_SHIPPING_DATE; ?>';
			}
		}
	/*var error_date = isValidDate(date_format(document.getElementById('shipping_date').value,'','Y-m-d'));
	if(error_date == false){
		alert('<?php echo ERROR_DATE_INVALID; ?>');
		//return false;
	}*/
	
	if(statusId == '<?php echo TEXT_DELIVERED_ID; ?>'){ 
		events_date_format = '<?php echo EVENTS_DATE_FORMAT; ?>';
		shipping_date = dates(document.status.shipping_date.value,events_date_format,'Y-m-d');
		valid = (isValidDate(dates(document.status.shipping_date.value,events_date_format,'Y-m-d')));
		//shipping date must be greater than or equal to order date condition
		if(!valid || date_format(order_date,'','Y-m-d')>shipping_date){
			error = true;
			error_result+='\n<?php echo ERROR_SHIPPING_DATE; ?>';
		}
			
	 }
	 if(error == true)
	 	alert(error_result);
	 else { 
	 do_post_command('status','<?php echo tep_href_link(FILENAME_ORDERS,'command=save_edit_order_details'); ?>');
	 document.getElementById('update_ajax_load').innerHTML=ajax_image_load;
	 }
	 	//return true;
	}

function dates(src,cur,des){
	ret = "";
	if(cur.split("-").length>0 && src.split("-").length>0){
	// Convert to Position Making
		des = des.replace("Y","0");
		des = des.replace("m","1");
		des = des.replace("d","2");

	// Convert to Position Making
		cur = cur.replace("Y","0");
		cur = cur.replace("m","1");
		cur = cur.replace("d","2");

	// Split the dates Arrays
		des_array = des.split("-");
		cur_array = cur.split("-");
		src_array = src.split("-");
	// Return the Destination Format of Current Format for Source Date
		ret = src_array[cur_array[des_array[0]]] + "-" + src_array[cur_array[des_array[1]]] + "-" + src_array[cur_array[des_array[2]]];
		return ret;
	}else{
		return false;
	}
}	
	function change_orders_status(status_id){
	document.getElementById('load_orders').innerHTML=ajax_image_load;
	do_get_command('<?php echo tep_href_link(FILENAME_ORDERS,'command=change_orders_status&status_id='); ?>'+status_id+'&cID='+cID);
	}
	function reset_search(){
	document.getElementById('order_search').value='';
	document.getElementById('load_orders').innerHTML=ajax_image_load;
	do_get_command('<?php echo tep_href_link(FILENAME_ORDERS,'command=change_orders_status&cID='); ?>'+cID);
	}
	function searchValidation(){
	var order_search_id=document.getElementById('order_search').value;
		if(order_search_id==''){
		alert('<?php echo ERROR_ORDER_ID; ?>');
		}else if(isNaN(order_search_id)){
		alert('<?php echo ERROR_ORDER_INTEGER; ?>');
		}else{
		do_get_command('<?php echo tep_href_link(FILENAME_ORDERS,'command=order_search&oID='); ?>'+order_search_id+'&cID='+cID);
		document.getElementById('load_orders').innerHTML=ajax_image_load;
		}
	return false;
	}
	function search_order(){
	var order_search_id=document.getElementById('order_search').value;
		if(order_search_id==''){
		alert('<?php echo ERROR_ORDER_ID; ?>');
		}else if(isNaN(order_search_id)){
		alert('<?php echo ERROR_ORDER_INTEGER; ?>');
		}else{
		do_get_command('<?php echo tep_href_link(FILENAME_ORDERS,'command=order_search&oID='); ?>'+order_search_id+'&cID='+cID);
		document.getElementById('load_orders').innerHTML=ajax_image_load;
		}
	}
	
	function do_close(orders_id) {
		if(document.getElementById('ajax_orders_'+orders_id) && document.getElementById('ajax_orders_'+orders_id).style.display=="" && document.getElementById('ajax_orders_'+orders_id).innerHTML!="" && row_expand==false ) {
			
			close_orders_details(orders_id);
		}row_expand=false;
	}
	function do_row_close() { 
		row_expand=true;
	}
</script>
</head>
<body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0" bgcolor="#FFFFFF">
<!-- header //-->
<?php include('includes/date_format_js.php');
	require(DIR_WS_INCLUDES . 'header.php');
?>
<!-- header_eof //-->

<!-- Ajax Work Starts -->
<?php $cID=isset($HTTP_GET_VARS['cID'])?$HTTP_GET_VARS['cID']:''; 
	$oID=isset($HTTP_GET_VARS['oID'])?$HTTP_GET_VARS['oID']:'';
?>
<script language="javascript"> 
	var cID='<?php echo $cID; ?>';
</script>
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr class="dataTableHeadingRow" style="height:30px;">

<td><table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr class="dataTableHeadingRow"><td  class="pageHeading" align="absbottom" style="padding-left:5px;" ><?php echo HEADING_TITLE; ?></td>
<td width="400" valign="bottom" class="smallText" align="right"><?php echo 'Order Id' . '&nbsp;' . tep_draw_form('order_search_form',FILENAME_ORDERS,'','post','onSubmit="return searchValidation();"') . tep_draw_input_field('order_search').'</form>&nbsp;<a  href="javascript: search_order();">'.tep_image(DIR_WS_IMAGES.'template/img_search.gif','','','','title="Search" align="absbottom"').'</a>&nbsp;&nbsp;&nbsp;'. 'Status ' . ' ' . tep_draw_pull_down_menu('status', array_merge(array(array('id' => '', 'text' => TEXT_ALL_ORDERS)), $orders_statuses), '', 'onChange="javascript: change_orders_status(this.value);"'); ?>&nbsp;&nbsp;</td>
</tr></table></td> 
</tr>
	<tr>
	<td style="padding:5px;"><table border="0" width="100%" cellspacing="0" cellpadding="0">
    <tr>
    <td width="25%" class="dataTableHeadingContent"><?php echo TABLE_HEADING_CUSTOMERS; ?></td>
    <td width="25%" class="dataTableHeadingContent" align="right"><?php echo TABLE_HEADING_ORDER_TOTAL; ?></td>
    <td width="25%" class="dataTableHeadingContent" align="center"><?php echo TABLE_HEADING_DATE_PURCHASED; ?></td>
    <td width="25%" class="dataTableHeadingContent" align="right"><?php echo TABLE_HEADING_STATUS; ?></td>
    </tr>
	</table></td>
	</tr>
	<tr>
	<td id="load_orders"><?php echo load_orders($oID,'',$cID); ?></td>
	</tr>
</table>
 
<!-- Ajax Work Ends -->

<!-- footer //-->
<?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
<!-- footer_eof //-->
</body>
</html>
<?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?>

<script language="javascript">
function changing_status(){ 
	document.getElementById('shipping').style.display='';
} 
var expand_orders=false;
var page=1;
<?php if(isset($HTTP_GET_VARS['expand']) && $HTTP_GET_VARS['expand']=='expand_orders'){
		if(isset($HTTP_GET_VARS['orders_page'])) {
?>page='<?php echo $HTTP_GET_VARS['orders_page']?>';
<?php }?>
expand_orders=true; 
row_expand=false;
	load_orders_details('<?php echo $HTTP_GET_VARS['orders_id'];?>');
	//edit_order_details('<?php echo $HTTP_GET_VARS['orders_id'];?>');
<?php } ?>
<?php if($HTTP_GET_VARS['return'] && $HTTP_GET_VARS['oID']){?>
do_get_command('<?php echo tep_href_link(FILENAME_ORDERS,'command=load_orders_details&orders_id=' . $HTTP_GET_VARS['oID'] . '&return=' . $HTTP_GET_VARS['return'] . '&id=' . $HTTP_GET_VARS['id'] . '&dpage=' . $HTTP_GET_VARS['page'] . '&type=' . $HTTP_GET_VARS['type'] . '&mPath=' . $HTTP_GET_VARS['mPath']); ?>');
<?php }?>
</script>