diff --git a/admin/editgroup.php b/admin/editgroup.php index 5af387f37a..a6bf9fe4a0 100755 --- a/admin/editgroup.php +++ b/admin/editgroup.php @@ -38,52 +38,36 @@ } if (! $error) { - $phpgw->db->lock(array("accounts","groups")); +// $phpgw->db->lock(array("accounts","groups","preferences","config","applications","phpgw_hooks","phpgw_sessions")); - $phpgw->db->query("SELECT group_apps FROM groups WHERE group_id=".$group_id,__FILE__,__LINE__); - $phpgw->db->next_record(); - $apps_before = $phpgw->db->f("group_apps"); $phpgw->accounts->add_app($n_group_permissions); - $apps_after = $phpgw->accounts->add_app("",True); + $apps_after = explode(":",$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[$i]; - } - } - } $phpgw->db->query("update groups set group_name='$n_group', group_apps='" . $apps_after . "' where group_id=$group_id"); - $phpgw->db->query("SELECT group_id FROM groups WHERE group_name='$n_group'"); - $phpgw->db->next_record(); - $group_con = $phpgw->db->f("group_id"); for ($i=0; $idb->query("SELECT account_groups FROM accounts WHERE account_id=".$n_users[$i]); $phpgw->db->next_record(); - if(strpos($phpgw->db->f("account_groups"),$group_con.":0,") == 0) { - $user_groups = $phpgw->db->f("account_groups") . ",$group_con:0,"; + if(strpos($phpgw->db->f("account_groups"),$group_id.":0,") == 0) { + $user_groups = $phpgw->db->f("account_groups") . ",$group_id:0,"; $user_groups = ereg_replace(",,",",",$user_groups); $phpgw->db->query("UPDATE accounts SET account_groups='$user_groups' WHERE account_id=".$n_users[$i]); } // The following sets any default preferences needed for new applications.. // This is smart enough to know if previous preferences were selected, use them. - if (count($new_apps)) { - $pref = new preferences($n_users[$i]); - $docommit = False; - for ($j=0;$jpreferences[$new_apps[$j]]) { - $phpgw->common->hook_single("add_def_pref", $new_apps[$j]); - $docommit = True; - } - } - if ($docommit) { - $pref->commit(); + $pref = new preferences(intval($n_users[$i])); + $docommit = False; + for ($j=1;$j<=count($apps_after);$j++) { + if (!$pref->preferences[$apps_after[$j]]) { + $phpgw->common->hook_single("add_def_pref", $apps_after[$j]); + $docommit = True; } } + if ($docommit) { + $pref->commit(); + } } $sep = $phpgw->common->filesystem_separator(); @@ -100,7 +84,7 @@ $cd = 33; } - $phpgw->db->unlock(); +// $phpgw->db->unlock(); Header("Location: " . $phpgw->link("groups.php","cd=$cd")); $phpgw->common->phpgw_exit(); diff --git a/admin/newaccount.php b/admin/newaccount.php index 46d9a281db..b8e9a39cf3 100755 --- a/admin/newaccount.php +++ b/admin/newaccount.php @@ -66,9 +66,7 @@ $phpgw->db->query("SELECT account_permissions FROM accounts WHERE account_lid='$n_loginid'",__LINE__,__FILE__); $phpgw->db->next_record(); $apps = explode(":",$phpgw->db->f("account_permissions")); - $phpgw->db->query("SELECT account_id FROM accounts WHERE account_lid='".$n_loginid."'"); - $phpgw->db->next_record(); - $pref = new preferences($phpgw->db->f("account_id")); + $pref = new preferences($n_loginid); $phpgw->common->hook_single("add_def_pref", "admin"); for ($i=1;$icommon->hook_single("add_def_pref", $apps[$i]); diff --git a/phpgwapi/inc/phpgw_accounts_shared.inc.php b/phpgwapi/inc/phpgw_accounts_shared.inc.php index 7d74bc5adf..6204a77667 100644 --- a/phpgwapi/inc/phpgw_accounts_shared.inc.php +++ b/phpgwapi/inc/phpgw_accounts_shared.inc.php @@ -196,7 +196,7 @@ var $account_id; var $preferences; - function preferences($account_id=0) + function preferences($account_id) { global $phpgw; @@ -205,18 +205,19 @@ if (is_long($account_id) && $account_id) { $this->account_id = $account_id; } elseif(is_string($account_id)) { - $db2->query("SELECT account_id FROM accounts WHERE account_lid='".$account_id."'"); + $db2->query("SELECT account_id FROM accounts WHERE account_lid='".$account_id."'",__LINE__,__FILE__); if($db2->num_rows()) { $db2->next_record(); $this->account_id = $db2->f("account_id"); + } else { + $load_pref = False; } } else { $load_pref = False; } if ($load_pref) { - $db2->query("select preference_value from preferences where preference_owner='" - . $this->account_id . "'",__LINE__,__FILE__); + $db2->query("SELECT preference_value FROM preferences WHERE preference_owner=".$this->account_id,__LINE__,__FILE__); $db2->next_record(); $this->preferences = unserialize($db2->f("preference_value")); }