} catch (\Exception $e) { \OCP\JSON::error(array('message' => $e->getMessage())); exit; } \OCP\JSON::error(); exit; break; case 'save': $key = isset($_POST['cfgkey']) ? $_POST['cfgkey'] : false; $val = isset($_POST['cfgval']) ? $_POST['cfgval'] : null; if ($key === false || is_null($val)) { \OCP\JSON::error(array('message' => $l->t('No data specified'))); exit; } $cfg = array($key => $val); $setParameters = array(); $configuration->setConfiguration($cfg, $setParameters); if (!in_array($key, $setParameters)) { \OCP\JSON::error(array('message' => $l->t($key . ' Could not set configuration %s', $setParameters[0]))); exit; } $configuration->saveConfiguration(); //clear the cache on save $connection = new \OCA\user_ldap\lib\Connection($ldapWrapper, $prefix); $connection->clearCache(); OCP\JSON::success(); break; default: \OCP\JSON::error(array('message' => $l->t('Action does not exist'))); break; }
<?php // Check user and app status OCP\JSON::checkAdminUser(); OCP\JSON::checkAppEnabled('user_ldap'); OCP\JSON::callCheck(); $helper = new \OCA\user_ldap\lib\Helper(); $serverConnections = $helper->getServerConfigurationPrefixes(); sort($serverConnections); $lk = array_pop($serverConnections); $ln = intval(str_replace('s', '', $lk)); $nk = 's' . str_pad($ln + 1, 2, '0', STR_PAD_LEFT); $resultData = array('configPrefix' => $nk); $newConfig = new \OCA\user_ldap\lib\Configuration($nk, false); if (isset($_POST['copyConfig'])) { $originalConfig = new \OCA\user_ldap\lib\Configuration($_POST['copyConfig']); $newConfig->setConfiguration($originalConfig->getConfiguration()); } else { $configuration = new \OCA\user_ldap\lib\Configuration($nk, false); $newConfig->setConfiguration($configuration->getDefaults()); $resultData['defaults'] = $configuration->getDefaults(); } $newConfig->saveConfiguration(); OCP\JSON::success($resultData);