<?

//將頁面處理值送回主模組	

function main_page()
{	
	global $action;
	
	//流程控制
	switch ($action)
	{   
	
		//上傳完成
   		case "step1":      	
      		$buffer = step1();      		
      		break;
        
	        //預設畫面
   		default:
      		$buffer = step0();      		
      		break;
	}	
	
	return $buffer;
}


//預設頁	
function step0()
{
	global $page,$uid;	

	$buffer = "<br>";
	
	$array['{TOP1_A}'] = "熱　情";
	$array['{TOP1_B}'] = "智　慧";
	$array['{TOP1_C}'] = "科　技";
	
	$buffer .= read_and_parser("top1.php",$array);	
	unset($array);	
	
	$array['{MIDDLE_PANEL_TITLE}'] = '上　傳　論　文';
	$array['{MIDDLE_PANEL_CONTENT}'] = '<form method="POST" action="module.php" enctype="multipart/form-data">';
	$array['{MIDDLE_PANEL_CONTENT}'] .= "<input type=hidden name=page value=$page>";
	$array['{MIDDLE_PANEL_CONTENT}'] .= "<input type=hidden name=action value=step1>";
	$array['{MIDDLE_PANEL_CONTENT}'] .= file_get_contents('require/upload0.htm');
	$array['{MIDDLE_PANEL_CONTENT}'] .= "</form>";


	/* 查詢論文類別 */
	$info = sql_b("SELECT type,name FROM paper_type_list order by type");	
	$xtemp = buffer_select('temp_array[0]',$info);
	
	if($uid=='SATURN') $array['{MIDDLE_PANEL_CONTENT}'] = '您必須先 <a href="module.php?page=member_login">登入系統</a>，才能夠執行這個動作唷！';
	
	$tempp = $array['{MIDDLE_PANEL_CONTENT}'];	
	$tempp = str_replace("{TYPE_LIST}",$xtemp,$tempp);
	$array['{MIDDLE_PANEL_CONTENT}'] = $tempp;
	
	$buffer .= read_and_parser("middle.php",$array);
	unset($array);
	
	return $buffer;
}

//第一步，上傳完成囉
function step1()
{
	global $page,$temp_array,$uid;
	global $uploads, $uploads_name, $uploads_size;
	
	if(!$temp_array[1]) error_message("您的【論文名稱】欄沒有輸入唷!");
	if(!$temp_array[2]) error_message("您的【論文作者】欄沒有輸入唷!");
	if(!$uploads) error_message("您的【要上傳的檔案】欄沒有輸入唷!");
	
	/*上傳檔案 & 寫入資料庫*/
	
	$file_type = strtolower(substr($uploads_name,-3,3));			
	
	$sql = "INSERT INTO paper VALUES(NULL,$uid";
	
	for($i=0;$i<sizeof($temp_array);$i++)
	{
		$sql .= ",'$temp_array[$i]'";
	}
	$sql .= ",'$file_type',NOW())";
	
	$id = sql_i($sql);		
	$id = checklen($id,3);	
	@copy($uploads,"papers/". $temp_array[0] . $id. '.' . $file_type);	
	@unlink($uploads);
	
	$buffer = "<br>";
	
	$array['{TOP1_A}'] = "熱　情";
	$array['{TOP1_B}'] = "智　慧";
	$array['{TOP1_C}'] = "科　技";
	
	$buffer .= read_and_parser("top1.php",$array);	
	unset($array);
	
	$array['{MIDDLE_PANEL_TITLE}'] = '上　傳　論　文';	
	$array['{MIDDLE_PANEL_CONTENT}'] .= file_get_contents('require/upload1.htm');	
	$buffer .= read_and_parser("middle.php",$array);
	unset($array);
	
	/* 顯示上傳資料 */
	
	$temp = sql_b("SELECT name FROM paper_type_list WHERE type = '$temp_array[0]'");
	$kkk[] = $temp[0][0];	
	
	$temp_ccc[] = $temp_array[0] . $id;
	$temp_ccc[] = $temp_array[0] . '-' . $kkk[0];
	$temp_ccc[] = $temp_array[1];
	$temp_ccc[] = $temp_array[2];
	$temp_ccc[] = $temp_array[0] . $id. '.' . $file_type;
	
	for($i=0;$i<sizeof($temp_ccc);$i++)
	{
		$buffer = str_replace('{' . ($i+1) . '}',$temp_ccc[$i],$buffer);
	}
	
	return $buffer;
}
?>