2001-01-11 10:52:33 +01:00
|
|
|
<?php
|
|
|
|
/**************************************************************************\
|
2001-01-13 11:18:50 +01:00
|
|
|
* phpGroupWare API - Preferences *
|
|
|
|
* This file written by Joseph Engo <jengo@phpgroupware.org> *
|
|
|
|
* and Mark Peters <skeeter@phpgroupware.org> *
|
|
|
|
* Manages user preferences *
|
|
|
|
* Copyright (C) 2000, 2001 Joseph Engo *
|
|
|
|
* -------------------------------------------------------------------------*
|
2001-01-16 14:52:32 +01:00
|
|
|
* This library is part of the phpGroupWare API *
|
|
|
|
* http://www.phpgroupware.org/api *
|
|
|
|
* ------------------------------------------------------------------------ *
|
2001-01-13 11:18:50 +01:00
|
|
|
* This library is free software; you can redistribute it and/or modify it *
|
|
|
|
* under the terms of the GNU Lesser General Public License as published by *
|
|
|
|
* the Free Software Foundation; either version 2.1 of the License, *
|
|
|
|
* or any later version. *
|
|
|
|
* This library is distributed in the hope that it will be useful, but *
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
|
|
|
|
* See the GNU Lesser General Public License for more details. *
|
|
|
|
* You should have received a copy of the GNU Lesser General Public License *
|
|
|
|
* along with this library; if not, write to the Free Software Foundation, *
|
|
|
|
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
|
2001-01-11 10:52:33 +01:00
|
|
|
\**************************************************************************/
|
|
|
|
|
|
|
|
/* $Id$ */
|
|
|
|
|
|
|
|
class preferences
|
|
|
|
{
|
|
|
|
var $account_id;
|
2001-02-03 11:48:41 +01:00
|
|
|
var $account_type;
|
|
|
|
var $data = Array();
|
2001-01-28 13:07:20 +01:00
|
|
|
var $db;
|
2001-01-11 10:52:33 +01:00
|
|
|
|
2001-02-03 11:48:41 +01:00
|
|
|
/**************************************************************************\
|
|
|
|
* Standard constructor for setting $this->account_id *
|
|
|
|
\**************************************************************************/
|
|
|
|
|
|
|
|
function preferences($account_id = False)
|
2001-01-11 10:52:33 +01:00
|
|
|
{
|
2001-01-28 13:07:20 +01:00
|
|
|
global $phpgw, $phpgw_info;
|
|
|
|
$this->db = $phpgw->db;
|
2001-02-06 13:06:17 +01:00
|
|
|
if ($account_id != False){ $this->account_id = $account_id; }
|
2001-01-28 13:07:20 +01:00
|
|
|
}
|
2001-02-03 11:48:41 +01:00
|
|
|
|
|
|
|
/**************************************************************************\
|
|
|
|
* These are the standard $this->account_id specific functions *
|
|
|
|
\**************************************************************************/
|
|
|
|
|
|
|
|
function read_repository()
|
2001-01-28 13:07:20 +01:00
|
|
|
{
|
|
|
|
$this->db->lock("preferences");
|
2001-02-06 13:38:35 +01:00
|
|
|
$this->db->query("SELECT preference_value FROM preferences WHERE preference_owner='".$this->account_id."'",__LINE__,__FILE__);
|
2001-01-28 13:07:20 +01:00
|
|
|
$this->db->next_record();
|
|
|
|
$pref_info = $this->db->f("preference_value");
|
2001-02-03 11:48:41 +01:00
|
|
|
$this->data = Array();
|
|
|
|
$this->data = unserialize($pref_info);
|
2001-01-28 13:07:20 +01:00
|
|
|
$this->db->unlock();
|
2001-02-03 11:48:41 +01:00
|
|
|
reset ($this->data);
|
|
|
|
return $this->data;
|
2001-01-28 13:07:20 +01:00
|
|
|
}
|
2001-01-11 10:52:33 +01:00
|
|
|
|
2001-02-03 11:48:41 +01:00
|
|
|
function read()
|
2001-01-28 13:07:20 +01:00
|
|
|
{
|
2001-02-03 11:48:41 +01:00
|
|
|
if (count($this->data) == 0){ $this->read_repository(); }
|
|
|
|
reset ($this->data);
|
|
|
|
return $this->data;
|
2001-01-11 10:52:33 +01:00
|
|
|
}
|
|
|
|
|
2001-02-03 11:48:41 +01:00
|
|
|
function add($app_name,$var,$value = "")
|
2001-01-11 10:52:33 +01:00
|
|
|
{
|
2001-02-03 11:48:41 +01:00
|
|
|
if (! $value) {
|
|
|
|
global $$var;
|
|
|
|
$value = $$var;
|
2001-01-11 10:52:33 +01:00
|
|
|
}
|
|
|
|
|
2001-02-04 09:27:35 +01:00
|
|
|
$this->data[$app_name][$var] = $value;
|
2001-02-03 11:48:41 +01:00
|
|
|
reset($this->data);
|
|
|
|
return $this->data;
|
2001-01-11 10:52:33 +01:00
|
|
|
}
|
|
|
|
|
2001-02-03 11:48:41 +01:00
|
|
|
function delete($app_name, $var = "")
|
2001-01-11 10:52:33 +01:00
|
|
|
{
|
2001-02-03 11:48:41 +01:00
|
|
|
if ($var == "") {
|
2001-02-04 09:27:35 +01:00
|
|
|
$this->data[$app_name] = array();
|
2001-02-03 11:48:41 +01:00
|
|
|
} else {
|
2001-02-04 09:27:35 +01:00
|
|
|
unset($this->data[$app_name][$var]);
|
2001-02-03 11:48:41 +01:00
|
|
|
}
|
|
|
|
reset ($this->data);
|
|
|
|
return $this->data;
|
2001-01-11 10:52:33 +01:00
|
|
|
}
|
|
|
|
|
2001-02-03 11:48:41 +01:00
|
|
|
function save_repository()
|
2001-01-11 10:52:33 +01:00
|
|
|
{
|
2001-02-03 11:48:41 +01:00
|
|
|
global $phpgw, $phpgw_info;
|
|
|
|
$this->db->lock("preferences");
|
2001-02-06 21:13:06 +01:00
|
|
|
$this->db->query("delete from preferences where preference_owner='" . $this->account_id . "'",__LINE__,__FILE__);
|
2001-02-03 11:48:41 +01:00
|
|
|
|
|
|
|
if ($PHP_VERSION < "4.0.0") {
|
|
|
|
$pref_info = addslashes(serialize($this->data));
|
|
|
|
} else {
|
|
|
|
$pref_info = serialize($this->data);
|
|
|
|
}
|
|
|
|
|
2001-02-06 21:13:06 +01:00
|
|
|
$this->db->query("insert into preferences (preference_owner,preference_value) values ('"
|
|
|
|
. $this->account_id . "','" . $pref_info . "')",__LINE__,__FILE__);
|
2001-02-03 11:48:41 +01:00
|
|
|
|
|
|
|
$this->db->unlock();
|
|
|
|
return $this->data;
|
|
|
|
}
|
|
|
|
|
|
|
|
function update_data($data) {
|
|
|
|
reset($data);
|
|
|
|
$this->data = Array();
|
|
|
|
$this->data = $data;
|
|
|
|
reset($this->data);
|
|
|
|
return $this->data;
|
2001-01-11 10:52:33 +01:00
|
|
|
}
|
|
|
|
|
2001-02-05 23:30:21 +01:00
|
|
|
// legacy support
|
|
|
|
function change($app_name,$var,$value = "")
|
|
|
|
{
|
|
|
|
return $this->add($app_name,$var,$value);
|
|
|
|
}
|
|
|
|
function commit()
|
|
|
|
{
|
|
|
|
return $this->save_repository();
|
|
|
|
}
|
|
|
|
|
2001-01-11 10:52:33 +01:00
|
|
|
} //end of preferences class
|
2001-02-03 11:48:41 +01:00
|
|
|
?>
|