From d30890881afe7d71424ff1d8ae37b3af5a455dfc Mon Sep 17 00:00:00 2001 From: jengo Date: Tue, 26 Dec 2000 06:30:51 +0000 Subject: [PATCH] Started fixing edit account --- admin/editaccount.php | 124 +++++++++++---------- admin/inc/accounts_ldap.inc.php | 49 ++++---- phpgwapi/inc/phpgw.inc.php | 6 +- phpgwapi/inc/phpgw_accounts_shared.inc.php | 7 +- 4 files changed, 96 insertions(+), 90 deletions(-) diff --git a/admin/editaccount.php b/admin/editaccount.php index 86df9dd1f7..9a5892cc06 100755 --- a/admin/editaccount.php +++ b/admin/editaccount.php @@ -13,9 +13,9 @@ $phpgw_info = array(); $phpgw_info["flags"] = array("noheader" => True, - "nonavbar" => True, - "currentapp" => "admin", - "parent_page" => "accounts.php"); + "nonavbar" => True, + "currentapp" => "admin", + "parent_page" => "accounts.php"); include("../header.inc.php"); include($phpgw_info["server"]["app_inc"]."/accounts_".$phpgw_info["server"]["account_repository"].".inc.php"); @@ -54,61 +54,68 @@ } if (! $totalerrors) { - $phpgw->db->query("SELECT account_permissions FROM accounts WHERE account_id = ".$account_id); - $phpgw->db->next_record(); - $apps_before = $phpgw->db->f("account_permissions"); + $phpgw->db->query("SELECT account_permissions FROM accounts WHERE account_lid='" . $old_loginid . "'",__LINE__,__FILE__); + $phpgw->db->next_record(); + $apps_before = $phpgw->db->f("account_permissions"); + + while ($permission = each($new_permissions)) { + if ($phpgw_info["apps"][$permission[0]]["enabled"]) { + $phpgw->accounts->add_app($permission[0]); + } + } + $apps_after = $phpgw->accounts->add_app("",True); + if($apps_before <> $apps_after) { + $after_apps = explode(":",$apps_after); + for ($i=1;$i<=count($after_apps);$i++) { + if (!strpos(" ".$apps_before." ",$after_apps)) { + $new_apps[] = $after_apps; + } + } + } - while ($permission = each($new_permissions)) { - if ($phpgw_info["apps"][$permission[0]]["enabled"]) { - $phpgw->accounts->add_app($permission[0]); - } - } - $apps_after = $phpgw->accounts->add_app("",True); - if($apps_before <> $apps_after) { - $after_apps = explode(":",$apps_after); - for ($i=1;$i<=count($after_apps);$i++) { - if (!strpos(" ".$apps_before." ",$after_apps)) { - $new_apps[] = $after_apps; - } - } - } + $cd = account_edit(array("loginid" => $n_loginid, "permissions" => $new_permissions, + "firstname" => $n_firstname, "lastname" => $n_lastname, + "passwd" => $n_passwd, "account_status" => $n_account_status, + "old_loginid" => $old_loginid, "account_id" => rawurldecode($account_id), + "groups" => $phpgw->accounts->groups_array_to_string($n_groups))); - $cd = account_edit(array("loginid" => $n_loginid, "permissions" => $new_permissions, - "firstname" => $n_firstname, "lastname" => $n_lastname, - "passwd" => $n_passwd, "account_status" => $n_account_status, - "old_loginid" => $old_loginid, "account_id" => rawurldecode($account_id), - "groups" => $phpgw->accounts->groups_array_to_string($n_groups))); + // If the user is logged in, it will force a refresh of the session_info + $phpgw->db->query("update phpgw_sessions set session_info='' where session_lid='$new_loginid@" . $phpgw_info["user"]["domain"] . "'",__LINE__,__FILE__); // The following sets any default preferences needed for new applications.. // This is smart enough to know if previous preferences were selected, use them. - if (count($new_apps)) { - if ($account_id <> $phpgw_info["user"]["account_id"]) { - $phpgw->db->query("SELECT preference_value FROM preferences WHERE preference_owner=".$account_id,__FILE__,__LINE__); - $phpgw->db->next_record(); - $phpgw_newuser["user"]["preferences"] = unserialize($phpgw->db->f("preference_value")); - } else { - $phpgw_newuser["user"]["preferences"] = $phpgw_info["user"]["preferences"]; - } - $docommit = False; - for ($j=0;$jcommon->hook_single("add_def_pref", $new_apps[$j]); - $docommit = True; - } - } - if ($docommit) { - if ($account_id <> $phpgw_info["user"]["account_id"]) { - $phpgw->preferences->commit_user($account_id); - } else { - $phpgw_info["user"]["preferences"] = $phpgw_newuser["user"]["preferences"]; - unset($phpgw_newuser); - $phpgw->preferences->commit(); - } - } - } + if (count($new_apps)) { + $phpgw->db->query("select account_id from accounts where account_lid='$new_loginid'",__LINE__,__FILE__); + $phpgw->db->next_record(); + $users_account_id = $phpgw->db->f("account_id"); + + if ($account_id <> $phpgw_info["user"]["account_id"]) { + $phpgw->db->query("SELECT preference_value FROM preferences WHERE preference_owner='$users_account_id'",__FILE__,__LINE__); + $phpgw->db->next_record(); + $phpgw_newuser["user"]["preferences"] = unserialize($phpgw->db->f("preference_value")); + } else { + $phpgw_newuser["user"]["preferences"] = $phpgw_info["user"]["preferences"]; + } + $docommit = False; + for ($j=0;$jcommon->hook_single("add_def_pref", $new_apps[$j]); + $docommit = True; + } + } + if ($docommit) { + if ($account_id <> $phpgw_info["user"]["account_id"]) { + $phpgw->preferences->commit_user($users_account_id); + } else { + $phpgw_info["user"]["preferences"] = $phpgw_newuser["user"]["preferences"]; + unset($phpgw_newuser); + $phpgw->preferences->commit(); + } + } + } - Header("Location: " . $phpgw->link("accounts.php", "cd=$cd")); - $phpgw->common->phpgw_exit(); + Header("Location: " . $phpgw->link("accounts.php", "cd=$cd")); + $phpgw->common->phpgw_exit(); } } // if $submit @@ -134,9 +141,9 @@ } if ($phpgw_info["server"]["account_repository"] == "ldap") { - $phpgw->template->set_var("form_action",$phpgw->link("editaccount.php","account_id=" . rawurlencode($userData["account_dn"]) . "&old_loginid=" . $userData["account_lid"])); + $phpgw->template->set_var("form_action",$phpgw->link("editaccount.php","account_id=" . rawurlencode($userData["account_dn"]) . "&old_loginid=" . $userData["account_lid"])); } else { - $phpgw->template->set_var("form_action",$phpgw->link("editaccount.php","account_id=" . $userData["account_id"] . "&old_loginid=" . $userData["account_lid"])); + $phpgw->template->set_var("form_action",$phpgw->link("editaccount.php","account_id=" . $userData["account_id"] . "&old_loginid=" . $userData["account_lid"])); } $phpgw->template->set_var("th_bg",$phpgw_info["theme"]["th_bg"]); @@ -149,10 +156,11 @@ $phpgw->template->set_var("n_loginid_value",$n_loginid); $phpgw->template->set_var("lang_account_active",lang("Account active")); - if ($userData["status"]) - $phpgw->template->set_var("account_checked","checked"); - else - $phpgw->template->set_var("account_checked",""); + if ($userData["status"]) { + $phpgw->template->set_var("account_checked","checked"); + } else { + $phpgw->template->set_var("account_checked",""); + } $phpgw->template->set_var("lang_password",lang("Password")); $phpgw->template->set_var("n_passwd_value",$n_passwd); diff --git a/admin/inc/accounts_ldap.inc.php b/admin/inc/accounts_ldap.inc.php index df9c09a981..260b59f722 100644 --- a/admin/inc/accounts_ldap.inc.php +++ b/admin/inc/accounts_ldap.inc.php @@ -143,16 +143,16 @@ // Much of this is going to be guess work for now, until we get things planned out. $entry["uid"] = $account_info["loginid"]; $entry["uidNumber"] = $account_info["account_id"]; - $entry["gidNumber"] = $account_info["account_id"]; - $entry["userpassword"] = $account_info["passwd"]; - $entry["loginShell"] = "/bin/bash"; + $entry["gidNumber"] = $account_info["account_id"]; + $entry["userpassword"] = $account_info["passwd"]; + $entry["loginShell"] = "/bin/bash"; $entry["homeDirectory"] = "/home/" . $account_info["loginid"]; - $entry["cn"] = sprintf("%s %s", $account_info["firstname"], $account_info["lastname"]); - $entry["sn"] = $account_info["lastname"]; - $entry["givenname"] = $account_info["firstname"]; + $entry["cn"] = sprintf("%s %s", $account_info["firstname"], $account_info["lastname"]); + $entry["sn"] = $account_info["lastname"]; + $entry["givenname"] = $account_info["firstname"]; //$entry["company"] = $company; //$entry["title"] = $title; - $entry["mail"] = $account_info["loginid"] . "@" . $phpgw_info["server"]["mail_suffix"]; + $entry["mail"] = $account_info["loginid"] . "@" . $phpgw_info["server"]["mail_suffix"]; //$entry["telephonenumber"] = $telephonenumber; //$entry["homephone"] = $homephone; //$entry["pagerphone"] = $pagerphone; @@ -197,14 +197,14 @@ . addslashes($account_info["lastname"]) . "','" . $phpgw->accounts->add_app("",True) . "','" . $account_info["groups"] . "','A',0)"; - $phpgw->db->query($sql); + $phpgw->db->query($sql,__LINE__,__FILE__); $phpgw->db->unlock(); $sep = $phpgw->common->filesystem_separator(); $basedir = $phpgw_info["server"]["files_dir"] . $sep . "users" . $sep; - if (! mkdir($basedir . $account_info["loginid"], 0707)) { + if (! @mkdir($basedir . $account_info["loginid"], 0707)) { $cd = 36; } else { $cd = 28; @@ -215,7 +215,7 @@ function account_edit($account_info) { - global $phpgw, $phpgw_info, $ldap; + global $phpgw, $phpgw_info, $ldap, $new_loginid; // This is just until the API fully handles reading the LDAP account info. @@ -226,10 +226,10 @@ $entry["uid"] = $account_info["loginid"]; $entry["homeDirectory"] = "/home/" . $account_info["loginid"]; - $entry["mail"] = $account_info["loginid"] . "@" . $phpgw_info["server"]["mail_suffix"]; + $entry["mail"] = $account_info["loginid"] . "@" . $phpgw_info["server"]["mail_suffix"]; $phpgw->db->query("update accounts set account_lid='" . $account_info["loginid"] . "' " - . "where account_lid='" . $account_info["old_loginid"] . "'"); + . "where account_lid='" . $account_info["old_loginid"] . "'",__LINE__,__FILE__); } if ($account_info["passwd"]) { @@ -237,7 +237,7 @@ // Update the sessions table. (The user might be logged in) $phpgw->db->query("update sessions set session_pwd='" . $phpgw->common->encrypt($n_passwd) . "' " - . "where session_lid='$lid'"); + . "where session_lid='$lid'",__LINE__,__FILE__); } while ($permission = each($account_info["permissions"])) { @@ -256,15 +256,16 @@ $dn = $account_info["account_id"]; @ldap_modify($ldap, $dn, $entry); - $phpgw->db->query("update accounts set account_firstname='". $account_info["firstname"] ."', - account_lastname='". $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->query("update accounts set account_firstname='". $account_info["firstname"] ."'," + . "account_lastname='". $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"]. "'",__LINE__,__FILE__); $cd = 27; + $new_loginid = $account_info["loginid"]; if ($account_info["old_loginid"] != $account_info["loginid"]) { $sep = $phpgw->common->filesystem_separator(); @@ -302,7 +303,7 @@ // set $account_id to uidnumber for sql $account_id = $allValues[0]["uidnumber"][0]; - $phpgw->db->query("select account_lid from accounts where account_id=$account_id"); + $phpgw->db->query("select account_lid from accounts where account_id=$account_id",__LINE__,__FILE__); $phpgw->db->next_record(); $lid = $phpgw->db->f(0); @@ -312,10 +313,10 @@ $phpgw->db->lock($table_locks); - $phpgw->db->query("delete from todo where todo_owner='".$account_id."'"); - $phpgw->db->query("delete from addressbook where ab_owner='".$account_id."'"); - $phpgw->db->query("delete from accounts where account_id='".$account_id."'"); - $phpgw->db->query("delete from preferences where preference_owner='".$account_id."'"); + $phpgw->db->query("delete from todo where todo_owner='".$account_id."'",__LINE__,__FILE__); + $phpgw->db->query("delete from addressbook where ab_owner='".$account_id."'",__LINE__,__FILE__); + $phpgw->db->query("delete from accounts where account_id='".$account_id."'",__LINE__,__FILE__); + $phpgw->db->query("delete from preferences where preference_owner='".$account_id."'",__LINE__,__FILE__); $phpgw->db->unlock(); diff --git a/phpgwapi/inc/phpgw.inc.php b/phpgwapi/inc/phpgw.inc.php index 9d21fae6f2..5db5dcac58 100644 --- a/phpgwapi/inc/phpgw.inc.php +++ b/phpgwapi/inc/phpgw.inc.php @@ -180,7 +180,6 @@ if (empty($phpgw_info["server"]["account_repository"])){$phpgw_info["server"]["account_repository"] = $phpgw_info["server"]["auth_type"];} include($phpgw_info["server"]["api_inc"] . "/phpgw_accounts_".$phpgw_info["server"]["account_repository"].".inc.php"); include($phpgw_info["server"]["api_inc"] . "/phpgw_accounts_shared.inc.php"); - $this->auth = new auth; $this->session = new sessions; }else{ @@ -199,9 +198,9 @@ include($phpgw_info["server"]["api_inc"] . "/phpgw_accounts_shared.inc.php"); $this->auth = new auth; } + $this->accounts = new accounts; $this->translation = new translation; $this->common = new common; - $this->accounts = new accounts; $this->preferences = new preferences; $this->acl = new acl; $this->hooks = new hooks; @@ -300,7 +299,6 @@ return $phpgw->translation->translate($key); } - } /**************************************************************************\ * Our API class ends here * @@ -309,7 +307,7 @@ * Direct functions, which are not part of the API class * * for whatever reason. * \**************************************************************************/ - + function lang($key, $m1="", $m2="", $m3="", $m4="", $m5="", $m6="", $m7="", $m8="", $m9="", $m10="" ) { global $phpgw; diff --git a/phpgwapi/inc/phpgw_accounts_shared.inc.php b/phpgwapi/inc/phpgw_accounts_shared.inc.php index 6b9bee2f7b..be782f89e4 100644 --- a/phpgwapi/inc/phpgw_accounts_shared.inc.php +++ b/phpgwapi/inc/phpgw_accounts_shared.inc.php @@ -264,11 +264,10 @@ $db = $phpgw->db; $db->lock(array("preferences")); - $db->query("SELECT * FROM preferences WHERE preference_owner=".$id); + $db->query("SELECT * FROM preferences WHERE preference_owner='$id'",__LINE__,__FILE__); if($db->num_rows()) { - $db->query("UPDATE preferences SET preference_value = '" - . serialize($phpgw_newuser["user"]["preferences"]) - . "' WHERE preference_owner=".$id,__LINE__,__FILE__); + $db->query("UPDATE preferences SET preference_value = '". serialize($phpgw_newuser["user"]["preferences"]) + . "' WHERE preference_owner=".$id,__LINE__,__FILE__); } else { $db->query("insert into preferences (preference_owner,preference_value) values (" . $id.",'".serialize($phpgw_newuser["user"]["preferences"])."')",__LINE__,__FILE__);