<?php 


// Check to ensure this file is included in Freeway!
defined('_FEXEC') or die();?>
<table border="0" WIDTH="100%" cellspacing="0" cellpadding="<?php echo CELLPADDING_SUB; ?>">
<?php
// BOF: Lango Added for template MOD
if (SHOW_HEADING_TITLE_ORIGINAL == 'yes') {
$header_text = '&nbsp;'
//EOF: Lango Added for template MOD
?>
      <tr>
        <td><table border="0" width="100%" cellspacing="0" cellpadding="0">
          <tr>
            <td class="pageHeading"><?php echo HEADING_TITLE; ?></td>
            <td align="right"><?php echo tep_image(DIR_WS_IMAGES . 'table_background_specials.gif', HEADING_TITLE, HEADING_IMAGE_WIDTH, HEADING_IMAGE_HEIGHT); ?></td>
          </tr>
        </table></td>
      </tr>
<?php
// BOF: Lango Added for template MOD
}else{
$header_text = HEADING_TITLE;
}
// EOF: Lango Added for template MOD
?>
<?php
// BOF: Lango Added for template MOD
if (MAIN_TABLE_BORDER == 'yes'){
table_image_border_top(false, false, $header_text);
}
// EOF: Lango Added for template MOD
?>
          <tr>
            <td class="main" colspan=2><?php echo TEXT_INFORMATION; ?></td>
          </tr>

      <tr>
        <td><table width="100%" border="0" cellspacing="0" cellpadding="2">
          <tr>
            <td class="infoBoxHeading" align="center"><?php echo TEXT_AFFILIATE_INDIVIDUAL_BANNER . ' ' . $affiliate_banners['affiliate_banners_title']; ?></td>
          </tr>
		  <?php echo tep_draw_form('individual_banner', tep_href_link(FILENAME_AFFILIATE_BANNERS),'post',' onSubmit="return ValidateForm();"'). tep_draw_hidden_field('individual_banner_id') ;?>
         <!-- <tr height="40">
            <td class="smallText" align="center"><?php //echo tep_draw_form('individual_banner', tep_href_link(FILENAME_AFFILIATE_BANNERS) ) . TEXT_AFFILIATE_INDIVIDUAL_BANNER_INFO . tep_draw_input_field('individual_banner_id', '', 'size="5"') . "&nbsp;&nbsp;" . tep_template_image_submit('button_affiliate_build_a_link.gif', IMAGE_BUTTON_BUILD_A_LINK,'align=absmiddle') . "</form>"; ?></td>
          </tr> -->
		<?php   $products_array=tep_get_products_array_single();
		  $events_array=tep_get_events_array_single();
		  $subscriptions_array=tep_get_subscription_array_single();
		  $services_array=tep_get_service_array_single();
		  ?>
		  <tr>
		  	<td>
				<table cellpadding="0" cellspacing="2" border="0" width="100%">
				  <tr>
				  	<td class="smallText" width="150"><?php echo '<b>' . TEXT_CATEGORY . '</b>';?></td>
					<td><table cellpadding="0" cellspacing="0" border="0" width="100%">
						<tr>
						  <td class="smallText"><?php echo tep_draw_radio_field('chk_option','P','','onClick=javascript:do_action();') . TEXT_PRODUCTS;?></td>
						  <td class="smallText"><?php echo tep_draw_radio_field('chk_option','E','','onClick=javascript:do_action();') . TEXT_EVENTS;?></td>
						  <td class="smallText"><?php echo tep_draw_radio_field('chk_option','S','','onClick=javascript:do_action();'). TEXT_SUBSCRIPTIONS?></td>
						  <td class="smallText"><?php echo tep_draw_radio_field('chk_option','V','','onClick=javascript:do_action();') . TEXT_SERVICES;?></td>
				 		 </tr>	
						</table>
					</td>
				  </tr>		
				  <tr><td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif','10','5');?></td></tr>
				  <tr>
				  	<td class="smallText" id="select" style="display:none" width="150"><?php echo '<b>' . TEXT_SELECT_CATEGORIES . '</b>';?> </td>
					<td class="smallText">
						<span  id="products" style="display:none"><?php echo tep_draw_product_select_menu('cmb_products',$products_array,'');?></span>
						<span id="events" style="display:none"><?php echo tep_draw_event_select_menu('cmb_events',$events_array,'');?></span>
						<span  id="subscriptions" style="display:none"><?php echo tep_draw_subscription_select_menu('cmb_subscriptions',$subscriptions_array,'') ;?></span>
						<span  id="services" style="display:none"><?php echo tep_draw_service_select_menu('cmb_services',$services_array,'');?></span>
					</td>
				</tr>		
				  <tr><td><?php echo tep_draw_separator('pixel_trans.gif','10','5');?></td></tr>
				  <tr>
				  	<td align="right" colspan="2"><?php echo tep_template_image_submit('button_affiliate_build_a_link.gif', IMAGE_BUTTON_BUILD_A_LINK,' align=absmiddle') . "</form>"?></td>
				  </tr>
				 </table>
				</td>
			</tr>	  
<?php
  if (tep_not_null($HTTP_POST_VARS['individual_banner_id']) || tep_not_null($HTTP_GET_VARS['individual_banner_id'])) {

    if (tep_not_null($HTTP_POST_VARS['individual_banner_id'])) $individual_banner_id = tep_db_prepare_input($HTTP_POST_VARS['individual_banner_id']);
    if ($HTTP_GET_VARS['individual_banner_id']) $individual_banner_id = tep_db_prepare_input($HTTP_GET_VARS['individual_banner_id']);
	
	switch ($HTTP_POST_VARS['chk_option']){
		case 'P':
    		$affiliate_pbanners_values = tep_db_query("select p.products_image_1 as image,p.products_title_1 as title,pd.products_name as name from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_id = '" . $individual_banner_id . "' and pd.products_id = '" . $individual_banner_id . "' and p.products_status = '1' and pd.language_id = '" . $languages_id . "'");
			$filename= FILENAME_PRODUCT_INFO;
			$params='&products_id=' . $individual_banner_id ;
		break;
		case 'E':
    		$affiliate_pbanners_values = tep_db_query("select e.events_image as image,ed.events_name as name from " . TABLE_EVENTS . " e, " . TABLE_EVENTS_DESCRIPTION . " ed where e.events_id = '" . $individual_banner_id . "' and ed.events_id = '" . $individual_banner_id . "' and e.events_status = '1' and ed.language_id = '" . $languages_id . "'");
			$filename= FILENAME_SESSION_DETAILS;
			$params='&events_id=' . $individual_banner_id ;
		break;
		case 'S':
    		$affiliate_pbanners_values = tep_db_query("select s.subscription_image as image ,sd.subscription_name as name  from " . TABLE_SUBSCRIPTIONS . " s, " . TABLE_SUBSCRIPTIONS_DESCRIPTION . " sd where s.subscription_id = '" . $individual_banner_id . "' and sd.subscription_id = '" . $individual_banner_id . "' and s.subscription_status = '1' and sd.language_id = '" . $languages_id . "'");
			$filename= FILENAME_SUBSCRIPTION_INFO;
			$params='&subscription_id=' . $individual_banner_id ;
		break;
		case 'V':
    		$affiliate_pbanners_values = tep_db_query("select s.service_image as image,sd.service_name as name from " . TABLE_SERVICES . " s, " . TABLE_SERVICES_DESCRIPTION . " sd where s.service_id = '" . $individual_banner_id . "' and sd.service_id = '" . $individual_banner_id . "' and s.service_status = '1' and sd.language_id = '" . $languages_id . "'");
			$filename= FILENAME_SERVICES_INFO;
			$params='&service_id=' . $individual_banner_id ;
		break;
	}

  //  $affiliate_pbanners_values = tep_db_query("select p.products_image_1,p.products_title_1,pd.products_name from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_id = '" . $individual_banner_id . "' and pd.products_id = '" . $individual_banner_id . "' and p.products_status = '1' and pd.language_id = '" . $languages_id . "'");
    if ($affiliate_pbanners = tep_db_fetch_array($affiliate_pbanners_values)) {
      switch (AFFILIATE_KIND_OF_BANNERS) {
       case 1:
			if($affiliate_pbanners['image'] !='' && (file_exists(DIR_FS_CATALOG . DIR_WS_IMAGES . "small/" .$affiliate_pbanners['image']) || file_exists(DIR_WS_HTTP_CATALOG .  DIR_WS_IMAGES . "big/" .$affiliate_pbanners['image']) || file_exists(DIR_WS_IMAGES . $affiliate_pbanners['image'])))
         		$link = '<a href="' . tep_href_link($filename . '?ref=' . $affiliate_id . $params . '&affiliate_banner_id=1') . '" target="_blank">' . (($HTTP_POST_VARS['chk_option']=='P') ? tep_product_small_image($affiliate_pbanners['image'],$affiliate_pbanners['title']): tep_info_image($affiliate_pbanners['image'],$affiliate_pbanners['name'],'100', '80')) . '</a>';
			else
				$link = '<a href="' . tep_href_link($filename . '?ref=' . $affiliate_id . $params . '&affiliate_banner_id=1'). '" target="_blank">' .(($HTTP_POST_VARS['chk_option']=='P')?$affiliate_pbanners['title']:$affiliate_pbanners['name']) . '</a>'; 
          break;
        case 2: // Link to Products
          $link = '<a href="' .tep_href_link($filename . '?ref=' . $affiliate_id .$params . '&affiliate_banner_id=1') .'" target="_blank"><img src="' . HTTP_SERVER . DIR_WS_HTTP_CATALOG . FILENAME_AFFILIATE_SHOW_BANNER . '?ref=' . $affiliate_id . '&affiliate_pbanner_id=' . $individual_banner_id . '" border="0" alt="' . $affiliate_pbanners['name'] . '"></a>';
          break;
      }
    }
?>
          <tr>
            <td class="smallText" align="center"><br><?php echo $link; ?></td>
          </tr>
          <tr>
            <td class="smallText" align="center"><?php echo TEXT_AFFILIATE_INFO; ?></td>
          </tr>
          <tr>
            <td align="center"><?php echo tep_draw_textarea_field('affiliate_banner', 'soft', '60', '6', $link); ?></td>
          </tr>
<?php
  }
?>
        </table></td>
      </tr>
<?php
  if (tep_db_num_rows($affiliate_banners_values)) {

    while ($affiliate_banners = tep_db_fetch_array($affiliate_banners_values)) {
		$products_type=$affiliate_banners['affiliate_products_type'];
		if($products_type=='') $products_type='P';
		switch ($products_type){
			case 'P':
    		    $affiliate_products_query = tep_db_query("select products_name as name from " . TABLE_PRODUCTS_DESCRIPTION . " where products_id = '" . $affiliate_banners['affiliate_products_id'] . "' and language_id = '" . $languages_id . "'");
				$filename=FILENAME_PRODUCT_INFO;
				$params='&products_id=';
			break;
			case 'E':
     		    $affiliate_products_query = tep_db_query("select events_name as name from " . TABLE_EVENTS_DESCRIPTION . " where events_id = '" . $affiliate_banners['affiliate_products_id'] . "' and language_id = '" . $languages_id . "'");
				$filename=FILENAME_SESSION_DETAILS;
				$params = '&events_id=';
			break;
			case 'S':
      			$affiliate_products_query = tep_db_query("select subscription_name as name from " . TABLE_SUBSCRIPTIONS_DESCRIPTION . " where subscription_id = '" . $affiliate_banners['affiliate_products_id'] . "' and language_id = '" . $languages_id . "'");
				$filename=FILENAME_SUBSCRIPTION_INFO;
				$params = '&subscription_id=';
			break;
			case 'V':
      			$affiliate_products_query = tep_db_query("select service_name as name from " . TABLE_SERVICES_DESCRIPTION . " where service_id = '" . $affiliate_banners['affiliate_products_id'] . "' and language_id = '" . $languages_id . "'");
				$filename=FILENAME_SERVICES_INFO;
				$params = '&service_id=';
			break;
		}
     // $affiliate_products_query = tep_db_query("select products_name from " . TABLE_PRODUCTS_DESCRIPTION . " where products_id = '" . $affiliate_banners['affiliate_products_id'] . "' and language_id = '" . $languages_id . "'");
      $affiliate_products = tep_db_fetch_array($affiliate_products_query);
      $prod_id = $affiliate_banners['affiliate_products_id'];
      $ban_id = $affiliate_banners['affiliate_banners_id'];
	  
      switch (AFFILIATE_KIND_OF_BANNERS) {
        case 1: // Link to Products
		$ext= substr($affiliate_banners['affiliate_banners_image'],(strlen($affiliate_banners['affiliate_banners_image'])-4),4); 
          if ($prod_id > 0) { 
		  	if($affiliate_banners['affiliate_banners_image']!='' && file_exists(DIR_WS_IMAGES . $affiliate_banners['affiliate_banners_image'])){
	            $link = '<a href="' . tep_href_link( $filename , 'ref=' . $affiliate_id . $params . $prod_id . '&affiliate_banner_id=' . $ban_id) . '" target="_blank" >';
				if(strtolower($ext) == '.swf') {
					if($affiliate_banners['flash_banner']=='Y'){
						$banner_width=$affiliate_banners['affiliate_flash_banner_width'];
						$banner_height=$affiliate_banners['affiliate_flash_banner_height'];
					} else { 	$banner_width='728'; $banner_height='90'; }
 			$link .='<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" id="flashLayer" WIDTH="'. $banner_width .'" HEIGHT="'.$banner_height.'" VALIGN="TOP" style="z-index:10;">
				<PARAM NAME=movie VALUE="'.HTTP_SERVER.DIR_WS_HTTP_CATALOG.DIR_WS_IMAGES.$affiliate_banners['affiliate_banners_image'] .'"> 
				<PARAM NAME=quality VALUE=high> 
				<PARAM NAME=bgcolor VALUE=#C6C5CA> 
				<PARAM NAME=wmode VALUE="transparent">'.
					'<EMBED src="'. HTTP_SERVER.DIR_WS_HTTP_CATALOG.DIR_WS_IMAGES. $affiliate_banners['affiliate_banners_image'] . '" quality=high bgcolor=#C6C5CA  wmode="transparent"  WIDTH="'.$banner_width.'" HEIGHT="'.$banner_height.'" VALIGN="TOP" id="flashLayer"  flashvars="__yamzbrowser=window.navigator.appName" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"></EMBED>';
			 $link .='</OBJECT>';				
				}else 						
					$link .= '<img src="' . HTTP_SERVER.DIR_WS_HTTP_CATALOG.DIR_WS_IMAGES . $affiliate_banners['affiliate_banners_image'] . '" border="0" alt="' . $affiliate_products['name'] . '" width="100" height="80"></a>';
			}else
				$link = '<a href="' . tep_href_link($filename . '?ref=' . $affiliate_id . $params . $prod_id . '&affiliate_banner_id=' . $ban_id ). '" target="_blank">' . $affiliate_products['name'] . '</a>';	
          } else { // generic_link
		  	if($affiliate_banners['affiliate_banners_image']!='' && file_exists(DIR_WS_IMAGES . $affiliate_banners['affiliate_banners_image'])){
		        $link = '<a href="' .tep_href_link(FILENAME_DEFAULT . '?ref=' . $affiliate_id . '&affiliate_banner_id=' . $ban_id ). '" target="_blank">';
				if(strtolower($ext) == '.swf') {
					if($affiliate_banners['flash_banner']=='Y'){
						$banner_width=$affiliate_banners['affiliate_flash_banner_width'];
						$banner_height=$affiliate_banners['affiliate_flash_banner_height'];
					} else { $banner_width='728'; $banner_height='90'; }					
 			 $link .='<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"  codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" id="flashLayer" WIDTH="'. $banner_width . '" HEIGHT="' . $banner_height .'" VALIGN="TOP" style="z-index:10;">
				<PARAM NAME=movie VALUE="'.HTTP_SERVER.DIR_WS_HTTP_CATALOG.DIR_WS_IMAGES.$affiliate_banners['affiliate_banners_image'] .'"> 
				<PARAM NAME=quality VALUE=high> 
				<PARAM NAME=bgcolor VALUE=#C6C5CA> 
				<PARAM NAME=wmode VALUE="transparent">'.
				'<EMBED src="'.HTTP_SERVER.DIR_WS_HTTP_CATALOG.DIR_WS_IMAGES.$affiliate_banners['affiliate_banners_image'] . '" quality=high bgcolor=#C6C5CA  wmode="transparent"  WIDTH="' . $banner_width .'" HEIGHT="' . $banner_height . '" VALIGN="TOP" id="flashLayer" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"></EMBED>';
			 $link .='</OBJECT>';				
				}	else
				$link .='<img src="' . HTTP_SERVER.DIR_WS_HTTP_CATALOG.DIR_WS_IMAGES . $affiliate_banners['affiliate_banners_image'] . '" border="1" alt="' . $affiliate_banners['affiliate_banners_title'] . '"  width="100" height="80"></a>';
			}else
				$link = '<a href="' . tep_href_link(FILENAME_DEFAULT . '?ref=' . $affiliate_id . '&affiliate_banner_id=' . $ban_id) . '" target="_blank">' .  $affiliate_banners['affiliate_banners_title'] . '</a>';	
          }
          break;
        case 2: // Link to Products
          if ($prod_id > 0) {
            $link = '<a href="' . tep_href_link($filename . '?ref=' . $affiliate_id . $params . $prod_id . '&affiliate_banner_id=' . $ban_id) . '" target="_blank"><img src="' . HTTP_SERVER . DIR_WS_HTTP_CATALOG . FILENAME_AFFILIATE_SHOW_BANNER . '?ref=' . $affiliate_id . '&affiliate_banner_id=' . $ban_id . '" border="1" alt="' . $affiliate_products['name'] . '  width="100" height="80"></a>';
          } else { // generic_link
            $link = '<a href="' . tep_href_link(FILENAME_DEFAULT . '?ref=' . $affiliate_id . '&affiliate_banner_id=' . $ban_id ). '" target="_blank"><img src="' . HTTP_SERVER . DIR_WS_HTTP_CATALOG . FILENAME_AFFILIATE_SHOW_BANNER . '?ref=' . $affiliate_id . '&affiliate_banner_id=' . $ban_id . '" border="1" alt="' . $affiliate_banners['affiliate_banners_title'] . '  width="100" height="80"></a>';
          }
          break;
      }
?>
      <tr>
        <td><table width="100%" border="0" cellspacing="0" cellpadding="2">
          <tr>
            <td class="infoBoxHeading" align="center"><?php echo TEXT_AFFILIATE_NAME . ' ' . $affiliate_banners['affiliate_banners_title']; ?></td>
          </tr>
          <tr>
            <td class="smallText" align="center"><br><?php echo $link; ?></td>
          </tr>
          <tr>
            <td class="smallText" align="center"><?php echo TEXT_AFFILIATE_INFO; ?></td>
          </tr>
          <tr>
            <td class="smallText" align="center"><?php echo tep_draw_textarea_field('affiliate_banner', 'soft', '60', '6', $link); ?></td>
          </tr>
        </table></td>
      </tr>
<?php
    }
  }
?>
<?php
// BOF: Lango Added for template MOD
if (MAIN_TABLE_BORDER == 'yes'){
table_image_border_bottom();
}
// EOF: Lango Added for template MOD
?>
      <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '20'); ?></td>
      </tr>
    </table>
	<script>
function do_action(){
	var type=document.individual_banner.chk_option;
	for(i=0;i<type.length;i++){
		if(type[i].checked){
			document.individual_banner.cmb_products.value=-1;
			document.individual_banner.cmb_events.value=-1;
			document.individual_banner.cmb_subscriptions.value=-1;
			document.individual_banner.cmb_services.value=-1;
			document.getElementById('select').style.display="";
			switch (type[i].value){
				case 'P':
					document.getElementById('products').style.display="";
					document.getElementById("events").style.display="none";
					document.getElementById("subscriptions").style.display="none";
					document.getElementById("services").style.display="none";
				break;
				case 'E':
					document.getElementById('products').style.display="none";
					document.getElementById("events").style.display="";
					document.getElementById("subscriptions").style.display="none";
					document.getElementById("services").style.display="none";
				break;
				case 'S':
					document.getElementById('products').style.display="none";
					document.getElementById("events").style.display="none";
					document.getElementById("subscriptions").style.display="";
					document.getElementById("services").style.display="none";
				break;
				case 'V':
					document.getElementById('products').style.display="none";
					document.getElementById("events").style.display="none";
					document.getElementById("subscriptions").style.display="none";
					document.getElementById("services").style.display="";
				break;
			}
		}
	}
}

function ValidateForm(){
var type=document.individual_banner.chk_option;
var error='';
var flag= false;
	for(i=0;i<type.length;i++){
		if(type[i].checked){ flag=true;
			switch (type[i].value) {
				case 'P':
					document.individual_banner.individual_banner_id.value=document.individual_banner.cmb_products.value;
					if(document.individual_banner.cmb_products.value==-1)
						error='<?php echo ERR_SELECT_PRODUCTS;?>';
					break;
				case 'E':
					document.individual_banner.individual_banner_id.value=document.individual_banner.cmb_events.value;
					if(document.individual_banner.cmb_events.value==-1)
						error='<?php echo ERR_SELECT_EVENTS;?>';
					break;
				case 'S':
					document.individual_banner.individual_banner_id.value=document.individual_banner.cmb_subscriptions.value;
					if(document.individual_banner.cmb_subscriptions.value==-1)
						error='<?php echo ERR_SELECT_SUBSCRIPTIONS;?>';
					break;
				case 'V':
					document.individual_banner.individual_banner_id.value=document.individual_banner.cmb_services.value;
					if(document.individual_banner.cmb_services.value==-1)
						error='<?php echo ERR_SELECT_SERVICES;?>';
					break;
			} //alert(document.individual_banner.individual_banner_id.value);
			//type[i].checked=false;
			if(error!=''){
				alert(error);
				return false;
			}	
			else 
				return;
		}
	}	
	if(flag==false){
		alert('<?php echo ERR_SELECT_CATEGORY;?>');
		return false;
	}
	return true;
}
var type=document.individual_banner.chk_option;
	for(i=0;i<type.length;i++){
		type[i].checked=false;
	}	
</script>	

