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

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