Exemple #1
0
    private void GetUsersForSync()
    {
        try
            {
                TR_count.Visible = true;
                UserData[] user_data;
                if (Request.QueryString["max"] != null)
                {
                    if (Request.QueryString["max"] != "")
                    {
                        m_intMax = Convert.ToInt32(Request.QueryString["max"]);
                    }
                }
                m_refSiteApi = new SiteAPI();
                m_refUserApi = new UserAPI();
                settings_data = m_refSiteApi.GetSiteVariables(m_refSiteApi.UserId);
                user_data = m_refUserApi.GetCMSUsersToSync(m_intMax);
                if (user_data == null)
                {
                    Response.Redirect("adreports.aspx?action=ViewAllReportTypes", false);
                }
                System.Web.UI.WebControls.BoundColumn colBound = new System.Web.UI.WebControls.BoundColumn();
                colBound.DataField = "CMSUSER";
                colBound.HeaderText = m_refMsg.GetMessage("cms username");
                colBound.HeaderStyle.CssClass = "title-header";
                colBound.HeaderStyle.Width = Unit.Percentage(22);
                colBound.ItemStyle.Width = Unit.Percentage(22);
                colBound.ItemStyle.Wrap = false;
                colBound.ItemStyle.VerticalAlign = VerticalAlign.Top;
                AdReportsGrid.Columns.Add(colBound);

                colBound = new System.Web.UI.WebControls.BoundColumn();
                colBound.DataField = "ADUSER";
                colBound.HeaderText = m_refMsg.GetMessage("ad username");
                colBound.HeaderStyle.CssClass = "title-header";
                colBound.HeaderStyle.Width = Unit.Percentage(23);
                colBound.ItemStyle.Width = Unit.Percentage(23);
                colBound.HeaderStyle.HorizontalAlign = HorizontalAlign.Center;
                colBound.ItemStyle.Wrap = false;
                colBound.ItemStyle.VerticalAlign = VerticalAlign.Top;
                AdReportsGrid.Columns.Add(colBound);

                colBound = new System.Web.UI.WebControls.BoundColumn();
                colBound.DataField = "AT";
                colBound.HeaderText = "@";
                colBound.HeaderStyle.CssClass = "title-header";
                colBound.HeaderStyle.Width = Unit.Percentage(2);
                colBound.ItemStyle.Width = Unit.Percentage(2);
                colBound.HeaderStyle.HorizontalAlign = HorizontalAlign.Center;
                colBound.ItemStyle.Wrap = false;
                AdReportsGrid.Columns.Add(colBound);

                colBound = new System.Web.UI.WebControls.BoundColumn();
                colBound.DataField = "DOMAIN";
                colBound.HeaderText = m_refMsg.GetMessage("ad domain");
                colBound.HeaderStyle.CssClass = "title-header";
                colBound.HeaderStyle.Width = Unit.Percentage(25);
                colBound.ItemStyle.Width = Unit.Percentage(25);
                colBound.HeaderStyle.HorizontalAlign = HorizontalAlign.Center;
                colBound.ItemStyle.Wrap = false;
                AdReportsGrid.Columns.Add(colBound);

                colBound = new System.Web.UI.WebControls.BoundColumn();
                colBound.DataField = "SEARCH";
                colBound.HeaderText = m_refMsg.GetMessage("generic Search");
                colBound.HeaderStyle.CssClass = "title-header";
                colBound.HeaderStyle.HorizontalAlign = HorizontalAlign.Center;
                colBound.HeaderStyle.Width = Unit.Percentage(13);
                colBound.ItemStyle.Width = Unit.Percentage(13);
                colBound.ItemStyle.Wrap = false;
                colBound.ItemStyle.HorizontalAlign = HorizontalAlign.Center;
                AdReportsGrid.Columns.Add(colBound);

                colBound = new System.Web.UI.WebControls.BoundColumn();
                colBound.DataField = "DELETE";
                colBound.HeaderText = m_refMsg.GetMessage("generic Delete title");
                colBound.HeaderStyle.CssClass = "title-header";
                colBound.HeaderStyle.Width = Unit.Percentage(15);
                colBound.ItemStyle.Width = Unit.Percentage(15);
                colBound.ItemStyle.Wrap = false;
                AdReportsGrid.Columns.Add(colBound);

                DataTable dt = new DataTable();
                DataRow dr;
                dt.Columns.Add(new DataColumn("CMSUSER", typeof(string)));
                dt.Columns.Add(new DataColumn("ADUSER", typeof(string)));
                dt.Columns.Add(new DataColumn("AT", typeof(string)));
                dt.Columns.Add(new DataColumn("DOMAIN", typeof(string)));
                dt.Columns.Add(new DataColumn("SEARCH", typeof(string)));
                dt.Columns.Add(new DataColumn("DELETE", typeof(string)));
                int e1count = 3;
                int e2count = 4;
                int userCount = (user_data != null ? user_data.Length : 0);
                string[] domainArray;
                int arrayCount = 0;
                long currentUserID = m_refUserApi.UserId;
                if (user_data != null && user_data.Length == m_intMax)
                {
                    TD_count.InnerHtml = m_intMax + " " + m_refMsg.GetMessage("ad users displayed") + " <a href=\"adreports.aspx?action=GetUsersForSynch&max=0\">" + m_refMsg.GetMessage("generic Show All") + "</a><br><br>";
                }
                if (settings_data.ADAuthentication == 1)
                {
                    if (user_data != null)
                    {
                        for (int i = 0; i <= user_data.Length - 1; i++)
                        {
                            dr = dt.NewRow();
                            domainArray = Strings.Split(user_data[i].Domain, ",", -1, 0);
                            if (user_data[i].IsMemberShip)
                            {
                                dr[0] = MemberShipUserIcon + user_data[i].Username;
                            }
                            else
                            {
                                dr[0] = CmsUserIcon + user_data[i].Username;
                            }
                            dr[0] += "<input type=\"hidden\" name=\"userid" + (i + 1) + "\" value=\"" + user_data[i].Id + "\">";
                            dr[1] = "<input type=\"text\" class=\"" + INPUTCLASS + "\" name=\"username" + (i + 1) + "\" id=\"username" + (i + 1) + "\" value=\"" + user_data[i].AdUserName + "\" maxlength=\"255\"></td>";
                            dr[2] = "@";
                            dr[3] = "";
                            if ((domainArray.Length - 1) > 0)
                            {
                                dr[3] += "<select name=\"sel_domain" + (i + 1) + "\" onchange=\"javascript:document.forms[0].domain" + (i + 1) + ".value = document.forms.synchusers.sel_domain" + (i + 1) + ".options[document.forms[0].sel_domain" + (i + 1) + ".selectedIndex].value;\">";
                                dr[3] += "<option value=\"\" selected>" + m_refMsg.GetMessage("multiples found");
                                for (arrayCount = 0; arrayCount <= (domainArray.Length - 1); arrayCount++)
                                {
                                    dr[3] += "<option value=\"" + domainArray[arrayCount] + "\">" + domainArray[arrayCount];
                                }
                                dr[3] += "</select><br>";
                                dr[3] += "<input type=\"text\" class=\"" + INPUTCLASS + "\" name=\"domain" + (i + 1) + "\" id=\"domain" + (i + 1) + "\" maxlength=\"255\">";
                            }
                            else
                            {
                                //dr(3)+="<input type=""hidden"">")
                                dr[3] += "<input type=\"text\" class=\"" + INPUTCLASS + "\" name=\"domain" + (i + 1) + "\" id=\"domain" + (i + 1) + "\" value=\"" + user_data[i].Domain + "\" maxlength=\"255\">";
                            }
                            dr[4] = "<a href=\"#\" OnClick=\"javascript:PopUpWindow(\'users.aspx?action=MapCMSUserToAD&id=" + user_data[i].Id + "&f=0&e1=" + "username" + (i + 1) + "&e2=" + "domain" + (i + 1) + "&rp=3\',\'Summary\',690,380,1,1);\">" + m_refMsg.GetMessage("generic Search") + "</a>";
                            if (user_data[i].Id == (int) currentUserID)
                            {
                                dr[5] = "<input type=\"checkbox\" name=\"delete" + (i + 1) + "\" value=\"delete\" disabled onClick=\"return false;\">";
                            }
                            else
                            {
                                dr[5] = "<input type=\"checkbox\" name=\"delete" + (i + 1) + "\" value=\"delete\">";
                            }
                            dt.Rows.Add(dr);
                            e1count = e1count + 4;
                            e2count = e2count + 4;
                        }

                        AdReportsGrid.ShowFooter = true;

                    }
                }
                usercount.Value = userCount.ToString();
                DataView dv = new DataView(dt);
                AdReportsGrid.DataSource = dv;
                AdReportsGrid.DataBind();
                GetUsersForSyncToolBar();
            }
            catch (Exception ex)
            {
                throw (new Exception(ex.Message));
            }
    }