<?php

/**
 * [BEGIN_COT_EXT]
 * Hooks=reward.newreward.done
 * [END_COT_EXT]
 */

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

require_once cot_incfile('ds', 'module');

$urr = $db->query("SELECT * FROM $db_users WHERE user_id=".$ruser.' LIMIT 1')->fetch();
if($urr['user_id'] > 0) {
  if(!in_array($urr['maingrp'], $cfg['ds']['supportinfo']['modergroups'])) {
    $supportchat = cot_create_chat($urr['user_id'], 0);
    if($supportchat > 0) {
      $pm = array();
      $pm['resend'] = json_encode(array());
      $pm['mtype'] = 0;
      $pm['mdata'] = json_encode(array('reward' => $rreward));
      $pm['dialog'] = (int)$supportchat;
      $pm['date'] = (int)$sys['now'];
		  $pm['text'] = 'Получена награда "'.$reward['r_title'].'"<br>'.$reward['r_desc'];
      $pm['fruser'] = 0;
      $pm['touser'] = $urr['user_id'];

      $pmsql = $db->insert($db_ds_msg, $pm);
      $pm['id'] = $db->lastInsertId();

      $state = ($fornewpm['fromid'] == $urr['user_id']) ? array('fromstatus' => '1') : array('tostatus' => '1');
      $db->update($db_ds_dialog, $state, "id = ".(int)$supportchat."");
    }
  }
}

