From b592122f3cd379506db6dfff4568776dc906c3e9 Mon Sep 17 00:00:00 2001 From: jengo Date: Fri, 20 Oct 2000 04:43:13 +0000 Subject: [PATCH] More work on the SQL version of the admin section, editing accounts is now working --- admin/editaccount.php | 72 ++++++++++++++++++++------------- admin/inc/accounts_ldap.inc.php | 4 +- admin/inc/accounts_sql.inc.php | 66 +++++++++++++++++++++++++++++- admin/newaccount.php | 5 ++- 4 files changed, 112 insertions(+), 35 deletions(-) diff --git a/admin/editaccount.php b/admin/editaccount.php index f470392070..c15cddc184 100755 --- a/admin/editaccount.php +++ b/admin/editaccount.php @@ -17,9 +17,14 @@ $phpgw_info["flags"]["disable_message_class"] = True; $phpgw_info["flags"]["disable_send_class"] = True; include("../header.inc.php"); - if (! $account_id) - Header("Location: " . $phpgw->link("accounts.php")); + include($phpgw_info["server"]["server_root"] . "/admin/inc/accounts_" + . $phpgw_info["server"]["auth_type"] . ".inc.php"); + if (! $account_id) { + Header("Location: " . $phpgw->link("accounts.php")); + } + + // This function is gonna go soon. (jengo) function change_owner($app,$table,$field,$new,$old) { global $phpgw, $phpgw_info; @@ -30,30 +35,42 @@ } if ($submit) { - $phpgw->db->query("select account_lid from accounts where account_id=$account_id"); - $phpgw->db->next_record(); - $lid = $phpgw->db->f("account_lid"); + if ($old_loginid != $n_loginid) { + if (account_exsists($n_loginid)) { + $error .= "
" . lang("That loginid has already been taken"); + } + $c_loginid = $n_loginid; + $n_loginid = $old_loginid; + } + + if ($n_passwd || $n_passwd_2) { + if ($n_passwd != $n_passwd_2) { + $error .= lang("The two passwords are not the same"); + } + if (! $n_passwd){ + $error .= lang("You must enter a password"); + } + } - if ($n_passwd || $n_passwd_2) { - if ($n_passwd != $n_passwd_2){ - $error .= lang("The two passwords are not the same"); - } - if (! $n_passwd){ - $error .= lang("You must enter a password"); - } - } + if (count($new_permissions) == 0){ + $error .= "
" . lang("You must add at least 1 permission to this account"); + } + + if (! $error) { + $cd = account_edit(array("loginid" => $n_loginid, "permissions" => $new_permissions, + "firstname" => $n_firstname, "lastname" => $n_lastname, + "passwd" => $n_passwd, "account_status" => $account_status, + "c_loginid" => $c_loginid, + "groups" => $phpgw->accounts->groups_array_to_string($n_groups))); + } - if ($lid != $n_loginid) { - $phpgw->db->query("select account_lid from accounts where account_lid='$n_loginid'"); - if ($phpgw->db->num_rows() != 0) { - $error .= "
" . lang("That loginid has already been taken"); - } - } + +// $phpgw->db->query("select account_lid from accounts where account_id=$account_id"); +// $phpgw->db->next_record(); +// $lid = $phpgw->db->f("account_lid"); - if (count($new_permissions) == 0){ - $error .= "
" . lang("You must add at least 1 permission to this account"); - } - if (! $error) { + +/* if (! $error) { $phpgw->db->lock(array('accounts','preferences','sessions')); if ($n_passwd) { $phpgw->db->query("update accounts set account_pwd='" . md5($n_passwd) . "', " @@ -66,12 +83,8 @@ $phpgw->accounts->add_app($permission[0]); } } - //$phpgw->permissions->add("hr"); - if ($new_permissions["anonymous"] && ! $new_permissions["admin"]){ - $phpgw->accounts->add_app("anonymous"); - } - if (! $n_account_status){ + if (! $n_account_status) { $n_account_status = "L"; } $cd = 27; @@ -108,7 +121,7 @@ $phpgw->db->unlock(); Header("Location: " . $phpgw->link("accounts.php", "cd=$cd")); exit; - } // if ! $error + } // if ! $error */ } // if $submit $phpgw->common->phpgw_header(); @@ -124,6 +137,7 @@ ?>
"> + "> " . lang("Error") . ":$error"; diff --git a/admin/inc/accounts_ldap.inc.php b/admin/inc/accounts_ldap.inc.php index 14dd764426..2ddc28106a 100644 --- a/admin/inc/accounts_ldap.inc.php +++ b/admin/inc/accounts_ldap.inc.php @@ -11,7 +11,7 @@ /* $Id$ */ - function account_list($start,$sort,$order) + function account_read($method,$start,$sort,$order) { } @@ -21,7 +21,7 @@ } - function account_edit($account_id,$account_info) + function account_edit($account_info) { } diff --git a/admin/inc/accounts_sql.inc.php b/admin/inc/accounts_sql.inc.php index da30d1e3a8..26a577ddeb 100755 --- a/admin/inc/accounts_sql.inc.php +++ b/admin/inc/accounts_sql.inc.php @@ -11,7 +11,7 @@ /* $Id$ */ - function account_list($start,$sort,$order) + function account_read($method,$start,$sort,$order) { } @@ -66,9 +66,71 @@ return $cd; } - function account_edit($account_id,$account_info) + function account_edit($account_info) { + global $phpgw_info, $phpgw; + $phpgw->db->lock(array('accounts','preferences','sessions')); + + if ($account_info["c_loginid"]) { + $phpgw->db->query("update accounts set account_lid='" . $account_info["c_loginid"] + . "' where account_lid='" . $account_info["loginid"] . "'"); + + $account_info["loginid"] = $account_info["c_loginid"]; + } + + if ($account_info["passwd"]) { + $phpgw->db->query("update accounts set account_pwd='" . md5($account_info["passwd"]) . "', " + . "account_lastpwd_change='" . time() . "' where account_lid='" + . $account_info["loginid"] . "'"); + $phpgw->db->query("update sessions set session_pwd='" . addslashes($account_info["passwd"]) + . "' where session_lid='" . $account_info["loginid"] . "'"); + } + + while ($permission = each($account_info["permissions"])) { + if ($phpgw_info["apps"][$permission[0]]["enabled"]) { + $phpgw->accounts->add_app($permission[0]); + } + } + + if (! $account_info["account_status"]) { + $account_info["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 != $account_info["loginid"]) { + change_owner("","preferences","preference_owner",$account_info["loginid"],$lid); + change_owner("addressbook","addressbook","ab_owner",$account_info["loginid"],$lid); + change_owner("todo","todo","todo_owner",$account_info["loginid"],$lid); + change_owner("","accounts","account_lid",$account_info["loginid"],$lid); + change_owner("","sessions","session_lid",$account_info["loginid"],$lid); + change_owner("calendar","webcal_entry","cal_create_by",$account_info["loginid"],$lid); + change_owner("calendar","webcal_entry_user","cal_login",$account_info["loginid"],$lid); + + if ($lid != $n_loginid) { + $sep = $phpgw->common->filesystem_separator(); + + $basedir = $phpgw_info["server"]["files_dir"] . $sep . "users" . $sep; + + if (! @rename($basedir . $lid, $basedir . $account_info["loginid"])) { + $cd = 35; + } + } + } + + $phpgw->db->query("update accounts set account_firstname='" + . addslashes($account_info["firstname"]) . "', account_lastname='" + . addslashes($account_info["lastname"]) . "', account_permissions='" + . $phpgw->accounts->add_app("",True) . "', account_status='" + . $account_info["account_status"] . "', account_groups='" + . $account_info["groups"] . "' where account_lid='" . $account_info["loginid"] + . "'"); + + $phpgw->db->unlock(); + + return $cd; } function account_delete($account_id) diff --git a/admin/newaccount.php b/admin/newaccount.php index 701882f301..0cb2a3f845 100755 --- a/admin/newaccount.php +++ b/admin/newaccount.php @@ -11,8 +11,9 @@ /* $Id$ */ - $phpgw_info["flags"] = array("noheader" => True, "nonavbar" => True, "disable_message_class" => True, - "disable_send_class" => True, "currentapp" => "admin"); + $phpgw_info["flags"] = array("noheader" => True, "nonavbar" => True, + "disable_message_class" => True, "disable_send_class" => True, + "currentapp" => "admin"); include("../header.inc.php"); include($phpgw_info["server"]["server_root"] . "/admin/inc/accounts_"