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

$return['success'] = true;
$return['data'] = array(
  'status' => 'none',
  'message' => 'Вы должны быть авторизованы',
);

if($usr['id'] > 0) {
  if($usr['ban']['banned'] && $usr['ban']['block']['market_seller']) {
    cot_error('Вы не можете активировать '.cot_sitename('padeg', '_i').', из за временной блокировки.');
    $return['data']['status'] = 'busy';
  } else {
    require_once cot_incfile('market', 'module');

    $status = cot_import('status', 'P', 'TXT');
    $switch_all = (isset($_POST['switch_all']) ? cot_import('switch_all', 'P', 'INT') : 1);
    if($status == 'busy') {
      $return['data']['status'] = 'busy';
      $db->update($db_market, array('item_update_real' => ($sys['now']-1)), "item_userid=".$usr['id'].' AND item_state=1');
      $db->update($db_market, array('item_update_real' => ($sys['now']-1), 'item_state' => 1), "item_userid=".$usr['id'].' AND item_state!=3 AND item_state!=-1');
      $db->update($db_users, array('user_workstatus' => $sys['now']), 'user_id='.$usr['id']);
    } else {
      //if($db->query("SELECT COUNT(*) FROM $db_market WHERE item_userid=".$usr['id'].' AND item_state=0 AND item_ismoder!=0')->fetchColumn() == 0) {
      //  $return['data']['message'] = 'У Вас нет активных '.cot_sitename('padeg', '_r');
      //} else {
        if(!$usr['profile']['user_workstatus']) $usr['profile']['user_workstatus'] = $sys['now'];
        $db->update($db_market, array('item_update_real' => ($sys['now']-1), 'item_state' => 0), "item_userid=".$usr['id'].' AND item_state=1 AND item_ismoder!=0'.($switch_all == 1 ? '' : ' AND item_update_real<'.$usr['profile']['user_workstatus']));
        $db->update($db_market, array('item_update_real' => ($sys['now']-1), 'item_state' => 2), "item_userid=".$usr['id'].' AND item_state=1 AND item_ismoder=0'.($switch_all == 1 ? '' : ' AND item_update_real<'.$usr['profile']['user_workstatus']));

        $db->update($db_users, array('user_workstatus' => 0), 'user_id='.$usr['id']);
        $return['data']['status'] = 'free';
      //}
    }
  }
}

?>
