// $debug=yes;
/***********
setup a new team
update an existing team
must be logged
if password blank allow anyone to join the team
allow to bulk email friends
***********/
require'../commonfiles/Functions.php';
require'../commonfiles/MyFunctions.php';
require'../commonfiles/brandconfig.php';
require'../commonfiles/newtemplate.php';
// connect mysql
$crm = new MySQL_class;
$crm->Create($crm_db,$crm_user,$crm_host,$crm_pass);
$gc_sql=$crm; // session handling
$db_foo = $crm; // template handling
$cdc = new MySQL_class;
$cdc->Create($cdc_db,$cdc_user,$cdc_host,$cdc_pass);
$tmp = new MySQL_class;
$tmp->Create($template_db,$template_user,$template_host_2,$template_pass);
// foil hackers
unset($u_type,$u_id,$session_email);
// start session
start_session($php_sessid);
$staging = "";
if(page_auth(3,$u_type,$cdc) == "yes")
{
$staging = "yes";
}
// test login
unset($u_type,$u_id,$session_email);
start_session($sessid);
if($u_id=="")
{
header("location: /store/login.php?next=/donation");
exit();
}
app_log('donation',$PHP_SELF,$search_word,$u_id,'view',$code,$array);
$message_array = get_messages('donation_team',$language_c,$TEMPLATE_MESSAGE,$code,$tmp);
unset($message);
// process ...
if($submit)
{
if(!$donation_id)
{
// Please select a donation campaign.
$message = "
Error: invalid ID";
}
if(!is_numeric(trim($monetary_goal)))
{
$message .= "
Please enter a goal.";
}
}
if($submit && !$message)
{
// make sure they are not already a member of this team
$query = "select id
from $DONATION_INDIVIDUAL
where donation_id = '".ass($donation_id)."'
and contact_id = '$u_id'
and brand = '$code' ";
$data = $crm->mydata($query);
$donation_individual_id = $data[id][0];
if($data[id][0])
{
$query = "update $DONATION_INDIVIDUAL set
description = '".ass($description)."',
monetary_goal = '".ass($monetary_goal)."'
where donation_id = '".ass($donation_id)."'
and contact_id = '$u_id'
and brand = '$code' ";
$crm->Update($query);
} else {
$donation_individual_id = make_rand();
$query = "insert into $DONATION_INDIVIDUAL set
id = '$donation_individual_id',
contact_id = '$u_id',
description = '".ass($description)."',
monetary_goal = '".ass($monetary_goal)."',
donation_id = '".ass($donation_id)."',
date_time = '".gmdate("Y-m-d H:i:s")."',
brand = '$code' ";
$crm->Insert($query);
}
header("location: donation.php?donation_individual_id=$donation_individual_id");
exit();
}
if(!$donation_individual_id)
{
$query = "select id
from $DONATION_INDIVIDUAL
where contact_id = '$u_id'
and brand = '$code' ";
$data = $crm->mydata($query);
$donation_individual_id = $data[id][0];
}
// start template engine
$tpl = new rFastTemplate(".");
$tpl->no_strict();
$tpl->quiet();
$tpl->define_raw( array( main => get_template('40',$TEMPLATE,$tmp,$code,$staging),
body => get_template('241',$TEMPLATE,$tmp,$code,$staging) ));
if($donation_id && !$message)
{
$query = "select monetary_goal, description
from $DONATION_INDIVIDUAL
where contact_id = '$u_id'
and donation_id = '".ass($donation_id)."'
and brand = '$code' ";
$data = $crm->mydata($query);
$monetary_goal = $data[monetary_goal][0];
$description = $data[description][0];
}
if($donation_individual_id && !$message)
{
$query = "select monetary_goal, description
from $DONATION_INDIVIDUAL
where contact_id = '$u_id'
and id = '$donation_individual_id'
and brand = '$code' ";
$data = $crm->mydata($query);
$monetary_goal = $data[monetary_goal][0];
$description = $data[description][0];
}
$query = "select d.id, d.name, d.description
from $DONATION d, $CAMPAIGN c
where c.activates_on <= '".gmdate("Y-m-d")."'
and c.disables_on >= '".gmdate("Y-m-d")."'
and d.campaign_id = c.id
and c.brand = '$code' ";
$data = $crm->mydata($query);
for($a=0;$aassign(array( 'DONATION_ID' => $data[id][$a],
DONATION_NAME => $data[name][$a],
DONATION_CHECKED => $checked,
DONATION_DESCRIPTION => $data[description][$a] ));
$tpl->parse("DONATION",".donation");
if(!$donation_id)
{
$donation_id = $data[id][$a];
}
}
$tpl = show_login($u_id,$tpl);
$tpl = html_chunks($staging,$tpl,$code,$brnd);
// just in case ...
if(!$donation_individual_id)
{
$query = "select id
from $DONATION_INDIVIDUAL
where donation_id = '".ass($donation_id)."'
and contact_id = '$u_id'
and brand = '$code' ";
$data = $crm->mydata($query);
$donation_individual_id = $data[id][0];
if(!$donation_individual_id)
{
$donation_individual_id = make_rand();
$query = "insert into $DONATION_INDIVIDUAL set
id = '$donation_individual_id',
donation_id = '".ass($donation_id)."',
contact_id = '$u_id',
brand = '$code' ";
$crm->Insert($query);
}
}
// asign basic stuff
$tpl->assign( array( SELF => $PHP_SELF,
MESSAGE => $message,
DESCRIPTION => $description,
DONATION_INDIVIDUAL_ID => $donation_individual_id,
MONETARY_GOAL => number_format($monetary_goal,2,'.',''),
PAGE_TITLE => 'Solo Fundraiser',
ALT_MESSAGE => strip_tags($alt_message) ));
$tpl->parse( MAIN, array( "body", "main" ));
$tpl->FastPrint();
exit();
?>