<?php

/**
 * [BEGIN_COT_EXT]
 * Hooks=users.details.tags
 * [END_COT_EXT]
 */

defined('COT_CODE') or die('Wrong URL');
require_once cot_incfile('portfolio', 'module');

list($usr['auth_read'], $usr['auth_write'], $usr['isadmin']) = cot_auth('portfolio', 'any', 'RWA');
if(!$usr['isadmin'] && $usr['maingrp'] == 6) $usr['isadmin'] = true;

$t1 = new XTemplate(cot_tplfile(array('portfolio', 'userdetails'), 'module'));

$where = array();
$order = array();

if(!$usr['isadmin'] && $urr['user_id'] != $usr['id']) $where['state'] = "item_state=0";
$where['owner'] = "item_userid=" . $urr['user_id'];
$order['date'] = "item_date DESC";

/* === Hook === */
foreach (cot_getextplugins('portfolio.userdetails.query') as $pl)
{
	include $pl;
}
/* ===== */

$where = ($where) ? 'WHERE ' . implode(' AND ', $where) : '';
$order = ($order) ? 'ORDER BY ' . implode(', ', $order) : '';

$portfolio_count_all = $db->query("SELECT COUNT(*) FROM $db_portfolio AS f
	" . $where)->fetchColumn();

$sqllist = $db->query("SELECT * FROM $db_portfolio AS f
	" . $where . "
	" . $order);

$sqllist_rowset = $sqllist->fetchAll();
$sqllist_idset = array();
foreach($sqllist_rowset as $item)
{
	$sqllist_idset[$item['item_id']] = $item['item_alias'];
}

/* === Hook === */
$extp = cot_getextplugins('portfolio.userdetails.loop');
/* ===== */

$jj=0;
foreach($sqllist_rowset as $item)
{
  $jj++;
	$t1->assign(cot_generate_portfoliotags($item, 'PRD_ROW_', 300, $usr['isadmin'], $cfg['homebreadcrumb']));
	
	/* === Hook === */
	foreach ($extp as $pl)
	{
		include $pl;
	}
	/* ===== */

	$t1->parse("MAIN.PRD_ROWS");
}

/* === Hook === */
foreach (cot_getextplugins('portfolio.userdetails.tags') as $pl)
{
	include $pl;
}
/* ===== */

$t1->parse("MAIN");

$t->assign(array(
	"USERS_DETAILS_PORTFOLIO_COUNT" => $portfolio_count_all,
));

$t->assign('PORTFOLIO', $t1->text("MAIN"));