예제 #1
0
        private void PassApply_Click(object sender, EventArgs e)
        {
            if (DNTRequest.GetString("uid") != "")
            {
                string uidlist = DNTRequest.GetString("uid");
                foreach (string uid in uidlist.Split(','))
                {
                    Discuz.Data.DatabaseProvider.GetInstance().UpdateUserSpaceId(Convert.ToInt32(uid));
                    //string sql = "UPDATE [" + BaseConfigs.GetTablePrefix + "users] SET [spaceid]=ABS([spaceid]) WHERE [uid]=" + uid;
                    //sql += ";SELECT [spaceid] FROM [" + BaseConfigs.GetTablePrefix + "users] WHERE [uid]=" + uid;
                    //int spceid = (int)AdminDatabase.ExecuteScalar(sql);
                    int     tabid = Spaces.GetNewTabId(Convert.ToInt32(uid));
                    TabInfo tab   = new TabInfo();
                    tab.TabID        = tabid;
                    tab.UserID       = Convert.ToInt32(uid);
                    tab.DisplayOrder = 0;
                    tab.TabName      = "首页";
                    tab.IconFile     = "";
                    tab.Template     = "template_25_75.htm";
                    Spaces.AddTab(tab);
                    //sql = "INSERT INTO [" + BaseConfigs.GetTablePrefix + "spacetabs] ([uid],[displayorder], [tabname], [iconfile],[template])  VALUES(" + uid + ",0,'默认','','template_25_75.htm');SELECT SCOPE_IDENTITY()";
                    //int tabid = Utils.StrToInt(AdminDatabase.ExecuteScalar(sql),0);
                    Spaces.AddLocalModule("builtin_calendarmodule.xml", int.Parse(uid), tabid, 1);
                    Spaces.AddLocalModule("builtin_statisticmodule.xml", int.Parse(uid), tabid, 1);
                    Spaces.AddLocalModule("builtin_postlistmodule.xml", int.Parse(uid), tabid, 2);

                    if (spaceConfig.Spacegreeting != string.Empty)
                    {
                        SpacePostInfo spacepostsinfo = new SpacePostInfo();
                        spacepostsinfo.Title          = string.Format("欢迎使用 {0} {1}", config.Forumtitle, config.Spacename);
                        spacepostsinfo.Content        = spaceConfig.Spacegreeting;
                        spacepostsinfo.Category       = string.Empty;
                        spacepostsinfo.PostStatus     = 1;
                        spacepostsinfo.CommentStatus  = 0;
                        spacepostsinfo.Postdatetime   = DateTime.Now;
                        spacepostsinfo.Author         = username;
                        spacepostsinfo.Uid            = Utils.StrToInt(uid, -1);
                        spacepostsinfo.PostUpDateTime = DateTime.Now;
                        spacepostsinfo.Commentcount   = 0;

                        DbProvider.GetInstance().AddSpacePost(spacepostsinfo);
                    }
                    ///添加最新主题到日志
                    List <TopicInfo> list = Topics.GetTopicsByUserId(userid, 1, config.Topictoblog, 0, 0);
                    foreach (TopicInfo mytopic in list)
                    {
                        int      pid  = Posts.GetFirstPostId(mytopic.Tid);
                        PostInfo post = Posts.GetPostInfo(mytopic.Tid, pid);
                        if (post != null && post.Message.Trim() != string.Empty)
                        {
                            SpacePostInfo spacepost = new SpacePostInfo();
                            spacepost.Author = username;
                            string content = Posts.GetPostMessageHTML(post, new AttachmentInfo[0]);
                            spacepost.Category       = "";
                            spacepost.Content        = content;
                            spacepost.Postdatetime   = DateTime.Now;
                            spacepost.PostStatus     = 1;
                            spacepost.PostUpDateTime = DateTime.Now;
                            spacepost.Title          = post.Title;
                            spacepost.Uid            = Utils.StrToInt(uid, -1);;

                            DbProvider.GetInstance().AddSpacePost(spacepost);
                        }
                    }

                    //短信通知用户个人空间已经开通
                    PrivateMessageInfo privatemessageinfo = new PrivateMessageInfo();
                    ShortUserInfo      userInfo           = Users.GetShortUserInfo(Convert.ToInt32(uid));
                    privatemessageinfo.Msgto        = userInfo == null ? "" : userInfo.Username;
                    privatemessageinfo.Msgtoid      = Convert.ToInt32(uid);
                    privatemessageinfo.Postdatetime = Utils.GetDateTime();
                    privatemessageinfo.Message      = "恭喜您,您的" + config.Spacename + "已经被管理员" + username + "开通!";
                    privatemessageinfo.Subject      = "恭喜,您的" + config.Spacename + "已经开通";
                    privatemessageinfo.Msgfrom      = username;
                    privatemessageinfo.Msgfromid    = userid;
                    privatemessageinfo.New          = 1;
                    privatemessageinfo.Folder       = 0;

                    PrivateMessages.CreatePrivateMessage(privatemessageinfo, 0);
                    //AdminDatabase.ExecuteNonQuery("INSERT INTO [" + BaseConfigs.GetTablePrefix + "pms] (msgfrom,msgfromid,msgto,msgtoid,folder,new,subject,postdatetime,message) VALUES ('" + username + "','" + userid + "','" + msgto.Replace("'", "''") + "','" + uid + "','0','1','" + subject + "','" + curdatetime + "','" + message + "')");
                    //AdminDatabase.ExecuteNonQuery("UPDATE [" + BaseConfigs.GetTablePrefix + "users] SET [newpmcount]=[newpmcount]+1  WHERE [uid] =" + uid);
                }
                base.RegisterStartupScript("PAGE", "window.location.href='space_spaceapplymanage.aspx';");
            }
            else
            {
                base.RegisterStartupScript("", "<script>alert('请选择要开通的空间!');window.location.href='space_spaceapplymanage.aspx';</script>");
            }
        }
예제 #2
0
        protected override void ShowPage()
        {
            pagetitle = string.Format("激活{0}", config.Spacename);

            if (userid == -1)
            {
                AddErrLine("你尚未登录");
                return;
            }

            UserInfo user = Users.GetUserInfo(userid);

            if (config.Enablespace != 1)
            {
                AddErrLine(string.Format("{0}功能已被关闭", config.Spacename));
                return;
            }

            bool isactivespace = false;
            bool isallowapply  = true;

            if (user.Spaceid > 0)
            {
                isactivespace = true;
            }
            else
            {
                if (user.Spaceid < 0)
                {
                    isallowapply = false;
                }
                else
                {
                    if (spaceactiveconfig.AllowPostcount == "1" || spaceactiveconfig.AllowDigestcount == "1" ||
                        spaceactiveconfig.AllowScore == "1" || spaceactiveconfig.AllowUsergroups == "1")
                    {
                        if (spaceactiveconfig.AllowPostcount == "1")
                        {
                            isallowapply = isallowapply && (Convert.ToInt32(spaceactiveconfig.Postcount) <= user.Posts);
                        }
                        if (spaceactiveconfig.AllowDigestcount == "1")
                        {
                            isallowapply = isallowapply &&
                                           (Convert.ToInt32(spaceactiveconfig.Digestcount) <= user.Digestposts);
                        }
                        if (spaceactiveconfig.AllowScore == "1")
                        {
                            isallowapply = isallowapply && (Convert.ToInt32(spaceactiveconfig.Score) <= user.Credits);
                        }
                        if (spaceactiveconfig.AllowUsergroups == "1")
                        {
                            isallowapply = isallowapply &&
                                           (("," + spaceactiveconfig.Usergroups + ",").IndexOf("," + user.Groupid + ",") !=
                                            -1);
                        }
                    }
                    else
                    {
                        isallowapply = false;
                    }
                }
            }

            if (isactivespace)
            {
                AddErrLine("您已经申请过个人空间!");
                return;
            }
            if (!isallowapply)
            {
                AddErrLine("您未被允许申请个人空间!");
                return;
            }

            if (DNTRequest.IsPost())
            {
                if (ForumUtils.IsCrossSitePost())
                {
                    AddErrLine("您的请求来路不正确,无法提交。如果您安装了某种默认屏蔽来路信息的个人防火墙软件(如 Norton Internet Security),请设置其不要禁止来路信息后再试。");
                    return;
                }
                if (DNTRequest.GetString("spacetitle").Length > 100)
                {
                    AddErrLine("个人空间标题不得超过100个字符");
                    return;
                }
                if (DNTRequest.GetString("description").Length > 200)
                {
                    AddErrLine("个人空间描述不得超过200个字符");
                    return;
                }
                if (DNTRequest.GetInt("bpp", 0) == 0)
                {
                    AddErrLine("显示日志篇数必需是一个大于0的数字");
                    return;
                }

                if (page_err == 0)
                {
                    DataRow dr = DbProvider.GetInstance().GetThemes();
                    spaceconfiginfo                = new SpaceConfigInfo();
                    spaceconfiginfo.UserID         = userid;
                    spaceconfiginfo.Spacetitle     = DNTRequest.GetHtmlEncodeString("spacetitle");
                    spaceconfiginfo.Description    = DNTRequest.GetHtmlEncodeString("description");
                    spaceconfiginfo.BlogDispMode   = DNTRequest.GetInt("blogdispmode", 0);
                    spaceconfiginfo.Bpp            = DNTRequest.GetInt("bpp", 0);
                    spaceconfiginfo.Commentpref    = DNTRequest.GetInt("commentpref", 0);
                    spaceconfiginfo.MessagePref    = DNTRequest.GetInt("messagepref", 0);
                    spaceconfiginfo.UpdateDateTime = spaceconfiginfo.CreateDateTime = DateTime.Now;
                    string rewritename = DNTRequest.GetFormString("rewritename").Trim();
                    if (rewritename != string.Empty)
                    {
                        if (Globals.CheckSpaceRewriteNameAvailable(rewritename) == 0)
                        {
                            spaceconfiginfo.Rewritename = rewritename;
                        }
                        else
                        {
                            AddErrLine("您输入的 个性域名 不可用或含有非法字符");
                            return;
                        }
                    }
                    else
                    {
                        spaceconfiginfo.Rewritename = "";
                    }

                    spaceconfiginfo.ThemeID      = int.Parse(dr["themeid"].ToString());
                    spaceconfiginfo.ThemePath    = dr["directory"].ToString();
                    spaceconfiginfo.PostCount    = 0;
                    spaceconfiginfo.CommentCount = 0;
                    spaceconfiginfo.VisitedTimes = 0;
                    spaceconfiginfo.DefaultTab   = 0;

                    string errorinfo = "";
                    int    blogid    = DbProvider.GetInstance().AddSpaceConfigData(spaceconfiginfo);
                    Users.UpdateUserSpaceId(-blogid, userid);

                    SpaceActiveConfigInfo _spaceconfiginfo = SpaceActiveConfigs.GetConfig();
                    if (_spaceconfiginfo.ActiveType == "0")
                    {
                        if (errorinfo == "")
                        {
                            SetUrl("index.aspx");
                            SetMetaRefresh();
                            SetShowBackLink(true);
                            AddMsgLine("您的申请已经提交,请等待管理员开通您的个人空间");
                        }
                        else
                        {
                            AddErrLine(errorinfo);
                            return;
                        }
                    }
                    else
                    {
                        Discuz.Data.DatabaseProvider.GetInstance().UpdateUserSpaceId(userid);
                        int     tabid = Spaces.GetNewTabId(userid);
                        TabInfo tab   = new TabInfo();
                        tab.TabID        = tabid;
                        tab.UserID       = userid;
                        tab.DisplayOrder = 0;
                        tab.TabName      = "首页";
                        tab.IconFile     = "";
                        tab.Template     = "template_25_75.htm";
                        Spaces.AddTab(tab);
                        Spaces.AddLocalModule("builtin_calendarmodule.xml", userid, tabid, 1);
                        Spaces.AddLocalModule("builtin_statisticmodule.xml", userid, tabid, 1);
                        Spaces.AddLocalModule("builtin_postlistmodule.xml", userid, tabid, 2);
                        if (SpaceActiveConfigs.GetConfig().Spacegreeting != string.Empty)
                        {
                            SpacePostInfo spacepostsinfo = new SpacePostInfo();
                            spacepostsinfo.Title          = string.Format("欢迎使用 {0} 个人空间", config.Forumtitle);
                            spacepostsinfo.Content        = SpaceActiveConfigs.GetConfig().Spacegreeting;
                            spacepostsinfo.Category       = string.Empty;
                            spacepostsinfo.PostStatus     = 1;
                            spacepostsinfo.CommentStatus  = 0;
                            spacepostsinfo.Postdatetime   = DateTime.Now;
                            spacepostsinfo.Author         = username;
                            spacepostsinfo.Uid            = userid;
                            spacepostsinfo.PostUpDateTime = DateTime.Now;
                            spacepostsinfo.Commentcount   = 0;
                            DbProvider.GetInstance().AddSpacePost(spacepostsinfo);
                        }

                        ///添加最新主题到日志
                        List <TopicInfo> list = Topics.GetTopicsByUserId(userid, 1, config.Topictoblog, 0, 0);
                        foreach (TopicInfo mytopic in list)
                        {
                            int      pid  = Posts.GetFirstPostId(mytopic.Tid);
                            PostInfo post = Posts.GetPostInfo(mytopic.Tid, pid);
                            if (post != null && post.Message.Trim() != string.Empty)
                            {
                                SpacePostInfo spacepost = new SpacePostInfo();
                                spacepost.Author = username;
                                string content = Posts.GetPostMessageHTML(post, new AttachmentInfo[0]);
                                spacepost.Category       = "";
                                spacepost.Content        = content;
                                spacepost.Postdatetime   = DateTime.Now;
                                spacepost.PostStatus     = 1;
                                spacepost.PostUpDateTime = DateTime.Now;
                                spacepost.Title          = post.Title;
                                spacepost.Uid            = userid;
                                DbProvider.GetInstance().AddSpacePost(spacepost);
                            }
                        }
                        SetUrl("space/");
                        SetMetaRefresh();
                        SetShowBackLink(true);
                        AddMsgLine("恭喜您,您的个人空间已经被开通");
                    }
                }
            }
            else
            {
                spaceconfiginfo = BlogProvider.GetSpaceConfigInfo(userid);
            }
        }