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

$return['success'] = 0;
$return['notfind'] = 0;
$return['error'] = '';

$id = cot_import('id', 'P', 'INT');
$newtext = cot_import('msg', 'P', 'TXT');

if(!empty($newtext) && $usr['id'] > 0) {
  if($id > 0) {
    $return['notfind'] = 1;
    $return['error'] = 'Сообщение не найдено';

    list($usr['auth_read'], $usr['auth_write'], $usr['isadmin']) = cot_auth('ds', 'a');
    if(in_array($usr['maingrp'], $cfg['ds']['supportinfo']['modergroups'])) $usr['isadmin'] = true;

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

    $msg = $db->query("SELECT * FROM $db_ds_msg WHERE id=".$id.' AND fruser='.$usr['id'].' LIMIT 1')->fetch();

    if($msg['id'] > 0) {
      if($msg['status'] == 1) {
        $return['notfind'] = 0;
        $return['error'] = '';
        $return['success'] = 1;
        $db->update($db_ds_msg, array('text' => $newtext), 'id='.$msg['id']);
      } else {
        $return['error'] = 'Сообщение уже прочитано';
      }
    }
  }
}

?>