useradmin pages rewrite started

This commit is contained in:
Lars Kneschke 2001-02-11 03:07:43 +00:00
parent 68efb23f14
commit 6b787678ea
5 changed files with 207 additions and 116 deletions

View File

@ -8,17 +8,119 @@
* Free Software Foundation; either version 2 of the License, or (at your * * Free Software Foundation; either version 2 of the License, or (at your *
* option) any later version. * * 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(); $t->set_var("form_action",$phpgw->link("editaccount.php","account_id=".$userData["account_id"]));
$phpgw_info["flags"] = array("noheader" => True,
"nonavbar" => True, $t->set_var("th_bg",$phpgw_info["theme"]["th_bg"]);
"currentapp" => "admin", $t->set_var("tr_color1",$phpgw_info["theme"]["row_on"]);
"parent_page" => "accounts.php"); $t->set_var("tr_color2",$phpgw_info["theme"]["row_off"]);
include("../header.inc.php");
include($phpgw_info["server"]["app_inc"]."/accounts_".$phpgw_info["server"]["account_repository"].".inc.php"); $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) function is_odd($n)
{ {
$ln = substr($n,-1); $ln = substr($n,-1);
@ -188,63 +290,61 @@
} // if $submit } // if $submit
$phpgw->common->phpgw_header();
echo parse_navbar();
$phpgw->template->set_file(array("form" => "account_form.tpl"));
if ($totalerrors) { if ($totalerrors) {
$phpgw->template->set_var("error_messages","<center>" . $phpgw->common->error_list($error) . "</center>"); $t->set_var("error_messages","<center>" . $phpgw->common->error_list($error) . "</center>");
} else { } else {
$phpgw->template->set_var("error_messages",""); $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) { $t->set_var("lang_password",lang("Password"));
$n_loginid = $userData["account_lid"]; $t->set_var("n_passwd_value",$n_passwd);
$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();
}
if ($phpgw_info["server"]["account_repository"] == "ldap") { $t->set_var("lang_reenter_password",lang("Re-Enter Password"));
$phpgw->template->set_var("form_action",$phpgw->link("editaccount.php","account_id=" . rawurlencode($userData["account_dn"]) . "&old_loginid=" . $userData["account_lid"])); $t->set_var("n_passwd_2_value",$n_passwd_2);
} 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("th_bg",$phpgw_info["theme"]["th_bg"]); $t->set_var("lang_firstname",lang("First Name"));
$phpgw->template->set_var("tr_color1",$phpgw_info["theme"]["row_on"]); $t->set_var("n_firstname_value",$n_firstname);
$phpgw->template->set_var("tr_color2",$phpgw_info["theme"]["row_off"]);
$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")); $t->set_var("lang_groups",lang("Groups"));
$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"));
$user_groups = $phpgw->accounts->read_group_names($userData["account_lid"]); $user_groups = $phpgw->accounts->read_group_names($userData["account_lid"]);
$groups_select = '<select name="n_groups[]" multiple>'; $groups_select = '<select name="n_groups[]" multiple>';
@ -259,7 +359,7 @@
$groups_select .= ">" . $phpgw->db->f("group_name") . "</option>\n"; $groups_select .= ">" . $phpgw->db->f("group_name") . "</option>\n";
} }
$groups_select .= "</select>"; $groups_select .= "</select>";
$phpgw->template->set_var("groups_select",$groups_select); $t->set_var("groups_select",$groups_select);
$i = 0; $i = 0;
$sorted_apps = $phpgw_info["apps"]; $sorted_apps = $phpgw_info["apps"];
@ -300,7 +400,7 @@
$i++; $i++;
} }
$phpgw->template->set_var("permissions_list",$perm_html); $t->set_var("permissions_list",$perm_html);
$apps->account_apps = Array(Array()); $apps->account_apps = Array(Array());
@ -331,7 +431,7 @@
$apps_after[$new_user_app[0]] = $new_app_user[$new_user_app[0]]; $apps_after[$new_user_app[0]] = $new_app_user[$new_user_app[0]];
} }
} }
*/
$includedSomething = False; $includedSomething = False;
// start inlcuding other admin tools // start inlcuding other admin tools
while($app = each($apps_after)) while($app = each($apps_after))
@ -340,10 +440,10 @@
// {gui_hooks} to "" // {gui_hooks} to ""
if ($phpgw->common->hook_single('show_user_data', $app[0])) $includedSomething=True; 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')); $t->set_var("lang_button",lang('Save'));
$phpgw->template->pparse('out','form'); $t->pparse('out','form');
account_close(); account_close();
$phpgw->common->phpgw_footer(); $phpgw->common->phpgw_footer();

View File

@ -108,7 +108,8 @@
for ($i=0, $j=0; $i<$info["count"]; $i++,$j++) { for ($i=0, $j=0; $i<$info["count"]; $i++,$j++) {
if (! $phpgw_info["server"]["global_denied_users"][$info[$i]["uid"][0]]) { 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_lid"] = $info[$i]["uid"][0];
$account_info[$i]["account_lastname"] = $info[$i]["sn"][0]; $account_info[$i]["account_lastname"] = $info[$i]["sn"][0];
$account_info[$i]["account_firstname"] = $info[$i]["givenname"][0]; $account_info[$i]["account_firstname"] = $info[$i]["givenname"][0];

View File

@ -10,17 +10,17 @@
<tr bgcolor="{tr_color1}"> <tr bgcolor="{tr_color1}">
<td>{lang_loginid}</td> <td>{lang_loginid}</td>
<td><input name="n_loginid" value="{n_loginid_value}"></td> <td><input name="account_lid" value="{n_loginid_value}"></td>
<td colspan="2" align="center"> <td colspan="2" align="center">
{lang_account_active}:&nbsp;<input type="checkbox" name="n_account_status" value="A" {account_checked}> {lang_account_active}:&nbsp;<input type="checkbox" name="status" value="A" {account_checked}>
</td> </td>
</tr> </tr>
<tr bgcolor="{tr_color2}"> <tr bgcolor="{tr_color2}">
<td>{lang_firstname}</td> <td>{lang_firstname}</td>
<td><input name="n_firstname" value="{n_firstname_value}"></td> <td><input name="firstname" value="{n_firstname_value}"></td>
<td>{lang_lastname}</td> <td>{lang_lastname}</td>
<td><input name="n_lastname" value="{n_lastname_value}"></td> <td><input name="lastname" value="{n_lastname_value}"></td>
</tr> </tr>
<tr bgcolor="{tr_color1}"> <tr bgcolor="{tr_color1}">

View File

@ -41,59 +41,49 @@
function read_repository() function read_repository()
{ {
global $phpgw, $phpgw_info; global $phpgw, $phpgw_info;
// get a ldap connection handle // get a ldap connection handle
$ds = $phpgw->common->ldapConnect(); $ds = $phpgw->common->ldapConnect();
// search the dn for the given uid // search the dn for the given uid
$sri = ldap_search($ds, $phpgw_info["server"]["ldap_context"], "uid=".$this->account_id); $sri = ldap_search($ds, $phpgw_info["server"]["ldap_context"], "uidnumber=".$this->account_id);
$allValues = ldap_get_entries($ds, $sri); $allValues = ldap_get_entries($ds, $sri);
/* Now dump it into the array; take first entry found */ /* Now dump it into the array; take first entry found */
$this->data["account_id"] = $allValues[0]["uidnumber"][0]; $this->data["account_id"] = $allValues[0]["uidnumber"][0];
$this->data["account_lid"] = $allValues[0]["uid"][0]; $this->data["account_lid"] = $allValues[0]["uid"][0];
$this->data["account_dn"] = $allValues[0]["dn"]; $this->data["account_dn"] = $allValues[0]["dn"];
$this->data["firstname"] = $allValues[0]["givenname"][0]; $this->data["firstname"] = $allValues[0]["givenname"][0];
$this->data["lastname"] = $allValues[0]["sn"][0]; $this->data["lastname"] = $allValues[0]["sn"][0];
$this->data["fullname"] = $allValues[0]["cn"][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->query("select * from phpgw_accounts where account_id='" . $this->data["account_id"] . "'",__LINE__,__FILE__);
$this->db->next_record(); $this->db->next_record();
$this->data["lastlogin"] = $this->db->f("account_lastlogin"); $this->data["lastlogin"] = $this->db->f("account_lastlogin");
$this->data["lastloginfrom"] = $this->db->f("account_lastloginfrom"); $this->data["lastloginfrom"] = $this->db->f("account_lastloginfrom");
$this->data["lastpasswd_change"] = $this->db->f("account_lastpwd_change"); $this->data["lastpasswd_change"] = $this->db->f("account_lastpwd_change");
$this->data["status"] = $this->db->f("account_status"); $this->data["status"] = $this->db->f("account_status");
return $this->data; return $this->data;
} }
function save_repository() function save_repository()
{ {
global $phpgw_info, $phpgw; global $phpgw_info, $phpgw;
/* ********This sets the server variables from the database******** */ $ds = $phpgw->common->ldapConnect();
/* $db->query("select * from phpgw_config",__LINE__,__FILE__);
while ($db->next_record()) {
$phpgw_info["server"][$db->f("config_name")] = $db->f("config_value");
}
$phpgw_info_temp["user"] = $phpgw_info["user"]; // search the dn for the given uid
$phpgw_info_temp["apps"] = $phpgw_info["apps"]; $sri = ldap_search($ds, $phpgw_info["server"]["ldap_context"], "uidnumber=".$this->account_id);
$phpgw_info_temp["server"] = $phpgw_info["server"]; $allValues = ldap_get_entries($ds, $sri);
$phpgw_info_temp["hooks"] = $phpgw->hooks->read();
$phpgw_info_temp["user"]["preferences"] = $phpgw_info["user"]["preferences"]; $entry["cn"] = sprintf("%s %s", $this->data["firstname"], $this->data["lastname"]);
$phpgw_info_temp["user"]["kp3"] = ""; // We don't want it anywhere in the $entry["sn"] = $this->data["lastname"];
// database for security. $entry["givenname"] = $this->data["firstname"];
if ($PHP_VERSION < "4.0.0") {
$info_string = addslashes($phpgw->crypto->encrypt($phpgw_info_temp)); ldap_modify($ds, $allValues[0]["dn"], $entry);
} 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__);
*/
} }
function add($account_name, $account_type, $first_name, $last_name, $passwd = False) function add($account_name, $account_type, $first_name, $last_name, $passwd = False)

View File

@ -57,7 +57,7 @@
return False; return False;
} }
function change_password($old_passwd, $new_passwd) { function change_password($old_passwd, $new_passwd, $account_id="") {
global $phpgw_info, $phpgw; global $phpgw_info, $phpgw;
$ldap = $phpgw->common->ldapConnect(); $ldap = $phpgw->common->ldapConnect();