0) { $error_message = "Error: User ID is Not Available"; include 'profile.form.php'; exit(); } // Validate the data entered - email if (!array_key_exists('entered_email',$_POST) || strlen(trim($_POST['entered_email'])) == 0) { $error_message = "Error: Primary Email Address is Required"; include 'profile.form.php'; exit(); } // Validate the email $email = strtolower(trim($_POST['entered_email'])); if (!preg_match("/^[^@]+@[a-z0-9-]+(\.[a-z]{2,16}){1,4}$/",$email)) { $error_message = "Error: Email Address Appears to be Invalid"; include 'profile.form.php'; exit(); } // Validate the other fields $first_name = trim($_POST['first_name']); $last_name = trim($_POST['last_name']); if (strlen($first_name) == 0 || strlen($last_name) == 0) { $error_message = "Error: First and Last Name is Required"; include 'profile.form.php'; exit(); } $home_phone = trim($_POST['home_phone']); if ($_SESSION['UserInfo']['type'] == 'Parent' && strlen($home_phone) == 0) { $error_message = "Error: Home Phone is Required"; include 'profile.form.php'; exit(); } $phone = preg_replace("/[^0-9]/","",$home_phone); if ($_SESSION['UserInfo']['type'] == 'Parent' && strlen($phone) != 10) { $error_message = "Error: Please enter full home phone number with area code"; include 'profile.form.php'; exit(); } if (strlen($phone) == 10) { $home_phone = "(" . substr($phone,0,3) . ")" . substr($phone,3,3) . "-" . substr($phone,6); } // Reformat first name if required if ($first_name == strtolower($first_name) || $first_name == strtoupper($first_name)) { $first_name = ucwords(strtolower($first_name)); $first_name = str_replace(" And "," and ",$first_name); } // Reformat last name if required if ($last_name == strtolower($last_name) || $last_name == strtoupper($last_name)) { $last_name = ucwords(strtolower($last_name)); $last_name = str_replace(" And "," and ",$last_name); } $additional1 = ''; $additional2 = ''; $school_directory = 'N'; $email_list = 'Y'; if (array_key_exists('additional1', $_POST)) $additional1 = trim($_POST['additional1']); if (array_key_exists('additional2', $_POST)) $additional2 = trim($_POST['additional2']); $email2 = trim($_POST['email2']); $email3 = trim($_POST['email3']); $receive_emails = 'N'; $email_reminders = 'N'; if (array_key_exists('receive_emails', $_POST)) $receive_emails = trim($_POST['receive_emails']); if (array_key_exists('email_reminders', $_POST)) $email_reminders = trim($_POST['email_reminders']); if (array_key_exists('language', $_POST)) $language = trim($_POST['language']); if (array_key_exists('school_directory', $_POST)) $school_directory = $_POST['school_directory']; if (array_key_exists('email_list', $_POST)) $email_list = $_POST['email_list']; if ($school_record['registration_userid'] == 'Email') $entered_userid = $email; if (!isset($language)) $language = $school_record['default_language']; $_SESSION['UserInfo']['userid'] = $entered_userid; $_SESSION['UserInfo']['first_name'] = $first_name; $_SESSION['UserInfo']['last_name'] = $last_name; $_SESSION['UserInfo']['home_phone'] = $home_phone; $_SESSION['UserInfo']['additional1'] = $additional1; $_SESSION['UserInfo']['additional2'] = $additional2; $_SESSION['UserInfo']['email'] = $email; $_SESSION['UserInfo']['receive_emails'] = $receive_emails; $_SESSION['UserInfo']['email_reminders'] = $email_reminders; $_SESSION['UserInfo']['school_directory'] = $school_directory; $_SESSION['UserInfo']['email_list'] = $email_list; $_SESSION['UserInfo']['language'] = $language; setcookie('language_cookie', $language, time()+60*60*24*120, $cookiePath); // Validate the second email address $email2 = strtolower($_POST['email2']); if (strlen($email2) > 0) { if (!preg_match("/^[^@]+@[a-z0-9-]+(\.[a-z]{2,16}){1,4}$/",$email2)) { $error_message = "Error: Second Email Address Appears to be Invalid"; include 'profile.form.php'; exit(); } } $_SESSION['UserInfo']['email2'] = $email2; // Validate the third email address $email3 = strtolower($_POST['email3']); if (strlen($email3) > 0) { if (!preg_match("/^[^@]+@[a-z0-9-]+(\.[a-z]{2,16}){1,4}$/",$email3)) { $error_message = "Error: Third Email Address Appears to be Invalid"; include 'profile.form.php'; exit(); } } $_SESSION['UserInfo']['email3'] = $email3; // Update the user's profile if (!isset($email2)) $email2 = ''; if (!isset($email3)) $email3 = ''; if (!isset($receive_emails) || $receive_emails == '') $receive_emails = 'N'; if (!isset($email_reminders) || $email_reminders == '') $email_reminders = 'N'; if (!isset($school_directory) || $school_directory == '') $school_directory = 'N'; if (!isset($email_list) || $email_list == '') $email_list = 'N'; if (!isset($language) || $language == '') $language = $school_record['default_language']; $query = "update users " . "set userid = '" . db_escape_string($entered_userid) . "', " . "first_name = '" . db_escape_string($first_name) . "', " . "last_name = '" . db_escape_string($last_name) . "', " . "home_phone = '" . db_escape_string($home_phone) . "', " . "additional1 = '" . db_escape_string($additional1) . "', " . "additional2 = '" . db_escape_string($additional2) . "', " . "email = '" . db_escape_string($email) . "', " . "email2 = '" . db_escape_string($email2) . "', " . "email3 = '" . db_escape_string($email3) . "', " . "receive_emails = '$receive_emails', " . "email_reminders = '$email_reminders', " . "school_directory = '$school_directory', " . "email_list = '$email_list', " . "language = '$language' " . "where school_num = $base_school_num " . "and record_num = $rnum"; db_query($query); // Update class number if required if ($school_record['registration_guest_student_info'] != 'N') { if ($school_record['orders_for'] == 'Registrant' || ($school_record['orders_for'] == 'Both' && $_SESSION['UserInfo']['type'] == 'Guest')) { if (array_key_exists('class_num',$_POST) && intval($_POST['class_num']) > 0) { $class_num = intval($_POST['class_num']); $user_num = $_SESSION['UserInfo']['record_num']; db_query("UPDATE people SET class_num = $class_num WHERE school_num = $base_school_num AND user_num = $user_num"); } } } // Handle staff allergens if ($_SESSION['UserInfo']['type'] == 'Staff') { $people_num = db_getVal("SELECT record_num FROM people WHERE school_num = $base_school_num AND user_num = $user_num AND people_type = 'Staff'"); $allergens = db_query("select * from allergens where school_num = $base_school_num order by sequence"); if (db_num_rows($allergens) > 0) { db_query("delete from allergies where school_num = $base_school_num and people_num = $people_num"); while ($row = db_fetch_array($allergens)) { $allergen_num = $row['record_num']; if (array_key_exists("allergen_$allergen_num",$_POST) && $_POST["allergen_$allergen_num"] == 'Y') { db_query("insert into allergies values($base_school_num,$people_num,$allergen_num)"); } } } } echo("
Your Profile Has Been Updated
\n"); header("Location: /?action=account&form_message=" . getLanguageText('MSG-PROFILE-UPDATED')); exit(); case "display": include 'profile.display.php'; break; default: include 'profile.display.php'; break; } ?>