私はjQueryウィジェットのDatePickerとDialogを使用して、AdamShawhttp://arshaw.com/fullcalendarによるfullCallendarと対話しています。私はたくさんのことをやっています。DatePickerを使用して、フルカレンダーの特定の日付にジャンプできます。イベントを予約するように選択すると、jQueryダイアログが表示され、ajax呼び出しを使用してフィールドをphpスクリプトに送信し、データを処理します。
ただし、私の問題は、fullcalendarの開始変数と終了変数で使用されるUNIXタイムスタンプに起因します。HTMLファイルの先頭にグローバル変数を設定し、fullcalendarでの選択から開始/終了時刻を設定して、データがダイアログに渡されるようにします。Dialogから、それをPHPスクリプトに渡します。しかし、そのUNIXタイムスタンプを「YmjHis」形式の日付に変換すると、奇妙な結果が得られます。
fullcalendarの「select」メソッドの関連コードは次のとおりです。
select: function(start, end, allDay) {
// need to check the day first. If the selected day/time < today, throw an alert
// otherwise allow the booking of the conference.
var now = calendar.fullCalendar('getDate');
if (start < now )
{
alert('You cannot book a conference in the past!');
calendar.fullCalendar( 'unselect' );
}
else
{
// set the global variables
st = start;
et = end;
$('#dialog-form').dialog('open'); // open the dialog form
}
},
さて、ダイアログでこれを行います(これは主にjQueryUIの例のページから直接取得されます:
$( "#dialog-form" ).dialog({
autoOpen: false,
height: 300,
width: 350,
modal: true,
buttons: {
"Create Event": function() {
var bValid = true;
allFields.removeClass( "ui-state-error" );
bValid = bValid && checkLength( name, "name", 3, 25 );
bValid = bValid && checkLength( title, "title", 1, 20 );
bValid = bValid && checkLength( email, "email", 6, 80 );
bValid = bValid && checkLength( ports, "ports", 1, 2 );
bValid = bValid && checkRegexp( name, /^[a-z]([0-9a-z_])+$/i, "Name may consist of a-z, 0-9, underscores, begin with a letter." );
// From jquery.validate.js (by joern), contributed by Scott Gonzalez: http://projects.scottsplayground.com/email_address_validation/
// change to ensure a domain email address
bValid = bValid && checkRegexp( email, /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i, "eg. ui@jquery.com" );
if ( bValid ) {
// code to insert into DB goes here
// need to somehow grab either a global variable or access
// full calendar start/end times from the selection phase
// in order to pass to the DB.
$.ajax(
{
url: "bookings.php",
type: "POST",
data: {e: email.val(), t: title.val(), n: name.val(), p: ports.val(), start: +st, end: +et},
dataType: "HTML",
success: function(data) {
$('.result').html(data);
// reload fullCalendar here maybe??
}
});
$( this ).dialog( "close" );
}
},
Cancel: function() {
$( this ).dialog( "close" );
}
},
close: function() {
allFields.val( "" ).removeClass( "ui-state-error" );
}
});
さて、私のbookings.phpファイルには次のテストコードが含まれています。
$file = 'variables.txt';
$arr= $_REQUEST;
$fp = fopen($file, 'w') or die('Could not open file!');
fwrite($fp, "variables are:\n");
foreach ($arr as $key => $value) {
$toFile = "Key: $key; Value: $value \n";
// write to file
fwrite($fp, "$toFile") or die('Could not write to file');
}
// DEBUG CODE write some blank space
fwrite($fp, "\n\n") or die('Could not write to file');
$startTime = $_REQUEST['start'];
$endTime = $_REQUEST['end'];
$start = date('YmjHis', $startTime);
fwrite($fp, "start time: $startTime = $start\n") or die('Could not write to file');
$end = date('YmjHis', $endtime);
fwrite($fp, "end time: $endTime = $end\n") or die('Could not write to file');
// close file
fclose($fp);
variable.txtファイルを見ると、次のように表示されます。
Key: e; Value: me@blah.com
Key: t; Value: blah
Key: n; Value: blah
Key: p; Value: 2
Key: start; Value: 1339610400000
Key: end; Value: 1339617600000
start time: 1339610400000 = 444200724160000
end time: 1339617600000 = 19691231160000
私が期待するのは、開始時刻と終了時刻が次のような形式になることです。20120613113000ああ、1969年の日付で終わらないでください。
ですから、私は明らかに私の変換で何か間違ったことをしています。これは、fullCalendarを完全に実装して、必要なことを実行するための最後のハードルであり、困惑しています。どんな助けでも大歓迎です。