1 | countFiles = 0; |
---|
2 | function validate_fields(type) |
---|
3 | { |
---|
4 | document.forms[0].uid.value = document.forms[0].uid.value.toLowerCase(); |
---|
5 | document.forms[0].old_uid.value = document.forms[0].old_uid.value.toLowerCase(); |
---|
6 | |
---|
7 | if (document.forms[0].uid.value == ''){ |
---|
8 | alert(document.getElementById('login_field_has_spaces').value); |
---|
9 | return; |
---|
10 | } |
---|
11 | |
---|
12 | if (document.forms[0].cn.value == ''){ |
---|
13 | alert(document.getElementById('list_email_field_is_empty').value); |
---|
14 | return; |
---|
15 | } |
---|
16 | |
---|
17 | if (document.forms[0].restrictionsOnEmailLists.value == 'true') |
---|
18 | { |
---|
19 | uid_tmp = document.forms[0].uid.value.split("-"); |
---|
20 | if ((uid_tmp.length < 3) || (uid_tmp[0] != 'lista')){ |
---|
21 | alert(document.getElementById('login_field_incomplete').value); |
---|
22 | return; |
---|
23 | } |
---|
24 | } |
---|
25 | |
---|
26 | if (document.forms[0].uid.value.split(" ").length > 1){ |
---|
27 | alert(document.getElementById('login_field_has_spaces').value); |
---|
28 | document.forms[0].uid.focus(); |
---|
29 | return; |
---|
30 | } |
---|
31 | |
---|
32 | if (document.forms[0].mail.value == ''){ |
---|
33 | alert(document.getElementById('list_email_field_is_empty').value); |
---|
34 | document.forms[0].mail.focus(); |
---|
35 | return; |
---|
36 | } |
---|
37 | var reEmail = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/; |
---|
38 | if(!reEmail.test(document.forms[0].mail.value)){ |
---|
39 | alert(document.getElementById('field_email_is_invalid').value); |
---|
40 | return false; |
---|
41 | } |
---|
42 | |
---|
43 | select_userInMaillist = document.getElementById('ea_select_usersInMaillist'); |
---|
44 | if (select_userInMaillist.options.length == 0){ |
---|
45 | alert(document.getElementById('no_user_is_part_of_the_list').value); |
---|
46 | return; |
---|
47 | } |
---|
48 | |
---|
49 | var handler_validate_fields = function(data) |
---|
50 | { |
---|
51 | if (!data.status) |
---|
52 | alert(data.msg); |
---|
53 | else |
---|
54 | { |
---|
55 | if (type == 'create_maillist') |
---|
56 | cExecuteForm ("$this.maillist.create", document.forms[0], handler_create); |
---|
57 | else if (type == 'edit_maillist') |
---|
58 | cExecuteForm ("$this.maillist.save", document.forms[0], handler_save); |
---|
59 | } |
---|
60 | } |
---|
61 | |
---|
62 | // Needed select all options from select |
---|
63 | for(var i=0; i<select_userInMaillist.options.length; i++) |
---|
64 | { |
---|
65 | // No IE, não seleciona o separador do select |
---|
66 | if (select_userInMaillist.options[i].value != -1) |
---|
67 | select_userInMaillist.options[i].selected = true; |
---|
68 | else |
---|
69 | select_userInMaillist.options[i].selected = false; |
---|
70 | } |
---|
71 | |
---|
72 | // O UID da lista foi alterado ou é uma nova lista. |
---|
73 | if ((document.forms[0].old_uid.value != document.forms[0].uid.value) || (type == 'create_maillist')){ |
---|
74 | cExecute ('$this.maillist.validate_fields&uid='+document.forms[0].uid.value+'&mail='+document.forms[0].mail.value, handler_validate_fields); |
---|
75 | } |
---|
76 | else if (type == 'edit_maillist') |
---|
77 | { |
---|
78 | cExecuteForm ("$this.maillist.save", document.forms[0], handler_save); |
---|
79 | } |
---|
80 | } |
---|
81 | |
---|
82 | // HANDLER CREATE |
---|
83 | // É necessário 2 funcões de retorno por causa do cExecuteForm. |
---|
84 | function handler_create(data) |
---|
85 | { |
---|
86 | return_handler_create(data); |
---|
87 | } |
---|
88 | function return_handler_create(data) |
---|
89 | { |
---|
90 | if (!data.status) |
---|
91 | alert(data.msg); |
---|
92 | else{ |
---|
93 | alert(document.getElementById('email_list_successfully_created').value); |
---|
94 | location.href="./index.php?menuaction=expressoAdmin1_2.uimaillists.list_maillists"; |
---|
95 | } |
---|
96 | return; |
---|
97 | } |
---|
98 | |
---|
99 | // HANDLER SAVE |
---|
100 | // É necessário 2 funcões de retorno por causa do cExecuteForm. |
---|
101 | function handler_save(data) |
---|
102 | { |
---|
103 | return_handler_save(data); |
---|
104 | } |
---|
105 | function return_handler_save(data) |
---|
106 | { |
---|
107 | if (!data.status) |
---|
108 | alert(data.msg); |
---|
109 | else{ |
---|
110 | alert(document.getElementById('email_list_successfully_saved').value); |
---|
111 | location.href="./index.php?menuaction=expressoAdmin1_2.uimaillists.list_maillists"; |
---|
112 | } |
---|
113 | return; |
---|
114 | } |
---|
115 | |
---|
116 | function save_scl() |
---|
117 | { |
---|
118 | select_users_SCL_Maillist = document.getElementById('ea_select_users_SCL_Maillist'); |
---|
119 | // Needed select all options from select |
---|
120 | for(var i=0; i<select_users_SCL_Maillist.options.length; i++) |
---|
121 | select_users_SCL_Maillist.options[i].selected = true; |
---|
122 | |
---|
123 | cExecuteForm ("$this.maillist.save_scl", document.forms[0], handler_save_scl); |
---|
124 | } |
---|
125 | function handler_save_scl(data) |
---|
126 | { |
---|
127 | return_handler_save_scl(data); |
---|
128 | } |
---|
129 | |
---|
130 | function return_handler_save_scl(data) |
---|
131 | { |
---|
132 | if (!data.status) |
---|
133 | alert(data.msg); |
---|
134 | else |
---|
135 | alert(document.getElementById('sending_control_list_successfully_saved').value); |
---|
136 | location.href="./index.php?menuaction=expressoAdmin1_2.uimaillists.list_maillists"; |
---|
137 | return; |
---|
138 | } |
---|
139 | |
---|
140 | function sinc_combos_org(context, recursive) |
---|
141 | { |
---|
142 | combo_org_maillists = document.getElementById('ea_combo_org_maillists'); |
---|
143 | |
---|
144 | for (i=0; i<combo_org_maillists.length; i++) |
---|
145 | { |
---|
146 | if (combo_org_maillists.options[i].value == context) |
---|
147 | { |
---|
148 | combo_org_maillists.options[i].selected = true; |
---|
149 | get_available_users(context, recursive); |
---|
150 | break; |
---|
151 | } |
---|
152 | } |
---|
153 | } |
---|
154 | |
---|
155 | function get_available_users(context, recursive) |
---|
156 | { |
---|
157 | var handler_get_available_users = function(data) |
---|
158 | { |
---|
159 | select_available_users = document.getElementById('ea_select_available_users'); |
---|
160 | |
---|
161 | //Limpa o select |
---|
162 | for(var i=0; i<select_available_users.options.length; i++) |
---|
163 | { |
---|
164 | select_available_users.options[i] = null; |
---|
165 | i--; |
---|
166 | } |
---|
167 | |
---|
168 | if ((data) && (data.length > 0)) |
---|
169 | { |
---|
170 | // Necessario, pois o IE6 tem um bug que retira o primeiro options se o innerHTML estiver vazio. |
---|
171 | select_available_users.innerHTML = ' ' + data; |
---|
172 | select_available_users.outerHTML = select_available_users.outerHTML; |
---|
173 | |
---|
174 | select_available_users.disabled = false; |
---|
175 | select_available_users_clone = document.getElementById('ea_select_available_users').cloneNode(true); |
---|
176 | document.getElementById('ea_input_searchUser').value = ''; |
---|
177 | } |
---|
178 | } |
---|
179 | |
---|
180 | //Impede chamada recursiva na raiz das organizações |
---|
181 | if ((recursive) && (document.forms[0].ldap_context.value == document.getElementById('ea_combo_org_maillists').value)) |
---|
182 | { |
---|
183 | alert(document.getElementById('it_is_not_possible_select_users').value); |
---|
184 | document.getElementById('ea_check_allUsers').checked = false; |
---|
185 | |
---|
186 | // Limpa select |
---|
187 | select_available_users = document.getElementById('ea_select_available_users'); |
---|
188 | select_available_users.innerHTML = ' '; |
---|
189 | select_available_users.outerHTML = select_available_users.outerHTML; |
---|
190 | return; |
---|
191 | } |
---|
192 | cExecute ('$this.ldap_functions.get_available_users_and_maillist&context='+context+'&recursive='+recursive+'&denied_uidnumber='+document.forms[0].uidnumber.value, handler_get_available_users); |
---|
193 | } |
---|
194 | |
---|
195 | function add_user2maillist() |
---|
196 | { |
---|
197 | select_available_users = document.getElementById('ea_select_available_users'); |
---|
198 | select_usersInMaillist = document.getElementById('ea_select_usersInMaillist'); |
---|
199 | |
---|
200 | var count_available_users = select_available_users.length; |
---|
201 | var count_usersInMailList = select_usersInMaillist.options.length; |
---|
202 | var new_options = ''; |
---|
203 | |
---|
204 | for (i = 0 ; i < count_available_users ; i++) |
---|
205 | { |
---|
206 | if (select_available_users.options[i].selected) |
---|
207 | { |
---|
208 | if(document.all) |
---|
209 | { |
---|
210 | if ( (select_usersInMaillist.innerHTML.indexOf('value='+select_available_users.options[i].value)) == '-1' ) |
---|
211 | { |
---|
212 | new_options += "<option value=" |
---|
213 | + select_available_users.options[i].value |
---|
214 | + ">" |
---|
215 | + select_available_users.options[i].text |
---|
216 | + "</options>"; |
---|
217 | } |
---|
218 | } |
---|
219 | else |
---|
220 | { |
---|
221 | if ( (select_usersInMaillist.innerHTML.indexOf('value="'+select_available_users.options[i].value+'"')) == '-1' ) |
---|
222 | { |
---|
223 | new_options += "<option value=" |
---|
224 | + select_available_users.options[i].value |
---|
225 | + ">" |
---|
226 | + select_available_users.options[i].text |
---|
227 | + "</options>"; |
---|
228 | } |
---|
229 | } |
---|
230 | } |
---|
231 | } |
---|
232 | |
---|
233 | if (new_options != '') |
---|
234 | { |
---|
235 | select_usersInMaillist.innerHTML = ' ' + new_options + select_usersInMaillist.innerHTML; |
---|
236 | select_usersInMaillist.outerHTML = select_usersInMaillist.outerHTML; |
---|
237 | document.getElementById('ea_input_searchUser').value = ""; |
---|
238 | } |
---|
239 | } |
---|
240 | |
---|
241 | function remove_user2maillist() |
---|
242 | { |
---|
243 | select_usersInMaillist = document.getElementById('ea_select_usersInMaillist'); |
---|
244 | |
---|
245 | for(var i = 0;i < select_usersInMaillist.options.length; i++) |
---|
246 | if(select_usersInMaillist.options[i].selected) |
---|
247 | select_usersInMaillist.options[i--] = null; |
---|
248 | } |
---|
249 | |
---|
250 | function add_user2scl_maillist() |
---|
251 | { |
---|
252 | select_available_users = document.getElementById('ea_select_available_users'); |
---|
253 | select_usersInMaillist = document.getElementById('ea_select_users_SCL_Maillist'); |
---|
254 | |
---|
255 | var count_available_users = select_available_users.length; |
---|
256 | var count_usersInMailList = select_usersInMaillist.options.length; |
---|
257 | var new_options = ''; |
---|
258 | |
---|
259 | for (i = 0 ; i < count_available_users ; i++) |
---|
260 | { |
---|
261 | if (select_available_users.options[i].selected) |
---|
262 | { |
---|
263 | if(document.all) |
---|
264 | { |
---|
265 | if ( (select_usersInMaillist.innerHTML.indexOf('value='+select_available_users.options[i].value)) == '-1' ) |
---|
266 | { |
---|
267 | new_options += "<option value=" |
---|
268 | + select_available_users.options[i].value |
---|
269 | + ">" |
---|
270 | + select_available_users.options[i].text |
---|
271 | + "</options>"; |
---|
272 | } |
---|
273 | } |
---|
274 | else |
---|
275 | { |
---|
276 | if ( (select_usersInMaillist.innerHTML.indexOf('value="'+select_available_users.options[i].value+'"')) == '-1' ) |
---|
277 | { |
---|
278 | new_options += "<option value=" |
---|
279 | + select_available_users.options[i].value |
---|
280 | + ">" |
---|
281 | + select_available_users.options[i].text |
---|
282 | + "</options>"; |
---|
283 | } |
---|
284 | } |
---|
285 | } |
---|
286 | } |
---|
287 | |
---|
288 | if (new_options != '') |
---|
289 | { |
---|
290 | select_usersInMaillist.innerHTML = '#' + new_options + select_usersInMaillist.innerHTML; |
---|
291 | select_usersInMaillist.outerHTML = select_usersInMaillist.outerHTML; |
---|
292 | } |
---|
293 | } |
---|
294 | |
---|
295 | function remove_user2scl_maillist() |
---|
296 | { |
---|
297 | select_usersInMaillist = document.getElementById('ea_select_users_SCL_Maillist'); |
---|
298 | |
---|
299 | for(var i = 0;i < select_usersInMaillist.options.length; i++) |
---|
300 | if(select_usersInMaillist.options[i].selected) |
---|
301 | select_usersInMaillist.options[i--] = null; |
---|
302 | } |
---|
303 | |
---|
304 | |
---|
305 | // Variaveis Locais |
---|
306 | if (document.getElementById('ea_select_available_users')) |
---|
307 | { |
---|
308 | var select_available_users = document.getElementById('ea_select_available_users'); |
---|
309 | var select_available_users_clone = select_available_users.cloneNode(true); |
---|
310 | } |
---|
311 | else |
---|
312 | { |
---|
313 | var select_available_users = ''; |
---|
314 | var select_available_users_clone = ''; |
---|
315 | } |
---|
316 | var finderTimeout = ''; |
---|
317 | |
---|
318 | // Funcoes |
---|
319 | function optionFinderTimeout(obj) |
---|
320 | { |
---|
321 | clearTimeout(finderTimeout); |
---|
322 | var oWait = document.getElementById("ea_span_searching"); |
---|
323 | oWait.innerHTML = 'Buscando...'; |
---|
324 | finderTimeout = setTimeout("optionFinder('"+obj.id+"')",500); |
---|
325 | } |
---|
326 | function optionFinder(id) { |
---|
327 | var oWait = document.getElementById("ea_span_searching"); |
---|
328 | var oText = document.getElementById(id); |
---|
329 | |
---|
330 | //Limpa todo o select |
---|
331 | var select_available_users_tmp = document.getElementById('ea_select_available_users') |
---|
332 | |
---|
333 | for(var i = 0;i < select_available_users_tmp.options.length; i++) |
---|
334 | select_available_users_tmp.options[i--] = null; |
---|
335 | |
---|
336 | var RegExp_name = new RegExp("\\b"+oText.value, "i"); |
---|
337 | |
---|
338 | //Inclui usuário começando com a pesquisa |
---|
339 | for(i = 0; i < select_available_users_clone.length; i++){ |
---|
340 | if ( RegExp_name.test(select_available_users_clone[i].text) || (select_available_users_clone[i].value == -1) ) |
---|
341 | { |
---|
342 | sel = select_available_users_tmp.options; |
---|
343 | option = new Option(select_available_users_clone[i].text,select_available_users_clone[i].value); |
---|
344 | |
---|
345 | if (select_available_users_clone[i].value == -1) |
---|
346 | option.disabled = true; |
---|
347 | |
---|
348 | sel[sel.length] = option; |
---|
349 | } |
---|
350 | } |
---|
351 | oWait.innerHTML = ' '; |
---|
352 | } |
---|
353 | |
---|
354 | function delete_maillist(uid, uidnumber) |
---|
355 | { |
---|
356 | if (confirm(document.getElementById('delete_list').value + uid + " ??")) |
---|
357 | { |
---|
358 | var handler_delete_maillist = function(data) |
---|
359 | { |
---|
360 | if (!data.status) |
---|
361 | alert(data.msg); |
---|
362 | else |
---|
363 | alert(document.getElementById('email_list_successfully_deleted'); |
---|
364 | |
---|
365 | location.href="./index.php?menuaction=expressoAdmin1_2.uimaillists.list_maillists"; |
---|
366 | return; |
---|
367 | } |
---|
368 | cExecute ('$this.maillist.delete&uidnumber='+uidnumber, handler_delete_maillist); |
---|
369 | } |
---|
370 | } |
---|
371 | |
---|
372 | function search_organization(key, element) |
---|
373 | { |
---|
374 | var organizations = document.getElementById(element); |
---|
375 | var RegExp_org = new RegExp("\\b"+key, "i"); |
---|
376 | |
---|
377 | for(i = 0; i < organizations.length; i++) |
---|
378 | { |
---|
379 | if (RegExp_org.test(organizations[i].text)) |
---|
380 | { |
---|
381 | organizations[i].selected = true; |
---|
382 | return; |
---|
383 | } |
---|
384 | } |
---|
385 | } |
---|
386 | |
---|
387 | function emailSuggestion_maillist() |
---|
388 | { |
---|
389 | var defaultDomain = document.forms[0].defaultDomain.value; |
---|
390 | var base_dn = "." + dn2ufn(document.forms[0].ldap_context.value); |
---|
391 | var selected_context = dn2ufn(document.forms[0].context.value.toLowerCase()); |
---|
392 | |
---|
393 | var uid = document.getElementById("ea_maillist_uid"); |
---|
394 | var mail= document.getElementById("ea_maillist_mail"); |
---|
395 | |
---|
396 | var raw_selected_context = selected_context.replace(base_dn, ""); |
---|
397 | |
---|
398 | var array_org_name = raw_selected_context.split('.'); |
---|
399 | var org_name = array_org_name[array_org_name.length-1]; |
---|
400 | |
---|
401 | if (mail.value == "") |
---|
402 | mail.value = uid.value + "@" + org_name + "." + defaultDomain; |
---|
403 | } |
---|
404 | |
---|
405 | function dn2ufn(dn) |
---|
406 | { |
---|
407 | var ufn = ''; |
---|
408 | var array_dn = dn.split(","); |
---|
409 | for (x in array_dn) |
---|
410 | { |
---|
411 | var tmp = array_dn[x].split("="); |
---|
412 | ufn += tmp[1] + '.'; |
---|
413 | } |
---|
414 | return ufn.substring(0,(ufn.length-1)); |
---|
415 | } |
---|