<?php
$projectRootPath = "../../";	//相对当前应用程序根的位置
//require_once("../include/checkPurview.php");
require_once("../web.config.php");

$do_submit=false;
if(!empty($_POST['fcontent']) && !empty($_POST['fAuthor'])  ){

    $fcontent=$_POST['fcontent'];
    $fAuthor=$_POST['fAuthor'];
    $bgColor=$_POST['bgColor'];
    $createTime=date("Y-m-d H:i:s");
    $sql="insert into deep_zhiTiao(bgColor,fcontent,fAuthor,createTime)values('$bgColor','$fcontent','$fAuthor','$createTime')";
    $ok=$conn->exec($sql);
    if($ok>0){
        $tip="祝福提交成功";
    }else{
        $tip="祝福提交失败";
    }
    $do_submit=true;
    //exit();
}

$colors=array('#fff','#f09','#f00','#f60','#ff84ff','#ff0','#f0f','#f90','#fcf','#bfabff','#e4e45a','#fc0','#bff','#fad6f0','#ffce7d','#ffa68c','#bdbede','#fc6','#73e7ff','#8cefd6','#97eb76','#eba876','#ceeb76','#eee');
$colors_rand=$colors[mt_rand(0, count($colors)-1)];

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="robots" content="noindex,nofollow" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>祝福纸条管理</title>
    <link href="../themes/<?php echo $themes_Path; ?>/main.css" rel="stylesheet" type="text/css" />
</head>
<body>
<br />
&nbsp; <a href="lovewall_Manage.php">祝福纸条管理</a> | <a href="lovewall_Add.php">添加祝福纸条</a>
<hr color="#0099FF" size="1" />
<br />
<dl class="manageContent">
    <dt>祝福纸条管理</dt>
    <dd>
    	<br />
              <?php
              if($do_submit){
                  echo "<h2>".$tip."</h2>3秒后自动跳转到爱墙管理页<br />" ;
                  ?>
                  <meta http-equiv="refresh" content="3;URL=lovewall_Manage.php" />
                  <?php
              }else{
              ?>

              <form action="" method="post" name="form1" id="form1">
                  <table width="70%" border="0" align="center" class="tableBoderForm">
                      <tr>
                          <th  height="30">许愿人姓名：</th>
                          <td> <input type="text" name="fAuthor" id="fAuthor" /></td>
                      </tr>
                      <tr>
                          <th width="150" height="30">输入祝福纸条内容<br/> 还能输入 <span class="wordNum">100</span> 个字</th>
                          <td> <textarea id="fcontent" name="fcontent" ></textarea><br/></td>
                      </tr>
                      <tr>
                          <th  height="30">标签颜色：</th>
                          <td>
              <input type="text" id="bgColor" name="bgColor" value="<?php echo $colors_rand ?>" style="background-color:<?php echo $colors_rand ?>" readonly="readonly" /><br/>
              <div>
                  <?php
                    //echo  count($colors);
                    for($color_val=0;$color_val<count($colors) ;$color_val++){
                        ?>
                        <div class="zhitiao_bgColor" style="width:25px;height:25px;border:1px solid #f0f; float:left;margin:2px; cursor: pointer;background-color:<?php echo $colors[$color_val] ?>"></div>
                        <?php
                    }
                  ?>
              </div>
</td>
                      </tr>

                      <tr>
                          <td colspan="2"><input type="submit" value="发布祝福纸条"  /></td>
                      </tr>
                  </table>
                  
                  
             
             
              
              </form>
              <?php
              }
              ?>


        <br />
    </dd>
</dl>
<br />
</body>
</html>
<script type="text/javascript" src="<?php echo $projectRootPath ?>Deep_library/js/jquery-1.4.2.min.js"></script>

<script type="text/javascript">
    $(function(){

        //祝福内容输入处理
        $("#fcontent").keyup(function(){
            //如果元素区字符数大于最大字符数，按照最大字符数截断
            //alert($("#fcontent").val().length);
            if($("#fcontent").val().length>100){
                $("#fcontent").val($("#fcontent").val().substring(0, 100) );
                //alert(1111111111);
            }
            //显示剩余的字符数
            $('.wordNum').html( 100- $("#fcontent").val().length  );
           
        });

        //纸条颜色
        $(".zhitiao_bgColor").click(function(){
            //alert('-------');
            //alert($(this).css('background-color'));
            $('#bgColor').css('background-color', $(this).css('background-color')).val($(this).css('background-color'));
        });

        //提交验证
        $("#form1").submit(function(){
            if($('#fcontent').val()==''){
               alert('祝福内容不能为空');
               $('#fcontent').focus();
               return false;
            }      
            if($('#fAuthor').val()==''){
               alert('许愿人姓名不能为空');
               $('#fAuthor').focus();
               return false;
            }
        });

    });
</script>
