|
From: Javier S. <ja...@us...> - 2001-09-07 08:47:07
|
Update of /cvsroot/phpbt/phpbt/admin
In directory usw-pr-cvs1:/tmp/cvs-serv14656
Modified Files:
user.php
Log Message:
Debug EMAIL_IS_LOGIN <> LOGIN_IS_MAIL pb :-)
Index: user.php
===================================================================
RCS file: /cvsroot/phpbt/phpbt/admin/user.php,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -r1.23 -r1.24
--- user.php 2001/09/03 20:28:43 1.23
+++ user.php 2001/09/07 08:47:04 1.24
@@ -29,44 +29,44 @@
global $q, $me, $_pv, $STRING, $now, $u;
// Validation
- if (!LOGIN_IS_EMAIL && !$_pv['flogin'] = trim($_pv['flogin'])) {
- $error = $STRING['givelogin'];
- } elseif (!valid_email($_pv['femail'])) {
+ if (!LOGIN_IS_EMAIL && !$_pv['flogin'] = trim($_pv['flogin'])) {
+ $error = $STRING['givelogin'];
+ } elseif (!valid_email($_pv['femail'])) {
$error = $STRING['giveemail'];
- } elseif (!$_pv['fpassword'] = trim($_pv['fpassword'])) {
+ } elseif (!$_pv['fpassword'] = trim($_pv['fpassword'])) {
$error = $STRING['givepassword'];
- }
- if ($error) {
- list_items($userid, $error);
- return;
- }
- if (!isset($_pv['factive'])) $_pv['factive'] = 0;
-
- if (LOGIN_IS_EMAIL) {
- $login = $_pv['email'];
- } else {
- $login = $_pv['login'];
- }
+ }
+ if ($error) {
+ list_items($userid, $error);
+ return;
+ }
+ if (!isset($_pv['factive'])) $_pv['factive'] = 0;
+
+ if (EMAIL_IS_LOGIN) {
+ $login = $_pv['femail'];
+ } else {
+ $login = $_pv['flogin'];
+ }
if (!$userid) {
if (ENCRYPTPASS) $mpassword = md5($_pv['fpassword']);
else $mpassword = $_pv['fpassword'];
- $new_user_id = $q->nextid(TBL_AUTH_USER);
+ $new_user_id = $q->nextid(TBL_AUTH_USER);
$q->query('insert into '.TBL_AUTH_USER
- ." (user_id, first_name, last_name, login, email, password, active,
- created_by, created_date, last_modified_by, last_modified_date)
- values ($new_user_id, '{$_pv['ffirstname']}', '{$_pv['flastname']}',
- '$login', '{$_pv['femail']}', '$mpassword', {$_pv['factive']}, $u, $now,
- $u, $now)");
- foreach ($_pv['fusergroup'] as $group) {
- $q->query("insert into ".TBL_USER_GROUP
- ." (user_id, group_id, created_by, created_date)
- values ('$new_user_id' ,'$group', $u, $now)");
- }
+ ." (user_id, first_name, last_name, login, email, password, active,
+ created_by, created_date, last_modified_by, last_modified_date)
+ values ($new_user_id, '{$_pv['ffirstname']}', '{$_pv['flastname']}',
+ '$login', '{$_pv['femail']}', '$mpassword', {$_pv['factive']}, $u, $now,
+ $u, $now)");
+ foreach ($_pv['fusergroup'] as $group) {
+ $q->query("insert into ".TBL_USER_GROUP
+ ." (user_id, group_id, created_by, created_date)
+ values ('$new_user_id' ,'$group', $u, $now)");
+ }
} else {
if (ENCRYPTPASS) {
$oldpass = $q->grab_field("select password from ".TBL_AUTH_USER
- ." where user_id = $userid");
+ ." where user_id = $userid");
if ($oldpass != $_pv['fpassword']) {
$pquery = "password = '".md5($_pv['fpassword'])."',";
} else {
@@ -75,42 +75,42 @@
} else {
$pquery = "password = '{$_pv['fpassword']}',";
}
- $q->query("update ".TBL_AUTH_USER." set first_name = '{$_pv['ffirstname']}',
- last_name = '{$_pv['flastname']}', email = '{$_pv['femail']}', $pquery
- active = {$_pv['factive']} where user_id = '$userid'");
-
- // Update group memberships
- // Get user's groups (without dropping the user group)
- $q->query('select ug.group_id from '.TBL_USER_GROUP.' ug left join '
- .TBL_AUTH_GROUP.' g using (group_id) '
- ." where user_id = $userid and group_name <> 'User'");
+ $q->query("update ".TBL_AUTH_USER." set first_name = '{$_pv['ffirstname']}',
+ last_name = '{$_pv['flastname']}',login = '$login', email = '{$_pv['femail']}', $pquery
+ active = {$_pv['factive']} where user_id = '$userid'");
+
+ // Update group memberships
+ // Get user's groups (without dropping the user group)
+ $q->query('select ug.group_id from '.TBL_USER_GROUP.' ug left join '
+ .TBL_AUTH_GROUP.' g using (group_id) '
+ ." where user_id = $userid and group_name <> 'User'");
while ($group_id = $q->grab_field()) {
- $user_groups[] = $group_id;
- }
- // Compute differences between old and new
- if (!is_array($user_groups)) {
- $user_groups = array();
- }
- if (!is_array($_pv['fusergroup'])) {
- $_pv['fusergroup'] = array();
- }
-
- $remove_from = array_diff($user_groups, $_pv['fusergroup']);
- $add_to = array_diff($_pv['fusergroup'], $user_groups);
-
- if (count($remove_from)) {
- foreach ($remove_from as $group) {
- $q->query('delete from '.TBL_USER_GROUP
- ." where user_id = $userid and group_id = $group");
- }
- }
- if (count($add_to)) {
- foreach ($add_to as $group) {
- $q->query("insert into ".TBL_USER_GROUP
- ." (user_id, group_id, created_by, created_date)
- values ('$userid' ,'$group', $u, $now)");
- }
- }
+ $user_groups[] = $group_id;
+ }
+ // Compute differences between old and new
+ if (!is_array($user_groups)) {
+ $user_groups = array();
+ }
+ if (!is_array($_pv['fusergroup'])) {
+ $_pv['fusergroup'] = array();
+ }
+
+ $remove_from = array_diff($user_groups, $_pv['fusergroup']);
+ $add_to = array_diff($_pv['fusergroup'], $user_groups);
+
+ if (count($remove_from)) {
+ foreach ($remove_from as $group) {
+ $q->query('delete from '.TBL_USER_GROUP
+ ." where user_id = $userid and group_id = $group");
+ }
+ }
+ if (count($add_to)) {
+ foreach ($add_to as $group) {
+ $q->query("insert into ".TBL_USER_GROUP
+ ." (user_id, group_id, created_by, created_date)
+ values ('$userid' ,'$group', $u, $now)");
+ }
+ }
}
header("Location: $me?");
}
@@ -121,12 +121,12 @@
if ($userid && !$error) {
$row = $q->grab("select * from ".TBL_AUTH_USER." where user_id = '$userid'");
-
- // Get user's groups
- $q->query('select group_id from '.TBL_USER_GROUP." where user_id = {$row['user_id']}");
+
+ // Get user's groups
+ $q->query('select group_id from '.TBL_USER_GROUP." where user_id = {$row['user_id']}");
while ($group_id = $q->grab_field()) {
- $user_groups[] = $group_id;
- }
+ $user_groups[] = $group_id;
+ }
$t->set_var(array(
'action' => $STRING['edit'],
@@ -138,7 +138,7 @@
'fpassword' => $row['password'],
'factive' => $row['active'] ? 'checked' : '',
'fusergroup' => build_select('group', $user_groups)
- ));
+ ));
} else {
$t->set_var(array(
'action' => $userid ? $STRING['edit'] : $STRING['addnew'],
@@ -149,18 +149,18 @@
'flastname' => stripslashes($_pv['lastname']),
'femail' => $_pv['email'],
'fpassword' => $_pv['password'] ? $_pv['password'] : genpassword(10),
- 'factive' => isset($_pv['active']) ? ($_pv['active'] ? 'checked' : '')
- : 'checked',
+ 'factive' => isset($_pv['active']) ? ($_pv['active'] ? 'checked' : '')
+ : 'checked',
'fusergroup' => build_select('group', $_pv['fusergroup'])
- ));
+ ));
+ }
+
+ // Show the login field only if login is not tied to email address
+ if (EMAIL_IS_LOGIN) {
+ $t->set_var('loginarea', '');
+ } else {
+ $t->parse('loginarea', 'loginentryarea', true);
}
-
- // Show the login field only if login is not tied to email address
- if (LOGIN_IS_EMAIL) {
- $t->set_var('loginarea', '');
- } else {
- $t->parse('loginarea', 'loginentryarea', true);
- }
}
function list_items($userid = 0, $error = '') {
@@ -182,9 +182,9 @@
'last' => $llimit+$selrange > $nr ? $nr : $llimit+$selrange,
'records' => $nr));
- $q->query("select user_id, concat(first_name,' ',last_name) as fullname,
- email, login, created_date, active from ".TBL_AUTH_USER
- ." order by $order $sort limit $llimit, $selrange");
+ $q->query("select user_id, concat(first_name,' ',last_name) as fullname,
+ email, login, created_date, active from ".TBL_AUTH_USER
+ ." order by $order $sort limit $llimit, $selrange");
if (!$q->num_rows()) {
$t->set_var('rows',"<tr><td>{$STRING['nousers']}</td></tr>");
@@ -234,4 +234,4 @@
page_close();
-?>
+?>
\ No newline at end of file
|