[2] | 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 == ''){ |
---|
[2712] | 9 | alert( ExpressoLivre.translate( 'NAME field is empty' ) + '.'); |
---|
[2] | 10 | return; |
---|
| 11 | } |
---|
| 12 | |
---|
| 13 | if (document.forms[0].description.value == ''){ |
---|
[2712] | 14 | alert( ExpressoLivre.translate( 'DESCRIPTION field is empty' ) + '.'); |
---|
[2] | 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')) ){ |
---|
[309] | 22 | alert( |
---|
[2712] | 23 | ExpressoLivre.translate( 'NAME field is incomplete' ) + '.\n' + |
---|
| 24 | ExpressoLivre.translate( 'the name field must be formed like' ) + ':\n' + |
---|
| 25 | ExpressoLivre.translate( 'group' ) + '-' + ExpressoLivre.translate( 'organization' ) + '-' + ExpressoLivre.translate( 'group name' ) + '.\n' + |
---|
| 26 | ExpressoLivre.translate( 'eg' ) + ': ' + 'grupo-celepar-rh.'); |
---|
[2] | 27 | return; |
---|
| 28 | } |
---|
| 29 | } |
---|
| 30 | |
---|
| 31 | var reCn = /^([a-zA-Z0-9_\-])+$/; |
---|
| 32 | var reDesc = /^([a-zA-Z0-9_\- .])+$/; |
---|
| 33 | |
---|
| 34 | if(!reCn.test(document.forms[0].cn.value)){ |
---|
[2712] | 35 | alert( ExpressoLivre.translate( 'NAME field contains characters not allowed' ) + '.'); |
---|
[2] | 36 | document.forms[0].cn.focus(); |
---|
| 37 | return; |
---|
| 38 | } |
---|
| 39 | |
---|
| 40 | if(!reDesc.test(document.forms[0].description.value)){ |
---|
[2712] | 41 | alert( ExpressoLivre.translate( 'DESCRIPTION field contains characters not allowed' ) + '.'); |
---|
[2] | 42 | document.forms[0].description.focus(); |
---|
| 43 | return; |
---|
| 44 | } |
---|
| 45 | |
---|
[46] | 46 | var reEmail = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/; |
---|
[309] | 47 | if ( (document.forms[0].email.value != '') && (!reEmail.test(document.forms[0].email.value)) ) |
---|
[46] | 48 | { |
---|
[2712] | 49 | alert( ExpressoLivre.translate( 'EMAIL field is empty' ) + '.'); |
---|
[46] | 50 | return false; |
---|
| 51 | } |
---|
| 52 | |
---|
[2] | 53 | var handler_validate_fields = function(data) |
---|
| 54 | { |
---|
[2712] | 55 | data = expresso.connector.unserialize( data.trim( ) ); |
---|
[2] | 56 | if (!data.status) |
---|
| 57 | alert(data.msg); |
---|
| 58 | else |
---|
| 59 | { |
---|
| 60 | if (type == 'create_group') |
---|
| 61 | cExecuteForm ("$this.group.create", document.forms[0], handler_create); |
---|
| 62 | else if (type == 'edit_group') |
---|
| 63 | cExecuteForm ("$this.group.save", document.forms[0], handler_save); |
---|
| 64 | } |
---|
| 65 | } |
---|
| 66 | |
---|
| 67 | // Needed select all options from select |
---|
| 68 | select_userInGroup = document.getElementById('ea_select_usersInGroup'); |
---|
| 69 | for(var i=0; i<select_userInGroup.options.length; i++) |
---|
| 70 | select_userInGroup.options[i].selected = true; |
---|
| 71 | |
---|
| 72 | // O CN do grupo foi alterado ou é um novo grupo. |
---|
| 73 | if ((document.forms[0].old_cn.value != document.forms[0].cn.value) || (type == 'create_group')){ |
---|
[2712] | 74 | ExpressoLivre.go( { |
---|
| 75 | "access" : 'expressoAdmin1_2.group.validate_fields&cn='+document.forms[0].cn.value, |
---|
| 76 | "handler" : handler_validate_fields |
---|
| 77 | } ); |
---|
[2] | 78 | } |
---|
| 79 | else if (type == 'edit_group') |
---|
| 80 | { |
---|
| 81 | cExecuteForm ("$this.group.save", document.forms[0], handler_save); |
---|
| 82 | } |
---|
| 83 | } |
---|
| 84 | |
---|
| 85 | // HANDLER CREATE |
---|
| 86 | // É necessário 2 funcões de retorno por causa do cExecuteForm. |
---|
| 87 | function handler_create(data) |
---|
| 88 | { |
---|
| 89 | return_handler_create(data); |
---|
| 90 | } |
---|
| 91 | function return_handler_create(data) |
---|
| 92 | { |
---|
| 93 | if (!data.status) |
---|
| 94 | alert(data.msg); |
---|
| 95 | else{ |
---|
[2712] | 96 | alert( ExpressoLivre.translate( 'Group successful created' ) + '.'); |
---|
[2] | 97 | location.href="./index.php?menuaction=expressoAdmin1_2.uigroups.list_groups"; |
---|
| 98 | } |
---|
| 99 | return; |
---|
| 100 | } |
---|
| 101 | |
---|
| 102 | // HANDLER SAVE |
---|
| 103 | // É necessário 2 funcões de retorno por causa do cExecuteForm. |
---|
| 104 | function handler_save(data) |
---|
| 105 | { |
---|
| 106 | return_handler_save(data); |
---|
| 107 | } |
---|
| 108 | function return_handler_save(data) |
---|
| 109 | { |
---|
| 110 | if (!data.status) |
---|
| 111 | alert(data.msg); |
---|
| 112 | else{ |
---|
[2712] | 113 | alert( ExpressoLivre.translate( 'Group successful saved' ) + '.'); |
---|
[2] | 114 | location.href="./index.php?menuaction=expressoAdmin1_2.uigroups.list_groups"; |
---|
| 115 | } |
---|
| 116 | return; |
---|
| 117 | } |
---|
| 118 | |
---|
| 119 | function sinc_combos_org(context, recursive) |
---|
| 120 | { |
---|
| 121 | combo_org_groups = document.getElementById('ea_combo_org_groups'); |
---|
| 122 | |
---|
| 123 | for (i=0; i<combo_org_groups.length; i++) |
---|
| 124 | { |
---|
| 125 | if (combo_org_groups.options[i].value == context) |
---|
| 126 | { |
---|
| 127 | combo_org_groups.options[i].selected = true; |
---|
| 128 | get_available_users(context, recursive); |
---|
| 129 | break; |
---|
| 130 | } |
---|
| 131 | } |
---|
| 132 | } |
---|
| 133 | |
---|
| 134 | function get_available_users(context, recursive) |
---|
| 135 | { |
---|
| 136 | var handler_get_available_users = function(data) |
---|
| 137 | { |
---|
| 138 | select_available_users = document.getElementById('ea_select_available_users'); |
---|
| 139 | |
---|
| 140 | //Limpa o select |
---|
| 141 | for(var i=0; i<select_available_users.options.length; i++) |
---|
| 142 | { |
---|
| 143 | select_available_users.options[i] = null; |
---|
| 144 | i--; |
---|
| 145 | } |
---|
| 146 | |
---|
| 147 | if ((data) && (data.length > 0)) |
---|
| 148 | { |
---|
| 149 | // Necessario, pois o IE6 tem um bug que retira o primeiro options se o innerHTML estiver vazio. |
---|
[86] | 150 | select_available_users.innerHTML = ' ' + data; |
---|
[2] | 151 | select_available_users.outerHTML = select_available_users.outerHTML; |
---|
| 152 | |
---|
| 153 | select_available_users.disabled = false; |
---|
| 154 | select_available_users_clone = document.getElementById('ea_select_available_users').cloneNode(true); |
---|
| 155 | document.getElementById('ea_input_searchUser').value = ''; |
---|
| 156 | } |
---|
| 157 | } |
---|
| 158 | |
---|
| 159 | //Impede chamada recursiva na raiz das organizações |
---|
| 160 | if ((recursive) && (document.forms[0].ldap_context.value == document.getElementById('ea_combo_org_groups').value)) |
---|
| 161 | { |
---|
[2712] | 162 | alert( ExpressoLivre.translate( 'It is not allow select all users from the root organization' ) + '.'); |
---|
[2] | 163 | document.getElementById('ea_check_allUsers').checked = false; |
---|
| 164 | |
---|
| 165 | // Limpa select |
---|
| 166 | select_available_users = document.getElementById('ea_select_available_users'); |
---|
[86] | 167 | select_available_users.innerHTML = ' '; |
---|
[2] | 168 | select_available_users.outerHTML = select_available_users.outerHTML; |
---|
| 169 | return; |
---|
| 170 | } |
---|
[2712] | 171 | ExpressoLivre.go( { |
---|
| 172 | "access" : 'expressoAdmin1_2.ldap_functions.get_available_users&context='+escape(context)+'&recursive='+recursive, |
---|
| 173 | "handler" : handler_get_available_users |
---|
| 174 | } ); |
---|
[2] | 175 | } |
---|
| 176 | |
---|
| 177 | function add_user2group() |
---|
| 178 | { |
---|
| 179 | var select_available_users = document.getElementById('ea_select_available_users'); |
---|
| 180 | var select_usersInGroup = document.getElementById('ea_select_usersInGroup'); |
---|
| 181 | |
---|
| 182 | var count_available_users = select_available_users.length; |
---|
| 183 | var count_usersInGroup = select_usersInGroup.options.length; |
---|
| 184 | var new_options = ''; |
---|
| 185 | |
---|
| 186 | for (i = 0 ; i < count_available_users ; i++) |
---|
| 187 | { |
---|
| 188 | if (select_available_users.options[i].selected) |
---|
| 189 | { |
---|
| 190 | if(document.all) |
---|
| 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 | else |
---|
| 202 | { |
---|
| 203 | if ( (select_usersInGroup.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 | + '</option>'; |
---|
| 210 | } |
---|
| 211 | } |
---|
| 212 | } |
---|
| 213 | } |
---|
| 214 | |
---|
| 215 | if (new_options != '') |
---|
| 216 | { |
---|
[86] | 217 | select_usersInGroup.innerHTML = ' ' + new_options + select_usersInGroup.innerHTML; |
---|
[2] | 218 | select_usersInGroup.outerHTML = select_usersInGroup.outerHTML; |
---|
[81] | 219 | document.getElementById('ea_input_searchUser').value = ""; |
---|
[2] | 220 | } |
---|
| 221 | } |
---|
| 222 | |
---|
| 223 | function remove_user2group() |
---|
| 224 | { |
---|
| 225 | select_usersInGroup = document.getElementById('ea_select_usersInGroup'); |
---|
| 226 | |
---|
| 227 | for(var i = 0;i < select_usersInGroup.options.length; i++) |
---|
| 228 | if(select_usersInGroup.options[i].selected) |
---|
| 229 | select_usersInGroup.options[i--] = null; |
---|
| 230 | } |
---|
| 231 | |
---|
| 232 | // Variaveis Locais |
---|
| 233 | if (document.getElementById('ea_select_available_users')) |
---|
| 234 | { |
---|
| 235 | var select_available_users = document.getElementById('ea_select_available_users'); |
---|
| 236 | var select_available_users_clone = select_available_users.cloneNode(true); |
---|
| 237 | } |
---|
| 238 | else |
---|
| 239 | { |
---|
| 240 | var select_available_users = ''; |
---|
| 241 | var select_available_users_clone = ''; |
---|
| 242 | } |
---|
| 243 | var finderTimeout = ''; |
---|
| 244 | |
---|
| 245 | // Funcoes |
---|
| 246 | function optionFinderTimeout(obj) |
---|
| 247 | { |
---|
| 248 | clearTimeout(finderTimeout); |
---|
| 249 | var oWait = document.getElementById("ea_span_searching"); |
---|
[2712] | 250 | oWait.innerHTML = ExpressoLivre.translate( 'Searching' ) + '...'; |
---|
[2] | 251 | var finderTimeout = setTimeout("optionFinder('"+obj.id+"')",500); |
---|
| 252 | } |
---|
| 253 | function optionFinder(id) { |
---|
| 254 | var oWait = document.getElementById("ea_span_searching"); |
---|
| 255 | var oText = document.getElementById(id); |
---|
| 256 | |
---|
| 257 | //Limpa todo o select |
---|
| 258 | var select_available_users_tmp = document.getElementById('ea_select_available_users') |
---|
| 259 | for(var i = 0;i < select_available_users_tmp.options.length; i++) |
---|
| 260 | select_available_users_tmp.options[i--] = null; |
---|
| 261 | |
---|
| 262 | var RegExp_name = new RegExp("\\b"+oText.value, "i"); |
---|
| 263 | |
---|
| 264 | //Inclui usuário começando com a pesquisa |
---|
| 265 | for(i = 0; i < select_available_users_clone.length; i++){ |
---|
| 266 | if (RegExp_name.test(select_available_users_clone[i].text)) |
---|
| 267 | { |
---|
| 268 | sel = select_available_users_tmp.options; |
---|
| 269 | option = new Option(select_available_users_clone[i].text,select_available_users_clone[i].value); |
---|
| 270 | sel[sel.length] = option; |
---|
| 271 | } |
---|
| 272 | } |
---|
| 273 | |
---|
| 274 | oWait.innerHTML = ' '; |
---|
| 275 | } |
---|
| 276 | |
---|
| 277 | function delete_group(cn, gidnumber) |
---|
| 278 | { |
---|
[2712] | 279 | if (confirm( ExpressoLivre.translate( 'Do you really want delete the group' ) + ' ' + cn + " ??")) |
---|
[2] | 280 | { |
---|
| 281 | var handler_delete_group = function(data) |
---|
| 282 | { |
---|
| 283 | if (!data.status) |
---|
| 284 | alert(data.msg); |
---|
| 285 | else |
---|
[2712] | 286 | alert( ExpressoLivre.translate( 'Group success deleted' ) + '.'); |
---|
[2] | 287 | |
---|
| 288 | location.href="./index.php?menuaction=expressoAdmin1_2.uigroups.list_groups"; |
---|
| 289 | return; |
---|
| 290 | } |
---|
| 291 | cExecute ('$this.group.delete&gidnumber='+gidnumber+'&cn='+cn, handler_delete_group); |
---|
| 292 | } |
---|
| 293 | } |
---|
[33] | 294 | |
---|
| 295 | function use_samba_attrs(value) |
---|
| 296 | { |
---|
[46] | 297 | document.forms[0].sambasid.disabled = !value; |
---|
[33] | 298 | } |
---|
| 299 | |
---|
| 300 | function get_available_sambadomains(context, type) |
---|
| 301 | { |
---|
| 302 | if ((type == 'create_group') && (document.getElementById('ea_div_display_samba_options').style.display != 'none')) |
---|
| 303 | { |
---|
| 304 | var handler_get_available_sambadomains = function(data) |
---|
| 305 | { |
---|
| 306 | document.forms[0].use_attrs_samba.checked = data.status; |
---|
| 307 | use_samba_attrs(data.status); |
---|
| 308 | |
---|
| 309 | if (data.status) |
---|
| 310 | { |
---|
| 311 | combo_sambadomains = document.getElementById('ea_combo_sambadomains'); |
---|
| 312 | for (i=0; i<data.sambaDomains.length; i++) |
---|
| 313 | { |
---|
| 314 | for (j=0; j<combo_sambadomains.length; j++) |
---|
| 315 | { |
---|
| 316 | if (combo_sambadomains.options[j].text == data.sambaDomains[i]) |
---|
| 317 | { |
---|
| 318 | combo_sambadomains.options[j].selected = true; |
---|
| 319 | break; |
---|
| 320 | } |
---|
| 321 | } |
---|
| 322 | } |
---|
| 323 | |
---|
| 324 | } |
---|
| 325 | } |
---|
| 326 | cExecute ('$this.ldap_functions.exist_sambadomains_in_context&context='+context, handler_get_available_sambadomains); |
---|
| 327 | } |
---|
[46] | 328 | } |
---|
| 329 | |
---|
| 330 | function groupEmailSuggestion(concatenateDomain, type) |
---|
| 331 | { |
---|
[47] | 332 | if (document.forms[0].email.disabled) |
---|
| 333 | return; |
---|
| 334 | |
---|
[46] | 335 | if (type != 'create_group') |
---|
| 336 | return; |
---|
| 337 | |
---|
| 338 | if (concatenateDomain == 'true') |
---|
| 339 | { |
---|
| 340 | var ldap_context = document.forms[0].ufn_ldap_context.value.toLowerCase(); |
---|
| 341 | var organization_context = document.forms[0].context.value.toLowerCase(); |
---|
| 342 | var select_orgs = document.getElementById('ea_combo_org_info'); |
---|
| 343 | |
---|
| 344 | for(var i=0; i<select_orgs.options.length; i++) |
---|
| 345 | { |
---|
| 346 | if(select_orgs.options[i].selected == true) |
---|
| 347 | { |
---|
| 348 | var x; |
---|
| 349 | var context = ''; |
---|
| 350 | select_context = select_orgs.options[i].value.toLowerCase(); |
---|
| 351 | organization_name = organization_context.split(","); |
---|
| 352 | |
---|
| 353 | for (x in organization_name) |
---|
| 354 | { |
---|
| 355 | tmp = organization_name[x].split("="); |
---|
| 356 | context += tmp[1] + '.'; |
---|
| 357 | } |
---|
| 358 | } |
---|
| 359 | } |
---|
| 360 | domain_name = document.forms[0].defaultDomain.value; |
---|
| 361 | |
---|
| 362 | x=context.indexOf(ldap_context,0); |
---|
| 363 | org_name_par = context.substring(0,(x-1)); |
---|
| 364 | org_name = org_name_par.split('.'); |
---|
| 365 | org_name = org_name[org_name.length-1]; |
---|
[47] | 366 | |
---|
[46] | 367 | if (org_name != '') |
---|
[47] | 368 | document.forms[0].email.value = document.forms[0].cn.value + '@' + org_name + '.aaa' + domain_name; |
---|
[46] | 369 | else |
---|
| 370 | document.forms[0].email.value = document.forms[0].cn.value; |
---|
| 371 | } |
---|
| 372 | else |
---|
| 373 | { |
---|
| 374 | document.forms[0].email.value = document.forms[0].cn.value; |
---|
| 375 | } |
---|
[73] | 376 | } |
---|
| 377 | |
---|
[474] | 378 | function search_organization(key, element) |
---|
[73] | 379 | { |
---|
[474] | 380 | var organizations = document.getElementById(element); |
---|
[73] | 381 | var RegExp_org = new RegExp("\\b"+key, "i"); |
---|
| 382 | |
---|
| 383 | for(i = 0; i < organizations.length; i++) |
---|
| 384 | { |
---|
| 385 | if (RegExp_org.test(organizations[i].text)) |
---|
| 386 | { |
---|
| 387 | organizations[i].selected = true; |
---|
| 388 | return; |
---|
| 389 | } |
---|
| 390 | } |
---|
[640] | 391 | } |
---|
| 392 | |
---|
| 393 | function popup_group_info() |
---|
| 394 | { |
---|
| 395 | var select_usersInGroup = document.getElementById('ea_select_usersInGroup'); |
---|
| 396 | var count_usersInGroup = select_usersInGroup.options.length; |
---|
| 397 | var html = ''; |
---|
| 398 | |
---|
| 399 | for (i = 0 ; i < count_usersInGroup ; i++) |
---|
| 400 | { |
---|
| 401 | if(parseInt(select_usersInGroup.options[i].value) > 0) |
---|
| 402 | html += select_usersInGroup.options[i].text + '<br>'; |
---|
| 403 | } |
---|
| 404 | |
---|
| 405 | var window_group = window.open('','','width=300,height=400,resizable=yes,scrollbars=yes,left=100,top=100'); |
---|
| 406 | window_group.document.body.innerHTML = '<html><head></head><body><H1>'+ document.forms[0].cn.value + '</H1>'+html+'</body></html>'; |
---|
| 407 | window_group.document.close(); |
---|
| 408 | return true; |
---|
[2712] | 409 | } |
---|