<?php

class SaveTemplatePage extends CMSWebPageBase {

	var $site;
	var $id;
	var $type;//ブログページ用

	function doPost(){
		
		if(UserInfoUtil::getSiteId() != $this->site){
			//サイトが違う
			echo json_encode(array("soy2_token"=>"", "status"=>"-1", "block"=>""));
		}else{
	    	if(soy2_check_token()){
	
				$result = $this->run("Page.SaveTemplateAction",array(
					"id" => $this->id,
					"type" => $this->type,
				));
		
				if($result->success()){
					$webPage = SOY2HTMLFactory::createInstance("Block.BlockListPage",array(
						"pageId" => $this->id
					));
		
			     	//BlockListPageはコンポーネントなので
			     	$webPage->execute();
			     	$html = $webPage->getObject();
		
					echo json_encode(array("soy2_token"=>soy2_get_token(), "status" => "1", "block"=>$html));
				}else{
					echo json_encode(array("soy2_token"=>soy2_get_token(), "status"=>"0", "block"=>""));;
				}
	    	}else{
				echo json_encode(array("soy2_token"=>soy2_get_token(), "status"=>"0", "block"=>""));;
	    	}
		}

		exit;

	}

    function SaveTemplatePage($args) {
    	$this->site = isset($args[0]) ? $args[0] : null ;
    	$this->id   = isset($args[1]) ? $args[1] : null ;
    	$this->type = isset($args[2]) ? $args[2] : null ;

    	WebPage::WebPage();

    	exit;
    }
}
?>