Commit 367f4f73 authored by Ted Trask's avatar Ted Trask
Browse files

Add searchusers action and make editusers and listusers actually be different

parent a23996b6
...@@ -10,8 +10,8 @@ mymodule.listusers = function( self ) ...@@ -10,8 +10,8 @@ mymodule.listusers = function( self )
return self.model.list_users() return self.model.list_users()
end end
mymodule.editusers = function( self ) mymodule.searchusers = function( self )
return self.model.list_users() return self.handle_form(self, self.model.get_search_options, self.model.search_users, self.clientdata, "Search", "Search Users")
end end
mymodule.deleteuser = function( self ) mymodule.deleteuser = function( self )
......
vmail-listusers-html.lsp
\ No newline at end of file
<% local view, viewlibrary, page_info, session = ...
htmlviewfunctions = require("htmlviewfunctions")
%>
<% if viewlibrary and viewlibrary.dispatch_component and viewlibrary.check_permission("listusers") then
viewlibrary.dispatch_component("listusers")
end %>
<% local redir = cfe({ type="hidden", value=page_info.orig_action }) %>
<% if viewlibrary and viewlibrary.dispatch_component and viewlibrary.check_permission("createuser") then %>
<% htmlviewfunctions.displayitem(cfe({type="link", value={redir=redir}, label="Create New User", option="Create", action="createuser" }), page_info) %>
<% end %>
<% if viewlibrary and viewlibrary.dispatch_component and viewlibrary.check_permission("createmanyusers") then %>
<% htmlviewfunctions.displayitem(cfe({type="link", value={redir=redir}, label="Create Multiple Users", option="Create", action="createmanyusers" }), page_info) %>
<% end %>
...@@ -62,12 +62,4 @@ html = require("acf.html") ...@@ -62,12 +62,4 @@ html = require("acf.html")
<p>No users found</p> <p>No users found</p>
<% end %> <% end %>
<% if viewlibrary and viewlibrary.dispatch_component and viewlibrary.check_permission("createuser") then %>
<% htmlviewfunctions.displayitem(cfe({type="link", value={redir=redir}, label="Create New User", option="Create", action="createuser" }), page_info, header_level2) %>
<% end %>
<% if viewlibrary and viewlibrary.dispatch_component and viewlibrary.check_permission("createmanyusers") then %>
<% htmlviewfunctions.displayitem(cfe({type="link", value={redir=redir}, label="Create Multiple Users", option="Create", action="createmanyusers" }), page_info, header_level2) %>
<% end %>
<% htmlviewfunctions.displaysectionend(header_level) %> <% htmlviewfunctions.displaysectionend(header_level) %>
...@@ -751,6 +751,45 @@ mymodule.list_users = function() ...@@ -751,6 +751,45 @@ mymodule.list_users = function()
return cfe({ type="structure", value=users, label="Voicemail Users", errtxt=errtxt }) return cfe({ type="structure", value=users, label="Voicemail Users", errtxt=errtxt })
end end
mymodule.get_search_options = function(self, clientdata)
retval = cfe({type="group", value={}, label="User Search"})
retval.value.username = cfe({label="Extension", seq=1})
retval.value.firstname = cfe({label="First Name", seq=2})
retval.value.lastname = cfe({label="Last Name", seq=3})
return retval
end
mymodule.search_users = function(self, search)
-- No validation
local res, err = pcall(function()
local connected = vmaildb.databaseconnect()
local where = {}
if search.value.username.value ~= "" then
where[#where+1] = "u.username ~ '"..vmaildb.escape(search.value.username.value).."'"
end
if search.value.firstname.value ~= "" then
where[#where+1] = "v2.value ~ '"..vmaildb.escape(search.value.firstname.value).."'"
end
if search.value.lastname.value ~= "" then
where[#where+1] = "v1.value ~ '"..vmaildb.escape(search.value.lastname.value).."'"
end
-- This crazy query gets the username from voicemail_users, the firstname and lastname from two instances of voicemail_values (using voicemail_params to determine the corresponding nid values) drops usernames starting with "tempuser" and ordering by username
local sql = "SELECT u.username, v1.value lastname, v2.value firstname FROM voicemail_users u LEFT OUTER JOIN voicemail_values v1 ON u.uid = v1.uid AND v1.nid=(SELECT nid FROM voicemail_params WHERE name='lastname') LEFT OUTER JOIN voicemail_values v2 ON u.uid = v2.uid AND v2.nid=(SELECT nid FROM voicemail_params WHERE name='firstname')"
if #where then
sql = sql.." WHERE "..table.concat(where, " AND ")
end
sql = sql.." ORDER BY u.username"
local users = vmaildb.getselectresponse(sql)
search.value.result = cfe({ type="structure", value=users, label="Voicemail Users" })
if connected then databasedisconnect() end
end)
if not res and err then
search.errtxt = err
end
return search
end
mymodule.get_delete_user = function(self, clientdata) mymodule.get_delete_user = function(self, clientdata)
local result = {} local result = {}
result.username = cfe({ value=clientdata.username or "", label="User Name" }) result.username = cfe({ value=clientdata.username or "", label="User Name" })
......
<% local form, viewlibrary, page_info, session = ...
htmlviewfunctions = require("htmlviewfunctions")
html = require("acf.html")
%>
<script type="text/javascript">
if (typeof jQuery == 'undefined') {
document.write('<script type="text/javascript" src="<%= html.html_escape(page_info.wwwprefix) %>/js/jquery-latest.js"><\/script>');
}
</script>
<% htmlviewfunctions.displaycommandresults({"createuser", "deleteuser", "editusersettings"}, session) %>
<%
if form.value.result then
local func = haserl.loadfile(page_info.viewfile:gsub("searchusers", "listusers"))
func(form.value.result, viewlibrary, page_info, session)
end
%>
<%
form.value.result = nil
htmlviewfunctions.displayitem(form, page_info)
%>
# Prefix and controller are already known at this point # Prefix and controller are already known at this point
# Cat Group Tab Action # Cat Group Tab Action
Applications 88Voicemail Search searchusers
Applications 88Voicemail Users editusers Applications 88Voicemail Users editusers
Applications 88Voicemail Voicemail listmessages Applications 88Voicemail Voicemail listmessages
Applications 88Voicemail Voicemail listmymessages Applications 88Voicemail Voicemail listmymessages
......
GUEST=vmail:processdialplanxml,vmail:processdirectoryxml GUEST=vmail:processdialplanxml,vmail:processdirectoryxml
USER=vmail:listfolders,vmail:listusers,vmail:listmymessages,vmail:downloadmymessage,vmail:deletemymessage,vmail:editmyusersettings,vmail:forwardmymessage,vmail:movemymessage,vmail:emailmymessage,vmail:callbackmymessage USER=vmail:listfolders,vmail:listusers,vmail:searchusers,vmail:listmymessages,vmail:downloadmymessage,vmail:deletemymessage,vmail:editmyusersettings,vmail:forwardmymessage,vmail:movemymessage,vmail:emailmymessage,vmail:callbackmymessage
EDITOR=vmail:editusers,vmail:createuser,vmail:createmanyusers,vmail:deleteuser,vmail:editusersettings EDITOR=vmail:editusers,vmail:createuser,vmail:createmanyusers,vmail:deleteuser,vmail:editusersettings
EXPERT=vmail:editconfig,vmail:listmessages,vmail:downloadmessage,vmail:deletemessage,vmail:forwardmessage,vmail:movemessage,vmail:emailmessage,vmail:callbackmessage EXPERT=vmail:editconfig,vmail:listmessages,vmail:downloadmessage,vmail:deletemessage,vmail:forwardmessage,vmail:movemessage,vmail:emailmessage,vmail:callbackmessage
ADMIN=vmail:listmessages,vmail:downloadmessage,vmail:deletemessage,vmail:forwardmessage,vmail:movemessage,vmail:emailmessage,vmail:callbackmessage,vmail:editusersettings,vmail:listfolders,vmail:listusers,vmail:editusers,vmail:createuser,vmail:createmanyusers,vmail:deleteuser,vmail:editconfig ADMIN=vmail:listmessages,vmail:downloadmessage,vmail:deletemessage,vmail:forwardmessage,vmail:movemessage,vmail:emailmessage,vmail:callbackmessage,vmail:editusersettings,vmail:listfolders,vmail:listusers,vmail:searchusers,vmail:editusers,vmail:createuser,vmail:createmanyusers,vmail:deleteuser,vmail:editconfig
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