From abf8c3bcd930367ec919d4258ae6143352b3b8e2 Mon Sep 17 00:00:00 2001 From: skeeter Date: Sun, 21 Jan 2001 01:26:23 +0000 Subject: [PATCH] implementation of applications class --- admin/editaccount.php | 6 +- admin/editgroup.php | 67 +++++--- admin/inc/accounts_ldap.inc.php | 21 ++- admin/inc/accounts_sql.inc.php | 16 +- admin/newaccount.php | 15 +- admin/newgroup.php | 55 +++++-- admin/templates/default/groups_form.tpl | 7 +- admin/templates/verdilak/groups_form.tpl | 7 +- phpgwapi/inc/class.accounts_ldap.inc.php | 10 +- phpgwapi/inc/class.accounts_shared.inc.php | 5 +- phpgwapi/inc/class.accounts_sql.inc.php | 10 +- phpgwapi/inc/class.applications.inc.php | 173 ++++++++++++++------- phpgwapi/inc/class.phpgw.inc.php | 4 + 13 files changed, 257 insertions(+), 139 deletions(-) diff --git a/admin/editaccount.php b/admin/editaccount.php index 540eafea75..e1e407d50c 100755 --- a/admin/editaccount.php +++ b/admin/editaccount.php @@ -134,12 +134,12 @@ } $userData = $phpgw->accounts->read_userData($account_id); - $db_perms = $phpgw->accounts->read_apps($userData["account_lid"]); if (! $submit) { $n_loginid = $userData["account_lid"]; $n_firstname = $userData["firstname"]; $n_lastname = $userData["lastname"]; + $apps = CreateObject('phpgwapi.applications',intval($userData["account_id"])); } if ($phpgw_info["server"]["account_repository"] == "ldap") { @@ -210,7 +210,7 @@ $perm_html .= '' . lang($perm_display[$i][1]) . '' . 'user_apps[$perm_display[$i][0]]) { $perm_html .= " checked"; } $perm_html .= ">"; @@ -224,7 +224,7 @@ $perm_html .= '' . lang($perm_display[$i][1]) . '' . 'user_apps[$perm_display[$i][0]]) { $perm_html .= " checked"; } $perm_html .= ">\n"; diff --git a/admin/editgroup.php b/admin/editgroup.php index 760a53ea1b..00064f4aa9 100755 --- a/admin/editgroup.php +++ b/admin/editgroup.php @@ -37,13 +37,14 @@ if (! $error) { // $phpgw->db->lock(array("accounts","groups","preferences","config","applications","phpgw_hooks","phpgw_sessions")); + $apps = CreateObject('phpgwapi.applications'); + $app_string = $apps->add_group($group_id,$n_group_permissions); + $apps->save_group($group_id); + $apps_after = explode(":",$app_string); - $phpgw->accounts->add_app($n_group_permissions); - $apps = $phpgw->accounts->add_app("",True); - $apps_after = explode(":",$apps); - - $phpgw->db->query("update groups set group_name='$n_group', group_apps='" . $apps - . "' where group_id=$group_id"); + if($old_group_name <> $n_group) { + $phpgw->db->query("update groups set group_name='$n_group' where group_id=$group_id"); + } for ($i=0; $idb->query("SELECT account_groups, account_lid FROM accounts WHERE account_id=".$n_users[$i]); @@ -116,10 +117,6 @@ for ($i=0; $idb->query("select group_name from groups where group_id=$group_id"); $phpgw->db->next_record(); @@ -132,11 +129,9 @@ $selected_users[$phpgw->db->f("account_id")] = " selected"; } - $gp = $phpgw->accounts->read_group_apps($group_id); - - for ($i=0; $iread_group_apps($group_id); + $db_perms = $apps->get_group_array($group_id); } $phpgw->db->query("select * from groups where group_id=$group_id"); @@ -170,14 +165,48 @@ $phpgw->template->set_var("user_list",$user_list); $phpgw->template->set_var("lang_permissions",lang("Permissions this group has")); + + $i = 0; + $sorted_apps = $phpgw_info["apps"]; + @asort($sorted_apps); + @reset($sorted_apps); while ($permission = each($phpgw_info["apps"])) { if ($permission[1]["enabled"]) { - $permissions_list .= ""; + $perm_display[$i][0] = $permission[0]; + $perm_display[$i][1] = $permission[1]["title"]; + $i++; } } - $phpgw->template->set_var("permissions_list",$permissions_list); + + $perm_html = ""; + 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]) . '' + . '' + . 'template->set_var("permissions_list",$perm_html); + $phpgw->template->set_var("lang_submit_button",lang("submit changes")); $phpgw->template->pparse("out","form"); diff --git a/admin/inc/accounts_ldap.inc.php b/admin/inc/accounts_ldap.inc.php index d1d7fd2365..9deb660210 100644 --- a/admin/inc/accounts_ldap.inc.php +++ b/admin/inc/accounts_ldap.inc.php @@ -184,22 +184,21 @@ $phpgw->db->lock(array("accounts")); - while ($permission = each($account_info["permissions"])) { - if ($phpgw_info["apps"][$permission[0]]["enabled"]) { - $phpgw->accounts->add_app($permission[0]); - } - } - $sql = "insert into accounts (account_id,account_lid,account_pwd,account_firstname," - . "account_lastname,account_permissions,account_groups,account_status," - . "account_lastpwd_change) values ('" . $account_info["account_id"] . "','" - . $account_info["loginid"] . "','x','". addslashes($account_info["firstname"]) . "','" - . addslashes($account_info["lastname"]) . "','" . $phpgw->accounts->add_app("",True) - . "','" . $account_info["groups"] . "','A',0)"; + . "account_lastname,account_groups,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)"; $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(); $basedir = $phpgw_info["server"]["files_dir"] . $sep . "users" . $sep; diff --git a/admin/inc/accounts_sql.inc.php b/admin/inc/accounts_sql.inc.php index 3647db7bdc..50248508fc 100755 --- a/admin/inc/accounts_sql.inc.php +++ b/admin/inc/accounts_sql.inc.php @@ -72,21 +72,19 @@ $phpgw->db->lock(array("accounts","preferences")); - while ($permission = each($account_info["permissions"])) { - if ($phpgw_info["apps"][$permission[0]]["enabled"]) { - $phpgw->accounts->add_app($permission[0]); - } - } - $sql = "insert into accounts (account_lid,account_pwd,account_firstname,account_lastname," - . "account_permissions,account_groups,account_status,account_lastpwd_change) values ('" + . "account_groups,account_status,account_lastpwd_change) values ('" . $account_info["loginid"] . "','" . md5($account_info["passwd"]) . "','" . addslashes($account_info["firstname"]) . "','". addslashes($account_info["lastname"]) - . "','" . $phpgw->accounts->add_app("",True) . "','" . $account_info["groups"] . "','A',0)"; + . "','" . $phpgw->accounts->groups_array_to_string($account_info["groups"]) . "','A',0)"; - $phpgw->db->query($sql); + $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(); $basedir = $phpgw_info["server"]["files_dir"] . $sep . "users" . $sep; diff --git a/admin/newaccount.php b/admin/newaccount.php index 4dae0bba42..b9f2b49876 100755 --- a/admin/newaccount.php +++ b/admin/newaccount.php @@ -61,16 +61,17 @@ if (! $error) { $cd = account_add(array("loginid" => $n_loginid, "permissions" => $new_permissions, "firstname" => $n_firstname, "lastname" => $n_lastname, - "passwd" => $n_passwd, - "groups" => $phpgw->accounts->groups_array_to_string($n_groups))); - $phpgw->db->query("SELECT account_permissions, account_id FROM accounts WHERE account_lid='$n_loginid'",__LINE__,__FILE__); + "passwd" => $n_passwd, "groups" => $n_groups)); + + $phpgw->db->query("SELECT account_id FROM accounts WHERE account_lid='$n_loginid'",__LINE__,__FILE__); $phpgw->db->next_record(); - $apps = explode(":",$phpgw->db->f("account_permissions")); $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"); - for ($i=1;$i"admin") - $phpgw->common->hook_single("add_def_pref", $apps[$i]); + while($apps = each($apps_array)) { + if($apps[0]<>"admin") + $phpgw->common->hook_single("add_def_pref", $apps[0]); } $pref->commit(); diff --git a/admin/newgroup.php b/admin/newgroup.php index 9f27466a95..1672d1a6e5 100755 --- a/admin/newgroup.php +++ b/admin/newgroup.php @@ -35,11 +35,11 @@ if (! $error) { $phpgw->db->lock(array("accounts","groups")); - $phpgw->accounts->add_app($n_group_permissions); - $apps = $phpgw->accounts->add_app("",True); - $phpgw->db->query("INSERT INTO groups (group_name,group_apps) VALUES " - . "('$n_group','" - . $apps . "')"); + $apps = CreateObject('phpgwapi.applications'); + $app_string = $apps->add_group($group_id,$n_group_permissions); + $apps->save_group($group_id); + + $phpgw->db->query("INSERT INTO groups (group_name) VALUES ('$n_group')"); $phpgw->db->query("SELECT group_id FROM groups WHERE group_name='$n_group'"); $phpgw->db->next_record(); $group_con = $phpgw->db->f("group_id"); @@ -129,19 +129,48 @@ } $phpgw->template->set_var("user_list",$user_list); - $phpgw->template->set_var("lang_permissions",lang("Select permissions this group will have")); - for ($i=0; $itemplate->set_var("lang_permissions",lang("Permissions this group has")); + $i = 0; + $sorted_apps = $phpgw_info["apps"]; + @asort($sorted_apps); + @reset($sorted_apps); while ($permission = each($phpgw_info["apps"])) { if ($permission[1]["enabled"]) { - $permissions_list .= ""; + $perm_display[$i][0] = $permission[0]; + $perm_display[$i][1] = $permission[1]["title"]; + $i++; } } - $phpgw->template->set_var("permissions_list",$permissions_list); + + $perm_html = ""; + 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]) . '' + . '' + . 'template->set_var("permissions_list",$perm_html); $phpgw->template->set_var("lang_submit_button",lang("Create Group")); $phpgw->template->pparse("out","form"); diff --git a/admin/templates/default/groups_form.tpl b/admin/templates/default/groups_form.tpl index ecd405dc35..bba2591c83 100644 --- a/admin/templates/default/groups_form.tpl +++ b/admin/templates/default/groups_form.tpl @@ -17,10 +17,9 @@ {lang_permissions} - - + + {permissions_list} +
diff --git a/admin/templates/verdilak/groups_form.tpl b/admin/templates/verdilak/groups_form.tpl index ecd405dc35..bba2591c83 100644 --- a/admin/templates/verdilak/groups_form.tpl +++ b/admin/templates/verdilak/groups_form.tpl @@ -17,10 +17,9 @@ {lang_permissions} - - + + {permissions_list} +
diff --git a/phpgwapi/inc/class.accounts_ldap.inc.php b/phpgwapi/inc/class.accounts_ldap.inc.php index 434ca63a15..17ec31f443 100644 --- a/phpgwapi/inc/class.accounts_ldap.inc.php +++ b/phpgwapi/inc/class.accounts_ldap.inc.php @@ -73,7 +73,8 @@ $db->next_record(); $phpgw_info["user"]["groups"] = explode (",",$db->f("account_groups")); - $phpgw_info["user"]["app_perms"] = explode (":",$db->f("account_permissions")); + $apps = CreateObject('phpgwapi.applications',intval($phpgw_info["user"]["account_id"])); + $phpgw_info["user"]["app_perms"] = $apps->app_perms; $phpgw_info["user"]["lastlogin"] = $db->f("account_lastlogin"); $phpgw_info["user"]["lastloginfrom"] = $db->f("account_lastloginfrom"); $phpgw_info["user"]["lastpasswd_change"] = $db->f("account_lastpwd_change"); @@ -123,7 +124,8 @@ $db->next_record(); $userData["groups"] = explode (",",$db->f("account_groups")); - $userData["app_perms"] = explode (":",$db->f("account_permissions")); + $apps = CreateObject('phpgwapi.applications',intval($userData["account_lid"])); + $userData["app_perms"] = $apps->app_perms; $userData["lastlogin"] = $db->f("account_lastlogin"); $userData["lastloginfrom"] = $db->f("account_lastloginfrom"); $userData["lastpasswd_change"] = $db->f("account_lastpwd_change"); @@ -138,7 +140,7 @@ $db2 = $phpgw->db; if (gettype($lid) == "integer") { - if ($phpgw_info["user"]["account_id"] != $lid) { + if ($phpgw_info["user"]["account_id"] != $lid || !$phpgw_info["user"]["groups"]) { $db2->query("select account_groups from accounts where account_id=$lid",__LINE__,__FILE__); $db2->next_record(); $gl = explode(",",$db2->f("account_groups")); @@ -146,7 +148,7 @@ $gl = $phpgw_info["user"]["groups"]; } } else { - if ($phpgw_info["user"]["userid"] != $lid) { + if ($phpgw_info["user"]["userid"] != $lid || !$phpgw_info["user"]["groups"]) { $db2->query("select account_groups from accounts where account_lid='$lid'",__LINE__,__FILE__); $db2->next_record(); $gl = explode(",",$db2->f("account_groups")); diff --git a/phpgwapi/inc/class.accounts_shared.inc.php b/phpgwapi/inc/class.accounts_shared.inc.php index fffd47efff..a790413e8f 100644 --- a/phpgwapi/inc/class.accounts_shared.inc.php +++ b/phpgwapi/inc/class.accounts_shared.inc.php @@ -38,9 +38,8 @@ } $phpgw_info["user"]["preferences"] = $phpgw->preferences->get_preferences(); $this->groups = $this->read_groups($phpgw_info["user"]["userid"]); - $this->apps = $this->read_apps($phpgw_info["user"]["userid"]); - - $phpgw_info["user"]["apps"] = $this->apps; + $apps = CreateObject('phpgwapi.applications',intval($phpgw_info["user"]["account_id"])); + $phpgw_info["user"]["apps"] = $apps->apps_enabled(); } // use this if you make any changes to phpgw_info, including preferences, config table changes, etc diff --git a/phpgwapi/inc/class.accounts_sql.inc.php b/phpgwapi/inc/class.accounts_sql.inc.php index 5b4416254d..5a0c3579e1 100644 --- a/phpgwapi/inc/class.accounts_sql.inc.php +++ b/phpgwapi/inc/class.accounts_sql.inc.php @@ -46,7 +46,8 @@ $phpgw_info["user"]["fullname"] = $db2->f("account_firstname") . " " . $db2->f("account_lastname"); $phpgw_info["user"]["groups"] = explode (",", $db2->f("account_groups")); - $phpgw_info["user"]["app_perms"] = explode (":", $db2->f("account_permissions")); + $apps = CreateObject('phpgwapi.applications',intval($phpgw_info["user"]["account_id"])); + $phpgw_info["user"]["app_perms"] = $apps->app_perms; $phpgw_info["user"]["lastlogin"] = $db2->f("account_lastlogin"); $phpgw_info["user"]["lastloginfrom"] = $db2->f("account_lastloginfrom"); $phpgw_info["user"]["lastpasswd_change"] = $db2->f("account_lastpwd_change"); @@ -70,7 +71,8 @@ $userData["fullname"] = $db2->f("account_firstname") . " " . $db2->f("account_lastname"); $userData["groups"] = explode(",", $db2->f("account_groups")); - $userData["app_perms"] = explode(":", $db2->f("account_permissions")); + $apps = CreateObject('phpgwapi.applications',intval($phpgw_info["user"]["account_id"])); + $userData["app_perms"] = $apps->app_perms; $userData["lastlogin"] = $db2->f("account_lastlogin"); $userData["lastloginfrom"] = $db2->f("account_lastloginfrom"); $userData["lastpasswd_change"] = $db2->f("account_lastpwd_change"); @@ -86,7 +88,7 @@ $db2 = $phpgw->db; if (gettype($lid) == "integer") { - if ($phpgw_info["user"]["account_id"] != $lid) { + if ($phpgw_info["user"]["account_id"] != $lid || !$phpgw_info["user"]["groups"]) { $db2->query("select account_groups from accounts where account_id=$lid",__LINE__,__FILE__); $db2->next_record(); $gl = explode(",",$db2->f("account_groups")); @@ -94,7 +96,7 @@ $gl = $phpgw_info["user"]["groups"]; } } else { - if ($phpgw_info["user"]["userid"] != $lid) { + if ($phpgw_info["user"]["userid"] != $lid || !$phpgw_info["user"]["groups"]) { $db2->query("select account_groups from accounts where account_lid='$lid'",__LINE__,__FILE__); $db2->next_record(); $gl = explode(",",$db2->f("account_groups")); diff --git a/phpgwapi/inc/class.applications.inc.php b/phpgwapi/inc/class.applications.inc.php index e6fb019529..e18ff66735 100755 --- a/phpgwapi/inc/class.applications.inc.php +++ b/phpgwapi/inc/class.applications.inc.php @@ -29,6 +29,8 @@ var $status = Array(); var $user_apps = Array(); var $group_apps = Array(Array()); + var $app_perms = Array(Array()); + var $apps_loaded = False; function applications($lid=0) { @@ -36,24 +38,33 @@ global $phpgw_info; $db2 = $phpgw->db; - $db2->query("select * from applications where app_enabled != '0'",__LINE__,__FILE__); - $apps_enabled = False; - while ($db2->next_record()) { - if($apps_enabled) $apps_enabled = True; - $name = $db2->f("app_name"); - $title = $db2->f("app_title"); - $status = $db2->f("app_enabled"); - $phpgw_info["apps"][$name] = array("title" => $title, "enabled" => True, "status" => $status); - - $this->set_var("enabled",1,$name); - $this->set_var("status",$db2->f("app_status"),$name); +// $db3 = $phpgw->db; + if(($this->is_type($lid,"integer") && $lid == $phpgw_info["user"]["account_id"]) || + ($this->is_type($lid,"string") && $lid == $phpgw_info["user"]["user_id"])) { + $load_info = True; + } + if(!$this->apps_loaded) { + $this->apps_loaded = True; + $db2->query("select * from applications where app_enabled != '0'",__LINE__,__FILE__); + $apps_enabled = False; + while ($db2->next_record()) { + if(!$apps_enabled) $apps_enabled = True; + $name = $db2->f("app_name"); + if($load_info) { + $title = $db2->f("app_title"); + $status = $db2->f("app_enabled"); + $phpgw_info["apps"][$name] = array("title" => $title, "enabled" => True, "status" => $status); + } + $this->enabled[$name] = 1; + $this->status[$name] = $db2->f("app_status"); + } } if($apps_enabled && $lid) { $owner_found = False; if($this->is_type($lid,"integer")) { $owner_id = $lid; $owner_found = True; - } else { + } elseif($this->is_type($lid,"string")) { $db2->query("SELECT account_id FROM accounts WHERE account_lid='".$lid."'",__LINE__,__FILE__); if($db2->num_rows()) { $db2->next_record(); @@ -62,9 +73,9 @@ } } if($owner_found) { - $this->set_var("account_id",$lid); - $this->read_user_apps($this->get_var("account_id")); - $this->read_group_apps($this->get_var("account_id")); + $this->account_id = $owner_id; + $this->read_user_group_apps($this->account_id); + $this->read_user_apps($this->account_id); } } } @@ -84,10 +95,8 @@ if($this->$var) { return $this->$var; } - } else { - if($this->$var[$index]) { - return $this->$var[$index]; - } + } elseif($this->$var[$index]) { + return $this->$var[$index]; } return False; } @@ -102,14 +111,14 @@ return $return_apps; } - function is_type($lid,$type) + function is_type($variable,$type) { - return (strtoupper(gettype($lid)) == strtoupper($type)); + return (strtoupper(gettype($variable)) == strtoupper($type)); } function read_user_apps($lid) { - global $phpgw; + global $phpgw, $phpgw_info; $db2 = $phpgw->db; @@ -118,88 +127,136 @@ } else { $db2->query("select account_permissions from accounts where account_lid='$lid'",__LINE__,__FILE__); } - $db2->next_record(); - - $apps = explode(":",$db2->f("account_permissions")); - for ($i=0; $iget_var("enabled",$apps[$i]) == 1) { - $this->set_var("user_apps[]",$apps[$i]); - $this->set_var("enabled",2,$apps[$i]); + if($db2->num_rows()) { + $db2->next_record(); + $apps = explode(":",$db2->f("account_permissions")); +if($lid <> $phpgw_info["user"]["account_id"]) echo "\n"; + for ($i=1; $i $phpgw_info["user"]["account_id"]) echo "\n"; + if ($this->enabled[$apps[$i]] == 1) { + $this->user_apps[$apps[$i]] = $apps[$i]; + $this->enabled[$apps[$i]] = 2; + $this->app_perms[] = $apps[$i]; + } } } } - function read_group_apps($lid) + function read_user_group_apps($lid) { global $phpgw; $groups = $phpgw->accounts->read_groups($lid); - for ($i=1; $i<(count($groups)-1); $i++) { - $ga = explode(":",$groups[$i]); - $group_array[$ga[0]] = $ga[1]; + if($groups) { + while ($group = each($groups)) { + $this->read_group_apps($group[0]); + } } + } - while ($group = each($group_array)) { - $db2->query("select group_apps from groups where group_id=".$group[0],__LINE__,__FILE__); - $db2->next_record(); + function read_group_apps($group_id) + { + global $phpgw; - $apps = explode(":",$db2->f("group_apps")); - for ($i=0;$iget_var("enabled",$apps[$i]) == 1) { - $this->set_var("group_apps[".$group[0]."][]",$apps[$i]); - $this->set_var("enabled",2,$apps[$i]); - } + $db2 = $phpgw->db; + + $db2->query("select group_apps from groups where group_id=".$group_id,__LINE__,__FILE__); + $db2->next_record(); + + $apps = explode(":",$db2->f("group_apps")); + for ($i=1;$ienabled[$apps[$i]] == 1) { + $this->group_apps[$group_id][$apps[$i]] = $apps[$i]; + $this->enabled[$apps[$i]] = 2; + $this->app_perms[] = $apps[$i]; } } } function is_system_enabled($appname) { - return $this->get_var("enabled",$appname) >= 1; + return $this->enabled[$appname] >= 1; } function is_user_enabled($appname) { - return $this->get_var("enabled",$appname) == 2; + return $this->enabled[$appname] == 2; + } + + function get_group_array($group_id) + { + return $this->group_apps[$group_id]; } function group_app_string($group_id) { - return ":".implode(":",$this->get_var("group_apps",$group_id)).":"; + reset($this->group_apps[$group_id]); + while($app = each($this->group_apps[$group_id])) { + $group_apps[] = $app[1]; + } + return ":".implode(":",$group_apps).":"; } function user_app_string() { - return ":".implode(":",$this->get_var("user_apps")).":"; + reset($this->user_apps); + while($app = each($this->user_apps)) { + $user_apps[] = $app[1]; + } + return ":".implode(":",$user_apps).":"; } function is_group($group_id,$appname) { - return $this->get_var("group_apps[".$group_id."]",$appname) == $appname; + return $this->group_apps[$group_id][$appname]; } function is_user($appname) { - return $this->get_var("user_apps",$appname) == $appname; + return $this->user_apps[$appname]; } function add_group($group_id,$appname) { - if ($this->get_var("enabled",$appname) && !$this->is_group($group_id,$appname)) { - $this->set_var("group_apps[".$group_id."][]",$appname); - $this->set_var("enabled",2,$appname); + if($this->is_type($appname,"array")) { + while($app = each($appname)) { + $this->add_group_app($group_id,$app[0]); + } + return $this->group_app_string($group_id); + } elseif($this->is_type($appname,"string")) { + $this->add_group_app($group_id,$appname); + return $this->group_app_string($group_id); + } + } + + function add_group_app($group_id,$appname) + { + if ($this->enabled[$appname] && !$this->is_group($group_id,$appname)) { + $this->group_apps[$group_id][] = $appname; + $this->enabled[$appname] = 2; } - return $this->group_app_string($group_id); } function add_user($appname) { - if ($this->get_var("enabled",$appname) && !$this->is_user($appname)) { - $this->set_var("user_apps[]",$appname); - $this->set_var("enabled",2,$appname); + if($this->is_type($appname,"array")) { + while($app = each($appname)) { + $this->add_user_app($app[0]); + } + return $this->user_app_string($group_id); + } elseif($this->is_type($appname,"string")) { + $this->add_user_app($group_id,$appname); + return $this->user_app_string($group_id); + } + } + + function add_user_app($appname) + { + if ($this->enabled[$appname] && !$this->is_user($appname)) { + $this->user_apps[] =$appname; + $this->enabled[$appname] = 2; } - return $this->user_app_string(); } function delete_group($group_id,$appname) @@ -230,9 +287,9 @@ { global $phpgw; - if($this->get_var("account_id")) { + if($this->account_id) { $db2 = $phpgw->db; - $db2->query("UPDATE account SET account_permissions = '".$this->user_app_string()."' WHERE account_id=".$this->get_var("account_id"),__LINE__,__FILE__); + $db2->query("UPDATE account SET account_permissions = '".$this->user_app_string()."' WHERE account_id=".$this->account_id,__LINE__,__FILE__); } } } diff --git a/phpgwapi/inc/class.phpgw.inc.php b/phpgwapi/inc/class.phpgw.inc.php index dc2c2493e8..a70d4dd7aa 100644 --- a/phpgwapi/inc/class.phpgw.inc.php +++ b/phpgwapi/inc/class.phpgw.inc.php @@ -37,6 +37,7 @@ class phpgw { var $accounts; + var $applications; var $acl; var $auth; var $db; @@ -112,10 +113,12 @@ if (empty($phpgw_info["server"]["account_repository"])){$phpgw_info["server"]["account_repository"] = $phpgw_info["server"]["auth_type"];} $this->accounts = CreateObject("phpgwapi.accounts"); $this->preferences = CreateObject("phpgwapi.preferences"); + $this->applications = CreateObject("phpgwapi.applications"); $this->session = CreateObject("phpgwapi.sessions"); if ($phpgw_info["flags"]["currentapp"] == "login") { $log = explode("@",$login); $this->preferences = CreateObject("phpgwapi.preferences", $log[0]); + $this->applications = CreateObject("phpgwapi.applications", $log[0]); }else{ if (! $this->session->verify()) { $this->db->query("select config_value from config where config_name='webserver_url'",__LINE__,__FILE__); @@ -124,6 +127,7 @@ exit; } $this->preferences = CreateObject("phpgwapi.preferences", intval($phpgw_info["user"]["account_id"])); + $this->applications = CreateObject("phpgwapi.applications", intval($phpgw_info["user"]["account_id"])); } $this->translation = CreateObject("phpgwapi.translation");