<?php
include_once("inc/conn.php");
include_once("inc/function.php");
login_check();

if($_GET["act"] =="modelsave"){
	$tzmodel_array=array();
	$query=$db->query("Select tznum,tzpoints,points from {$web_dbtop}game28_users_tz where NO=".intval($_GET["luckno"])." and uid=".intval($_COOKIE["usersid"])." Order by id desc");
		if($rs=$db->fetch_array($query)){
			$tznum=explode("|",$rs["tznum"]);
			$tzpoints_array=explode("|",$rs["tzpoints"]);
			$tzpoints=$rs["points"];
		}
	for($i = 0; $i <28 ; $i ++){
		$tzmodel_array[$i]=0;
		for($y = 0; $y < count($tznum); $y++){
			if($tznum[$y]==$i){
				$tzmodel_array[$i]=$tzpoints_array[$y];
			}
		}
	}
	$tznum=implode("|",$tzmodel_array);
	if($_POST["tbID"]){
		$db->query("update {$web_dbtop}game28_auto_tz set tzname='".str_check($_POST["tbModelName"])."',tzunm='".$tznum."',tzpoints=$tzpoints where id =".intval($_POST["tbID"]));
	}else{
		$db->query("INSERT INTO {$web_dbtop}game28_auto_tz (uid,tzname,tzunm,tzpoints,tzid) VALUES (".intval($_COOKIE["usersid"]).",'".str_check($_POST["tbModelName"])."','".$tznum."',$tzpoints,".intval($_POST["tbModelID"]).")");
	}
	echo "<script language=javascript>alert('投注模式保存成功！');location.href='luckmodelsave.php?luckno=".$_GET["luckno"]."';</script>";
	exit;
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">
<HTML xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>幸运28-游戏中心-<?=$web_name;?></title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<meta name="keywords" content="<?=$web_keywords;?>" />
<meta name="description" content="<?=$web_description;?>" />
<META http-equiv=X-UA-Compatible content=IE=EmulateIE7>
<link href="style/default.css" rel="stylesheet" type="text/css" />
</head>
<?php include_once("top.php");?>
<script language="javascript">
qiehuan(2);
document.getElementById("qh_con2").getElementsByTagName('li')[0].className="current";
</script>
<DIV class="wrapper">
	<DIV class="page_content">
		<DIV class="webgame-info-title">
		  <UL>
			<LI><A href="luck.php">幸运28首页</A></LI>
			<LI><A href="luckhelp.php">幸运28规则</A></LI>
			<LI class="current"><A href="luckmylist.php">我的投注记录</A></LI>
			<LI><A href="luckmodel.php">投注模式编辑</A></LI>
			<LI><A href="luckautoset.php">自动投注</A></LI>
			<LI><A href="luckdirection.php">幸运28走势图</A></LI>
		  </UL>
		</DIV>
		<DIV class="webgame-info">
			<DIV class="webgame-info-tabs">
			  <table width="940" height="27" border="0" align="center" cellpadding="0" cellspacing="0">
                <tr>
                  <td width="12"><img src="images/game2_03.jpg" width="12" height="27" /></td>
                  <td background="images/game2_04.jpg" class="font14">自动投注设置:</td>
                  <td width="13"><img src="images/game2_06.jpg" width="13" height="27" /></td>
                </tr>
              </table>
			  <table width="100%" border="0" cellspacing="0" cellpadding="0">
                <tr>
                  <td height="5"></td>
                </tr>
              </table>
			  <table width="940" border="0" align="center" cellpadding="0" cellspacing="0">
                <tr>
                  <td bgcolor="#248301"><form action="?act=modelsave&luckno=<?=$_GET["luckno"]?>" method="post">
                      <input name="tbID" id="hidID" type="hidden" value="" />
                      <table width="100%" border="0" cellspacing="1" cellpadding="4">
                        <tr>
                          <td width="40%" height="28" align="right" bgcolor="#FFFFFF">请选择保存的投注模式名称：</td>
                          <td width="60%" bgcolor="#FFFFFF"><select name="tbModelID" id="tbModelID" onChange="chgModel(this.selectedIndex)">
                              <?
															$tzname=array("投注模式一","投注模式二","投注模式三","投注模式四","投注模式五","投注模式六","投注模式七","投注模式八","投注模式九","投注模式十",
															"投注模式十一","投注模式十二","投注模式十三","投注模式十四","投注模式十五","投注模式十六","投注模式十七","投注模式十八","投注模式十九","投注模式二十",
															"投注模式二一","投注模式二二","投注模式二三","投注模式二四","投注模式二五","投注模式二六","投注模式二七","投注模式二八","投注模式二九","投注模式三十",
															"投注模式三一","投注模式三二","投注模式三三","投注模式三四","投注模式三五","投注模式三六","投注模式三七","投注模式三八","投注模式三九","投注模式四十");
															$i=1;
															foreach($tzname as $tzarray){
																$query=$db->query("Select tzname,tzid from {$web_dbtop}game28_auto_tz where uid=".intval($_COOKIE["usersid"])." and tzid=$i Order by tzid asc");
																if($rs=$db->fetch_array($query)){
																	echo"<option label=\"".$rs["tzname"]."\" value=\"".$i."\">".$rs["tzname"]."</option>";
																}else{
																	echo"<option label=\"".$tzarray."\" value=\"".$i."\">".$tzarray."</option>";
																}
															$i++;
															}
														?>
                          </select></td>
                        </tr>
                        <tr>
                          <td height="28" align="right" bgcolor="#FFFFFF">自定义您的投注模式名称：</td>
                          <td bgcolor="#FFFFFF"><input type="text" name="tbModelName" id="tbModelName" value=""/></td>
                        </tr>
                        <tr>
                          <td height="28" colspan="2" align="center" valign="top" bgcolor="#FFFFFF"><input value=" 保  存 " type="submit" id="btnSubmit" /></td>
                        </tr>
                      </table>
                  </form></td>
                </tr>
              </table>
			  <?
				$game28tz_array = array();
				$query=$db->query("Select * from {$web_dbtop}game28_auto_tz where uid=".intval($_COOKIE["usersid"])."  Order by tzid asc");
				while($rs=$db->fetch_array($query)){
					$game28tz_array[]="{\"ID\":\"".$rs["id"]."\",\"modelID\":\"".$rs["tzid"]."\",\"modelName\":\"".$rs["tzname"]."\"}";
				}
				$tzjs=implode(",",$game28tz_array);
				?>
				<script type="text/javascript">
				<!--
				function chgModel(index){
					var modelID = document.getElementById("tbModelID").options[index].value;
					document.getElementById("hidID").value = '';
					var flag = false;
					var result = {"arrJsonModel":[<?=$tzjs?>]};
					if(result.arrJsonModel != null){
						document.getElementById("tbModelName").value = document.getElementById("tbModelID").options[index].text;	
						for(i=0;i<result.arrJsonModel.length;i++){
							if(result.arrJsonModel[i].modelID==modelID){
								flag = true;
								index = i;
							}
						}
						if(flag){
							document.getElementById("hidID").value = result.arrJsonModel[index].ID;
						}
					}
				}
				chgModel(0);
				-->
				</script>
		  </DIV>
			<DIV class=cl></DIV>
		</DIV>
		<DIV class="area960-b h5px"></DIV>
	<!--Flink End-->
	<div class="blank10"></div>
	<!--Footer Start-->
<?php include_once("footer.php");?>
</DIV>