<?php
/**
 * XTC - EBAY API
 * ADD EBAYTRANSACTION AS CHECKOUT PROCESS
 *
 * @version $Id: ebayapi_crontimer.php,v 1.9 2013/07/25 11:22:52 cvs Exp $
 * @copyright 2004
 * @author: mario aspeleiter <dazze@gmx.de>
 **/

include('includes/application_top.php');

$query = xtc_db_query("SELECT orders_id FROM ".TABLE_ORDERS." WHERE orders_status='".ORDERS_STATUS_UPSELLING."' && ( UNIX_TIMESTAMP( date_purchased )+".(EBAY_XSELL_DAYSPAN*60*60*24)." ) < UNIX_TIMESTAMP( NOW() )");
while($order = xtc_db_fetch_array($query)){
    order::add_history_static($order['orders_id'], 1, false, sprintf(
        "Automatisch nach %d Tagen von -Ebay-Upselling- auf -Offen- gesetzt.",
        EBAY_XSELL_DAYSPAN
    ));
}
$orders_query = xtc_db_query("UPDATE ".TABLE_ORDERS." SET orders_status='1',last_modified=now() WHERE orders_status='".ORDERS_STATUS_UPSELLING."' && ( UNIX_TIMESTAMP( date_purchased )+".(EBAY_XSELL_DAYSPAN*60*60*24)." ) < UNIX_TIMESTAMP( NOW() )");

// NEUEN STATUS BERUECKSICHTIGEN
$status_array = array();
$query = xtc_db_query("SELECT orders_id,orders_status FROM ".TABLE_ORDERS." WHERE (orders_status='".ORDERS_STATUS_UPSELLING."' or orders_status='".ORDERS_STATUS_VERSENDET."' or orders_status='1' or orders_status='2') and ( ( UNIX_TIMESTAMP(warning_span_date) + ( (60*60*24) * warning_span ) ) < UNIX_TIMESTAMP( NOW() ) ) and warning_span > 0");
while($order = xtc_db_fetch_array($query)){
    $status_array[] = $order;
}
if(sizeOf($status_array)){
    foreach($status_array as $order){
        order::add_history_static($order['orders_id'], $order['orders_status'], false, 
            'Automatisch wieder ins Mahnwesen integriert.'
        );
    }
}
$orders_query = xtc_db_query("UPDATE ".TABLE_ORDERS." SET warning_span=0,warning_span_date='0000-00-00 00:00:00',no_warning='0',last_modified=now() WHERE  (orders_status='".ORDERS_STATUS_UPSELLING."' or orders_status='".ORDERS_STATUS_VERSENDET."' or orders_status='1' or orders_status='2') and ( ( UNIX_TIMESTAMP(warning_span_date) + ( (60*60*24) * warning_span ) ) < UNIX_TIMESTAMP( NOW() ) ) and warning_span > 0");
