<?php

/**
 * [BEGIN_COT_EXT]
 * Hooks=ds.ajax.send.first
 * [END_COT_EXT]
 */

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

require_once cot_incfile('mavatars', 'plug');

$conversations_files = cot_import('conversations-files', 'P', 'ARR');

$mavatar = new mavatar('ds', $chatid, '', 'edit');
$mavatars_count_tmp = $mavatar->tags();

$$mavatars_count = array();

if(is_array($conversations_files['delete']) && count($conversations_files['delete']) > 0) {
  foreach($mavatars_count_tmp as $key => $dfile) {
    if(!in_array($dfile['ID'], $conversations_files['delete'])) {
      $mavatars_count[$key] = $dfile;
    } else {
      $mavatar->delete_mavatar_byid($dfile['ID']);
    }
  }
} else {
  $mavatars_count = $mavatars_count_tmp;
}