mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-11-07 16:44:20 +01:00
classes are in the newer format. Still some cleanup to do but the concept is at least in progress
This commit is contained in:
parent
ef7c988605
commit
3ac75481c1
@ -118,7 +118,7 @@
|
||||
//echo "check point 1 - $last_loginid<br>\n";
|
||||
$prefs = CreateObject("phpgwapi.preferences", $last_loginid);
|
||||
//echo "check point 2<br>\n";
|
||||
$phpgw_info["user"]["preferences"] = $prefs->get_saved_preferences();
|
||||
$phpgw_info["user"]["preferences"] = $prefs->read_repository();
|
||||
//echo "check point 3<br>\n";
|
||||
#print "LANG:".$phpgw_info["user"]["preferences"]["common"]["lang"]."<br>";
|
||||
$phpgw->translation->add_app("login");
|
||||
|
@ -95,9 +95,9 @@
|
||||
{
|
||||
global $phpgw_info, $phpgw;
|
||||
|
||||
if (gettype($id) == "string") { $id = $this->username2userid($id); }
|
||||
if (gettype($id) == "string") { $id = $this->name2id($id); }
|
||||
$groups = Array();
|
||||
$group_memberships = $phpgw->acl->get_location_list_for_id("phpgw_group", 1, "u", intval($id));
|
||||
$group_memberships = $phpgw->acl->get_location_list_for_id("phpgw_group", 1, intval($id));
|
||||
if ($group_memberships) {
|
||||
for ($idx=0; $idx<count($group_memberships); $idx++){
|
||||
$groups[$group_memberships[$idx]] = 1;
|
||||
@ -108,7 +108,11 @@
|
||||
}
|
||||
}
|
||||
|
||||
function read_group_names($lid = "")
|
||||
function read_group_names($lid = ""){
|
||||
return $this->security_equals($lid);
|
||||
}
|
||||
|
||||
function security_equals($lid = "")
|
||||
{
|
||||
global $phpgw, $phpgw_info;
|
||||
|
||||
@ -163,24 +167,25 @@
|
||||
return $accounts;
|
||||
}
|
||||
|
||||
function username2userid($user_name)
|
||||
function name2id($account_name)
|
||||
{
|
||||
global $phpgw, $phpgw_info;
|
||||
|
||||
$this->db->query("SELECT account_id FROM accounts WHERE account_lid='".$user_name."'",__LINE__,__FILE__);
|
||||
$this->db->query("SELECT account_id FROM accounts WHERE account_lid='".$account_name."'",__LINE__,__FILE__);
|
||||
if($this->db->num_rows()) {
|
||||
$this->db->next_record();
|
||||
|
||||
return $this->db->f("account_id");
|
||||
}else{
|
||||
return False;
|
||||
}
|
||||
}
|
||||
|
||||
function userid2username($user_id)
|
||||
function id2name($account_id)
|
||||
{
|
||||
global $phpgw, $phpgw_info;
|
||||
|
||||
$this->db->query("SELECT account_lid FROM accounts WHERE account_id='".$user_id."'",__LINE__,__FILE__);
|
||||
$this->db->query("SELECT account_lid FROM accounts WHERE account_id='".$account_id."'",__LINE__,__FILE__);
|
||||
if($this->db->num_rows()) {
|
||||
$this->db->next_record();
|
||||
return $this->db->f("account_lid");
|
||||
@ -189,32 +194,22 @@
|
||||
}
|
||||
}
|
||||
|
||||
function groupname2groupid($group_name)
|
||||
function get_type($account_id)
|
||||
{
|
||||
global $phpgw, $phpgw_info;
|
||||
|
||||
$this->db->query("SELECT group_id FROM groups WHERE group_name='".$group_name."'",__LINE__,__FILE__);
|
||||
/*
|
||||
$this->db->query("SELECT account_type FROM accounts WHERE account_id='".$account_id."'",__LINE__,__FILE__);
|
||||
if($this->db->num_rows()) {
|
||||
$this->db->next_record();
|
||||
return $this->db->f("group_id");
|
||||
return $this->db->f("account_type");
|
||||
}else{
|
||||
return False;
|
||||
}
|
||||
*/
|
||||
return "u";
|
||||
}
|
||||
|
||||
function groupid2groupname($group_id)
|
||||
{
|
||||
global $phpgw, $phpgw_info;
|
||||
|
||||
$this->db->query("SELECT group_name FROM groups WHERE group_id='".$group_id."'",__LINE__,__FILE__);
|
||||
if($this->db->num_rows()) {
|
||||
$this->db->next_record();
|
||||
return $this->db->f("group_name");
|
||||
}else{
|
||||
return False;
|
||||
}
|
||||
}
|
||||
|
||||
function exists($accountname){
|
||||
$this->db->query("SELECT account_id FROM accounts WHERE account_lid='".$accountname."'",__LINE__,__FILE__);
|
||||
if($this->db->num_rows()) {
|
||||
|
@ -25,147 +25,183 @@
|
||||
|
||||
class acl
|
||||
{
|
||||
var $account_id;
|
||||
var $account_type;
|
||||
var $data = Array();
|
||||
var $db;
|
||||
|
||||
function acl()
|
||||
/**************************************************************************\
|
||||
* Standard constructor for setting $this->account_id *
|
||||
\**************************************************************************/
|
||||
|
||||
function acl($account_id = False)
|
||||
{
|
||||
global $phpgw;
|
||||
global $phpgw, $phpgw_info;
|
||||
$this->db = $phpgw->db;
|
||||
if ($account_id == False){
|
||||
$this->account_id = $phpgw_info["user"]["account_id"];
|
||||
} elseif (is_long($account_id)) {
|
||||
$this->account_id = $account_id;
|
||||
} elseif(is_string($account_id)) {
|
||||
$this->account_id = $phpgw->accounts->name2id($account_id);
|
||||
}
|
||||
}
|
||||
|
||||
/* This is a new class. These are sample table entries
|
||||
insert into phpgw_acl (acl_appname, acl_location, acl_account, acl_account_type, acl_rights)
|
||||
values('filemanager', 'create', 1, 'u', 4);
|
||||
insert into phpgw_acl (acl_appname, acl_location, acl_account, acl_account_type, acl_rights)
|
||||
values('filemanager', 'create', 1, 'g', 2);
|
||||
insert into phpgw_acl (acl_appname, acl_location, acl_account, acl_account_type, acl_rights)
|
||||
values('filemanager', 'create', 2, 'u', 1);
|
||||
insert into phpgw_acl (acl_appname, acl_location, acl_account, acl_account_type, acl_rights)
|
||||
values('filemanager', 'create', 2, 'g', 2);
|
||||
*/
|
||||
/**************************************************************************\
|
||||
* These are the standard $this->account_id specific functions *
|
||||
\**************************************************************************/
|
||||
|
||||
function get_rights($location,$appname = False, $user_id = ""){
|
||||
function read_repository()
|
||||
{
|
||||
global $phpgw, $phpgw_info;
|
||||
$sql = "select * from phpgw_acl where (acl_account in (".$this->account_id.", 0";
|
||||
$equalto = $phpgw->accounts->security_equals($this->account_id);
|
||||
if (is_array($equalto) && count($equalto) > 0){
|
||||
for ($idx = 0; $idx < count($equalto); ++$idx){
|
||||
$sql .= ",".$equalto[$idx][0];
|
||||
}
|
||||
}
|
||||
$sql .= "))";
|
||||
$this->db->query($sql ,__LINE__,__FILE__);
|
||||
$count = $this->db->num_rows();
|
||||
$this->data = Array();
|
||||
for ($idx = 0; $idx < $count; ++$idx){
|
||||
//reset ($this->data);
|
||||
//while(list($idx,$value) = each($this->data)){
|
||||
$this->db->next_record();
|
||||
$this->data[] = array("appname" => $this->db->f("acl_appname"),
|
||||
"location" => $this->db->f("acl_location"),
|
||||
"account" => $this->db->f("acl_account"),
|
||||
"rights" => $this->db->f("acl_rights")
|
||||
);
|
||||
}
|
||||
reset ($this->data);
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
function read()
|
||||
{
|
||||
if (count($this->data) == 0){ $this->read_repository(); }
|
||||
reset ($this->data);
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
function add($appname = False, $location, $rights)
|
||||
{
|
||||
if ($appname == False){
|
||||
$appname = $phpgw_info["flags"]["currentapp"];
|
||||
}
|
||||
if($user_id == "") {
|
||||
$user_id = $phpgw_info["user"]["account_id"];
|
||||
}
|
||||
// User piece
|
||||
$sql = "select acl_rights from phpgw_acl where acl_appname='$appname'";
|
||||
$sql .= " and (acl_location in ('$location','everywhere')) and ";
|
||||
$sql .= "((acl_account_type = 'u' and acl_account = ".$user_id.")";
|
||||
$this->data[] = array("appname" => $appname, "location" => $location, "account" => $this->account_id, "rights" => $rights);
|
||||
reset($this->data);
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
// Group piece
|
||||
$sql .= " or (acl_account_type='g' and acl_account in (0"; // group 0 covers all users
|
||||
$memberships = $phpgw->accounts->read_group_names($user_id);
|
||||
if (is_array($memberships) && count($memberships) > 0){
|
||||
for ($idx = 0; $idx < count($memberships); ++$idx){
|
||||
$sql .= ",".$memberships[$idx][0];
|
||||
function delete($appname = False, $location)
|
||||
{
|
||||
if ($appname == False){
|
||||
$appname = $phpgw_info["flags"]["currentapp"];
|
||||
}
|
||||
$count = count($this->data);
|
||||
reset ($this->data);
|
||||
while(list($idx,$value) = each($this->data)){
|
||||
if ($this->data[$idx]["appname"] == $appname && $this->data[$idx]["location"] == $location && $this->data[$idx]["account"] == $this->account_id){
|
||||
$this->data[$idx] = Array();
|
||||
}
|
||||
}
|
||||
$sql .= ")))";
|
||||
$rights = 0;
|
||||
reset($this->data);
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
function save_repository(){
|
||||
global $phpgw, $phpgw_info;
|
||||
reset($this->data);
|
||||
|
||||
$sql = "delete from phpgw_acl where acl_account = ".$this->account_id;
|
||||
$this->db->query($sql ,__LINE__,__FILE__);
|
||||
if ($this->db->num_rows() == 0 && $phpgw_info["server"]["acl_default"] != "deny"){ return True; }
|
||||
while ($this->db->next_record()) {
|
||||
if ($this->db->f("acl_rights") == 0){ return False; }
|
||||
$rights |= $this->db->f("acl_rights");
|
||||
|
||||
$count = count($this->data);
|
||||
reset ($this->data);
|
||||
while(list($idx,$value) = each($this->data)){
|
||||
if ($this->data[$idx]["account"] == $this->account_id){
|
||||
$sql = "insert into phpgw_acl (acl_appname, acl_location, acl_account, acl_rights)";
|
||||
$sql .= " values('".$this->data[$idx]["appname"]."', '".$this->data[$idx]["location"]."', ".$this->account_id.", ".$this->data[$idx]["rights"].")";
|
||||
$this->db->query($sql ,__LINE__,__FILE__);
|
||||
}
|
||||
}
|
||||
reset($this->data);
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
/**************************************************************************\
|
||||
* These are the non-standard $this->account_id specific functions *
|
||||
\**************************************************************************/
|
||||
|
||||
function get_rights($location,$appname = False){
|
||||
global $phpgw, $phpgw_info;
|
||||
if (count($this->data) == 0){ $this->read_repository(); }
|
||||
reset ($this->data);
|
||||
if ($appname == False){
|
||||
$appname = $phpgw_info["flags"]["currentapp"];
|
||||
}
|
||||
$count = count($this->data);
|
||||
if ($count == 0 && $phpgw_info["server"]["acl_default"] != "deny"){ return True; }
|
||||
$rights = 0;
|
||||
// for ($idx = 0; $idx < $count; ++$idx){
|
||||
reset ($this->data);
|
||||
while(list($idx,$value) = each($this->data)){
|
||||
if ($this->data[$idx]["appname"] == $appname) {
|
||||
if ($this->data[$idx]["location"] == $location || $this->data[$idx]["location"] == 'everywhere'){
|
||||
if ($this->data[$idx]["rights"] == 0){ return False; }
|
||||
$rights |= $this->data[$idx]["rights"];
|
||||
}
|
||||
}
|
||||
}
|
||||
return $rights;
|
||||
}
|
||||
|
||||
function check($location, $required, $appname = False, $user_id = ""){
|
||||
function check($location, $required, $appname = False){
|
||||
global $phpgw, $phpgw_info;
|
||||
$rights = $this->get_rights($location,$appname, $user_id);
|
||||
|
||||
$rights = $this->get_rights($location,$appname);
|
||||
return !!($rights & $required);
|
||||
}
|
||||
|
||||
function get_specific_rights($location, $appname = False, $id = "", $id_type = "u"){
|
||||
function get_specific_rights($location, $appname = False){
|
||||
global $phpgw, $phpgw_info;
|
||||
|
||||
if ($appname == False){
|
||||
$appname = $phpgw_info["flags"]["currentapp"];
|
||||
}
|
||||
if($id == "") {
|
||||
$id = $phpgw_info["user"]["account_id"];
|
||||
}
|
||||
// User piece
|
||||
$sql = "select acl_rights from phpgw_acl where acl_appname='$appname'";
|
||||
$sql .= " and acl_location = '$location' and ";
|
||||
$sql .= "acl_account_type = '".$id_type."' and acl_account = ".$id;
|
||||
$this->db->query($sql ,__LINE__,__FILE__);
|
||||
|
||||
$count = count($this->data);
|
||||
if ($count == 0 && $phpgw_info["server"]["acl_default"] != "deny"){ return True; }
|
||||
$rights = 0;
|
||||
if ($this->db->num_rows() == 0 && $phpgw_info["server"]["acl_default"] != "deny"){
|
||||
return True;
|
||||
}
|
||||
while ($this->db->next_record()) {
|
||||
if ($this->db->f("acl_rights") == 0){ return False; }
|
||||
$rights |= $this->db->f("acl_rights");
|
||||
|
||||
reset ($this->data);
|
||||
while(list($idx,$value) = each($this->data)){
|
||||
if ($this->data[$idx]["appname"] == $appname &&
|
||||
($this->data[$idx]["location"] == $location || $this->data[$idx]["location"] == 'everywhere') &&
|
||||
$this->data[$idx]["account"] == $this->account_id) {
|
||||
if ($this->data[$idx]["rights"] == 0){ return False; }
|
||||
$rights |= $this->data[$idx]["rights"];
|
||||
}
|
||||
}
|
||||
return $rights;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
function check_specific($location, $required, $appname = False){
|
||||
$rights = $this->get_specific_rights($location,$appname);
|
||||
return !!($rights & $required);
|
||||
}
|
||||
|
||||
function add($app, $location, $id, $id_type, $rights){
|
||||
$sql = "insert into phpgw_acl (acl_appname, acl_location, acl_account, acl_account_type, acl_rights)";
|
||||
$sql .= " values('".$app."', '".$location."', ".$id.", '".$id_type."', ".$rights.")";
|
||||
$this->db->query($sql ,__LINE__,__FILE__);
|
||||
return True;
|
||||
}
|
||||
|
||||
function delete($app, $location, $id, $id_type){
|
||||
$sql = "delete from phpgw_acl where acl_appname like '".$app."'"
|
||||
. " and acl_location like '".$location."' and "
|
||||
. " acl_account_type = '".$id_type."' and acl_account = ".$id;
|
||||
$this->db->query($sql ,__LINE__,__FILE__);
|
||||
return $this->db->num_rows();
|
||||
}
|
||||
|
||||
function replace($app, $location, $id, $id_type, $rights){
|
||||
$this->delete($app, $location, $id, $id_type);
|
||||
$this->add($app, $location, $id, $id_type, $rights);
|
||||
return True;
|
||||
}
|
||||
|
||||
function get_app_list_for_id($location, $required, $id = "", $id_type = "u"){
|
||||
global $phpgw, $phpgw_info;
|
||||
if ($id == ""){ $id = $phpgw_info["user"]["account_id"]; }
|
||||
$sql = "select acl_appname, acl_rights from phpgw_acl where acl_location = '$location' and ";
|
||||
$sql .= "acl_account_type = '".$id_type."' and acl_account = ".$id;
|
||||
$this->db->query($sql ,__LINE__,__FILE__);
|
||||
$rights = 0;
|
||||
if ($this->db->num_rows() == 0 ){ return False; }
|
||||
while ($this->db->next_record()) {
|
||||
if ($this->db->f("acl_rights") == 0){ return False; }
|
||||
$rights |= $this->db->f("acl_rights");
|
||||
if (!!($rights & $required) == True){
|
||||
$apps[] = $this->db->f("acl_appname");
|
||||
}
|
||||
}
|
||||
return $apps;
|
||||
}
|
||||
|
||||
function get_location_list($app, $required){
|
||||
global $phpgw, $phpgw_info;
|
||||
// User piece
|
||||
$sql = "select acl_location, acl_rights from phpgw_acl where acl_appname = '$app' ";
|
||||
$sql .= " and ((acl_account_type = 'u' and acl_account = '".$phpgw_info["user"]["account_id"]."')";
|
||||
|
||||
// Group piece
|
||||
$sql .= " or (acl_account_type='g' and acl_account in (0"; // group 0 covers all users
|
||||
$memberships = $phpgw->accounts->read_group_names($phpgw_info["user"]["account_id"]);
|
||||
if (is_array($memberships) && count($memberships) > 0){
|
||||
for ($idx = 0; $idx < count($memberships); ++$idx){
|
||||
$sql .= ",".$memberships[$idx][0];
|
||||
$sql .= " and (acl_account in ('".$this->account_id."', 0"; // group 0 covers all users
|
||||
$equalto = $phpgw->accounts->security_equals($this->account_id);
|
||||
if (is_array($equalto) && count($equalto) > 0){
|
||||
for ($idx = 0; $idx < count($equalto); ++$idx){
|
||||
$sql .= ",".$equalto[$idx][0];
|
||||
}
|
||||
}
|
||||
$sql .= ")))";
|
||||
@ -185,12 +221,80 @@
|
||||
return $locations;
|
||||
}
|
||||
|
||||
function get_location_list_for_id($app, $required, $id_type = "", $id = ""){
|
||||
/*
|
||||
This is kinda how the function SHOULD work, so that it doesnt need to do its own sql query.
|
||||
It should use the values in the $this->data
|
||||
|
||||
function get_location_list($app, $required){
|
||||
global $phpgw, $phpgw_info;
|
||||
if ($id == ""){ $id = $phpgw_info["user"]["account_id"]; }
|
||||
if ($id_type == ""){ $id_type = "u"; }
|
||||
if ($appname == False){
|
||||
$appname = $phpgw_info["flags"]["currentapp"];
|
||||
}
|
||||
|
||||
$count = count($this->data);
|
||||
if ($count == 0 && $phpgw_info["server"]["acl_default"] != "deny"){ return True; }
|
||||
$rights = 0;
|
||||
|
||||
reset ($this->data);
|
||||
while(list($idx,$value) = each($this->data)){
|
||||
if ($this->data[$idx]["appname"] == $appname && $this->data[$idx]["rights"] != 0){
|
||||
$location_rights[$this->data[$idx]["location"]] |= $this->data[$idx]["rights"];
|
||||
}
|
||||
}
|
||||
reset($location_rights);
|
||||
for ($idx = 0; $idx < count($location_rights); ++$idx){
|
||||
if (!!($location_rights[$idx] & $required) == True){
|
||||
$location_rights[] = $this->data[$idx]["location"];
|
||||
}
|
||||
}
|
||||
return $locations;
|
||||
}
|
||||
*/
|
||||
|
||||
/**************************************************************************\
|
||||
* These are the generic functions. Not specific to $this->account_id *
|
||||
\**************************************************************************/
|
||||
|
||||
function add_repository($app, $location, $account_id, $rights){
|
||||
$this->delete_repository($app, $location, $account_id);
|
||||
$sql = "insert into phpgw_acl (acl_appname, acl_location, acl_account, acl_rights)";
|
||||
$sql .= " values('".$app."', '".$location."', ".$account_id.", ".$rights.")";
|
||||
$this->db->query($sql ,__LINE__,__FILE__);
|
||||
return True;
|
||||
}
|
||||
|
||||
function delete_repository($app, $location, $account_id){
|
||||
$sql = "delete from phpgw_acl where acl_appname like '".$app."'"
|
||||
. " and acl_location like '".$location."' and "
|
||||
. " acl_account = ".$account_id;
|
||||
$this->db->query($sql ,__LINE__,__FILE__);
|
||||
return $this->db->num_rows();
|
||||
}
|
||||
|
||||
|
||||
function get_app_list_for_id($location, $required, $account_id = False){
|
||||
global $phpgw, $phpgw_info;
|
||||
if ($account_id == False){ $account_id = $this->account_id; }
|
||||
$sql = "select acl_appname, acl_rights from phpgw_acl where acl_location = '$location' and ";
|
||||
$sql .= "acl_account = ".$account_id;
|
||||
$this->db->query($sql ,__LINE__,__FILE__);
|
||||
$rights = 0;
|
||||
if ($this->db->num_rows() == 0 ){ return False; }
|
||||
while ($this->db->next_record()) {
|
||||
if ($this->db->f("acl_rights") == 0){ return False; }
|
||||
$rights |= $this->db->f("acl_rights");
|
||||
if (!!($rights & $required) == True){
|
||||
$apps[] = $this->db->f("acl_appname");
|
||||
}
|
||||
}
|
||||
return $apps;
|
||||
}
|
||||
|
||||
function get_location_list_for_id($app, $required, $account_id = False){
|
||||
global $phpgw, $phpgw_info;
|
||||
if ($account_id == False){ $account_id = $phpgw_info["user"]["account_id"]; }
|
||||
$sql = "select acl_location, acl_rights from phpgw_acl where acl_appname = '$app' and ";
|
||||
$sql .= "acl_account_type = '".$id_type."' and acl_account = ".$id;
|
||||
$sql .= "acl_account = ".$account_id;
|
||||
$this->db->query($sql ,__LINE__,__FILE__);
|
||||
$rights = 0;
|
||||
if ($this->db->num_rows() == 0 ){ return False; }
|
||||
@ -205,13 +309,13 @@
|
||||
return $locations;
|
||||
}
|
||||
|
||||
function get_ids_for_location($location, $required, $app = False, $id_type = "u"){
|
||||
function get_ids_for_location($location, $required, $app = False){
|
||||
global $phpgw, $phpgw_info;
|
||||
if ($app == False){
|
||||
$app = $phpgw_info["flags"]["currentapp"];
|
||||
}
|
||||
$sql = "select acl_account, acl_rights from phpgw_acl where acl_appname = '$app' and ";
|
||||
$sql .= "acl_account_type = '".$id_type."' and acl_location = '".$location."'";
|
||||
$sql .= "acl_location = '".$location."'";
|
||||
$this->db->query($sql ,__LINE__,__FILE__);
|
||||
$rights = 0;
|
||||
if ($this->db->num_rows() == 0 ){ return False; }
|
||||
|
@ -26,65 +26,108 @@
|
||||
{
|
||||
var $account_id;
|
||||
var $account_type;
|
||||
var $account_apps = Array(Array());
|
||||
var $data = Array();
|
||||
var $db;
|
||||
|
||||
function applications($params = "")
|
||||
/**************************************************************************\
|
||||
* Standard constructor for setting $this->account_id *
|
||||
\**************************************************************************/
|
||||
function applications($account_id = "")
|
||||
{
|
||||
global $phpgw, $phpgw_info;
|
||||
$this->db = $phpgw->db;
|
||||
if (is_array($params)) {
|
||||
if (isset($params[1])){
|
||||
$this->account_type = $params[1];
|
||||
}else{
|
||||
$this->account_type = "u";
|
||||
}
|
||||
if ($params[0] == ""){
|
||||
$this->account_id = $phpgw_info["user"]["account_id"];
|
||||
} elseif (is_long($params[0])) {
|
||||
$this->account_id = $params[0];
|
||||
} elseif(is_string($params[0])) {
|
||||
if ($this->account_type = "u"){
|
||||
$this->account_id = $phpgw->accounts->username2userid($params[0]);
|
||||
}else{
|
||||
$this->account_id = $phpgw->accounts->groupname2groupid($params[0]);
|
||||
}
|
||||
}
|
||||
}else{
|
||||
if ($account_id == ""){
|
||||
$this->account_id = $phpgw_info["user"]["account_id"];
|
||||
$this->account_type = "u";
|
||||
} elseif (is_long($account_id)) {
|
||||
$this->account_id = $account_id;
|
||||
} elseif(is_string($account_id)) {
|
||||
$this->account_id = $phpgw->accounts->name2id($account_id);
|
||||
}
|
||||
$this->account_type = $phpgw->accounts->get_type($account_id);
|
||||
}
|
||||
|
||||
function enabled_apps()
|
||||
/**************************************************************************\
|
||||
* These are the standard $this->account_id specific functions *
|
||||
\**************************************************************************/
|
||||
|
||||
function read_repository()
|
||||
{
|
||||
global $phpgw, $phpgw_info;
|
||||
if (gettype($phpgw_info["apps"]) != "array") {
|
||||
$this->read_installed_apps();
|
||||
}
|
||||
@reset($phpgw_info["apps"]);
|
||||
$this->data = Array();
|
||||
reset($phpgw_info["apps"]);
|
||||
while ($app = each($phpgw_info["apps"])) {
|
||||
if ($this->account_type == "g") {
|
||||
$check = $phpgw->acl->check_specific("run",1,$app[0], $this->account_id, "g");
|
||||
}else{
|
||||
$check = $phpgw->acl->check("run",1,$app[0], $this->account_id);
|
||||
}
|
||||
$check = $phpgw->acl->check("run",1,$app[0]);
|
||||
if ($check) {
|
||||
$this->account_apps[$app[0]] = array("title" => $phpgw_info["apps"][$app[0]]["title"], "name" => $app[0], "enabled" => True, "status" => $phpgw_info["apps"][$app[0]]["status"]);
|
||||
$this->data[$app[0]] = array("title" => $phpgw_info["apps"][$app[0]]["title"], "name" => $app[0], "enabled" => True, "status" => $phpgw_info["apps"][$app[0]]["status"]);
|
||||
}
|
||||
}
|
||||
return $this->account_apps;
|
||||
reset($this->data);
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
function read() {
|
||||
if (count($this->data) == 0){ $this->read_repository(); }
|
||||
reset($this->data);
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
function add($apps) {
|
||||
global $phpgw_info;
|
||||
if(gettype($apps) == "array") {
|
||||
while($app = each($apps)) {
|
||||
$this->data[$app[1]] = array("title" => $phpgw_info["apps"][$app[1]]["title"], "name" => $app[1], "enabled" => True, "status" => $phpgw_info["apps"][$app[1]]["status"]);
|
||||
}
|
||||
} elseif(gettype($apps) == "string") {
|
||||
$this->data[$apps] = array("title" => $phpgw_info["apps"][$apps]["title"], "name" => $apps, "enabled" => True, "status" => $phpgw_info["apps"][$apps]["status"]);
|
||||
}
|
||||
reset($this->data);
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
function delete($appname) {
|
||||
if($this->data[$appname]) {
|
||||
unset($this->data[$appname]);
|
||||
}
|
||||
reset($this->data);
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
function update_data($data) {
|
||||
reset($data);
|
||||
$this->data = Array();
|
||||
$this->data = $data;
|
||||
reset($this->data);
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
function save_repository(){
|
||||
global $phpgw;
|
||||
$num_rows = $phpgw->acl->delete("%%", "run", $this->account_id);
|
||||
reset($this->data);
|
||||
while($app = each($this->data)) {
|
||||
if(!$this->is_system_enabled($app[0])) { continue; }
|
||||
$phpgw->acl->add($app[0],'run',$this->account_id,1);
|
||||
}
|
||||
reset($this->data);
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
/**************************************************************************\
|
||||
* These are the non-standard $this->account_id specific functions *
|
||||
\**************************************************************************/
|
||||
|
||||
function app_perms()
|
||||
{
|
||||
global $phpgw, $phpgw_info;
|
||||
if (count($this->account_apps) == 0) {
|
||||
$this->enabled_apps();
|
||||
if (count($this->data) == 0) {
|
||||
$this->read_repository();
|
||||
}
|
||||
@reset($this->account_apps);
|
||||
while (list ($key) = each ($this->account_apps)) {
|
||||
$app[] = $this->account_apps[$key]["name"];
|
||||
@reset($this->data);
|
||||
while (list ($key) = each ($this->data)) {
|
||||
$app[] = $this->data[$key]["name"];
|
||||
}
|
||||
return $app;
|
||||
}
|
||||
@ -96,52 +139,27 @@
|
||||
}
|
||||
@reset($phpgw_info["apps"]);
|
||||
while ($app = each($phpgw_info["apps"])) {
|
||||
if ($phpgw->acl->check_specific("run",1,$app[0], $this->account_id, $this->account_type) && $this->is_system_enabled($app[0])) {
|
||||
$this->account_apps[$app[0]] = array("title" => $phpgw_info["apps"][$app[0]]["title"], "name" => $app[0], "enabled" => True, "status" => $phpgw_info["apps"][$app[0]]["status"]);
|
||||
if ($phpgw->acl->check_specific("run",1,$app[0], $this->account_id) && $this->is_system_enabled($app[0])) {
|
||||
$this->data[$app[0]] = array("title" => $phpgw_info["apps"][$app[0]]["title"], "name" => $app[0], "enabled" => True, "status" => $phpgw_info["apps"][$app[0]]["status"]);
|
||||
}
|
||||
}
|
||||
return $this->account_apps;
|
||||
reset($this->data);
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
function add_app($apps) {
|
||||
if(gettype($apps) == "array") {
|
||||
while($app = each($apps)) {
|
||||
$this->account_apps[$app[1]] = array("title" => $phpgw_info["apps"][$app[1]]["title"], "name" => $app[1], "enabled" => True, "status" => $phpgw_info["apps"][$app[1]]["status"]);
|
||||
}
|
||||
} elseif(gettype($apps) == "string") {
|
||||
$this->account_apps[$apps] = array("title" => $phpgw_info["apps"][$apps]["title"], "name" => $apps, "enabled" => True, "status" => $phpgw_info["apps"][$apps]["status"]);
|
||||
}
|
||||
reset($this->account_apps);
|
||||
return $this->account_apps;
|
||||
}
|
||||
|
||||
function delete_app($appname) {
|
||||
unset($this->account_apps[$appname]);
|
||||
reset($this->account_apps);
|
||||
return $this->account_apps;
|
||||
}
|
||||
|
||||
function save_apps(){
|
||||
global $phpgw, $phpgw_info;
|
||||
$num_rows = $phpgw->acl->delete("%%", "run", $this->account_id, $this->account_type);
|
||||
reset($this->account_apps);
|
||||
while($app = each($this->account_apps)) {
|
||||
if(!$phpgw_info["apps"][$app[0]]["enabled"]) { continue; }
|
||||
$phpgw->acl->add($app[0],'run',$this->account_id,$this->account_type,1);
|
||||
}
|
||||
reset($this->account_apps);
|
||||
return $this->account_apps;
|
||||
}
|
||||
/**************************************************************************\
|
||||
* These are the generic functions. Not specific to $this->account_id *
|
||||
\**************************************************************************/
|
||||
|
||||
function read_installed_apps(){
|
||||
global $phpgw, $phpgw_info;
|
||||
global $phpgw_info;
|
||||
$this->db->query("select * from applications where app_enabled != '0' order by app_order asc",__LINE__,__FILE__);
|
||||
if($this->db->num_rows()) {
|
||||
while ($this->db->next_record()) {
|
||||
$name = $this->db->f("app_name");
|
||||
$title = $this->db->f("app_title");
|
||||
$status = $this->db->f("app_enabled");
|
||||
$phpgw_info["apps"][$name] = array("title" => $title, "name" => $name, "enabled" => True, "status" => $status);
|
||||
$phpgw_info["apps"]["$name"] = array("title" => $title, "name" => $name, "enabled" => True, "status" => $status);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -158,4 +176,4 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
?>
|
@ -127,9 +127,11 @@
|
||||
exit;
|
||||
}
|
||||
$this->preferences = CreateObject("phpgwapi.preferences", intval($phpgw_info["user"]["account_id"]));
|
||||
$this->applications = CreateObject("phpgwapi.applications", array(intval($phpgw_info["user"]["account_id"]),'u'));
|
||||
$phpgw_info["user"]["preferences"] = $this->preferences->get_saved_preferences();
|
||||
$phpgw_info["user"]["apps"] = $this->applications->enabled_apps();
|
||||
$this->applications = CreateObject("phpgwapi.applications", intval($phpgw_info["user"]["account_id"]));
|
||||
$this->acl = CreateObject("phpgwapi.acl", intval($phpgw_info["user"]["account_id"]));
|
||||
$phpgw_info["user"]["acl"] = $this->acl->read_repository();
|
||||
$phpgw_info["user"]["preferences"] = $this->preferences->read_repository();
|
||||
$phpgw_info["user"]["apps"] = $this->applications->read_repository();
|
||||
@reset($phpgw_info["user"]["apps"]);
|
||||
}
|
||||
$this->translation = CreateObject("phpgwapi.translation");
|
||||
|
@ -27,98 +27,100 @@
|
||||
class preferences
|
||||
{
|
||||
var $account_id;
|
||||
var $preference = Array();
|
||||
var $account_type;
|
||||
var $data = Array();
|
||||
var $db;
|
||||
|
||||
function preferences($account_id = "")
|
||||
/**************************************************************************\
|
||||
* Standard constructor for setting $this->account_id *
|
||||
\**************************************************************************/
|
||||
|
||||
function preferences($account_id = False)
|
||||
{
|
||||
global $phpgw, $phpgw_info;
|
||||
$this->db = $phpgw->db;
|
||||
if ($account_id == ""){
|
||||
if ($account_id == False){
|
||||
$this->account_id = $phpgw_info["user"]["account_id"];
|
||||
}elseif (is_long($account_id)) {
|
||||
} elseif (is_long($account_id)) {
|
||||
$this->account_id = $account_id;
|
||||
} elseif(is_string($account_id)) {
|
||||
$this->account_id = $phpgw->accounts->username2userid($account_id);
|
||||
$this->account_id = $phpgw->accounts->name2id($account_id);
|
||||
}
|
||||
//echo "Account ID (Initializing prefs) = ".$this->account_id."<br>\n";
|
||||
}
|
||||
|
||||
function get_saved_preferences()
|
||||
|
||||
/**************************************************************************\
|
||||
* These are the standard $this->account_id specific functions *
|
||||
\**************************************************************************/
|
||||
|
||||
function read_repository()
|
||||
{
|
||||
global $phpgw;
|
||||
$this->db->lock("preferences");
|
||||
$this->db->query("SELECT preference_value FROM preferences WHERE preference_owner=".$this->account_id,__LINE__,__FILE__);
|
||||
$this->db->next_record();
|
||||
$pref_info = $this->db->f("preference_value");
|
||||
$this->preference = Array();
|
||||
$this->preference = unserialize($pref_info);
|
||||
$this->data = Array();
|
||||
$this->data = unserialize($pref_info);
|
||||
$this->db->unlock();
|
||||
return $this->preference;
|
||||
reset ($this->data);
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
|
||||
function get_preferences()
|
||||
function read()
|
||||
{
|
||||
global $phpgw;
|
||||
return $this->preference;
|
||||
if (count($this->data) == 0){ $this->read_repository(); }
|
||||
reset ($this->data);
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
// This should be called when you are done makeing changes to the preferences
|
||||
function commit($line = "",$file = "")
|
||||
function add($app_name,$var,$value = "")
|
||||
{
|
||||
global $phpgw, $phpgw_info;
|
||||
|
||||
//echo "<br>commit called<br>Line: $line<br>File: $file".$phpgw_info["user"]["account_id"]."<br>";
|
||||
if ($this->account_id) {
|
||||
$this->db->lock("preferences");
|
||||
$this->db->query("delete from preferences where preference_owner=" . $this->account_id,__LINE__,__FILE__);
|
||||
|
||||
if ($PHP_VERSION < "4.0.0") {
|
||||
$pref_info = addslashes(serialize($this->preference));
|
||||
} else {
|
||||
$pref_info = serialize($this->preference);
|
||||
}
|
||||
|
||||
$this->db->query("insert into preferences (preference_owner,preference_value) values ("
|
||||
. $this->account_id . ",'" . $pref_info . "')",__LINE__,__FILE__);
|
||||
|
||||
$this->db->unlock();
|
||||
|
||||
if ($phpgw_info["user"]["account_id"] == $this->account_id) {
|
||||
$this->get_saved_preferences();
|
||||
$phpgw->accounts->sync(__LINE__,__FILE__);
|
||||
}
|
||||
if (! $value) {
|
||||
global $$var;
|
||||
$value = $$var;
|
||||
}
|
||||
}
|
||||
|
||||
// Add a new preference.
|
||||
function change($app_name,$var,$value = "")
|
||||
{
|
||||
global $phpgw_info;
|
||||
|
||||
if (! $value) {
|
||||
global $$var;
|
||||
$value = $$var;
|
||||
}
|
||||
|
||||
$this->preference["$app_name"]["$var"] = $value;
|
||||
$this->data["$app_name"]["$var"] = $value;
|
||||
reset($this->data);
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
function delete($app_name,$var)
|
||||
function delete($app_name, $var = "")
|
||||
{
|
||||
if (! $var) {
|
||||
$this->reset($app_name);
|
||||
} else {
|
||||
unset($this->preference["$app_name"]["$var"]);
|
||||
}
|
||||
if ($var == "") {
|
||||
$this->data["$app_name"] = array();
|
||||
} else {
|
||||
unset($this->data["$app_name"]["$var"]);
|
||||
}
|
||||
reset ($this->data);
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
// This will kill all preferences within a certain app
|
||||
function reset($app_name)
|
||||
function save_repository()
|
||||
{
|
||||
$this->preference["$app_name"] = array();
|
||||
global $phpgw, $phpgw_info;
|
||||
$this->db->lock("preferences");
|
||||
$this->db->query('delete from preferences where preference_owner=' . $this->account_id,__LINE__,__FILE__);
|
||||
|
||||
if ($PHP_VERSION < "4.0.0") {
|
||||
$pref_info = addslashes(serialize($this->data));
|
||||
} else {
|
||||
$pref_info = serialize($this->data);
|
||||
}
|
||||
|
||||
$this->db->query('insert into preferences (preference_owner,preference_value) values ('
|
||||
. $this->account_id . ",'" . $pref_info . "')",__LINE__,__FILE__);
|
||||
|
||||
$this->db->unlock();
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
function update_data($data) {
|
||||
reset($data);
|
||||
$this->data = Array();
|
||||
$this->data = $data;
|
||||
reset($this->data);
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
} //end of preferences class
|
||||
?>
|
||||
?>
|
||||
|
Loading…
Reference in New Issue
Block a user