Commit c2c216a9 authored by Ulbrich, Christopher's avatar Ulbrich, Christopher
Browse files

added functions to modify plugin settings & read available plugins

parent e4d145de
......@@ -179,4 +179,98 @@ class RemoteControlHandler extends remotecontrol_handle
// How can we set parameters for the createPassword() function?
/**
* Get PluginID
*
* Function to get the ID of a plugin with a known name
*
* @access public
* @param string $sSessionKey Auth Credentials
* @param string $sPluginName name of Plugin to search for
* @return string|array The requested value or an array with the error in case of error
*/
public function get_plugin_id($sSessionKey, $sPluginName)
{
if ($this->_checkSessionKey($sSessionKey)) {
if (!Permission::model()->hasGlobalPermission('settings', 'read')) {
return array('status' => 'Permission to read settings denied');
}
$aoPlugins = Plugin::model()->findAll();
foreach ($aoPlugins as $oPlugin) {
if ($oPlugin->name == $sPluginName){
return $oPlugin->id;
}
}
return NULL;
} else {
return array('status' => 'Invalid session key');
}
}
/**
* Get plugin configuration description
*
* Function get plugin config parameter description for a plugin with a known ID
*
* @access public
* @param string $sSessionKey Auth Credentials
* @param string $iPluginID ID of plugin to describe
* @return string|array The requested value or an array with the error in case of error
*/
public function get_plugin_config($sSessionKey, $iPluginID)
{
if ($this->_checkSessionKey($sSessionKey)) {
if (!Permission::model()->hasGlobalPermission('settings', 'read')) {
return array('status' => 'Permission to read settings denied');
}
$arPlugin = Plugin::model()->findByPk($iPluginID)->attributes;
if ($arPlugin === null) {
return array('status' => 'The plugin was not found.');
}
$oPluginObject = App()->getPluginManager()->loadPlugin($arPlugin['name'], $arPlugin['id']);
$aSettings = $oPluginObject->getPluginSettings(false);
return $aSettings;
} else {
return array('status' => 'Invalid session key');
}
}
/**
* Set plugin configuration value
*
* Function set plugin config values for a plugin with a known name
*
* @access public
* @param string $sSessionKey Auth Credentials
* @param string $sPluginName name of the plugin to configure
* @param string $sConfigName name of the config option to set
* @param string $sConfigValue value to set for the config option
* @return string|array The requested value or an array with the error in case of error
*/
public function set_plugin_config($sSessionKey, $sPluginName, $sConfigName, $sConfigValue)
{
if ($this->_checkSessionKey($sSessionKey)) {
if (!Permission::model()->hasGlobalPermission('settings', 'update')) {
return array('status' => 'Permission to change settings denied');
}
$aoPlugins = Plugin::model()->findAll();
foreach ($aoPlugins as $oPlugin) {
if ($oPlugin->name == $sPluginName){
$oPluginObject = App()->getPluginManager()->loadPlugin($oPlugin->name, $oPlugin->id);
$aSave = array();
$aSave[$sConfigName] = $sConfigValue;
$oPluginObject->saveSettings($aSave);
return true;
}
}
return array('status' => 'The plugin was not found.');
} else {
return array('status' => 'Invalid session key');
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment