|
3 | 3 | require_once dirname(__FILE__).'/accesscheck.php'; |
4 | 4 |
|
5 | 5 | $start = sprintf('%d', !empty($_GET['start']) ? $_GET['start'] : 0); |
6 | | -echo PageLinkActionButton('admins', $GLOBALS['I18N']->get('List of Administrators'), "start=$start"); |
| 6 | +echo PageLinkActionButton('admins', s('List of Administrators'), "start=$start"); |
7 | 7 |
|
8 | 8 | require dirname(__FILE__).'/structure.php'; |
9 | 9 |
|
|
28 | 28 | $noaccess = 1; |
29 | 29 | } |
30 | 30 | if ($noaccess) { |
31 | | - echo Error($GLOBALS['I18N']->get('No Access')); |
| 31 | + echo Error(s('No Access')); |
32 | 32 |
|
33 | 33 | return; |
34 | 34 | } |
35 | 35 |
|
36 | 36 | if (!empty($_POST['change'])) { |
37 | 37 | if (!verifyToken()) { //# csrf check, should be added in more places |
38 | | - echo Error($GLOBALS['I18N']->get('No Access')); |
| 38 | + echo Error(s('No Access')); |
39 | 39 |
|
40 | 40 | return; |
41 | 41 | } |
|
50 | 50 | $totalres = Sql_fetch_Row($result); |
51 | 51 | $total = $totalres[0]; |
52 | 52 | if (!$total) { |
| 53 | + |
| 54 | + if (isset($_REQUEST['adminpassword'])) { |
| 55 | + $adminpass = $_REQUEST['adminpassword']; |
| 56 | + } else { |
| 57 | + $adminpass = random_bytes(32); |
| 58 | + } |
53 | 59 | Sql_Query(sprintf('insert into %s (loginname,namelc,password,email,created) values("%s","%s","%s","%s",now())', |
54 | 60 | $tables['admin'], strtolower(normalize($_POST['loginname'])), |
55 | | - strtolower(normalize($_POST['loginname'])), encryptPass(random_bytes(32)), |
| 61 | + strtolower(normalize($_POST['loginname'])), encryptPass($adminpass), |
56 | 62 | sql_escape($_POST['email']))); |
57 | 63 | $id = Sql_Insert_Id($tables['admin'], 'id'); |
58 | 64 | } else { |
|
95 | 101 | if (!empty($_POST['updatepassword'])) { |
96 | 102 | //Send token email. |
97 | 103 | echo sendAdminPasswordToken($id).'<br/>'; |
98 | | - //# check for password changes |
99 | | - } elseif (isset($_POST['password'])) { |
100 | | - // Sql_Query("update {$tables["admin"]} set password = \"".sql_escape($_POST['password'])."\" where id = $id"); |
| 104 | + |
101 | 105 | } |
102 | 106 | if (isset($_POST['attribute']) && is_array($_POST['attribute'])) { |
103 | 107 | foreach ($_POST['attribute'] as $key => $val) { |
|
115 | 119 | $GLOBALS['tables']['admin'], adminName($_SESSION['logindetails']['id']), sql_escape(serialize($privs)), |
116 | 120 | $id)); |
117 | 121 |
|
118 | | - echo $GLOBALS['I18N']->get('Changes saved'); |
| 122 | + echo s('Changes saved'); |
119 | 123 | echo '</div>'; |
120 | 124 | } else { |
121 | | - Error($GLOBALS['I18N']->get('Error adding new admin, login name and/or email not inserted, email not valid or admin already exists')); |
| 125 | + Error(s('Error adding new admin, login name and/or email not inserted, email not valid or admin already exists')); |
122 | 126 | } |
123 | 127 | } |
124 | 128 |
|
125 | 129 | if (!empty($_GET['delete'])) { |
126 | 130 | $delete = sprintf('%d', $_GET['delete']); |
127 | 131 | // delete the index in delete |
128 | | - echo $GLOBALS['I18N']->get('Deleting')." $delete ..\n"; |
| 132 | + echo s('Deleting')." $delete ..\n"; |
129 | 133 | if ($delete != $_SESSION['logindetails']['id']) { |
130 | 134 | Sql_query(sprintf('delete from %s where id = %d', $GLOBALS['tables']['admin'], $delete)); |
131 | 135 | Sql_query(sprintf('delete from %s where adminid = %d', $GLOBALS['tables']['admin_attribute'], $delete)); |
132 | | - echo '..'.$GLOBALS['I18N']->get('Done'); |
| 136 | + echo '..'.s('Done'); |
133 | 137 | } else { |
134 | | - echo '..'.$GLOBALS['I18N']->get('Failed, you cannot delete yourself'); |
| 138 | + echo '..'.s('Failed, you cannot delete yourself'); |
135 | 139 | } |
136 | 140 | echo "<br /><hr/><br />\n"; |
137 | 141 | } |
138 | 142 |
|
139 | 143 | echo '<div class="panel">'; |
140 | 144 |
|
141 | 145 | if ($id) { |
142 | | - echo '<h3>'.$GLOBALS['I18N']->get('Edit Administrator').': '; |
| 146 | + $addAdmin = false; |
| 147 | + echo '<h3>'.s('Edit Administrator').': '; |
143 | 148 | $result = Sql_query("SELECT * FROM {$tables['admin']} where id = $id"); |
144 | 149 | $data = sql_fetch_assoc($result); |
145 | 150 | echo $data['loginname'].'</h3>'; |
|
148 | 153 | $data['loginname']); |
149 | 154 | } |
150 | 155 | } else { |
| 156 | + $addAdmin = true; |
151 | 157 | $data = array(); |
152 | | - echo '<h3>'.$GLOBALS['I18N']->get('Add a new Administrator').'</h3>'; |
| 158 | + echo '<h3>'.s('Add a new Administrator').'</h3>'; |
153 | 159 | } |
154 | 160 |
|
155 | 161 | echo '<div class="content">'; |
156 | 162 | //var_dump($data); |
157 | 163 |
|
158 | 164 | echo formStart(' class="adminAdd"'); |
159 | | -printf('<input type="hidden" name="id" value="%d" /><table class="adminDetails" border="1">', $id); |
| 165 | +printf('<input type="hidden" name="id" value="%d" /><table class="adminDetails" border="1">', $id); |
160 | 166 |
|
161 | 167 | if (isset($data['privileges'])) { |
162 | 168 | $privileges = unserialize($data['privileges']); |
|
179 | 185 | //If key is 'password' and the passwords are encrypted, locate two radio buttons to allow an update. |
180 | 186 | if ($b == 'Password') { |
181 | 187 | $changeAdminPass = !empty($_SESSION['firstinstall']); |
| 188 | + if ($addAdmin===true){ |
| 189 | + |
| 190 | + echo ' <tr> |
| 191 | + <td>'.s('Choose how to set password').'</td> |
| 192 | + <td> |
| 193 | + <input type="radio" id="passwordoption1" name="passwordoption" value="1" checked="checked">'.s('Send email').' |
| 194 | + <input type="radio" id= "passwordoption0" name="passwordoption" value="0" >'.s('Create password').' |
| 195 | + </td> |
| 196 | + </tr> |
| 197 | + |
| 198 | + <tr id="passrow"> |
| 199 | + <td> |
| 200 | + <label for="adminpassword">'.s('Create password').'</label> |
| 201 | + </td> |
| 202 | + <td> |
| 203 | + <input type="password" name="adminpassword" id="adminpassword" value="" > |
| 204 | + <span id= "shortpassword">'.s('Password must be at least 8 characters').'</span> |
| 205 | + </td> |
| 206 | + </tr> |
| 207 | + |
| 208 | + <tr id="confirmrow"> |
| 209 | + <td> |
| 210 | + <label for="confirmpassword">'.s('Confirm password').'</label> |
| 211 | + </td> |
| 212 | + <td> |
| 213 | + <input type="password" name="confirmpassword" id="confirmpassword" value=""> |
| 214 | + <span id= "notmatching">'.s('Not matching').'</span> |
| 215 | + </td> |
| 216 | + </tr>'; |
| 217 | + |
| 218 | + |
| 219 | + } |
| 220 | + |
182 | 221 | if ($changeAdminPass) { |
183 | 222 | $checkNo = ''; |
184 | 223 | $checkYes = 'checked="checked"'; |
185 | 224 | } else { |
186 | 225 | $checkYes = ''; |
187 | 226 | $checkNo = 'checked="checked"'; |
188 | 227 | } |
189 | | - |
190 | | - printf('<tr><td>%s (%s)</td><td>%s<input type="radio" name="updatepassword" value="0" %s>%s</input> |
| 228 | + if ($addAdmin===false) { |
| 229 | + printf('<tr><td>%s (%s)</td><td>%s<input type="radio" name="updatepassword" value="0" %s>%s</input> |
191 | 230 | <input type="radio" name="updatepassword" value="1" %s>%s</input></td></tr> |
192 | 231 | ', |
193 | | - $GLOBALS['I18N']->get('Password'), $GLOBALS['I18N']->get('hidden'), |
194 | | - $GLOBALS['I18N']->get('Update it?') , |
195 | | - $checkNo, |
196 | | - $GLOBALS['I18N']->get('No'), $checkYes, $GLOBALS['I18N']->get('Yes')); |
| 232 | + s('Password'), s('hidden'), |
| 233 | + s('Update it?'), |
| 234 | + $checkYes, s('Yes'), $checkNo, s('No')); |
| 235 | + } |
197 | 236 | } else { |
198 | 237 | if ($b != 'Password') { |
199 | | - printf('<tr><td>%s</td><td>%s</td></tr>', $GLOBALS['I18N']->get($b), $data[$key]); |
| 238 | + if ($addAdmin !==true) { |
| 239 | + printf('<tr><td>%s</td><td>%s</td></tr>', s($b), $data[$key]); |
| 240 | + } |
200 | 241 | } else { |
201 | 242 | printf('<tr><td>%s</td><td><input type="text" name="%s" value="%s" size="30" /></td></tr>'."\n", |
202 | | - $GLOBALS['I18N']->get('Password'), $key, stripslashes($data[$key])); |
| 243 | + s('Password'), $key, stripslashes($data[$key])); |
203 | 244 | } |
204 | 245 | } |
205 | 246 | } |
206 | 247 | } elseif ($key == 'loginname' && $data[$key] == 'admin') { |
207 | | - printf('<tr><td>'.$GLOBALS['I18N']->get('Login Name').'</td><td>admin</td>'); |
| 248 | + printf('<tr><td>'.s('Login Name').'</td><td>admin</td>'); |
208 | 249 | echo '<td><input type="hidden" name="loginname" value="admin" /></td></tr>'; |
209 | 250 | } elseif ($key == 'superuser' || $key == 'disabled') { |
210 | 251 | if ($accesslevel == 'all') { |
211 | 252 | //If key is 'superuser' or 'disable' locate a boolean combo box. |
212 | | - printf('<tr><td>%s</td><td>', $GLOBALS['I18N']->get($val[1])); |
| 253 | + printf('<tr><td>%s</td><td>', s($val[1])); |
213 | 254 | printf('<select name="%s" size="1">', $key); |
214 | | - echo '<option value="1" '.(!empty($data[$key]) ? ' selected="selected"' : '').'>'.$GLOBALS['I18N']->get('Yes').'</option>'; |
215 | | - echo '<option value="0" '.(empty($data[$key]) ? ' selected="selected"' : '').'>'.$GLOBALS['I18N']->get('No').'</option></select>'; |
| 255 | + echo '<option value="1" '.(!empty($data[$key]) ? ' selected="selected"' : '').'>'.s('Yes').'</option>'; |
| 256 | + echo '<option value="0" '.(empty($data[$key]) ? ' selected="selected"' : '').'>'.s('No').'</option></select>'; |
216 | 257 | echo '</td></tr>'."\n"; |
217 | 258 | } |
218 | 259 | } elseif (!empty($val[1]) && !strpos($key, '_')) { |
| 260 | + |
219 | 261 | printf('<tr><td>%s</td><td><input type="text" name="%s" value="%s" size="30" /></td></tr>'."\n", |
220 | | - $GLOBALS['I18N']->get($val[1]), $key, htmlspecialchars(stripslashes($data[$key]))); |
| 262 | + s($val[1]), $key, htmlspecialchars(stripslashes($data[$key]))); |
221 | 263 | } |
222 | 264 | } |
223 | 265 | $res = Sql_Query("select |
|
268 | 310 | <label for="settings"><input type="checkbox" name="settings" ' .$checked['settings'].'/>'.s('Change Settings').'</label> |
269 | 311 | </div>'; |
270 | 312 | echo '</td></tr>'; |
271 | | - |
272 | | -echo '<tr><td colspan="2"><input class="submit" type="submit" name="change" value="'.$GLOBALS['I18N']->get('Save Changes').'" /></td></tr></table>'; |
| 313 | +if (!empty($_POST['passwordoption'])) { |
| 314 | + echo sendAdminPasswordToken($id).'<br/>'; |
| 315 | +} |
| 316 | +echo '<tr><td colspan="2"><input class="submit" type="submit" name="change" id ="savechanges" value="' . s('Save Changes') . '" /></td></tr></table>'; |
273 | 317 |
|
274 | 318 | echo '</div>'; // content |
275 | 319 | echo '</div>'; // panel |
|
0 commit comments