2018-08-21 14:42:44 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* EGgroupware admin - admin command: edit preferences
|
|
|
|
*
|
|
|
|
* @link http://www.egroupware.org
|
|
|
|
* @author Hadi Nategh <hn@egroupware.org>
|
|
|
|
* @package admin
|
|
|
|
* @copyright (c) 2018 by Hadi Nategh <hn@egroupware.org>
|
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
|
|
|
*/
|
|
|
|
|
2018-08-23 15:24:13 +02:00
|
|
|
use EGroupware\Api;
|
|
|
|
|
2018-08-21 14:42:44 +02:00
|
|
|
/**
|
|
|
|
* admin command: edit preferences
|
2018-08-23 15:24:13 +02:00
|
|
|
*
|
|
|
|
* @property-read int $account numerical account_id
|
|
|
|
* @property-read string $pref "user", "default", "forced" or "group"
|
|
|
|
* @property-read string $app app-name
|
|
|
|
* @property-read array $set values to set
|
|
|
|
* @property-read array $old old values
|
2018-08-21 14:42:44 +02:00
|
|
|
*/
|
|
|
|
class admin_cmd_edit_preferences extends admin_cmd
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Constructor
|
2018-08-23 15:24:13 +02:00
|
|
|
* @param string|int|array $account account name or id, or array with all parameters
|
|
|
|
* @param string $type ="user" "user", "default", "forced" or "group"
|
|
|
|
* @param string $app =null app-name, required if $account is no array
|
|
|
|
* @param array $set =null name => value pairs to change
|
|
|
|
* @param array $old =null name => value pairs of old values
|
|
|
|
* @param array $extra =array() values for keys requested(_email) or comment
|
2018-08-21 14:42:44 +02:00
|
|
|
*/
|
2018-08-23 15:24:13 +02:00
|
|
|
function __construct($account, $type=null, $app=null, array $set=null, array $old=null, array $extra=array())
|
2018-08-21 14:42:44 +02:00
|
|
|
{
|
|
|
|
if (!is_array($account))
|
|
|
|
{
|
|
|
|
$account = array(
|
|
|
|
'account' => $account,
|
2018-08-23 15:24:13 +02:00
|
|
|
'pref' => $type, // type is __CLASS__!
|
|
|
|
'app' => $app,
|
2018-08-21 14:42:44 +02:00
|
|
|
'set' => $set,
|
2018-08-23 15:24:13 +02:00
|
|
|
'old' => $old,
|
|
|
|
)+$extra;
|
2018-08-21 14:42:44 +02:00
|
|
|
}
|
2018-08-23 15:24:13 +02:00
|
|
|
|
2018-08-21 14:42:44 +02:00
|
|
|
admin_cmd::__construct($account);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Edit a preference
|
|
|
|
*
|
|
|
|
* @param boolean $check_only =false only run the checks (and throw the exceptions), but not the command itself
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
protected function exec($check_only=false)
|
|
|
|
{
|
2018-08-23 15:24:13 +02:00
|
|
|
switch($this->pref)
|
|
|
|
{
|
|
|
|
case 'forced':
|
|
|
|
case 'default':
|
|
|
|
unset($this->account);
|
|
|
|
break;
|
|
|
|
case 'user':
|
|
|
|
$this->account = self::parse_account($this->account, true);
|
|
|
|
break;
|
|
|
|
case 'group':
|
|
|
|
$this->account = self::parse_account($this->account, false);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
throw new Api\Exception\WrongUserinput(lang('Invalid type "%1"!', $this->pref));
|
|
|
|
}
|
|
|
|
if ($this->app !== 'common') self::parse_apps(array($this->app));
|
|
|
|
|
2018-08-21 14:42:44 +02:00
|
|
|
if ($check_only) return;
|
2018-08-23 15:24:13 +02:00
|
|
|
|
2018-09-05 18:27:19 +02:00
|
|
|
$prefs = new Api\Preferences(in_array($this->pref, array('default', 'forced')) ? $this->pref : $this->account);
|
2018-08-23 15:24:13 +02:00
|
|
|
$prefs->read_repository();
|
|
|
|
foreach($this->set as $name => $value)
|
|
|
|
{
|
|
|
|
if (!isset($value) || $value === '')
|
|
|
|
{
|
2018-09-04 22:05:58 +02:00
|
|
|
$prefs->delete($this->app, $name, in_array($this->pref, array('default', 'forced')) ? $this->pref : 'user');
|
2018-08-23 15:24:13 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-09-04 22:05:58 +02:00
|
|
|
$prefs->add($this->app, $name, $value, in_array($this->pref, array('default', 'forced')) ? $this->pref : 'user');
|
2018-08-23 15:24:13 +02:00
|
|
|
}
|
|
|
|
}
|
2019-01-10 15:06:05 +01:00
|
|
|
$prefs->save_repository(true, $this->pref == 'group' ? 'user' : $this->pref);
|
|
|
|
|
2018-08-21 14:42:44 +02:00
|
|
|
return lang('Preferences saved.');
|
|
|
|
}
|
2018-08-22 12:26:56 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return a title / string representation for a given command, eg. to display it
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
function __tostring()
|
|
|
|
{
|
2018-08-23 15:24:13 +02:00
|
|
|
switch($this->pref)
|
|
|
|
{
|
|
|
|
case 'forced':
|
|
|
|
return lang('Forced preferences');
|
|
|
|
|
|
|
|
case 'default':
|
|
|
|
return lang('Default preferences');
|
|
|
|
}
|
|
|
|
return lang('Preferences').' '.self::display_account($this->account);
|
2018-08-22 12:26:56 +02:00
|
|
|
}
|
2018-08-21 14:42:44 +02:00
|
|
|
}
|