Rev Author Line No. Line
250 kaklik 1 /* $Id: user_password.js,v 1.1 2005/11/23 19:10:30 nijel Exp $ */
2  
3  
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)
12 {
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';
22 }
23  
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
39  
40 return true;
41 } // end of the 'checkPassword()' function
42  
43  
44 /**
45 * Validates the "add an user" form
46 *
47 * @return boolean whether the form is validated or not
48 */
49 function checkAddUser()
50 {
51 var the_form = document.forms['addUserForm'];
52  
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;
57 }
58  
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;
63 }
64  
65 return checkPassword(the_form);
66 } // end of the 'checkAddUser()' function
67  
68  
69 /**
70 * Validates the "update a profile" form
71 *
72 * @return boolean whether the form is validated or not
73 */
74 function checkUpdProfile()
75 {
76 var the_form = document.forms['updUserForm'];
77  
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;
82 }
83  
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;
88 }
89  
90 return checkPassword(the_form);
91 } // end of the 'checkUpdProfile()' function
92  
93  
94 /**
95 * Gets the list of selected options in combo
96 *
97 * @param object the form to check
98 *
99 * @return string the list of selected options
100 */
101 function getSelected(the_field) {
102 var the_list = '';
103 var opts = the_field.options;
104 var opts_cnt = opts.length;
105  
106 for (var i = 0; i < opts_cnt; i++) {
107 if (opts[i].selected) {
108 the_list += opts[i].text + ', ';
109 }
110 } // end for
111  
112 return the_list.substring(0, the_list.length - 2);
113 } // end of the 'getSelected()' function
114  
115  
116 /**
117 * Reloads the page to get tables names in a database or fields names in a
118 * table
119 *
120 * @param object the input text box to build the query from
121 */
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;
128  
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;
135 }
136 if (typeof(the_form['tablegrant']) != 'undefined') {
137 the_form['tablegrant'].selectedIndex = -1;
138 }
139 if (typeof(the_form['colgrant']) != 'undefined') {
140 the_form['colgrant'].selectedIndex = -1;
141 }
142 }
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);
154 }
155 sel_idx = the_form['tablegrant'].selectedIndex;
156 if (sel_idx > 0) {
157 l += '&tablegrant=' + escape(the_form['tablegrant'].options[sel_idx].text);
158 }
159 }
160  
161 var lpos = l.indexOf('&' + box_name);
162 if (lpos > 0) {
163 l = l.substring(0, lpos);
164 } // end if
165  
166 location.href = l + '&' + box_name + '=' + escape(getSelected(the_field));
167 }
168  
169 } // end of the 'change()' function
170  
171  
172 /**
173 * Checks/unchecks all privileges
174 *
175 * @param string the form name
176 * @param boolean whether to check or to uncheck the element
177 *
178 * @return boolean always true
179 */
180 function checkForm(the_form, do_check) {
181 var elts = document.forms[the_form].elements;
182 var elts_cnt = elts.length;
183  
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
190  
191 return true;
192 } // end of the 'checkForm()' function