Commit 418c8cfe authored by Ted Trask's avatar Ted Trask

Change bulk creation to use nid from database rather than hardcoding

parent fb9dad6b
......@@ -719,9 +719,16 @@ mymodule.set_bunchsettings = function (self, bunchdata)
local res, err = pcall(function()
local connected = vmaildb.databaseconnect()
local entry = {}
entry.value = getuserparams()
if not entry.value or not entry.value.username or not entry.value.firstname or not entry.value.lastname or not entry.value["vm-password"] then
error("Database parameters missing", 0)
end
entry.value["vm-password-confirm"] = nil
local sql = "BEGIN TRANSACTION"
vmaildb.runsqlcommand(sql)
for i,line in ipairs(format.string_to_table(format.dostounix(bunchdata.value.bunch.value), '\n')) do
if string.find(line, "%S") then
local username, firstname, lastname, password = string.match(line, "(%w+):(%w+):(%w+):(%w+)")
......@@ -736,19 +743,18 @@ mymodule.set_bunchsettings = function (self, bunchdata)
vmaildb.runsqlcommand("ROLLBACK")
break
else
local entry = cfe({value={}})
entry.value.username = cfe({value=username})
entry.value.firstname = cfe({value=firstname})
entry.value.lastname = cfe({value=lastname})
entry.value["vm-password"] = cfe({value=password})
entry.value.username.value = username
entry.value.firstname.value=firstname
entry.value.lastname.value=lastname
entry.value["vm-password"].value=password
if validateentry(entry) then
sql = "INSERT INTO voicemail_users VALUES(null, '"..vmaildb.escape(username).."')"
vmaildb.runsqlcommand(sql)
sql = "SELECT uid FROM voicemail_users where username ='"..vmaildb.escape(username).."'";
uid = vmaildb.getselectresponse(sql)
sql = "INSERT INTO voicemail_values VALUES('"..uid[1].uid.."', '2', '"..vmaildb.escape(tostring(firstname)).."')"
sql = "INSERT INTO voicemail_values VALUES('"..vmaildb.escape(uid[1].uid).."', '"..vmaildb.escape(entry.value.firstname.nid).."', '"..vmaildb.escape(tostring(firstname)).."')"
vmaildb.runsqlcommand(sql)
sql = "INSERT INTO voicemail_values VALUES('"..uid[1].uid.."', '3', '"..vmaildb.escape(tostring(lastname)).."')"
sql = "INSERT INTO voicemail_values VALUES('"..vmaildb.escape(uid[1].uid).."', '"..vmaildb.escape(entry.value.lastname.nid).."', '"..vmaildb.escape(tostring(lastname)).."')"
vmaildb.runsqlcommand(sql)
sql = "INSERT INTO voicemail_prefs (username, domain, password) VALUES ('"..vmaildb.escape(username).."', '"..config.domain.."', '"..vmaildb.escape(password).."')"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment