private void MakeAdminText(List <Project> projects, string projectNode, int i) { User coach = UserUtil.GetCoach(projects[i].CoachId); WorkflowModel workflow = WorkflowUtil.GetWorkflow(projects[i].WorkflowId); projectNode = "<div class=\"item\"><div class=\"ui small image\"><i class=\"huge inbox icon\"/></i></div>"; projectNode += "<div class=\"content\"><a class=\"header\" href='Projects.aspx?pid=" + projects[i].ProjectId + "'>" + projects[i].Name + "</a><div class=\"meta\">"; projectNode += "<span class=\"stay\">" + coach.FullName + " | " + workflow.WorkflowName + " | <a href='Projects.aspx?pid=" + projects[i].ProjectId + "&edit=1'>Edit Project</a>" + " | <a href='Projects.aspx?pid=" + projects[i].ProjectId + "&del=1'>Delete Project</a></span></div><div class=\"description\">"; projectNode += projects[i].Notes + "</div></div></div>"; projectList.InnerHtml += projectNode; projectNode = ""; count++; }
private void SaveComponents(int workflowId) { User user = (User)Session["User"]; WorkflowModel w = WorkflowUtil.GetWorkflow(workflowId); List <WorkflowComponent> compList = WorkflowComponentUtil.GetWorkflowComponents(workflowId); int i = 0; foreach (Panel panelControls in WorkflowSteps.Controls.OfType <Panel>()) { string id = panelControls.ID.Replace("stepControl", string.Empty); Panel div = (Panel)panelControls.FindControl("title" + id); TextBox stepTitle = (TextBox)div.FindControl("stepTitle" + id); DropDownList formSelector = (DropDownList)panelControls.FindControl("formSelector" + id); int formId = int.Parse(formSelector.SelectedValue); WorkflowComponentUtil.UpdateWorkflowComponent(compList[i].WFComponentID, stepTitle.Text, formId); Log.Info(user.Identity + " updated " + w.WorkflowName + " with component " + stepTitle.Text + " assigned to form " + FormUtil.GetFormTemplate(formId).FormName); i++; } }
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 Page_Load(object sender, EventArgs e) { //validates that the user is logged in if (Session["User"] != null) { User user = (User)Session["User"]; userLbl.Text = user.FullName; if (user.RoleId == 4) { AdminBtn.Visible = true; } if (user.RoleId == 1) { CreateClientWorkflowList(user.CompanyId); CreateNewWorkflowBtn.Visible = false; } else if (user.RoleId == 2) { CreateWorkflowList(user.UserId); CreateNewWorkflowBtn.Visible = false; } else if (user.RoleId == 4 || user.RoleId == 3) { CreateAdminWorkflowList(); } //loads the selected form if there is one if (Request.QueryString["wid"] != null) { int workflowId = int.Parse(Request.QueryString["wid"]); WorkflowModel w = WorkflowUtil.GetWorkflow(workflowId); //admin and trying to del if (Request.QueryString["del"] != null && user.RoleId == 4) { if (WorkflowUtil.DeleteWorkflow(w.WorkflowId)) { Log.Info(user.Identity + " deleted a workflow template " + w.WorkflowName); ReloadSection(); } else { WorkflowError.Visible = true; WorkflowError.Text = "Unable to delete Workflow " + w.WorkflowName; } } else { workflowListing.Visible = false; //if they are trying to edit and they are admin, show workflow builder if (Request.QueryString["edit"] != null && user.RoleId == 4) { if (WorkflowUtil.EditableWorkflow(w.WorkflowId)) { workflowBuilder.Visible = true; WorkflowName.Text = w.WorkflowName; CreateWorkflowBtn.Text = "Update Workflow"; LoadWorkflowSteps(workflowId); } else { workflowListing.Visible = true; WorkflowError.Visible = true; WorkflowError.Text = "Unable to edit Workflow " + w.WorkflowName + " while projects are assigned to it"; } } //otherwise just show the workflow viewer else { workflowViewer.Visible = true; List <WorkflowComponent> comps = WorkflowComponentUtil.GetWorkflowComponents(w.WorkflowId); ProjectInformation(w, comps); } } } //if theyre an admin and trying to make a new form else if (Request.QueryString["edit"] != null && Request.QueryString["wid"] == null && user.RoleId == 4) { workflowListing.Visible = false; workflowBuilder.Visible = true; } } else { Response.Redirect("Login.aspx"); } }
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); } }