<?php
defined('COT_CODE') or die('Wrong URL');

require_once cot_incfile('market', 'module');
require_once cot_incfile('marketorders', 'plug');

$lastdate = cot_import('lastdate', 'G', 'INT');
if(!$lastdate) $lastdate = 0;

$IS_ORDER_PAGE = cot_import('IS_ORDER_PAGE', 'G', 'INT');

if($usr['id'] > 0) {
  $return = cot_mk_track_stack($lastdate, $IS_ORDER_PAGE);

  /* === Hook === */
  foreach (cot_getextplugins('api.track_stack.main') as $pl)
  {
  	include $pl;
  }
  /* ===== */

  if($return['push']['cntnew']['order'] > 0) {
    $return['push']['order']['tracks'] = array_reverse($return['push']['order']['tracks']);
    $return['push']['order']['hist'] = array_reverse($return['push']['order']['hist']);
  }

  if($return['push']['cntnew']['notify'] > 0) {
    $return['push']['notify'] = array_reverse($return['push']['notify']);
  }
}

$return['status'] = 'success';
//$return['lastdate'] = ($sys['now'] > $lastdate ? $sys['now'] : $lastdate);
$return['user_id'] = $usr['id'];