<?php

/**
 * [BEGIN_COT_EXT]
 * Hooks=marketorders.order.tags
 * [END_COT_EXT]
 */

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

/** выведет похожие сообщения которые относятся к заказу */

/*
$dsjj = 0;
if($marketorder['order_userid'] > 0 && $marketorder['order_seller'] > 0) {
  require_once cot_incfile('ds', 'module');

  $ds_dialog = $db->query("SELECT * FROM $db_ds_dialog WHERE (fromid=".$marketorder['order_userid']." AND toid=".$marketorder['order_seller'].") OR (fromid=".$marketorder['order_seller']." AND toid=".$marketorder['order_userid'].") LIMIT 1")->fetch();
  if($ds_dialog['id'] > 0) {
    $dsfromid = ($ds_dialog['fromid'] == $marketorder['order_userid']) ? $ds_dialog['fromid'] : $ds_dialog['toid'];  //определяем от кого переписка
    $opponent = ($ds_dialog['fromid'] == $marketorder['order_userid']) ? $ds_dialog['toid'] : $ds_dialog['fromid'];  //определяем c кем переписка
    $act_f = ($ds_dialog['fromid'] == $marketorder['order_userid']) ? 'act_fid' : 'act_tid';

    $ds_lastmsgdate = ($marketorder['order_paid'] > 0 ? $marketorder['order_paid'] : $marketorder['order_date']);
    $ds_break = 0;
    $ds_parse = array();
    $ds_msgs = $db->query("SELECT * FROM $db_ds_msg WHERE dialog=".$ds_dialog['id']." AND $act_f!=0 AND date<".$ds_lastmsgdate." AND mtype!=4 ORDER BY id DESC LIMIT 25")->fetchAll();
    $ds_lastmsgdate -= 86400;
    $ds_lastmsgstep = 43200;

    foreach($ds_msgs as $row) {
      if($row['date'] > ($ds_lastmsgdate-$ds_lastmsgstep)) {
        $ds_lastmsgdate = $row['date'];
      } else {
        $ds_break = 1;
      }
      if($row['mtype'] > 0) {
        $ds_lastmsgstep = $ds_lastmsgstep/2;
        //{DS_ROW_MDATA.orderId}
      }
      if(!$ds_break) {
        $ds_parse[] = $row;
      } else {
        break;
      }
    }

    krsort($ds_parse);

    $opptags = cot_generate_usertags($opponent, 'DS_ROW_USER_');
    $usrtags = cot_generate_usertags($dsfromid, 'DS_ROW_USER_');

    foreach($ds_parse as $row) {
      $dsjj++;

      $mdata = cot_ds_get_mdata($row['mtype'], $row['mdata']);
      $pretext = '';

      if($row['mtype'] == 5) {
        $mdata['item_url'] = '<a href="'.cot_url('market', 'id='.$mdata['item_id']).'">'.$mdata['item_title'].'</a>';
        $pretext = cot_rc($cfg['ds']['mtypes_notytitle'][5], array('item_title' => $mdata['item_url']));
      } elseif($row['mtype'] == 6) {
        $mdata['item_url'] = '<a href="'.cot_url('projects', 'id='.$mdata['item_id']).'">'.$mdata['item_title'].'</a>';
        $pretext = cot_rc($cfg['ds']['mtypes_notytitle'][6], array('item_title' => $mdata['item_url']));
      }

      $t->assign(array(
        'DS_ROW_JJ' => $dsjj,
  			'DS_ROW_ID' => $row['id'],
  			'DS_ROW_DATE' => cot_date('H:i', $row['date']),
  			'DS_ROW_TEXT' => $row['text'],
        'DS_ROW_RESEND' => cot_ds_resend_msg($row['resend']),
        'DS_ROW_STATUS' => $row['status'],
        'DS_ROW_STAR' => ($row[$act_f] == 2 ? 1 : 0),
        'DS_ROW_MTYPE' => $row['mtype'],
        'DS_ROW_MDATA' => $mdata,
        'DS_ROW_PRETEXT' => $pretext,
  		));

      if ($row['touser'] == $dsfromid){
        $t->assign($opptags);
      } else {
  		  $t->assign($usrtags);
      }

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

  }
}

$t->assign(array(
	"ORDER_SAME_DS_CNT" => $dsjj,
));

*/
