<?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(DIR_WS_CLASSES . 'split_page_results_event.php');
  tep_get_last_access_file();
  $mode=isset($HTTP_GET_VARS['mode'])?$HTTP_GET_VARS['mode']:'';
  $subscription_id=isset($HTTP_GET_VARS['subscription_id'])?$HTTP_GET_VARS['subscription_id']:'';
  $spack_id=isset($HTTP_GET_VARS['spack_id'])?$HTTP_GET_VARS['spack_id']:-1;
  $licence_code=isset($HTTP_GET_VARS['licence_code'])?$HTTP_GET_VARS['licence_code']:'';
  $domain_name=isset($HTTP_GET_VARS['domain_name'])?$HTTP_GET_VARS['domain_name']:'';    
  $customer_name=isset($HTTP_GET_VARS['customer_name'])?$HTTP_GET_VARS['customer_name']:'';
  $entered_minutes=isset($HTTP_GET_VARS['entered_minutes'])?$HTTP_GET_VARS['entered_minutes']:'';
  $chk_status=isset($HTTP_GET_VARS['chk_status'])?$HTTP_GET_VARS['chk_status']:'';
  $chk_finished=isset($HTTP_GET_VARS['chk_finished'])?$HTTP_GET_VARS['chk_finished']:0;
  $page=isset($HTTP_GET_VARS['page'])?$HTTP_GET_VARS['page']:1;
  if($mode!=""){
  	if($mode=='product_page_navigation' || $mode=='search_support_pack') products_list();
  	else if($mode!='') echo get_software_pack_details();  	   	 
  	exit;
  }
  $support_pack_list=array();
  $support_pack_list[0]=array('id'=>-1,'text'=>TEXT_ALL);
  $support_pack_selection_query=tep_db_query("select osp.subscription_id,pd.subscription_name from ".TABLE_ORDERS_PRODUCTS_SUPPORT_PACKS." osp,".TABLE_SUBSCRIPTIONS_DESCRIPTION." pd where osp.subscription_id=pd.subscription_id  group by osp.subscription_id");
  if(tep_db_num_rows($support_pack_selection_query)>0)
  	while($support_pack_selection=tep_db_fetch_array($support_pack_selection_query))
  		$support_pack_list[]=array('id'=>$support_pack_selection['subscription_id'],'text'=>$support_pack_selection['subscription_name']);  
?>
<!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">
	<style type="text/css">
		#pup {position:absolute; visibility:hidden; z-index:200; width:130; }
	</style>
	<script language="javascript" src="includes/general.js"></script>	
	<script language="Javascript" src="includes/http.js"></script>
	<script language="Javascript">		
	function page_navigation(mode,obj1,obj2,obj3){
	  	var page_product=document.getElementById("page_1");
	  	var chk_status=0;
	  	if(document.getElementById("chk_status") && document.getElementById("chk_status").checked) chk_status=1;
	  	if(mode=='customer_list') page_product=document.getElementById("page_2");	  		  		 
	  	var page_no=1;
	  	if(page_product) page_no=parseInt(page_product.options[page_product.selectedIndex].value);
	  	var support_pack_id=0;
	  	if(document.getElementById("mode")) document.getElementById("mode").value=mode;
		if(document.getElementById("support_pack_id")) var support_pack_id=document.getElementById("support_pack_id").value;	  		
	  	var command="";
	  	if(mode!=""){
	  		if(page_product){
				if(obj3=='next') 					
					page_no+=1;
				else if(obj3=='prev') 										
					page_no-=1;
	  		}
	  	   if(page_no) command="<?php echo tep_href_link(FILENAME_REPORTS_SOFT_PACK,'mode=product_page_navigation');?>&page="+page_no+"&chk_status="+chk_status;
	  	   if(mode=='customer_list') command="<?php echo tep_href_link(FILENAME_REPORTS_SOFT_PACK,'mode=customer_list');?>&page="+page_no+"&spack_id="+support_pack_id+"&chk_status="+chk_status;
	  	}
	  	if(command!="") {
	  		if(document.getElementById("pop_loading")) document.getElementById("pop_loading").style.display="";	  		
	  		do_get_command(command);
	  	}	  	
	  }
	  
	  function visible_box_in(obj){
		if(obj){
			obj.readOnly=false;
			obj.style.border='';								
		}
	  }
	  
	  function supportpack_search(){
	  	 var pack_id=0;
	  	 var chk_status=0;
	  	 var chk_finished=0;
	  	 if(document.getElementById("support_pack_list")) pack_id=document.getElementById("support_pack_list").options[document.getElementById("support_pack_list").selectedIndex].value;
	  	 if(document.getElementById("chk_status") && document.getElementById("chk_status").checked) chk_status=1;
	  	 if(document.getElementById("chk_finished") && document.getElementById("chk_finished").checked) chk_finished=1;
	  	 do_get_command("<?php echo tep_href_link(FILENAME_REPORTS_SOFT_PACK,'mode=search_support_pack');?>&spack_id="+pack_id+"&chk_status="+chk_status+"&chk_finished="+chk_finished);
		 if(document.getElementById("mode")) document.getElementById("mode").value='search_support_pack';
		 if(document.getElementById("pop_loading")) document.getElementById("pop_loading").style.display="";
	  }
	  
	  function visible_box_blur(obj,licence_code){	  	
	  	if(obj){
			var found_border=false;
			if(((licence_code && obj.name.indexOf('domain_')>0) ||(licence_code && obj.name.indexOf('name_')>0)) && obj.style.border==''){
				obj.readOnly=true;
				obj.style.border='0px';
				obj.alt=obj.title=obj.value;
				found_border=true;	
			}
			if(licence_code && obj.name.indexOf('domain_')>0 && found_border) do_get_command("<?php echo tep_href_link(FILENAME_REPORTS_SOFT_PACK,'mode=update_customer_domain');?>&licence_code="+licence_code+"&domain_name="+obj.value);
			else if(licence_code && obj.name.indexOf('name_')>0 && found_border) do_get_command("<?php echo tep_href_link(FILENAME_REPORTS_SOFT_PACK,'mode=update_customer_name');?>&licence_code="+licence_code+"&customer_name="+obj.value);			
			else if(licence_code && obj.src.indexOf('.gif')>0){
				if(document.getElementById("hidden_license_code")) {
					if(document.getElementById("hidden_license_code").value>0 && document.getElementById("time_popup_"+document.getElementById("hidden_license_code").value)) document.getElementById("time_popup_"+document.getElementById("hidden_license_code").value).style.display="none";  
					document.getElementById("hidden_license_code").value=licence_code;
					if(document.getElementById("time_popup_"+licence_code)) document.getElementById("time_popup_"+licence_code).style.display="";
					if(document.getElementById("txt_minutes_"+licence_code)) document.getElementById("txt_minutes_"+licence_code).value="";	
				}
																				
			}else if(licence_code && obj.name.indexOf('_minutes')>0) {
				if(obj && document.getElementById("remain_minute_"+licence_code))
					var get_minute=document.getElementById("remain_minute_"+licence_code).innerHTML;
					get_minute=parseInt(get_minute.replace(" Mins",""));
					if(get_minute<=0 || obj.value=="" ||  (obj.value.value!='' && (obj.value.substr(0,1)=='-' && (get_minute<obj.value.substr(1,obj.value.length) || obj.value.substr(1,obj.value.length)<=0 || isNaN(obj.value.substr(1,obj.value.length)) || obj.value.substr(1,obj.value.length)==""))) || get_minute<obj.value || obj.value==0) alert("<?php echo ERR_MINUTES_EXCITS;?>");
					else {
						var remain_minute=((obj.value.indexOf('-')==0)?parseInt(get_minute)+parseInt(obj.value.substr(1,obj.value.length)):(parseInt(get_minute) - parseInt(obj.value)));
						if(remain_minute<=0) {
							remain_minute=0;
							if(document.getElementById("img_time_"+licence_code)) document.getElementById("img_time_"+licence_code).style.display="none";	
						}
						document.getElementById("remain_minute_"+licence_code).innerHTML=((remain_minute==0)?'Finished!':remain_minute+" Mins");						
						if(obj.value) {
							if(document.getElementById("pop_loading")) document.getElementById("pop_loading").style.display="";
							do_get_command("<?php echo tep_href_link(FILENAME_REPORTS_SOFT_PACK,'mode=update_used_minutes');?>&licence_code="+licence_code+"&entered_minutes="+obj.value);
							if(document.getElementById("time_popup_"+licence_code)) document.getElementById("time_popup_"+licence_code).style.display="none";
						}											
					} 									
			} 	
		}
	  }
	  
	  function get_support_pack_details(mode,subscription_id){
		 var command="";
		 var mode_hidden=document.getElementById("mode");
		 var subscription_id_hidden=document.getElementById("subscription_id");
		 var support_pack_hidden=document.getElementById("support_pack_id");
		 var active_customer=0;
		 if(document.getElementById("chk_status") && document.getElementById("chk_status").checked) active_customer=1;  
		 if(mode=='software_pack' && subscription_id_hidden && subscription_id_hidden.value>0 && document.getElementById("software_pack_"+subscription_id_hidden.value)) document.getElementById("software_pack_"+subscription_id_hidden.value).style.display="none";
		 else if(mode=='customer_list' && support_pack_hidden && support_pack_hidden.value>0 && document.getElementById("customer_list_"+support_pack_hidden.value)) document.getElementById("customer_list_"+support_pack_hidden.value).style.display="none";
		 if(mode!="" && subscription_id){
			if(mode=='software_pack')
				command="<?php echo tep_href_link(FILENAME_REPORTS_SOFT_PACK,'mode=software_pack')?>&subscription_id="+subscription_id+"&chk_status="+active_customer;
			else if(mode=='customer_list')
				command="<?php echo tep_href_link(FILENAME_REPORTS_SOFT_PACK,'mode=customer_list')?>&spack_id="+subscription_id+"&chk_status="+active_customer;
			else if(mode=='activate' && confirm("<?php echo TEXT_ACTIVATION_CONFIRMATION;?>"))
				command="<?php echo tep_href_link(FILENAME_REPORTS_SOFT_PACK,'mode=activate')?>&licence_code="+subscription_id;								
			else if(mode=='deactivate' && confirm("<?php echo TEXT_DEACTIVATION_CONFIRMATION;?>"))
				command="<?php echo tep_href_link(FILENAME_REPORTS_SOFT_PACK,'mode=deactivate')?>&licence_code="+subscription_id;				
			
		 }
		if(document.getElementById("pop_loading")) document.getElementById("pop_loading").style.display=""; 
		if(command) do_get_command(command);
		if(mode_hidden) mode_hidden.value=mode;
		if(mode=='software_pack' && subscription_id_hidden) subscription_id_hidden.value=subscription_id;
		if(mode=='customer_list' && support_pack_hidden) support_pack_hidden.value=subscription_id;
	  }
	  
	 function do_result(result){
	 //alert (result);
	 	var subscription_id_obj=document.getElementById("subscription_id");
	 	var support_pack_id_obj=document.getElementById("support_pack_id");
	 	var mode_hidden=document.getElementById("mode");
	 	var hidden_license_code=document.getElementById("hidden_license_code");
	 	if(document.getElementById("pop_loading")) document.getElementById("pop_loading").style.display="none";
	 	if(mode_hidden && (mode_hidden.value=='search_support_pack' || mode_hidden.value=='product_navigation') && document.getElementById("products_list"))
	 		document.getElementById("products_list").innerHTML=result;
	 	else if(result!="" && subscription_id_obj && subscription_id_obj.value>0 && document.getElementById("software_pack_"+subscription_id_obj.value) && mode_hidden && mode_hidden.value=='software_pack'){
			document.getElementById("software_pack_"+subscription_id_obj.value).innerHTML=result;
			document.getElementById("software_pack_"+subscription_id_obj.value).style.display="";
	 	}else if(result!="" && support_pack_id_obj && support_pack_id_obj.value>0 && document.getElementById("customer_list_"+support_pack_id_obj.value) && mode_hidden && mode_hidden.value=='customer_list'){
			document.getElementById("customer_list_"+support_pack_id_obj.value).innerHTML=result;
			document.getElementById("customer_list_"+support_pack_id_obj.value).style.display="";
	 	}else if(mode_hidden && mode_hidden.value!='' && result!="" && result>0 && document.getElementById("img_licence_"+result)){
	 		if(mode_hidden.value=='activate') {
				document.getElementById("img_licence_"+result).onclick=function () {get_support_pack_details('deactivate',result)};
				document.getElementById("img_licence_"+result).src=document.getElementById("img_licence_"+result).src.replace("icon_inactive.gif","icon_active.gif");
	 		}else if(mode_hidden.value=='deactivate') {
				document.getElementById("img_licence_"+result).onclick=function () {get_support_pack_details('activate',result)};
				document.getElementById("img_licence_"+result).src=document.getElementById("img_licence_"+result).src.replace("icon_active.gif","icon_inactive.gif");
	 		}
	 	}else if(mode_hidden && mode_hidden.value=='get_used_minutes'){	 		
	 		var element=document.getElementById("popContent");
			if (element) element.innerHTML=result;
	 	}	 	
	 }
	</script>
</head>
<body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0" bgcolor="#FFFFFF">
<script language="javascript" src="includes/popup.js"></script>
<script language="javascript">
 	var baby=new Array();	
	baby[1]="";
	var openpopup=0;
	function showorder_history(license_code)
	{
			// check if popup has already opened
			if (skin.visibility=="visible") return;
			var element=document.getElementById("popup_license_details_"+license_code);
			var content;
			if (!element) return;
			content='<table border="0" cellspacing="0" cellpadding="4" style="background-color: #FDFDFD; border-color: #A9BBF3; border-style: solid; border-width: 1px;" width="100%"><tr><td id="popContent" class="main">';
			// if type is session then display message loading
			if (license_code){
				content+="<?php echo TEXT_LOADING;?>";
				popwidth=530;
			} 
			content+='</div></td></tr></table>';

			baby[1]=content;
			if (baby[1]!="") popup("1","#ffffff");			
			// if needed to get the contents using ajax
			if (license_code){
				command="<?php echo tep_href_link(FILENAME_REPORTS_SOFT_PACK);?>?mode=get_used_minutes&licence_code="+license_code;
				if(document.getElementById("mode")) document.getElementById("mode").value='get_used_minutes';
				if(document.getElementById("hidden_license_code")) document.getElementById("hidden_license_code").value=license_code;
				do_get_command(command);
			}
	}
	function closepopup(){
		do_close();
		kill();
	}
</script>
<!-- header //--><?php require(DIR_WS_INCLUDES . 'header.php'); ?> <!-- header_eof //-->
  <!-- body //-->
	<table border="0" width="100%" cellspacing="2" cellpadding="2">
		<tr>
		  <td>
		    <table border="0" cellpacing="0" cellpadding="0" width="100%">
 				<tr class="PageHeading" style="height:40;">
 				  <td width="40%"><?php echo TEXT_SOFTWARE_HEADING;?></td>
 				  <td valign="bottom" align="left" class="main"><div class="smalltext" align="center" id='pop_loading' style='display:none;width:110px;height:15px;z-index:10;border:1px solid;border-color:#6883CA;background-color:#F2F5FE;padding:3px;'>Loading...</div></td>
 				</tr>
 				<tr>
 				  <td colspan="2">
 				    <table border="0" cellspacing="3" cellpadding="2" class="searchArea" width="100%">
 				      <tr>
 				      	 <td class="main" align="left"><?php echo TEXT_SOFTWAREPACK_NAME.'&nbsp;&nbsp;&nbsp;'.tep_draw_pull_down_menu('support_pack_list',$support_pack_list);?></td> 				      	 
 				      	 <td class="main" align="left"><?php echo tep_draw_checkbox_field('chk_status').' '.TEXT_SOFTWARE_PACKS;?></td>
 				      	 <!--<td class="main" align="left"><?php echo tep_draw_checkbox_field('chk_finished').' '.TEXT_FINISHED;?></td>-->
 				      	 <td class="main" align="left">&nbsp;</td>
 				      	 <td class="main" align="left"><?php echo tep_image_button('button_search.gif',IMAGE_SEARCH,' style="cursor:pointer;cursor:hand;" onclick="javascript:supportpack_search();"')?></td>
 				      </tr> 				       				      
 				    </table>
 				  </td>
 				</tr> 				
 				<tr><td colspan="2" class="cell_bg_report_header">&nbsp;</td></tr>
 				<tr>
 					<td colspan="2" id="products_list"><?php echo products_list();?></td>
 				</tr>		    
		    </table>
		  </td>
		</tr>
	 <?php echo tep_draw_hidden_field('mode').tep_draw_hidden_field('subscription_id').tep_draw_hidden_field('support_pack_id').tep_draw_hidden_field('hidden_license_code');?>	
	</table>
  <!-- body //-->
<!-- footer //--> <?php require(DIR_WS_INCLUDES . 'footer.php');?> <!-- footer_eof //-->
</body>
</html>
<?php 
 function get_software_pack_details(){
 	global $subscription_id,$spack_id,$licence_code,$mode,$domain_name,$customer_name,$entered_minutes,$page,$chk_status; 	
	if($subscription_id && $mode=='software_pack'){
		$print_string.="<table border='0' cellspacing='3' cellpadding='2' width='100%'><tr><td>&nbsp;</td></tr><tr><td width='2%'>&nbsp;</td><td>";
		$print_string.="<table border='0' cellspacing='0' cellpadding='0' width='100%'>";
		$software_pack_list=tep_db_query("select osp.support_packs_id,osp.orders_id,osp.subscription_name,osp.support_minutes,o.customers_name,count(spl.support_packs_id) as no_users from ".TABLE_ORDERS_PRODUCTS_SUPPORT_PACKS." osp LEFT JOIN ".TABLE_ORDERS." o on osp.orders_id=o.orders_id LEFT JOIN ".TABLE_SUBSCRIPTIONS." p on p.subscription_id=osp.subscription_id LEFT JOIN ".TABLE_SUBSCRIPTIONS_DESCRIPTION." pd on p.subscription_id=pd.subscription_id,".TABLE_SUPPORT_PACKS_LICENSE. " spl where osp.subscription_id='".$subscription_id."' and spl.support_packs_id=osp.support_packs_id ".(($chk_status==1)?" and spl.activate='Y' ":'')." group by spl.support_packs_id order by pd.subscription_name");		
	//	echo "select osp.support_packs_id,osp.orders_id,osp.subscription_name,osp.support_minutes,count(spl.support_packs_id) as no_users from ".TABLE_ORDERS_PRODUCTS_SUPPORT_PACKS." osp LEFT JOIN ".TABLE_ORDERS." o on osp.orders_id=o.orders_id LEFT JOIN ".TABLE_SUBSCRIPTIONS." p on p.subscription_id=osp.subscription_id LEFT JOIN ".TABLE_SUBSCRIPTIONS_DESCRIPTION." pd on p.subscription_id=pd.subscription_id,".TABLE_SUPPORT_PACKS_LICENSE. " spl where osp.subscription_id='".$subscription_id."' and spl.support_packs_id=osp.support_packs_id ".(($chk_status==1)?" and spl.activate='Y' ":'')." group by spl.support_packs_id order by pd.subscription_name";
		if(tep_db_num_rows($software_pack_list)>0){
			$print_string.="<tr class='dataTableHeadingTitleRow'>";
				$print_string.="<td width='25%' class='dataTableHeadingTitleContent'>".TEXT_ORDER_ID."</td>";
				$print_string.="<td width='25%' class='dataTableHeadingTitleContent'>".TEXT_RESELLER_NAME."</td>";
				$print_string.="<td width='25%' align='right' class='dataTableHeadingTitleContent'>".tep_draw_separator("pixel_trans.gif","20","5").TEXT_NUMBEROF_USERS."</td>";
				$print_string.="<td  align='right' class='dataTableHeadingTitleContent'>".TEXT_SUPPORT_MINUTES."</td>";

			$print_string.="</tr>";
		 	$print_string.="<tr><td colspan='4'><table border='0' cellspacing='0' cellpadding='2' width='100%'>";
		 	$cnt_s=0;
			while($software_pack=tep_db_fetch_array($software_pack_list)){
				$class="dataTableRowEven";
				if($cnt_s%2==0) $class="dataTableRowOdd";
				$print_string.='<tr class="'.$class.'" style="cursor:pointer;cursor:hand;" onclick="javascript:get_support_pack_details(\'customer_list\','.$software_pack['support_packs_id'].');">';					
					$print_string.="<td width='100' class='main'>".$software_pack['orders_id']."</td>";
					$print_string.="<td width='100' class='main'>".$software_pack['customers_name']."</td>";
					$print_string.="<td width='100' class='main' align='right'>".$software_pack['no_users'].tep_draw_separator("pixel_trans.gif","10","5")."</td>";
					$print_string.="<td width='100' align='right' class='main'>".$software_pack['support_minutes']." Mins</td>";

				$print_string.="</tr>";
				$print_string.="<tr><td id='customer_list_".$software_pack['support_packs_id']."' colspan='4' style='display:none;'></td></tr>";
				$cnt_s++;
			}
		 $print_string.="</table></td></tr><tr><td>&nbsp;</td></tr><tr><td>&nbsp;</td></tr>";
		}else $print_string.="<tr><td colspan='4' align='center' class='main'>".SOFTWARE_PACK_RESULT_NOT_FOUND."</td></tr>";		
		$print_string.="</table></td></tr></table>";
	}else if($spack_id && $mode=='customer_list'){
		$print_string="<table border='0' cellspacing='0' cellpadding='0' width='100%'><tr><td width='1%'>".tep_draw_separator("pixel_trans.gif","50","5")."</td><td>";
		$print_string.="<table border='0' cellspacing='0' cellpadding='0' width='100%'>";
		$support_pack_customer="select license_code,support_packs_id,customer_domain,customer_name,activate from ".TABLE_SUPPORT_PACKS_LICENSE." where support_packs_id='".(int)$spack_id."'".(($chk_status==1)?" and activate='Y'":'')." order by license_code";
		$support_pack_customer_split = new splitPageResultsEvent($page, MAX_DISPLAY_SEARCH_RESULTS, $support_pack_customer, $support_pack_customer_num_rows);
		$support_pack_customer_query=tep_db_query($support_pack_customer);
		if(tep_db_num_rows($support_pack_customer_query)>0){
			$print_string.="<tr class='dataTableHeadingTitleRow'>";
				$print_string.="<td width='50' class='dataTableHeadingTitleContent'>".TEXT_STATUS."</td>";
				$print_string.="<td width='100' class='dataTableHeadingTitleContent'>".TEXT_LICENCE_CODE."</td>";
				$print_string.="<td width='100' class='dataTableHeadingTitleContent'>".TEXT_CUSTOMER_NAME."</td>";
				$print_string.="<td width='100' class='dataTableHeadingTitleContent'>".TEXT_CUSTOMER_DOMAIN."</td>";
				$print_string.="<td  width='100' align='right' class='dataTableHeadingTitleContent'>".TEXT_REMAINING_MINUTES."</td>";
			$print_string.="</tr>";
			$print_string.="<tr><td colspan='5'><table border='0' cellspacing='0' cellpadding='2' width='100%'>";
			$cnt_c=0;
			while($support_pack=tep_db_fetch_array($support_pack_customer_query)){
				$class="dataTableRowEven";				
				$bgcolr="background:#ffffff";
				if($cnt_c%2==0) {
					$bgcolr="background:#F3F3F3";	
					$class="dataTableRowOdd";
				}
				$print_string.='<tr class="'.$class.'">';
					//$print_string.="<td width='10%' class='main'>".(($support_pack['activate']=='N')?tep_image('images/template/icon_inactive.gif',IMAGE_ACTIVATE,'','',' id="img_licence_'.$support_pack['license_code'].'" style="cursor:pointer;cursor:hand;" onclick="javascript:get_support_pack_details(\'activate\','.$support_pack['license_code'].');"'):tep_image('images/template/icon_active.gif',IMAGE_DEACTIVATE,'','',' id="img_licence_'.$support_pack['license_code'].'" style="cursor:pointer;cursor:hand;" onclick="javascript:get_support_pack_details(\'deactivate\','.$support_pack['license_code'].');"'))."</td>";
					//$print_string.="<td width='25%' class='main'>".tep_draw_input_field('customer_name_'.$support_pack['license_code'],$support_pack['customer_name'],' alt="'.$support_pack['customer_name'].'" title="'.$support_pack['customer_name'].'" maxlength="125" style="border:0;'.$bgcolr.'" readonly onclick="javascript:visible_box_in(this);" onblur="javascript:visible_box_blur(this,'.$support_pack['license_code'].');"')."</td>";
					//$print_string.="<td width='20%' class='main'>".tep_draw_input_field('customer_domain_'.$support_pack['license_code'],$support_pack['customer_domain'],' alt="'.$support_pack['customer_domain'].'" title="'.$support_pack['customer_domain'].'" maxlength="255" style="border:0;'.$bgcolr.'" readonly onclick="javascript:visible_box_in(this);" onblur="javascript:visible_box_blur(this,'.$support_pack['license_code'].');"')."<div id='popup_license_details_".$support_pack['license_code']."'></div></td>";
					$print_string.="<td width='50' class='main'>".tep_draw_separator("pixel_trans.gif","5","5").(($support_pack['activate']=='N')?tep_image('images/template/icon_inactive.gif',IMAGE_ACTIVATE,'','',' id="img_licence_'.$support_pack['license_code'].'"'):tep_image('images/template/icon_active.gif',IMAGE_DEACTIVATE,'','',' id="img_licence_'.$support_pack['license_code'].'"'))."</td>";
					$print_string.='<td width="115" onMouseOver="javascript:showorder_history('.$support_pack['license_code'].');" onMouseOut="javascript:closepopup()" class="main">'.tep_draw_separator("pixel_trans.gif","5","5").sprintf('%05d',$support_pack['license_code'])."<div id='popup_license_details_".$support_pack['license_code']."'></div></td>";					
					$print_string.="<td width='110' class='main' alt='".$support_pack['customer_name']."' title='".$support_pack['customer_name']."'>".((strlen($support_pack['customer_name'])>35)?substr($support_pack['customer_name'],0,35).'...':$support_pack['customer_name'])."</td>";					
					$print_string.="<td width='100' class='main' alt='".$support_pack['customer_domain']."' title='".$support_pack['customer_domain']."'>".((strlen($support_pack['customer_domain'])>50)?substr($support_pack['customer_domain'],0,50).'...':$support_pack['customer_domain'])."</td>";
					$remaining_minutes=get_remaining_mintutes($spack_id,$support_pack['license_code']);
					if($remaining_minutes<=0) $remaining_minutes=TEXT_FINISHED;
					else $remaining_minutes.=' Mins';					
					$string="<td align='right' width='100' nowrap='true' class='main'><span id='remain_minute_".$support_pack['license_code']."'>".$remaining_minutes.'</span></td>';
					//if($support_pack['activate']=='Y') $string.="<td class='main'><div style='display:none;width:140px;height:20px;z-index:10;border:1px solid;border-color:#6883CA;background-color:#F2F5FE;padding:3px;' id='time_popup_".$support_pack['license_code']."'><table border='0' cellspacing='0' cellpadding='0' width='100%'><tr><td valign='top' class='main'>".tep_draw_input_field('txt_minutes_'.$support_pack['license_code'],'',' size=5 maxlength=5 ').' Mins'.'</td><td class="middle">'.tep_image('images/template/img_savel.gif',IMGAE_SAVE,'','',' style="cursor:pointer;cursor:hand;" onclick="javascript:visible_box_blur(document.getElementById(\'txt_minutes_'.$support_pack['license_code'].'\'),'.$support_pack['license_code'].');"').'&nbsp;'.tep_image('images/template/img_closel.gif',IMAGE_CLOSE,'','',' style="cursor:pointer;cursor:hand;" onclick="javascript:if(document.getElementById(\'time_popup_'.$support_pack['license_code'].'\')) document.getElementById(\'time_popup_'.$support_pack['license_code'].'\').style.display=\'none\';"')."</td></tr></table></div></td>";
					$print_string.="<td align='right' width='100' class='main'><table border='0' cellspacing='0' cellpadding='0' width='70%'><tr>".$string."</tr></table></td>";									
				$print_string.="</tr>";
				$cnt_c++;
			}
			$print_string.="</table></td></tr><tr><td>&nbsp;</td></tr>";
			if($support_pack_customer_num_rows>MAX_DISPLAY_SEARCH_RESULTS){
				$print_string.="<tr><td align='right' colspan='5'><table border='0' cellspacing='0' cellpadding='2'><tr><td class='smallText' align='left'>";
				$print_string.=$support_pack_customer_split->display_script_links($support_pack_customer_num_rows, MAX_DISPLAY_SEARCH_RESULTS, REPORT_MAX_LINKS_PAGE, $page,'','page_navigation(\'customer_list\'','2');
				$print_string.="</td></tr></table></td></tr>";
			}
		}else $print_string.="<tr><td colspan='5' align='center' class='main'>".NO_CUSTOMERS_FOUND."</td></tr>";
		$print_string.="</table></td></tr></table>";
	}else if(($mode=='activate' || $mode=='deactivate') && $licence_code){
		tep_db_query("update ".TABLE_SUPPORT_PACKS_LICENSE." set activate='".(($mode=='deactivate')?'N':'Y')."' where license_code='".(int)$licence_code."'");
		$print_string=$licence_code;
	}else if($mode=='update_customer_domain' || $mode=='update_customer_name')
		tep_db_query("update ".TABLE_SUPPORT_PACKS_LICENSE." set ".(($mode=='update_customer_domain')?"customer_domain='".$domain_name."'":"customer_name='".$customer_name."'")." where license_code='".(int)$licence_code."'");
	else if($mode=='get_used_minutes' && $licence_code>0){
		$get_order_history_query=tep_db_query("select domain_name,customer_email,date_format(support_added,'%Y-%m-%d') as support_added,minutes_used from ".TABLE_SUPPORT_PACKS_ORDER_HISTORY." where license_code='".(int)$licence_code."'");
		$print_string="<table border='0' cellspacing='0' cellpadding='4' width='100%'>";
		 if(tep_db_num_rows($get_order_history_query)>0){
				$print_string.="<tr class='dataTableHeadingTitleRow'>";
					$print_string.="<td id='popContent' width='40%' align='left' class='dataTableHeadingTitleContent'>".TEXT_DOMAIN_NAME."</td>";
					$print_string.="<td id='popContent' width='40%' align='left' class='dataTableHeadingTitleContent'>".TEXT_CUSTOMER_EMAIL."</td>";
					$print_string.="<td id='popContent' widht='10%' class='dataTableHeadingTitleContent'>".TEXT_SOFTWARE_DATE_ADDED."</td>";
					$print_string.="<td id='popContent' width='15%' align='right' class='dataTableHeadingTitleContent'>".TEXT_MINUTES_USED."</td>";
				$print_string.="</tr>";
			while($get_order_history=tep_db_fetch_array($get_order_history_query)){
				$print_string.="<tr>";
					$print_string.="<td id='popContent' align='left' class='main'>".((strlen($get_order_history['domain_name'])>25)?substr($get_order_history['domain_name'],0,25).'...':$get_order_history['domain_name'])."</td>";
					$print_string.="<td id='popContent' align='left' class='main'>".((strlen($get_order_history['customer_email'])>25)?substr($get_order_history['customer_email'],0,25).'...':$get_order_history['customer_email'])."</td>";
					$print_string.="<td id='popContent' align='left' class='main'>".format_date($get_order_history['support_added'])."</td>";
					$print_string.="<td id='popContent' class='main' align='right'>".$get_order_history['minutes_used']."</td>";
				$print_string.="</tr>";
			}
		}else {
			$print_string="<tr><td align='center'>".SUPPORT_MINUTES_NOT_FOUND."</td></tr>";
		}
		$print_string.="</table>";
	}
	else if($mode=='update_used_minutes' && $entered_minutes!="" && $licence_code){
		$insert_array=array();
		$get_details_query=tep_db_query("select license_code,support_packs_id,customer_domain,customer_name,customer_email from ".TABLE_SUPPORT_PACKS_LICENSE." where license_code='".(int)$licence_code."'");
		if(tep_db_num_rows($get_details_query)>0) $get_details=tep_db_fetch_array($get_details_query);
		$insert_array=array('support_pack_id'=>$get_details['support_packs_id'],'license_code'=>$get_details['license_code'],'domain_name'=>$get_details['customer_domain'],'customer_email'=>$get_details['customer_email'],'support_added'=>getServerDate(true),'minutes_used'=>$entered_minutes);
		tep_db_perform(TABLE_SUPPORT_PACKS_ORDER_HISTORY,$insert_array);
	}
	echo $print_string;
 }
 
 function get_remaining_mintutes($support_pack_id,$licence_code){
 	$remaining_minutes=0;
 	$total_support_minutes=0;
 	$used_support_minutes=0;
 	if($support_pack_id>0 && $licence_code>0){
		$support_minutes_query=tep_db_query("select support_minutes from ".TABLE_ORDERS_PRODUCTS_SUPPORT_PACKS." where support_packs_id='".(int)$support_pack_id."'");
	  if(tep_db_num_rows($support_minutes_query)>0){
			$support_minutes=tep_db_fetch_array($support_minutes_query);
			$total_support_minutes=$support_minutes['support_minutes'];
			$remaining_minutes=$total_support_minutes;
	  }
	  $used_minutes_query=tep_db_query("select sum(minutes_used) as minutes_used from ".TABLE_SUPPORT_PACKS_ORDER_HISTORY." where support_pack_id='".(int)$support_pack_id."' and license_code='".(int)$licence_code."' group by license_code");
	  if(tep_db_num_rows($used_minutes_query)>0){
	  		$used_minutes=tep_db_fetch_array($used_minutes_query);
	  		$used_support_minutes=$used_minutes['minutes_used'];	  		
	  }
 	}
	if($total_support_minutes!="" && $used_support_minutes!="") $remaining_minutes=$total_support_minutes-$used_support_minutes;	
	return $remaining_minutes;
 }
 
 function products_list(){
   global $suport_pack_list,$page,$chk_status,$chk_finished,$mode,$spack_id;
   	$search_string="";
   	if($mode=='search_support_pack' && $spack_id>0) $search_string=" and osp.subscription_id='".(int)$spack_id."'";
   	if($chk_status==1) $search_string.=" and spl.activate='Y'";
   	//$suport_pack_list_query="select p.products_id,pd.products_name,sum(osp.support_minutes) as total_support_minutes,sum(osp.no_users) as total_no_user from ".TABLE_ORDERS_PRODUCTS_SUPPORT_PACKS." osp LEFT JOIN ".TABLE_ORDERS." o on osp.orders_id=o.orders_id LEFT JOIN ".TABLE_PRODUCTS." p on p.products_id=osp.products_id LEFT JOIN ".TABLE_PRODUCTS_DESCRIPTION." pd on p.products_id=pd.products_id ".$search_string." group by osp.products_id order by pd.products_name";
   	$suport_pack_list_query="select p.subscription_id,pd.subscription_name,sum(osp.support_minutes) as total_support_minutes,count(spl.license_code) as total_no_user from ".TABLE_ORDERS_PRODUCTS_SUPPORT_PACKS." osp LEFT JOIN ".TABLE_ORDERS." o on osp.orders_id=o.orders_id LEFT JOIN ".TABLE_SUBSCRIPTIONS." p on p.subscription_id=osp.subscription_id LEFT JOIN ".TABLE_SUBSCRIPTIONS_DESCRIPTION." pd on p.subscription_id=pd.subscription_id,".TABLE_SUPPORT_PACKS_LICENSE." spl where  spl.support_packs_id=osp.support_packs_id ".$search_string." group by osp.subscription_id order by pd.subscription_name";
   	//echo $suport_pack_list_query;
   	$support_split = new splitPageResultsEvent($page, MAX_DISPLAY_SEARCH_RESULTS, $suport_pack_list_query, $suport_pack_list_num_rows);
    $suport_pack_list=tep_db_query($suport_pack_list_query);
  ?>
 	<table border="0" cellpacing="0" cellpadding="0" width="100%">
 				       <?php
 				        if(tep_db_num_rows($suport_pack_list)>0){ ?>
 				        	<tr class="dataTableHeadingTitleRow">
 				        		<td class="dataTableHeadingTitleContent" width="100"><?php echo TEXT_SOFTWAREPACK_NAME;?></td> 				        		
 				        		<td class="dataTableHeadingTitleContent"  width="100">&nbsp;</td>
 				        		<td class="dataTableHeadingTitleContent"  align='right' width="100"><?php echo TEXT_TOTAL_NO_USERS;?></td>
								<td class="dataTableHeadingTitleContent" align='right' width="100">&nbsp;</td>
 				        	</tr>
 				        	<tr>
 				        	 <td colspan="4">
 				        	  <table border="0" cellspacing="0" cellpadding="2" width="100%">
		  	 					 <?php $cnt=0; 
		  	 					 while($suport_pack=tep_db_fetch_array($suport_pack_list)){		  	 					   
			  	 				   $search_status="";			  	 				   
		  	 					   if($chk_status==1) $search_status=" and spl.support_packs_id=osp.support_packs_id and spl.activate='Y'";
		  	 					   $software_pack_list=tep_db_query("select osp.support_packs_id,osp.subscription_name,osp.support_minutes,osp.no_users from ".TABLE_ORDERS_PRODUCTS_SUPPORT_PACKS." osp LEFT JOIN ".TABLE_ORDERS." o on osp.orders_id=o.orders_id LEFT JOIN ".TABLE_SUBSCRIPTIONS." p on p.subscription_id=osp.subscription_id LEFT JOIN ".TABLE_SUBSCRIPTIONS_DESCRIPTION." pd on p.subscription_id=pd.subscription_id,".TABLE_SUPPORT_PACKS_LICENSE." spl where osp.subscription_id='".$suport_pack['subscription_id']."' ".$search_status." group by osp.support_packs_id order by pd.subscription_name");
		  	 					   if(tep_db_num_rows($software_pack_list)>0) {		  	 					  
		  	 					   $class="dataTableRowEven";
		  	 					   if($cnt%2==0) $class="dataTableRowOdd";
		  	 					   $cnt++;
		  	 					 ?>
		  	 					    <tr class="<?php echo $class;?>" style="cursor:pointer;cursor:hand;'" onClick="javascript:get_support_pack_details('software_pack',<?php echo $suport_pack['subscription_id'];?>);">
		  	 						   <td width="100" class="main"><?php echo $suport_pack['subscription_name'];?></td>
		  	 						   <td width="100" class="main" align="right">&nbsp;</td>
		  	 						   <td width="100" class="main" align='right'><?php echo $suport_pack['total_no_user'];?></td>
									   <td class="main" align='right' width="100">&nbsp;</td>
		  	 					   	</tr>
		  	 					    <tr>
		  	 					       <td colspan="4" id="software_pack_<?php echo $suport_pack['subscription_id'];?>" style="display:none;"></td>
		  	 					    </tr>
		  	 				     <?php  } else if($spack_id!=-1) { ?>
		  	 				     	<tr>
	 				          			<td colspan="4" class="main" align="center"><?php echo RESULT_NOT_FOUND;?></td>
	 				       			</tr> 
		  	 				     <?php } 
		  	 				     } ?>
  	 				          </table>
  	 				         </td>
  	 				        </tr>
  	 				        <?php if($spack_id==-1 && $suport_pack_list_num_rows>MAX_DISPLAY_SEARCH_RESULTS){ ?>
  	 				        <tr>
							  <td align="right" colspan="3">
								<table border="0" cellspacing="0" cellpadding="2">
									<tr> 
										<td class="smallText" align="left"><?php  echo $support_split->display_script_links($suport_pack_list_num_rows, MAX_DISPLAY_SEARCH_RESULTS, REPORT_MAX_LINKS_PAGE, $page,'','page_navigation(\'product_navigation\'','1'); ?></td>
									</tr>
								</table>
							 </td>
							</tr>										
 					 <?php } 
 					 	}else { ?>
	 				       <tr>
	 				          	<td colspan="3" class="main" align="center"><?php echo RESULT_NOT_FOUND;?></td>
	 				       </tr>
 				 <?php  } ?>
      </table>
 <?php } ?>