<?
if (!isset($_SESSION)) //判斷是否已經開啟SESSION
{
	header("Cache-control:private");
session_start();
}//開起SESSION}
putenv("NLS_LANG=TRADITIONAL CHINESE_TAIWAN.AL32UTF8");
require_once("../function.php");

check_login();

$mAccount=$_SESSION['mAccount'];

if($mAccount!=''){
//echo $mAccount;
require_once("../db.php");
$res = oci_parse($conn,"select * from MEMBER where MACCOUNT='$mAccount'") or die('Insert error');
oci_execute($res);

$row=oci_fetch_object($res);
$mId=$row->MID;
/*
$str1=mysql_query("select * from member where mAccount='$mAccount'");
$row1=mysql_fetch_object($str1);
$mId=$row1->mId;
*/




?>



<?
//$aId=$_GET["aId"];
?>
<?php
require_once("../db.php");


	if(isset($_POST['markerAddress']))
		$aAddress=$_POST['markerAddress'];


	if(isset($_POST['lng']))
		$lng=$_POST['lng'];
	if(isset($_POST['lat']))
		$lat=$_POST['lat'];




$aName=$_POST['aName'];
//$host=$_POST['host'];
$start_date=$_POST['start_date'];
$end_date=$_POST['end_date'];
/*$date=$_POST['date'];
$pre_date=explode(" - ",$date);
$start_date=$pre_date[0];
$end_date=$pre_date[1];
*/
//$aPlace=$_POST['aPlace'];
//$aAddress=$_POST['aAddress'];
$content=$_POST['content'];


//$fees=$_POST['fees'];
$aType=$_POST['aType'];
//$website=$_POST['website'];
//$aPhone=$_POST['aPhone'];
//$mId=$_POST['mId'];


if(empty($aName)||empty($aAddress)||empty($content)||empty($aType))
{
	echo "<script>";
	echo "alert(\"有欄位空白!!\");";
	echo "history.go(-1)";
	echo "</script>";
}else{
/*
$sql="INSERT INTO activity (aName,host,start_date,end_date,aPlace,content,pic,fees,aType,website,aPhone,aAddress_1,aAddress_2,lng,lat) VALUES 
('$name','$host','$start_date','$end_date','$place','$content','$pic_name','$fees','$type','$website','$phone','$rAddress','','$lng','$lat')";
mysql_query($sql_restau);	
*/
$content=nl2br(htmlspecialchars($content));
$aName=nl2br(htmlspecialchars($aName));
//$host=nl2br(htmlspecialchars($host));
$start_date=nl2br(htmlspecialchars($start_date));
$end_date=nl2br(htmlspecialchars($end_date));
//$aPlace=nl2br(htmlspecialchars($aPlace));
//$fees=nl2br(htmlspecialchars($fees));
$aType=nl2br(htmlspecialchars($aType));
//$website=nl2br(htmlspecialchars($website));
//$aPhone=nl2br(htmlspecialchars($aPhone));
$aAddress=nl2br(htmlspecialchars($aAddress));

$map="INSERT INTO MAP (MAPID,LON,LAT) VALUES (MAP_ID.NEXTVAL,'$lng','$lat')";

$min = oci_parse($conn,$map) or die('Insert error');
oci_execute($min);


 $str="INSERT INTO activity (AID,ANAME,ATIME,END_DATE,ADDRESS,ACONTENT,TID,MAPID,MID) VALUES 
(ACT_ID.NEXTVAL,'$aName','$start_date','$end_date','$aAddress','$content','$aType',MAP_ID.CURRVAL,'$mId')";
$inact = oci_parse($conn,$str) or die('Insert error');
oci_execute($inact);



	


/**************************************************************************************/


//上傳多個檔案
/*
	$i = 0;
	while($_FILES['picture']['name'][$i])
	{
	*/	
		$error=$_FILES['picture']['error'] ;
			if($error== UPLOAD_ERR_OK){
				
		$file = $_FILES['picture']['name'];
		$tmpname = $_FILES['picture']['tmp_name'];
		
		
		$seq=rand(0,10000).time();
		$subname = explode(".",$file);	
      //$pName = "picture/".$aId."_".$pId.".".$subname[1];
		//$filename = "tmp/".$news_id."_".$doc_id.".".$subname[1];
		//$mod_doc = "update AMS_TR05 set FILEPATH = '$filename' where DOC_SN = '$doc_id'";
		//$result_mod_doc = odbc_exec($conn,$mod_doc);
		
			if($subname[count($subname)-1]=='gif'||$subname[count($subname)-1]=='png'||$subname[count($subname)-1]=='jpg'||$subname[count($subname)-1]=='JPG'||$subname[count($subname)-1]=='PNG'||$subname[count($subname)-1]=='GIF'){
		$subname[1] = strtolower($subname[1]);
		
	
		$pName = "picture/".$seq.".".$subname[1];
		
        //$sql_doc = "insert into news_doc (id,filename) values ('$news_id','$filename')";
		$sql_doc = "insert into PICTURE (AID,PID,PPATH,PNAME) values (ACT_ID.CURRVAL,PIC_ID.NEXTVAL,,'$pName','$tmpname')";
		$inpic = oci_parse($conn,$sql_doc) or die('Insert error');
        oci_execute($inpic);
		
		}else{
		echo "檔名錯誤";
		
		}
		
		/*
		$sql_doc = "insert into picture (aId,pName) values ('$aId','$pName')";
		$result_doc = mysql_query($sql_doc);

		$sql_file = "select * from picture where pName = '$pName' AND aId = '$aId'";
		$result_file = mysql_query($sql_file);
		$row_file = mysql_fetch_object($result_file);
		$pId = $row_file->pId;
		
	
		$mod_doc = "update picture set pPath = '$pName' where pId = '$pId'";
		$result_mod_doc = mysql_query($mod_doc);
		*/
		if (copy($tmpname,$pName))
		{
			unlink($tmpname);
		}
		
	}else if ($error != UPLOAD_ERR_NO_FILE){
			echo "<script>";
	echo "alert('". $_FILES['picture']['name']."上傳失敗');";
	echo "history.go(-1)";
	echo "</script>";
		}
		

		 $curaid = oci_parse($conn,"SELECT ACT_ID.CURRVAL FROM DUAL") or die('Insert error');
oci_execute($curaid);
 $arraid=oci_fetch_array($curaid);
		 $arraid[0];
		
		
		echo "
		<html>
        	<head>
        	<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>
        	</head>
        	<body>
        	<script language=javascript>
        	alert('活動發佈成功！');
        	location.href='activity_show_detail.php?aId=$arraid[0]';
        	</script>
        	</body>
        	</html>
		";



}
	
	
		/*
		$i++;
	}*/
	/***********************************************************************************************************/


?>
<?

}else{echo "請先登入";}
?>


