ajax 関数によってトリガーされるデータベースの更新にパススルー ファイルを使用しています。アヤックスは:
$("#updateInventory").live('click', function() {
$('#updateInventory').attr('disabled', 'disabled');
$.ajax({
type: "POST",
url: "updateInventoryExecmws.php",//
dataType: "json",
success: function(data){
update = data.update;
console.log(data);
if (update == true){
alert(data.message);
} else {
$('#message').html(data.saying);
}
}
});
});
パススルーファイルは次のとおりです。
<?php
passthru('php /home/bookcell/public_html/testbcos/mbas/updateInventorymws.php >> /home/bookcell/public_html/testbcos/exports/mbas.txt &');
$saying = array('saying' => 'Updating Inventory for today. An email will be sent as soon as the update is finished.');
echo json_encode($saying);
?>
これはすべて正常に機能し、updateInventorymws.php ファイルを開始します。ここで、更新が今日すでに行われているかどうか、ユーザーに警告してスクリプトの実行を停止しているかどうかを確認する必要があります。アラートを除いて、これはすべて正しく機能します。このコードは次のとおりです。
//inventory already been updated today?
$updatedTodayResult = $conn->query("SELECT * from order_sold where date_sold between NOW() - interval 5 minute and NOW()");
$updatedTodayRows = $updatedTodayResult->num_rows;
if($updatedTodayRows < 1){
$updatedToday = false;
$note = "Updating Inventory for today. An email will be sent as soon as the update is finished.";
}else{
$updatedToday = true;
$note = "Inventory is already updating for today.";
}
if($updatedToday == false){
// run the update here
}
$records = $x;
$to = "myemail@me.com";
$subject = "Update Inventory Report";
$body = $records . " records were successfully updated in today's inventory update!";
mail($to, $subject, $body);
$message = array('message' => $note,
'update' => $updatedToday,
);
}else{
$records1 = 'Someone has attempted to run Update Inventory more than once today. If this problem shouldn\'t occur, please see administrator.';
$to = "myemail@me.com";
$subject = "Update Inventory Report";
$body = $records1;
mail($to, $subject, $body);
$message = array('message' => $note,
'update' => $updatedToday,
);
}
echo json_encode($message);
これからアラートを作成して、ユーザーが更新が既に行われたことを知る方法はありますか??