protected void Page_Load(object sender, EventArgs e)
        {
            Master.SelectedTab = tabID.actMyClubs;

            if (!IsPostBack)
            {
                expandoCreateClub.ExpandoLabel.Font.Bold = true;
                UserState = Page.User.Identity.IsAuthenticated ? (EarnedGratuity.UserQualifies(Page.User.Identity.Name, Gratuity.GratuityTypes.CreateClub) ? AuthState.Authorized : AuthState.Unauthorized) : AuthState.Unauthenticated;

                vcNew.ActiveClub = new Club();

                switch (UserState)
                {
                case AuthState.Unauthenticated:
                    pnlCreateClub.Visible = pnlYourClubs.Visible = false;
                    lblTrialStatus.Text   = Branding.ReBrand(Resources.Club.MustBeMember);
                    break;

                case AuthState.Unauthorized:
                    lblTrialStatus.Text     = Branding.ReBrand(Resources.Club.ClubCreateTrial);
                    vcNew.ActiveClub.Status = Club.ClubStatus.Promotional;
                    break;

                case AuthState.Authorized:
                    lblTrialStatus.Text     = Branding.ReBrand(Resources.Club.ClubCreateNoTrial);
                    vcNew.ActiveClub.Status = Club.ClubStatus.OK;
                    break;
                }

                Refresh();
            }
        }
    protected void Page_Load(object sender, EventArgs e)
    {
        Profile m_pf = MyFlightbook.Profile.GetUser(Page.User.Identity.Name);

        if (!IsPostBack)
        {
            lblCurrencyExpirationPromotion.Text = Branding.ReBrand(Resources.Profile.EmailCurrencyExpirationPromotion);
            rowPromo.Visible = !(ckCurrencyExpiring.Enabled = EarnedGratuity.UserQualifies(Page.User.Identity.Name, Gratuity.GratuityTypes.CurrencyAlerts));

            EmailSubscriptionManager esm = new EmailSubscriptionManager(m_pf.Subscriptions);

            ckCurrencyWeekly.Checked   = esm.HasSubscription(SubscriptionType.Currency);
            ckCurrencyExpiring.Checked = esm.HasSubscription(SubscriptionType.Expiration);
            ckTotalsWeekly.Checked     = esm.HasSubscription(SubscriptionType.Totals);
            ckMonthly.Checked          = esm.HasSubscription(SubscriptionType.MonthlyTotals);
        }
    }
Exemple #3
0
    protected override MFBImageInfo UploadForUser(string szUser, HttpPostedFile pf, string szComment)
    {
        int idFlight = Convert.ToInt32(Request.Form["idFlight"], CultureInfo.InvariantCulture);

        if (idFlight <= 0)
        {
            throw new MyFlightbookException(Resources.WebService.errInvalidFlight);
        }

        LogbookEntry le = new LogbookEntry
        {
            FlightID = idFlight
        };

        if (!le.FLoadFromDB(le.FlightID, szUser, LogbookEntry.LoadTelemetryOption.None))
        {
            throw new MyFlightbookException(Resources.WebService.errFlightDoesntExist);
        }
        if (le.User != szUser)
        {
            throw new MyFlightbookException(Resources.WebService.errFlightNotYours);
        }

        // Check if authorized for videos
        if (MFBImageInfo.ImageTypeFromFile(pf) == MFBImageInfo.ImageFileType.S3VideoMP4 && !EarnedGratuity.UserQualifies(szUser, Gratuity.GratuityTypes.Videos))
        {
            throw new MyFlightbookException(Branding.ReBrand(Resources.LocalizedText.errNotAuthorizedVideos));
        }

        LatLong ll    = null;
        string  szLat = Request.Form["txtLat"];
        string  szLon = Request.Form["txtLon"];

        if (!String.IsNullOrEmpty(szLat) && !String.IsNullOrEmpty(szLon))
        {
            ll = LatLong.TryParse(szLat, szLon, CultureInfo.InvariantCulture);
        }

        mfbImageFlight.Key = le.FlightID.ToString(CultureInfo.InvariantCulture);
        return(new MFBImageInfo(MFBImageInfo.ImageClass.Flight, mfbImageFlight.Key, pf, szComment, ll));
    }
Exemple #4
0
    protected override MFBImageInfo UploadForUser(string szUser, HttpPostedFile pf, string szComment)
    {
        string szTail     = Request.Form["txtAircraft"];
        int    idAircraft = Aircraft.idAircraftUnknown;
        bool   fUseID     = util.GetIntParam(Request, "id", 0) != 0;

        if (String.IsNullOrEmpty(szTail))
        {
            throw new MyFlightbookException(Resources.WebService.errBadTailNumber);
        }
        if (fUseID)
        {
            if (!int.TryParse(szTail, out idAircraft) || idAircraft == Aircraft.idAircraftUnknown)
            {
                throw new MyFlightbookException(Resources.WebService.errBadTailNumber);
            }
        }
        else if (szTail.Length > Aircraft.maxTailLength || szTail.Length < 3)
        {
            throw new MyFlightbookException(Resources.WebService.errBadTailNumber);
        }

        // Check if authorized for videos
        if (MFBImageInfo.ImageTypeFromFile(pf) == MFBImageInfo.ImageFileType.S3VideoMP4 && !EarnedGratuity.UserQualifies(szUser, Gratuity.GratuityTypes.Videos))
        {
            throw new MyFlightbookException(Branding.ReBrand(Resources.LocalizedText.errNotAuthorizedVideos));
        }

        UserAircraft ua = new UserAircraft(szUser);

        ua.InvalidateCache();   // in case the aircraft was added but cache is not refreshed.
        Aircraft[] rgac = ua.GetAircraftForUser();

        Aircraft ac = null;

        if (fUseID)
        {
            ac = new Aircraft(idAircraft);
        }
        else
        {
            string szTailNormal = Aircraft.NormalizeTail(szTail);

            // Look for the aircraft in the list of the user's aircraft (that way you get the right version if it's a multi-version aircraft and no ID was specified
            // Hack for backwards compatibility with mobile apps and anonymous aircraft
            // Look to see if the tailnumber matches the anonymous tail
            ac = Array.Find <Aircraft>(rgac, uac =>
                                       (String.Compare(Aircraft.NormalizeTail(szTailNormal), Aircraft.NormalizeTail(uac.TailNumber), StringComparison.CurrentCultureIgnoreCase) == 0 ||
                                        String.Compare(szTail, uac.HackDisplayTailnumber, StringComparison.CurrentCultureIgnoreCase) == 0));
        }

        if (ac == null || !ua.CheckAircraftForUser(ac))
        {
            throw new MyFlightbookException(Resources.WebService.errNotYourAirplane);
        }

        mfbImageAircraft.Key = ac.AircraftID.ToString(System.Globalization.CultureInfo.InvariantCulture);
        return(new MFBImageInfo(MFBImageInfo.ImageClass.Aircraft, mfbImageAircraft.Key, pf, szComment, null));
    }
Exemple #5
0
    /// <summary>
    /// Initialize the edit form for a new flight (blank fields) or for editing of an existing flight
    /// </summary>
    /// <param name="idFlight">-1 for a new flight, otherwise the ID of the flight to load</param>
    /// <param name="fForceLoad">True to force load (e.g., an admin mode, or CFI editing a user's flight)</param>
    public void SetUpNewOrEdit(int idFlight, bool fForceLoad = false)
    {
        LogbookEntry le = new LogbookEntry()
        {
            User = Page.User.Identity.Name
        };

        InitBasicControls();

        // Initialize our logbook entry from the db or make it a new entry
        bool fAdminMode = (CurrentUser.CanSupport && (util.GetStringParam(Request, "a").Length > 0));

        IsAdmin = fForceLoad || fAdminMode;

        FlightID = idFlight;

        if (!le.FLoadFromDB(FlightID, Page.User.Identity.Name, LogbookEntry.LoadTelemetryOption.LoadAll, IsAdmin))
        {
            // if this isn't found, try again with a new flight (but tell the user of the error)
            lblError.Text = le.ErrorString;
            FlightID      = (le = new LogbookEntry()
            {
                User = Page.User.Identity.Name
            }).FlightID;
        }

        // check for CFI signing mode
        if (fForceLoad && !le.IsNewFlight)
        {
            if (le.User.CompareOrdinal(Page.User.Identity.Name) != 0 && le.CanEditThisFlight(Page.User.Identity.Name))
            {
                pnlPublic.Visible = pnlPictures.Visible = false;
                FlightUser        = le.User; // save the name of the owner of the flight.
            }
            else
            {
                throw new MyFlightbookException(String.Format(CultureInfo.InvariantCulture, "attempt by {0} to edit non-owned flight (owned by {1}) by non-instructor!", Page.User.Identity.Name, le.User));
            }
        }

        // Enable Admin Signature fix-up
        if (!le.IsNewFlight && le.CFISignatureState != LogbookEntryBase.SignatureState.None)
        {
            lblSigSavedHash.Text   = le.DecryptedFlightHash;
            lblSigCurrentHash.Text = le.DecryptedCurrentHash;

            if (le.CFISignatureState == LogbookEntry.SignatureState.Invalid)
            {
                pnlSigEdits.Visible = true;
                LogbookEntry leNew   = LogbookEntry.LogbookEntryFromHash(lblSigCurrentHash.Text);
                LogbookEntry leSaved = LogbookEntry.LogbookEntryFromHash(lblSigSavedHash.Text);
                rptDiffs.DataSource = leSaved.CompareTo(leNew, CurrentUser.UsesHHMM);
                rptDiffs.DataBind();
            }

            if (fAdminMode)
            {
                LogbookEntry.SignatureSanityCheckState sscs = le.AdminSignatureSanityCheckState;
                pnlAdminFixSignature.Visible = true;
                lblSigSavedState.Text        = le.CFISignatureState.ToString();
                lblSigSanityCheck.Text       = sscs.ToString();
            }
        }

        // If the user has entered another flight this session, default to that date rather than today
        if (Session[keyLastEntryDate] != null && FlightID == LogbookEntry.idFlightNew)
        {
            le.Date = (DateTime)Session[keyLastEntryDate];
        }

        // see if we have a pending in-progress flight
        if (FlightID == LogbookEntry.idFlightNew && Session[keySessionInProgress] != null)
        {
            le = (LogbookEntry)Session[keySessionInProgress];
        }
        Session[keySessionInProgress] = null; // clear it out regardless.

        UseLastTail = true;

        // If a repeat or a reverse is requested, then clone and/or reverse it.
        le = CloneOrReverse(le);

        // If this is a shared flight, initialize from that.
        le = SharedFlight(le);

        // If we're setting up a new flight and last flight had an ending hobbs, initialize with that
        // clear the cookie, if present, regardless.
        HttpCookie c = Request.Cookies[keyCookieLastEndingHobbs];

        if (c != null)
        {
            if (le.IsNewFlight)
            {
                if (decimal.TryParse(c.Value.ToString(), NumberStyles.Any, CultureInfo.InvariantCulture, out decimal hobbsEnd))
                {
                    le.HobbsStart = hobbsEnd;
                }
            }
            Response.Cookies[keyCookieLastEndingHobbs].Expires = DateTime.Now.AddDays(-1);   // clear it.
        }

        SetUpAircraftForFlight(le);

        InitFormFromLogbookEntry(le);

        bool fCanDoVideo = EarnedGratuity.UserQualifies(Page.User.Identity.Name, Gratuity.GratuityTypes.Videos);

        mfbMFUFlightImages.IncludeVideos = fCanDoVideo;
        mfbVideoEntry1.CanAddVideos      = fCanDoVideo;
        mfbVideoEntry1.FlightID          = le.FlightID;
        lblPixForFlight.Text             = fCanDoVideo ? Resources.LogbookEntry.HeaderImagesVideosForFlight : Resources.LogbookEntry.HeaderImagesForFlight;

        FinalizeSetupForFlight(le);

        mfbDate.Focus();
    }