function closed($tokens, &$next, &$i, &$message, &$boolean_tokens) { //comes from closed parenthesis or token $i++; $next = $tokens[$i]; if (preg_match("/[\\|&]{1}/", $next)) { //pointer is an operator operator($tokens, $next, $i, $message, $boolean_tokens); } elseif (preg_match("/\\){1}/", $next)) { //pointer is a closed closed($tokens, $next, $i, $message, $boolean_tokens); } elseif ($next == "\n") { //end of descent, no errors $message = false; } else { //error found $message = $tokens[$i] == "\n" ? "Error near end of boolean expression" : "Error in boolean expression at token " . ($i + 1) . " near " . $next; } }
function change($userid) { // Change user details global $_POST, $link, $table_users, $users_userid, $users_name, $users_mail, $users_passwd, $users_homedir, $users_note, $users_count, $users_admin, $users_closed; print "<h3>Change Account</h3>\n\n"; if ($_POST["submit"]) { // The change form is submitted and should be processed $new_userid = addslashes($_POST["userid"]); $new_name = addslashes($_POST["name"]); $new_mail = addslashes($_POST["mail"]); $new_passwd1 = addslashes($_POST["new_passwd1"]); $new_passwd2 = addslashes($_POST["new_passwd2"]); $new_homedir = addslashes($_POST["homedir"]); $new_note = addslashes($_POST["note"]); if ($_POST["admin"] == "on") { $new_admin = 1; } if ($_POST["admin"] == "off") { $new_admin = 0; } if ($_POST["closed"] == "on") { closed($userid, 1); } if ($_POST["closed"] == "off") { closed($userid, 0); } if ($new_userid == "" || $new_passwd1 != $new_passwd2) { print "<p>Old userid or password is empty, or new passwords are not identical. <a href=\"?page=admin&action=change&id={$userid}\">Try again</a></p>\n"; } else { $query = "UPDATE\n\t\t\t\t{$table_users}\n\t\t\tSET\n\t\t\t\t{$users_userid}\t= '{$new_userid}',\n\t\t\t\t{$users_name}\t= '{$new_name}',\n\t\t\t\t{$users_mail}\t= '{$new_mail}',\n\t\t\t\t{$users_homedir}\t= '{$new_homedir}',\n\t\t\t\t{$users_note}\t= '{$new_note}',\n\t\t\t\t{$users_admin}\t= '{$new_admin}'"; if ($new_passwd1 != "") { $query .= ", {$users_passwd} = PASSWORD('{$new_passwd1}')"; } $query .= " WHERE {$users_userid} = '{$userid}'"; $result = mysql_query($query) or die("Database query failed."); print "<p>Changes applied.</p>\n"; } } else { // If the change form is not submitted, print it $query = "SELECT\n\t\t\t{$users_name},\n\t\t\t{$users_mail},\n\t\t\t{$users_homedir},\n\t\t\t{$users_note},\n\t\t\t{$users_count},\n\t\t\t{$users_admin},\n\t\t\t{$users_closed}\n\t\tFROM\n\t\t\t{$table_users}\n\t\tWHERE\n\t\t\t{$users_userid} = '{$userid}'"; $result = mysql_query($query) or die("Database query failed."); $row = mysql_fetch_assoc($result); $name = stripslashes($row[$users_name]); $mail = stripslashes($row[$users_mail]); $homedir = stripslashes($row[$users_homedir]); $note = stripslashes($row[$users_note]); $count = $row[$users_count]; $admin = $row[$users_admin]; $closed = $row[$users_closed]; if ($admin) { $admin_s = "checked=\"checked\""; } if ($closed) { $closed_s = "checked=\"checked\""; } ?> <form action="?page=admin&action=change&<?php print "table={$table_short}&id={$userid}"; ?> " method="post"> <table> <tr> <th class="thv">Userid</th> <td><input type="text" name="userid" value="<?php print $userid; ?> " /></td> </tr> <tr> <th class="thv">Name</th> <td><input type="text" name="name" value="<?php print $name; ?> " /></td> </tr> <tr> <th class="thv">Mail</th> <td><input type="text" name="mail" value="<?php print $mail; ?> " /></td> </tr> <tr> <th class="thv">Homedir</th> <td><input type="text" name="homedir" value="<?php print $homedir; ?> " /></td> </tr> <tr> <th class="thv">New password</th> <td><input type="password" name="new_passwd1" /> Leave blank if you wont change</td> </tr> <tr> <th class="thv">New password</th> <td><input type="password" name="new_passwd2" /> Again</td> </tr> <tr> <th class="thv">Note</th> <td><textarea name="note" cols="60" rows="6"><?php print $note; ?> </textarea></td> </tr> <tr> <th class="thv">Logins</th> <td><?php print $count; ?> </td> </tr> <tr> <th class="thv">Admin</th> <td><input type="checkbox" name="admin" <?php print $admin_s; ?> /></td> </tr> <tr> <th class="thv">Closed</th> <td><input type="checkbox" name="closed" <?php print $closed_s; ?> /></td> </tr> </table> <p><input type="submit" name="submit" value="Change" /></p> </form> <?php } }
print "<p class=\"menu\">\n<a href=\"?page=admin\">User List</a> |\n<a href=\"?page=admin&action=logout\">Logout</a>\n</p>\n"; $action = addslashes($_GET["action"]); $id = addslashes($_GET["id"]); // These functions are included from libs/admin.lib.php switch ($action) { case "change": change($id); break; case "delete": delete($id); break; case "open": closed($id, 0); break; case "close": closed($id, 1); break; default: list_users(); } } else { // If not logged in, logged out or something failed, print login form ?> <form action="?page=admin" method="post"> <table> <tr> <th class="thv">Username</th> <td><input type="text" name="userid" /></td> </tr>