<?php

	include ("inc.all.php");
	
	$q=new Cdb;
	
		
	$t->set_file("content", "template.ads.htm");
	$t->set_file("ads_row", "template.ads_row.html");
	if ($_GET['err'] == 1){
		$t->set_var('error',"<tr><td align='center'><b style='color:red'>You must fill in your name and email!</b></td></tr>");
	}elseif ($_GET['err'] == 2){
		$t->set_var('error',"<tr><td align='center'><b style='color:red'>You must fill in both name and email!</b></td></tr>");
	}elseif ($_GET['err'] == 3){
		$t->set_var('error',"<tr><td align='center'><b style='color:red'>Some of the emails match each other!</b></td></tr>");
	}else{
		$t->set_var('error',"");
	}

	$member_id= $_GET['mid'];
	
	$q->query("SELECT aff_url FROM members WHERE id='".$member_id."'");

	$q->next_record();
	$aff_link = $q->f("aff_url");
	
	$q->query("SELECT * FROM campaigns WHERE member_id='$member_id' AND id='".$_GET['id']."'");
	$q->next_record();

	$t->set_var("url",get_setting("site_full_url"));
	
	$t->set_var("campaign_id",$_GET['id']);
	$t->set_var("mid",$_GET['mid']);
	$t->set_var("min_fields",$q->f("mandatory_number_of_friends"));
	$t->set_var("fields",$q->f("number_of_friends"));
	if ($q->f("use_reward_email_just_taf") == 1 && $q->f("warn_members_if_no_qualify1") == 1)
		$t->set_var("min_gift_email",$q->f("number_of_friends_to_qualify_bonus1"));
	else 
		$t->set_var("min_gift_email","-1");
	
	if ($q->f("allow_members_to_edit_emails") == 0){
		$t->set_var("readonly_mail", "readonly");
	}
	if ($q->f("bypass_link")){
		preg_match("'^http.*'",$q->f("landing_page"),$match);
		
		$t->set_var("bypass_link", "
		<tr>
  			<td align=\"center\"><a href='".($match[0] ? $q->f("landing_page") : "http://".$q->f("landing_page"))."' onclick='return confirm(\"Are you sure you want to leave without submiting?\")>".$q->f("bypass_link_text")."</a></td>
  		</tr>");
	}
	if ($q->f("allow_members_to_enter_preciding_note") == 1){
		$t->set_var("preceding_note", "<input type='text' size='50' name='note' id='note' value='Enter your preceding note here'>");
	}else{
		$t->set_var("preceding_note","");
	}	
	
	$body_match = "";
	$t->set_var("subject",$q->f("invitation_email_subject"));	
	
	
	$message = $q->f("invitation_email_body");
	$message = str_replace("[[sitename]]",$q->f("website_name"),$message);
	$message = str_replace("[[link]]",$q->f("link"),$message);
	$t->set_var("body",$message);	
	for ($i=1; $i<=$q->f("number_of_friends");$i++){
		$t->set_var("id",$i);
		$t->parse("adds_row", "ads_row",true);
	}
	if ($q->f("use_aff_link")){
		$t->set_var("aff_link","<tr><td colspan='3'><a href='$aff_link' target='_blank'>$aff_link</a></td></tr>");
	}
	
include("inc.bottom_taf.php");

?>