Esempio n. 1
0
        protected void checkedCategories_DataBound(object sender, EventArgs e)
        {
            ListItemCollection checkedCats = checkedCategories.Items;
            CheckBox           showInt     = ResultsPanel.FindControl("showIntStakeholders") as CheckBox;

            /* Remove last (special) and the first (general) categories */

            if (checkedCats.Count > 6) // check that there is the 'special' category (= 'Other' selected in start)
            {
                checkedCats.RemoveAt(6);
                showInt.Visible = true;
            }
            else
            {
                showInt.Visible = false;
            }
            checkedCats.RemoveAt(0);

            for (int i = 0; i < checkedCats.Count; i++)
            {
                checkedCats[i].Selected = true;
                checkedCats[i].Attributes.Add("Name", "checkedCategories");
            }
        }
Esempio n. 2
0
        ///*Shows the sql being executed  */
        //protected void SqlDemographics_Inserting(object sender, SqlDataSourceCommandEventArgs e)
        //{
        //    SqlParameterCollection myCollection = (SqlParameterCollection)e.Command.Parameters;

        //    IEnumerator ie = myCollection.GetEnumerator();
        //    string strSQL = string.Empty;
        //    while ((ie.MoveNext()))
        //    {
        //        SqlParameter param = (SqlParameter)ie.Current;
        //        string strValue = string.Empty;
        //        if (param.Value == null)
        //            strValue = "NULL";
        //        else
        //            strValue = param.Value.ToString();

        //        strSQL += param.ParameterName.ToString() + "=" + strValue + "<BR />";
        //    }

        //    Response.Write(strSQL.ToString());
        //}


        protected void FinishButton_Click(object sender, EventArgs e)
        {
            string[] stringSeparators = new string[] { "--" };
            string[] questions        = HiddenQuestions.Value.Split(stringSeparators, System.StringSplitOptions.None);
            string[] answers          = HiddenAnswers.Value.Split(stringSeparators, System.StringSplitOptions.None);
            string[] ratings          = HiddenRatings.Value.Split(stringSeparators, System.StringSplitOptions.None);
            string   Culture          = System.Threading.Thread.CurrentThread.CurrentCulture.Name;

            DropDownList LanguageSelector = (DropDownList)CategoriesDataList.FindControl("LanguageSelector");

            targetCountry = LanguageSelector.SelectedValue;

            string timestamp       = GetTimestamp(System.DateTime.Now);
            string datetime        = DateTime.Now.ToString("yyyy-MM-dd H:mm:ss zzz");
            string anonymousUserId = "";

            for (int i = 0; i < questions.Length - 1; i++)
            {
                SqlCategories.InsertParameters["ModuleId"].DefaultValue        = this.ModuleId.ToString();
                SqlCategories.InsertParameters["QuestionnaireID"].DefaultValue = timestamp;
                SqlCategories.InsertParameters["QuestionID"].DefaultValue      = questions[i];
                SqlCategories.InsertParameters["Locale"].DefaultValue          = Culture;
                SqlCategories.InsertParameters["TargetedCountry"].DefaultValue = targetCountry;
                SqlCategories.InsertParameters["AnswerID"].DefaultValue        = answers[i];
                SqlCategories.InsertParameters["AnsweredOnDate"].DefaultValue  = datetime;

                if (Request.IsAuthenticated)
                {
                    SqlCategories.InsertParameters["AnsweredByUser"].DefaultValue = this.UserId.ToString();
                    SqlCategories.InsertParameters["AnonymousGuid"].DefaultValue  = "";
                }
                else
                {
                    HttpCookie pbpCookie = Request.Cookies.Get("puzzledByPolicy");
                    if (pbpCookie != null)
                    {
                        anonymousUserId = pbpCookie["anonymousId"];
                    }
                    else
                    {
                        anonymousUserId = SetCookie("puzzledByPolicy").ToString();
                    }
                    SqlCategories.InsertParameters["AnsweredByUser"].DefaultValue = "-1";
                    SqlCategories.InsertParameters["AnonymousGuid"].DefaultValue  = anonymousUserId;
                }
                // IP  = Request.UserHostAddress()
                SqlCategories.InsertParameters["Rating"].DefaultValue = ratings[i];
                try
                {
                    SqlCategories.Insert();
                }
                catch (FormatException ex)
                {
                    Response.Redirect("http://join.puzzledbypolicy.eu/");
                }
            }

            LinkButton sendingBtn = (LinkButton)sender;

            /* If SubmitDemogBtn has been clicked, we also save the demographics
             * answers
             */
            if (sendingBtn.ID.Equals("SubmitDemogBtn"))
            {
                if (Request.IsAuthenticated)
                {
                    SqlDemographics.InsertParameters["userID"].DefaultValue = this.UserId.ToString();
                }
                else
                {
                    SqlDemographics.InsertParameters["userID"].DefaultValue = anonymousUserId;
                }

                SqlDemographics.InsertParameters["QuestionnaireID"].DefaultValue = timestamp;

                if (!DEM_birthplace.Value.Equals(""))
                {
                    SqlDemographics.InsertParameters["Question1"].DefaultValue = DEM_birthplace.Value;
                }
                if (!DEM_livingplace.Value.Equals(""))
                {
                    SqlDemographics.InsertParameters["Question2"].DefaultValue = DEM_livingplace.Value;
                }
                if (!DEM_age.Value.Equals(""))
                {
                    SqlDemographics.InsertParameters["Question3"].DefaultValue = DEM_age.Value;
                }
                if (!DEM_sex.Value.Equals(""))
                {
                    SqlDemographics.InsertParameters["Question4"].DefaultValue = DEM_sex.Value;
                }
                if (!DEM_education.Value.Equals(""))
                {
                    SqlDemographics.InsertParameters["Question5"].DefaultValue = DEM_education.Value;
                }
                if (!DEM_profession.Value.Equals(""))
                {
                    SqlDemographics.InsertParameters["Question6"].DefaultValue = DEM_profession.Value;
                }
                if (!DEM_municipality.Value.Equals(""))
                {
                    SqlDemographics.InsertParameters["Question7"].DefaultValue = DEM_municipality.Value;
                }

                try
                {
                    SqlDemographics.Insert();
                }
                catch (FormatException ex)
                {
                    Response.Write(ex.Message);
                    return;
                    //Response.Redirect("http://join.puzzledbypolicy.eu/");
                }
            }

            LinkButton save     = (LinkButton)ResultsPanel.FindControl("SaveButton");
            LinkButton clear    = (LinkButton)ResultsPanel.FindControl("ClearButton");
            HyperLink  feedback = (HyperLink)ResultsPanel.FindControl("FeedbackButton");

            save.CssClass  = "saveBtn sBtn_" + Culture;
            clear.CssClass = "clearBtn clBtn_" + Culture;

            feedback.CssClass    = "feedbackBtn fBtn_" + Culture;
            feedback.NavigateUrl = ConfigurationManager.AppSettings["DomainName"] + "/" + Culture + "/feedback.aspx";
            feedback.Target      = "_blank";

            /*We set the hidden field to false so as not to popup the demographics
             * unless we reload the profiler
             */
            //showDemographicsPopup.Value = "false";


            /* Link with u-Debate.
             *
             * Completely agree/disagree: 3 points
             * Tend to agree/disagree :   1 point
             * Neutral/No opinion:       0 points
             *
             * Multiply by Ratings  1 -> 1
             *                      2 -> 2
             *                      3 -> 3
             *
             * Category   Questions
             *    1         2  - 4
             *    2         5  - 6
             *    3         7  - 8
             *    4         9  - 11
             *    5         12 - 14
             */

            int[] weights  = new int[13]; // 13 questions
            int[] extremes = new int[5];
            /* We skip the first(general) and last(specific) questions (plus the last empty cell) */
            for (int an = 1; an <= answers.Length - 3; an++)
            {
                if (answers[an] == "1" || answers[an] == "5")
                {
                    weights[an - 1] = 3;
                }
                else if (answers[an] == "2" || answers[an] == "4")
                {
                    weights[an - 1] = 1;
                }
                else
                {
                    weights[an - 1] = 0;
                }
                if (Convert.ToInt32(ratings[an]) > 0)
                {
                    weights[an - 1] *= Convert.ToInt32(ratings[an]);
                }
            }
            extremes[0] = weights[0] + weights[1] + weights[2];    // employment
            extremes[1] = weights[3] + weights[4];                 //studying
            extremes[2] = weights[5] + weights[6];                 //family reunification
            extremes[3] = weights[7] + weights[8] + weights[9];    //Long-term resident immigrants and citizenship
            extremes[4] = weights[10] + weights[11] + weights[12]; //Irregular migration, re-admission and return

            int topExtreme = 0;

            for (int i = 0; i < 5; i++)
            {
                if (extremes[i] > extremes[topExtreme])
                {
                    topExtreme = i;
                }
            }
            string threadUrl = String.Empty;

            string uDebateText = String.Empty;

            /* Check if the user had selected no answer/neutral in all questions
             * and just link to the home debate page if this is true
             */
            if (extremes[topExtreme] > 0)
            {
                uDebateText = Localization.GetString("uDebateLink" + (topExtreme + 1) + ".Text", LocalResourceFile);
            }
            else
            {
                topExtreme = -1; // no answer so we go to the default threadurl
            }
            if (Culture == "en-GB")
            {
                switch (topExtreme)
                {
                case 0: threadUrl = fetchThreadUrl("59", Culture); break;

                case 1: threadUrl = fetchThreadUrl("60", Culture); break;

                case 2: threadUrl = fetchThreadUrl("61", Culture); break;

                case 3: threadUrl = fetchThreadUrl("62", Culture); break;

                case 4: threadUrl = fetchThreadUrl("63", Culture); break;

                default: threadUrl = "http://join.puzzledbypolicy.eu/en-GB/uDebate.aspx"; break;
                }
            }
            else
            {
                switch (targetCountry)
                {
                case "el-GR": switch (topExtreme)
                    {
                    case 0: threadUrl = fetchThreadUrl("65", Culture); break;

                    case 1: threadUrl = fetchThreadUrl("76", Culture); break;

                    case 2: threadUrl = fetchThreadUrl("77", Culture); break;

                    case 3: threadUrl = fetchThreadUrl("69", Culture); break;

                    case 4: threadUrl = fetchThreadUrl("71", Culture); break;

                    default: threadUrl = "http://join.puzzledbypolicy.eu/el-GR/uDebate.aspx"; break;
                    }
                    break;

                case "es-ES": switch (topExtreme)
                    {
                    case 0: threadUrl = fetchThreadUrl("35", Culture); break;

                    case 1: threadUrl = fetchThreadUrl("36", Culture); break;

                    case 2: threadUrl = fetchThreadUrl("37", Culture); break;

                    case 3: threadUrl = fetchThreadUrl("38", Culture); break;

                    case 4: threadUrl = fetchThreadUrl("39", Culture); break;

                    default: threadUrl = "http://join.puzzledbypolicy.eu/es-ES/uDebate.aspx"; break;
                    }
                    break;

                case "it-IT": switch (topExtreme)
                    {
                    case 0: threadUrl = fetchThreadUrl("26", Culture); break;

                    case 1: threadUrl = fetchThreadUrl("48", Culture); break;

                    case 2: threadUrl = fetchThreadUrl("49", Culture); break;

                    case 3: threadUrl = fetchThreadUrl("50", Culture); break;

                    case 4: threadUrl = fetchThreadUrl("51", Culture); break;

                    default: threadUrl = "http://join.puzzledbypolicy.eu/it-IT/uDebate.aspx"; break;
                    }
                    break;

                case "hu-HU": switch (topExtreme)
                    {
                    case 0: threadUrl = fetchThreadUrl("42", Culture); break;

                    case 1: threadUrl = fetchThreadUrl("72", Culture); break;

                    case 2: threadUrl = fetchThreadUrl("73", Culture); break;

                    case 3: threadUrl = fetchThreadUrl("74", Culture); break;

                    case 4: threadUrl = fetchThreadUrl("75", Culture); break;

                    default: threadUrl = "http://join.puzzledbypolicy.eu/hu-HU/uDebate.aspx"; break;
                    }
                    break;

                default: switch (topExtreme)
                    {
                    case 0: threadUrl = fetchThreadUrl("59", Culture); break;

                    case 1: threadUrl = fetchThreadUrl("60", Culture); break;

                    case 2: threadUrl = fetchThreadUrl("61", Culture); break;

                    case 3: threadUrl = fetchThreadUrl("62", Culture); break;

                    case 4: threadUrl = fetchThreadUrl("63", Culture); break;

                    default: threadUrl = "http://join.puzzledbypolicy.eu/en-GB/uDebate.aspx"; break;
                    }
                    break;
                }
            }

            if (!Page.ClientScript.IsClientScriptBlockRegistered("exampleScript"))
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "exampleScript", @"
                <script language = 'javascript'>
                  jQuery(document).ready(function() {
                       jQuery('#uDebateProposal').html(""<h3>"
                                                        + Localization.GetString("uDebateHeader.Text", LocalResourceFile) + "</h3>"
                                                        + uDebateText + "<p align='center'> <a href='" + threadUrl
                                                        + @"' target='_blank'>"
                                                        + Localization.GetString("TakePart", LocalResourceFile) + @"</a></p>"");
                         jQuery('.trigger').show();
                         jQuery('.trigger').addClass('active'); 
                         jQuery('.uDebateLinkDiv').show();                         
                  });
                </script>
                ");
            }

            //jQuery('#uDebateLinkDiv').animate({'bottom': '+=213px'}, 4000);

            //String host = ConfigurationManager.AppSettings["hostServer"];
            //String host = "http://join.puzzledbypolicy.eu";
            String host = ConfigurationManager.AppSettings["DomainName"];

            String resultsService = host +
                                    "/PProfilerResults/BarChartData.aspx?questions=" +
                                    HiddenQuestions.Value + "&answers=" +
                                    HiddenAnswers.Value + "&ratings=" +
                                    HiddenRatings.Value + "&locale=" + targetCountry;

            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.Load(new StringReader(GetMessage(resultsService)));

            XmlNodeList xmlnodelist = xmlDoc.GetElementsByTagName("graph");

            if (xmlnodelist.Count > 0)
            {
                XmlNode xmlnode = xmlnodelist.Item(0);

                XmlNodeList valueslist = xmlnode.ChildNodes;

                foreach (XmlNode value in valueslist)
                {
                    ProfilerResults += value.Attributes["title"].Value + ": ";
                    ProfilerResults += value.InnerText + "% ";
                }
            }
        }