Fix for the Open in New Window in Patient/Client->Patients search gui, take 2.
[openemr.git] / phpmyadmin / js / server_privileges.js
blobe4ea4680789a0d3414de8b949bb4aa5e2a4fcdfe
1 /* vim: set expandtab sw=4 ts=4 sts=4: */
2 /**
3  * function used in server privilege pages
4  *
5  * @version $Id$
6  */
8 /**
9  * Validates the password field in a form
10  *
11  * @param   object   the form
12  *
13  * @return  boolean  whether the field value is valid or not
14  */
15 function checkPassword(the_form)
17     // Did the user select 'no password'?
18     if (typeof(the_form.elements['nopass']) != 'undefined' && the_form.elements['nopass'][0].checked) {
19         return true;
20     } else if (typeof(the_form.elements['pred_password']) != 'undefined' && (the_form.elements['pred_password'].value == 'none' || the_form.elements['pred_password'].value == 'keep')) {
21         return true;
22     }
24     // Validates
25     if (the_form.elements['pma_pw'].value == '') {
26         alert(jsPasswordEmpty);
27         the_form.elements['pma_pw2'].value = '';
28         the_form.elements['pma_pw'].focus();
29         return false;
30     } else if (the_form.elements['pma_pw'].value != the_form.elements['pma_pw2'].value) {
31         alert(jsPasswordNotSame);
32         the_form.elements['pma_pw'].value  = '';
33         the_form.elements['pma_pw2'].value = '';
34         the_form.elements['pma_pw'].focus();
35         return false;
36     } // end if...else if
38     return true;
39 } // end of the 'checkPassword()' function
42 /**
43  * Validates the "add a user" form
44  *
45  * @return  boolean  whether the form is validated or not
46  */
47 function checkAddUser(the_form)
49     if (the_form.elements['pred_hostname'].value == 'userdefined' && the_form.elements['hostname'].value == '') {
50         alert(jsHostEmpty);
51         the_form.elements['hostname'].focus();
52         return false;
53     }
55     if (the_form.elements['pred_username'].value == 'userdefined' && the_form.elements['username'].value == '') {
56         alert(jsUserEmpty);
57         the_form.elements['username'].focus();
58         return false;
59     }
61     return checkPassword(the_form);
62 } // end of the 'checkAddUser()' function
65 /**
66  * Generate a new password, which may then be copied to the form
67  * with suggestPasswordCopy().
68  *
69  * @param   string   the form name
70  *
71  * @return  boolean  always true
72  */
73 function suggestPassword() {
74     // restrict the password to just letters and numbers to avoid problems:
75     // "editors and viewers regard the password as multiple words and
76     // things like double click no longer work"
77     var pwchars = "abcdefhjmnpqrstuvwxyz23456789ABCDEFGHJKLMNPQRSTUVWYXZ";
78     var passwordlength = 16;    // do we want that to be dynamic?  no, keep it simple :)
79     var passwd = document.getElementById('generated_pw');
80     passwd.value = '';
82     for ( i = 0; i < passwordlength; i++ ) {
83         passwd.value += pwchars.charAt( Math.floor( Math.random() * pwchars.length ) )
84     }
85     return passwd.value;
89 /**
90  * Copy the generated password (or anything in the field) to the form
91  *
92  * @param   string   the form name
93  *
94  * @return  boolean  always true
95  */
96 function suggestPasswordCopy() {
97     document.getElementById('text_pma_pw').value = document.getElementById('generated_pw').value;
98     document.getElementById('text_pma_pw2').value = document.getElementById('generated_pw').value;
99     return true;