1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
|
<?php
/**
* Preference storage implementation for an IMSP server.
*
* $Horde: framework/Prefs/Prefs/imsp.php,v 1.1.10.11 2006/02/28 05:59:19 slusarz Exp $
*
* Copyright 2004-2006 Michael Rubinsky <mrubinsk@horde.org>
*
* See the enclosed file COPYING for license information (LGPL). If you
* did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
*
* @author Michael Rubinsky <mrubinsk@horde.org>
* @package Horde_Prefs
*/
class Prefs_imsp extends Prefs {
/**
* Constructor function.
* $params must contain:
* 'auth_method', 'server', 'port'
*
* @param string $user Username of current user.
* @param string $password Password for current user.
* @param string $scope The scope for these preferences.
* @param array $params The parameters needed for this object.
* @param boolean $caching Are we using session cache?
*/
function Prefs_imsp($user, $password = '', $scope = '',
$params = null, $caching = true)
{
global $conf;
parent::Prefs();
require_once 'Net/IMSP.php';
$this->_scope = $scope;
$this->_caching = $caching;
$this->_user = $user;
$this->params = $params;
if (preg_match('/(^.*)@/', $user, $matches)) {
$this->params['username'] = $matches[1];
} else {
$this->params['username'] = $user;
}
$this->params['password'] = $password;
if (isset($this->params['socket'])) {
$this->params['socket'] = $params['socket'] . 'imsp_' . $this->params['username'] . '.sck';
}
$this->_imsp = &Net_IMSP::singleton('Options', $this->params);
$result = $this->_imsp->init();
if (is_a($result, 'PEAR_Error')) {
Horde::fatal($result, __FILE__, __LINE__);
}
$this->_imsp->setLogger($conf['log']);
}
/**
* Retrieves the requested set of preferences from the IMSP server.
*
* @return mixed True on success or a PEAR_Error object on failure.
*/
function retrieve()
{
/* Get the defaults. */
parent::retrieve();
/* Get the shared prefs and remove the scope value from the
* string. */
$global_prefs = $this->_imsp->get('horde.*');
if (is_a($global_prefs, 'PEAR_Error')) {
return $global_prefs;
}
foreach ($global_prefs as $key => $val) {
$newKey = str_replace('horde.', '', $key);
if ($val == '-') {
$val = $this->getDefault($newKey);
}
if (isset($this->_prefs[$newKey])) {
$this->setValue($newKey, $val);
} else {
$this->add($newKey, $val, _PREF_SHARED);
}
/* Don't forget to clean it. */
$this->setDirty($newKey, false);
}
/* Now the app specific prefs. */
$local_prefs = $this->_imsp->get($this->_scope . '.*');
if (is_a($local_prefs, 'PEAR_Error')) {
return $local_prefs;
}
foreach ($local_prefs as $key => $val) {
$newKey = str_replace($this->_scope . '.', '', $key);
if ($val == '-') {
$val = $this->getDefault($newKey);
}
if (isset($this->_prefs[$newKey])) {
$this->setValue($newKey, $val);
} else {
$this->add($newKey, $val, 0);
}
/* Clean the pref. */
$this->setDirty($newKey, false);
}
$this->_callHooks();
$this->cacheUpdate();
return true;
}
/**
* Stores all dirty prefs to IMSP server.
*
* @return mixed True on success or a PEAR_Error object on failure.
*/
function store()
{
$dirty_prefs = $this->_dirtyPrefs();
if (!count($dirty_prefs)) {
return true;
}
foreach ($dirty_prefs as $name) {
$scope = $this->getScope($name);
$value = $this->getValue($name);
if (empty($value)) {
$value = '-';
}
$result = $this->_imsp->set($scope . '.' . $name, $value);
if (is_a($result, 'PEAR_Error')) {
$GLOBALS['notification']->push("There was a problem saving the prefrences");
return $result;
}
/* Clean the pref since it was just saved. */
$this->setDirty($name, false);
}
$this->cacheUpdate();
return true;
}
}
|