<?php

/**
 * [BEGIN_COT_EXT]
 * Hooks=users.edit.update.first
 * [END_COT_EXT]
 */

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

$paychgblock = cot_import('ruser_paychgblock','P','TXT');
$paychgblock = (!empty($paychgblock) ? cot_date2stamp($paychgblock, 'd.m.Y H:i') : 0);
$ruser['user_paychgblock'] = ($paychgblock > $sys['now'] ? $paychgblock : 0);

$payoutsblock = cot_import('ruser_payoutsblock','P','TXT');
$payoutsblock = (!empty($payoutsblock) ? cot_date2stamp($payoutsblock, 'd.m.Y H:i') : 0);
$ruser['user_payoutsblock'] = ($payoutsblock > $sys['now'] ? $payoutsblock : 0);

$purse_fname = cot_import('ruser_purse_fname','P','TXT', 255);
$purse_lname = cot_import('ruser_purse_lname','P','TXT', 255);
$purse_fcard = cot_import('ruser_purse_fcard','P','TXT');

$ruser['user_payment_card_num'] = $purse_fcard;
$ruser['user_payment_card_fn'] = $purse_fname;
$ruser['user_payment_card_ln'] = $purse_lname;

$yandex_purse = cot_import('ruser_purse_yandex','P','TXT', 15);
$wm_purse = cot_import('ruser_purse_wm','P','TXT', 20);
$qiwi_purse = cot_import('ruser_purse_qiwi','P','TXT', 50);

if (!empty($yandex_purse) && $yandex_purse != $urr['user_payment_yandex']) {
  if ($db->query("SELECT COUNT(*) FROM $db_users WHERE user_payment_yandex='".$yandex_purse."' AND user_id!=".$urr['user_id']." LIMIT 1")->fetchColumn() > 0) cot_error('Данный Яндекс.Деньги кошелек уже есть в базе данных.', 'yandex_purse');
  $ruser['user_payment_yandex'] = $yandex_purse;
}
if (!empty($qiwi_purse) && $qiwi_purse != $urr['user_payment_qiwi']) {
  if ($db->query("SELECT COUNT(*) FROM $db_users WHERE user_payment_qiwi='".$qiwi_purse."' AND user_id!=".$urr['user_id']." LIMIT 1")->fetchColumn() > 0) cot_error('Данный Qiwi кошелек уже есть в базе данных.', 'qiwi_purse');
  $ruser['user_payment_qiwi'] = $qiwi_purse;
}
if (!empty($wm_purse) && $wm_purse != $urr['user_payment_wm']) {
  if ($db->query("SELECT COUNT(*) FROM $db_users WHERE user_payment_wm='".$wm_purse."' AND user_id!=".$urr['user_id']." LIMIT 1")->fetchColumn() > 0) cot_error('Данный WebMoney кошелек уже есть в базе данных.', 'wm_purse');
  $ruser['user_payment_wm'] = $wm_purse;
}

?>