<?php
/*
###################################################################################
  Bigware Shop 2.3
  Release Datum: 23.08.2015
  
  Bigware Shop
  http://www.bigware.de

  Copyright (c) 2015 Bigware LTD
  (c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
  (c) 2015	Bigware LTD

  Copyrightvermerke duerfen nicht entfernt werden.
  ------------------------------------------------------------------------
  Dieses Programm ist freie Software. Sie koennen es unter den Bedingungen
  der GNU General Public License, wie von der Free Software Foundation
  veroeffentlicht, weitergeben und/oder modifizieren, entweder gemaess Version 2 
  der Lizenz oder (nach Ihrer Option) jeder spaeteren Version.
  Die Veroeffentlichung dieses Programms erfolgt in der Hoffnung, dass es Ihnen
  von Nutzen sein wird, aber OHNE IRGENDEINE GARANTIE, sogar ohne die
  implizite Garantie der MARKTREIFE oder der VERWENDBARKEIT FUER EINEN
  BESTIMMTEN ZWECK. Details finden Sie in der GNU General Public License.
  
  Sie sollten eine Kopie der GNU General Public License zusammen mit diesem
  Programm erhalten haben. Falls nicht, schreiben Sie an die Free Software
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.

  Infos:
  ------------------------------------------------------------------------
  Der Bigware Shop wurde vor vielen Jahren bereits aus dem bekannten Shopsystem osCommerce
  weiter- und neuentwickelt.
  Der Bigware Shop legt im hohen Masse Wert auf Bedienerfreundlichkeit, beinhaltet eine leichte
  Installation, viele neue professionelle Werkzeuge und zeichnet sich aus durch eine grosse 
  Community, die bei Problemen weiterhelfen kann.
  
  Der Bigware Shop ist auf jedem System lauffaehig, welches eine PHP Umgebung
  (ab PHP 4.1.3) und mySQL zur Verfuegung stellt und auf Linux basiert.
 
  Hilfe erhalten Sie im Forum auf www.bigware.de 
  
  -----------------------------------------------------------------------
  
 ##################################################################################




*/
?>
<?php
  require('load_this/load_bigware_11.php');
  require(FOLDER_RELATIV_CLASSES . 'class_bigware_1.php');
  $currencies = new currencies();
  $orders_statuses = array();
  $orders_status_array = array();
  $orders_status_query = go_db_query("select orders_status_id, orders_status_name from " . DB_TBL_ORDERS_STATUS . " where language_id = '" . (int)$languages_id . "'");
  
	while ($orders_status = go_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'];
  }
  $action = (isset($_GET['action']) ? $_GET['action'] : '');
  
  if (go_not_null($action)) {
    switch ($action) {
      case 'update_order':
        $oID = go_db_producing_input($_GET['oID']);
        $status = go_db_producing_input($_POST['status']);
        $comments = go_db_producing_input($_POST['comments']);
        $order_updated = false;
        $check_status_query = go_db_query("select attendees_name, attendees_email_address, orders_status, date_purchased from " . DB_TBL_ORDERS . " where orders_id = '" . (int)$oID . "'");
        $check_status = go_db_fetch_array($check_status_query);
        if ( ($check_status['orders_status'] != $status) || go_not_null($comments)) {
          go_db_query("update " . DB_TBL_ORDERS . " set orders_status = '" . go_db_input($status) . "', last_modified = now() where orders_id = '" . (int)$oID . "'");
          $attendee_notified = '0';
          if (isset($_POST['notify']) && ($_POST['notify'] == 'on')) {
            $notify_comments = '';
            if (isset($_POST['notify_comments']) && ($_POST['notify_comments'] == 'on')) {
              $notify_comments = sprintf(EMAIL_TEXT_COMMENTS_UPDATE, $comments) . "\n\n";
            }
            $email = SHOP_NAME . "\n" . EMAIL_SEPARATOR . "\n" . EMAIL_TEXT_ORDER_NUMBER . ' ' . $oID . "\n" . EMAIL_TEXT_INVOICE_URL . ' ' . go_catalog_href_link(NAME_OF_FILE_CATALOG_MEMBER_HISTORY_INFO, 'order_id=' . $oID, 'SSL') . "\n" . EMAIL_TEXT_DATE_ORDERED . ' ' . go_date_long($check_status['date_purchased']) . "\n\n" . $notify_comments . sprintf(EMAIL_TEXT_STATUS_UPDATE, $orders_status_array[$status]);
            go_mail($check_status['attendees_name'], $check_status['attendees_email_address'], EMAIL_TEXT_SUBJECT, $email, SHOP_OWNER, SHOP_OWNER_EMAIL_ADDRESS);
            $attendee_notified = '1';
          }
          go_db_query("insert into " . DB_TBL_ORDERS_STATUS_HISTORY . " (orders_id, orders_status_id, date_added, attendee_notified, comments) values ('" . (int)$oID . "', '" . go_db_input($status) . "', now(), '" . go_db_input($attendee_notified) . "', '" . go_db_input($comments)  . "')");
          $order_updated = true;
        }
        if ($order_updated == true) {
         $messageStack->add_session(SUCCESS_ORDER_UPDATED, 'success');
        } else {
          $messageStack->add_session(WARNING_ORDER_NOT_UPDATED, 'warning');
        }
        go_forward(go_href_link(NAME_OF_FILE_AFTERBUY_ORDER, go_get_all_get_parameter(array('action')) . 'action=change'));
        break;
      case 'deleteconfirm':
        $oID = go_db_producing_input($_GET['oID']);
        go_remove_order($oID, $_POST['restock']);
        go_forward(go_href_link(NAME_OF_FILE_AFTERBUY_ORDER, go_get_all_get_parameter(array('oID', 'action'))));
        break;
    }
  }
  if (($action == 'change') && isset($_GET['oID'])) {
    $oID = go_db_producing_input($_GET['oID']);
    $orders_query = go_db_query("select orders_id from " . DB_TBL_ORDERS . " where orders_id = '" . (int)$oID . "'");
    $order_exists = true;
    if (!go_db_num_rows($orders_query)) {
      $order_exists = false;
      $messageStack->add(sprintf(ERROR_ORDER_DOES_NOT_EXIST, $oID), 'error');
    }
  }
  include(FOLDER_RELATIV_CLASSES . 'class_bigware_9.php');
?>
<!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="load_this/style.css">
<script language="javascript" src="load_this/menu.js"></script>
<style type="text/css">
<!--
tableDataColor  {background-color: <?php echo $color; ?>; }
//-->
</style>
<script language="javascript" src="load_this/general.js"></script>
</head>
<body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0" bgcolor="#FFFFFF">
<!-- header //-->
<?php
  require(FOLDER_RELATIV_INCLUDES . 'load_bigware_9.php');
?>
<!-- header_eof //-->
<!-- body //-->
<table border="0" width="100%" cellspacing="2" cellpadding="2">
  <tr>
    <td width="<?php echo FRAME_WIDTH; ?>" valign="top">
<!-- left_navigation //-->
<!-- left_navigation_eof //-->
</td>
<!-- body_text //-->
    <td width="100%" valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="2">
<?php
require(FOLDER_RELATIV_INCLUDES . 'load_bigware_5.php');
require(FOLDER_RELATIV_INCLUDES . 'load_bigware_3.php');
  if (($action == 'change') && ($order_exists == true)) {
    $order = new order($oID);
?>
      <tr>
        <td width="100%"><table border="0" width="100%" cellspacing="0" cellpadding="0">
          <tr>
            <td class="pageGeneralsign"><?php echo ABOVE_TITLE; ?></td>
            <td class="pageGeneralsign" align="right"><?php echo go_fetch_dividing_up('tranparentes.gif', 1, ABOVE_PICTURE_HEIGHT); ?></td>
            <td class="pageGeneralsign" align="right"><?php echo '<a href="' . go_href_link(NAME_OF_FILE_AFTERBUY_ORDER, go_get_all_get_parameter(array('action'))) . '">' . go_picture_button('button_back.gif', PICTURE_BACK) . '</a>'; ?></td>
          </tr>
        </table></td>
      </tr>
      <tr>
        <td><table width="100%" border="0" cellspacing="0" cellpadding="2">
          <tr>
            <td colspan="3"><?php echo go_fetch_dividing_up(); ?></td>
          </tr>
          <tr>
            <td valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="2">
              <tr>
                <td class="main" valign="top"><b><?php echo TYPE_IN_ATTENDEE; ?></b></td>
                <td class="main"><?php echo go_form_of_address($order->attendee['format_id'], $order->attendee, 1, '', '<br>'); ?></td>
              </tr>
              <tr>
                <td colspan="2"><?php echo go_fetch_dividing_up('tranparentes.gif', '1', '5'); ?></td>
              </tr>
<!--PIVACF start-->
              <tr>
                <td class="main"><b><?php echo TYPE_IN_PIVA; ?></b></td>
                <td class="main"><?php echo $order->billing['piva']; ?></td>
              </tr>
              <tr>
                <td class="main"><b><?php echo TYPE_IN_CF; ?></b></td>
                <td class="main"><?php echo $order->billing['cf']; ?></td>
              </tr>                                            
<!--PIVACF end-->
							
              <tr>
                <td class="main"><b><?php echo TYPE_IN_TELEPHONE_NUMBER; ?></b></td>
                <td class="main"><?php echo $order->attendee['telephone']; ?></td>
              </tr>
              <tr>
                <td class="main"><b><?php echo TYPE_IN_EMAIL_ADDRESS; ?></b></td>
                <td class="main"><?php echo '<a href="mailto:' . $order->attendee['email_address'] . '"><u>' . $order->attendee['email_address'] . '</u></a>'; ?></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 TYPE_IN_SHIPPING_ADDRESS; ?></b></td>
                <td class="main"><?php echo go_form_of_address($order->delivery['format_id'], $order->delivery, 1, '', '<br>'); ?></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 TYPE_IN_BILLING_ADDRESS; ?></b></td>
                <td class="main"><?php echo go_form_of_address($order->billing['format_id'], $order->billing, 1, '', '<br>'); ?></td>
              </tr>
            </table></td>
          </tr>
        </table></td>
      </tr>
      <tr>
        <td><?php echo go_fetch_dividing_up('tranparentes.gif', '1', '10'); ?></td>
      </tr>
      <tr>
        <td><table border="0" cellspacing="0" cellpadding="2">
          <tr>
            <td class="main"><b><?php echo TYPE_IN_PAYMENT_METHOD; ?></b></td>
            <td class="main"><?php echo $order->info['payment_method']; ?></td>
          </tr>
<?php
    if (go_not_null($order->info['cc_type']) || go_not_null($order->info['cc_owner']) || go_not_null($order->info['cc_code'])) {
?>
          <tr>
            <td colspan="2"><?php echo go_fetch_dividing_up('tranparentes.gif', '1', '10'); ?></td>
          </tr>
          <tr>
            <td class="main"><?php echo TYPE_IN_CRCHANGE_CARD_TYPE; ?></td>
            <td class="main"><?php echo $order->info['cc_type']; ?></td>
          </tr>
          <tr>
            <td class="main"><?php echo TYPE_IN_CRCHANGE_CARD_OWNER; ?></td>
            <td class="main"><?php echo $order->info['cc_owner']; ?></td>
          </tr>
          <tr>
            <td class="main"><?php echo TYPE_IN_CRCHANGE_CARD_NUMBER; ?></td>
            <td class="main"><?php echo $order->info['cc_number']; ?></td>
          </tr>
          <tr>
            <td class="main"><?php echo TYPE_IN_CRCHANGE_CARD_CODE; ?></td>
            <td class="main"><?php echo $order->info['cc_code']; ?></td>
          </tr>
          <tr>
            <td class="main"><?php echo TYPE_IN_CRCHANGE_CARD_EXPIRES; ?></td>
            <td class="main"><?php echo $order->info['cc_expires']; ?></td>
          </tr>
<?php
    }
?>
        </table></td>
      </tr>
      <tr>
        <td><?php echo go_fetch_dividing_up('tranparentes.gif', '1', '10'); ?></td>
      </tr>
      <tr>
        <td><table border="0" width="100%" cellspacing="0" cellpadding="2">
          <tr class="tbUPCountData">
            <td class="tbUPDataInside" colspan="2"><?php echo DB_TBL_ABOVE_ITEMS; ?></td>
            <td class="tbUPDataInside"><?php echo DB_TBL_ABOVE_ITEMS_MODEL; ?></td>
            <td class="tbUPDataInside" align="right"><?php echo DB_TBL_ABOVE_TAX; ?></td>
            <td class="tbUPDataInside" align="right"><?php echo DB_TBL_ABOVE_PRICE_EXCLUDING_TAX; ?></td>
            <td class="tbUPDataInside" align="right"><?php echo DB_TBL_ABOVE_PRICE_INCLUDING_TAX; ?></td>
            <td class="tbUPDataInside" align="right"><?php echo DB_TBL_ABOVE_TOTAL_EXCLUDING_TAX; ?></td>
            <td class="tbUPDataInside" align="right"><?php echo DB_TBL_ABOVE_TOTAL_INCLUDING_TAX; ?></td>
          </tr>
<?php
    for ($i=0, $n=sizeof($order->items); $i<$n; $i++) {
    	
    $returns_check_query = go_db_query("SELECT r.rma_value, rp.items_id FROM " . DB_TBL_RETURNS . " r, " . DB_TBL_RETURNS_ITEMS_DATA . " rp where r.returns_id = rp.returns_id and r.order_id = '" . $oID . "' and rp.items_id = '" . $order->items[$i]['id'] . "' ");
if (!go_db_num_rows($returns_check_query)){
$return = '&nbsp;';
} else {
$returns = go_db_fetch_array($returns_check_query);
$return_link = '<a href=' . go_href_link(NAME_OF_FILE_RETURNS, 'bigID=' . $returns['rma_value']) . '><font color=red><b><i>Returns</b></i></font></a>';
}
      echo '          <tr class="tbCountData">' . "\n" .
           '            <td class="TbInsideData" valign="top" align="right">' . $order->items[$i]['qty'] . '&nbsp;x</td>' . "\n" .
           '            <td class="TbInsideData" valign="top">' . $order->items[$i]['name'] . '&nbsp;&nbsp;' . $return_link;
      if (isset($order->items[$i]['characteristics']) && (sizeof($order->items[$i]['characteristics']) > 0)) {
        for ($j = 0, $k = sizeof($order->items[$i]['characteristics']); $j < $k; $j++) {
          echo '<br><nobr><small>&nbsp;<i> - ' . $order->items[$i]['characteristics'][$j]['option'] . ': ' . $order->items[$i]['characteristics'][$j]['value'];
          if ($order->items[$i]['characteristics'][$j]['price'] != '0') echo ' (' . $order->items[$i]['characteristics'][$j]['prefix'] . $currencies->format($order->items[$i]['characteristics'][$j]['price'] * $order->items[$i]['qty'], true, $order->info['currency'], $order->info['currency_value']) . ')';
          echo '</i></small></nobr>';
        }
      }
      echo '            </td>' . "\n" .
           '            <td class="TbInsideData" valign="top">' . $order->items[$i]['model'] . '</td>' . "\n" .
           '            <td class="TbInsideData" align="right" valign="top">' . go_display_tax_value($order->items[$i]['tax']) . '%</td>' . "\n" .
           '            <td class="TbInsideData" align="right" valign="top"><b>' . $currencies->format($order->items[$i]['final_price'], true, $order->info['currency'], $order->info['currency_value']) . '</b></td>' . "\n" .
           '            <td class="TbInsideData" align="right" valign="top"><b>' . $currencies->format(go_add_tax($order->items[$i]['final_price'], $order->items[$i]['tax']), true, $order->info['currency'], $order->info['currency_value']) . '</b></td>' . "\n" .
           '            <td class="TbInsideData" align="right" valign="top"><b>' . $currencies->format($order->items[$i]['final_price'] * $order->items[$i]['qty'], true, $order->info['currency'], $order->info['currency_value']) . '</b></td>' . "\n" .
           '            <td class="TbInsideData" align="right" valign="top"><b>' . $currencies->format(go_add_tax($order->items[$i]['final_price'], $order->items[$i]['tax']) * $order->items[$i]['qty'], true, $order->info['currency'], $order->info['currency_value']) . '</b></td>' . "\n";
      echo '          </tr>' . "\n";
    }
?>
          <tr>
            <td align="right" colspan="8"><table border="0" cellspacing="0" cellpadding="2">
<?php
    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 go_fetch_dividing_up('tranparentes.gif', '1', '10'); ?></td>
      </tr>
      <tr>
        <td class="main"><table border="1" cellspacing="0" cellpadding="5">
          <tr>
            <td class="smallText" align="center"><b><?php echo DB_TBL_ABOVE_DATE_ADDED; ?></b></td>
            <td class="smallText" align="center"><b><?php echo DB_TBL_ABOVE_ATTENDEE_NOTIFIED; ?></b></td>
            <td class="smallText" align="center"><b><?php echo DB_TBL_ABOVE_STATUS; ?></b></td>
            <td class="smallText" align="center"><b><?php echo DB_TBL_ABOVE_COMMENTS; ?></b></td>
          </tr>
<?php
    $orders_history_query = go_db_query("select orders_status_id, date_added, attendee_notified, comments from " . DB_TBL_ORDERS_STATUS_HISTORY . " where orders_id = '" . go_db_input($oID) . "' order by date_added");
    if (go_db_num_rows($orders_history_query)) {
      while ($orders_history = go_db_fetch_array($orders_history_query)) {
        echo '          <tr>' . "\n" .
             '            <td class="smallText" align="center">' . go_datetime_short($orders_history['date_added']) . '</td>' . "\n" .
             '            <td class="smallText" align="center">';
        if ($orders_history['attendee_notified'] == '1') {
          echo go_picture(FOLDER_RELATIV_ICONS . 'tick.gif', ICON_TICK) . "</td>\n";
        } else {
          echo go_picture(FOLDER_RELATIV_ICONS . 'cross.gif', ICON_CROSS) . "</td>\n";
        }
        echo '            <td class="smallText">' . $orders_status_array[$orders_history['orders_status_id']] . '</td>' . "\n" .
             '            <td class="smallText">' . nl2br(go_db_output($orders_history['comments'])) . '&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 class="main"><br><b><?php echo DB_TBL_ABOVE_COMMENTS; ?></b></td>
      </tr>
      <tr>
        <td><?php echo go_fetch_dividing_up('tranparentes.gif', '1', '5'); ?></td>
      </tr>
      <tr><?php echo go_fetch_form('status', NAME_OF_FILE_AFTERBUY_ORDER, go_get_all_get_parameter(array('action')) . 'action=update_order'); ?>
        <td class="main"><?php echo go_fetch_textarea_field('comments', 'soft', '60', '5'); ?></td>
      </tr>
      <tr>
        <td><?php echo go_fetch_dividing_up('tranparentes.gif', '1', '10'); ?></td>
      </tr>
      <tr>
        <td><table border="0" cellspacing="0" cellpadding="2">
          <tr>
            <td><table border="0" cellspacing="0" cellpadding="2">
              <tr>
                <td class="main"><b><?php echo TYPE_IN_STATUS; ?></b> <?php echo go_fetch_pull_down_menu('status', $orders_statuses, $order->info['orders_status']); ?></td>
              </tr>
              <tr>
                <td class="main"><b><?php echo TYPE_IN_NOTIFY_ATTENDEE; ?></b> <?php echo go_fetch_checkbox_field('notify', '', true); ?></td>
                <td class="main"><b><?php echo TYPE_IN_NOTIFY_COMMENTS; ?></b> <?php echo go_fetch_checkbox_field('notify_comments', '', true); ?></td>
              </tr>
            </table></td>
            <td valign="top"><?php echo go_picture_submit('button_update.gif', PICTURE_UPDATE); ?></td>
          </tr>
        </table></td>
      </form></tr>
<?php
  } else {
?>
      <tr>
        <td width="100%"><table border="0" width="100%" cellspacing="0" cellpadding="0">
          <tr>
            <td class="pageGeneralsign"><?php echo ABOVE_TITLE; ?></td>
            <td class="pageGeneralsign" align="right"><?php echo go_fetch_dividing_up('tranparentes.gif', 1, ABOVE_PICTURE_HEIGHT); ?></td>
            <td align="right"><table border="0" width="100%" cellspacing="0" cellpadding="0">
              <tr><?php echo go_fetch_form('orders', NAME_OF_FILE_AFTERBUY_ORDER, '', 'get'); ?>
                <td class="smallText" align="right"><?php echo ABOVE_TITLE_SEARCH . ' ' . go_fetch_inputfeld('oID', '', 'size="12"') . go_fetch_hidden_field('action', 'change'); ?></td>
              </form></tr>
              <tr><?php echo go_fetch_form('status', NAME_OF_FILE_AFTERBUY_ORDER, '', 'get'); ?>
                <td class="smallText" align="right"><?php echo ABOVE_TITLE_STATUS . ' ' . go_fetch_pull_down_menu('status', array_merge(array(array('id' => '0', 'text' => TEXT_ALL_ORDERS)), $orders_statuses), '', 'onChange="this.form.submit();"'); ?></td>
              </form></tr>							
              <tr><?php echo go_fetch_form('grouped', NAME_OF_FILE_AFTERBUY_ORDER, '', 'get'); ?>
                <td class="smallText" align="right">
								<?php echo '<a href="' . go_href_link(NAME_OF_FILE_AFTERBUY_ORDER) . '">' . go_picture_button('button_reset.gif', PICTURE_RESET) . '</a>';?>
              </form></tr>							
							          
            </table></td>
          </tr>
        </table></td>
      </tr>
      <tr>
        <td><table border="0" width="100%" cellspacing="1" cellpadding="0">
          <tr>
            <td valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="2">
              <tr class="tbUPCountData">
                <td class="tbUPDataInside"><?php echo DB_TBL_ABOVE_ATTENDEES; ?></td>
								<td></td>
                <td class="tbUPDataInside" align="right"><?php echo DB_TBL_ABOVE_ORDER_TOTAL; ?></td>
                <td class="tbUPDataInside" align="center"><?php echo DB_TBL_ABOVE_DATE_PURCHASED; ?></td>
                <td class="tbUPDataInside" align="right"><?php echo DB_TBL_ABOVE_STATUS; ?></td>
                <td class="tbUPDataInside" align="right"><?php echo DB_TBL_ABOVE_ACTION; ?>&nbsp;</td>
              </tr>
<?php
require('main_bigware_90.php');
    if (isset($_GET['bigID'])) {
      $bigID = go_db_producing_input($_GET['bigID']);
      $orders_query_raw = "select o.orders_id, o.attendees_name, o.attendees_company, o.attendees_id, o.payment_method, o.date_purchased, o.last_modified, o.currency, o.currency_value, s.orders_status_name, ot.text as order_total from ((" . DB_TBL_ORDERS . " o) left join " . DB_TBL_ORDERS_TOTAL . " ot on (o.orders_id = ot.orders_id), " . DB_TBL_ORDERS_STATUS . " s) where o.attendees_id = '" . (int)$bigID . "' and o.orders_status = s.orders_status_id and s.language_id = '" . (int)$languages_id . "' and ot.class = 'ot_total' order by orders_id DESC";
		} elseif (isset($_GET['attendees_group_id'])) {
      $statusgr = go_db_producing_input($_GET['attendees_group_id']);
      $orders_query_raw = "select o.orders_id, o.attendees_name, o.attendees_company, o.payment_method, o.date_purchased, o.last_modified, o.currency, o.currency_value, s.orders_status_name, ot.text as order_total from ((" . DB_TBL_ORDERS . " o) left join " . DB_TBL_ORDERS_TOTAL . " ot on (o.orders_id = ot.orders_id), " . DB_TBL_ORDERS_STATUS . " s) where o.orders_status = s.orders_status_id and s.language_id = '" . (int)$languages_id . "' and ot.class = 'ot_total' order by o.orders_id DESC";
		} elseif (isset($_GET['status'])) {
      $status = go_db_producing_input($_GET['status']);
			if ($status == "0"){
			$orders_query_raw = "select o.orders_id, o.attendees_name, o.attendees_company, o.payment_method, o.date_purchased, o.last_modified, o.currency, o.currency_value, s.orders_status_name, ot.text as order_total from ((" . DB_TBL_ORDERS . " o) left join " . DB_TBL_ORDERS_TOTAL . " ot on (o.orders_id = ot.orders_id), " . DB_TBL_ORDERS_STATUS . " s) where o.orders_status = s.orders_status_id and s.language_id = '" . (int)$languages_id . "' and ot.class = 'ot_total' order by o.orders_id DESC";
			} else {
      $orders_query_raw = "select o.orders_id, o.attendees_name, o.attendees_company, o.payment_method, o.date_purchased, o.last_modified, o.currency, o.currency_value, s.orders_status_name, ot.text as order_total from ((" . DB_TBL_ORDERS . " o) left join " . DB_TBL_ORDERS_TOTAL . " ot on (o.orders_id = ot.orders_id), " . DB_TBL_ORDERS_STATUS . " s) where o.orders_status = s.orders_status_id and s.language_id = '" . (int)$languages_id . "' and s.orders_status_id = '" . (int)$status . "' and ot.class = 'ot_total' order by o.orders_id DESC";
    }
		} else {
      $orders_query_raw = "select o.orders_id, o.attendees_name, o.attendees_company, o.payment_method, o.date_purchased, o.last_modified, o.currency, o.currency_value, s.orders_status_name, ot.text as order_total from ((" . DB_TBL_ORDERS . " o) left join " . DB_TBL_ORDERS_TOTAL . " ot on (o.orders_id = ot.orders_id), " . DB_TBL_ORDERS_STATUS . " s) where o.orders_status = s.orders_status_id and s.language_id = '" . (int)$languages_id . "' and ot.class = 'ot_total' order by o.orders_id DESC";
}
    $orders_split = new splitPageResults($_GET['page'], MAX_SHOW_SEARCH_RESULTS, $orders_query_raw, $orders_query_numrows);
    $orders_query = go_db_query($orders_query_raw);
    
		while ($orders = go_db_fetch_array($orders_query)) {
    if ((!isset($_GET['oID']) || (isset($_GET['oID']) && ($_GET['oID'] == $orders['orders_id']))) && !isset($oInfo)) {
  		$oInfo = new objectInfo($orders);
  	} 
    		if ($orders['attendees_group_id'] != 0){
    		$color_query = go_db_query("select color_bar FROM ". DB_TBL_ATTENDEES_GROUPS ." where attendees_group_id = ". $orders['attendees_group_id'] ."");
    		$color = go_db_fetch_array($color_query); 
    		} 
      
			if (isset($oInfo) && is_object($oInfo) && ($orders['orders_id'] == $oInfo->orders_id)) {
        echo '<tr id="defaultSelected" class="tbCountDataSelected" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)" onclick="document.location.href=\'' . go_href_link(NAME_OF_FILE_AFTERBUY_ORDER, go_get_all_get_parameter(array('oID', 'action')) . 'oID=' . $oInfo->orders_id . '&action=import') . '\'">' . "\n"; 
     } elseif ($orders['attendees_group_id'] != 0) {
        echo '<tr bgcolor="'. $color['color_bar'] .'" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)" onclick="document.location.href=\'' . go_href_link(NAME_OF_FILE_AFTERBUY_ORDER, go_get_all_get_parameter(array('oID')) . 'oID=' . $orders['orders_id']) . '\'">' . "\n";
      } else {
			echo '<tr class="tbCountData" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)" onclick="document.location.href=\'' . go_href_link(NAME_OF_FILE_AFTERBUY_ORDER, go_get_all_get_parameter(array('oID')) . 'oID=' . $orders['orders_id']) . '\'">' . "\n";
			}
?>
                <td class="TbInsideData"><?php echo $orders['attendees_name'] .'&nbsp;(' . $orders['attendees_company'] .')'; ?></td>
                <?php if ($orders['attendees_group_id'] != '0'){ ?>
		<td bgcolor="<?php echo $color['color_bar']; ?>" width="10"></td>
		<?php } else { ?><td class="TbInsideData"></td><?php } ?>
		<td class="TbInsideData" align="right"><?php echo strip_tags($orders['order_total']); ?></td>
                <td class="TbInsideData" align="center"><?php echo go_datetime_short($orders['date_purchased']); ?></td>
                <td class="TbInsideData" align="right"><?php echo $orders['orders_status_name']; ?></td>
                <td class="TbInsideData" align="right"><?php if (isset($oInfo) && is_object($oInfo) && ($orders['orders_id'] == $oInfo->orders_id)) { echo go_picture(FOLDER_RELATIV_PICTURES . 'icon_arrow_right.gif', ''); } else { echo '<a href="' . go_href_link(NAME_OF_FILE_AFTERBUY_ORDER, go_get_all_get_parameter(array('oID')) . 'oID=' . $orders['orders_id']) . '">' . go_picture(FOLDER_RELATIV_PICTURES . 'icon_info.gif', PICTURE_ICON_INFO) . '</a>'; } ?>&nbsp;</td>
              </tr>
<?php
    }
?>
              <tr>
                <td colspan="5"><table border="0" width="100%" cellspacing="0" cellpadding="2">
                  <tr>
                    <td class="smallText" valign="top"><?php echo $orders_split->display_count($orders_query_numrows, MAX_SHOW_SEARCH_RESULTS, $_GET['page'], TEXT_SHOW_NUMBER_OF_ORDERS); ?></td>
                    <td class="smallText" align="right"><?php echo $orders_split->display_links($orders_query_numrows, MAX_SHOW_SEARCH_RESULTS, MAX_SHOW_PAGE_LINKS, $_GET['page'], go_get_all_get_parameter(array('page', 'oID', 'action'))); ?></td>
                  </tr>
                </table></td>
              </tr>
            </table></td>
<?php
  $heading = array();
  $contents = array();
  switch ($action) {
    case 'delete':
      $heading[] = array('text' => '<b>' . TEXT_INFO_ABOVE_DELETE_ORDER . '</b>');
      $contents = array('form' => go_fetch_form('orders', NAME_OF_FILE_AFTERBUY_ORDER, go_get_all_get_parameter(array('oID', 'action')) . 'oID=' . $oInfo->orders_id . '&action=deleteconfirm'));
      $contents[] = array('text' => TEXT_INFO_DELETE_INTRO . '<br><br><b>' . $bigwareInfo->attendees_firstname . ' ' . $bigwareInfo->attendees_lastname . '</b>');
      $contents[] = array('text' => '<br>' . go_fetch_checkbox_field('restock') . ' ' . TEXT_INFO_RESTOCK_ITEM_QUANTITY);
      $contents[] = array('align' => 'center', 'text' => '<br>' . go_picture_submit('button_delete.gif', PICTURE_DELETE) . ' <a href="' . go_href_link(NAME_OF_FILE_AFTERBUY_ORDER, go_get_all_get_parameter(array('oID', 'action')) . 'oID=' . $oInfo->orders_id) . '">' . go_picture_button('button_cancel.gif', PICTURE_CANCEL) . '</a>');
      break;
    default:
      if (isset($oInfo) && is_object($oInfo)) {
        $heading[] = array('text' => '<b>[' . $oInfo->orders_id . ']&nbsp;&nbsp;' . go_datetime_short($oInfo->date_purchased) . '</b>');
        $contents[] = array('align' => 'center', 'text' => '<a href="' . go_href_link(NAME_OF_FILE_AFTERBUY_ORDER, go_get_all_get_parameter(array('oID', 'action')) . 'oID=' . $oInfo->orders_id . '&action=import') . '">' . go_picture_button('button_afterbuy.gif', PICTURE_CHANGE) . '</a>');
        $contents[] = array('text' => '<br>' . TEXT_DATE_ORDER_CREATED . ' ' . go_date_short($oInfo->date_purchased));
        if (go_not_null($oInfo->last_modified)) $contents[] = array('text' => TEXT_DATE_ORDER_LAST_MODIFIED . ' ' . go_date_short($oInfo->last_modified));
        $contents[] = array('text' => '<br>' . TEXT_INFO_PAYMENT_METHOD . ' '  . $oInfo->payment_method);
      }
      break;
  }
  if ( (go_not_null($heading)) && (go_not_null($contents)) ) {
    echo '            <td width="25%" valign="top"><br>' . "\n";
    $frame = new frame;
    echo $frame->infoBox($heading, $contents);
    echo '            </td>' . "\n";
  }
?>
          </tr>
        </table></td>
      </tr>
<?php
  }
?>
    </table></td>
<!-- body_text_eof //-->
  </tr>
</table>
<!-- body_eof //-->
<!-- footer //-->
<?php require(FOLDER_RELATIV_INCLUDES . 'load_bigware_7.php'); ?>
<!-- footer_eof //-->
<br>
</body>
</html>
<?php require(FOLDER_RELATIV_INCLUDES . 'load_bigware_6.php'); ?>
