Started fixing edit account

This commit is contained in:
jengo 2000-12-26 06:30:51 +00:00
parent 7cea5beeb0
commit d30890881a
4 changed files with 96 additions and 90 deletions

View File

@ -13,9 +13,9 @@
$phpgw_info = array(); $phpgw_info = array();
$phpgw_info["flags"] = array("noheader" => True, $phpgw_info["flags"] = array("noheader" => True,
"nonavbar" => True, "nonavbar" => True,
"currentapp" => "admin", "currentapp" => "admin",
"parent_page" => "accounts.php"); "parent_page" => "accounts.php");
include("../header.inc.php"); include("../header.inc.php");
include($phpgw_info["server"]["app_inc"]."/accounts_".$phpgw_info["server"]["account_repository"].".inc.php"); include($phpgw_info["server"]["app_inc"]."/accounts_".$phpgw_info["server"]["account_repository"].".inc.php");
@ -54,61 +54,68 @@
} }
if (! $totalerrors) { if (! $totalerrors) {
$phpgw->db->query("SELECT account_permissions FROM accounts WHERE account_id = ".$account_id); $phpgw->db->query("SELECT account_permissions FROM accounts WHERE account_lid='" . $old_loginid . "'",__LINE__,__FILE__);
$phpgw->db->next_record(); $phpgw->db->next_record();
$apps_before = $phpgw->db->f("account_permissions"); $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)) { $cd = account_edit(array("loginid" => $n_loginid, "permissions" => $new_permissions,
if ($phpgw_info["apps"][$permission[0]]["enabled"]) { "firstname" => $n_firstname, "lastname" => $n_lastname,
$phpgw->accounts->add_app($permission[0]); "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)));
$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, // If the user is logged in, it will force a refresh of the session_info
"firstname" => $n_firstname, "lastname" => $n_lastname, $phpgw->db->query("update phpgw_sessions set session_info='' where session_lid='$new_loginid@" . $phpgw_info["user"]["domain"] . "'",__LINE__,__FILE__);
"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)));
// The following sets any default preferences needed for new applications.. // The following sets any default preferences needed for new applications..
// This is smart enough to know if previous preferences were selected, use them. // This is smart enough to know if previous preferences were selected, use them.
if (count($new_apps)) { if (count($new_apps)) {
if ($account_id <> $phpgw_info["user"]["account_id"]) { $phpgw->db->query("select account_id from accounts where account_lid='$new_loginid'",__LINE__,__FILE__);
$phpgw->db->query("SELECT preference_value FROM preferences WHERE preference_owner=".$account_id,__FILE__,__LINE__); $phpgw->db->next_record();
$phpgw->db->next_record(); $users_account_id = $phpgw->db->f("account_id");
$phpgw_newuser["user"]["preferences"] = unserialize($phpgw->db->f("preference_value"));
} else { if ($account_id <> $phpgw_info["user"]["account_id"]) {
$phpgw_newuser["user"]["preferences"] = $phpgw_info["user"]["preferences"]; $phpgw->db->query("SELECT preference_value FROM preferences WHERE preference_owner='$users_account_id'",__FILE__,__LINE__);
} $phpgw->db->next_record();
$docommit = False; $phpgw_newuser["user"]["preferences"] = unserialize($phpgw->db->f("preference_value"));
for ($j=0;$j<count($new_apps);$j++) { } else {
if (! @$phpgw_newuser["user"]["preferences"][$new_apps[$j]]) { $phpgw_newuser["user"]["preferences"] = $phpgw_info["user"]["preferences"];
$phpgw->common->hook_single("add_def_pref", $new_apps[$j]); }
$docommit = True; $docommit = False;
} for ($j=0;$j<count($new_apps);$j++) {
} if (! @$phpgw_newuser["user"]["preferences"][$new_apps[$j]]) {
if ($docommit) { $phpgw->common->hook_single("add_def_pref", $new_apps[$j]);
if ($account_id <> $phpgw_info["user"]["account_id"]) { $docommit = True;
$phpgw->preferences->commit_user($account_id); }
} else { }
$phpgw_info["user"]["preferences"] = $phpgw_newuser["user"]["preferences"]; if ($docommit) {
unset($phpgw_newuser); if ($account_id <> $phpgw_info["user"]["account_id"]) {
$phpgw->preferences->commit(); $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")); Header("Location: " . $phpgw->link("accounts.php", "cd=$cd"));
$phpgw->common->phpgw_exit(); $phpgw->common->phpgw_exit();
} }
} // if $submit } // if $submit
@ -134,9 +141,9 @@
} }
if ($phpgw_info["server"]["account_repository"] == "ldap") { 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 { } 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"]); $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("n_loginid_value",$n_loginid);
$phpgw->template->set_var("lang_account_active",lang("Account active")); $phpgw->template->set_var("lang_account_active",lang("Account active"));
if ($userData["status"]) if ($userData["status"]) {
$phpgw->template->set_var("account_checked","checked"); $phpgw->template->set_var("account_checked","checked");
else } else {
$phpgw->template->set_var("account_checked",""); $phpgw->template->set_var("account_checked","");
}
$phpgw->template->set_var("lang_password",lang("Password")); $phpgw->template->set_var("lang_password",lang("Password"));
$phpgw->template->set_var("n_passwd_value",$n_passwd); $phpgw->template->set_var("n_passwd_value",$n_passwd);

View File

@ -143,16 +143,16 @@
// Much of this is going to be guess work for now, until we get things planned out. // Much of this is going to be guess work for now, until we get things planned out.
$entry["uid"] = $account_info["loginid"]; $entry["uid"] = $account_info["loginid"];
$entry["uidNumber"] = $account_info["account_id"]; $entry["uidNumber"] = $account_info["account_id"];
$entry["gidNumber"] = $account_info["account_id"]; $entry["gidNumber"] = $account_info["account_id"];
$entry["userpassword"] = $account_info["passwd"]; $entry["userpassword"] = $account_info["passwd"];
$entry["loginShell"] = "/bin/bash"; $entry["loginShell"] = "/bin/bash";
$entry["homeDirectory"] = "/home/" . $account_info["loginid"]; $entry["homeDirectory"] = "/home/" . $account_info["loginid"];
$entry["cn"] = sprintf("%s %s", $account_info["firstname"], $account_info["lastname"]); $entry["cn"] = sprintf("%s %s", $account_info["firstname"], $account_info["lastname"]);
$entry["sn"] = $account_info["lastname"]; $entry["sn"] = $account_info["lastname"];
$entry["givenname"] = $account_info["firstname"]; $entry["givenname"] = $account_info["firstname"];
//$entry["company"] = $company; //$entry["company"] = $company;
//$entry["title"] = $title; //$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["telephonenumber"] = $telephonenumber;
//$entry["homephone"] = $homephone; //$entry["homephone"] = $homephone;
//$entry["pagerphone"] = $pagerphone; //$entry["pagerphone"] = $pagerphone;
@ -197,14 +197,14 @@
. addslashes($account_info["lastname"]) . "','" . $phpgw->accounts->add_app("",True) . addslashes($account_info["lastname"]) . "','" . $phpgw->accounts->add_app("",True)
. "','" . $account_info["groups"] . "','A',0)"; . "','" . $account_info["groups"] . "','A',0)";
$phpgw->db->query($sql); $phpgw->db->query($sql,__LINE__,__FILE__);
$phpgw->db->unlock(); $phpgw->db->unlock();
$sep = $phpgw->common->filesystem_separator(); $sep = $phpgw->common->filesystem_separator();
$basedir = $phpgw_info["server"]["files_dir"] . $sep . "users" . $sep; $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; $cd = 36;
} else { } else {
$cd = 28; $cd = 28;
@ -215,7 +215,7 @@
function account_edit($account_info) 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. // This is just until the API fully handles reading the LDAP account info.
@ -226,10 +226,10 @@
$entry["uid"] = $account_info["loginid"]; $entry["uid"] = $account_info["loginid"];
$entry["homeDirectory"] = "/home/" . $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"] . "' " $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"]) { if ($account_info["passwd"]) {
@ -237,7 +237,7 @@
// Update the sessions table. (The user might be logged in) // Update the sessions table. (The user might be logged in)
$phpgw->db->query("update sessions set session_pwd='" . $phpgw->common->encrypt($n_passwd) . "' " $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"])) { while ($permission = each($account_info["permissions"])) {
@ -256,15 +256,16 @@
$dn = $account_info["account_id"]; $dn = $account_info["account_id"];
@ldap_modify($ldap, $dn, $entry); @ldap_modify($ldap, $dn, $entry);
$phpgw->db->query("update accounts set account_firstname='". $account_info["firstname"] ."', $phpgw->db->query("update accounts set account_firstname='". $account_info["firstname"] ."',"
account_lastname='". $account_info["lastname"] ."', . "account_lastname='". $account_info["lastname"] ."',"
account_permissions='". $phpgw->accounts->add_app("",True) . "', . "account_permissions='". $phpgw->accounts->add_app("",True) . "', "
account_status='". $account_info["account_status"] . "', . "account_status='". $account_info["account_status"] . "', "
account_groups='". $account_info["groups"] . "' . "account_groups='". $account_info["groups"] . "'"
where account_lid='" . $account_info["loginid"]. "'"); . "where account_lid='" . $account_info["loginid"]. "'",__LINE__,__FILE__);
$cd = 27; $cd = 27;
$new_loginid = $account_info["loginid"];
if ($account_info["old_loginid"] != $account_info["loginid"]) { if ($account_info["old_loginid"] != $account_info["loginid"]) {
$sep = $phpgw->common->filesystem_separator(); $sep = $phpgw->common->filesystem_separator();
@ -302,7 +303,7 @@
// set $account_id to uidnumber for sql // set $account_id to uidnumber for sql
$account_id = $allValues[0]["uidnumber"][0]; $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(); $phpgw->db->next_record();
$lid = $phpgw->db->f(0); $lid = $phpgw->db->f(0);
@ -312,10 +313,10 @@
$phpgw->db->lock($table_locks); $phpgw->db->lock($table_locks);
$phpgw->db->query("delete from todo where todo_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."'"); $phpgw->db->query("delete from addressbook where ab_owner='".$account_id."'",__LINE__,__FILE__);
$phpgw->db->query("delete from accounts where account_id='".$account_id."'"); $phpgw->db->query("delete from accounts where account_id='".$account_id."'",__LINE__,__FILE__);
$phpgw->db->query("delete from preferences where preference_owner='".$account_id."'"); $phpgw->db->query("delete from preferences where preference_owner='".$account_id."'",__LINE__,__FILE__);
$phpgw->db->unlock(); $phpgw->db->unlock();

View File

@ -180,7 +180,6 @@
if (empty($phpgw_info["server"]["account_repository"])){$phpgw_info["server"]["account_repository"] = $phpgw_info["server"]["auth_type"];} 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_".$phpgw_info["server"]["account_repository"].".inc.php");
include($phpgw_info["server"]["api_inc"] . "/phpgw_accounts_shared.inc.php"); include($phpgw_info["server"]["api_inc"] . "/phpgw_accounts_shared.inc.php");
$this->auth = new auth; $this->auth = new auth;
$this->session = new sessions; $this->session = new sessions;
}else{ }else{
@ -199,9 +198,9 @@
include($phpgw_info["server"]["api_inc"] . "/phpgw_accounts_shared.inc.php"); include($phpgw_info["server"]["api_inc"] . "/phpgw_accounts_shared.inc.php");
$this->auth = new auth; $this->auth = new auth;
} }
$this->accounts = new accounts;
$this->translation = new translation; $this->translation = new translation;
$this->common = new common; $this->common = new common;
$this->accounts = new accounts;
$this->preferences = new preferences; $this->preferences = new preferences;
$this->acl = new acl; $this->acl = new acl;
$this->hooks = new hooks; $this->hooks = new hooks;
@ -300,7 +299,6 @@
return $phpgw->translation->translate($key); return $phpgw->translation->translate($key);
} }
} }
/**************************************************************************\ /**************************************************************************\
* Our API class ends here * * Our API class ends here *
@ -309,7 +307,7 @@
* Direct functions, which are not part of the API class * * Direct functions, which are not part of the API class *
* for whatever reason. * * for whatever reason. *
\**************************************************************************/ \**************************************************************************/
function lang($key, $m1="", $m2="", $m3="", $m4="", $m5="", $m6="", $m7="", $m8="", $m9="", $m10="" ) function lang($key, $m1="", $m2="", $m3="", $m4="", $m5="", $m6="", $m7="", $m8="", $m9="", $m10="" )
{ {
global $phpgw; global $phpgw;

View File

@ -264,11 +264,10 @@
$db = $phpgw->db; $db = $phpgw->db;
$db->lock(array("preferences")); $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()) { if($db->num_rows()) {
$db->query("UPDATE preferences SET preference_value = '" $db->query("UPDATE preferences SET preference_value = '". serialize($phpgw_newuser["user"]["preferences"])
. serialize($phpgw_newuser["user"]["preferences"]) . "' WHERE preference_owner=".$id,__LINE__,__FILE__);
. "' WHERE preference_owner=".$id,__LINE__,__FILE__);
} else { } else {
$db->query("insert into preferences (preference_owner,preference_value) values (" $db->query("insert into preferences (preference_owner,preference_value) values ("
. $id.",'".serialize($phpgw_newuser["user"]["preferences"])."')",__LINE__,__FILE__); . $id.",'".serialize($phpgw_newuser["user"]["preferences"])."')",__LINE__,__FILE__);