<?php

/**
 * [BEGIN_COT_EXT]
 * Hooks=index.tags
 * [END_COT_EXT]
 */

defined('COT_CODE') or die('Wrong URL');

$mk_footer_info = array(
  'all_active_market' => $db->query("SELECT COUNT(*) FROM $db_market WHERE item_state=0 AND item_ismoder!=0")->fetchColumn(),
  'avg_worktime' => $db->query("SELECT AVG((100 / order_deadline) * order_worktime) FROM $db_market_orders
      WHERE order_paid>0 AND order_paid>".($sys['now']-86400*30*3)." AND order_worktime>0 AND order_status='done'")->fetchColumn(),
  'avg_worktime_gap' => '1 день',
  'avg_worktime_gap_expimp' => '1 <span>день</span>',
  'new_market_week' => $db->query("SELECT COUNT(*) FROM $db_market WHERE item_date>".($sys['now']-86400*7)." AND item_state=0 AND item_ismoder!=0")->fetchColumn(),
);

if($mk_footer_info['avg_worktime'] > 0) {
  $mk_footer_info['avg_worktime_gap'] = cot_build_timegap((int)($sys['now'] - $mk_footer_info['avg_worktime']));

  $extimp_new = array();
  $extimp_wgap = explode(" ", $mk_footer_info['avg_worktime_gap']);
  $jj = 0;
  foreach($extimp_wgap as $val) {
    $extimp_new[] = (($jj==1) ? '<span>'.$val.'</span>' : $val);
    $jj = ($jj==0) ? 1 : 0;
  }
  $mk_footer_info['avg_worktime_gap_expimp'] = implode(" ", $extimp_new);
}

$mk_footer_info['all_active_market'] = number_format(($mk_footer_info['all_active_market'] > 0 ? $mk_footer_info['all_active_market'] : 0), 0, '', ' ');
$mk_footer_info['all_active_market_label'] = cot_sitename('declension', 'all_active_market_label', 'declension', $mk_footer_info['all_active_market'], true);

$mk_footer_info['new_market_week'] = number_format(($mk_footer_info['new_market_week'] > 0 ? $mk_footer_info['new_market_week'] : 0), 0, '', ' ');
$mk_footer_info['new_market_week_label'] = cot_sitename('declension', 'new_market_week_label', 'declension', $mk_footer_info['new_market_week'], true);

/*
  //<span class="f34" style="line-height:30px;">1</span> день <span class="f34" style="line-height:30px;">6</span> часов

    $orders = $db->query("SELECT order_deadline, order_worktime FROM $db_market_orders as o
      WHERE order_paid>0 AND order_worktime>0 AND order_status!='new' AND order_pid=".$item['item_id']." AND order_seller=".$item['item_userid'])->fetchAll();

    foreach($orders as $ord) {
      $work_speed[] = (100 / $ord['order_deadline']) * ($ord['order_worktime']);
*/

//$out['market_lastord'] = $db->query("SELECT order_paid FROM $db_market_orders WHERE order_paid>0 ORDER BY order_paid DESC LIMIT 1")->fetchColumn();
//$out['market_lastord'] = cot_build_timeago($out['market_lastord']);