egroupware_official/admin/editaccount.php

217 lines
8.4 KiB
PHP
Raw Normal View History

2000-08-18 05:24:22 +02:00
<?php
/**************************************************************************\
* phpGroupWare - administration *
* http://www.phpgroupware.org *
* -------------------------------------------- *
* 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 2 of the License, or (at your *
* option) any later version. *
\**************************************************************************/
/* $Id$ */
$phpgw_info["flags"] = array("noheader" => True, "nonavbar" => True);
2000-08-18 05:24:22 +02:00
$phpgw_info["flags"]["currentapp"] = "admin";
2000-09-25 23:13:52 +02:00
$phpgw_info["flags"]["disable_message_class"] = True;
$phpgw_info["flags"]["disable_send_class"] = True;
2000-08-18 05:24:22 +02:00
include("../header.inc.php");
2000-09-26 00:27:40 +02:00
if (! $account_id)
2000-08-18 05:24:22 +02:00
Header("Location: " . $phpgw->link("accounts.php"));
function change_owner($app,$table,$field,$new,$old)
{
global $phpgw, $phpgw_info;
if ($phpgw_info["apps"][$app]["enabled"] || ! $app) {
$phpgw->db->query("update $table set $field='$new' where $field='$old'");
}
}
if ($submit) {
2000-09-26 00:27:40 +02:00
$phpgw->db->query("select account_lid from accounts where account_id=$account_id");
2000-09-06 17:55:58 +02:00
$phpgw->db->next_record();
2000-09-26 00:27:40 +02:00
$lid = $phpgw->db->f("account_lid");
2000-09-06 17:55:58 +02:00
if ($n_passwd || $n_passwd_2) {
if ($n_passwd != $n_passwd_2){
2000-09-07 22:49:55 +02:00
$error .= lang("The two passwords are not the same");
2000-09-06 17:55:58 +02:00
}
if (! $n_passwd){
2000-09-07 22:49:55 +02:00
$error .= lang("You must enter a password");
2000-09-06 17:55:58 +02:00
}
}
if ($lid != $n_loginid) {
2000-09-26 00:27:40 +02:00
$phpgw->db->query("select account_lid from accounts where account_lid='$n_loginid'");
2000-09-06 17:55:58 +02:00
if ($phpgw->db->num_rows() != 0) {
2000-09-07 22:49:55 +02:00
$error .= "<br>" . lang("That loginid has already been taken");
2000-09-06 17:55:58 +02:00
}
}
2000-08-18 05:24:22 +02:00
2000-09-06 17:55:58 +02:00
if (count($new_permissions) == 0){
2000-09-07 22:49:55 +02:00
$error .= "<br>" . lang("You must add at least 1 permission to this account");
2000-09-06 17:55:58 +02:00
}
if (! $error) {
$phpgw->db->lock(array('accounts','preferences','sessions'));
if ($n_passwd) {
2000-09-26 00:27:40 +02:00
$phpgw->db->query("update accounts set account_pwd='" . md5($n_passwd) . "', "
. "account_lastpwd_change='" . time() . "' where account_lid='" . "$lid'");
$phpgw->db->query("update sessions set session_pwd='" . addslashes($n_passwd)
. "' where session_lid='$lid'");
2000-09-06 17:55:58 +02:00
}
while ($permission = each($new_permissions)) {
if ($phpgw_info["apps"][$permission[0]]["enabled"]) {
$phpgw->accounts->add_app($permission[0]);
2000-08-18 05:24:22 +02:00
}
2000-09-06 17:55:58 +02:00
}
//$phpgw->permissions->add("hr");
if ($new_permissions["anonymous"] && ! $new_permissions["admin"]){
$phpgw->accounts->add_app("anonymous");
}
if (! $n_account_status){
$n_account_status = "L";
}
$cd = 27;
// If they changed there loginid, we need to change the owner in ALL
// tables to reflect on the new one
if ($lid != $n_loginid) {
2000-09-28 01:17:36 +02:00
change_owner("","preferences","preference_owner",$n_loginid,$lid);
change_owner("addressbook","addressbook","ab_owner",$n_loginid,$lid);
change_owner("todo","todo","todo_owner",$n_loginid,$lid);
change_owner("","accounts","account_lid",$n_loginid,$lid);
change_owner("","sessions","session_lid",$n_loginid,$lid);
2000-09-06 17:55:58 +02:00
change_owner("calendar","webcal_entry","cal_create_by",$n_loginid,$lid);
change_owner("calendar","webcal_entry_user","cal_login",$n_loginid,$lid);
if ($lid <> $n_loginid) {
$sep = $phpgw->common->filesystem_separator();
2000-08-18 05:24:22 +02:00
2000-08-27 14:24:57 +02:00
$basedir = $phpgw_info["server"]["server_root"] . $sep . "filemanager" . $sep
2000-09-06 17:55:58 +02:00
. "users" . $sep;
2000-08-18 05:24:22 +02:00
2000-08-27 14:24:57 +02:00
if (! @rename($basedir . $lid, $basedir . $n_loginid)) {
2000-09-06 17:55:58 +02:00
$cd = 35;
}
2000-08-18 05:24:22 +02:00
}
2000-09-06 17:55:58 +02:00
}
2000-08-18 05:24:22 +02:00
2000-09-26 00:27:40 +02:00
$phpgw->db->query("update accounts set account_firstname='" . addslashes($n_firstname) . "',"
. " account_lastname='" . addslashes($n_lastname) . "', account_permissions='"
. $phpgw->accounts->add_app("",True) . "', account_status='"
. "$n_account_status', account_groups='"
. $phpgw->accounts->array_to_string("none",$n_groups)
. "' where account_lid='$n_loginid'");
2000-08-18 05:24:22 +02:00
$phpgw->db->unlock();
2000-08-18 05:24:22 +02:00
Header("Location: " . $phpgw->link("accounts.php", "cd=$cd"));
exit;
2000-09-06 17:55:58 +02:00
} // if ! $error
2000-08-18 05:24:22 +02:00
} // if $submit
$phpgw->common->header();
$phpgw->common->navbar();
2000-08-27 03:52:30 +02:00
2000-09-26 00:27:40 +02:00
$phpgw->db->query("select account_lid from accounts where account_id=$account_id");
$phpgw->db->next_record();
2000-09-26 00:27:40 +02:00
$db_perms = $phpgw->accounts->read_apps($phpgw->db->f("account_lid"));
2000-09-26 00:27:40 +02:00
$phpgw->db->query("select * from accounts where account_id=$account_id");
2000-08-18 05:24:22 +02:00
$phpgw->db->next_record();
2000-09-26 00:27:40 +02:00
$account_status = $phpgw->db->f("account_status");
2000-09-06 17:55:58 +02:00
?>
<form method="POST" action="<?php echo $phpgw->link("editaccount.php"); ?>">
2000-09-26 00:27:40 +02:00
<input type="hidden" name="account_id" value="<? echo $account_id; ?>">
2000-09-06 17:55:58 +02:00
<?php
if ($error) {
2000-09-07 22:49:55 +02:00
echo "<center>" . lang("Error") . ":$error</center>";
2000-09-06 17:55:58 +02:00
}
?>
2000-08-18 05:24:22 +02:00
<center>
<table border=0 width=65%>
<tr>
2000-09-07 22:49:55 +02:00
<td><?php echo lang("LoginID"); ?></td>
2000-09-26 00:27:40 +02:00
<td><input name="n_loginid" value="<? echo $phpgw->db->f("account_lid"); ?>"></td>
2000-08-18 05:24:22 +02:00
</tr>
<tr>
2000-09-07 22:49:55 +02:00
<td><?php echo lang("First Name"); ?></td>
2000-09-26 00:27:40 +02:00
<td><input name="n_firstname" value="<?echo $phpgw->db->f("account_firstname"); ?>"></td>
2000-08-18 05:24:22 +02:00
</tr>
<tr>
2000-09-07 22:49:55 +02:00
<td><?php echo lang("Last Name"); ?></td>
2000-09-26 00:27:40 +02:00
<td><input name="n_lastname" value="<? echo $phpgw->db->f("account_lastname"); ?>"></td>
2000-08-18 05:24:22 +02:00
</tr>
<tr>
2000-09-07 22:49:55 +02:00
<td><?php echo lang("Groups"); ?></td>
2000-08-18 05:24:22 +02:00
<td><select name="n_groups[]" multiple size="5">
2000-09-06 17:55:58 +02:00
<?php
2000-09-26 00:27:40 +02:00
$user_groups = $phpgw->accounts->read_group_names($phpgw->db->f("account_lid"));
2000-09-06 17:55:58 +02:00
$phpgw->db->query("select * from groups");
while ($phpgw->db->next_record()) {
echo "<option value=\"" . $phpgw->db->f("group_id") . "\"";
for ($i=0; $i<count($user_groups); $i++) {
if ($user_groups[$i][0] == $phpgw->db->f("group_id")){
echo " selected";
2000-08-18 05:24:22 +02:00
}
2000-09-06 17:55:58 +02:00
}
echo ">" . $phpgw->db->f("group_name") . "</option>\n";
}
?>
</select>
</tr>
<?php
$i = 0;
while ($permission = each($phpgw_info["apps"])) {
if ($permission[1]["enabled"]) {
$perm_display[$i][0] = $permission[0];
$perm_display[$i][1] = $permission[1]["title"];
2000-08-18 05:24:22 +02:00
$i++;
2000-09-06 17:55:58 +02:00
}
}
2000-09-06 17:55:58 +02:00
for ($i=0;$i<200;) { // The $i<200 is only used for a brake
if (! $perm_display[$i][1]) break;
2000-09-07 22:49:55 +02:00
echo '<tr><td>' . lang($perm_display[$i][1]) . '</td>'
2000-09-06 17:55:58 +02:00
. '<td><input type="checkbox" name="new_permissions['
. $perm_display[$i][0] . ']" value="True"';
if ($new_permissions[$perm_display[$i][0]] || $db_perms[$perm_display[$i][0]]) {
echo " checked";
}
echo "></td>";
$i++;
if (! $perm_display[$i][1]) break;
2000-09-07 22:49:55 +02:00
echo '<td>' . lang($perm_display[$i][1]) . '</td>'
2000-09-06 17:55:58 +02:00
. '<td><input type="checkbox" name="new_permissions['
. $perm_display[$i][0] . ']" value="True"';
if ($new_permissions[$perm_display[$i][0]] || $db_perms[$perm_display[$i][0]]) {
echo " checked";
}
echo "></td></tr>";
$i++;
}
?>
2000-08-18 05:24:22 +02:00
<tr>
2000-09-07 22:49:55 +02:00
<td><?php echo lang("Account active"); ?></td>
2000-09-06 17:55:58 +02:00
<td><input type="checkbox" name="n_account_status" value="A" <?php if ($account_status == "A") { echo " checked"; } ?>>
</td>
2000-08-18 05:24:22 +02:00
</tr>
<tr>
2000-09-07 22:49:55 +02:00
<td><?php echo lang("New password [ Leave blank for no change ]"); ?></td>
2000-08-18 05:24:22 +02:00
<td><input type=password name="n_passwd"></td>
</tr>
<tr>
2000-09-07 22:49:55 +02:00
<td><?php echo lang("Re-enter password"); ?></td>
2000-08-18 05:24:22 +02:00
<td><input type=password name="n_passwd_2"></td>
</tr>
<tr>
2000-09-07 22:49:55 +02:00
<td colspan=2><input type="submit" name="submit" value="<?php echo lang("submit"); ?>"></td>
2000-08-18 05:24:22 +02:00
</tr>
</table>
</center>
</form>
2000-09-25 23:13:52 +02:00
<?php include($phpgw_info["server"]["api_dir"] . "/footer.inc.php"); ?>