source: companies/serpro/expressoAdmin1_2/js/jscode/users.js @ 903

Revision 903, 18.6 KB checked in by niltonneto, 15 years ago (diff)

Importacao inicial do Expresso do Serpro

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