<?php

/**
 * [BEGIN_COT_EXT]
 * Hooks=api.project_get_Details
 * [END_COT_EXT]
 */

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

if($item_cache['item_id'] > 0) {
  require_once cot_incfile('mavatars', 'plug');

  $mavatar_description = new mavatar('market', 'description', $item_cache['item_id'], '');
  $mavatar_instruction = new mavatar('market', 'instruction', $item_cache['item_id'], '');

  $mavatar_files = array();

  foreach($mavatar_description->tags() as $mav) {
    $mav['FILEEXTICON'] = 'doc';
    if(cot_mavatar_is_photo($mav['FILEEXT'])) {
      $mav['FILEEXTICON'] = 'image';
    } elseif(cot_mavatar_is_audio($mav['FILEEXT'])) {
      $mav['FILEEXTICON'] = 'audio';
    } elseif($mav['FILEEXT'] == 'zip' || $mav['FILEEXT'] == 'rar') {
      $mav['FILEEXTICON'] = 'zip';
    }

    $mavatar_files[] = array(
      'id' => $mav['ID'],
      'name' => $mav['FILEORIGNAME'] . '.' . $mav['FILEEXT'],
      'path' => $mav['FILEPATH'],
      'exticon' => $mav['FILEEXTICON']
    );
  }

  foreach($mavatar_instruction->tags() as $mav) {
    $mav['FILEEXTICON'] = 'doc';
    if(cot_mavatar_is_photo($mav['FILEEXT'])) {
      $mav['FILEEXTICON'] = 'image';
    } elseif(cot_mavatar_is_audio($mav['FILEEXT'])) {
      $mav['FILEEXTICON'] = 'audio';
    } elseif($mav['FILEEXT'] == 'zip' || $mav['FILEEXT'] == 'rar') {
      $mav['FILEEXTICON'] = 'zip';
    }

    $mavatar_files[] = array(
      'id' => $mav['ID'],
      'name' => $mav['FILEORIGNAME'] . '.' . $mav['FILEEXT'],
      'path' => $mav['FILEPATH'],
      'exticon' => $mav['FILEEXTICON']
    );
  }

  if(count($mavatar_files) > 0) {
    $return['content']['files'] = '<div id="list-files" class="mt10 pl10 pr20 files-list">';
    foreach($mavatar_files as $mav) {
      $return['content']['files'] .= '<div id="id'.$mav['id'].'" class="mb5">
          <a href="'.$mav['path'].$mav['name'].'" target="_blank" class="color-text">
            <i class="ico-file-'.$mav['exticon'].' dib v-align-m"></i>
            <span class="dib v-align-m ml10 mw80p">'.$mav['name'].'</span>
          </a>
        </div>';
    }
    $return['content']['files'] .= '</div>';
  }

  unset($mavatar_description,$mavatar_instruction,$mavatar_files);
}