Licensed under the GNU GPL version 2 or any later. See file COPYRIGHT for details.
*/
require_once('./init.php');
$lang = Lang::instance();
if ( !is_logged() ) {
die("Access denied!
Disable password protection or Log in.");
}
if(isset($_POST['save']))
{
check_token();
$t = array();
$langs = getLangs();
Config::$params['lang']['options'] = array_keys($langs);
Config::set('lang', _post('lang'));
// in Demo mode we can set only language by cookies
if (defined('MTT_DEMO')) {
setcookie('lang', Config::get('lang'), 0, url_dir(Config::get('url')=='' ? getRequestUri() : Config::getUrl('url')));
$t['saved'] = 1;
jsonExit($t);
}
if (isset($_POST['password']) && $_POST['password'] != '') Config::set('password', passwordHash($_POST['password'])) ;
elseif (!_post('allowpassword')) Config::set('password', '');
Config::set('smartsyntax', (int)_post('smartsyntax'));
// Do not set invalid timezone
try {
$tz = trim(_post('timezone'));
$testTZ = new DateTimeZone($tz); //will throw Exception on invalid timezone
Config::set('timezone', $tz);
}
catch (Exception $e) {
}
Config::set('autotag', (int)_post('autotag'));
Config::set('markup', (int)_post('markdown') == 0 ? 'v1' : 'markdown');
Config::set('firstdayofweek', (int)_post('firstdayofweek'));
Config::set('clock', (int)_post('clock'));
Config::set('dateformat', removeNewLines(_post('dateformat')) );
Config::set('dateformat2', removeNewLines(_post('dateformat2')) );
Config::set('dateformatshort', removeNewLines(_post('dateformatshort')) );
Config::set('title', removeNewLines(trim(_post('title'))) );
Config::set('showdate', (int)_post('showdate'));
Config::set('showtime', (int)_post('showtime'));
Config::set('showdateInline', (int)_post('showdateInline'));
Config::set('exactduedate', (int)_post('exactduedate'));
Config::set('appearance', removeNewLines(trim(_post('appearance'))) );
Config::set('newTaskCounter', (int)_post('newTaskCounter'));
Config::set('newTaskCounterIcon', (int)_post('newTaskCounterIcon'));
Config::save();
$t['saved'] = 1;
jsonExit($t);
}
else if (isset($_POST['activate']))
{
check_token();
$t = array('saved'=>0);
// in Demo mode we do nothing
if (defined('MTT_DEMO')) {
$t['saved'] = 1;
jsonExit($t);
}
$activate = (int)_post('activate');
$ext = _post('ext');
$extBundles = MTTExtensionLoader::bundles();
$exts = array_keys($extBundles);
$a = Config::get('extensions');
if (!is_array($a)) $a = [];
if (in_array($ext, $exts)) {
if ($activate) {
try {
MTTExtensionLoader::loadExtension($ext);
$a[] = $ext;
}
catch (Exception $e) {
http_response_code(500);
logAndDie($e->getMessage());
}
}
else $a = array_values(array_diff($a, [$ext]));
Config::set('extensions', $a);
Config::save();
}
else if (!$activate && in_array($ext, $a)) {
$a = array_values(array_diff($a, [$ext]));
Config::set('extensions', $a);
Config::save();
}
$t['saved'] = 1;
jsonExit($t);
}
function _c($key)
{
return Config::get($key);
}
function getLangs()
{
$langDir = Lang::instance()->langDir();
if ( ! $h = opendir($langDir) ) {
return false;
}
$a = array();
while ( false !== ($file = readdir($h)) )
{
if ( preg_match('/(.+)\.json$/', $file, $m) ) {
$jsonText = file_get_contents($langDir. $file);
if (false === $jsonText) {
die("false ");
continue;
}
$a[$m[1]] = $m[1];
$j = json_decode($jsonText, true);
if ( isset($j['_header']['language']) && isset($j['_header']['original_name']) ) {
$a[$m[1]]= [
'name' => $j['_header']['original_name'],
'title' => $j['_header']['language']
];
}
}
}
closedir($h);
uasort($a, 'cmpLangs');
return $a;
}
function cmpLangs($a, $b) : int
{
//return strcmp( mb_strtoupper($a['name']), mb_strtoupper($b['name']) );
return strcasecmp($a['title'], $b['title']);
}
function selectOptions($a, $value, $default=null)
{
if(!$a) return '';
$s = '';
if($default !== null && !isset($a[$value])) $value = $default;
foreach($a as $k=>$v) {
$s .= '';
}
return $s;
}
/**
* @param array $a array of id=>array(name, optional title)
* @param mixed $key Key of OPTION to be selected
* @param mixed $default Default key if $key is not present in $a
*/
function selectOptionsA($a, $key, $default=null)
{
if(!$a) return '';
$s = '';
if ($default !== null && !isset($a[$key])) $key = $default;
else if ($default === null && !isset($a[$key])) {
$s .= '';
}
foreach($a as $k=>$v) {
if (!is_array($v)) {
$v = array('name' => $k);
}
$s .= '';
}
return $s;
}
function timezoneIdentifiers()
{
$zones = DateTimeZone::listIdentifiers();
$a = array();
foreach($zones as $v) {
$a[$v] = $v;
}
return $a;
}
function listExtensions()
{
$extBundles = MTTExtensionLoader::bundles();
$activatedExts = Config::get('extensions');
if (!is_array($activatedExts))
$activatedExts = [];
$a = [];
foreach ($extBundles as $ext => $meta) {
$out = htmlspecialchars($meta['name']. ' v'. $meta['version']). ' ';
if (in_array($ext, $activatedExts)) {
$out .= "". __('set_deactivate', true). '';
$instance = MTTExtensionLoader::extensionInstance($ext);
if ($instance instanceof MTTExtensionSettingsInterface) {
$out .= " ". __('a_settings', true). "";
}
$activatedExts = array_diff($activatedExts, [$ext]);
}
else {
$out .= "". __('set_activate', true). '';
}
$a[] = $out;
}
// removed and not deactivated
foreach ($activatedExts as $ext) {
$out = "$ext <not found> "."". __('set_deactivate', true). '';
$a[] = $out;
}
print( implode("
\n", $a) );
}
header('Content-type:text/html; charset=utf-8');
?>