From 2bd2c994b7a060b31f375a677efbe31e5545844d Mon Sep 17 00:00:00 2001 From: skeeter Date: Fri, 2 Feb 2001 12:28:39 +0000 Subject: [PATCH] edit/new accounts works with new acl/applications and w/o warnings --- admin/editaccount.php | 111 +++++++++++++++++----- admin/inc/accounts_ldap.inc.php | 13 +-- admin/inc/accounts_sql.inc.php | 11 +-- admin/newaccount.php | 121 +++++++++++++++++++----- phpgwapi/inc/class.acl.inc.php | 2 +- phpgwapi/inc/class.applications.inc.php | 1 - 6 files changed, 187 insertions(+), 72 deletions(-) diff --git a/admin/editaccount.php b/admin/editaccount.php index a4b6beb6c9..6731aaaa0c 100755 --- a/admin/editaccount.php +++ b/admin/editaccount.php @@ -60,14 +60,14 @@ } if (!count($new_permissions) || !count($n_groups)) { - $error[$totalerrors++] = "
" . lang("You must add at least 1 permission to this account"); + $error[$totalerrors++] = "
" . lang("You must add at least 1 permission or group to this account"); } 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->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->read_installed_apps(); @@ -89,12 +89,12 @@ } } // 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_id = intval($account_id); + $apps->account_id = $account_id; $apps->account_apps = Array(Array()); while($app = each($new_permissions)) { if($app[1]) { @@ -106,17 +106,17 @@ } $apps->save_apps(); - $cd = account_edit(array("loginid" => $n_loginid, "firstname" => $n_firstname, - "lastname" => $n_lastname, "passwd" => $n_passwd, - "account_status" => $n_account_status, "old_loginid" => $old_loginid, - "account_id" => rawurldecode($account_id))); + $cd = account_edit(array('loginid' => $n_loginid, 'firstname' => $n_firstname, + 'lastname' => $n_lastname, 'passwd' => $n_passwd, + 'account_status' => $n_account_status, 'old_loginid' => $old_loginid, + 'account_id' => rawurldecode($account_id))); // 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__); // Add new groups user is associated to for($i=0;$iacl->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.. @@ -128,13 +128,13 @@ $docommit = False; $after_apps = explode(':',$apps_after); for($i=1;$icommon->hook_single("add_def_pref", $after_apps[$i]); + $phpgw->common->hook_single('add_def_pref', $after_apps[$i]); $docommit = True; } } @@ -142,16 +142,46 @@ if ($docommit) { $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 - 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(); - Header("Location: " . $phpgw->link("accounts.php", "cd=$cd")); + Header('Location: ' . $phpgw->link('accounts.php', 'cd='.$cd)); $phpgw->common->phpgw_exit(); } @@ -174,7 +204,8 @@ $n_loginid = $userData["account_lid"]; $n_firstname = $userData["firstname"]; $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(); } @@ -241,6 +272,7 @@ } } + @reset($db_perms); for ($i=0;$i<200;) { // The $i<200 is only used for a brake if (! $perm_display[$i][1]) break; $perm_html .= '' . lang($perm_display[$i][1]) . '' @@ -269,17 +301,48 @@ $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 - 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 // {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->pparse("out","form"); + $phpgw->template->set_var("lang_button",lang('Save')); + $phpgw->template->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 9da3ff87ef..46dbde08b3 100644 --- a/admin/inc/accounts_ldap.inc.php +++ b/admin/inc/accounts_ldap.inc.php @@ -182,22 +182,13 @@ @ldap_close($ldap); - $phpgw->db->lock(array("accounts")); - $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"] . "','x','". addslashes($account_info["firstname"]) . "','" - . addslashes($account_info["lastname"]) . "'," - . "'" . $phpgw->accounts->groups_array_to_string($account_info["groups"]) . "','A',0)"; + . addslashes($account_info["lastname"]) . "','A',0)"; $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(); diff --git a/admin/inc/accounts_sql.inc.php b/admin/inc/accounts_sql.inc.php index 8af2205b30..632a8918e2 100755 --- a/admin/inc/accounts_sql.inc.php +++ b/admin/inc/accounts_sql.inc.php @@ -69,20 +69,13 @@ { global $phpgw, $phpgw_info; - $phpgw->db->lock(array("accounts","preferences")); - $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"]) . "','" . 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->unlock(); - - $apps = CreateObject('phpgwapi.applications',$account_info["loginid"]); - $apps->add_user($account_info["permissions"]); - $apps->save_user(); $sep = $phpgw->common->filesystem_separator(); diff --git a/admin/newaccount.php b/admin/newaccount.php index b9f2b49876..15fe26dd4b 100755 --- a/admin/newaccount.php +++ b/admin/newaccount.php @@ -48,40 +48,106 @@ if ($n_passwd != $n_passwd_2) $error[$totalerrors++] = lang("The two passwords are not the same"); - if (count($new_permissions) == 0) - $error[$totalerrors++] = lang("You must add at least 1 permission to this account"); - - if (count($n_groups) == 0) - $error[$totalerrors++] = lang("Account must belong to at least 1 group"); + if (!count($new_permissions) || !count($n_groups)) { + $error[$totalerrors++] = "
" . lang("You must add at least 1 permission or group to this account"); + } if (account_exsists($n_loginid)) { $error[$totalerrors++] = lang("That loginid has already been taken"); } if (! $error) { - $cd = account_add(array("loginid" => $n_loginid, "permissions" => $new_permissions, - "firstname" => $n_firstname, "lastname" => $n_lastname, - "passwd" => $n_passwd, "groups" => $n_groups)); + $phpgw->db->lock(array("accounts","preferences","phpgw_sessions","phpgw_acl","applications")); + + $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->next_record(); - $pref = CreateObject('phpgwapi.preferences',intval($phpgw->db->f("account_id"))); - $apps_object = CreateObject('phpgwapi.applications',intval($phpgw->db->f("account_id"))); - $apps_array = $apps_object->apps_enabled(); - $phpgw->common->hook_single("add_def_pref", "admin"); - while($apps = each($apps_array)) { - if($apps[0]<>"admin") - $phpgw->common->hook_single("add_def_pref", $apps[0]); - } - $pref->commit(); + $phpgw->db->query("SELECT account_id FROM accounts WHERE account_lid='$n_loginid'",__LINE__,__FILE__); + $phpgw->db->next_record(); + $account_id = intval($phpgw->db->f("account_id")); + $apps = CreateObject('phpgwapi.applications',array($account_id,'u')); + $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;$iacl->add("phpgw_group",$n_groups[$i],$account_id,'u',1); + } + + $pref = CreateObject('phpgwapi.preferences',$account_id); + $phpgw->common->hook_single("add_def_pref", "admin"); + while($apps = each($apps_after)) { + if($apps[0]<>"admin") + $phpgw->common->hook_single("add_def_pref", $apps[0]); + } + $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 inlcuding other admin tools - while(list($key,$value) = each($phpgw_info["user"]["app_perms"])) + while($app = each($apps_after)) { - $phpgw->common->hook_single("add_user_data", $value); + $phpgw->common->hook_single('add_user_data', $value); } - Header("Location: " . $phpgw->link("accounts.php","cd=$cd")); + Header('Location: ' . $phpgw->link('accounts.php','cd='.$cd)); $phpgw->common->phpgw_exit(); } } @@ -178,13 +244,16 @@ } $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 - 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 // {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",""); $phpgw->template->set_var("lang_button",Lang("Add")); diff --git a/phpgwapi/inc/class.acl.inc.php b/phpgwapi/inc/class.acl.inc.php index 19286987b1..7970cdb0d6 100644 --- a/phpgwapi/inc/class.acl.inc.php +++ b/phpgwapi/inc/class.acl.inc.php @@ -99,7 +99,6 @@ $this->db->query($sql ,__LINE__,__FILE__); $rights = 0; if ($this->db->num_rows() == 0 && $phpgw_info["server"]["acl_default"] != "deny"){ -// echo "rows: ".$this->db->num_rows()."
"; return True; } while ($this->db->next_record()) { @@ -112,6 +111,7 @@ function check_specific($location, $required, $appname = False, $id = "", $id_type = "u"){ global $phpgw, $phpgw_info; $rights = $this->get_specific_rights($location,$appname, $id, $id_type); + return !!($rights & $required); } diff --git a/phpgwapi/inc/class.applications.inc.php b/phpgwapi/inc/class.applications.inc.php index 7b175bfe25..0a90d82e38 100755 --- a/phpgwapi/inc/class.applications.inc.php +++ b/phpgwapi/inc/class.applications.inc.php @@ -54,7 +54,6 @@ $this->account_id = $phpgw_info["user"]["account_id"]; $this->account_type = "u"; } -//echo "Account ID (Initializing applications) = ".$this->account_id."
\n"; } function enabled_apps()