<?php

/**
 * [BEGIN_COT_EXT]
 * Hooks=api.getCertificates.usertags,api.getPortfolio.usertags
 * [END_COT_EXT]
 */

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

if($uid > 0) {
  require_once cot_incfile('rewards', 'plug');

  $rewardsql = $db->query("SELECT * FROM $db_rewards_owners as rewards_owners
    JOIN $db_rewards as rewards ON rewards.r_id=rewards_owners.rid
    WHERE rewards_owners.uid=".$uid."
    ORDER BY rewards_owners.odate DESC
    ")->fetchAll();

  $rewards = array();
  foreach($rewardsql as $reward) {
    $rewards[] = array(
      'date' => cot_date('d.m.Y H:i', $reward['odate']),
  	  'title' => $reward['r_title'],
      'desc' => $reward['r_desc'],
  	  'img' => $rewards_path.(file_exists($rewards_path . $reward['r_id'] . '.png') ? $reward['r_id'] : '0').'.png',
    );
  }

  if($usr['id'] > 0 && $usr['id'] == $uid) $db->update($db_rewards_owners, array('oview' => $sys['now']), 'uid='.$uid);

  $t->assign(array(
    'USER_TAGS_REWARDS_CNT' => count($rewards),
    'USER_TAGS_REWARDS' => $rewards,
  ));
}