<commit_before>require 'rubygems'
require 'sinatra'
require 'sinatra/reloader'
require 'sqlite3'

configure do
	@db = SQLite3::Database.new './public/main.db'
	@db.execute 'CREATE TABLE IF NOT EXISTS
							"Users"
							( "id" INTEGER PRIMARY KEY AUTOINCREMENT,
								"username" TEXT,
								"phone" TEXT,
								"datestamp" TEXT,
								"master" TEXT,
								"color" TEXT )'
end

def file_read file
	f = File.open file
	while (line=f.gets)
		@entry=@entry+line+"<br>"
	end
	f.close
end

def input_errors? hh
		@error = hh.select {|key| params[key] == ""}.values.join(", then ").downcase.capitalize
		if @error == ''
			@error = nil
			return false
		else
			return true
		end
end

get '/' do
	erb :index
end

get '/about' do
	erb :about
end

get '/visit' do
	erb :visit
end

get '/contacts' do
	erb :contacts
end

post '/' do
	@login = params[:login]
	@password = params[:password]

	hh = {:login => 'Enter login',
				:password => '<PASSWORD>',
				}

	return erb :index if input_errors? hh

	if @login == "admin" && @password == "<PASSWORD>"
		@entry="<label>Booked:</label><br><br>"
		file_read "./public/users.txt"
		@entry=@entry+"<br>"+"<br>"+"<label>Questions:</label>"+"<br>"
		file_read "./public/questions.txt"
	else
		@entry='<div class="alert alert-danger">ACCESS DENIED</div>'
	end

	erb :admin
end


post '/visit' do
	@username = params[:username]
	@phone = params[:phone]
	@time = params[:time]
	@master = params[:master]
	@color = params[:color]

	hh = {:username => 'Enter name',
				:phone => 'Enter phone',
				:time => 'Enter time'
				}

	return erb :visit if input_errors? hh

	f = File.open "./public/users.txt", "a"
	f.write "User: #{@username}, Phone: #{@phone}, Time: #{@time}, Master: #{@master}, Color: #{@color}\n"
	f.close

	erb "<div class='alert alert-success'>Thanks #{@username}! #{@master} is waiting you at #{@time}.</div>"
end

post '/contacts' do
	@email = params[:email]
	@text = params[:text]<commit_msg>Save users to db<commit_after>require 'rubygems'
require 'sinatra'
require 'sinatra/reloader'
require 'sqlite3'

#configure do
	db = SQLite3::Database.new './public/main.db'
	db.execute 'CREATE TABLE IF NOT EXISTS
							"Users"
							( "id" INTEGER PRIMARY KEY AUTOINCREMENT,
								"username" TEXT,
								"phone" TEXT,
								"datestamp" TEXT,
								"master" TEXT,
								"color" TEXT )'
#end

def file_read file
	f = File.open file
	while (line=f.gets)
		@entry=@entry+line+"<br>"
	end
	f.close
end

def input_errors? hh
		@error = hh.select {|key| params[key] == ""}.values.join(", then ").downcase.capitalize
		if @error == ''
			@error = nil
			return false
		else
			return true
		end
end

get '/' do
	erb :index
end

get '/about' do
	erb :about
end

get '/visit' do
	erb :visit
end

get '/contacts' do
	erb :contacts
end

post '/' do
	@login = params[:login]
	@password = params[:password]

	hh = {:login => 'Enter login',
				:password => '<PASSWORD>',
				}

	return erb :index if input_errors? hh

	if @login == "admin" && @password == "<PASSWORD>"
		@entry="<label>Booked:</label><br><br>"
		file_read "./public/users.txt"
		@entry=@entry+"<br>"+"<br>"+"<label>Questions:</label>"+"<br>"
		file_read "./public/questions.txt"
	else
		@entry='<div class="alert alert-danger">ACCESS DENIED</div>'
	end

	erb :admin
end


post '/visit' do
	@username = params[:username]
	@phone = params[:phone]
	@time = params[:time]
	@master = params[:master]
	@color = params[:color]

	hh = {:username => 'Enter name',
				:phone => 'Enter phone',
				:time => 'Enter time'
				}

	return erb :visit if input_errors? hh

	db.execute 'INSERT INTO Users (username, phone, datestamp, master, color) VALUES (?, ?, ?, ?, ?)', [@username, @phone, @time, @master, @color]

	f = File.open "./public/users.txt", "a"
	f.write "User: #{@username}, Phone: #{@phone}, Time: #{@time}, Master: #{@master}, Color: #{@color}\n"
	f.close

	erb "<div class='alert alert-success'>Thanks #{@username}! #{@master} is waiting you at #{@time}.</div>"
end

post '/contacts' do
	@email = params[:email]
	@text = params[:text]
{'fraction_non_alphanumeric': 0.18352244696595954, 'fraction_numerical': 0.000986679822397632, 'mean_word_length': 3.6342857142857143, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5761043', 'n_tokens_mistral': 1674, 'n_tokens_neox': 1475, 'n_words': 405}