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

Revision 5133, 20.1 KB checked in by wmerlotto, 12 years ago (diff)

Ticket #2305 - Enviando alteracoes, desenvolvidas internamente na Prognus, do modulo ExpressoAdmin.

  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
1countFiles = 1;
2
3function Element( id )
4{
5    return document.getElementById( id );
6}
7
8function validate_fields(type)
9{
10        if (type == 'create_user')
11        {
12                //UID
13                document.forms[0].uid.value = document.forms[0].uid.value.toLowerCase();
14               
15                if (document.forms[0].uid.value == ''){
16                        alert(get_lang('LOGIN field is empty') + '.');
17                        return;
18                }
19                else if (document.forms[0].uid.value.length < document.forms[0].minimumSizeLogin.value){
20                        alert(get_lang('LOGIN field must be bigger than') + ' ' + document.forms[0].minimumSizeLogin.value + ' ' + get_lang('characters') + '.');
21                        return;
22                }
23               
24                // Verifica se o delimitador do Cyrus permite ponto (dot.) nas mailboxes;
25                if (document.forms[0].imapDelimiter.value == '/')
26                        var reUid = /^([a-zA-Z0-9_\.\-])+$/;
27                else
28                        var reUid = /^([a-zA-Z0-9_\-])+$/;
29                if(!reUid.test(document.forms[0].uid.value)){
30                        alert(get_lang('LOGIN field contains characters not allowed') + '.');
31                        return;
32                }
33       
34                //PASSWORD's
35                if (document.forms[0].password1.value == ''){
36                        alert(get_lang('Password field is empty') + '.');
37                        return;
38                }
39                if (document.forms[0].password2.value == ''){
40                        alert(get_lang('re-password field is empty') + '.');
41                        return;
42                }
43        }
44
45        if (document.forms[0].password1.value != document.forms[0].password2.value){
46                alert(get_lang('password and re-password are different') + '.');
47                return;
48        }
49
50        // Corporative Information
51        if (document.forms[0].corporative_information_employeenumber.value != "")
52        {
53                var re_employeenumber = /^([0-9])+$/;
54               
55                if(!re_employeenumber.test(document.forms[0].corporative_information_employeenumber.value))
56                {
57                        alert(get_lang('EmployeeNumber contains characters not allowed') + '. ' + get_lang('Only numbers are allowed') + '.');
58                        document.forms[0].corporative_information_employeenumber.focus();
59                        return;
60                }
61        }
62
63        //MAIL
64        document.forms[0].mail.value = document.forms[0].mail.value.toLowerCase();
65        if (document.forms[0].mail.value == ''){
66                alert(get_lang('Email field is empty') + '.');
67                return;
68        }
69        var reEmail = /^([a-zA-Z0-9_\-])+(\.[a-zA-Z0-9_\-]+)*\@([a-zA-Z0-9_\-])+(\.[a-zA-Z0-9_\-]+)*$/;
70        if(!reEmail.test(document.forms[0].mail.value)){
71                alert(get_lang('Email field is not valid') + '.');
72                return false;
73        }
74       
75        //FIRSTNAME
76        var reGivenname = /^[a-zA-Z0-9 \-\.]+$/;
77        if(!reGivenname.test(document.forms[0].givenname.value)){
78                alert(get_lang('First name field contains characters not allowed') + '.');
79                return false;
80        }
81        else if (document.forms[0].givenname.value == ''){
82                alert(get_lang('First name field is empty') + '.');
83                return;
84        }
85       
86        //LASTNAME
87        var reSn = /^[a-zA-Z0-9 \-\.]+$/;
88        if(!reSn.test(document.forms[0].sn.value)){
89                alert(get_lang('Last name field contains characters not allowed') + '.');
90                return false;
91        }
92        else if (document.forms[0].sn.value == ''){
93                alert(get_lang('Last name field is empty') + '.');
94                return;
95        }
96       
97        //TELEPHONENUMBER
98        if (document.forms[0].telephonenumber.value != '')
99        {
100                reg_tel = /\(\d{2}\)\d{4}-\d{4}$/;
101                if (!reg_tel.exec(document.forms[0].telephonenumber.value))
102                {
103                        alert(get_lang('Phone field is incorrect') + '.');
104                        return;
105                }
106        }
107       
108        //FORWAR ONLY
109        if ((document.forms[0].deliverymode.checked) && (document.forms[0].mailforwardingaddress.value == '')){
110                alert(get_lang('Forward email is empty') + '.');
111                return;
112        }
113       
114        // Email Quota
115        if (document.forms[0].mailquota.value == ''){
116                alert(get_lang('User without email quota') + '.');
117                return;
118        }
119       
120        //GROUPS
121        if (document.getElementById('ea_select_user_groups').length < 1){
122                alert(get_lang('User is not in any group') + '.');
123                return;
124        }
125
126        //SAMBA
127        if (document.getElementById('tabcontent6').style.display != 'none'){
128                if ((document.forms[0].sambalogonscript.value == '') && (!document.forms[0].sambalogonscript.disabled)){
129                        alert(get_lang('Logon script is empty') + '.');
130                        return;
131                }
132                if ((document.forms[0].sambahomedirectory.value == '') && (!document.forms[0].sambahomedirectory.disabled)){
133                        alert(get_lang('Users home directory is empty') + '.');
134                        return;
135                }
136        }
137
138        // Uid, Mail and CPF exist?
139        var attrs_array = new Array();
140        attrs_array['type'] = type;
141        attrs_array['uid'] = document.forms[0].uid.value;
142        attrs_array['mail'] = document.forms[0].mail.value;
143        attrs_array['cpf'] = document.forms[0].corporative_information_cpf.value;
144       
145        if (document.forms[0].mailalternateaddress.value != '')
146                attrs_array['mailalternateaddress'] = document.forms[0].mailalternateaddress.value;
147        var attributes = admin_connector.serialize(attrs_array);
148
149        var handler_validate_fields = function(data)
150        {
151                if (!data.status)
152                {
153                        alert(data.msg);
154                }
155                else
156                {
157                        if ( (data.question) && (!confirm(data.question)) )
158                        {
159                                return false;
160                        }
161
162                        if (type == 'create_user')
163                        {       // Turn enabled checkbox on create user.
164                                document.getElementById('changepassword').disabled = false;
165                                cExecuteForm ("$this.user.create", document.forms[0], handler_create);
166                        }
167                        else
168                        {
169                                //Turn enabled all checkboxes and inputs
170                                document.getElementById('changepassword').disabled = false;
171                                document.getElementById('phpgwaccountstatus').disabled = false;
172                                document.getElementById('phpgwaccountvisible').disabled = false;
173                                document.getElementById('telephonenumber').disabled = false;
174                                document.getElementById('mailforwardingaddress').disabled = false;
175                                document.getElementById('mailalternateaddress').disabled = false;
176                                document.getElementById('passwd_expired').disabled = false;
177                                document.getElementById('accountstatus').disabled = false;
178                                document.getElementById('deliverymode').disabled = false;
179                                document.getElementById('use_attrs_samba').disabled = false;
180                               
181                                table_apps = document.getElementById('ea_table_apps');
182                                var inputs = table_apps.getElementsByTagName("input");
183                                for (var i = 0; i < inputs.length; i++)
184                                {
185                                        inputs[i].disabled = false;
186                                }
187                                cExecuteForm ("$this.user.save", document.forms[0], handler_save);
188                        }
189                }
190        }
191       
192        // Needed select all options from select
193        select_user_maillists = document.getElementById('ea_select_user_maillists');
194        select_user_groups = document.getElementById('ea_select_user_groups');
195        for(var i=0; i<select_user_maillists.options.length; i++)
196                select_user_maillists.options[i].selected = true;
197        for(var i=0; i<select_user_groups.options.length; i++)
198                select_user_groups.options[i].selected = true;
199        /////////////////////////////////////////////////////////////////////////////////////////////////////////
200        document.getElementById('uid').disabled = false; //Caso o login seja gerado automático, tirar o disabled.
201        cExecute ('$this.ldap_functions.validate_fields&attributes='+attributes, handler_validate_fields);
202}
203
204function generate_login(first_name,second_name) {
205        if ((first_name=='') || (second_name=='')) {
206                alert(get_lang("You must type the first and the second name before generate the login"));
207                return;
208        }
209        var attrs_array = new Array();
210        attrs_array['first_name'] = first_name;
211        attrs_array['second_name'] = second_name;
212        var attributes = admin_connector.serialize(attrs_array);
213       
214        var handler_generate_login = function(data) {
215                if(data['status']) {
216                        document.getElementById('uid').value = data['msg'];
217                        emailSuggestion_expressoadmin('true','true');
218                        document.getElementById("mail").value=document.getElementById("mail1").value;
219                }
220                else
221                        alert(data['msg']);
222        }
223
224        cExecute ('$this.ldap_functions.generate_login&attributes='+attributes, handler_generate_login);
225}
226
227// HANDLER CREATE
228// É necessário 2 funcões de retorno por causa do cExecuteForm.
229function handler_create(data)
230{
231        return_handler_create(data);
232}
233function return_handler_create(data)
234{
235        if (!data.status)
236                alert(data.msg);
237        else
238                alert(get_lang('User successful created') + '.');
239
240        location.href="./index.php?menuaction=expressoAdmin1_2.uiaccounts.list_users";
241        return;
242}
243
244
245// HANDLER SAVE
246// É necessário 2 funcões de retorno por causa do cExecuteForm.
247function handler_save(data)
248{
249        return_handler_save(data);
250}
251function return_handler_save(data)
252{
253        if (!data.status){
254                alert(data.msg);
255        }
256        else{
257                alert(get_lang('User successful saved') + '.');
258        }
259        location.href="./index.php?menuaction=expressoAdmin1_2.uiaccounts.list_users";
260        return;
261}
262
263function get_available_groups(context, sentence)
264{
265//     if( !sentence )
266//      sentence = Element( 'ea_input_searchGroup' ).value;
267//
268//      var url = '$this.ldap_functions.get_available_groups&context='+context + '&sentence='+sentence;
269//
270//     var fillHandler = function( fill ){
271//
272//      //fill = fill.users;
273//
274//      Element('ea_select_available_groups').innerHTML = fill;
275//
276//      return( fill !== "" );
277//     }
278//
279//     userFinder( sentence, fillHandler, url, new Function('x','return x'), 'ea_span_searching_group' );
280
281    if( !sentence )
282        sentence = 'ea_input_searchGroup';
283
284    optionFind( sentence, 'ea_select_available_groups',
285                '$this.ldap_functions.get_available_groups',
286                context, 'ea_span_searching_group' );
287               
288}
289       
290function add_user2group()
291{
292        select_available_groups = document.getElementById('ea_select_available_groups');
293        select_user_groups = document.getElementById('ea_select_user_groups');
294        combo_primary_user_group = document.getElementById('ea_combo_primary_user_group');
295
296        for (i = 0 ; i < select_available_groups.length ; i++)
297        {
298                if (select_available_groups.options[i].selected)
299                {
300                        isSelected = false;
301                        for(var j = 0;j < select_user_groups.options.length; j++)
302                        {
303                                if(select_user_groups.options[j].value == select_available_groups.options[i].value)
304                                {
305                                        isSelected = true;                                             
306                                        break; 
307                                }
308                        }
309
310                        if(!isSelected)
311                        {
312                                new_option1 = document.createElement('option');
313                                new_option1.value =select_available_groups.options[i].value;
314                                new_option1.text = select_available_groups.options[i].text;
315                                new_option1.selected = true;
316                                select_user_groups.options[select_user_groups.options.length] = new_option1;
317                               
318                                new_option2 = document.createElement('option');
319                                new_option2.value =select_available_groups.options[i].value;
320                                new_option2.text = select_available_groups.options[i].text;
321                                combo_primary_user_group.options[combo_primary_user_group.options.length] = new_option2;
322                        }
323                }
324        }
325               
326        for (j =0; j < select_available_groups.options.length; j++)
327                select_available_groups.options[j].selected = false;
328}       
329       
330function remove_user2group()
331{
332        select_user_groups = document.getElementById('ea_select_user_groups');
333        combo_primary_user_group = document.getElementById('ea_combo_primary_user_group');
334       
335        var x;
336        var j=0;
337        var to_remove = new Array();
338       
339        for(var i = 0;i < select_user_groups.options.length; i++)
340        {
341                if(select_user_groups.options[i].selected)
342                {
343                        to_remove[j] = select_user_groups.options[i].value;
344                        j++;
345                        select_user_groups.options[i--] = null;
346                }
347        }
348       
349        for (x in to_remove)
350        {
351                for(var i=0; i<combo_primary_user_group.options.length; i++)
352                {
353                        if (combo_primary_user_group.options[i].value == to_remove[x])
354                        {
355                                combo_primary_user_group.options[i] = null;
356                        }       
357                }
358        }
359}
360       
361function get_available_maillists(context, sentence)
362{
363    if( !sentence )
364        sentence = Element('ea_input_searchMailList').value;
365
366    var url = '$this.ldap_functions.get_available_maillists&context='+context + '&sentence='+sentence;
367
368    var fillHandler = function( fill ){
369
370        //fill = fill.users;
371
372        Element('ea_select_available_maillists').innerHTML = fill;
373
374        return( fill !== "" );
375        }
376
377    userFinder( sentence, fillHandler, url, new Function('x','return x'), 'ea_span_searching_maillist' );
378}
379       
380function add_user2maillist()
381{
382        select_available_maillists = document.getElementById('ea_select_available_maillists');
383        select_user_maillists = document.getElementById('ea_select_user_maillists');
384
385        for (i = 0 ; i < select_available_maillists.length ; i++)
386        {
387
388                if (select_available_maillists.options[i].selected)
389                {
390                        isSelected = false;
391                        for(var j = 0;j < select_user_maillists.options.length; j++)
392                        {
393                                if(select_user_maillists.options[j].value == select_available_maillists.options[i].value)
394                                {
395                                        isSelected = true;                                             
396                                        break; 
397                                }
398                        }
399
400                        if(!isSelected)
401                        {
402                                new_option = document.createElement('option');
403                                new_option.value =select_available_maillists.options[i].value;
404                                new_option.text = select_available_maillists.options[i].text;
405                                new_option.selected = true;
406                                       
407                                select_user_maillists.options[select_user_maillists.options.length] = new_option;
408                        }
409                }
410        }
411               
412        for (j =0; j < select_available_maillists.options.length; j++)
413                select_available_maillists.options[j].selected = false;
414}       
415       
416function remove_user2maillist()
417{
418        select_user_maillists = document.getElementById('ea_select_user_maillists');
419
420        for(var i = 0;i < select_user_maillists.options.length; i++)
421                if(select_user_maillists.options[i].selected)
422                        select_user_maillists.options[i--] = null;
423}
424       
425function sinc_combos_org(context)
426{
427        combo_org_groups = document.getElementById('ea_combo_org_groups');
428        combo_org_maillists = document.getElementById('ea_combo_org_maillists');
429
430        for (i=0; i<combo_org_groups.length; i++)
431        {
432                if (combo_org_groups.options[i].value == context)
433                {
434                        combo_org_groups.options[i].selected = true;
435                        combo_org_maillists.options[i].selected = true;
436                }
437        }
438}
439       
440function use_samba_attrs(value)
441{
442        if (value)
443        {
444                if (document.forms[0].sambalogonscript.value == '')
445                {
446                        if (document.forms[0].defaultLogonScript.value == '')
447                        {
448                                document.forms[0].sambalogonscript.value = document.forms[0].uid.value + '.bat';
449                        }
450                        else
451                        {
452                                document.forms[0].sambalogonscript.value = document.forms[0].defaultLogonScript.value;
453                        }
454                }
455                if (document.forms[0].sambahomedirectory.value == '')
456                {
457                        document.forms[0].sambahomedirectory.value = '/home/'+document.forms[0].uid.value+'/';
458                }
459        }
460       
461        if (!document.forms[0].use_attrs_samba.disabled)
462        {
463                document.forms[0].sambaacctflags.disabled = !value;
464                document.forms[0].sambadomain.disabled = !value;
465                document.forms[0].sambalogonscript.disabled = !value;
466                document.forms[0].sambahomedirectory.disabled = !value;
467        }
468}
469       
470function set_user_default_password()
471{
472        var handler_set_user_default_password = function(data)
473        {
474                if (!data.status)
475                        alert(data.msg);
476                else
477                        alert(get_lang('Default password successful saved') + '.');
478                return;
479        }
480        cExecute ('$this.user.set_user_default_password&uid='+document.forms[0].uid.value, handler_set_user_default_password); 
481}
482
483function return_user_password()
484{
485        var handler_return_user_password = function(data)
486        {
487                if (!data.status)
488                        alert(data.msg);
489                else
490                        alert(get_lang('Users password successful returned') + '.');
491                return;
492        }
493        cExecute ('$this.user.return_user_password&uid='+document.forms[0].uid.value, handler_return_user_password);
494}
495
496function delete_user(uid, uidnumber)
497{
498        if (confirm(get_lang("Do you really want delete the user") + " " + uid + "?"))
499        {
500                var handler_delete_user = function(data)
501                {
502                        if (!data.status)
503                                alert(data.msg);
504                        else
505                                alert(get_lang('User successful deleted') + '.');
506                       
507                        location.href="./index.php?menuaction=expressoAdmin1_2.uiaccounts.list_users";
508                        return;
509                }
510                cExecute ('$this.user.delete&uidnumber='+uidnumber+'&uid='+uid, handler_delete_user);
511        }
512}
513
514function rename_user(uid, uidnumber)
515{
516        if (document.getElementById('accounts_form_imapDelimiter').value == '/')
517                var reUid = /^([a-zA-Z0-9_\.\-])+$/;
518        else
519                var reUid = /^([a-zA-Z0-9_\-])+$/;
520
521        new_uid = prompt(get_lang('Rename users login from') + ': ' + uid + " " + get_lang("to") + ': ', uid);
522
523        if(!reUid.test(new_uid)){
524                alert(get_lang('LOGIN field contains characters not allowed') + '.');
525                document.forms[0].account_lid.focus();
526                return;
527        }
528       
529        if ((new_uid) && (new_uid != uid))
530        {
531                var handler_validate_fields = function(data)
532                {
533                        if (!data.status)
534                                alert(data.msg);
535                        else
536                                cExecute ('$this.user.rename&uid='+uid+'&new_uid='+new_uid, handler_rename);
537                       
538                        return;
539                }
540               
541                // New uid exist?
542                attrs_array = new Array();
543                attrs_array['type'] = 'rename_user';
544                attrs_array['uid'] = new_uid;
545                attributes = admin_connector.serialize(attrs_array);
546       
547                cExecute ('$this.ldap_functions.validate_fields&attributes='+attributes, handler_validate_fields);
548        }
549}
550
551// HANDLER RENAME
552function handler_rename(data)
553{
554        if (!data.status)
555                alert(data.msg);
556        else{
557                alert(get_lang('User login successful renamed') + "\n" + data.exec_return);
558                location.href="./index.php?menuaction=expressoAdmin1_2.uiaccounts.list_users";
559        }
560        return;
561
562}
563
564
565// Variaveis Locais
566var finderTimeout_maillist = '';
567
568// Funcoes Find MailList
569function optionFinderTimeout_maillist(obj, event)
570{
571    if( event && event.keyCode !== 13 )
572        return;
573
574    optionFinder_maillist( obj.id );
575}
576function optionFinder_maillist(id) {
577               
578    get_available_maillists( Element('ea_combo_org_maillists').value, Element(id).value );
579       
580}                       
581
582// Variaveis Locais
583var finderTimeout_group = '';
584
585
586// Funcoes Find Group
587function optionFinderTimeout_group(obj, event)
588{
589               
590        if( event && event.keyCode !== 13 )
591            return;
592       
593        optionFinder_group(obj.id);
594}
595function optionFinder_group(id) {       
596       
597        get_available_groups( Element('ea_combo_org_groups').value, Element(id).value );
598}
599
600function get_available_sambadomains(context, type)
601{
602        if ((type == 'create_user') && (document.getElementById('tabcontent7').style.display != 'none'))
603        {
604                var handler_get_available_sambadomains = function(data)
605                {
606                        document.forms[0].use_attrs_samba.checked = data.status;
607                        use_samba_attrs(data.status);
608                       
609                        if (data.status)
610                        {
611                                combo_sambadomains = document.getElementById('ea_combo_sambadomains');
612                                for (i=0; i<data.sambaDomains.length; i++)
613                                {
614                                        for (j=0; j<combo_sambadomains.length; j++)
615                                        {
616                                                if (combo_sambadomains.options[j].text == data.sambaDomains[i])
617                                                {
618                                                        combo_sambadomains.options[j].selected = true;
619                                                        break;
620                                                }
621                                        }
622                                }
623                               
624                        }
625                }
626               
627                cExecute ('$this.ldap_functions.exist_sambadomains_in_context&context='+context, handler_get_available_sambadomains);
628        }
629}
630
631function empty_inbox(uid)
632{
633        var action = get_lang('Cleanned user mailbox');
634        var handler_write_log = function(){}
635        var handler_empty_inbox = function(data)
636        {
637                if (!data.status)
638                        alert(data.msg);
639                else{
640                        cExecute ('$this.user.write_log_from_ajax&_action='+action+'&userinfo='+uid, handler_write_log);
641                        alert(get_lang('Emptied')+' '+ data.inbox_size + ' ' + get_lang('MB from user inbox'));
642                        document.getElementById('mailquota_used').value = data.mailquota_used;
643                }
644        }
645        cExecute ('$this.imap_functions.empty_user_inbox&uid='+uid, handler_empty_inbox);
646}
647
648function validarCPF(cpf)
649{
650        if(cpf.length != 11 || cpf == "00000000000" || cpf == "11111111111" ||
651                cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" ||
652                cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" ||
653                cpf == "88888888888" || cpf == "99999999999"){
654          return false;
655   }
656
657        soma = 0;
658        for(i = 0; i < 9; i++)
659                soma += parseInt(cpf.charAt(i)) * (10 - i);
660        resto = 11 - (soma % 11);
661        if(resto == 10 || resto == 11)
662                resto = 0;
663        if(resto != parseInt(cpf.charAt(9)))
664        {
665                return false;
666        }
667       
668        soma = 0;
669        for(i = 0; i < 10; i ++)
670                soma += parseInt(cpf.charAt(i)) * (11 - i);
671        resto = 11 - (soma % 11);
672        if(resto == 10 || resto == 11)
673                resto = 0;
674        if(resto != parseInt(cpf.charAt(10))){
675                return false;
676        }
677        return true;
678}
679
680function search_organization(key, element)
681{
682        var organizations = document.getElementById(element);
683        var RegExp_org = new RegExp("\\b"+key, "i");
684       
685        for(i = 0; i < organizations.length; i++)
686        {
687                if (RegExp_org.test(organizations[i].text))
688                {
689                        organizations[i].selected = true;
690                        return;
691                }
692        }
693}
694
695function add_input_mailalternateaddress()
696{
697        var input = document.createElement("INPUT");
698        input.size = 30;
699        input.name = "mailalternateaddress[]";
700        input.setAttribute("autocomplete","off");
701        document.getElementById("td_input_mailalternateaddress").appendChild(document.createElement("br"));
702        document.getElementById("td_input_mailalternateaddress").appendChild(input);
703}
704
705function add_input_mailforwardingaddress()
706{
707        var input = document.createElement("INPUT");
708        input.size = 30;
709        input.name = "mailforwardingaddress[]";
710        input.setAttribute("autocomplete","off");
711        document.getElementById("td_input_mailforwardingaddress").appendChild(document.createElement("br"));
712        document.getElementById("td_input_mailforwardingaddress").appendChild(input);
713}
714
715function set_changepassword()
716{
717        if (document.getElementById('passwd_expired').checked)
718                {
719                document.getElementById('changepassword').checked = true;
720                document.getElementById('changepassword').disabled = true;
721                }
722                else
723                {
724                document.getElementById('changepassword').disabled =false;
725                }
726}
727
728
Note: See TracBrowser for help on using the repository browser.