<?php
$where 					= " WHERE 1=1 ";
$next_page_condition 	= "";
$paging ="";
if($_REQUEST['start']){
	$paging .="&start=".$_REQUEST['start'];
}
###########################################  STRAT FILTER CONITIONS    #####################################
if($job_search) {
    $where	.= " AND (id = '$job_search' OR first_name LIKE '%$job_search%' OR last_name LIKE '%$job_search%' OR email LIKE '%$job_search%' OR postcode LIKE '%$job_search%') ";
    $next_page_condition.="&job_search=$job_search";
}
//$admin_id_global_search 	= isset($_REQUEST['admin_id_global_search']) ? $_REQUEST['admin_id_global_search'] : "";
if($admin_id_global_search){
	$consultant_ids = "";
	$sql1 = "select job_id FROM job_admin_mapping where admin_id = '".$admin_id_global_search."' ";
	$rs1 =  mysqli_query($conn,$sql1);
	if(mysqli_num_rows($rs1) > 0){
		while($row1 = mysqli_fetch_assoc($rs1)){
			$consultant_ids .= $row1["job_id"].",";
		}
		$consultant_ids = substr($consultant_ids,0,-1);
	}
	$where 	.= " AND id IN($consultant_ids) ";
	$next_page_condition.="&admin_id_global_search=".$_REQUEST['admin_id_global_search'];
}
$archive_status_id = $config->archive_status_id;
$where	.= " AND prospect_status != '$archive_status_id' ";
###########################################  	END  FILTER CONITIONS 	#####################################
###########################################  PAGING WITH PER PAGE  #####################################
$file_name		= "index"; // this is file name which is used during paging  , included at the bottom of the page
$table_name		= "job";
$paging_table_name	= $table_name;
$paging_query		= $where;
$join_query_for_paging = "SELECT * FROM $table_name  $where ";
$page_header = "Search";
include("paging/paging_query.inc.php");
############################################ END PAGING WITH PER PAGE  #######################################
$query = "SELECT * FROM $table_name $where ORDER BY id DESC LIMIT $eu, $limit";
$sql=mysqli_query($conn,$query);
$result=mysqli_num_rows($sql);
########################################################################################
?>
 <section class="content-header">
  <h1>
	<?=$page_header;?>
  </h1>
</section>
<section class="content">
	<div class="row">
		<div class="col-xs-12">
			<div class="box">
				<!----------------------- Message ------------------------------->
				<? if(isset($_SESSION['info_message'])){ ?>
				  <div class="alert alert-info alert-dismissable">
					<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
					<? echo $_SESSION['info_message']; unset($_SESSION['info_message']);?>
				  </div>
				  <? } ?>
				<!----------------------- End Message ------------------------------->
				<div class="box-body">
				<!-- search form -->
				<?php //include_once('job_management_search_options.inc.php');?>
				<!-- /.search form -->
					<div class="col-xs-6">
						<div style="float:left;clear:right;font-weight:bold;">Status</div>
						<?
							foreach(gsi::$jobStatusColorArray as $key => $value){
								if($key=='e'){
									$jobStatus["Prospect"] = $value;
									
								}else if($key=='q'){
									$jobStatus["Quotation"] = $value;
									
								}else if($key=='j'){
									$jobStatus["Clients"] = $value;
									
								}
							}
							foreach($jobStatus as $k => $v){	
								if($k=='Prospect'){
									$altvalue = 1;
								}else if($k=='Quotation'){
									$altvalue = 2;
								}else if($k=='Clients'){									
									$altvalue = 3;
								}
								echo "<div class='activity_status_button' alt='$altvalue' style='cursor:pointer;background:$v;width:auto;height:auto;float:left;clear:right;margin-left:5px;padding: 3px 10px;color: #fff;border-radius: 3px;font-size: 13px;'>$k</div>";
							}
						?>
						<a href="index?page=view_jobs_by_search" style='cursor:pointer;background:#E91E63;width:auto;height:auto;float:left;clear:right;margin-left:5px;padding: 3px 10px;color: #fff;border-radius: 3px;font-size: 13px;'>View all</a>
					</div>
					<div style="clear:both;margin-bottom:10px;"></div>
					<form action="index?page=add_job" method="post" name="form1" id="form1">
					<!--<div class="box-footer">
					   <button type="submit" name="add" class="btn btn-primary">Add Job</button>
					</div>-->
					<? if($result>0){?>
					 <table id="example1" class="table table-bordered table-striped">
						<thead>
						  <tr>
							<!--<th>#</th>-->
							<th>Company Name / Contact Name</th>
							<th>Email</th>
							<th style="width:8%;">Date</th>
							<th>One To One</th>
							<th>Referrals</th>
							<th>Appointment</th>
							<th>Notes / Reminders</th>
							<th>Document</th>	
							<!--<th>Draft</th>	
							<th>Edit</th>
							<th>Delete</th>-->
						  </tr>
						</thead>
						<tbody>
							<?
								while($row =mysqli_fetch_array($sql)){
									$bg_color = "";
									$bg_color_key = "";
									$status = "";
									$bg_color = gsi::$jobStatusColorArray[$gsi->getEnqQuoteJobStatusById($row["id"])];
									
									if($bg_color == '#FFC0CB'){
										$status = 1;
									}elseif($bg_color == '#FFDC89'){
										$status = 2;
									}elseif($bg_color == '#71E096'){
										$status = 3;
									}
									
							?>
						  <tr class="activity<?=$status;?>" alt="<?=$status;?>" style="background-color:<?=$bg_color;?>;">
							<!--<td><a href="index?page=view_enquiry_progress&from=view_jobs_by_search&id=<?//=$row['id'];?>"><?php //echo $row['id']; ?></a></td>-->
							<td>
								<a href="index?page=view_enquiry_progress&from=view_jobs_by_search&id=<?=$row['id'];?>">
								<?php 
									if(isset($row['company_name']) && $row['company_name'] !=""){
										echo $row["company_name"]." / ";
									}
									if(isset($row['first_name']) && $row['first_name'] !=""){
										echo ucfirst($row['first_name'])." ".ucfirst($row['last_name']); 
									}									
								?>
								</a>
							</td>
							<td><?php echo $row['email']; ?></td>
							<td><?php echo utility::getFormatedDate($row['common_date']); ?></td>
							<td><a href="" data-toggle="modal" data-target="#myModal" class="one_to_one" alt="<?=$row['id'];?>" style="">One To One</a></td>
							<td><a href="" data-toggle="modal" data-target="#myModal" class="referrals" alt="<?=$row['id'];?>" style="">Referrals</a></td>
							<td><a href="" data-toggle="modal" data-target="#myModal" class="appointment" alt="<?=$row['id'];?>" style="">Appointment</a></td>
							<td>
								<a href="" data-toggle="modal" data-target="#myModal" class="notes" alt="<?=$row['id'];?>" style="">Notes</a> / <a href="" data-toggle="modal" data-target="#myModal" class="reminders" alt="<?=$row['id'];?>" style="">Reminders</a>
							</td>
							<td><a href="" data-toggle="modal" data-target="#myModal" class="document" alt="<?=$row['id'];?>" style="">Document</a></td>
							<!--<td><a href="" data-toggle="modal" data-target="#myModal" class="draft" alt="<?=$row['id'];?>" style="">Draft</a></td>
							<td><a href="index?page=add_job&action=edit&id=<?=$row['id'].$next_page_condition.$paging;?>"> <img src="../images/edit.gif" border="0" /> </a></td>
							<td><a href="index?page=view_job&action=delete&id=<?=$row['id'].$next_page_condition.$paging; ?>"
							onclick=" javascript:return confirm('Are you sure! You want to delete');"><img
							src="../images/del.gif" border="0" /> </a></td>-->
						  </tr>
							<? } ?>
							<!-- Paging starts here  -->
							<? 
								$next_page_condition .="&page=view_jobs_by_search";
								include("paging/paging_row.inc.php") ?>
							<!-- Paging ends starts here  -->
						</tbody>
					 </table>
					 <? }else{ ?>
						No client found...
					 <? } ?>
				</div>
				<!--<div class="box-footer">
                   <button type="submit" name="add" class="btn btn-primary">Add Job</button>
                </div>-->
				</form>
			</div>
		</div>
	</div>
</section>
<script type="text/javascript">
$(function () {

	$(".activity_status_button").click(function(){
		//alert('aaaaaaaaaaa');
		var activity = $(this).attr("alt");
		//alert(activity);
		if(activity == 1){
			$(".activity1").show();
			$(".activity2").hide();
			$(".activity3").hide();
		}else if(activity == 2){
			$(".activity2").show();
			$(".activity1").hide();
			$(".activity3").hide();
		}else if(activity == 3){
			$(".activity3").show();
			$(".activity1").hide();
			$(".activity2").hide();
		}
	});


	$(".mileage").click(function(){	
		$("#myModalLabel").text("Mileage Management");
		var hide_top_left = "&hide_top=1&hide_left=1";
		var job_id = $(this).attr("alt");		
		$(".modal_iframe").attr("src","<?=$config->frontEndURL?>/admin/mileage/index?page=view&source=j&job_id="+job_id+hide_top_left);
	});
	$(".notes").click(function(){	
		$("#myModalLabel").text("Notes");
		var hide_top_left = "&hide_top=1&hide_left=1";
		var job_id = $(this).attr("alt");		
		$(".modal_iframe").attr("src","<?=$config->frontEndURL?>/admin/notes/index?page=view&source=j&job_id="+job_id+hide_top_left);
	});
	$(".reminders").click(function(){	
		$("#myModalLabel").text("Reminders Management");
		var hide_top_left = "&hide_top=1&hide_left=1";
		var job_id = $(this).attr("alt");		
		$(".modal_iframe").attr("src","<?=$config->frontEndURL?>/admin/notes/index?page=view_reminder&source=j&job_id="+job_id+hide_top_left);
	});
	$(".appointment").click(function(){	
		$("#myModalLabel").text("Appointment Management");
		var hide_top_left = "&hide_top=1&hide_left=1";
		var job_id = $(this).attr("alt");		
		$(".modal_iframe").attr("src","<?=$config->frontEndURL?>/admin/appointment/index?page=view&source=j&job_id="+job_id+hide_top_left);
	});
	$(".document").click(function(){	
		$("#myModalLabel").text("Documents Management");
		var hide_top_left = "&hide_top=1&hide_left=1";
		var job_id = $(this).attr("alt");		
		$(".modal_iframe").attr("src","<?=$config->frontEndURL?>/admin/document_management/index?page=view&source=j&job_id="+job_id+hide_top_left);
	});
	$(".one_to_one").click(function(){	
		$("#myModalLabel").text("One To One Management");
		var hide_top_left = "&hide_top=1&hide_left=1";
		var job_id = $(this).attr("alt");		
		$(".modal_iframe").attr("src","<?=$config->frontEndURL?>/admin/one_to_one_management/index?page=view&source=e&job_id="+job_id+hide_top_left);
	});
	$(".referrals").click(function(){	
		$("#myModalLabel").text("Referrals Management");
		var hide_top_left = "&hide_top=1&hide_left=1";
		var job_id = $(this).attr("alt");		
		$(".modal_iframe").attr("src","<?=$config->frontEndURL?>/admin/referrals_management/index?page=view&source=e&job_id="+job_id+hide_top_left);
	});
	$(".draft").click(function(){	
		$("#myModalLabel").text("Draft Management");
		var hide_top_left = "&hide_top=1&hide_left=1";
		var job_id = $(this).attr("alt");		
		$(".modal_iframe").attr("src","<?=$config->frontEndURL?>/admin/draft_management/index?page=view&source=j&job_id="+job_id+hide_top_left);
	});
	$(".timesheet").click(function(){	
		$("#myModalLabel").text("Timesheet Management");
		var hide_top_left = "&hide_top=1&hide_left=1";
		var job_id = $(this).attr("alt");		
		$(".modal_iframe").attr("src","<?=$config->frontEndURL?>/admin/timesheet_management/index?page=view&source=j&job_id="+job_id+hide_top_left);
	});
	$(".close_button").click(function(){
		$(".modal_iframe").attr("src","");
	});
});
</script>