##############################################################
## MOD Title:		Forumtitle as Weblink
## MOD Author: OXPUS < webmaster@oxpus.de > (Karsten Ude) http://www.oxpus.de
## MOD Description:	Gives admins the possibility to enter a weblink for forumtitles
##			to link on an internal or external site instead to a forum.
## MOD Version:		1.2.0
##
## Spanish Translation: ThE KuKa - http://www.phpbb-es.com
## Installation Level:	Easy
## Installation Time:	3-5 Minutes
## Files To Edit:	7
##			index.php
##			admin/admin_forums.php
##			language/lang_english/lang_admin.php
##			language/lang_german/lang_admin.php
##			language/lang_english/lang_main.php
##			language/lang_german/lang_main.php
##			templates/subSilver/index_body.tpl
##			templates/subSilver/admin/forum_edit_body.tpl
##
## Included Files:	n/a
##############################################################
## For Security Purposes, Please Check: http://www.phpbb.com/mods/ for the
## latest version of this MOD. Downloading this MOD from other sites could cause malicious code
## to enter into your phpBB Forum. As such, phpBB will not offer support for MOD's not offered
## in our MOD-Database, located at: http://www.phpbb.com/mods/
##############################################################
## Author Notes:
##
## Instead entering the given SQL-Statement, you can upload the file db_update.php
## to your phpbb root directory and run this with your browser.
## This file will do all nessassary changes in the database for you.
## After using this file, please delete it to avoid errors.
##
## If you have installed the Categories Hierarchy Mod, don't install this mod, too!
## Creating a forum as a weblink is possible with the Categories Hierarchy Mod!
##
##############################################################
## MOD History:
##
##   2004-08-16 - Version 1.2.0
##      - Add counter for links
##
##   2004-02-08 - Version 1.1.2
##      - Fix a typo in the HowTo
##
##   2004-01-25 - Version 1.1.1
##      - Passed through phpBB.com Mod Validator
##
##   2004-01-21 - Version 1.1.0
##      - Enter a different forum icon
##	- Fix colums posts, topics and last post on index
##
##   2004-01-17 - Version 1.0.0
##      - First release
##
##############################################################
## Before Adding This MOD To Your Forum, You Should Back Up All Files Related To This MOD
##############################################################

#
#-----[ SQL ]------------------------------------------
#
ALTER TABLE `phpbb_forums` ADD `title_is_link` TINYINT( 1 ) DEFAULT '0' NOT NULL,
ADD `weblink` VARCHAR( 200 ) NOT NULL,
ADD `forum_link_icon` VARCHAR( 200 ) NOT NULL,
ADD `forum_link_count` MEDIUMINT(8) UNSIGNED NOT NULL;

#
#-----[ OPEN ]------------------------------------------
#
index.php

#
#-----[ FIND ]------------------------------------------
#
//
// Start session management
//
$userdata = session_pagestart($user_ip, PAGE_INDEX);
init_userprefs($userdata);
//
// End session management
//

#
#-----[ AFTER, ADD ]------------------------------------------
#
$forum_id = ( isset($HTTP_POST_VARS[POST_FORUM_URL]) ) ? intval($HTTP_POST_VARS[POST_FORUM_URL]) : intval($HTTP_GET_VARS[POST_FORUM_URL]);
$forum_link = ( isset($HTTP_POST_VARS['forum_link']) ) ? intval($HTTP_POST_VARS['forum_link']) : intval($HTTP_GET_VARS['forum_link']);

if ( $forum_link == 1 && $forum_id != 0 )
{
	$sql = "UPDATE " . FORUMS_TABLE . "
		SET forum_link_count = forum_link_count + 1
		WHERE forum_id = $forum_id";
	if ( !$db->sql_query($sql) )
	{
		message_die(GENERAL_ERROR, 'Could not update link counter', '', __LINE__, __FILE__, $sql);
	}

	$sql = "SELECT weblink FROM " . FORUMS_TABLE . "
		WHERE forum_id = $forum_id";
	if ( !$result = $db->sql_query($sql) )
	{
		message_die(GENERAL_ERROR, 'Could not read forum weblink', '', __LINE__, __FILE__, $sql);
	}

	while ( $row = $db->sql_fetchrow($result) )
	{
		$forum_weblink = $row['weblink'];
	}

	header("Location: ".$forum_weblink);
	exit;
}

#
#-----[ FIND ]------------------------------------------
#
								'FORUM_FOLDER_IMG' => $folder_image,

#
#-----[ REPLACE WITH ]------------------------------------------
#
								'FORUM_FOLDER_IMG' => ( $forum_data[$j]['title_is_link'] == 1 && $forum_data[$j]['forum_link_icon'] != '' ) ? $forum_data[$j]['forum_link_icon'] : $folder_image,
								'FORUM_LINK_COUNT' => ( $forum_data[$j]['title_is_link'] == 1 ) ? sprintf($lang['Forum_link_count'], $forum_data[$j]['forum_link_count']) : '',

#
#-----[ FIND ]------------------------------------------
#
								'U_VIEWFORUM' => append_sid("viewforum.$phpEx?" . POST_FORUM_URL . "=$forum_id"))
							);

#
#-----[ REPLACE WITH ]------------------------------------------
#
								'U_VIEWFORUM' => ( $forum_data[$j]['title_is_link'] == 1 ) ? append_sid("index.$phpEx?" . POST_FORUM_URL . "=$forum_id&amp;forum_link=1") : append_sid("viewforum.$phpEx?" . POST_FORUM_URL . "=$forum_id"))

							);

							if ( $forum_data[$j]['title_is_link'] == 1 )
							{
								$template->assign_block_vars('catrow.forumrow.switch_forum_link_on', array());
							}
							else
							{
								$template->assign_block_vars('catrow.forumrow.switch_forum_link_off', array());
							}

#
#-----[ OPEN ]------------------------------------------
#
admin/admin_forums.php

#
#-----[ FIND ]------------------------------------------
#
				$forumdesc = $row['forum_desc'];
				$forumstatus = $row['forum_status'];

#
#-----[ AFTER, ADD ]------------------------------------------
#
				$forum_is_link = $row['title_is_link'];
				$forum_weblink = $row['weblink'];
				$forum_link_icon = $row['forum_link_icon'];

#
#-----[ FIND ]------------------------------------------
#
				'L_FORUM_TITLE' => $l_title, 

#
#-----[ AFTER, ADD ]------------------------------------------
#
				'L_FORUM_IS_LINK' => $lang['Forum_is_link'],
				'L_FORUM_WEBLINK' => $lang['Forum_weblink'],
				'L_FORUM_LINK_ICON' => $lang['Forum_link_icon'],

#
#-----[ FIND ]------------------------------------------
#
				'DESCRIPTION' => $forumdesc)

#
#-----[ REPLACE WITH ]------------------------------------------
#
				'DESCRIPTION' => $forumdesc,
				'FORUM_IS_LINK' => ( $forum_is_link == 1 ) ? 'checked="checked"' : '',
				'FORUM_WEBLINK' => $forum_weblink,
				'FORUM_LINK_ICON' => $forum_link_icon)

#
#-----[ FIND ]------------------------------------------
#
			// These two options ($lang['Status_unlocked'] and $lang['Status_locked']) seem to be missing from

#
#-----[ BEFORE, ADD ]------------------------------------------
#
			$forum_is_link = ( empty($forum_is_link) ) ? 0 : $forum_is_link;

#
#-----[ FIND ]------------------------------------------
#
			$sql = "INSERT INTO " . FORUMS_TABLE . " (forum_id, forum_name, cat_id, forum_desc, forum_order, forum_status, prune_enable" . $field_sql . ")
				VALUES ('" . $next_id . "', '" . str_replace("\'", "''", $HTTP_POST_VARS['forumname']) . "', " . intval($HTTP_POST_VARS[POST_CAT_URL]) . ", '" . str_replace("\'", "''", $HTTP_POST_VARS['forumdesc']) . "', $next_order, " . intval($HTTP_POST_VARS['forumstatus']) . ", " . intval($HTTP_POST_VARS['prune_enable']) . $value_sql . ")";

#
#-----[ REPLACE WITH ]------------------------------------------
#
			$sql = "INSERT INTO " . FORUMS_TABLE . " (forum_id, forum_name, cat_id, forum_desc, forum_order, forum_status, prune_enable" . $field_sql . ", title_is_link, weblink, forum_link_icon)
				VALUES ('" . $next_id . "', '" . str_replace("\'", "''", $HTTP_POST_VARS['forumname']) . "', " . intval($HTTP_POST_VARS[POST_CAT_URL]) . ", '" . str_replace("\'", "''", $HTTP_POST_VARS['forumdesc']) . "', $next_order, " . intval($HTTP_POST_VARS['forumstatus']) . ", " . intval($HTTP_POST_VARS['prune_enable']) . $value_sql . ", " . intval($HTTP_POST_VARS['forum_is_link']) . ", '" . str_replace("\'", "''", $HTTP_POST_VARS['weblink']) . "', '" . str_replace("\'", "''", $HTTP_POST_VARS['forum_link_icon']) . "')";

#
#-----[ FIND ]------------------------------------------
#
			$sql = "UPDATE " . FORUMS_TABLE . "
				SET forum_name = '" . str_replace("\'", "''", $HTTP_POST_VARS['forumname']) . "', cat_id = " . intval($HTTP_POST_VARS[POST_CAT_URL]) . ", forum_desc = '" . str_replace("\'", "''", $HTTP_POST_VARS['forumdesc']) . "', forum_status = " . intval($HTTP_POST_VARS['forumstatus']) . ", prune_enable = " . intval($HTTP_POST_VARS['prune_enable']) . "
				WHERE forum_id = " . intval($HTTP_POST_VARS[POST_FORUM_URL]);

#
#-----[ REPLACE WITH ]------------------------------------------
#
			$sql = "UPDATE " . FORUMS_TABLE . "
				SET forum_name = '" . str_replace("\'", "''", $HTTP_POST_VARS['forumname']) . "', cat_id = " . intval($HTTP_POST_VARS[POST_CAT_URL]) . ", forum_desc = '" . str_replace("\'", "''", $HTTP_POST_VARS['forumdesc']) . "', forum_status = " . intval($HTTP_POST_VARS['forumstatus']) . ", prune_enable = " . intval($HTTP_POST_VARS['prune_enable']) . ", title_is_link = " . intval($HTTP_POST_VARS['forum_is_link']) . ", weblink = '" . str_replace("\'", "''", $HTTP_POST_VARS['forum_weblink']) . "', forum_link_icon = '" . str_replace("\'", "''", $HTTP_POST_VARS['forum_link_icon']) . "'
				WHERE forum_id = " . intval($HTTP_POST_VARS[POST_FORUM_URL]);

#
#-----[ FIND ]------------------------------------------
#
					'NUM_TOPICS' => $forum_rows[$j]['forum_topics'],
					'NUM_POSTS' => $forum_rows[$j]['forum_posts'],

					'U_VIEWFORUM' => append_sid($phpbb_root_path."viewforum.$phpEx?" . POST_FORUM_URL . "=$forum_id"),

#
#-----[ REPLACE WITH ]------------------------------------------
#
					'NUM_TOPICS' => ( $forum_rows[$j]['forum_link_icon'] != '' && $forum_rows[$j]['title_is_link'] == 1 ) ? (( substr($forum_rows[$j]['forum_link_icon'],0,4) == 'http' || substr($forum_rows[$j]['forum_link_icon'],0,4) == 'HTTP' ) ? '<img src="'.$forum_rows[$j]['forum_link_icon'].'" border="0">' : '<img src="./../'.$forum_rows[$j]['forum_link_icon'].'" border="0">') : $forum_rows[$j]['forum_topics'],
					'NUM_POSTS' => ( $forum_rows[$j]['forum_link_icon'] != '' && $forum_rows[$j]['title_is_link'] == 1 ) ? '' : $forum_rows[$j]['forum_posts'],

					'U_VIEWFORUM' => ( $forum_rows[$j]['title_is_link'] == 1 ) ? $forum_rows[$j]['weblink'] : append_sid($phpbb_root_path."viewforum.$phpEx?" . POST_FORUM_URL . "=$forum_id"),

#
#-----[ OPEN ]------------------------------------------
#
language/lang_spanish/lang_admin.php

#
#-----[ FIND ]------------------------------------------
#
?>

#
#-----[ BEFORE, ADD ]------------------------------------------
#
$lang['Forum_is_link'] = 'Cambiar el titulo del foro por enlace Web';
$lang['Forum_weblink'] = 'Enlace Web ( incluyendo HTTP:// )';
$lang['Forum_link_icon'] = 'Icono para este Foro. Este reemplaza el icono por defecto del indice del foro.<br />Usted puede introducir una imagen desde su directorio de phpBB (desde "/")<br />o enlace externo (ruta completa).';

#
#-----[ OPEN ]------------------------------------------
#
language/lang_spanish/lang_main.php

#
#-----[ FIND ]------------------------------------------
#
?>

#
#-----[ AFTER, ADD ]------------------------------------------
#
$lang['Forum_link_count'] = 'Enlace visitado en %s ocasiones.';

#
#-----[ OPEN ]------------------------------------------
#
templates/subSilver/index_body.tpl

#
#-----[ FIND ]------------------------------------------
#
	<td class="row1" align="center" valign="middle" height="50"><img src="{catrow.forumrow.FORUM_FOLDER_IMG}" width="46" height="25" alt="{catrow.forumrow.L_FORUM_FOLDER_ALT}" title="{catrow.forumrow.L_FORUM_FOLDER_ALT}" /></td>

#
#-----[ REPLACE WITH ]------------------------------------------
#
	<td class="row1" align="center" valign="middle" height="50"><img src="{catrow.forumrow.FORUM_FOLDER_IMG}" alt="{catrow.forumrow.L_FORUM_FOLDER_ALT}" title="{catrow.forumrow.L_FORUM_FOLDER_ALT}" /></td>

#
#-----[ FIND ]------------------------------------------
#
	<td class="row2" align="center" valign="middle" height="50"><span class="gensmall">{catrow.forumrow.TOPICS}</span></td>
	<td class="row2" align="center" valign="middle" height="50"><span class="gensmall">{catrow.forumrow.POSTS}</span></td>
	<td class="row2" align="center" valign="middle" height="50" nowrap="nowrap"> <span class="gensmall">{catrow.forumrow.LAST_POST}</span></td>

#
#-----[ REPLACE WITH ]------------------------------------------
#
<!-- BEGIN switch_forum_link_off -->
	<td class="row2" align="center" valign="middle" height="50"><span class="gensmall">{catrow.forumrow.TOPICS}</span></td>
	<td class="row2" align="center" valign="middle" height="50"><span class="gensmall">{catrow.forumrow.POSTS}</span></td>
	<td class="row2" align="center" valign="middle" height="50" nowrap="nowrap"> <span class="gensmall">{catrow.forumrow.LAST_POST}</span></td>
<!-- END switch_forum_link_off -->
<!-- BEGIN switch_forum_link_on -->
	<td class="row2" align="center" valign="middle" height="50" colspan="3"><span class="gensmall">{catrow.forumrow.FORUM_LINK_COUNT}</span></td>
<!-- END switch_forum_link_on -->

#
#-----[ OPEN ]------------------------------------------
#
templates/subSilver/admin/forum_edit_body.tpl

#
#-----[ FIND ]------------------------------------------
#
	<tr>
	  <td class="row1">{L_FORUM_STATUS}</td>
	  <td class="row2"><select name="forumstatus">{S_STATUS_LIST}</select></td>
	</tr>

#
#-----[ AFTER, ADD ]------------------------------------------
#
	<tr>
	  <td class="row1">{L_FORUM_IS_LINK}</td>
	  <td class="row2"><input class="post" type="checkbox" name="forum_is_link" value="1" {FORUM_IS_LINK} /></td>
	</tr>
	<tr>
	  <td class="row1">{L_FORUM_WEBLINK}</td>
	  <td class="row2"><input class="post" type="text" size="25" maxlength="200" name="forum_weblink" value="{FORUM_WEBLINK}" /></td>
	</tr>
	<tr>
	  <td class="row1">{L_FORUM_LINK_ICON}</td>
	  <td class="row2"><input class="post" type="text" size="25" maxlength="200" name="forum_link_icon" value="{FORUM_LINK_ICON}" /></td>
	</tr>


#
#-----[ SAVE/CLOSE ALL FILES ]------------------------------------------
#
# EoM