<?php

include("inc.top.php");
$q=new Cdb;
	$t->set_file("content", "campaign_edit.html");
	get_logged_info();
	$member_id=$q->f("id");
	if ($_GET['err'] == 1){
		$t->set_var('error',"<tr><td align='center'><b style='color:red'>The fields marked with * are mandatory</b></td></tr>");
	}elseif ($_GET['err'] == 2){
		$t->set_var('error',"<tr><td align='center'><b style='color:red'>The number of friends to ask on page is greater than the mandatory number to submit</b></td></tr>");
	}elseif ($_GET['err'] == 3){
		$t->set_var('error',"<tr><td align='center'><b style='color:red'>The number of friends or mandatory friends are not a number</b></td></tr>");
	}else{
		$t->set_var('error',"");
	}

	$q->query("SELECT * FROM campaigns WHERE member_id='$member_id' AND id='".$_GET['id']."'");
	$q->next_record();
	$camp_id=$q->f("id");
	$window_height = 400;
	for ($i=1; $i<=$q->f("number_of_friends");$i++){
		$window_height += 32;
	}
	$t->set_var("w_height", $window_height);

	$t->set_var("id",$q->f("id"));
	$t->set_var("mid",$member_id);
	$t->set_var("sitename_viral",get_setting("site_full_url"));
	$aaa=str_replace('"','&quot;',$q->f("name"));
	$t->set_var("name",stripslashes($aaa) );
	$aaa=str_replace('"','&quot;',$q->f("website_name"));
	$t->set_var("website_name",stripslashes($aaa) );
	$t->set_var("number_of_friends",$q->f("number_of_friends"));
	$t->set_var("mandatory_number_of_friends",$q->f("mandatory_number_of_friends"));
	$t->set_var("submit_name",stripslashes($q->f("submit_name")));
	$t->set_var("gift_url",$q->f("gift_url"));
	$t->set_var("gift_url2",$q->f("gift_url2"));
	$t->set_var("html_text_".$q->f('html_text'),"checked");
	
	$error_captcha="";
	if (function_exists("imagecreate")==0) $error_captcha.="GDI library not installed"; 
	if (function_exists("imagettftext")==0) $error_captcha.="FreeType library not installed";
	$t->set_var("captcha_error",$error_captcha);
	
	if ($q->f('use_reward_email_just_taf') == 1)
		$t->set_var("chck_use_reward_email_just_taf","checked");
	if ($q->f('captcha') == 1)
		$t->set_var("chck_captcha","checked");
	$t->set_var("number_of_friends_to_qualify_bonus1",$q->f("number_of_friends_to_qualify_bonus1"));
	if ($q->f('warn_members_if_no_qualify1') == 1)
		$t->set_var("chck_warn_members_if_no_qualify1","checked");
	$t->set_var("gift_email_subject_line1",stripslashes($q->f("gift_email_subject_line1")));
	$t->set_var("gift_email_body1",stripslashes($q->f("gift_email_body1")));
	if ($q->f('use_joined_bonus') == 1)
		$t->set_var("chck_use_joined_bonus","checked");
	$t->set_var("number_of_friends_to_qualify_bonus2",$q->f("number_of_friends_to_qualify_bonus2"));
	$t->set_var("gift_email_subject_line2",stripslashes($q->f("gift_email_subject_line2")));
	$t->set_var("gift_email_body2",stripslashes($q->f("gift_email_body2")));
	$t->set_var("link",$q->f("link"));
	if ($q->f('enable_link_tracking') == 1)
		$t->set_var("chck_enable_link_tracking","checked");
	$t->set_var("invitation_email_subject",stripslashes($q->f("invitation_email_subject")));
	$t->set_var("invitation_email_body",stripslashes($q->f("invitation_email_body")));
	if ($q->f('include_do_not_email_me_again_link') == 1)
		$t->set_var("chck_include_do_not_email_me_again_link","checked");
	if ($q->f('allow_members_to_edit_emails') == 1)
		$t->set_var("chck_allow_members_to_edit_emails","checked");
	if ($q->f('allow_members_to_enter_preciding_note') == 1)
		$t->set_var("chck_allow_members_to_enter_preciding_note","checked");
	$t->set_var("landing_page",$q->f("landing_page"));
	if ($q->f('send_confirmation_to_sender') == 1)
		$t->set_var("chck_send_confirmation_to_sender","checked");
	$t->set_var("ty_email_subject",stripslashes($q->f("ty_email_subject")));
	$t->set_var("ty_email_body",stripslashes($q->f("ty_email_body")));
	if ($q->f('send_click_notification') == 1)
		$t->set_var("chck_send_click_notification","checked");
	$t->set_var("click_email_subject",stripslashes($q->f("click_email_subject")));
	$t->set_var("click_email_body",stripslashes($q->f("click_email_body")));
	if ($q->f('send_join_notification') == 1)
		$t->set_var("chck_send_join_notification","checked");
	$t->set_var("join_email_subject",stripslashes($q->f("join_email_subject")));
	$t->set_var("join_email_body",stripslashes($q->f("join_email_body")));

	if ($q->f('use_aff_link') == 1)
		$t->set_var("chck_use_aff_link","checked");
	if ($q->f('enable_ip_ban') == 1)
		$t->set_var("enable_ip_ban_chk","checked");
	$t->set_var("nr_tries",$q->f("nr_tries"));
	if ($q->f('bypass_link') == 1)
		$t->set_var("bypass_link_chk","checked");
	$t->set_var("bypass_link_text",stripslashes($q->f("bypass_link_text")));
		
	if ($q->f('subscribe_to_my_arp') == 1)
		$t->set_var("subscribe_to_my_arp_chk","checked");
	
	$t->set_var("arp_email",$q->f("arp_email"));	
	$t->set_var("arp_message_subject",stripslashes($q->f("arp_message_subject")));
	$t->set_var("arp_message_body",stripslashes($q->f("arp_message_body")));
	
	if ($q->f('arp_type') == 1)
		$t->set_var("arp_type1_chk","checked");
	else 
		$t->set_var("arp_type2_chk","checked");
		
	$q->query("SELECT * FROM autoresponder_config WHERE field!='method' AND campaign_id='".$_GET['id']."' AND field != 'first_name' AND field != 'email'");
	$values_arr = array();
	while ($q->next_record()){

		if (strpos($q->f("field"),$_GET['id']."field") === false){
				
		}else{
			preg_match("'\d+(.*)'",$q->f("field"),$match);
			$t->set_var($match[1], $q->f("value"));
			$q->next_record();
			preg_match("'\d+(.*)'",$q->f("field"),$match);
			$t->set_var($match[1], $q->f("value"));
		}
	}

	$q->query("select * from autoresponder_config where field='method' AND campaign_id='".$_GET['id']."'");
	$q->next_record();
//	$first_id = $q->f("id");
	$t->set_var("selected".$q->f("value"),"checked");
	$q->query("select * from autoresponder_config where field='url' AND campaign_id='".$_GET['id']."'");
	$q->next_record();
	$t->set_var("url",$q->f("value"));
	$q->query("select * from autoresponder_config where field='first_name' AND campaign_id='".$_GET['id']."'");
	$q->next_record();
	$t->set_var("first_name",$q->f("value"));
//	$t->set_var("value_name", substr(getdbfields("select_x",$q->f("value")),0,-5));

	$q->query("select * from autoresponder_config where field='email' AND campaign_id='".$_GET['id']."'");
	$q->next_record();
	$t->set_var("email",$q->f("value"));
//	$t->set_var("email_value", substr(getdbfields("select_x",$q->f("value")),0,-5));
	$q->query("SELECT * FROM autoresponder_config WHERE field<>'method' AND field<>'url' AND field<>'first_name' AND field<>'email' AND campaign_id='".$_GET['id']."'");
	
for ($i=1;$i<=10;$i++)
	{
		$q->next_record();
		$t->set_var("field".$i,$q->f("field"));
		//$q->query("SELECT * FROM autoresponder_config WHERE field='value".$i."' AND campaign_id='".$_GET['id']."'");
		//$q->next_record();
		$t->set_var("value".$i,$q->f("value"));
	}
	
	$t->set_var("sitename", SITENAME);

	$t->set_file("main", "main.html");
	
	$t->set_file("menu_html", "member.area.menu.html");
	
	$t->parse("menu", "menu_html");

	$ocontent=$t->parse("page", "content");

	$t->set_var("content", $ocontent);
	
		$t->set_var("down_url","download_taf.php?id=".$camp_id);

	
	$t->pparse("out", "main");	



?>