bug 782828
[phpmyadmin/crack.git] / libraries / server_privileges.js
bloba3aded4ed82e5be12ea20f3699d6c245b3cf61c2
1 /* $Id$ */
4 /**
5  * Validates the password field in a form
6  *
7  * @param   object   the form
8  *
9  * @return  boolean  whether the field value is valid or not
10  */
11 function checkPassword(the_form)
13     // Did the user select 'no password'?
14     if (typeof(the_form.elements['nopass']) != 'undefined' && the_form.elements['nopass'][0].checked) {
15         return true;
16     } else if (typeof(the_form.elements['pred_password']) != 'undefined' && (the_form.elements['pred_password'].value == 'none' || the_form.elements['pred_password'].value == 'keep')) {
17         return true;
18     }
20     // Validates
21     if (the_form.elements['pma_pw'].value == '') {
22         alert(jsPasswordEmpty);
23         the_form.elements['pma_pw2'].value = '';
24         the_form.elements['pma_pw'].focus();
25         return false;
26     } else if (the_form.elements['pma_pw'].value != the_form.elements['pma_pw2'].value) {
27         alert(jsPasswordNotSame);
28         the_form.elements['pma_pw'].value  = '';
29         the_form.elements['pma_pw2'].value = '';
30         the_form.elements['pma_pw'].focus();
31         return false;
32     } // end if...else if
34     return true;
35 } // end of the 'checkPassword()' function
38 /**
39  * Validates the "add a user" form
40  *
41  * @return  boolean  whether the form is validated or not
42  */
43 function checkAddUser(the_form)
45     if (the_form.elements['pred_hostname'].value == 'userdefined' && the_form.elements['hostname'].value == '') {
46         alert(jsHostEmpty);
47         the_form.elements['hostname'].focus();
48         return false;
49     }
51     if (the_form.elements['pred_username'].value == 'userdefined' && the_form.elements['username'].value == '') {
52         alert(jsUserEmpty);
53         the_form.elements['username'].focus();
54         return false;
55     }
57     return checkPassword(the_form);
58 } // end of the 'checkAddUser()' function
61 /**
62  * Checks/unchecks all checkboxes
63  *
64  * @param   string   the form name
65  * @param   atring   the name of the array with the checlboxes
66  * @param   boolean  whether to check or to uncheck the element
67  *
68  * @return  boolean  always true
69  */
70 function setCheckboxes(the_form, the_checkboxes, do_check)
72     var elts      = document.forms[the_form].elements[the_checkboxes + '[]'];
73     var elts_cnt  = (typeof(elts.length) != 'undefined')
74                   ? elts.length
75                   : 0;
77     if (elts_cnt) {
78         for (var i = 0; i < elts_cnt; i++) {
79             elts[i].checked = do_check;
80         } // end for
81     } else {
82         elts.checked        = do_check;
83     } // end if... else
85     return true;
86 } // end of the 'setCheckboxes()' function