<?php
/* ====================
  [BEGIN_COT_EXT]
  Hooks=market.edit.tags
  [END_COT_EXT]
  ==================== */

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

$aditem = array('item_id' => 0, 'byuser' => 0);
if($usr['isadmin']) {
  require_once cot_incfile('ads', 'plug');

  if($ads_positions_special['market_showonindex'] > 0) {
    $ad = $db->query("SELECT * FROM $db_ads WHERE item_userid>0 AND item_marketid=".$id.' AND item_position='.$ads_positions_special['market_showonindex'].' AND (item_paused>0 OR item_expire>'.$sys['now'].') LIMIT 1')->fetch();

    if($ad['item_id'] > 0) {
      $aditem = $ad;
      $aditem['byuser'] = 1;
    } else {
      $ad = $db->query("SELECT * FROM $db_ads WHERE item_userid=0 AND item_marketid=".$id.' AND item_position='.$ads_positions_special['market_showonindex'].' LIMIT 1')->fetch();

      if($ad['item_id'] > 0) {
        $aditem = $ad;
        $aditem['byuser'] = 0;
      }
    }
  }
}
$t->assign('ADS_ITEM', $aditem);