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

Revision 2860, 22.9 KB checked in by niltonneto, 14 years ago (diff)

Ticket #1090 - Correção de falha não validada no ticket #1052.

  • 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               
9                if (document.forms[0].uid.value == ''){
10                        alert( ExpressoLivre.translate( 'LOGIN field is empty' )  + '.');
11                        return;
12                }
13                else if (document.forms[0].uid.value.length < document.forms[0].minimumSizeLogin.value){
14                        alert( ExpressoLivre.translate( 'LOGIN field must be bigger than' )  + ' ' + document.forms[0].minimumSizeLogin.value + ' ' +  ExpressoLivre.translate( 'characters' )  + '.');
15                        return;
16                }
17               
18                // Verifica se o delimitador do Cyrus permite ponto (dot.) nas mailboxes;
19                if (document.forms[0].imapDelimiter.value == '/')
20                        var reUid = /^([a-zA-Z0-9_\.\-])+$/;
21                else
22                        var reUid = /^([a-zA-Z0-9_\-])+$/;
23                if(!reUid.test(document.forms[0].uid.value)){
24                        alert( ExpressoLivre.translate( 'LOGIN field contains characters not allowed' )  + '.');
25                        return;
26                }
27       
28                //PASSWORD's
29                if (document.forms[0].password1.value == ''){
30                        alert( ExpressoLivre.translate( 'Password field is empty' )  + '.');
31                        return;
32                }
33                if (document.forms[0].password2.value == ''){
34                        alert( ExpressoLivre.translate( 'repassword field is empty' )  + '.');
35                        return;
36                }
37        }
38
39        if (document.forms[0].password1.value != document.forms[0].password2.value){
40                alert( ExpressoLivre.translate( 'password and repassword are different' )  + '.');
41                return;
42        }
43
44        // Corporative Information
45        if (document.forms[0].corporative_information_employeenumber.value != "")
46        {
47                var re_employeenumber = /^([0-9])+$/;
48               
49                if(!re_employeenumber.test(document.forms[0].corporative_information_employeenumber.value))
50                {
51                        alert( ExpressoLivre.translate( 'EmployeeNumber contains characters not allowed' )  + '. ' +  ExpressoLivre.translate( 'Only numbers are allowed' )  + '.');
52                        document.forms[0].corporative_information_employeenumber.focus();
53                        return;
54                }
55        }
56
57        //MAIL
58        document.forms[0].mail.value = document.forms[0].mail.value.toLowerCase();
59        if (document.forms[0].mail.value == ''){
60                alert( ExpressoLivre.translate( 'Email field is empty' )  + '.');
61                return;
62        }
63        var reEmail = /^([a-zA-Z0-9_\-])+(\.[a-zA-Z0-9_\-]+)*\@([a-zA-Z0-9_\-])+(\.[a-zA-Z0-9_\-]+)*$/;
64        if(!reEmail.test(document.forms[0].mail.value)){
65                alert( ExpressoLivre.translate( 'Email field is not valid' )  + '.');
66                return false;
67        }
68       
69        //FIRSTNAME
70        var reGivenname = /^[a-zA-Z0-9 \-\.]+$/;
71        if(!reGivenname.test(document.forms[0].givenname.value)){
72                alert( ExpressoLivre.translate( 'First name field contains characters not allowed' )  + '.');
73                return false;
74        }
75        else if (document.forms[0].givenname.value == ''){
76                alert( ExpressoLivre.translate( 'First name field is empty' )  + '.');
77                return;
78        }
79       
80        //LASTNAME
81        var reSn = /^[a-zA-Z0-9 \-\.]+$/;
82        if(!reSn.test(document.forms[0].sn.value)){
83                alert( ExpressoLivre.translate( 'Last name field contains characters not allowed' )  + '.');
84                return false;
85        }
86        else if (document.forms[0].sn.value == ''){
87                alert( ExpressoLivre.translate( 'Last name field is empty' )  + '.');
88                return;
89        }
90       
91        //TELEPHONENUMBER
92        if (document.forms[0].telephonenumber.value != '')
93        {
94                reg_tel = /\(\d{2}\)\d{4}-\d{4}$/;
95                if (!reg_tel.exec(document.forms[0].telephonenumber.value))
96                {
97                        alert( ExpressoLivre.translate( 'Phone field is incorrect' )  + '.');
98                        return;
99                }
100        }
101       
102        //FORWAR ONLY
103        if ((document.forms[0].deliverymode.checked) && (document.forms[0].mailforwardingaddress.value == '')){
104                alert( ExpressoLivre.translate( 'Forward email is empty' )  + '.');
105                return;
106        }
107       
108        // Email Quota
109        if (document.forms[0].mailquota.value == ''){
110                alert( ExpressoLivre.translate( 'User without email quota' )  + '.');
111                return;
112        }
113       
114        //GROUPS
115        if (document.getElementById('ea_select_user_groups').length < 1){
116                alert( ExpressoLivre.translate( 'User is not in any group' )  + '.');
117                return;
118        }
119
120        //SAMBA
121        if (document.getElementById('tabcontent6').style.display != 'none'){
122                if ((document.forms[0].sambalogonscript.value == '') && (!document.forms[0].sambalogonscript.disabled)){
123                        alert( ExpressoLivre.translate( 'Logon script is empty' )  + '.');
124                        return;
125                }
126                if ((document.forms[0].sambahomedirectory.value == '') && (!document.forms[0].sambahomedirectory.disabled)){
127                        alert( ExpressoLivre.translate( 'Users home directory is empty' )  + '.');
128                        return;
129                }
130        }
131
132        // Uid, Mail and CPF exist?
133        var attrs_array = new Array();
134        attrs_array['type'] = type;
135        attrs_array['uid'] = document.forms[0].uid.value;
136        attrs_array['mail'] = document.forms[0].mail.value;
137        attrs_array['cpf'] = document.forms[0].corporative_information_cpf.value;
138       
139        if (document.forms[0].mailalternateaddress.value != '')
140                attrs_array['mailalternateaddress'] = document.forms[0].mailalternateaddress.value;
141        var attributes = connector.serialize(attrs_array);
142
143        var handler_validate_fields = function(data)
144        {
145                if (!data.status)
146                {
147                        alert(data.msg);
148                }
149                else
150                {
151                        if ( (data.question) && (!confirm(data.question)) )
152                        {
153                                return false;
154                        }
155                       
156                        if (type == 'create_user')
157                        {       // Turn enabled checkbox before create user.
158                                document.getElementById('changepassword').disabled = false;
159                                cExecuteForm ("$this.user.create", document.forms[0], handler_create);
160                        }
161                        else
162                        {
163                                //Turn enabled all checkboxes and inputs
164                                document.getElementById('changepassword').disabled = false;
165                                document.getElementById('phpgwaccountstatus').disabled = false;
166                                document.getElementById('phpgwaccountvisible').disabled = false;
167                                document.getElementById('telephonenumber').disabled = false;
168                                document.getElementById('mailforwardingaddress').disabled = false;
169                                document.getElementById('mailalternateaddress').disabled = false;
170                                document.getElementById('passwd_expired').disabled = false;
171                                document.getElementById('accountstatus').disabled = false;
172                                document.getElementById('deliverymode').disabled = false;
173                                document.getElementById('use_attrs_samba').disabled = false;
174                               
175                                table_apps = document.getElementById('ea_table_apps');
176                                var inputs = table_apps.getElementsByTagName("input");
177                                for (var i = 0; i < inputs.length; i++)
178                                {
179                                        inputs[i].disabled = false;
180                                }
181                                cExecuteForm ("$this.user.save", document.forms[0], handler_save);
182                        }
183                }
184        }
185       
186        // Needed select all options from select
187        select_user_maillists = document.getElementById('ea_select_user_maillists');
188        select_user_groups = document.getElementById('ea_select_user_groups');
189        for(var i=0; i<select_user_maillists.options.length; i++)
190                select_user_maillists.options[i].selected = true;
191        for(var i=0; i<select_user_groups.options.length; i++)
192                select_user_groups.options[i].selected = true;
193        /////////////////////////////////////////////////////////////////////////////////////////////////////////
194        document.getElementById('uid').disabled = false; //Caso o login seja gerado automático, tirar o disabled.
195        cExecute ('$this.ldap_functions.validate_fields&attributes='+attributes, handler_validate_fields);
196}
197
198function generate_login(first_name,second_name) {
199        if ((first_name=='') || (second_name=='')) {
200                alert( ExpressoLivre.translate( "You must type the first and the second name before generate the login" ) );
201                return;
202        }
203        var attrs_array = new Array();
204        attrs_array['first_name'] = first_name;
205        attrs_array['second_name'] = second_name;
206        var attributes = connector.serialize(attrs_array);
207       
208        var handler_generate_login = function(data) {
209                if(data['status']) {
210                        document.getElementById('uid').value = data['msg'];
211                        emailSuggestion_expressoadmin('true','true');
212                        document.getElementById("mail").value=document.getElementById("mail1").value;
213                }
214                else
215                        alert(data['msg']);
216        }
217
218        cExecute ('$this.ldap_functions.generate_login&attributes='+attributes, handler_generate_login);
219}
220
221// HANDLER CREATE
222// É necessário 2 funcões de retorno por causa do cExecuteForm.
223function handler_create(data)
224{
225        return_handler_create(data);
226}
227function return_handler_create(data)
228{
229        if (!data.status)
230                alert(data.msg);
231        else
232                alert( ExpressoLivre.translate( 'User successful created' )  + '.');
233
234        location.href="./index.php?menuaction=expressoAdmin1_2.uiaccounts.list_users";
235        return;
236}
237
238
239// HANDLER SAVE
240// É necessário 2 funcões de retorno por causa do cExecuteForm.
241function handler_save(data)
242{
243        return_handler_save(data);
244}
245function return_handler_save(data)
246{
247        if (!data.status){
248                alert(data.msg);
249        }
250        else{
251                alert( ExpressoLivre.translate( 'User successful saved' )  + '.');
252        }
253        location.href="./index.php?menuaction=expressoAdmin1_2.uiaccounts.list_users";
254        return;
255}
256
257function get_available_groups(context)
258{
259        var handler_get_available_groups = function(data)
260        {
261                data = data.trim( );
262                select_available_groups = document.getElementById('ea_select_available_groups');
263
264                if ((data) && (data.length > 0))
265                {
266                        // Necessario, pois o IE6 tem um bug que retira o primeiro options se o innerHTML estiver vazio.
267                        select_available_groups.innerHTML = '#' + data;
268                        select_available_groups.outerHTML = select_available_groups.outerHTML;
269                        select_available_groups_clone = select_available_groups.cloneNode(true);
270                        document.getElementById('ea_input_searchGroup').value = '';
271                }
272                else
273                {
274                        // Necessario, pois o IE6 tem um bug que retira o primeiro options se o innerHTML estiver vazio.
275                        select_available_groups.innerHTML = '#';
276                        select_available_groups.outerHTML = select_available_groups.outerHTML;
277                }
278        }
279
280        ExpressoLivre.go( {
281                "access" : "expressoAdmin1_2.ldap_functions.get_available_groups&context="+escape(context),
282                "handler" : handler_get_available_groups
283        } );
284}
285       
286function add_user2group()
287{
288        select_available_groups = document.getElementById('ea_select_available_groups');
289        select_user_groups = document.getElementById('ea_select_user_groups');
290        combo_primary_user_group = document.getElementById('ea_combo_primary_user_group');
291
292        for (i = 0 ; i < select_available_groups.length ; i++)
293        {
294                if (select_available_groups.options[i].selected)
295                {
296                        isSelected = false;
297                        for(var j = 0;j < select_user_groups.options.length; j++)
298                        {
299                                if(select_user_groups.options[j].value == select_available_groups.options[i].value)
300                                {
301                                        isSelected = true;                                             
302                                        break; 
303                                }
304                        }
305
306                        if(!isSelected)
307                        {
308                                new_option1 = document.createElement('option');
309                                new_option1.value =select_available_groups.options[i].value;
310                                new_option1.text = select_available_groups.options[i].text;
311                                new_option1.selected = true;
312                                select_user_groups.options[select_user_groups.options.length] = new_option1;
313                               
314                                new_option2 = document.createElement('option');
315                                new_option2.value =select_available_groups.options[i].value;
316                                new_option2.text = select_available_groups.options[i].text;
317                                combo_primary_user_group.options[combo_primary_user_group.options.length] = new_option2;
318                        }
319                }
320        }
321               
322        for (j =0; j < select_available_groups.options.length; j++)
323                select_available_groups.options[j].selected = false;
324}       
325       
326function remove_user2group()
327{
328        select_user_groups = document.getElementById('ea_select_user_groups');
329        combo_primary_user_group = document.getElementById('ea_combo_primary_user_group');
330       
331        var x;
332        var j=0;
333        var to_remove = new Array();
334       
335        for(var i = 0;i < select_user_groups.options.length; i++)
336        {
337                if(select_user_groups.options[i].selected)
338                {
339                        to_remove[j] = select_user_groups.options[i].value;
340                        j++;
341                        select_user_groups.options[i--] = null;
342                }
343        }
344       
345        for (x in to_remove)
346        {
347                for(var i=0; i<combo_primary_user_group.options.length; i++)
348                {
349                        if (combo_primary_user_group.options[i].value == to_remove[x])
350                        {
351                                combo_primary_user_group.options[i] = null;
352                        }       
353                }
354        }
355}
356       
357function get_available_maillists(context)
358{
359        var handler_get_available_maillists = function(data)
360        {
361                select_available_maillists = document.getElementById('ea_select_available_maillists');
362
363                if ((data) && (data.length > 0))
364                {
365                        // Necessario, pois o IE6 tem um bug que retira o primeiro options se o innerHTML estiver vazio.
366                        select_available_maillists.innerHTML = '#' + data;
367                        select_available_maillists.outerHTML = select_available_maillists.outerHTML;
368                        select_available_maillists_clone = select_available_maillists.cloneNode(true);
369                        document.getElementById('ea_input_searchMailList').value = '';
370                }
371                else
372                {
373                        // Necessario, pois o IE6 tem um bug que retira o primeiro options se o innerHTML estiver vazio.
374                        select_available_maillists.innerHTML = '#';
375                        select_available_maillists.outerHTML = select_available_maillists.outerHTML;
376                }
377        }
378        ExpressoLivre.go( {
379                "access" : "expressoAdmin1_2.ldap_functions.get_available_maillists&context=" + context,
380                "handler" : handler_get_available_maillists
381        } );
382}
383       
384function add_user2maillist()
385{
386        select_available_maillists = document.getElementById('ea_select_available_maillists');
387        select_user_maillists = document.getElementById('ea_select_user_maillists');
388
389        for (i = 0 ; i < select_available_maillists.length ; i++)
390        {
391
392                if (select_available_maillists.options[i].selected)
393                {
394                        isSelected = false;
395                        for(var j = 0;j < select_user_maillists.options.length; j++)
396                        {
397                                if(select_user_maillists.options[j].value == select_available_maillists.options[i].value)
398                                {
399                                        isSelected = true;                                             
400                                        break; 
401                                }
402                        }
403
404                        if(!isSelected)
405                        {
406                                new_option = document.createElement('option');
407                                new_option.value =select_available_maillists.options[i].value;
408                                new_option.text = select_available_maillists.options[i].text;
409                                new_option.selected = true;
410                                       
411                                select_user_maillists.options[select_user_maillists.options.length] = new_option;
412                        }
413                }
414        }
415               
416        for (j =0; j < select_available_maillists.options.length; j++)
417                select_available_maillists.options[j].selected = false;
418}       
419       
420function remove_user2maillist()
421{
422        select_user_maillists = document.getElementById('ea_select_user_maillists');
423
424        for(var i = 0;i < select_user_maillists.options.length; i++)
425                if(select_user_maillists.options[i].selected)
426                        select_user_maillists.options[i--] = null;
427}
428       
429function sinc_combos_org(context)
430{
431        combo_org_groups = document.getElementById('ea_combo_org_groups');
432        combo_org_maillists = document.getElementById('ea_combo_org_maillists');
433
434        for (i=0; i<combo_org_groups.length; i++)
435        {
436                if (combo_org_groups.options[i].value == context)
437                {
438                        combo_org_groups.options[i].selected = true;
439                        combo_org_maillists.options[i].selected = true;
440                }
441        }
442}
443       
444function use_samba_attrs(value)
445{
446        if (value)
447        {
448                if (document.forms[0].sambalogonscript.value == '')
449                {
450                        if (document.forms[0].defaultLogonScript.value == '')
451                        {
452                                document.forms[0].sambalogonscript.value = document.forms[0].uid.value + '.bat';
453                        }
454                        else
455                        {
456                                document.forms[0].sambalogonscript.value = document.forms[0].defaultLogonScript.value;
457                        }
458                }
459                if (document.forms[0].sambahomedirectory.value == '')
460                {
461                        document.forms[0].sambahomedirectory.value = '/home/'+document.forms[0].uid.value+'/';
462                }
463        }
464       
465        if (!document.forms[0].use_attrs_samba.disabled)
466        {
467                document.forms[0].sambaacctflags.disabled = !value;
468                document.forms[0].sambadomain.disabled = !value;
469                document.forms[0].sambalogonscript.disabled = !value;
470                document.forms[0].sambahomedirectory.disabled = !value;
471        }
472}
473       
474function set_user_default_password()
475{
476        var handler_set_user_default_password = function(data)
477        {
478                if (!data.status)
479                        alert(data.msg);
480                else
481                        alert( ExpressoLivre.translate( 'Default password successful saved' )  + '.');
482                return;
483        }
484        cExecute ('$this.user.set_user_default_password&uid='+document.forms[0].uid.value, handler_set_user_default_password); 
485}
486
487function return_user_password()
488{
489        var handler_return_user_password = function(data)
490        {
491                if (!data.status)
492                        alert(data.msg);
493                else
494                        alert( ExpressoLivre.translate( 'Users password successful returned' )  + '.');
495                return;
496        }
497        cExecute ('$this.user.return_user_password&uid='+document.forms[0].uid.value, handler_return_user_password);
498}
499
500function delete_user(uid, uidnumber)
501{
502        if (confirm( ExpressoLivre.translate( "Do you really want delete the user" )  + " " + uid + "?"))
503        {
504                var handler_delete_user = function(data)
505                {
506                        if (!data.status)
507                                alert(data.msg);
508                        else
509                                alert( ExpressoLivre.translate( 'User successful deleted' )  + '.');
510                       
511                        location.href="./index.php?menuaction=expressoAdmin1_2.uiaccounts.list_users";
512                        return;
513                }
514                cExecute ('$this.user.delete&uidnumber='+uidnumber+'&uid='+uid, handler_delete_user);
515        }
516}
517
518function rename_user(uid, uidnumber)
519{
520        if (document.getElementById('accounts_form_imapDelimiter').value == '/')
521                var reUid = /^([a-zA-Z0-9_\.\-])+$/;
522        else
523                var reUid = /^([a-zA-Z0-9_\-])+$/;
524
525        new_uid = prompt( ExpressoLivre.translate( 'Rename users login from' )  + ': ' + uid + " " +  ExpressoLivre.translate( "to" )  + ': ', uid);
526
527        if(!reUid.test(new_uid)){
528                alert( ExpressoLivre.translate( 'LOGIN field contains characters not allowed' )  + '.');
529                document.forms[0].account_lid.focus();
530                return;
531        }
532       
533        if ((new_uid) && (new_uid != uid))
534        {
535                var handler_validate_fields = function(data)
536                {
537                        if (!data.status)
538                                alert(data.msg);
539                        else
540                                cExecute ('$this.user.rename&uid='+uid+'&new_uid='+new_uid, handler_rename);
541                       
542                        return;
543                }
544               
545                // New uid exist?
546                attrs_array = new Array();
547                attrs_array['type'] = 'rename_user';
548                attrs_array['uid'] = new_uid;
549                attributes = connector.serialize(attrs_array);
550       
551                cExecute ('$this.ldap_functions.validate_fields&attributes='+attributes, handler_validate_fields);
552        }
553}
554
555// HANDLER RENAME
556function handler_rename(data)
557{
558        if (!data.status)
559                alert(data.msg);
560        else{
561                alert( ExpressoLivre.translate( 'User login successful renamed' )  + "\n" + data.exec_return);
562                location.href="./index.php?menuaction=expressoAdmin1_2.uiaccounts.list_users";
563        }
564        return;
565
566}
567
568
569// Variaveis Locais
570var finderTimeout_maillist = '';
571
572// Funcoes Find MailList
573function optionFinderTimeout_maillist(obj)
574{
575        clearTimeout(finderTimeout_maillist);
576        var oWait = document.getElementById("ea_span_searching_maillist");
577        oWait.innerHTML =  ExpressoLivre.translate( 'Searching' )  + '...';
578        finderTimeout_maillist = setTimeout("optionFinder_maillist('"+obj.id+"')",500);
579}
580function optionFinder_maillist(id) {
581        var oWait = document.getElementById("ea_span_searching_maillist");
582        var oText = document.getElementById(id);
583               
584        //Limpa todo o select
585        for(var i = 0;i < select_available_maillists.options.length; i++)
586                select_available_maillists.options[i--] = null;
587       
588        var RegExp_name = new RegExp(oText.value, "i");
589       
590        //Inclui as listas começando com a pesquisa
591        for(i = 0; i < select_available_maillists_clone.length; i++){
592                if (RegExp_name.test(select_available_maillists_clone[i].text))
593                {
594                        sel = select_available_maillists.options;
595                        option = new Option(select_available_maillists_clone[i].text,select_available_maillists_clone[i].value);                               
596                        sel[sel.length] = option;
597                }
598        }
599        oWait.innerHTML = '&nbsp;';
600}                       
601
602// Variaveis Locais
603var finderTimeout_group = '';
604
605
606// Funcoes Find Group
607function optionFinderTimeout_group(obj)
608{
609        clearTimeout(finderTimeout_group);
610        var oWait = document.getElementById("ea_span_searching_group");
611        oWait.innerHTML =  ExpressoLivre.translate( 'Searching' )  + '...';
612        finderTimeout_group = setTimeout("optionFinder_group('"+obj.id+"')",500);
613}
614function optionFinder_group(id) {       
615        var oWait = document.getElementById("ea_span_searching_group");
616        var oText = document.getElementById(id);
617               
618        //Limpa todo o select
619        for(var i = 0;i < select_available_groups.options.length; i++)
620                select_available_groups.options[i--] = null;
621       
622        var RegExp_name = new RegExp(oText.value, "i");
623       
624        //Inclui as listas começando com a pesquisa
625        for(i = 0; i < select_available_groups_clone.length; i++){
626                if (RegExp_name.test(select_available_groups_clone[i].text))
627                {
628                        sel = select_available_groups.options;
629                        option = new Option(select_available_groups_clone[i].text,select_available_groups_clone[i].value);                             
630                        sel[sel.length] = option;
631                }
632        }
633        oWait.innerHTML = '&nbsp;';
634}
635
636function get_available_sambadomains(context, type)
637{
638        if ((type == 'create_user') && (document.getElementById('tabcontent7').style.display != 'none'))
639        {
640                var handler_get_available_sambadomains = function(data)
641                {
642                        document.forms[0].use_attrs_samba.checked = data.status;
643                        use_samba_attrs(data.status);
644                       
645                        if (data.status)
646                        {
647                                combo_sambadomains = document.getElementById('ea_combo_sambadomains');
648                                for (i=0; i<data.sambaDomains.length; i++)
649                                {
650                                        for (j=0; j<combo_sambadomains.length; j++)
651                                        {
652                                                if (combo_sambadomains.options[j].text == data.sambaDomains[i])
653                                                {
654                                                        combo_sambadomains.options[j].selected = true;
655                                                        break;
656                                                }
657                                        }
658                                }
659                               
660                        }
661                }
662               
663                cExecute ('$this.ldap_functions.exist_sambadomains_in_context&context='+context, handler_get_available_sambadomains);
664        }
665}
666
667function empty_inbox(uid)
668{
669        var action =  ExpressoLivre.translate( 'Cleanned user mailbox' ) ;
670        var handler_write_log = function(){}
671        var handler_empty_inbox = function(data)
672        {
673                if (!data.status)
674                        alert(data.msg);
675                else{
676                        cExecute ('$this.user.write_log_from_ajax&_action='+action+'&userinfo='+uid, handler_write_log);
677                        alert( ExpressoLivre.translate( 'Emptied' ) +' '+ data.inbox_size + ' ' +  ExpressoLivre.translate( 'MB from user inbox' ) );
678                        document.getElementById('mailquota_used').value = data.mailquota_used;
679                }
680        }
681        cExecute ('$this.imap_functions.empty_user_inbox&uid='+uid, handler_empty_inbox);
682}
683
684function validarCPF(cpf)
685{
686        if(cpf.length != 11 || cpf == "00000000000" || cpf == "11111111111" ||
687                cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" ||
688                cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" ||
689                cpf == "88888888888" || cpf == "99999999999"){
690          return false;
691   }
692
693        soma = 0;
694        for(i = 0; i < 9; i++)
695                soma += parseInt(cpf.charAt(i)) * (10 - i);
696        resto = 11 - (soma % 11);
697        if(resto == 10 || resto == 11)
698                resto = 0;
699        if(resto != parseInt(cpf.charAt(9)))
700        {
701                return false;
702        }
703       
704        soma = 0;
705        for(i = 0; i < 10; i ++)
706                soma += parseInt(cpf.charAt(i)) * (11 - i);
707        resto = 11 - (soma % 11);
708        if(resto == 10 || resto == 11)
709                resto = 0;
710        if(resto != parseInt(cpf.charAt(10))){
711                return false;
712        }
713        return true;
714}
715
716function search_organization(key, element)
717{
718        var organizations = document.getElementById(element);
719        var RegExp_org = new RegExp("\\b"+key, "i");
720       
721        for(i = 0; i < organizations.length; i++)
722        {
723                if (RegExp_org.test(organizations[i].text))
724                {
725                        organizations[i].selected = true;
726                        return;
727                }
728        }
729}
730
731function add_input_mailalternateaddress()
732{
733        var input = document.createElement("INPUT");
734        input.size = 30;
735        input.name = "mailalternateaddress[]";
736        input.setAttribute("autocomplete","off");
737        document.getElementById("td_input_mailalternateaddress").appendChild(document.createElement("br"));
738        document.getElementById("td_input_mailalternateaddress").appendChild(input);
739}
740
741function add_input_mailforwardingaddress()
742{
743        var input = document.createElement("INPUT");
744        input.size = 30;
745        input.name = "mailforwardingaddress[]";
746        input.setAttribute("autocomplete","off");
747        document.getElementById("td_input_mailforwardingaddress").appendChild(document.createElement("br"));
748        document.getElementById("td_input_mailforwardingaddress").appendChild(input);
749}
750
751function set_changepassword()
752{
753        if (document.getElementById('passwd_expired').checked)
754                {
755                document.getElementById('changepassword').checked = true;
756                document.getElementById('changepassword').disabled = true;
757                }
758                else
759                {
760                document.getElementById('changepassword').disabled =false;
761                }
762}
Note: See TracBrowser for help on using the repository browser.