function Update($arFields) { global $DB, $APPLICATION; $aMsg = array(); $USER_ID = intval($arFields["USER_ID"]); if ($USER_ID) { if ($arFields["ACTIVE"] !== "Y") { CSecurityUser::Deactivate($USER_ID); } else { $secret = substr(trim($arFields["SECRET"]), 0, 64); if (strlen($secret) <= 0) { CSecurityUser::Delete($USER_ID); } else { $rsKey = $DB->Query("SELECT * from b_sec_user WHERE USER_ID = " . $USER_ID); $arKey = $rsKey->Fetch(); if ($arKey && $arKey["SECRET"] == $secret) { $cnt = intval($arKey["COUNTER"]); } else { $cnt = 0; } $sync1 = trim($arFields["SYNC1"]); $sync2 = trim($arFields["SYNC2"]); if ($sync1 || $sync2) { $bin_secret = pack('H*', $secret); $cnt = CSecurityUser::GetSyncCounter($bin_secret, $sync1, $sync2, $aMsg); } if ($arKey) { $DB->Query("\n\t\t\t\t\t\t\tUPDATE b_sec_user SET\n\t\t\t\t\t\t\t\tACTIVE = 'Y',\n\t\t\t\t\t\t\t\tSECRET = '" . $DB->ForSQL($secret) . "',\n\t\t\t\t\t\t\t\tCOUNTER = " . $cnt . "\n\t\t\t\t\t\t\tWHERE USER_ID = " . $USER_ID . "\n\t\t\t\t\t\t"); } else { $DB->Query("\n\t\t\t\t\t\t\tINSERT INTO b_sec_user (\n\t\t\t\t\t\t\t\tUSER_ID, ACTIVE, SECRET, COUNTER\n\t\t\t\t\t\t\t) VALUES (\n\t\t\t\t\t\t\t\t" . $USER_ID . ", 'Y', '" . $DB->ForSQL($secret) . "', " . $cnt . ")\n\t\t\t\t\t\t"); } } } } if (count($aMsg) > 0) { $e = new CAdminException($aMsg); $APPLICATION->ThrowException($e); return false; } return true; }