protected void DenyFormBtn_Click(object sender, EventArgs e) { FormResult.Visible = false; //updating a form not, creating it if (Request.QueryString["pfid"] != null) { string denyText = DenyReason.Text; int formId = int.Parse(Request.QueryString["pfid"]); Form f = FormUtil.GetForm(formId); Project p = ProjectUtil.GetProject(f.ProjectId); User user = (User)Session["User"]; FormUtil.DenyForm(formId, denyText, user.RoleId); FormResult.CssClass = "success"; FormResult.Text = "Denied form " + f.FormName; if (denyText.Length > 0) { FormResult.Text += ": " + denyText; } else { denyText = "None specified"; } Log.Info(user.Identity + " denied " + CompanyUtil.GetCompanyName(p.CompanyId) + "'s form " + f.FormName + " - " + p.Name + " with reason: " + denyText); Response.Redirect("Forms.aspx?pfid=" + formId); FormResult.Visible = true; } }
//client submitting form protected void SubmitFormBtn_Click(object sender, EventArgs e) { SaveForm(); FormResult.Visible = false; string formJson = formViewerData.Value.ToString(); if (formJson.Length > 0 && formJson != "undefined") { //updating a form not, creating it if (Request.QueryString["pfid"] != null) { int formId = int.Parse(Request.QueryString["pfid"]); Form f = FormUtil.GetForm(formId); FormUtil.SubmitForm(formId, f.FormName, formJson); User user = (User)Session["User"]; Log.Info(user.Identity + " submitted " + CompanyUtil.GetCompanyName(user.CompanyId) + "'s form " + f.FormName + " with " + formJson); FormResult.CssClass = "success"; FormResult.Text = "Submitted form " + f.FormName; Response.Redirect("Forms.aspx?pfid=" + formId); } } else { FormResult.CssClass = "error"; FormResult.Text = "Please fill out the form"; } FormResult.Visible = true; }
protected void CoachDownloadBtn_Click(object sender, EventArgs e) { if (Request.QueryString["pfid"] != null) { int formId = int.Parse(Request.QueryString["pfid"]); Form f = FormUtil.GetForm(formId); Project p = ProjectUtil.GetProject(f.ProjectId); FormResult.CssClass = "success"; FormResult.Text = "Denied form " + f.FormName; User user = (User)Session["User"]; Log.Info(user.Identity + " downloaded files from " + CompanyUtil.GetCompanyName(p.CompanyId) + "'s form " + f.FormName + " - " + p.Name); SendFile(f.FilePath); FormResult.Visible = true; } }
private void SaveForm() { FormResult.Visible = false; string formJson = formViewerData.Value.ToString(); if (formJson.Length > 0 && formJson != "undefined") { //updating a form not, creating it if (Request.QueryString["pfid"] != null) { int formId = int.Parse(Request.QueryString["pfid"]); Form f = FormUtil.GetForm(formId); Project p = ProjectUtil.GetProject(f.ProjectId); FormUtil.UpdateForm(formId, f.FormName, formJson); User user = (User)Session["User"]; Log.Info(user.Identity + " edited " + CompanyUtil.GetCompanyName(user.CompanyId) + " a form" + f.FormName + " from project " + p.Name + " with " + formJson); if (fileInputName.Value.ToString().Length > 0) { string localName = fileUploadName.Value.ToString(); string fileType = localName.Split('.')[1]; string path = CompanyUtil.GetCompanyName(user.CompanyId) + "-" + p.Name + "-" + f.FormName + "." + fileType; SaveFiles(path); f = FormUtil.UpdateFormFile(f, path, localName); Log.Info(user.Identity + " edited " + CompanyUtil.GetCompanyName(user.CompanyId) + " a form" + f.FormName + " from project " + p.Name + " added a file " + f.FilePath); } FormResult.CssClass = "success"; FormResult.Text = "Updated form " + f.FormName; } } else { FormResult.CssClass = "error"; FormResult.Text = "Please fill out the form"; } FormResult.Visible = true; }
protected void ProjectFileDownloader_Click(object sender, EventArgs e) { if (Request.QueryString["pid"] != null) { int projId = int.Parse(Request.QueryString["pid"]); Project p = ProjectUtil.GetProject(projId); Company c = CompanyUtil.GetCompany(p.CompanyId); WorkflowModel w = WorkflowUtil.GetWorkflow(p.WorkflowId); List <WorkflowComponent> workflowComponents = WorkflowComponentUtil.GetWorkflowComponents(w.WorkflowId); string zipPath = String.Format("{0} - {1} - {2}.zip", w.WorkflowName, p.Name, CompanyUtil.GetCompanyName(p.CompanyId)); //delete the zip if it exists if (File.Exists(zipPath)) { File.Delete(zipPath); } using (ZipArchive zip = ZipFile.Open(zipPath, ZipArchiveMode.Create)) { //for each form get the file foreach (WorkflowComponent wc in workflowComponents) { Form f = FormUtil.GetProjectFormByTemplate(wc.FormID, projId); if (f.FilePath.Length > 0) { string fileType = f.FilePath.Split('.')[1]; string fileName = string.Format("{0} {1} Attachment.{2}", CompanyUtil.GetCompanyName(p.CompanyId), f.FormName, fileType); zip.CreateEntryFromFile(f.FilePath, fileName); } string pdfName = string.Format("{0} - {1} - {2}.pdf", w.WorkflowName, f.FormName, c.CompanyName); string pdfPath = string.Format("./PDFGen/{0}", pdfName); zip.CreateEntryFromFile(pdfPath, pdfName); } } SendFile(zipPath); } }
protected void CreateProjectBtn_Click(object sender, EventArgs e) { int companyId = int.Parse(SelectedCompany.Value); int workflowId = int.Parse(SelectedWorkflow.Value); int coachId = int.Parse(SelectedCoach.Value); string projectName = ProjectName.Text; string projectNotes = ProjectNotes.Text; if (projectName.Length > 0) { if (companyId != -1) { if (workflowId != -1) { if (coachId != -1) { if (Request.QueryString["pid"] != null) { int projId = int.Parse(Request.QueryString["pid"]); Project p = ProjectUtil.UpdateProject(projId, projectName, companyId, coachId, projectNotes); User user = (User)Session["User"]; Log.Info(user.Identity + " updated project " + projectName + " with a Workflow of " + WorkflowUtil.GetWorklowName(workflowId) + " assigned to " + CompanyUtil.GetCompanyName(companyId) + " under Coach " + UserUtil.GetCoachName(coachId) + " with notes: " + projectNotes); Response.Redirect("Projects.aspx?pid=" + p.ProjectId); } else { Project p = ProjectUtil.CreateProject(projectName, workflowId, companyId, coachId, projectNotes); User user = (User)Session["User"]; Log.Info(user.Identity + " created project " + projectName + " with a Workflow of " + WorkflowUtil.GetWorklowName(workflowId) + " assigned to " + CompanyUtil.GetCompanyName(companyId) + " under Coach " + UserUtil.GetCoachName(coachId) + " with notes: " + projectNotes); Response.Redirect("Projects.aspx?pid=" + p.ProjectId); } } } } } else { //enter valid name } }
protected void ApproveFormBtn_Click(object sender, EventArgs e) { FormResult.Visible = false; //updating a form not, creating it if (Request.QueryString["pfid"] != null) { int formId = int.Parse(Request.QueryString["pfid"]); Form f = FormUtil.GetForm(formId); Project p = ProjectUtil.GetProject(f.ProjectId); WorkflowModel w = WorkflowUtil.GetWorkflow(p.WorkflowId); User user = (User)Session["User"]; FormUtil.ApproveForm(formId, user.RoleId); Log.Info(user.Identity + " approved " + CompanyUtil.GetCompanyName(p.CompanyId) + "'s form " + f.FormName + " - " + p.Name); FormResult.CssClass = "success"; FormResult.Text = "Approved form " + f.FormName; FormResult.Visible = true; //prep html for pdf generation HtmlDocument doc = new HtmlDocument(); string pdfName = string.Format("{0} - {1} - {2}", w.WorkflowName, f.FormName, CompanyUtil.GetCompanyName(p.CompanyId)); string html = formViewerData.Value; if (html.Contains("user-data")) { html = html.Replace("user-data", "value"); } if (html.Contains("\"")) { html = html.Replace("\"", "'"); } doc.LoadHtml(html); doc.Save("PDFGen/" + CompanyUtil.GetCompanyName(p.CompanyId) + "_" + f.FormName + "_" + p.Name + ".html"); //radiobtns foreach (HtmlNode link in doc.DocumentNode.SelectNodes("//input[@type]")) { HtmlAttribute type = link.Attributes["type"]; if (type.Value.Equals("radio")) { if (link.Attributes.Contains("checked")) { } else { if (link.Attributes.Contains("id")) { string toDelId = link.Attributes["id"].Value; foreach (HtmlNode label in doc.DocumentNode.SelectNodes("//label[@for]")) { string forId = label.Attributes["for"].Value; if (forId.Equals(toDelId)) { label.Remove(); } } } } link.Attributes.Remove("value"); } } //text fields, dates, + similar foreach (HtmlNode link in doc.DocumentNode.SelectNodes("//input[@value]")) { HtmlAttribute value = link.Attributes["value"]; if (link.Attributes.Contains("placeholder")) { link.Attributes.Remove("placeholder"); } string val = value.Value; link.InnerHtml = val; link.Attributes.Remove("value"); } //text areas foreach (HtmlNode link in doc.DocumentNode.SelectNodes("//textarea[@value]")) { HtmlAttribute value = link.Attributes["value"]; if (link.Attributes.Contains("placeholder")) { link.Attributes.Remove("placeholder"); } string val = value.Value; link.InnerHtml = val; link.Attributes.Remove("value"); } //attached files if (f.FilePath.Length > 0) { foreach (HtmlNode link in doc.DocumentNode.SelectNodes("//input[@type]")) { HtmlAttribute type = link.Attributes["type"]; if (type.Value.Equals("file")) { string fileType = f.FilePath.Split('.')[1]; string fileName = string.Format("{0} {1} Attachment.{2}", CompanyUtil.GetCompanyName(p.CompanyId), f.FormName, fileType); link.InnerHtml = "See " + fileName; } } } doc.Save("PDFGen/" + CompanyUtil.GetCompanyName(p.CompanyId) + "_" + f.FormName + "_" + p.Name + ".html"); doc.Load("PDFGen/" + CompanyUtil.GetCompanyName(p.CompanyId) + "_" + f.FormName + "_" + p.Name + ".html"); html = doc.Text; //pdf gen PDFGen.CreateHTMLPDF(html, pdfName); Response.Redirect("Forms.aspx?pfid=" + formId); } }
//Register a new user in the system protected void RegisterBtn_Click(object sender, EventArgs e) { UserCreateResult.Visible = false; EmailError.Visible = false; NameError.Visible = false; PasswordError.Visible = false; RoleCompanyError.Visible = false; string email = Email.Text; string firstName = FirstName.Text; string lastName = LastName.Text; string pass = Password.Text; string pass2 = PasswordRepeat.Text; int roleId = int.Parse(SelectedRole.Value); int companyId = int.Parse(SelectedCompany.Value); string displayName = ""; bool verificationEmail = true; //Validate that the logged in user has permissions to do this //Validate the new user's information //Create the new user account //Send an email to the new user //checks that a role was selected for the user if (!UserUtil.DoesUserExist(email)) { if (firstName.Length > 0 && lastName.Length > 0) { if (roleId != -1) { if (companyId != -1) { if (pass.Equals(pass2)) { if (pass.Length > 7) { int validPass = ValidatePasswordSecurity(pass); if (validPass == 0) { //creates the user in firebase Firebase.Auth.User fbUser = FirebaseUtil.CreateNewUser(email, pass, displayName, verificationEmail); //if the user already exists in firebase, try to log them in if (fbUser == null) { fbUser = FirebaseUtil.LoginUser(email, pass); } if (fbUser != null) { User u = UserUtil.CreateUser(roleId, companyId, email, firstName, lastName); User user = (User)Session["User"]; if (user != null) { Log.Info(user.Identity + " created a new " + RoleUtil.GetRole(roleId).RoleName + " account under " + CompanyUtil.GetCompanyName(companyId) + " assigned to " + firstName + " " + lastName + " - " + email); } else { Log.Info("System created a new " + RoleUtil.GetRole(roleId).RoleName + " account under " + CompanyUtil.GetCompanyName(companyId) + " assigned to " + firstName + " " + lastName + " - " + email); } u.FirebaseUser = fbUser; //display user created msg UserCreateResult.Visible = true; UserCreateResult.Text = "Successfully created user " + u.Identity; } else { UserCreateResult.CssClass = "error"; UserCreateResult.Visible = true; UserCreateResult.Text = "Error creating user in Firebase"; } } else { PasswordError.Visible = true; if (validPass == 1) { PasswordError.Text = "Password must contain at least 1 uppercase"; } else if (validPass == 2) { PasswordError.Text = "Password must contain at least 1 lowercase"; } else if (validPass == 3) { PasswordError.Text = "Password must contain at least 1 number"; } else { PasswordError.Text = "Unknown password error"; } } } else { //display user failed to be created msg PasswordError.Visible = true; PasswordError.Text = "Password must be at least 8 chars"; } } else { //throw error, passwords don't match PasswordError.Visible = true; PasswordError.Text = "Passwords don't match"; } } else { //throw error, please select company for user RoleCompanyError.Visible = true; RoleCompanyError.Text = "Please select a company"; } } else { //throw error, please select role for new user RoleCompanyError.Visible = true; RoleCompanyError.Text = "Please select a role"; } } else { NameError.Visible = true; NameError.Text = "Please enter a first and last name"; } } else { EmailError.Visible = true; EmailError.Text = "Email already in use"; } ClearFields(); }