<?php
/**
  @licence GPL 2005-2010  The osCSS developers - osCSS Open Source E-commerce
  @portion code Copyright (c) 2002 osCommerce
  @package osCSS-2 <www http://www.oscss.org>
  @version 2.0.9
  @date  05/09/10, 11:17
  @author oscim <mail aurelien@oscim.fr> <www http://www.oscim.fr>
  @encode UTF-8
*/

  $xx_mins_ago = (time() - 900);


// remove entries that have expired
        tep_db_query("delete from " . TABLE_WHOS_ONLINE . " where time_last_click < '" . $xx_mins_ago . "'");
?>
<!-- body //-->
<h3><?php echo HEADING_TITLE; ?></h3>
<!-- body_text //-->

<table style="width:100%" class="dataTable">
  <thead>
    <tr>
      <th><?php echo TABLE_HEADING_ONLINE; ?></th>
      <th class="tcenter"><?php echo TABLE_HEADING_CUSTOMER_ID; ?></th>
      <th><?php echo TABLE_HEADING_FULL_NAME; ?></th>
      <th class="tcenter"><?php echo TABLE_HEADING_IP_ADDRESS; ?></th>
      <th><?php echo TABLE_HEADING_ENTRY_TIME; ?></th>
      <th class="tcenter"><?php echo TABLE_HEADING_LAST_CLICK; ?></th>
      <th><?php echo TABLE_HEADING_LAST_PAGE_URL; ?></th>
    </tr>
  </thead>
  <tbody>
<?php
  $whos_online_query = tep_db_query("select customer_id, full_name, ip_address, time_entry, time_last_click, last_page_url, session_id from " . TABLE_WHOS_ONLINE);
  while ($whos_online = tep_db_fetch_array($whos_online_query)) {
    $time_online = (time() - $whos_online['time_entry']);
    if ((!isset($_GET['info']) || (isset($_GET['info']) && ($_GET['info'] == $whos_online['session_id']))) && !isset($info)) {
      $info = $whos_online['session_id'];
    }
?>
    <tr id="defaultSelected" class="dataTableRow">
      <td ><?php echo gmdate('H:i:s', $time_online); ?></td>
      <td class="tcenter"><?php echo $whos_online['customer_id']; ?></td>
      <td ><?php echo $whos_online['full_name']; ?></td>
      <td class="tcenter"><?php echo $whos_online['ip_address']; ?></td>
      <td ><?php echo date('H:i:s', $whos_online['time_entry']); ?></td>
      <td class="tcenter"><?php echo date('H:i:s', $whos_online['time_last_click']); ?></td>
      <td ><?php if (preg_match('#^(.*)' . tep_session_name() . '=[a-f,0-9]+[&]*(.*)#i', $whos_online['last_page_url'], $array)) { echo $array[1] . $array[2]; } else { echo $whos_online['last_page_url']; } ?>&nbsp;</td>
    </tr>
<?php
  }
?>
    </tbody>
    </table>
        <p><?php echo sprintf(TEXT_NUMBER_OF_CUSTOMERS, tep_db_num_rows($whos_online_query)); ?></p>

<?php
  $heading = array();
  $contents = array();

  if (isset($info)) {
    $heading[] = array('text' => '<h4>' . TABLE_HEADING_SHOPPING_CART . '</h4>');

    if (STORE_SESSIONS == 'mysql') {
      $session_data = tep_db_query("select value from " . TABLE_SESSIONS . " WHERE sesskey = '" . $info . "'");
      $session_data = tep_db_fetch_array($session_data);
      $session_data = trim($session_data['value']);
    } else {
      if ( (file_exists(tep_session_save_path() . '/sess_' . $info)) && (filesize(tep_session_save_path() . '/sess_' . $info) > 0) ) {
        $session_data = file(tep_session_save_path() . '/sess_' . $info);
        $session_data = trim(implode('', $session_data));
      }
    }
    if ($length = strlen($session_data)) {
        $start_id = strpos($session_data, 'customer_id|s');
        $start_cart = strpos($session_data, 'cart|O');
        $start_currency = strpos($session_data, 'currency|s');
        $start_country = strpos($session_data, 'customer_country_id|s');
        $start_zone = strpos($session_data, 'customer_zone_id|s');

if ($start_cart<1) $start_cart=1;
      for ($i=$start_cart; $i<$length; $i++) {
        if ($session_data[$i] == '{') {
          if (isset($tag)) {
            $tag++;
          } else {
            $tag = 1;
          }
        } elseif ($session_data[$i] == '}') {
          $tag--;
        } elseif ( (isset($tag)) && ($tag < 1) ) {
          break;
        }
      }

      $session_data_id = substr($session_data, $start_id, (strpos($session_data, ';', $start_id) - $start_id + 1));
      $session_data_cart = substr($session_data, $start_cart, $i);
      $session_data_currency = substr($session_data, $start_currency, (strpos($session_data, ';', $start_currency) - $start_currency + 1));
      $session_data_country = substr($session_data, $start_country, (strpos($session_data, ';', $start_country) - $start_country + 1));
      $session_data_zone = substr($session_data, $start_zone, (strpos($session_data, ';', $start_zone) - $start_zone + 1));

      session_decode($session_data_id);
      session_decode($session_data_currency);
      session_decode($session_data_country);
      session_decode($session_data_zone);
      session_decode($session_data_cart);

      if (isset($cart) && is_object($cart)) {
        $products = $cart->get_products();
        for ($i = 0, $n = sizeof($products); $i < $n; $i++) {
          $contents[] = array('text' => $products[$i]['quantity'] . ' x ' . $products[$i]['name']);
        }

        if (sizeof($products) > 0) {
          $contents[] = array('text'  => TEXT_SHOPPING_CART_SUBTOTAL . ' ' . $currencies->format($cart->show_total(), true, $currency));
        } else {
          $contents[] = array('text' => '&nbsp;');
        }
      }
    }
  }
?>
<div class="fright" style="width:29%">
<?php
  if ( (tep_not_null($heading)) && (tep_not_null($contents)) ) {
    $box = new box;
    echo $box->infoBox($heading, $contents);
  }
?>
        </div>
<!-- body_text_eof //-->
<!-- body_eof //-->