############################################################## 
## MOD Title: JC Topic View Tracker
## MOD Author: BondGamer < jcthebuilder1@yahoo.com > (JC the Builder) http://www.bondgamer.com
## MOD Description:	This MOD will allow moderators and administrators to track who views each topic. 
##			Each time a user opens a topic page in an activated forum, their name and IP is recorded. 
##			This can be useful for making sure unauthorized users don't have access to certain areas of your board.
##
## MOD Version:		0.5.2
## 
## Installation Level: 	Easy
## Installation Time:  	15 Minutes 
## Files To Edit: 7
##			mcp.php
##			viewtopic.php
##			adm/style/acp_forums.html
##			includes/constants.php
##			includes/acp/acp_forums.php
##			language/en/viewtopic.php
##			language/en/acp_acp_forums.php
## Included Files: 5
##			topic_view_tracker.php
##			topic_view_tracker_db_update.php
##			language/en/mods/permissions_tracker.php
##			styles/prosilver/templates/topic_view_tracker.html
##			styles/subsilver2/templates/topic_view_tracker.html
## License: http://opensource.org/licenses/gpl-license.php GNU General Public License v2 
##############################################################
## For security purposes, please check: http://www.bondgamer.com
## Or http://www.phpbb.com/community/viewtopic.php?f=70&t=546593
## for the latest version of this MOD. No support
## will be given for MODs not found within the MODs Database
##############################################################
## Author Notes: 
## 
##  Copyright 2007-2008 JC the Builder
##
##############################################################
## History:
##  (yyyy-mm-dd)
##   2008-6-5 - Version 0.5.2 (BETA)
##      - Fixed permission naming conflict
##   2008-6-5 - Version 0.5.1 (BETA)
##      - Fixed SQL error in create table
##      - Added in missing mcp.php edit
##   2008-6-4 - Version 0.5.0 (BETA)
##      - Streamlined permission checks
##      - No longer tracks anonymous users (cost for overhead was not worth it)
##      - Added toggles to enable/disable tracker for each forum
##      - Topic View Tracker link moved to quick-mod select on topic pages
##      - All SQL updates now done via one executable file (topic_view_tracker_db_update.php)
##   2007-5-30 - Version 0.1.0 (BETA)
##      - Initial Beta release
##############################################################
#
#-----[ COPIAR ]----------------------
#

topic_view_tracker_db_update.php to ./topic_view_tracker_db_update.php
root/topic_view_tracker.php to ./topic_view_tracker.php
root/language/en/mods/permissions_tracker.php to ./language/en/mods/permissions_tracker.php
root/styles/prosilver/templates/topic_view_tracker.html to ./styles/prosilver/templates/topic_view_tracker.html
root/styles/subsilver2/templates/topic_view_tracker.html to ./styles/subsilver2/templates/topic_view_tracker.html

#
#-----[ DIY ]----------------------
#

Your forum SQL user needs the permissions to CREATE and ALTER tables.
Most likely you have them, otherwise you need to perform the SQL operations manually.

Go to topic_view_tracker_db_update.php.
If the database updates are successful !DELETE THE FILE! and continue installation.
If there is an error then request help in phpBB topic (http://www.phpbb.com/community/viewtopic.php?f=70&t=546593)

#
#-----[ ABRIR ]----------------------
#

mcp.php

#
#-----[ BUSCAR ]----------------------
#

default:
	trigger_error("$action not allowed as quickmod");

#
#-----[ AGREGAR ANTES ]----------------------
#

case 'topic_view_tracker':
	redirect(append_sid("{$phpbb_root_path}topic_view_tracker.$phpEx?t=$topic_id"));
break;

#
#-----[ ABRIR ]----------------------
#

viewtopic.php

#
#-----[ BUSCAR ]----------------------
#

// What is start equal to?

#
#-----[ AGREGAR ANTES ]----------------------
#

// Begin JC Topic View Tracker MOD
if ($topic_data['forum_topic_tracker'] && $user->data['is_registered'])
{
	$sql = 'UPDATE ' . TOPIC_TRACKER_TABLE . " 
			SET topic_id = $topic_id, view_time = " . time() . ", last_ip = '".$user->ip."', view_count = view_count + 1 
			WHERE topic_id = $topic_id 
				AND user_id = " . $user->data['user_id'] . "";
	if ( !$db->sql_query($sql) || !$db->sql_affectedrows() )
	{	
		// This is the first time user viewing topic, insert new record
		$sql = 'INSERT IGNORE INTO ' . TOPIC_TRACKER_TABLE . ' (topic_id, user_id, view_time, last_ip, view_count)
				VALUES (' . $topic_id . ', ' . $user->data['user_id'] . ', ' . time() . ", '" . $user->ip . "', 1)";
		$db->sql_query($sql);
	}
}
// End JC Topic View Tracker MOD

#
#-----[ BUSCAR ]----------------------
#

$topic_mod .= ($auth->acl_get('m_', $forum_id)) ? '<option value="topic_logs">' . $user->lang['VIEW_TOPIC_LOGS'] . '</option>' : '';

#
#-----[ AGREGAR DESPUES ]----------------------
#

// Begin JC Topic View Tracker MOD
$topic_mod .= (($auth->acl_get('a_') || $auth->acl_getf_global('m_') || $auth->acl_get('m_tracker', $forum_id)) && $topic_data['forum_topic_tracker']) ? '<option value="topic_view_tracker">' . $user->lang['TOPIC_VIEW_TRACKER'] . '</option>' : '';
// End JC Topic View Tracker MOD

#
#-----[ ABRIR ]----------------------
#

adm/style/acp_forums.html

#
#-----[ BUSCAR ]----------------------
#

<dl>
	<dt><label for="topics_per_page">{L_FORUM_TOPICS_PAGE}:</label><br /><span>{L_FORUM_TOPICS_PAGE_EXPLAIN}</span></dt>
	<dd><input type="text" id="topics_per_page" name="topics_per_page" value="{TOPICS_PER_PAGE}" size="4" maxlength="4" /></dd>
</dl>

#
#-----[ AGREGAR DESPUES ]----------------------
#

<dl>
	<dt><label for="forum_topic_tracker">{L_TOPIC_TRACKER}:</label><br /><span>{L_TOPIC_TRACKER_EXPLAIN}</span></dt>
	<dd><input type="radio" class="radio" name="forum_topic_tracker" value="1"<!-- IF S_TOPIC_TRACKER_ENABLE --> id="forum_topic_tracker" checked="checked"<!-- ENDIF --> /> {L_YES} &nbsp; <input type="radio" class="radio" name="forum_topic_tracker" value="0"<!-- IF not S_TOPIC_TRACKER_ENABLE --> id="forum_topic_tracker" checked="checked"<!-- ENDIF --> /> {L_NO}</dd>
</dl>

#
#-----[ ABRIR ]----------------------
#

includes/constants.php

#
#-----[ BUSCAR ]----------------------
#

// Additional tables

#
#-----[ AGREGAR DESPUES ]----------------------
#

define('TOPIC_TRACKER_TABLE',		$table_prefix . 'topic_tracker');

#
#-----[ ABRIR ]----------------------
#

includes/acp/acp_forums.php

#
#-----[ BUSCAR ]----------------------
#

'forum_password_confirm'=> request_var('forum_password_confirm', '', true),

#
#-----[ AGREGAR DESPUES ]----------------------
#

'forum_topic_tracker'	=> request_var('forum_topic_tracker', 0),

#
#-----[ BUSCAR ]----------------------
#

'forum_password_confirm'=> '',

#
#-----[ AGREGAR DESPUES ]----------------------
#

'forum_topic_tracker'	=> false,

#
#-----[ BUSCAR ]----------------------
#

'FORUM_RULES_PLAIN'			=> $forum_rules_data['text'],

#
#-----[ AGREGAR DESPUES ]----------------------
#

'TOPIC_TRACKER'				=> $forum_data['forum_topic_tracker'],

#
#-----[ BUSCAR ]----------------------
#

'S_ENABLE_POST_REVIEW'		=> ($forum_data['forum_flags'] & FORUM_FLAG_POST_REVIEW) ? true : false,

#
#-----[ AGREGAR DESPUES ]----------------------
#

'S_TOPIC_TRACKER_ENABLE'	=> ($forum_data['forum_topic_tracker']) ? true : false,

#
#-----[ ABRIR ]----------------------
#

language/en/viewtopic.php

#
#-----[ BUSCAR ]----------------------
#

'MOVE_TOPIC'				=> 'Move topic',

#
#-----[ AGREGAR DESPUES ]----------------------
#

'TOPIC_VIEW_TRACKER'		=> 'Topic View Tracker',

#
#-----[ ABRIR ]----------------------
#

language/en/acp/forums.php

#
#-----[ BUSCAR ]----------------------

));

#
#-----[ AGREGAR ANTES ]----------------------
#

'TOPIC_TRACKER'						=> 'Track Topic Viewers',
'TOPIC_TRACKER_EXPLAIN'				=> 'Record registered users who view topics in this forum. Moderators with the Topic View Tracker permission can see this information via quick-mod select.',

#
#-----[ ABRIR ]----------------------
#

language/es/viewtopic.php

#
#-----[ BUSCAR ]----------------------
#

'MOVE_TOPIC'				=> 'Mover tema',

#
#-----[ AGREGAR DESPUES ]----------------------
#

'TOPIC_VIEW_TRACKER'		=> 'Ver seguimiento de tema',

#
#-----[ ABRIR ]----------------------
#

language/es/acp/forums.php

#
#-----[ BUSCAR ]----------------------

));

#
#-----[ AGREGAR ANTES ]----------------------
#

'TOPIC_TRACKER'						=> 'Seguimiento de vistas de temas',
'TOPIC_TRACKER_EXPLAIN'				=> 'Seguimiento de usuarios que ven los temas en este foro. Los Moderadores con permisos para ver seguimiento de tema pueden ver esta informacin.',

#
#-----[ GUARDE/CIERRE TODOS LOS ARCHIVOS ]------------------------------------------
#
# EoM
