####################################################################################################
## MOD Title: Democracy MOD
## MOD Author: Carbofos < carbofos@mail.ru > (N/A) N/A
## MOD Author: ETZel < N/A > (N/A) N/A
## MOD Description: Adds some social mechanisms to the phpBB (namely: warnings + reputation + reports)
## MOD Version: 0.1.4
##
## Installation Level: Intermediate
## Installation Time: ~15 Minutes
## Files To Edit (15):
##      index.php
##      posting.php
##      profile.php
##      viewtopic.php
##      admin/admin_db_utilities.php
##      includes/constants.php
##      includes/functions_post.php
##      includes/page_header.php
##      includes/usercp_viewprofile.php
##      language/lang_english/lang_admin.php
##      language/lang_english/lang_main.php
##      templates/subSilver/subSilver.cfg
##      templates/subSilver/index_body.tpl
##      templates/subSilver/profile_view_body.tpl
##      templates/subSilver/viewtopic_body.tpl
## Included Files (20):
##      post_report.php
##      admin/admin_democracy.php
##      includes/usercp_reputation.php
##      language/lang_english/email/reputation_ban.tpl
##      language/lang_english/email/reputation_warning.tpl
##      templates/subSilver/modcp_post_report_body.tpl
##      templates/subSilver/profile_modify_reputation.tpl
##      templates/subSilver/profile_view_reputation.tpl
##      templates/subSilver/profile_warning.tpl
##      templates/subSilver/admin/reputation_body.tpl
##      templates/subSilver/images/icon_ban.gif
##      templates/subSilver/images/icon_edit_small.gif
##      templates/subSilver/images/icon_lock_small.gif
##      templates/subSilver/images/icon_red.gif
##      templates/subSilver/images/icon_report.gif
##      templates/subSilver/images/icon_warning.gif
##      templates/subSilver/images/icon_yellow.gif
##      templates/subSilver/images/thumb_dn.gif
##      templates/subSilver/images/thumb_up.gif
##      templates/subSilver/images/lang_english/icon_reviews.gif
##
## License: http://opensource.org/licenses/gpl-license.php GNU General Public License v2
####################################################################################################
##
## For security purposes, please check: http://www.phpbb.com/mods/
## for the latest version of this MOD. Although MODs are checked
## before being allowed in the MODs Database there is no guarantee
## that there are no security problems within the MOD. No support
## will be given for MODs not found within the MODs Database which
## can be found at http://www.phpbb.com/mods/
##
####################################################################################################
##
## Author Notes:
##  This MOD adds some of the "democracy" features to phpBB such as "reputation system" and
##  "warnings system" as well as some minor features to help board administration to keep
##  board in order.
##  Please note that both of these systems are subjective, because it wasn't my goal to build
##  an ideal society (has anybody succeeded in this anyway?) so it'll be as objective as board
##  administration will want it to be, just like in real life, heh ;)
## A short description:
##  - Every user now has a so-called reputation, measured in a number
##  - The reason a user might get a reputation point (or lose it) are his/her posts
##  - User has to review one of the posts to add or substract one point to post author's reputation
##  - User can review a post only once and (by default) won't be able to edit the review later
##  - It's up on the board administration to add review requirements (how objective it has to be) to board rules
##  - If a user feels some post (or review) is breaking a board rule he/she can notify officials using a special button
##  - Moderators and administrators can view such reports via a special page and take actions directly from there
##  - These actions include editing or deleting post or review, locking topic, issuing a warning or banning a user
##  - Same actions can be done by moderators directly from the topic
##  - A post (by default) becomes locked after moderator or administrator has edited it
##  - Warnings and bans work the same way as reviews - a reason should be stated
##  - Warnings and even bans can expire over time
##  - Admin can choose whether expired warnings and bans are deleted or kept as expired
##  - After gaining certain amount of non-expired warnings user gets automatically banned (turned on by default)
##  - Administrators and moderators are considered one team, so the warnings system is not applied to them
##  - Username which has the most reputation is displayed in Who is Online box
##
####################################################################################################
##
## MOD History:
## Versions 0.0.9x
##  - Few prebeta versions
## Version 0.1.0
##  - First beta version
## Version 0.1.1
##  - New feature: bans can also expire over time (setup in ACP separately from warnings expire)
##  - Catched a few minor bugs
## Version 0.1.2
##  - Fixed a bug introduced in version 0.1.1 (forgot to add a little string to constants.php...)
##  - Added feature I forgot to add earlier: delete user reports :)
##  - When you delete post or review that was reported, the report is now deleted too
##  - Some minor improvements
## Version 0.1.3
##  - Fixed bug that made all user's warnings expired
##  - Report post button now appears properly
##  - Fixed some bugs in templates
##  - Added option to view bans/warnings and reviews separately
##  - Added compatibility with Global Moderator Mod and User Level Mod (beta support)
##  - Some more minor code improvements
## Version 0.1.4
##  - Fixed LOTS of bugs
##  - Added MOD's tables to db_utilities tables list
##  - Removed compatibility with Global Moderator Mod and User Level Mod (will be later as add-ons)
##
####################################################################################################
##
## Before Adding This MOD To Your Forum, You Should Back Up All Files Related To This MOD
##
####################################################################################################
#
#-----------------------[ COPY ]-------------------------
#
copy root/post_report.php                                          to post_report.php
copy root/admin/admin_democracy.php                                to admin/admin_democracy.php
copy root/includes/usercp_reputation.php                           to includes/usercp_reputation.php
copy root/language/lang_english/email/reputation_ban.tpl           to language/lang_english/email/reputation_ban.tpl
copy root/language/lang_english/email/reputation_warning.tpl       to language/lang_english/email/reputation_warning.tpl
copy root/templates/subSilver/modcp_post_report_body.tpl           to templates/subSilver/modcp_post_report_body.tpl
copy root/templates/subSilver/profile_modify_reputation.tpl        to templates/subSilver/profile_modify_reputation.tpl
copy root/templates/subSilver/profile_view_reputation.tpl          to templates/subSilver/profile_view_reputation.tpl
copy root/templates/subSilver/profile_warning.tpl                  to templates/subSilver/profile_warning.tpl
copy root/templates/subSilver/admin/reputation_body.tpl            to templates/subSilver/admin/reputation_body.tpl
copy root/templates/subSilver/images/icon_edit_small.gif           to templates/subSilver/images/icon_edit_small.gif
copy root/templates/subSilver/images/icon_lock_small.gif           to templates/subSilver/images/icon_lock_small.gif
copy root/templates/subSilver/images/icon_red.gif                  to templates/subSilver/images/icon_red.gif
copy root/templates/subSilver/images/icon_report.gif               to templates/subSilver/images/icon_report.gif
copy root/templates/subSilver/images/icon_warning.gif              to templates/subSilver/images/icon_warning.gif
copy root/templates/subSilver/images/icon_yellow.gif               to templates/subSilver/images/icon_yellow.gif
copy root/templates/subSilver/images/thumb_dn.gif                  to templates/subSilver/images/thumb_dn.gif
copy root/templates/subSilver/images/thumb_up.gif                  to templates/subSilver/images/thumb_up.gif
copy root/templates/subSilver/images/lang_english/icon_reviews.gif to templates/subSilver/images/lang_english/icon_reviews.gif
#
#------------------------[ SQL ]-------------------------
#
CREATE TABLE `phpbb_reputation` (
  `id` mediumint(8) unsigned NOT NULL auto_increment,
  `modification` tinyint(1) NOT NULL default '0',
  `user_id` mediumint(8) NOT NULL default '0',
  `voter_id` mediumint(8) NOT NULL default '0',
  `post_id` mediumint(8) NOT NULL default '0',
  `forum_id` smallint(5) unsigned NOT NULL default '0',
  `poster_ip` varchar(8) NOT NULL default '',
  `date` int(11) default NULL,
  `expire` int(11) default NULL,
  `edit_time` int(11) default NULL,
  `edit_count` smallint(5) unsigned NOT NULL default '0',
  PRIMARY KEY  (`id`),
  KEY `user_id` (`user_id`),
  KEY `voter_id` (`voter_id`),
  KEY `post_id` (`post_id`),
  KEY `forum_id` (`forum_id`),
  KEY `date` (`date`)
);

CREATE TABLE `phpbb_reputation_text` (
  `id` mediumint(8) unsigned NOT NULL default '0',
  `text` text,
  `bbcode_uid` varchar(10) NOT NULL default '',
  PRIMARY KEY  (`id`)
);

CREATE TABLE `phpbb_post_reports` (
  `report_id` mediumint(8) NOT NULL auto_increment,
  `post_id` mediumint(8) NOT NULL default '0',
  `review_id` mediumint(8) NOT NULL default '0',
  `forum_id` smallint(5) unsigned NOT NULL default '0',
  `user_id` mediumint(8) NOT NULL default '0',
  `report_time` int(11) NOT NULL default '0',
  `reports_num` mediumint(8) NOT NULL default '0',
  PRIMARY KEY  (`report_id`),
  KEY `post_id` (`post_id`),
  KEY `review_id` (`review_id`),
  KEY `forum_id` (`forum_id`)
);

ALTER TABLE `phpbb_users` ADD `reputation` smallint(8) NOT NULL default '0';
ALTER TABLE `phpbb_users` ADD `warnings` tinyint(4) unsigned NOT NULL default '0';

ALTER TABLE `phpbb_posts` ADD `post_reviews` smallint(8) unsigned NOT NULL default '0';
ALTER TABLE `phpbb_posts` ADD `post_locked` tinyint(1) unsigned NOT NULL default '0';

INSERT INTO `phpbb_config` ( `config_name` , `config_value` ) VALUES
('reputation_last_check_time', '0'),
('warnings_enabled', '0'),
('reputation_enabled', '0'),
('reputation_mode', '1'),
('reputation_users_can_edit', '0'),
('reputation_users_can_delete', '0'),
('reputation_anonymous_can_view', '0'),
('reputation_enable_reports', '1'),
('reputation_reports_per_page', '20'),
('reputation_reviews_per_page', '20'),
('reputation_moderators_can_ban', '1'),
('reputation_expire_mod_defined', '1'),
('reputation_expire_lower', '1'),
('reputation_expire_upper', '-1'),
('reputation_expire_default', '30'),
('reputation_check_rate', '3600'),
('reputation_delete_expired', '0'),
('reputation_auto_ban', '1'),
('reputation_num_warnings', '2'),
('reputation_check_reports', '1'),
('reputation_reports_color', 'FF0000'),
('reputation_ban_expire', '0'),
('reputation_ban_expire_lower', '0'),
('reputation_ban_expire_upper', '-1'),
('reputation_ban_exipre_default', '3');

#
#-----[ OPEN ]------------------------------------------
#
index.php
#
#-----[ FIND ]------------------------------------------
#
$newest_uid = $newest_userdata['user_id'];

#
#-----[ AFTER, ADD ]------------------------------------------
#
//////////democracy///////////////////////////////
//
// Get user(s) with the most reputation points
//
if ( $board_config['reputation_enabled'] )
{
    $sql = 'SELECT MAX(reputation) AS maxrep FROM ' . USERS_TABLE;
    if ( !($result = $db->sql_query($sql)) )
    {
        message_die(GENERAL_ERROR, 'Couldn\'t retrieve the reputation stats', '', __LINE__, __FILE__, $sql);
    }
    $reputation_max = $db->sql_fetchrow($result);

    if ( $reputation_max['maxrep'] > 0 )
    {
        $sql = 'SELECT username, user_id, reputation, user_level FROM ' . USERS_TABLE . '
            WHERE user_id <> ' . ANONYMOUS . '
                AND reputation = ' . $reputation_max['maxrep'];

        if ( !($result = $db->sql_query($sql)) )
        {
            message_die(GENERAL_ERROR, 'Couldn\'t retrieve the reputation stats', '', __LINE__, __FILE__, $sql);
        }

        $respect_set = $db->sql_fetchrowset($result);

        if ( count($respect_set) > 1 )
        {
            $l_respected_user_s = $lang['reputation_most_respected_users'];
        }
        else
        {
            $l_respected_user_s = $lang['reputation_most_respected_user'];
        }
        for ( $i = 0; $i < count($respect_set); $i++ )
        {
            $respected_user_link = '<b><a href="' . append_sid("profile.$phpEx?mode=viewprofile&amp;" . POST_USERS_URL . '=' . $respect_set[$i]['user_id']) . '"class="' . get_user_level_class($respect_set[$i]['user_level'], 'gen', $respect_set[$i]) . '">' . $respect_set[$i]['username'] . '</a></b>';
            $s_respected_user_s .= ( $s_respected_user_s != '' ) ? ', ' . $respected_user_link : $respected_user_link;
        }
        $s_respected_user_s .= '<br />';
    }
}
//
// Check for post reports
//
if ( $board_config['reputation_check_reports'] == 1 && ( $userdata['user_level'] == ADMIN || $userdata['user_level'] == MOD || $userdata['user_level'] == GLOBAL_MOD || $userdata['user_level'] == MAIN_MOD ) )
{
    switch ( $userdata['user_level'] )
    {
        case ADMIN:
            // Select all reports
            $from = POST_REPORTS_TABLE . ' r';
            $where = '1';
            break;
        case MOD:
            // Select reports from only those forums user can moderate
            $from = POST_REPORTS_TABLE . ' r, ' . USER_GROUP_TABLE . ' g, ' . AUTH_ACCESS_TABLE . ' a';
            $where = 'a.auth_mod = 1
                    AND a.forum_id = r.forum_id
                    AND a.group_id = g.group_id
                    AND g.user_id = ' . $userdata['user_id'];
            break;
    }

    //
    // Get reports count
    //
    $sql = 'SELECT COUNT(r.report_id) AS num_reports
        FROM ' . $from . '
        WHERE ' . $where;
    if ( !($result = $db->sql_query($sql)) )
    {
        message_die(GENERAL_ERROR, "Could not obtain limited reports count information", '', __LINE__, __FILE__, $sql);
    }
    $total_post_reports = ( $row = $db->sql_fetchrow($result) ) ? intval($row['num_reports']) : 0;
}
///////////////////////////////////////////////

#
#-----[ FIND ]------------------------------------------
#
    include($phpbb_root_path . 'includes/page_header.'.$phpEx);

#
#-----[ AFTER, ADD ]------------------------------------------
#
///////democracy///////
    //
    // Make a link to reported posts (for authorized ppl only)
    //
    if ( $board_config['reputation_enable_reports'] == 1 && ( $userdata['user_level'] == ADMIN || $userdata['user_level'] == MOD || $userdata['user_level'] == GLOBAL_MOD || $userdata['user_level'] == MAIN_MOD ) )
    {
        $link_color = '';
        if ( isset($total_post_reports) )
        {
            $l_reported_posts = $lang['reputation_reported_posts'] . ': ' . ( $total_post_reports == 0 ? '0' : "<b>$total_post_reports</b>" );
            if ( $board_config['reputation_reports_color'] != '' && $total_post_reports > 0 )
            {
                $link_color = ' style="color:#' . $board_config['reputation_reports_color'] . '"';
            }
        }
        else
        {
            $l_reported_posts = $lang['reputation_view_reported_posts'];
        }
        $u_reported_posts = '<a href="' . append_sid("post_report.$phpEx?mode=view") . '" class="gensmall"' . $link_color . '>' . $l_reported_posts . '</a><br />';
    }
//////////////


#
#-----[ FIND ]------------------------------------------
#
        'FORUM_LOCKED_IMG' => $images['forum_locked'],
        'L_FORUM' => $lang['Forum'],

#
#-----[ AFTER, ADD ]------------------------------------------
#
////////////////democracy//////////////////////
        'RESPECTED_USERS' => $l_respected_user_s . $s_respected_user_s,
        'U_VIEW_REPORTED' => $u_reported_posts,
///////////////////////////////////////////

#
#-----[ OPEN ]------------------------------------------
#
posting.php
#
#-----[ FIND ]------------------------------------------
#
        $sql = "SELECT f.*, t.topic_id, t.topic_status, t.topic_type, t.topic_first_post_id, t.topic_last_post_id, t.topic_vote, p.post_id, p.poster_id" . $select_sql . "

#
#-----[ IN-LINE FIND ]------------------------------------------
#
" . $select_sql . "


#
#-----[ IN-LINE BEFORE, ADD ]------------------------------------------
#
, p.post_locked

#
#-----[ FIND ]------------------------------------------
#
    message_die(GENERAL_MESSAGE, $lang['No_such_post']);
}

#
#-----[ AFTER, ADD ]------------------------------------------
#
////democracy/////
if ( $post_info['post_locked'] == 1 && !$is_auth['auth_mod'] )
{
    message_die(GENERAL_MESSAGE, $lang['Post_locked'] . '<br /><br />' . sprintf($lang['Click_return_topic'], '<a href="' . append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id") . '">', '</a>'));
}
/////////////


#
#-----[ FIND ]------------------------------------------
#
    switch ( $mode )
    {
        case 'editpost':

#
#-----[ AFTER, ADD ]------------------------------------------
#
////////////democracy/////
            if ( $post_data['poster_id'] != $userdata['user_id'] )
            {
                $post_data['post_locked'] = ( !empty($HTTP_POST_VARS['lock_post']) ? 1 : 0 );
            }
//////////////////////

#
#-----[ FIND ]------------------------------------------
#
//
// Delete selection
//

#
#-----[ BEFORE, ADD ]------------------------------------------
#
/////democracy///////
//
// Lock selection
//
if ( $mode == 'editpost' && $post_data['poster_id'] != $userdata['user_id'] && $is_auth['auth_mod'] )
{
    $template->assign_block_vars('switch_lock_checkbox', array());
}
/////////////


#
#-----[ FIND ]------------------------------------------
#
    'L_NOTIFY_ON_REPLY' => $lang['Notify'],
    'L_DELETE_POST' => $lang['Delete_post'],

#
#-----[ AFTER, ADD ]------------------------------------------
#
    'L_LOCK_POST' => $lang['reputation_lock_post'], /* /////democracy////////   */

#
#-----[ OPEN ]------------------------------------------
#
profile.php
#
#-----[ FIND ]------------------------------------------
#
if ($mode == 'privmsg_popup')
{
    include($phpbb_root_path . "profilcp/profilcp_privmsg_popup.$phpEx");
}

#
#-----[ AFTER, ADD ]------------------------------------------
#
//////////democracy/////////////////
if ( $mode == 'reputation' )
{
    include($phpbb_root_path . 'includes/usercp_reputation.'.$phpEx);
    exit;
}
/////////////////////////////////

#
#-----[ OPEN ]------------------------------------------
#
viewtopic.php
#
#-----[ FIND ]------------------------------------------
#
$sql = "SELECT u.*, p.*,  pt.post_text, pt.post_subject, pt.bbcode_uid

#
#-----[ IN-LINE FIND ]------------------------------------------
#
pt.bbcode_uid

#
#-----[ IN-LINE AFTER, ADD ]------------------------------------------
#
, u.reputation, u.warnings, u.user_level

#
#-----[ FIND ]------------------------------------------
#
    $mini_post_url = append_sid("viewtopic.$phpEx?" . POST_POST_URL . '=' . $postrow[$i]['post_id']) . '#' . $postrow[$i]['post_id'];

#
#-----[ BEFORE, ADD ]------------------------------------------
#
////////////////////////democracy//////
        if ( ( $board_config['warnings_enabled'] || $board_config['reputation_enabled'] ) && $postrow[$i]['post_reviews'] > 0 )
        {
            $temp_url = append_sid("profile.$phpEx?mode=reputation&amp;m=" . REPUTATION_VIEW . '&' . POST_POST_URL . '=' . $postrow[$i]['post_id']);
            $post_reviews = sprintf($lang['reputation_view_reviews'], $postrow[$i]['post_reviews']);
            $reviews_img = '<a href="' . $temp_url . '"><img src="' . $images['icon_reviews'] . '" alt="' . $post_reviews . '" title="' . $post_reviews . '" border="0" /></a>';
            $reviews = '<a href="' . $temp_url . '" title="' . $post_reviews . '">' . $lang['Reviews'] . '</a>';
        }
        else
        {
            $reviews_img = '';
            $reviews = '';
        }
////////////////////////////

#
#-----[ FIND ]------------------------------------------
#
            $delpost_img = '';
            $delpost = '';
        }

#
#-----[ AFTER, ADD ]------------------------------------------
#
/////////////democracy////////////////////
        if ( $board_config['reputation_enable_reports'] )
        {
            if( $userdata['user_id'] != ANONYMOUS )
            {
                $temp_url = "post_report.$phpEx?mode=report&amp;" . POST_POST_URL . "=" . $postrow[$i]['post_id'] . "&amp;sid=" . $userdata['session_id'];
                $reportpost_img = '<a href="' . $temp_url . '"><img src="' . $images['report_post'] . '" alt="' . $lang['reputation_report_post'] . '" title="' . $lang['reputation_report_post'] . '" border="0" /></a>';
                $reportpost = '<a href="' . $temp_url . '">' . $lang['reputation_report_post'] . '</a>';
            }
        }
///////////////////////////////////////////

#
#-----[ FIND ]------------------------------------------
#
        'SIGNATURE' => $user_sig,
        'EDITED_MESSAGE' => $l_edited_by,

#
#-----[ AFTER, ADD ]------------------------------------------
#
    //////democracy/////////
        'POSTER_REPUTATION' => $user_reputation,
        'POSTER_WARNINGS' => empty($user_warnings) ? '' : $user_warnings,

        'REPORTPOST' => $reportpost,
        'REPORTPOST_IMG' => $reportpost_img,
        'RED' => $ban,
        'RED_IMG' => $ban_img,
        'YELLOW' => $warn,
        'YELLOW_IMG' => $warn_img,
        'REVIEWS' => $reviews,
        'REVIEWS_IMG' => $reviews_img,
////////////////////////////

#
#-----[ OPEN ]------------------------------------------
#
admin/admin_db_utilities.php
#
#-----[ FIND ]------------------------------------------
#
$tables = array(
#
#-----[ IN-LINE FIND ]------------------------------------------
#
);
#
#-----[ IN-LINE BEFORE, ADD ]------------------------------------------
#
, 'reputation', 'reputation_text', 'post_reports'
#
#-----[ OPEN ]------------------------------------------
#
includes/constants.php
#
#-----[ FIND ]------------------------------------------
#
?>

#
#-----[ BEFORE, ADD ]------------------------------------------
#
///////////////democracy/////////////////////
define('REPUTATION_TABLE', $table_prefix.'reputation');
define('REPUTATION_TEXT_TABLE', $table_prefix.'reputation_text');
define('POST_REPORTS_TABLE', $table_prefix.'post_reports');

// reputation modes definition
define('REPUTATION_VIEW', 0);
define('REPUTATION_INC', 1);
define('REPUTATION_DEC', 2);
define('REPUTATION_WARNING', 3);
define('REPUTATION_BAN', 4);
define('REPUTATION_EDIT', 5);
define('REPUTATION_DELETE', 6);
define('REPUTATION_WARNING_EXPIRED', 7);
define('REPUTATION_BAN_EXPIRED', 8);

define('POST_REVIEWS_URL', 'r');

define('REPUTATION_MODE_FULL', 4);
define('REPUTATION_MODE_REPUTATION', 3);
define('REPUTATION_MODE_WARNINGS', 2);
define('REPUTATION_MODE_NONE', 1);
////////////////////////////////////////////


#
#-----[ OPEN ]------------------------------------------
#
includes/functions_post.php
#
#-----[ FIND ]------------------------------------------
#
        message_die(GENERAL_ERROR, 'Error in posting', '', __LINE__, __FILE__, $sql);
    }

#
#-----[ AFTER, ADD ]------------------------------------------
#
////democracy/////
    if ( $mode == 'editpost' && $post_data['poster_id'] != $userdata['user_id'] )
    {
        $sql = 'UPDATE ' . POSTS_TABLE . '
            SET post_locked = ' . $post_data['post_locked'] . '
            WHERE post_id = ' . $post_id;
        if (!$db->sql_query($sql))
        {
            message_die(GENERAL_ERROR, 'Error in posting', '', __LINE__, __FILE__, $sql);
        }
    }
/////////////

#
#-----[ FIND ]------------------------------------------
#
        $sql = "DELETE FROM " . POSTS_TEXT_TABLE . "
            WHERE post_id = $post_id";
        if (!$db->sql_query($sql))
        {
            message_die(GENERAL_ERROR, 'Error in deleting post', '', __LINE__, __FILE__, $sql);
        }

#
#-----[ AFTER, ADD ]------------------------------------------
#
/////////democracy///////////////
        $sql = "UPDATE " . REPUTATION_TABLE . "
            SET post_id = -1
            WHERE post_id = $post_id";
        if (!$db->sql_query($sql))
        {
            message_die(GENERAL_ERROR, 'Error in deleting post references', '', __LINE__, __FILE__, $sql);
        }
////////////////////////

#
#-----[ OPEN ]------------------------------------------
#
admin/admin_db_utilities.php
#
#-----[ FIND ]------------------------------------------
#
$tables = array(
#
#-----[ IN-LINE FIND ]------------------------------------------
#
);
#
#-----[ IN-LINE BEFORE, ADD ]------------------------------------------
#
, 'reputation', 'reputation_text', 'post_reports'
#
#-----[ OPEN ]------------------------------------------
#
includes/page_header.php
#
#-----[ FIND ]------------------------------------------
#
$template->set_filenames(array(
    'overall_header' => ( empty($gen_simple_header) ) ? 'overall_header.tpl' : 'simple_header.tpl')
);

#
#-----[ AFTER, ADD ]------------------------------------------
#
//////////////////democracy///////////////////////////////////
//
// Check for expired warnings and bans
//
$current_time = time();

if ( $board_config['reputation_last_check_time'] + $board_config['reputation_check_rate'] < $current_time )
{
   $sql = 'SELECT id, user_id, modification FROM ' . REPUTATION_TABLE . '
           WHERE (modification = ' . REPUTATION_WARNING . ' OR modification = ' . REPUTATION_BAN . ")
            AND expire < $current_time";
    if ( !($result = $db->sql_query($sql)) )
    {
        message_die(GENERAL_ERROR, 'Couldn\'t select from rep table', '', __LINE__, __FILE__, $sql);
    }
    while ($row = $db->sql_fetchrow($result))
    {
        if ( $board_config['reputation_delete_expired'] == 1 )
        {
            $sql = 'DELETE FROM ' . REPUTATION_TABLE . '
                    WHERE id = ' . $row['id'];
            if ( !$db->sql_query($sql) )
            {
                message_die(GENERAL_ERROR, 'Couldn\'t delete expired warnings', '', __LINE__, __FILE__, $sql);
            }
            $sql = 'DELETE FROM ' . REPUTATION_TEXT_TABLE . '
                    WHERE id = ' . $row['id'];
            if ( !$db->sql_query($sql) )
            {
                message_die(GENERAL_ERROR, 'Couldn\'t delete expired warnings', '', __LINE__, __FILE__, $sql);
            }
        }
        else
        {
            if ( $row['modification'] == REPUTATION_WARNING )
            {
                $set = REPUTATION_WARNING_EXPIRED;
            }
            else
            {
                $set = REPUTATION_BAN_EXPIRED;
            }
            $sql = 'UPDATE ' . REPUTATION_TABLE . '
                SET modification = ' . $set . '
                WHERE id = ' . $row['id'];
            if ( !$db->sql_query($sql) )
            {
                message_die(GENERAL_ERROR, 'Couldn\'t cancel expired warnings', '', __LINE__, __FILE__, $sql);
            }
        }
        if ( $row['modification'] == REPUTATION_BAN )
        {
            $sql = 'DELETE FROM ' . BANLIST_TABLE . "
                WHERE ban_userid = '" . $row['user_id'] . "'";
            if ( !$db->sql_query($sql) )
            {
                message_die(GENERAL_ERROR, "Couldn't obtain banlist information", "", __LINE__, __FILE__, $sql);
            }
        }
        $sql = 'UPDATE ' . USERS_TABLE . '
            SET warnings = warnings - 1
            WHERE user_id = ' . $row['user_id'];
        if ( !$db->sql_query($sql) )
        {
            message_die(CRITICAL_ERROR, "Could not update user rep.", '', __LINE__, __FILE__, $sql);
        }
    }
    //
    // Save last check time
    //
    $sql = "UPDATE " . CONFIG_TABLE . " SET
        config_value = $current_time
        WHERE config_name = 'reputation_last_check_time'";
    if( !$db->sql_query($sql) )
    {
        message_die(GENERAL_ERROR, "Failed to update board settings", "", __LINE__, __FILE__, $sql);
    }
}
/////////////////////////////////

#
#-----[ OPEN ]------------------------------------------
#
language/lang_english/lang_admin.php
#
#-----[ FIND ]------------------------------------------
#
$lang['Login_reset_time_explain'] =

#
#-----[ AFTER, ADD ]------------------------------------------
#
//
// Democracy MOD
//
$lang['reputation_board_mode'] = 'Board Mode';
$lang['reputation_board_mode_exp'] = 'From this page you can change your Board\'s rules mode and setup its behaviour.<br />Note: The default option value is shown as <u>underlined</u>.';
$lang['reputation_mode_1'] = 'Anarchy';        // 'none'
$lang['reputation_mode_2'] = 'Totality';    // 'warnings'
$lang['reputation_mode_3'] = 'Feudalism';    // 'reputation'
$lang['reputation_mode_4'] = 'Democracy';    // 'full'
$lang['reputation_select_mode'] = 'Select board regime';
$lang['reputation_mode_1_exp'] = 'None of Democracy MOD\'s features are enabled.';
$lang['reputation_mode_2_exp'] = 'Only Warnings system is enabled.';
$lang['reputation_mode_3_exp'] = 'Only Reputation system is enabled.';
$lang['reputation_mode_4_exp'] = 'All features of Democracy MOD are enabled.';
$lang['reputation_gen_options'] = 'General options (related to both Reputation and Warnings)';
$lang['reputation_reputation_options'] = 'Reputation options';
$lang['reputation_warnings_options'] = 'Warnings options';
$lang['reputation_app_to'] = 'Appliable to';
$lang['reputation_anonymous_view'] = 'Allow anonymous access';
$lang['reputation_anonymous_view_exp'] = 'Anonymous users can read reviews and warnings pages';
$lang['reputation_enable_reports'] = 'Enable Report Post button';
$lang['reputation_enable_reports_exp'] = 'Enable users to report posts to moderator(s)';
$lang['reputation_check_reports'] = 'Display number of reported posts to moderators';
$lang['reputation_check_reports_exp'] = 'Use this to notify moderators about post reports';
$lang['reputation_reports_color'] = 'Color used to distinguish the link to reports page';
$lang['reputation_reports_color_exp'] = 'If there are any reports. Leave blank if you don\'t want the link to have different color';
$lang['reputation_reports_per_page'] = 'Reports per page';
$lang['reputation_reviews_per_page'] = 'Reputation reviews per page';
$lang['reputation_reviews_per_page_exp'] = 'All warnings are displayed on top of each page regardless of this number';
$lang['reputation_users_can_edit'] = 'Users can edit their own reviews';
$lang['reputation_users_can_delete'] = 'Users can delete their own reviews';
$lang['reputation_moders_can_ban'] = 'Moderators can ban users';
$lang['reputation_moders_can_ban_exp'] = 'Bans work the same way as warnings except the user becomes banned';
$lang['reputation_expire_enabled'] = 'Warnings can expire over time';
$lang['reputation_expire_default'] = 'Default expire time for warnings';
$lang['reputation_expire_min'] = 'Minimal expire time for warnings';
$lang['reputation_expire_max'] = 'Maximal expire time for warnings';
$lang['reputation_ban_expire_enabled'] = 'Bans can expire over time';
$lang['reputation_ban_expire_default'] = 'Default expire time for bans';
$lang['reputation_ban_expire_min'] = 'Minimal expire time for bans';
$lang['reputation_ban_expire_max'] = 'Maximal expire time for bans';
$lang['reputation_check_rate'] = 'Expired warnings and bans check rate';
$lang['reputation_check_rate_exp'] = 'Manipulate delay between checkups to reduce the workload';
$lang['reputation_check_rate_hint'] = '3600 = 1 hour, 86400 = 1 day';
$lang['reputation_expired_warnings'] = 'Expired warnings and bans';
$lang['reputation_delete'] = 'Delete';
$lang['reputation_mark_expired'] = 'Mark as expired';
$lang['reputation_auto_ban'] = 'Enable auto-ban';
$lang['reputation_auto_ban_exp'] = 'Users will get banned after recieving a certain amount of active warnings';
$lang['reputation_num_warnings'] = 'Amount of warnings needed to auto-ban user';
$lang['reputation_check_confirm'] = 'Please confirm your intention to change settings by checking the appropriate checkbox!';
$lang['Click_return_reputation_index'] = 'Click %sHere%s to return to Board Regime administraton';

#
#-----[ OPEN ]------------------------------------------
#
language/lang_english/lang_main.php
#
#-----[ FIND ]------------------------------------------
#
$lang['Please_remove_install_contrib'] =

#
#-----[ AFTER, ADD ]------------------------------------------
#
//
// Democracy MOD
//
$lang['Reputation'] = 'Reputation';
$lang['Warnings'] = 'Warnings';
$lang['Reason'] = 'Reason';
$lang['Warning'] = 'Warning';
$lang['New_warning'] = 'New warning';
$lang['Post_Reports'] = 'Post Reports';
$lang['Review'] = 'Review';
$lang['Reviews'] = 'Reviews';
$lang['New_review'] = 'New review';
$lang['Official'] = 'Official'; // i.e. Moderator
$lang['Display'] = 'Display';
$lang['User'] = 'User';
$lang['Edit'] = 'Edit';
$lang['Post_locked'] = 'Sorry, you are not allowed edit or delete this post any more.';
$lang['reputation_days'] = 'days';
$lang['reputation_seconds'] = 'seconds';
$lang['reputation_and'] = 'and';
$lang['reputation_expire_hint_inf'] = 'Enter -1 for infinity';
$lang['reputation_lock_post'] = 'Lock this post';
$lang['reputation_for'] = 'for';
$lang['reputation_from'] = 'from';
$lang['reputation_to'] = 'to';
$lang['reputation_approve'] = 'Approve';
$lang['reputation_approved'] = 'Approved';
$lang['reputation_disapprove'] = 'Disapprove';
$lang['reputation_disapproved'] = 'Disapproved';
$lang['reputation_post_ref'] = 'Post reference';
$lang['reputation_post_reviews'] = 'Post reviews';
$lang['reputation_post_was_deleted'] = 'Post was deleted';
$lang['reputation_warning_issued'] = 'Warning issued';
$lang['reputation_total'] = 'Total';
$lang['reputation_issued'] = 'Issued';
$lang['reputation_expire'] = 'Expire';
$lang['reputation_expired'] = 'Expired';
$lang['reputation_never'] = 'Never';
$lang['reputation_warning'] = 'Warning';
$lang['reputation_ban'] = 'Ban';
$lang['reputation_description'] = 'Review';
$lang['reputation_edit_review'] = 'Edit review';
$lang['reputation_delete_review'] = 'Delete review';
$lang['reputation_warnings_to'] = 'Warnings given to %s';
$lang['reputation_reviewed'] = 'Reviewed';
$lang['reputation_actions'] = 'Actions';
$lang['reputation_order_by'] = 'Order by';
$lang['reputation_post_peports_exp'] = 'Using the form below you can check out posts and reviews reported by users and perform actions on them.<br />Hint: After you resolve the report delete it to prevent other moderators from taking same actions as you did once more :)';
$lang['reputation_report_date'] = 'Report date';
$lang['reputation_reports_number'] = 'Reports number';
$lang['reputation_first_reported'] = 'First reported by';
$lang['reputation_of'] = 'Reputation of %s';
$lang['reputation_view_details'] = 'View details';
$lang['reputation_warn_user'] = 'Give this user a warning';
$lang['reputation_ban_user'] = 'Ban this user';
$lang['reputation_view_reviews'] = 'This post has %s review(s)';
$lang['reputation_report_post'] = 'Report this post to moderator(s)';
$lang['reputation_report'] = 'Report';
$lang['reputation_report_success'] = 'The officials have been informed';
$lang['reputation_view_reported_posts'] = 'View posts reported by users';
$lang['reputation_reported_posts'] = 'Posts reported by users';
$lang['reputation_modify'] = 'Modify user\'s reputation';
$lang['reputation_give_warning'] = 'Give user a warning';
$lang['reputation_user'] = 'To user';
$lang['reputation_display_expired'] = 'Show expired warnings';
$lang['reputation_expire_never'] = 'Never expire';
$lang['reputation_expire_after'] = 'Expired after';
$lang['reputation_expire_hint'] = 'Enter a value';
$lang['reputation_warning_expired'] =  'Expired warning';
$lang['reputation_warnings_expired'] =  'Expired warnings given to';
$lang['reputation_most_respected_user'] = 'Our most respected user is ';
$lang['reputation_most_respected_users'] = 'Our most respected users are ';
$lang['reputation_note_cant_edit'] = 'Please note that you won\'t be able to edit your review later';
$lang['reputation_note_can_edit'] = 'Please note that you\'ll be able to edit only your review text';
$lang['reputation_self_no_modify'] = 'You can\'t modify your reputation!';
$lang['reputation_anonymous_no_reputation'] = 'Anonymous users don\'t have reputation!';
$lang['reputation_anonymous_no_reviews'] = 'Anonymous posts don\'t have reviews!';
$lang['reputation_already_voted'] = 'You have already referred to this post!';
$lang['reputation_cant_warn_mods'] = 'Moderators and administrators cannot be given warnings';
$lang['reputation_no_comments_entered'] = 'You didn\'t enter any comment!';
$lang['reputation_no_post_spec'] = 'No post specified!';
$lang['reputation_no_user_spec'] = 'No user specified!';
$lang['reputation_no_review_spec'] = 'No review specified!';
$lang['reputation_update_successfull'] = 'You have successfully voted for this user\'s reputation';
$lang['reputation_sorry_auth_view'] = 'Sorry, you cannot view reputation details';
$lang['reputation_warning_successfull'] = 'The user has been warned successfully';
$lang['reputation_this_post_reviews'] = 'This post reviews';
$lang['reputation_deleted_no_edit'] = 'The review you try to edit referres to deleted post';
$lang['reputation_no_reviews'] = 'This post hasn\'t got any reviews';
$lang['reputation_no_details'] = 'This user hasn\'t got any reputation details';
$lang['reputation_last_warning_issued'] = 'The user has already got last warning';
$lang['reputation_already_warned'] = 'This user has been already warned for this post';
$lang['reputation_already_banned'] = 'This user is already banned';
$lang['reputation_msg_view_warning'] = '%sView this warning%s';
$lang['reputation_msg_delete_report'] = '%sDelete report%s';
$lang['reputation_msg_view_profile'] = '%sView this user\'s profile%s';
$lang['reputation_msg_back_to_topic'] = '%sGo back to topic%s';
$lang['reputation_msg_back_to_reviews'] = '%sGo back to reviews%s';
$lang['reputation_msg_view_your_review'] = '%sView your review of this post%s';
$lang['reputation_confirm_delete'] = 'Are you sure you want to delete this review?';
$lang['reputation_delete_success'] = 'Review was deleted successfully. User\'s reputation has been updated.';
$lang['reputation_no_expire_entered'] = 'You didn\'t enter an expire date for this warning';
$lang['reputation_confirm_report'] = 'Are you sure you want to report this post to moderator(s)?';
$lang['reputation_confirm_report2'] = 'Are you sure you want to report this review to moderator(s)?';
$lang['reputation_mail_warning'] = 'You have recieved a warning';
$lang['reputation_mail_ban'] = 'You have been banned';
$lang['reputation_report_deleted'] = 'The report has been deleted.';
$lang['reputation_msg_back_to_reports'] = '%sBack to the Reports page%s';

#
#-----[ OPEN ]------------------------------------------
#
templates/subSilver/index_body.tpl
#
#-----[ FIND ]------------------------------------------
#
        <a href="{U_SEARCH_NEW}" class="gensmall">{L_SEARCH_NEW}</a><br /><a href="{U_SEARCH_SELF}" class="gensmall">{L_SEARCH_SELF}</a><br />

#
#-----[ IN-LINE FIND ]------------------------------------------
#
        <a href="{U_SEARCH_NEW}"

#
#-----[ IN-LINE BEFORE, ADD ]------------------------------------------
#
        {U_VIEW_REPORTED}

#
#-----[ FIND ]------------------------------------------
#
    <td class="row1" align="left" width="100%"><span class="gensmall">{TOTAL_POSTS}<br />{TOTAL_USERS}<br />{NEWEST_USER}</span>

#
#-----[ IN-LINE FIND ]------------------------------------------
#
    {NEWEST_USER}

#
#-----[ IN-LINE BEFORE, ADD ]------------------------------------------
#
{RESPECTED_USERS}

#
#-----[ OPEN ]------------------------------------------
#
templates/subSilver/subSilver.cfg
#
#-----[ FIND ]------------------------------------------
#
//
$board_config['vote_graphic_length'] = 205;
$board_config['privmsg_graphic_length'] = 175;

#
#-----[ AFTER, ADD ]------------------------------------------
#

////////////////democracy//////////////////////////
$images['user_warning'] = "$current_template_images/icon_warning.gif";
$images['user_ban'] = "$current_template_images/icon_ban.gif";
$images['report_post'] = "$current_template_images/icon_report.gif";
$images['ban_user'] = "$current_template_images/icon_red.gif";
$images['warn_user'] = "$current_template_images/icon_yellow.gif";
$images['thumb_up'] = "$current_template_images/thumb_up.gif";
$images['thumb_dn'] = "$current_template_images/thumb_dn.gif";
$images['icon_reviews'] = "$current_template_images/{LANG}/icon_reviews.gif";
$images['icon_edit_small'] = "$current_template_images/icon_edit_small.gif";
$images['icon_lock_small'] = "$current_template_images/icon_lock_small.gif";
///////////////////////////////////////////

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

#
#-----[ FIND ]------------------------------------------
#
                <td valign="top" nowrap="nowrap">{postrow.QUOTE_IMG} {postrow.EDIT_IMG} {postrow.DELETE_IMG} {postrow.IP_IMG}</td>

#
#-----[ REPLACE WITH ]------------------------------------------
#
                <td valign="top" nowrap="nowrap">{postrow.REVIEWS_IMG} {postrow.QUOTE_IMG} {postrow.EDIT_IMG} {postrow.DELETE_IMG} {postrow.REPORTPOST_IMG} {postrow.IP_IMG}</td>

#
#-----[ OPEN ]------------------------------------------
#
includes/usercp_reputation.php

#
#-----[ FIND AND DELETE ]------------------------------------------
#
include($phpbb_root_path . 'includes/functions_post.'.$phpEx);
include($phpbb_root_path . 'includes/bbcode.'.$phpEx);

#
#-----[ FIND AND DELETE ]------------------------------------------
#
        include($phpbb_root_path . 'includes/emailer.'.$phpEx);

#
#-----[ OPEN ]------------------------------------------
#
profilcp/def/def_userfields.php

#
#-----[ FIND ]------------------------------------------
#
    // generic informations

#
#-----[ AFTER, ADD ]------------------------------------------
#
            'user_reputation' => array(
                'lang_key'     => 'Reputation',
                'class'        => 'generic',
                'type'         => 'VARCHAR',
                'dsp_func'     => 'pcp_output_reputation',
            ),
            'user_warnings' => array(
                'lang_key'     => 'Warnings',
                'class'        => 'generic',
                'type'         => 'VARCHAR',
                'dsp_func'     => 'pcp_output_warnings',
            ),

#
#-----[ OPEN ]------------------------------------------
#
profilcp/def/def_usermaps.php

#
#-----[ FIND ]------------------------------------------
#
        ),
    ),

    'PCP.viewprofile.base.real' => array(

#
#-----[ BEFORE, ADD ]------------------------------------------
#
            'user_warnings' => array(
                'leg'          => true,
                'txt'          => true,
                'style'        => '<span class="gensmall">%s</span>',
            ),
            'user_reputation' => array(
                'leg'          => true,
                'img'          => true,
                'style'        => '<span class="gensmall">%s</span>',
            ),

#
#-----[ FIND ]------------------------------------------
#
        ),
    ),

    'PHPBB.viewtopic.buttons.ignore' => array(

#
#-----[ BEFORE, ADD ]------------------------------------------
#
            'user_warnings' => array(
                'img'          => true,
                'style'        => '<td valign="absbottom" nowrap="nowrap"><span class="gensmall">%s</span></td>',
            ),

#
#-----[ FIND ]------------------------------------------
#
        ),
    ),

    'PHPBB.viewtopic.left.ignore' => array(

#
#-----[ BEFORE, ADD ]------------------------------------------
#
            'user_reputation' => array(
                'txt'          => true,
                'style'        => '<br /><div align="left" class="gensmall">%s</div>',
            ),
#
#-----[ OPEN ]------------------------------------------
#
profilcp/def/def_userfuncs_custom.php

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

#
#-----[ BEFORE, ADD ]------------------------------------------
#
//-----------------------------------
//
//
//
// democracy output
//
//-----------------------------------
function pcp_output_reputation($field_name, $view_userdata, $map_name='')
{
   global $board_config, $phpbb_root_path, $phpEx, $lang, $images, $userdata, $db;
   global $values_list, $tables_linked, $classes_fields, $user_maps, $user_fields;

    $user_warnings = '';
    $user_reputation = '';
    $txt = '';
    $img = '';
    $res = '';

    if ( ($view_userdata['user_id'] != ANONYMOUS) )
    {
        $sql = 'SELECT ban_userid
            FROM ' . BANLIST_TABLE;
        if ( !($result = $db->sql_query($sql)) )
        {
            message_die(GENERAL_ERROR, "Couldn't obtain banlist information", "", __LINE__, __FILE__, $sql);
        }
        while ( $row = $db->sql_fetchrow($result) )
        {
            $banned[$row['ban_userid']] = true;
        }
    
        if ( $board_config['reputation_enabled'] )
        {
            $thumb_up_img = '<img src="' . $images['thumb_up'] . '" alt="' . $lang['reputation_approve'] . '" title="' . $lang['reputation_approve'] . '" border="0" />';
            $thumb_dn_img = '<img src="' . $images['thumb_dn'] . '" alt="' . $lang['reputation_disapprove'] . '" title="' . $lang['reputation_disapprove'] . '" border="0" />';

            $user_reputation = '<a href="' . append_sid("profile.$phpEx?mode=reputation&amp;m=" . REPUTATION_VIEW . '&amp;' . POST_USERS_URL . '=' . $view_userdata['user_id'] . '&amp;view=rep') . '" title="' . $lang['reputation_view_details'] . '">' . $lang['Reputation'] . '</a>' . ': ' . $view_userdata['reputation'];
            if ( $view_userdata['user_id'] != $userdata['user_id'] && $userdata['user_id'] != ANONYMOUS )
            {
                $user_reputation .= '&nbsp;&nbsp;<a href="' . append_sid("profile.$phpEx?mode=reputation&amp;m=" . REPUTATION_INC . '&amp;' . POST_POST_URL . '=' . $view_userdata['post_id']) . '">' . $thumb_up_img . '</a>&nbsp;&nbsp;<a href="' . append_sid("profile.$phpEx?mode=reputation&amp;m=" . REPUTATION_DEC . '&amp;' . POST_POST_URL . '=' . $view_userdata['post_id']) . '">' . $thumb_dn_img . '</a><br />';
            }
                $u_view_reputation = append_sid("profile.$phpEx?mode=reputation&amp;m=" . REPUTATION_VIEW . '&amp;' . POST_USERS_URL . '=' . $view_userdata['user_id'] . '&amp;view=rep');
                $img = $view_userdata['reputation'] . '<br />' . '<a href="' . $u_view_reputation . '">' . $lang['reputation_view_details'] . '</a>';
        }
        if ( $board_config['warnings_enabled'] )
        {
            $warnings = $view_userdata['warnings'];
            if ( $banned[$view_userdata['user_id']] )
            {
                $user_ban = true;
                $warnings = $warnings - 1;
            }
            else
            {
                $user_ban = false;
            }

            if ( $view_userdata['warnings'] > 0 )
            {
                $temp_url = append_sid("profile.$phpEx?mode=reputation&amp;" . POST_USERS_URL . '=' . $view_userdata['user_id'] . '&amp;m=' . REPUTATION_VIEW . '&amp;view=warn');
                $user_warnings = '<a href="' . $temp_url . '" title="' . sprintf($lang['reputation_warnings_to'], $poster) . '">';

                for ($k = 0; $k < $warnings; $k++ )
                {
                    $user_warnings .= '<img src="' . $images['user_warning'] . '" alt="' . $lang['reputation_warning'] . '" border="0" />';
                }
                if ( $user_ban )
                {
                    $user_warnings .= '<img src="' . $images['user_ban'] . '" alt="' . $lang['reputation_ban'] . '" border="0" />';
                }
                $user_warnings .= '</a>';
            }
        }

        $reputation = $user_reputation;
        $warnings = empty($user_warnings) ? '' : $user_warnings;
        $txt = $reputation . '<br />' . $warnings;
        
      // result
      $res = pcp_output_format($field_name, $txt, $img, $map_name);
    }
   return $res;
}
//-----------------------------------
//
//
//
// democracy output
//
//-----------------------------------
function pcp_output_warnings($field_name, $view_userdata, $map_name='')
{
   global $board_config, $phpbb_root_path, $phpEx, $lang, $images, $userdata, $is_auth;
   global $values_list, $tables_linked, $classes_fields, $user_maps, $user_fields;


    $txt = '';
    $img = '';
    $res = '';

        if ( $board_config['warnings_enabled'] )
        {
            if ( $userdata['user_id'] != $postrow[$i]['user_id'] && $postrow[$i]['user_level'] != ADMIN && $postrow[$i]['user_level'] != MOD && $postrow[$i]['user_level'] != GLOBAL_MOD && $postrow[$i]['user_level'] != MAIN_MOD && $is_auth['auth_mod'] )
            {
                $temp_url = "profile.$phpEx?mode=reputation&amp;m=" . REPUTATION_WARNING . "&amp;" . POST_POST_URL . "=" . $postrow[$i]['post_id'] . "&amp;sid=" . $userdata['session_id'];
                $warn_img = '<a href="' . $temp_url . '"><img src="' . $images['warn_user'] . '" alt="' . $lang['reputation_warn_user'] . '" title="' . $lang['reputation_warn_user'] . '" border="0" /></a>';
                $warn = '<a href="' . $temp_url . '">' . $lang['reputation_warn_user'] . '</a>';

                if ( $board_config['reputation_moderators_can_ban'] == 1 )
                {
                    $temp_url = "profile.$phpEx?mode=reputation&amp;m=" . REPUTATION_BAN . "&amp;" . POST_POST_URL . "=" . $postrow[$i]['post_id'] . "&amp;sid=" . $userdata['session_id'];
                    $ban_img = '<a href="' . $temp_url . '"><img src="' . $images['ban_user'] . '" alt="' . $lang['reputation_ban_user'] . '" title="' . $lang['reputation_ban_user'] . '" border="0" /></a>';
                    $ban = '<a href="' . $temp_url . '">' . $lang['reputation_ban_user'] . '</a>';
                }
                else
                {
                    $ban_img = '';
                    $ban = '';
                }
            }
            else
            {
                $warn_img = '';
                $warn = '';
                $ban_img = '';
                $ban = '';
            }
                $u_view_warnings = append_sid("profile.$phpEx?mode=reputation&amp;m=" . REPUTATION_VIEW . '&amp;' . POST_USERS_URL . '=' . $view_userdata['user_id'] . '&amp;view=warn');
                $txt = $view_userdata['warnings'] . '<br />' . '<a href="' . $u_view_warnings . '">' . $lang['reputation_view_details'] . '</a>';
        }

        $img = $warn_img . '&nbsp;' . $ban_img;

      // result
      $res = pcp_output_format($field_name, $txt, $img, $map_name);
    
   return $res;
}
#
#-----[ SAVE/CLOSE ALL FILES ]------------------------------------------
#
# EoM 