<?php
defined('COT_CODE') or die('Wrong URL');

$return['success'] = 1;

$inboxId = cot_import('inboxId', 'G', 'INT');
$score = cot_import('score', 'G', 'INT');
$check = cot_import('check', 'G', 'INT');

if($score > 5) $score = 5;

if($inboxId > 0 && $score > 0 && $usr['id'] > 0 && !in_array($usr['maingrp'], $cfg['ds']['supportinfo']['modergroups'])) {
  require_once cot_incfile('ds', 'module');
  $supportchat = cot_create_chat($usr['id'], 0);
  $msg = $db->query("SELECT * FROM $db_ds_msg WHERE id=".$inboxId.' AND dialog='.$supportchat.' AND fruser>0 LIMIT 1')->fetch();

  if($msg['id'] > 0) {
    $newscore = array(
      's_date' => $sys['now'],
      's_mid' => $msg['id'],
      's_touid' => $msg['fruser'],
      's_score' => $score,
      's_modvis' => ($check ? 1 : 0)
    );

    if($db->query("SELECT * FROM $db_ds_score WHERE s_mid=".$msg['id'].' LIMIT 1')->fetchColumn() > 0) {
      $db->update($db_ds_score, $newscore, 's_mid='.$msg['id']);
    } else {
      $db->insert($db_ds_score, $newscore);
    }
  }
}

?>
