<?

if (!isset($_SESSION)) //判斷是否已經開啟SESSION
{
session_start();
}//開起SESSION
$mId=$_SESSION['mId'];
require_once("../function.php");
putenv("NLS_LANG=TRADITIONAL CHINESE_TAIWAN.AL32UTF8");
check_login();


?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>JUME(Join You And Me)揪咪揪團活動網</title>
<!-- Include Core Datepicker Stylesheet -->		
<link href="../member/style/edit_activity.css" rel="stylesheet" type="text/css" media="screen" />
<link rel="stylesheet" href="style/ui.datepicker.css" type="text/css" media="screen" title="core css file"/>
<script type="text/javascript" src="../jQuery/jquery-1.2.6.js"></script>
<script type="text/javascript" language="javascript" src="insert_js.js"></script>
<SCRIPT LANGUAGE="JavaScript" src="../jQuery/TbxLenLimit.js"></SCRIPT>
 <script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAA-fZzs3imoScYLbCOBKQlzRTDQbFKLWBUv-hmAr6_O3aN5ZraihS617SXs678fe0xileB-cptWVBJ5w"
      type="text/javascript"></script>
</head>


<body onunload="GUnload()">
<div id="header">
	<? //include("../member/header2.php"); ?>
</div>
<div id="content">
<?
require_once("../db.php");
$aId=$_GET["aId"];

$res = oci_parse($conn,"select * from ACTIVITY NATURAL JOIN MAP where AID='$aId'") or die('Insert error');

oci_execute($res);

$row=oci_fetch_object($res);



CheckaID($mId);
 $chk_usr=chk_user($row->MID);
 if($chk_usr!='no'){
 
function ChangWord($NewWord){
		// 將 enter 符號換為 <br>
    	$NewWord=str_replace("<br />","",$NewWord);
		// 將 [']+ 符號,換為 `
   		$NewWord=ereg_replace("[']+", "`", $NewWord);
		return $NewWord;
 	}
	
?>

<div id="raisedetail" align="center">

<form action="edit_activity_act.php" method="post" enctype="multipart/form-data" id="act_form" name="restauForm" onsubmit="return valid_add();">
<input type="hidden" name="aId" value="<? echo $aId;?>">
<table border="0" id="temp">
  	<tr align="left">
		<th scope="row" class="must">活動名稱</th>
    	<td><? echo"<input type='text' name='aName' size='45' maxlength='35' value='$row->ANAME'>"?>(建議30字以內)</td>
  	</tr>
	<tr align="left">
  		<th scope="row" class="must">活動時間</th>
  		<td><? echo"<input type='text' size='10' name='start_date' value='$row->ATIME' id='start_date'/>to<input type='text' size='10' name='end_date' value='$row->END_DATE' id='end_date'/>";?></td> 
	</tr>
	<!--
	<tr align="left">
    	<th scope="row" class="must">場地</th>
    	<td><? echo"<input type='text' name='aPlace' size='45' maxlength='20' value='$row->aPlace'>"?>(建議20字以內)</td>
  	</tr>
	-->
  	<tr align="left">
    	<th scope="row" class="must">地址</th>
    	<td><input id='addFie' type="text" size="45" name="markerAddress" onkeydown="toPosition(this.value)"	style='color:#666'
				onfocus='clickField(this.id);' value=<?=$row->ADDRESS ?>></input>
				<div id='replyAddCheck' style='color:#03152f; display:block' ></div>
			
		</td>
  	</tr>
  <tr align="left">
    <th>圖片上傳</th>
    <td>
	<? 
	    
$sql = oci_parse($conn,"SELECT * FROM PICTURE WHERE AID='$aId'") or die('Insert error');

oci_execute($sql);



		
		/*
		$row2=mysql_fetch_array($res);
		if($row2[0]!=''){
		echo "<img src=".$row2[0].">";
		}else{echo "NO PICS";}
		*/
 
		//$sql_doc = "select * from AMS_TR05 where NEWS_SN = '$news_id'";
		//$result_doc = odbc_exec($conn,$sql_doc);
		$exist = oci_fetch_all($sql,$result);
		if($exist == 0)
		{
						echo "<input type='file' name='picture' size='40'><br>";
		}
		else{
			echo "‧刪除圖片<br />";
			$i=1;
			while($row_doc = oci_fetch_object($sql)){
				echo "<input type='checkbox' id='p$i' name='delete' value='".$row_doc->PID."&".$row_doc->PPATH."'>";
				echo $row_doc->PNAME."<br />";
				$i++;
			}
			echo "<div id='Q113' class='sub-option'>";
			echo "<br />‧新增圖片<br />";
			echo "<input type='file' name='picture' size='40'>";
			echo "</div>";	
	}
?> 
<!--
	<tr align="left">
    	<th>主辦單位</th>
    	<td><? echo"<input type='text' name='host' size='45' maxlength='20' value='$row->host'>"?>(建議20字以內)</td>
  	</tr>
	-->
<tr>
	<td colspan='2'>
<div id="map" style=" width:500px; height:500px; clear:both;margin: 0px auto;" ></div>
  
<? 
  if($row->LAT==''||$row->LON==''){
  $add="var point=new GLatLng(22.626083, 120.265768);";
  }else{
  $add="var point=new GLatLng(".$row->LAT.",".$row->LON.");";

  }
  
  echo "<script type='text/javascript'>
  
        var map = new GMap2(document.getElementById('map'));
        //map.setCenter(new GLatLng(23.6, 121.1419), 15);
		
		".$add."
		map.setCenter(point, 14);
		
		marker=new GMarker(point);
		map.addOverlay(marker);
		map.addControl(new GSmallMapControl());
	    map.addControl(new GMapTypeControl());
			marker=new GMarker(point,{draggable: true});
		drag();
		
		map.addOverlay(marker);
		marker.openInfoWindowHtml(\"<br> <div style='text-align:left''>你的位置:<br>".$row->ADDRESS."</div><br>可以拖曳我定位或是輸入地址唷 ^.<\");
	
		geocoder = new GClientGeocoder();
		 
   </script>";
   
   //echo $row->lat;
?>


</td>
</tr>
  	<tr >
        <th colspan="2" id="con"><div style="margin: 0px auto;" >活動內容</div></th>
      </tr>
      <tr>
		<td colspan="2">超過將會被截掉喔~
			<textarea name='content' cols="65" rows="14" MaxLen="1000" class="ShowLen"><?=ChangWord($row->ACONTENT)?></textarea></td>
  	</tr>
	<!--
  	<tr align="left">
    	<th>活動費用</th>
    	<td><? echo"<input type='text' name='fees' size='10' maxlength='10' value='$row->fees'>"?></td>
  	</tr>
	-->
  	<tr align="left">
    	<th>類別</th>
    	<td><input type="radio" name="aType" id="1" value="1" <? if($row->TID==1) echo "checked";?> />Shopping
 	    	<input type="radio" name="aType" id="2" value="2" <? if($row->TID==2) echo "checked";?> />Party      
			<input type="radio" name="aType" id="3" value="3" <? if($row->TID==3) echo "checked";?> />Food
        	<input type="radio" name="aType" id="4" value="4" <? if($row->TID==4) echo "checked";?> />Travel
			<input type="radio" name="aType" id="5" value="5" <? if($row->TID==5) echo "checked";?> />Sports
        	<input type="radio" name="aType" id="6" value="6" <? if($row->TID==6) echo "checked";?> />Educate
		</td>
  	</tr>
	<!--
  	<tr align="left">
    	<th>網站</th>
    	<td><? echo"<input type='text' name='website' size='50' maxlength='30' value='$row->website'>"?>(建議先縮網址)</td>
  	</tr>
  	<tr align="left">
    	<th>聯絡電話</th>
    	<td><? echo"<input type='text' name='aPhone' size='20' maxlength='15' value='$row->aPhone'>"?></td>
  	</tr>
	-->
  	<input type="hidden" value="" name="rId"></input>
	
	<input type="hidden" value="" name="lng" value='<? if($row->LON!='') echo $row->LON ;else echo "120.265768"; ?>'></input>
	<input type="hidden" value="" name="lat"  value='<? if($row->LAT!='') echo $row->LAT ;else echo "22.626083"; ?>'></input>
	
</table>
<p>
  <input type="hidden" name="aId" value="<?=$aId?>">
  <input type="hidden" name="mapid" value="<?=$row->MAPID?>">
<!--<input type='button' value='確定修改' class="bu" onclick='checkBeforeSubmit();'>-->
  <input type="submit" name="Submit" value="確定修改" />
  <input type="button" onClick="history.back(-1);" value="取消修改">
  </p>

    
<div id="invDiv" name='invDiv' style='display:none'></div>
		<input id='ln' type='text' style='display:none' ></input>
		<input id='la' type='text' style='display:none' ></input>
</center>
</form>
</div><!--end #raisedetail-->
</div><!--END #content-->

<div id="footer">   
  <div id="footer-in" align="center">
  <p>版權資訊</p>
    <p>國立中山大學  資訊管理學系  揪咪揪團網 <a href="mailto:jumemis@yahoo.com.tw">揪咪團隊<img src="../mail/send email.gif" border="0"/></a> 版權所有  Taiwan All Rights Reserved</p> 
  </div><!-- end #footer-in -->
</div><!-- end #footer -->

</body>
</html>

<?

}else{echo "非本人喔~";}
	?>
<script type="text/javascript" src="js/ui.datepicker.js"></script>
<script type="text/javascript" language="javascript" src="insert_js.js"></script>
</script>

 

	  <script type="text/javascript"> 
	  
 
	  
	  
	  

	  
$("#start_date").datepicker({ 
   beforeShow: customRange,
    dateFormat:"yy-mm-dd",
    minDate:"0",
	showOn: "both", 
    buttonImage: "style/pickup.gif", 
    buttonImageOnly: true 
});
$("#end_date").datepicker({ 
beforeShow: customRange,
    dateFormat:"yy-mm-dd",
  	 minDate:"0",
    showOn: "both", 
    buttonImage: "style/pickup.gif", 
    buttonImageOnly: true 
});
function customRange(input) { 
var tm=$("#start_date").datepicker("getDate");
var tm_2=$("#end_date").datepicker("getDate");
if(input.id == "end_date" && tm != null){
return {minDate: $("#start_date").datepicker("getDate") }
}
/*
  if(input.id == "start_date" && tm_2 != null){
return { minDate: $("#end_date").datepicker("getDate")  }
} */ 
	/*,maxDate: (input.id == "start_date" ? $("#end_date").datepicker("getDate") : null)}; */
} 

  function valid_add()
	{
		var msg = "";	
		//alert(msg);
		var x;
		
        formobj = window.document.getElementById("act_form");
        
         if (formobj.aName.value == ""){
    msg += "請輸入活動名稱\n";
        }

		
		if (formobj.start_date.value == "")
        {
        	  msg += "請輸開始時間\n";
        }
		if (formobj.end_date.value == "")
        {
        	  msg += "請輸結束時間\n";
        }
		if (formobj.end_date.value < formobj.start_date.value )
        {
        	  msg += "時間輸入錯誤\n";
        }
	
		if (formobj.markerAddress.value == "")
        {
        	  msg += "請輸入地址\n";
        }
		if (formobj.content.value == "")
        {
        	  msg += "請輸入活動內容\n";
        }
			/*
			if (formobj.fees.value == "")
        {
        	  msg += "請輸入手機\n";
        }*/
		if(checkFile_act()==false){
		msg += "僅限上傳JPG或GIF或PNG \n";
		
		}
			
	
		/*
		if(formobj.aPhone.value!=""){
       if(isNaN(formobj.aPhone.value)){
		msg += "電話錯誤\n";
			  
		}
		
		}if(formobj.fees.value!=""){
		 if(isNaN(formobj.fees.value)){
		msg += "費用錯誤\n";
			  
		}
		}
       */
		if (msg != "")
        {
            alert(msg);
            return false;
        }
        else
        {
			
			return true;
			
        }
		
   }
   
		//這裡控制要檢查的項目，true表示要檢查，false表示不檢查    
 var isCheckImageType = true;  //是否檢查圖片副檔名    
 var isCheckImageWidth = true;  //是否檢查圖片寬度    
 var isCheckImageHeight = true;  //是否檢查圖片高度    
 var isCheckImageSize = true;  //是否檢查圖片檔案大小    
   
 var ImageSizeLimit = 100000;  //上傳上限，單位:byte    
 var ImageWidthLimit = 400;  //圖片寬度上限    
 var ImageHeightLimit = 300;  //圖片高度上限    
   
 function checkFile_act() {    
     var f = window.document.getElementById("act_form"); 
	
     var re = /\.(jpg|gif|png)$/i;  //允許的圖片副檔名  
     if(f.picture.value!=''){  
     if (isCheckImageType && !re.test(f.picture.value)) { 
	return false;
         /*alert("只允許上傳JPG或GIF影像檔"); 
         return false;   */
     /*} else { 
     	 document.mr.submit(); 
     
     }
    } else { 
     document.mr.submit()	; 
     return true;*/
     }   
 }    
 }
 function checkImage() {    
     if (isCheckImageWidth && this.width > ImageWidthLimit) {    
         showMessage('寬度','px',this.width,ImageWidthLimit);    
     } else if (isCheckImageHeight && this.height > ImageHeightLimit) {    
         showMessage('高度','px',this.height,ImageHeightLimit);    
     } else if (isCheckImageSize && this.fileSize > ImageSizeLimit) {    
         showMessage('檔案大小','kb',this.fileSize/1000,ImageSizeLimit/1000);            
     } else {    
         document.mr.submit();    
     }    
 }    
 function showMessage(kind,unit,real,limit) {    
     var msg = "您所選擇的圖片kind為 real unit\n超過了上傳上限 limit unit\n不允許上傳！"    
     alert(msg.replace(/kind/,kind).replace(/unit/g,unit).replace(/real/,real).replace(/limit/,limit));    
 }    

	 
	   function showInputQ1(e){
	   
if($('#p1').is(':checked')) {
    // do something
	$('#Q113').show();
		
	
	}else 
	{		
		$('#Q113').hide();
		
		
	}
}

	showInputQ1();

	
	$("input[id='p1']").click(showInputQ1);
 
</script> 
