$page = "newuser"; include_once("include/classdb.php"); // Database class include_once("include/validateEmailFormat.php"); // Email format validation if(isset($_POST["Register"]) && $_POST["Register"] == "True") { if($_POST["Screen"] && $_POST["Email"] && $_POST["Where"]) { if(preg_match("/^[a-z0-9]{1,9}$/i", $_POST["Screen"])) { $db_object = new db(); // Open db connection $sql = "SELECT Screen_name FROM user WHERE Screen_name = '" . $_POST["Screen"] . "';"; $db_object->query($sql); if(!$db_object->num_rows()) // Check that screen name doesn'nt already exist in "user" table { $sql = "SELECT UserID FROM user WHERE Email = '" . $_POST["Email"] . "';"; $db_object->query($sql); if(!$db_object->num_rows()) // Check that email doesn'nt already exist in "user" table { if(validateEmailFormat($_POST["Email"])) // Check email format { $sql = "SELECT Word FROM wordlist WHERE WordID = " . rand(1, 460) . ";"; $db_object->query($sql); $row = $db_object->fetch_array(); $mailTo = $_POST['Email']; $mailSubject = "Berkeley's Demonstrate Camera Registration"; $mailMessage = "Welcome to demonstrate!\n\n"; //$mailMessage .= "Your screen name is: " . $_POST["Screen"] . "\n"; $mailMessage .= "Your password is: " . $row["Word"] . "\n\n"; $mailMessage .= "To participate, visit:\n\n"; $mailMessage .= "http://demonstrate.berkeley.edu\n"; $mailHeaders = "From: register@demonstrate.berkeley.edu"; $mail = mail($mailTo, $mailSubject, $mailMessage, $mailHeaders); if($mail) // Was email sent? { $table = "user"; $fields = "Email, Password, Clear_pass, Screen_name, Register_time, WhereHearFrom"; $values = "'" . $_POST['Email'] . "', '" . md5($row["Word"]) . "', '" . $row["Word"] . "', '" . $_POST['Screen'] . "', '" . date('YmdHis') . "', '" . $_POST['Where'] . "'"; $db_object->insert($table,$fields,$values); //if(!file_exists($_SERVER[DOCUMENT_ROOT] . "/photos/" . $db_object->insert_id . "/")) // Create directory where snapshots are put //mkdir( $_SERVER[DOCUMENT_ROOT] . "/photos/" . $db_object->insert_id . "/", 0777); header("Location: signin.php?Registered=True"); // Redirect to login page exit; } else { // !!! // Email could not be sent $msg = "Email could not be sent. Please register again."; $error = true; } } else { // !!! // Format of email is incorrect $msg = "You have entered an invalid email address."; $error = true; } } else { // !!! // Email address already exists in "user" table $msg = "Email address already registered. Please enter another email address."; $error = true; } } else { // !!! // Bad screen name $msg = "Screen name already used. Please choose another screen name."; $error = true; } } else { // !!! // Bad screen name $msg = "Screen name must be less than 10 alphanumeric characters and have no spaces."; $error = true; } } else { // !!! // User did'nt fill out all fields $msg = "Please fill out all fields below and register again."; $error = true; } } include_once("include/header.php"); include_once("include/msg.php"); ?>