Example #1
0
        /// <summary>
        /// Perform the necessary action to update the module's state, and
        /// send the email to the module submitter if emails are enabled.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SendBtn_Click(object sender, System.EventArgs e)
        {
            Emails.formatEmailBody(Message, CustomMessage.Text);
            MailMessage msg = Emails.constructMailMessage(Message, UserName, Globals.EditorsEmail);

            switch (Message.Type)
            {
            case EmailType.SubmitterApproved:
                UsersControl.approveSubmitter(UserName);
                break;

            case EmailType.SubmitterDenied:
                UsersControl.rejectSubmitter(UserName);
                break;

            case EmailType.ModuleApproved:
                ModulesControl.approveModule(ModuleID);
                break;

            case EmailType.ModuleDeniedSave:
                ModulesControl.rejectModule(ModuleID, true);
                break;

            case EmailType.ModuleDeniedDelete:
                ModulesControl.rejectModule(ModuleID, false);
                deleteMaterials();
                break;

            case EmailType.FacultyApproved:
                UsersControl.approveFaculty(UserName);
                break;

            case EmailType.FacultyDenied:
                UsersControl.rejectFaculty(UserName);
                break;
            }

            // Message to be displayed on editors page.
            string successMessage = "Operation successful.  ";

            // Only send an email if they're enabled.
            if (Globals.EmailsEnabled)
            {
                try {
                    SmtpMail.SmtpServer = AspNetForums.Components.Globals.SmtpServer;
                    SmtpMail.Send(msg);
                    successMessage += "Email sent to user.";
                } catch (Exception ex) {
                    successMessage += "But an error occurred while sending an email to the user.";
                }
            }
            else
            {
                successMessage += "Email not sent to user because they are disabled.";
            }

            Response.Redirect("EditorsPage.aspx?message=" +
                              HttpUtility.UrlEncode(successMessage));
        }
Example #2
0
 /// <summary>
 /// Mark a module as rejected.  Delete if necessary.  If not
 /// deleted, module remains locked.
 /// </summary>
 /// <param name="moduleID">The module to reject.</param>
 /// <param name="save">Whether to save the module or delete it.</param>
 public static void rejectModule(int moduleID, bool save)
 {
     if (save)
     {
         Modules.updateModuleStatus(moduleID, ModuleStatus.InProgress);
     }
     else
     {
         Modules.setLock(moduleID, "");
         ModulesControl.removeModule(moduleID);
     }
 }
        /// <summary>
        /// Handles clicks from links in the Modules table.
        /// </summary>
        /// <param name="source"></param>
        /// <param name="e"></param>
        private void ModuleGrid_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
        {
            int moduleID = Convert.ToInt32(e.CommandArgument);

            if (e.CommandName == "Delete")
            {
                ModulesControl.removeModule(moduleID);
                bindGrid();
            }
            else if (e.CommandName == "Edit")
            {
                Response.Redirect("editModule.aspx?moduleID=" + moduleID);
            }
        }
        /// <summary>
        /// Handles Continue button-click events.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ContinueBtn_Click(object sender, System.EventArgs e)
        {
            Modules.ModuleInfo mod        = (Modules.ModuleInfo)Session["EditModule"];
            string             queryParam = "";

            if (RadioButtonList1.SelectedIndex == 0)                 // Edit
            {
                queryParam = "?moduleID=" + mod.Id;
            }
            else                 // Delete
            {
                deleteMaterials(mod.Id);
                ModulesControl.removeModule(mod.Id);
                Session.Remove("EditModule");
            }

            Response.Redirect("editModule.aspx" + queryParam, true);
        }
        /// <summary>
        /// Handles clicks from links in the "My Modules" table.
        /// </summary>
        /// <param name="source"></param>
        /// <param name="e"></param>
        private void ModulesGrid_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
        {
            int moduleID = Convert.ToInt32(e.CommandArgument);

            if (e.CommandName == "Delete")
            {
                ModulesControl.removeModule(moduleID);
                bindModuleGrid();
            }
            else if (e.CommandName == "Edit")
            {
                if (!User.IsInRole("Administrator"))
                {
                    ModulesControl.checkOutModule(moduleID, User.Identity.Name);
                }
                Response.Redirect("editModule.aspx?moduleID=" + moduleID);
            }
            else if (e.CommandName == "Undo")
            {
                ModulesControl.undoCheckOut(moduleID);
                bindModuleGrid();
            }
        }
        private void Page_Load(object sender, System.EventArgs e)
        {
            if (!IsPostBack)
            {
                try {
                    string strModuleID = Request.Params["moduleID"];

                    if (strModuleID != null)
                    {
                        int moduleID = int.Parse(Request.Params["moduleID"]);
                        Modules.ModuleInfo modInfo = Modules.getModuleInfo(moduleID);
                        ModInfo     = modInfo;
                        isSubmitter = ModulesControl.isModuleSubmitter(User.Identity.Name, modInfo.Id);
                        isAuthor    = ModulesControl.isModuleAuthor(User.Identity.Name, modInfo.Id);
                        bool isEditor = User.IsInRole(UserRole.Editor.ToString());

                        // If the user is not an editor...
                        if (!isEditor)
                        {
                            if (modInfo.Status == ModuleStatus.PreviousVersion)
                            {
                                // If the module being viewed is a previous version, display the newest
                                // version of the module, and tell the user.
                                Modules.ModuleInfo curVer = Modules.getModuleCurrentVersion(modInfo.BaseId);
                                string             newUrl = "viewModule.aspx?moduleID=" + curVer.Id;
                                lblMessage.Text = "There is a <a href=\"" + newUrl + "\">newer version</a> of the module you are trying to access.  "
                                                  + "You will be directed to it momentarily.";
                                Response.AppendHeader("Refresh", REFRESH_DELAY + "; URL=" + newUrl);
                                disableModule();
                                return;
                            }
                            else if (modInfo.Status != ModuleStatus.Approved && !isSubmitter)
                            {
                                // If it is the newest version, but has not been approved
                                // and this user is not the submitter, do not let them view
                                // the module.
                                disableModule();
                                lblMessage.Text = "Module not available.";
                                return;
                            }
                        }

                        // Modules.Size

                        string[] labels = { "Lecture",
                                            "Lab",
                                            "Exercise",
                                            "Homework",
                                            "Other" };
                        string[] sizeText = { modInfo.LectureSize,
                                              modInfo.LabSize,
                                              modInfo.ExerciseSize,
                                              modInfo.HomeworkSize,
                                              modInfo.OtherSize };

                        ArrayList sizes = new ArrayList(NUM_SIZES);

                        for (int i = 0; i < NUM_SIZES; i++)
                        {
                            if (!sizeText[i].Equals(""))
                            {
                                sizes.Add("<strong>" + labels[i] + "</strong>: " + sizeText[i]);
                            }
                        }

                        SizeRepeater.DataSource = sizes;
                        SizeRepeater.DataBind();

                        // Authors

                        AuthorsRepeater.DataSource = Authors.getAll(modInfo.Id);
                        AuthorsRepeater.DataBind();

                        // Materials
                        // Since Materials aren't displayed as simply as other
                        // areas, some modification needs to be done
                        // Retrieve the materials that the user has the access level right to acquire
                        tempMats1 = getAccessLevelFilesList(moduleID);                         //Materials.getAll( moduleID );
                        ArrayList tempMats2   = new ArrayList();
                        ArrayList knownTitles = new ArrayList();
                        int       pos         = 0;

                        foreach (Materials.MaterialInfo mi in tempMats1)
                        {
                            int    position = mi.Link.LastIndexOf('.'); // temp value for extracting the title and extension
                            string title;                               // the title part of the filename
                            string extension;                           // the extension of the filename

                            if (position == -1)
                            {
                                title     = "(No Title)";
                                extension = mi.Link;
                            }
                            else
                            {
                                title     = mi.Link.Substring(0, position);
                                extension = getFormat(mi.Link.Substring(position + 1));
                            }

                            // this is the reference to the current material that will
                            // be added to the materials repeater in the html
                            string reference = "(<a href='Materials/" + mi.ModuleID + "/" + mi.Link +
                                               "' target='_blank'>" + extension + "</a>)";

                            // see if we've already come across this title
                            int index = knownTitles.IndexOf(title.ToLower());

                            if (index == -1)
                            {
                                // Means that the title hasn't already been found,
                                // so we need to add it as a new Material group
                                tempMats2.Add(new Materials.MaterialInfo(mi.Id, mi.IdentInfo, reference,
                                                                         mi.ModuleID, mi.RatingImage, mi.Rating,
                                                                         mi.AccessFlag));
                                knownTitles.Add(title.ToLower());
                            }
                            else
                            {
                                // Means that the title has already been found, so we
                                // need to add a link for this extra Material to the
                                // appropriate existing Material group
                                ((Materials.MaterialInfo)(tempMats2[index])).Link += " " + reference;
                            }
                        }

                        MaterialsRepeater.DataSource = tempMats2;
                        MaterialsRepeater.DataBind();

                        // Categories

                        CategoriesRepeater.DataSource = Categories.getAll(modInfo.Id);
                        CategoriesRepeater.DataBind();

                        // Prerequisites

                        PrereqRepeater.DataSource = Prerequisites.getAll(modInfo.Id);
                        PrereqRepeater.DataBind();

                        // Objectives

                        ObjectivesRepeater.DataSource = Objectives.getAll(modInfo.Id);
                        ObjectivesRepeater.DataBind();

                        // Topics

                        TopicsRepeater.DataSource = Topics.getAll(modInfo.Id);
                        TopicsRepeater.DataBind();

                        // Resources

                        IList resourcesList = Resources.getAll(modInfo.Id);

                        // If there are no resources, display text that says so.
                        if (resourcesList.Count == 0)
                        {
                            ResourcesRepeater.Controls.Add(new LiteralControl("<p>No resources.</p>"));
                        }
                        else
                        {
                            ResourcesRepeater.DataSource = resourcesList;
                            ResourcesRepeater.DataBind();
                        }

                        // See Also

                        IList seeAlsoList = SeeAlso.getAll(modInfo.Id);

                        // If there are no alternate modules, display text that says so.
                        if (seeAlsoList.Count == 0)
                        {
                            SeeAlsoRepeater.Controls.Add(new LiteralControl("<p>No alternate modules.</p>"));
                        }
                        else
                        {
                            SeeAlsoRepeater.DataSource = seeAlsoList;
                            SeeAlsoRepeater.DataBind();
                        }

                        // Ratings

                        if (modInfo.Status == ModuleStatus.Approved)
                        {
                            ModuleRatingInfo mci = ModuleRatings.getRating(modInfo.Id);
                            RateModuleControl1.RatingInfo = mci;

                            // Submitters and authors can't rate their own modules.
                            if (isSubmitter || isAuthor)
                            {
                                RateModuleControl1.AddRatingEnabled = false;
                                RatingsMessage.Text = "<p>You may not rate a module that " +
                                                      "you have submitted or are listed as an author of.</p>";
                            }
                            else
                            {
                                Rating rating = ModuleRatingsControl.getRatingForUser(User.Identity.Name, mci);
                                RateModuleControl1.UserRating = rating;
                            }
                        }
                        else
                        {
                            disableRatings();
                        }

                        // Related Modules
                        IList related = ModuleGroups.getRelatedModules(modInfo.BaseId);

                        if (related.Count == 0)
                        {
                            H21.Visible = false;
                        }
                        else
                        {
                            RelatedRepeater.DataSource = related;
                            RelatedRepeater.DataBind();
                        }
                    }
                    else
                    {
                        lblMessage.Text =
                            "An error occurred while attempting to get the requested module." +
                            "  No module was specified.  <a href=\"browseModules.aspx\">Browse</a>" +
                            " or <a href=\"search.aspx\">search</a> to select a module to view.";
                    }
                } catch (Exception ex) {
                    lblMessage.Text =
                        "An error occurred while attempting to get the requested module." +
                        "  " + ex.Message + " " + ex.StackTrace;
                }
            }
        }
 /// <summary>
 /// Ignore changes to the module and undo the module check out.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 protected void CancelBtn_Click(object sender, System.EventArgs e)
 {
     ModulesControl.undoCheckOut(ModuleID);
     Response.Redirect("MyAccount.aspx", true);
 }
        /// <summary>
        /// Save a new module or changes to an existing module.
        /// </summary>
        /// <param name="status">The status to designate for the module.</param>
        private Modules.ModuleInfo saveModule(ModuleStatus status)
        {
            // tells whether old data exists that needs to be
            // removed before adding any new data
            bool removePrevious = false;

            // tells whether user is just updating an existing
            // module or if they want to create a new module
            // (possibly a new version of an existing module)
            bool isUpdate = false;

            Modules.ModuleInfo mi = createModuleInfo();

            ModuleID           = mi.Id;
            ErrorMessage.Text += "Getting base ID for module: " + ModuleID;

            if (ModuleID > 0)
            {
                mi.BaseId = Modules.getModuleInfo(ModuleID).BaseId;
            }
            else
            {
                mi.BaseId = 0;
            }

            mi.Status      = status;
            mi.Submitter   = User.Identity.Name;
            mi.SubmitterID = UserAccounts.getUserInfo(User.Identity.Name).SubmitterID;

            switch (ModuleEditType)
            {
            case EditType.New:

                isUpdate = false;

                break;

            case EditType.InProgress:

                isUpdate       = true;
                removePrevious = true;

                break;

            case EditType.Approved:
                Modules.ModuleInfo oldModule = Modules.getModuleInfo(ModuleID);
                mi.BaseId = oldModule.BaseId;
                // If this module was previously Approved, and an admin changed it,
                // just update the module without creating a new version.
                if (User.Identity.IsAuthenticated && User.IsInRole(UserRole.Admin.ToString()))
                {
                    string modSubmitter = oldModule.Submitter;
                    // If this module is the admin's own, behave as if not an admin.
                    // Admins deserve multiple versions too.
                    if (User.Identity.Name.Equals(modSubmitter))
                    {
                        isUpdate   = false;
                        mi.Version = oldModule.Version + 1;
                    }
                    else
                    {
                        mi.Submitter   = modSubmitter;
                        mi.SubmitterID = oldModule.SubmitterID;

                        isUpdate   = true;
                        mi.Version = oldModule.Version;
                    }
                }
                // If this module was previously Approved, and a non-admin changed
                // it, create a new version of the module, and check it out accordingly.
                else
                {
                    isUpdate = false;
                    MaterialsControl1.retrieveMaterials(oldModule.Id);
                    mi.Version = oldModule.Version + 1;
                }
                removePrevious = true;

                break;
            }

            try
            {
                ModuleID = ModulesControl.checkInModule(mi, isUpdate);

                ErrorMessage.Text += " Assigned ModuleID = " + ModuleID + ".  ";

                mi.Id = ModuleID;

                foreach (IEditControl ec in editControls)
                {
                    ec.insertAll(ModuleID, removePrevious);
                }

                /** HANDLE THE VARIANTS **/

                // is true if this module is new OR a variant is chosen (including <None>)
                if (VariantOf != -1)
                {
                    int groupID = ModuleGroups.getGroupID(mi.BaseId);

                    // if this module was reset as a variant of the same module
                    // as before, or if it was set as a variant of a module in
                    // the same group as it already is in, do nothing
                    if (groupID != -1 && groupID == ModuleGroups.getGroupID(VariantOf))
                    {
                    }
                    // if this module was already in a group by itself, and the
                    // user tries to put it in a new group by itself, ignore
                    // the request and do nothing
                    else if (groupID != -1 && VariantOf == 0 && ModuleGroups.getRelatedModules(mi.BaseId).Count == 0)
                    {
                    }
                    else
                    {
                        // if <None> was chosen, add this module to its own module group
                        if (VariantOf == 0)
                        {
                            ModuleGroups.addToNew(mi.BaseId);
                        }
                        // else add this module to the group that was chosen
                        // SQL code resolves duplicates
                        else
                        {
                            ModuleGroups.addToExisting(mi.BaseId, VariantOf);
                        }
                    }
                }
                else
                {
                    // If the module was not a variant, add this module to its own module group
                    ModuleGroups.addToNew(mi.BaseId);
                }
            }
            catch (Exception e)
            {
                string message = "An error occurred while saving your module.";

                // If a new module was being created and there was an error, remove
                // the module (and by cascading, any added pieces).
                if (ModuleEditType == EditType.New && ModuleID != 0)
                {
                    ModulesControl.removeModule(ModuleID);
                    message += "  Module was not saved.  Review the module and try to resubmit it.";
                }
                else
                {
                    message       += "  All of your changes were not saved.  Review the module and try to resubmit it.";
                    ModuleEditType = EditType.InProgress;
                }

                // send an email to admins reporting the error
                Email msg = Emails.getEmail(EmailType.CriticalError);
                Emails.formatEmail(msg, mi.Submitter, mi.Id);
                Emails.formatEmailBody(msg, e.StackTrace + "::" + e.Message);
                MailMessage mail = Emails.constructErrorMessage(msg, Globals.AdminsEmail);
                SmtpMail.SmtpServer = AspNetForums.Components.Globals.SmtpServer;
                SmtpMail.Send(mail);

                message += " An e-mail reporting the error has been sent to the SWEnet Administrators.";
                throw new Exception(message, e);
            }

            return(mi);
        }
        /// <summary>
        /// Handles the Submit button-click event.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void SubmitBtn_Click(object sender, EventArgs e)
        {
            string message = "";
            bool   isValid = validate();

            // If invalid/incomplete data exists, alert the user to the problem,
            // redirect them to the right location, and don't attempt to save
            // or submit the module. (we don't save because duplicate items may
            // be the cause of invalid data, and the DB can't handle duplicates)
            if (!isValid)
            {
                ErrorMessage.Text = "Some required items are missing or invalid.  " +
                                    "Please review the following fields before attempting to submit again.";

                // Now we should find where the first error is and redirect the
                // user to that upload step
                if (!(TitleValidator.IsValid && AbstractValidator.IsValid && CategoriesControl1.validate()))
                {
                    UploadStep = 0;
                }
                else if (!AuthorsControl1.validate())
                {
                    UploadStep = 1;
                }
                else if (!(PrerequisitesControl1.validate() && ObjectivesControl1.validate() && TopicsControl1.validate()))
                {
                    UploadStep = 2;
                }
                else if (!(MaterialsControl1.validate() && ResourcesControl1.validate()))
                {
                    UploadStep = 3;
                }
                else if (!(SeeAlsoControl1.validate() && CheckInValidator.IsValid))
                {
                    UploadStep = 4;
                }
                else
                {
                    ErrorMessage.Text = "Could not locate problem.";
                    UploadStep        = 4;
                }

                StepLbl.Text = "" + (UploadStep + 1);
                toggleButtonsAndPanels(UploadStep);

                NextBtn.CausesValidation = true;
                return;
            }

            // If the module was valid, save it and submit it for approval.
            // (if an admin is submitting, it doesn't need approval)
            try
            {
                ModuleStatus       status;
                Modules.ModuleInfo module;

                if ((User.Identity.IsAuthenticated && User.IsInRole(UserRole.Admin.ToString())))
                {
                    status = ModuleStatus.Approved;
                    module = saveModule(status);
                    ModulesControl.approveModule(module.Id);
                }
                else
                {
                    status = ModuleStatus.PendingApproval;
                    module = saveModule(status);

                    // Send a Module Approval notification to the editors
                    Email email = Emails.getEmail(EmailType.ApproveModule);
                    Emails.formatEmail(email, User.Identity.Name, module.Id);
                    MailMessage msg = Emails.constructEditorsMail(email, Globals.AdminsEmail);
                    SmtpMail.SmtpServer = AspNetForums.Components.Globals.SmtpServer;
                    SmtpMail.Send(msg);
                }

                // Postprocessing

                // Only reset if everything worked.  Otherwise, the data will
                // be saved so the user may try again.
                reset();

                Response.Redirect("uploadResult.aspx?moduleID=" + ModuleID, true);
            }
            catch (Exception ex)
            {
                ErrorMessage.Text = ex.Message + "..." + ex.StackTrace;
            }
        }