1 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 * function used for password change form
9 * Validates the password field in a form
11 * @param object the form
13 * @return boolean whether the field value is valid or not
15 function checkPassword(the_form)
17 // Gets the elements pointers
18 if (the_form.name == 'addUserForm' || the_form.name == 'chgPassword') {
20 var pswd1_name = 'pma_pw';
21 var pswd2_name = 'pma_pw2';
24 pswd1_name = 'new_pw';
25 pswd2_name = 'new_pw2';
29 if (the_form.elements['nopass'][pswd_index].checked) {
30 if (the_form.elements[pswd1_name].value == '') {
31 alert(jsPasswordEmpty);
32 the_form.elements[pswd2_name].value = '';
33 the_form.elements[pswd1_name].focus();
35 } else if (the_form.elements[pswd1_name].value != the_form.elements[pswd2_name].value) {
36 alert(jsPasswordNotSame);
37 the_form.elements[pswd1_name].value = '';
38 the_form.elements[pswd2_name].value = '';
39 the_form.elements[pswd1_name].focus();
45 } // end of the 'checkPassword()' function
49 * Validates the "add an user" form
51 * @return boolean whether the form is validated or not
53 function checkAddUser()
55 var the_form = document.forms['addUserForm'];
57 if (the_form.elements['anyhost'][1].checked && the_form.elements['host'].value == '') {
59 the_form.elements['host'].focus();
63 if (the_form.elements['anyuser'][1].checked && the_form.elements['pma_user'].value == '') {
65 the_form.elements['pma_user'].focus();
69 return checkPassword(the_form);
70 } // end of the 'checkAddUser()' function
74 * Validates the "update a profile" form
76 * @return boolean whether the form is validated or not
78 function checkUpdProfile()
80 var the_form = document.forms['updUserForm'];
82 if (the_form.elements['anyhost'][1].checked && the_form.elements['new_server'].value == '') {
84 the_form.elements['new_server'].focus();
88 if (the_form.elements['anyuser'][1].checked && the_form.elements['new_user'].value == '') {
90 the_form.elements['new_user'].focus();
94 return checkPassword(the_form);
95 } // end of the 'checkUpdProfile()' function
99 * Gets the list of selected options in combo
101 * @param object the form to check
103 * @return string the list of selected options
105 function getSelected(the_field) {
107 var opts = the_field.options;
108 var opts_cnt = opts.length;
110 for (var i = 0; i < opts_cnt; i++) {
111 if (opts[i].selected) {
112 the_list += opts[i].text + ', ';
116 return the_list.substring(0, the_list.length - 2);
117 } // end of the 'getSelected()' function
121 * Reloads the page to get tables names in a database or fields names in a
124 * @param object the input text box to build the query from
126 function change(the_field) {
127 var l = location.href;
128 var lpos = l.indexOf('?lang');
129 var box_name = the_field.name;
130 var the_form = the_field.form.elements;
133 if (box_name == 'newdb') {
134 the_form['anydb'][0].checked = true;
135 the_form['anytable'][0].checked = true;
136 the_form['anycolumn'][0].checked = true;
137 if (typeof(the_form['dbgrant']) != 'undefined') {
138 the_form['dbgrant'].selectedIndex = -1;
140 if (typeof(the_form['tablegrant']) != 'undefined') {
141 the_form['tablegrant'].selectedIndex = -1;
143 if (typeof(the_form['colgrant']) != 'undefined') {
144 the_form['colgrant'].selectedIndex = -1;
149 l += '?lang=' + the_form['lang'].value
150 + '&convcharset=' . the_form['convcharset'].value
151 + '&server=' + the_form['server'].value
153 + '&host=' + escape(the_form['host'].value)
154 + '&pma_user=' + escape(the_form['pma_user'].value);
155 sel_idx = the_form['dbgrant'].selectedIndex;
157 l += '&dbgrant=' + escape(the_form['dbgrant'].options[sel_idx].text);
159 sel_idx = the_form['tablegrant'].selectedIndex;
161 l += '&tablegrant=' + escape(the_form['tablegrant'].options[sel_idx].text);
165 var lpos = l.indexOf('&' + box_name);
167 l = l.substring(0, lpos);
170 location.href = l + '&' + box_name + '=' + escape(getSelected(the_field));
173 } // end of the 'change()' function
177 * Checks/unchecks all privileges
179 * @param string the form name
180 * @param boolean whether to check or to uncheck the element
182 * @return boolean always true
184 function checkForm(the_form, do_check) {
185 var elts = document.forms[the_form].elements;
186 var elts_cnt = elts.length;
188 for (var i = 0; i < elts_cnt; i++) {
189 var whichElt = elts[i].name;
190 if (whichElt.indexOf('_priv') >= 0) {
191 document.forms[the_form].elements[whichElt].checked = do_check;
196 } // end of the 'checkForm()' function