<?	
	$db = mysql_connect("localhost", "iqhorg_quitter", "Quitter@iqh");
	mysql_select_db("iqhorg_iqhquitline",$db);

	$VarUserID = $_GET['userID'];		
	$today = date("Y-m-d");
	
	if(isset($_POST['update']))
	{	
	
		if(!empty($_POST['satisfaction']) or !empty( $_POST['quit_30days']))		
		{
			$query = "UPDATE surveys SET ".
					"satisfaction = '".$_POST['satisfaction']. "', ".
					"quit_30days = '".$_POST['quit_30days']. "', ".
					"quit_24hours = '".$_POST['quit_24hours']. "', ".
					"cigs_use = '".$_POST['cigs_use']. "', ".
					"cigs_when = '".$_POST['cigs_when']. "', ".
					"cigs_days = '".$_POST['cigs_days']. "', ".
					"cigs_amount = '".$_POST['cigs_amount']. "', ".
					"cigs_intent = '".$_POST['cigs_intent']. "', ".
					"cgr_use = '".$_POST['cgr_use']. "', ".
					"cgr_when = '".$_POST['cgr_when']. "', ".
					"cgr_days = '".$_POST['cgr_days']. "', ".
					"cgr_amount = '".$_POST['cgr_amount']. "', ".
					"cgr_intent = '".$_POST['cgr_intent']. "', ".
					"pipe_use = '".$_POST['pipe_use']. "', ".
					"pipe_when = '".$_POST['pipe_when']. "', ".
					"pipe_days = '".$_POST['pipe_days']. "', ".
					"pipe_amount = '".$_POST['pipe_amount']. "', ".
					"pipe_intent = '".$_POST['pipe_intent']. "', ".
					"dip_use = '".$_POST['dip_use']. "', ".
					"dip_when = '".$_POST['dip_when']. "', ".
					"dip_days = '".$_POST['dip_days']. "', ".
					"dip_amount = '".$_POST['dip_amount']. "', ".
					"dip_intent = '".$_POST['dip_intent']. "', ".
					"other_use = '".$_POST['other_use']. "', ".
					"other_when = '".$_POST['other_when']. "', ".
					"other_days = '".$_POST['other_days']. "', ".
					"other_amount = '".$_POST['other_amount']. "', ".
					"other_intent = '".$_POST['other_intent']. "', ".
					"med_patch = '".$_POST['med_patch']. "', ".
					"med_gum = '".$_POST['med_gum']. "', ".
					"med_loz = '".$_POST['med_loz']. "', ".
					"med_spray = '".$_POST['med_spray']. "', ".
					"med_inhaler = '".$_POST['med_inhaler']. "', ".
					"med_zyban = '".$_POST['med_zyban']. "', ".
					"med_chantix = '".$_POST['med_chantix']. "', ".
					"med_other = '".$_POST['med_other']. "', ".
					"help_healthpro = '".$_POST['help_healthpro']. "', ".
					"help_website = '".$_POST['help_website']. "', ".
					"help_phone = '".$_POST['help_phone']. "', ".
					"help_counseling = '".$_POST['help_counseling']. "', ".
					"help_self = '".$_POST['help_self']. "', ".
					"help_other = '".$_POST['help_other']. "', ".
					"survey_date = '" .date("Y-m-d"). "', ".
					"user_staff = 'staff ', ".
					"status = 'Completed' ".
					"WHERE userID = ".$_POST['userID']. ";";										
															
					mysql_query($query);
					mysql_close();		

					echo "<h4>Thanks for Completing the Survey</h4>";
					echo "<p><a href='https://iqhquitline.com/members/'>Click here to go to the Members site</a></p>";
					
					exit();
					
					// header('Location: https://iqhquitline.com/surveys/thanks.html');	 		
							
			}			
		}	 			
	
		$user = mysql_query("select * from surveys where userID = " .$userID. ";",$db);  	
		//$user = mysql_query("select * from surveys where userID=1",$db);  		
	
		while ($myuser = mysql_fetch_row($user)) 
		{ 
?>
			<form class="form-inline" name="add" method="post" action="<? echo $PHP_SELF; ?>">
			<input value="<? echo $userID;?>" type="hidden" name="userID">
			<input value="<? echo $user_name?>" type="hidden" name="user_name">
	
    			<legend><? echo $full_name; ?></legend>	         
				<table cellpadding="8">
				<tr>
    	        	<td><strong>How satisfied where you with the service?</strong></td>
        	        <td>
            	    	<select name="satisfaction">
	            		<option value=""></option>
						<?
							$selsat = mysql_query("select listitem from cd_listitems where list='sat' order by sortorder",$db);  
							while ($myselsat = mysql_fetch_row($selsat)) 
							{ 
								if ($myselsat[0] == $myuser[4]) {$sel = 'Selected';} else { $sel = '';}
						?>
						<option value="<? echo $myselsat[0];?>" <? echo $sel; ?>><? echo $myselsat[0];?></option>
        	        	<?
            	    		}
						?>
						</select>
    	        	</td>
        	    </tr> 
				<tr>
             		<td><strong>Have you used any tobacco products in the last 30 days?</strong></td>
	                <td>
					<select name="quit_30days">
	    	        <option value=""></option>			
    	    	    <? 
						$sel30 = mysql_query("select * from cd_yesno where yesno='Yes' or yesno='No' or yesno='Refused'",$db);  
						while ($mysel30 = mysql_fetch_array($sel30)) 
						{ 
							if ($mysel30[0] == $myuser[5]) {$sel = 'Selected';} else { $sel = '';}
					?>
					<option value="<? echo $mysel30[0];?>" <? echo $sel; ?>><? echo $mysel30['yesno'];?></option> 
	            	<?    
						}
					?>
					</select>                
        	    	</td>
            	</tr>  
				<tr>
					<td><strong>Have you used any tobacco products in the past 24 hours?</strong></td>
					<td>
            	    <select name="quit_24hours">
                	<option value=""></option>
					<?	
    	            	$sel30 = mysql_query("select * from cd_yesno where yesno='Yes' or yesno='No'",$db);  
						while ($mysel30 = mysql_fetch_array($sel30)) 
						{ 
							if ($mysel30[0] == $myuser[6]) {$sel = 'Selected';} else { $sel = '';}
					?>
					<option value="<? echo $mysel30[0];?>" <? echo $sel; ?>><? echo $mysel30['yesno'];?></option> 
            	    <?    
                		}
					?>
					</select>
        	        </td>
				</tr>
				</table>
	            <br />
    	        <table>
        	    <tr>
					<td><strong>What tobacco products have you used in the past 30 days?</strong></td>	
				</tr>
    	        </table>
        	    <table class="table table-bordered">            
            	<tr>
	            	<thead>	
					<th><strong>Tobacco Type</strong></th>
					<th><strong>How Often?</strong></th>
					<th><strong>How Many?</strong></th>		
					<th><strong>How Many Days?</strong></th>
					<th><strong>Intend to quit?</strong></th>
					</thead>                
				</tr>
            	<?
					if ($myuser[7] == 'Yes') {$selyes7 = 'checked';}
					if ($myuser[11] == 'Yes') {$selyes11 = 'checked';}			
				?>	
        	    <tr>
					<td><label class="checkbox"><input type="checkbox" name="cigs_use" value="Yes" <? echo $selyes7;?>>Cigarettes</label></td>            
					<td>
					<select name="cigs_when" class="selectbox span2">
    	           	<option value=""></option>
        	        <?
					$selcigfreq = mysql_query("select listitem from cd_listitems where list='days' order by sortorder",$db);  
					while ($myselcigfreq = mysql_fetch_row($selcigfreq)) 
					{ 
						if ($myselcigfreq[0] == $myuser[8]) {$sel = 'Selected';} else { $sel = '';}
					?>
					<option value="<? echo $myselcigfreq[0];?>" <? echo $sel;?>><? echo $myselcigfreq[0];?></option>
                	<? 
	               	}
					?>
					</select>
	                </td>
					<td><input class="span1" value="<? echo $myuser[10];?>" type="text" name="cigs_amount"><label class="checkbox">&nbsp;Each</label></td>
					<td><input class="span1" value="<? echo $myuser[9];?>" type="text" name="cigs_days"></td>
					<td><label class="checkbox"><input type="checkbox" name="cigs_intent" value="Yes" <? echo $selyes11;?>> Yes</label></td>                
            	</tr>
				<tr>
				<? 	
					if ($myuser[12] == 'Yes') {$selyes12 = 'checked';}
					if ($myuser[16] == 'Yes') {$selyes16 = 'checked';}
				?>		
					<td><label class="checkbox"><input type="checkbox" name="cgr_use" value="Yes" <? echo $selyes12;?>>Cigars</label></td>
					<td><select name="cgr_when" class="selectbox span2">
                		<option value=""></option>					
                    	<?
	                    $selcigfreq = mysql_query("select listitem from cd_listitems where list='days' order by sortorder",$db);  
						while ($myselcigfreq = mysql_fetch_row($selcigfreq)) 
						{ 
							if ($myselcigfreq[0] == $myuser[13]) {$sel = 'Selected';} else { $sel = '';}
						?>	
						<option value="<? echo $myselcigfreq[0];?>" <? echo $sel; ?>><? echo $myselcigfreq[0];?></option>
	                   	<?
    	                }
						?>
						</select>
                	</td>
					<td><input class="span1" value="<? echo $myuser[15];?>" type="text" name="cgr_amount"><label class="checkbox">&nbsp;Each</label></td>
					<td><input class="span1" value="<? echo $myuser[14];?>" type="text" name="cgr_days"></td>
					<td><label class="checkbox"><input type="checkbox" name="cgr_intent" value="Yes" <? echo $selyes16;?>> Yes</label></td>            
            	</tr>   
				<? 
					if ($myuser[17] == 'Yes') {$selyes17 = 'checked';}
					if ($myuser[21] == 'Yes') {$selyes21 = 'checked';}
				?>
				<tr>

					<td><label class="checkbox"><input type="checkbox" name="pipe_use" value="Yes" <? echo $selyes17;?>>Pipes</label></td>
					<td><select name="pipe_when" class="selectbox span2">
            	    	<option value=""></option>
						<?	
	                		$selcigfreq = mysql_query("select listitem from cd_listitems where list='days' order by sortorder",$db);  
							while ($myselcigfreq = mysql_fetch_row($selcigfreq)) 
							{ 
								if ($myselcigfreq[0] == $myuser[18]) {$sel = 'Selected';} else { $sel = '';}
						?>
						<option value="<? echo $myselcigfreq[0];?>" <? echo $sel; ?>><? echo $myselcigfreq[0];?></option>
            			<?    
	              			}
						?>
						</select>
	             	</td>
					<td><input class="span1" value="<? echo $myuser[20];?>" type="text" name="pipe_amount"><label class="checkbox">&nbsp;Bowls</label></td>
					<td><input class="span1" value="<? echo $myuser[19];?>" type="text" name="pipe_days"></td>
					<td><label class="checkbox"><input type="checkbox" name="pipe_intent" value="Yes" <? echo $selyes21;?>> Yes</label></td>
            	</tr>
             	<?
					if ($myuser[22] == 'Yes') {$selyes22 = 'checked';}
					if ($myuser[26] == 'Yes') {$selyes26 = 'checked';}		 
				?>
             	<tr>
			 		<td><label class="checkbox"><input type="checkbox" name="dip_use" value="Yes" <? echo $selyes22;?>>Chew/Dip</label></td>
					<td>
					<select name="dip_when" class="selectbox span2">
        	        <option value=""></option>
					<?
                	$selcigfreq = mysql_query("select listitem from cd_listitems where list='days' order by sortorder",$db);  
					while ($myselcigfreq = mysql_fetch_row($selcigfreq)) 
					{ 
						if ($myselcigfreq[0] == $myuser[23]) {$sel = 'Selected';} else { $sel = '';}
					?>
					<option value="<? echo $myselcigfreq[0];?>" <? echo $sel; ?>><? echo $myselcigfreq[0];?></option>
                	<?
                	}
					?>
					</select>
                	</td>
					<td><input class="span1"  value="<? echo $myuser[25];?>" type="text" name="dip_amount"><label class="checkbox">&nbsp;Pouches</label></td>
					<td><input class="span1" value="<? echo $myuser[24];?>" type="text" name="dip_days"></td>
					<td><label class="checkbox"><input type="checkbox" name="dip_intent" value="Yes" <? echo $selyes26;?>> Yes</label></td>             
             	</tr>
				<tr>
				<? 
					if ($myuser[27] == 'Yes') {$selyes27 = 'checked';}
					if ($myuser[11] == 'Yes') {$selyes31 = 'checked';}
				?>
					<td><label class="checkbox"><input type="checkbox" name="other_use" value="Yes" <? echo $selyes27;?>>Other</label></td>
					<td>
					<select name="other_when" class="selectbox span2">
                	<option value=""></option>
					<? 
                	$selcigfreq = mysql_query("select listitem from cd_listitems where list='days' order by sortorder",$db);  
					while ($myselcigfreq = mysql_fetch_row($selcigfreq)) 
					{ 
						if ($myselcigfreq[0] == $myuser[28]) {$sel = 'Selected';} else { $sel = '';}
					?>				
					<option value="<? echo $myselcigfreq[0];?>" <? echo $sel; ?>><? echo $myselcigfreq[0];?></option>
               		<?
                	}
					?>
					</select>
                	</td>
					<td><input class="span1" value="<? echo $myuser[30];?>" type="text" name="other_amount"><label class="checkbox">&nbsp;Each</label></td>
					<td><input class="span1" value="<? echo $myuser[29];?>" type="text" name="other_days"></td>
					<td><label class="checkbox"><input type="checkbox" name="other_intent" value="Yes" <? echo $selyes31;?>> Yes</label></td>             
            	</table>
				<br />           
	            <table cellpadding="8" class="table table-bordered">
				<thead>
        	    <tr>                   
					<th><strong>Which Medications did you use if any?</strong><br></th>
					<th><strong>Which types of assistance did you use if any?</strong><br></th>
				</tr>
    	        </thead>
        	    <tbody>
				<tr>
					<td valign="top">
				<?
					if ($myuser[32] == 'Yes') {$selyes32 = 'checked';}
					if ($myuser[33] == 'Yes') {$selyes33 = 'checked';}
					if ($myuser[34] == 'Yes') {$selyes34 = 'checked';}
					if ($myuser[35] == 'Yes') {$selyes35 = 'checked';}
					if ($myuser[36] == 'Yes') {$selyes36 = 'checked';}
					if ($myuser[37] == 'Yes') {$selyes37 = 'checked';}
					if ($myuser[38] == 'Yes') {$selyes38 = 'checked';}
					if ($myuser[39] == 'Yes') {$selyes39 = 'checked';}
				?>
					<label class="checkbox"><input type="checkbox" name="med_patch" value="Yes" <? echo $selyes32;?>> Nicotine Patch</label><br>
					<label class="checkbox"><input type="checkbox" name="med_gum" value="Yes" <? echo $selyes33;?>> Nicotine Gum</label><br>
					<label class="checkbox"><input type="checkbox" name="med_loz" value="Yes" <? echo $selyes34;?>> Nicotine Lozenge</label><br>
					<label class="checkbox"><input type="checkbox" name="med_inhaler" value="Yes" <? echo $selyes35;?>> Nicotine Inhaler</label><br>
					<label class="checkbox"><input type="checkbox" name="med_spray" value="Yes" <? echo $selyes36;?>> Nicotine Spray</label><br>
					<label class="checkbox"><input type="checkbox" name="med_chantix" value="Yes" <? echo $selyes38;?>> Chantix</label><br>
					<label class="checkbox"><input type="checkbox" name="med_zyban" value="Yes" <? echo $selyes37;?>> Zyban</label><br>
					<label class="checkbox"><input type="checkbox" name="med_other" value="Yes" <? echo $selyes39;?>> Other Medications</label>
					</td>
					<td valign="top">
				<?
					if ($myuser[40] == 'Yes') {$selyes40 = 'checked';}
					if ($myuser[41] == 'Yes') {$selyes41 = 'checked';}
					if ($myuser[42] == 'Yes') {$selyes42 = 'checked';}
					if ($myuser[43] == 'Yes') {$selyes43 = 'checked';}
					if ($myuser[44] == 'Yes') {$selyes44 = 'checked';}
					if ($myuser[45] == 'Yes') {$selyes45 = 'checked';}
				?>
					<label class="checkbox"><input type="checkbox" name="help_healthpro" value="Yes" <? echo $selyes40;?>> Healthcare Professional</label><br>
					<label class="checkbox"><input type="checkbox" name="help_website" value="Yes" <? echo $selyes41;?>> Other Website</label><br>
					<label class="checkbox"><input type="checkbox" name="help_phone" value="Yes" <? echo $selyes42;?>> Telephone Program</label><br>
					<label class="checkbox"><input type="checkbox" name="help_counseling" value="Yes" <? echo $selyes43;?>> Other Counseling</label><br>
					<label class="checkbox"><input type="checkbox" name="help_self" value="Yes" <? echo $selyes44;?>> Self Help</label><br>
					<label class="checkbox"><input type="checkbox" name="help_other" value="Yes" <? echo $selyes45;?>> Something Else</label><br>
					</td>
        	    </tr>
            </tbody>
			</table>
            <br />
		
        	<input name="update" type="submit" id="update" value="Update" />            
			</form>
<?
}
?>  