<?php
/* ====================
  [BEGIN_COT_EXT]
  Hooks=market.index.presearch.loop
  [END_COT_EXT]
  ==================== */

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

if($usr['id'] == 0 || $usr['id'] != $item['item_userid']) {
  require_once cot_incfile('ads', 'plug');

  $ad = $db->query("SELECT * FROM $db_ads WHERE item_marketid=".$item['item_id'].' AND item_position='.$ads_positions_special['market_showonindex'].' AND item_paused=0 LIMIT 1')->fetch();

  if($ad['item_id'] > 0 && $ad['item_expire'] > $sys['now']) {
    ads_tracks($ad['item_id'], 'show');
    $t->assign('IPRD_URL', cot_url('plug', 'e=ads&a=click&id='.$ad['item_id'].'&c='.$c));
  } else {
    $db->update($db_market, array('item_showonindex' => 0), 'item_id='.$item['item_id']);
  }
}