From ea66a64a460020ab5f727cd0c232931345709787 Mon Sep 17 00:00:00 2001 From: skeeter Date: Fri, 22 Dec 2000 21:18:35 +0000 Subject: [PATCH] new hook file for preferences --- .../inc/hook_admin_add_def_pref.inc.php | 5 ++ admin/editaccount.php | 63 ++++++++++++++++--- admin/editgroup.php | 49 +++++++++++++-- admin/inc/accounts_ldap.inc.php | 3 +- admin/inc/accounts_sql.inc.php | 8 +-- admin/inc/hook_admin_add_def_pref.inc.php | 8 +++ admin/newaccount.php | 33 +++------- admin/newapplication.php | 15 +++++ calendar/inc/hook_admin_add_def_pref.inc.php | 8 +++ phpgwapi/inc/phpgw_accounts_shared.inc.php | 44 +++++++++++++ 10 files changed, 193 insertions(+), 43 deletions(-) create mode 100755 addressbook/inc/hook_admin_add_def_pref.inc.php create mode 100755 admin/inc/hook_admin_add_def_pref.inc.php create mode 100755 calendar/inc/hook_admin_add_def_pref.inc.php diff --git a/addressbook/inc/hook_admin_add_def_pref.inc.php b/addressbook/inc/hook_admin_add_def_pref.inc.php new file mode 100755 index 0000000000..38c6364377 --- /dev/null +++ b/addressbook/inc/hook_admin_add_def_pref.inc.php @@ -0,0 +1,5 @@ +preferences->add_newuser("addressbook","company","addressbook_True"); + $phpgw->preferences->add_newuser("addressbook","lastname","addressbook_True"); + $phpgw->preferences->add_newuser("addressbook","firstname","addressbook_True"); +?> diff --git a/admin/editaccount.php b/admin/editaccount.php index b74b15e0b8..a80685e72f 100755 --- a/admin/editaccount.php +++ b/admin/editaccount.php @@ -51,27 +51,76 @@ } if (! $totalerrors) { - $cd = account_edit(array("loginid" => $n_loginid, "permissions" => $new_permissions, + $phpgw->db->query("SELECT account_permissions FROM accounts WHERE account_id = ".$account_id); + $phpgw->db->next_record(); + $apps_before = $phpgw->db->f("account_permissions"); + + while ($permission = each($new_permissions)) { + if ($phpgw_info["apps"][$permission[0]]["enabled"]) { + $phpgw->accounts->add_app($permission[0]); + } + } + $apps_after = $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; + } + } + } + + $cd = account_edit(array("loginid" => $n_loginid, "permissions" => $new_permissions, "firstname" => $n_firstname, "lastname" => $n_lastname, "passwd" => $n_passwd, "account_status" => $n_account_status, "old_loginid" => $old_loginid, "account_id" => rawurldecode($account_id), "groups" => $phpgw->accounts->groups_array_to_string($n_groups))); + +// 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)) { + if ($account_id <> $phpgw_info["user"]["account_id"]) { + $phpgw->db->query("SELECT preference_value FROM preferences WHERE preference_owner=".$account_id,__FILE__,__LINE__); + $phpgw->db->next_record(); + $phpgw_newuser["user"]["preferences"] = unserialize($phpgw->db->f("preference_value"); + } else { + $phpgw_newuser["user"]["preferences"] = $phpgw_info["user"]["preferences"] + } + $docommit = False; + for ($j=0;$jcommon->hook_single("add_def_pref", $new_apps[$j]); + $docommit = True; + } + } + if ($docommit) { + if ($account_id <> $phpgw_info["user"]["account_id"]) { + $phpgw->preferences->commit_user($account_id); + } else { + $phpgw_info["user"]["preferences"] = $phpgw_newuser["user"]["preferences"]; + unset($phpgw_newuser); + $phpgw->preferences->commit(); + } + } + } + + Header("Location: " . $phpgw->link("accounts.php", "cd=$cd")); + exit; } - Header("Location: " . $phpgw->link("accounts.php", "cd=$cd")); - exit; } // if $submit + $phpgw->template->set_file(array("form" => "account_form.tpl")); + + $phpgw->common->phpgw_header(); + $phpgw->common->navbar(); + if ($totalerrors) { $phpgw->template->set_var("error_messages","
" . $phpgw->common->error_list($error) . "
"); } else { $phpgw->template->set_var("error_messages",""); } - $phpgw->template->set_file(array("form" => "account_form.tpl")); - - $phpgw->common->phpgw_header(); - $phpgw->common->navbar(); $userData = $phpgw->accounts->read_userData($account_id); $db_perms = $phpgw->accounts->read_apps($userData["account_lid"]); diff --git a/admin/editgroup.php b/admin/editgroup.php index 75e04ca5ce..fdbbf5509b 100755 --- a/admin/editgroup.php +++ b/admin/editgroup.php @@ -40,10 +40,22 @@ if (! $error) { $phpgw->db->lock(array("accounts","groups")); - $phpgw->accounts->add_app($n_group_permissions); - $phpgw->db->query("update groups set group_name='$n_group', group_apps='" - . $phpgw->accounts->add_app("",True) - . "' where group_id=$group_id"); + $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); + + 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; + } + } + } + $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"); @@ -55,6 +67,35 @@ $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)) { + if ($n_users[$i] <> $phpgw_info["user"]["account_id"]) { + if(is_array($phpgw_newuser)) unset($phpgw_newuser); + $phpgw->db->query("SELECT preference_value FROM preferences WHERE preference_owner=".$n_users[$i],__FILE__,__LINE__); + $phpgw->db->next_record(); + $phpgw_newuser["user"]["preferences"] = unserialize($phpgw->db->f("preference_value"); + } else { + $phpgw_newuser["user"]["preferences"] = $phpgw_info["user"]["preferences"] + } + $docommit = False; + for ($j=0;$jcommon->hook_single("add_def_pref", $new_apps[$j]); + $docommit = True; + } + } + if ($docommit) { + if ($n_users[$i] <> $phpgw_info["user"]["account_id"]) { + $phpgw->preferences->commit_user($n_users[$i]); + } else { + $phpgw_info["user"]["preferences"] = $phpgw_newuser["user"]["preferences"]; + unset($phpgw_newuser); + $phpgw->preferences->commit(); + } + } + } } $sep = $phpgw->common->filesystem_separator(); diff --git a/admin/inc/accounts_ldap.inc.php b/admin/inc/accounts_ldap.inc.php index b33a8c5edd..53ce1c3cd8 100644 --- a/admin/inc/accounts_ldap.inc.php +++ b/admin/inc/accounts_ldap.inc.php @@ -182,8 +182,7 @@ @ldap_close($ldap); - add_default_preferences($account_info["account_id"]); - $phpgw->db->lock(array("accounts","preferences")); + $phpgw->db->lock(array("accounts")); while ($permission = each($account_info["permissions"])) { if ($phpgw_info["apps"][$permission[0]]["enabled"]) { diff --git a/admin/inc/accounts_sql.inc.php b/admin/inc/accounts_sql.inc.php index 2bcd11b012..aff6a9e9fa 100755 --- a/admin/inc/accounts_sql.inc.php +++ b/admin/inc/accounts_sql.inc.php @@ -85,12 +85,6 @@ . "','" . $phpgw->accounts->add_app("",True) . "','" . $account_info["groups"] . "','A',0)"; $phpgw->db->query($sql); - - $phpgw->db->query("select account_id from accounts where account_lid='" - . $account_info["loginid"] . "'"); - $phpgw->db->next_record(); - add_default_preferences($phpgw->db->f("account_id")); - $phpgw->db->unlock(); $sep = $phpgw->common->filesystem_separator(); @@ -167,6 +161,8 @@ function account_delete($account_id) { global $phpgw; + global $phpgw_info; + $phpgw->db->query("select account_lid from accounts where account_id=$account_id"); $phpgw->db->next_record(); diff --git a/admin/inc/hook_admin_add_def_pref.inc.php b/admin/inc/hook_admin_add_def_pref.inc.php new file mode 100755 index 0000000000..a8b1689454 --- /dev/null +++ b/admin/inc/hook_admin_add_def_pref.inc.php @@ -0,0 +1,8 @@ +preferences->add_newuser("common","maxmatchs","15"); + $phpgw->preferences->add_newuser("common","theme","default"); + $phpgw->preferences->add_newuser("common","tz_offset","0"); + $phpgw->preferences->add_newuser("common","dateformat","m/d/Y"); + $phpgw->preferences->add_newuser("common","timeformat","12"); + $phpgw->preferences->add_newuser("common","lang","en"); +?> diff --git a/admin/newaccount.php b/admin/newaccount.php index cf3726986b..76aa4c9228 100755 --- a/admin/newaccount.php +++ b/admin/newaccount.php @@ -16,29 +16,6 @@ include("../header.inc.php"); include($phpgw_info["server"]["app_inc"]."/accounts_".$phpgw_info["server"]["account_repository"].".inc.php"); - function add_default_preferences($account_id) - { - global $phpgw; - -/* $phpgw->common->preferences_add($account_id,"maxmatchs","common","15"); - $phpgw->common->preferences_add($account_id,"theme","common","default"); - $phpgw->common->preferences_add($account_id,"tz_offset","common","0"); - $phpgw->common->preferences_add($account_id,"dateformat","common","m/d/Y"); - $phpgw->common->preferences_add($account_id,"timeformat","common","12"); - $phpgw->common->preferences_add($account_id,"lang","common","en"); - $phpgw->common->preferences_add($account_id,"company","addressbook","True"); - $phpgw->common->preferences_add($account_id,"lastname","addressbook","True"); - $phpgw->common->preferences_add($account_id,"firstname","addressbook","True"); */ - - // Even if they don't have access to the calendar, we will add these. - // Its better then the calendar being all messed up, they will be deleted - // the next time the update there preferences. -/* $phpgw->common->preferences_add($account_id,"weekstarts","calendar","Monday"); - $phpgw->common->preferences_add($account_id,"workdaystarts","calendar","9"); - $phpgw->common->preferences_add($account_id,"workdayends","calendar","17"); */ - } - - if ($submit) { $totalerrors = 0; @@ -75,7 +52,15 @@ "firstname" => $n_firstname, "lastname" => $n_lastname, "passwd" => $n_passwd, "groups" => $phpgw->accounts->groups_array_to_string($n_groups))); - + $phpgw->db->query("SELECT account_permissions FROM accounts WHERE account_lid='$n_loginid'"); + $phpgw->db->next_record(); + $apps = explode(":",$phpgw->db->f("account_permissions")); + $phpgw->common->hook_single("add_def_pref", "admin"); + for($i=1;$i<=sizeof($apps);$i++) { + $appname = $apps[$i]; + $phpgw->common->hook_single("add_def_pref", $appname); + } + $phpgw->preferences->commit_newuser($n_loginid); Header("Location: " . $phpgw->link("accounts.php","cd=$cd")); exit; } diff --git a/admin/newapplication.php b/admin/newapplication.php index a4a57e343a..bb2b2e8b80 100644 --- a/admin/newapplication.php +++ b/admin/newapplication.php @@ -56,6 +56,21 @@ . addslashes($n_app_name) . "','" . addslashes($n_app_title) . "'," . "$n_app_status,$app_order)",__LINE__,__FILE__); + $phpgw->db->query("SELECT preference_owner, preference_value FROM preferences"); + if($phpgw->db->num_rows()) { + while($phpgw->db->next_record()) { + if($phpgw->db->f("preference_owner") != $phpgw_info["user"]["account_id"] { + $phpgw_newuser["user"]["preferences"] = unserialize($phpgw->db->f("preference_value"); + $phpgw->common->hook_single("add_def_pref", $n_app_name); + $phpgw->preferences->commit_user($phpgw->db->f("preference_owner")); + } else { + $phpgw->common->hook_single("add_def_pref", $n_app_name); + $phpgw_info["user"]["preferences"]["$n_app_name"] = $phpgw_newuser["user"]["preferences"]["$n_app_name"]; + unset($phpgw_newuser); + $phpgw->preferences->commit(); + } + } + } Header("Location: " . $phpgw->link("applications.php")); exit; } else { diff --git a/calendar/inc/hook_admin_add_def_pref.inc.php b/calendar/inc/hook_admin_add_def_pref.inc.php new file mode 100755 index 0000000000..019f5a6f67 --- /dev/null +++ b/calendar/inc/hook_admin_add_def_pref.inc.php @@ -0,0 +1,8 @@ +preferences->add_newuser("calendar","weekstarts","Monday"); + $phpgw->preferences->add_newuser("calendar","workdaystarts","9"); + $phpgw->preferences->add_newuser("calendar","workdayends","17"); + $phpgw->preferences->add_newuser("calendar","defaultcalendar","index.php"); + $phpgw->preferences->add_newuser("calendar","defaultfilter","all"); + $phpgw->preferences->add_newuser("calendar","mainscreen_showevents","Y"); +?> diff --git a/phpgwapi/inc/phpgw_accounts_shared.inc.php b/phpgwapi/inc/phpgw_accounts_shared.inc.php index 3f16089beb..29d18e68c3 100644 --- a/phpgwapi/inc/phpgw_accounts_shared.inc.php +++ b/phpgwapi/inc/phpgw_accounts_shared.inc.php @@ -230,6 +230,50 @@ global $phpgw_info; $phpgw_info["user"]["preferences"][$app_name] = array(); } + + // This will commit preferences for a new user + function commit_newuser($n_loginid) { + global $phpgw; + + $db = $phpgw->db; + $db->lock(array("accounts")); + $db->query("SELECT account_id FROM accounts WHERE account_lid='".$n_loginid."'"); + $db->next_record(); + $id = $db->f("account_id"); + $db->unlock(); + $this->commit_user($id); + } + + // This will commit preferences for a new user + function commit_user($id) { + global $phpgw_newuser, $phpgw; + + $db = $phpgw->db; + $db->lock(array("preferences")); + $db->query("SELECT * FROM preferences WHERE preference_owner=".$id); + if($db->num_rows()) { + $db->query("UPDATE preferences SET preference_value = '" + . serialize($phpgw_newuser["user"]["preferences"]) + . "' WHERE preference_owner=".$id,__LINE__,__FILE__); + } else { + $db->query("insert into preferences (preference_owner,preference_value) values (" + . $id.",'".serialize($phpgw_newuser["user"]["preferences"])."')",__LINE__,__FILE__); + } + $db->unlock(); + unset($phpgw_newuser); + } + + // This will add all preferences within a certain app for a new user + function add_newuser($app_name,$var,$value="") { + global $phpgw_newuser; + + if (! $value) { + global $$var; + $value = $$var; + } + + $phpgw_newuser["user"]["preferences"][$app_name][$var] = $value; + } } //end of preferences class