日期:2014-05-16 浏览次数:21266 次
onload_table(Host) ->
?DEBUG("In ~p module ~p onload data from mysql Host ~p ~n", [?MODULE, ?LINE, Host]),
odbc_queries:sql_get_privacy_list_default(Host),
PrivacyListDefault =
case catch odbc_queries:sql_get_privacy_list_default(Host) of
{selected, ["username", "name"], []} ->[];
{selected, ["username", "name"], PrivacyListDefault1} -> PrivacyListDefault1
end,
PrivacyListData =
case catch odbc_queries:sql_get_privacy_list_data(Host) of
{selected, ["id", "t", "value", "action", "ord", "match_all",
"match_iq", "match_message",
"match_presence_in", "match_presence_out"],
[]} ->[];
{selected, ["id", "t", "value", "action", "ord", "match_all",
"match_iq", "match_message",
"match_presence_in", "match_presence_out"],
RItems} ->
Items = lists:map(fun raw_to_item_with_id/1, RItems),
Items
end,
case catch odbc_queries:sql_get_privacy_list(Host) of
{selected, ["username", "name", "id"], []} -> [];
{selected, ["username", "name", "id"], PrivacyList} ->
assemble_data(PrivacyListDefault, PrivacyList, PrivacyListData, [],Host)
end.
assemble_data(DList, [P | PList], PLData, Res,Host)->
case P of
{UserName, ListName, Id} ->
Default =
case [{K, V} || {K, V} <- DList, K =:= UserName] of
[] -> none;
[{UserName, ListName}] -> ListName;
_ -> none
end,
Test = [{listitem, Type, Value, Action, Order, All, Iq, Message, In, Out}
||{Kid, {listitem, Type, Value, Action, Order, All, Iq, Message, In, Out}}
<- PLData, Kid =:= Id],
ListItems =
%case [{listitem, Type, Value, Action, Order, All, Iq, Message, In, Out}
% || {listitem, Type, Value, Action, Order, All, Iq, Message, In, Out}
% <- PLData, Order =:= Id] of
case [ListItem
|| {Kid, #listitem{}=ListItem}
<- PLData, Kid =:= Id] of
ListItems1 when is_list(ListItems1)->
ListItems1;
[] -> [];
_ -> []
end,
Privacy = #privacy{us = {UserName, Host}, default = Default, lists = ListItems},
mnesia:dirty_write(Privacy),
assemble_data(DList, PList, PLData, Res,Host);
_ ->
assemble_data(DList, PList, PLData, Res,Host)
end;
assemble_data(_DList, [], _PLData, Res,_Host)->
Res.
?