예제 #1
0
        /// <summary>
        /// Handles the ItemDataBound event of the lstFAQs control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Web.UI.WebControls.DataListItemEventArgs" /> instance containing the event data.</param>
        protected void lstFAQs_ItemDataBound(object sender, System.Web.UI.WebControls.DataListItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                FAQsInfo FaqItem   = (FAQsInfo)e.Item.DataItem;
                string   question  = HtmlDecode(new FAQsController().ProcessTokens(FaqItem, this.QuestionTemplate));
                Label    lblAnswer = (Label)(e.Item.FindControl("A2"));

                try
                {
                    if (SupportsClientAPI) // AJAX Mode
                    {
                        //change clientidmode, the old answerlabel still has the id from all categories.
                        lblAnswer.ClientIDMode = ClientIDMode.Static;
                        string answerID = string.Format("DNN_FAQ_{0}_{1}", ModuleId, FaqItem.ItemID);
                        lblAnswer.ID = answerID;

                        ((LinkButton)(e.Item.FindControl("lnkQ2"))).Visible = false;

                        HtmlAnchor linkQuestion = (HtmlAnchor)(e.Item.FindControl("Q2"));
                        linkQuestion.InnerHtml = question;

                        // Utilize the ClientAPI to create ajax request
                        string ClientCallBackRef = ClientAPI.GetCallbackEventReference(this, FaqItem.ItemID.ToString(),
                                                                                       "GetFaqAnswerSuccess",
                                                                                       "\'" + lblAnswer.ClientID + "\'",
                                                                                       "GetFaqAnswerError");
                        //Set CallBackRef ClientScriptBlock
                        string jsClientCallBackRef = string.Format("var ClientCallBackRef{0}= \"{1}\";", lblAnswer.ClientID, ClientCallBackRef);
                        Page.ClientScript.RegisterClientScriptBlock(this.GetType(), string.Format("ClientCallBackRef{0}", lblAnswer.ClientID), jsClientCallBackRef, true);

                        //Set LoadingTemplate ClientScriptBlock
                        string jsLoadingTemplate = string.Format("var LoadingTemplate{0}= '{1}';", lblAnswer.ClientID, HtmlDecode(this.LoadingTemplate));
                        Page.ClientScript.RegisterClientScriptBlock(this.GetType(), string.Format("LoadingTemplate{0}", lblAnswer.ClientID), jsLoadingTemplate, true);

                        //Define javascript action
                        string AjaxJavaScript = "javascript: SetAnswerLabel('" + lblAnswer.ClientID + "');";

                        linkQuestion.Attributes.Add("onClick", AjaxJavaScript);
                    }
                    else // Postback Mode
                    {
                        ((HtmlAnchor)(e.Item.FindControl("Q2"))).Visible = false;

                        LinkButton linkQuestion = (LinkButton)(e.Item.FindControl("lnkQ2"));
                        linkQuestion.Text = question;
                    }
                    // If only one question (Requestparameter faqid) show answer immediately
                    if (RequestFaqId > -1)
                    {
                        IncrementViewCount(FaqItem.ItemID);
                        lblAnswer.Text = HtmlDecode(new FAQsController().ProcessTokens(FaqItem, this.AnswerTemplate));
                    }
                }
                catch (Exception exc) //Module failed to load
                {
                    DotNetNuke.Services.Exceptions.Exceptions.ProcessModuleLoadException(this, exc);
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Increments the view count for one FAQ record.
        /// </summary>
        /// <param name="faqId">The ItemID of the FAQ to increment.</param>
        public void IncrementViewCount(int faqId)
        {
            FAQsInfo faq = GetFAQ(faqId);

            faq.ViewCount++;
            UpdateFAQ(faq);
        }
예제 #3
0
 /// <summary>
 /// Updates the FAQ in the database.
 /// </summary>
 /// <param name="faq">Info object containing faq information</param>
 public void UpdateFAQ(FAQsInfo faq)
 {
     using (IDataContext ctx = DataContext.Instance())
     {
         var rep = ctx.GetRepository <FAQsInfo>();
         rep.Update(faq);
     }
 }
예제 #4
0
 /// <summary>
 /// Adds a new FAQ to the database.
 /// </summary>
 /// <param name="faq">Info object containing faq information</param>
 /// <returns>ItemID (primary key) of new FAQ record</returns>
 public int AddFAQ(FAQsInfo faq)
 {
     using (IDataContext ctx = DataContext.Instance())
     {
         var rep = ctx.GetRepository <FAQsInfo>();
         rep.Insert(faq);
         return(faq.ItemID);
     }
 }
예제 #5
0
        /// <summary>
        /// Handles the Click event of the cmdUpdate control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs" /> instance containing the event data.</param>
        protected void cmdUpdate_Click(System.Object sender, System.EventArgs e)
        {
            try
            {
                // We do not allow for script or markup in the question
                PortalSecurity objSecurity = new PortalSecurity();
                string         question    = objSecurity.InputFilter(txtQuestionField.Text, PortalSecurity.FilterFlag.NoScripting | PortalSecurity.FilterFlag.NoMarkup);
                string         answer      = objSecurity.InputFilter(teAnswerField.Text, PortalSecurity.FilterFlag.NoScripting);

                FAQsController faqsController = new FAQsController();
                FAQsInfo       faq;

                int?newCatID = null;
                if (drpCategory.SelectedValue != "-1")
                {
                    newCatID = int.Parse(drpCategory.SelectedValue);
                }

                // Do we add of update? The Id will tell us
                if (FaqId != -1)
                {
                    faq              = faqsController.GetFAQ(FaqId);
                    faq.CategoryId   = newCatID;
                    faq.FaqHide      = chkFaqHide.Checked;
                    faq.PublishDate  = datepickerPublishDate.SelectedDate;
                    faq.ExpireDate   = datepickerExpireDate.SelectedDate;
                    faq.Question     = question;
                    faq.Answer       = answer;
                    faq.DateModified = DateTime.Now;
                    faqsController.UpdateFAQ(faq);
                }
                else
                {
                    faq = new FAQsInfo
                    {
                        ItemID        = FaqId,
                        CategoryId    = newCatID,
                        FaqHide       = chkFaqHide.Checked,
                        PublishDate   = datepickerPublishDate.SelectedDate,
                        ExpireDate    = datepickerExpireDate.SelectedDate,
                        Question      = question,
                        Answer        = answer,
                        CreatedByUser = UserId.ToString(),
                        ViewCount     = 0,
                        DateModified  = DateTime.Now,
                        ModuleID      = ModuleId,
                        CreatedDate   = DateTime.Now
                    };
                    faqsController.AddFAQ(faq);
                }
                Response.Redirect(Globals.NavigateURL(), true);
            }
            catch (Exception exc) //Module failed to load
            {
                Exceptions.ProcessModuleLoadException(this, exc);
            }
        }
예제 #6
0
        /// <summary>
        /// Handles the Load event of the Page control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs" /> instance containing the event data.</param>
        protected void Page_Load(System.Object sender, System.EventArgs e)
        {
            if (Page.IsPostBack == false)
            {
                cmdDelete.Attributes.Add("onClick", "javascript:return confirm(\'" + Localization.GetString("DeleteItem") + "\');");

                FAQsController FAQsController = new FAQsController();

                PopulateCategoriesDropDown();

                if (!Null.IsNull(FaqId))
                {
                    FAQsInfo FaqItem = FAQsController.GetFAQ(FaqId);

                    if (FaqItem != null)
                    {
                        if (FaqItem.CategoryId != null)
                        {
                            drpCategory.SelectedValue = FaqItem.CategoryId.ToString();
                        }

                        chkFaqHide.Checked = FaqItem.FaqHide;
                        datepickerPublishDate.SelectedDate = FaqItem.PublishDate;
                        datepickerExpireDate.SelectedDate  = FaqItem.ExpireDate;
                        teAnswerField.Text    = FaqItem.Answer;
                        txtQuestionField.Text = FaqItem.Question;
                        UserInfo user = UserController.GetUserById(PortalId, Convert.ToInt32(FaqItem.CreatedByUser));
                        ctlAudit.CreatedByUser = (user != null ? user.DisplayName : "");
                        if (FaqItem.DateModified == Null.NullDate)
                        {
                            ctlAudit.CreatedDate = FaqItem.CreatedDate.ToString();
                        }
                        else
                        {
                            ctlAudit.CreatedDate = FaqItem.DateModified.ToString();
                        }
                    }
                    else
                    {
                        Response.Redirect(Globals.NavigateURL(), true);
                    }
                }
                else
                {
                    cmdDelete.Visible = false;
                    ctlAudit.Visible  = false;
                }
            }
        }
예제 #7
0
        /// <summary>
        /// Processes the faq tokens.
        /// </summary>
        /// <param name="faqItem">The FAQ item.</param>
        /// <param name="template">The template.</param>
        /// <returns>Answers in which all tokens are processed</returns>
        public string ProcessTokens(FAQsInfo faqItem, string template)
        {
            // For compability issues we need to convert old tokens to new tokens (sigh...)
            StringBuilder compatibleTemplate = new StringBuilder(template);

            compatibleTemplate.Replace("[ANSWER]", "[FAQ:ANSWER]");
            compatibleTemplate.Replace("[CATEGORYNAME]", "[FAQ:CATEGORYNAME]");
            compatibleTemplate.Replace("[CATEGORYDESC]", "[FAQ:CATEGORYDESC]");
            compatibleTemplate.Replace("[USER]", "[FAQ:USER]");
            compatibleTemplate.Replace("[VIEWCOUNT]", "[FAQ:VIEWCOUNT]");
            compatibleTemplate.Replace("[DATECREATED]", "[FAQ:DATECREATED]");
            compatibleTemplate.Replace("[DATEMODIFIED]", "[FAQ:DATEMODIFIED]");
            compatibleTemplate.Replace("[QUESTION]", "[FAQ:QUESTION]");
            compatibleTemplate.Replace("[INDEX]", "[FAQ:INDEX]");

            // Now we can call TokenReplace
            FAQsTokenReplace tokenReplace = new FAQsTokenReplace(faqItem);

            return(tokenReplace.ReplaceFAQsTokens(template));
        }
예제 #8
0
        /// <summary>
        /// Raises the client API callback event.
        /// </summary>
        /// <param name="eventArgument">The event argument.</param>
        /// <returns></returns>
        public string RaiseClientAPICallbackEvent(string eventArgument)
        {
            try
            {
                int            FaqId   = int.Parse(eventArgument);
                FAQsController objFAQs = new FAQsController();

                IncrementViewCount(FaqId);

                FAQsInfo FaqItem = objFAQs.GetFAQ(FaqId);

                return(HtmlDecode(objFAQs.ProcessTokens(FaqItem, this.AnswerTemplate)));
            }
            catch (Exception exc)
            {
                DotNetNuke.Services.Exceptions.Exceptions.ProcessModuleLoadException(this, exc);
            }

            return("");
        }
예제 #9
0
 /// <summary>
 /// Updates the FAQ in the database.
 /// </summary>
 /// <param name="faq">Info object containing faq information</param>
 public void UpdateFAQ(FAQsInfo faq)
 {
     using (IDataContext ctx = DataContext.Instance())
     {
         var rep = ctx.GetRepository<FAQsInfo>();
         rep.Update(faq);
     }
 }
예제 #10
0
 /// <summary>
 /// Adds a new FAQ to the database.
 /// </summary>
 /// <param name="faq">Info object containing faq information</param>
 /// <returns>ItemID (primary key) of new FAQ record</returns>
 public int AddFAQ(FAQsInfo faq)
 {
     using (IDataContext ctx = DataContext.Instance())
     {
         var rep = ctx.GetRepository<FAQsInfo>();
         rep.Insert(faq);
         return faq.ItemID;
     }
 }
예제 #11
0
 public FAQsTokenReplace(FAQsInfo faqs) : base(Scope.DefaultSettings)
 {
     UseObjectLessExpression         = true;
     PropertySource[ObjectLessToken] = faqs;
     PropertySource["faq"]           = faqs;
 }
예제 #12
0
 public FAQsTokenReplace() : base(Scope.DefaultSettings)
 {
     UseObjectLessExpression         = true;
     PropertySource[ObjectLessToken] = new FAQsInfo();
 }
예제 #13
0
		/// <summary>
		/// Determines if the element matches the filter input.
		/// </summary>
		private bool MatchElement(FAQsInfo fData)
		{
			
			bool match = false;
			bool noneChecked = true;

            FAQsController faqsController = new FAQsController();
		    IEnumerable<CategoryInfo> cats = faqsController.ListCategories(ModuleId, true);
		    string categoryName;

			switch (ShowCategoryType)
			{
				case 0:
					//Filter on the checked items
					foreach (RadListBoxItem item in listCategories.Items)
					{

						//Get the checkbox in the Control
						CheckBox chkCategory = (CheckBox) (item.FindControl("chkCategory"));

						//If checked the faq module is being filtered on one or more category's
						if (chkCategory.Checked)
						{

							//Set Checked Flag
							noneChecked = false;

							//Get the filtered category
							string checkedCategoryName = chkCategory.Text;

							//Get the elements that match the catagory
                            var matchedCat = (from c in cats where c.FaqCategoryId == fData.CategoryId select c).SingleOrDefault();
                            categoryName = (matchedCat != null ? matchedCat.FaqCategoryName : "");

							if ((categoryName == checkedCategoryName) ||
							    (fData.CategoryId == null && checkedCategoryName == Localization.GetString("EmptyCategory", LocalResourceFile)))
							{
								match = true;
							    break;
							}
						}
					}
					break;
				case 1:
					if (treeCategories.SelectedNode != null)
					{
						noneChecked = (treeCategories.SelectedNode.Text == Localization.GetString("AllCategory", LocalResourceFile));
                        var matchedCat = (from c in cats where c.FaqCategoryId == fData.CategoryId select c).SingleOrDefault();
					    categoryName = (matchedCat != null ? matchedCat.FaqCategoryName : "");
						if (treeCategories.SelectedNode.Text == categoryName ||
								(fData.CategoryId == null && treeCategories.SelectedNode.Text == Localization.GetString("EmptyCategory", LocalResourceFile)))
						{
							match = true;
							break;
						}
					}
					break;
				case 2:
					if (drpCategories.SelectedValue != null)
					{
						string selectedCat = drpCategories.SelectedItem.Text;
						
						// strip out possible level points
						while (selectedCat.StartsWith("."))
						{
							selectedCat = selectedCat.Substring(1);
						}
						noneChecked = (selectedCat == Localization.GetString("AllCategory", LocalResourceFile));
                        var matchedCat = (from c in cats where c.FaqCategoryId == fData.CategoryId select c).SingleOrDefault();
                        categoryName = (matchedCat != null ? matchedCat.FaqCategoryName : "");
						if (selectedCat == categoryName ||
								(fData.CategoryId == null && selectedCat == Localization.GetString("EmptyCategory", LocalResourceFile)))
						{
							match = true;
							break;
						}
					}
					break;
			}
			
			if (noneChecked)
			{
				return true;
			}
			
			return match;
			
		}
예제 #14
0
        /// <summary>
        /// Imports the module (IPortable interface)
        /// </summary>
        /// <param name="moduleID">The module ID.</param>
        /// <param name="content">The content.</param>
        /// <param name="version">The version.</param>
        /// <param name="userId">The user id.</param>
        public void ImportModule(int moduleID, string content, string version, int userId)
        {
            Version vers = new Version(version);

            if (vers > new Version("5.0.0"))
            {
                XElement xRoot = XElement.Parse(content);
                Dictionary <int, int> idTrans = new Dictionary <int, int>();

                // First we import the categories
                List <CategoryInfo> lstCategories = new List <CategoryInfo>();
                XElement            xCategories   = xRoot.Element("categories");
                foreach (var xCategory in xCategories.Elements())
                {
                    // translate the parentid's to new values
                    int oldParentId = Int32.Parse(xCategory.Element("categoryparentid").Value, CultureInfo.InvariantCulture);
                    int newParentId = 0;
                    if (oldParentId > 0 && idTrans.ContainsKey(oldParentId))
                    {
                        newParentId = idTrans[oldParentId];
                    }

                    // Fill category properties
                    CategoryInfo category = new CategoryInfo();
                    category.ModuleId               = moduleID;
                    category.FaqCategoryParentId    = newParentId;
                    category.FaqCategoryName        = xCategory.Element("categoryname").Value;
                    category.FaqCategoryDescription = xCategory.Element("categorydescription").Value;
                    category.ViewOrder              = Int32.Parse(xCategory.Element("vieworder").Value, CultureInfo.InvariantCulture);

                    // add category and save old and new id to translation dictionary
                    int oldCategoryId = Int32.Parse(xCategory.Element("categoryid").Value, CultureInfo.InvariantCulture);
                    int newCategoryId = AddCategory(category);
                    idTrans.Add(oldCategoryId, newCategoryId);
                }

                // Next import the faqs
                List <FAQsInfo> lstFaqs = new List <FAQsInfo>();
                XElement        xFaqs   = xRoot.Element("faqs");
                foreach (var xFaq in xFaqs.Elements())
                {
                    // translate id with help of translation dictionary build before
                    int oldCategoryId = Int32.Parse(xFaq.Element("categoryid").Value, CultureInfo.InvariantCulture);
                    int newCategoryId = -1;
                    if (idTrans.ContainsKey(oldCategoryId))
                    {
                        newCategoryId = idTrans[oldCategoryId];
                    }

                    // Fill FAQs properties
                    FAQsInfo faq = new FAQsInfo();
                    faq.ModuleID     = moduleID;
                    faq.Question     = xFaq.Element("question").Value;
                    faq.Answer       = xFaq.Element("answer").Value;
                    faq.CategoryId   = newCategoryId;
                    faq.CreatedDate  = DateTime.Parse(xFaq.Element("creationdate").Value);
                    faq.DateModified = DateTime.Now;
                    faq.FaqHide      = Boolean.Parse(xFaq.Element("faqhide").Value);

                    // These dates might be emtpy
                    try
                    {
                        faq.PublishDate = DateTime.Parse(xFaq.Element("publishdate").Value);
                    }
                    catch (Exception)
                    {
                        faq.PublishDate = null;
                    }

                    try
                    {
                        faq.ExpireDate = DateTime.Parse(xFaq.Element("expiredate").Value);
                    }
                    catch (Exception)
                    {
                        faq.ExpireDate = null;
                    }

                    // Add Faq to database
                    AddFAQ(faq);
                }
            }
            else
            {
                ArrayList catNames = new ArrayList();
                ArrayList Question = new ArrayList();
                XmlNode   xmlFaq;
                XmlNode   xmlFaqs = Globals.GetContent(content, "faqs");

                //' check if category exists. if not create category
                foreach (XmlNode tempLoopVar_xmlFAQ in xmlFaqs)
                {
                    xmlFaq = tempLoopVar_xmlFAQ;
                    if ((xmlFaq["catname"].InnerText != Null.NullString) && (!catNames.Contains(xmlFaq["catname"].InnerText)))
                    {
                        catNames.Add(xmlFaq["catname"].InnerText);

                        CategoryInfo objCat = new CategoryInfo();
                        objCat.ModuleId               = moduleID;
                        objCat.FaqCategoryName        = xmlFaq["catname"].InnerText;
                        objCat.FaqCategoryDescription = xmlFaq["catdescription"].InnerText;

                        AddCategory(objCat);
                    }
                }
                // check is question is empty. if empty is category.
                int loop = 0;
                foreach (XmlNode tempLoopVar_xmlFAQ in xmlFaqs)
                {
                    loop++;
                    xmlFaq = tempLoopVar_xmlFAQ;

                    if (xmlFaq["question"].InnerText != Null.NullString && xmlFaq["question"].InnerText != string.Empty)
                    {
                        FAQsInfo objFAQs = new FAQsInfo();
                        objFAQs.ModuleID = moduleID;
                        objFAQs.Question = xmlFaq["question"].InnerText;
                        objFAQs.Answer   = xmlFaq["answer"].InnerText;
                        string faqCategoryName = xmlFaq["catname"].InnerText;

                        // Check if creationdate exists in export, if nothing set current date. else import
                        if (xmlFaq["creationdate"] == null)
                        {
                            objFAQs.CreatedDate  = DateTime.Now;
                            objFAQs.DateModified = DateTime.Now;
                        }
                        else
                        {
                            objFAQs.CreatedDate  = DateTime.Parse(xmlFaq["creationdate"].InnerText);
                            objFAQs.DateModified = DateTime.Parse(xmlFaq["datemodified"].InnerText);
                        }

                        if (xmlFaq["vieworder"] != null)
                        {
                            objFAQs.ViewOrder = int.Parse(xmlFaq["vieworder"].InnerText);
                        }
                        else
                        {
                            objFAQs.ViewOrder = loop;
                        }
                        objFAQs.CreatedByUser = userId.ToString();

                        bool foundCat = false;
                        foreach (CategoryInfo objCat in ListCategories(moduleID, false))
                        {
                            if (faqCategoryName == objCat.FaqCategoryName)
                            {
                                objFAQs.CategoryId = objCat.FaqCategoryId;
                                foundCat           = true;
                                break;
                            }
                        }

                        if (!foundCat)
                        {
                            objFAQs.CategoryId = null;
                        }

                        AddFAQ(objFAQs);
                    }
                }
            }
        }
예제 #15
0
		public FAQsTokenReplace(FAQsInfo faqs) : base(Scope.DefaultSettings)
		{
			UseObjectLessExpression = true;
			PropertySource[ObjectLessToken] = faqs;
			PropertySource["faq"] = faqs;
		}
예제 #16
0
		public FAQsTokenReplace (): base(Scope.DefaultSettings)
		{
			UseObjectLessExpression = true;
			PropertySource[ObjectLessToken] = new FAQsInfo();
		}
예제 #17
0
        /// <summary>
        /// Imports the module (IPortable interface)
        /// </summary>
        /// <param name="moduleID">The module ID.</param>
        /// <param name="content">The content.</param>
        /// <param name="version">The version.</param>
        /// <param name="userId">The user id.</param>
        public void ImportModule(int moduleID, string content, string version, int userId)
        {
            Version vers = new Version(version);
            if (vers > new Version("5.0.0"))
            {
                XElement xRoot = XElement.Parse(content);
                Dictionary<int, int> idTrans = new Dictionary<int, int>();

                // First we import the categories
                List<CategoryInfo> lstCategories = new List<CategoryInfo>();
                XElement xCategories = xRoot.Element("categories");
                foreach (var xCategory in xCategories.Elements())
                {
                    // translate the parentid's to new values
                    int oldParentId = Int32.Parse(xCategory.Element("categoryparentid").Value, CultureInfo.InvariantCulture);
                    int newParentId = 0;
                    if (oldParentId > 0 && idTrans.ContainsKey(oldParentId))
                        newParentId = idTrans[oldParentId];

                    // Fill category properties
                    CategoryInfo category = new CategoryInfo();
                    category.ModuleId = moduleID;
                    category.FaqCategoryParentId = newParentId;
                    category.FaqCategoryName = xCategory.Element("categoryname").Value;
                    category.FaqCategoryDescription = xCategory.Element("categorydescription").Value;
                    category.ViewOrder = Int32.Parse(xCategory.Element("vieworder").Value, CultureInfo.InvariantCulture);

                    // add category and save old and new id to translation dictionary
                    int oldCategoryId = Int32.Parse(xCategory.Element("categoryid").Value, CultureInfo.InvariantCulture);
                    int newCategoryId = AddCategory(category);
                    idTrans.Add(oldCategoryId, newCategoryId);
                }

                // Next import the faqs
                List<FAQsInfo> lstFaqs = new List<FAQsInfo>();
                XElement xFaqs = xRoot.Element("faqs");
                foreach (var xFaq in xFaqs.Elements())
                {
                    // translate id with help of translation dictionary build before
                    int oldCategoryId = Int32.Parse(xFaq.Element("categoryid").Value, CultureInfo.InvariantCulture);
                    int newCategoryId = -1;
                    if (idTrans.ContainsKey(oldCategoryId))
                        newCategoryId = idTrans[oldCategoryId];

                    // Fill FAQs properties
                    FAQsInfo faq = new FAQsInfo();
                    faq.ModuleID = moduleID;
                    faq.Question = xFaq.Element("question").Value;
                    faq.Answer = xFaq.Element("answer").Value;
                    faq.CategoryId = newCategoryId;
                    faq.CreatedDate = DateTime.Parse(xFaq.Element("creationdate").Value);
                    faq.DateModified = DateTime.Now;
                    faq.FaqHide = Boolean.Parse(xFaq.Element("faqhide").Value);

                    // These dates might be emtpy
                    try
                    {
                        faq.PublishDate = DateTime.Parse(xFaq.Element("publishdate").Value);
                    }
                    catch (Exception)
                    {
                        faq.PublishDate = null;
                    }

                    try
                    {
                        faq.ExpireDate = DateTime.Parse(xFaq.Element("expiredate").Value);
                    }
                    catch (Exception)
                    {
                        faq.ExpireDate = null;
                    }

                    // Add Faq to database
                    AddFAQ(faq);
                }
            }
            else
            {
                ArrayList catNames = new ArrayList();
                ArrayList Question = new ArrayList();
                XmlNode xmlFaq;
                XmlNode xmlFaqs = Globals.GetContent(content, "faqs");

                //' check if category exists. if not create category
                foreach (XmlNode tempLoopVar_xmlFAQ in xmlFaqs)
                {
                    xmlFaq = tempLoopVar_xmlFAQ;
                    if ((xmlFaq["catname"].InnerText != Null.NullString) && (!catNames.Contains(xmlFaq["catname"].InnerText)))
                    {
                        catNames.Add(xmlFaq["catname"].InnerText);

                        CategoryInfo objCat = new CategoryInfo();
                        objCat.ModuleId = moduleID;
                        objCat.FaqCategoryName = xmlFaq["catname"].InnerText;
                        objCat.FaqCategoryDescription = xmlFaq["catdescription"].InnerText;

                        AddCategory(objCat);
                    }
                }
                // check is question is empty. if empty is category.
                int loop = 0;
                foreach (XmlNode tempLoopVar_xmlFAQ in xmlFaqs)
                {
                    loop++;
                    xmlFaq = tempLoopVar_xmlFAQ;

                    if (xmlFaq["question"].InnerText != Null.NullString && xmlFaq["question"].InnerText != string.Empty)
                    {
                        FAQsInfo objFAQs = new FAQsInfo();
                        objFAQs.ModuleID = moduleID;
                        objFAQs.Question = xmlFaq["question"].InnerText;
                        objFAQs.Answer = xmlFaq["answer"].InnerText;
                        string faqCategoryName = xmlFaq["catname"].InnerText;

                        // Check if creationdate exists in export, if nothing set current date. else import
                        if (xmlFaq["creationdate"] == null)
                        {
                            objFAQs.CreatedDate = DateTime.Now;
                            objFAQs.DateModified = DateTime.Now;
                        }
                        else
                        {
                            objFAQs.CreatedDate = DateTime.Parse(xmlFaq["creationdate"].InnerText);
                            objFAQs.DateModified = DateTime.Parse(xmlFaq["datemodified"].InnerText);
                        }

                        if (xmlFaq["vieworder"] != null)
                        {
                            objFAQs.ViewOrder = int.Parse(xmlFaq["vieworder"].InnerText);
                        }
                        else
                        {
                            objFAQs.ViewOrder = loop;
                        }
                        objFAQs.CreatedByUser = userId.ToString();

                        bool foundCat = false;
                        foreach (CategoryInfo objCat in ListCategories(moduleID, false))
                        {
                            if (faqCategoryName == objCat.FaqCategoryName)
                            {
                                objFAQs.CategoryId = objCat.FaqCategoryId;
                                foundCat = true;
                                break;
                            }
                        }

                        if (!foundCat)
                        {
                            objFAQs.CategoryId = null;
                        }

                        AddFAQ(objFAQs);
                    }
                }
            }

        }
예제 #18
0
        /// <summary>
        /// Handles the Select event of the lstFAQs control.
        /// </summary>
        /// <param name="source">The source of the event.</param>
        /// <param name="e">The <see cref="System.Web.UI.WebControls.DataListCommandEventArgs" /> instance containing the event data.</param>
        protected void lstFAQs_ItemCommand(object source, System.Web.UI.WebControls.DataListCommandEventArgs e)
        {
            FAQsController controller = new FAQsController();
            int            itemId     = System.Convert.ToInt32(e.CommandArgument);
            int            index      = e.Item.ItemIndex;
            int            itemCount  = FaqData.Count;

            switch (e.CommandName.ToLower())
            {
            case "select":
                if (!SupportsClientAPI)
                {
                    try
                    {
                        Label    lblAnswer = (Label)(lstFAQs.Items[index].FindControl("A2"));
                        FAQsInfo FaqItem   = controller.GetFAQ(itemId);

                        if (lblAnswer.Text == "")
                        {
                            IncrementViewCount(FaqItem.ItemID);
                            lblAnswer.Text = HtmlDecode(controller.ProcessTokens(FaqItem, this.AnswerTemplate));
                        }
                        else
                        {
                            lblAnswer.Text = "";
                        }
                    }
                    catch (Exception exc)     //Module failed to load
                    {
                        DotNetNuke.Services.Exceptions.Exceptions.ProcessModuleLoadException(this, exc);
                    }
                }
                break;

            case "up":
                if (index == 0)
                {
                    controller.ReorderFAQ(itemId, ((FAQsInfo)FaqData[itemCount - 1]).ItemID, ModuleId);
                }
                else
                {
                    controller.ReorderFAQ(itemId, ((FAQsInfo)FaqData[index - 1]).ItemID, ModuleId);
                }
                FaqData = null;
                BindData();
                break;

            case "down":
                if (index == itemCount - 1)
                {
                    controller.ReorderFAQ(itemId, ((FAQsInfo)FaqData[0]).ItemID, ModuleId);
                }
                else
                {
                    controller.ReorderFAQ(itemId, ((FAQsInfo)FaqData[index + 1]).ItemID, ModuleId);
                }
                //Response.Redirect(DotNetNuke.Common.Globals.NavigateURL());
                FaqData = null;
                BindData();
                break;
            }
        }
예제 #19
0
        /// <summary>
        /// Determines if the element matches the filter input.
        /// </summary>
        private bool MatchElement(FAQsInfo fData)
        {
            bool match       = false;
            bool noneChecked = true;

            FAQsController             faqsController = new FAQsController();
            IEnumerable <CategoryInfo> cats           = faqsController.ListCategories(ModuleId, true);
            string categoryName;

            switch (ShowCategoryType)
            {
            case 0:
                //Filter on the checked items
                foreach (RadListBoxItem item in listCategories.Items)
                {
                    //Get the checkbox in the Control
                    CheckBox chkCategory = (CheckBox)(item.FindControl("chkCategory"));

                    //If checked the faq module is being filtered on one or more category's
                    if (chkCategory.Checked)
                    {
                        //Set Checked Flag
                        noneChecked = false;

                        //Get the filtered category
                        string checkedCategoryName = chkCategory.Text;

                        //Get the elements that match the catagory
                        var matchedCat = (from c in cats where c.FaqCategoryId == fData.CategoryId select c).SingleOrDefault();
                        categoryName = (matchedCat != null ? matchedCat.FaqCategoryName : "");

                        if ((categoryName == checkedCategoryName) ||
                            (fData.CategoryId == null && checkedCategoryName == Localization.GetString("EmptyCategory", LocalResourceFile)))
                        {
                            match = true;
                            break;
                        }
                    }
                }
                break;

            case 1:
                if (treeCategories.SelectedNode != null)
                {
                    noneChecked = (treeCategories.SelectedNode.Text == Localization.GetString("AllCategory", LocalResourceFile));
                    var matchedCat = (from c in cats where c.FaqCategoryId == fData.CategoryId select c).SingleOrDefault();
                    categoryName = (matchedCat != null ? matchedCat.FaqCategoryName : "");
                    if (treeCategories.SelectedNode.Text == categoryName ||
                        (fData.CategoryId == null && treeCategories.SelectedNode.Text == Localization.GetString("EmptyCategory", LocalResourceFile)))
                    {
                        match = true;
                        break;
                    }
                }
                break;

            case 2:
                if (drpCategories.SelectedValue != null)
                {
                    string selectedCat = drpCategories.SelectedItem.Text;

                    // strip out possible level points
                    while (selectedCat.StartsWith("."))
                    {
                        selectedCat = selectedCat.Substring(1);
                    }
                    noneChecked = (selectedCat == Localization.GetString("AllCategory", LocalResourceFile));
                    var matchedCat = (from c in cats where c.FaqCategoryId == fData.CategoryId select c).SingleOrDefault();
                    categoryName = (matchedCat != null ? matchedCat.FaqCategoryName : "");
                    if (selectedCat == categoryName ||
                        (fData.CategoryId == null && selectedCat == Localization.GetString("EmptyCategory", LocalResourceFile)))
                    {
                        match = true;
                        break;
                    }
                }
                break;
            }

            if (noneChecked)
            {
                return(true);
            }

            return(match);
        }
예제 #20
0
        /// <summary>
        /// Processes the faq tokens.
        /// </summary>
        /// <param name="faqItem">The FAQ item.</param>
        /// <param name="template">The template.</param>
        /// <returns>Answers in which all tokens are processed</returns>
        public string ProcessTokens(FAQsInfo faqItem, string template)
        {
            // For compability issues we need to convert old tokens to new tokens (sigh...)
            StringBuilder compatibleTemplate = new StringBuilder(template);
            compatibleTemplate.Replace("[ANSWER]", "[FAQ:ANSWER]");
            compatibleTemplate.Replace("[CATEGORYNAME]", "[FAQ:CATEGORYNAME]");
            compatibleTemplate.Replace("[CATEGORYDESC]", "[FAQ:CATEGORYDESC]");
            compatibleTemplate.Replace("[USER]", "[FAQ:USER]");
            compatibleTemplate.Replace("[VIEWCOUNT]", "[FAQ:VIEWCOUNT]");
            compatibleTemplate.Replace("[DATECREATED]", "[FAQ:DATECREATED]");
            compatibleTemplate.Replace("[DATEMODIFIED]", "[FAQ:DATEMODIFIED]");
            compatibleTemplate.Replace("[QUESTION]", "[FAQ:QUESTION]");
            compatibleTemplate.Replace("[INDEX]", "[FAQ:INDEX]");

            // Now we can call TokenReplace
            FAQsTokenReplace tokenReplace = new FAQsTokenReplace(faqItem);
            return tokenReplace.ReplaceFAQsTokens(template);
        }
예제 #21
0
        /// <summary>
        /// Handles the Click event of the cmdUpdate control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs" /> instance containing the event data.</param>
        protected void cmdUpdate_Click(System.Object sender, System.EventArgs e)
        {

            try
            {
                   // We do not allow for script or markup in the question
                PortalSecurity objSecurity = new PortalSecurity();
                string question = objSecurity.InputFilter(txtQuestionField.Text, PortalSecurity.FilterFlag.NoScripting | PortalSecurity.FilterFlag.NoMarkup);
                string answer = objSecurity.InputFilter(teAnswerField.Text, PortalSecurity.FilterFlag.NoScripting);

                FAQsController faqsController = new FAQsController();
                FAQsInfo faq;

                int? newCatID = null;
                if (drpCategory.SelectedValue != "-1")
                    newCatID = int.Parse(drpCategory.SelectedValue);

                 // Do we add of update? The Id will tell us
                if (FaqId != -1)
                {
                    faq = faqsController.GetFAQ(FaqId);
                    faq.CategoryId = newCatID;
                    faq.FaqHide = chkFaqHide.Checked;
                    faq.PublishDate = datepickerPublishDate.SelectedDate;
                    faq.ExpireDate = datepickerExpireDate.SelectedDate;
                    faq.Question = question;
                    faq.Answer = answer;
                    faq.DateModified = DateTime.Now;
                    faqsController.UpdateFAQ(faq);
                }
                else
                {
                    faq = new FAQsInfo
                              {
                                  ItemID = FaqId,
                                  CategoryId = newCatID,
                                  FaqHide = chkFaqHide.Checked,
                                  PublishDate = datepickerPublishDate.SelectedDate,
                                  ExpireDate = datepickerExpireDate.SelectedDate,
                                  Question = question,
                                  Answer = answer,
                                  CreatedByUser = UserId.ToString(),
                                  ViewCount = 0,
                                  DateModified = DateTime.Now,
                                  ModuleID = ModuleId,
                                  CreatedDate = DateTime.Now
                              };
                    faqsController.AddFAQ(faq);
                }
                Response.Redirect(Globals.NavigateURL(), true);
            }
            catch (Exception exc) //Module failed to load
            {
                Exceptions.ProcessModuleLoadException(this, exc);
            }

        }