5 * Validates the password field in a form
7 * @param object the form
9 * @return boolean whether the field value is valid or not
11 function checkPassword(the_form)
13 // Gets the elements pointers
14 if (the_form.name == 'addUserForm' || the_form.name == 'chgPassword') {
16 var pswd1_name = 'pma_pw';
17 var pswd2_name = 'pma_pw2';
20 pswd1_name = 'new_pw';
21 pswd2_name = 'new_pw2';
25 if (the_form.elements['nopass'][pswd_index].checked) {
26 if (the_form.elements[pswd1_name].value == '') {
27 alert(jsPasswordEmpty);
28 the_form.elements[pswd2_name].value = '';
29 the_form.elements[pswd1_name].focus();
31 } else if (the_form.elements[pswd1_name].value != the_form.elements[pswd2_name].value) {
32 alert(jsPasswordNotSame);
33 the_form.elements[pswd1_name].value = '';
34 the_form.elements[pswd2_name].value = '';
35 the_form.elements[pswd1_name].focus();
41 } // end of the 'checkPassword()' function
45 * Validates the "add an user" form
47 * @return boolean whether the form is validated or not
49 function checkAddUser()
51 var the_form = document.forms['addUserForm'];
53 if (the_form.elements['anyhost'][1].checked && the_form.elements['host'].value == '') {
55 the_form.elements['host'].focus();
59 if (the_form.elements['anyuser'][1].checked && the_form.elements['pma_user'].value == '') {
61 the_form.elements['pma_user'].focus();
65 return checkPassword(the_form);
66 } // end of the 'checkAddUser()' function
70 * Validates the "update a profile" form
72 * @return boolean whether the form is validated or not
74 function checkUpdProfile()
76 var the_form = document.forms['updUserForm'];
78 if (the_form.elements['anyhost'][1].checked && the_form.elements['new_server'].value == '') {
80 the_form.elements['new_server'].focus();
84 if (the_form.elements['anyuser'][1].checked && the_form.elements['new_user'].value == '') {
86 the_form.elements['new_user'].focus();
90 return checkPassword(the_form);
91 } // end of the 'checkUpdProfile()' function
95 * Gets the list of selected options in combo
97 * @param object the form to check
99 * @return string the list of selected options
101 function getSelected(the_field) {
103 var opts = the_field.options;
104 var opts_cnt = opts.length;
106 for (var i = 0; i < opts_cnt; i++) {
107 if (opts[i].selected) {
108 the_list += opts[i].text + ', ';
112 return the_list.substring(0, the_list.length - 2);
113 } // end of the 'getSelected()' function
117 * Reloads the page to get tables names in a database or fields names in a
120 * @param object the input text box to build the query from
122 function change(the_field) {
123 var l = location.href;
124 var lpos = l.indexOf('?lang');
125 var box_name = the_field.name;
126 var the_form = the_field.form.elements;
129 if (box_name == 'newdb') {
130 the_form['anydb'][0].checked = true;
131 the_form['anytable'][0].checked = true;
132 the_form['anycolumn'][0].checked = true;
133 if (typeof(the_form['dbgrant']) != 'undefined') {
134 the_form['dbgrant'].selectedIndex = -1;
136 if (typeof(the_form['tablegrant']) != 'undefined') {
137 the_form['tablegrant'].selectedIndex = -1;
139 if (typeof(the_form['colgrant']) != 'undefined') {
140 the_form['colgrant'].selectedIndex = -1;
145 l += '?lang=' + the_form['lang'].value
146 + '&convcharset=' . the_form['convcharset'].value
147 + '&server=' + the_form['server'].value
149 + '&host=' + escape(the_form['host'].value)
150 + '&pma_user=' + escape(the_form['pma_user'].value);
151 sel_idx = the_form['dbgrant'].selectedIndex;
153 l += '&dbgrant=' + escape(the_form['dbgrant'].options[sel_idx].text);
155 sel_idx = the_form['tablegrant'].selectedIndex;
157 l += '&tablegrant=' + escape(the_form['tablegrant'].options[sel_idx].text);
161 var lpos = l.indexOf('&' + box_name);
163 l = l.substring(0, lpos);
166 location.href = l + '&' + box_name + '=' + escape(getSelected(the_field));
169 } // end of the 'change()' function
173 * Checks/unchecks all privileges
175 * @param string the form name
176 * @param boolean whether to check or to uncheck the element
178 * @return boolean always true
180 function checkForm(the_form, do_check) {
181 var elts = document.forms[the_form].elements;
182 var elts_cnt = elts.length;
184 for (var i = 0; i < elts_cnt; i++) {
185 var whichElt = elts[i].name;
186 if (whichElt.indexOf('_priv') >= 0) {
187 document.forms[the_form].elements[whichElt].checked = do_check;
192 } // end of the 'checkForm()' function