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

$id = cot_import('id', 'G', 'TXT');

if($usr['id'] > 0 || ($usr['isadmin'] && $id > 0)) {
  $urr = $db->query("SELECT * FROM $db_users WHERE user_id=".(($usr['isadmin'] && $id > 0) ? $id : $usr['id']).' LIMIT 1')->fetch();

  if($urr['user_id'] > 0) {
    if($a == 'usertype') {
      $usertype = cot_import('usertype', 'G', 'INT');
        $userTypes = array(
          1 => 7, //Покупатель
          2 => 4, //Продавец
          4 => 4, //Покупатель
          7 => 7, //Продавец
        );
        if(cot_plugin_active('usergroupselector') && $usertype > 0 && $userTypes[$usertype] > 0) {
          $ruser = array(
            'user_usergroup' => $userTypes[$usertype]
          );
          if(in_array($urr['user_maingrp'], array(4, 7))) {
            $db->update($db_users, array('user_auth' => '', 'user_maingrp' => $ruser['user_usergroup'], 'user_usergroup' => $ruser['user_usergroup']), "user_id=".$urr['user_id']);
            $db->update($db_groups_users, array('gru_groupid' => $ruser['user_usergroup']), "gru_userid=".$urr['user_id']);
          }

          $return['success'] = 1;
        }
    }
  }
}

?>
