<?php
/* ====================
  [BEGIN_COT_EXT]
  Hooks=global
  [END_COT_EXT]
  ==================== */

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

require_once cot_incfile('ads', 'plug');
require_once cot_incfile('payments', 'module');
require_once cot_incfile('market', 'module');

if ($adspays = cot_payments_getallpays('ads', 'paid'))
{
	foreach ($adspays as $pay)
	{	
    $expire = $sys['now'] + $pay['pay_time'];

    if($pay['pay_code'] > 0) {
      $ads = $db->query("SELECT * FROM $db_ads WHERE item_id=".$pay['pay_code']." LIMIT 1")->fetch();

      if($ads['item_id'] > 0) {
    		if(cot_payments_updatestatus($pay['pay_id'], 'done'))
    		{
    			$db->update($db_ads, array('item_expire' => (int)$expire, 'item_begin' => $sys['now']), "item_id=".(int)$ads['item_id']);

          global $ads_positions_special;

          if($ads['item_position'] == $ads_positions_special['market_showonindex'] && $ads['item_marketid'] > 0) {
            $db->update($db_market, array('item_showonindex' => 1), 'item_id='.$ads['item_marketid']);
          }

    			/* === Hook === */
    			foreach (cot_getextplugins('payads.done') as $pl)
    			{
    				include $pl;
    			}
    			/* ===== */
    		}
      }
    }
	}
}