<?php


include("inc.top.php");
$q=new Cdb;
$q2=new Cdb;
$q3=new Cdb;	
	get_logged_info();
	$member_id=$q->f("id");
	$q2->query("SELECT * FROM campaigns WHERE member_id='$member_id' AND id='".$_GET['id']."'");
	$q2->next_record();
	$camp_id=$q2->f("id");

if ($q2->f('use_reward_email_just_taf')){
	$insert .="
	use_reward_email_just_taf='".$q2->f('use_reward_email_just_taf')."',
	number_of_friends_to_qualify_bonus1='".$q2->f('number_of_friends_to_qualify_bonus1')."',
	warn_members_if_no_qualify1='".$q2->f('warn_members_if_no_qualify1')."',
	gift_email_subject_line1='".addslashes($q2->f('gift_email_subject_line1'))."',
	gift_email_body1='".addslashes($q2->f('gift_email_body1'))."',";
}

if ($q2->f('use_joined_bonus')){
	$insert .="
	number_of_friends_to_qualify_bonus2='".$q2->f('number_of_friends_to_qualify_bonus2')."',
	use_joined_bonus='".$q2->f('use_joined_bonus')."',
	gift_email_subject_line2='".addslashes($q2->f('gift_email_subject_line2'))."',
	gift_email_body2='".addslashes($q2->f('gift_email_body2'))."',";
}

if ($q2->f('send_confirmation_to_sender')){
	$insert .="
	send_confirmation_to_sender='".$q2->f('send_confirmation_to_sender')."',
	ty_email_subject='".addslashes($q2->f('ty_email_subject'))."',
	ty_email_body='".addslashes($q2->f('ty_email_body'))."',";
}

if ($q2->f('send_click_notification')){
	$insert .="
	send_click_notification='".$q2->f('send_click_notification')."',
	click_email_subject='".addslashes($q2->f('click_email_subject'))."',
	click_email_body='".addslashes($q2->f('click_email_body'))."',";
}

if ($q2->f('send_join_notification')){
	$insert .="
	send_join_notification='".$q2->f('send_join_notification')."',
	join_email_subject='".addslashes($q2->f('join_email_subject'))."',
	join_email_body='".addslashes($q2->f('join_email_body'))."',";
}
if ($q2->f('submit_name')){
	$insert .="
	submit_name='".addslashes($q2->f('submit_name'))."',";
}
if ($q2->f('captcha')){
	$insert .="
	captcha='".$q2->f('captcha')."',";
}
if ($q2->f('use_aff_link')){
	$insert .="
	use_aff_link='".$q2->f('use_aff_link')."',";
}
if ($q2->f('gift_url')){
	$insert .="
	gift_url='".$q2->f('gift_url')."',";
}
if ($q2->f('gift_url2')){
	$insert .="
	gift_url2='".$q2->f('gift_url2')."',";
}

if ($q2->f('bypass_link')){
	$insert .="
	bypass_link='".$q2->f('bypass_link')."',
	bypass_link_text='".addslashes($q2->f('bypass_link_text'))."',";
}
if ($q2->f('enable_ip_ban')){
	$insert .="
	enable_ip_ban='".$q2->f('enable_ip_ban')."',
	nr_tries='".$q2->f('nr_tries')."',";
}else $insert .="enable_ip_ban='".$q2->f('enable_ip_ban')."',";
if ($q2->f('subscribe_to_my_arp')){
	$insert .="
	arp_type='".$q2->f('arp_type')."',
	arp_email='".$q2->f('arp_email')."',
	arp_message_subject='".addslashes($q2->f('arp_message_subject'))."',
	arp_message_body='".addslashes($q2->f('arp_message_body'))."',";
}

$q->query("INSERT INTO campaigns SET 
	member_id='".$q->f("id")."',
	name='".addslashes($q2->f('name'))."',
	website_name='".addslashes($q2->f('website_name'))."',
	number_of_friends='".$q2->f('number_of_friends')."',
	mandatory_number_of_friends='".$q2->f('mandatory_number_of_friends')."',
	link='".$q2->f('link')."',
	enable_link_tracking='".$q2->f('enable_link_tracking')."',
	invitation_email_subject='".addslashes($q2->f('invitation_email_subject'))."',
	invitation_email_body='".addslashes($q2->f('invitation_email_body'))."',
	include_do_not_email_me_again_link='".$q2->f('include_do_not_email_me_again_link')."',
	allow_members_to_edit_emails='".$q2->f('allow_members_to_edit_emails')."',
	allow_members_to_enter_preciding_note='".$q2->f('allow_members_to_enter_preciding_note')."',
	landing_page='".$q2->f('landing_page')."',".$insert."
	subscribe_to_my_arp='".$q2->f('subscribe_to_my_arp')."',
	html_text='".$q2->f('html_text')."',
	color_bg_main='".$q2->f('color_bg_main')."',
	color_bg_table='".$q2->f('color_bg_table')."',
	color_border_table='".$q2->f('color_border_table')."',
	border_table='".$q2->f('border_table')."'
	");

if ($q2->f('subscribe_to_my_arp') && $q2->f('arp_type') == '2'){
	$q->query("SELECT LAST_INSERT_ID() AS last FROM campaigns");
	$q->next_record();
	$last = $q->f("last");
	$q3->query("select * from autoresponder_config where field='method' AND campaign_id='".$_GET['id']."'");
	$q3->next_record();
	
	$query="INSERT INTO autoresponder_config SET field='method', value='".$q3->f("value")."', campaign_id='$last'";
	
	$q3->query($query);
	$q3->query("select * from autoresponder_config where field='url' AND campaign_id='".$_GET['id']."'");
	$q3->next_record();
	$query="INSERT INTO autoresponder_config SET field='url', value='".$q3->f("value")."', campaign_id='$last'";
	$q3->query($query);
	$q3->query("select * from autoresponder_config where field='first_name' AND campaign_id='".$_GET['id']."'");
	$q3->next_record();
	$query="INSERT INTO autoresponder_config SET field='first_name', value='".$q3->f("value")."', campaign_id='$last'";
	$q3->query($query);
	$q3->query("select * from autoresponder_config where field='email' AND campaign_id='".$_GET['id']."'");
	$q3->next_record();
	$query="INSERT INTO autoresponder_config SET field='email', value='".$q3->f("value")."', campaign_id='$last'";
	$q3->query($query);
	$q3->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++)
	{
		$q3->next_record();
		
		$query="INSERT INTO autoresponder_config SET field='".$q3->f("field")."', value='".$q3->f("value")."', campaign_id='$last'";
		
		$q->query($query);
//		$query="INSERT INTO autoresponder_config SET field='value".$i."', value='".$q2->f("value".$i)."', campaign_id='$last'";
//		$q->query($query);
	}

}

header("Location: view_campains.ag.php");




?>