Installer Class missing array variable check
[openemr.git] / phpmyadmin / js / user_password.js
blobfcfa15a4f9b58b3d6b3e2581eeb625c09957f2e8
1 /* vim: set expandtab sw=4 ts=4 sts=4: */
2 /**
3  * function used for password change form
4  *
5  * @version $Id$
6  */
8 /**
9  * Validates the password field in a form
10  *
11  * @param   object   the form
12  *
13  * @return  boolean  whether the field value is valid or not
14  */
15 function checkPassword(the_form)
17     // Gets the elements pointers
18     if (the_form.name == 'addUserForm' || the_form.name == 'chgPassword') {
19         var pswd_index = 1;
20         var pswd1_name = 'pma_pw';
21         var pswd2_name = 'pma_pw2';
22     } else {
23         pswd_index     = 2;
24         pswd1_name     = 'new_pw';
25         pswd2_name     = 'new_pw2';
26     }
28     // Validates
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();
34             return false;
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();
40             return false;
41         } // end if...else if
42     } // end if
44     return true;
45 } // end of the 'checkPassword()' function
48 /**
49  * Validates the "add an user" form
50  *
51  * @return  boolean  whether the form is validated or not
52  */
53 function checkAddUser()
55     var the_form = document.forms['addUserForm'];
57     if (the_form.elements['anyhost'][1].checked && the_form.elements['host'].value == '') {
58         alert(jsHostEmpty);
59         the_form.elements['host'].focus();
60         return false;
61     }
63     if (the_form.elements['anyuser'][1].checked && the_form.elements['pma_user'].value == '') {
64         alert(jsUserEmpty);
65         the_form.elements['pma_user'].focus();
66         return false;
67     }
69     return checkPassword(the_form);
70 } // end of the 'checkAddUser()' function
73 /**
74  * Validates the "update a profile" form
75  *
76  * @return  boolean  whether the form is validated or not
77  */
78 function checkUpdProfile()
80     var the_form = document.forms['updUserForm'];
82     if (the_form.elements['anyhost'][1].checked && the_form.elements['new_server'].value == '') {
83         alert(jsHostEmpty);
84         the_form.elements['new_server'].focus();
85         return false;
86     }
88     if (the_form.elements['anyuser'][1].checked && the_form.elements['new_user'].value == '') {
89         alert(jsUserEmpty);
90         the_form.elements['new_user'].focus();
91         return false;
92     }
94     return checkPassword(the_form);
95 } // end of the 'checkUpdProfile()' function
98 /**
99  * Gets the list of selected options in combo
101  * @param   object  the form to check
103  * @return  string  the list of selected options
104  */
105 function getSelected(the_field) {
106     var the_list = '';
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 + ', ';
113         }
114     } // end for
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
122  * table
124  * @param  object  the input text box to build the query from
125  */
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;
131     var sel_idx  = null;
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;
139         }
140         if (typeof(the_form['tablegrant']) != 'undefined') {
141             the_form['tablegrant'].selectedIndex = -1;
142         }
143         if (typeof(the_form['colgrant']) != 'undefined') {
144             the_form['colgrant'].selectedIndex = -1;
145         }
146     }
147     else {
148         if (lpos <= 0) {
149             l        += '?lang=' + the_form['lang'].value
150                      +  '&convcharset=' . the_form['convcharset'].value
151                      +  '&server=' + the_form['server'].value
152                      +  '&grants=1'
153                      +  '&host=' + escape(the_form['host'].value)
154                      +  '&pma_user=' + escape(the_form['pma_user'].value);
155             sel_idx  = the_form['dbgrant'].selectedIndex;
156             if (sel_idx > 0) {
157                 l    += '&dbgrant=' + escape(the_form['dbgrant'].options[sel_idx].text);
158             }
159             sel_idx  = the_form['tablegrant'].selectedIndex;
160             if (sel_idx > 0) {
161                 l    += '&tablegrant=' + escape(the_form['tablegrant'].options[sel_idx].text);
162             }
163         }
165         var lpos = l.indexOf('&' + box_name);
166         if (lpos > 0) {
167             l = l.substring(0, lpos);
168         } // end if
170         location.href = l + '&' + box_name + '=' + escape(getSelected(the_field));
171     }
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
183  */
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;
192         } // end if
193     } // end for
195     return true;
196 } // end of the 'checkForm()' function