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

Revision 27, 18.4 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       
249function get_available_groups(context)
250{
251        var handler_get_available_groups = function(data)
252        {
253                select_available_groups = document.getElementById('ea_select_available_groups');
254                //Limpa o select
255                for(var i=0; i<select_available_groups.options.length; i++)
256                {
257                        select_available_groups.options[i] = null;
258                        i--;
259                }
260
261                if (data.length > 0)
262                {
263                        for (i=0; i<data.length; i++)
264                        {
265                                new_option = new Option(data[i].cn[0],data[i].gidnumber[0],false,false);
266                                select_available_groups.options[i] = new_option;
267                        }
268                        //select_available_groups.disabled = false;
269                        select_available_groups.options[0].selected = true;
270                        select_available_groups_clone = select_available_groups.cloneNode(true);
271                        document.getElementById('ea_input_searchGroup').value = '';
272                       
273                }
274        }       
275               
276cExecute ('$this.ldap_functions.get_available_groups&context='+context, handler_get_available_groups);
277}
278       
279
280function add_user2group()
281{
282        select_available_groups = document.getElementById('ea_select_available_groups');
283        select_user_groups = document.getElementById('ea_select_user_groups');
284        combo_primary_user_group = document.getElementById('ea_combo_primary_user_group');
285
286        for (i = 0 ; i < select_available_groups.length ; i++)
287        {
288                if (select_available_groups.options[i].selected)
289                {
290                        isSelected = false;
291                        for(var j = 0;j < select_user_groups.options.length; j++)
292                        {
293                                if(select_user_groups.options[j].value == select_available_groups.options[i].value)
294                                {
295                                        isSelected = true;                                             
296                                        break; 
297                                }
298                        }
299
300                        if(!isSelected)
301                        {
302                                new_option1 = document.createElement('option');
303                                new_option1.value =select_available_groups.options[i].value;
304                                new_option1.text = select_available_groups.options[i].text;
305                                new_option1.selected = true;
306                                select_user_groups.options[select_user_groups.options.length] = new_option1;
307                               
308                                new_option2 = document.createElement('option');
309                                new_option2.value =select_available_groups.options[i].value;
310                                new_option2.text = select_available_groups.options[i].text;
311                                combo_primary_user_group.options[combo_primary_user_group.options.length] = new_option2;
312                        }
313                }
314        }
315               
316        for (j =0; j < select_available_groups.options.length; j++)
317                select_available_groups.options[j].selected = false;
318}       
319       
320function remove_user2group()
321{
322        select_user_groups = document.getElementById('ea_select_user_groups');
323        combo_primary_user_group = document.getElementById('ea_combo_primary_user_group');
324       
325        var x;
326        var j=0;
327        var to_remove = new Array();
328       
329        for(var i = 0;i < select_user_groups.options.length; i++)
330        {
331                if(select_user_groups.options[i].selected)
332                {
333                        to_remove[j] = select_user_groups.options[i].value;
334                        j++;
335                        select_user_groups.options[i--] = null;
336                }
337        }
338       
339        for (x in to_remove)
340        {
341                for(var i=0; i<combo_primary_user_group.options.length; i++)
342                {
343                        if (combo_primary_user_group.options[i].value == to_remove[x])
344                        {
345                                combo_primary_user_group.options[i] = null;
346                        }       
347                }
348        }
349       
350        //return;
351        /*
352        //Refaz combo do primary group
353        for(var i=0; i<combo_primary_user_group.options.length; i++)
354        {
355                if(combo_primary_user_group.options[i].selected == true)
356                {
357                        var user_primary_group = combo_primary_user_group.options[i].value;
358                        alert(user_primary_group);
359                }
360               
361                combo_primary_user_group.options[i] = null;
362                i--;
363        }
364       
365        for(var i = 0;i < select_user_groups.options.length; i++)
366        {
367                new_option = document.createElement('option');
368                new_option.value= select_user_groups.options[i].value;
369                new_option.text = select_user_groups.options[i].text;
370               
371                if (user_primary_group == select_user_groups.options[i].value)
372                        new_option.selected = true;
373               
374                combo_primary_user_group.options[i] = new_option;
375        }*/
376}
377       
378function get_available_maillists(context)
379{
380        var handler_get_available_maillists = function(data)
381        {
382                select_available_maillists = document.getElementById('ea_select_available_maillists');
383                //Limpa o select
384                for(var i=0; i<select_available_maillists.options.length; i++)
385                {
386                        select_available_maillists.options[i] = null;
387                        i--;
388                }
389
390                if (data.length > 0)
391                {
392                        for (i=0; i<data.length; i++)
393                        {
394                                new_option = new Option(data[i].uid[0]+' ('+data[i].mail[0]+')', data[i].uidnumber[0], false, false);
395                                select_available_maillists.options[i] = new_option;
396                        }
397                        select_available_maillists.disabled = false;
398                        select_available_maillists.options[0].selected = true;
399                        select_available_maillists_clone = select_available_maillists.cloneNode(true);
400                        document.getElementById('ea_input_searchMailList').value = '';
401                }
402        }       
403               
404        cExecute ('$this.ldap_functions.get_available_maillists&context='+context, handler_get_available_maillists);
405}
406       
407function add_user2maillist()
408{
409        select_available_maillists = document.getElementById('ea_select_available_maillists');
410        select_user_maillists = document.getElementById('ea_select_user_maillists');
411
412        for (i = 0 ; i < select_available_maillists.length ; i++)
413        {
414
415                if (select_available_maillists.options[i].selected)
416                {
417                        isSelected = false;
418                        for(var j = 0;j < select_user_maillists.options.length; j++)
419                        {
420                                if(select_user_maillists.options[j].value == select_available_maillists.options[i].value)
421                                {
422                                        isSelected = true;                                             
423                                        break; 
424                                }
425                        }
426
427                        if(!isSelected)
428                        {
429                                new_option = document.createElement('option');
430                                new_option.value =select_available_maillists.options[i].value;
431                                new_option.text = select_available_maillists.options[i].text;
432                                new_option.selected = true;
433                                       
434                                select_user_maillists.options[select_user_maillists.options.length] = new_option;
435                        }
436                }
437        }
438               
439        for (j =0; j < select_available_maillists.options.length; j++)
440                select_available_maillists.options[j].selected = false;
441}       
442       
443function remove_user2maillist()
444{
445        select_user_maillists = document.getElementById('ea_select_user_maillists');
446
447        for(var i = 0;i < select_user_maillists.options.length; i++)
448                if(select_user_maillists.options[i].selected)
449                        select_user_maillists.options[i--] = null;
450}
451       
452function sinc_combos_org(context)
453{
454        combo_org_groups = document.getElementById('ea_combo_org_groups');
455        combo_org_maillists = document.getElementById('ea_combo_org_maillists');
456
457        for (i=0; i<combo_org_groups.length; i++)
458        {
459                if (combo_org_groups.options[i].value == context)
460                {
461                        combo_org_groups.options[i].selected = true;
462                        combo_org_maillists.options[i].selected = true;
463                }
464        }
465}
466       
467function use_samba_attrs(value)
468{
469        if (value)
470        {
471                if (document.forms[0].sambalogonscript.value == '')
472                {
473                        if (document.forms[0].defaultLogonScript.value == '')
474                        {
475                                document.forms[0].sambalogonscript.value = document.forms[0].uid.value + '.bat';
476                        }
477                        else
478                        {
479                                document.forms[0].sambalogonscript.value = document.forms[0].defaultLogonScript.value;
480                        }
481                }
482                if (document.forms[0].sambahomedirectory.value == '')
483                {
484                        document.forms[0].sambahomedirectory.value = '/home/'+document.forms[0].uid.value+'/';
485                }
486        }
487       
488        if (!document.forms[0].use_attrs_samba.disabled)
489        {
490                document.forms[0].sambaacctflags.disabled = !value;
491                document.forms[0].sambadomain.disabled = !value;
492                document.forms[0].sambalogonscript.disabled = !value;
493                document.forms[0].sambahomedirectory.disabled = !value;
494        }
495}
496       
497function set_user_default_password()
498{
499        var handler_set_user_default_password = function(data)
500        {
501                if (!data.status)
502                        alert(data.msg);
503                else
504                {
505                        alert('Senha default cadastrada com êxito!!');
506                        //location.href="./index.php?menuaction=expressoAdmin1_2.uiaccounts.list_users";
507                }
508                return;
509        }
510        cExecute ('$this.user.set_user_default_password&uid='+document.forms[0].uid.value, handler_set_user_default_password); 
511}
512
513function return_user_password()
514{
515        var handler_return_user_password = function(data)
516        {
517                if (!data.status)
518                        alert(data.msg);
519                else
520                {
521                        alert('Senha do usuário retornado com êxito!!');
522                        //location.href="./index.php?menuaction=expressoAdmin1_2.uiaccounts.list_users";
523                }
524                return;
525        }
526        cExecute ('$this.user.return_user_password&uid='+document.forms[0].uid.value, handler_return_user_password);
527}
528
529function delete_user(uid, uidnumber, context)
530{
531        if (confirm("Realmente deletar usuário " + uid + " ??"))
532        {
533                var handler_delete_user = function(data)
534                {
535                        if (!data.status)
536                                alert(data.msg);
537                        else
538                                alert('Usuário deletado com êxito!!');
539                       
540                        location.href="./index.php?menuaction=expressoAdmin1_2.uiaccounts.list_users";
541                        return;
542                }
543                cExecute ('$this.user.delete&uidnumber='+uidnumber+'&context='+context, handler_delete_user);
544        }
545}
546
547function rename_user(uid, uidnumber, context)
548{
549
550        if (document.getElementById('accounts_form_imapDelimiter').value == '/')
551                var reUid = /^([a-zA-Z0-9_\.\-])+$/;
552        else
553                var reUid = /^([a-zA-Z0-9_\-])+$/;
554
555        new_uid = prompt("Alterar login do usuário " + uid + " para: ", uid);
556
557        if(!reUid.test(new_uid)){
558                alert('Campo LOGIN comtém caracteres não permitidos.');
559                document.forms[0].account_lid.focus();
560                return;
561        }
562       
563        if ((new_uid) && (new_uid != uid))
564        {
565                var handler_validate_fields = function(data)
566                {
567                        if (!data.status)
568                                alert(data.msg);
569                        else
570                                cExecute ('$this.user.rename&uid='+uid+'&new_uid='+new_uid+'&context='+context, handler_rename);
571                       
572                        return;
573                }
574               
575                // New uid exist?
576                attrs_array = new Array();
577                attrs_array['type'] = 'rename_user';
578                attrs_array['uid'] = new_uid;
579                attributes = connector.serialize(attrs_array);
580       
581                cExecute ('$this.ldap_functions.validate_fields&attributes='+attributes, handler_validate_fields);
582        }
583}
584
585// HANDLER RENAME
586function handler_rename(data)
587{
588        if (!data.status)
589                alert(data.msg);
590        else{
591                alert("Usuário renomeado com êxito!\n" + data.exec_return);
592                location.href="./index.php?menuaction=expressoAdmin1_2.uiaccounts.list_users";
593        }
594        return;
595
596}
597
598
599// Variaveis Locais
600var finderTimeout_maillist = '';
601
602// Funcoes Find MailList
603function optionFinderTimeout_maillist(obj)
604{
605        clearTimeout(finderTimeout_maillist);
606        var oWait = document.getElementById("ea_span_searching_maillist");
607        oWait.innerHTML = 'Buscando...';
608        finderTimeout_maillist = setTimeout("optionFinder_maillist('"+obj.id+"')",500);
609}
610function optionFinder_maillist(id) {   
611        var oWait = document.getElementById("ea_span_searching_maillist");
612        var oText = document.getElementById(id);
613               
614        //Limpa todo o select
615        for(var i = 0;i < select_available_maillists.options.length; i++)
616                select_available_maillists.options[i--] = null;
617       
618        var RegExp_name = new RegExp(oText.value, "i");
619       
620        //Inclui as listas começando com a pesquisa
621        for(i = 0; i < select_available_maillists_clone.length; i++){
622                if (RegExp_name.test(select_available_maillists_clone[i].text))
623                {
624                        sel = select_available_maillists.options;
625                        option = new Option(select_available_maillists_clone[i].text,select_available_maillists_clone[i].value);                               
626                        sel[sel.length] = option;
627                }
628        }
629        oWait.innerHTML = '&nbsp;';
630}                       
631
632// Variaveis Locais
633var finderTimeout_group = '';
634
635
636// Funcoes Find Group
637function optionFinderTimeout_group(obj)
638{
639        clearTimeout(finderTimeout_group);
640        var oWait = document.getElementById("ea_span_searching_group");
641        oWait.innerHTML = 'Buscando...';
642        finderTimeout_group = setTimeout("optionFinder_group('"+obj.id+"')",500);
643}
644function optionFinder_group(id) {       
645        var oWait = document.getElementById("ea_span_searching_group");
646        var oText = document.getElementById(id);
647               
648        //Limpa todo o select
649        for(var i = 0;i < select_available_groups.options.length; i++)
650                select_available_groups.options[i--] = null;
651       
652        var RegExp_name = new RegExp(oText.value, "i");
653       
654        //Inclui as listas começando com a pesquisa
655        for(i = 0; i < select_available_groups_clone.length; i++){
656                if (RegExp_name.test(select_available_groups_clone[i].text))
657                {
658                        sel = select_available_groups.options;
659                        option = new Option(select_available_groups_clone[i].text,select_available_groups_clone[i].value);                             
660                        sel[sel.length] = option;
661                }
662        }
663        oWait.innerHTML = '&nbsp;';
664}                       
Note: See TracBrowser for help on using the repository browser.