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

Revision 2, 18.2 KB checked in by niltonneto, 17 years ago (diff)

Removida todas as tags usadas pelo CVS ($Id, $Source).
Primeira versão no CVS externo.

  • 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        document.forms[0].sambaacctflags.disabled = !value;
489        document.forms[0].sambalogonscript.disabled = !value;
490        document.forms[0].sambahomedirectory.disabled = !value;
491}
492       
493function set_user_default_password()
494{
495        var handler_set_user_default_password = function(data)
496        {
497                if (!data.status)
498                        alert(data.msg);
499                else
500                {
501                        alert('Senha default cadastrada com êxito!!');
502                        //location.href="./index.php?menuaction=expressoAdmin1_2.uiaccounts.list_users";
503                }
504                return;
505        }
506        cExecute ('$this.user.set_user_default_password&uid='+document.forms[0].uid.value, handler_set_user_default_password); 
507}
508
509function return_user_password()
510{
511        var handler_return_user_password = function(data)
512        {
513                if (!data.status)
514                        alert(data.msg);
515                else
516                {
517                        alert('Senha do usuário retornado com êxito!!');
518                        //location.href="./index.php?menuaction=expressoAdmin1_2.uiaccounts.list_users";
519                }
520                return;
521        }
522        cExecute ('$this.user.return_user_password&uid='+document.forms[0].uid.value, handler_return_user_password);
523}
524
525function delete_user(uid, uidnumber, context)
526{
527        if (confirm("Realmente deletar usuário " + uid + " ??"))
528        {
529                var handler_delete_user = function(data)
530                {
531                        if (!data.status)
532                                alert(data.msg);
533                        else
534                                alert('Usuário deletado com êxito!!');
535                       
536                        location.href="./index.php?menuaction=expressoAdmin1_2.uiaccounts.list_users";
537                        return;
538                }
539                cExecute ('$this.user.delete&uidnumber='+uidnumber+'&context='+context, handler_delete_user);
540        }
541}
542
543function rename_user(uid, uidnumber, context)
544{
545        new_uid = prompt("Alterar login do usuário " + uid + " para: ", uid);
546       
547        var reUid = /^([a-zA-Z0-9_\-])+$/;
548        if(!reUid.test(new_uid)){
549                alert('Campo LOGIN comtém caracteres não permitidos.');
550                document.forms[0].account_lid.focus();
551                return;
552        }
553       
554        if ((new_uid) && (new_uid != uid))
555        {
556                var handler_validate_fields = function(data)
557                {
558                        if (!data.status)
559                                alert(data.msg);
560                        else
561                                cExecute ('$this.user.rename&uid='+uid+'&new_uid='+new_uid+'&context='+context, handler_rename);
562                       
563                        return;
564                }
565               
566                // New uid exist?
567                attrs_array = new Array();
568                attrs_array['type'] = 'rename_user';
569                attrs_array['uid'] = new_uid;
570                attributes = connector.serialize(attrs_array);
571       
572                cExecute ('$this.ldap_functions.validate_fields&attributes='+attributes, handler_validate_fields);
573        }
574}
575
576// HANDLER RENAME
577function handler_rename(data)
578{
579        if (!data.status)
580                alert(data.msg);
581        else{
582                alert("Usuário renomeado com êxito!\n" + data.exec_return);
583                location.href="./index.php?menuaction=expressoAdmin1_2.uiaccounts.list_users";
584        }
585        return;
586
587}
588
589
590// Variaveis Locais
591var finderTimeout_maillist = '';
592
593// Funcoes Find MailList
594function optionFinderTimeout_maillist(obj)
595{
596        clearTimeout(finderTimeout_maillist);
597        var oWait = document.getElementById("ea_span_searching_maillist");
598        oWait.innerHTML = 'Buscando...';
599        finderTimeout_maillist = setTimeout("optionFinder_maillist('"+obj.id+"')",500);
600}
601function optionFinder_maillist(id) {   
602        var oWait = document.getElementById("ea_span_searching_maillist");
603        var oText = document.getElementById(id);
604               
605        //Limpa todo o select
606        for(var i = 0;i < select_available_maillists.options.length; i++)
607                select_available_maillists.options[i--] = null;
608       
609        var RegExp_name = new RegExp(oText.value, "i");
610       
611        //Inclui as listas começando com a pesquisa
612        for(i = 0; i < select_available_maillists_clone.length; i++){
613                if (RegExp_name.test(select_available_maillists_clone[i].text))
614                {
615                        sel = select_available_maillists.options;
616                        option = new Option(select_available_maillists_clone[i].text,select_available_maillists_clone[i].value);                               
617                        sel[sel.length] = option;
618                }
619        }
620        oWait.innerHTML = '&nbsp;';
621}                       
622
623// Variaveis Locais
624var finderTimeout_group = '';
625
626
627// Funcoes Find Group
628function optionFinderTimeout_group(obj)
629{
630        clearTimeout(finderTimeout_group);
631        var oWait = document.getElementById("ea_span_searching_group");
632        oWait.innerHTML = 'Buscando...';
633        finderTimeout_group = setTimeout("optionFinder_group('"+obj.id+"')",500);
634}
635function optionFinder_group(id) {       
636        var oWait = document.getElementById("ea_span_searching_group");
637        var oText = document.getElementById(id);
638               
639        //Limpa todo o select
640        for(var i = 0;i < select_available_groups.options.length; i++)
641                select_available_groups.options[i--] = null;
642       
643        var RegExp_name = new RegExp(oText.value, "i");
644       
645        //Inclui as listas começando com a pesquisa
646        for(i = 0; i < select_available_groups_clone.length; i++){
647                if (RegExp_name.test(select_available_groups_clone[i].text))
648                {
649                        sel = select_available_groups.options;
650                        option = new Option(select_available_groups_clone[i].text,select_available_groups_clone[i].value);                             
651                        sel[sel.length] = option;
652                }
653        }
654        oWait.innerHTML = '&nbsp;';
655}                       
Note: See TracBrowser for help on using the repository browser.