Navigation Menu

Skip to content

Commit

Permalink
Step 1 improvement issue 0000301:
Browse files Browse the repository at this point in the history
  o Change status of table #_user_infos
  o Don't send password to webmaster, guest, generic

Next Step:
  o Functions Check of status
  o Restricted Access for user generic

git-svn-id: http://piwigo.org/svn/trunk@1070 68402e56-0260-453c-a942-63ccdbb3a9ee
  • Loading branch information
rub committed Mar 8, 2006
1 parent cba56c0 commit b263f0c
Show file tree
Hide file tree
Showing 15 changed files with 160 additions and 33 deletions.
2 changes: 1 addition & 1 deletion admin/include/functions.php
Expand Up @@ -1230,7 +1230,7 @@ function sync_users()
{
$insert = array();
$insert['user_id'] = $user_id;
$insert['status'] = 'guest';
$insert['status'] = 'normal';
$insert['template'] = $conf['default_template'];
$insert['nb_image_line'] = $conf['nb_image_line'];
$insert['nb_line_page'] = $conf['nb_line_page'];
Expand Down
2 changes: 1 addition & 1 deletion admin/include/isadmin.inc.php
Expand Up @@ -27,7 +27,7 @@

include( PHPWG_ROOT_PATH.'admin/include/functions.php' );

if ($user['status'] != 'admin')
if (!is_admin())
{
echo '<div style="text-align:center;">'.$lang['access_forbiden'].'<br />';
echo '<a href="'.PHPWG_ROOT_PATH.'identification.php">'.$lang['identification'].'</a></div>';
Expand Down
18 changes: 10 additions & 8 deletions admin/mailtousers.php
Expand Up @@ -77,16 +77,18 @@ function find_available_check_key()
*/
function update_data_user_mail_notification()
{
/* $query = '
insert into '.USER_MAIL_NOTIFICATION_TABLE.'
(user_id, enabled)
(select id, \'false\' from '.USERS_TABLE.'
where mail_address is not null and id not in (select user_id from '.USER_MAIL_NOTIFICATION_TABLE.'))
;';
pwg_query($query);*/

global $conf, $page;

// Set null mail_address empty
$query = '
update
'.USERS_TABLE.'
set
mail_address = null
where
trim(mail_address) = \'\';';
pwg_query($query);

$query = '
select
id user_id, username, mail_address
Expand Down
4 changes: 2 additions & 2 deletions admin/user_list.php
Expand Up @@ -377,7 +377,7 @@ function get_filtered_user_list()
// Webmaster status must not be changed
if ($conf['webmaster_id'] == $user_id and isset($data['status']))
{
$data['status'] = 'admin';
$data['status'] = 'webmaster';
}

array_push($datas, $data);
Expand Down Expand Up @@ -649,7 +649,7 @@ function get_filtered_user_list()
{
$selected = $_POST['status'] == $status ? 'selected="selected"' : '';
}
else if ('guest' == $status)
else if ('normal' == $status)
{
$selected = 'selected="selected"';
}
Expand Down
4 changes: 2 additions & 2 deletions category.php
Expand Up @@ -368,7 +368,7 @@
$template->assign_block_vars('logout', array());
}

if ('admin' == $user['status'])
if (is_admin())
{
$template->assign_block_vars('admin', array());
}
Expand Down Expand Up @@ -408,7 +408,7 @@

if (isset($page['cat'])
and is_numeric($page['cat'])
and 'admin' == $user['status'])
and is_admin())
{
$template->assign_block_vars(
'edit',
Expand Down
2 changes: 1 addition & 1 deletion include/common.inc.php
Expand Up @@ -208,7 +208,7 @@
echo '</div>';

if ( basename($_SERVER["PHP_SELF"]) != 'identification.php'
and $user['status'] != 'admin' )
and !is_admin() )
{
exit();
}
Expand Down
2 changes: 1 addition & 1 deletion include/functions.inc.php
Expand Up @@ -355,7 +355,7 @@ function pwg_log( $file, $category, $picture = '' )

if ($conf['log'])
{
if ( ($conf['history_admin'] ) or ( (! $conf['history_admin']) and ($user['status'] != 'admin') ) )
if ( ($conf['history_admin'] ) or ( (! $conf['history_admin']) and (!is_admin()) ) )
{
$login = ($user['id'] == $conf['guest_id'])
? 'guest' : addslashes($user['username']);
Expand Down
2 changes: 1 addition & 1 deletion include/functions_notification.inc.php
Expand Up @@ -192,7 +192,7 @@ function news($start, $end)
$nb_updated_categories));
}

if ('admin' == $user['status'])
if (is_admin())
{
$nb_unvalidated_comments = count(unvalidated_comments($end));
if ($nb_unvalidated_comments > 0)
Expand Down
15 changes: 13 additions & 2 deletions include/functions_user.inc.php
Expand Up @@ -292,7 +292,7 @@ function calculate_permissions($user_id, $user_status)
}

// if user is not an admin, locked categories can be considered as private$
if ($user_status != 'admin')
if (!is_admin())
{
$query = '
SELECT id
Expand Down Expand Up @@ -439,7 +439,7 @@ function create_user_infos($user_id)
$insert =
array(
'user_id' => $user_id,
'status' => $user_id == $conf['webmaster_id'] ? 'admin' : 'guest',
'status' => $user_id == $conf['webmaster_id'] ? 'admin' : 'normal',
'template' => $conf['default_template'],
'nb_image_line' => $conf['nb_image_line'],
'nb_line_page' => $conf['nb_line_page'],
Expand Down Expand Up @@ -536,4 +536,15 @@ function log_user($user_id, $remember_me)
$_SESSION['id'] = $user_id;
}

/*
* Return if current is an administrator
* @return bool
*/
function is_admin()
{
global $user;

return ($user['status'] == 'webmaster' or $user['status'] == 'admin') ? true : false;
}

?>
103 changes: 103 additions & 0 deletions install/db/12-database.php
@@ -0,0 +1,103 @@
<?php
// +-----------------------------------------------------------------------+
// | PhpWebGallery - a PHP based picture gallery |
// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
// | Copyright (C) 2003-2005 PhpWebGallery Team - http://phpwebgallery.net |
// +-----------------------------------------------------------------------+
// | branch : BSF (Best So Far)
// | file : $RCSfile$
// | last update : $Date: 2005-09-21 00:04:57 +0200 (mer, 21 sep 2005) $
// | last modifier : $Author: plg $
// | revision : $Revision: 870 $
// +-----------------------------------------------------------------------+
// | 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 = 'Field "Status" Table #user_infos changed';

include_once(PHPWG_ROOT_PATH.'include/constants.php');
include(PHPWG_ROOT_PATH . 'include/config_default.inc.php');
@include(PHPWG_ROOT_PATH. 'include/config_local.inc.php');

// +-----------------------------------------------------------------------+
// | Upgrade content |
// +-----------------------------------------------------------------------+

echo "Alter table ".USER_INFOS_TABLE;
$query = "
alter table ".USER_INFOS_TABLE."
modify column `status` enum('webmaster', 'admin', 'normal', 'generic', 'guest') NOT NULL default 'guest'
;";
pwg_query($query);

echo "Define webmaster";
$query = '
update
'.USER_INFOS_TABLE.'
set status = \'webmaster\'
where
user_id = '.$conf['webmaster_id'].' and status = \'admin\'
;';
$result = pwg_query($query);

echo "Define normal";
$query = '
select
user_id
from
'.USER_INFOS_TABLE.'
where
user_id != '.$conf['guest_id'].' and status = \'guest\'
;';
$result = pwg_query($query);

$datas = array();

while ($row = mysql_fetch_array($result))
{
array_push(
$datas,
array(
'user_id' => $row['user_id'],
'status' => 'normal'
)
);
}

mass_updates(
USER_INFOS_TABLE,
array(
'primary' => array('user_id'),
'update' => array('status')
),
$datas
);

// +-----------------------------------------------------------------------+
// | End notification |
// +-----------------------------------------------------------------------+

echo
"\n"
.'Column '.USER_INFOS_TABLE.'.status changed'
."\n"
;

?>
3 changes: 2 additions & 1 deletion install/phpwebgallery_structure.sql
@@ -1,4 +1,5 @@
-- MySQL dump 9.11
-- MySQL dump 9.11
--
-- Host: localhost Database: pwg-bsf
-- ------------------------------------------------------
Expand Down Expand Up @@ -294,7 +295,7 @@ CREATE TABLE `phpwebgallery_user_infos` (
`user_id` smallint(5) NOT NULL default '0',
`nb_image_line` tinyint(1) unsigned NOT NULL default '5',
`nb_line_page` tinyint(3) unsigned NOT NULL default '3',
`status` enum('admin','guest') NOT NULL default 'guest',
`status` enum('webmaster', 'admin', 'normal', 'generic', 'guest') NOT NULL default 'guest',
`language` varchar(50) NOT NULL default 'english',
`maxwidth` smallint(6) default NULL,
`maxheight` smallint(6) default NULL,
Expand Down
5 changes: 4 additions & 1 deletion language/en_UK.iso-8859-1/admin.lang.php
Expand Up @@ -392,8 +392,11 @@
$lang['user_delete_hint'] = 'Click here to delete this user. Warning! This operation cannot be undone!';
$lang['user_id URL parameter is missing'] = 'user_id URL parameter is missing';
$lang['user_status'] = 'User status';
$lang['user_status_webmaster'] = 'Webmaster';
$lang['user_status_admin'] = 'Administrator';
$lang['user_status_guest'] = 'User';
$lang['user_status_normal'] = 'User';
$lang['user_status_generic'] = 'Generic';
$lang['user_status_guest'] = 'Guest';
$lang['username'] = 'username';
$lang['users'] = 'Users';
$lang['visitors'] = 'Visitors';
Expand Down
5 changes: 4 additions & 1 deletion language/fr_FR.iso-8859-1/admin.lang.php
Expand Up @@ -392,8 +392,11 @@
$lang['user_delete_hint'] = 'Cliquer ici pour supprimer cet utilisateur. Attention : cette opération ne peut pas être annulée !';
$lang['user_id URL parameter is missing'] = 'le paramètre d\'URL "user_id" manque';
$lang['user_status'] = 'Statut de l\'utilisateur';
$lang['user_status_webmaster'] = 'Webmestre';
$lang['user_status_admin'] = 'Administrateur';
$lang['user_status_guest'] = 'Visiteur';
$lang['user_status_normal'] = 'Visiteur';
$lang['user_status_generic'] = 'Générique';
$lang['user_status_guest'] = 'Invité';
$lang['username'] = 'nom utilisateur';
$lang['users'] = 'Utilisateurs';
$lang['visitors'] = 'Visiteurs';
Expand Down
8 changes: 6 additions & 2 deletions password.php
Expand Up @@ -69,8 +69,12 @@
SELECT '.$conf['user_fields']['id'].' AS id
, '.$conf['user_fields']['username'].' AS username
, '.$conf['user_fields']['email'].' AS email
FROM '.USERS_TABLE.'
WHERE '.$conf['user_fields']['email'].' = \''.$mail_address.'\'
FROM '.USERS_TABLE.' as u
INNER JOIN '.USER_INFOS_TABLE.' AS ui
ON u.'.$conf['user_fields']['id'].' = ui.user_id
WHERE '
.$conf['user_fields']['email'].' = \''.$mail_address.'\' AND
ui.status not in (\'guest\', \'generic\', \'webmaster\')
;';
$result = pwg_query($query);

Expand Down
18 changes: 9 additions & 9 deletions picture.php
Expand Up @@ -114,7 +114,7 @@
}

//-------------------------------------------------------------- representative
if ('admin' == $user['status'] and isset($_GET['representative']))
if (is_admin() and isset($_GET['representative']))
{
$query = '
UPDATE '.CATEGORIES_TABLE.'
Expand Down Expand Up @@ -480,7 +480,7 @@
$data{'image_id'} = $_GET['image_id'];
$data{'content'} = htmlspecialchars( $_POST['content'], ENT_QUOTES);

if (!$conf['comments_validation'] or $user['status'] == 'admin')
if (!$conf['comments_validation'] or is_admin())
{
$data{'validated'} = 'true';
$data{'validation_date'} = $dbnow;
Expand All @@ -498,9 +498,9 @@
// information message
$message = $lang['comment_added'];

if (!$conf['comments_validation'] or $user['status'] == 'admin')
if (!$conf['comments_validation'] or is_admin())

if ( $conf['comments_validation'] and $user['status'] != 'admin' )
if ( $conf['comments_validation'] and !is_admin() )
{
$message.= '<br />'.$lang['comment_to_validate'];
}
Expand All @@ -519,7 +519,7 @@
// comment deletion
if ( isset( $_GET['del'] )
and is_numeric( $_GET['del'] )
and $user['status'] == 'admin' )
and is_admin() )
{
$query = 'DELETE FROM '.COMMENTS_TABLE;
$query.= ' WHERE id = '.$_GET['del'];
Expand Down Expand Up @@ -686,7 +686,7 @@
);
}
// button to set the current picture as representative
if ('admin' == $user['status'] and
if (is_admin() and
isset($page['cat']) and is_numeric($page['cat']))
{
$template->assign_block_vars(
Expand All @@ -700,7 +700,7 @@
);
}

if ('admin' == $user['status'])
if (is_admin())
{
$template->assign_block_vars(
'caddie',
Expand Down Expand Up @@ -752,7 +752,7 @@
}
}
//------------------------------------ admin link for information modifications
if ( $user['status'] == 'admin' )
if ( is_admin() )
{
$template->assign_block_vars('admin', array());
}
Expand Down Expand Up @@ -1152,7 +1152,7 @@
'COMMENT'=>parse_comment_content($row['content'])
));

if ( $user['status'] == 'admin' )
if ( is_admin() )
{
$template->assign_block_vars(
'comments.comment.delete',
Expand Down

0 comments on commit b263f0c

Please sign in to comment.