diff --git a/admin/editaccount.php b/admin/editaccount.php index adc237ef0b..7ae2769ef4 100755 --- a/admin/editaccount.php +++ b/admin/editaccount.php @@ -8,17 +8,119 @@ * 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, + "currentapp" => "admin", + "parent_page" => "accounts.php" + ); + + include("../header.inc.php"); + include($phpgw_info["server"]["app_inc"]."/accounts_".$phpgw_info["server"]["account_repository"].".inc.php"); + + // creates the html for the user data + function createPageBody($account_id) + { + global $phpgw,$phpgw_info; + + $t = new Template($phpgw->common->get_tpl_dir("admin")); + $t->set_file(array("form" => "account_form.tpl")); - /* $Id$ */ + $account = CreateObject('phpgwapi.accounts',$account_id); + + $userData = $account->read_repository($account_id); - $phpgw_info = array(); - $phpgw_info["flags"] = array("noheader" => True, - "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"); + $t->set_var("form_action",$phpgw->link("editaccount.php","account_id=".$userData["account_id"])); + + $t->set_var("th_bg",$phpgw_info["theme"]["th_bg"]); + $t->set_var("tr_color1",$phpgw_info["theme"]["row_on"]); + $t->set_var("tr_color2",$phpgw_info["theme"]["row_off"]); + + $t->set_var("lang_action",lang("Edit user account")); + $t->set_var("lang_loginid",lang("LoginID")); + $t->set_var("lang_account_active",lang("Account active")); + $t->set_var("lang_password",lang("Password")); + $t->set_var("lang_reenter_password",lang("Re-Enter Password")); + $t->set_var("lang_lastname",lang("Last Name")); + $t->set_var("lang_groups",lang("Groups")); + $t->set_var("lang_firstname",lang("First Name")); + $t->set_var("lang_button",lang('Save')); + $t->set_var("n_loginid_value",$userData["account_lid"]); + $t->set_var("n_passwd_value",$n_passwd); + $t->set_var("n_passwd_2_value",$n_passwd_2); + + if ($userData["status"]) + { + $t->set_var("account_checked","checked"); + } + else + { + $t->set_var("account_checked",""); + } + $t->set_var("n_firstname_value",$userData["firstname"]); + $t->set_var("n_lastname_value",$userData["lastname"]); + + $t->pparse('out','form'); + } + + // stores the userdata + function saveUserData($_userData) + { + $account = CreateObject('phpgwapi.accounts',$_userData['account_id']); + $account->update_data($_userData); + $account->save_repository(); + if ($_userData['passwd']) + { + $auth = CreateObject('phpgwapi.auth'); +# $auth->change_password($old_passwd, $_userData['passwd']); + } + } + + // checks if the userdata are valid + function userDataValid($_userData) + { + return TRUE; + } + + // todo + // not needed if i use the same file for new users too + if (! $account_id) { + Header("Location: " . $phpgw->link("accounts.php")); + } + + + if ($submit) + { + $userData = array( + 'account_lid' => $account_lid, 'firstname' => $firstname, + 'lastname' => $lastname, 'passwd' => $n_passwd, + 'status' => $status, 'old_loginid' => $old_loginid, + 'account_id' => $account_id + ); + + if (userDataValid($userData)) + { + saveUserData($userData); + Header('Location: ' . $phpgw->link('accounts.php', 'cd='.$cd)); + $phpgw->common->phpgw_exit(); + } + } + else + { + $phpgw->common->phpgw_header(); + echo parse_navbar(); + + createPageBody($account_id); + + account_close(); + $phpgw->common->phpgw_footer(); + } + + return; + function is_odd($n) { $ln = substr($n,-1); @@ -188,63 +290,61 @@ } // if $submit - $phpgw->common->phpgw_header(); - echo parse_navbar(); - - $phpgw->template->set_file(array("form" => "account_form.tpl")); - if ($totalerrors) { - $phpgw->template->set_var("error_messages","
" . $phpgw->common->error_list($error) . "
"); - } else { - $phpgw->template->set_var("error_messages",""); - } + if ($totalerrors) { + $t->set_var("error_messages","
" . $phpgw->common->error_list($error) . "
"); + } else { + $t->set_var("error_messages",""); + } - $userData = $phpgw->accounts->read_userData($account_id); + $userData = $phpgw->accounts->read_repository($account_id); + + if (! $submit) { + print $n_loginid = $userData["account_lid"]; + print $n_firstname = $userData["firstname"]; + print $n_lastname = $userData["lastname"]; + $apps = CreateObject('phpgwapi.applications',array(intval($userData["account_id"]),'u')); + $apps->read_installed_apps(); + /* $db_perms = $apps->read_account_specific(); */ + } + + if ($phpgw_info["server"]["account_repository"] == "ldap") { + $t->set_var("form_action",$phpgw->link("editaccount.php","account_id=" . rawurlencode($userData["account_dn"]) . "&old_loginid=" . $userData["account_lid"])); + } else { + $t->set_var("form_action",$phpgw->link("editaccount.php","account_id=" . $userData["account_id"] . "&old_loginid=" . $userData["account_lid"])); + } + + $t->set_var("th_bg",$phpgw_info["theme"]["th_bg"]); + $t->set_var("tr_color1",$phpgw_info["theme"]["row_on"]); + $t->set_var("tr_color2",$phpgw_info["theme"]["row_off"]); + + $t->set_var("lang_action",lang("Edit user account")); + + $t->set_var("lang_loginid",lang("LoginID")); + $t->set_var("n_loginid_value",$n_loginid); + + $t->set_var("lang_account_active",lang("Account active")); + + if ($userData["status"]) { + $t->set_var("account_checked","checked"); + } else { + $t->set_var("account_checked",""); + } - if (! $submit) { - $n_loginid = $userData["account_lid"]; - $n_firstname = $userData["firstname"]; - $n_lastname = $userData["lastname"]; - $apps = CreateObject('phpgwapi.applications',array(intval($userData["account_id"]),'u')); - $apps->read_installed_apps(); - $db_perms = $apps->read_account_specific(); - } + $t->set_var("lang_password",lang("Password")); + $t->set_var("n_passwd_value",$n_passwd); - 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"])); - } else { - $phpgw->template->set_var("form_action",$phpgw->link("editaccount.php","account_id=" . $userData["account_id"] . "&old_loginid=" . $userData["account_lid"])); - } + $t->set_var("lang_reenter_password",lang("Re-Enter Password")); + $t->set_var("n_passwd_2_value",$n_passwd_2); - $phpgw->template->set_var("th_bg",$phpgw_info["theme"]["th_bg"]); - $phpgw->template->set_var("tr_color1",$phpgw_info["theme"]["row_on"]); - $phpgw->template->set_var("tr_color2",$phpgw_info["theme"]["row_off"]); + $t->set_var("lang_firstname",lang("First Name")); + $t->set_var("n_firstname_value",$n_firstname); - $phpgw->template->set_var("lang_action",lang("Edit user account")); + $t->set_var("lang_lastname",lang("Last Name")); + $t->set_var("n_lastname_value",$n_lastname); - $phpgw->template->set_var("lang_loginid",lang("LoginID")); - $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",""); - } - - $phpgw->template->set_var("lang_password",lang("Password")); - $phpgw->template->set_var("n_passwd_value",$n_passwd); - - $phpgw->template->set_var("lang_reenter_password",lang("Re-Enter Password")); - $phpgw->template->set_var("n_passwd_2_value",$n_passwd_2); - - $phpgw->template->set_var("lang_firstname",lang("First Name")); - $phpgw->template->set_var("n_firstname_value",$n_firstname); - - $phpgw->template->set_var("lang_lastname",lang("Last Name")); - $phpgw->template->set_var("n_lastname_value",$n_lastname); - - $phpgw->template->set_var("lang_groups",lang("Groups")); + $t->set_var("lang_groups",lang("Groups")); +/* $user_groups = $phpgw->accounts->read_group_names($userData["account_lid"]); $groups_select = '"; - $phpgw->template->set_var("groups_select",$groups_select); + $t->set_var("groups_select",$groups_select); $i = 0; $sorted_apps = $phpgw_info["apps"]; @@ -300,7 +400,7 @@ $i++; } - $phpgw->template->set_var("permissions_list",$perm_html); + $t->set_var("permissions_list",$perm_html); $apps->account_apps = Array(Array()); @@ -331,7 +431,7 @@ $apps_after[$new_user_app[0]] = $new_app_user[$new_user_app[0]]; } } - +*/ $includedSomething = False; // start inlcuding other admin tools while($app = each($apps_after)) @@ -340,10 +440,10 @@ // {gui_hooks} to "" if ($phpgw->common->hook_single('show_user_data', $app[0])) $includedSomething=True; } - if (!$includedSomething) $phpgw->template->set_var('gui_hooks',''); + if (!$includedSomething) $t->set_var('gui_hooks',''); - $phpgw->template->set_var("lang_button",lang('Save')); - $phpgw->template->pparse('out','form'); + $t->set_var("lang_button",lang('Save')); + $t->pparse('out','form'); account_close(); $phpgw->common->phpgw_footer(); diff --git a/admin/inc/accounts_ldap.inc.php b/admin/inc/accounts_ldap.inc.php index 46dbde08b3..9862b7cf50 100644 --- a/admin/inc/accounts_ldap.inc.php +++ b/admin/inc/accounts_ldap.inc.php @@ -108,7 +108,8 @@ for ($i=0, $j=0; $i<$info["count"]; $i++,$j++) { if (! $phpgw_info["server"]["global_denied_users"][$info[$i]["uid"][0]]) { - $account_info[$i]["account_id"] = rawurlencode($info[$i]["dn"]); +# $account_info[$i]["account_id"] = rawurlencode($info[$i]["dn"]); + $account_info[$i]["account_id"] = $info[$i]["uidnumber"][0]; $account_info[$i]["account_lid"] = $info[$i]["uid"][0]; $account_info[$i]["account_lastname"] = $info[$i]["sn"][0]; $account_info[$i]["account_firstname"] = $info[$i]["givenname"][0]; diff --git a/admin/templates/default/account_form.tpl b/admin/templates/default/account_form.tpl index f5c0ca3bb3..27558caecf 100644 --- a/admin/templates/default/account_form.tpl +++ b/admin/templates/default/account_form.tpl @@ -10,17 +10,17 @@ {lang_loginid} - + - {lang_account_active}:  + {lang_account_active}:  {lang_firstname} - + {lang_lastname} - + diff --git a/phpgwapi/inc/class.accounts_ldap.inc.php b/phpgwapi/inc/class.accounts_ldap.inc.php index 86206f2c7d..48b7d35b06 100644 --- a/phpgwapi/inc/class.accounts_ldap.inc.php +++ b/phpgwapi/inc/class.accounts_ldap.inc.php @@ -41,59 +41,49 @@ function read_repository() { - global $phpgw, $phpgw_info; - - // get a ldap connection handle - $ds = $phpgw->common->ldapConnect(); - - // search the dn for the given uid - $sri = ldap_search($ds, $phpgw_info["server"]["ldap_context"], "uid=".$this->account_id); - $allValues = ldap_get_entries($ds, $sri); - - /* Now dump it into the array; take first entry found */ - $this->data["account_id"] = $allValues[0]["uidnumber"][0]; - $this->data["account_lid"] = $allValues[0]["uid"][0]; - $this->data["account_dn"] = $allValues[0]["dn"]; - $this->data["firstname"] = $allValues[0]["givenname"][0]; - $this->data["lastname"] = $allValues[0]["sn"][0]; - $this->data["fullname"] = $allValues[0]["cn"][0]; - - $this->db->query("select * from phpgw_accounts where account_id='" . $this->data["account_id"] . "'",__LINE__,__FILE__); - $this->db->next_record(); - - $this->data["lastlogin"] = $this->db->f("account_lastlogin"); - $this->data["lastloginfrom"] = $this->db->f("account_lastloginfrom"); - $this->data["lastpasswd_change"] = $this->db->f("account_lastpwd_change"); - $this->data["status"] = $this->db->f("account_status"); - - return $this->data; + global $phpgw, $phpgw_info; + + // get a ldap connection handle + $ds = $phpgw->common->ldapConnect(); + + // search the dn for the given uid + $sri = ldap_search($ds, $phpgw_info["server"]["ldap_context"], "uidnumber=".$this->account_id); + $allValues = ldap_get_entries($ds, $sri); + + /* Now dump it into the array; take first entry found */ + $this->data["account_id"] = $allValues[0]["uidnumber"][0]; + $this->data["account_lid"] = $allValues[0]["uid"][0]; + $this->data["account_dn"] = $allValues[0]["dn"]; + $this->data["firstname"] = $allValues[0]["givenname"][0]; + $this->data["lastname"] = $allValues[0]["sn"][0]; + $this->data["fullname"] = $allValues[0]["cn"][0]; + + $this->db->query("select * from phpgw_accounts where account_id='" . $this->data["account_id"] . "'",__LINE__,__FILE__); + $this->db->next_record(); + + $this->data["lastlogin"] = $this->db->f("account_lastlogin"); + $this->data["lastloginfrom"] = $this->db->f("account_lastloginfrom"); + $this->data["lastpasswd_change"] = $this->db->f("account_lastpwd_change"); + $this->data["status"] = $this->db->f("account_status"); + + return $this->data; } function save_repository() { global $phpgw_info, $phpgw; - /* ********This sets the server variables from the database******** */ -/* $db->query("select * from phpgw_config",__LINE__,__FILE__); - while ($db->next_record()) { - $phpgw_info["server"][$db->f("config_name")] = $db->f("config_value"); - } + $ds = $phpgw->common->ldapConnect(); - $phpgw_info_temp["user"] = $phpgw_info["user"]; - $phpgw_info_temp["apps"] = $phpgw_info["apps"]; - $phpgw_info_temp["server"] = $phpgw_info["server"]; - $phpgw_info_temp["hooks"] = $phpgw->hooks->read(); - $phpgw_info_temp["user"]["preferences"] = $phpgw_info["user"]["preferences"]; - $phpgw_info_temp["user"]["kp3"] = ""; // We don't want it anywhere in the - // database for security. - if ($PHP_VERSION < "4.0.0") { - $info_string = addslashes($phpgw->crypto->encrypt($phpgw_info_temp)); - } else { - $info_string = $phpgw->crypto->encrypt($phpgw_info_temp); - } - $db->query("update phpgw_sessions set session_info='$info_string' where session_id='" - . $phpgw_info["user"]["sessionid"] . "'",__LINE__,__FILE__); -*/ + // search the dn for the given uid + $sri = ldap_search($ds, $phpgw_info["server"]["ldap_context"], "uidnumber=".$this->account_id); + $allValues = ldap_get_entries($ds, $sri); + + $entry["cn"] = sprintf("%s %s", $this->data["firstname"], $this->data["lastname"]); + $entry["sn"] = $this->data["lastname"]; + $entry["givenname"] = $this->data["firstname"]; + + ldap_modify($ds, $allValues[0]["dn"], $entry); } function add($account_name, $account_type, $first_name, $last_name, $passwd = False) diff --git a/phpgwapi/inc/class.auth_ldap.inc.php b/phpgwapi/inc/class.auth_ldap.inc.php index 3232d90a72..48c3d97523 100644 --- a/phpgwapi/inc/class.auth_ldap.inc.php +++ b/phpgwapi/inc/class.auth_ldap.inc.php @@ -57,7 +57,7 @@ return False; } - function change_password($old_passwd, $new_passwd) { + function change_password($old_passwd, $new_passwd, $account_id="") { global $phpgw_info, $phpgw; $ldap = $phpgw->common->ldapConnect();