egroupware/admin/editaccount.php

231 lines
8.7 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");
if (! $con)
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-25 23:13:52 +02:00
$phpgw->db->query("select loginid from accounts where con=$con");
2000-09-06 17:55:58 +02:00
$phpgw->db->next_record();
$lid = $phpgw->db->f("loginid");
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) {
$phpgw->db->query("select loginid from accounts where loginid='$n_loginid'");
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) {
$phpgw->db->query("update accounts set passwd='" . md5($n_passwd) . "', "
. "lastpasswd_change='" . time() . "' where loginid='" . "$lid'");
$phpgw->db->query("update sessions set passwd='" . addslashes($n_passwd)
. "' where loginid='$lid'");
}
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) {
change_owner("","preferences","owner",$n_loginid,$lid);
change_owner("addressbook","addressbook","owner",$n_loginid,$lid);
change_owner("todo","todo","owner",$n_loginid,$lid);
change_owner("","accounts","loginid",$n_loginid,$lid);
change_owner("","sessions","loginid",$n_loginid,$lid);
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-06 17:55:58 +02:00
$phpgw->db->query("update accounts set firstname='" . addslashes($n_firstname) . "',"
. " lastname='" . addslashes($n_lastname) . "', permissions='"
. $phpgw->accounts->add_app("",True) . "', status='"
. "$n_account_status', groups='"
. $phpgw->accounts->array_to_string("none",$n_groups)
. "' where loginid='$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-25 23:13:52 +02:00
$phpgw->db->query("select loginid from accounts where con=$con");
$phpgw->db->next_record();
$db_perms = $phpgw->accounts->read_apps($phpgw->db->f("loginid"));
2000-09-25 23:13:52 +02:00
$phpgw->db->query("select * from accounts where con=$con");
2000-08-18 05:24:22 +02:00
$phpgw->db->next_record();
2000-08-27 03:52:30 +02:00
$account_status = $phpgw->db->f("status");
2000-09-06 17:55:58 +02:00
?>
<form method="POST" action="<?php echo $phpgw->link("editaccount.php"); ?>">
2000-08-18 05:24:22 +02:00
<input type="hidden" name="con" value="<? echo $con; ?>">
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-08-18 05:24:22 +02:00
<td><input name="n_loginid" value="<? echo $phpgw->db->f("loginid"); ?>"></td>
</tr>
<tr>
2000-09-07 22:49:55 +02:00
<td><?php echo lang("First Name"); ?></td>
2000-08-18 05:24:22 +02:00
<td><input name="n_firstname" value="<?echo $phpgw->db->f("firstname"); ?>"></td>
</tr>
<tr>
2000-09-07 22:49:55 +02:00
<td><?php echo lang("Last Name"); ?></td>
2000-08-18 05:24:22 +02:00
<td><input name="n_lastname" value="<? echo $phpgw->db->f("lastname"); ?>"></td>
</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
$user_groups = $phpgw->accounts->read_group_names($phpgw->db->f("loginid"));
$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
}
}
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
2000-08-27 03:52:30 +02:00
/*
2000-09-07 22:49:55 +02:00
echo "<tr><td>" . lang("Anonymous user") . "</td><td><input type=\""
2000-08-18 05:24:22 +02:00
. "checkbox\" name=\"new_permissions[anonymous]\" value=\"True\"";
if ($db_perms["anonymous"] || $new_permissions[anonymous])
2000-09-06 17:55:58 +02:00
echo " checked";
echo "></td>";
2000-08-18 05:24:22 +02:00
2000-09-07 22:49:55 +02:00
echo "<td>" . lang("Manager") . "</td><td><input type=\""
2000-08-18 05:24:22 +02:00
. "checkbox\" name=\"new_permissions[manager]\" value=\"True\"";
if ($db_perms["manager"] || $new_permissions[manager])
2000-09-06 17:55:58 +02:00
echo " checked";
2000-08-18 05:24:22 +02:00
echo "></td></tr>";
2000-08-27 03:52:30 +02:00
*/
2000-09-06 17:55:58 +02:00
?>
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"); ?>