edit/new accounts works with new acl/applications and w/o warnings

This commit is contained in:
skeeter 2001-02-02 12:28:39 +00:00
parent 435c1dc721
commit 2bd2c994b7
6 changed files with 187 additions and 72 deletions

View File

@ -60,14 +60,14 @@
} }
if (!count($new_permissions) || !count($n_groups)) { if (!count($new_permissions) || !count($n_groups)) {
$error[$totalerrors++] = "<br>" . lang("You must add at least 1 permission to this account"); $error[$totalerrors++] = "<br>" . lang("You must add at least 1 permission or group to this account");
} }
if (! $totalerrors) { if (! $totalerrors) {
$phpgw->db->lock(array("accounts","preferences","phpgw_sessions","phpgw_acl","applications")); $phpgw->db->lock(array('accounts','preferences','phpgw_sessions','phpgw_acl','applications'));
$phpgw->db->query("SELECT account_id FROM accounts WHERE account_lid='" . $old_loginid . "'",__LINE__,__FILE__); $phpgw->db->query("SELECT account_id FROM accounts WHERE account_lid='" . $old_loginid . "'",__LINE__,__FILE__);
$phpgw->db->next_record(); $phpgw->db->next_record();
$account_id = $phpgw->db->f("account_id"); $account_id = intval($phpgw->db->f("account_id"));
$apps = CreateObject('phpgwapi.applications',array(intval($account_id),'u')); $apps = CreateObject('phpgwapi.applications',array(intval($account_id),'u'));
$apps->read_installed_apps(); $apps->read_installed_apps();
@ -89,12 +89,12 @@
} }
} }
// delete old groups user was associated to // delete old groups user was associated to
$phpgw->acl->delete("phpgw_group",$groups[0],$account_id,'u'); $phpgw->acl->delete('phpgw_group',$groups[0],$account_id,'u');
} }
} }
$apps->account_type = 'u'; $apps->account_type = 'u';
$apps->account_id = intval($account_id); $apps->account_id = $account_id;
$apps->account_apps = Array(Array()); $apps->account_apps = Array(Array());
while($app = each($new_permissions)) { while($app = each($new_permissions)) {
if($app[1]) { if($app[1]) {
@ -106,17 +106,17 @@
} }
$apps->save_apps(); $apps->save_apps();
$cd = account_edit(array("loginid" => $n_loginid, "firstname" => $n_firstname, $cd = account_edit(array('loginid' => $n_loginid, 'firstname' => $n_firstname,
"lastname" => $n_lastname, "passwd" => $n_passwd, 'lastname' => $n_lastname, 'passwd' => $n_passwd,
"account_status" => $n_account_status, "old_loginid" => $old_loginid, 'account_status' => $n_account_status, 'old_loginid' => $old_loginid,
"account_id" => rawurldecode($account_id))); 'account_id' => rawurldecode($account_id)));
// If the user is logged in, it will force a refresh of the session_info // 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__); //$phpgw->db->query("update phpgw_sessions set session_info='' where session_lid='$new_loginid@" . $phpgw_info["user"]["domain"] . "'",__LINE__,__FILE__);
// Add new groups user is associated to // Add new groups user is associated to
for($i=0;$i<count($n_groups);$i++) { for($i=0;$i<count($n_groups);$i++) {
$phpgw->acl->add("phpgw_group",$n_groups[$i],$account_id,'u',1); $phpgw->acl->add('phpgw_group',$n_groups[$i],$account_id,'u',1);
} }
// The following sets any default preferences needed for new applications.. // The following sets any default preferences needed for new applications..
@ -128,13 +128,13 @@
$docommit = False; $docommit = False;
$after_apps = explode(':',$apps_after); $after_apps = explode(':',$apps_after);
for($i=1;$i<count($after_apps) - 1;$i++) { for($i=1;$i<count($after_apps) - 1;$i++) {
if($after_apps[$i]=="admin") { if($after_apps[$i]=='admin') {
$check = "common"; $check = 'common';
} else { } else {
$check = $after_apps[$i]; $check = $after_apps[$i];
} }
if (!$t["$check"]) { if (!$t["$check"]) {
$phpgw->common->hook_single("add_def_pref", $after_apps[$i]); $phpgw->common->hook_single('add_def_pref', $after_apps[$i]);
$docommit = True; $docommit = True;
} }
} }
@ -143,15 +143,45 @@
$pref->commit(); $pref->commit();
} }
$apps->account_apps = Array(Array());
$apps_after = Array(Array());
// Read new Group ID's
$new_groups = $phpgw->accounts->read_groups($account_id);
// Read new Group Apps
if ($new_groups) {
$apps->account_type = 'g';
reset($new_groups);
while($groups = each($new_groups)) {
$apps->account_id = intval($groups[0]);
$new_app_groups = $apps->read_account_specific();
@reset($new_app_groups);
while($new_group_app = each($new_app_groups)) {
if(!$apps_after[$new_group_app[0]]) {
$apps_after[$new_group_app[0]] = $new_app_groups[$new_group_app[0]];
}
}
}
}
$apps->account_type = 'u';
$apps->account_id = $account_id;
$new_app_user = $apps->read_account_specific();
while($new_user_app = each($new_app_user)) {
if(!$apps_after[$new_user_app[0]]) {
$apps_after[$new_user_app[0]] = $new_app_user[$new_user_app[0]];
}
}
// start including other admin tools // start including other admin tools
while(list($key,$value) = each($phpgw_info["user"]["app_perms"])) while($app = each($apps_after))
{ {
$phpgw->common->hook_single("update_user_data", $value); $phpgw->common->hook_single('update_user_data', $app[0]);
} }
$phpgw->db->unlock(); $phpgw->db->unlock();
Header("Location: " . $phpgw->link("accounts.php", "cd=$cd")); Header('Location: ' . $phpgw->link('accounts.php', 'cd='.$cd));
$phpgw->common->phpgw_exit(); $phpgw->common->phpgw_exit();
} }
@ -174,7 +204,8 @@
$n_loginid = $userData["account_lid"]; $n_loginid = $userData["account_lid"];
$n_firstname = $userData["firstname"]; $n_firstname = $userData["firstname"];
$n_lastname = $userData["lastname"]; $n_lastname = $userData["lastname"];
$apps = CreateObject('phpgwapi.applications',intval($userData["account_id"])); $apps = CreateObject('phpgwapi.applications',array(intval($userData["account_id"]),'u'));
$apps->read_installed_apps();
$db_perms = $apps->read_account_specific(); $db_perms = $apps->read_account_specific();
} }
@ -241,6 +272,7 @@
} }
} }
@reset($db_perms);
for ($i=0;$i<200;) { // The $i<200 is only used for a brake for ($i=0;$i<200;) { // The $i<200 is only used for a brake
if (! $perm_display[$i][1]) break; if (! $perm_display[$i][1]) break;
$perm_html .= '<tr bgcolor="'.$phpgw_info["theme"]["row_on"].'"><td>' . lang($perm_display[$i][1]) . '</td>' $perm_html .= '<tr bgcolor="'.$phpgw_info["theme"]["row_on"].'"><td>' . lang($perm_display[$i][1]) . '</td>'
@ -269,17 +301,48 @@
$phpgw->template->set_var("permissions_list",$perm_html); $phpgw->template->set_var("permissions_list",$perm_html);
$apps->account_apps = Array(Array());
// Read new Group ID's
$new_groups = $phpgw->accounts->read_groups($account_id);
$apps_after = Array(Array());
// Read new Group Apps
if ($new_groups) {
$apps->account_type = 'g';
reset($new_groups);
while($groups = each($new_groups)) {
$apps->account_id = intval($groups[0]);
$new_app_groups = $apps->read_account_specific();
@reset($new_app_groups);
while($new_group_app = each($new_app_groups)) {
if(!$apps_after[$new_group_app[0]]) {
$apps_after[$new_group_app[0]] = $new_app_groups[$new_group_app[0]];
}
}
}
}
$apps->account_type = 'u';
$apps->account_id = intval($userData["account_id"]);
$new_app_user = $apps->read_account_specific();
while($new_user_app = each($new_app_user)) {
if(!$apps_after[$new_user_app[0]]) {
$apps_after[$new_user_app[0]] = $new_app_user[$new_user_app[0]];
}
}
$includedSomething = False;
// start inlcuding other admin tools // start inlcuding other admin tools
while(list($key,$value) = each($phpgw_info["user"]["app_perms"])) while($app = each($apps_after))
{ {
// check if we have something included, when not ne need to set // check if we have something included, when not ne need to set
// {gui_hooks} to "" // {gui_hooks} to ""
if ($phpgw->common->hook_single("show_user_data", $value)) $includedSomething="true"; if ($phpgw->common->hook_single('show_user_data', $app[0])) $includedSomething=True;
} }
if (!$includedSomething) $phpgw->template->set_var("gui_hooks",""); if (!$includedSomething) $phpgw->template->set_var('gui_hooks','');
$phpgw->template->set_var("lang_button",lang("Save")); $phpgw->template->set_var("lang_button",lang('Save'));
$phpgw->template->pparse("out","form"); $phpgw->template->pparse('out','form');
account_close(); account_close();
$phpgw->common->phpgw_footer(); $phpgw->common->phpgw_footer();

View File

@ -182,22 +182,13 @@
@ldap_close($ldap); @ldap_close($ldap);
$phpgw->db->lock(array("accounts"));
$sql = "insert into accounts (account_id,account_lid,account_pwd,account_firstname," $sql = "insert into accounts (account_id,account_lid,account_pwd,account_firstname,"
. "account_lastname,account_groups,account_status,account_lastpwd_change) " . "account_lastname,account_status,account_lastpwd_change) "
. "values ('" . $account_info["account_id"] . "','" . $account_info["loginid"] . "values ('" . $account_info["account_id"] . "','" . $account_info["loginid"]
. "','x','". addslashes($account_info["firstname"]) . "','" . "','x','". addslashes($account_info["firstname"]) . "','"
. addslashes($account_info["lastname"]) . "'," . addslashes($account_info["lastname"]) . "','A',0)";
. "'" . $phpgw->accounts->groups_array_to_string($account_info["groups"]) . "','A',0)";
$phpgw->db->query($sql,__LINE__,__FILE__); $phpgw->db->query($sql,__LINE__,__FILE__);
$phpgw->db->unlock();
$apps = CreateObject('phpgwapi.applications',$account_info["account_id"]);
$apps->add_user($account_info["permissions"]);
$apps->save_user();
$sep = $phpgw->common->filesystem_separator(); $sep = $phpgw->common->filesystem_separator();

View File

@ -69,20 +69,13 @@
{ {
global $phpgw, $phpgw_info; global $phpgw, $phpgw_info;
$phpgw->db->lock(array("accounts","preferences"));
$sql = "insert into accounts (account_lid,account_pwd,account_firstname,account_lastname," $sql = "insert into accounts (account_lid,account_pwd,account_firstname,account_lastname,"
. "account_groups,account_status,account_lastpwd_change) values ('" . "account_status,account_lastpwd_change) values ('"
. $account_info["loginid"] . "','" . md5($account_info["passwd"]) . "','" . $account_info["loginid"] . "','" . md5($account_info["passwd"]) . "','"
. addslashes($account_info["firstname"]) . "','". addslashes($account_info["lastname"]) . addslashes($account_info["firstname"]) . "','". addslashes($account_info["lastname"])
. "','" . $phpgw->accounts->groups_array_to_string($account_info["groups"]) . "','A',0)"; . "','A',0)";
$phpgw->db->query($sql,__LINE__,__FILE__); $phpgw->db->query($sql,__LINE__,__FILE__);
$phpgw->db->unlock();
$apps = CreateObject('phpgwapi.applications',$account_info["loginid"]);
$apps->add_user($account_info["permissions"]);
$apps->save_user();
$sep = $phpgw->common->filesystem_separator(); $sep = $phpgw->common->filesystem_separator();

View File

@ -48,40 +48,106 @@
if ($n_passwd != $n_passwd_2) if ($n_passwd != $n_passwd_2)
$error[$totalerrors++] = lang("The two passwords are not the same"); $error[$totalerrors++] = lang("The two passwords are not the same");
if (count($new_permissions) == 0) if (!count($new_permissions) || !count($n_groups)) {
$error[$totalerrors++] = lang("You must add at least 1 permission to this account"); $error[$totalerrors++] = "<br>" . lang("You must add at least 1 permission or group to this account");
}
if (count($n_groups) == 0)
$error[$totalerrors++] = lang("Account must belong to at least 1 group");
if (account_exsists($n_loginid)) { if (account_exsists($n_loginid)) {
$error[$totalerrors++] = lang("That loginid has already been taken"); $error[$totalerrors++] = lang("That loginid has already been taken");
} }
if (! $error) { if (! $error) {
$cd = account_add(array("loginid" => $n_loginid, "permissions" => $new_permissions, $phpgw->db->lock(array("accounts","preferences","phpgw_sessions","phpgw_acl","applications"));
"firstname" => $n_firstname, "lastname" => $n_lastname,
"passwd" => $n_passwd, "groups" => $n_groups)); $cd = account_add(array("loginid" => $n_loginid, "firstname" => $n_firstname,
"lastname" => $n_lastname, "passwd" => $n_passwd));
$phpgw->db->query("SELECT account_id FROM accounts WHERE account_lid='$n_loginid'",__LINE__,__FILE__); $phpgw->db->query("SELECT account_id FROM accounts WHERE account_lid='$n_loginid'",__LINE__,__FILE__);
$phpgw->db->next_record(); $phpgw->db->next_record();
$pref = CreateObject('phpgwapi.preferences',intval($phpgw->db->f("account_id"))); $account_id = intval($phpgw->db->f("account_id"));
$apps_object = CreateObject('phpgwapi.applications',intval($phpgw->db->f("account_id"))); $apps = CreateObject('phpgwapi.applications',array($account_id,'u'));
$apps_array = $apps_object->apps_enabled(); $apps->read_installed_apps();
// Read Group Apps
if ($n_groups) {
$apps->account_type = 'g';
reset($n_groups);
while($groups = each($n_groups)) {
$apps->account_id = $groups[0];
$old_app_groups = $apps->read_account_specific();
@reset($old_app_groups);
while($old_group_app = each($old_app_groups)) {
if(!$apps_after[$old_group_app[0]]) {
$apps_after[$old_group_app[0]] = $old_app_groups[$old_group_app[0]];
}
}
}
}
$apps->account_type = 'u';
$apps->account_id = $account_id;
$apps->account_apps = Array(Array());
@reset($new_permissions);
while($app = each($new_permissions)) {
if($app[1]) {
$apps->add_app($app[0]);
if(!$apps_after[$app[0]]) {
$apps_after[] = $app[0];
}
}
}
$apps->save_apps();
// Assign user to groups
for($i=0;$i<count($n_groups);$i++) {
$phpgw->acl->add("phpgw_group",$n_groups[$i],$account_id,'u',1);
}
$pref = CreateObject('phpgwapi.preferences',$account_id);
$phpgw->common->hook_single("add_def_pref", "admin"); $phpgw->common->hook_single("add_def_pref", "admin");
while($apps = each($apps_array)) { while($apps = each($apps_after)) {
if($apps[0]<>"admin") if($apps[0]<>"admin")
$phpgw->common->hook_single("add_def_pref", $apps[0]); $phpgw->common->hook_single("add_def_pref", $apps[0]);
} }
$pref->commit(); $pref->commit();
// start inlcuding other admin tools $apps->account_apps = Array(Array());
while(list($key,$value) = each($phpgw_info["user"]["app_perms"])) $apps_after = Array(Array());
{
$phpgw->common->hook_single("add_user_data", $value); // Read new Group ID's
$new_groups = $phpgw->accounts->read_groups($account_id);
// Read new Group Apps
if ($new_groups) {
$apps->account_type = 'g';
reset($new_groups);
while($groups = each($new_groups)) {
$apps->account_id = intval($groups[0]);
$new_app_groups = $apps->read_account_specific();
@reset($new_app_groups);
while($new_group_app = each($new_app_groups)) {
if(!$apps_after[$new_group_app[0]]) {
$apps_after[$new_group_app[0]] = $new_app_groups[$new_group_app[0]];
}
}
}
} }
Header("Location: " . $phpgw->link("accounts.php","cd=$cd")); $apps->account_type = 'u';
$apps->account_id = $account_id;
$new_app_user = $apps->read_account_specific();
while($new_user_app = each($new_app_user)) {
if(!$apps_after[$new_user_app[0]]) {
$apps_after[$new_user_app[0]] = $new_app_user[$new_user_app[0]];
}
}
// start inlcuding other admin tools
while($app = each($apps_after))
{
$phpgw->common->hook_single('add_user_data', $value);
}
Header('Location: ' . $phpgw->link('accounts.php','cd='.$cd));
$phpgw->common->phpgw_exit(); $phpgw->common->phpgw_exit();
} }
} }
@ -178,13 +244,16 @@
} }
$phpgw->template->set_var("permissions_list",$perms_html); $phpgw->template->set_var("permissions_list",$perms_html);
$includedSomething = False;
// Skeeter: I don't see this as a player, if creating new accounts...
// start inlcuding other admin tools // start inlcuding other admin tools
while(list($key,$value) = each($phpgw_info["user"]["app_perms"])) // while(list($key,$value) = each($phpgw_info["user"]["app_perms"]))
{ // {
// check if we have something included, when not ne need to set // check if we have something included, when not ne need to set
// {gui_hooks} to "" // {gui_hooks} to ""
if ($phpgw->common->hook_single("show_newuser_data", $value)) $includedSomething="true"; // if ($phpgw->common->hook_single("show_newuser_data", $value)) $includedSomething="true";
} // }
if (!$includedSomething) $phpgw->template->set_var("gui_hooks",""); if (!$includedSomething) $phpgw->template->set_var("gui_hooks","");
$phpgw->template->set_var("lang_button",Lang("Add")); $phpgw->template->set_var("lang_button",Lang("Add"));

View File

@ -99,7 +99,6 @@
$this->db->query($sql ,__LINE__,__FILE__); $this->db->query($sql ,__LINE__,__FILE__);
$rights = 0; $rights = 0;
if ($this->db->num_rows() == 0 && $phpgw_info["server"]["acl_default"] != "deny"){ if ($this->db->num_rows() == 0 && $phpgw_info["server"]["acl_default"] != "deny"){
// echo "rows: ".$this->db->num_rows()."<br>";
return True; return True;
} }
while ($this->db->next_record()) { while ($this->db->next_record()) {
@ -112,6 +111,7 @@
function check_specific($location, $required, $appname = False, $id = "", $id_type = "u"){ function check_specific($location, $required, $appname = False, $id = "", $id_type = "u"){
global $phpgw, $phpgw_info; global $phpgw, $phpgw_info;
$rights = $this->get_specific_rights($location,$appname, $id, $id_type); $rights = $this->get_specific_rights($location,$appname, $id, $id_type);
return !!($rights & $required); return !!($rights & $required);
} }

View File

@ -54,7 +54,6 @@
$this->account_id = $phpgw_info["user"]["account_id"]; $this->account_id = $phpgw_info["user"]["account_id"];
$this->account_type = "u"; $this->account_type = "u";
} }
//echo "Account ID (Initializing applications) = ".$this->account_id."<br>\n";
} }
function enabled_apps() function enabled_apps()