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

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