<?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');  
  tep_get_last_access_file();
  
    $query=tep_db_query("select * from " . TABLE_CONFIGURATION_GROUP . " where lower(configuration_access_key)='" . strtolower($CONFIG_ACCESS_KEY) . "'");
  $result=tep_db_fetch_array($query);
  
  $config_commission_query = tep_db_query("select * from " . TABLE_CONFIGURATION . " where configuration_key='AFFILIATE_COMMISSION_JUNCTION'");
  $config_commission_result=tep_db_fetch_array($config_commission_query);
  
  $config_enterprise_query = tep_db_query("select * from " . TABLE_CONFIGURATION . " where configuration_key='AFFILIATE_ENTERPRISE_ID'");
  $config_enterprise_result=tep_db_fetch_array($config_enterprise_query);
  
 
  
  $config_action_query=tep_db_query("select * from " . TABLE_CONFIGURATION . " where configuration_key='AFFILIATE_ACTION_ID'");
  $config_action_result= tep_db_fetch_array($config_action_query); 

  
	 $command=(isset($HTTP_GET_VARS['command'])?$HTTP_GET_VARS['command']:'');
	 if($command!=''){
	 	echo $command . '||' ;
	 	switch($command){
			case 'get_detail':
				echo do_get_details();
			break;
			case 'save' :
				  $EID=(isset($HTTP_POST_VARS['EID'])?$HTTP_POST_VARS['EID']:'');
				  $AID=(isset($HTTP_POST_VARS['AID'])?$HTTP_POST_VARS['AID']:'');
				  $commission=(isset($HTTP_POST_VARS['chk_commission'])?$HTTP_POST_VARS['chk_commission']:'false');
				
				tep_db_query("update " . TABLE_CONFIGURATION . " set configuration_value='" . $commission. "' where configuration_key='AFFILIATE_COMMISSION_JUNCTION'");
				tep_db_query("update " . TABLE_CONFIGURATION . " set configuration_value='" . $EID. "' where configuration_key='AFFILIATE_ENTERPRISE_ID'");
				tep_db_query("update " . TABLE_CONFIGURATION . " set configuration_value='" . $AID. "' where configuration_key='AFFILIATE_ACTION_ID'");
				echo '<a>'. $commission . '</a>';
			break;
		}
		exit;
	 }

 
  $action=(isset($HTTP_GET_VARS['action'])?$HTTP_GET_VARS['action']:'');
  $EID=(isset($HTTP_POST_VARS['EID'])?(int)$HTTP_POST_VARS['EID']:'');
  $AID=(isset($HTTP_POST_VARS['AID'])?(int)$HTTP_POST_VARS['AID']:'');
  $commission=(isset($HTTP_POST_VARS['chk_commission'])?$HTTP_POST_VARS['chk_commission']:'false');

  if($action=='update'){
  	tep_db_query("update " . TABLE_CONFIGURATION . " set configuration_value='" . $commission. "' where configuration_key='AFFILIATE_COMMISSION_JUNCTION'");
	tep_db_query("update " . TABLE_CONFIGURATION . " set configuration_value='" . $EID. "' where configuration_key='AFFILIATE_ENTERPRISE_ID'");
	tep_db_query("update " . TABLE_CONFIGURATION . " set configuration_value='" . $AID. "' where configuration_key='AFFILIATE_ACTION_ID'");
  }
  ?>
<!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/menu.js"></script>
<script language="javascript" src="includes/general.js"></script>
<script language="javascript" src="includes/http.js"></script>
<script language="javascript">	

 function ValidateForm(){ 
 	var error='';
	
	var len=document.commission.chk_commission.length;
	
	for(i=0;i<len;i++){ 
		if(document.commission.chk_commission[i].checked ){
			if(document.commission.chk_commission[i].value=='true'){
				if( (document.commission.EID.value=='') || (str_trim(document.commission.EID.value)=="") ){
					error='<?php echo ERR_EMPTY_FIELDS;?>';
				}
				if( (document.commission.AID.value=='') || (str_trim(document.commission.AID.value)=="") ){
					error='<?php echo ERR_EMPTY_FIELDS;?>';
				} 
				if(error!=''){
					alert(error);
					return false;
				} 
			}	
		}	
	}
	return true;	
 }
 
 function checkform(){
 	if(ValidateForm()){
		do_page_fetch('save');
	}
		return false;
 }
 
 function do_page_fetch(action){
 var command='';
 	switch (action){
		case 'get_detail':
			//document.getElementById('head').style.display="none";
			
			
			document.getElementById('config_value').innerHTML=document.getElementById('loading').innerHTML;
			command='<?php echo tep_href_link(FILENAME_MARKETING_AFFILIATE_COMMISSION);?>' + '?command=' + action;
		
		break;
		case 'close':
			document.getElementById("data").style.display="none";
			document.getElementById("data").innerHTML="";
			document.getElementById('head').style.display="";
			document.getElementById('config_value').innerHTML='<?php echo '<a>' . $config_commission_result['configuration_value'] . '</a>';?>';
			return;
		break;	
		case 'save'	:
			 var command='';
			 
			command='<?php echo tep_href_link(FILENAME_MARKETING_AFFILIATE_COMMISSION);?>' + '?command=save';
			do_post_command('commission',command);
			return;
		break;
	}
	do_get_command(command);
 }
 
 function do_result(result){
 	var splt_arr=Array();
	splt_arr=result.split('||'); 
	switch(splt_arr[0]){
		case 'get_detail':
		document.getElementById('head').style.display="none";
		document.getElementById('data').style.display="";
			document.getElementById('data').innerHTML=splt_arr[1];
		break;
		case 'save':
			document.getElementById('data').style.display="none";
			document.getElementById('head').style.display="";
			//document.getElementById('config_title').innerHTML=splt_arr[1];
			document.getElementById('config_value').innerHTML=splt_arr[1];
		break;
	}
 }
 function do_action(){ 
 	var len=document.commission.chk_commission.length;
	for(i=0;i<len;i++){
		if(document.commission.chk_commission[i].checked){
			if(document.commission.chk_commission[i].value=='true'){
				document.getElementById('commissions').style.display="";
			}
			else {
				document.commission.AID.value='';
				document.commission.EID.value='';
				document.getElementById('commissions').style.display="none";
				//document.getElementById('commission_details').style.display="none";
			}
		}
	}
 }
 
</script>
</head>
<body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0" bgcolor="#FFFFFF" onLoad="SetFocus();" >
<script language="javascript" src="includes/popup.js" ></script>
<script>
				var baby=new Array();
				baby[1]="";
				var cEvent=0;
function popupWindow(action){
var contentText; 
	switch(action){ 
		case '1':
			contentText='<?php echo INFO_ENTERPRISE_ID;?>';
			break;
		case '2':
			contentText='<?php echo INFO_ACTION_ID;?>';
			break;
		case '3':
			contentText='<?php echo $config_commission_result['configuration_description'];?>';
			break;	
	}
					content='<table border="0" cellspacing="0" class="tableArea" cellpadding="4" width="100%"><tr><td class=smallText>';
					content+=contentText;
					content+='</td></tr></table>';
					popwidth=250;
					baby[1]=content;
					if (baby[1]!="")
					{
						popup("1","#ffffff");
					}	
}


</script>
<!-- header //-->
<?php 
require(DIR_WS_INCLUDES . 'header.php'); ?>

<!-- header_eof //-->

<!-- body //-->
<table border="0" width="100%" cellspacing="2" cellpadding="2" onMouseOut="javascript:clearTimeout(1)" >
	<tr >
<!-- body_text //-->
		<td width="100%" valign="top">
			<table  border="0" width="100%" cellspacing="0" cellpadding="2" >  
				<tr>            
					<td class='config_title_line'>
						<?php //echo tep_draw_form('commission','marketing_affiliate_commission.php?action=update','','post','onSubmit="return ValidateForm();"')
								echo tep_draw_form('commission',FILENAME_MARKETING_AFFILIATE_COMMISSION,'','post','onSubmit="return checkform();"')
						?>
						<table border="0" width="100%" cellspacing="5" cellpadding="2">		
							<tr>
								<td class="pageHeading" colspan="2"><?php echo HEADING_AFFILIATE_COMMISSION;?></td>
							</tr>	

							<div id="loading" style="display:none"><div style="height:30px;margin-left:30px"><img src="images/24-1.gif"></div></div>
							<tr style="cursor:hand;cursor:pointer" height="25"  onClick="javascript:if(document.getElementById('data').style.display=='none') do_page_fetch('get_detail');">
									<td><div id="head" onMouseOver="popupWindow('3');"  onMouseOut="javascript:kill();">	
										<?php commission_details();?>
									</div><span id="data" style="display:none"></span>	
									</td>
								</tr>		
							<tr>
								<td width="10" height="10" colspan="2"></td>
							</tr>	    
						</table>		
						</form>
					</td>
				</tr>
			</table> 	   
		</td>
<!-- body_text_eof //-->
	</tr>
</table>
<script>
	<?php if($config_commission_result['configuration_value']=='false'){?>
	//document.getElementById('chk_commission').checked=false;
	//document.getElementById('commission').style.display="none";
	<?php } else {?>
	//document.getElementById('commission').style.display="";
	<?php } ?>
</script>
<!-- body_eof //-->
<!-- footer //-->
<?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
<!-- footer_eof //-->
</body>
</html>
<?php require(DIR_WS_INCLUDES . 'application_bottom.php'); 

function commission_details(){ 
global $config_enterprise_result,$config_commission_result;
?>
	
				<table cellpadding="3" cellspacing="3" width="100%" border="0">
					<tr class='config_title' id="config_title">
						<td><?php echo $config_commission_result['configuration_title'];?></td>
					</tr>	
					<tr class='config_title'>
						<td id="config_value"><?php echo '<a>' . $config_commission_result['configuration_value'] . '</a>';?></td>
					</tr>
				</table>	
<?php }

function do_get_details(){ 
	global $config_enterprise_result,$config_commission_result,$config_action_result;
?>
		<table cellpadding="0" cellspacing="5" width="50%" border="0" class="config_box">
			<tr class='config_title'>
				<td><?php echo $config_commission_result['configuration_title'];?></td>
			</tr>	
			<tr class='config_title' >
				<td><?php echo tep_draw_radio_field('chk_commission','true',(($config_commission_result['configuration_value']=='true')?true:false),'','onClick="javascript:do_action(this);"') . tep_draw_separator('pixel_trans.gif','10','10') . TEXT_TRUE .tep_draw_separator('pixel_trans.gif','10','10');
				echo tep_draw_radio_field('chk_commission','false',(($config_commission_result['configuration_value']=='false')?true:false),'','onClick="javascript:do_action(this);"') . tep_draw_separator('pixel_trans.gif','10','10') . TEXT_FALSE.tep_draw_separator('pixel_trans.gif','10','10');
				?></td>
			</tr>
			<?php /*if(($config_commission_result['configuration_value']=='true')){?>
			<tr id="commission_details">
				<td>
						<table cellpadding="0" cellspacing="0" border="1" width="50%">
							<tr><td height="10" colspan="4"></td></tr>
							<tr><td class="main" width="50"><?php echo $config_enterprise_result['configuration_title'] . ': ';?></td><td width="30" class="main"><?php echo $config_enterprise_result['configuration_value'];?></td>
								<td class="main" width="50"><?php echo $config_action_result['configuration_title'] . ': ';?></td><td width="30" class="main"><?php echo $config_action_result['configuration_value'];?></td>
							</tr>
						</table>
				</td>
			</tr>					
			<?php }*/?>
			<?php if(($config_commission_result['configuration_value']=='true'))
						$style="style=display:";
					else 
						$style="style=display:none"	;
			?>
			<tr>
				<td><div id="commissions" <?php echo $style;?>>
					<table cellpadding="0" cellspacing="5" border="0" width="100%">
						<tr>
							<td width="175" class="main"><?php echo $config_enterprise_result['configuration_title']; ?></td>
							<td class="main" width="100"><?php echo tep_draw_input_field('EID',$config_enterprise_result['configuration_value'])?><!--<input type="text" name="EID" value="<?php echo $config_enterprise_result['configuration_value']?>">--></td>
							<td class="dataTableContent"><?php echo '<span onMouseOver="javascript:popupWindow(\'1\')" onMouseOut="javascript:kill();">' . tep_image(DIR_WS_IMAGES. 'icon_info.gif') . '</a>'; ?></td>
						</tr>
						<tr>
							<td width="175" class="main"><?php echo $config_action_result['configuration_title']; ?></td>
							<td class="main" width="100"><?php echo tep_draw_input_field('AID',$config_action_result['configuration_value']);?><!--<input type="text" name="AID" value="<?php echo $config_action_result['configuration_value']?>">--></td>
							<td class="dataTableContent"><?php echo '<span onMouseOver="javascript:popupWindow(\'2\')" onMouseOut="javascript:kill();">' . tep_image(DIR_WS_IMAGES. 'icon_info.gif') . '</a>'; ?></td>
						</tr>
					</table>
					</div>
				</td>
			</tr>	
			<?php //}?>
			<tr>
				<td><table cellpadding="0" cellspacing="0" border="0" width="100%"><tr>
				<td width="450" align="right" id="img_save"><input type="image" src="images/template/img_savel.gif" alt="save" title="save" border="0">&nbsp;&nbsp;<a href="javascript:do_page_fetch('close');"><img src="images/template/img_closel.gif" alt="close" title="close" border="0"></a>&nbsp;&nbsp;</td>
				<td height="10"></td>
			</tr></table></td>	
			</tr>	
				
		</table>	
<?php }
?>

