<?php
/*********************************************************      
 文件说明:         
    功能说明:节假日列表


    调用关系:调用:header.inc  
             被调用:实现各个功能模块的页面        
    变量说明:
             

作者:
NO.1      
姓名：          
时间：   
修改说明：
*********************************************************/ 
require("../../inc/header.inc");
?>
<body leftmargin="15" rightmargin="10" onload="javascript:adjust();" onresize="javascript:adjust();" style="overflow:hidden;overflow-x:hidden;overflow-y:hidden;">
<form name="editform" action="<?php echo"$PHP_SELF?id=$id&mode=$mode"; ?>" method="POST">
<?php
adjust_head();
adjust_title_head();
$ppsDb = 'PPS_DB';
$tableName = 'pre_bill_holiday';
$DEBUG = 0;
$listPageURL='tariffHoliday.php';
$strThisPage=$strTitleAdvanced.$strTitleSpace."Tariff plan".$strTitleSpace."Holiday";
$arr_mode=array("edit","add");
if($mode == "add"){
	$tableTitle = "Add holiday";
}
elseif($mode == "edit"){
	$tableTitle = "Edit holiday";
}


//==========================================================
//数据处理
//==========================================================
//保存修改的变量
if(strlen($set) > 0){
//修改原有记录
	if($mode=="edit"){		
		$editSql="UPDATE $tableName
				  SET name = '$name'
				  WHERE month = '$month'
				  AND day = '$day'";
		if($DEBUG)  echo "<br>$editSql";
		$result= @mysqli_query($pubConn,$editSql);
		echo mysqli_error($pubConn);
	}
//添加新的记录
	if($mode=="add"){
		//检查是否有日期重复的项目
		$getSql="SELECT * FROM $tableName";
		$result=mysqli_query($pubConn,$getSql);
		$rows=mysqli_fetch_array($result);
		do{
			if ($DEBUG)  echo "<br>recordedMonth=$rows[month]<br>recordedDay=$rows[day]";
			if ($rows[month]==$month && $rows[day]==$day){
				echo "<SCRIPT LANGUAGE=\"JavaScript\">";
				echo "alert(\"The holiday date for ($month-$day) is already existed, please confirm and retry!\")";
				echo "</SCRIPT>";
				echo " <meta http-equiv=\"refresh\" content=\"0; url=tariffHolidayEdit.php?mode=$arr_mode[1]\"> ";
				exit();
			}
		}while($rows=mysqli_fetch_array($result));

		$insertSql="INSERT INTO $tableName
					(month,day,name)
					VALUES
					('$month','$day','$name')";
		if($DEBUG)  echo "<br>$insertSql";
		if($DEBUG)  echo "<br>month=$month<br>day=$day";
		$result= @mysqli_query($pubConn,$insertSql);
		echo mysqli_error($pubConn);
	}
echo " <meta http-equiv=\"refresh\" content=\"0; url=$listPageURL\"> ";
}
//删除数据
if(strlen($delete) > 0){
	$deleteSql="DELETE FROM $tableName
				WHERE month = '$month'
				AND day = '$day'";
	if($DEBUG)  echo "<br>$deleteSql";
	$result= @mysqli_query($pubConn,$deleteSql);
	echo mysqli_error($pubConn);
	echo " <meta http-equiv=\"refresh\" content=\"0; url=$listPageURL\"> ";
}

$sql="SELECT * 
	  FROM $tableName
	  WHERE month='$month'
	  AND day='$day'";
$result=mysqli_query($pubConn,$sql);
$rows=mysqli_fetch_array($result);
?>


<?php
echo "<table id=\"table_up\" border=\"0\" width=\"100%\">";
	echo "<tr>";
		echo "<td width=\"50%\">";
		echo "$strThisPage";
		echo "</td>";
		echo "<td width=\"50%\" align=\"right\">&nbsp;";

		echo "</td>";
	echo "</tr>";
	echo "<tr>";
		echo "<td align=\"left\">";
		echo "<br>";
?>
<a href="tariffHoliday.php" target="_self"><img align=absBottom border="0" src="../../images/list.gif" width="16" height="16">List</a>&nbsp;&nbsp;&nbsp;
<?php
	echo "<a href=\"tariffHolidayEdit.php?mode=$arr_mode[1]\" target=\"_self\">";
?>
<img align="absBottom" border="0" src="../../images/add.gif" width="16" height="16">Add</a>&nbsp;&nbsp;&nbsp;
<?php
		echo "</td>";
		echo "<td width=\"50%\" align=\"right\">&nbsp;";
		echo "</td>";
	echo "</tr>";
echo "</table>";

adjust_title_tail();
adjust_content_head();
echo "<br>";


?>


  <table border="1" width="400" cellpadding="2" cellspacing="0"  bordercolor="#666666" bordercolordark="#FFFFFF" bgcolor="#FFFFFF"  >
    <tr bgcolor="#E6E6E6">
	<td colspan="2"><?php echo $tableTitle; ?></td>
	</tr>
	<tr>
    <td width="40%"><?php echo $strDate; ?></td>
	<td width="60%">
	<?php 
		if($mode == "edit"){
			$month=omc_keep_length($rows[month],0,2);
			$day=omc_keep_length($rows[day],0,2);
			echo "$month&nbsp;-&nbsp;$day";
			echo "<input type=\"hidden\" name=\"month\" size=\"20\" value=\"$month\">";
			echo "<input type=\"hidden\" name=\"day\" size=\"20\" value=\"$day\">";
		}

		elseif($mode == "add"){
			echo "<select size=\"1\" name=\"month\">";       
			for($i=1;$i<=12;$i++){   
				$m=($i<10?"0":"").$i;       
				echo "<option value=\"$m\">$m</option>"; 
			}		   
			echo "</select>";
			echo "&nbsp;-&nbsp;";
			echo "<select size=\"1\" name=\"day\">";       
			for($i=1;$i<=31;$i++){   
				$m=($i<10?"0":"").$i;       
				echo "<option value=\"$m\">$m</option>"; 
			}		   
			echo "</select>";
		}	
		echo "&nbsp;(mm-dd)"; 
  ?>
	</td>
	</tr>
	<tr>
    <td><?php echo $strDescription; ?></td>
	<td>
	<?php
		$rows[name]=$rows[name]?$rows[name]:'--';
		echo "<input type=\"text\" name=\"name\" size=\"20\" value=\"$rows[name]\" class=\"text\">"; 
	?>
	</td>
    </tr>
  </table>
  <table  width="400">     
    <tr>     
     <td> 
	      <input type="submit" name="set" value="Set" style="width:40" class="button">&nbsp; 
		  <input type="reset" name="reset" value="Reset" class="button">&nbsp;
		  <input type="button" name="return" value="Return" onclick=jacascript:location.href="./tariffHoliday.php" class="button">&nbsp;
          <?php
			if($mode == "edit"){
				echo "<input type=\"submit\" name=\"delete\" value=\"Delete\" class=\"button\">";
		    } 
		  ?>
     </td>         
   </tr>           
  </table>
</form>
<?php
adjust_content_tail();
?>
</body>   
</html>