<?php

if ($topic_id) {

$query = "UPDATE topics SET 

viewed = viewed + 1

WHERE topic_ID='$topic_id'";

}

$log = "INSERT INTO visits (
userID,
last_area,
visit_date
) 

values (
'$userID',
'$area',
NOW()
)";


if ($add_topic) {

if (!$topic or !$discuss) {
$promptred="Topic not complete";
}

// Array of Bad words

$words = array('fuck','shit','damn','ass','nigger','bastard','cunt','bitch','slut','motherfuck');

// Array of extention to words

$exten = array('','ed','ing','s','er','ers','es');

// Input string

$str = $topic. " " .$discuss;

// Create an array from input

$string = explode(' ',strtolower($str));

// Create a new array for all combinations of swear words

$wordList = array();

// Add all combinations to the new array

foreach($words as $word){   
foreach($exten as $ext){      
$wordList[] = $word.$ext;   }}

// Loop through each input word, and check if it is a bad word or not
// FALSE = Good Words
// TRUE = Bad Words

$badWord = FALSE;
foreach($string as $s){   if(in_array($s, $wordList)){      $badWord = TRUE;   }}

// Do something if output is good or bad in this case display a message

if($badWord)   {

$promptred="Inapropriate content";
unset($topic,$discuss);
}

if ($topic and $discuss) {

$query = "INSERT INTO topics (
topic_id,
userID,
forum,
topic,
discuss,
date_added
) 

values (
'',
'$userID',
'$forum',
'$topic',
'$discuss',
NOW()
)";

$promptgreen="Topic Posted";

unset($area);

}
}

if ($add_post) {

if (!$comment) {
$promptred="Comment is blank";
}

if ($comment) {

$query = "INSERT INTO posts (
post_id,
userID,
topic_id,
comment,
date_added
) 

values (
'',
'$userID',
'$topic_id',
'$comment',
NOW()
)";

$promptgreen="Comment Posted";

unset($area);

}
}

if ($send_chat) {

if (!$chattext) {
$promptred="Message is blank";
}

if ($chattext) {

$query = "INSERT INTO chat (
chatID,
childID,
userID,
text,
date_added) 

values (
'',
'',
'$userID',
'$chattext',
NOW()
)";

$promptgreen="Message saved";

}
}




if ($user_add) {

$qzip = mysql_query("select count(*) from zip where zip='$user_zip' and state='AL'",$db);  
while ($rzip = mysql_fetch_row($qzip)) { 

$checkzip=$rzip[0];

}

if ($checkzip>0) {


if (!$username or !$password or !$user_lastname or !$user_firstname or !$user_zip or !$user_email or !$user_type) {
$promptred="Required Fields Left Blank";
$area='user_add';
}


if ($username & $password & $user_lastname & $user_firstname & $user_zip & $user_email & $user_type) {

$profile = mysql_query("select count(*) from user where username ='$username'",$db);  
while ($myprofile = mysql_fetch_row($profile)) { 

if ($myprofile[0]>0) {

unset($username);
$promptred="User Name Already Exists";
$area='user_add';
}

$semail = mysql_query("select count(*) from user where user_email ='$user_email'",$db);  
while ($remail = mysql_fetch_row($semail)) { 

if ($remail[0]>0) {

unset($user_email);
$promptred="Email Already Exists";
$area='user_add';
}


if ($myprofile[0]<1 and $remail[0]<1) {



$query = "INSERT INTO user (
userID,
username,
password,
active,
user_lastname,
user_firstname,
user_email,
user_zip,
user_type,
source_search,
source_facebook,
source_myspace,
source_twitter,
source_website,
source_family,
source_insurance,
source_doctor,
source_employer,
source_school,
source_clinic,
source_flyer,
source_newspaper,
source_tv_commercial,
source_tv_news,
source_tv_teenad,
source_radio,
source_1_800,
source_billboard,
date_added) 

values (
'',
'$username',
'$password',
'1',
'$user_lastname',
'$user_firstname',
'$user_email',
'$user_zip',
'$user_type',
'$source_search',
'$source_facebook',
'$source_myspace',
'$source_twitter',
'$source_website',
'$source_family',
'$source_insurance',
'$source_doctor',
'$source_employer',
'$source_school',
'$source_clinic',
'$source_flyer',
'$source_newspaper',
'$source_tv_commercial',
'$source_tv_news',
'$source_tv_teenad',
'$source_radio',
'$source_1_800',
'$source_billboard',
NOW()
)";

$promptred="";
$promptgreen="Welcome ". $user_firstname;
$area='user_welcome';
include "../mail/registration.inc";
}
}
}
}
}
if ($checkzip<1) { 
unset($user_zip);
$promptred="Unsupported Zip";
$area='user_add';
}
}

if ($user_edit) {

$qzip = mysql_query("select count(*) from zip where zip='$user_zip' and state='AL'",$db);  
while ($rzip = mysql_fetch_row($qzip)) { 

$checkzip=$rzip[0];

}

if ($checkzip>0) {

if (!$username or !$password or !$user_lastname or !$user_firstname or !$user_zip or !$user_email or !$user_type) {
$promptred="Required Fields Left Blank";
$area='user_edit';
}

if ($username & $password & $user_lastname & $user_firstname &  $user_zip & $user_email & $user_type) {

$profile = mysql_query("select count(*) from user where username ='$username' and userID <> '$userID'",$db);  
while ($myprofile = mysql_fetch_row($profile)) { 

if ($myprofile[0]>0) {

unset($username);
$promptred="User Name Already Exists";

if ($user_type=='user'){$area='user_edit';}
if ($user_type=='supporter'){$area='profile';}

}

if ($myprofile[0]<1) {

$query = "UPDATE user SET 
username = '$username',
password = '$password',
user_firstname = '$user_firstname',
user_lastname = '$user_lastname',
user_zip = '$user_zip',
user_email = '$user_email',
user_type = '$user_type',
source_search = '$source_search',
source_facebook = '$source_facebook',
source_myspace = '$source_myspace',
source_twitter = '$source_twitter',
source_website = '$source_website',
source_family = '$source_family',
source_insurance = '$source_insurance',
source_doctor = '$source_doctor',
source_employer = '$source_employer',
source_school = '$source_school',
source_clinic = '$source_clinic',
source_flyer = '$source_flyer',
source_newspaper = '$source_newspaper',
source_tv_commercial = '$source_tv_commercial',
source_tv_news = '$source_tv_news',
source_tv_teenad = '$source_tv_teenad',
source_radio = '$source_radio',
source_1_800 = '$source_1_800',
source_billboard = '$source_billboard'

WHERE userID='$userID' ";

$promptgreen="Membership Saved";
if ($user_type=='user'){$area='user_edit';}
if ($user_type=='supporter'){$area='profile';}


}
}
}
}
if ($checkzip<1) { 
$promptred="Unsupported Zip";
if ($user_type=='user'){$area='user_edit';}
if ($user_type=='supporter'){$area='profile';}

}
}



if ($user_demographics) {

if (!$quit_howsoon or !$user_sex or !$user_dob or !$user_insurance or !$user_race or !$user_hispanic 
or !$user_education or !$user_pregnant) {

$query = "UPDATE user SET 
quit_howsoon = '$quit_howsoon',
user_sex = '$user_sex',
user_dob = '$user_dob',
user_insurance = '$user_insurance',
user_race = '$user_race',
user_hispanic = '$user_hispanic',
user_education = '$user_education',
user_pregnant = '$user_pregnant'

WHERE userID='$userID' ";

$promptred="Required Fields Left Blank";
$area='user_demographics';

}

if ($quit_howsoon & $user_sex and $user_dob and $user_insurance and $user_race and $user_hispanic and $user_education and $user_pregnant) {

$query = "UPDATE user SET 
quit_howsoon = '$quit_howsoon',
user_sex = '$user_sex',
user_dob = '$user_dob',
user_insurance = '$user_insurance',
user_race = '$user_race',
user_hispanic = '$user_hispanic',
user_education = '$user_education',
user_pregnant = '$user_pregnant',
demographics_saved = 1
WHERE userID='$userID' ";

$promptgreen="Demographics Saved";
$area='user_whichtobacco';

}
}


if ($user_whichtobacco) {

if (!$cigarette_freq & !$cigar_freq & !$chew_freq & !$dip_freq & !$pipe_amount) {
$fail = 1;
}

if ($cigarette_freq) {
if ((!$cigarette_amount or !$cigarette_length)) {
$fail = 1;
}}

if ($cigar_freq) {
if ((!$cigar_amount or !$cigar_length)) {
$fail = 1;
}}

if ($pipe_freq) {
if ((!$pipe_amount or !$pipe_length)) {
$fail = 1;
}}

if ($dip_freq) {
if ((!$dip_amount or !$dip_length)) {
$fail = 1;
}}

if ($chew_freq) {
if ((!$chew_amount or !$chew_length)) {
$fail = 1;
}}


if ($fail==1) {

$query = "UPDATE user SET 
cigarette_freq = '$cigarette_freq',
cigarette_amount = '$cigarette_amount',
cigarette_length = '$cigarette_length',
cigar_freq = '$cigar_freq',
cigar_amount = '$cigar_amount',
cigar_length = '$cigar_length',
chew_freq = '$chew_freq',
chew_amount = '$chew_amount',
chew_length = '$chew_length',
dip_freq = '$dip_freq',
dip_amount = '$dip_amount',
dip_length = '$dip_length',
pipe_freq = '$pipe_freq',
pipe_amount = '$pipe_amount',
pipe_length = '$pipe_length'
WHERE userID='$userID' ";

$promptred="Required Fields Left Blank";
$area='user_whichtobacco';
}

else {


$query = "UPDATE user SET 
cigarette_freq = '$cigarette_freq',
cigarette_amount = '$cigarette_amount',
cigarette_length = '$cigarette_length',
cigar_freq = '$cigar_freq',
cigar_amount = '$cigar_amount',
cigar_length = '$cigar_length',
chew_freq = '$chew_freq',
chew_amount = '$chew_amount',
chew_length = '$chew_length',
dip_freq = '$dip_freq',
dip_amount = '$dip_amount',
dip_length = '$dip_length',
pipe_freq = '$pipe_freq',
pipe_amount = '$pipe_amount',
pipe_length = '$pipe_length',
whichtobacco_saved = 1
WHERE userID='$userID' ";

$promptgreen="Type Tobacco Saved";
$area='user_tobaccouse';
}
}

if ($user_tobaccouse) {

$query = "UPDATE user SET 
user_cigarettes_how_soon = '$user_cigarettes_how_soon',
user_cigarettes_which_one = '$user_cigarettes_which_one',
user_cigarettes_hard_not_allowed = '$user_cigarettes_hard_not_allowed',
user_cigarettes_when_ill = '$user_cigarettes_when_ill',
user_smokeless_swallow = '$user_smokeless_swallow',
user_smokeless_how_soon = '$user_smokeless_how_soon',
user_smokeless_mouth_how_long = '$user_smokeless_mouth_how_long',
tobaccouse_saved = 1
WHERE userID='$userID' ";

$promptgreen="Dependence Questions Saved";
$area='user_attempts';


}


if ($user_attempts) {

$query = "UPDATE user SET 
att_have_you = '$att_have_you',
att_longest = '$att_longest',
att_help1 = '$att_help1',
att_help2 = '$att_help2',
att_help3 = '$att_help3',
att_help4 = '$att_help4',
att_help5 = '$att_help5',
att_help6 = '$att_help6',
att_help7 = '$att_help7',
att_help8 = '$att_help8',
att_help_other = '$att_help_other',
att_nohelp1 = '$att_nohelp1',
att_nohelp2 = '$att_nohelp2',
att_nohelp3 = '$att_nohelp3',
att_nohelp4 = '$att_nohelp4',
att_nohelp5 = '$att_nohelp5',
att_nohelp6 = '$att_nohelp6',
att_nohelp7 = '$att_nohelp7',
att_nohelp8 = '$att_nohelp8',
att_nohelp_other = '$att_nohelp_other',
att_reasons = '$att_reasons',
att_notes = '$att_notes',
attempts_saved = 1
WHERE userID='$userID' ";

$promptgreen="Quit Attempt Questions Saved";
$area='user_triggers';


}

if ($user_triggers) {

$query = "UPDATE user SET 
trig_wake_face = '$trig_wake_face',
trig_wake_brush = '$trig_wake_brush',
trig_wake_shower = '$trig_wake_shower',
trig_coffee_juice = '$trig_coffee_juice',
trig_coffee_less = '$trig_coffee_less',
trig_coffee_decaf = '$trig_coffee_decaf',
trig_drive_sip = '$trig_drive_sip',
trig_drive_chew = '$trig_drive_chew',
trig_drive_pen = '$trig_drive_pen',
trig_meal_wash = '$trig_meal_wash',
trig_meal_gum = '$trig_meal_gum',
trig_meal_toothpick = '$trig_meal_toothpick',
trig_breaks_music = '$trig_breaks_music',
trig_breaks_read = '$trig_breaks_read',
trig_breaks_call = '$trig_breaks_call',
trig_bored_walk = '$trig_bored_walk',
trig_bored_puzzles = '$trig_bored_puzzles',
trig_bored_snack = '$trig_bored_snack',
trig_bored_water = '$trig_bored_water',
trig_users_walk = '$trig_users_walk',
trig_users_water = '$trig_users_water',
trig_users_tell = '$trig_users_tell',
trig_alcohol_avoid = '$trig_alcohol_avoid',
trig_alcohol_smokefree = '$trig_alcohol_smokefree',
challenges_notes = '$challenges_notes',
triggers_saved = 1
WHERE userID='$userID' ";

$promptgreen="Trigger Questions Saved";
$area='user_stress';


}

if ($user_stress) {

$query = "UPDATE user SET 
stress_how_much = '$stress_how_much',
stress_use_tobacco = '$stress_use_tobacco',
stress1 = '$stress1',
stress2 = '$stress2',
stress3 = '$stress3',
stress4 = '$stress4',
stress5 = '$stress5',
stress6 = '$stress6',
stress7 = '$stress7',
stress8 = '$stress8',
stress9 = '$stress9',
stress_other = '$stress_other',
stress_saved = 1
WHERE userID='$userID' ";

$promptgreen="Stress Questions Saved";
$area='user_substitutes';


}

if ($user_substitutes) {

$query = "UPDATE user SET 
substitute_straws = '$substitute_straws',
substitute_toothpicks = '$substitute_toothpicks',
substitute_pen = '$substitute_pen',
substitute_breath = '$substitute_breath',
substitute_other = '$substitute_other',
substitute_notes = '$substitute_notes',
substitutes_saved = 1
WHERE userID='$userID' ";

$promptgreen="Substitute Questions Saved";
$area='user_distractions';


}

if ($user_distractions) {

$query = "UPDATE user SET 
distractions_gum = '$distractions_gum',
distractions_seeds = '$distractions_seeds',
distractions_water = '$distractions_water',
distractions_puzzles = '$distractions_puzzles',
distractions_books = '$distractions_books',
distractions_exercise = '$distractions_exercise',
distractions_call = '$distractions_call',
distractions_other = '$distractions_other',
distractions_saved = 1
WHERE userID='$userID' ";

$promptgreen="Distraction Questions Saved";
$area='user_motivation';


}

if ($user_motivation) {

$query = "UPDATE user SET 
motive_health = '$motive_health',
motive_health_specific = '$motive_health_specific',
motive_family = '$motive_family',
motive_family_specific = '$motive_family_specific',
motive_social = '$motive_social',
motive_social_specific = '$motive_social_specific',
motive_smokefree = '$motive_smokefree',
motive_smokefree_specific = '$motive_smokefree_specific',
motive_sports = '$motive_sports',
motive_sports_specific = '$motive_sports_specific',
motive_prevention = '$motive_prevention',
motive_prevention_specific = '$motive_prevention_specific',
motive_cost = '$motive_cost',
motive_cost_specific = '$motive_cost_specific',
motive_pregnant = '$motive_pregnant',
motive_pregnant_specific = '$motive_pregnant_specific',
motive_other = '$motive_other',
motive_harmful = '$motive_harmful',
motive_benefits = '$motive_benefits',
motive_notes = '$motive_notes',
motivation_saved = 1
WHERE userID='$userID' ";

$promptgreen="Motivation Questions Saved";
$area='user_support';


}

if ($user_support) {

$query = "UPDATE user SET 
support_name1 = '$support_name1',
support_email1 = '$support_email1',
support_name2 = '$support_name2',
support_email2 = '$support_email2',
support_name3 = '$support_name3',
support_email3 = '$support_email3',
quitbuddy_name1 = '$quitbuddy_name1',
quitbuddy_email1 = '$quitbuddy_email1',
quitbuddy_name2 = '$quitbuddy_name2',
quitbuddy_email2 = '$quitbuddy_email2',
quitbuddy_name3 = '$quitbuddy_name3',
quitbuddy_email3 = '$quitbuddy_email3',
support_saved = 1
WHERE userID='$userID' ";

$promptgreen="Support Questions Saved";
$area='user_environment';


}

if ($user_environment) {

$query = "UPDATE user SET 
environment_others = '$environment_others',
environment_smokers = '$environment_smokers',
environment_quitters = '$environment_quitters',
environment_around = '$environment_around',
environment_allowed = '$environment_allowed',
environment_presteps1 = '$environment_presteps1',
environment_presteps2 = '$environment_presteps2',
environment_presteps3 = '$environment_presteps3',
environment_presteps4 = '$environment_presteps4',
environment_presteps5 = '$environment_presteps5',
environment_presteps6 = '$environment_presteps6',
environment_presteps7 = '$environment_presteps7',
environment_presteps_other = '$environment_presteps_other',
environment_poststeps1 = '$environment_poststeps1',
environment_poststeps2 = '$environment_poststeps2',
environment_poststeps3 = '$environment_poststeps3',
environment_poststeps4 = '$environment_poststeps4',
environment_poststeps_other = '$environment_poststeps_other',
environment_notes = '$environment_notes',
environment_saved = 1
WHERE userID='$userID' ";

$promptgreen="Environment Questions Saved";
$area='user_healthyhabits';


}

if ($user_healthyhabits) {

$query = "UPDATE user SET 
habits_exercise1 = '$habits_exercise1',
habits_exercise2 = '$habits_exercise2',
habits_exercise_other = '$habits_exercise_other',
habits_water1 = '$habits_water1',
habits_water2 = '$habits_water2',
habits_water3 = '$habits_water3',
habits_water4 = '$habits_water4',
habits_water5 = '$habits_water5',
habits_water_other = '$habits_water_other',
habits_snacks1 = '$habits_snacks1',
habits_snacks2 = '$habits_snacks2',
habits_snacks3 = '$habits_snacks3',
habits_snacks_other = '$habits_snacks_other',
habits_sleep1 = '$habits_sleep1',
habits_sleep2 = '$habits_sleep2',
habits_sleep3 = '$habits_sleep3',
habits_sleep_other = '$habits_sleep_other',
habits_medical1 = '$habits_medical1',
habits_medical2 = '$habits_medical2',
habits_medical_other = '$habits_medical_other',
habits_notes = '$habits_notes',
healthyhabits_saved = 1
WHERE userID='$userID' ";

$promptgreen="Healthy Habits Questions Saved";
$area='user_quitdate';


}

if ($user_quitdate) {

$query = "UPDATE user SET 
quit_date = '$quit_date',
quit_usemeds = '$quit_usemeds',
quit_medical = '$quit_medical',
quit_weekend = '$quit_weekend',
med_patch  = '$med_patch',
med_gum  = '$med_gum',
med_lozenge  = '$med_lozenge',
med_inhaler  = '$med_inhaler',
med_spray  = '$med_spray',
med_chantix  = '$med_chantix',
med_zyban  = '$med_zyban'
WHERE userID='$userID' ";

$promptgreen="Quit Date Saved";
$area='user_quitdate';

if ($quit_date) {
include "../mail/quitdateset.inc";
}

}

if ($user_quitting) {

$query = "UPDATE user SET 
actual_quitdate = '$actual_quitdate',
actual_meds  = '$actual_meds',
withdrawal_irritable = '$withdrawal_irritable',
withdrawal_tired = '$withdrawal_tired',
withdrawal_sleeping = '$withdrawal_sleeping',
withdrawal_concentrating = '$withdrawal_concentrating',
withdrawal_weight = '$withdrawal_weight',
withdrawal_craving = '$withdrawal_craving',
concerns_alcohol = '$concerns_alcohol',
concerns_caffeine = '$concerns_caffeine',
concerns_weight = '$concerns_weight',
concerns_stress = '$concerns_stress',
concerns_others = '$concerns_others'
WHERE userID='$userID' ";

$promptgreen="Quitting Info Saved";
$area='user_quitting';


}

if ($user_stayingquit) {

if ($_REQUEST['puffyear'] and $_REQUEST['puffmonth'] and $_REQUEST['puffday'] ) {

$query = "UPDATE user SET 
lastpuff = '$lastpuff'

WHERE userID='$userID' ";

$promptgreen="Staying Quit Info Saved";
$area='user_stayingquit';

}
else{
$promptred="Date was not complete";
$area='user_stayingquit';

}


}


if ($med_problems) {

$query = "UPDATE user SET 
health_heart_disease = '$health_heart_disease',
health_heart_attack = '$health_heart_attack',
health_heartbeats = '$health_heartbeats',
health_high_bp = '$health_high_bp',
health_diabetes = '$health_diabetes',
health_ulcers = '$health_ulcers',
health_pregnant = '$health_pregnant',
health_zyban = '$health_zyban',
health_chantix = '$health_chantix',
health_depression = '$health_depression',
health_asthma = '$health_asthma',
health_sodium = '$health_sodium',
health_adhesive = '$health_adhesive',
health_skin = '$health_skin',
health_none = '$health_none',
physician_name = '$physician_name',
physician_fax = '$physician_fax'
WHERE userID='$userID' ";

$promptgreen="Medical Info Saved";

}

if ($edit_address) {

$query = "UPDATE user SET 

user_address = '$user_address',
user_city = '$user_city',
user_state = 'AL',
user_phone = '$user_phone'

WHERE userID='$userID' ";

$promptgreen="Address Saved";

}


mysql_query($log);
mysql_query($query);
mysql_close();


?>

