Page 1 of 1

Weather forecasts

Posted: 30. June 2009 07:21
by thepips
Hi,
I'm trying to teach myself a bit about php and SQL so I decided to create a slight variation on a weather forecast block. As the site is for users who are going to travel I wanted them to be able to enter their destination and see the weather there.
You can see what I've got so far at http://www.arvclub.co.uk
Logon newbietest
password letmein

Here's the code for the weather block

Code: Select all

<?php
        if (!defined('IN_PHPBB'))
        {
           exit;
        }

        if (!defined('IN_PORTAL'))
        {
           exit;
        }

	if ($user->data['user_id'] > 1)
	{
		$display_menu = true;	
	}
	else
	{
		$display_menu = false;
	}
            $userid_weather = $user->data['user_id'];
			$sql = "SELECT user_from FROM " . phpbb_users . " WHERE user_id = " . $userid_weather;
            $result = $db->sql_query_limit($sql, 1);
            $weather_location = $db->sql_fetchfield('user_from');

            $db->    sql_freeresult($result);


            $template->assign_vars(array(
                'WEATHER_LOC'     => (!empty($weather_location)) ? $weather_location : 'England',
                'USERID_WEATHER' => $userid_weather,
                'SHOW_SEARCH' => $display_menu,
            ));
?>
And here's the code for the HTML

Code: Select all


<div class="portal-panel">
	<div class="inner">
		<span class="portal-corners-top"><span></span></span>
			<h3><img src="{T_THEME_PATH}/images/portal/bullet.gif" width="18px" height="17px" alt=""/>&nbsp;Weather</h3>

			<!-- IF SHOW_SEARCH -->
				<form method="post" id="forecast" action="{U_UPDATE_LOCATION}">
					<input type="text"
						tabindex="6"
						name="location"
						id="searchfield"
						size="22"
						maxlength="40"
						title="Enter town or postcode"
						class="inputbox search"
						value="{WEATHER_LOC}"
						onclick="if(this.value=='Weather')this.value='{WEATHER_LOC}';"
						onblur="if(this.value=='')this.value='London';"
					/>
					<fieldset class="submit-buttons">
					<input type="reset"
						value="{L_RESET}"
						name="reset"
						class="button2" />
					<input type="submit"
						name="action"
						value="{L_SUBMIT}"
						class="button1" />{S_FORM_TOKEN}
					</fieldset>
				</form></p><!-- ENDIF -->

<!-Weather in {WEATHER_LOC}, England on your site - HTML code - weatherforecastmap.com --><div align="center"><script src="http://www.weatherforecastmap.com/weather3.php?zona=england_{WEATHER_LOC}"></script><a alt="Weather Today in {WEATHER_LOC}" title="Weather Today in {WEATHER_LOC}" href="http://www.weatherforecastmap.com/england/{WEATHER_LOC}" >Weather Today in {WEATHER_LOC}</a></div><!-end of code-->	<span class="portal-corners-bottom"><span></span></span>

	</div>
</div>
<br style="clear:both" />
Any help and advice would be appreciated

Regards
Doug

Re: Weather forecasts

Posted: 30. June 2009 07:57
by Mike
Just a minor remark: Please make sure to make your Block (html) compatible with B3P 1.0.3
Knowledge Base: Adding Custom Blocks

Re: Weather forecasts

Posted: 30. June 2009 13:39
by thepips
Thanks for that. I'd better get my forum upgraded to 1.0.3 then!

Re: Weather forecasts

Posted: 30. June 2009 22:51
by Mike
Thats a good idea ;) If you know any more information, you can browse our KB... There are a lot of helpful Articles :)

Re: Weather forecasts

Posted: 31. August 2009 14:53
by thepips
Well, I'm making small steps but I could really do with a bit of help. I just can't get the table updated. Please can anyone help?
Here is the block

Code: Select all

<?php
	if (!defined('IN_PHPBB'))
        {
           exit;
        }

    if (!defined('IN_PORTAL'))
        {
           exit;
        }

include($phpbb_root_path . 'portal/includes/functions_weather.' . $phpEx);

	if ($user->data['user_id'] > 1)
	{
		$display_menu = true;	
	}
	else
	{
		$display_menu = false;
	}
		
// If the user is logged in

		if ($user->data['user_id'] != ANONYMOUS)
		{
			$location = request_var('location', '');
			//Get the custom profile field for this user
			$user->get_profile_fields($user->data['user_id']);
			
			//If they have a location set, use it
			if (!empty($user->profile_fields['pf_location']))
			{   
			   	$location = $user->profile_fields['pf_location'];
				
				/**
				 * We are cleaning any unwanted data out of the string
				 * @var string mixed
				 */
				$location = clean_location($location);
			}
			else
			{
				/**
				 * We will select a random location and return it
				 * @return string mixed $location
				 */
				$location = random_location();				/**
				 * We are cleaning any unwanted data out of the string
				 * @var string mixed
				 */
				$location = clean_location($location);
			}
			/**
			 * This is where the action starts
			 * @var $location string mixed
			 */			
//			build_weather::get_weather($location);
		}
		// If not logged in, use the default or let them check their weather via URL
		elseif ($user->data['user_id'] == ANONYMOUS && !$auth->acl_get('u_weather'))
		{
		   	/**
			 * We will select a random location and return it
	 		 * @return string mixed $location
	 		 */ 
			$location = random_location();
			/**
			 * We are cleaning any unwanted data out of the string
			 * @var string mixed
			 */
			$location = clean_location($location);
		}

	$template->assign_vars(array(
                'WEATHER_LOC'     => (!empty($location)) ? $location : '', 
                'USERID_WEATHER' => $userid_weather,
                'SHOW_SEARCH' => $display_menu,
				'U_UPDATE_LOCATION'		=> append_sid("{$phpbb_root_path}portal/includes/update_location.$phpEx"),
            ));
		
	
?>
and this is the associated HTML

Code: Select all

{$LR_BLOCK_H_L}<img src="{T_THEME_PATH}/images/portal/portal_weather.png" width="16px" height="16px" alt=""/>&nbsp;Weather{$LR_BLOCK_H_R}                     
<div class="portal-panel">
	<div class="inner">
		<span class="portal-corners-top"><span></span></span>
				<!-- IF SHOW_SEARCH -->
				<form method="post" id="forecast" action="{U_UPDATE_LOCATION}">
					<input type="hidden"
						name="theuser"
						value="{USERID_WEATHER}"
					/>
					<input type="text"
						tabindex="6"
						name="location"
						id="searchfield"
						size="22"
						maxlength="40"
						title="Enter town or postcode"
						class="inputbox search"
						value="{WEATHER_LOC}"
						onclick="if(this.value=='Weather')this.value='{WEATHER_LOC}';"
					/>
					<fieldset class="submit-buttons">
					<input type="reset"
						value="{L_RESET}"
						name="reset"
						class="button2" />
					<input type="submit"
						name="action"
						value="{L_SUBMIT}"
						class="button1" />{S_FORM_TOKEN}
					</fieldset>
				</form></p><!-- ENDIF -->

<!-Weather in {WEATHER_LOC}, UK on your site - HTML code - weatherforecastmap.com --><div align="center"><script src="http://www.weatherforecastmap.com/weather3.php?zona=england_{WEATHER_LOC}"></script><a alt="Weather Today in {WEATHER_LOC}" title="Weather Today in {WEATHER_LOC}" href="http://www.weatherforecastmap.com/england/{WEATHER_LOC}" target='_blank'>Weather Today in {WEATHER_LOC}</a></div><!-end of code-->	<span class="portal-corners-bottom"><span></span></span>

	</div>
</div>
<br style="clear:both" />
           
    {$LR_BLOCK_F_L}{$LR_BLOCK_F_R}
And finally here is the PHP that is executed when you click on submit

Code: Select all

<?php

/**
 * @author Action Replay
 * @copyright 2009
 */
 
if (!defined('IN_PHPBB'))
{
   exit;
}

if (!defined('IN_PORTAL'))
{
   exit;
}

$user_id = $_POST('theuser');

	if ($user_id != ANONYMOUS)
	{
		//Get the custom profile field for this user
		$sql = 'UPDATE ' . PROFILE_FIELDS_DATA . '
				SET pf_location = "' . $_POST['location']
				 . '" WHERE user_id = ' . (int) $user_id;
		$db->sql_query($sql);
	}
?>
Really would appreciate any hints or tips to move this along a bit further.

If you'd like to see what I've got so far have a look at my website
The userid is test user with password letmein

Regards
Doug

Re: Weather forecasts

Posted: 3. September 2009 08:29
by thepips
bump.
Can anyone help me? or at least point me in a direction where I can find the info to help myself.
Regards
Doug

Re: Weather forecasts

Posted: 5. September 2009 10:27
by thepips
I'm not making a lot of progress on this. I'd really appreciate a steer on where I'm going wrong