<?php

/* ====================
  [BEGIN_COT_EXT]
  Hooks=ds.dialog.tags,projects.tags
  [END_COT_EXT]
  ==================== */

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

if($usr['id'] > 0) {
  require_once cot_incfile('market', 'module');

  $user_marketitems = $db->query("SELECT * FROM $db_market WHERE item_userid=".$usr['id'].' AND item_state=0 '.(!empty($onlythiscat) ? ' AND (item_cat="'.$onlythiscat.'" OR item_catattr="'.$onlythiscat.'")' : '').' ORDER BY item_title ASC')->fetchAll();
  foreach($user_marketitems as $mkitem) {
    $mktags = cot_generate_markettags($mkitem, 'PRD_ROW_', $cfg['market']['shorttextlen'], $usr['isadmin'], $cfg['homebreadcrumb']);

    $mktags['PRD_ROW_PACKAGE'] = $mktags['PRD_ROW_COSTPLAN']['package'];
    $mktags['PRD_ROW_DAYS'] = $mktags['PRD_ROW_COSTPLAN']['days'];
    $mktags['PRD_ROW_COST'] = $mktags['PRD_ROW_COSTPLAN']['price'];
    $mktags['PRD_ROW_COST_WORKER'] = ($mktags['PRD_ROW_COST']-$mktags['PRD_ROW_COST']*($market_crt/100));
    $t->assign($mktags);

    if($mktags['PRD_ROW_PACKAGE']) {
      $item_catcostplans = (!empty($mkitem['item_catcostplans']) ? json_decode($mkitem['item_catcostplans'], 1) : array());
      if(!is_array($item_catcostplans)) $item_catcostplans = array('bundle_type' => 'none');
      if($item_catcostplans['bundle_type'] == "package") {
        foreach(array('standard', 'medium', 'premium') as $type) {
          $item_catcostplans['bundles'][$type]['payerPrice'] = $item_catcostplans['bundles'][$type]['price']-$item_catcostplans['bundles'][$type]['price']*($market_crt/100);
        }
        $t->assign(array(
          'PRD_ROW_PACKAGE_DATA' => $item_catcostplans['bundles'],
        ));
        $t->parse('MAIN.MARKET_PACKAGE');
      }
    }

    $t->parse('MAIN.MARKET_USERITEMS');
  }

  $t->assign(array(
    'MARKET_CRT' => $market_crt,
    'MARKET_WORKERPRICE' => (500-500*($market_crt/100))
  ));
}
