<?
$defaultTimeZone='UTC';
if(date_default_timezone_get()!=$defaultTimeZone){
	date_default_timezone_set($defaultTimeZone);
}

$where = "";
$admin_id_search 	= isset($_REQUEST['admin_id_search']) ? $_REQUEST['admin_id_search'] : "";
if(isset($admin_id_search) && $admin_id_search !=""){
	$where .= " AND admin_id = $admin_id_search ";
}
if(isset($_REQUEST['source'])){
	$source = $_REQUEST['source'];
	$where 	.= " AND source ='$source' ";
}

$current_month_array = array();
$current_month_appointment_array = array();
$current_month_appointment_html_array = array();
if(isset($_REQUEST['action']) && $_REQUEST['action'] == 'view_calendar'){	
	$year_month = $_REQUEST['year_month'];
	$year_year = $_REQUEST['year_year'];
}else{
	$year_month = date('m');
	$year_year = date('Y');
}
$date_string = "01-".$year_month."-".$year_year;
$first_day_of_current_month = $year_year."-".$year_month."-01";
$number_of_days_in_month = cal_days_in_month(CAL_GREGORIAN, $year_month, $year_year);
$last_day_of_current_month = $year_year."-".$year_month."-".$number_of_days_in_month;


for($i=1;$i<=$number_of_days_in_month;$i++){
	array_push($current_month_array,str_pad($i,2,0,STR_PAD_LEFT)."-".$year_month."-".$year_year);
}
?>
<link rel="stylesheet" href="../css/SimpleCalendar.css" />
<section class="content-header">
  <h1 style="float:left;margin-bottom:10px;">
	Reminders Management
  </h1>
  <div style="floar:right;float:right;">
	<a href="<?php echo $siteURL ?>/notes/index?page=view_reminder_for_admin&source=<?=$source;?>"><i class="fa fa-list"></i> <span>List View</span></a>
  </div>
</section>
<section class="content">
	<div class="row">
		<div class="col-xs-12">
			<div class="box">
				<div class="box-body">
					<form class="form-horizontal noprint"  id="view_calender_form" action="index?page=view_calendar_for_reminders&action=view_calendar" method="post">
						<div class="form-group">
						   <div class="col-sm-3" id="year_div">
						   <label for="Years" class="control-label">Years</label>
							<?
								$gsi->getYearList("year_year",$year_year,"100%",false);
							?>
						   </div>
						   <div class="col-sm-3" id="month_div">
						   <label for="Months" class="control-label">Months</label>
							<?
								$gsi->getYearMonth("year_month",$year_month,"100%",false);
							?>
						   </div>
						   <div class="col-sm-3" id="month_div">
						   <label for="Months" class="control-label">Consultant</label>
							<?
								Admin::getAdminList("admin_id_search",$admin_id_search,"100%",false,"form-control");
							?>
						   </div>
						   
						  <div class="col-sm-3">
							<br>
							<a href="" onClick="window.print();" id="print_button" class="btn btn-default" style="float:right !important;"><i class="fa fa-print"></i> Print</a>
							<input type="hidden" id="source" name="source" value="<?php echo $source;?>">
						  </div>
						</div>
					</form>
					<div>
					<?php
					//error_reporting(E_ALL ^ E_WARNING);
					require_once('../include/SimpleCalendar.php');

					$calendar = new SimpleCalendar();

					$calendar->setStartOfWeek('Monday');
					$calendar->setDate($date_string);
					
					$sql_for_reminder = "SELECT * FROM notes WHERE note_date BETWEEN '$first_day_of_current_month 00:00:00' and '$last_day_of_current_month 23:59:59' AND note_type = 1 $where ";
					$rs_for_reminder = mysqli_query($conn,$sql_for_reminder);
					$result_for_reminder = mysqli_num_rows($rs_for_reminder);
					if($result_for_reminder > 0){
						while($row_for_reminder = mysqli_fetch_assoc($rs_for_reminder)){
							$reminder_id = $row_for_reminder['id'];
							$job_id = $row_for_reminder['job_id'];
							$company_name = utility::getTableFieldById("job","company_name","id",$row_for_reminder['job_id']);
							$admin_id = $row_for_reminder['admin_id'];
							$admin = Admin::getAdminsById($admin_id);
							$job = $gsi->getEnqQuoteJobById($job_id);
							$reminder_date = utility::getFormatedDateReturn($row_for_reminder['note_date']);
							$reminder_time = $row_for_reminder['reminder_time'];
							$reminder_text = $row_for_reminder['note_text'];
							
							
							//$status_bar_color = "yellow";
							//$status_bar_value = "R";
							
							$table_shift_caleder = "<div id='table_".$row_for_reminder['id']."' style='display:none;'><table>";
							$table_shift_caleder .= "<tr><td>Job : </td><td>$job</td></tr>";
							$table_shift_caleder .= "<tr><td>Consultant : </td><td>$admin</td></tr>";
							$table_shift_caleder .= "<tr><td>Date : </td><td>$reminder_date</td></tr>";
							$table_shift_caleder .= "<tr><td>Time : </td><td>$reminder_time</td></tr>";
							$table_shift_caleder .= "<tr><td>Description : </td><td>$reminder_text</td></tr>";
							$table_shift_caleder .= "</table></div>";
							echo $table_shift_caleder;
							$time_for_span = $reminder_time;
							//$status_bar = "<span class='pull-right badge bg-$status_bar_color'>$status_bar_value</span>";
							
							
			
							$calendar->addDailyHtml( "<span id=".$row_for_reminder['id'].">".$gsi->getInitial8CharOfCompanyName($company_name)." <span style='font-size:10px;'>(".$time_for_span.")</span></span>$status_bar", $row_for_reminder["note_date"] , $row_for_reminder["note_date"], $holiday_in_time_format_array );
						}
					}
					$calendar->addDailyHtmlAdd( "<span style='font-size:20px;color:#3c8dbc;' title='Add'>+</span>", array(), $current_month_array );
					
					$calendar->show(true);
					?>
					</div>
				</div>
			</div>
		</div>
	</div>
	<div class='triangle' style='width:0; height:0; border-bottom:10px solid #3c8dbc; border-left:5px solid transparent; border-right:5px solid transparent;display: none;'></div>
	<div id='floating_div' style='display: none;'></div>
</section>


<style>
.badge{
	padding: 2px 3px;
}
.event{
	cursor:default;
}
.new_select{
    -webkit-border-radius: 0;
    border-radius: 0;
    background-color: white;
    font-family: inherit;
    border: 1px solid #cccccc;
    -webkit-box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.1);
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.1);
    color: rgba(0, 0, 0, 0.75);
    display: block;
    font-size: 0.875em;
    margin: 0 0 1em 0;
    padding: 0.5em;
    height: 2.3125em;
    width: 100%;
    -moz-box-sizing: border-box;
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
    -webkit-transition: -webkit-box-shadow 0.45s, border-color 0.45s ease-in-out;
    -moz-transition: -moz-box-shadow 0.45s, border-color 0.45s ease-in-out;
    transition: box-shadow 0.45s, border-color 0.45s ease-in-out;
}
@media print
{
	/*.noprint {display:none;}*/
	table.SimpleCalendar tbody td{
		height: 130px;
	}
	#year_div,#month_div{
		width:30%;
		float:left;
		clear:right;
	}
	#print_button{
		display:none;
	}
}
</style>
<script type="text/javascript">		
$(document).ready(function() {
	$(".add_appointment").click(function(){	
		$("#myModalLabel").text("Reminder Management");
		var hide_top_left = "&hide_top=1&hide_left=1";
		var app_date = $(this).attr("alt");		
		$(".modal_iframe").attr("src","<?=$config->frontEndURL?>/admin/notes/index?page=add_reminder_for_calender&source=<?=$source;?>&app_date="+app_date+hide_top_left);
	});
	$(".close_button").click(function(){
		$(".modal_iframe").attr("src","");
		location.reload();
	});
	
	$('.event').hover(
         function (event) {
		   var span_id = $(this).children("span").attr("id");   
		   content = $("#table_"+span_id).html();
		   //alert(content);
			position = $(this).parent().position();	
			position_of_event = $(this).position();	
			position_top = position.top + position_of_event.top;
			scrollHeight = 100;
			top_position = 145;
			top_position_for_triangle = 135;
			if ($(document).scrollTop() >= scrollHeight) {
				top_position = 100;
				top_position_for_triangle = 90;
			}
			floating_div_left = 160;
			floating_triangle_left = 260;
			if($(window).width() < 640){
				top_position = top_position;
				top_position_for_triangle = top_position_for_triangle;
				floating_div_left = 10;
				floating_triangle_left  = 20;
			}
			//alert(position.top);			
			$("#floating_div").css({"padding":"10px","background":"#FFF","border":"1px solid #3c8dbc","width":"auto","position":"absolute","z-index":"9999","top":position_top+top_position,"left":position.left+floating_div_left});
			$("#floating_div").html(content);
			$(".triangle").css({"position":"absolute","z-index":"9999","top":position_top+top_position_for_triangle,"left":position.left+floating_triangle_left });
			$(".triangle").show();
			$("#floating_div").show();
         }, 
         function () {
			$("#floating_div").css({"border":"0px solid #3c8dbc"});
			$("#floating_div").html("");
			$("#floating_div").hide();
			$(".triangle").hide();
         }
     );
	
	//$("#month_year").on("change",function() {
	$("#year_month,#year_year,#admin_id_search").on("change",function() {
		$("#view_calender_form").submit();
	});
});
</script>