function add_or_remove_allergy($add_or_remove) { $return_value = array(); if (!check_params(["party_id", "auth_token", "person_id", "allergy"])) { $return_value["status"] = false; $return_value["reason"] = "Invalid Parameters"; } else { $party_id = $_POST["party_id"]; $auth_token = $_POST["auth_token"]; $person_id = $_POST["person_id"]; $allergy = $_POST["allergy"]; $db_conn = open_db_conn(); if (is_null($db_conn)) { $return_value["status"] = false; $return_value["reason"] = "Database Error"; } else { // Validate client input if (strlen($allergy) <= 0) { $return_value["status"] = false; $return_value["reason"] = "Must enter an allergy"; } else { if (authorize_request($party_id, $auth_token, $db_conn, $return_value)) { $result = false; if ($add_or_remove == "add") { $result = add_allergy($person_id, $allergy, $db_conn); } else { $result = remove_allergy($person_id, $allergy, $db_conn); } if (!$result) { $return_value["status"] = false; $return_value["reason"] = "Database Error"; } else { $return_value["status"] = true; $return_value["person_id"] = $person_id; $return_value["allergy"] = $allergy; } } } } } return $return_value; }
<?php require_once "create_db_conn.php"; require_once "db_utils.php"; require_once "utils.php"; $return_value = array(); if (!check_params(["party_id", "auth_token", "person_id", "first_name", "last_name", "food_pref", "over_21", "is_attending"])) { $return_value["status"] = false; $return_value["reason"] = "Invalid Parameters"; } else { $party_id = $_POST["party_id"]; $auth_token = $_POST["auth_token"]; $person_id = $_POST["person_id"]; $first_name = $_POST["first_name"]; $last_name = $_POST["last_name"]; $food_pref = $_POST["food_pref"]; $over_21 = $_POST["over_21"]; $is_attending = $_POST["is_attending"]; $db_conn = open_db_conn(); if (is_null($db_conn)) { $return_value["status"] = false; $return_value["reason"] = "Database Error"; } else { if (authorize_request($party_id, $auth_token, $db_conn, $return_value)) { if (!update_person($person_id, $first_name, $last_name, $food_pref, $over_21, $is_attending, $db_conn)) { $return_value["status"] = false; $return_value["reason"] = "Database Error"; } else { $return_value["status"] = true; $return_value["person_id"] = $person_id; $return_value["first_name"] = $first_name;
} function check_params($r) { echo "#####" . ($r instanceof ReflectionMethod ? $r->class . '::' : '') . $r->name . "()#####\n"; $i = 0; foreach ($r->getParameters() as $p) { echo "===" . $i . "===\n"; $i++; check_params_func($p, 'getName'); check_params_func($p, 'isPassedByReference'); try { check_params_decl_class($p, 'getClass'); } catch (ReflectionException $e) { echo $e->getMessage() . "\n"; } check_params_decl_class($p, 'getDeclaringClass'); // check_params_decl_func($p, 'getDeclaringFunction'); check_params_func($p, 'isArray'); check_params_func($p, 'allowsNull'); check_params_func($p, 'isOptional'); check_params_func($p, 'isDefaultValueAvailable'); if ($p->isOptional()) { check_params_func($p, 'getDefaultValue'); } } } check_params(new ReflectionFunction('test')); check_params(new ReflectionMethod('test::method')); ?> ===DONE===
<?php require_once "create_db_conn.php"; require_once "db_utils.php"; require_once "utils.php"; $return_value = array(); if (!check_params(["party_id", "auth_token", "addr_house_num", "addr_street", "addr_apt", "addr_city", "addr_state", "addr_zip"])) { $return_value["status"] = false; $return_value["reason"] = "Invalid Parameters"; } else { $party_id = $_POST["party_id"]; $auth_token = $_POST["auth_token"]; $addr_house_num = $_POST["addr_house_num"]; $addr_street = $_POST["addr_street"]; $addr_apt = $_POST["addr_apt"] != "" ? $_POST["addr_apt"] : null; $addr_city = $_POST["addr_city"]; $addr_state = $_POST["addr_state"]; $addr_zip = $_POST["addr_zip"]; $db_conn = open_db_conn(); if (is_null($db_conn)) { $return_value["status"] = false; $return_value["reason"] = "Database Error"; } else { if (authorize_request($party_id, $auth_token, $db_conn, $return_value)) { // Validate zip code if (strlen($addr_zip) != 5 || !preg_match("/[0-9]{5}/", $addr_zip)) { $return_value["status"] = false; $return_value["reason"] = "Invalid ZIP code"; } else { if (!validate_state($addr_state)) { $return_value["status"] = false;
<?php require_once "utils.php"; require_once "mail_utils.php"; $return_value = array(); if (!check_params(["name", "from", "login_code", "message"])) { $return_value["status"] = false; $return_value["reason"] = "Invalid parameters"; } else { if (!send_login_trouble_email($_POST["name"], $_POST["from"], $_POST["login_code"], $_POST["message"])) { $return_value["status"] = false; $return_value["reason"] = "Send mail error"; } else { $return_value["status"] = true; } } header("Content-type: application/json"); header("Cache-Control: no-cache, no-store, must-revalidate"); header("Pragma: no-cache"); header("Expires: 0"); echo json_encode($return_value);
} if (!checkdate($m, $d, $y)) { return "{$y}年{$m}月{$d}日は不正です"; } return true; } if (isset($_REQUEST["y"])) { $y = $_REQUEST["y"]; } if (isset($_REQUEST["m"])) { $m = $_REQUEST["m"]; } if (isset($_REQUEST["d"])) { $d = $_REQUEST["d"]; } if (($result = check_params($y, $m, $d)) !== true) { $error = $result; } else { $year = $y; $month = $m; $day = $d; } $item = $dbh->get_schedule($year, $month, $day); ?> <html> <head> <title>Schedule</title> <meta http-equiv=content-type content="text/html; charset=UTF-8"> </head> <body> <?php
// Make sure at least the person id was provided if (!isset($_POST["person_id"])) { $return_value["status"] = false; $return_value["reason"] = "Invalid Parameters"; } else { $person_id = $_POST["person_id"]; // Get the person's data to use for validation purposes $person_info = get_single_person($person_id, $db_conn); $params_to_check = array("party_id", "auth_token", "person_id", "is_attending", "food_pref", "over_21"); if ($person_info["is_invited_to_rehearsal"]) { array_push($params_to_check, "is_attending_rehearsal"); } if ($person_info["is_invited_to_movie"]) { array_push($params_to_check, "is_attending_movie"); } if (!check_params($params_to_check)) { $return_value["status"] = false; $return_value["reason"] = "Invalid Parameters"; } else { $party_id = $_POST["party_id"]; $auth_token = $_POST["auth_token"]; $is_attending = $_POST["is_attending"]; $food_pref = $_POST["food_pref"]; $over_21 = $_POST["over_21"]; $is_attending_rehearsal = 0; $is_attending_movie = 0; if ($person_info["is_invited_to_rehearsal"]) { $is_attending_rehearsal = $_POST["is_attending_rehearsal"]; } if ($person_info["is_invited_to_movie"]) { $is_attending_movie = $_POST["is_attending_movie"];
<?php require_once "create_db_conn.php"; require_once "db_utils.php"; require_once "utils.php"; $return_value = array(); if (!check_params(["party_id", "auth_token", "person_id", "first_name", "last_name"])) { $return_value["status"] = false; $return_value["reason"] = "Invalid Parameters"; } else { $party_id = $_POST["party_id"]; $auth_token = $_POST["auth_token"]; $person_id = $_POST["person_id"]; $first_name = $_POST["first_name"]; $last_name = $_POST["last_name"]; $db_conn = open_db_conn(); if (is_null($db_conn)) { $return_value["status"] = false; $return_value["reason"] = "Database Error"; } else { if (authorize_request($party_id, $auth_token, $db_conn, $return_value)) { if (!update_person_name($person_id, $first_name, $last_name, $db_conn)) { $return_value["status"] = false; $return_value["reason"] = "Database Error"; } else { $return_value["status"] = true; $return_value["person_id"] = $person_id; $return_value["first_name"] = $first_name; $return_value["last_name"] = $last_name; } }
<?php require_once "create_db_conn.php"; require_once "db_utils.php"; require_once "utils.php"; $return_value = array(); if (!check_params(["party_id", "auth_token", "first_name", "last_name", "food_pref", "over_21"])) { $return_value["status"] = false; $return_value["reason"] = "Invalid Parameters"; } else { $party_id = $_POST["party_id"]; $auth_token = $_POST["auth_token"]; $first_name = $_POST["first_name"]; $last_name = $_POST["last_name"]; $over_21 = $_POST["over_21"]; $food_pref = $_POST["food_pref"]; $is_attending = 1; $db_conn = open_db_conn(); if (is_null($db_conn)) { $return_value["status"] = false; $return_value["reason"] = "Database Error"; } else { // Validate data from client if (strlen($first_name) <= 0) { // Make sure they have a first name $return_value["status"] = false; $return_value["reason"] = "Must enter a first name"; } else { if (strlen($last_name) <= 0) { // And a last name $return_value["status"] = false;
function add_or_remove_music_suggestion($add_or_remove) { require_once "create_db_conn.php"; require_once "db_utils.php"; require_once "utils.php"; define("MAX_MUSIC_SUGGESTIONS", 10); $return_value = array(); if (!check_params(["party_id", "auth_token", "artist_name", "song_title"])) { $return_value["status"] = false; $return_value["reason"] = "Invalid Parameters"; } else { $party_id = $_POST["party_id"]; $auth_token = $_POST["auth_token"]; $artist_name = $_POST["artist_name"]; $song_title = $_POST["song_title"]; $db_conn = open_db_conn(); if (is_null($db_conn)) { $return_value["status"] = false; $return_value["reason"] = "Database Error"; } else { // Validate client data (just make sure artist and song are non-empty) if (strlen($artist_name) <= 0) { $return_value["status"] = false; $return_value["reason"] = "Must enter an artist name"; } else { if (strlen($song_title) <= 0) { $return_value["status"] = false; $return_value["reason"] = "Must enter a song title"; } else { if (authorize_request($party_id, $auth_token, $db_conn, $return_value)) { if ($add_or_remove == "add") { $suggestion_count = music_suggestion_count($party_id, $db_conn); if ($suggestion_count >= MAX_MUSIC_SUGGESTIONS) { $return_value["status"] = false; $return_value["reason"] = "Music suggestion limit reached"; return $return_value; } } // Special case: Make sure Nathan can't remove what's hannenin if ($party_id == 2 && $artist_name == "Soulja Boy" && $song_title == "What's Hannenin'") { $return_value["status"] = false; $return_value["reason"] = "Sorry Nathan, I can't let you do that"; } else { $result = false; if ($add_or_remove == "add") { $result = add_music_suggestion($party_id, $artist_name, $song_title, $db_conn); } else { $result = remove_music_suggestion($party_id, $artist_name, $song_title, $db_conn); } if (!$result) { $return_value["status"] = false; $return_value["reason"] = "Database Error"; } else { $return_value["status"] = true; $return_value["artist_name"] = $artist_name; $return_value["song_title"] = $song_title; } } } } } } } return $return_value; }
<?php require_once "utils.php"; require_once "mail_utils.php"; $return_value = array(); if (!check_params(["name", "from", "message"])) { $return_value["status"] = false; $return_value["reason"] = "Invalid parameters"; } else { if (!send_question_email($_POST["name"], $_POST["from"], $_POST["message"])) { $return_value["status"] = false; $return_value["reason"] = "Send mail error"; } else { $return_value["status"] = true; } } header("Content-type: application/json"); header("Cache-Control: no-cache, no-store, must-revalidate"); header("Pragma: no-cache"); header("Expires: 0"); echo json_encode($return_value);