protected void btnSave_OnClick(object sender, System.EventArgs e)
    {
        Page.Validate("form");

        if (Page.IsValid)
        {

            int user_id = Convert.ToInt32(Context.Items["UserID"]);

            if (!String.IsNullOrEmpty(Request.QueryString["pollID"]))
            {
                poll_id = Convert.ToInt32(Request.QueryString["pollID"]);
                qSoc_Poll2 poll = new qSoc_Poll2(poll_id);

                poll.Question = txtQuestion.Text;
                poll.LastModified = DateTime.Now;
                poll.LastModifiedBy = user_id;
                if (!String.IsNullOrEmpty(ddlTheme.SelectedValue))
                    poll.ThemeID = Convert.ToInt32(ddlTheme.SelectedValue);
                else
                    poll.ThemeID = 0;

                DateTime start_time = new DateTime();
                DateTime end_time = new DateTime();
                if (rblAvailable.SelectedValue == "Yes")
                {
                    poll.Available = "Yes";
                    start_time = DateTime.Now;
                    end_time = DateTime.Now.AddYears(10);
                    poll.StartDate = start_time;
                    poll.EndDate = end_time;

                    /*
                    // code no longer used since use defaults for setting these values
                    if (!String.IsNullOrEmpty(Convert.ToString(rdtStartTime.SelectedDate)))
                        poll.StartDate = Convert.ToDateTime(rdtStartTime.SelectedDate);
                    if (!String.IsNullOrEmpty(Convert.ToString(rdtEndTime.SelectedDate)))
                        poll.EndDate = Convert.ToDateTime(rdtEndTime.SelectedDate);
                     */
                }
                else
                {
                    poll.Available = "No";
                    start_time = DateTime.Now.AddDays(-2);
                    end_time = DateTime.Now.AddDays(-1);
                    poll.StartDate = start_time;
                    poll.EndDate = end_time;

                    /*
                    // code no longer used since use defaults for setting these values
                    if (!String.IsNullOrEmpty(Convert.ToString(rdtStartTime.SelectedDate)))
                        poll.StartDate = null;
                    if (!String.IsNullOrEmpty(Convert.ToString(rdtEndTime.SelectedDate)))
                        poll.EndDate = null;
                    */
                }

                poll.Update();
            }
            else
            {
                qSoc_Poll2 poll = new qSoc_Poll2();
                poll.ScopeID = 1;
                poll.Created = DateTime.Now;
                poll.CreatedBy = user_id;
                poll.LastModified = DateTime.Now;
                poll.LastModifiedBy = user_id;
                poll.Available = "Yes";
                poll.MarkAsDelete = 0;
                poll.Question = txtQuestion.Text;
                if (ddlPollType.SelectedValue == "Think")
                {
                    poll.PollType = "Opinion";
                    poll.ExperienceType = "Think";
                }
                else if (ddlPollType.SelectedValue == "Fact")
                {
                    poll.PollType = "Fact";
                    poll.ExperienceType = "Poll";
                }
                else if (ddlPollType.SelectedValue == "Opinion")
                {
                    poll.PollType = "Opinion";
                    poll.ExperienceType = "Poll";
                }
                poll.Available = "No";

                if (!String.IsNullOrEmpty(ddlTheme.SelectedValue))
                    poll.ThemeID = Convert.ToInt32(ddlTheme.SelectedValue);

                // default to start time is today and end time is 20 years from now
                poll.StartDate = DateTime.Now;
                poll.EndDate = DateTime.Now.AddYears(20);

                poll.Insert();
                /*
                if (!String.IsNullOrEmpty(Convert.ToString(rdtStartTime.SelectedDate)))
                    poll.StartDate = Convert.ToDateTime(rdtStartTime.SelectedDate);
                if (!String.IsNullOrEmpty(Convert.ToString(rdtEndTime.SelectedDate)))
                    poll.EndDate = Convert.ToDateTime(rdtEndTime.SelectedDate);
                 */

                poll_id = poll.PollID;

                if (ddlPollType.SelectedValue == "Think")
                {
                    int curr_choice_id = createNewChoice(poll_id, "Agree", false);
                    curr_choice_id = createNewChoice(poll_id, "Disagree", false);
                }
            }

            // process if highlighted poll
            qDbs_SQLcode sql = new qDbs_SQLcode();
            string sqlCode = string.Empty;
            sqlCode = "UPDATE qSoc_Polls SET Highlighted = null";

            if (lblHighlightedMessage.Text.Contains("current") && chkHighlightedPoll.Checked == false)
            {
                sql.ExecuteSQL(sqlCode);        // // clear all highlighted options
            }
            else if (chkHighlightedPoll.Checked && lblHighlightedMessage.Text.Contains("current"))
            {
                sql.ExecuteSQL(sqlCode);        // clear all highlighted options
                qSoc_Poll2 poll = new qSoc_Poll2(poll_id);
                poll.Highlighted = true;
                poll.Update();
            }
            else if (chkHighlightedPoll.Checked && lblHighlightedMessage.Text.Contains("Check"))
            {
                sql.ExecuteSQL(sqlCode);        // clear all highlighted options
                qSoc_Poll2 poll = new qSoc_Poll2(poll_id);
                poll.Highlighted = true;
                poll.Update();
            }

            // add keywords
            string owner_keywords = string.Empty;
            qPtl_KeywordReference.DeleteKeywordReferencesByContent((int)qSoc_ContentType.Types.Poll, poll_id);
            foreach (ListItem item in cblKeywords.Items)
            {
                if (item.Selected)
                {
                    if (!String.IsNullOrEmpty(owner_keywords))
                        owner_keywords += "," + item.Text;
                    else
                        owner_keywords += item.Text;
                    qPtl_KeywordReference keyword = new qPtl_KeywordReference();
                    keyword.Available = "Yes";
                    keyword.ScopeID = Convert.ToInt32(Context.Items["ScopeID"]);
                    keyword.KeywordID = Convert.ToInt32(item.Value);
                    keyword.ContentTypeID = (int)qSoc_ContentType.Types.Poll;
                    keyword.ReferenceID = poll_id;
                    keyword.Created = DateTime.Now;
                    keyword.LastModified = DateTime.Now;
                    keyword.CreatedBy = Convert.ToInt32(Context.Items["UserID"]);
                    keyword.LastModifiedBy = Convert.ToInt32(Context.Items["UserID"]);
                    keyword.MarkAsDelete = 0;
                    keyword.Insert();
                }
            }

            string reserved_keywords = string.Empty;
            foreach (ListItem item in chkTopics.Items)
            {
                if (item.Selected)
                {
                    if (!String.IsNullOrEmpty(reserved_keywords))
                        reserved_keywords += "," + item.Text;
                    else
                        reserved_keywords += item.Text;
                }
            }

            qSoc_Feed feed = new qSoc_Feed((int)qSoc_ContentType.Types.Poll, poll_id);

            if (!chkDisplayInFeed.Checked && !chkDisplayInExplore.Checked)
            {
                if (feed != null)
                {
                    if (feed.FeedID > 0)
                    {
                        feed.MarkAsDelete = 1;
                        feed.Available = "No";
                        feed.ReservedKeywords = reserved_keywords;
                        if (!chkDisplayInFeed.Checked)
                            feed.VisibleFeed = false;
                        if (!chkDisplayInExplore.Checked)
                            feed.VisibleExplore = false;
                        feed.Update();
                    }
                }
            }
            else if (chkDisplayInFeed.Checked || chkDisplayInExplore.Checked || !string.IsNullOrEmpty(reserved_keywords))
            {
                qSoc_Poll2 poll = new qSoc_Poll2(poll_id);

                int p_user_id = user_id;
                if (post_as_user_id > 0)
                    p_user_id = post_as_user_id;

                qPtl_User user = new qPtl_User(p_user_id);
                var u_space = qSoc_UserSpace_View.GetUserSpaces(poll.CreatedBy);

                // evaluate title and description
                string p_title = q_Helper.replaceSpecialCharacters(poll.Question);
                string p_description = string.Empty;
                // add choices to description field
                var choices = qSoc_PollChoice2.GetAvailablePollChoices(poll_id);

                string choices_html = string.Empty;
                int i = 1;
                if (choices != null)
                {
                    foreach (var c in choices)
                    {
                        if (!String.IsNullOrEmpty(choices_html))
                            choices_html += "<br>";
                        choices_html += i + ") " + c.Choice;
                        i++;
                    }
                }

                if (!String.IsNullOrEmpty(choices_html))
                {
                    p_description = choices_html;
                }

                if (feed != null)
                {
                    if (feed.FeedID > 0)
                    {
                        feed.CreatedBy = user.UserID;
                        feed.Available = poll.Available;
                        if (chkMoveToTop.Checked)
                            feed.LastModified = DateTime.Now;
                        feed.LastModifiedBy = user.UserID;
                        feed.MarkAsDelete = poll.MarkAsDelete;
                        feed.OwnerMarkAsDelete = poll.MarkAsDelete;
                        feed.ContentTypeID = (int)qSoc_ContentType.Types.Poll;
                        feed.ReferenceID = poll_id;
                        feed.OwnerID = user.UserID;
                        feed.OwnerName = user.UserName;
                        feed.OwnerProfilePic = user.ProfilePict;
                        feed.Type = "poll";
                        feed.Title = p_title;
                        feed.Description = p_description;
                        feed.Body = p_description;
                        feed.OwnerRole = user.HighestRole;
                        feed.OwnerRoleID = user.HighestRank;
                        feed.OwnerKeywords = owner_keywords;
                        feed.ReservedKeywords = reserved_keywords;
                        feed.UploadedFrom = "manager";
                        if (!String.IsNullOrEmpty(ddlTheme.SelectedValue))
                        {
                            feed.ThemeID = Convert.ToInt32(ddlTheme.SelectedValue);
                            feed.ThemeName = Convert.ToString(ddlTheme.SelectedItem);
                        }
                        if (chkDisplayInFeed.Checked)
                            feed.VisibleFeed = true;
                        else
                            feed.VisibleFeed = false;
                        if (chkDisplayInExplore.Checked)
                            feed.VisibleExplore = true;
                        else
                            feed.VisibleExplore = false;
                        feed.Update();
                    }
                    else
                    {
                        // create new feed item
                        if (u_space != null)
                        {
                            foreach (var s in u_space)
                            {
                                feed.SpaceID = s.SpaceID;
                                feed.SpaceName = s.SpaceShortName;
                            }
                        }
                        feed.ScopeID = Convert.ToInt32(Context.Items["ScopeID"]);
                        feed.Available = poll.Available;
                        feed.Created = DateTime.Now;
                        feed.CreatedBy = user.UserID;
                        feed.LastModified = DateTime.Now;
                        feed.LastModifiedBy = user.UserID;
                        feed.MarkAsDelete = poll.MarkAsDelete;
                        feed.OwnerMarkAsDelete = poll.MarkAsDelete;
                        feed.ContentTypeID = (int)qSoc_ContentType.Types.Poll;
                        feed.ReferenceID = poll_id;
                        feed.OwnerID = user.UserID;
                        feed.OwnerName = user.UserName;
                        feed.OwnerProfilePic = user.ProfilePict;
                        feed.Type = "poll";
                        feed.Title = p_title;
                        feed.Description = p_description;
                        feed.Body = p_description;
                        feed.OwnerRole = user.HighestRole;
                        feed.OwnerRoleID = user.HighestRank;

                        feed.VisibleAll = true;
                        feed.VisibleFriends = true;
                        feed.VisibleFollowers = true;
                        feed.VisibleSpace = true;
                        feed.VisiblePrivate = true;
                        feed.VisibleFeed = true;
                        feed.VisibleOwnerFeed = true;
                        feed.VisibleOwnerProfile = true;
                        if (!String.IsNullOrEmpty(ddlTheme.SelectedValue))
                        {
                            feed.ThemeID = Convert.ToInt32(ddlTheme.SelectedValue);
                            feed.ThemeName = Convert.ToString(ddlTheme.SelectedItem);
                        }
                        feed.ReservedKeywords = reserved_keywords;
                        if (!String.IsNullOrEmpty(owner_keywords))
                        {
                            feed.OwnerKeywords = owner_keywords;
                        }
                        feed.UploadedFrom = "manager";
                        if (chkDisplayInFeed.Checked)
                            feed.VisibleFeed = true;
                        else
                            feed.VisibleFeed = false;
                        if (chkDisplayInExplore.Checked)
                            feed.VisibleExplore = true;
                        else
                            feed.VisibleExplore = false;
                        feed.Insert();
                    }
                }
            }

            // redirect to page to add poll + keywords
            if (!String.IsNullOrEmpty(Request.QueryString["pollID"]))
            {
                Response.Redirect("poll-edit.aspx?pollID=" + poll_id);
            }
            else
            {
                Response.Redirect(Request.Url.ToString() + "?mode=add-successful&pollID=" + poll_id);
            }
        }
        else
        {
            lblMessage.Text = "*** A problem has occurred -- make sure all the required information has been entered ***";
            lblMessageBottom.Text = "*** A problem has occurred -- make sure all the required information has been entered ***";
        }
    }
    protected void btnSave_OnClick(object sender, System.EventArgs e)
    {
        Page.Validate("form");

        if (Page.IsValid)
        {
            int user_id = Convert.ToInt32(Context.Items["UserID"]);

            comment_id = Convert.ToInt32(Request.QueryString["commentID"]);
            qSoc_Comment2 comment = new qSoc_Comment2(comment_id);
            comment.LastModified = DateTime.Now;
            comment.LastModifiedBy = Convert.ToInt32(Context.Items["UserID"]);
            comment.Comment = txtComment.Text;
            comment.Available = rblAvailable.SelectedValue;
            comment.Update();

            string user_name = (new qPtl_User(user_id)).UserName;

            // add keywords
            string owner_keywords = string.Empty;
            qPtl_KeywordReference.DeleteKeywordReferencesByContent((int)qSoc_ContentType.Types.Shout, comment_id);
            foreach (ListItem item in cblKeywords.Items)
            {
                if (item.Selected)
                {
                    if (!String.IsNullOrEmpty(owner_keywords))
                        owner_keywords += "," + item.Text;
                    else
                        owner_keywords += item.Text;
                    qPtl_KeywordReference keyword = new qPtl_KeywordReference();
                    keyword.Available = "Yes";
                    keyword.ScopeID = Convert.ToInt32(Context.Items["ScopeID"]);
                    keyword.KeywordID = Convert.ToInt32(item.Value);
                    keyword.ContentTypeID = (int)qSoc_ContentType.Types.Shout;
                    keyword.ReferenceID = comment_id;
                    keyword.Created = DateTime.Now;
                    keyword.LastModified = DateTime.Now;
                    keyword.CreatedBy = Convert.ToInt32(Context.Items["UserID"]);
                    keyword.LastModifiedBy = Convert.ToInt32(Context.Items["UserID"]);
                    keyword.MarkAsDelete = 0;
                    keyword.Insert();
                }
            }

            // update feed information
            qSoc_Feed feed = new qSoc_Feed((int)qSoc_ContentType.Types.Shout, comment_id);

            if (feed != null)
            {
                if (feed.FeedID > 0)
                {
                    feed.Body = txtComment.Text;
                    int length_comment = comment.Comment.Length;
                    int max_length = 250;
                    if (length_comment < max_length)
                        max_length = length_comment;
                    feed.Title = feed.Body.Substring(0, max_length);
                    feed.Available = rblAvailable.SelectedValue;
                    feed.Update();
                }
            }

            lblMessage.Text = "*** Record Successfully Updated ***";
            lblMessageBottom.Text = "*** Record Successfully Updated ***";
            if (Request.QueryString["edit-mode"] == "in-place")
                Response.Redirect(Request.QueryString["returnURL"]);
            else
                Response.Redirect("comments-list.aspx");
        }
    }
    protected void btnSave_OnClick(object sender, System.EventArgs e)
    {
        Page.Validate("form");

        if (Page.IsValid)
        {

            int user_id = Convert.ToInt32(Context.Items["UserID"]);

            if (!String.IsNullOrEmpty(Request.QueryString["trainingID"]))
            {
                training_id = Convert.ToInt32(Request.QueryString["trainingID"]);
                qLrn_Training training = new qLrn_Training(training_id);
                training.Title = txtTitle.Text;
                training.Description = txtDescription.Text;
                training.LastModified = DateTime.Now;
                training.LastModifiedBy = user_id;
                training.Available = rblAvailable.SelectedValue;
                if (!String.IsNullOrEmpty(ddlAuthors.SelectedValue))
                    training.PersonAuthorID = Convert.ToInt32(ddlAuthors.SelectedValue);
                if (Convert.ToString(ddlTrainingTypes.SelectedItem) == "Internal")
                {
                    training.DesignThemeID = Convert.ToInt32(ddlDesignTemplates.SelectedValue);
                }
                else if (Convert.ToString(ddlTrainingTypes.SelectedItem) == "External")
                {
                    training.Link = txtLink.Text;
                }
                else if (Convert.ToString(ddlTrainingTypes.SelectedItem) == "In Person")
                {
                    // do something
                }
                training.Update();
            }
            else
            {
                qLrn_Training training = new qLrn_Training();
                training.ScopeID = Convert.ToInt32(Context.Items["ScopeID"]);
                training.Created = DateTime.Now;
                training.CreatedBy = user_id;
                training.LastModified = DateTime.Now;
                training.LastModifiedBy = user_id;
                training.Available = "Yes";
                training.MarkAsDelete = 0;
                training.Title = txtTitle.Text;
                training.Description = txtDescription.Text;
                training.LastModified = DateTime.Now;
                training.LastModifiedBy = user_id;
                training.Available = rblAvailable.SelectedValue;
                training.TrainingTypeID = Convert.ToInt32(ddlTrainingTypes.SelectedValue);
                if (!String.IsNullOrEmpty(ddlAuthors.SelectedValue))
                    training.PersonAuthorID = Convert.ToInt32(ddlAuthors.SelectedValue);
                if (Convert.ToString(ddlTrainingTypes.SelectedItem) == "Internal")
                {
                    training.DesignThemeID = Convert.ToInt32(ddlDesignTemplates.SelectedValue);
                }
                else if (Convert.ToString(ddlTrainingTypes.SelectedItem) == "External")
                {
                    training.Link = txtLink.Text;
                }
                else if (Convert.ToString(ddlTrainingTypes.SelectedItem) == "In Person")
                {
                    // do something
                }
                training.Insert();

                training_id = training.TrainingID;
            }

            // add keywords
            string owner_keywords = string.Empty;
            qPtl_KeywordReference.DeleteKeywordReferencesByContent((int)qSoc_ContentType.Types.Training, training_id);
            foreach (ListItem item in cblKeywords.Items)
            {
                if (item.Selected)
                {
                    if (!String.IsNullOrEmpty(owner_keywords))
                        owner_keywords += "," + item.Text;
                    else
                        owner_keywords += item.Text;
                    qPtl_KeywordReference keyword = new qPtl_KeywordReference();
                    keyword.Available = "Yes";
                    keyword.ScopeID = Convert.ToInt32(Context.Items["ScopeID"]);
                    keyword.KeywordID = Convert.ToInt32(item.Value);
                    keyword.ContentTypeID = (int)qSoc_ContentType.Types.Training;
                    keyword.ReferenceID = training_id;
                    keyword.Created = DateTime.Now;
                    keyword.LastModified = DateTime.Now;
                    keyword.CreatedBy = Convert.ToInt32(Context.Items["UserID"]);
                    keyword.LastModifiedBy = Convert.ToInt32(Context.Items["UserID"]);
                    keyword.MarkAsDelete = 0;
                    keyword.Insert();
                }
            }

            string reserved_keywords = string.Empty;
            foreach (ListItem item in chkTopics.Items)
            {
                if (item.Selected)
                {
                    if (!String.IsNullOrEmpty(reserved_keywords))
                        reserved_keywords += "," + item.Text;
                    else
                        reserved_keywords += item.Text;
                }
            }

            qSoc_Feed feed = new qSoc_Feed((int)qSoc_ContentType.Types.Training, training_id);

            if (!chkDisplayInFeed.Checked && !chkDisplayInExplore.Checked)
            {
                if (feed != null)
                {
                    if (feed.FeedID > 0)
                    {
                        if (feed.Type == "training" && feed.Available == "Yes" && feed.VisibleFeed == false && feed.VisibleExplore == false)
                        {
                            // situation when the training needs to be available for campaigns but is not visible otherwise
                            feed.MarkAsDelete = 1;
                            feed.Available = "Yes";
                            feed.VisibleFeed = false;
                            feed.VisibleExplore = false;
                        }
                        else
                        {
                            feed.MarkAsDelete = 1;
                            feed.Available = "No";
                            feed.ReservedKeywords = reserved_keywords;
                            if (!chkDisplayInFeed.Checked)
                                feed.VisibleFeed = false;
                            if (!chkDisplayInExplore.Checked)
                                feed.VisibleExplore = false;
                        }

                        feed.Update();
                    }
                }
            }
            else if (chkDisplayInFeed.Checked || chkDisplayInExplore.Checked || !string.IsNullOrEmpty(reserved_keywords))
            {
                qLrn_Training training = new qLrn_Training(training_id);

                int p_user_id = user_id;
                if (post_as_user_id > 0)
                    p_user_id = post_as_user_id;

                qPtl_User user = new qPtl_User(p_user_id);
                var u_space = qSoc_UserSpace_View.GetUserSpaces(training.CreatedBy);

                // evaluate title and description
                string p_title = q_Helper.replaceSpecialCharacters(training.Title);
                string p_description = q_Helper.replaceSpecialCharacters(training.Description);

                // add first slide image to the description
                var slides = qLrn_TrainingSlide_View.GetAvailableSlidesInOrder(training.TrainingID);
                string slide_icon = string.Empty;
                int s_count = 0;
                foreach (var s in slides)
                {
                    if (s_count == 0)
                    {
                        string slide_image_path = Convert.ToString(System.Configuration.ConfigurationManager.AppSettings["Learning_SlideIconBasePath"]);
                        if (!String.IsNullOrEmpty(slide_image_path))
                        {
                            slide_icon = "<img src=\"" + slide_image_path + "/" + s.TrainingID + "/" + s.SlideID + ".png?width=200&height=133\">";
                        }

                        s_count++;
                    }
                }
                string body = p_description;
                if (!String.IsNullOrEmpty(slide_icon))
                {
                    body = slide_icon + "<br>" + p_description;
                }

                if (feed != null)
                {
                    if (feed.FeedID > 0)
                    {
                        feed.CreatedBy = user.UserID;
                        feed.Available = training.Available;
                        if (chkMoveToTop.Checked)
                            feed.LastModified = DateTime.Now;
                        feed.LastModifiedBy = user.UserID;
                        feed.MarkAsDelete = training.MarkAsDelete;
                        feed.OwnerMarkAsDelete = training.MarkAsDelete;
                        feed.ContentTypeID = (int)qSoc_ContentType.Types.Training;
                        feed.ReferenceID = training_id;
                        feed.OwnerID = user.UserID;
                        feed.OwnerName = user.UserName;
                        feed.OwnerProfilePic = user.ProfilePict;
                        feed.Type = "training";
                        feed.Title = p_title;
                        feed.Description = p_description;
                        feed.Body = body;
                        feed.OwnerRole = user.HighestRole;
                        feed.OwnerRoleID = user.HighestRank;
                        feed.OwnerKeywords = owner_keywords;
                        feed.ReservedKeywords = reserved_keywords;
                        feed.UploadedFrom = "manager";
                        if (chkDisplayInFeed.Checked)
                            feed.VisibleFeed = true;
                        else
                            feed.VisibleFeed = false;
                        if (chkDisplayInExplore.Checked)
                            feed.VisibleExplore = true;
                        else
                            feed.VisibleExplore = false;
                        feed.Update();
                    }
                    else
                    {
                        // create new feed item
                        if (u_space != null)
                        {
                            foreach (var s in u_space)
                            {
                                feed.SpaceID = s.SpaceID;
                                feed.SpaceName = s.SpaceShortName;
                            }
                        }
                        feed.ScopeID = Convert.ToInt32(Context.Items["ScopeID"]);
                        feed.Available = training.Available;
                        feed.Created = DateTime.Now;
                        feed.CreatedBy = user.UserID;
                        feed.LastModified = DateTime.Now;
                        feed.LastModifiedBy = user.UserID;
                        feed.MarkAsDelete = training.MarkAsDelete;
                        feed.OwnerMarkAsDelete = training.MarkAsDelete;
                        feed.ContentTypeID = (int)qSoc_ContentType.Types.Training;
                        feed.ReferenceID = training_id;
                        feed.OwnerID = user.UserID;
                        feed.OwnerName = user.UserName;
                        feed.OwnerProfilePic = user.ProfilePict;
                        feed.Type = "training";
                        feed.Title = p_title;
                        feed.Description = p_description;
                        feed.Body = p_description;
                        feed.OwnerRole = user.HighestRole;
                        feed.OwnerRoleID = user.HighestRank;

                        feed.VisibleAll = true;
                        feed.VisibleFriends = true;
                        feed.VisibleFollowers = true;
                        feed.VisibleSpace = true;
                        feed.VisiblePrivate = true;
                        feed.VisibleFeed = true;
                        feed.VisibleOwnerFeed = true;
                        feed.VisibleOwnerProfile = true;
                        feed.ReservedKeywords = reserved_keywords;
                        if (!String.IsNullOrEmpty(owner_keywords))
                        {
                            feed.OwnerKeywords = owner_keywords;
                        }
                        feed.UploadedFrom = "manager";
                        if (chkDisplayInFeed.Checked)
                            feed.VisibleFeed = true;
                        else
                            feed.VisibleFeed = false;
                        if (chkDisplayInExplore.Checked)
                            feed.VisibleExplore = true;
                        else
                            feed.VisibleExplore = false;
                        feed.Insert();
                    }
                }
            }

            string user_name = (new qPtl_User(user_id)).UserName;

            if (!String.IsNullOrEmpty(Request.QueryString["trainingID"]))
            {
                lblMessage.Text = "*** Record Successfully Updated ***";
                lblMessageBottom.Text = "*** Record Successfully Updated ***";
                if (Request.QueryString["edit-mode"] == "in-place")
                    Response.Redirect(Request.QueryString["returnURL"]);
                else
                    Response.Redirect("trainings-list.aspx");
            }
            else
            {
                //Response.Redirect(Request.Url.ToString() + "?mode=add-successful&questionCategoryID=" + tip_id);
                Response.Redirect("trainings-list.aspx");
            }
        }
    }
    protected void btnSave_OnClick(object sender, System.EventArgs e)
    {
        int user_id = Convert.ToInt32(Context.Items["UserID"]);

        if (!String.IsNullOrEmpty(Request.QueryString["articleID"]))
        {
            article_id = Convert.ToInt32(Request.QueryString["articleID"]);
            qLrn_Article article = new qLrn_Article(article_id);
            article.Title = txtTitle.Text;
            article.Description = txtSummary.Text;
            article.Body = reContent.Content;
            article.LastModified = DateTime.Now;
            article.LastModifiedBy = user_id;
            if (!String.IsNullOrEmpty(ddlAuthor.SelectedValue))
            {
                article.AuthorID = Convert.ToInt32(ddlAuthor.SelectedValue);
                article.OrganizationAuthorID = Convert.ToInt32(ddlAuthor.SelectedValue);
            }
            if (!String.IsNullOrEmpty(ddlLanguage.SelectedValue))
                article.Language = ddlLanguage.SelectedValue;
            else
                article.Language = "en";
            if (!String.IsNullOrEmpty(ddlTheme.SelectedValue))
                article.ThemeID = Convert.ToInt32(ddlTheme.SelectedValue);
            article.Available = rblAvailable.SelectedValue;
            if (plhArticleType.Visible == true)
                article.ArticleType = ddlArticleType.SelectedValue;
            article.Update();
        }
        else
        {
            qLrn_Article article = new qLrn_Article();
            article.ScopeID = 1;
            article.Created = DateTime.Now;
            article.CreatedBy = user_id;
            article.LastModified = DateTime.Now;
            article.LastModifiedBy = user_id;
            article.Available = "Yes";
            article.MarkAsDelete = 0;
            article.Title = txtTitle.Text;
            article.Description = txtSummary.Text;
            article.Body = reContent.Content;
            article.LastModified = DateTime.Now;
            article.LastModifiedBy = user_id;
            if (!String.IsNullOrEmpty(ddlAuthor.SelectedValue))
            {
                article.AuthorID = Convert.ToInt32(ddlAuthor.SelectedValue);
                article.OrganizationAuthorID = Convert.ToInt32(ddlAuthor.SelectedValue);
            }
            if (!String.IsNullOrEmpty(ddlLanguage.SelectedValue))
                article.Language = ddlLanguage.SelectedValue;
            else
                article.Language = "en";
            if (!String.IsNullOrEmpty(ddlTheme.SelectedValue))
                article.ThemeID = Convert.ToInt32(ddlTheme.SelectedValue);
            if (plhArticleType.Visible == true)
                article.ArticleType = ddlArticleType.SelectedValue;
            article.Available = rblAvailable.SelectedValue;
            article.Insert();

            article_id = article.ArticleID;
        }

        string user_name = (new qPtl_User(user_id)).UserName;

        // add keywords
        string owner_keywords = string.Empty;
        qPtl_KeywordReference.DeleteKeywordReferencesByContent((int)qSoc_ContentType.Types.Article, article_id);
        foreach (ListItem item in cblKeywords.Items)
        {
            if (item.Selected)
            {
                if (!String.IsNullOrEmpty(owner_keywords))
                    owner_keywords += "," + item.Text;
                else
                    owner_keywords += item.Text;
                qPtl_KeywordReference keyword = new qPtl_KeywordReference();
                keyword.Available = "Yes";
                keyword.ScopeID = Convert.ToInt32(Context.Items["ScopeID"]);
                keyword.KeywordID = Convert.ToInt32(item.Value);
                keyword.ContentTypeID = (int)qSoc_ContentType.Types.Article;
                keyword.ReferenceID = article_id;
                keyword.Created = DateTime.Now;
                keyword.LastModified = DateTime.Now;
                keyword.CreatedBy = Convert.ToInt32(Context.Items["UserID"]);
                keyword.LastModifiedBy = Convert.ToInt32(Context.Items["UserID"]);
                keyword.MarkAsDelete = 0;
                keyword.Insert();
            }
        }

        string reserved_keywords = string.Empty;
        foreach (ListItem item in chkTopics.Items)
        {
            if (item.Selected)
            {
                if (!String.IsNullOrEmpty(reserved_keywords))
                    reserved_keywords += "," + item.Text;
                else
                    reserved_keywords += item.Text;
            }
        }

        qSoc_Feed feed = new qSoc_Feed((int)qSoc_ContentType.Types.Article, article_id);

        if (!chkDisplayInFeed.Checked && !chkDisplayInExplore.Checked)
        {
            if (feed != null)
            {
                if (feed.FeedID > 0)
                {
                    feed.MarkAsDelete = 1;
                    feed.Available = "No";
                    feed.ReservedKeywords = reserved_keywords;
                    if (!chkDisplayInFeed.Checked)
                        feed.VisibleFeed = false;
                    if (!chkDisplayInExplore.Checked)
                        feed.VisibleExplore = false;
                    feed.Update();
                }
            }
        }
        else if (chkDisplayInFeed.Checked || chkDisplayInExplore.Checked || !string.IsNullOrEmpty(reserved_keywords))
        {
            qLrn_Article article = new qLrn_Article(article_id);

            int p_user_id = user_id;
            if (post_as_user_id > 0)
                p_user_id = post_as_user_id;

            qPtl_User user = new qPtl_User(p_user_id);
            var u_space = qSoc_UserSpace_View.GetUserSpaces(article.CreatedBy);

            // evaluate title and description
            string p_title = q_Helper.replaceSpecialCharacters(article.Title);
            string p_description = q_Helper.replaceSpecialCharacters(article.Description);

            if (feed != null)
            {
                if (feed.FeedID > 0)
                {
                    feed.CreatedBy = user.UserID;
                    feed.Available = article.Available;
                    if (chkMoveToTop.Checked)
                        feed.LastModified = DateTime.Now;
                    feed.LastModifiedBy = user.UserID;
                    feed.MarkAsDelete = article.MarkAsDelete;
                    feed.OwnerMarkAsDelete = article.MarkAsDelete;
                    feed.ContentTypeID = (int)qSoc_ContentType.Types.Article;
                    feed.ReferenceID = article_id;
                    feed.OwnerID = user.UserID;
                    feed.OwnerName = user.UserName;
                    feed.OwnerProfilePic = user.ProfilePict;
                    feed.Type = "article";
                    feed.Title = p_title;
                    feed.Description = p_description;
                    feed.Body = p_description;
                    feed.OwnerRole = user.HighestRole;
                    feed.OwnerRoleID = user.HighestRank;
                    feed.OwnerKeywords = owner_keywords;
                    feed.ReservedKeywords = reserved_keywords;
                    feed.UploadedFrom = "manager";
                    if (!String.IsNullOrEmpty(ddlTheme.SelectedValue))
                    {
                        feed.ThemeID = Convert.ToInt32(ddlTheme.SelectedValue);
                        feed.ThemeName = Convert.ToString(ddlTheme.SelectedItem);
                    }
                    if (chkDisplayInFeed.Checked)
                        feed.VisibleFeed = true;
                    else
                        feed.VisibleFeed = false;
                    if (chkDisplayInExplore.Checked)
                        feed.VisibleExplore = true;
                    else
                        feed.VisibleExplore = false;
                    feed.Update();
                }
                else
                {
                    // create new feed item
                    if (u_space != null)
                    {
                        foreach (var s in u_space)
                        {
                            feed.SpaceID = s.SpaceID;
                            feed.SpaceName = s.SpaceShortName;
                        }
                    }
                    feed.ScopeID = Convert.ToInt32(Context.Items["ScopeID"]);
                    feed.Available = article.Available;
                    feed.Created = DateTime.Now;
                    feed.CreatedBy = user.UserID;
                    feed.LastModified = DateTime.Now;
                    feed.LastModifiedBy = user.UserID;
                    feed.MarkAsDelete = article.MarkAsDelete;
                    feed.OwnerMarkAsDelete = article.MarkAsDelete;
                    feed.ContentTypeID = (int)qSoc_ContentType.Types.Article;
                    feed.ReferenceID = article_id;
                    feed.OwnerID = user.UserID;
                    feed.OwnerName = user.UserName;
                    feed.OwnerProfilePic = user.ProfilePict;
                    feed.Type = "article";
                    feed.Title = p_title;
                    feed.Description = p_description;
                    feed.Body = p_description;
                    feed.OwnerRole = user.HighestRole;
                    feed.OwnerRoleID = user.HighestRank;

                    feed.VisibleAll = true;
                    feed.VisibleFriends = true;
                    feed.VisibleFollowers = true;
                    feed.VisibleSpace = true;
                    feed.VisiblePrivate = true;
                    feed.VisibleFeed = true;
                    feed.VisibleOwnerFeed = true;
                    feed.VisibleOwnerProfile = true;
                    if (!String.IsNullOrEmpty(ddlTheme.SelectedValue))
                    {
                        feed.ThemeID = Convert.ToInt32(ddlTheme.SelectedValue);
                        feed.ThemeName = Convert.ToString(ddlTheme.SelectedItem);
                    }
                    feed.ReservedKeywords = reserved_keywords;
                    if (!String.IsNullOrEmpty(owner_keywords))
                    {
                        feed.OwnerKeywords = owner_keywords;
                    }
                    feed.UploadedFrom = "manager";
                    if (chkDisplayInFeed.Checked)
                        feed.VisibleFeed = true;
                    else
                        feed.VisibleFeed = false;
                    if (chkDisplayInExplore.Checked)
                        feed.VisibleExplore = true;
                    else
                        feed.VisibleExplore = false;
                    feed.Insert();
                }
            }
        }

        // redirect to page to add theme + keywords
        //Response.Redirect("~/qLrn/articles-list.aspx");
        if (!String.IsNullOrEmpty(Request.QueryString["articleID"]))
        {
            lblMessage.Text = "*** Record Successfully Updated ***";
            lblMessageBottom.Text = "*** Record Successfully Updated ***";
            if (Request.QueryString["edit-mode"] == "in-place")
            {
                string return_redirect = Request.QueryString["returnURL"];
                if (!String.IsNullOrEmpty(Request.QueryString["location"]))
                    return_redirect += "&location=" + Request.QueryString["location"];
                Response.Redirect(return_redirect);
            }
            else
                Response.Redirect("articles-list.aspx");
        }
        else
        {
            Response.Redirect(Request.Url.ToString() + "?mode=add-successful&articleID=" + article_id);
        }
    }
    protected void btnSave_OnClick(object sender, System.EventArgs e)
    {
        int user_id = Convert.ToInt32(Context.Items["UserID"]);

        if (!String.IsNullOrEmpty(Request.QueryString["topicID"]))
        {
            topic_id = Convert.ToInt32(Request.QueryString["topicID"]);
            qSoc_Topic topic = new qSoc_Topic(topic_id);

            topic.Name = txtName.Text;
            topic.URL = txtURL.Text;
            topic.Summary = txtSummary.Text;
            topic.Description = reContent.Content;
            topic.Available = rblAvailable.SelectedValue;
            topic.LastModified = DateTime.Now;
            topic.LastModifiedBy = user_id;
            topic.ImageURL = txtImageURL.Text;
            topic.IconURL = txtIconURL.Text;
            topic.Update();
        }
        else
        {
            qSoc_Topic topic = new qSoc_Topic();
            topic.ScopeID = 1;
            topic.Created = DateTime.Now;
            topic.CreatedBy = user_id;
            topic.LastModified = DateTime.Now;
            topic.LastModifiedBy = user_id;
            topic.Available = "Yes";
            topic.MarkAsDelete = 0;
            topic.Name = txtName.Text;
            topic.URL = txtURL.Text;
            topic.Summary = txtSummary.Text;
            topic.Description = reContent.Content;
            topic.Available = rblAvailable.SelectedValue;
            topic.ImageURL = txtImageURL.Text;
            topic.IconURL = txtIconURL.Text;
            topic.Insert();

            topic_id = topic.TopicID;
        }

        // add keywords
        qPtl_KeywordReference.DeleteKeywordReferencesByContent((int)qSoc_ContentType.Types.Topic, topic_id);
        foreach (ListItem item in cblKeywords.Items)
        {
            if (item.Selected)
            {
                qPtl_KeywordReference keyword = new qPtl_KeywordReference();
                keyword.Available = "Yes";
                keyword.ScopeID = Convert.ToInt32(Context.Items["ScopeID"]);
                keyword.KeywordID = Convert.ToInt32(item.Value);
                keyword.ContentTypeID = (int)qSoc_ContentType.Types.Topic;
                keyword.ReferenceID = topic_id;
                keyword.Created = DateTime.Now;
                keyword.LastModified = DateTime.Now;
                keyword.CreatedBy = Convert.ToInt32(Context.Items["UserID"]);
                keyword.LastModifiedBy = Convert.ToInt32(Context.Items["UserID"]);
                keyword.MarkAsDelete = 0;
                keyword.Insert();
            }
        }

        Response.Redirect("~/manage/site/metadata/topics-list.aspx");
    }
    protected void btnSave_OnClick(object sender, System.EventArgs e)
    {
        Page.Validate("form");

        if (Page.IsValid)
        {

            int user_id = Convert.ToInt32(Context.Items["UserID"]);

            if (!String.IsNullOrEmpty(Request.QueryString["linkID"]))
            {
                link_id = Convert.ToInt32(Request.QueryString["linkID"]);
                qPtl_Link link = new qPtl_Link(link_id);

                link.Title = txtName.Text;
                link.Description = txtSummary.Text;
                link.Available = rblAvailable.SelectedValue;
                link.LastModified = DateTime.Now;
                link.LastModifiedBy = user_id;
                link.URL = txtURL.Text;
                if (!String.IsNullOrEmpty(ddlAuthor.SelectedValue))
                    link.AuthorID = Convert.ToInt32(ddlAuthor.SelectedValue);
                if (!String.IsNullOrEmpty(ddlTheme.SelectedValue))
                    link.ThemeID = Convert.ToInt32(ddlTheme.SelectedValue);
                link.Type = ddlType.SelectedValue;
                if (Convert.ToString(ddlType.SelectedValue).Contains("Internal"))
                    link.Source = "internal";
                else
                    link.Source = "external";
                link.UploadedFrom = "manager";
                link.Language = ddlLanguage.SelectedValue;
                link.LinkType = ddlLinkType.SelectedValue;
                link.Update();
            }
            else
            {
                qPtl_Link link = new qPtl_Link();
                link.ScopeID = 1;
                link.Created = DateTime.Now;
                link.CreatedBy = user_id;
                link.LastModified = DateTime.Now;
                link.LastModifiedBy = user_id;
                link.Available = "Yes";
                link.MarkAsDelete = 0;
                link.Title = txtName.Text;
                link.Description = txtSummary.Text;
                link.URL = txtURL.Text;
                link.Available = rblAvailable.SelectedValue;
                link.Language = ddlLanguage.SelectedValue;
                link.LinkType = ddlLinkType.SelectedValue;
                if (!String.IsNullOrEmpty(ddlAuthor.SelectedValue))
                    link.AuthorID = Convert.ToInt32(ddlAuthor.SelectedValue);
                if (!String.IsNullOrEmpty(ddlTheme.SelectedValue))
                    link.ThemeID = Convert.ToInt32(ddlTheme.SelectedValue);
                link.Type = ddlType.SelectedValue;

                if (Convert.ToString(ddlType.SelectedValue).Contains("Internal"))
                    link.Source = "internal";
                else
                    link.Source = "external";
                link.UploadedFrom = "manager";
                link.Insert();

                link_id = link.LinkID;
            }

            // add keywords
            string owner_keywords = string.Empty;
            qPtl_KeywordReference.DeleteKeywordReferencesByContent((int)qSoc_ContentType.Types.Link, link_id);
            foreach (ListItem item in cblKeywords.Items)
            {
                if (item.Selected)
                {
                    if (!String.IsNullOrEmpty(owner_keywords))
                        owner_keywords += "," + item.Text;
                    else
                        owner_keywords += item.Text;
                    qPtl_KeywordReference keyword = new qPtl_KeywordReference();
                    keyword.Available = "Yes";
                    keyword.ScopeID = Convert.ToInt32(Context.Items["ScopeID"]);
                    keyword.KeywordID = Convert.ToInt32(item.Value);
                    keyword.ContentTypeID = (int)qSoc_ContentType.Types.Link;
                    keyword.ReferenceID = link_id;
                    keyword.Created = DateTime.Now;
                    keyword.LastModified = DateTime.Now;
                    keyword.CreatedBy = Convert.ToInt32(Context.Items["UserID"]);
                    keyword.LastModifiedBy = Convert.ToInt32(Context.Items["UserID"]);
                    keyword.MarkAsDelete = 0;
                    keyword.Insert();
                }
            }

            string reserved_keywords = string.Empty;
            foreach (ListItem item in chkTopics.Items)
            {
                if (item.Selected)
                {
                    if (!String.IsNullOrEmpty(reserved_keywords))
                        reserved_keywords += "," + item.Text;
                    else
                        reserved_keywords += item.Text;
                }
            }

            qSoc_Feed feed = new qSoc_Feed((int)qSoc_ContentType.Types.Link, link_id);

            if (!chkDisplayInFeed.Checked && !chkDisplayInExplore.Checked)
            {
                if (feed != null)
                {
                    if (feed.FeedID > 0)
                    {
                        feed.MarkAsDelete = 1;
                        feed.Available = "No";
                        feed.ReservedKeywords = reserved_keywords;
                        if (!chkDisplayInFeed.Checked)
                            feed.VisibleFeed = false;
                        if (!chkDisplayInExplore.Checked)
                            feed.VisibleExplore = false;
                        feed.Update();
                    }
                }
            }
            else if (chkDisplayInFeed.Checked || chkDisplayInExplore.Checked || !string.IsNullOrEmpty(reserved_keywords))
            {
                qPtl_Link link = new qPtl_Link(link_id);

                int p_user_id = user_id;
                if (post_as_user_id > 0)
                    p_user_id = post_as_user_id;

                qPtl_User user = new qPtl_User(p_user_id);
                var u_space = qSoc_UserSpace_View.GetUserSpaces(link.CreatedBy);

                // evaluate title and description
                string p_title = q_Helper.replaceSpecialCharacters(link.Title);
                string p_description = q_Helper.replaceSpecialCharacters(link.Description);

                if (feed != null)
                {
                    if (feed.FeedID > 0)
                    {
                        feed.CreatedBy = user.UserID;
                        feed.Available = link.Available;
                        if (chkMoveToTop.Checked)
                            feed.LastModified = DateTime.Now;
                        feed.LastModifiedBy = user.UserID;
                        feed.MarkAsDelete = link.MarkAsDelete;
                        feed.OwnerMarkAsDelete = link.MarkAsDelete;
                        feed.ContentTypeID = (int)qSoc_ContentType.Types.Link;
                        feed.ReferenceID = link_id;
                        feed.OwnerID = user.UserID;
                        feed.OwnerName = user.UserName;
                        feed.OwnerProfilePic = user.ProfilePict;
                        feed.Type = "link";
                        feed.Title = p_title;
                        feed.URL = link.URL;
                        feed.Description = p_description;
                        feed.Body = p_description;
                        feed.OwnerRole = user.HighestRole;
                        feed.OwnerRoleID = user.HighestRank;
                        feed.OwnerKeywords = owner_keywords;
                        feed.ReservedKeywords = reserved_keywords;
                        feed.UploadedFrom = "manager";
                        if (!String.IsNullOrEmpty(ddlTheme.SelectedValue))
                        {
                            feed.ThemeID = Convert.ToInt32(ddlTheme.SelectedValue);
                            feed.ThemeName = Convert.ToString(ddlTheme.SelectedItem);
                        }
                        if (chkDisplayInFeed.Checked)
                            feed.VisibleFeed = true;
                        else
                            feed.VisibleFeed = false;
                        if (chkDisplayInExplore.Checked)
                            feed.VisibleExplore = true;
                        else
                            feed.VisibleExplore = false;
                        feed.Update();
                    }
                    else
                    {
                        // create new feed item
                        if (u_space != null)
                        {
                            foreach (var s in u_space)
                            {
                                feed.SpaceID = s.SpaceID;
                                feed.SpaceName = s.SpaceShortName;
                            }
                        }
                        feed.ScopeID = Convert.ToInt32(Context.Items["ScopeID"]);
                        feed.Available = link.Available;
                        feed.Created = DateTime.Now;
                        feed.CreatedBy = user.UserID;
                        feed.LastModified = DateTime.Now;
                        feed.LastModifiedBy = user.UserID;
                        feed.MarkAsDelete = link.MarkAsDelete;
                        feed.OwnerMarkAsDelete = link.MarkAsDelete;
                        feed.ContentTypeID = (int)qSoc_ContentType.Types.Link;
                        feed.ReferenceID = link_id;
                        feed.OwnerID = user.UserID;
                        feed.OwnerName = user.UserName;
                        feed.OwnerProfilePic = user.ProfilePict;
                        feed.Type = "link";
                        feed.Title = p_title;
                        feed.Description = p_description;
                        feed.Body = p_description;
                        feed.OwnerRole = user.HighestRole;
                        feed.OwnerRoleID = user.HighestRank;
                        feed.URL = link.URL;

                        feed.VisibleAll = true;
                        feed.VisibleFriends = true;
                        feed.VisibleFollowers = true;
                        feed.VisibleSpace = true;
                        feed.VisiblePrivate = true;
                        feed.VisibleFeed = true;
                        feed.VisibleOwnerFeed = true;
                        feed.VisibleOwnerProfile = true;
                        if (!String.IsNullOrEmpty(ddlTheme.SelectedValue))
                        {
                            feed.ThemeID = Convert.ToInt32(ddlTheme.SelectedValue);
                            feed.ThemeName = Convert.ToString(ddlTheme.SelectedItem);
                        }
                        feed.ReservedKeywords = reserved_keywords;
                        if (!String.IsNullOrEmpty(owner_keywords))
                        {
                            feed.OwnerKeywords = owner_keywords;
                        }
                        feed.UploadedFrom = "manager";
                        if (chkDisplayInFeed.Checked)
                            feed.VisibleFeed = true;
                        else
                            feed.VisibleFeed = false;
                        if (chkDisplayInExplore.Checked)
                            feed.VisibleExplore = true;
                        else
                            feed.VisibleExplore = false;
                        feed.Insert();
                    }
                }
            }

            // redirect to page to add link + keywords
            if (!String.IsNullOrEmpty(Request.QueryString["linkID"]))
            {
                //lblMessage.Text = "*** Record Successfully Updated ***";
                //lblMessageBottom.Text = "*** Record Successfully Updated ***";
                Response.Redirect("links-list.aspx");
            }
            else
            {
                Response.Redirect(Request.Url.ToString() + "?mode=add-successful&linkID=" + link_id);
            }
        }
    }
    protected void btnSave_OnClick(object sender, System.EventArgs e)
    {
        Page.Validate("form");

        if (Page.IsValid)
        {

            int user_id = Convert.ToInt32(Context.Items["UserID"]);

            if (!String.IsNullOrEmpty(Request.QueryString["tipID"]))
            {
                tip_id = Convert.ToInt32(Request.QueryString["tipID"]);
                qSoc_Tip tip = new qSoc_Tip(tip_id);
                tip.Name = txtTitle.Text;
                tip.Summary = txtSummary.Text;
                tip.Text = txtTip.Text;
                tip.LearnMoreURL = txtURL.Text;
                tip.LastModified = DateTime.Now;
                tip.LastModifiedBy = user_id;
                tip.Type = ddlTipType.SelectedValue;
                if (!String.IsNullOrEmpty(ddlTheme.SelectedValue))
                    tip.ThemeID = Convert.ToInt32(ddlTheme.SelectedValue);
                tip.Available = rblAvailable.SelectedValue;
                tip.Author = txtAuthor.Text;
                tip.Update();
            }
            else
            {
                qSoc_Tip tip = new qSoc_Tip();
                tip.ScopeID = 1;
                tip.Created = DateTime.Now;
                tip.CreatedBy = user_id;
                tip.LastModified = DateTime.Now;
                tip.LastModifiedBy = user_id;
                tip.Available = "Yes";
                tip.MarkAsDelete = 0;
                tip.Name = txtTitle.Text;
                tip.Summary = txtSummary.Text;
                tip.Text = txtTip.Text;
                tip.LearnMoreURL = txtURL.Text;
                tip.LastModified = DateTime.Now;
                tip.LastModifiedBy = user_id;
                tip.Type = ddlTipType.SelectedValue;
                if (!String.IsNullOrEmpty(ddlTheme.SelectedValue))
                    tip.ThemeID = Convert.ToInt32(ddlTheme.SelectedValue);
                tip.Available = rblAvailable.SelectedValue;
                tip.Author = txtAuthor.Text;
                tip.Insert();

                tip_id = tip.TipID;
            }

            string user_name = (new qPtl_User(user_id)).UserName;

            // add keywords
            string owner_keywords = string.Empty;
            qPtl_KeywordReference.DeleteKeywordReferencesByContent((int)qSoc_ContentType.Types.Tip, tip_id);
            foreach (ListItem item in cblKeywords.Items)
            {
                if (item.Selected)
                {
                    if (!String.IsNullOrEmpty(owner_keywords))
                        owner_keywords += "," + item.Text;
                    else
                        owner_keywords += item.Text;
                    qPtl_KeywordReference keyword = new qPtl_KeywordReference();
                    keyword.Available = "Yes";
                    keyword.ScopeID = Convert.ToInt32(Context.Items["ScopeID"]);
                    keyword.KeywordID = Convert.ToInt32(item.Value);
                    keyword.ContentTypeID = (int)qSoc_ContentType.Types.Tip;
                    keyword.ReferenceID = tip_id;
                    keyword.Created = DateTime.Now;
                    keyword.LastModified = DateTime.Now;
                    keyword.CreatedBy = Convert.ToInt32(Context.Items["UserID"]);
                    keyword.LastModifiedBy = Convert.ToInt32(Context.Items["UserID"]);
                    keyword.MarkAsDelete = 0;
                    keyword.Insert();
                }
            }

            string reserved_keywords = string.Empty;
            foreach (ListItem item in chkTopics.Items)
            {
                if (item.Selected)
                {
                    if (!String.IsNullOrEmpty(reserved_keywords))
                        reserved_keywords += "," + item.Text;
                    else
                        reserved_keywords += item.Text;
                }
            }

            qSoc_Feed feed = new qSoc_Feed((int)qSoc_ContentType.Types.Tip, tip_id);

            if (!chkDisplayInFeed.Checked && !chkDisplayInExplore.Checked)
            {
                if (feed != null)
                {
                    if (feed.FeedID > 0)
                    {
                        feed.MarkAsDelete = 1;
                        feed.Available = "No";
                        feed.ReservedKeywords = reserved_keywords;
                        if (!chkDisplayInFeed.Checked)
                            feed.VisibleFeed = false;
                        if (!chkDisplayInExplore.Checked)
                            feed.VisibleExplore = false;
                        feed.Update();
                    }
                }
            }
            else if (chkDisplayInFeed.Checked || chkDisplayInExplore.Checked || !string.IsNullOrEmpty(reserved_keywords))
            {
                qSoc_Tip tip = new qSoc_Tip(tip_id);

                int p_user_id = user_id;
                if (post_as_user_id > 0)
                    p_user_id = post_as_user_id;

                qPtl_User user = new qPtl_User(p_user_id);
                var u_space = qSoc_UserSpace_View.GetUserSpaces(tip.CreatedBy);

                // evaluate title and description
                string p_title = q_Helper.replaceSpecialCharacters(tip.Name);
                string p_description = q_Helper.replaceSpecialCharacters(tip.Text);

                if (feed != null)
                {
                    if (feed.FeedID > 0)
                    {
                        feed.CreatedBy = user.UserID;
                        feed.Available = tip.Available;
                        if (chkMoveToTop.Checked)
                            feed.LastModified = DateTime.Now;
                        feed.LastModifiedBy = user.UserID;
                        feed.MarkAsDelete = tip.MarkAsDelete;
                        feed.OwnerMarkAsDelete = tip.MarkAsDelete;
                        feed.ContentTypeID = (int)qSoc_ContentType.Types.Tip;
                        feed.ReferenceID = tip_id;
                        feed.OwnerID = user.UserID;
                        feed.OwnerName = user.UserName;
                        feed.OwnerProfilePic = user.ProfilePict;
                        feed.Type = "tip";
                        feed.Title = p_title;
                        feed.Description = p_description;
                        feed.Body = p_description;
                        feed.OwnerRole = user.HighestRole;
                        feed.OwnerRoleID = user.HighestRank;
                        feed.OwnerKeywords = owner_keywords;
                        feed.ReservedKeywords = reserved_keywords;
                        feed.UploadedFrom = "manager";
                        if (!String.IsNullOrEmpty(ddlTheme.SelectedValue))
                        {
                            feed.ThemeID = Convert.ToInt32(ddlTheme.SelectedValue);
                            feed.ThemeName = Convert.ToString(ddlTheme.SelectedItem);
                        }
                        if (chkDisplayInFeed.Checked)
                            feed.VisibleFeed = true;
                        else
                            feed.VisibleFeed = false;
                        if (chkDisplayInExplore.Checked)
                            feed.VisibleExplore = true;
                        else
                            feed.VisibleExplore = false;
                        feed.Update();
                    }
                    else
                    {
                        // create new feed item
                        if (u_space != null)
                        {
                            foreach (var s in u_space)
                            {
                                feed.SpaceID = s.SpaceID;
                                feed.SpaceName = s.SpaceShortName;
                            }
                        }
                        feed.ScopeID = Convert.ToInt32(Context.Items["ScopeID"]);
                        feed.Available = tip.Available;
                        feed.Created = DateTime.Now;
                        feed.CreatedBy = user.UserID;
                        feed.LastModified = DateTime.Now;
                        feed.LastModifiedBy = user.UserID;
                        feed.MarkAsDelete = tip.MarkAsDelete;
                        feed.OwnerMarkAsDelete = tip.MarkAsDelete;
                        feed.ContentTypeID = (int)qSoc_ContentType.Types.Tip;
                        feed.ReferenceID = tip_id;
                        feed.OwnerID = user.UserID;
                        feed.OwnerName = user.UserName;
                        feed.OwnerProfilePic = user.ProfilePict;
                        feed.Type = "tip";
                        feed.Title = p_title;
                        feed.Description = p_description;
                        feed.Body = p_description;
                        feed.OwnerRole = user.HighestRole;
                        feed.OwnerRoleID = user.HighestRank;

                        feed.VisibleAll = true;
                        feed.VisibleFriends = true;
                        feed.VisibleFollowers = true;
                        feed.VisibleSpace = true;
                        feed.VisiblePrivate = true;
                        feed.VisibleFeed = true;
                        feed.VisibleOwnerFeed = true;
                        feed.VisibleOwnerProfile = true;
                        if (!String.IsNullOrEmpty(ddlTheme.SelectedValue))
                        {
                            feed.ThemeID = Convert.ToInt32(ddlTheme.SelectedValue);
                            feed.ThemeName = Convert.ToString(ddlTheme.SelectedItem);
                        }
                        feed.ReservedKeywords = reserved_keywords;
                        if (!String.IsNullOrEmpty(owner_keywords))
                        {
                            feed.OwnerKeywords = owner_keywords;
                        }
                        feed.UploadedFrom = "manager";
                        if (chkDisplayInFeed.Checked)
                            feed.VisibleFeed = true;
                        else
                            feed.VisibleFeed = false;
                        if (chkDisplayInExplore.Checked)
                            feed.VisibleExplore = true;
                        else
                            feed.VisibleExplore = false;
                        feed.Insert();
                    }
                }
            }

            if (!String.IsNullOrEmpty(Request.QueryString["tipID"]))
            {
                lblMessage.Text = "*** Record Successfully Updated ***";
                lblMessageBottom.Text = "*** Record Successfully Updated ***";
                if (Request.QueryString["edit-mode"] == "in-place")
                    Response.Redirect(Request.QueryString["returnURL"]);
                else
                    Response.Redirect("tips-list.aspx");
            }
            else
            {
                Response.Redirect(Request.Url.ToString() + "?mode=add-successful&tipID=" + tip_id);
            }
        }
    }
    protected void btnSave_OnClick(object sender, System.EventArgs e)
    {
        Page.Validate("form");

        if (Page.IsValid)
        {

            int user_id = Convert.ToInt32(Context.Items["UserID"]);
            video_id = Convert.ToInt32(Request.QueryString["videoID"]);

            string user_name = (new qPtl_User(user_id)).UserName;

            qSoc_Video video = new qSoc_Video(video_id);
            video.Title = txtTitle.Text;
            video.Description = txtDescription.Text;
            if (!String.IsNullOrEmpty(ddlTheme.SelectedValue))
                video.ThemeID = Convert.ToInt32(ddlTheme.SelectedValue);
            video.Status = "Approved";
            video.Created = video.Created;
            video.CreatedBy = video.CreatedBy;
            video.Approved = DateTime.Now;
            video.Source = lblVideoType.Text;
            video.LastModified = DateTime.Now;
            video.LastModifiedBy = user_id;
            video.Length = video.Length;
            video.EmbedCode = txtEmbed.Text;
            if (txtPreviewImage.Visible == true)
                video.ThumbnailURL = txtPreviewImage.Text;
            video.SourceVideoID = txtSourceVideoID.Text;
            if (!String.IsNullOrEmpty(ddlExternalSource.SelectedValue))
                video.ExternalSourceName = ddlExternalSource.SelectedValue;
            string author = string.Empty;
            author = ddlAuthor.SelectedValue;
            if (!String.IsNullOrEmpty(author))
                video.AuthorID = Convert.ToInt32(ddlAuthor.SelectedValue);
            video.Available = rblAvailable.SelectedValue;

            // process if highlighted video
            qDbs_SQLcode sql = new qDbs_SQLcode();
            string sqlCode = string.Empty;
            sqlCode = "UPDATE qSoc_Videos SET HighlightedWF = null";

            qSoc_HighlightedVideo.Delete(video_id);

            if (lblHighlightedMessage.Text.Contains("current") && chkHighlightedVideo.Checked == false)
            {
                sql.ExecuteSQL(sqlCode);
                video.HighlightedWF = null;
            }
            else if (chkHighlightedVideo.Checked && lblHighlightedMessage.Text.Contains("current"))
            {
                sql.ExecuteSQL(sqlCode);
                qSoc_HighlightedVideo high_video = new qSoc_HighlightedVideo();
                high_video = qSoc_HighlightedVideo.GetLatest();
                high_video.Available = "No";
                high_video.Created = DateTime.Now;
                high_video.CreatedBy = user_id;
                high_video.LastModified = DateTime.Now;
                high_video.LastModifiedBy = user_id;
                high_video.MarkAsDelete = 1;
                high_video.Status = "Hidden";
                high_video.Update();
            }
            else if (chkHighlightedVideo.Checked && lblHighlightedMessage.Text.Contains("Check"))
            {
                sql.ExecuteSQL(sqlCode);
                qSoc_HighlightedVideo new_highlighted = new qSoc_HighlightedVideo();
                new_highlighted.VideoID = video_id;
                new_highlighted.ScopeID = Convert.ToInt32(Context.Items["ScopeID"]);
                new_highlighted.Available = "Yes";
                new_highlighted.Created = DateTime.Now;
                new_highlighted.CreatedBy = user_id;
                new_highlighted.LastModified = DateTime.Now;
                new_highlighted.LastModifiedBy = user_id;
                new_highlighted.MarkAsDelete = 0;
                new_highlighted.Status = "Visible";
                new_highlighted.Insert();
                video.HighlightedWF = "Yes";
            }
            video.Update();

            // add keywords
            string owner_keywords = string.Empty;
            qPtl_KeywordReference.DeleteKeywordReferencesByContent((int)qSoc_ContentType.Types.Video, video_id);
            foreach (ListItem item in cblKeywords.Items)
            {
                if (item.Selected)
                {
                    if (!String.IsNullOrEmpty(owner_keywords))
                        owner_keywords += "," + item.Text;
                    else
                        owner_keywords += item.Text;
                    qPtl_KeywordReference keyword = new qPtl_KeywordReference();
                    keyword.Available = "Yes";
                    keyword.ScopeID = Convert.ToInt32(Context.Items["ScopeID"]);
                    keyword.KeywordID = Convert.ToInt32(item.Value);
                    keyword.ContentTypeID = (int)qSoc_ContentType.Types.Video;
                    keyword.ReferenceID = video_id;
                    keyword.Created = DateTime.Now;
                    keyword.LastModified = DateTime.Now;
                    keyword.CreatedBy = Convert.ToInt32(Context.Items["UserID"]);
                    keyword.LastModifiedBy = Convert.ToInt32(Context.Items["UserID"]);
                    keyword.MarkAsDelete = 0;
                    keyword.Insert();
                }
            }

            string reserved_keywords = string.Empty;
            foreach (ListItem item in chkTopics.Items)
            {
                if (item.Selected)
                {
                    if (!String.IsNullOrEmpty(reserved_keywords))
                        reserved_keywords += "," + item.Text;
                    else
                        reserved_keywords += item.Text;
                }
            }

            qSoc_Feed feed = new qSoc_Feed((int)qSoc_ContentType.Types.Video, video.VideoID);

            if (!chkDisplayInFeed.Checked && !chkDisplayInExplore.Checked)
            {
                if (feed != null)
                {
                    if (feed.FeedID > 0)
                    {
                        feed.MarkAsDelete = 1;
                        feed.Available = "No";
                        feed.ReservedKeywords = reserved_keywords;
                        if (!chkDisplayInFeed.Checked)
                            feed.VisibleFeed = false;
                        if (!chkDisplayInExplore.Checked)
                            feed.VisibleExplore = false;
                        feed.Update();
                    }
                }
            }
            else if (chkDisplayInFeed.Checked || chkDisplayInExplore.Checked || !string.IsNullOrEmpty(reserved_keywords))
            {
                int p_user_id = user_id;
                if (post_as_user_id > 0)
                    p_user_id = post_as_user_id;

                qPtl_User user = new qPtl_User(p_user_id);
                var u_space = qSoc_UserSpace_View.GetUserSpaces(video.CreatedBy);

                if (feed != null)
                {
                    if (feed.FeedID > 0)
                    {
                        feed.Available = video.Available;
                        feed.ScopeID = Convert.ToInt32(Context.Items["ScopeID"]);
                        feed.CreatedBy = user.UserID;
                        if (chkMoveToTop.Checked)
                            feed.LastModified = DateTime.Now;
                        feed.LastModified = video.LastModified;
                        feed.LastModifiedBy = user.UserID;
                        feed.MarkAsDelete = video.MarkAsDelete;
                        feed.OwnerMarkAsDelete = video.MarkAsDelete;
                        feed.ContentTypeID = (int)qSoc_ContentType.Types.Video;
                        feed.ReferenceID = video.VideoID;
                        feed.OwnerID = user.UserID;
                        feed.OwnerName = user.UserName;
                        feed.OwnerProfilePic = user.ProfilePict;
                        feed.Type = "video";
                        feed.Title = video.Title;
                        feed.Description = video.Description;
                        feed.OwnerRole = user.HighestRole;
                        feed.OwnerRoleID = user.HighestRank;
                        feed.OwnerKeywords = owner_keywords;
                        feed.UploadedFrom = "manager";
                        feed.ReservedKeywords = reserved_keywords;
                        feed.Thumbnail = video.ThumbnailURL;
                        if (!String.IsNullOrEmpty(ddlTheme.SelectedValue))
                        {
                            feed.ThemeID = Convert.ToInt32(ddlTheme.SelectedValue);
                            feed.ThemeName = Convert.ToString(ddlTheme.SelectedItem);
                        }
                        if (video.Source == "internal")
                        {
                            feed.VideoKey = video.ViddlerID;
                        }
                        else
                        {
                            string embed_code = Convert.ToString(video.EmbedCode);
                            feed.Embed = embed_code;
                            feed.VideoKey = null;
                        }
                        if (chkDisplayInFeed.Checked)
                            feed.VisibleFeed = true;
                        else
                            feed.VisibleFeed = false;
                        if (chkDisplayInExplore.Checked)
                            feed.VisibleExplore = true;
                        else
                            feed.VisibleExplore = false;
                        feed.Update();
                    }
                    else
                    {
                        // create new feed item
                        if (u_space != null)
                        {
                            foreach (var s in u_space)
                            {
                                feed.SpaceID = s.SpaceID;
                                feed.SpaceName = s.SpaceShortName;
                            }
                        }
                        feed.Available = video.Available;
                        feed.ScopeID = Convert.ToInt32(Context.Items["ScopeID"]);
                        feed.Created = DateTime.Now;    //video.Created;
                        feed.CreatedBy = user.UserID;
                        feed.LastModified = DateTime.Now;
                        feed.LastModifiedBy = user.UserID;
                        feed.MarkAsDelete = video.MarkAsDelete;
                        feed.OwnerMarkAsDelete = video.MarkAsDelete;
                        feed.ContentTypeID = (int)qSoc_ContentType.Types.Video;
                        feed.ReferenceID = video.VideoID;
                        feed.OwnerID = user.UserID;
                        feed.OwnerName = user.UserName;
                        feed.OwnerProfilePic = user.ProfilePict;
                        feed.Type = "video";
                        feed.Title = video.Title;
                        feed.Description = video.Description;
                        feed.OwnerRole = user.HighestRole;
                        feed.OwnerRoleID = user.HighestRank;
                        feed.OwnerKeywords = owner_keywords;
                        feed.UploadedFrom = "manager";
                        feed.ReservedKeywords = reserved_keywords;
                        feed.Thumbnail = video.ThumbnailURL;
                        if (!String.IsNullOrEmpty(ddlTheme.SelectedValue))
                        {
                            feed.ThemeID = Convert.ToInt32(ddlTheme.SelectedValue);
                            feed.ThemeName = Convert.ToString(ddlTheme.SelectedItem);
                        }
                        if (video.Source == "internal")
                        {
                            feed.VideoKey = video.ViddlerID;
                        }
                        else
                        {
                            string embed_code = Convert.ToString(video.EmbedCode);
                            feed.Embed = embed_code;
                        }

                        feed.VisibleAll = true;
                        feed.VisibleFriends = true;
                        feed.VisibleFollowers = true;
                        feed.VisibleSpace = true;
                        feed.VisiblePrivate = true;
                        feed.VisibleFeed = true;
                        feed.VisibleOwnerFeed = true;
                        feed.VisibleOwnerProfile = true;
                        if (!String.IsNullOrEmpty(owner_keywords))
                        {
                            feed.OwnerKeywords = owner_keywords;
                        }
                        if (chkDisplayInFeed.Checked)
                            feed.VisibleFeed = true;
                        else
                            feed.VisibleFeed = false;
                        if (chkDisplayInExplore.Checked)
                            feed.VisibleExplore = true;
                        else
                            feed.VisibleExplore = false;
                        feed.Insert();

                    }
                }
            }

            // see if there is a pending task for this video
            if (video.Status == "Approved")
            {
                qPtl_Task task = new qPtl_Task((int)qSoc_ContentType.Types.Video, video_id);

                if (task != null)
                {
                    if (task.TaskID > 0)
                    {
                        task.PercentCompleted = 100;
                        task.Status = "Completed";
                        task.Update();
                    }
                }
            }

            // redirect to page to add theme + keywords
            //  Response.Redirect("~/qSoc/videos-list.aspx");
            lblMessage.Text = "*** Record Successfully Updated ***";
            lblMessageBottom.Text = "*** Record Successfully Updated ***";
        }
    }
    protected void btnSave_OnClick(object sender, System.EventArgs e)
    {
        int user_id = Convert.ToInt32(Context.Items["UserID"]);

        if (!String.IsNullOrEmpty(Request.QueryString["BlogID"]))
        {
            blog_id = Convert.ToInt32(Request.QueryString["BlogID"]);
            qSoc_Blog2 blog = new qSoc_Blog2(blog_id);
            blog.Title = txtTitle.Text;
            blog.Summary = txtSummary.Text;
            blog.Text = reContent.Content;
            blog.LastModified = DateTime.Now;
            blog.LastModifiedBy = user_id;
            if (!String.IsNullOrEmpty(ddlAuthor.SelectedValue))
                blog.AuthorID = Convert.ToInt32(ddlAuthor.SelectedValue);
            if (!String.IsNullOrEmpty(ddlTheme.SelectedValue))
                blog.ThemeID = Convert.ToInt32(ddlTheme.SelectedValue);
            blog.Available = rblAvailable.SelectedValue;
            blog.Type = rblType.SelectedValue;
            blog.ApprovedStatus = ddlStatus.SelectedValue;
            if (ddlStatus.SelectedValue == "Approved")
            {
                blog.ApprovedBy = user_id;
                blog.Approved = DateTime.Now;
            }
            blog.Update();
        }
        else
        {
            qSoc_Blog2 blog = new qSoc_Blog2();
            blog.ScopeID = 1;
            blog.Created = DateTime.Now;
            blog.CreatedBy = user_id;
            blog.LastModified = DateTime.Now;
            blog.LastModifiedBy = user_id;
            blog.Available = "Yes";
            blog.MarkAsDelete = 0;
            blog.UserID = user_id;
            blog.Title = txtTitle.Text;
            blog.Summary = txtSummary.Text;
            blog.Text = reContent.Content;
            blog.LastModified = DateTime.Now;
            blog.LastModifiedBy = user_id;
            if (!String.IsNullOrEmpty(ddlAuthor.SelectedValue))
                blog.AuthorID = Convert.ToInt32(ddlAuthor.SelectedValue);
            if (!String.IsNullOrEmpty(ddlTheme.SelectedValue))
                blog.ThemeID = Convert.ToInt32(ddlTheme.SelectedValue);
            blog.Available = rblAvailable.SelectedValue;
            blog.Type = rblType.SelectedValue;
            blog.ApprovedStatus = ddlStatus.SelectedValue;
            if (ddlStatus.SelectedValue == "Approved")
            {
                blog.ApprovedBy = user_id;
                blog.Approved = DateTime.Now;
            }
            blog.UploadedFrom = "manager";
            blog.Insert();

            blog_id = blog.BlogID;
        }

        string user_name = (new qPtl_User(user_id)).UserName;

        // add keywords
        string owner_keywords = string.Empty;
        qPtl_KeywordReference.DeleteKeywordReferencesByContent((int)qSoc_ContentType.Types.Story, blog_id);
        foreach (ListItem item in cblKeywords.Items)
        {
            if (item.Selected)
            {
                if (!String.IsNullOrEmpty(owner_keywords))
                    owner_keywords += "," + item.Text;
                else
                    owner_keywords += item.Text;
                qPtl_KeywordReference keyword = new qPtl_KeywordReference();
                keyword.Available = "Yes";
                keyword.ScopeID = Convert.ToInt32(Context.Items["ScopeID"]);
                keyword.KeywordID = Convert.ToInt32(item.Value);
                keyword.ContentTypeID = (int)qSoc_ContentType.Types.Story;
                keyword.ReferenceID = blog_id;
                keyword.Created = DateTime.Now;
                keyword.LastModified = DateTime.Now;
                keyword.CreatedBy = Convert.ToInt32(Context.Items["UserID"]);
                keyword.LastModifiedBy = Convert.ToInt32(Context.Items["UserID"]);
                keyword.MarkAsDelete = 0;
                keyword.Insert();
            }
        }

        string reserved_keywords = string.Empty;
        foreach (ListItem item in chkTopics.Items)
        {
            if (item.Selected)
            {
                if (!String.IsNullOrEmpty(reserved_keywords))
                    reserved_keywords += "," + item.Text;
                else
                    reserved_keywords += item.Text;
            }
        }

        // process if highlighted blog
        qDbs_SQLcode sql = new qDbs_SQLcode();
        string sqlCode = string.Empty;
        sqlCode = "UPDATE qSoc_Blogs SET Highlighted = null";

        if (lblHighlightedMessage.Text.Contains("current") && chkHighlightedItem.Checked == false)
        {
            sql.ExecuteSQL(sqlCode);        // clear all highlighted options
        }
        else if (chkHighlightedItem.Checked && lblHighlightedMessage.Text.Contains("current"))
        {
            sql.ExecuteSQL(sqlCode);        // clear all highlighted options
            qSoc_Blog2 curr_item = new qSoc_Blog2(blog_id);
            curr_item.Highlighted = true;
            curr_item.Update();
        }
        else if (chkHighlightedItem.Checked && lblHighlightedMessage.Text.Contains("Check"))
        {
            sql.ExecuteSQL(sqlCode);        // clear all highlighted options
            qSoc_Blog2 blog = new qSoc_Blog2(blog_id);
            blog.Highlighted = true;
            blog.Update();
        }

        qSoc_Feed feed = new qSoc_Feed((int)qSoc_ContentType.Types.Story, blog_id);

        if (!chkDisplayInFeed.Checked && !chkDisplayInExplore.Checked)
        {
            if (feed != null)
            {
                if (feed.FeedID > 0)
                {
                    feed.MarkAsDelete = 1;
                    feed.Available = "No";
                    feed.ReservedKeywords = reserved_keywords;
                    if (!chkDisplayInFeed.Checked)
                        feed.VisibleFeed = false;
                    if (!chkDisplayInExplore.Checked)
                        feed.VisibleExplore = false;
                    feed.Update();
                }
            }
        }
        else if (chkDisplayInFeed.Checked || chkDisplayInExplore.Checked || !string.IsNullOrEmpty(reserved_keywords))
        {
            qSoc_Blog2 blog = new qSoc_Blog2(blog_id);

            int p_user_id = user_id;
            if (post_as_user_id > 0)
                p_user_id = post_as_user_id;

            qPtl_User user = new qPtl_User(p_user_id);
            var u_space = qSoc_UserSpace_View.GetUserSpaces(blog.CreatedBy);

            // evaluate title and description
            string p_title = blog.Title.Replace("'", "\"");
            p_title = q_Helper.replaceSpecialCharacters(p_title);
            string p_description = q_Helper.replaceSpecialCharacters(blog.Summary);

            if (feed != null)
            {
                if (feed.FeedID > 0)
                {
                    feed.CreatedBy = user.UserID;
                    feed.Available = blog.Available;
                    if (chkMoveToTop.Checked)
                        feed.LastModified = DateTime.Now;
                    feed.LastModifiedBy = user.UserID;
                    feed.MarkAsDelete = blog.MarkAsDelete;
                    feed.OwnerMarkAsDelete = blog.MarkAsDelete;
                    feed.ContentTypeID = (int)qSoc_ContentType.Types.Story;
                    feed.ReferenceID = blog_id;
                    feed.OwnerID = user.UserID;
                    feed.OwnerName = user.UserName;
                    feed.OwnerProfilePic = user.ProfilePict;
                    feed.Type = "blog";
                    feed.Title = p_title;
                    feed.Description = p_description;
                    feed.Body = p_description;
                    feed.OwnerRole = user.HighestRole;
                    feed.OwnerRoleID = user.HighestRank;
                    feed.OwnerKeywords = owner_keywords;
                    feed.ReservedKeywords = reserved_keywords;
                    feed.UploadedFrom = "manager";
                    if (!String.IsNullOrEmpty(ddlTheme.SelectedValue))
                    {
                        feed.ThemeID = Convert.ToInt32(ddlTheme.SelectedValue);
                        feed.ThemeName = Convert.ToString(ddlTheme.SelectedItem);
                    }
                    if (chkDisplayInFeed.Checked)
                        feed.VisibleFeed = true;
                    else
                        feed.VisibleFeed = false;
                    if (chkDisplayInExplore.Checked)
                        feed.VisibleExplore = true;
                    else
                        feed.VisibleExplore = false;
                    feed.Update();
                }
                else
                {
                    // create new feed item
                    if (u_space != null)
                    {
                        foreach (var s in u_space)
                        {
                            feed.SpaceID = s.SpaceID;
                            feed.SpaceName = s.SpaceShortName;
                        }
                    }
                    feed.ScopeID = Convert.ToInt32(Context.Items["ScopeID"]);
                    feed.Available = blog.Available;
                    feed.Created = DateTime.Now;
                    feed.CreatedBy = user.UserID;
                    feed.LastModified = DateTime.Now;
                    feed.LastModifiedBy = user.UserID;
                    feed.MarkAsDelete = blog.MarkAsDelete;
                    feed.OwnerMarkAsDelete = blog.MarkAsDelete;
                    feed.ContentTypeID = (int)qSoc_ContentType.Types.Story;
                    feed.ReferenceID = blog_id;
                    feed.OwnerID = user.UserID;
                    feed.OwnerName = user.UserName;
                    feed.OwnerProfilePic = user.ProfilePict;
                    feed.Type = "blog";
                    feed.Title = p_title;
                    feed.Description = p_description;
                    feed.Body = p_description;
                    feed.OwnerRole = user.HighestRole;
                    feed.OwnerRoleID = user.HighestRank;

                    feed.VisibleAll = true;
                    feed.VisibleFriends = true;
                    feed.VisibleFollowers = true;
                    feed.VisibleSpace = true;
                    feed.VisiblePrivate = true;
                    feed.VisibleFeed = true;
                    feed.VisibleOwnerFeed = true;
                    feed.VisibleOwnerProfile = true;
                    if (!String.IsNullOrEmpty(ddlTheme.SelectedValue))
                    {
                        feed.ThemeID = Convert.ToInt32(ddlTheme.SelectedValue);
                        feed.ThemeName = Convert.ToString(ddlTheme.SelectedItem);
                    }
                    feed.ReservedKeywords = reserved_keywords;
                    if (!String.IsNullOrEmpty(owner_keywords))
                    {
                        feed.OwnerKeywords = owner_keywords;
                    }
                    feed.UploadedFrom = "manager";
                    if (chkDisplayInFeed.Checked)
                        feed.VisibleFeed = true;
                    else
                        feed.VisibleFeed = false;
                    if (chkDisplayInExplore.Checked)
                        feed.VisibleExplore = true;
                    else
                        feed.VisibleExplore = false;
                    feed.Insert();
                }
            }
        }

        //Response.Redirect("~/qSoc/blogs-list.aspx");
        if (!String.IsNullOrEmpty(Request.QueryString["BlogID"]))
        {
            lblMessage.Text = "*** Record Successfully Updated ***";
            lblMessageBottom.Text = "*** Record Successfully Updated ***";
        }
        else
        {
            if (!String.IsNullOrEmpty(Request.QueryString["type"]))
                Response.Redirect(Request.Url.ToString() + "&mode=add-successful&BlogID=" + blog_id);
            else
                Response.Redirect(Request.Url.ToString() + "?mode=add-successful&BlogID=" + blog_id);
        }
    }