sorry, wrong version checked in
[phpmyadmin/arisferyanto.git] / libraries / user_password.js
blob4fa0d26e2e3d70823366c5d0b39f5b44cc84bbf4
1 /* $Id$ */
4 /**
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') {
15 var pswd_index = 1;
16 var pswd1_name = 'pma_pw';
17 var pswd2_name = 'pma_pw2';
18 } else {
19 pswd_index = 2;
20 pswd1_name = 'new_pw';
21 pswd2_name = 'new_pw2';
24 // Validates
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();
30 return false;
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();
36 return false;
37 } // end if...else if
38 } // end if
40 return true;
41 } // end of the 'checkPassword()' function
44 /**
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 == '') {
54 alert(jsHostEmpty);
55 the_form.elements['host'].focus();
56 return false;
59 if (the_form.elements['anyuser'][1].checked && the_form.elements['pma_user'].value == '') {
60 alert(jsUserEmpty);
61 the_form.elements['pma_user'].focus();
62 return false;
65 return checkPassword(the_form);
66 } // end of the 'checkAddUser()' function
69 /**
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 == '') {
79 alert(jsHostEmpty);
80 the_form.elements['new_server'].focus();
81 return false;
84 if (the_form.elements['anyuser'][1].checked && the_form.elements['new_user'].value == '') {
85 alert(jsUserEmpty);
86 the_form.elements['new_user'].focus();
87 return false;
90 return checkPassword(the_form);
91 } // end of the 'checkUpdProfile()' function
94 /**
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) {
102 var the_list = '';
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 + ', ';
110 } // end for
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
118 * table
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;
127 var sel_idx = null;
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;
143 else {
144 if (lpos <= 0) {
145 l += '?lang=' + the_form['lang'].value
146 + '&convcharset=' . the_form['convcharset'].value
147 + '&server=' + the_form['server'].value
148 + '&grants=1'
149 + '&host=' + escape(the_form['host'].value)
150 + '&pma_user=' + escape(the_form['pma_user'].value);
151 sel_idx = the_form['dbgrant'].selectedIndex;
152 if (sel_idx > 0) {
153 l += '&dbgrant=' + escape(the_form['dbgrant'].options[sel_idx].text);
155 sel_idx = the_form['tablegrant'].selectedIndex;
156 if (sel_idx > 0) {
157 l += '&tablegrant=' + escape(the_form['tablegrant'].options[sel_idx].text);
161 var lpos = l.indexOf('&' + box_name);
162 if (lpos > 0) {
163 l = l.substring(0, lpos);
164 } // end if
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;
188 } // end if
189 } // end for
191 return true;
192 } // end of the 'checkForm()' function