CVE-2012-10008 (published 2023-02-20T07:15Z)

A vulnerability, which was classified as critical, has been found in uakfdotb oneapp. This issue affects some unknown processing. The manipulation leads to sql injection. The attack may be initiated remotely. This product does not use versioning. This is why information about affected and unaffected releases are unavailable. The patch is named 5413ac804f1b09f9decc46a6c37b08352c49669c. It is recommended to apply a patch to fix this issue. The associated identifier of this vulnerability is VDB-221483.

CVSS v3 base score: 9.8, CRITICAL (CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H)

Weakness information:
cwe_id: CWE-89
cwe_name: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
description: The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. Without sufficient removal or quoting of SQL syntax in user-controllable inputs, the generated SQL query can cause those inputs to be interpreted as SQL instead of ordinary user data.
extended_description: 
            
            
         
         

Fix information:
repo_url: https://github.com/uakfdotb/oneapp
commit_details: repo_url: https://github.com/uakfdotb/oneapp
author: Perennate
author_date: 2012-05-10 03:21:00+00:00
msg: All users are now unified in the users table. Club and site administrators are determined by associations with groups in the user_groups table. Additionally, a few critical MySQL injection vulnerabilities are fixed in this revision.
repository: repo_url: https://github.com/uakfdotb/oneapp
repo_name: uakfdotb/oneapp
description: Automatically exported from code.google.com/p/oneapp
repo_language: PHP
owner: uakfdotb
file_changes: filename: comments.php
change_type: ModificationType.MODIFY
diff: @@ -5,15 +5,15 @@ include("../include/db_connect.php");
 include("../include/session.php");
 
 //check for $_REQUEST['id'] here because this page should never be accessed without an id set
-if(isset($_SESSION['admin_id']) && $_REQUEST['id']) {
-	$club_id = escape(getAdminClub($_SESSION['admin_id']));
-	$admin_id = escape($_SESSION['admin_id']);
+if(isset($_SESSION['admin']) && isset($_REQUEST['id'])) {
+	$club_id = $_SESSION['admin_club_id'];
+	$user_id = $_SESSION['user_id'];
 	$app_id = escape($_REQUEST['id']);
 	
 	if($club_id != 0) {
 		//retrieve and display comments (if not found in table, comments have not been set yet so default to blank)
 		$current_comments = "";
-		$result = mysql_query("SELECT comments FROM club_notes WHERE application_id='$app_id' AND admin_id='$admin_id'");
+		$result = mysql_query("SELECT comments FROM club_notes WHERE application_id='$app_id' AND user_id='$user_id'");
 		if($row = mysql_fetch_array($result)) {
 			$current_comments = $row[0];
 		}
@@ -23,6 +23,6 @@ if(isset($_SESSION['admin_id']) && $_REQUEST['id']) {
 		get_page_advanced("index", "admin", array('warning' => "General application admin does not have comments!"));
 	}
 } else {
-	header('Location: index.php?error=' . urlencode("You are not logged in!"));
+	header('Location: index.php');
 }
 ?>

programming_language: PHP
filename: easy_question.php
change_type: ModificationType.MODIFY
diff: @@ -7,8 +7,8 @@ include("../include/session.php");
 include("../include/apply_gen.php");
 include("../include/latex.php");
 
-if(isset($_SESSION['admin_id'])) {
-	$club_id = escape(getAdminClub($_SESSION['admin_id']));
+if(isset($_SESSION['admin'])) {
+	$club_id = $_SESSION['admin_club_id'];
 	
 	if(isset($_REQUEST['type'])) {
 		if(isset($_REQUEST['done'])) {

programming_language: PHP
filename: gen_pdf.php
change_type: ModificationType.MODIFY
diff: @@ -7,8 +7,8 @@ include("../include/session.php");
 include("../include/apply_gen.php");
 include("../include/latex.php");
 
-if(isset($_SESSION['admin_id'])) {
-	$club_id = escape(getAdminClub($_SESSION['admin_id']));
+if(isset($_SESSION['admin'])) {
+	$club_id = $_SESSION['admin_club_id'];
 	include("category_manager.php"); //sets database and whereString based on club/category
 	
 	$message = "";

programming_language: PHP
filename: index.php
change_type: ModificationType.MODIFY
diff: @@ -8,28 +8,78 @@ if(isset($_REQUEST['error'])) {
 	$error = $_REQUEST['error'];
 }
 
-if(isset($_REQUEST['username']) && isset($_REQUEST['password'])) {
-	$checkResult = checkAdmin($_REQUEST['username'], $_REQUEST['password']);
+if(!isset($_SESSION['admin']) && (isset($_SESSION['user_id']) || isset($_REQUEST['username'])) && isset($_REQUEST['password']) && isset($_REQUEST['club'])) {
+	if(!isset($_SESSION['user_id'])) {
+		//log in first
+		$loginResult = checkLogin($_REQUEST['username'], $_REQUEST['password']);
+		
+		if($result >= 0) {
+			$_SESSION['user_id'] = $loginResult;
+		} else if($result == -2) {
+			$error = "Please try again later (you are locked out for too many failed attempts).";
+		} else if($result == -3) {
+			$error = "Login and registration are currently disabled.";
+		} else if($result == -1) {
+			$error = "Login information is not correct.";
+		} else {
+			$error = "Internal error!";
+		}
+	}
 	
-	if($checkResult !== FALSE) {
-		$_SESSION['admin_id'] = $checkResult;
-	} else {
-		$error = "Incorrect username/password. You may be locked from your account. ";
+	//only continue if we haven't failed already
+	if(isset($_SESSION['user_id'])) {
+		$attempt_club_id = escape(intval($_REQUEST['club']));
+		$checkResult = checkAdminLogin($_SESSION['user_id'], $_REQUEST['password'], $attempt_club_id);
+		
+		if($checkResult === TRUE) {
+			$_SESSION['admin'] = true;
+			$_SESSION['admin_club_id'] = $attempt_club_id;
+			
+			//make sure a admin_notes_settings entry exists for this user
+			$result = mysql_query("SELECT COUNT(*) FROM admin_notes_settings WHERE user_id = '" . $_SESSION['user_id'] . "'");
+			$row = mysql_fetch_row($result);
+		
+			if($row[0] == 0) {
+				mysql_query("INSERT INTO admin_notes_settings (user_id, box_enabled, cat_enabled, comment_enabled) VALUES ('" . $_SESSION['user_id'] . "', '0', '0', '0')");
+			}
+		} else if($checkResult === -1) {
+			$error = "Login information is not correct.";
+		} else if($checkResult === -2) {
+			$error = "Please try again later (you are locked out for too many failed attempts).";
+		} else if($checkResult === 1) {
+			$error = "Invalid club specified.";
+		}
 	}
-} else if(isset($_REQUEST['action']) && isset($_SESSION['admin_id'])) {
+} else if(isset($_REQUEST['action']) && isset($_SESSION['admin'])) {
 	if($_REQUEST['action'] == 'logout') {
-		$success = "You are now logged out.";
-		session_unset();
+		$success = "You are now logged out of the club administration area.";
+		unset($_SESSION['admin']);
+		unset($_SESSION['admin_club_id']);
 	}
 }
 
-if(isset($_SESSION['admin_id'])) {
-	get_page_advanced("index", "admin");
-} else if(isset($error)) {
-	get_page_advanced("index_login", "admin", array('error' => $error));
+$parameters = array();
+
+if(isset($error)) {
+	$parameters['error'] = $error;
 } else if(isset($success)) {
-	get_page_advanced("index_login", "admin", array('success' => $success));
+	$parameters['success'] = $success;
+}
+
+if(isset($_SESSION['admin'])) {
+	get_page_advanced("index", "admin", $parameters);
 } else {
-	get_page_advanced("index_login", "admin");
+	if(isset($_SESSION['user_id'])) {
+		$parameters['user_loggedin'] = true;
+		$parameters['clubs'] = getAdminClubs($_SESSION['user_id']);
+	} else {
+		$parameters['user_loggedin'] = false;
+		
+		//list normal clubs, and general application
+		$parameters['clubs'] = listClubsIdName();
+		$parameters['clubs'][0] = 'General application';
+	}
+	
+	get_page_advanced("index_login", "admin", $parameters);
 }
 ?>

programming_language: PHP
filename: man_club.php
change_type: ModificationType.MODIFY
diff: @@ -4,65 +4,43 @@ include("../include/common.php");
 include("../include/db_connect.php");
 include("../include/session.php");
 
-if(isset($_SESSION['admin_id'])) {
-	$club_id = escape(getAdminClub($_SESSION['admin_id']));
-	$admin_id = escape($_SESSION['admin_id']);
+if(isset($_SESSION['admin'])) {
+	$club_id = $_SESSION['admin_club_id'];
+	$user_id = $_SESSION['user_id'];
 	
 	if($club_id != 0) {
-		if(isset($_REQUEST['action'])){
-			$currpass = mysql_query("SELECT password FROM admins WHERE id='" . $_SESSION['admin_id'] . "'");
-			$currpass = mysql_fetch_array($currpass);
-			if($_REQUEST['old_password']==$currpass[0]){
-				if(isset($_REQUEST['description']) && isset($_REQUEST['view_time']) && isset($_REQUEST['open_time']) && isset($_REQUEST['close_time']) && isset($_REQUEST['user_type'])) {
-					$description = escape($_REQUEST['description']);
-					$view_time = strtotime($_REQUEST['view_time']);
-					$open_time = strtotime($_REQUEST['open_time']);
-					$close_time = strtotime($_REQUEST['close_time']);
-					$num_recommend = escape($_REQUEST['num_recommend']);
-					$user_type = escape($_REQUEST['user_type']);
-					if($user_type == "Name"){
-						$usernot = 1;
-					} else {
-						$usernot = 0;
-					}
-		
-					mysql_query("UPDATE clubs SET description='$description', view_time='$view_time', open_time='$open_time', close_time='$close_time', num_recommend='$num_recommend' WHERE id='$club_id'");
-					$success = "Account Updated!";
-				}
-				if(isset($_REQUEST['new_password'])) {
-					$changepass = changeAdminPass($admin_id,$_REQUEST['new_password'],$_REQUEST['new_password_conf']);
-					if($changepass == 1){
-						$success = "Password Updated!";
-					} else if($changepass == -2){
-						$error = "New password does not match!";
-					} else {
-						$error = "Invaid new password!";
-					}
-				}
-			} else {
-				$error = "Incorrect password! If you have forgotten this password, contact your rood advisor.";
-			}
-		} else {
-			$info = "You need your current password to make any changes!";
+		if(isset($_REQUEST['description']) && isset($_REQUEST['view_time']) && isset($_REQUEST['open_time']) && isset($_REQUEST['close_time'])) {
+			$description = escape($_REQUEST['description']);
+			$view_time = strtotime($_REQUEST['view_time']);
+			$open_time = strtotime($_REQUEST['open_time']);
+			$close_time = strtotime($_REQUEST['close_time']);
+			$num_recommend = escape($_REQUEST['num_recommend']);
+
+			mysql_query("UPDATE clubs SET description='$description', view_time='$view_time', open_time='$open_time', close_time='$close_time', num_recommend='$num_recommend' WHERE id='$club_id'");
+			$success = "Club updated successfully.";
 		}
 		
-		$result = mysql_query("SELECT c.name, a.email, c.description, c.view_time, c.open_time, c.close_time, c.num_recommend FROM clubs c, admins a WHERE c.id='$club_id' AND a.id='$admin_id'");
+		$result = mysql_query("SELECT name, description, view_time, open_time, close_time, num_recommend FROM clubs WHERE id='$club_id'");
 	
 		if($row = mysql_fetch_array($result)) {
-			if( isset($error) ) {
-				get_page_advanced("man_club", "admin", array('error'=> $error, 'email' => $row['email'], 'club_name' => $row['name'], 'description' => $row['description'], 'view_time' => $row['view_time'], 'open_time' => $row['open_time'], 'close_time' => $row['close_time'], 'num_recommend' => $row['num_recommend']));
+			$parameters = array('club_name' => $row['name'], 'description' => $row['description'], 'view_time' => $row['view_time'], 'open_time' => $row['open_time'], 'close_time' => $row['close_time'], 'num_recommend' => $row['num_recommend']);
+			
+			if(isset($error)) {
+				$parameters['error'] = $error;
 			} else if( isset($success) ){
-				get_page_advanced("man_club", "admin", array('success' => $success, 'email' => $row['email'], 'club_name' => $row['name'], 'description' => $row['description'], 'view_time' => $row['view_time'], 'open_time' => $row['open_time'], 'close_time' => $row['close_time'], 'num_recommend' => $row['num_recommend']));
+				$parameters['success'] = $success;
 			} else if( isset($info) ){
-				get_page_advanced("man_club", "admin", array('info' => $info, 'email' => $row['email'], 'club_name' => $row['name'], 'description' => $row['description'], 'view_time' => $row['view_time'], 'open_time' => $row['open_time'], 'close_time' => $row['close_time'], 'num_recommend' => $row['num_recommend']));
+				$parameters['info'] = $info;
 			} else if( isset($warning) ){
-				get_page_advanced("man_club", "admin", array('warning' => $warning, 'email' => $row['email'], 'club_name' => $row['name'], 'description' => $row['description'], 'view_time' => $row['view_time'], 'open_time' => $row['open_time'], 'close_time' => $row['close_time'], 'num_recommend' => $row['num_recommend']));
-			} else {
-				get_page_advanced("man_club", "admin", array('email' => $row['email'], 'club_name' => $row['name'], 'description' => $row['description'], 'view_time' => $row['view_time'], 'open_time' => $row['open_time'], 'close_time' => $row['close_time'], 'num_recommend' => $row['num_recommend']));
+				$parameters['warning'] = $warning;
 			}
+			
+			get_page_advanced("man_club", "admin", $parameters);
 		} else {
 			get_page_advanced("message", "admin", array('message' => "Error: your club cannot be found in the clubs table.", 'title' => "Manage Club"));
 		}
+	} else {
+			get_page_advanced("message", "admin", array('message' => "Error: general application does not have club settings.", 'title' => "Manage Club"));
 	}
 } else {
 	header('Location: index.php?error=' . urlencode("You are not logged in!"));

programming_language: PHP
filename: man_notes.php
change_type: ModificationType.MODIFY
diff: @@ -4,9 +4,9 @@ include("../include/common.php");
 include("../include/db_connect.php");
 include("../include/session.php");
 
-if(isset($_SESSION['admin_id'])) {
-	$club_id = escape(getAdminClub($_SESSION['admin_id']));
-	$admin_id = escape($_SESSION['admin_id']);
+if(isset($_SESSION['admin'])) {
+	$club_id = $_SESSION['admin_club_id'];
+	$user_id = $_SESSION['user_id'];
 	
 	if($club_id != 0) {
 		//first, notes enabled/disabled settings
@@ -15,11 +15,11 @@ if(isset($_SESSION['admin_id'])) {
 			$cat_enabled = isset($_REQUEST['cat_enabled']) ? 1 : 0;
 			$comment_enabled = isset($_REQUEST['comment_enabled']) ? 1 : 0;
 			
-			mysql_query("UPDATE admins SET box_enabled = '$box_enabled', cat_enabled = '$cat_enabled', comment_enabled = '$comment_enabled' WHERE id = '" . $_SESSION['admin_id'] . "'");
+			mysql_query("UPDATE admin_notes_settings SET box_enabled = '$box_enabled', cat_enabled = '$cat_enabled', comment_enabled = '$comment_enabled' WHERE user_id = '$user_id'");
 			$success = "Note preferences updated successfully!";
 		}
 		
-		$result = mysql_query("SELECT box_enabled, cat_enabled, comment_enabled FROM admins WHERE id='" . $_SESSION['admin_id'] . "'");
+		$result = mysql_query("SELECT box_enabled, cat_enabled, comment_enabled FROM admin_notes_settings WHERE user_id='$user_id'");
 		
 		$box_enabled = false;
 		$cat_enabled = false;
@@ -37,20 +37,20 @@ if(isset($_SESSION['admin_id'])) {
 			$catName = escape($_REQUEST['name']);
 			
 			if($_REQUEST['action'] == "delete") {
-				mysql_query("DELETE FROM club_notes_categories WHERE admin_id = '$admin_id' AND name = '$catName'");
+				mysql_query("DELETE FROM club_notes_categories WHERE club_id = '$club_id' AND name = '$catName'");
 				$success = "Category deleted!";
 			} else if($_REQUEST['action'] == "add") {
-				$result = mysql_query("SELECT name FROM club_notes_categories WHERE admin_id = '$admin_id' AND name = '$catName'");
+				$result = mysql_query("SELECT name FROM club_notes_categories WHERE club_id = '$club_id' AND name = '$catName'");
 				if($row = mysql_fetch_array($result)) {
 					$error = "Category already exists!";
 				} else {
-					mysql_query("INSERT INTO club_notes_categories (name, admin_id) VALUES ('$catName', '$admin_id')");
+					mysql_query("INSERT INTO club_notes_categories (name, club_id) VALUES ('$catName', '$club_id')");
 					$success = "Category added!";
 				}
 			}
 		}
 		
-		$result = mysql_query("SELECT name FROM club_notes_categories WHERE admin_id = '$admin_id'");
+		$result = mysql_query("SELECT name FROM club_notes_categories WHERE club_id = '$club_id'");
 		$categories = array();
 		
 		while($row = mysql_fetch_array($result)) {

programming_language: PHP
filename: man_questions.php
change_type: ModificationType.MODIFY
diff: @@ -7,8 +7,8 @@ include("../include/session.php");
 include("../include/apply_gen.php");
 include("../include/apply_admin.php");
 
-if(isset($_SESSION['admin_id'])) {
-	$club_id = escape(getAdminClub($_SESSION['admin_id']));
+if(isset($_SESSION['admin'])) {
+	$club_id = $_SESSION['admin_club_id'];
 	include("category_manager.php");
 	
 	$message = "";

programming_language: PHP
filename: preview.php
change_type: ModificationType.MODIFY
diff: @@ -6,8 +6,8 @@ include("../include/session.php");
 
 include("../include/apply_gen.php");
 
-if(isset($_SESSION['admin_id'])) {
-	$club_id = escape(getAdminClub($_SESSION['admin_id']));
+if(isset($_SESSION['admin'])) {
+	$club_id = $_SESSION['admin_club_id'];
 	include("category_manager.php");
 	
 	$result = mysql_query("SELECT varname, vardesc, vartype FROM $database WHERE $whereString ORDER BY orderId");

programming_language: PHP
filename: statistics.php
change_type: ModificationType.MODIFY
diff: @@ -7,8 +7,8 @@ include("../include/session.php");
 include("../include/apply_gen.php");
 include("../include/statistics.php");
 
-if(isset($_SESSION['admin_id'])) {
-	$club_id = escape(getAdminClub($_SESSION['admin_id']));
+if(isset($_SESSION['admin'])) {
+	$club_id = $_SESSION['club_id'];
 	
 	$adminStat = adminStatistics($club_id);
 	$responseStat = responseStatistics($club_id, true, 8);

programming_language: PHP
filename: user_detail.php
change_type: ModificationType.MODIFY
diff: @@ -4,7 +4,7 @@ include("../include/common.php");
 include("../include/db_connect.php");
 include("../include/session.php");
 
-if(isset($_SESSION['admin_id']) && isset($_REQUEST['id'])) {
+if(isset($_SESSION['admin']) && isset($_REQUEST['id'])) {
 	//todo: admins currently can get information of users that didn't apply to their club
 	$user_id = escape($_REQUEST['id']);
 	$userinfo = getUserInformation($user_id); //userinfo is array(username, email)

programming_language: PHP
filename: view_recommendation.php
change_type: ModificationType.MODIFY
diff: @@ -4,7 +4,7 @@ include("../include/common.php");
 include("../include/db_connect.php");
 include("../include/session.php");
 
-if(isset($_SESSION['admin_id']) && isset($_REQUEST['peer_pdf']) && isset($_REQUEST['user_id'])) {
+if(isset($_SESSION['admin']) && isset($_REQUEST['peer_pdf']) && isset($_REQUEST['user_id'])) {
 	//todo: admins can see any peer recommendations if they know the user ID
 	$peer_pdf = escape($_REQUEST['peer_pdf']);
 	$user_id = escape($_REQUEST['user_id']);

programming_language: PHP
filename: view_submit.php
change_type: ModificationType.MODIFY
diff: @@ -6,14 +6,15 @@ include("../include/session.php");
 
 include("../include/apply_submit.php");
 
-if(isset($_SESSION['admin_id'])) {
-	$club_id = escape(getAdminClub($_SESSION['admin_id']));
-	$admin_id = escape($_SESSION['admin_id']);
+if(isset($_SESSION['admin'])) {
+	$club_id = $_SESSION['admin_club_id'];
+	$user_id = $_SESSION['user_id'];
 	
 	if($club_id != 0) {
 		//check if this admin is using textboxes and categories
-		$result = mysql_query("SELECT box_enabled, cat_enabled, comment_enabled FROM admins WHERE id='" . escape($_SESSION['admin_id']) . "'");
+		$result = mysql_query("SELECT box_enabled, cat_enabled, comment_enabled FROM admin_notes_settings WHERE user_id='$user_id'");
 		$row = mysql_fetch_array($result);
+		
 		$box_enabled = ($row['box_enabled'] == 1) ? true : false;
 		$cat_enabled = ($row['cat_enabled'] == 1) ? true : false;
 		$comment_enabled = ($row['comment_enabled'] == 1) ? true : false;
@@ -27,7 +28,7 @@ if(isset($_SESSION['admin_id'])) {
 		//we will need to construct a map from the application database IDs to the box and category note values if enabled
 		// we do this now so that we can check if an entry exists already for updating the notes table
 		if($box_enabled || $cat_enabled || $comment_enabled) {
-			$toolsResult = mysql_query("SELECT application_id, box, category, comments FROM club_notes WHERE admin_id = '$admin_id'");
+			$toolsResult = mysql_query("SELECT application_id, box, category, comments FROM club_notes WHERE club_id = '$club_id'");
 	
 			while($row = mysql_fetch_array($toolsResult)) {
 				$toolsMap[$row['application_id']] = array($row['box'], $row['category'], $row['comments']);
@@ -46,7 +47,7 @@ if(isset($_SESSION['admin_id'])) {
 					//if the tools map does not contain the ID, then we have to add it to database
 					if(!isset($toolsMap[$application_id])) {
 						$toolsMap[$application_id] = array('', '');
-						mysql_query("INSERT INTO club_notes (application_id, admin_id) VALUES ('$application_id', '$admin_id')");
+						mysql_query("INSERT INTO club_notes (application_id, club_id) VALUES ('$application_id', '$club_id')");
 					}
 				
 					//now we check what needs to be updated
@@ -71,7 +72,7 @@ if(isset($_SESSION['admin_id'])) {
 			
 					if(strlen($updateString) > 0) {
 						$updateString = substr($updateString, 0, -2);
-						mysql_query("UPDATE club_notes SET $updateString WHERE application_id='$application_id' AND admin_id='$admin_id'");
+						mysql_query("UPDATE club_notes SET $updateString WHERE application_id='$application_id' AND club_id='$club_id'");
 					}
 				}
 			}
@@ -95,7 +96,7 @@ if(isset($_SESSION['admin_id'])) {
 		//category filter manager
 		if($cat_enabled) {
 			//first, we retrieve a list of categories (this will be used in dropdown as well)
-			$catResult = mysql_query("SELECT name FROM club_notes_categories WHERE admin_id = '$admin_id'");
+			$catResult = mysql_query("SELECT name FROM club_notes_categories WHERE club_id = '$club_id'");
 	
 			while($row = mysql_fetch_array($catResult)) {
 				array_push($catList, $row[0]);

programming_language: PHP
filename: index_login.php
change_type: ModificationType.MODIFY
diff: @@ -1,6 +1,6 @@
 <h1>Administrator Page</h1>
 
-<p>Log in with the administrator username and password. These are added through <b>Admin Management</b> in the root administration section. If you do not know your username and password, then you should contact your root administrator.</p>
+<p>Use the form below to log in to the club administration area.</p>
 
 <div id="admin_table">
 <div id="admin_login">
@@ -10,14 +10,24 @@
 
 	<form method="POST" action="index.php">
 	<table>
+	<? if(!$user_loggedin) { ?>
 	<tr id="admin_username">
 	<td><p id="admin_username" align="right">Username:</p></td>
 	<td><input type="text" name="username"/></td>
 	</tr>
+	<? } ?>
 	<tr id="admin_password">
 	<td><p id="admin_password" align="right">Password:</p></td>
 	<td><input type="password" name="password"/></td>
 	</tr>
+	<tr id="admin_username">
+	<td><p id="admin_username" align="right">Club:</p></td>
+	<td><select name="club">
+		<? foreach($clubs as $club_id => $club_name) { ?>
+			<option value="<?= $club_id ?>"><?= $club_name ?></option>
+		<? } ?>
+	</select></td>
+	</tr>
 	<tr id="admin_submit">
 	<td colspan="2" align="right"><input type="submit" value="Submit" align="center"/></td>
 	</tr>

programming_language: PHP
filename: man_club.php
change_type: ModificationType.MODIFY
diff: @@ -15,7 +15,6 @@
 <tr><td><p>Open time</p></td><td><input type="text" id="open_time" name="open_time" value="<?= date('m/d/y H:i:s', $open_time) ?>" /><img src="<?= $stylePath ?>/datetimepicker/images/cal.gif" onclick="javascript:NewCssCal('open_time', 'MMddyyyy', 'arrow', true)" style="cursor:pointer"/></td></tr>
 <tr><td><p>Close time</p></td><td><input type="text" id="close_time" name="close_time" value="<?= date('m/d/y H:i:s', $close_time) ?>" /><img src="<?= $stylePath ?>/datetimepicker/images/cal.gif" onclick="javascript:NewCssCal('close_time', 'MMddyyyy', 'arrow', true)" style="cursor:pointer"/></td></tr>
 <tr><td><p>Number of recommenations</p></td><td><input type="text" name="num_recommend" value="<?= $num_recommend ?>" /></td></tr>
-<tr><td><p>Update Password</p></td><td><input type="password" name="new_password"></td></tr>
 <tr><td colspan ="2" align="right"><input type="submit" value="Update" /></td></tr>
 </table>
 </form>

programming_language: PHP
filename: index_login.php
change_type: ModificationType.MODIFY
diff: @@ -3,6 +3,9 @@
 <p>Please login with your root password to access the root administration area. Your root password can be reset manually in config.php.</p>
 
 <form method="POST" action="index.php">
-Password: <input type="password" name="password"><br>
-<input type="submit" name="submit" value="Submit">
+<? if(!$user_loggedin) { ?>
+Username: <input type="text" name="username" /><br />
+<? } ?>
+Password: <input type="password" name="password" /><br />
+<input type="submit" name="submit" value="Submit" />
 </form>

programming_language: PHP
filename: man_admins.php
change_type: ModificationType.MODIFY
diff: @@ -16,28 +16,15 @@ if(isset($message) && $message != "") {
 	<td align="right"><p class="admin_table_entry">Admin username</p></td>
 	<td><input type="text" name="username" style="width:100%"></td>
 </tr>
-<tr>
-	<td align="right"><p class="admin_table_entry">Password</p></td>
-	<td><input type="password" name="password" style="width:100%"></td>
-</tr>
-<tr>
-	<td align="right"><p class="admin_table_entry">Email address</p></td>
-	<td><input type="text" name="email" style="width:100%"></td>
-</tr>
 <tr>
 	<td align="right"><p class="admin_table_entry">Club</p></td>
 	<td><select name="club_id">
-			<option value="0">General Application</option>
 		<?
-			
-			$result = mysql_query("SELECT id, name FROM clubs ORDER BY name");
-
-			while($row = mysql_fetch_array($result))
-			  {
-				echo "<option value=\"".$row['id']."\">".$row['name']."</option>";
-			  }
-
+			foreach($clubsList as $club_id => $club_name) {
+				echo "<option value=\"" . $club_id . "\">" . $club_name . "</option>";
+ 			}
 		?>
+		<option value="0">General Application</option>
 	</select></td>
 </tr>
 <tr><td align="right" colspan="2"><input type="submit" value="Add admin"></td></tr>
@@ -46,12 +33,11 @@ if(isset($message) && $message != "") {
 
 <table width=100%>
 <tr>
-	<th><p class="admin_table_header">Club ID</th></p>
+	
 	<th><p class="admin_table_header">Username</p></th>
-	<th><p class="admin_table_header">Email</p></th>
-	<th><p class="admin_table_header">Change pass</p></th>
+	<th><p class="admin_table_header">Club</p></th>
 	<th><p class="admin_table_header">Update</p></th>
-	<th><p class="admin_table_header">Delete</p></th>
+	<th><p class="admin_table_header">Remove</p></th>
 </tr>
 
 <?
@@ -59,42 +45,30 @@ foreach($adminList as $item) {
 ?>
 	<form method="post" action="man_admins.php">
 	<input type="hidden" name="id" value="<?= $item[0] ?>">
+	<input type="hidden" name="club_id_orig" value="<?= $item[1] ?>">
 	<tr>
+		<td><input type="text" name="username" value="<?= $item[2] ?>" style="width:100%"></td>
 		<td><select name="club_id" style="width:100%">
 						<option value="<?= $item[1] ?>">
 			<?
 				if ($item[1] == 0) {
-				   echo "General App";
-				}
-				else {
-					 $result = mysql_query("SELECT id, name FROM clubs WHERE id = '$item[1]'");
-					 $row = mysql_fetch_array($result);
-					 echo $row['name'];
+				   echo "General Application";
+				} else {
+					 echo $clubsList[$item[1]];
 				}
 			?>
 			</option>
 				<?
-
-					$result = mysql_query("SELECT id, name FROM clubs ORDER BY name");
-
-					while($row = mysql_fetch_array($result)) {
-						if ($row['id']!=$item[1]) {
-							echo "<option value=\"".$row['id']."\">".$row['name']."</option>";
-						}
-					}
-
-					if ($item[1] > 0) {
-					   echo "<option value=\"0\">General Application</option>";
-					}
-
+				foreach($clubsList as $club_id => $club_name) {
+					echo "<option value=\"" . $club_id . "\">" . $club_name . "</option>";
+ 				}
+ 				
+ 				echo "<option value=\"0\">General Application</option>";
 				?>
 </select>
 </td>
-		<td><input type="text" name="username" value="<?= $item[2] ?>" style="width:100%"></td>
-		<td><input type="text" name="email" value="<?= $item[3] ?>" style="width:100%"></td>
-		<td><input type="password" name="password" style="width:100%"></td>
 		<td><input type="submit" name="action" value="update"></td>
-		<td><input type="submit" name="action" value="delete"></td>
+		<td><input type="submit" name="action" value="remove"></td>
 	</tr>
 	</form>
 <?

programming_language: PHP
filename: index_login.php
change_type: ModificationType.MODIFY
diff: @@ -4,14 +4,24 @@
 <br />
 <table width=60% class="log_in">
 	<form method="POST" action="index.php">
+	<? if(!$user_loggedin) { ?>
 	<tr>
 		<td width=20%><p class="name">Username</p></td>
 		<td align="right"><input type="text" name="username"/></td>
 	</tr>
+	<? } ?>
 	<tr>
 		<td><p class="name">Password</p></td>
 		<td align="right"><input type="password" name="password"/></td>
 	</tr>
+	<tr>
+		<td><p class="name">Club:</p></td>
+		<td align="right"><select name="club">
+		<? foreach($clubs as $club_id => $club_name) { ?>
+			<option value="<?= $club_id ?>"><?= $club_name ?></option>
+		<? } ?>
+		</select></td>
+	</tr>
 	<tr class="club_info">
 		<td colspan="2" align="right"><input type="submit" value="Log In" class="positive"/></td>
 	</tr>

programming_language: PHP
filename: index_login.php
change_type: ModificationType.MODIFY
diff: @@ -4,6 +4,9 @@
 
 <form method="POST" action="index.php">
 <table class="center"><tr>
+<? if(!$user_loggedin) { ?>
+<td>Username <input type="text" name="username" /></td>
+<? } ?>
 <td>Password <input type="password" name="password"></td>
 <td><input type="submit" name="submit" value="Submit"></td>
 </tr></table>

programming_language: PHP
filename: man_admins.php
change_type: ModificationType.MODIFY
diff: @@ -10,26 +10,15 @@
 	<td style="padding-right:10px">Admin username</td>
 	<td><input type="text" name="username"></td>
 </tr>
-<tr>
-	<td>Password</p></td>
-	<td><input type="password" name="password"></td>
-</tr>
-<tr>
-	<td>Email address</td>
-	<td><input type="text" name="email"></td>
-</tr>
 <tr>
 	<td>Club</td>
 	<td><select name="club_id">
-		<option value="0">General Application</option>
 		<?
-			$result = mysql_query("SELECT id, name FROM clubs ORDER BY name");
-
-			while($row = mysql_fetch_array($result))
-			{
-				echo "<option value=\"".$row['id']."\">".$row['name']."</option>";
+			foreach($clubsList as $club_id => $club_name) {
+				echo "<option value=\"" . $club_id . "\">" . $club_name . "</option>";
 			}
 		?>
+		<option value="0">General Application</option>
 	</select></td>
 </tr>
 <tr>
@@ -54,10 +43,8 @@
 
 <table class="tbl_repeat">
 <tr>
-	<th>Club</th>
 	<th align="left">Username</th>
-	<th align="left">Email</th>
-	<th align="left">Change pass</th>
+	<th>Club</th>
 	<th></th>
 	<th></th>
 </tr>
@@ -67,41 +54,31 @@ foreach($adminList as $item) {
 ?>
 	<form method="post" action="man_admins.php">
 	<input type="hidden" name="id" value="<?= $item[0] ?>">
+	<input type="hidden" name="club_id_orig" value="<?= $item[1] ?>">
 	<tr>
+		<td><input class="slide" onfocus="OnFocusInput (this)" onblur="OnBlurInput (this)" type="text" name="username" value="<?= $item[2] ?>"></td>
 		<td><select name="club_id">
 			<option value="<?= $item[1] ?>">
 			<?
 				if ($item[1] == 0) {
-				   echo "General App";
-				}
-				else {
-					//todo: terribly inefficient
-					$result = mysql_query("SELECT id, name FROM clubs WHERE id = '$item[1]'");
-					$row = mysql_fetch_array($result);
-					echo $row['name'];
+				   echo "General Application";
+				} else {
+					echo $clubsList[$item[1]];
 				}
 			?>
 			</option>
-		
+			
 			<?
-				$result = mysql_query("SELECT id, name FROM clubs ORDER BY name");
-
-				while($row = mysql_fetch_array($result)) {
-					if ($row['id']!=$item[1]) {
-						echo "<option value=\"" . $row['id'] . "\">" . $row['name'] . "</option>";
-					}
-				}
-				if ($item[1] > 0) {
-				   echo "<option value=\"0\">General Application</option>";
+				foreach($clubsList as $club_id => $club_name) {
+					echo "<option value=\"" . $club_id . "\">" . $club_name . "</option>";
 				}
+
+				echo "<option value=\"0\">General Application</option>";
 			?>
-			</select>
-			</td>
-			<td><input class="slide" onfocus="OnFocusInput (this)" onblur="OnBlurInput (this)" type="text" name="username" value="<?= $item[2] ?>"></td>
-			<td><input class="slide" onfocus="OnFocusInput (this)" onblur="OnBlurInput (this)" type="text" name="email" value="<?= $item[3] ?>" size="10"></td>
-			<td><input class="slide" onfocus="OnFocusInput (this)" onblur="OnBlurInput (this)" type="password" name="password"></td>
-			<td><input type="submit" name="action" value="Update" class="update"></td>
-			<td><input type="submit" name="action" value="Delete" class="delete negative"></td>
+		</select>
+		</td>
+		<td><input type="submit" name="action" value="Update" class="update"></td>
+		<td><input type="submit" name="action" value="Remove" class="delete negative"></td>
 		</tr>
 		</tr>
 	</form>

programming_language: PHP
filename: common.php
change_type: ModificationType.MODIFY
diff: @@ -514,7 +514,7 @@ function updateAccount($user_id, $oldPassword, $newPassword, $newPasswordConfirm
 
 //user id: success; -1: invalid login; -2: try again later; -3: login disabled
 function checkLogin($username, $password) {
-	if(!lockAction("checkuser")) {
+	if(!checkLock("checkuser")) {
 		return -2;
 	}
 	
@@ -536,9 +536,11 @@ function checkLogin($username, $password) {
 			
 			return $row['id'];
 		} else {
+			lockAction("checkuser");
 			return -1;
 		}
 	} else {
+		lockAction("checkuser");
 		return -1;
 	}
 }
@@ -572,23 +574,22 @@ function getProfile($userid) {
 	return $profile;
 }
 
-//returns array (username, email address, name)
-function getUserInformation($user_id) {
-	$user_id = escape($user_id);
-	$result = mysql_query("SELECT username, email, name FROM users WHERE id='$user_id'");
+//returns user_id, or FALSE on failure
+function getUserId($username) {
+	$username = escape($username);
+	$result = mysql_query("SELECT id FROM users WHERE username = '$username'");
 	
-	if($row = mysql_fetch_array($result)) {
-		return array($row[0], $row[1], $row[2]);
+	if($row = mysql_fetch_row($result)) {
+		return $row[0];
 	} else {
 		return FALSE;
 	}
 }
 
-//returns array (username, email address, club name)
-function getAdminInformation($admin_id) {
-	$admin_id = escape($admin_id);
-	$club_id = getAdminClub($admin_id);
-	$result = mysql_query("SELECT a.username, a.email, c.name FROM admins a, clubs c WHERE a.id='$admin_id' AND c.id='$club_id'");
+//returns array (username, email address, name)
+function getUserInformation($user_id) {
+	$user_id = escape($user_id);
+	$result = mysql_query("SELECT username, email, name FROM users WHERE id='$user_id'");
 	
 	if($row = mysql_fetch_array($result)) {
 		return array($row[0], $row[1], $row[2]);
@@ -599,7 +600,7 @@ function getAdminInformation($admin_id) {
 
 //true: success; -1: invalid login; -2: try again later
 function verifyLogin($user_id, $password) {
-	if(!lockAction("checkuser")) {
+	if(!checkLock("checkuser")) {
 		return -2;
 	}
 	
@@ -612,124 +613,129 @@ function verifyLogin($user_id, $password) {
 		if($password == $row['password']) {
 			return true;
 		} else {
+			lockAction("checkuser");
 			return -1;
 		}
 	} else {
+		lockAction("checkuser");
 		return -1;
 	}
 }
 
-function addAdmin($username, $password, $email, $club_id) {
-	$username = escape($username);
-	$password = escape(chash($password));
-	$email = escape($email);
+//true: success; -1: invalid login; -2: try again later; 1: invalid club
+function checkAdminLogin($user_id, $password, $club_id) {
+	$user_id = escape($user_id);
 	$club_id = escape($club_id);
-	
-	$result = mysql_query("INSERT INTO admins (username, password, email, club_id) VALUES ('$username', '$password', '$email', '$club_id')");
-}
-
-function updateAdmin($admin_id, $username, $password, $email, $club_id) {
-	$admin_id = escape($admin_id);
-	$setString = "";
-	
-	if(strlen($username) > 0) {
-		$setString .= ", username = '" . escape($username) . "'";
-	}
-	
-	if(strlen($password) > 0) {
-		$setString .= ", password = '" . escape(chash($password)) . "'";
-	}
-	
-	if(strlen($email) > 0) {
-		$setString .= ", email = '" . escape($email) . "'";
-	}
-	
-	if(strlen($club_id) > 0) {
-		$setString .= ", club_id = '" . escape($club_id) . "'";
-	}
-	
-	if(strlen($setString) > 0) {
-		$setString = substr($setString, 2);
-		$result = mysql_query("UPDATE admins SET $setString WHERE id='$admin_id'");
-	}
-}
 
-function checkAdmin($username, $password) {
-	if(!checkLock("checkadmin")) {
-		return FALSE;
-	}
+	//first verify login information
+	$login_result = verifyLogin($user_id, $password);
 	
-	$username = escape($username);
-	$password = escape(chash($password));
-	
-	$result = mysql_query("SELECT id, password FROM admins WHERE username='" . $username . "'");
-	
-	if($row = mysql_fetch_array($result)) {
-		if(strcmp($password, $row['password']) == 0) {
-			return $row['id'];
+	if($login_result === TRUE) {
+		//check that admin owns the club
+		$result = mysql_query("SELECT COUNT(*) FROM user_groups WHERE user_id = '$user_id' AND `group` = '$club_id' AND `group` >= '0'");
+		$row = mysql_fetch_row($result);
+		
+		if($row[0] == 0) {
+			return 1;
 		} else {
-			lockAction("checkadmin");
-			return FALSE;
+			return TRUE;
 		}
 	} else {
-		lockAction("checkadmin");
-		return FALSE;
+		return $login_result;
 	}
 }
 
-//returns admin ID, or false on failure
-function getAdminClub($admin_id) {
-	$admin_id = escape($admin_id);
-	$result = mysql_query("SELECT club_id FROM admins WHERE id='$admin_id'");
+//true: success; -1: invalid login; -2: try again later; 1: not root administrator
+function checkRootLogin($user_id, $password) {
+	$user_id = escape($user_id);
+
+	//first verify login information
+	$login_result = verifyLogin($user_id, $password);
 	
-	if($row = mysql_fetch_array($result)) {
-		return $row[0];
+	if($login_result === TRUE) {
+		//check that admin is a root administrator
+		$result = mysql_query("SELECT COUNT(*) FROM user_groups WHERE `group` = '-1' AND user_id = '$user_id'");
+		$row = mysql_fetch_row($result);
+		
+		if($row[0] == 0) {
+			return 1;
+		} else {
+			return TRUE;
+		}
 	} else {
-		return FALSE;
+		return $login_result;
 	}
 }
 
-function checkRoot($password) {
-	if(!checkLock("root")) {
-		return FALSE;
-	}
+//returns list of club_id => club_name that admin can manage, or empty list of none
+function getAdminClubs($user_id) {
+	$user_id = escape($user_id);
 	
-	$config = $GLOBALS['config'];
+	//first add regular clubs
+	$result = mysql_query("SELECT `group`, clubs.name FROM user_groups LEFT JOIN clubs ON clubs.id = `group` WHERE user_id='$user_id' AND `group` > '0'");
 	
-	$root_password = $config['root_password'];
-	if(substr($root_password, 0, 1) == ':') { //rest of root password is actually a hash
-		$root_password = substr($root_password, 1);
-		$password = chash($config['root_password_salt'] . $password);
+	$clubs_array = array();
+	
+	while($row = mysql_fetch_row($result)) {
+		$clubs_array[$row[0]] = $row[1];
 	}
 	
-	if($password == $root_password) {
-		return true;
-	} else {
-		lockAction("root");
-		return false;
+	//add general application if needed
+	$result = mysql_query("SELECT COUNT(*) FROM user_groups WHERE user_id =' $user_id' AND `group` = '0'");
+	$row = mysql_fetch_row($result);
+	
+	if($row[0] > 0) {
+		$clubs_array[0] = 'General application';
 	}
+	
+	return $clubs_array;
 }
 
-//1: success; -1: invalid password
-function changeAdminPassword($admin_id, $password){
-	if(validPassword($password) != 0) {
-		return -1;
-	} else {
-		mysql_query("UPDATE admins SET password = '" . escape(chash($password)) . "' WHERE id='" . $admin_id . "'");
-		return 1;
+//can be used to add, remove, or alter a user group association
+// if club_id = -1 or association doesn't exist, association will be added
+// if new_club_id = -1, association will be removed
+// otherwise, association will be altered
+//returns TRUE in success, FALSE on failure
+function alterAdminClubs($user_id, $club_id, $new_club_id) {
+	$user_id = escape($user_id);
+	$club_id = escape($club_id);
+	$new_club_id = escape($new_club_id);
+	
+	$old_association = FALSE;
+	
+	//verify existing association
+	if($club_id != -1) {
+		$result = mysql_query("SELECT COUNT(*) FROM user_groups WHERE user_id = '$user_id' AND `group` = '$club_id'");
+		$row = mysql_fetch_row($result);
+		
+		if($row[0] > 0) {
+			$old_association = TRUE;
+		}
 	}
-}
-
-//1: success; -1: invalid password, -2 password doesnt match
-function changeAdminPass($admin_id, $password, $verify){
-	if($password != $verify){
-		return -2;
-	} else if(validPassword($password) != 0) {
-		return -1;
-	} else {
-		mysql_query("UPDATE admins SET password = '" . escape(chash($password)) . "' WHERE id='" . $admin_id . "'");
-		return 1;
+	
+	//invalidate new_club_id if it exists already
+	// in this case, we just delete club_id association
+	if($new_club_id != -1) {
+		$result = mysql_query("SELECT COUNT(*) FROM user_groups WHERE user_id = '$user_id' AND `group` = '$new_club_id'");
+		$row = mysql_fetch_row($result);
+		
+		if($row[0] > 0) {
+			$new_club_id = -1;
+		}
+	}
+	
+	if($old_association) {
+		//update or delete existing association
+		if($new_club_id == -1) {
+			mysql_query("DELETE FROM user_groups WHERE user_id = '$user_id' AND `group` = '$club_id'");
+		} else {
+			mysql_query("UPDATE user_groups SET `group` = '$new_club_id' WHERE user_id = '$user_id' AND `group` = '$club_id'");
+		}
+	} else if($new_club_id != -1) { //only add an association if we're not trying to delete it!
+		mysql_query("INSERT INTO user_groups (user_id, `group`) VALUES ('$user_id', '$new_club_id')");
 	}
+	
+	return TRUE;
 }
 
 //returns array of (club id, club name, club description, user's application id)
@@ -771,6 +777,18 @@ function clubInfo($club_id) {
 	}
 }
 
+//returns array of club_id => club_name
+function listClubsIdName() {
+	$result = mysql_query("SELECT id, name FROM clubs");
+	$array = array();
+	
+	while($row = mysql_fetch_row($result)) {
+		$array[$row[0]] = $row[1];
+	}
+	
+	return $array;
+}
+
 //returns boolean: true=proceed, false=lock up; the difference between this and lockAction is that this can be used for repeated tasks, like admin
 // then, only if action was unsuccessful would lockAction be called
 function checkLock($action) {

programming_language: PHP
filename: install.sql
change_type: ModificationType.MODIFY
diff: @@ -1,16 +1,17 @@
 CREATE TABLE baseapp (id INT PRIMARY KEY AUTO_INCREMENT, category INT, orderId INT, varname VARCHAR(1024), vardesc VARCHAR(1024), vartype VARCHAR(1024));
 CREATE TABLE basecat (id INT PRIMARY KEY AUTO_INCREMENT, name VARCHAR(32), orderId INT);
 CREATE TABLE users (id INT PRIMARY KEY AUTO_INCREMENT, username VARCHAR(64), password VARCHAR(128), name VARCHAR(128), email VARCHAR(256), register_time INT, accessed INT);
+CREATE TABLE user_groups (user_id INT, `group` INT);
 CREATE TABLE reset (user_id INT PRIMARY KEY, time INT, auth VARCHAR(64));
 CREATE TABLE profiles (user_id INT, var_id INT, val VARCHAR(256));
 CREATE TABLE clubs (id INT PRIMARY KEY AUTO_INCREMENT, name VARCHAR(32), description TEXT, view_time INT, open_time INT, close_time INT, num_recommend INT);
-CREATE TABLE admins (id INT PRIMARY KEY AUTO_INCREMENT, club_id INT, username VARCHAR(64), password VARCHAR(128), email VARCHAR(256), box_enabled INT, cat_enabled INT, comment_enabled INT);
 CREATE TABLE supplements (id INT PRIMARY KEY AUTO_INCREMENT, club_id INT, orderId INT, varname VARCHAR(1024), vardesc TEXT, vartype VARCHAR(1024));
 CREATE TABLE applications (id INT PRIMARY KEY AUTO_INCREMENT, user_id INT, club_id INT, submitted VARCHAR(512));
 CREATE TABLE answers (id INT PRIMARY KEY AUTO_INCREMENT, application_id INT, var_id INT, val TEXT);
 CREATE TABLE recommendations (id INT PRIMARY KEY AUTO_INCREMENT, user_id INT, author VARCHAR(64), email VARCHAR(256), auth VARCHAR(64), status INT, filename VARCHAR(32));
 CREATE TABLE recommender_answers (id INT PRIMARY KEY AUTO_INCREMENT, recommend_id INT, var_id INT, val TEXT);
 CREATE TABLE pages (id INT PRIMARY KEY AUTO_INCREMENT, name VARCHAR(32), text TEXT);
-CREATE TABLE club_notes (application_id INT, admin_id INT, box TEXT, category VARCHAR(16), rank INT, comments TEXT);
-CREATE TABLE club_notes_categories (admin_id INT, name VARCHAR(16));
+CREATE TABLE club_notes (application_id INT, user_id INT, box TEXT, category VARCHAR(16), rank INT, comments TEXT);
+CREATE TABLE club_notes_categories (club_id INT, name VARCHAR(16));
+CREATE TABLE admin_notes_settings (user_id INT, box_enabled INT, cat_enabled INT, comment_enabled INT);
 CREATE TABLE locks (id INT NOT NULL PRIMARY KEY AUTO_INCREMENT, ip VARCHAR(16), time INT, action VARCHAR(16), num INT);

programming_language: SQL
filename: install.php
change_type: ModificationType.ADD
diff: @@ -0,0 +1,18 @@
+<?php
+include("../include/common.php");
+include("../config.php");
+include("../include/db_connect.php");
+include("../include/session.php");
+
+//make sure that users aren't set up yet
+$result = mysql_query("SELECT COUNT(*) FROM users");
+$row = mysql_fetch_row($result);
+
+if($row[0] == 0) {
+	mysql_query("INSERT INTO users (username, password, name, email, register_time, accessed) VALUES ('admin', '" . chash("") . "', 'Site Administrator', 'admin@example.com', '0', '0')");
+	$admin_id = escape(mysql_insert_id());
+	mysql_query("INSERT INTO user_groups (user_id, `group`) VALUES ('$admin_id', '0')");
+	mysql_query("INSERT INTO user_groups (user_id, `group`) VALUES ('$admin_id', '-1')");
+}
+
+?>

programming_language: PHP
filename: login.php
change_type: ModificationType.MODIFY
diff: @@ -8,6 +8,7 @@ if(isset($_SESSION['user_id'])) {
 	get_page("message", array("title" => "Logged In", "message" => "You are already logged in! Click <a href=\"application/\">here</a> to continue."));
 } else if(isset($_REQUEST['username']) && isset($_REQUEST['password'])) {
 	$result = checkLogin($_REQUEST['username'], $_REQUEST['password']);
+	
 	if($result >= 0) {
 		$_SESSION['user_id'] = $result;
 		get_page("login", array("title" => "Logged In", "message" => "You are now logged in. Click <a href=\"application/\">here</a> to continue.", "redirect" => "application/"));

programming_language: PHP
filename: index_login.php
change_type: ModificationType.MODIFY
diff: @@ -1,19 +1,29 @@
 <h1>Administrator Page</h1>
 
-<p>Log in with the administrator username and password. These are added through <b>Admin Management</b> in the root administration section. If you do not know your username and password, then you should contact your root administrator.</p>
+<p>Use the form below to log in to the club administration area.</p>
 
 <table>
 	<tr>
 		<form method="POST" action="index.php">
 		<table>
+			<? if(!$user_loggedin) { ?>
 			<tr>
 				<td>Username:</td>
 				<td><input type="text" name="username"/></td>
 			</tr>
+			<? } ?>
 			<tr>
 				<td>Password:</td>
 				<td><input type="password" name="password"/></td>
 			</tr>
+			<tr>
+				<td>Club:</td>
+				<td><select name="club">
+				<? foreach($clubs as $club_id => $club_name) { ?>
+					<option value="<?= $club_id ?>"><?= $club_name ?></option>
+				<? } ?>
+				</select></td>
+			</tr>
 			<tr>
 				<td colspan="2"><input type="submit" value="Submit" align="center"/></td>
 			</tr>

programming_language: PHP
filename: man_club.php
change_type: ModificationType.MODIFY
diff: @@ -31,16 +31,3 @@
 </tr>
 </table>
 </form>
-
-<h3>Administrator password</h3>
-<form method="post" action="man_club.php">
-<table>
-<tr>
-	<td>Update Password</td>
-	<td><input type="password" name="new_password"></td>
-</tr>
-<tr>
-	<td colspan="2"><input type="submit" value="Update" /></td>
-</tr>
-</table>
-</form>

programming_language: PHP
filename: index_login.php
change_type: ModificationType.MODIFY
diff: @@ -3,6 +3,9 @@
 <p>Please login with your root password to access the root administration area. Your root password can be reset manually in config.php.</p>
 
 <form method="POST" action="index.php">
-Password: <input type="password" name="password"><br>
-<input type="submit" name="submit" value="Submit">
+<? if(!$user_loggedin) { ?>
+Username: <input type="text" name="username" /><br />
+<? } ?>
+Password: <input type="password" name="password" /><br />
+<input type="submit" name="submit" value="Submit" />
 </form>

programming_language: PHP
filename: man_admins.php
change_type: ModificationType.MODIFY
diff: @@ -16,26 +16,15 @@ if(isset($message) && $message != "") {
 	<td>Admin username</td>
 	<td><input type="text" name="username"></td>
 </tr>
-<tr>
-	<td>Password</p></td>
-	<td><input type="password" name="password"></td>
-</tr>
-<tr>
-	<td>Email address</td>
-	<td><input type="text" name="email"></td>
-</tr>
 <tr>
 	<td>Club</td>
 	<td><select name="club_id">
-		<option value="0">General Application</option>
 		<?
-			$result = mysql_query("SELECT id, name FROM clubs ORDER BY name");
-
-			while($row = mysql_fetch_array($result))
-			{
-				echo "<option value=\"".$row['id']."\">".$row['name']."</option>";
+			foreach($clubsList as $club_id => $club_name) {
+				echo "<option value=\"" . $club_id . "\">" . $club_name . "</option>";
 			}
 		?>
+		<option value="0">General Application</option>
 	</select></td>
 </tr>
 <tr>
@@ -46,12 +35,10 @@ if(isset($message) && $message != "") {
 
 <table>
 <tr>
-	<th>Club ID</th>
 	<th>Username</th>
-	<th>Email</th>
-	<th>Change pass</th>
+	<th>Club</th>
 	<th>Update</th>
-	<th>Delete</th>
+	<th>Remove</th>
 </tr>
 
 <?
@@ -59,42 +46,31 @@ foreach($adminList as $item) {
 ?>
 	<form method="post" action="man_admins.php">
 	<input type="hidden" name="id" value="<?= $item[0] ?>">
+	<input type="hidden" name="club_id_orig" value="<?= $item[1] ?>">
 	<tr>
+		<td><input type="text" name="username" value="<?= $item[2] ?>"></td>
 		<td><select name="club_id">
 			<option value="<?= $item[1] ?>">
 			<?
 				if ($item[1] == 0) {
-				   echo "General App";
-				}
-				else {
-					//todo: terribly inefficient
-					$result = mysql_query("SELECT id, name FROM clubs WHERE id = '$item[1]'");
-					$row = mysql_fetch_array($result);
-					echo $row['name'];
+				   echo "General Application";
+				} else {
+					echo $clubsList[$item[1]];
 				}
 			?>
 			</option>
 			
 			<?
-				$result = mysql_query("SELECT id, name FROM clubs ORDER BY name");
-
-				while($row = mysql_fetch_array($result)) {
-					if ($row['id']!=$item[1]) {
-						echo "<option value=\"" . $row['id'] . "\">" . $row['name'] . "</option>";
-					}
+				foreach($clubsList as $club_id => $club_name) {
+					echo "<option value=\"" . $club_id . "\">" . $club_name . "</option>";
 				}
 
-				if ($item[1] > 0) {
-				   echo "<option value=\"0\">General Application</option>";
-				}
+				echo "<option value=\"0\">General Application</option>";
 			?>
 		</select>
 		</td>
-		<td><input type="text" name="username" value="<?= $item[2] ?>"></td>
-		<td><input type="text" name="email" value="<?= $item[3] ?>"></td>
-		<td><input type="password" name="password"></td>
 		<td><input type="submit" name="action" value="update"></td>
-		<td><input type="submit" name="action" value="delete"></td>
+		<td><input type="submit" name="action" value="remove"></td>
 	</tr>
 	</form>
 <?

programming_language: PHP
filename: index.php
change_type: ModificationType.MODIFY
diff: @@ -4,27 +4,51 @@ include("../config.php");
 include("../include/db_connect.php");
 include("../include/session.php");
 
-if(isset($_SESSION['admin_id']) || isset($_SESSION['id'] ) ) {
-	session_unset();
-	$warning = "You have been logged out! You may not log in as two different account types at once!";
-	get_page_advanced("index_login", "root", array("warning" => $warning));
-}
+$parameters = array();
 
-if(isset($_REQUEST['action'])) {
+if(isset($_REQUEST['action']) && isset($_SESSION['root'])) {
 	if($_REQUEST['action'] == 'logout') {
-		session_unset();
-		get_page_advanced("index_login", "root", array('success' => "You have been logged out!"));
+		unset($_SESSION['root']);
+		$parameters['success'] = "You are now logged out of the site administration area.";
+	}
+} else if(!isset($_SESSION['root']) && (isset($_SESSION['user_id']) || isset($_REQUEST['username'])) && isset($_REQUEST['password'])) {
+	if(!isset($_SESSION['user_id'])) {
+		//log in first
+		$loginResult = checkLogin($_REQUEST['username'], $_REQUEST['password']);
+		
+		if($loginResult >= 0) {
+			$_SESSION['user_id'] = $loginResult;
+		} else if($loginResult == -2) {
+			$parameters['error'] = "Please try again later (you are locked out for too many failed attempts).";
+		} else if($loginResult == -3) {
+			$parameters['error'] = "Login and registration are currently disabled.";
+		} else if($loginResult == -1) {
+			$parameters['error'] = "Login information is not correct.";
+		} else {
+			$parameters['error'] = "Internal error!";
+		}
 	}
-} else if(isset($_REQUEST['password'])) {
-	if(checkRoot($_REQUEST['password'])) {
-		$_SESSION['root'] = true;
-		get_page_advanced("index", "root", array('success' => "You are now logged in!"));
-	} else {
-		get_page_advanced("index_login", "root", array('error' => "Password is incorrect or you have been locked out."));
+	
+	//only continue if we haven't failed already
+	if(isset($_SESSION['user_id'])) {
+		$checkResult = checkRootLogin($_SESSION['user_id'], $_REQUEST['password']);
+		
+		if($checkResult === TRUE) {
+			$_SESSION['root'] = true;
+		} else if($checkResult === -1) {
+			$parameters['error'] = "Login information is not correct.";
+		} else if($checkResult === -2) {
+			$parameters['error'] = "Please try again later (you are locked out for too many failed attempts).";
+		} else if($checkResult === 1) {
+			$parameters['error'] = "You are not a root administrator.";
+		}
 	}
-} else if(isset($_SESSION['root'])) {
-	get_page_advanced("index", "root");
+}
+
+if(isset($_SESSION['root'])) {
+	get_page_advanced("index", "root", $parameters);
 } else {
-	get_page_advanced("index_login", "root");
+	$parameters['user_loggedin'] = isset($_SESSION['user_id']);
+	get_page_advanced("index_login", "root", $parameters);
 }
 ?>

programming_language: PHP
filename: man_admins.php
change_type: ModificationType.MODIFY
diff: @@ -9,67 +9,42 @@ if(isset($_SESSION['root'])) {
 	if(isset($_REQUEST['action'])) {
 		$action = $_REQUEST['action'];
 		
-		if($action == 'add') {
-			if($_REQUEST['username'] != "" && $_REQUEST['password'] != "") {
-				$result = mysql_query("SELECT id FROM admins WHERE username='" . $_REQUEST['username'] . "'");
-				if($row = mysql_fetch_array($result)){
-					$error = "Username already in use!";
-				} else {
-					if($_REQUEST['email'] != "") {
-						$result = mysql_query("SELECT id FROM admins WHERE email='" . $_REQUEST['email'] . "'");
-						if($row = mysql_fetch_array($result)){
-							$error = "Email already in use!";
-						} else {
-							addAdmin($_REQUEST['username'], $_REQUEST['password'], $_REQUEST['email'], $_REQUEST['club_id']);
-							$success = "Admin added successfully!";
-						}
-					} else {
-						addAdmin($_REQUEST['username'], $_REQUEST['password'], $_REQUEST['email'], $_REQUEST['club_id']);
-						$success = "Admin added successfully!";
-					}
-				}
+		if($action == 'add' && isset($_REQUEST['username']) && isset($_REQUEST['club_id'])) {
+			$user_id = getUserId($_REQUEST['username']);
+			
+			if($user_id !== FALSE) {
+				alterAdminClubs($user_id, -1, $_REQUEST['club_id']);
 			} else {
-				$error = "You need a username and password!";
-			}
-		} else if($action == 'delete' || $action == 'Delete') {
-			$admin_id = escape($_REQUEST['id']);
-			mysql_query("DELETE FROM admins WHERE id='$admin_id'");
-			$success =  "Admin deleted successfully!";
-		} else if($action == 'update' || $action == 'Update') {
-			$result = mysql_query("SELECT id FROM admins WHERE username='" . $_REQUEST['username'] . "'");
-			if($row = mysql_fetch_array($result)){
-				$error = "Username already in use!";
-			} else {
-				if($_REQUEST['email'] != "") {
-					$result = mysql_query("SELECT id FROM admins WHERE email='" . $_REQUEST['email'] . "'");
-					if($row = mysql_fetch_array($result)){
-						$error = "Email already in use!";
-					} else {
-						updateAdmin($_REQUEST['id'], $_REQUEST['username'], $_REQUEST['password'], $_REQUEST['email'], $_REQUEST['club_id']);
-						$success =  "Admin updated successfully!";
-					}
-				} else {
-					updateAdmin($_REQUEST['id'], $_REQUEST['username'], $_REQUEST['password'], $_REQUEST['email'], $_REQUEST['club_id']);
-					$success =  "Admin updated successfully!";
-				}
+				$error = "Username not found.";
 			}
+		} else if(($action == 'remove' || $action == "Remove") && isset($_REQUEST['id']) && isset($_REQUEST['club_id_orig'])) {
+			alterAdminClubs($_REQUEST['id'], $_REQUEST['club_id_orig'], -1);
+			$success =  "Admin removed successfully.";
+		} else if(($action == 'update' || $action == 'Update') && isset($_REQUEST['id']) && isset($_REQUEST['club_id_orig']) && isset($_REQUEST['club_id'])) {
+			alterAdminClubs($_REQUEST['id'], $_REQUEST['club_id_orig'], $_REQUEST['club_id']);
+			$success = "Admin updated successfully.";
 		}
 	}
 	
-	$result = mysql_query("SELECT id, club_id, username, email FROM admins ORDER BY club_id");
+	$clubsList = listClubsIdName();
+	$result = mysql_query("SELECT user_groups.user_id, user_groups.`group`, users.username FROM user_groups LEFT JOIN users ON user_groups.user_id = users.id WHERE user_groups.`group` >= '0' ORDER BY user_groups.`group`");
 	$adminList = array();
 	
 	while($row = mysql_fetch_array($result)) {
-		array_push($adminList, array($row[0], $row[1], $row[2], $row[3]));
+		array_push($adminList, array($row[0], $row[1], $row[2]));
 	}
 	
-	if(isset($error)){
-		get_page_advanced("man_admins", "root", array('error' => $error, 'adminList' => $adminList));
-	} else if(isset($success)){
-		get_page_advanced("man_admins", "root", array('success' => $success, 'adminList' => $adminList));
-	} else {
-		get_page_advanced("man_admins", "root", array('adminList' => $adminList));
+	$parameters = array();
+	$parameters['adminList'] = $adminList;
+	$parameters['clubsList'] = $clubsList;
+	
+	if(isset($error)) {
+		$parameters['error'] = $error;
+	} else if(isset($success)) {
+		$parameters['success'] = $success;
 	}
+	
+	get_page_advanced("man_admins", "root", $parameters);
 } else {
 	header('Location: index.php');
 }

programming_language: PHP