1 | countFiles = 0; |
---|
2 | |
---|
3 | function Element(id){ |
---|
4 | return document.getElementById( id ); |
---|
5 | } |
---|
6 | |
---|
7 | function validate_fields(type) |
---|
8 | { |
---|
9 | document.forms[0].uid.value = document.forms[0].uid.value.toLowerCase(); |
---|
10 | document.forms[0].old_uid.value = document.forms[0].old_uid.value.toLowerCase(); |
---|
11 | |
---|
12 | if (document.forms[0].uid.value == ''){ |
---|
13 | alert(get_lang('login field is empty') + '.'); |
---|
14 | return; |
---|
15 | } |
---|
16 | |
---|
17 | if (document.forms[0].cn.value == ''){ |
---|
18 | alert(get_lang('name field is empty') + '.'); |
---|
19 | return; |
---|
20 | } |
---|
21 | |
---|
22 | if (document.forms[0].restrictionsOnEmailLists.value == 'true') |
---|
23 | { |
---|
24 | uid_tmp = document.forms[0].uid.value.split("-"); |
---|
25 | if ((uid_tmp.length < 3) || (uid_tmp[0] != 'lista')){ |
---|
26 | alert( |
---|
27 | get_lang('login field is incomplete') + '.\n' + |
---|
28 | get_lang('the login field must be formed like') + ':\n' + |
---|
29 | get_lang('list') + '-' + get_lang('organization') + '-' + get_lang('listname') + '.\n' + |
---|
30 | get_lang('eg') + ': ' + 'lista-celepar-rh.'); |
---|
31 | return; |
---|
32 | } |
---|
33 | } |
---|
34 | |
---|
35 | if (document.forms[0].uid.value.split(" ").length > 1){ |
---|
36 | alert(get_lang('LOGIN field contains characters not allowed') + '.'); |
---|
37 | document.forms[0].uid.focus(); |
---|
38 | return; |
---|
39 | } |
---|
40 | |
---|
41 | if (document.forms[0].mail.value == ''){ |
---|
42 | alert(get_lang('EMAIL field is empty') + '.'); |
---|
43 | document.forms[0].mail.focus(); |
---|
44 | return; |
---|
45 | } |
---|
46 | var reEmail = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/; |
---|
47 | if(!reEmail.test(document.forms[0].mail.value)){ |
---|
48 | alert(get_lang('Email field is not valid') + '.'); |
---|
49 | return false; |
---|
50 | } |
---|
51 | |
---|
52 | select_userInMaillist = document.getElementById('ea_select_usersInMaillist'); |
---|
53 | if (select_userInMaillist.options.length == 0){ |
---|
54 | alert(get_lang('Any user is in the list') + '.'); |
---|
55 | return; |
---|
56 | } |
---|
57 | |
---|
58 | var handler_validate_fields = function(data) |
---|
59 | { |
---|
60 | if (!data.status) |
---|
61 | alert(data.msg); |
---|
62 | else |
---|
63 | { |
---|
64 | if (type == 'create_maillist') |
---|
65 | cExecuteForm ("$this.maillist.create", document.forms[0], handler_create); |
---|
66 | else if (type == 'edit_maillist') |
---|
67 | cExecuteForm ("$this.maillist.save", document.forms[0], handler_save); |
---|
68 | } |
---|
69 | } |
---|
70 | |
---|
71 | // Needed select all options from select |
---|
72 | for(var i=0; i<select_userInMaillist.options.length; i++) |
---|
73 | { |
---|
74 | // No IE, não seleciona o separador do select |
---|
75 | if (select_userInMaillist.options[i].value != -1) |
---|
76 | select_userInMaillist.options[i].selected = true; |
---|
77 | else |
---|
78 | select_userInMaillist.options[i].selected = false; |
---|
79 | } |
---|
80 | |
---|
81 | // O UID da lista foi alterado ou é uma nova lista. |
---|
82 | if ((document.forms[0].old_uid.value != document.forms[0].uid.value) || (type == 'create_maillist')){ |
---|
83 | cExecute ('$this.maillist.validate_fields&uid='+document.forms[0].uid.value+'&mail='+document.forms[0].mail.value, handler_validate_fields); |
---|
84 | } |
---|
85 | else if (type == 'edit_maillist') |
---|
86 | { |
---|
87 | cExecuteForm ("$this.maillist.save", document.forms[0], handler_save); |
---|
88 | } |
---|
89 | } |
---|
90 | |
---|
91 | // HANDLER CREATE |
---|
92 | // É necessário 2 funcões de retorno por causa do cExecuteForm. |
---|
93 | function handler_create(data) |
---|
94 | { |
---|
95 | return_handler_create(data); |
---|
96 | } |
---|
97 | function return_handler_create(data) |
---|
98 | { |
---|
99 | if (!data.status) |
---|
100 | alert(data.msg); |
---|
101 | else{ |
---|
102 | alert(get_lang('Email list successful created') + '.'); |
---|
103 | location.href="./index.php?menuaction=expressoAdmin1_2.uimaillists.list_maillists"; |
---|
104 | } |
---|
105 | return; |
---|
106 | } |
---|
107 | |
---|
108 | // HANDLER SAVE |
---|
109 | // É necessário 2 funcões de retorno por causa do cExecuteForm. |
---|
110 | function handler_save(data) |
---|
111 | { |
---|
112 | return_handler_save(data); |
---|
113 | } |
---|
114 | function return_handler_save(data) |
---|
115 | { |
---|
116 | if (!data.status) |
---|
117 | alert(data.msg); |
---|
118 | else{ |
---|
119 | alert(get_lang('Email list successful saved') + '.'); |
---|
120 | location.href="./index.php?menuaction=expressoAdmin1_2.uimaillists.list_maillists"; |
---|
121 | } |
---|
122 | return; |
---|
123 | } |
---|
124 | |
---|
125 | function save_scl() |
---|
126 | { |
---|
127 | select_users_SCL_Maillist = document.getElementById('ea_select_users_SCL_Maillist'); |
---|
128 | // Needed select all options from select |
---|
129 | for(var i=0; i<select_users_SCL_Maillist.options.length; i++) |
---|
130 | select_users_SCL_Maillist.options[i].selected = true; |
---|
131 | |
---|
132 | cExecuteForm ("$this.maillist.save_scl", document.forms[0], handler_save_scl); |
---|
133 | } |
---|
134 | function handler_save_scl(data) |
---|
135 | { |
---|
136 | return_handler_save_scl(data); |
---|
137 | } |
---|
138 | |
---|
139 | function return_handler_save_scl(data) |
---|
140 | { |
---|
141 | if (!data.status) |
---|
142 | alert(data.msg); |
---|
143 | else |
---|
144 | alert(get_lang('SCL successful saved') + '.'); |
---|
145 | location.href="./index.php?menuaction=expressoAdmin1_2.uimaillists.list_maillists"; |
---|
146 | return; |
---|
147 | } |
---|
148 | |
---|
149 | function sinc_combos_org(context, recursive) |
---|
150 | { |
---|
151 | combo_org_maillists = document.getElementById('ea_combo_org_maillists'); |
---|
152 | |
---|
153 | for (i=0; i<combo_org_maillists.length; i++) |
---|
154 | { |
---|
155 | if (combo_org_maillists.options[i].value == context) |
---|
156 | { |
---|
157 | combo_org_maillists.options[i].selected = true; |
---|
158 | get_available_users(context, recursive); |
---|
159 | break; |
---|
160 | } |
---|
161 | } |
---|
162 | } |
---|
163 | |
---|
164 | function get_available_users(context, recursive) |
---|
165 | { |
---|
166 | // var sentence = Element('ea_input_searchUser').value; |
---|
167 | // |
---|
168 | // var url = '$this.ldap_functions.get_available_users_and_maillist&context=' |
---|
169 | // + Element('ea_combo_org_maillists').value |
---|
170 | // + '&sentence=' + sentence |
---|
171 | // + '&denied_uidnumber=' + document.forms[0].uidnumber.value; |
---|
172 | // |
---|
173 | // var fillHandler = function( fill ){ |
---|
174 | // |
---|
175 | // Element('ea_select_available_users').innerHTML = fill; |
---|
176 | // |
---|
177 | // return( fill !== "" ); |
---|
178 | // } |
---|
179 | // |
---|
180 | // userFinder( sentence, fillHandler, url, 'ea_span_searching' ); |
---|
181 | |
---|
182 | var url = '$this.ldap_functions.get_available_users_and_maillist&denied_uidnumber=' + document.forms[0].uidnumber.value; |
---|
183 | |
---|
184 | optionFind( 'ea_input_searchUser', 'ea_select_available_users', url, |
---|
185 | 'ea_combo_org_maillists', 'ea_span_searching' ); |
---|
186 | } |
---|
187 | |
---|
188 | function add_user2maillist() |
---|
189 | { |
---|
190 | select_available_users = document.getElementById('ea_select_available_users'); |
---|
191 | select_usersInMaillist = document.getElementById('ea_select_usersInMaillist'); |
---|
192 | |
---|
193 | var count_available_users = select_available_users.length; |
---|
194 | var count_usersInMailList = select_usersInMaillist.options.length; |
---|
195 | var new_options = ''; |
---|
196 | |
---|
197 | for (i = 0 ; i < count_available_users ; i++) |
---|
198 | { |
---|
199 | if (select_available_users.options[i].selected) |
---|
200 | { |
---|
201 | if(document.all) |
---|
202 | { |
---|
203 | if ( (select_usersInMaillist.innerHTML.indexOf('value='+select_available_users.options[i].value)) == '-1' ) |
---|
204 | { |
---|
205 | new_options += "<option value=" |
---|
206 | + select_available_users.options[i].value |
---|
207 | + ">" |
---|
208 | + select_available_users.options[i].text |
---|
209 | + "</options>"; |
---|
210 | } |
---|
211 | } |
---|
212 | else |
---|
213 | { |
---|
214 | if ( (select_usersInMaillist.innerHTML.indexOf('value="'+select_available_users.options[i].value+'"')) == '-1' ) |
---|
215 | { |
---|
216 | new_options += "<option value=" |
---|
217 | + select_available_users.options[i].value |
---|
218 | + ">" |
---|
219 | + select_available_users.options[i].text |
---|
220 | + "</options>"; |
---|
221 | } |
---|
222 | } |
---|
223 | } |
---|
224 | } |
---|
225 | |
---|
226 | if (new_options != '') |
---|
227 | { |
---|
228 | select_usersInMaillist.innerHTML = ' ' + new_options + select_usersInMaillist.innerHTML; |
---|
229 | select_usersInMaillist.outerHTML = select_usersInMaillist.outerHTML; |
---|
230 | document.getElementById('ea_input_searchUser').value = ""; |
---|
231 | } |
---|
232 | } |
---|
233 | |
---|
234 | function remove_user2maillist() |
---|
235 | { |
---|
236 | select_usersInMaillist = document.getElementById('ea_select_usersInMaillist'); |
---|
237 | |
---|
238 | for(var i = 0;i < select_usersInMaillist.options.length; i++) |
---|
239 | if(select_usersInMaillist.options[i].selected) |
---|
240 | select_usersInMaillist.options[i--] = null; |
---|
241 | } |
---|
242 | |
---|
243 | function add_user2scl_maillist() |
---|
244 | { |
---|
245 | select_available_users = document.getElementById('ea_select_available_users'); |
---|
246 | select_usersInMaillist = document.getElementById('ea_select_users_SCL_Maillist'); |
---|
247 | |
---|
248 | var count_available_users = select_available_users.length; |
---|
249 | var count_usersInMailList = select_usersInMaillist.options.length; |
---|
250 | var new_options = ''; |
---|
251 | |
---|
252 | for (i = 0 ; i < count_available_users ; i++) |
---|
253 | { |
---|
254 | if (select_available_users.options[i].selected) |
---|
255 | { |
---|
256 | if(document.all) |
---|
257 | { |
---|
258 | if ( (select_usersInMaillist.innerHTML.indexOf('value='+select_available_users.options[i].value)) == '-1' ) |
---|
259 | { |
---|
260 | new_options += "<option value=" |
---|
261 | + select_available_users.options[i].value |
---|
262 | + ">" |
---|
263 | + select_available_users.options[i].text |
---|
264 | + "</options>"; |
---|
265 | } |
---|
266 | } |
---|
267 | else |
---|
268 | { |
---|
269 | if ( (select_usersInMaillist.innerHTML.indexOf('value="'+select_available_users.options[i].value+'"')) == '-1' ) |
---|
270 | { |
---|
271 | new_options += "<option value=" |
---|
272 | + select_available_users.options[i].value |
---|
273 | + ">" |
---|
274 | + select_available_users.options[i].text |
---|
275 | + "</options>"; |
---|
276 | } |
---|
277 | } |
---|
278 | } |
---|
279 | } |
---|
280 | if (new_options != '') |
---|
281 | { |
---|
282 | usersOptionsHtml = select_usersInMaillist.innerHTML; |
---|
283 | usersOptionsHtml = (($.browser.msie && $.browser.version < 9) ? '#' : ' ') + new_options + usersOptionsHtml; |
---|
284 | $(select_usersInMaillist).html(usersOptionsHtml); |
---|
285 | } |
---|
286 | } |
---|
287 | |
---|
288 | function remove_user2scl_maillist() |
---|
289 | { |
---|
290 | select_usersInMaillist = document.getElementById('ea_select_users_SCL_Maillist'); |
---|
291 | |
---|
292 | for(var i = 0;i < select_usersInMaillist.options.length; i++) |
---|
293 | if(select_usersInMaillist.options[i].selected) |
---|
294 | select_usersInMaillist.options[i--] = null; |
---|
295 | } |
---|
296 | |
---|
297 | |
---|
298 | // Variaveis Locais |
---|
299 | if (document.getElementById('ea_select_available_users')) |
---|
300 | { |
---|
301 | var select_available_users = document.getElementById('ea_select_available_users'); |
---|
302 | var select_available_users_clone = select_available_users.cloneNode(true); |
---|
303 | } |
---|
304 | else |
---|
305 | { |
---|
306 | var select_available_users = ''; |
---|
307 | var select_available_users_clone = ''; |
---|
308 | } |
---|
309 | var finderTimeout = ''; |
---|
310 | |
---|
311 | // Funcoes |
---|
312 | function optionFinderTimeout(obj, event) |
---|
313 | { |
---|
314 | if( event && event.keyCode !== 13 ) |
---|
315 | return; |
---|
316 | |
---|
317 | optionFinder( obj.id ); |
---|
318 | } |
---|
319 | function optionFinder(id) { |
---|
320 | get_available_users(); |
---|
321 | } |
---|
322 | |
---|
323 | function delete_maillist(uid, uidnumber) |
---|
324 | { |
---|
325 | if (confirm(get_lang('Do you really want delete the email list') + ' ' + uid + " ??")) |
---|
326 | |
---|
327 | { |
---|
328 | var handler_delete_maillist = function(data) |
---|
329 | { |
---|
330 | if (!data.status) |
---|
331 | alert(data.msg); |
---|
332 | else |
---|
333 | alert(get_lang('Email list successful deleted') + '.'); |
---|
334 | |
---|
335 | location.href="./index.php?menuaction=expressoAdmin1_2.uimaillists.list_maillists"; |
---|
336 | return; |
---|
337 | } |
---|
338 | cExecute ('$this.maillist.delete&uidnumber='+uidnumber, handler_delete_maillist); |
---|
339 | } |
---|
340 | } |
---|
341 | |
---|
342 | function search_organization(key, element) |
---|
343 | { |
---|
344 | var organizations = document.getElementById(element); |
---|
345 | var RegExp_org = new RegExp("\\b"+key, "i"); |
---|
346 | |
---|
347 | for(i = 0; i < organizations.length; i++) |
---|
348 | { |
---|
349 | if (RegExp_org.test(organizations[i].text)) |
---|
350 | { |
---|
351 | organizations[i].selected = true; |
---|
352 | return; |
---|
353 | } |
---|
354 | } |
---|
355 | } |
---|
356 | |
---|
357 | function emailSuggestion_maillist() |
---|
358 | { |
---|
359 | var defaultDomain = document.forms[0].defaultDomain.value; |
---|
360 | var base_dn = "." + dn2ufn(document.forms[0].ldap_context.value); |
---|
361 | var selected_context = dn2ufn(document.forms[0].context.value.toLowerCase()); |
---|
362 | |
---|
363 | var uid = document.getElementById("ea_maillist_uid"); |
---|
364 | var mail= document.getElementById("ea_maillist_mail"); |
---|
365 | |
---|
366 | var raw_selected_context = selected_context.replace(base_dn, ""); |
---|
367 | |
---|
368 | var array_org_name = raw_selected_context.split('.'); |
---|
369 | var org_name = array_org_name[array_org_name.length-1]; |
---|
370 | |
---|
371 | if (mail.value == "") |
---|
372 | mail.value = uid.value + "@" + org_name + "." + defaultDomain; |
---|
373 | } |
---|
374 | |
---|
375 | function dn2ufn(dn) |
---|
376 | { |
---|
377 | var ufn = ''; |
---|
378 | var array_dn = dn.split(","); |
---|
379 | for (x in array_dn) |
---|
380 | { |
---|
381 | var tmp = array_dn[x].split("="); |
---|
382 | ufn += tmp[1] + '.'; |
---|
383 | } |
---|
384 | return ufn.substring(0,(ufn.length-1)); |
---|
385 | } |
---|
386 | |
---|
387 | function LTrim(value) |
---|
388 | { |
---|
389 | var w_space = String.fromCharCode(32); |
---|
390 | var strTemp = ""; |
---|
391 | var iTemp = 0; |
---|
392 | |
---|
393 | var v_length = value ? value.length : 0; |
---|
394 | if(v_length < 1) |
---|
395 | return ""; |
---|
396 | |
---|
397 | while(iTemp < v_length){ |
---|
398 | if(value && value.charAt(iTemp) != w_space){ |
---|
399 | strTemp = value.substring(iTemp,v_length); |
---|
400 | break; |
---|
401 | } |
---|
402 | iTemp++; |
---|
403 | } |
---|
404 | return strTemp; |
---|
405 | } |
---|
406 | |
---|
407 | function validateEmail() |
---|
408 | { |
---|
409 | |
---|
410 | externalEmail = document.getElementById('ea_input_externalUser'); |
---|
411 | |
---|
412 | if( externalEmail.value ) |
---|
413 | { |
---|
414 | //var element = arguments[0]; |
---|
415 | var validate = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/; |
---|
416 | |
---|
417 | if(this.LTrim(externalEmail.value) != "" && externalEmail.value != "") |
---|
418 | { |
---|
419 | if(!validate.test(externalEmail.value)) |
---|
420 | { |
---|
421 | alert(get_lang('Email address is not valid') + '.'); |
---|
422 | externalEmail.focus(); |
---|
423 | return false; |
---|
424 | }else { |
---|
425 | this.add_externalUser2maillist(externalEmail.value); |
---|
426 | } |
---|
427 | } |
---|
428 | |
---|
429 | } |
---|
430 | } |
---|
431 | |
---|
432 | function add_externalUser2maillist(mailAddress) |
---|
433 | { |
---|
434 | input_externalUsers = mailAddress.toLowerCase(); //document.getElementById('ea_input_externalUser').value; |
---|
435 | select_usersInMaillist = document.getElementById('ea_select_usersInMaillist'); |
---|
436 | |
---|
437 | var count_externalUsers = input_externalUsers.length; |
---|
438 | var count_usersInMaillist = select_usersInMaillist.options.length; |
---|
439 | var new_options = ''; |
---|
440 | |
---|
441 | var teste = ''; //Variavel que ira receber mensagem de alerta ao usuario; |
---|
442 | var alerta = new Boolean(0); //Variavel que sera usada para verificar se o alerta ao usuario sera exibido ou nao; |
---|
443 | |
---|
444 | //Laco abaixo compara se o valor escolhido em select_available_users ja existe em select_usersInMaillist |
---|
445 | //se existir, adiciona o valor em teste e muda a variavel alerta para true; teste sera exibido em tela |
---|
446 | //apenas de alerta true; ver if no fim da funcao; |
---|
447 | for(j = 0; j < count_usersInMaillist; j++) |
---|
448 | { |
---|
449 | var tmp = select_usersInMaillist.options[j].text |
---|
450 | |
---|
451 | if(tmp.match(input_externalUsers)) |
---|
452 | { |
---|
453 | teste = get_lang("User already belongs to the list") + "\n" + input_externalUsers + "\n"; |
---|
454 | alerta = new Boolean(1); |
---|
455 | } |
---|
456 | } |
---|
457 | |
---|
458 | if(alerta != true) |
---|
459 | { |
---|
460 | if(document.all) |
---|
461 | { |
---|
462 | if ( (select_usersInMaillist.innerHTML.indexOf('value='+input_externalUsers)) == '-1' ) |
---|
463 | { |
---|
464 | new_options += "<option value=" |
---|
465 | + input_externalUsers |
---|
466 | + ">" |
---|
467 | + input_externalUsers |
---|
468 | + "</option>"; |
---|
469 | } |
---|
470 | } |
---|
471 | else |
---|
472 | { |
---|
473 | if ( (select_usersInMaillist.innerHTML.indexOf('value="'+input_externalUsers+'"')) == '-1' ) |
---|
474 | { |
---|
475 | new_options += "<option value=" |
---|
476 | + input_externalUsers |
---|
477 | + ">" |
---|
478 | + input_externalUsers |
---|
479 | + "</option>"; |
---|
480 | } |
---|
481 | } |
---|
482 | } |
---|
483 | |
---|
484 | if(alerta == true) |
---|
485 | { |
---|
486 | alert(teste); |
---|
487 | } |
---|
488 | |
---|
489 | |
---|
490 | if (new_options != '') |
---|
491 | { |
---|
492 | select_usersInMaillist.innerHTML = '#' + new_options + select_usersInMaillist.innerHTML; |
---|
493 | select_usersInMaillist.outerHTML = select_usersInMaillist.outerHTML; |
---|
494 | } |
---|
495 | |
---|
496 | document.getElementById('ea_input_externalUser').value = ''; |
---|
497 | } |
---|