<?php
exit();
session_start();
ini_set("display_errors",1);
error_reporting(E_ALL);
?>
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<title>外注工程管理表</title>
<link rel="stylesheet" href="cssreset-min.css">
<link rel="stylesheet" href="style.css">
<script src="jquery-1.11.2.min.js"></script>
</head>
<body>
<?php
if(array_key_exists("s",$_GET) && $_GET["s"] != ""){
if(preg_match("/^[0-9]{8}$/", $_GET["s"])){
$start_day = substr($_GET["s"], 0, 4) . "-" . substr($_GET["s"], 4, 2) . "-" . substr($_GET["s"], 6, 2);
}else{
$start_day = date("Y-m-d");
}
}else{
$start_day = date("Y-m-d");
}
if(array_key_exists("c",$_GET) && $_GET["c"] != ""){
if(preg_match("/^[0-9]+$/", $_GET["c"])){
$column = $_GET["c"];
}else{
$column = 14;
}
}else{
$column = 14;
}
include 'class.php';
$db = Db::con();
include 'edit.php';
include 'save.php';
?>
<div class="frm">
<input type="button" value=" 新規登録 " id="save_btn">
<span class="<?php if(!array_key_exists("v", $_GET)){
echo 'down_btn"';
}else{
echo 'btn" id="default_btn"';
}
?>> 通常 </span>
<span class="<?php if(array_key_exists("v", $_GET) && $_GET["v"] == "none_draw"){
echo 'down_btn"';
}else{
echo 'btn" id="none_draw_btn"';
}
?>> 未出図依頼 </span>
<span class="<?php if(array_key_exists("v", $_GET) && $_GET["v"] == "none_sup"){
echo 'down_btn"';
}else{
echo 'btn" id="none_sup_btn"';
}
?>> 製作先未決定 </span>
<span class="<?php if(array_key_exists("v", $_GET) && $_GET["v"] == "done"){
echo 'down_btn"';
}else{
echo 'btn" id="done_btn"';
}
?>> 出荷済 </span>
<span class="<?php if(array_key_exists("v", $_GET) && $_GET["v"] == "hold"){
echo 'down_btn"';
}else{
echo 'btn" id="hold_btn"';
}
?>> 保留 </span>
</div>
<div id="start" class="frm">
列数:<input type="text" value="<?php echo $column ?>" id="column_count">
日付:
<!-- 年 -->
<select id="start_y">
<option><?php echo date("Y",strtotime(" $start_day - 2 year")); ?></option>
<option><?php echo date("Y",strtotime(" $start_day - 1 year")); ?></option>
<option selected ><?php echo date("Y",strtotime(" $start_day + 0 year")); ?></option>
<option><?php echo date("Y",strtotime(" $start_day + 1 year")); ?></option>
<option><?php echo date("Y",strtotime(" $start_day + 2 year")); ?></option>
</select>
<!-- 月 -->
<select id="start_m">
<?php
for($i=1; $i <= 12; $i++){
if((int)date("m",strtotime("$start_day")) == $i){
if($i < 10){ $i = "0" . $i; }
echo '<option selected>', $i, '</option>';
}else{
if($i < 10){ $i = "0" . $i; }
echo '<option>', $i, '</option>';
}
}
?>
</select>
<!-- 日 -->
<select id="start_d">
<?php
for($i=1; $i <= 31; $i++){
if((int)date("d",strtotime("$start_day")) == $i){
if($i < 10){ $i = "0" . $i; }
echo '<option selected>', $i, '</option>';
}else{
if($i < 10){ $i = "0" . $i; }
echo '<option>', $i, '</option>';
}
}
?>
</select>
<input type="button" value=" 更新 " id="start_position">
<input type="button" value=" 本日 " id="today_position">
</div>
<?php include 'table.php'; ?>
<script>
$(document).on("change","#task_select",function(){
if($("#task_select option:selected").text() == "検査"){
$("#task_select_val").removeAttr("disabled");
}else{
$("#task_select_val").attr("disabled", "disabled");
}
});
$(document).on("click","#input_task_cancel_btn", function(){
$("#input_task_add").remove();
});
$(document).on("click","#input_task_add_btn", function(){
var task = $("#task_select option:selected").text();
var task_val = $("#task_select_val").val();
var id = $(this).prev().children("input[name=id]").val();
var ymd = $(this).prev().children("input[name=ymd]").val();
$.ajax({
type: "POST",
url: "add_task.php",
acync: false,
data: {
task: task,
task_val: task_val,
id: id,
ymd: ymd
},
dataType: 'html',
success: function(data){
if (data === "false"){
alert("エラーが発生しました。処理は中断されました。");
return;
}
$("#input_task_add").remove();
window.location.reload();
},error: function(){
alert("エラーが発生しました。処理は中断されました。");
return;
}
});
});
//ダイアログを表示
$(document).on("click", ".tbl_btn", function(){
if(document.getElementById("input_task_add") != null){
return;
}
var id = $(this).parent().parent().parent().parent().data("id");
var ymd = $(this).parent().data("date");
var top = $(this).position().top;
var left = $(this).position().left;
var html =
'<form class="frm">'+
'タスク:<select id="task_select"><option>出図日</option><option>支給品手配</option><option>検査</option><option>納期</option></select> '+
'<input type="text" id="task_select_val" disabled="disabled">'+
'<input type="hidden" name="id" value="' + id + '">'+
'<input type="hidden" name="ymd" value="' + ymd + '">'+
'</form>'+
'<input type="button" value=" 登録 " id="input_task_add_btn"> <input type="button" value=" 中止 "id="input_task_cancel_btn">';
var e = $("<div>", {
id: "input_task_add",
html: html
});
$("body").append(e);
$("#input_task_add").css({
"background-color": "white",
"position": "absolute",
"z-index": "999",
"border":"2px solid #1253A4",
"padding": "10px",
"width": "265px",
"top": top,
"left": left
});
});
$(document).on("click", "#default_btn", function(){
var y = $("#start_y option:selected").text();
var m = $("#start_m option:selected").text();
var d = $("#start_d option:selected").text();
var start_day = y + m + d;
var count = $("#column_count").val();
window.location.href = "<?php echo $_SERVER['SCRIPT_NAME']; ?>" + "?s=" + start_day + "&c=" + count + "";
});
$(document).on("click", "#done_btn", function(){
var y = $("#start_y option:selected").text();
var m = $("#start_m option:selected").text();
var d = $("#start_d option:selected").text();
var start_day = y + m + d;
var count = $("#column_count").val();
window.location.href = "<?php echo $_SERVER['SCRIPT_NAME']; ?>" + "?v=done&s=" + start_day + "&c=" + count + "";
});
$(document).on("click", "#none_draw_btn", function(){
var y = $("#start_y option:selected").text();
var m = $("#start_m option:selected").text();
var d = $("#start_d option:selected").text();
var start_day = y + m + d;
var count = $("#column_count").val();
window.location.href = "<?php echo $_SERVER['SCRIPT_NAME']; ?>" + "?v=none_draw&s=" + start_day + "&c=" + count + "";
});
$(document).on("click", "#none_sup_btn", function(){
var y = $("#start_y option:selected").text();
var m = $("#start_m option:selected").text();
var d = $("#start_d option:selected").text();
var start_day = y + m + d;
var count = $("#column_count").val();
window.location.href = "<?php echo $_SERVER['SCRIPT_NAME']; ?>" + "?v=none_sup&s=" + start_day + "&c=" + count + "";
});
$(document).on("click", "#hold_btn", function(){
var y = $("#start_y option:selected").text();
var m = $("#start_m option:selected").text();
var d = $("#start_d option:selected").text();
var start_day = y + m + d;
var count = $("#column_count").val();
window.location.href = "<?php echo $_SERVER['SCRIPT_NAME']; ?>" + "?v=hold&s=" + start_day + "&c=" + count + "";
});
//更新
$(document).on("click", "#start_position", function(){
var y = $("#start_y option:selected").text();
var m = $("#start_m option:selected").text();
var d = $("#start_d option:selected").text();
var start_day = y + m + d;
var count = $("#column_count").val();
window.location.href = "<?php echo $_SERVER['SCRIPT_NAME']; ?><?php if(array_key_exists("v",$_GET) && $_GET["v"] != ""){ echo "?v=", $_GET["v"], "&"; }else{ echo "?"; } ?>s=" + start_day + "&c=" + count + "";
});
//本日
$(document).on("click", "#today_position", function(){
var count = $("#column_count").val();
window.location.href = "<?php echo $_SERVER['SCRIPT_NAME']; ?><?php if(array_key_exists("v",$_GET) && $_GET["v"] != ""){ echo "?v=", $_GET["v"], "&"; }else{ echo "?"; } ?>s=" + <?php echo date("Ymd"); ?> + "&c=" + count + "";
});
$(document).on("click","#save_btn",function(){
$("#edit_div").css("display","none");
$("#save_div").css("display","block");
});
//中止
$(document).on("click","#save_cancel_btn",function(){
$("#save_div").css("display","none");
});
$(document).on("click","#edit_cancel_btn",function(){
$("#edit_div").css("display","none");
});
$(document).on("click",".edit_btn",function(){
$("#save_div").css("display","none");
var id = $(this).parent().parent().parent().parent().data("id");
var kokyaku = $(this).parent().parent().find(".val_2").children("p").text();
var katashiki = $(this).parent().parent().find(".val_3").children("p").text();
var kouban = $(this).parent().parent().find(".val_4").children("p").text();
var suryo = $(this).parent().parent().find(".val_5").children("p").text();
var seisakusaki = $(this).parent().parent().find(".val_6").children("p").text();
var tanka = $(this).parent().parent().find(".val_7").children("p").text();
$("#edit_div").css("display","block");
//表示させているのはdata-idではなくループカウンタ
$("#update_id").text($(this).parent().parent().parent().find(".cap_1").children("p").text());
$("#edit_id").val(id);
$("#edit_kokyaku").val(kokyaku);
$("#edit_katashiki").val(katashiki);
$("#edit_kouban").val(kouban);
$("#edit_suryo").val(suryo);
$("#edit_seisakusaki").val(seisakusaki);
$("#edit_tanka").val(tanka.replace(/,/g,""));
});
//更新・削除・出荷
$(document).on("click","#edit_update_btn, #edit_delete_btn, #edit_hide_btn, #edit_hide_cancel_btn, #edit_hold_btn, #edit_hold_cancel_btn",function(){
var condition = $(this).attr("id");
var id = $("#edit_id").val();
var kokyaku = $("#edit_kokyaku").val();
var katashiki = $("#edit_katashiki").val();
var kouban = $("#edit_kouban").val();
var suryo = $("#edit_suryo").val();
var seisakusaki = $("#edit_seisakusaki").val();
var tanka = $("#edit_tanka").val();
var y = $("#edit_year option:selected").text();
var m = $("#edit_month option:selected").text();
$.ajax({
type: "POST",
url: "edit_condition.php",
timeout: 3000,
acync: false,
data: {
condition: condition,
id: id,
kokyaku: kokyaku,
katashiki: katashiki,
kouban: kouban,
suryo: suryo,
seisakusaki: seisakusaki,
tanka: tanka,
y: y,
m: m
},
dataType: "html",
success: function(data){
if (data === "false"){
alert("エラーが発生しました。処理は中断されました。");
return;
}
alert();
$("#edit_div").css("display","none");
window.location.reload();
},error: function(){
alert("エラーが発生しました。処理は中断されました。");
return;
}
});
});
$(document).keydown(function(e){
if(e.keyCode === 27){
$("#edit_div").css("display","none");
$("#save_div").css("display","none");
$("#input_task_add").remove();
}
});
</script>
</body>
</html>