<!--akmal 20160809 -->
<script type="text/javascript">
// ----------------------------------Start delete butiran function-----------------------------------------------------------------
	function deleteId(id)
	{
	var textDel = document.getElementById("delete"+id+"").getAttribute("data-delete"+ id+"");

	if (confirm("Anda akan membuang butiran "+ textDel  +". Klik OK untuk teruskan.") == true)
	{
			$.ajax({
			method: 'POST',
			url: '<?php echo base_url().'setup/deletesubreview';?>',
			data: {
			a : id,
			b : 1,
	},
	success: function(result) {
		$('.table-container').load('<?php echo current_url().' #datatable_list'?>');
		}
		}); 
		}
	}
// ----------------------------------End delete butiran function-----------------------------------------------------------------

	
// ----------------------------------Start add butiran function-----------------------------------------------------------------
	function addId(reviewID)
	{
		var idAddModal = reviewID;
		//console.log(idAddModal);//debug data reviewID
		var butiran = $("#butiran").val();

		if(confirm("Anda akan menambah butiran "+butiran+". Klik ok untuk teruskan") == true)
		{
			$.ajax({
				method: 'POST',
				url: '<?php echo base_url().'setup/insertsubreview';?>',
				data: {
				b : idAddModal,
				c : butiran
				},
				success: function(result) {
					var bil = $('#rowTable1 tr').length + 1;
					//$('#rowTable1').load('<?php echo base_url().'setup/subreview/'.$this->uri->segment(3).' #rowTable1';?>');
					var obj = JSON.parse(result);
					$('#rowTable1').append('<tr><td class="text-center">'+bil+'</td>'+
																 '<td class="text-left" >'+obj.text+'</td>'+
																 '<td><center>'+
																 '<a data-id="'+obj.ID+'" data-idItem="'+obj.text+'"  title="edit" class="btn bg-blue btn-sm" data-toggle="modal" data-target="#editModal" onclick="editId(this)" data-toggle="tooltip" value="'+obj.ID+'"> <span class="glyphicon glyphicon-pencil"/></a> '+
																 '<a id="delete'+obj.ID+'" data-delete'+obj.ID+'="'+obj.text+' "title="delete" class="btn bg-red btn-sm" onclick="deleteId('+obj.ID+')" data-toggle="tooltip"> <span class="fa fa-times"/></a></center></td></tr>');										
					$('#addModal').modal('toggle');
					return;
				}
			});
		}
		
		return false;
	}
// ----------------------------------End add butiran function-----------------------------------------------------------------


// ----------------------------------Start edit butiran function-----------------------------------------------------------------
	function editId(a) 
	{
			var text = $(a).attr('data-idItem');
			var id = $(a).attr('data-id');
			$("#butiran2").val(text);
			$("#idButiran").val(id);
	
	}

	function editSubmit(reviewID)
	{
			var idAddModal = reviewID;
			//console.log(idAddModal);
			var butiran = $("#butiran2").val();
			var idTarget = $("#idButiran").val();

	if(confirm("Klik Ok jika anda bersetuju untuk mengubah butiran ini.")== true){
		$.ajax({
				method: 'POST',
				url: '<?php echo base_url("/setup/updateRow/");?>',
				data: {
				a : idTarget,
				b : reviewID,
				c : butiran
		},
		success: function(result) {
				$('.table-container').load('<?php echo current_url().' #datatable_list'?>');
				$('#editModal').modal('toggle');
			}
		});
	}else{
		//console.log('batal');
	}
	}
// ----------------------------------End edit butiran function-----------------------------------------------------------------

</script>

<?php
/**
* @author: Abu Aiman
* @created: 19/08/2016
* @updated: 22/08/2016 (Abu) - List refresh after insert/delete/update
						23/08/2016 (Zul) - Remove debug/log lines. Transfer to production
						24/08/2016 (Abu) - Dropdown - Group by category
*/
?>

<div class="modal fade" id="modal-details" role="dialog" data-backdrop="static" data-keyboard="false">
	<div class="modal-dialog modal-lg" style="width:1500px;">
		<div class="modal-content">
			<div class="modal-header bg-white text-center" >
				<button type="button" class="close" data-dismiss="modal">&times;</button>
				<h4 class="modal-title" id="modal-details-label"></h3>
			</div>
			<div class="modal-body">
				<ul class="nav nav-tabs">
					<li class="active" id="personaltab">
						<a href="#tab_1" data-toggle="tab" aria-expanded="true"><?php echo $this->lang->line('personal');?></a>
					</li>
					<li id="companytab">
						<a href="#tab_2" data-toggle="tab" aria-expanded="true"><?php echo $this->lang->line('company');?></a>
					</li>
				</ul>
				<div class="tab-content">
					<div id="tab_1" class="tab-pane active">
					</div>
				</div>
			</div>
			<div class="modal-footer">
				<a type="button" class="btn btn-danger btn-sm" data-dismiss="modal"><?php echo $this->lang->line('close');?></a>
				<a id="modalAddBtn" href="javascript:newCustomer();" type="button" class="btn bg-olive btn-sm"><span class="glyphicon glyphicon-plus"></span>
					<?php echo $this->lang->line('add');?>
				</a>
				<a id="modalEditBtn" href="" type="button" class="btn bg-olive btn-sm"><span class="glyphicon glyphicon-plus"></span>
					<?php echo $this->lang->line('update');?>
				</a>
			</div>
		</div>
	</div>
</div>

<div class="content-wrapper">
	<!-- Content Header (Page header) -->
	<section class="content-header">
		<h1>Semakan Kelayakan</h1>
		<?php 	if($semak[5]=='0') { //Replace 0 in parentID
													echo substr_replace($semak,'',5,1);
													}
													else echo $semak; ?>
		<ol class="breadcrumb">
			<li><a href="#"><i class="fa fa-dashboard"></i> Semakan Kelayakan</a></li>
			<li class="active"></li>
		</ol>
	</section>

	<!-- Main content -->
	<section class="content">


		<div class="box box-danger">
			<div class="box-header with-border">
				<h3 class="box-title">Senarai Semak</h3>
				<?php if(current_url() != base_url('/setup/subreview/')) : ?>
					<button type="button" class="btn btn-sm bg-blue pull-right" data-toggle="modal" data-target="#addModal" style="margin-right:30px;"><i class="fa fa-plus"></i>&nbsp;Tambah</button>
				<?php endif; ?>
				<div class="box-tools pull-right">
					<button class="btn pull-right btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
				</div>
			</div>	

			<div class="box-body">
				<div class="row">
					<div class="col-md-12">
						<div class="row">
							<div class="col-sm-12">
<!--------------------------------------Start Dropdown Senarai Semak Menu---------------------------------------------------------------------->
							<div class="dropdown col-sm-12" style="width:100%;">
									<button class="btn btn-default dropdown-toggle col-sm-12" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true" style="overflow:auto;">
										<?php  
											if($semak[5]=='0') { //Replace 0 in parentID
													echo substr_replace($semak,'',5,1);
													}
													else echo $semak;?>
										<span class="caret"/>
									</button>
									<ul class="dropdown-menu" aria-labelledby="dropdownMenu1" style="white-space:normal;height:350px;overflow: auto;">
										<?php
										echo '<li class="dropdown-header" style="background-color: #d9d9d9;"><b>Syarat Kelayakan</b></li>';
												function repZero($pID){//Remove init '0' in parentID
															if(($pID)== '0')
																return substr_replace($pID,'',0); 
																else 
																return $pID;
														}
									if ($rsSemak) foreach ($rsSemak as $rows){
										if ($rows->methodID == 1)
										echo '<li style="overflow:hidden;"><a href="'.base_url('/setup/subreview/').'/'.$rows->ID.'">'.'Item '.repZero($rows->parentID).$rows->code.' : '.$rows->text.'</a></li>';
									}
										echo '<li class="dropdown-header" style="background-color: #d9d9d9;"><b>Keupayaan Operasi</b></li>';
									if ($rsSemak) foreach ($rsSemak as $rows){
										if ($rows->methodID == 2)
										echo '<li style="overflow:hidden;"><a href="'.base_url('/setup/subreview/').'/'.$rows->ID.'">'.'Item '.repZero($rows->parentID).$rows->code.' : '.$rows->text.'</a></li>';
									}
									echo '<li class="dropdown-header" style="background-color: #d9d9d9;"><b>Keupayaan Kewangan</b></li>';
									if ($rsSemak) foreach ($rsSemak as $rows){
										if ($rows->methodID == 3)
										echo '<li style="overflow:hidden;"><a href="'.base_url('/setup/subreview/').'/'.$rows->ID.'">'.'Item '.repZero($rows->parentID).$rows->code.' : '.$rows->text.'</a></li>';
									}
										?>
									</ul>
								</div>
<!--------------------------------------End Dropdown Senarai Semak Menu---------------------------------------------------------------------->
							</div>
						</div>
						<br>
						<form class="form-horizontal">
							<input type="hidden" name="ID" id="companyID" value="1" /> <!-- TODO : PUT ACTUAL COMPANY ID HERE -->
							<div class="table-container">
							<table id="datatable_list" class="table table-bordered table-striped datatables">
								<thead>
									<tr>
										<th class="text-center col-sm-1">Bil</th>
										<th class="text-center col-sm-6">Butiran</th>
										<th class="text-center col-sm-1">Tindakan</th>
									</tr>
								</thead>
<!-----------------------------------------Start table senarai semak-------------------------------------------------------------------->		
									<tbody id="rowTable1">
									<?php
									$bil = 1;
									if($rs) foreach ($rs as $row) {
											$id = $row->reviewID;
											$idItem = $row->ID;
									
										echo '<tr><td class="text-center">'.$bil.'</td>';
										echo '<td class="text-left" >'.$row->text.'</td>';
										echo '<td><center>
										<a data-id="'.$idItem.'" data-idItem="'.$row->text.'"  title="edit" class="btn bg-blue btn-sm" data-toggle="modal" data-target="#editModal" onclick="editId(this)" data-toggle="tooltip" value="'.$idItem.'"> <span class="fa fa-edit"/></a>
										<a id="delete'.$idItem.'" data-delete'.$idItem.'="'.$row->text.' "title="delete" class="btn bg-red btn-sm" onclick="deleteId('.$idItem.')" data-toggle="tooltip"> <span class="fa fa-trash"></span></a></td></tr>';
										$bil ++;
										}
										echo '';
									?>
									</tbody>
<!----------------------------------------------End table senarai semak-------------------------------------------------------------------->		

							</table>
							</div>
						</form>
					</div><!-- /.col -->
				</div><!-- /.row -->
			</div><!-- /.box-body -->

<!-- -------------------Start Tambah Semakan Kelayakan Modal ------------------------------->

<div id="addModal" class="modal fade" role = "dialog" style="width:100%;">
	<div class="modal-dialog" style="width: 1200px;overflow:auto;">
		<!--modal content-->
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal">&times </button>
				<center><h4 class=modal-title>Tambah Semakan Kelayakan</h4></center>
			</div>

						
			<div class="modal-body">
				<!--form-->
				<div class="form-group" value="<?php $id ?>">
					<label for="number">Semakan Untuk:</label><br>
					<input type="text"  class="form-control" value="<?php echo $semak;?>"  readonly />
				</div>
				<div class="form-group">
					<label for="text">Butiran:</label>
					<input type="text" class="form-control" id="butiran"/>
				</div>
			</div>

			<div class="modal-footer">
				<button type="button" class="btn btn-danger btn-sm pull-center" data-dismiss="modal"><i class="fa fa-times"></i>&nbsp;Batal</button>
				<button type="button" class="btn bg-olive btn-sm pull-center" onclick="addId(<?php echo $this->uri->segment(3);?>)"><i class="fa fa-check"></i>&nbsp;Simpan</button>

			</div>
		</div>
	</div>
</div>
			
			
<!-- -------------------End Tambah Semakan Kelayakan Modal ------------------------------->

<!-- ---------------------Start Edit Semakan Kelayakan Modal ------------------------------->
								<div id="editModal" class="modal fade" role = "dialog" style="width:100%">
									<div class="modal-dialog" style="width: 1200px;overflow:auto;">
										<!--modal content-->
										<div class="modal-content">
											<div class="modal-header">
												<button type="button" class="close" data-dismiss="modal">&times </button>
											</div>

											<center><h4 class=modal-title>Ubahsuai Butiran Kelayakan</h4></center>
											<form name="formButiran">
												<div class="modal-body">
													<!--form-->
													<!--debug-->
													
													<input type="hidden" id="idButiran" value=""/><!--debug-->
													<div class="form-group">
														<label for="number">Semakan Untuk:</label><br>
															<input type="text"  class="form-control" value="<?php echo $semak;?>"  readonly />
																</div>
																<div class="form-group">
																	<label for="text">Butiran:</label>
																	<input type="text" class="form-control" id="butiran2" value=""/>
																</div>
															</form>
															<!--form-->

															<div class="modal-footer">
																<button type="button" class="btn btn-danger btn-sm pull-center" data-dismiss="modal"><i class="fa fa-times"></i>&nbsp;Batal</button>
																<button type="button" class="btn bg-olive btn-sm pull-center" onclick="editSubmit(<?php echo $this->uri->segment(3);?>)"><i class="fa fa-check"></i>&nbsp;Simpan</button>
																</div>
															</div></div></div></div>
<!-- ----------------------------End Edit Semakan Kelayakan Modal ----------------------------------------------------->

											</div><!-- /.box box-danger-->


											<!-- auditors comment -->
											<!-- TODO : PUT THE ACTUAL COMPANY DETAILS HERE -->

											<!-- reports template -->
											<!-- TODO : PUT THE ACTUAL COMPANY DETAILS HERE -->
											</section>
										</div>
										<!-- MODAL SECTION -->
										<!-- GENERAL MODAL -->
										<div class="modal fade" id="modal-details" role="dialog">
											<div class="modal-dialog modal-lg">
												<div class="modal-content">
													<form id="selectCompForm" action="<?php echo base_url(); ?>miti/home/selectCompany" method="POST" role="form">
															<div class="modal-header" >
																<button type="button" class="close" data-dismiss="modal">&times;</button>
																<h3 class="modal-title" id="modal-details-label"></h3>
															</div>			
															<div class="modal-body">				
																<div class="form-group">
																	<h1><?php echo $this->lang->line('choosePrompt'); ?></h1>
																	<textarea id="attachmentDescription" name="description" class="form-control" cols="100" rows="3" style="resize:none;"></textarea>
																</div>
															</div>

															<div class="modal-footer">
																<a type="button" class="btn btn-danger btn-sm" data-dismiss="modal"><i class="fa fa-times"></i>&nbsp;Batal</a>
																<a type="button" class="btn bg-green btn-sm">
																	<span class="fa fa-check"></span>
																	<?php echo $this->lang->line('Save');?>
																</a>
															</div>
														</form>
													</div>
												</div>
											</div>