Location: PHPKode > projects > Gnew > Gnew-2013.1/users/info.php
<?php
// -----------------------------------------------------------------------------
// $Id: info.php 682 2013-03-28 14:17:41Z raoul $
//
// Copyright (C) 2013 Raoul Proença
// License: GNU GPL version 3 (see copying.txt file)
// Website: http://www.gnew.fr/
// -----------------------------------------------------------------------------
// This program is free software: you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free Software
// Foundation, either version 3 of the License, or (at your option) any later
// version.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
// details.
//
// You should have received a copy of the GNU General Public License along with
// this program. If not, see <http://www.gnu.org/licenses/>.
// -----------------------------------------------------------------------------

include('./../includes/common.php');

page_header($lang['USERS_INFO']);

// Check query
if (!empty($_GET['user_id']) && string_is_int($_GET['user_id']))
{
    $sql->query('SELECT user_articles, user_comments, user_creation, user_day, user_email, user_language, user_last_visit, user_level, user_location, user_month, user_name, user_news, user_occupation, user_polls, user_posts, user_show_email, user_signature, user_template, user_votes, user_website, user_year
                 FROM ' . TABLE_USERS . '
                 WHERE user_id = \'' . $_GET['user_id'] . '\'');
    $table_users = $sql->fetch();
    // Check user
    if (!$table_users['user_name'])
    {
        error_template($lang['ERROR_NO_DATA']);
    }
    else
    {
        if ($table_users['user_show_email'])
        {
            $user_email = make_clickable($table_users['user_email']);
        }
        else
        {
            $user_email = '';
        }
        $level_list = array('0' => $lang['BANNED'],
                            '1' => $lang['PUBLIC'],
                            '2' => $lang['MODERATOR'],
                            '3' => $lang['ADVANCED_MODERATOR'],
                            '4' => $lang['ADMINISTRATOR']);
        $user_level = $level_list[$table_users['user_level']];

        if ($table_users['user_day'] && $table_users['user_month'] && $table_users['user_year'])
        {
            $month_days = array(1 => 31, 3 => 31, 4 => 30, 5 => 31, 6 => 30, 7 => 31, 8 => 31, 9 => 30, 10 => 31, 11 => 30, 12 => 31);
            $num_days = $offset = 0;
            $today_day = date('j', time());
            $today_month = date('n', time());
            $today_year = date('Y', time());

            for ($i = $table_users['user_year']; $i <= $today_year; $i++)
            {
                if ((($i % 4 == 0) && ($i % 100 != 0)) || ($i % 400 == 0))
                {
                    $month_days[2][$i] = 29;
                }
                else
                {
                    $month_days[2][$i] = 28;
                }
            }
            // days between 'user_day' and end of 'user_year'?
            for ($i = $table_users['user_month']; $i <= 12; $i++)
            {
                if (!isset($first_month))
                {
                    if ($i == 2)
                    {
                        $num_days += $month_days[2][$table_users['user_year']] - $table_users['user_day'];
                    }
                    else
                    {
                        $num_days += $month_days[$i] - $table_users['user_day'];
                    }
                    $first_month = true;
                }
                else
                {
                    if ($i == 2)
                    {
                        $num_days += $month_days[2][$table_users['user_year']];
                    }
                    else
                    {
                        $num_days += $month_days[$i];
                    }
                }
            }
            // days between beginning of 'today_year' and 'today_day'?
            $j = 1;
            while ($j < $today_month)
            {
                if ($j == 2)
                {
                    $num_days += $month_days[2][$today_year];
                }
                else
                {
                    $num_days += $month_days[$j];
                }
                $j++;
            }
            $num_days += $today_day;
            // bissextile 'user_year'?
            if ($month_days[2][$table_users['user_year']] == 29)
            {
                if ($table_users['user_month'] <= 2)
                {
                    $offset += 1;
                }
            }
            // bissextile 'today_year'?
            if ($month_days[2][$today_year] == 29)
            {
                if ($table_users['user_month'] > 2)
                {
                    $offset += 1;
                }
            }
            $user_age = ($num_days / (365 + $offset)) + ($today_year - $table_users['user_year'] - 1);
            $user_age = floor($user_age);
        }
        else
        {
            $user_age = $lang['NOT_SPECIFIED'];
        }

        // Administrator?
        if ($users['user_level'] == 4)
        {
            $edit_link = ' [ <a href="./../admin/users.php?action=edit_user&amp;user_id=' . $_GET['user_id'] . '">' . $lang['EDIT'] . '</a> ]';
        }
        else
        {
            $edit_link = '';
        }
        $template->set_file('info', 'users/info.htpl');
        $template->set_var(array('EDIT_LINK' => $edit_link,
                                 'HEADER_USERS_INFO' => sprintf($lang['HEADER_USERS_INFO'], $table_users['user_name']),
                                 'USER_AGE' => $user_age,
                                 'USER_ARTICLES' => $table_users['user_articles'],
                                 'USER_COMMENTS' => $table_users['user_comments'],
                                 'USER_CREATION' => format_date($table_users['user_creation']),
                                 'USER_EMAIL' => $user_email,
                                 'USER_LANGUAGE' => $table_users['user_language'],
                                 'USER_LAST_VISIT' => format_date($table_users['user_last_visit']),
                                 'USER_LEVEL' => $user_level,
                                 'USER_LOCATION' => $table_users['user_location'],
                                 'USER_NEWS' => $table_users['user_news'],
                                 'USER_OCCUPATION' => $table_users['user_occupation'],
                                 'USER_POLLS' => $table_users['user_polls'],
                                 'USER_POSTS' => $table_users['user_posts'],
                                 'USER_SIGNATURE' => $table_users['user_signature'],
                                 'USER_TEMPLATE' => $table_users['user_template'],
                                 'USER_VOTES' => $table_users['user_votes'],
                                 'USER_WEBSITE' => make_clickable($table_users['user_website'])));
        $template->parse('info', null, false, TABLE_USERS);
    }
}
else
{
    error_template($lang['ERROR_NO_DATA']);
}

page_footer();

?>
Return current item: Gnew