<?php
	require("__include-common.php");
	require("../account/__logincheck.php");

	$user_id = $_SESSION['login_id'];
	if (($subject = form_str_adjust($_POST['subj'])) == '') {
		$subject = "(無題)";
	}
	$now_date = date("Y/m/d H:i:s");
	$con = my_mysql_connect(_DB_SCHEMA);
	if ($_POST['id'].'' == '' or $_POST['id'] == '0') {
		$sql = "insert into m_psketch";
		$sql .= " (id_account";
		$sql .= ", c_subject";
		$sql .= ", c_json";
		$sql .= ", c_image";
		$sql .= ", c_background";
		$sql .= ", c_registtime";
		$sql .= ", c_updatetime";
		$sql .= ") values ";
		$sql .= "( '".$user_id."'";
		$sql .= ", '".str_for_mysql($subject)."'";
		$sql .= ", '".post_to_mysql('json')."'";
		$sql .= ", '".post_to_mysql('image')."'";
		$sql .= ", '".post_to_mysql('bg')."'";
		$sql .= ", '".$now_date."'";
		$sql .= ", '".$now_date."'";
		$sql .= ")";
		$ret = mysql_query($sql);
		if (!$ret) {
			echo '0';
			exit;
		}
		$id = mysql_insert_id();
		$con = mysql_close($con);
	} else {
		$id = intval($_POST['id']);
		$sql = "update m_psketch set";
		$sql .= " c_subject = '".str_for_mysql($subject)."'";
		$sql .= ", c_json = '".post_to_mysql('json')."'";
		$sql .= ", c_image = '".post_to_mysql('image')."'";
		$sql .= ", c_background = '".post_to_mysql('bg')."'";
		$sql .= ", c_updatetime = '".$now_date."'";
		$sql .= " where id_psketch = ".$id;
		$sql .= " and id_account = ".$user_id;
		$ret = mysql_query($sql);
		$con = mysql_close($con);
	}
	echo $id;
?>
