<?php //version 1.43

include("inc.all.php");
$q2 = new CDb();

get_logged_info();

$q2->query("SELECT member_id, id FROM campaigns WHERE id='".$_GET['id']."' AND member_id='".$q->f("id")."'");
$q2->next_record();
if ($q2->f("id") == ""){
	header("Location: member.area.logout.php");
	exit;
}
if ($_POST['name'] == '' || $_POST['website_name'] == '' || $_POST['number_of_friends'] == '' || $_POST['mandatory_number_of_friends'] == ''){
	header("Location: campaign_edit.php?id=".$_GET['id']."&err=1");
	exit;
}
if ($_POST['number_of_friends'] < $_POST['mandatory_number_of_friends']){
	header("Location: campaign_edit.php?id=".$_GET['id']."&err=2");
	exit;
}

if (($_POST['number_of_friends']+0) == 0){
	header("Location: campaign_edit.php?id=".$_GET['id']."&err=3");
	exit;
}

$insert = "";

if ($_POST['use_reward_email_just_taf']){
	$insert .="
	use_reward_email_just_taf='".$_POST['use_reward_email_just_taf']."',
	number_of_friends_to_qualify_bonus1='".$_POST['number_of_friends_to_qualify_bonus1']."',
	gift_url='".$_POST['gift_url']."',
	warn_members_if_no_qualify1='".$_POST['warn_members_if_no_qualify1']."',
	gift_email_subject_line1='".addslashes($_POST['gift_email_subject_line1'])."',
	gift_email_body1='".addslashes($_POST['gift_email_body1'])."',";
}else{
	$insert .="
	use_reward_email_just_taf='".$_POST['use_reward_email_just_taf']."',";
}

if ($_POST['use_joined_bonus']){
	$insert .="
	number_of_friends_to_qualify_bonus2='".$_POST['number_of_friends_to_qualify_bonus2']."',
	gift_url2='".$_POST['gift_url2']."',
	use_joined_bonus='".$_POST['use_joined_bonus']."',
	gift_email_subject_line2='".addslashes($_POST['gift_email_subject_line2'])."',
	gift_email_body2='".addslashes($_POST['gift_email_body2'])."',";
}else{
	$insert .="
	use_joined_bonus='".$_POST['use_joined_bonus']."',";
}

if ($_POST['send_confirmation_to_sender']){
	$insert .="
	send_confirmation_to_sender='".$_POST['send_confirmation_to_sender']."',
	ty_email_subject='".addslashes($_POST['ty_email_subject'])."',
	ty_email_body='".addslashes($_POST['ty_email_body'])."',";
}else $insert .="send_confirmation_to_sender='".$_POST['send_confirmation_to_sender']."',";

if ($_POST['send_click_notification']){
	$insert .="
	send_click_notification='".$_POST['send_click_notification']."',
	click_email_subject='".addslashes($_POST['click_email_subject'])."',
	click_email_body='".addslashes($_POST['click_email_body'])."',";
}else $insert .="send_click_notification='".$_POST['send_click_notification']."',";

if ($_POST['send_join_notification']){
	$insert .="
	send_join_notification='".$_POST['send_join_notification']."',
	join_email_subject='".addslashes($_POST['join_email_subject'])."',
	join_email_body='".addslashes($_POST['join_email_body'])."',";
}else $insert .="send_join_notification='".$_POST['send_join_notification']."',";

if ($_POST['submit_name']){
	$insert .="
	submit_name='".$_POST['submit_name']."',";
}
if ($_POST['captcha']){
	$insert .="
	captcha='".$_POST['captcha']."',";
}else $insert .= "captcha='',";
if ($_POST['use_aff_link']){
	$insert .="
	use_aff_link='".$_POST['use_aff_link']."',";
}else $insert .= "use_aff_link='',";
if ($_POST['gift_url']){
	$insert .="
	gift_url='".$_POST['gift_url']."',";
}
if ($_POST['gift_url2']){
	$insert .="
	gift_url2='".$_POST['gift_url2']."',";
}

if ($_POST['bypass_link']){
	$insert .="
	bypass_link='".$_POST['bypass_link']."',
	bypass_link_text='".addslashes($_POST['bypass_link_text'])."',";
}else $insert .="bypass_link='".$_POST['bypass_link']."',";

if ($_POST['enable_ip_ban']){
	$insert .="
	enable_ip_ban='".$_POST['enable_ip_ban']."',
	nr_tries='".$_POST['nr_tries']."',";
}else $insert .="enable_ip_ban='".$_POST['enable_ip_ban']."',";
if ($_POST['subscribe_to_my_arp']){
	$insert .="
	arp_email='".$_POST['arp_email']."',
	arp_message_subject='".addslashes($_POST['arp_message_subject'])."',
	arp_message_body='".addslashes($_POST['arp_message_body'])."',";
}
	$insert .="
	arp_type='".$_POST['arp_type']."',";


$q2->query("UPDATE campaigns SET 
	name='".addslashes($_POST['name'])."',
	website_name='".addslashes($_POST['website_name'])."',
	number_of_friends='".$_POST['number_of_friends']."',
	mandatory_number_of_friends='".$_POST['mandatory_number_of_friends']."',
	link='".$_POST['link']."',
	enable_link_tracking='".$_POST['enable_link_tracking']."',
	invitation_email_subject='".addslashes($_POST['invitation_email_subject'])."',
	invitation_email_body='".addslashes($_POST['invitation_email_body'])."',
	include_do_not_email_me_again_link='".$_POST['include_do_not_email_me_again_link']."',
	allow_members_to_edit_emails='".$_POST['allow_members_to_edit_emails']."',
	allow_members_to_enter_preciding_note='".$_POST['allow_members_to_enter_preciding_note']."',
	landing_page='".$_POST['landing_page']."',".$insert."
	subscribe_to_my_arp='".$_POST['subscribe_to_my_arp']."',
	html_text='".$_POST['html_text']."'
	WHERE id='".$_GET['id']."' AND member_id='".$q->f("id")."'
");

/*echo "UPDATE campaigns SET 
	name='".$_POST['name']."',
	website_name='".$_POST['website_name']."',
	number_of_friends='".$_POST['number_of_friends']."',
	mandatory_number_of_friends='".$_POST['mandatory_number_of_friends']."',
	link='".$_POST['link']."',
	enable_link_tracking='".$_POST['enable_link_tracking']."',
	invitation_email_subject='".$_POST['invitation_email_subject']."',
	invitation_email_body='".$_POST['invitation_email_body']."',
	include_do_not_email_me_again_link='".$_POST['include_do_not_email_me_again_link']."',
	allow_members_to_edit_emails='".$_POST['allow_members_to_edit_emails']."',
	allow_members_to_enter_preciding_note='".$_POST['allow_members_to_enter_preciding_note']."',
	landing_page='".$_POST['landing_page']."',".$insert."
	subscribe_to_my_arp='".$_POST['subscribe_to_my_arp']."'
	WHERE id='".$_GET['id']."' AND member_id='".$q->f("id")."'
";*/

$q->query("SELECT id FROM autoresponder_config WHERE campaign_id='".$_GET['id']."'");
$q->next_record();
$arp_id = 0;
if ($_POST['arp_type'] == '2')
if ($q->f("id") ){
	$arp_id = $q->f("id");
	$change = "UPDATE";
	$where = " WHERE campaign_id='".$_GET['id']."'";
	$and1=" AND field='method'";$and2=" AND field='url'";$and3=" AND field='first_name'";$and4=" AND field='email'";
	$and="";
}else{
	$change = "INSERT INTO";
	$where = ", campaign_id='".$_GET['id']."'";
	$and1="";$and2="";$and3="";$and4="";$and5="";$and=" ";
}

if ($_POST['subscribe_to_my_arp'] && $_POST['arp_type'] == '2'){
	$query="$change autoresponder_config SET field='method', value='".$_POST["method"]."'".$where.$and1;
	
	$q->query($query);
	$query="$change autoresponder_config SET field='url', value='".$_POST["url"]."'".$where.$and2;
	$q->query($query);
	$query="$change autoresponder_config SET field='first_name', value='".$_POST["first_name"]."'".$where.$and3;
	$q->query($query);
	$query="$change autoresponder_config SET field='email', value='".$_POST["email"]."'".$where.$and4;
	$q->query($query);
	for ($i=1;$i<=10;$i++)
	{	

		if ($arp_id) $and5 = " AND id='".($arp_id+$i+3)."'";
		$query="$change autoresponder_config SET field='".$_POST["field".$i]."', value='".$_POST["value".$i]."'".$where.$and5;
	//	echo $query;
		$q->query($query);

//		$query="$change autoresponder_config SET value='".$_POST["value".$i]."'".$where." AND id='".($arp_id+$i+4)."'";
//		//echo $query."  ".$i.$where.$and6.($_POST["value".$i])."nnnn<br>";
//		
//		$q->query($query);
	} 
}



header("Location: campaign_edit.php?id=".$_GET['id']);
?>