<?php
header('Content-Type: text/html; charset=utf-8');
$path="../../";
include("../../map.php");
include("../../scripts.php");
?>
<!doctype html>
<html lang="en">
<head>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<title>Crm+ Task Board | <?php echo $firma?></title>
	<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
	<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
	<link rel="stylesheet" href="//cdn.<?php echo $cdnurl?>/css/watolye.css" type="text/css" /> 
	<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
	<link href="//fonts.googleapis.com/css?family=Patrick+Hand" rel="stylesheet">
	<script src="//cdn.ckeditor.com/4.10.0/basic/ckeditor.js"></script>
	<script src="//code.jquery.com/jquery-1.10.2.js"></script>
	<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
	<link rel="stylesheet" href="style.css">
	<style>
		.cke_top {display:none !important;}
		.body{ font-size:14px; font-family: 'Patrick Hand', cursive;}
	</style>
</head>
<body>
	<div class="btnToolbar" style="padding-left: 5px; margin-top: 10px; display: flex ; align-items: center; width: 98.2%;">
		<a href="?" onclick="location.href='?'" class="btn btn-info" style="margin-top:-1px;"><i class="fa fa-home" aria-hidden="true" style="font-size: 16px;"></i></a>
		<a id="btnCreateNewList" href="#" class="btn btn-warning"><?php echo translate("Yeni Kart")?></a>
		<a id="btnCreateNewOrder" href="#" class="btn btn-warning"><?php echo translate("Yeni Akış")?></a>
		<a id="result" style="display:none"></a>

		<a id="btnClearAll" href="#"  onclick="AjaxGResult('save.php?ne=dellallwork','#result','');"class="btn btn-danger" style="margin-left:auto;">
			<i class="fa fa-broom" aria-hidden="true" style="margin-right:5px;"></i> <?php echo translate("Akışları Temizle")?>
		</a>
	</div>
	<div class="orders">
		<?php for ($x = 1; $x <= 8; $x++) { ?>
			<div class="column col-xl-3 col-md-3 col-sm-3 col-xs-12 w24 mw98" id="col-<?php echo $x;?>" style="margin: 5px; padding: 0px;">
				<?php
				$bgs=array("","warning","info","success","danger","warning","info","success","danger");
				$sqlx=mysqli_query($conn, "select * from kategoriler where ne='wkategori' and sira='".$x."' order by sira asc"); while($rsx=mysqli_fetch_assoc($sqlx)){
					?>
					<i class="fa fa-times fr cp v3-btn-danger" id="del_box<?php echo $rsx["Cat_ID"]?>" onclick="AjaxGResult('save.php?ne=delllist&id=<?php echo $rsx["Cat_ID"]?>','#result','');hide('#col-<?php echo $x;?>')" style="display:none; font-size:20px; position: absolute; right: 0px; top: 0px; cursor:pointer;border-radius: 0px 0px 0px 10px; padding: 4px 5px; color: white;"></i>
					<script>
						jQuery(document).ready(function(){
							jQuery('#header-<?php echo $rsx["Cat_ID"];?>').mouseover(function() {
								jQuery('#del_box<?php echo $rsx["Cat_ID"]?>').show();
							});
							jQuery('#header-<?php echo $rsx["Cat_ID"];?>').mouseout(function() {
								jQuery('#del_box<?php echo $rsx["Cat_ID"]?>').hide();
							});
							jQuery('#del_box<?php echo $rsx["Cat_ID"];?>').mouseover(function() {
								jQuery('#del_box<?php echo $rsx["Cat_ID"]?>').show();
							});
						});
					</script>
					<div class="box bg-<?php echo $bgs[$x]?>" data-title="Unfinished" id="box-<?php echo $rsx["Cat_ID"];?>">
						<div class="header" id="header-<?php echo $rsx["Cat_ID"];?>">
							<?php echo $rsx["Cat_".$_SESSION['lang'].""];?></span>
						</div>
						<div class="body">
							<ul id="sortable1" class="droptrue" style="height:92%; overflow:auto;">
								<?php $sql=mysqli_query($conn, "select * from t1 where ne='workflow' and s2=".$rsx["Cat_ID"]." and s13=1 order by s1 asc"); while($rs=mysqli_fetch_assoc($sql)){?>
									<script>
										jQuery(document).ready(function(){
											jQuery('#row-<?php echo $rs["id"]?>').mouseover(function() {
												jQuery('#action-<?php echo $rs["id"]?>').show();
											});
											jQuery('#row-<?php echo $rs["id"]?>').mouseout(function() {
												jQuery('#action-<?php echo $rs["id"]?>').hide();
											});
											jQuery('#action-<?php echo $rs["id"]?>').mouseover(function() {
												jQuery('#action-<?php echo $rs["id"]?>').show();
											});
										});
									</script>
									<li class="ui-state-highlight" id="row-<?php echo $rs["id"]?>" style="font-size:14px;">
										<?php echo $rs["t1"]?> <span style="font-size: 10px; display: inline-flex;"><?php echo kisalt($rs["n1"],2)?></span>
										<div id="action-<?php echo $rs["id"]?>" style="display:none; width: 20%; float: right;">
											<i class="fa fa-times fr cp v3-btn-danger" onclick="AjaxGResult('save.php?ne=dellorder&id=<?php echo $rs["id"]?>','#result',''); hide('#row-<?php echo $rs["id"]?>')" style="float:right; cursor:pointer;"></i>
											<i class="fa fa-pencil fr cp  v3-btn-warning" onclick="toggle('#d<?php echo $rs["id"]?>');" style="float: right; cursor: pointer; margin-right: 5px; margin-top: 0px; font-size: 15px; padding: 3px;"></i>
										</div>
									</li>
									<div style="border: 1px solid #f0ad4e !important; display:none; position: fixed; left:0px; top: 0px; z-index: 99; width: 100%; height: 100vh; padding-top: 5%; background: rgba(252, 251, 243, 0.8); z-index: 99;" id="d<?php echo $rs["id"]?>">
										<form name="ckeform" class="panel panel-default" style="width: <?php if($mobile==""){echo "45";}else{echo "100";}?>%; background: #fcfbf3; margin-left: auto; margin-right: auto;" id="f<?php echo $rs["id"]?>">
											<div class="panel-heading" style="height: 40px; border-radius: 5px 5px 0px 0px;">
												<h3 class="panel-title"><input type="text" name="t1" value="<?php echo $rs["t1"]?>" style="background: transparent; border: 0px; width:90%; float:left;"> <i class="fa fa-times-circle fr cp" onclick="toggle('#d<?php echo $rs["id"]?>');" style="float:right; cursor:pointer;"></i></h3>
											</div>
											<div class="panel-body" style="padding:0px;">
												<textarea name="n1" id="rte<?php echo $rs["id"]?>" style="width:100%; height:90%; background: transparent; border: 0px;"><?php echo $rs["n1"]?></textarea>
												<script type="text/javascript">CKEDITOR.replace( 'rte<?php echo $rs["id"]?>' ); </script>
												<button type="button" onclick="AjaxPResult('save.php?ne=updateorder&id=<?php echo $rs["id"]?>','#f<?php echo $rs["id"]?>','');" class="btn btn-sm btn-warning fr mt10" style="margin-bottom:10px;"> <?php echo translate("Kaydet")?></button>
											</div>
										</form>
									</div>
								<?php }?>
							</ul>
						</div>
					</div>
				<?php }?>
			</div>
		<?php }?>
	</div>
	<br style="clear:both">
	<div id="dialog-form" title="<?php echo translate("Yeni Akış")?>">
		<form>
			<fieldset>
				<label for="po"><?php echo translate("Akış Başlık")?></label>
				<input type="text" name="title" id="title" value="W0001" onfocus="if(this.value == '<?php echo translate("W0001")?>') { this.value = ''} "  onblur="if(this.value == '') { this.value='<?php echo translate("W0001")?>'; }" class="form-control text ui-widget-content ui-corner-all">
				<label for="list"><?php echo translate("Kart Seçiniz")?></label>
				<select id="list" name="list" class="form-control">
					<?php $sqlx=mysqli_query($conn, "select * from kategoriler where ne='wkategori' order by sira asc"); while($rsx=mysqli_fetch_assoc($sqlx)){?>
						<option value="<?php echo cevir($rsx["Cat_".$_SESSION['lang'].""]);?>"><?php echo $rsx["Cat_".$_SESSION['lang'].""];?></option>
					<?php }?>
				</select>
				<input type="submit" tabindex="-1" style="position:absolute; top:-1000px">
			</fieldset>
		</form>
	</div>
	<div id="dialog-form-list" title="<?php echo translate("Yeni Kart")?>">
		<form id="formList">
			<fieldset>
				<label for="listname"><?php echo translate("Kart Başlık")?></label>
				<input type="text" name="listname" id="listname" value="<?php echo translate("Yeni Kart")?>" onfocus="if(this.value == '<?php echo translate("Yeni Kart")?>') { this.value = ''} "  onblur="if(this.value == '') { this.value='<?php echo translate("Yeni Kart")?>'; }" class="text ui-widget-content ui-corner-all form-control">
				<input type="submit" tabindex="-1" style="position:absolute; top:-1000px">
			</fieldset>
		</form>
	</div>
	<script type="text/javascript">
		jQuery(document).ready(function () {
			jQuery('ul').sortable({
				update: function (event, ui) {
					var data = jQuery(this).sortable('serialize');
					jQuery(".result").text(data);
					var id = jQuery(this).closest('.box').attr('id');
					jQuery.ajax({
						data: data,
						type: 'POST',
						url: 'save.php?boxID='+id+''
					});
				}
			});
			jQuery('.column').sortable({
				update: function (event, ui) {
					var data = jQuery(this).sortable('serialize');
					jQuery(".result").text(data);
					var id = jQuery(this).closest('.column').attr('id');
					jQuery.ajax({
						data: data,
						type: 'POST',
						url: 'save.php?colID='+id+''
					});
				}
			});
		});
		jQuery(function () {
			function initSortable() {
				jQuery(".column").sortable({
					connectWith: ".column",
					handle: ".header",
//                    	cancel: ".header"
//                    	placeholder: "portlet-placeholder ui-corner-all"
				});
				jQuery("ul.droptrue").sortable({
					connectWith: "ul"
				});
				jQuery("ul.dropfalse").sortable({
					connectWith: "ul",
//                    dropOnEmpty: false
				});
				jQuery("#sortable1, #sortable2, #sortable3").disableSelection();
			}
			initSortable();
			jQuery(".btn")
			.button()
			.click(function (event) {
				event.preventDefault();
			});
			function addOrder() {
				var valid = true;
				if (valid) {
					selectedList = jQuery('#list').find(":selected").text();
					box = jQuery('div').find("[data-title='" + selectedList + "']");
					boxList = box.find('ul');
					var title = jQuery('#title').val();
					jQuery.get( "save.php?ne=addorder&title="+title+"&selectedList="+selectedList+"" );
						//alert(""+po+" > "+company+" > "+selectedList+"");	//Order kayıt
					boxList.append("<li class=\"ui-state-highlight\">" + title + "</li>");
					location.href='?';
					dialog.dialog("close");
				}
				return valid;
			}
			dialog = jQuery("#dialog-form").dialog({
				autoOpen: false,
				height: 380,
				width: 350,
				modal: true,
				buttons: {
					"<?php echo translate("Ekle")?>": addOrder,
					"<?php echo translate("İptal")?>": function () {
						dialog.dialog("close");
					}
				},
				close: function () {
				}
			});
			function addList() {
				bodyWidth = jQuery("body").width();
				nextWidth = bodyWidth + 300;
				jQuery('body').css('width', nextWidth + 'px');
				var listName = jQuery('#listname').val();
				jQuery.get( "save.php?ne=addlist&listName="+listName+"" );
				jQuery("div.orders").append("<div class=\"column\">" +
					"<div class=\"box\" data-title=\"" + listName + "\">" +
					"<div class=\"header\">" +
					"    " + listName +
					"</div>" +
					"<div class=\"body\">" +
					"    <ul id=\"sortable3\" class=\"droptrue\">" +
					"    </ul>" +
					"</div>" +
					"</div></div>");
				initSortable();
				location.href='?';
				dialogList.dialog("close");
			}
			dialogList = jQuery("#dialog-form-list").dialog({
				autoOpen: false,
				height: 250,
				width: 350,
				modal: true,
				buttons: {
					"<?php echo translate("Ekle")?>": addList,
					"<?php echo translate("İptal")?>": function () {
						dialogList.dialog("close");
					}
				},
				close: function () {
				}
			});
			form = dialog.find("form").on("submit", function (event) {
				event.preventDefault();
				addOrder();
			});
			form = dialog.find("#formList").on("submit", function (event) {
				event.preventDefault();
				addList();
			});
			jQuery("#btnCreateNewOrder").button().on("click", function () {
				dialog.dialog("open");
			});
			jQuery("#btnCreateNewList").button().on("click", function () {
				dialogList.dialog("open");
			});
		});
	</script>
</body>
</html>