<commit_before><?php
/*
  $Id$

  osCommerce, Open Source E-Commerce Solutions
  http://www.oscommerce.com

  Copyright (c) 2014 osCommerce

  Released under the GNU General Public License
*/

  use OSC\OM\HTML;
  use OSC\OM\OSCOM;
  use OSC\OM\Registry;

  require('includes/application_top.php');

  $OSCOM_Hooks = Registry::get('Hooks');

  require(DIR_WS_CLASSES . 'currencies.php');
  $currencies = new currencies();

  $orders_statuses = [];
  $orders_status_array = [];

  $Qstatus = $OSCOM_Db->get('orders_status', [
    'orders_status_id',
    'orders_status_name'
  ], [
    'language_id' => (int)$_SESSION['languages_id']
  ]);

  while ($Qstatus->fetch()) {
    $orders_statuses[] = [
      'id' => $Qstatus->valueInt('orders_status_id'),
      'text' => $Qstatus->value('orders_status_name')
    ];

    $orders_status_array[$Qstatus->valueInt('orders_status_id')] = $Qstatus->value('orders_status_name');
  }

  include(DIR_WS_CLASSES . 'order.php');

  if (isset($_GET['oID']) && is_numeric($_GET['oID']) && ($_GET['oID'] > 0)) {
    $oID = HTML::sanitize($_GET['oID']);

    $Qorders = $OSCOM_Db->get('orders', 'orders_id', ['orders_id' => (int)$oID]);

    if ($Qorders->fetch()) {
      $order = new order($Qorders->valueInt('orders_id'));
    } else {
      $OSCOM_MessageStack->add(sprintf(ERROR_ORDER_DOES_NOT_EXIST, $oID), 'error');
    }
  }

  if (!isset($_GET['page']) || !is_numeric($_GET['page'])) {
    $_GET['page'] = 1;
  }

  $action = (isset($_GET['action']) ? $_GET['action'] : '');

  $OSCOM_Hooks->call('Orders', 'PreAction');

  if (tep_not_null($action)) {
    switch ($action) {
      case 'update_order':
        $oID = HTML::sanitize($_GET['oID']);
        $status = HTML::sanitize($_POST['status']);
        $comments = HTML::sanitize($_POST['comments']);

        $order_updated = false;

        $Qcheck = $OSCOM_Db->get('orders', [
          'customers_name',
          'customers_email_address',
          'orders_status',
          'date_purchased'
        ], [
          'orders_id' => (int)$oID
        ]);

        if ( ($Qcheck->value('orders_status') != $status) || tep_not_null($comments)) {
          $OSCOM_Db->save('orders', [
            'orders_status' => $status,
            'last_modified' => 'now()'
          ], [
            'orders_id' => (int)$oID
          ]);

          $customer_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 = STORE_NAME . "\n" . EMAIL_SEPARATOR . "\n" . EMAIL_TEXT_ORDER_NUMBER . ' ' . $oID . "\n" . EMAIL_TEXT_INVOICE_URL . ' ' . OSCOM::link('Shop/' . FILENAME_CATALOG_ACCOUNT_HISTORY_INFO, 'order_id=' . $oID, 'SSL') . "\n" . EMAIL_TEXT_DATE_ORDERED . ' ' . tep_date_long($Qcheck->value('date_purchased')) . "\n\n" . $notify_comments . sprintf(EMAIL_TEXT_STATUS_UPDATE, $orders_status_array[$status]);

            tep_mail($Qcheck->value('customers_name'), $Qcheck->value('customers_email_address'), EMAIL_TEXT_SUBJECT, $email, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS);

            $customer_notified = '1';
          }

          $OSCOM_Db->save('orders_status_history', [
            'orders_id' => (int)$oID,
            'orders_status_id' => $status,
            'date_added' => 'now()',
            'customer_notified' => $customer_notified,
            'comments' => $comments
          ]);

          $order_updated = true;
        }

        if ($order_updated == true) {
         $OSCOM_MessageStack->add(SUCCESS_ORDER_UPDATED, 'success');
        } else {
          $OSCOM_MessageStack->add(WARNING_ORDER_NOT_UPDATED, 'warning');
        }

        OSCOM::redirect(FILENAME_ORDERS, tep_get_all_get_params(array('action')) . 'action=edit');
        break;
      case 'deleteconfirm':
        $oID = HTML::sanitize($_GET['oID']);

        tep_remove_order($oID, $_POST['restock']);

        OSCOM::redirect(FILENAME_ORDERS, tep_get_all_get_params(array('oID', 'action')));
        break;
    }
  }

  $OSCOM_Hooks->call('Orders', 'Action');

  $show_listing = true;

  require(DIR_WS_INCLUDES . 'template_top.php');
?>

<h2><i class="fa fa-shopping-cart"></i> <a href="<?= OSCOM::link('orders.php'); ?>"><?= HEADING_TITLE; ?></a></h2>

<?php
  if (!empty($action)) {
    if (($action == 'edit') && isset($order)) {
      $show_listing = false;
?>

<h3><?= '#' . $order->info['id'] . ' (' . strip_tags($order->info['total']) . ')'; ?></h3>

<div style="text-align: right; padding-bottom: 15px;"><?php echo HTML::button(IMAGE_ORDERS_INVOICE, 'fa fa-file-o', OSCOM::link(FILENAME_ORDERS_INVOICE, 'oID=' . $_GET['oID']), null, array('newwindow' => true)) . HTML::button(IMAGE_ORDERS_PACKINGSLIP, 'fa fa-file', OSCOM::link(FILENAME_ORDERS_PACKINGSLIP, 'oID=' . $_GET['oID']), null, array('newwindow' => true)) . HTML::button(IMAGE_BACK, 'fa fa-chevron-left', OSCOM::link(FILENAME_ORDERS, tep_get_all_get_params(array('action')))); ?></div>

<div id="orderTabs">
  <ul class="nav nav-tabs">
    <li class="active"><a data-target="#section_summary_content" data-toggle="tab"><?= 'Summary'; ?></a></li>
    <li><a data-target="#section_products_content" data-toggle="tab"><?= 'Products'; ?></a></li>
    <li><a data-target="#section_status_history_content" data-toggle="tab"><?= 'History'; ?></a></li>
  </ul>

  <div class="tab-content">
    <div id="section_summary_content" class="tab-pane active oscom-m-top-15">
      <div class="row">
        <div class="col-sm-4">
          <div class="panel panel-info">
            <div class="panel-heading">
              <h3 class="panel-title"><?= ENTRY_CUSTOMER; ?></h3>
            </div>

            <div class="panel-body">
              <p><?= tep_address_format($order->customer['format_id'], $order->customer, 1, '', '<br />'); ?></p>
              <p><?= '<i class="fa fa-fw fa-phone"></i> ' . $order->customer['telephone'] . '<br /><i class="fa fa-fw fa-envelope-o"></i> ' . '<a href="mailto:' . $order->customer['email_address'] . '"><u>' . $order->customer['email_address'] . '</u></a>'; ?></p>
            </div>
          </div>
        </div>
<commit_msg>update buttons<commit_after><?php
/*
  $Id$

  osCommerce, Open Source E-Commerce Solutions
  http://www.oscommerce.com

  Copyright (c) 2014 osCommerce

  Released under the GNU General Public License
*/

  use OSC\OM\HTML;
  use OSC\OM\OSCOM;
  use OSC\OM\Registry;

  require('includes/application_top.php');

  $OSCOM_Hooks = Registry::get('Hooks');

  require(DIR_WS_CLASSES . 'currencies.php');
  $currencies = new currencies();

  $orders_statuses = [];
  $orders_status_array = [];

  $Qstatus = $OSCOM_Db->get('orders_status', [
    'orders_status_id',
    'orders_status_name'
  ], [
    'language_id' => (int)$_SESSION['languages_id']
  ]);

  while ($Qstatus->fetch()) {
    $orders_statuses[] = [
      'id' => $Qstatus->valueInt('orders_status_id'),
      'text' => $Qstatus->value('orders_status_name')
    ];

    $orders_status_array[$Qstatus->valueInt('orders_status_id')] = $Qstatus->value('orders_status_name');
  }

  include(DIR_WS_CLASSES . 'order.php');

  if (isset($_GET['oID']) && is_numeric($_GET['oID']) && ($_GET['oID'] > 0)) {
    $oID = HTML::sanitize($_GET['oID']);

    $Qorders = $OSCOM_Db->get('orders', 'orders_id', ['orders_id' => (int)$oID]);

    if ($Qorders->fetch()) {
      $order = new order($Qorders->valueInt('orders_id'));
    } else {
      $OSCOM_MessageStack->add(sprintf(ERROR_ORDER_DOES_NOT_EXIST, $oID), 'error');
    }
  }

  if (!isset($_GET['page']) || !is_numeric($_GET['page'])) {
    $_GET['page'] = 1;
  }

  $action = (isset($_GET['action']) ? $_GET['action'] : '');

  $OSCOM_Hooks->call('Orders', 'PreAction');

  if (tep_not_null($action)) {
    switch ($action) {
      case 'update_order':
        $oID = HTML::sanitize($_GET['oID']);
        $status = HTML::sanitize($_POST['status']);
        $comments = HTML::sanitize($_POST['comments']);

        $order_updated = false;

        $Qcheck = $OSCOM_Db->get('orders', [
          'customers_name',
          'customers_email_address',
          'orders_status',
          'date_purchased'
        ], [
          'orders_id' => (int)$oID
        ]);

        if ( ($Qcheck->value('orders_status') != $status) || tep_not_null($comments)) {
          $OSCOM_Db->save('orders', [
            'orders_status' => $status,
            'last_modified' => 'now()'
          ], [
            'orders_id' => (int)$oID
          ]);

          $customer_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 = STORE_NAME . "\n" . EMAIL_SEPARATOR . "\n" . EMAIL_TEXT_ORDER_NUMBER . ' ' . $oID . "\n" . EMAIL_TEXT_INVOICE_URL . ' ' . OSCOM::link('Shop/' . FILENAME_CATALOG_ACCOUNT_HISTORY_INFO, 'order_id=' . $oID, 'SSL') . "\n" . EMAIL_TEXT_DATE_ORDERED . ' ' . tep_date_long($Qcheck->value('date_purchased')) . "\n\n" . $notify_comments . sprintf(EMAIL_TEXT_STATUS_UPDATE, $orders_status_array[$status]);

            tep_mail($Qcheck->value('customers_name'), $Qcheck->value('customers_email_address'), EMAIL_TEXT_SUBJECT, $email, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS);

            $customer_notified = '1';
          }

          $OSCOM_Db->save('orders_status_history', [
            'orders_id' => (int)$oID,
            'orders_status_id' => $status,
            'date_added' => 'now()',
            'customer_notified' => $customer_notified,
            'comments' => $comments
          ]);

          $order_updated = true;
        }

        if ($order_updated == true) {
         $OSCOM_MessageStack->add(SUCCESS_ORDER_UPDATED, 'success');
        } else {
          $OSCOM_MessageStack->add(WARNING_ORDER_NOT_UPDATED, 'warning');
        }

        OSCOM::redirect(FILENAME_ORDERS, tep_get_all_get_params(array('action')) . 'action=edit');
        break;
      case 'deleteconfirm':
        $oID = HTML::sanitize($_GET['oID']);

        tep_remove_order($oID, $_POST['restock']);

        OSCOM::redirect(FILENAME_ORDERS, tep_get_all_get_params(array('oID', 'action')));
        break;
    }
  }

  $OSCOM_Hooks->call('Orders', 'Action');

  $show_listing = true;

  require(DIR_WS_INCLUDES . 'template_top.php');
?>

<h2><i class="fa fa-shopping-cart"></i> <a href="<?= OSCOM::link('orders.php'); ?>"><?= HEADING_TITLE; ?></a></h2>

<?php
  if (!empty($action)) {
    if (($action == 'edit') && isset($order)) {
      $show_listing = false;
?>

<h3><?= '#' . $order->info['id'] . ' (' . strip_tags($order->info['total']) . ')'; ?></h3>

<div style="text-align: right; padding-bottom: 15px;"><?= HTML::button(IMAGE_BACK, 'fa fa-chevron-left', OSCOM::link(FILENAME_ORDERS, tep_get_all_get_params(array('action'))), null, null, 'btn-info') . HTML::button(IMAGE_ORDERS_INVOICE, 'fa fa-file-text-o', OSCOM::link(FILENAME_ORDERS_INVOICE, 'oID=' . $_GET['oID']), null, array('newwindow' => true), 'btn-primary') . HTML::button(IMAGE_ORDERS_PACKINGSLIP, 'fa fa-clipboard', OSCOM::link(FILENAME_ORDERS_PACKINGSLIP, 'oID=' . $_GET['oID']), null, array('newwindow' => true), 'btn-primary'); ?></div>

<div id="orderTabs">
  <ul class="nav nav-tabs">
    <li class="active"><a data-target="#section_summary_content" data-toggle="tab"><?= 'Summary'; ?></a></li>
    <li><a data-target="#section_products_content" data-toggle="tab"><?= 'Products'; ?></a></li>
    <li><a data-target="#section_status_history_content" data-toggle="tab"><?= 'History'; ?></a></li>
  </ul>

  <div class="tab-content">
    <div id="section_summary_content" class="tab-pane active oscom-m-top-15">
      <div class="row">
        <div class="col-sm-4">
          <div class="panel panel-info">
            <div class="panel-heading">
              <h3 class="panel-title"><?= ENTRY_CUSTOMER; ?></h3>
            </div>

            <div class="panel-body">
              <p><?= tep_address_format($order->customer['format_id'], $order->customer, 1, '', '<br />'); ?></p>
              <p><?= '<i class="fa fa-fw fa-phone"></i> ' . $order->customer['telephone'] . '<br /><i class="fa fa-fw fa-envelope-o"></i> ' . '<a href="mailto:' . $order->customer['email_address'] . '"><u>' . $order->customer['email_address'] . '</u></a>'; ?></p>
            </div>
          </div>
        </div>

{'fraction_non_alphanumeric': 0.2084716295242611, 'fraction_numerical': 0.00316105579263474, 'mean_word_length': 3.2494963062458027, 'pattern_counts': {'":': 0, '<': 131, '<?xml version=': 0, '>': 219, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2815874', 'n_tokens_mistral': 4515, 'n_tokens_neox': 4440, 'n_words': 653}