Page 1 of 1

User changeable weather forecasts

Posted: 6. November 2009 20:18
by thepips
Hi,
I've seen a couple of weather forecasts on here but wanted to do something a bit different. I've added a box to allow the users to change the city from the portal.
Have a look on my forum http://www.arvclub.co.uk, userid test user, password letmein.
You can enter a city in the UK or country, city for any other country.

First of all you'll need to create a custom profile field called location to hold the weather forecast location in.
Edit UCP.php and find

Code: Select all

	default:
		$default = true;
	break;
}
Insert before the found line

Code: Select all

	case 'update_location':
			$sql = 'UPDATE phpbb_profile_fields_data SET pf_location = "' . $_POST['location'] . '" WHERE user_id = ' . $user->data['user_id'];
			$db->sql_query($sql);
			$affected_rows =$db->sql_affectedrows();
			if ($affected_rows == 0)
			{
				$db->sql_query('INSERT phpbb_profile_fields_data ' . $db->sql_build_array('INSERT', array(
					'user_id'		=> $user->data['user_id'],
					'pf_location'	=> $_POST['location'])));
			}
			redirect(append_sid("../portal.$phpEx"));

	break;
Create a new file called /Forum/portal/block/weather.php

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 pf_location FROM phpbb_profile_fields_data WHERE user_id = " . $userid_weather;
    $result = $db->sql_query_limit($sql, 1);
    $weather_location = $db->sql_fetchfield('pf_location');
	$charpos=strpos($weather_location, ',');
	if ($charpos)
	{
		$country=substr($weather_location,0, $charpos);
		$weather_location=substr($weather_location,$charpos+1);	
	}
	else
	{
		$country='united-kingdom';
	}
	$city = str_replace(" ","-", ltrim($weather_location));
            $db->    sql_freeresult($result);
            $template->assign_vars(array(
                'WEATHER_LOC'     => (!empty($weather_location)) ? $weather_location : 'England',
                'USERID_WEATHER' => $userid_weather,
                'SHOW_SEARCH' => $display_menu,
                'COUNTRY' => $country,
                'CITY' => $city,
		'U_UPDATE_LOCATION'		=> append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=update_location'),
            ));
?>
And another file called /Forum/styles/prosilver/template/portal/block/weather.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={COUNTRY}_{CITY}"></script><a alt="Weather Today in {WEATHER_LOC}" title="Weather Today in {WEATHER_LOC}" href="http://www.weatherforecastmap.com/{COUNTRY}/{CITY}" 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}
Hope you like it.

Regards
Doug