Skip to content

Commit

Permalink
feature 564: logs in the history table each user login
Browse files Browse the repository at this point in the history
feature 562: possibility to log page visits for any combination of 
administrators/users/guests

git-svn-id: http://piwigo.org/svn/trunk@1565 68402e56-0260-453c-a942-63ccdbb3a9ee
  • Loading branch information
rvelices committed Oct 19, 2006
1 parent 939cfe5 commit af621d4
Show file tree
Hide file tree
Showing 12 changed files with 168 additions and 59 deletions.
41 changes: 20 additions & 21 deletions admin/configuration.php
Expand Up @@ -46,22 +46,6 @@
{
$page['section'] = $_GET['section'];
}
//------------------------------------------------------ $conf reinitialization
$result = pwg_query('SELECT param,value FROM '.CONFIG_TABLE);
while ($row = mysql_fetch_array($result))
{
$conf[$row['param']] = $row['value'];
// if the parameter is present in $_POST array (if a form is submited), we
// override it with the submited value
if (isset($_POST[$row['param']]))
{
$conf[$row['param']] = $_POST[$row['param']];
if ( 'page_banner'==$row['param'] )
{ // should we do it for all ?
$conf[$row['param']] = stripslashes( $conf[$row['param']] );
}
}
}
//------------------------------ verification and registration of modifications
if (isset($_POST['submit']))
{
Expand All @@ -74,6 +58,10 @@
{
array_push($page['errors'], $lang['conf_gallery_url_error']);
}
$_POST['log'] = empty($_POST['log'])?'false':'true';
$_POST['history_admin'] = empty($_POST['history_admin'])?'false':'true';
$_POST['history_guest'] = empty($_POST['history_guest'])?'false':'true';
$_POST['login_history'] = empty($_POST['login_history'])?'false':'true';
break;
}
case 'comments' :
Expand Down Expand Up @@ -119,7 +107,7 @@
// updating configuration if no error found
if (count($page['errors']) == 0)
{
// echo '<pre>'; print_r($_POST); echo '</pre>';
//echo '<pre>'; print_r($_POST); echo '</pre>';
$result = pwg_query('SELECT * FROM '.CONFIG_TABLE);
while ($row = mysql_fetch_array($result))
{
Expand Down Expand Up @@ -147,6 +135,13 @@
}
}

//------------------------------------------------------ $conf reinitialization
$result = pwg_query('SELECT param,value FROM '.CONFIG_TABLE);
while ($row = mysql_fetch_array($result))
{
$conf[$row['param']] = $row['value'];
}

//----------------------------------------------------- template initialization
$template->set_filenames( array('config'=>'admin/configuration.tpl') );

Expand All @@ -171,16 +166,20 @@
{
$html_check='checked="checked"';

$history_yes = ($conf['log']=='true')?'checked="checked"':'';
$history_no = ($conf['log']=='false')?'checked="checked"':'';
$lock_yes = ($conf['gallery_locked']=='true')?'checked="checked"':'';
$lock_no = ($conf['gallery_locked']=='false')?'checked="checked"':'';
$history_users = ($conf['log']=='true')?$html_check:'';
$history_admin = ($conf['history_admin']=='true')?$html_check:'';
$history_guest = ($conf['history_guest']=='true')?$html_check:'';
$login_history = ($conf['login_history']=='true')?$html_check:'';

$template->assign_block_vars(
'general',
array(
'HISTORY_YES'=>$history_yes,
'HISTORY_NO'=>$history_no,
'HISTORY_USERS'=>$history_users,
'HISTORY_ADMIN'=>$history_admin,
'HISTORY_GUEST'=>$history_guest,
'LOGIN_HISTORY'=>$login_history,
'GALLERY_LOCKED_YES'=>$lock_yes,
'GALLERY_LOCKED_NO'=>$lock_no,
($conf['rate']=='true'?'RATE_YES':'RATE_NO')=>$html_check,
Expand Down
1 change: 1 addition & 0 deletions identification.php
Expand Up @@ -64,6 +64,7 @@
$remember_me = true;
}
log_user($row['id'], $remember_me);
pwg_log_login( $username );
redirect(empty($redirect_to) ? make_index_url() : $redirect_to);
}
else
Expand Down
3 changes: 0 additions & 3 deletions include/config_default.inc.php
Expand Up @@ -430,9 +430,6 @@
// nb_logs_page : how many logs to display on a page
$conf['nb_logs_page'] = 300;

// history_admin : history admin visits ?
$conf['history_admin'] = false;

// +-----------------------------------------------------------------------+
// | urls |
// +-----------------------------------------------------------------------+
Expand Down
51 changes: 37 additions & 14 deletions include/functions.inc.php
Expand Up @@ -384,15 +384,40 @@ function pwg_log( $file, $category, $picture = '' )
{
global $conf, $user;

if ($conf['log'])
if ( is_admin() )
{
$doit=$conf['history_admin'];
}
elseif ( $user['is_the_guest'] )
{
$doit=$conf['history_guest'];
}
else
{
$doit = $conf['log'];
}

if ($doit)
{
if (($conf['history_admin']) or ((! $conf['history_admin'])
and (!is_admin())))
{
$login = ($user['id'] == $conf['guest_id'])
? 'guest' : addslashes($user['username']);
insert_into_history($login, $file, $category, $picture);
}
}

function pwg_log_login( $username )
{
global $conf;
if ( $conf['login_history'] )
{
insert_into_history($username, 'login', '', '');
}
}

$query = '
// inserts a row in the history table
function insert_into_history( $login, $file, $category, $picture)
{
$query = '
INSERT INTO '.HISTORY_TABLE.'
(date,login,IP,file,category,picture)
VALUES
Expand All @@ -403,9 +428,7 @@ function pwg_log( $file, $category, $picture = '' )
\''.addslashes(strip_tags($category)).'\',
\''.addslashes($picture).'\')
;';
pwg_query($query);
}
}
pwg_query($query);
}

// format_date returns a formatted date for display. The date given in
Expand Down Expand Up @@ -461,7 +484,7 @@ function format_date($date, $type = 'us', $show_time = false)
return $formated_date;
}

function pwg_stripslashes($value)
function pwg_stripslashes($value)
{
if (get_magic_quotes_gpc())
{
Expand All @@ -470,7 +493,7 @@ function pwg_stripslashes($value)
return $value;
}

function pwg_addslashes($value)
function pwg_addslashes($value)
{
if (!get_magic_quotes_gpc())
{
Expand All @@ -479,7 +502,7 @@ function pwg_addslashes($value)
return $value;
}

function pwg_quotemeta($value)
function pwg_quotemeta($value)
{
if (get_magic_quotes_gpc()) {
$value = stripslashes($value);
Expand Down Expand Up @@ -699,7 +722,7 @@ function get_thumbnail_src($path, $tn_ext = '', $with_rewrite = true)
function my_error($header)
{
global $conf;

$error = '<pre>';
$error.= $header;
$error.= '[mysql error '.mysql_errno().'] ';
Expand Down Expand Up @@ -944,7 +967,7 @@ function get_available_upgrade_ids()
function load_conf_from_db()
{
global $conf;

$query = '
SELECT param,value
FROM '.CONFIG_TABLE.'
Expand All @@ -959,7 +982,7 @@ function load_conf_from_db()
while ($row = mysql_fetch_array($result))
{
$conf[ $row['param'] ] = isset($row['value']) ? $row['value'] : '';

// If the field is true or false, the variable is transformed into a
// boolean value.
if ($conf[$row['param']] == 'true' or $conf[$row['param']] == 'false')
Expand Down
4 changes: 3 additions & 1 deletion install/config.sql
Expand Up @@ -19,7 +19,9 @@ INSERT INTO phpwebgallery_config (param,value,comment) VALUES ('gallery_url','ht
INSERT INTO phpwebgallery_config (param,value,comment) VALUES ('rate','true','Rating pictures feature is enabled');
INSERT INTO phpwebgallery_config (param,value,comment) VALUES ('rate_anonymous','true','Rating pictures feature is also enabled for visitors');
INSERT INTO phpwebgallery_config (param,value,comment) VALUES ('page_banner','<h1>PhpWebGallery demonstration site</h1><p>My photos web site</p>','html displayed on the top each page of your gallery');

INSERT INTO phpwebgallery_config (param,value,comment) VALUES ('history_admin','false','keep a history of administrator visits on your website');
INSERT INTO phpwebgallery_config (param,value,comment) VALUES ('history_guest','true','keep a history of guest visits on your website');
INSERT INTO phpwebgallery_config (param,value,comment) VALUES ('login_history','true','keep a history of user logins on your website');
-- Notification by mail
INSERT INTO phpwebgallery_config (param,value,comment) VALUES ('nbm_send_mail_as','','Send mail as param value for notification by mail');
INSERT INTO phpwebgallery_config (param,value,comment) VALUES ('nbm_send_detailed_content','true','Send detailed content for notification by mail');
Expand Down
52 changes: 52 additions & 0 deletions install/db/30-database.php
@@ -0,0 +1,52 @@
<?php
// +-----------------------------------------------------------------------+
// | PhpWebGallery - a PHP based picture gallery |
// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
// | Copyright (C) 2003-2006 PhpWebGallery Team - http://phpwebgallery.net |
// +-----------------------------------------------------------------------+
// | branch : BSF (Best So Far)
// | file : $RCSfile$
// | last update : $Date: 2006-07-23 14:17:00 +0200 (dim, 23 jui 2006) $
// | last modifier : $Author: nikrou $
// | revision : $Revision: 1492 $
// +-----------------------------------------------------------------------+
// | 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 |
// | |
// | 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, write to the Free Software |
// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
// | USA. |
// +-----------------------------------------------------------------------+

if (!defined('PHPWG_ROOT_PATH'))
{
die('Hacking attempt!');
}

$upgrade_description = 'Add history_guest and login_history to #config';

$query = '
INSERT INTO '.PREFIX_TABLE."config (param,value,comment) VALUES ('history_admin','false','keep a history of administrator visits on your website');";
pwg_query($query);

$query = '
INSERT INTO '.PREFIX_TABLE."config (param,value,comment) VALUES ('history_guest','true','keep a history of guest visits on your website');";
pwg_query($query);

$query = '
INSERT INTO '.PREFIX_TABLE."config (param,value,comment) VALUES ('login_history','true','keep a history of user logins on your website');";
pwg_query($query);

echo
"\n"
. $upgrade_description
."\n"
;
?>
1 change: 1 addition & 0 deletions language/en_UK.iso-8859-1/admin.lang.php
Expand Up @@ -99,6 +99,7 @@
$lang['Link all category elements to some existing categories'] = 'Link all category elements to some existing categories';
$lang['Linked categories'] = 'Linked categories';
$lang['Lock gallery'] = 'Lock gallery';
$lang['Login history'] = 'User login history';
$lang['Maintenance'] = 'Maintenance';
$lang['Manage permissions for a category'] = 'Manage permissions for a category';
$lang['Manage permissions for group "%s"'] = 'Manage permissions for group "%s"';
Expand Down
20 changes: 14 additions & 6 deletions language/en_UK.iso-8859-1/help/configuration.html
Expand Up @@ -21,12 +21,6 @@ <h3>General</h3>

<li><strong>Gallery URL</strong>: used for the RSS feed.</li>

<li><strong>History</strong>: visits on pages <span
class="pwgScreen">category.php</span> and <span
class="pwgScreen">picture.php</span> will be registered in
<code>history</code> table. Visits will be shown in <span
class="pwgScreen">Administration, General, History</span>.</li>

<li><strong>Lock gallery</strong>: Lock the entire gallery for
maintenance. Only administrator users will be able to reach the
gallery.</li>
Expand All @@ -36,6 +30,20 @@ <h3>General</h3>
<li><strong>Rating by guests</strong>: Even non registered users can
rate images.</li>

<li><strong>History Users</strong>: visits by registrered users on pages <span
class="pwgScreen">category.php</span> and <span
class="pwgScreen">picture.php</span> will be saved in the
<code>history</code> table. Visits will be shown in <span
class="pwgScreen">Administration, General, History</span>.</li>

<li><strong>History Administrator</strong>: page visits by administrators
will be saved.</li>

<li><strong>History Guests</strong>: page visits by guests will be saved.</li>

<li><strong>User login history</strong>: when a user logs in, it will be
logged in the <code>history</code> table.</li>

</ul>


Expand Down
1 change: 1 addition & 0 deletions language/fr_FR.iso-8859-1/admin.lang.php
Expand Up @@ -99,6 +99,7 @@
$lang['Link all category elements to some existing categories'] = 'Associer tous les éléments de la catégorie à des catégories existantes';
$lang['Linked categories'] = 'Catégories associées';
$lang['Lock gallery'] = 'Verrouiller la galerie';
$lang['Login history'] = 'Historique des connexions';
$lang['Maintenance'] = 'Maintenance';
$lang['Manage permissions for a category'] = 'Gérer les permissions pour une catégorie';
$lang['Manage permissions for group "%s"'] = 'Gérer les permissions pour le groupe "%s"';
Expand Down
21 changes: 15 additions & 6 deletions language/fr_FR.iso-8859-1/help/configuration.html
Expand Up @@ -21,12 +21,6 @@ <h2>Configuration</h2>

<li><strong>URL de la galerie</strong>: utilisé pour le flux RSS.</li>

<li><strong>Historique</strong>: visites des pages <span
class="pwgScreen">category.php</span> et <span
class="pwgScreen">picture.php</span> sont enregistrées dans la table
<code>history</code>. Les visites sont affichées dans l'écran <span
class="pwgScreen">Administration, Général, Historique</span>.</li>

<li><strong>Verrouiller la galerie</strong>: Verrouiller l'ensemble de la
galerie pour maintenance. Seul les administrateurs pourront accéder à la
galerie.</li>
Expand All @@ -36,6 +30,21 @@ <h2>Configuration</h2>
<li><strong>Notation par les visiteurs</strong>: Même les utilisateurs
non enregistrés peuvent noter les images.</li>

<li><strong>Historique Utilisateurs</strong>: les visites des pages <span
class="pwgScreen">index.php</span> et <span
class="pwgScreen">picture.php</span> par les utilisateurs enregistrés sont
enregistrées dans la table <code>history</code>. Les visites sont affichées
dans l'écran <span class="pwgScreen">Administration, Général, Historique</span>.</li>

<li><strong>Historique Administrateur</strong>: les visites des pages
par les administrateurs sont enregistrées.</li>

<li><strong>Historique Invités</strong>: les visites des pages
par les invités sont enregistrées.</li>

<li><strong>Historique des connexions</strong>: chaque connexion
utilisateur, est enregistrée dans la table <code>history</code>.</li>

</ul>


Expand Down
1 change: 0 additions & 1 deletion register.php
Expand Up @@ -48,7 +48,6 @@
if (count($errors) == 0)
{
$user_id = get_userid($_POST['login']);
log_user( $user_id, false);
redirect(make_index_url());
}
}
Expand Down

0 comments on commit af621d4

Please sign in to comment.