Weather forecasts

Forum rules
This forum is not for support requests.

Only post Modifications for Board3 Portal 1.0.x in this forum.
Locked

Topic author
thepips
Active Member
Posts: 22
Joined: 23. December 2008 15:50
phpBB.com User: thepips

Weather forecasts

Post 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
User avatar

Mike
Former Team Member
Posts: 1862
Joined: 3. July 2008 23:59
Location: Schwarzwald / FDS
Contact:

Re: Weather forecasts

Post 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
kein Support per PN / Messenger
no Support via PM / Messenger

Topic author
thepips
Active Member
Posts: 22
Joined: 23. December 2008 15:50
phpBB.com User: thepips

Re: Weather forecasts

Post by thepips »

Thanks for that. I'd better get my forum upgraded to 1.0.3 then!
User avatar

Mike
Former Team Member
Posts: 1862
Joined: 3. July 2008 23:59
Location: Schwarzwald / FDS
Contact:

Re: Weather forecasts

Post by Mike »

Thats a good idea ;) If you know any more information, you can browse our KB... There are a lot of helpful Articles :)
kein Support per PN / Messenger
no Support via PM / Messenger

Topic author
thepips
Active Member
Posts: 22
Joined: 23. December 2008 15:50
phpBB.com User: thepips

Re: Weather forecasts

Post 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

Topic author
thepips
Active Member
Posts: 22
Joined: 23. December 2008 15:50
phpBB.com User: thepips

Re: Weather forecasts

Post 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

Topic author
thepips
Active Member
Posts: 22
Joined: 23. December 2008 15:50
phpBB.com User: thepips

Re: Weather forecasts

Post by thepips »

I'm not making a lot of progress on this. I'd really appreciate a steer on where I'm going wrong
Locked

Return to “board3 Portal v1.0.x - Modifications in Dev”