source: trunk/expressoAdmin1_2/js/jscode/users.js @ 63

Revision 63, 19.5 KB checked in by niltonneto, 17 years ago (diff)

* empty log message *

  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
1countFiles = 1;
2function validate_fields(type)
3{
4        if (type == 'create_user')
5        {
6                //UID
7                document.forms[0].uid.value = document.forms[0].uid.value.toLowerCase();
8                if (document.forms[0].uid.value == ''){
9                        alert('Campo LOGIN está vazio.');
10                        return;
11                }
12                else if (document.forms[0].uid.value.length < document.forms[0].minimumSizeLogin.value){
13                        alert('Campo LOGIN deve ter mais que '+document.forms[0].minimumSizeLogin.value+' caracteres.');
14                        return;
15                }
16               
17                // Verifica se o delimitador do Cyrus permite ponto (dot.) nas mailboxes;
18                if (document.forms[0].imapDelimiter.value == '/')
19                        var reUid = /^([a-zA-Z0-9_\.\-])+$/;
20                else
21                        var reUid = /^([a-zA-Z0-9_\-])+$/;
22                if(!reUid.test(document.forms[0].uid.value)){
23                        alert('Campo LOGIN comtém caracteres não permitidos.');
24                        document.forms[0].account_lid.focus();
25                        return;
26                }
27       
28                //PASSWORD's
29                if (document.forms[0].password1.value == ''){
30                        alert('Campo SENHA está vazio.');
31                        return;
32                }
33                if (document.forms[0].password2.value == ''){
34                        alert('Campo RE-SENHA está vazio.');
35                        return;
36                }
37        }
38
39        if (document.forms[0].password1.value != document.forms[0].password2.value){
40                alert('Campo SENHA e RE-SENHA são diferentes.');
41                return;
42        }
43       
44        // Corporative Information
45        if (document.forms[0].corporative_information_employeenumber.value != "")
46        {
47                var re_employeenumber = /^([0-9])+$/;
48               
49                if(!re_employeenumber.test(document.forms[0].corporative_information_employeenumber.value))
50                {
51                        alert('Campo matrícula contém caracteres não permitidos. Somente números são permitidos.');
52                        document.forms[0].corporative_information_employeenumber.focus();
53                        return;
54                }
55        }
56
57        if (document.forms[0].corporative_information_cpf.value != "")
58        {
59                var re_cpf = /^([0-9])+$/;
60
61                if(!re_cpf.test(document.forms[0].corporative_information_cpf.value))
62                {
63                        alert('Campo cpf contém caracteres não permitidos. Somente números são permitidos');
64                        document.forms[0].corporative_information_employeenumber.focus();
65                        return;
66                }
67       
68                if (! validarCPF(document.forms[0].corporative_information_cpf.value) )
69                {
70                        alert("Campo CPF invalido.");
71                        document.forms[0].corporative_information_cpf.focus();
72                        return;
73                }
74        }
75       
76        //MAIL
77        document.forms[0].mail.value = document.forms[0].mail.value.toLowerCase();
78        if (document.forms[0].mail.value == ''){
79                alert('Campo E-MAIL está vazio.');
80                return;
81        }
82        var reEmail = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
83        if(!reEmail.test(document.forms[0].mail.value)){
84                alert("Campo E-mail não é válido.");
85                return false;
86        }
87       
88        //FIRSTNAME
89        if (document.forms[0].givenname.value == ''){
90                alert('Campo PRIMEIRO NOME está vazio.');
91                return;
92        }
93       
94        //LASTNAME
95        if (document.forms[0].sn.value == ''){
96                alert('Campo ÚLTIMO NOME está vazio.');
97                return;
98        }
99       
100        //TELEPHONENUMBER
101        if (document.forms[0].telephonenumber.value != '')
102        {
103                reg_tel = /\(\d{2}\)\d{4}-\d{4}$/;
104                if (!reg_tel.exec(document.forms[0].telephonenumber.value))
105                {
106                        alert('Campo Telefone incorreto.');
107                        return;
108                }
109        }
110       
111        //FORWAR ONLY
112        if ((document.forms[0].deliverymode.checked) && (document.forms[0].mailforwardingaddress.value == '')){
113                alert('Campo E-MAIL DE ENCAMINHAMENTO está vazio.');
114                return;
115        }
116       
117        // Email Quota
118        if (document.forms[0].mailquota.value == ''){
119                alert('Usuário sem COTA.');
120                return;
121        }
122       
123        //GROUPS
124        if (document.getElementById('ea_select_user_groups').length < 1){
125                alert('Nenhum GRUPO selecionado.');
126                return;
127        }
128
129        //SAMBA
130        if (document.getElementById('tabcontent6').style.display != 'none'){
131                if ((document.forms[0].sambalogonscript.value == '') && (!document.forms[0].sambalogonscript.disabled)){
132                        alert('Script de logon do usuário está vazio.');
133                        return;
134                }
135                if ((document.forms[0].sambahomedirectory.value == '') && (!document.forms[0].sambahomedirectory.disabled)){
136                        alert('Diretório Home do usuário está vazio.');
137                        return;
138                }
139        }
140
141        // Uid & Mail exist?
142        var attrs_array = new Array();
143        attrs_array['type'] = type;
144        attrs_array['uid'] = document.forms[0].uid.value;
145        attrs_array['mail'] = document.forms[0].mail.value;
146        if (document.forms[0].mailalternateaddress.value != '')
147                attrs_array['mailalternateaddress'] = document.forms[0].mailalternateaddress.value;
148        var attributes = connector.serialize(attrs_array);
149
150        var handler_validate_fields = function(data)
151        {
152                if (!data.status)
153                        alert(data.msg);
154                else
155                {
156                        if (type == 'create_user')
157                        {
158                                cExecuteForm ("$this.user.create", document.forms[0], handler_create);
159                        }
160                        else
161                        {
162                                //Turn enabled all checkboxes and inputs
163                                document.getElementById('changepassword').disabled = false;
164                                document.getElementById('phpgwaccountstatus').disabled = false;
165                                document.getElementById('phpgwaccountvisible').disabled = false;
166                                document.getElementById('telephonenumber').disabled = false;
167                                document.getElementById('mailforwardingaddress').disabled = false;
168                                document.getElementById('mailalternateaddress').disabled = false;
169                                document.getElementById('accountstatus').disabled = false;
170                                document.getElementById('deliverymode').disabled = false;
171                                document.getElementById('use_attrs_samba').disabled = false;
172                               
173                                table_apps = document.getElementById('ea_table_apps');
174                                var inputs = table_apps.getElementsByTagName("input");
175                                for (var i = 0; i < inputs.length; i++)
176                                {
177                                        inputs[i].disabled = false;
178                                }
179                                cExecuteForm ("$this.user.save", document.forms[0], handler_save);
180                        }
181                }
182        }
183       
184        // Needed select all options from select
185        select_user_maillists = document.getElementById('ea_select_user_maillists');
186        select_user_groups = document.getElementById('ea_select_user_groups');
187        for(var i=0; i<select_user_maillists.options.length; i++)
188                select_user_maillists.options[i].selected = true;
189        for(var i=0; i<select_user_groups.options.length; i++)
190                select_user_groups.options[i].selected = true;
191        /////////////////////////////////////////////////////////////////////////////////////////////////////////
192       
193        cExecute ('$this.ldap_functions.validate_fields&attributes='+attributes, handler_validate_fields);
194}
195
196// HANDLER CREATE
197// É necessário 2 funcões de retorno por causa do cExecuteForm.
198function handler_create(data)
199{
200        return_handler_create(data);
201}
202function return_handler_create(data)
203{
204        if (!data.status)
205                alert(data.msg);
206        else
207                alert('Usuário criado com êxito!');
208
209        location.href="./index.php?menuaction=expressoAdmin1_2.uiaccounts.list_users";
210        return;
211}
212
213
214// HANDLER SAVE
215// É necessário 2 funcões de retorno por causa do cExecuteForm.
216function handler_save(data)
217{
218        return_handler_save(data);
219}
220function return_handler_save(data)
221{
222        if (!data.status){
223                alert(data.msg);
224        }
225        else{
226                alert('Usuário salvo com êxito!!');
227        }
228        location.href="./index.php?menuaction=expressoAdmin1_2.uiaccounts.list_users";
229        return;
230}
231
232function get_available_groups(context)
233{
234        var handler_get_available_groups = function(data)
235        {
236                select_available_groups = document.getElementById('ea_select_available_groups');
237
238                if ((data) && (data.length > 0))
239                {
240                        // Necessario, pois o IE6 tem um bug que retira o primeiro options se o innerHTML estiver vazio.
241                        select_available_groups.innerHTML = '#' + data;
242                        select_available_groups.outerHTML = select_available_groups.outerHTML;
243                        select_available_groups_clone = select_available_groups.cloneNode(true);
244                        document.getElementById('ea_input_searchGroup').value = '';
245                }
246                else
247                {
248                        // Necessario, pois o IE6 tem um bug que retira o primeiro options se o innerHTML estiver vazio.
249                        select_available_groups.innerHTML = '#';
250                        select_available_groups.outerHTML = select_available_groups.outerHTML;
251                }
252        }       
253               
254        cExecute ('$this.ldap_functions.get_available_groups&context='+context, handler_get_available_groups);
255}
256       
257function add_user2group()
258{
259        select_available_groups = document.getElementById('ea_select_available_groups');
260        select_user_groups = document.getElementById('ea_select_user_groups');
261        combo_primary_user_group = document.getElementById('ea_combo_primary_user_group');
262
263        for (i = 0 ; i < select_available_groups.length ; i++)
264        {
265                if (select_available_groups.options[i].selected)
266                {
267                        isSelected = false;
268                        for(var j = 0;j < select_user_groups.options.length; j++)
269                        {
270                                if(select_user_groups.options[j].value == select_available_groups.options[i].value)
271                                {
272                                        isSelected = true;                                             
273                                        break; 
274                                }
275                        }
276
277                        if(!isSelected)
278                        {
279                                new_option1 = document.createElement('option');
280                                new_option1.value =select_available_groups.options[i].value;
281                                new_option1.text = select_available_groups.options[i].text;
282                                new_option1.selected = true;
283                                select_user_groups.options[select_user_groups.options.length] = new_option1;
284                               
285                                new_option2 = document.createElement('option');
286                                new_option2.value =select_available_groups.options[i].value;
287                                new_option2.text = select_available_groups.options[i].text;
288                                combo_primary_user_group.options[combo_primary_user_group.options.length] = new_option2;
289                        }
290                }
291        }
292               
293        for (j =0; j < select_available_groups.options.length; j++)
294                select_available_groups.options[j].selected = false;
295}       
296       
297function remove_user2group()
298{
299        select_user_groups = document.getElementById('ea_select_user_groups');
300        combo_primary_user_group = document.getElementById('ea_combo_primary_user_group');
301       
302        var x;
303        var j=0;
304        var to_remove = new Array();
305       
306        for(var i = 0;i < select_user_groups.options.length; i++)
307        {
308                if(select_user_groups.options[i].selected)
309                {
310                        to_remove[j] = select_user_groups.options[i].value;
311                        j++;
312                        select_user_groups.options[i--] = null;
313                }
314        }
315       
316        for (x in to_remove)
317        {
318                for(var i=0; i<combo_primary_user_group.options.length; i++)
319                {
320                        if (combo_primary_user_group.options[i].value == to_remove[x])
321                        {
322                                combo_primary_user_group.options[i] = null;
323                        }       
324                }
325        }
326}
327       
328function get_available_maillists(context)
329{
330        var handler_get_available_maillists = function(data)
331        {
332                select_available_maillists = document.getElementById('ea_select_available_maillists');
333
334                if ((data) && (data.length > 0))
335                {
336                        // Necessario, pois o IE6 tem um bug que retira o primeiro options se o innerHTML estiver vazio.
337                        select_available_maillists.innerHTML = '#' + data;
338                        select_available_maillists.outerHTML = select_available_maillists.outerHTML;
339                        select_available_maillists_clone = select_available_maillists.cloneNode(true);
340                        document.getElementById('ea_input_searchMailList').value = '';
341                }
342                else
343                {
344                        // Necessario, pois o IE6 tem um bug que retira o primeiro options se o innerHTML estiver vazio.
345                        select_available_maillists.innerHTML = '#';
346                        select_available_maillists.outerHTML = select_available_maillists.outerHTML;
347                }
348        }
349        cExecute ('$this.ldap_functions.get_available_maillists&context='+context, handler_get_available_maillists);
350}
351       
352function add_user2maillist()
353{
354        select_available_maillists = document.getElementById('ea_select_available_maillists');
355        select_user_maillists = document.getElementById('ea_select_user_maillists');
356
357        for (i = 0 ; i < select_available_maillists.length ; i++)
358        {
359
360                if (select_available_maillists.options[i].selected)
361                {
362                        isSelected = false;
363                        for(var j = 0;j < select_user_maillists.options.length; j++)
364                        {
365                                if(select_user_maillists.options[j].value == select_available_maillists.options[i].value)
366                                {
367                                        isSelected = true;                                             
368                                        break; 
369                                }
370                        }
371
372                        if(!isSelected)
373                        {
374                                new_option = document.createElement('option');
375                                new_option.value =select_available_maillists.options[i].value;
376                                new_option.text = select_available_maillists.options[i].text;
377                                new_option.selected = true;
378                                       
379                                select_user_maillists.options[select_user_maillists.options.length] = new_option;
380                        }
381                }
382        }
383               
384        for (j =0; j < select_available_maillists.options.length; j++)
385                select_available_maillists.options[j].selected = false;
386}       
387       
388function remove_user2maillist()
389{
390        select_user_maillists = document.getElementById('ea_select_user_maillists');
391
392        for(var i = 0;i < select_user_maillists.options.length; i++)
393                if(select_user_maillists.options[i].selected)
394                        select_user_maillists.options[i--] = null;
395}
396       
397function sinc_combos_org(context)
398{
399        combo_org_groups = document.getElementById('ea_combo_org_groups');
400        combo_org_maillists = document.getElementById('ea_combo_org_maillists');
401
402        for (i=0; i<combo_org_groups.length; i++)
403        {
404                if (combo_org_groups.options[i].value == context)
405                {
406                        combo_org_groups.options[i].selected = true;
407                        combo_org_maillists.options[i].selected = true;
408                }
409        }
410}
411       
412function use_samba_attrs(value)
413{
414        if (value)
415        {
416                if (document.forms[0].sambalogonscript.value == '')
417                {
418                        if (document.forms[0].defaultLogonScript.value == '')
419                        {
420                                document.forms[0].sambalogonscript.value = document.forms[0].uid.value + '.bat';
421                        }
422                        else
423                        {
424                                document.forms[0].sambalogonscript.value = document.forms[0].defaultLogonScript.value;
425                        }
426                }
427                if (document.forms[0].sambahomedirectory.value == '')
428                {
429                        document.forms[0].sambahomedirectory.value = '/home/'+document.forms[0].uid.value+'/';
430                }
431        }
432       
433        if (!document.forms[0].use_attrs_samba.disabled)
434        {
435                document.forms[0].sambaacctflags.disabled = !value;
436                document.forms[0].sambadomain.disabled = !value;
437                document.forms[0].sambalogonscript.disabled = !value;
438                document.forms[0].sambahomedirectory.disabled = !value;
439        }
440}
441       
442function set_user_default_password()
443{
444        var handler_set_user_default_password = function(data)
445        {
446                if (!data.status)
447                        alert(data.msg);
448                else
449                {
450                        alert('Senha default cadastrada com êxito!!');
451                        //location.href="./index.php?menuaction=expressoAdmin1_2.uiaccounts.list_users";
452                }
453                return;
454        }
455        cExecute ('$this.user.set_user_default_password&uid='+document.forms[0].uid.value, handler_set_user_default_password); 
456}
457
458function return_user_password()
459{
460        var handler_return_user_password = function(data)
461        {
462                if (!data.status)
463                        alert(data.msg);
464                else
465                {
466                        alert('Senha do usuário retornado com êxito!!');
467                        //location.href="./index.php?menuaction=expressoAdmin1_2.uiaccounts.list_users";
468                }
469                return;
470        }
471        cExecute ('$this.user.return_user_password&uid='+document.forms[0].uid.value, handler_return_user_password);
472}
473
474function delete_user(uid, uidnumber, context)
475{
476        if (confirm("Realmente deletar usuário " + uid + " ??"))
477        {
478                var handler_delete_user = function(data)
479                {
480                        if (!data.status)
481                                alert(data.msg);
482                        else
483                                alert('Usuário deletado com êxito!!');
484                       
485                        location.href="./index.php?menuaction=expressoAdmin1_2.uiaccounts.list_users";
486                        return;
487                }
488                cExecute ('$this.user.delete&uidnumber='+uidnumber+'&context='+context, handler_delete_user);
489        }
490}
491
492function rename_user(uid, uidnumber, context)
493{
494
495        if (document.getElementById('accounts_form_imapDelimiter').value == '/')
496                var reUid = /^([a-zA-Z0-9_\.\-])+$/;
497        else
498                var reUid = /^([a-zA-Z0-9_\-])+$/;
499
500        new_uid = prompt("Alterar login do usuário " + uid + " para: ", uid);
501
502        if(!reUid.test(new_uid)){
503                alert('Campo LOGIN comtém caracteres não permitidos.');
504                document.forms[0].account_lid.focus();
505                return;
506        }
507       
508        if ((new_uid) && (new_uid != uid))
509        {
510                var handler_validate_fields = function(data)
511                {
512                        if (!data.status)
513                                alert(data.msg);
514                        else
515                                cExecute ('$this.user.rename&uid='+uid+'&new_uid='+new_uid+'&context='+context, handler_rename);
516                       
517                        return;
518                }
519               
520                // New uid exist?
521                attrs_array = new Array();
522                attrs_array['type'] = 'rename_user';
523                attrs_array['uid'] = new_uid;
524                attributes = connector.serialize(attrs_array);
525       
526                cExecute ('$this.ldap_functions.validate_fields&attributes='+attributes, handler_validate_fields);
527        }
528}
529
530// HANDLER RENAME
531function handler_rename(data)
532{
533        if (!data.status)
534                alert(data.msg);
535        else{
536                alert("Usuário renomeado com êxito!\n" + data.exec_return);
537                location.href="./index.php?menuaction=expressoAdmin1_2.uiaccounts.list_users";
538        }
539        return;
540
541}
542
543
544// Variaveis Locais
545var finderTimeout_maillist = '';
546
547// Funcoes Find MailList
548function optionFinderTimeout_maillist(obj)
549{
550        clearTimeout(finderTimeout_maillist);
551        var oWait = document.getElementById("ea_span_searching_maillist");
552        oWait.innerHTML = 'Buscando...';
553        finderTimeout_maillist = setTimeout("optionFinder_maillist('"+obj.id+"')",500);
554}
555function optionFinder_maillist(id) {   
556        var oWait = document.getElementById("ea_span_searching_maillist");
557        var oText = document.getElementById(id);
558               
559        //Limpa todo o select
560        for(var i = 0;i < select_available_maillists.options.length; i++)
561                select_available_maillists.options[i--] = null;
562       
563        var RegExp_name = new RegExp(oText.value, "i");
564       
565        //Inclui as listas começando com a pesquisa
566        for(i = 0; i < select_available_maillists_clone.length; i++){
567                if (RegExp_name.test(select_available_maillists_clone[i].text))
568                {
569                        sel = select_available_maillists.options;
570                        option = new Option(select_available_maillists_clone[i].text,select_available_maillists_clone[i].value);                               
571                        sel[sel.length] = option;
572                }
573        }
574        oWait.innerHTML = '&nbsp;';
575}                       
576
577// Variaveis Locais
578var finderTimeout_group = '';
579
580
581// Funcoes Find Group
582function optionFinderTimeout_group(obj)
583{
584        clearTimeout(finderTimeout_group);
585        var oWait = document.getElementById("ea_span_searching_group");
586        oWait.innerHTML = 'Buscando...';
587        finderTimeout_group = setTimeout("optionFinder_group('"+obj.id+"')",500);
588}
589function optionFinder_group(id) {       
590        var oWait = document.getElementById("ea_span_searching_group");
591        var oText = document.getElementById(id);
592               
593        //Limpa todo o select
594        for(var i = 0;i < select_available_groups.options.length; i++)
595                select_available_groups.options[i--] = null;
596       
597        var RegExp_name = new RegExp(oText.value, "i");
598       
599        //Inclui as listas começando com a pesquisa
600        for(i = 0; i < select_available_groups_clone.length; i++){
601                if (RegExp_name.test(select_available_groups_clone[i].text))
602                {
603                        sel = select_available_groups.options;
604                        option = new Option(select_available_groups_clone[i].text,select_available_groups_clone[i].value);                             
605                        sel[sel.length] = option;
606                }
607        }
608        oWait.innerHTML = '&nbsp;';
609}
610
611function get_available_sambadomains(context, type)
612{
613        if ((type == 'create_user') && (document.getElementById('tabcontent6').style.display != 'none'))
614        {
615                var handler_get_available_sambadomains = function(data)
616                {
617                        document.forms[0].use_attrs_samba.checked = data.status;
618                        use_samba_attrs(data.status);
619                       
620                        if (data.status)
621                        {
622                                combo_sambadomains = document.getElementById('ea_combo_sambadomains');
623                                for (i=0; i<data.sambaDomains.length; i++)
624                                {
625                                        for (j=0; j<combo_sambadomains.length; j++)
626                                        {
627                                                if (combo_sambadomains.options[j].text == data.sambaDomains[i])
628                                                {
629                                                        combo_sambadomains.options[j].selected = true;
630                                                        break;
631                                                }
632                                        }
633                                }
634                               
635                        }
636                }
637                cExecute ('$this.ldap_functions.exist_sambadomains_in_context&context='+context, handler_get_available_sambadomains);
638        }
639}
640
641function empty_inbox(uid)
642{
643        var action = "Limpado INBOX do usuario";
644        var handler_write_log = function(){}
645        var handler_empty_inbox = function(data)
646        {
647                if (!data.status)
648                        alert(data.msg);
649                else{
650                        cExecute ('$this.user.write_log_from_ajax&_action='+action+'&userinfo='+uid, handler_write_log);
651                        alert("Esvaziados '" + data.inbox_size + "' MB da caixa postal do usuário");
652                        document.getElementById('mailquota_used').value = data.mailquota_used;
653                }
654        }
655        cExecute ('$this.imap_functions.empty_inbox&uid='+uid, handler_empty_inbox);
656}
657
658function validarCPF(cpf)
659{
660        if(cpf.length != 11 || cpf == "00000000000" || cpf == "11111111111" ||
661                cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" ||
662                cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" ||
663                cpf == "88888888888" || cpf == "99999999999"){
664          return false;
665   }
666
667        soma = 0;
668        for(i = 0; i < 9; i++)
669                soma += parseInt(cpf.charAt(i)) * (10 - i);
670        resto = 11 - (soma % 11);
671        if(resto == 10 || resto == 11)
672                resto = 0;
673        if(resto != parseInt(cpf.charAt(9)))
674        {
675                return false;
676        }
677       
678        soma = 0;
679        for(i = 0; i < 10; i ++)
680                soma += parseInt(cpf.charAt(i)) * (11 - i);
681        resto = 11 - (soma % 11);
682        if(resto == 10 || resto == 11)
683                resto = 0;
684        if(resto != parseInt(cpf.charAt(10))){
685                return false;
686        }
687        return true;
688}
Note: See TracBrowser for help on using the repository browser.