1 | countFiles = 1; |
---|
2 | |
---|
3 | function create_institutional_accounts() |
---|
4 | { |
---|
5 | select_owners = Element('ea_select_owners'); |
---|
6 | for(var i = 0;i < select_owners.options.length; i++) |
---|
7 | select_owners.options[i].selected = true; |
---|
8 | cExecuteForm ("$this.ldap_functions.create_institutional_accounts", document.forms['institutional_accounts_form'], handler_create_institutional_accounts); |
---|
9 | } |
---|
10 | |
---|
11 | function handler_create_institutional_accounts(data_return) |
---|
12 | { |
---|
13 | handler_create_institutional_accounts2(data_return); |
---|
14 | return; |
---|
15 | } |
---|
16 | |
---|
17 | function handler_create_institutional_accounts2(data_return) |
---|
18 | { |
---|
19 | if (!data_return.status) |
---|
20 | { |
---|
21 | write_msg(data_return.msg, 'error'); |
---|
22 | } |
---|
23 | else |
---|
24 | { |
---|
25 | close_lightbox(); |
---|
26 | write_msg(get_lang('Institutional account successful created') + '.', 'normal'); |
---|
27 | } |
---|
28 | return; |
---|
29 | } |
---|
30 | |
---|
31 | function set_onload() |
---|
32 | { |
---|
33 | sinc_combos_org(Element('ea_combo_org').value); |
---|
34 | get_available_users(Element('ea_combo_org').value); |
---|
35 | } |
---|
36 | |
---|
37 | function get_available_users(context) |
---|
38 | { |
---|
39 | var handler_get_users = function(data) |
---|
40 | { |
---|
41 | select_available_users = Element('ea_select_available_users'); |
---|
42 | |
---|
43 | //Clean select |
---|
44 | for(var i=0; i<select_available_users.options.length; i++) |
---|
45 | { |
---|
46 | select_available_users.options[i] = null; |
---|
47 | i--; |
---|
48 | } |
---|
49 | |
---|
50 | if ((data) && (data.length > 0)) |
---|
51 | { |
---|
52 | // Necessario, pois o IE6 tem um bug que retira o primeiro options se o innerHTML estiver vazio. |
---|
53 | select_available_users.innerHTML = ' ' + data; |
---|
54 | select_available_users.outerHTML = select_available_users.outerHTML; |
---|
55 | |
---|
56 | select_available_users.disabled = false; |
---|
57 | select_available_users_clone = Element('ea_select_available_users').cloneNode(true); |
---|
58 | //document.getElementById('ea_input_searchUser').value = ''; |
---|
59 | } |
---|
60 | } |
---|
61 | cExecute ('$this.ldap_functions.get_available_users&context='+context, handler_get_users); |
---|
62 | } |
---|
63 | |
---|
64 | function search_organization(key, element) |
---|
65 | { |
---|
66 | var organizations = Element(element); |
---|
67 | var RegExp_org = new RegExp("\\b"+key, "i"); |
---|
68 | |
---|
69 | for(i = 0; i < organizations.length; i++) |
---|
70 | { |
---|
71 | if (RegExp_org.test(organizations[i].text)) |
---|
72 | { |
---|
73 | organizations[i].selected = true; |
---|
74 | return; |
---|
75 | } |
---|
76 | } |
---|
77 | } |
---|
78 | |
---|
79 | function sinc_combos_org(context) |
---|
80 | { |
---|
81 | combo_org_available_users = Element('ea_combo_org_available_users'); |
---|
82 | |
---|
83 | for (i=0; i<combo_org_available_users.length; i++) |
---|
84 | { |
---|
85 | if (combo_org_available_users.options[i].value == context) |
---|
86 | { |
---|
87 | combo_org_available_users.options[i].selected = true; |
---|
88 | get_available_users(context); |
---|
89 | break; |
---|
90 | } |
---|
91 | } |
---|
92 | } |
---|
93 | |
---|
94 | var finderTimeout = ''; |
---|
95 | function optionFinderTimeout(obj) |
---|
96 | { |
---|
97 | clearTimeout(finderTimeout); |
---|
98 | var oWait = Element("ea_span_searching"); |
---|
99 | oWait.innerHTML = get_lang('searching') + '...'; |
---|
100 | finderTimeout = setTimeout("optionFinder('"+obj.id+"')",500); |
---|
101 | } |
---|
102 | function optionFinder(id) { |
---|
103 | var oWait = Element("ea_span_searching"); |
---|
104 | var oText = Element(id); |
---|
105 | |
---|
106 | //Limpa todo o select |
---|
107 | var select_available_users_tmp = Element('ea_select_available_users') |
---|
108 | |
---|
109 | for(var i = 0;i < select_available_users_tmp.options.length; i++) |
---|
110 | select_available_users_tmp.options[i--] = null; |
---|
111 | |
---|
112 | var RegExp_name = new RegExp("\\b"+oText.value, "i"); |
---|
113 | |
---|
114 | //Inclui usuário começando com a pesquisa |
---|
115 | for(i = 0; i < select_available_users_clone.length; i++){ |
---|
116 | if ( RegExp_name.test(select_available_users_clone[i].text) || (select_available_users_clone[i].value == -1) ) |
---|
117 | { |
---|
118 | sel = select_available_users_tmp.options; |
---|
119 | option = new Option(select_available_users_clone[i].text,select_available_users_clone[i].value); |
---|
120 | |
---|
121 | if (select_available_users_clone[i].value == -1) |
---|
122 | option.disabled = true; |
---|
123 | |
---|
124 | sel[sel.length] = option; |
---|
125 | } |
---|
126 | } |
---|
127 | oWait.innerHTML = ' '; |
---|
128 | } |
---|
129 | |
---|
130 | function add_user() |
---|
131 | { |
---|
132 | select_available_users = Element('ea_select_available_users'); |
---|
133 | select_owners = Element('ea_select_owners'); |
---|
134 | |
---|
135 | var count_available_users = select_available_users.length; |
---|
136 | // var count_owners = select_owners.options.length; |
---|
137 | var new_options = ''; |
---|
138 | |
---|
139 | for (i = 0 ; i < count_available_users ; i++) |
---|
140 | { |
---|
141 | if (select_available_users.options[i].selected) |
---|
142 | { |
---|
143 | if(document.all) |
---|
144 | { |
---|
145 | if ( (select_owners.innerHTML.indexOf('value='+select_available_users.options[i].value)) == '-1' ) |
---|
146 | { |
---|
147 | new_options += "<option value=" |
---|
148 | + select_available_users.options[i].value |
---|
149 | + ">" |
---|
150 | + select_available_users.options[i].text |
---|
151 | + "</options>"; |
---|
152 | } |
---|
153 | } |
---|
154 | else |
---|
155 | { |
---|
156 | if ( (select_owners.innerHTML.indexOf('value="'+select_available_users.options[i].value+'"')) == '-1' ) |
---|
157 | { |
---|
158 | new_options += "<option value=" |
---|
159 | + select_available_users.options[i].value |
---|
160 | + ">" |
---|
161 | + select_available_users.options[i].text |
---|
162 | + "</options>"; |
---|
163 | } |
---|
164 | } |
---|
165 | } |
---|
166 | } |
---|
167 | |
---|
168 | if (new_options != '') |
---|
169 | { |
---|
170 | select_owners.innerHTML = ' ' + new_options + select_owners.innerHTML; |
---|
171 | select_owners.outerHTML = select_owners.outerHTML; |
---|
172 | document.getElementById('ea_input_searchUser').value = ""; |
---|
173 | } |
---|
174 | } |
---|
175 | |
---|
176 | function remove_user() |
---|
177 | { |
---|
178 | select_owners = Element('ea_select_owners'); |
---|
179 | for(var i = 0;i < select_owners.options.length; i++) |
---|
180 | if(select_owners.options[i].selected) |
---|
181 | select_owners.options[i--] = null; |
---|
182 | } |
---|
183 | |
---|
184 | function get_institutional_accounts_timeOut(input) |
---|
185 | { |
---|
186 | var head_table = '<table border="0" width="90%"><tr bgcolor="#d3dce3"><td width="30%">'+get_lang("full name")+'</td><td width="30%">'+get_lang("mail")+'</td><td width="5%" align="center">'+get_lang("delete")+'</td></tr></table>'; |
---|
187 | |
---|
188 | if (input.length > 4) |
---|
189 | { |
---|
190 | clearTimeout(finderTimeout); |
---|
191 | finderTimeout = setTimeout("get_institutional_accounts('"+input+"')",500); |
---|
192 | } |
---|
193 | else |
---|
194 | { |
---|
195 | Element('institutional_accounts_content').innerHTML = head_table; |
---|
196 | } |
---|
197 | } |
---|
198 | |
---|
199 | function get_institutional_accounts(input) |
---|
200 | { |
---|
201 | var handler_get_institutional_accounts = function(data) |
---|
202 | { |
---|
203 | if (data.status == 'true') |
---|
204 | { |
---|
205 | var table = '<table border="0" width="90%"><tr bgcolor="#d3dce3"><td width="30%">'+get_lang("full name")+'</td><td width="30%">'+get_lang("mail")+'</td><td width="5%" align="center">'+get_lang("delete")+'</td></tr>'+data.trs+'</table>'; |
---|
206 | Element('institutional_accounts_content').innerHTML = table; |
---|
207 | } |
---|
208 | else |
---|
209 | write_msg(data.msg, 'error'); |
---|
210 | } |
---|
211 | cExecute ('$this.ldap_functions.get_institutional_accounts&input='+input, handler_get_institutional_accounts); |
---|
212 | } |
---|
213 | |
---|
214 | function edit_institutional_account(uid) |
---|
215 | { |
---|
216 | var handle_edit_institutional_account = function(data) |
---|
217 | { |
---|
218 | if (data.status == 'true') |
---|
219 | { |
---|
220 | modal('institutional_accounts_modal','save'); |
---|
221 | |
---|
222 | var combo_org = Element('ea_combo_org'); |
---|
223 | for (i=0; i<combo_org.length; i++) |
---|
224 | { |
---|
225 | if (combo_org.options[i].value == data.user_context) |
---|
226 | { |
---|
227 | combo_org.options[i].selected = true; |
---|
228 | break; |
---|
229 | } |
---|
230 | } |
---|
231 | |
---|
232 | // anchor |
---|
233 | Element('anchor').value = "uid=" + uid + ',' + data.user_context; |
---|
234 | |
---|
235 | if (data.accountStatus != 'active') |
---|
236 | Element('accountStatus').checked = false; |
---|
237 | |
---|
238 | if (data.phpgwAccountVisible == '-1') |
---|
239 | Element('phpgwAccountVisible').checked = true; |
---|
240 | |
---|
241 | Element('cn').value = data.cn; |
---|
242 | Element('mail').value = data.mail; |
---|
243 | Element('description').value = data.description; |
---|
244 | Element('ea_select_owners').innerHTML = data.owners; |
---|
245 | |
---|
246 | sinc_combos_org(data.user_context); |
---|
247 | } |
---|
248 | else |
---|
249 | write_msg(data.msg, 'error'); |
---|
250 | } |
---|
251 | cExecute ('$this.ldap_functions.get_institutional_account_data&uid='+uid, handle_edit_institutional_account); |
---|
252 | } |
---|
253 | |
---|
254 | function save_institutional_accounts() |
---|
255 | { |
---|
256 | if (is_ie){ |
---|
257 | var i = 0; |
---|
258 | while (document.forms(i).name != "institutional_accounts_form"){i++} |
---|
259 | form = document.forms(i); |
---|
260 | } |
---|
261 | else |
---|
262 | form = document.forms["institutional_accounts_form"]; |
---|
263 | |
---|
264 | select_owners = Element('ea_select_owners'); |
---|
265 | for(var i = 0;i < select_owners.options.length; i++) |
---|
266 | select_owners.options[i].selected = true; |
---|
267 | cExecuteForm ("$this.ldap_functions.save_institutional_accounts", form, handler_save_institutional_accounts); |
---|
268 | } |
---|
269 | |
---|
270 | function handler_save_institutional_accounts(data_return) |
---|
271 | { |
---|
272 | handler_save_institutional_accounts2(data_return); |
---|
273 | return; |
---|
274 | } |
---|
275 | function handler_save_institutional_accounts2(data_return) |
---|
276 | { |
---|
277 | if (!data_return.status) |
---|
278 | { |
---|
279 | write_msg(data_return.msg, 'error'); |
---|
280 | } |
---|
281 | else |
---|
282 | { |
---|
283 | get_institutional_accounts(Element('ea_institutional_account_search').value); |
---|
284 | close_lightbox(); |
---|
285 | write_msg(get_lang('Institutional account successful saved') + '.', 'normal'); |
---|
286 | } |
---|
287 | return; |
---|
288 | } |
---|
289 | |
---|
290 | function delete_institutional_accounts(uid) |
---|
291 | { |
---|
292 | if (!confirm(get_lang('Are you sure that you want to delete this institutional account') + "?")) |
---|
293 | return; |
---|
294 | |
---|
295 | var handle_delete_institutional_account = function(data_return) |
---|
296 | { |
---|
297 | if (!data_return.status) |
---|
298 | { |
---|
299 | write_msg(data_return.msg, 'error'); |
---|
300 | } |
---|
301 | else |
---|
302 | { |
---|
303 | write_msg(get_lang('Institutional account successful deleted') + '.', 'normal'); |
---|
304 | get_institutional_accounts(Element('ea_institutional_account_search').value); |
---|
305 | } |
---|
306 | return; |
---|
307 | } |
---|
308 | cExecute ('$this.ldap_functions.delete_institutional_account_data&uid='+uid, handle_delete_institutional_account); |
---|
309 | } |
---|