<%@ Control Language="C#" %>
<%@ Import Namespace="Kesion.Cache" %>
<%@ Import Namespace="Kesion.Publics" %>
<%@ Import Namespace="Kesion.BLL" %>
<%@ Import Namespace="Kesion.Config" %>
<%@ Import Namespace="Kesion.Components" %>
<%@ Import Namespace="Kesion.HtmlTags" %>
<%@ Import Namespace="System.Data" %>
<script runat="server" type="text/C#">

    /* 页面编写：自由的飞 at 2017-5-8
     * 注意事项：
     * 1、程序如要终止返回，不可以直接用KSCMS.Die("输出值"); 
     *    取而代之的为 KSCMS.W("输出值"); 
     *                 return;
     * 2、页面可以用 __user.字段 访问用户信息,如__user.UserName 访问用户名 __user.RealName 访问姓名;
     * 3、此页面除了支持C#语法还支持使用所有的标签调用，如{$GetSiteName} 网站名称 
     * 
     */


    dynamic __user = HttpContext.Current.Items["user"];                //初始化用户信息，
    private static dynamic __info = new System.Dynamic.ExpandoObject();   //初始化当前页信息

    protected void Page_Load(object sender, EventArgs e)
    {
        if (KSCMS.S("action").Equals("dosave"))
        { 
            #region 保存
            string BlogName = Utils.RemoveXss(KSCMS.S("BlogName"));
            string Logo = Utils.RemoveXss(KSCMS.S("logo"));
            int ClassID = Utils.StrToInt(KSCMS.S("classId"));
            string Descript = Utils.RemoveXss(KSCMS.S("Descript"));
            string Announce = Utils.RemoveXss(KSCMS.S("Announce"));

            Hashtable ht = new Hashtable();
            ht.Add("BlogName", BlogName);
            ht.Add("Logo", Logo);
            ht.Add("ClassID", ClassID);
            ht.Add("Descript", Descript);
            ht.Add("Announce", Announce);



            if (DataFactory.Exists("KS_Blog", "UserID = " + __user.UserID))
            {
                if (CommonData.Update("KS_BLOG", ht, "WHERE UserID = " + __user.UserID))
                {
                    Msg.Alert("恭喜，修改成功！", KSCMS.GetComeUrl());
                    return;
                }
                else
                {
                    Msg.Alert("修改失败！请重试!", KSCMS.GetComeUrl());
                    return;
                }
            }
            else
            {

                Hashtable ht2 = new Hashtable();
                ht2.Add("UserName", __user.UserName);
                ht2.Add("UserId", __user.UserID);
                ht2.Add("ArticleTotal", 0);
                ht2.Add("AlbumTotal", 0);
                ht2.Add("CorpusTotal", 0);
                ht2.Add("AskTotal", 0);
                ht2.Add("MessageTotal", 0);
                CommonData.Insert("KS_BlogStatus", ht2);

                BlogConfigInfo __configinfo = BlogConfigManage.Deserialize(Server.MapPath("~/config/plus/plus.space/Blog.config"));

                CommonFunc.InitBlogNav(new TemporaryVar().UserID, (new TemporaryVar()).UserName);

                ht.Add("UserID", __user.UserID);
                ht.Add("UserName", __user.UserName);
                ht.Add("AddDate", DateTime.Now);

                ht.Add("TemplateID", Utils.StrToInt(MyCache.GetShopCommonConfig(93)));
                ht.Add("Status", __configinfo.BlogEnCheck);       //设置默认审核机制
                ht.Add("Hits", 0);
                ht.Add("best", 0);
                ht.Add("TopList", 0);
                ht.Add("hot", 0);
                ht.Add("ListGuestNum", 10);
                ht.Add("ListReplayNum", 10);
                ht.Add("ListLogNum", 10);
                ht.Add("ListBlogNum", 10);
                ht.Add("ContentLen", 30);

                if (CommonData.Insert("KS_Blog", ht))
                {
                    Msg.Alert("空间参数设置成功！", KSCMS.GetComeUrl());
                    return;
                }
                else
                {
                    Msg.Alert("修改失败！请重试...", KSCMS.GetComeUrl());
                    return;
                }
            }

            return;
            #endregion
        }
        else
        {
            #region 初始化
            using (DataTable dt = DataFactory.GetDataTable("select  top 1 * from ks_blog where UserID = " + new TemporaryVar().UserID + ";"))        //读取空间配置表
            {
                if (dt.Rows.Count > 0)
                {
                    foreach (DataRow dr in dt.Rows)
                    {
                        __info.BlogName = dr["BlogName"].ToString();
                        __info.Logo = dr["logo"].ToString();

                        if (string.IsNullOrEmpty(__info.Logo))
                        {
                            __info.Logo = "/SysImg/nopic.gif";
                        }
                        __info.ClassID = dr["ClassID"].ToString();
                        __info.Descript = dr["Descript"].ToString();
                        __info.Announce = dr["Announce"].ToString();

                    }
                }
                else
                {
                    __info.BlogName = __user.UserName + "的个人空间";
                    __info.Logo =
                   __info.ClassID = "1";
                    __info.Descript = "";
                    __info.Announce = "";


                }
            }
            #endregion
        }
    }
</script>

<script>
    function checkform() {
        if ($("#BlogName").val() == '') {
            $.dialog.alert('请输入空间名称!', function() {
            $("#BlogName").focus();
            });
            return false;

        }
        if ($("#ClassID option:selected").val() == '0') {
            $.dialog.alert('请选择分类!', function() {
             $("#ClassID").focus();
            });
            return false;

        }
        if ($("#Descript").val() == '') {
            $.dialog.alert('请填写你的站点描述!', function () {
                $("#Descript").focus();
            });
            return false;

        }
        if ($("#Announce").val() == '') {
            $.dialog.alert('请填写你的站点公告!', function () {
                $("#Announce").focus();
            });
            return false;
        }

        return true;

    }

</script>

<div class="r_tybox nomar">
  <div class="r_title"><h4>我的空间设置</h4>
      
        <div class="tabs">	
            
    			<ul>
    				<li class='puton'><a href="<%=BasicField.GetUserUrl("space/blogedit") %>">空间参数设置</a></li>
    			<%--	<li><a href="/plus/SetSpaceTemplate.aspx" target="_blank">空间模板绑定</a></li>--%>
                    <li><a href="<%=BasicField.GetUserUrl("content/PostManage") %>">我的文章</a></li>

    			</ul>
        </div>
        
    </div>

      <form name="myform" action="{$GetCurrUrl}" method="post" id="myform">
      <input type="hidden" name="action" value="dosave"/>
        <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" class="border">
                <tr>
                  <td class="lefttd">个人主页</td>
                  <td><input type="button" value="浏览我的主页" class="grey-bt bt-w-auto" onclick="window.open('<%=BasicField.GetRewriteUrl("space",Utils.StrToInt(new TemporaryVar().UserID))%>');"/></td>
                </tr>
                <tr class="tdbg">
                  <td class="lefttd">空间名称：</td>
                  <td class="tag_left">
                        <input type="text" name="BlogName" id="BlogName" class="textbox" value="<%=__info.BlogName %>"/>
               		    <span class="tips">空间站点的名称。如我的家园，我的博客等</span>
                   </td>
                </tr>
			
                <tr class="tdbg">
                  <td class="lefttd">Logo地址：</td>
                  <td class="tag_left">

                  <span style="display:none"><input type="text" name="Logo" id="Logo" class="textbox" value="<%=__info.Logo %>" /></span>
              
                  <div id="uppannel" class="tx_box" style="width:480px;height:40px;">
                       <%=Kesion.APPCode.UploadAPI.EchoUpload("spacelogo","Logo") %>
           	      </div>
              
                    <div class="ar_r_t"><div class="ar_l_t"><div class="ar_r_b"><div class="ar_l_b"><img id="blogLogo" onerror="this.src='/sysimg/nopic.gif';" userface="" src="<%=__info.Logo %>" style="width:130px;border-width:0px;" /></div></div></div></div>

               
                 </td>
                </tr>
      
                <tr class="tdbg">
                  <td class="lefttd">空间分类：</td>
                  <td class="tag_left">
                   <select name="ClassID" id="ClassID">
                       <option value="0">-请选择类别-</option>
                       <%
                           using (DataTable dt = DataFactory.GetDataTable("select * from ks_blogClassify"))
                           {

                               if (dt.Rows.Count > 0)
                               {
                                   foreach (DataRow dr in dt.Rows)
                                   {
                                       Response.Write(string.Format(@"<option value='{0}'{2}>{1}</option>", dr["classid"].ToString(), dr["classname"].ToString(),__info.ClassID==dr["classid"].ToString()?" selected":string.Empty));
                                   }
                               }
                           }
                       %>
                   </select>
              
                   <span class="tips">空间站点分类，以便游客查找</span>
                   </td>
                </tr>
                <tr class="tdbg">
                  <td class="lefttd">站点描述：</td>
                  <td class="tag_left"><textarea class="textbox"  name="Descript" id="Descript" style="width:80%;height:60px; padding:10px" cols=50 rows=6><%=__info.Descript %></textarea>
              
                  <br/><span class="tips" style="padding-left:0px">关于您的空间站点介绍</span> </td>
                </tr>
                <tr class="tdbg">
                  <td class="lefttd">空间公告：</td>
                  <td class="tag_left"><textarea class="textbox" name="Announce" id="Announce" style="width:80%;height:60px; padding:10px" cols=50 rows=6><%=__info.Announce %></textarea><br/><span class="tips" style="padding-left:0px">发布您的最新活动公告，让更多用户了解您。</span></td>
                </tr>
           
        </table>
        <div class="cz_btn t-a-center">
         
            <input type="submit" ID="Button1" class="green-bt bt-w-auto d-inline-block" onclick="return(checkform())"  value="OK,提交修改"  />
         
        </div>
   </form>

   
</div>

