<?php session_start();
		if (isset($_SESSION['logged']) && $_SESSION['logged'] == 'yes') {
			include ('../../../scripts/classes.php'); if ($_SESSION['lang']=="EN"){include ('../../../lang/en.php');}elseif ($_SESSION['lang']=="GR"){include ('../../../lang/gr.php');}else {include ('../../../lang/en.php');}
			
			$mode = $lbl_celebrations_list;
			$page_title = $lbl_celebrations_list ; //Assign Page Title
			
			$array = getGlobalSettings(); foreach ($array as $settings){extract($settings);}
			$mods = getCLSModules('CELEBRATIONS'); foreach ($mods as $modules){extract($modules);} if ($mod_name == true) $_CELEBRATIONS = 1; //echo $_CELEBRATIONS;
			
			if ($_SERVER['REQUEST_METHOD'] != 'GET' || $_CELEBRATIONS!=1 ) exit;
			$action = $_GET['namedays'];	
			//get date
			$today=date("Y-m-d"); 	
			$day = isset($_GET['selected_day']) ? mysqli_real_escape_string($mysqli, $_GET['selected_day']) : @date("d");
			$month = isset($_GET['selected_month']) ? mysqli_real_escape_string($mysqli,$_GET['selected_month']) : @date("m");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php echo $page_title ?></title>
<link rel="shortcut icon" href="../../../img/favicon.png" />
<link href="../../../cms1.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" href="../../../scripts/jkit/css/jkit.css" />
</head>
<body>
<script>top.document.title=self.document.title;</script>
		<div>
		<fieldset style="min-height:200px">
		<legend><?php echo  $mode ?></legend>
		<br />
		<div style="padding:5px;">
		<form name="frmDM" action="<?php $_SERVER["PHP_SELF"] ?>" method="get">
		<label><?php echo $lbl_day ?></label>
			<select name="selected_day" id="selected_day" class="addform_drop_1">
			<?php for ($i = 1; $i <= 31; ++$i) {echo "<option ".(($_GET['selected_day'] == $i) ? "selected" : "")." value='".$i."'>".$i."</option>";} ?>
			</select>
		<label><?php echo $lbl_month ?></label>
			<select name="selected_month" id="selected_month" class="addform_drop_1">
			<?php for ($i = 1; $i <= 12; ++$i) {echo "<option ".(($_GET['selected_month'] == $i) ? "selected" : "")." value='".$i."'>".$i."</option>";} ?>>
			</select>
		<input type="submit" name="btnSubmit" value="<?php echo $lbl_view; ?>" class="button"/>		
		</form>		
		</div>
	<?php
	//Customers list
			$sql_names_today ="SELECT `name` AS celebs FROM namedays WHERE `day`='$day' AND `month`= '$month'";		
			$result_names_today = mysqli_query($mysqli, $sql_names_today) or die("Query failed : " . mysqli_error($mysqli));
				if (mysqli_num_rows($result_names_today) == 0){
				echo "<div class='warning'><ul><li>";
				echo "$lbl_no_celebrations_day</li></ul></div>";
				}else{
					$celebs = array();
						while ($line=mysqli_fetch_array($result_names_today)) {	
							$celebs[] = $line[0]; 
						}	
						$trim_celeb = implode(" ", $celebs);
						//print_r(implode(",", $celebs));		 
						$words = EXPLODE(" ", $trim_celeb);
							echo "<div class='completed'><ul><li>";
							echo "$lbl_namedays_that_day</li></ul></div>";
							echo "<div style='padding:10px; border: 1px solid; margin:1px;border-color:#999999;color:#666666'>";
							print_r(implode(", ", $words));
							echo"</div>";
						
						//~~~~~~~~~~~~~~create warning about duals namedays
						$sql_dual_today ="SELECT `name` AS celeb FROM namedays WHERE `day`='$day' AND `month`= '$month' AND is_dual='1'";		
						$result_dual_today=mysqli_query($mysqli, $sql_dual_today) or die("Query failed : " . mysqli_error($mysqli));
							if (mysqli_num_rows($result_dual_today) == 0){
							//exit();
							}else{
							echo "<div class='warning'><ul><li>";
							echo "$lbl_names_is_dual</li><br />";
									while ($line=mysqli_fetch_assoc($result_dual_today)) {	 
										$celeb = $line['celeb'];
										echo "$celeb ";;
									}						
							echo "</ul></div>";
							}
						//~~~~~~~~~~~~~~end	
				 
				 		//~~~~~~~~~~~~~~create warning about transfer namedays 
						$sql_transfer_today ="SELECT `name` AS celeb FROM namedays WHERE `day`='$day' AND `month`= '$month' AND is_transfer='1'";		
						$result_transfer_today = mysqli_query($mysqli, $sql_transfer_today) or die("Query failed : " . mysqli_error($mysqli));
							if (mysqli_num_rows($result_transfer_today) == 0){
							//exit();
							}else{
							echo "<div class='warning'><ul><li>";
							echo "$lbl_names_is_tranfer ".@date('Y')."</li><br />";
									while ($line = mysqli_fetch_assoc($result_transfer_today)) {	 
										$celeb = $line['celeb'];
										echo "$celeb ";;
									}						
							echo "</ul></div>";
							}
						//~~~~~~~~~~~~~~end	
						
						FOR($i=0;$i<count($words);$i++)
						{$query_string .= "LIKE '%".$words[$i]."%' OR first_name ";}//{$query_string .= "LIKE '%".$words[$i]."%' OR first_name ";}		 
						$query_string = SUBSTR($query_string,0,STRLEN($query_string)-14);
						//echo $query_string;
						
						//~~~~~~~~~~~~~~~pagination
						define('MAX_REC_PER_PAGE', 20); 
						$pagin = mysqli_query($mysqli, "SELECT COUNT(id) FROM cls_customers WHERE first_name ".$query_string."") or die("Count query error!"); 
						list($total) = mysqli_fetch_row($pagin);
						$total_pages = ceil($total / MAX_REC_PER_PAGE);
						$page = intval(@$_GET["page"]);     
							if (0 == $page){
							  $page = 1;
							}    
						$start = MAX_REC_PER_PAGE * ($page - 1);
						$max = MAX_REC_PER_PAGE;
						//~~~~~~~~~~~~~~~~end of pagination
						
						$sql_fest = "SELECT *  FROM cls_customers WHERE first_name ".$query_string." 
									ORDER BY turnover DESC, last_transaction_date DESC
									LIMIT $start, $max";			 
					
						$result_fest = mysqli_query($mysqli, $sql_fest);
							if (mysqli_num_rows($result_fest) == 0){
							echo "<div class='critical'><ul><li>";
							echo "$lbl_no_customers_name</li></ul></div>";
							exit();
							}else{
						echo "<div style='padding-top:20px';><table align='left' cellpadding='1' cellspacing='1' border='0' class='default_dg_table' width='100%'>
						<tr>
							<td class='manual_table_td'>$lbl_grid_barcode</td>
							<td class='manual_table_td'>$lbl_grid_name</td>
							<td class='manual_table_td'>$lbl_grid_phone</td>
							<td class='manual_table_td'>$lbl_grid_phone (2)</td>
							<td class='manual_table_td'>$lbl_grid_turnover</td>
							<td class='manual_table_td'>$lbl_credits</td>
							<td class='manual_table_td'>$lbl_last_transaction_date</td>
							<td class='manual_table_td'>$lbl_grid_active_male</td>
						<tr>";	
								while ($row = mysqli_fetch_assoc($result_fest)) {	
								$customer_name = $row['last_name']." ".$row['first_name'];
							echo "<tr>
								<td class='manual_table_td_d'>".$row['barcode_id']."</td>
								<td class='manual_table_td_d'><a href='../../customers.php?cus_mode=details&cus_rid=".$row['id']."' data-jkit=\"[lightbox]\" title=\"".$customer_name."\">".$customer_name."</a></td>
								<td class='manual_table_td_d'>".$row['phone']."</td>
								<td class='manual_table_td_d'>".$row['phone2']."</td>
								<td class='manual_table_td_d'>&euro;".$row['turnover']."</td>
								<td class='manual_table_td_d'>".$row['credits']."</td>	
								<td class='manual_table_td_d'>".$row['last_transaction_date']."</td>";
								if ($row['is_active']==1){echo "<td class='manual_table_td_d'>".$lbl_yes."</td>";}else{echo "<td class='manual_table_td_d'><font color='red'>".$lbl_no."</font></td>";}
							echo "</tr>";
								}
						}	
					?>
					</table>
					<div style="float:left; width:95%;" align="center">		
					<table>
						<tr>		
							<td><?php echo $lbl_page ?></td>
							<?php
								for ($i = 1; $i <= $total_pages; $i++) {
								$txt = $i;
								if ($page != $i)
								$txt = "<a href=\"celebrations_list.php?selected_day=$day&selected_month=$month&page=$i\"><span class=\"goto\">$txt</span></a>";
							?>      
							<td>| <strong><?php echo $txt ?></strong></td>
					<?php
					}
					echo "</tr></table>";
			}
		?>
		</tr></table>
		</div>
		</fieldset>	
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
	<script src="../../../scripts/jkit/jquery.easing.1.3.js"></script>
	<script src="../../../scripts/jkit/jquery.jkit.1.2.16.min.js"></script>
	<script type="text/javascript">
	$(document).ready(function(){
		$('body').jKit({ 
			'plugins': {
			},
			'replacements': {
				'encode': specialEncodeCommand
			}
		});
	});
	function specialEncodeCommand(that, type, options){
		var s = this.settings;
		var $that = $(that);
		this.executeCommand(that, type, options);
		if (options.format == 'uppercase'){
			$that.html($that.html().toUpperCase());
		}
	}
	</script>		
</body>
</html>
<?php 
} else {
    header('Location: login.php');
}
?>

