USE [master]
GO
/****** Object:  Database [mintdata]    Script Date: 11/11/2008 15:50:37 ******/
IF EXISTS (SELECT name FROM master.dbo.sysdatabases WHERE name = N'mintdata')
	DROP DATABASE [mintdata]
GO
CREATE DATABASE [mintdata] 
GO
IF (1 = FULLTEXTSERVICEPROPERTY('IsFullTextInstalled'))
begin
EXEC [mintdata].[dbo].[sp_fulltext_database] @action = 'enable'
end
GO
ALTER DATABASE [mintdata] SET ANSI_NULL_DEFAULT ON
GO
ALTER DATABASE [mintdata] SET ANSI_NULLS ON
GO
ALTER DATABASE [mintdata] SET ANSI_PADDING ON
GO
ALTER DATABASE [mintdata] SET ANSI_WARNINGS OFF
GO
ALTER DATABASE [mintdata] SET ARITHABORT OFF
GO
ALTER DATABASE [mintdata] SET AUTO_CLOSE OFF
GO
ALTER DATABASE [mintdata] SET AUTO_CREATE_STATISTICS ON
GO
ALTER DATABASE [mintdata] SET AUTO_SHRINK OFF
GO
ALTER DATABASE [mintdata] SET AUTO_UPDATE_STATISTICS ON
GO
ALTER DATABASE [mintdata] SET CURSOR_CLOSE_ON_COMMIT OFF
GO
ALTER DATABASE [mintdata] SET CURSOR_DEFAULT  GLOBAL
GO
ALTER DATABASE [mintdata] SET CONCAT_NULL_YIELDS_NULL OFF
GO
ALTER DATABASE [mintdata] SET NUMERIC_ROUNDABORT OFF
GO
ALTER DATABASE [mintdata] SET QUOTED_IDENTIFIER OFF
GO
ALTER DATABASE [mintdata] SET RECURSIVE_TRIGGERS OFF
GO
ALTER DATABASE [mintdata] SET  READ_WRITE
GO
ALTER DATABASE [mintdata] SET RECOVERY FULL
GO
ALTER DATABASE [mintdata] SET  MULTI_USER
GO
ALTER DATABASE [mintdata] SET TORN_PAGE_DETECTION ON
GO
if ( ((@@microsoftversion / power(2, 24) = 8) and (@@microsoftversion & 0xffff >= 760)) or 
		(@@microsoftversion / power(2, 24) >= 9) )begin 
	exec dbo.sp_dboption @dbname =  N'mintdata', @optname = 'db chaining', @optvalue = 'OFF'
 end
GO
USE [mintdata]
GO
/****** Object:  StoredProcedure [dbo].[Domain_Lookup]    Script Date: 11/14/2008 23:43:07 ******/
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[Domain_Lookup]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE [Domain_Lookup]
GO
/****** Object:  StoredProcedure [dbo].[Edit_Domain]    Script Date: 11/14/2008 23:43:07 ******/
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[Edit_Domain]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE [Edit_Domain]
GO
/****** Object:  StoredProcedure [dbo].[Rec_Block]    Script Date: 11/14/2008 23:43:07 ******/
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[Rec_Block]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE [Rec_Block]
GO
/****** Object:  StoredProcedure [dbo].[Enable_Device]    Script Date: 11/14/2008 23:43:07 ******/
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[Enable_Device]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE [Enable_Device]
GO
/****** Object:  StoredProcedure [dbo].[Host_Dom_Look]    Script Date: 11/14/2008 23:43:07 ******/
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[Host_Dom_Look]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE [Host_Dom_Look]
GO
/****** Object:  StoredProcedure [dbo].[Is_Enabled]    Script Date: 11/14/2008 23:43:07 ******/
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[Is_Enabled]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE [Is_Enabled]
GO
/****** Object:  StoredProcedure [dbo].[Log_Looker]    Script Date: 11/14/2008 23:43:07 ******/
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[Log_Looker]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE [Log_Looker]
GO
/****** Object:  StoredProcedure [dbo].[Look_Single_Dom]    Script Date: 11/14/2008 23:43:07 ******/
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[Look_Single_Dom]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE [Look_Single_Dom]
GO
/****** Object:  StoredProcedure [dbo].[Lookup_URL]    Script Date: 11/14/2008 23:43:07 ******/
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[Lookup_URL]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE [Lookup_URL]
GO
/****** Object:  StoredProcedure [dbo].[Pass_Lookup]    Script Date: 11/14/2008 23:43:07 ******/
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[Pass_Lookup]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE [Pass_Lookup]
GO
/****** Object:  StoredProcedure [dbo].[Summary_Display]    Script Date: 11/14/2008 23:43:07 ******/
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[Summary_Display]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE [Summary_Display]
GO
/****** Object:  StoredProcedure [dbo].[Add_User]    Script Date: 11/14/2008 23:43:06 ******/
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[Add_User]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE [Add_User]
GO
/****** Object:  StoredProcedure [dbo].[Admin_User_Display]    Script Date: 11/14/2008 23:43:07 ******/
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[Admin_User_Display]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE [Admin_User_Display]
GO
/****** Object:  StoredProcedure [dbo].[Admin_User_Display_Search]    Script Date: 11/14/2008 23:43:07 ******/
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[Admin_User_Display_Search]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE [Admin_User_Display_Search]
GO
/****** Object:  StoredProcedure [dbo].[Device_Display]    Script Date: 11/14/2008 23:43:07 ******/
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[Device_Display]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE [Device_Display]
GO
/****** Object:  StoredProcedure [dbo].[User_Domain_Lookup]    Script Date: 11/14/2008 23:43:07 ******/
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[User_Domain_Lookup]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE [User_Domain_Lookup]
GO
/****** Object:  StoredProcedure [dbo].[Delete_Device]    Script Date: 11/14/2008 23:43:07 ******/
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[Delete_Device]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE [Delete_Device]
GO
/****** Object:  StoredProcedure [dbo].[User_AddDom]    Script Date: 11/14/2008 23:43:07 ******/
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[User_AddDom]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE [User_AddDom]
GO
/****** Object:  StoredProcedure [dbo].[Device_Lookup]    Script Date: 11/14/2008 23:43:07 ******/
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[Device_Lookup]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE [Device_Lookup]
GO
/****** Object:  StoredProcedure [dbo].[User_RemDom]    Script Date: 11/14/2008 23:43:07 ******/
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[User_RemDom]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE [User_RemDom]
GO
/****** Object:  StoredProcedure [dbo].[Disable_Device]    Script Date: 11/14/2008 23:43:07 ******/
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[Disable_Device]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE [Disable_Device]
GO
/****** Object:  StoredProcedure [dbo].[Disable_Device_IP]    Script Date: 11/14/2008 23:43:07 ******/
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[Disable_Device_IP]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE [Disable_Device_IP]
GO
/****** Object:  StoredProcedure [dbo].[Device_Display_Search]    Script Date: 11/14/2008 23:43:07 ******/
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[Device_Display_Search]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE [Device_Display_Search]
GO
/****** Object:  StoredProcedure [dbo].[User_Lookup]    Script Date: 11/14/2008 23:43:07 ******/
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[User_Lookup]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE [User_Lookup]
GO
/****** Object:  StoredProcedure [dbo].[Add_Device]    Script Date: 11/14/2008 23:43:06 ******/
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[Add_Device]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE [Add_Device]
GO
/****** Object:  StoredProcedure [dbo].[Update_Device]    Script Date: 11/14/2008 23:43:07 ******/
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[Update_Device]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE [Update_Device]
GO
/****** Object:  StoredProcedure [dbo].[Update_User_Info]    Script Date: 11/14/2008 23:43:07 ******/
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[Update_User_Info]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE [Update_User_Info]
GO
/****** Object:  StoredProcedure [dbo].[Update_User_Password]    Script Date: 11/14/2008 23:43:07 ******/
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[Update_User_Password]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE [Update_User_Password]
GO
/****** Object:  StoredProcedure [dbo].[User_Answer_Lookup]    Script Date: 11/14/2008 23:43:07 ******/
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[User_Answer_Lookup]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE [User_Answer_Lookup]
GO
/****** Object:  StoredProcedure [dbo].[User_Settings_Lookup]    Script Date: 11/14/2008 23:43:07 ******/
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[User_Settings_Lookup]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE [User_Settings_Lookup]
GO
/****** Object:  Table [dbo].[Admins]    Script Date: 11/14/2008 23:43:06 ******/
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[Admins]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
DROP TABLE [Admins]
GO
/****** Object:  StoredProcedure [dbo].[GeoIP_Import]    Script Date: 11/14/2008 23:43:07 ******/
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[GeoIP_Import]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE [GeoIP_Import]
GO
/****** Object:  Table [dbo].[Admin]    Script Date: 11/11/2008 15:50:37 ******/
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[Admin]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
DROP TABLE [Admin]
GO
/****** Object:  Table [dbo].[UpdateLogs]    Script Date: 11/14/2008 23:43:06 ******/
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[UpdateLogs]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
DROP TABLE [UpdateLogs]
GO
/****** Object:  StoredProcedure [dbo].[Admin_DomLook]    Script Date: 11/14/2008 23:43:07 ******/
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[Admin_DomLook]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE [Admin_DomLook]
GO
/****** Object:  StoredProcedure [dbo].[Lookup_geoip]    Script Date: 11/14/2008 23:43:07 ******/
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[Lookup_geoip]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE [Lookup_geoip]
GO
/****** Object:  StoredProcedure [dbo].[Admin_AddDom]    Script Date: 11/14/2008 23:43:06 ******/
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[Admin_AddDom]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE [Admin_AddDom]
GO
/****** Object:  StoredProcedure [dbo].[Update_Admin_User]    Script Date: 11/14/2008 23:43:07 ******/
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[Update_Admin_User]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE [Update_Admin_User]
GO
/****** Object:  StoredProcedure [dbo].[Admin_Lookup]    Script Date: 11/14/2008 23:43:07 ******/
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[Admin_Lookup]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE [Admin_Lookup]
GO
/****** Object:  StoredProcedure [dbo].[Admin_RemDom]    Script Date: 11/14/2008 23:43:07 ******/
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[Admin_RemDom]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE [Admin_RemDom]
GO
/****** Object:  StoredProcedure [dbo].[Rec_Limit]    Script Date: 11/14/2008 23:43:07 ******/
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[Rec_Limit]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE [Rec_Limit]
GO
/****** Object:  StoredProcedure [dbo].[MaxMind_Import]    Script Date: 11/14/2008 23:43:07 ******/
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[MaxMind_Import]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE [MaxMind_Import]
GO
/****** Object:  StoredProcedure [dbo].[Logon_Update]    Script Date: 11/14/2008 23:43:07 ******/
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[Logon_Update]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE [Logon_Update]
GO
/****** Object:  StoredProcedure [dbo].[CL_User_Check]    Script Date: 11/14/2008 23:43:07 ******/
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[CL_User_Check]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE [CL_User_Check]
GO
/****** Object:  StoredProcedure [dbo].[CL_User_Lookup]    Script Date: 11/14/2008 23:43:07 ******/
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[CL_User_Lookup]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE [CL_User_Lookup]
GO
/****** Object:  Table [dbo].[GeoLook]    Script Date: 11/14/2008 23:43:06 ******/
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[GeoLook]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
DROP TABLE [GeoLook]
GO
/****** Object:  StoredProcedure [dbo].[Client_Update]    Script Date: 11/14/2008 23:43:07 ******/
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[Client_Update]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE [Client_Update]
GO
/****** Object:  Table [dbo].[GeoLoc]    Script Date: 11/14/2008 23:43:06 ******/
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[GeoLoc]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
DROP TABLE [GeoLoc]
GO
/****** Object:  StoredProcedure [dbo].[Del_Dom_Lookup]    Script Date: 11/14/2008 23:43:07 ******/
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[Del_Dom_Lookup]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE [Del_Dom_Lookup]
GO
/****** Object:  Table [dbo].[Records]    Script Date: 11/14/2008 23:43:06 ******/
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[Records]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
DROP TABLE [Records]
GO
/****** Object:  Table [dbo].[UserDomains]    Script Date: 11/14/2008 23:43:06 ******/
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[UserDomains]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
DROP TABLE [UserDomains]
GO
/****** Object:  Table [dbo].[Users]    Script Date: 11/14/2008 23:43:06 ******/
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[Users]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
DROP TABLE [Users]
GO
/****** Object:  Table [dbo].[SystemDomains]    Script Date: 11/14/2008 23:43:06 ******/
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[SystemDomains]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
DROP TABLE [SystemDomains]
GO
/****** Object:  UserDefinedFunction [dbo].[IPtoNumeric]    Script Date: 11/14/2008 23:43:07 ******/
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[IPtoNumeric]') AND xtype in (N'FN', N'IF', N'TF'))
DROP FUNCTION [IPtoNumeric]
GO
/****** Object:  Table [dbo].[GeoLook]    Script Date: 11/14/2008 23:43:06 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[GeoLook]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
BEGIN
CREATE TABLE [GeoLook](
	[startIpNum] [bigint] NULL,
	[endIpNum] [bigint] NULL,
	[locId] [bigint] NULL
) ON [PRIMARY]
END
GO
IF NOT EXISTS (SELECT * FROM dbo.sysindexes WHERE id = OBJECT_ID(N'[GeoLook]') AND name = N'Geo_IP_Look')
CREATE CLUSTERED INDEX [Geo_IP_Look] ON [GeoLook] 
(
	[startIpNum] ASC,
	[endIpNum] ASC,
	[locId] ASC
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[GeoLoc]    Script Date: 11/14/2008 23:43:06 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[GeoLoc]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
BEGIN
CREATE TABLE [GeoLoc](
	[locId] [bigint] NULL,
	[country] [nvarchar](2) NULL,
	[region] [nvarchar](3) NULL,
	[city] [nvarchar](100) NULL,
	[postalCode] [nvarchar](10) NULL,
	[latitude] [nvarchar](15) NULL,
	[longitude] [nvarchar](15) NULL,
	[metroCode] [nvarchar](5) NULL,
	[areaCode] [nvarchar](5) NULL
) ON [PRIMARY]
END
GO
IF NOT EXISTS (SELECT * FROM dbo.sysindexes WHERE id = OBJECT_ID(N'[GeoLoc]') AND name = N'Geo_Info_Look')
CREATE CLUSTERED INDEX [Geo_Info_Look] ON [GeoLoc] 
(
	[locId] ASC,
	[country] ASC,
	[region] ASC,
	[city] ASC,
	[latitude] ASC,
	[longitude] ASC
) ON [PRIMARY]
GO
/****** Object:  StoredProcedure [dbo].[User_AddDom]    Script Date: 11/14/2008 23:43:07 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[User_AddDom]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
BEGIN
EXEC dbo.sp_executesql @statement = N'
/****** Object:  Stored Procedure dbo.Admin_AddDom    Script Date: 10/6/2002 2:37:32 AM ******/
CREATE PROCEDURE [User_AddDom] (
     @UserID nvarchar(255),
     @Password nvarchar(255),
     @Dom nvarchar(255)

   )
AS

SET NOCOUNT ON

select Dom
from UserDomains with (nolock)
WHERE Dom = @Dom

IF NOT EXISTS ( SELECT * FROM UserDomains with (nolock) WHERE Dom = @Dom) begin
INSERT INTO UserDomains
(Dom, UserID, Password) 
VALUES (@Dom, @UserID, @Password)
End

' 
END
GO
/****** Object:  StoredProcedure [dbo].[Device_Lookup]    Script Date: 11/14/2008 23:43:07 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[Device_Lookup]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
BEGIN
EXEC dbo.sp_executesql @statement = N'
/****** Object:  Stored Procedure dbo.Device_Lookup    Script Date: 10/6/2002 2:37:33 AM ******/
CREATE PROCEDURE [Device_Lookup] (
     @URL nvarchar(500),
     @UserID nvarchar(255)   
   )
AS

SET NOCOUNT ON


select 
Disabled,
IP,
DD,
URL,
Dtim = 
(
select Top 1 DD
from UpdateLogs
Where 
(URL = Records.URL)
Order By DD DESC
)
from Records with (nolock)
WHERE URL = @URL
And UserID = @UserID

' 
END
GO
/****** Object:  Table [dbo].[UserDomains]    Script Date: 11/14/2008 23:43:06 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[UserDomains]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
BEGIN
CREATE TABLE [UserDomains](
	[ID] [bigint] IDENTITY(1,1) NOT NULL,
	[Dom] [nvarchar](255) NULL,
	[UserID] [nvarchar](255) NULL,
	[Password] [nvarchar](255) NULL,
 CONSTRAINT [PK_UserDomains] PRIMARY KEY CLUSTERED 
(
	[ID] ASC
) ON [PRIMARY]
) ON [PRIMARY]
END
GO
/****** Object:  StoredProcedure [dbo].[Domain_Lookup]    Script Date: 11/14/2008 23:43:07 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[Domain_Lookup]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
BEGIN
EXEC dbo.sp_executesql @statement = N'
/****** Object:  Stored Procedure dbo.Domain_Lookup    Script Date: 10/6/2002 2:37:33 AM ******/
CREATE PROCEDURE [Domain_Lookup] (
     @UserID nvarchar(255),
     @Password varchar(255)
   )
AS

SET NOCOUNT ON


SELECT SystemDomains.Dom 
from SystemDomains
UNION ALL SELECT UserDomains.Dom FROM UserDomains 
where UserDomains.UserID = @UserID 
And UserDomains.Password = @Password

' 
END
GO
/****** Object:  Table [dbo].[Users]    Script Date: 11/14/2008 23:43:06 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[Users]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
BEGIN
CREATE TABLE [Users](
	[ID] [bigint] IDENTITY(1,1) NOT NULL,
	[UserID] [nvarchar](255) NULL,
	[Password] [nvarchar](255) NULL,
	[Registered] [datetime] NULL,
	[FName] [nvarchar](255) NULL,
	[LName] [nvarchar](255) NULL,
	[Email] [nvarchar](255) NULL,
	[country] [nvarchar](2) NULL,
	[Abuse] [int] NULL,
	[RegPeriod] [int] NULL,
	[PurchNumb] [nvarchar](50) NULL,
	[Question] [nvarchar](255) NULL,
	[Answer] [nvarchar](255) NULL,
	[IP] [nvarchar](255) NULL,
	[region] [nvarchar](3) NULL,
	[city] [nvarchar](100) NULL,
	[latitude] [nvarchar](15) NULL,
	[longitude] [nvarchar](15) NULL,
 CONSTRAINT [PK_Users] PRIMARY KEY CLUSTERED 
(
	[ID] ASC
) ON [PRIMARY]
) ON [PRIMARY]
END
GO
/****** Object:  StoredProcedure [dbo].[User_Domain_Lookup]    Script Date: 11/14/2008 23:43:07 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[User_Domain_Lookup]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
BEGIN
EXEC dbo.sp_executesql @statement = N'
/****** Object:  Stored Procedure dbo.Domain_Lookup    Script Date: 10/6/2002 2:37:33 AM ******/
CREATE PROCEDURE [User_Domain_Lookup] (
     @UserID nvarchar(255)
   )
AS

SET NOCOUNT ON


SELECT Dom 
from UserDomains
where UserID = @UserID 


' 
END
GO
/****** Object:  StoredProcedure [dbo].[Log_Looker]    Script Date: 11/14/2008 23:43:07 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[Log_Looker]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
BEGIN
EXEC dbo.sp_executesql @statement = N'
/****** Object:  Stored Procedure dbo.Log_Looker    Script Date: 10/6/2002 2:37:33 AM ******/
CREATE PROCEDURE [Log_Looker] (
     @URL nvarchar(500)
   )
AS

SET NOCOUNT ON

select TOP 10 
DD,
IP
from UpdateLogs with (nolock)
WHERE URL= @URL
Order By DD DESC

' 
END
GO
/****** Object:  StoredProcedure [dbo].[Look_Single_Dom]    Script Date: 11/14/2008 23:43:07 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[Look_Single_Dom]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
BEGIN
EXEC dbo.sp_executesql @statement = N'
/****** Object:  Stored Procedure dbo.Look_Single_Dom    Script Date: 10/6/2002 2:37:33 AM ******/
CREATE PROCEDURE [Look_Single_Dom] (
     @Dom nvarchar(255),
     @UserID nvarchar(255)
   )
AS

SET NOCOUNT ON


SELECT SystemDomains.Dom 
from SystemDomains Where SystemDomains.Dom = @Dom
UNION ALL SELECT UserDomains.Dom FROM UserDomains 
where UserDomains.UserID = @UserID 
And UserDomains.Dom = @Dom
' 
END
GO
/****** Object:  StoredProcedure [dbo].[Admin_User_Display]    Script Date: 11/14/2008 23:43:07 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[Admin_User_Display]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
BEGIN
EXEC dbo.sp_executesql @statement = N'
/****** Object:  Stored Procedure dbo.Admin_User_Display    Script Date: 10/6/2002 2:37:32 AM ******/
CREATE PROCEDURE [Admin_User_Display] (
     @Page int,
     @RecsPerPage int
        )
AS

SET NOCOUNT ON
--Create a temporary table
CREATE TABLE #TempSItems
(
ID int IDENTITY,
UserID nvarchar(255),
Password nvarchar(255),
Registered datetime,
FName nvarchar(255),
LName nvarchar(255),
Country nvarchar(2),
Region nvarchar(3),
City nvarchar(100),
Latitude nvarchar(15),
Longitude nvarchar(15),
IP nvarchar(255),
RegDevs int,
Dtim datetime
)


-- Insert the rows from tblItems into the temp. table
INSERT INTO #TempSItems (UserID, Password,  Registered, FName, LName, Country, Region, City, Latitude, Longitude, IP, RegDevs, Dtim)
SELECT
UserID, 
Password,
Registered, 
FName, 
LName, 
Country,
Region, 
City, 
Latitude, 
Longitude,
IP,
RegDevs = 
(
select COUNT(*)
from Records
Where 
(UserID = Users.UserID)
),
Dtim = 
(
select Top 1 DD
from UpdateLogs
Where 
(Uid = Users.UserID)
Order By DD DESC
)

FROM Users
Order By Registered ASC

-- Find out the first and last record we want
DECLARE @FirstRec int, @LastRec int
SELECT @FirstRec = (@Page - 1) * @RecsPerPage
SELECT @LastRec = (@Page * @RecsPerPage + 1)

-- Now, return the set of paged records, plus, an indiciation of we
-- have more records or not!
SELECT *,
    TotalCount = 
	(
	 SELECT COUNT(*) 
	 FROM #TempSItems TI

	) 
FROM #TempSItems
WHERE ID > @FirstRec AND ID < @LastRec

SET NOCOUNT OFF




' 
END
GO
/****** Object:  StoredProcedure [dbo].[Admin_User_Display_Search]    Script Date: 11/14/2008 23:43:07 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[Admin_User_Display_Search]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
BEGIN
EXEC dbo.sp_executesql @statement = N'
/****** Object:  Stored Procedure dbo.Admin_User_Display_Search    Script Date: 10/6/2002 2:37:32 AM ******/
CREATE PROCEDURE [Admin_User_Display_Search] (
      @UserID nvarchar(255),
     @Page int,
     @RecsPerPage int
        )
AS

SET NOCOUNT ON
--Create a temporary table
CREATE TABLE #TempSItems
(
ID int IDENTITY,
UserID nvarchar(255),
Password nvarchar(255),
Registered datetime,
FName nvarchar(255),
LName nvarchar(255),
Country nvarchar(2),
Region nvarchar(3),
City nvarchar(100),
Latitude nvarchar(15),
Longitude nvarchar(15),
IP nvarchar(255),
RegDevs int,
Dtim datetime
)


-- Insert the rows from tblItems into the temp. table
INSERT INTO #TempSItems (UserID, Password,  Registered, FName, LName, Country, Region, City, Latitude, Longitude, IP, RegDevs, Dtim)
SELECT
UserID, 
Password,
Registered, 
FName, 
LName, 
Country,
Region, 
City, 
Latitude, 
Longitude,
IP,
RegDevs = 
(
select COUNT(*)
from Records
Where 
(UserID = Users.UserID)
),
Dtim = 
(
select Top 1 DD
from UpdateLogs
Where 
(Uid = Users.UserID)
Order By DD DESC
)
FROM Users
Where UserID Like @UserID
Order By Registered ASC

-- Find out the first and last record we want
DECLARE @FirstRec int, @LastRec int
SELECT @FirstRec = (@Page - 1) * @RecsPerPage
SELECT @LastRec = (@Page * @RecsPerPage + 1)

-- Now, return the set of paged records, plus, an indiciation of we
-- have more records or not!
SELECT *,
    TotalCount = 
	(
	 SELECT COUNT(*) 
	 FROM #TempSItems TI

	) 
FROM #TempSItems
WHERE ID > @FirstRec AND ID < @LastRec

SET NOCOUNT OFF




' 
END
GO
/****** Object:  StoredProcedure [dbo].[Device_Display]    Script Date: 11/14/2008 23:43:07 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[Device_Display]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
BEGIN
EXEC dbo.sp_executesql @statement = N'
/****** Object:  Stored Procedure dbo.Device_Display    Script Date: 10/6/2002 2:37:32 AM ******/
CREATE PROCEDURE [Device_Display] (
     @User nvarchar(255),
     @Page int,
     @RecsPerPage int
        )
AS

SET NOCOUNT ON
--Create a temporary table
CREATE TABLE #TempSItems
(
ID int IDENTITY,
Host nvarchar(255),
Dom nvarchar(255),
UserID nvarchar(255),
iEnabled nvarchar(10),
IP nvarchar(255),
DD datetime,
URL nvarchar(500),
LastUpdate datetime
)


-- Insert the rows from tblItems into the temp. table
INSERT INTO #TempSItems (Host, Dom, UserID, iEnabled, IP,DD, URL, LastUpdate)
SELECT  Top 2000
Host, 
Dom, 
UserID, 
Disabled, 
IP, 
DD, 
URL,
Dtim = 
(
select Top 1 DD
from UpdateLogs
Where 
(URL = Records.URL)
Order By DD DESC
)

FROM Records

WHERE 
 (UserID = @User)
Order By DD DESC



-- Find out the first and last record we want
DECLARE @FirstRec int, @LastRec int
SELECT @FirstRec = (@Page - 1) * @RecsPerPage
SELECT @LastRec = (@Page * @RecsPerPage + 1)

-- Now, return the set of paged records, plus, an indiciation of we
-- have more records or not!
SELECT *,
    TotalCount = 
	(
	 SELECT COUNT(*) 
	 FROM #TempSItems TI

	) 
FROM #TempSItems
WHERE ID > @FirstRec AND ID < @LastRec

SET NOCOUNT OFF


' 
END
GO
/****** Object:  Table [dbo].[SystemDomains]    Script Date: 11/14/2008 23:43:06 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[SystemDomains]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
BEGIN
CREATE TABLE [SystemDomains](
	[ID] [bigint] IDENTITY(1,1) NOT NULL,
	[Dom] [nvarchar](255) NULL,
 CONSTRAINT [PK_SystemDomains] PRIMARY KEY CLUSTERED 
(
	[ID] ASC
) ON [PRIMARY]
) ON [PRIMARY]
INSERT INTO SystemDomains
(Dom) 
VALUES ('replaceme.com')
END
GO
/****** Object:  StoredProcedure [dbo].[Device_Display_Search]    Script Date: 11/14/2008 23:43:07 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[Device_Display_Search]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
BEGIN
EXEC dbo.sp_executesql @statement = N'
/****** Object:  Stored Procedure dbo.Device_Display_Search    Script Date: 10/6/2002 2:37:32 AM ******/
CREATE PROCEDURE [Device_Display_Search] (
     @Record nvarchar(255),     
     @User nvarchar(255),
     @Page int,
     @RecsPerPage int
     
   )
AS

SET NOCOUNT ON
--Create a temporary table
CREATE TABLE #TempSItems
(

ID int IDENTITY,
Host nvarchar(255),
Dom nvarchar(255),
UserID nvarchar(255),
iEnabled nvarchar(10),
IP nvarchar(255),
URL nvarchar(500),
DD nvarchar(20),
LastUpdate nvarchar(20)
)


-- Insert the rows from tblItems into the temp. table
INSERT INTO #TempSItems (Host, Dom, UserID, iEnabled, IP, URL, DD, LastUpdate)
SELECT  Top 2000
Host, 
Dom, 
UserID, 
Disabled, 
IP, 
URL,
DD, 
Dtim = 
(
select Top 1 DD
from UpdateLogs
Where 
(URL = Records.URL)
Order By DD DESC
)

FROM Records

WHERE 
 (UserID = @User)
AND
(URL Like @Record)


-- Find out the first and last record we want
DECLARE @FirstRec int, @LastRec int
SELECT @FirstRec = (@Page - 1) * @RecsPerPage
SELECT @LastRec = (@Page * @RecsPerPage + 1)

-- Now, return the set of paged records, plus, an indiciation of we
-- have more records or not!
SELECT *,
    TotalCount = 
	(
	 SELECT COUNT(*) 
	 FROM #TempSItems TI

	) 
FROM #TempSItems
WHERE ID > @FirstRec AND ID < @LastRec

SET NOCOUNT OFF
' 
END
GO
/****** Object:  StoredProcedure [dbo].[User_Lookup]    Script Date: 11/14/2008 23:43:07 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[User_Lookup]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
BEGIN
EXEC dbo.sp_executesql @statement = N'
/****** Object:  Stored Procedure dbo.User_Lookup    Script Date: 10/6/2002 2:37:32 AM ******/
CREATE PROCEDURE [User_Lookup] (
@UserID nvarchar(255),
@Password nvarchar(255)
   )
AS

SET NOCOUNT ON

SELECT UserID, Password
FROM Users with (Nolock) WHERE
UserID = @UserID And Password = @Password
' 
END
GO
/****** Object:  StoredProcedure [dbo].[Pass_Lookup]    Script Date: 11/14/2008 23:43:07 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[Pass_Lookup]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
BEGIN
EXEC dbo.sp_executesql @statement = N'
/****** Object:  Stored Procedure dbo.Pass_Lookup    Script Date: 10/6/2002 2:37:33 AM ******/
CREATE PROCEDURE [Pass_Lookup] (
     @UserID nvarchar(255)    
   )
AS

SET NOCOUNT ON

select Question
from Users with (nolock)
WHERE UserID = @UserID

' 
END
GO
/****** Object:  StoredProcedure [dbo].[Summary_Display]    Script Date: 11/14/2008 23:43:07 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[Summary_Display]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
BEGIN
EXEC dbo.sp_executesql @statement = N'
/****** Object:  Stored Procedure dbo.Summary_Display    Script Date: 10/6/2002 2:37:33 AM ******/
CREATE PROCEDURE [Summary_Display]  
AS

SELECT
    UserCount = 	( SELECT COUNT(*)  FROM Users) ,
    RecordCount = ( SELECT COUNT(*)  FROM Records) ,
    SysDomainCount = ( SELECT COUNT(*)  FROM SystemDomains	) ,
    UserDomainCount = ( SELECT COUNT(*)  FROM UserDomains),
    TodayUpdates = ( SELECT COUNT(*)  FROM UpdateLogs Where DD BETWEEN GETDATE()-1 AND GETDATE()),
    TodayUsers = ( SELECT COUNT(*)  FROM Users Where Registered BETWEEN GETDATE()-1 AND GETDATE()),
    TodayRecords = ( SELECT COUNT(*)  FROM Records Where DD BETWEEN GETDATE()-1 AND GETDATE())



' 
END
GO
/****** Object:  StoredProcedure [dbo].[User_Answer_Lookup]    Script Date: 11/14/2008 23:43:07 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[User_Answer_Lookup]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
BEGIN
EXEC dbo.sp_executesql @statement = N'
/****** Object:  Stored Procedure dbo.User_Answer_Lookup    Script Date: 10/6/2002 2:37:33 AM ******/
CREATE PROCEDURE [User_Answer_Lookup] (
     @UserID nvarchar(255),
     @Answer nvarchar(255)
     

   )
AS

SET NOCOUNT ON

select Password
from Users with (nolock)
WHERE UserID = @UserID
And Answer = @Answer

' 
END
GO
/****** Object:  UserDefinedFunction [dbo].[IPtoNumeric]    Script Date: 11/14/2008 23:43:07 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[IPtoNumeric]') AND xtype in (N'FN', N'IF', N'TF'))
BEGIN
execute dbo.sp_executesql @statement = N'CREATE FUNCTION [IPtoNumeric]  (@strIP varchar(255))
RETURNS bigint
AS
BEGIN
DECLARE @intIPNum bigint
        IF (LEN(@strIP)-LEN(REPLACE(@strIP,''.'','''')))/LEN(''.'') = 3   -- check to ensure there are 3 dots
    SET @intIPNum = (16777216 *  CAST(PARSENAME(@strIP,4) as bigint) + 65536 * PARSENAME(@strIP,3) + 256 * PARSENAME(@strIP,2) + PARSENAME(@strIP,1))
RETURN @intIPNum
END

' 
END
GO
/****** Object:  Table [dbo].[Admins]    Script Date: 11/14/2008 23:43:06 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[Admins]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
BEGIN
CREATE TABLE [Admins](
	[ID] [int] IDENTITY(1,1) NOT NULL,
	[UserID] [nvarchar](255) NULL,
	[Password] [nvarchar](255) NULL,
	[Acc_Goup] [nvarchar](15) NULL,
 CONSTRAINT [PK_Admins] PRIMARY KEY CLUSTERED 
(
	[ID] ASC
) ON [PRIMARY]
) ON [PRIMARY]
END
GO
/****** Object:  StoredProcedure [dbo].[GeoIP_Import]    Script Date: 11/14/2008 23:43:07 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[GeoIP_Import]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
BEGIN
EXEC dbo.sp_executesql @statement = N'
CREATE PROCEDURE [GeoIP_Import]
(
@FilePath nvarchar(4000)
)
AS
declare @SQL varchar(500)
IF EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = ''GeoLook'')BEGIN
DROP TABLE GeoLook
END


CREATE TABLE GeoLook (
                 IP_Start bigint,
                 IP_End bigint,
                 Registrar NVARCHAR(7),
                 As_IP bigint,
                 Counrty_Ab NVARCHAR(2),
                 Country_thr NVARCHAR(3),
                 Country_Full NVARCHAR(50) )


SET @SQL=''BULK INSERT GeoLook FROM '''''' + @FilePath + '''''' WITH (FIRSTROW = 174, FIELDTERMINATOR ='''','''',ROWTERMINATOR=''''\n'''')''
EXEC(@sql)
ALTER TABLE GeoLook ADD ID bigint IDENTITY(1,1) PRIMARY KEY




' 
END
GO
/****** Object:  Table [dbo].[Admin]    Script Date: 11/11/2008 15:50:37 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[Admin]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
BEGIN
CREATE TABLE [Admin](
	[UserID] [nvarchar](255) NULL,
	[Password] [nvarchar](255) NULL,
	[PayPeriod] [nvarchar](50) NULL,
	[Price1] [nvarchar](50) NULL,
	[Price2] [nvarchar](50) NULL,
	[Price3] [nvarchar](50) NULL,
	[Trial] [nvarchar](50) NULL,
	[Message] [ntext] NULL,
	[RegistarInstruc] [ntext] NULL,
	[PayPal] [nvarchar](50) NULL,
	[Payon] [nvarchar](50) NULL,
	[MaxRec] [int] NULL,
	[MaxDom] [nvarchar](50) NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
INSERT INTO Admin  
(UserID, Password, MaxRec) 
VALUES ('admin', 'cGFzc3dvcmQ=', '35')
END
GO


/****** Object:  Table [dbo].[UpdateLogs]    Script Date: 11/14/2008 23:43:06 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[UpdateLogs]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
BEGIN
CREATE TABLE [UpdateLogs](
	[URL] [nvarchar](500) NULL,
	[DD] [datetime] NULL,
	[IP] [nvarchar](255) NULL,
	[Model] [nvarchar](50) NULL,
	[Uid] [nvarchar](255) NULL
) ON [PRIMARY]
END
GO
/****** Object:  StoredProcedure [dbo].[Update_Admin_User]    Script Date: 11/14/2008 23:43:07 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[Update_Admin_User]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
BEGIN
EXEC dbo.sp_executesql @statement = N'
/****** Object:  Stored Procedure dbo.Update_Admin_User    Script Date: 10/6/2002 2:37:33 AM ******/
CREATE PROCEDURE [Update_Admin_User] (
     @UserID nvarchar(255),
     @Password nvarchar(255),
     @UP_UserID nvarchar(255),
     @UP_Password nvarchar(255)

   )
AS

SET NOCOUNT ON

select UserID
from Admin with (nolock)
WHERE UserID = @UserID
And Password = @Password

IF EXISTS ( SELECT * FROM Admin with (nolock) WHERE UserID = @UserID And Password = @Password) begin
UPDATE Admin 
SET UserID = @Up_UserID,
Password = @Up_Password
Where (UserID = @UserID)
End

' 
END
GO
/****** Object:  StoredProcedure [dbo].[Admin_Lookup]    Script Date: 11/14/2008 23:43:07 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[Admin_Lookup]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
BEGIN
EXEC dbo.sp_executesql @statement = N'
/****** Object:  Stored Procedure dbo.Admin_Lookup    Script Date: 10/6/2002 2:37:33 AM ******/
CREATE PROCEDURE [Admin_Lookup] (
@UserID nvarchar(255),
@Password nvarchar(255)
   )
AS

SET NOCOUNT ON

SELECT UserID, Password, MaxRec
FROM Admin with (Nolock) WHERE
UserID = @UserID And Password = @Password

' 
END
GO
/****** Object:  StoredProcedure [dbo].[Rec_Limit]    Script Date: 11/14/2008 23:43:07 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[Rec_Limit]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
BEGIN
EXEC dbo.sp_executesql @statement = N'
/****** Object:  Stored Procedure dbo.Update_Device    Script Date: 10/6/2002 2:37:33 AM ******/
CREATE PROCEDURE [Rec_Limit] (
     @RecValue bigint
 )
AS

SET NOCOUNT ON

UPDATE Admin 
SET MaxRec = @RecValue





' 
END
GO
/****** Object:  StoredProcedure [dbo].[MaxMind_Import]    Script Date: 11/14/2008 23:43:07 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[MaxMind_Import]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
BEGIN
EXEC dbo.sp_executesql @statement = N'
CREATE PROCEDURE [MaxMind_Import]
(
@GeoLiteCity_Blocks nvarchar(4000),
@GeoLiteCity_Location nvarchar(4000)
)
AS
declare @SQL varchar(500)
declare @SQL1 varchar(500)
IF EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = ''GeoLook'')BEGIN
DROP TABLE GeoLook
END


CREATE TABLE GeoLook (
                 startIpNum bigint,
                 endIpNum bigint,
                 locId  bigint
)

SET @SQL=''BULK INSERT GeoLook FROM '''''' + @GeoLiteCity_Blocks + '''''' WITH (FIRSTROW = 3, formatfile=''''c:\mintdata\GeoLiteCity-Blocks.fmt'''')''
EXEC(@sql)
CREATE CLUSTERED INDEX Geo_IP_Look
ON GeoLook
([StartIpNum], [endIpNum],  [locId])
   

IF EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = ''GeoLoc'')BEGIN
DROP TABLE GeoLoc
END


CREATE TABLE GeoLoc (
                 locId bigint,
                 country nvarchar(2),
                 region nvarchar(3),
                 city nvarchar(100),
                 postalCode nvarchar(10),
                 latitude nvarchar(15),
                 longitude nvarchar(15),
                 metroCode nvarchar(5),
                 areaCode nvarchar(5)
)

SET @SQL1=''BULK INSERT GeoLoc FROM '''''' + @GeoLiteCity_Location + '''''' WITH (FIRSTROW = 3, formatfile=''''c:\mintdata\GeoLiteCity-Location.fmt'''')''
EXEC(@sql1)
CREATE CLUSTERED INDEX Geo_Info_Look
ON GeoLoc
([locId], [country], [region], [city], [latitude], [longitude])



' 
END
GO
/****** Object:  StoredProcedure [dbo].[CL_User_Check]    Script Date: 11/14/2008 23:43:07 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[CL_User_Check]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
BEGIN
EXEC dbo.sp_executesql @statement = N'
/****** Object:  Stored Procedure dbo.CL_User_Check    Script Date: 10/6/2002 2:37:33 AM ******/
CREATE PROCEDURE [CL_User_Check] (
     @UserID nvarchar(255),
     @Password nvarchar(255)
     

   )
AS

SET NOCOUNT ON

select UserID
from Users with (nolock)
WHERE UserID = @UserID
And Password = @Password

' 
END
GO
/****** Object:  Table [dbo].[Records]    Script Date: 11/14/2008 23:43:06 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[Records]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
BEGIN
CREATE TABLE [Records](
	[ID] [bigint] IDENTITY(1,1) NOT NULL,
	[Host] [nvarchar](255) NULL,
	[Dom] [nvarchar](255) NULL,
	[UserID] [nvarchar](255) NULL,
	[Password] [nvarchar](255) NULL,
	[Disabled] [bit] NULL CONSTRAINT [DF_Records_Disabled]  DEFAULT ((0)),
	[Type] [nvarchar](3) NULL,
	[IP] [nvarchar](255) NULL,
	[DD] [datetime] NULL,
	[URL] [nvarchar](500) NULL,
 CONSTRAINT [PK_Records] PRIMARY KEY CLUSTERED 
(
	[ID] ASC
) ON [PRIMARY]
) ON [PRIMARY]
END
GO
/****** Object:  StoredProcedure [dbo].[Logon_Update]    Script Date: 11/14/2008 23:43:07 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[Logon_Update]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
BEGIN
EXEC dbo.sp_executesql @statement = N'
/****** Object:  Stored Procedure dbo.Client_Update    Script Date: 10/6/2002 2:37:33 AM ******/
CREATE PROCEDURE [Logon_Update] (
     @UserID nvarchar(255),
     @Country nvarchar(2),
     @Region nvarchar(3),
     @City nvarchar(100),
     @Latitude nvarchar(15),
     @Longitude nvarchar(15),
     @IP nvarchar(255)
  )
AS

SET NOCOUNT ON

IF EXISTS ( SELECT * FROM Users with (nolock) WHERE UserID = @UserID) begin
UPDATE Users 
SET country = @Country,
region = @Region,
city = @City,
latitude = @Latitude,
longitude = @Longitude,
IP = @IP
Where (UserID = @UserID)
End

' 
END
GO
/****** Object:  StoredProcedure [dbo].[Add_User]    Script Date: 11/14/2008 23:43:06 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[Add_User]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
BEGIN
EXEC dbo.sp_executesql @statement = N'
/****** Object:  Stored Procedure dbo.Add_User    Script Date: 10/6/2002 2:37:32 AM ******/
CREATE  PROCEDURE [Add_User] (
     @UserID nvarchar(255),
     @Password nvarchar(255),
     @FName nvarchar(255),
     @LName nvarchar(255),
     @Question nvarchar(255),
     @Answer nvarchar(255),
     @Country nvarchar(2),
     @Region nvarchar(3),
     @City nvarchar(100),
     @Latitude nvarchar(15),
     @Longitude nvarchar(15),
     @IP nvarchar(25)
   )
AS

SET NOCOUNT ON

-- If found selection

Select UserID
from Users with (nolock)
WHERE Userid = @UserID

IF NOT EXISTS ( SELECT  * FROM Users with (nolock) WHERE   UserId = @UserID) Begin

INSERT INTO Users
(UserID, Password, Registered, FName, LName, Email, Country, Question, Answer, IP, region, city, latitude, longitude) 
VALUES (@UserID, @Password, GETDATE(), @FName, @LName, @UserID, @Country, @Question, @Answer, @IP, @Region, @City, @Latitude, @Longitude )
End 

' 
END
GO
/****** Object:  StoredProcedure [dbo].[User_RemDom]    Script Date: 11/14/2008 23:43:07 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[User_RemDom]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
BEGIN
EXEC dbo.sp_executesql @statement = N'
/****** Object:  Stored Procedure dbo.Admin_RemDom    Script Date: 10/6/2002 2:37:33 AM ******/
CREATE PROCEDURE [User_RemDom] (
     @AdminUserID nvarchar(255),
     @Password nvarchar(255),
     @User nvarchar(255),
     @Dom nvarchar(255)

   )
AS

SET NOCOUNT ON

SELECT 
Records.Host, 
Records.Dom, 
UserDomains.Dom as Udom
FROM UserDomains
LEFT JOIN Records ON UserDomains.Dom = Records.Dom 
WHERE  (UserDomains.Dom = @Dom)


IF EXISTS ( SELECT * FROM Admin with (nolock) WHERE UserID = @AdminUserID And Password = @Password ) begin
Delete From Records Where Dom = @Dom
Delete From UserDomains Where Dom = @Dom And UserID = @User
End

' 
END
GO
/****** Object:  StoredProcedure [dbo].[Admin_DomLook]    Script Date: 11/14/2008 23:43:07 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[Admin_DomLook]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
BEGIN
EXEC dbo.sp_executesql @statement = N'
/****** Object:  Stored Procedure dbo.Admin_DomLook    Script Date: 10/6/2002 2:37:32 AM ******/
CREATE PROCEDURE [Admin_DomLook] 
AS

SET NOCOUNT ON

select Dom
from SystemDomains with (nolock)

' 
END
GO
/****** Object:  StoredProcedure [dbo].[Admin_AddDom]    Script Date: 11/14/2008 23:43:06 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[Admin_AddDom]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
BEGIN
EXEC dbo.sp_executesql @statement = N'
/****** Object:  Stored Procedure dbo.Admin_AddDom    Script Date: 10/6/2002 2:37:32 AM ******/
CREATE PROCEDURE [Admin_AddDom] (
     @UserID nvarchar(255),
     @Password nvarchar(255),
     @Dom nvarchar(255)

   )
AS

SET NOCOUNT ON

select UserID
from Admin with (nolock)
WHERE UserID = @UserID
And Password = @Password

IF EXISTS ( SELECT * FROM Admin with (nolock) WHERE UserID = @UserID And Password = @Password ) begin
INSERT INTO SystemDomains
(Dom) 
VALUES (@Dom)
End

' 
END
GO
/****** Object:  StoredProcedure [dbo].[Admin_RemDom]    Script Date: 11/14/2008 23:43:07 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[Admin_RemDom]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
BEGIN
EXEC dbo.sp_executesql @statement = N'
/****** Object:  Stored Procedure dbo.Admin_RemDom    Script Date: 10/6/2002 2:37:33 AM ******/
CREATE PROCEDURE [Admin_RemDom] (
     @UserID nvarchar(255),
     @Password nvarchar(255),
     @Dom nvarchar(255)

   )
AS

SET NOCOUNT ON

Select Host, Dom
from Records with (nolock)
WHERE Dom = @Dom


IF EXISTS ( SELECT * FROM Admin with (nolock) WHERE UserID = @UserID And Password = @Password ) begin
Delete From Records Where Dom = @Dom
Delete From SystemDomains Where Dom = @Dom
End

' 
END
GO
/****** Object:  StoredProcedure [dbo].[Lookup_geoip]    Script Date: 11/14/2008 23:43:07 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[Lookup_geoip]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
BEGIN
EXEC dbo.sp_executesql @statement = N'CREATE PROCEDURE [Lookup_geoip] (
@IP nvarchar(255)

   )
AS
SET NOCOUNT ON

DECLARE @IPNUM bigint
set @IPNUM =  dbo.IPtoNumeric(@IP)

SELECT 
Geoloc.country, 
Geoloc.region, 
Geoloc.city, 
Geoloc.latitude, 
Geoloc.longitude
FROM GeoLook
INNER JOIN Geoloc ON GeoLook.locId = Geoloc.locId 
WHERE  (@IPNUM BETWEEN GeoLook.startIpNum AND GeoLook.endIpNum)

' 
END
GO
/****** Object:  StoredProcedure [dbo].[User_Settings_Lookup]    Script Date: 11/14/2008 23:43:07 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[User_Settings_Lookup]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
BEGIN
EXEC dbo.sp_executesql @statement = N'
/****** Object:  Stored Procedure dbo.User_Settings_Lookup    Script Date: 10/6/2002 2:37:34 AM ******/
CREATE PROCEDURE [User_Settings_Lookup] (
     @UserID nvarchar(255),
     @Password nvarchar(255)

   )
AS

SET NOCOUNT ON



select UserID,
Password,
Registered,
FName,
LName,
Question,
Answer,
Devcount = 
	(
	 SELECT COUNT(*) 
	 FROM Records
              WHERE UserID = @UserID
              And Password = @Password
	) 
from Users with (nolock)
WHERE UserID = @UserID
And Password = @Password
' 
END
GO
/****** Object:  StoredProcedure [dbo].[Add_Device]    Script Date: 11/14/2008 23:43:06 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[Add_Device]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
BEGIN
EXEC dbo.sp_executesql @statement = N'
/****** Object:  Stored Procedure dbo.Add_Device    Script Date: 10/6/2002 2:37:32 AM ******/
CREATE PROCEDURE [Add_Device] (
     @Host nvarchar(255),
     @Dom nvarchar(255),
     @UserID nvarchar(255),
     @Password nvarchar(255),
     @Type nvarchar(3),
     @IP nvarchar(255)
     
  )
AS

SET NOCOUNT ON

Select Host
from Records with (nolock)
WHERE Host = @Host
And Dom = @Dom

IF NOT EXISTS ( SELECT  * FROM Records with (nolock) WHERE Host = @Host And Dom = @Dom) Begin

INSERT INTO Records
(Host, Dom, UserID, Password, Type, IP, DD, URL) 
VALUES (@Host, @Dom, @UserID, @Password, @Type, @IP,  GETDATE(), @Host + ''.'' +  @Dom )
End

' 
END
GO
/****** Object:  StoredProcedure [dbo].[Update_Device]    Script Date: 11/14/2008 23:43:07 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[Update_Device]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
BEGIN
EXEC dbo.sp_executesql @statement = N'
/****** Object:  Stored Procedure dbo.Update_Device    Script Date: 10/6/2002 2:37:33 AM ******/
CREATE PROCEDURE [Update_Device] (
     @UserID nvarchar(255),
     @Password nvarchar(255),
     @IP nvarchar(255),
     @URL nvarchar(500)
     

   )
AS

SET NOCOUNT ON

select Host, Dom,  IP
from Records with (nolock)
WHERE UserID = @UserID
And Password = @Password
And URL = @URL



IF EXISTS ( SELECT * FROM Records with (nolock) WHERE UserID = @UserID And Password = @Password And URL = @URL) begin
UPDATE Records 
SET IP = @IP,
URL = @URL
Where (URL = @URL)
End


INSERT INTO UpdateLogs
(URL, DD, IP) 
VALUES (@URL, GETDATE(), @IP)

' 
END
GO
/****** Object:  StoredProcedure [dbo].[Update_User_Info]    Script Date: 11/14/2008 23:43:07 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[Update_User_Info]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
BEGIN
EXEC dbo.sp_executesql @statement = N'
/****** Object:  Stored Procedure dbo.Update_User_Info    Script Date: 10/6/2002 2:37:33 AM ******/
CREATE PROCEDURE [Update_User_Info] (
     @UserID nvarchar(255),
     @Password nvarchar(255),
     @Up_UserID nvarchar(255),
     @FName nvarchar(255),
     @LName nvarchar(255),
     @Question nvarchar(255),
     @Answer nvarchar(255)

   )
AS

SET NOCOUNT ON

select UserID
from Users with (nolock)
WHERE UserID = @UserID
And Password = @Password

IF EXISTS ( SELECT * FROM Users with (nolock) WHERE UserID = @UserID And Password = @Password) begin
UPDATE Users 
SET UserID = @Up_UserID,
FName = @FName,
LName = @LName,
Question = @Question,
Email = @Up_UserID,
Answer = @Answer
Where (UserID = @UserID)
End

IF EXISTS ( SELECT * FROM Records with (nolock) WHERE UserID = @UserID And Password = @Password) begin
UPDATE Records 
SET UserID = @Up_UserID
Where (UserID = @UserID)
End

' 
END
GO
/****** Object:  StoredProcedure [dbo].[Update_User_Password]    Script Date: 11/14/2008 23:43:07 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[Update_User_Password]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
BEGIN
EXEC dbo.sp_executesql @statement = N'
/****** Object:  Stored Procedure dbo.Update_User_Password    Script Date: 10/6/2002 2:37:33 AM ******/
CREATE PROCEDURE [Update_User_Password] (
     @UserID nvarchar(255),
     @Password nvarchar(255),
     @Up_Pass nvarchar(255)

   )
AS

SET NOCOUNT ON

select UserID
from Users with (nolock)
WHERE UserID = @UserID
And Password = @Password

IF EXISTS ( SELECT * FROM Users with (nolock) WHERE UserID = @UserID And Password = @Password) begin
UPDATE Users 
SET Password = @Up_Pass
Where (UserID = @UserID)
End

IF EXISTS ( SELECT * FROM Records with (nolock) WHERE UserID = @UserID And Password = @Password) begin
UPDATE Records 
SET Password = @Up_Pass
Where (UserID = @UserID)
End
' 
END
GO
/****** Object:  StoredProcedure [dbo].[Disable_Device]    Script Date: 11/14/2008 23:43:07 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[Disable_Device]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
BEGIN
EXEC dbo.sp_executesql @statement = N'
/****** Object:  Stored Procedure dbo.Disable_Device    Script Date: 10/6/2002 2:37:33 AM ******/
CREATE PROCEDURE [Disable_Device] (
     @URL nvarchar(500),
     @UserID nvarchar(255),
     @Password nvarchar(255)
   )
AS

SET NOCOUNT ON

IF EXISTS ( SELECT  * FROM  Records with (nolock) WHERE URL = @URL And UserID = @UserID And Password = @Password) begin
UPDATE Records 
SET Disabled = 1 
Where (URL = @URL)
End

' 
END
GO
/****** Object:  StoredProcedure [dbo].[Disable_Device_IP]    Script Date: 11/14/2008 23:43:07 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[Disable_Device_IP]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
BEGIN
EXEC dbo.sp_executesql @statement = N'
/****** Object:  Stored Procedure dbo.Disable_Device_IP    Script Date: 10/6/2002 2:37:33 AM ******/
CREATE PROCEDURE [Disable_Device_IP] (
     @URL nvarchar(500),
     @UserID nvarchar(255),
     @Password nvarchar(255)
   )
AS

SET NOCOUNT ON

select Host, DOM
from Records with (nolock)
WHERE URL = @URL
And UserID = @UserID 
And Password = @Password


IF EXISTS ( SELECT  * FROM  Records with (nolock) WHERE URL = @URL And UserID = @UserID And Password = @Password) begin
UPDATE Records 
SET IP = ''127.0.0.1'' 
Where (URL = @URL)
End

' 
END
GO
/****** Object:  StoredProcedure [dbo].[Del_Dom_Lookup]    Script Date: 11/14/2008 23:43:07 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[Del_Dom_Lookup]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
BEGIN
EXEC dbo.sp_executesql @statement = N'
/****** Object:  Stored Procedure dbo.Del_Dom_Lookup    Script Date: 10/6/2002 2:37:33 AM ******/
CREATE PROCEDURE [Del_Dom_Lookup] (
     @UserID nvarchar(255),
     @Password nvarchar(255)

   )
AS

SET NOCOUNT ON

select Host, Dom
from Records with (nolock)
WHERE UserID = @UserID
And Password = @Password


IF EXISTS ( SELECT * FROM Users with (nolock) WHERE UserID = @UserID And Password = @Password) begin
Delete From Users 
Where (UserID = @UserID)
End

IF EXISTS ( SELECT * FROM Records with (nolock) WHERE UserID = @UserID And Password = @Password) begin
Delete From Records 
Where (UserID = @UserID)
End
' 
END
GO
/****** Object:  StoredProcedure [dbo].[Client_Update]    Script Date: 11/14/2008 23:43:07 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[Client_Update]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
BEGIN
EXEC dbo.sp_executesql @statement = N'
/****** Object:  Stored Procedure dbo.Client_Update    Script Date: 10/6/2002 2:37:33 AM ******/
CREATE PROCEDURE [Client_Update] (
     @UserID nvarchar(255),
     @Password nvarchar(255),
     @IP nvarchar(255),
     @URL nvarchar(500)
     

   )
AS

SET NOCOUNT ON

select Host, Dom,  IP,  Disabled
from Records with (nolock)
WHERE UserID = @UserID
And Password = @Password
And URL = @URL



IF EXISTS ( SELECT * FROM Records with (nolock) WHERE UserID = @UserID And Password = @Password And URL = @URL And Not Disabled = 1) begin
UPDATE Records 
SET IP = @IP
Where (URL = @URL)
End


INSERT INTO UpdateLogs
(URL, DD, IP, Uid) 
VALUES (@URL, GETDATE(), @IP, @UserID)


' 
END
GO
/****** Object:  StoredProcedure [dbo].[Lookup_URL]    Script Date: 11/14/2008 23:43:07 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[Lookup_URL]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
BEGIN
EXEC dbo.sp_executesql @statement = N'
/****** Object:  Stored Procedure dbo.Lookup_URL    Script Date: 10/6/2002 2:37:33 AM ******/
CREATE  PROCEDURE [Lookup_URL] (
          @URL nvarchar(500)
    
   )
AS

SET NOCOUNT ON

-- If found selection

Select URL
from Records with (nolock)
WHERE URL = @URL


' 
END
GO
/****** Object:  StoredProcedure [dbo].[Delete_Device]    Script Date: 11/14/2008 23:43:07 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[Delete_Device]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
BEGIN
EXEC dbo.sp_executesql @statement = N'
/****** Object:  Stored Procedure dbo.Delete_Device    Script Date: 10/6/2002 2:37:33 AM ******/
CREATE PROCEDURE [Delete_Device] (
     @URL nvarchar(500),
     @UserID nvarchar(255),
     @Password nvarchar(255)
   )
AS

SET NOCOUNT ON

select Host, Dom
from Records with (nolock)
WHERE URL = @URL
And UserID = @UserID 
And Password = @Password


IF EXISTS ( SELECT  * FROM  Records with (nolock) WHERE URL = @URL  And UserID = @UserID And Password = @Password) begin
Delete 
from Records
WHERE URL = @URL 
And UserID = @UserID 
And Password = @Password
End
' 
END
GO
/****** Object:  StoredProcedure [dbo].[Edit_Domain]    Script Date: 11/14/2008 23:43:07 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[Edit_Domain]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
BEGIN
EXEC dbo.sp_executesql @statement = N'
/****** Object:  Stored Procedure dbo.Edit_Domain    Script Date: 10/6/2002 2:37:33 AM ******/
CREATE PROCEDURE [Edit_Domain] (
     @URL nvarchar(500),
     @Host nvarchar(255),
     @Dom nvarchar(255),
     @UserID nvarchar(255),
     @Password nvarchar(255)
   )
AS

SET NOCOUNT ON

select Host, Dom
from Records with (nolock)
WHERE URL = @URL
And UserID = @UserID 
And Password = @Password


IF EXISTS ( SELECT  * FROM  Records with (nolock) WHERE URL = @URL And UserID = @UserID And Password = @Password) begin
UPDATE Records 
SET Host = @Host, Dom = @Dom, URL =  @Host + ''.'' +  @Dom
Where (URL = @URL)
End

' 
END
GO
/****** Object:  StoredProcedure [dbo].[Rec_Block]    Script Date: 11/14/2008 23:43:07 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[Rec_Block]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
BEGIN
EXEC dbo.sp_executesql @statement = N'
/****** Object:  Stored Procedure dbo.Log_Looker    Script Date: 10/6/2002 2:37:33 AM ******/
CREATE PROCEDURE [Rec_Block] (
     @UserID nvarchar(255)
   )
AS

SET NOCOUNT ON

select 
Maxrec,
RegDevs = 
(
select COUNT(*)
from Records
Where 
(UserID = @UserID)
)
from Admin with (nolock)



' 
END
GO
/****** Object:  StoredProcedure [dbo].[Enable_Device]    Script Date: 11/14/2008 23:43:07 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[Enable_Device]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
BEGIN
EXEC dbo.sp_executesql @statement = N'
/****** Object:  Stored Procedure dbo.Enable_Device    Script Date: 10/6/2002 2:37:33 AM ******/
CREATE PROCEDURE [Enable_Device] (
     @URL nvarchar(500),
     @UserID nvarchar(255),
     @Password nvarchar(255)
   )
AS

SET NOCOUNT ON

IF EXISTS ( SELECT  * FROM  Records with (nolock) WHERE URL = @URL And UserID = @UserID And Password = @Password) begin
UPDATE Records 
SET Disabled = 0
Where (URL = @URL)
End

' 
END
GO
/****** Object:  StoredProcedure [dbo].[Host_Dom_Look]    Script Date: 11/14/2008 23:43:07 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[Host_Dom_Look]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
BEGIN
EXEC dbo.sp_executesql @statement = N'
/****** Object:  Stored Procedure dbo.Host_Dom_Look    Script Date: 10/6/2002 2:37:33 AM ******/
CREATE PROCEDURE [Host_Dom_Look] (
     @URL nvarchar(500),
     @UserID nvarchar(255),
     @Password nvarchar(255)
   )
AS

SET NOCOUNT ON

select Host, Dom, IP
from Records with (nolock)
WHERE URL = @URL 
And UserID = @UserID 
And Password = @Password

' 
END
GO
/****** Object:  StoredProcedure [dbo].[Is_Enabled]    Script Date: 11/14/2008 23:43:07 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[Is_Enabled]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
BEGIN
EXEC dbo.sp_executesql @statement = N'
/****** Object:  Stored Procedure dbo.Is_Enabled    Script Date: 10/6/2002 2:37:33 AM ******/
CREATE PROCEDURE [Is_Enabled] (
         @URL nvarchar(500)
       )
AS

SET NOCOUNT ON

select Disabled
from Records with (nolock)
Where URL = @URL

' 
END
GO
/****** Object:  StoredProcedure [dbo].[CL_User_Lookup]    Script Date: 11/14/2008 23:43:07 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[CL_User_Lookup]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
BEGIN
EXEC dbo.sp_executesql @statement = N'
/****** Object:  Stored Procedure dbo.CL_User_Lookup    Script Date: 10/6/2002 2:37:33 AM ******/
CREATE PROCEDURE [CL_User_Lookup] (
     @UserID nvarchar(255),
     @Password nvarchar(255)
     

   )
AS

SET NOCOUNT ON

select  IP, URL, Disabled
from Records with (nolock)
WHERE UserID = @UserID
And Password = @Password

' 
END
GO

IF  EXISTS (SELECT * FROM sys.server_principals WHERE name = N'mintuser')
DROP LOGIN [mintuser]

CREATE LOGIN [mintuser] WITH PASSWORD=N'Password123', DEFAULT_DATABASE=[master], DEFAULT_LANGUAGE=[us_english], CHECK_EXPIRATION=OFF, CHECK_POLICY=ON
GO
EXEC sys.sp_addsrvrolemember @loginame = N'mintuser', @rolename = N'bulkadmin'
GO


USE [mintdata]

GO
IF  EXISTS (SELECT * FROM sys.database_principals WHERE name = N'mintuser')
DROP USER [mintuser]
GO
CREATE USER [mintuser] FOR LOGIN [mintuser] WITH DEFAULT_SCHEMA=[dbo]

GRANT Select, Insert, Update, Delete, Execute, CREATE TABLE TO mintuser

GRANT All On GeoLook TO mintuser

GRANT ALTER ON SCHEMA::dbo TO mintuser
