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