<?php
/*
  osCommRes, Services Online
  http://www.oscommres.com

  Copyright (c) 2005 osCommRes

  Released under the GNU General Public License
  
  Freeway eCommerce from ZacWare
http://www.zac-ware.com/freeway

Copyright 2007 ZacWare Pty. Ltd
*/
// Set flag that this is a parent file
	define( '_FEXEC', 1 );
	require('includes/application_top.php');
    require('includes/classes/split_page_results_event.php');
	tep_get_last_access_file();
	require(DIR_WS_CLASSES . 'currencies.php');
	$currencies=new currencies();
	$dis_time_format="";
	
	if(defined('TIME_FORMAT')) $dis_time_format=TIME_FORMAT;
	$action = (isset($HTTP_GET_VARS['action']) ? $HTTP_GET_VARS['action'] : '');
	$cnt = (isset($HTTP_GET_VARS['cnt']) ? $HTTP_GET_VARS['cnt'] : '');		
	$content=""; 
	//ajax start	
	
  	if($action=='customers_page_navigation'){
		global $page;
		$page=isset($HTTP_GET_VARS['customers_page'])?(int)$HTTP_GET_VARS['customers_page']:'';
		echo 'customers_page_navigation^^';
		echo customers_page();
		exit;
	}
	if($action=='get_customer_details'){
		$customers_id=(int)$HTTP_GET_VARS['customer_id'];
		if($customers_id>0){
			$customer_query=tep_db_query("select c.customers_id,c.customers_firstname,c.customers_lastname,c.customers_email_address from " . TABLE_CUSTOMERS . " c left join " . TABLE_ADDRESS_BOOK . " a on c.customers_id = a.customers_id and c.customers_default_address_id = a.address_book_id where c.customers_id='".(int)$customers_id."'");	
			if(tep_db_num_rows($customer_query)>0){
				$customer=tep_db_fetch_array($customer_query);
				$firstname=$customer['customers_firstname'];
				$lastname=$customer['customers_lastname'];
				
				$customers_info_query=tep_db_query('select ci.customers_info_date_account_created as account_created,ci.customers_info_date_of_last_logon as last_logon,ci.customers_info_number_of_logons as numberof_logons,ci.customers_info_date_account_last_modified as last_modified from '.TABLE_CUSTOMERS_INFO." ci where ci.customers_info_id='" . $customer['customers_id'] . "'");
				$customers_info_array=tep_db_fetch_array($customers_info_query);
				
              // 	if($customers_info_array['last_modified']=='') $customers_info_array['last_modified']=$customers_info_array['account_created'];
					if($customers_info_array['last_modified']!='') { 
					
					$split=split(" ",$customers_info_array['last_modified']); 
					if($split[0]!='0000-00-00') { 
						$last_modified=date('h:i A',strtotime($split[1]));  
						if($dis_time_format!="") {
							if($dis_time_format=='24')
								$last_modified=date('H:i:s',strtotime($split[1]));
						}
						$customers_info_array['last_modified']=format_date($split[0]).' '.$last_modified;
					}
               }
				if($customers_info_array['account_created']!='') { 
					
					$split=split(" ",$customers_info_array['account_created']); 
					$last_modified=date('h:i A',strtotime($split[1]));  
					if($dis_time_format!="") {
						if($dis_time_format=='24')
							$last_modified=date('H:i:s',strtotime($split[1]));
					}
					$customers_info_array['account_created']=format_date($split[0]).' '.$last_modified;
               }
				$oID=0;
				$id_card_query=tep_db_query("select  distinct o.orders_id,op.products_type from ".TABLE_ORDERS." o,".TABLE_ORDERS_PRODUCTS." op,".TABLE_ORDERS_TOTAL." ot where o.orders_id=op.orders_id and op.products_type in('P','E','V','S') and ot.orders_id=o.orders_id and ot.orders_id=op.orders_id and o.customers_id='".(int)$customer['customers_id']."' and ot.class='ot_total' order by o.orders_id DESC limit 0,5");
					while($id_card_array=tep_db_fetch_array($id_card_query))
						if($id_card_array['products_type']=='E')
							$oID=$id_card_array['orders_id'];

				if($customer['last_modified']!='') {
					
					$content="<CD>".$customer['customers_id']."^".$customer['customers_email_address']."^".$customers_info_array['account_created']."^".$customers_info_array['last_modified']."^".format_date($customers_info_array['last_logon'])."^".$customers_info_array['numberof_logons']."^".$currencies->format(tep_get_wallet_balance($customer['customers_id']))."^".$firstname."^".$lastname."^".(int)$oID;	
				}	
				else {
					$content="<CD>".$customer['customers_id']."^".$customer['customers_email_address']."^".$customers_info_array['account_created']."^".$customers_info_array['last_modified']."^".format_date($customers_info_array['last_logon'])."^".$customers_info_array['numberof_logons']."^".$currencies->format(tep_get_wallet_balance($customer['customers_id']))."^".$firstname."^".$lastname."^".(int)$oID;	
				}	
				//if($cnt>0)
					$content.="^" . $cnt . "^" . load_customers_details($customers_id);
				$content.="</CD>"	;
			$order_query=tep_db_query("select  distinct o.orders_id,o.date_purchased,o.payment_method,op.products_type,op.products_name,op.final_price,op.products_tax,op.products_quantity,ot.class,ot.text from ".TABLE_ORDERS." o,".TABLE_ORDERS_PRODUCTS." op,".TABLE_ORDERS_TOTAL." ot where o.orders_id=op.orders_id and op.products_type in('P','E','V','S') and ot.orders_id=o.orders_id and ot.orders_id=op.orders_id and o.customers_id='".(int)$customer['customers_id']."' and ot.class='ot_total' order by o.orders_id DESC limit 0,5");
	
				if(tep_db_num_rows($order_query)>0){
				  $content.="<OD>";
				    $i=0;
					while($order=tep_db_fetch_array($order_query)){	
							
					//$date_purchased=date('h:i A',strtotime($order['date_purchased']));																	
					   $content.=(($i>0)?'^':'').$order['orders_id']."^".$order['products_name']."^".$order['final_price']."^".format_date($order['date_purchased']);
					   $i++;
			   	    }																				
			   	  $content.="</OD>";														 
				}
			} 	
		}	       
	    echo $content; 
		exit;
	}  
 //ajax end 	  
?>
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html <?php echo HTML_PARAMS; ?>>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>">
<title><?php echo TITLE; ?></title>
<link rel="stylesheet" type="text/css" href="includes/stylesheet.css">
<script language="javascript" src="includes/menu.js"></script>
<script language="javascript" src="includes/general.js"></script>
<script language="JavaScript" src="includes/date-picker.js"></script>
<script language="javascript" src="includes/http.js"></script>
<script language="javascript">
var img_src="<?php echo HTTP_SERVER.DIR_WS_ADMIN.'images/';?>";
/*	function get_customer_details(cnt,id,total_cus){		
		var row_cnt=document.getElementById("tab_row["+cnt+"]");
		var len = total_cus;
	
		if(row_cnt && row_cnt.className=='customerdataTableRowSelected'){
			document.frm_customer.action='<?php echo tep_href_link(FILENAME_CUSTOMERS,'mPath=1');?>&cID='+id+'&page_no='+(cnt+1)+'&action=edit&return=ct';
			document.frm_customer.submit();	
		}else {		
		  if(document.getElementById("tab_row[1]")){ 
		   	for(i=0;i<len;i++){			
			 var row=document.getElementById("tab_row["+i+"]");	
			 row.className='dataTableRow';	
			 if(i==cnt){ row.className='customerdataTableRowSelected';
			 }
		    }
		  }else {
		  	 var row=document.getElementById("tab_row[0]");			 						
		 	 row.className='customerdataTableRowSelected';
		  }		
		  command="<?php echo tep_href_link(FILENAME_CUSTOMERS_MAINPAGE,'action=get_customer_details');?>&customer_id="+id;	
		  		
		  do_get_command(command);
		  if(document.getElementById("loadings")) document.getElementById("loadings").innerHTML="<img alt='Loading...' title='Loading...' src='images/24-1.gif'>";
		  /*if(document.getElementById("customer_details")) document.getElementById("customer_details").innerHTML="";
		  if(document.getElementById("customer_options")) document.getElementById("customer_options").innerHTML="";
		  if(document.getElementById("orders_details")) document.getElementById("orders_details").innerHTML="";
		  if(document.getElementById("wallet_details")) document.getElementById("wallet_details").innerHTML="";*/
	/*	}			
	}*/
	var prev_row_cnt='-1';
	function get_customer_details(cnt,id,total_cus){		
		var len = total_cus;
		var row=document.getElementById("tab_row["+cnt+"]");	
		var ajx_row=document.getElementById("tab_row_ajx["+cnt+"]");	
	
	 	if(row.style.display==''){
			if(prev_row_cnt>=0) {
				document.getElementById("tab_row["+prev_row_cnt+"]").style.display='';
				document.getElementById("tab_row_ajx["+prev_row_cnt+"]").style.display='none';
			}
				
			row.style.display='none';
			ajx_row.style.display='';
			//if(cnt>0)
			ajx_row.innerHTML="<img alt='Loading...' title='Loading...' src='images/24-1.gif'>";
			prev_row_cnt=cnt;
		}
	 
		
		  command="<?php echo tep_href_link(FILENAME_CUSTOMERS_MAINPAGE,'action=get_customer_details');?>&customer_id="+id + "&cnt="+cnt;	
		  		
		  do_get_command(command);
		  if(document.getElementById("loadings")) document.getElementById("loadings").innerHTML="<img alt='Loading...' title='Loading...' src='images/24-1.gif'>";
		  /*if(document.getElementById("customer_details")) document.getElementById("customer_details").innerHTML="";
		  if(document.getElementById("customer_options")) document.getElementById("customer_options").innerHTML="";
		  if(document.getElementById("orders_details")) document.getElementById("orders_details").innerHTML="";
		  if(document.getElementById("wallet_details")) document.getElementById("wallet_details").innerHTML="";*/
		}			
	//}
	
	function edit_customer(id) { 
		var obj=document.getElementById("page_1");
			var cpage_no=1;
		if(obj)
			cpage_no=parseInt(obj.options[obj.selectedIndex].value);
		document.frm_customer.action='<?php echo tep_href_link(FILENAME_CUSTOMERS,'mPath=1');?>&cID='+id+'&action=edit&return=cm&page=' + cpage_no;
		document.frm_customer.submit();	
	}
	function do_result(result){	   
	//alert (result);
	var token=result.split('^^');
	switch(token[0]){
		case 'customers_page_navigation':
			prev_row_cnt='-1';
			document.getElementById('ajax_customers_details').innerHTML=token[1];
			return;
			break;
	}
	   var table_gen="<?php echo "<table border='0' cellspacing='3' cellpadding='1' width='100%' class='info_content'>"; ?>";
	   var customer_details="";	   
	   var customer_actions="";	   
	   var orders_details="";
	   var wallet_details=orders_details;	   
	   if(result.indexOf('<CD>')==0 && result.indexOf('</CD>')>0){
	    raw_result=result.substr(4,result.indexOf('</CD>')-4);
	    raw_result_split=raw_result.split("^");
	    var content_class="info_content_td";	    	    
	    if(raw_result_split[0]){	    	    	
	    	customer_details=table_gen;
	    		customers_id=raw_result_split[0];
				if(raw_result_split[7]) customer_details+="<tr><td align='left'><?php echo TEXT_CUSTOMER_NAME.'<br>';?>"+raw_result_split[7] + '&nbsp;' + raw_result_split[8]+"</td></tr>";
	    		if(raw_result_split[2]) customer_details+="<tr><td align='left'><?php echo TEXT_DATE_ACCOUNT_CREATED.'<br>';?>"+raw_result_split[2]+"</td></tr>";
	    		if(raw_result_split[3]) customer_details+="<tr><td align='left'><?php echo TEXT_DATE_ACCOUNT_LAST_MODIFIED.'<br>';?>"+raw_result_split[3]+"</td></tr>";
	    		if(raw_result_split[4]) customer_details+="<tr><td align='left'><?php echo TEXT_INFO_DATE_LAST_LOGON.'<br>';?>"+raw_result_split[4]+"</td></tr>";
	    		if(raw_result_split[5]) customer_details+="<tr><td align='left'><?php echo TEXT_INFO_NUMBER_OF_LOGONS.'<br>';?>"+raw_result_split[5]+"</td></tr>";				 
				 //wallet				  		    							    			    		    		   
	    	  	  customer_details+="<tr><td align='left'><?php echo TEXT_WALLET_BALANCE;?><br>"+raw_result_split[6]+"</td></tr>";
				  customer_details+="<tr><td align='left'><a href=<?php echo tep_href_link(FILENAME_CUSTOMERS,'mPath=1&action=edit');?>&cID="+raw_result_split[0]+"><?php echo TEXT_EDIT_CUSTOMER;?>"+"</td></tr>";		    	  	  	    	  	  
	    	  	//wallet	    		    		    	    	
	    		 customer_id=raw_result_split[0];
	    		 customer_actions+="<tr><td align='left'><a href='<?php echo tep_href_link(FILENAME_CREATE_ACCOUNT);?>'>"+"<?php echo TEXT_CREATE_CUSTOMER;?></a></td></tr>";	    		 	    		 	    		 	    		 
	    		 customer_actions+="<tr><td align='left'><a href=<?php echo tep_href_link(FILENAME_MAIL,'selected_box=tools');?>&customer="+raw_result_split[1]+">"+"<?php echo TEXT_EMAIL;?>"+"</td></tr>";	
				     		 
	    		 customer_actions+="<tr><td align='left'><a target='_blank' href=<?php echo tep_href_link(FILENAME_EVENTS_ID_CARD);?>?cID="+raw_result_split[9]+"><?php echo TEXT_ID_CARDS;?>"+"</td></tr>";
	    		 customer_actions+="<tr><td align='left'><a href=<?php echo tep_href_link(FILENAME_WALLET_PAYMENT,'mPath=1');?>&cID="+raw_result_split[0]+"><?php echo TEXT_UPLOAD_FUNDS;?>"+"</td></tr>";
				
				 if(raw_result_split[10]) { 
					var row=document.getElementById("tab_row["+raw_result_split[10]+"]");	
					var ajx_row=document.getElementById("tab_row_ajx["+raw_result_split[10]+"]");	
					row.style.display="none";
					ajx_row.style.display="";
					ajx_row.innerHTML= raw_result_split[11];
				 } 
	    	if(raw_result_split[1]) document.frm_customer.customers_email_address.value=raw_result_split[1];	    		    		    		    	
	    }	    
	   }	
	   raw_result="";	   
	   if(result.indexOf('<OD>')>0 && result.indexOf('</OD>')>0){	     
	     raw_result=result.substr(result.indexOf('<OD>')+4,result.indexOf('</OD>')-4);
	     raw_result_split=raw_result.split("^");	     
	     if(raw_result_split.length>0){	       
	       for(i=0;i<raw_result_split.length;i+=4){	     
	   	     if(raw_result_split[i]){		    	 		    	
	    		pro_count=i+1;
	    		total_count=i+2;
				date_pur=i+3;
	    		if(raw_result_split[pro_count] && raw_result_split[total_count] && raw_result_split[date_pur]) orders_details+="<tr><td td align='left'><a title='"+raw_result_split[pro_count]+"' alt='"+raw_result_split[pro_count]+"' href=<?php echo tep_href_link(FILENAME_ORDERS,'action=edit');?>&cID="+customer_id+"&oID="+raw_result_split[i]+">"+((raw_result_split[pro_count].length>25)?raw_result_split[pro_count].substr(0,25)+'...':raw_result_split[pro_count])+"</a></td><td align='right'>&nbsp;"+raw_result_split[total_count]+"</td><td align='right'>&nbsp;"+raw_result_split[date_pur]+"</td></tr>";	    			    				    			    		    	
	      	 } 	 	        
	       }	       
	       orders_details+="<tr><td align='right'></td><td align='right'></td><td align='right' nowrap='nowrap'><a  href=<?php echo tep_href_link(FILENAME_ORDERS);?>?cID="+customers_id+"><?php echo TEXT_MORE_ORDERS;?></a></td></tr>";
	      // orders_details+="<tr><td align='left'><a  href=<?php echo tep_href_link(FILENAME_CREATE_ORDER_NEW);?>?cID="+customers_id+"><?php echo TEXT_CREATE_ORDER;?></a></td></tr>";	          	      	 	   	
	     } 
	   } else  orders_details+="<tr><td align='center' class='dataTableContent'><?php echo TEXT_NO_RECORD_FOUND;?></td></tr>";	   
	   tab_end='</table>';
	   if(document.getElementById("loadings")) document.getElementById("loadings").innerHTML="";
	   if(customer_details && document.getElementById("customer_details")) document.getElementById("customer_details").innerHTML=table_gen+customer_details+tab_end; 
	   if(customer_options && document.getElementById("customer_options")) document.getElementById("customer_options").innerHTML=table_gen+customer_actions+tab_end;	   
	   if(orders_details && document.getElementById("orders_details")) document.getElementById("orders_details").innerHTML=table_gen+orders_details+tab_end;	   
	}
	 function do_hover_change(element,eve){ 
	  var img_get_src=element.childNodes[0];
		if(eve==2) {
			img_get_src.src=img_src+'template/img_edit_hover.gif';
		} else if(eve==3){
			img_get_src.src=img_src+'template/img_edit.gif';
		}
			
	 }  	

</script>
</head>
<body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0" bgcolor="#FFFFFF" onLoad="SetFocus();">
<!-- header //-->
<?php require(DIR_WS_INCLUDES . 'header.php'); ?>
<!-- header_eof //-->
<!-- body //-->
<table border="0" width="100%" cellspacing="2" cellpadding="2">
  <tr> 
<!-- body_text //-->
    <td width="100%" valign="top"><table border="0" cellspacing="0" cellpadding="2" width="100%">
      <tr>
        <td><table border="0" width="100%" cellspacing="0" cellpadding="0">
          <tr>
            <td valign="top"><table id="tbl" border="0" width="100%" cellspacing="0" cellpadding="0" class="info_content">
               <tr class="dataTableHeadingRow">
					<td class="main" width="30%"><?php echo TABLE_HEADING_LASTNAME; ?></td>
					<td class="main" width="30%"><?php echo TABLE_HEADING_FIRSTNAME; ?></td>
					<td class="main" align="center" width="40%"><?php echo TABLE_HEADING_LAST_MODIFIED; ?></td>				                
               </tr>
			   <tr>
					 <td colspan="3" id="ajax_customers_details">
						 <?php echo customers_page(); ?>
					 </td>
			  </tr>	
		  	 </table>
		    </td>
          </tr>
          </table></td>
       </tr>
			
		 	<tr><td><?php echo tep_draw_separator('pixel_trans.gif', '2', '10'); ?></td></tr>	 
		 
		 <tr>
		 		<td>
					<table border="0" width="100%" cellspacing="0" cellpadding="0">
						<tr>
							<td>
								<table border="0" width="100%" cellpadding="5" cellspacing="0">
									<tr>
									 <td>
										<table cellpadding="0" cellspacing="0" border="0" width="100%">
											<tr class="product_title">
												<td colspan="2"><?php echo '<b>' . TEXT_CLIENTS . '</b>'; ?></td>
											 </tr>
											 <tr height="7"></tr>	
											<tr>
											  	<td valign="top" width="7%">
													<table border="0" cellpadding="0" cellspacing="0">
													<tr> 
													<td height="74px"  width="59px" align="center" valign="top"><?php echo tep_image(DIR_WS_IMAGES . 'categories/clients.png', Clients,'58','60');?></td>
													</tr>
													</table>
												</td> 
														
												 <td width="93%" valign="top">
												 <table cellpadding="1" cellspacing="3" border="0" width="100%" class="info_content">
												 <tr>
												 <td class="info_content" valign="top"><?php echo '<a href="'. tep_href_link(FILENAME_CREATE_ACCOUNT,'top=1').'">'. BOX_CLIENTS . '</a>';?></td>
												 </tr>	
												 <tr>
													<td colspan="3">
														<table border="0" cellspacing="20" cellpadding="0" width="90%">				
															<tr>
															  <td width="25%" valign="top" class='infoBox'>
																 <table border="0" cellpadding="0" cellspacing="0" width="100%">
																	 <tr class="dataTableHeadingRow">
																	   <td class="info_heading" align="left" valign='absmiddle'>&nbsp;<?php echo TEXT_CUSTOMER_INFO;?></td>
																	 </tr>
																	 <tr>
																	   <td id="customer_details" valign="top"></td>
																	 </tr>
																 </table>
															  </td>				  
															  <td width="25%" valign="top" class='infoBox'>
																 <table border="0" cellpadding="0" cellspacing="0" width="100%">
																	 <tr class="dataTableHeadingRow">
																	   <td class="info_heading" align="left">&nbsp;<?php echo TEXT_CUSTOMER_ACTIONS;?></td>
																	 </tr>
																	 <tr>
																	   <td id="customer_options" valign="top"></td>
																	 </tr>
																 </table>
															  </td>
															  <td width="50%" valign="top" class='infoBox'>
																 <table border="0" cellpadding="0" cellspacing="0" width="100%">
																	 <tr class="dataTableHeadingRow">
																	   <td class="info_heading" align="left">&nbsp;<?php echo TEXT_ORDERS;?></td>
																	 </tr>
																	 <tr>
																	   <td id="orders_details" valign="top"></td>
																	 </tr>
																 </table>
															  </td>				  				  
															</tr>								
														</table> 
													</td>
												</tr>
												 
												 </table>
												</td>
										  </tr>	
										 </table>
										 </td>
										</tr>
									
									<tr>
									 <td>
										<table cellpadding="0" cellspacing="0" border="0" width="100%">
											<tr class="product_title">
												<td colspan="2"><?php echo '<b>' . TEXT_ORDERS . '</b>'; ?></td>
											 </tr>
											 <tr height="7"></tr>	
											<tr>
											  	<td valign="top" width="7%">
													<table border="0" cellpadding="0" cellspacing="0">
													<tr> 
													<td height="74px"  width="59px" align="center" valign="top"><?php echo tep_image(DIR_WS_IMAGES . 'categories/orders.png', Orders,'58','60');?></td>
													</tr>
													</table>
												</td> 
														
												 <td width="93%" valign="top">
												 <table cellpadding="1" cellspacing="3" border="0" width="100%" class="info_content">
												 <tr>
												 <td class="info_content" valign="top"><?php echo '<a href="'. tep_href_link(FILENAME_CREATE_ORDER_NEW,'top=1').'">'. BOX_ORDERS . '</a>';?></td>
												 </tr>	
												 </table>
												</td>
										  </tr>	
										 </table>
										 </td>
									</tr>
			
								<tr>
									 <td>
										<table cellpadding="0" cellspacing="0" border="0" width="100%">
											<tr class="product_title">
												<td colspan="2"><?php echo '<b>' . TEXT_GROUPS . '</b>'; ?></td>
											 </tr>
											 <tr height="7"></tr>	
											<tr>
											  	<td valign="top" width="7%">
													<table border="0" cellpadding="0" cellspacing="0">
													<tr> 
													<td height="74px"  width="59px" align="center" valign="top"><?php echo tep_image(DIR_WS_IMAGES . 'categories/groups.png', Groups,'58','60');?></td>
													</tr>
													</table>
												</td> 
														
												 <td width="93%" valign="top">
												 <table cellpadding="1" cellspacing="3" border="0" width="100%" class="info_content">
												 <tr>
												 <td class="info_content" valign="top"><?php echo '<a href="'. tep_href_link(FILENAME_CUSTOMERS_GROUPS,'top=1').'">'. BOX_CUSTOMERS_GROUPS . '</a>';?></td>
												 </tr>	
												 <tr>
												 <td class="info_content"><?php echo '<a href="'. tep_href_link(FILENAME_SUBSCRIPTION_GROUP,'top=1').'">'. BOX_SUBSCRIPTION_GROUPS . '</a>';?></td>
												 </tr>	 
												 </table>
												</td>
										  </tr>	
										 </table>
										 </td>
								 </tr>
							 </table>	 
							</td>
						 </tr>
						</table> 
					  </td>
					</tr>  	
        
		
		</table></td>
      </tr>
    </table></td>    
<!-- body_text_eof //-->
  </tr>
</table>
<!-- body_eof //-->

<!-- footer //-->
<?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
<!-- footer_eof //-->
</body>
</html> 
<?php require(DIR_WS_INCLUDES . 'application_bottom.php'); 
function sbs_get_zone_name($country_id, $zone_id) {
    $zone_query = tep_db_query("select zone_name from " . TABLE_ZONES . " where zone_country_id = '" .(int)$country_id . "' and zone_id = '" .(int)$zone_id . "'");
    if (tep_db_num_rows($zone_query)) {
      $zone = tep_db_fetch_array($zone_query);
      return $zone['zone_name'];
    } else {
      return $default_zone;
    }
  }
?>

<script language="javascript">
var ajax_image_load='<?php echo tep_image(DIR_WS_IMAGES.'24-1.gif'); ?>';
	function customers_page_navigation(arg1,agr2,agr3,agr4){
	var page_no=1;
	if(agr2==1) var obj=document.getElementById("page_1");
		else if(agr2==2) var obj=document.getElementById("page_2");
		if(agr2 && agr4){
			if(obj){
 	 			page_no=parseInt(obj.options[obj.selectedIndex].value);
 	 			if(agr4=='next') {
 	 				if(obj.length==obj.selectedIndex+1) return;
 	 				page_no+=1;
 	 			}else if(agr4=='prev') {
	 	 			if(obj.selectedIndex==0) return;
 		 			page_no-=1;
 	 			}
 	 			if(page_no<=1) page_no=1;
 	 		} 	 		
	}		
		page=page_no;
		if(agr2==1) command="<?php echo tep_href_link(FILENAME_CUSTOMERS_MAINPAGE,'action=customers_page_navigation&customers_page='); ?>"+page_no;
		else if(agr2==2) command="<?php echo tep_href_link(FILENAME_CUSTOMERS_MAINPAGE,'action=customers_page_navigation&customers_page='); ?>"+page_no;

		if(command!=""){
		 document.getElementById('ajax_customers_details').innerHTML=ajax_image_load;	
		 do_get_command(command);
		}
	}
	
</script>	


<?php
	function customers_page(){
	global $page,$customers_id,$total_customers;
	echo tep_draw_form('frm_customer', FILENAME_CUSTOMERS); 
   // $search = ' where ci.customers_info_id=c.customers_id and ci.customers_info_id=a.customers_id';
    if (isset($HTTP_GET_VARS['search']) && tep_not_null($HTTP_GET_VARS['search'])) {
      $keywords = tep_db_input(tep_db_prepare_input($HTTP_GET_VARS['search']));
      $search = "where c.customers_lastname like '%" . $keywords . "%' or c.customers_firstname like '%" . $keywords . "%' or c.customers_email_address like '%" . $keywords . "%'";
    }
    $customers_query_raw = "select c.customers_id, LTRIM(c.customers_lastname) as customers_lastname, LTRIM(c.customers_firstname) as customers_firstname  from " . TABLE_CUSTOMERS . " c left join " . TABLE_ADDRESS_BOOK . " a on c.customers_id = a.customers_id and c.customers_default_address_id = a.address_book_id " . $search . " order by concat(c.customers_lastname,' ',c.customers_firstname),c.customers_username";

   
	$customers_split = new splitPageResultsEvent($page, MAX_DISPLAY_SEARCH_RESULTS, $customers_query_raw, $customers_numrows);
	$customers_query= tep_db_query($customers_query_raw);
	
	
	$cnt=0;          
    $customers_id=0;
	$total_customers=0;
	$total_customers = tep_db_num_rows($customers_query);
	$customers_flag=true;
	echo '<table width="100%" cellpadding="0" cellspacing="0" border="0">';
    while ($customers = tep_db_fetch_array($customers_query)) {          
	if($customers_flag) {
      $customers_id=$customers['customers_id'];
	}  
	$customers_info_query=tep_db_query('select customers_info_date_account_last_modified as last_modified, customers_info_date_account_created as account_created from '.TABLE_CUSTOMERS_INFO." where customers_info_id='" . $customers['customers_id'] . "'");
	$customers_info_array=tep_db_fetch_array($customers_info_query);
	 
	  $customers_flag=false;
      
	   echo '          <tr id="tab_row['.$cnt.']" class="dataTableRow" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)" onclick="javascript:get_customer_details('.$cnt.','.$customers['customers_id'].','.$total_customers.');" >' . "\n";     
?>
	  			
                <td style="padding-top:5px;" width="30%" align="left"><?php echo $customers['customers_lastname']; ?></td>
                <td style="padding-top:5px;" width="30%" align="left"><?php echo $customers['customers_firstname']; ?></td>
                <td style="padding-top:5px;" width="40%" align="center"><?php 
                	if($customers_info_array['last_modified']=='' || $customers_info_array['last_modified']=='0000-00-00' || $customers_info_array['last_modified']=='0000-00-00 00:00:00') $customers_info_array['last_modified']=$customers_info_array['account_created'];
					if($customers_info_array['last_modified']!='') { 
					
					$split=split(" ",$customers_info_array['last_modified']); 
					$last_modified=date('h:i A',strtotime($split[1]));  
					if($dis_time_format!="") {
						if($dis_time_format=='24')
							$last_modified=date('H:i:s',strtotime($split[1]));
					}
					echo format_date($split[0]).' '.$last_modified;
               }
                ?></td>				                
              </tr>
			  <tr><td colspan="3" id="tab_row_ajx[<?php echo $cnt?>]" style="display:none; padding-top:-5px;"></td></tr>
<?php $cnt++; 
    }
?>	

<!---	<tr style="height:40"><td colspan="3" align="left"><a href="<?php echo tep_href_link(FILENAME_CUSTOMERS,'top=1&mPath=1');?>">			           <?php echo TEXT_SHOW_ALL;?></a></td>
</tr> !--->
		   <tr style="height:20"><td colspan="3" align="left"><?php echo tep_draw_separator('pixel_trans.gif','5','5'); ?></td></tr>
		   
              <tr>
                <td colspan="4"><table border="0" width="100%" cellspacing="0" cellpadding="2">                  
<?php
    if (isset($HTTP_GET_VARS['search']) && tep_not_null($HTTP_GET_VARS['search'])) {
?>
                  <tr>
                    <td align="right" colspan="2"><?php echo '<a href="' . tep_href_link(FILENAME_CUSTOMERS_MAINPAGE) . '">' . tep_image_button('button_reset.gif', IMAGE_RESET) . '</a>'; ?></td>
                  </tr>
<?php
    }
?>
<tr>
<td colspan="3">

<?php 	if(tep_db_num_rows($customers_query)>0){ ?>	
		<table border="0" cellspacing="0" cellpadding="0" width="100%">
			<tr>				  
		         <td class="smallText" valign="top"><?php echo  $customers_split->display_count($customers_numrows, MAX_DISPLAY_SEARCH_RESULTS, $page, TEXT_DISPLAY_NUMBER_OF_CUSTOMERS); ?></td>
		    	 <td class="smallText" align="right"><?php echo $customers_split->display_script_links($customers_numrows, MAX_DISPLAY_SEARCH_RESULTS, MAX_DISPLAY_PAGE_LINKS, $page,1,'customers_page_navigation(\'\'','1'); ?></td>
		    </tr>
		</table>
<?php  }  ?>

			<input type="hidden" name="customers_email_address">
			
				</form>
				</td>
				</tr>
				</table></td></tr></table>
<?php } // Function Ends 

	function load_customers_details($customers_id){

	$customers_query = tep_db_query("select c.customers_firstname,c.customers_lastname,c.customers_email_address,c.customers_id, c.customers_gender, LTRIM(c.customers_firstname) as customers_firstname, LTRIM(c.customers_lastname) as customers_lastname, c.customers_dob, c.customers_email_address, c.customers_second_email_address,c.customers_password,a.entry_company, a.entry_street_address, a.entry_suburb, a.entry_postcode, a.entry_city, a.entry_state, c.customers_type,c.is_blocked,
	                                 a.entry_zone_id, a.entry_country_id, c.customers_telephone, c.customers_second_telephone,c.customers_fax, c.customers_newsletter,c.customers_subscription_newsletter,c.customers_reserve_newsletter,c.customers_default_address_id,c.customers_groups_id,c.customers_discount,c.customers_username,c.customers_occupation,c.suspend_from,c.resume_from,c.customers_interest from " . TABLE_CUSTOMERS . " c left join " . TABLE_ADDRESS_BOOK . 
					 " a on c.customers_default_address_id = a.address_book_id where a.customers_id = c.customers_id and c.customers_id = '" . (int)$customers_id . "' order by concat(c.customers_lastname,' ',c.customers_firstname), c.customers_username");

        $customers = tep_db_fetch_array($customers_query); 
		if (!is_array($customers)) $customers=array();
        $cInfo = new objectInfo($customers);
		
	 $info_query = tep_db_query("select customers_info_date_account_created as date_account_created, customers_info_date_account_last_modified as date_account_last_modified, customers_info_date_of_last_logon as date_last_logon, customers_info_number_of_logons as number_of_logons from " . TABLE_CUSTOMERS_INFO . " where customers_info_id = '" .(int)$customers['customers_id'] . "'");
	$info = tep_db_fetch_array($info_query);

	$country_query = tep_db_query("select countries_name from " . TABLE_COUNTRIES . " where countries_id = '" . (int)$customers['entry_country_id'] . "'");
	$country = tep_db_fetch_array($country_query);
		
    $reviews_query = tep_db_query("select count(*) as number_of_reviews from " . TABLE_REVIEWS . " where customers_id = '" . (int)$customers['customers_id'] . "'");
	$reviews = tep_db_fetch_array($reviews_query);	

	$customer_info = array_merge((array)$country, (array)$info, (array)$reviews);
	
	$cInfo_array = array_merge($customers, (array)$customer_info);
	$cInfo = new objectInfo($cInfo_array);
	
	$details='<table border="0" cellpadding="0" cellspacing="0" width="100%" class="openContent">' .
				'<tr class="openContent_top">' .
					'<td width="300" class="main">'. tep_draw_separator('pixel_trans.gif','10','10').( ($cInfo->is_blocked=='N')?tep_image(DIR_WS_IMAGES.'template/icon_active.gif','Block'):tep_image(DIR_WS_IMAGES.'template/icon_inactive.gif','UnBlock') ) .'&nbsp;&nbsp;'.$cInfo->customers_lastname.'&nbsp;'.$cInfo->customers_firstname . '</td> ' .
					'<td  width="100" align="center">' .
						'<table style="background:#DEE4F5;" width="100%" border="0" cellpadding="0" id="header_operation_id" cellspacing="0">' .
							'<tr id="img_ids">'.
								'<td class="cell_bg_popm_left" width="10">&nbsp;</td>'.
								'<td style="cursor:pointer;" width="10%" OnClick="javascript:edit_customer('.$cInfo->customers_id.');" onMouseOver="javascript:do_hover_change(this,2);" onMouseOut="javascript:do_hover_change(this,3);"><img alt="Edit" title="Edit" src="images/template/img_edit.gif"></td>';
	$details.='<td class="cell_bg_popm_right" width="10">&nbsp;</td>'. 
			'</tr>'; 
		$details.='</table>' .
	'</td>'.
	'<td width="450"  align="right">'.'<a id="customers_operation" style="display:none;">'.tep_image(DIR_WS_IMAGES.'template/img_savel.gif','Save','','','').'</a>'.'&nbsp;&nbsp;<a id="customers_close_button" style="display:none;" href="javascript: close_customer();">'.tep_image(DIR_WS_IMAGES.'template/img_closel.gif','Close','','','').'</a></td>'.
	'</tr>'.
	'<tr>'.
		'<td id="preview_details" style="padding-top:10px;" colspan="3" width="100%"><table width="100%" class="main" cellpadding="2" cellspacing="2" border="0">'.
			'<tr>'.
				'<td width="18%" align="right">' . TEXT_EMAIL_ADDRESS . '</td>'.
				'<td width="10%" align="left">' . $cInfo->customers_email_address . '</td>'.
				'<td width="18%" align="right">' . TEXT_DATE_ACCOUNT_CREATED . '</td>'.
				'<td width="18%" align="left">' .  format_date($cInfo->date_account_created) . '</td>'.
				'<td width="18%" align="right">' . TEXT_INFO_DATE_LAST_LOGON . '</td>'.
				'<td width="10%" align="left">' . format_date($cInfo->date_last_logon) . '</td>'.
			'</tr>'.
			'<tr>'.
				'<td width="18%" align="right">' .  TEXT_INFO_COUNTRY . '</td>'.
				'<td width="18%" align="left">' .  $cInfo->countries_name . '</td>'.
				'<td width="18%" align="right">' . TEXT_DATE_ACCOUNT_LAST_MODIFIED . '</td>' .
				'<td width="18%" align="left">' . format_date($cInfo->date_account_last_modified) . '</td>'.
				'<td width="18%" align="right">' . TEXT_INFO_NUMBER_OF_LOGONS . '</td>'.
				'<td width="18%" align="left">' . $cInfo->number_of_logons . '</td>'.
			'</tr>'.
			'<tr>'.
				'<td colspan="6">' . tep_draw_separator('pixel_trans.gif','10','10') . '</td>'.
			'</tr>';	
		$details.=	'<tr>'.
				'<td colspan="6" align="right" style="padding-right:15px">'.'<a href="'.tep_href_link(FILENAME_ORDERS,'cID='.$cInfo->customers_id).'">'.tep_image_button('button_orders.gif','Orders').'</a>'.
					'</td>'.
			'</tr>' .
		'</table></td>'.
	'</tr> '.
	'<tr>' .
	'<td>' . tep_draw_separator('pixel_trans.gif','10','10') . '</td>'.
	'</tr>'.
	'</table>';
	return $details;
	} // function load_customers_details ends

?>

<script language="javascript">
//get_customer_details(0,<?php echo $customers_id;?>,<?php echo $total_customers; ?>);
</script>
