1 | // Variaveis Globais |
---|
2 | countFiles = 0; |
---|
3 | function validate_fields(type, restrictionsOnGroup) |
---|
4 | { |
---|
5 | document.forms[0].cn.value = document.forms[0].cn.value.toLowerCase(); |
---|
6 | document.forms[0].old_cn.value = document.forms[0].old_cn.value.toLowerCase(); |
---|
7 | |
---|
8 | if (document.forms[0].cn.value == ''){ |
---|
9 | alert(document.getElementById('group_name_field_is_empty').value); |
---|
10 | return; |
---|
11 | } |
---|
12 | |
---|
13 | if (document.forms[0].description.value == ''){ |
---|
14 | alert(document.getElementById('description_field_is_empty').value); |
---|
15 | return; |
---|
16 | } |
---|
17 | |
---|
18 | if (restrictionsOnGroup == 'true') |
---|
19 | { |
---|
20 | cn_tmp = document.forms[0].cn.value.split("-"); |
---|
21 | if ( (cn_tmp.length < 3) || ((cn_tmp[0] != 'grupo') && (cn_tmp[0] != 'smb')) ){ |
---|
22 | alert(document.getElementById('field_name_is_incomplete').value); |
---|
23 | return; |
---|
24 | } |
---|
25 | } |
---|
26 | |
---|
27 | var reCn = /^([a-zA-Z0-9_\-])+$/; |
---|
28 | var reDesc = /^([a-zA-Z0-9_\- .])+$/; |
---|
29 | |
---|
30 | if(!reCn.test(document.forms[0].cn.value)){ |
---|
31 | alert(document.getElementById('group_name_not_allowed').value); |
---|
32 | document.forms[0].cn.focus(); |
---|
33 | return; |
---|
34 | } |
---|
35 | |
---|
36 | if(!reDesc.test(document.forms[0].description.value)){ |
---|
37 | alert(document.getElementGroupById('description_field_not_allowed').value); |
---|
38 | document.forms[0].description.focus(); |
---|
39 | return; |
---|
40 | } |
---|
41 | |
---|
42 | var reEmail = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/; |
---|
43 | if ( (document.forms[0].email.value == '') || (!reEmail.test(document.forms[0].email.value)) ) |
---|
44 | { |
---|
45 | alert(document.getElementById('field_email_is_invalid').value); |
---|
46 | return false; |
---|
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_group') |
---|
56 | cExecuteForm ("$this.group.create", document.forms[0], handler_create); |
---|
57 | else if (type == 'edit_group') |
---|
58 | cExecuteForm ("$this.group.save", document.forms[0], handler_save); |
---|
59 | } |
---|
60 | } |
---|
61 | |
---|
62 | // Needed select all options from select |
---|
63 | select_userInGroup = document.getElementById('ea_select_usersInGroup'); |
---|
64 | for(var i=0; i<select_userInGroup.options.length; i++) |
---|
65 | select_userInGroup.options[i].selected = true; |
---|
66 | |
---|
67 | // O CN do grupo foi alterado ou é um novo grupo. |
---|
68 | if ((document.forms[0].old_cn.value != document.forms[0].cn.value) || (type == 'create_group')){ |
---|
69 | cExecute ('$this.group.validate_fields&cn='+document.forms[0].cn.value, handler_validate_fields); |
---|
70 | } |
---|
71 | else if (type == 'edit_group') |
---|
72 | { |
---|
73 | cExecuteForm ("$this.group.save", document.forms[0], handler_save); |
---|
74 | } |
---|
75 | } |
---|
76 | |
---|
77 | // HANDLER CREATE |
---|
78 | // É necessário 2 funcões de retorno por causa do cExecuteForm. |
---|
79 | function handler_create(data) |
---|
80 | { |
---|
81 | return_handler_create(data); |
---|
82 | } |
---|
83 | function return_handler_create(data) |
---|
84 | { |
---|
85 | if (!data.status) |
---|
86 | alert(data.msg); |
---|
87 | else{ |
---|
88 | alert(document.getElementById('group_successfully_created').value); |
---|
89 | location.href="./index.php?menuaction=expressoAdmin1_2.uigroups.list_groups"; |
---|
90 | } |
---|
91 | return; |
---|
92 | } |
---|
93 | |
---|
94 | // HANDLER SAVE |
---|
95 | // É necessário 2 funcões de retorno por causa do cExecuteForm. |
---|
96 | function handler_save(data) |
---|
97 | { |
---|
98 | return_handler_save(data); |
---|
99 | } |
---|
100 | function return_handler_save(data) |
---|
101 | { |
---|
102 | if (!data.status) |
---|
103 | alert(data.msg); |
---|
104 | else{ |
---|
105 | alert(document.getElementById('group_successfully_saved').value); |
---|
106 | location.href="./index.php?menuaction=expressoAdmin1_2.uigroups.list_groups"; |
---|
107 | } |
---|
108 | return; |
---|
109 | } |
---|
110 | |
---|
111 | function sinc_combos_org(context, recursive) |
---|
112 | { |
---|
113 | combo_org_groups = document.getElementById('ea_combo_org_groups'); |
---|
114 | |
---|
115 | for (i=0; i<combo_org_groups.length; i++) |
---|
116 | { |
---|
117 | if (combo_org_groups.options[i].value == context) |
---|
118 | { |
---|
119 | combo_org_groups.options[i].selected = true; |
---|
120 | get_available_users(context, recursive); |
---|
121 | break; |
---|
122 | } |
---|
123 | } |
---|
124 | } |
---|
125 | |
---|
126 | function get_available_users(context, recursive) |
---|
127 | { |
---|
128 | var handler_get_available_users = function(data) |
---|
129 | { |
---|
130 | select_available_users = document.getElementById('ea_select_available_users'); |
---|
131 | |
---|
132 | //Limpa o select |
---|
133 | for(var i=0; i<select_available_users.options.length; i++) |
---|
134 | { |
---|
135 | select_available_users.options[i] = null; |
---|
136 | i--; |
---|
137 | } |
---|
138 | |
---|
139 | if ((data) && (data.length > 0)) |
---|
140 | { |
---|
141 | // Necessario, pois o IE6 tem um bug que retira o primeiro options se o innerHTML estiver vazio. |
---|
142 | select_available_users.innerHTML = ' ' + data; |
---|
143 | select_available_users.outerHTML = select_available_users.outerHTML; |
---|
144 | |
---|
145 | select_available_users.disabled = false; |
---|
146 | select_available_users_clone = document.getElementById('ea_select_available_users').cloneNode(true); |
---|
147 | document.getElementById('ea_input_searchUser').value = ''; |
---|
148 | } |
---|
149 | } |
---|
150 | |
---|
151 | //Impede chamada recursiva na raiz das organizações |
---|
152 | if ((recursive) && (document.forms[0].ldap_context.value == document.getElementById('ea_combo_org_groups').value)) |
---|
153 | { |
---|
154 | alert(document.getElementById('not_possible_select_all_users').value) |
---|
155 | document.getElementById('ea_check_allUsers').checked = false; |
---|
156 | |
---|
157 | // Limpa select |
---|
158 | select_available_users = document.getElementById('ea_select_available_users'); |
---|
159 | select_available_users.innerHTML = ' '; |
---|
160 | select_available_users.outerHTML = select_available_users.outerHTML; |
---|
161 | return; |
---|
162 | } |
---|
163 | cExecute ('$this.ldap_functions.get_available_users&context='+context+'&recursive='+recursive, handler_get_available_users); |
---|
164 | } |
---|
165 | |
---|
166 | function add_user2group() |
---|
167 | { |
---|
168 | var select_available_users = document.getElementById('ea_select_available_users'); |
---|
169 | var select_usersInGroup = document.getElementById('ea_select_usersInGroup'); |
---|
170 | |
---|
171 | var count_available_users = select_available_users.length; |
---|
172 | var count_usersInGroup = select_usersInGroup.options.length; |
---|
173 | var new_options = ''; |
---|
174 | |
---|
175 | for (i = 0 ; i < count_available_users ; i++) |
---|
176 | { |
---|
177 | if (select_available_users.options[i].selected) |
---|
178 | { |
---|
179 | if(document.all) |
---|
180 | { |
---|
181 | if ( (select_usersInGroup.innerHTML.indexOf('value='+select_available_users.options[i].value)) == '-1' ) |
---|
182 | { |
---|
183 | new_options += '<option value=' |
---|
184 | + select_available_users.options[i].value |
---|
185 | + '>' |
---|
186 | + select_available_users.options[i].text |
---|
187 | + '</option>'; |
---|
188 | } |
---|
189 | } |
---|
190 | else |
---|
191 | { |
---|
192 | if ( (select_usersInGroup.innerHTML.indexOf('value="'+select_available_users.options[i].value+'"')) == '-1' ) |
---|
193 | { |
---|
194 | new_options += '<option value=' |
---|
195 | + select_available_users.options[i].value |
---|
196 | + '>' |
---|
197 | + select_available_users.options[i].text |
---|
198 | + '</option>'; |
---|
199 | } |
---|
200 | } |
---|
201 | } |
---|
202 | } |
---|
203 | |
---|
204 | if (new_options != '') |
---|
205 | { |
---|
206 | select_usersInGroup.innerHTML = ' ' + new_options + select_usersInGroup.innerHTML; |
---|
207 | select_usersInGroup.outerHTML = select_usersInGroup.outerHTML; |
---|
208 | document.getElementById('ea_input_searchUser').value = ""; |
---|
209 | } |
---|
210 | } |
---|
211 | |
---|
212 | function remove_user2group() |
---|
213 | { |
---|
214 | select_usersInGroup = document.getElementById('ea_select_usersInGroup'); |
---|
215 | |
---|
216 | for(var i = 0;i < select_usersInGroup.options.length; i++) |
---|
217 | if(select_usersInGroup.options[i].selected) |
---|
218 | select_usersInGroup.options[i--] = null; |
---|
219 | } |
---|
220 | |
---|
221 | // Variaveis Locais |
---|
222 | if (document.getElementById('ea_select_available_users')) |
---|
223 | { |
---|
224 | var select_available_users = document.getElementById('ea_select_available_users'); |
---|
225 | var select_available_users_clone = select_available_users.cloneNode(true); |
---|
226 | } |
---|
227 | else |
---|
228 | { |
---|
229 | var select_available_users = ''; |
---|
230 | var select_available_users_clone = ''; |
---|
231 | } |
---|
232 | var finderTimeout = ''; |
---|
233 | |
---|
234 | // Funcoes |
---|
235 | function optionFinderTimeout(obj) |
---|
236 | { |
---|
237 | clearTimeout(finderTimeout); |
---|
238 | var oWait = document.getElementById("ea_span_searching"); |
---|
239 | oWait.innerHTML = 'Buscando...'; |
---|
240 | var finderTimeout = setTimeout("optionFinder('"+obj.id+"')",500); |
---|
241 | } |
---|
242 | function optionFinder(id) { |
---|
243 | var oWait = document.getElementById("ea_span_searching"); |
---|
244 | var oText = document.getElementById(id); |
---|
245 | |
---|
246 | //Limpa todo o select |
---|
247 | var select_available_users_tmp = document.getElementById('ea_select_available_users') |
---|
248 | for(var i = 0;i < select_available_users_tmp.options.length; i++) |
---|
249 | select_available_users_tmp.options[i--] = null; |
---|
250 | |
---|
251 | var RegExp_name = new RegExp("\\b"+oText.value, "i"); |
---|
252 | |
---|
253 | //Inclui usuário começando com a pesquisa |
---|
254 | for(i = 0; i < select_available_users_clone.length; i++){ |
---|
255 | if (RegExp_name.test(select_available_users_clone[i].text)) |
---|
256 | { |
---|
257 | sel = select_available_users_tmp.options; |
---|
258 | option = new Option(select_available_users_clone[i].text,select_available_users_clone[i].value); |
---|
259 | sel[sel.length] = option; |
---|
260 | } |
---|
261 | } |
---|
262 | |
---|
263 | oWait.innerHTML = ' '; |
---|
264 | } |
---|
265 | |
---|
266 | function delete_group(cn, gidnumber) |
---|
267 | { |
---|
268 | if (confirm(document.getElementById('delete_group').value + " (" + cn + ")")) |
---|
269 | { |
---|
270 | var handler_delete_group = function(data) |
---|
271 | { |
---|
272 | if (!data.status) |
---|
273 | alert(data.msg); |
---|
274 | else |
---|
275 | alert(document.getElementById('group_successfully_deleted').value); |
---|
276 | |
---|
277 | location.href="./index.php?menuaction=expressoAdmin1_2.uigroups.list_groups"; |
---|
278 | return; |
---|
279 | } |
---|
280 | cExecute ('$this.group.delete&gidnumber='+gidnumber+'&cn='+cn, handler_delete_group); |
---|
281 | } |
---|
282 | } |
---|
283 | |
---|
284 | function use_samba_attrs(value) |
---|
285 | { |
---|
286 | document.forms[0].sambasid.disabled = !value; |
---|
287 | } |
---|
288 | |
---|
289 | function get_available_sambadomains(context, type) |
---|
290 | { |
---|
291 | if ((type == 'create_group') && (document.getElementById('ea_div_display_samba_options').style.display != 'none')) |
---|
292 | { |
---|
293 | var handler_get_available_sambadomains = function(data) |
---|
294 | { |
---|
295 | document.forms[0].use_attrs_samba.checked = data.status; |
---|
296 | use_samba_attrs(data.status); |
---|
297 | |
---|
298 | if (data.status) |
---|
299 | { |
---|
300 | combo_sambadomains = document.getElementById('ea_combo_sambadomains'); |
---|
301 | for (i=0; i<data.sambaDomains.length; i++) |
---|
302 | { |
---|
303 | for (j=0; j<combo_sambadomains.length; j++) |
---|
304 | { |
---|
305 | if (combo_sambadomains.options[j].text == data.sambaDomains[i]) |
---|
306 | { |
---|
307 | combo_sambadomains.options[j].selected = true; |
---|
308 | break; |
---|
309 | } |
---|
310 | } |
---|
311 | } |
---|
312 | |
---|
313 | } |
---|
314 | } |
---|
315 | cExecute ('$this.ldap_functions.exist_sambadomains_in_context&context='+context, handler_get_available_sambadomains); |
---|
316 | } |
---|
317 | } |
---|
318 | |
---|
319 | function groupEmailSuggestion(concatenateDomain, type) |
---|
320 | { |
---|
321 | if (document.forms[0].email.disabled) |
---|
322 | return; |
---|
323 | |
---|
324 | if (type != 'create_group') |
---|
325 | return; |
---|
326 | |
---|
327 | if (concatenateDomain == 'true') |
---|
328 | { |
---|
329 | var ldap_context = document.forms[0].ufn_ldap_context.value.toLowerCase(); |
---|
330 | var organization_context = document.forms[0].context.value.toLowerCase(); |
---|
331 | var select_orgs = document.getElementById('ea_combo_org_info'); |
---|
332 | |
---|
333 | for(var i=0; i<select_orgs.options.length; i++) |
---|
334 | { |
---|
335 | if(select_orgs.options[i].selected == true) |
---|
336 | { |
---|
337 | var x; |
---|
338 | var context = ''; |
---|
339 | select_context = select_orgs.options[i].value.toLowerCase(); |
---|
340 | organization_name = organization_context.split(","); |
---|
341 | |
---|
342 | for (x in organization_name) |
---|
343 | { |
---|
344 | tmp = organization_name[x].split("="); |
---|
345 | context += tmp[1] + '.'; |
---|
346 | } |
---|
347 | } |
---|
348 | } |
---|
349 | domain_name = document.forms[0].defaultDomain.value; |
---|
350 | |
---|
351 | x=context.indexOf(ldap_context,0); |
---|
352 | org_name_par = context.substring(0,(x-1)); |
---|
353 | org_name = org_name_par.split('.'); |
---|
354 | org_name = org_name[org_name.length-1]; |
---|
355 | |
---|
356 | if (org_name != '') |
---|
357 | document.forms[0].email.value = document.forms[0].cn.value + '@' + org_name + '.aaa' + domain_name; |
---|
358 | else |
---|
359 | document.forms[0].email.value = document.forms[0].cn.value; |
---|
360 | } |
---|
361 | else |
---|
362 | { |
---|
363 | document.forms[0].email.value = document.forms[0].cn.value; |
---|
364 | } |
---|
365 | } |
---|
366 | |
---|
367 | function search_organization(key) |
---|
368 | { |
---|
369 | var organizations = document.getElementById('ea_combo_org_info'); |
---|
370 | var RegExp_org = new RegExp("\\b"+key, "i"); |
---|
371 | |
---|
372 | for(i = 0; i < organizations.length; i++) |
---|
373 | { |
---|
374 | if (RegExp_org.test(organizations[i].text)) |
---|
375 | { |
---|
376 | organizations[i].selected = true; |
---|
377 | return; |
---|
378 | } |
---|
379 | } |
---|
380 | } |
---|