示例#1
0
                die('0;Database error when executing query.');
            }
            $num_added++;
        }
        break;
    case "EDIT":
        $src_date = $_POST["src_date"];
        $src_apid = $_POST["src_apid"];
        $dst_apid = $_POST["dst_apid"];
        $alid = trim($_POST["alid"]);
        // IE adds some whitespace crud to this!?
        if ($alid == 0) {
            $alid = -1;
        }
        // this should not be necessary, but just in case...
        list($src_apid, $dst_apid, $opp) = orderAirports($src_apid, $dst_apid);
        # 6 parameters per row
        $sql = <<<QUERY
UPDATE flights
SET src_apid=?, src_date=?, src_time=?, dst_apid=?, duration=?, distance=?,
    registration=?, code=?, seat=?, seat_type=?, class=?, reason=?,
    note=?, plid=?, alid=?, trid=?, opp=?, mode=?,
    upd_time=NOW()
WHERE fid=? AND uid=?
QUERY;
        $sth = $dbh->prepare($sql);
        $success = $sth->execute(array($src_apid, $src_date, $src_time, $dst_apid, $duration, $distance, $registration, $number, $seat, $seat_type, $class, $reason, $note, $plid, $alid, $trid, $opp, $mode, $fid, $uid));
        if (!$success) {
            # PDO will print a warning with the error.
            error_log("Could not insert flight for user {$uid}.");
            die('0;Database error when executing query.');
/**
 * Check to see if this user already has this segment imported.
 * @param $date DateTime
 * @param $from int Source airport ID
 * @param $to int Destination airport ID
 * @param $flight_number string Flight number (e.g. UA451)
 */
function is_duplicate_segment($date, $from, $to, $flight_number)
{
    global $dbh, $DEBUG;
    list($src_apid, $dst_apid, $opp) = orderAirports($from, $to);
    $mysql_date = $date->format('Y-m-d');
    $sth = $dbh->prepare("SELECT COUNT(*) as NUM FROM flights WHERE uid=? AND src_date=? AND src_apid=? AND dst_apid=? AND opp=?");
    $sth->execute(array($_SESSION["uid"], $mysql_date, $src_apid, $dst_apid, $opp));
    $result = $sth->fetch();
    if ($DEBUG) {
        error_log("is_duplicate_segment: {$mysql_date} {$from}-{$to} on {$flight_number} for user {$_SESSION['uid']} has duplicate status: " . $result[0]);
    }
    return $result[0] != 0;
}