2018-06-23 23:50:22 +02:00
|
|
|
<?php
|
|
|
|
function rsettings($_action, $_data = null) {
|
|
|
|
global $pdo;
|
|
|
|
global $lang;
|
2018-08-03 20:31:33 +02:00
|
|
|
$_data_log = $_data;
|
2018-06-23 23:50:22 +02:00
|
|
|
switch ($_action) {
|
|
|
|
case 'add':
|
|
|
|
if ($_SESSION['mailcow_cc_role'] != "admin") {
|
2018-08-13 23:20:40 +02:00
|
|
|
$_SESSION['return'][] = array(
|
2018-06-23 23:50:22 +02:00
|
|
|
'type' => 'danger',
|
2018-08-03 20:31:33 +02:00
|
|
|
'log' => array(__FUNCTION__, $_action, $_data_log),
|
|
|
|
'msg' => 'access_denied'
|
2018-06-23 23:50:22 +02:00
|
|
|
);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
$content = $_data['content'];
|
|
|
|
$desc = $_data['desc'];
|
2018-07-15 16:02:27 +02:00
|
|
|
$active = intval($_data['active']);
|
2018-06-23 23:50:22 +02:00
|
|
|
if (empty($content)) {
|
2018-08-13 23:20:40 +02:00
|
|
|
$_SESSION['return'][] = array(
|
2018-06-23 23:50:22 +02:00
|
|
|
'type' => 'danger',
|
2018-08-03 20:31:33 +02:00
|
|
|
'log' => array(__FUNCTION__, $_action, $_data_log),
|
|
|
|
'msg' => 'map_content_empty'
|
2018-06-23 23:50:22 +02:00
|
|
|
);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
$stmt = $pdo->prepare("INSERT INTO `settingsmap` (`content`, `desc`, `active`)
|
|
|
|
VALUES (:content, :desc, :active)");
|
|
|
|
$stmt->execute(array(
|
|
|
|
':content' => $content,
|
|
|
|
':desc' => $desc,
|
|
|
|
':active' => $active
|
|
|
|
));
|
|
|
|
}
|
|
|
|
catch (PDOException $e) {
|
2018-08-13 23:20:40 +02:00
|
|
|
$_SESSION['return'][] = array(
|
2018-06-23 23:50:22 +02:00
|
|
|
'type' => 'danger',
|
2018-08-03 20:31:33 +02:00
|
|
|
'log' => array(__FUNCTION__, $_action, $_data_log),
|
|
|
|
'msg' => array('mysql_error', $e)
|
2018-06-23 23:50:22 +02:00
|
|
|
);
|
|
|
|
return false;
|
|
|
|
}
|
2018-08-13 23:20:40 +02:00
|
|
|
$_SESSION['return'][] = array(
|
2018-06-23 23:50:22 +02:00
|
|
|
'type' => 'success',
|
2018-08-03 20:31:33 +02:00
|
|
|
'log' => array(__FUNCTION__, $_action, $_data_log),
|
|
|
|
'msg' => 'settings_map_added'
|
2018-06-23 23:50:22 +02:00
|
|
|
);
|
|
|
|
break;
|
|
|
|
case 'edit':
|
|
|
|
if ($_SESSION['mailcow_cc_role'] != "admin") {
|
2018-08-13 23:20:40 +02:00
|
|
|
$_SESSION['return'][] = array(
|
2018-06-23 23:50:22 +02:00
|
|
|
'type' => 'danger',
|
2018-08-03 20:31:33 +02:00
|
|
|
'log' => array(__FUNCTION__, $_action, $_data_log),
|
|
|
|
'msg' => 'access_denied'
|
2018-06-23 23:50:22 +02:00
|
|
|
);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
$ids = (array)$_data['id'];
|
|
|
|
foreach ($ids as $id) {
|
|
|
|
$is_now = rsettings('details', $id);
|
|
|
|
if (!empty($is_now)) {
|
|
|
|
$content = (!empty($_data['content'])) ? $_data['content'] : $is_now['content'];
|
|
|
|
$desc = (!empty($_data['desc'])) ? $_data['desc'] : $is_now['desc'];
|
|
|
|
$active = (isset($_data['active'])) ? intval($_data['active']) : $is_now['active_int'];
|
|
|
|
}
|
|
|
|
else {
|
2018-08-13 23:20:40 +02:00
|
|
|
$_SESSION['return'][] = array(
|
2018-06-23 23:50:22 +02:00
|
|
|
'type' => 'danger',
|
2018-08-03 20:31:33 +02:00
|
|
|
'log' => array(__FUNCTION__, $_action, $_data_log),
|
2018-08-13 23:20:40 +02:00
|
|
|
'msg' => array('settings_map_invalid', $id)
|
2018-06-23 23:50:22 +02:00
|
|
|
);
|
2018-08-13 23:20:40 +02:00
|
|
|
continue;
|
2018-06-23 23:50:22 +02:00
|
|
|
}
|
|
|
|
$content = trim($content);
|
|
|
|
try {
|
|
|
|
$stmt = $pdo->prepare("UPDATE `settingsmap` SET
|
|
|
|
`content` = :content,
|
|
|
|
`desc` = :desc,
|
|
|
|
`active` = :active
|
|
|
|
WHERE `id` = :id");
|
|
|
|
$stmt->execute(array(
|
|
|
|
':content' => $content,
|
|
|
|
':desc' => $desc,
|
|
|
|
':active' => $active,
|
|
|
|
':id' => $id
|
|
|
|
));
|
|
|
|
}
|
|
|
|
catch (PDOException $e) {
|
2018-08-13 23:20:40 +02:00
|
|
|
$_SESSION['return'][] = array(
|
2018-06-23 23:50:22 +02:00
|
|
|
'type' => 'danger',
|
2018-08-03 20:31:33 +02:00
|
|
|
'log' => array(__FUNCTION__, $_action, $_data_log),
|
|
|
|
'msg' => array('mysql_error', $e)
|
2018-06-23 23:50:22 +02:00
|
|
|
);
|
2018-08-13 23:20:40 +02:00
|
|
|
continue;
|
2018-06-23 23:50:22 +02:00
|
|
|
}
|
2018-08-13 23:20:40 +02:00
|
|
|
$_SESSION['return'][] = array(
|
|
|
|
'type' => 'success',
|
|
|
|
'log' => array(__FUNCTION__, $_action, $_data_log),
|
|
|
|
'msg' => array('object_modified', htmlspecialchars($ids))
|
|
|
|
);
|
2018-06-23 23:50:22 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'delete':
|
|
|
|
if ($_SESSION['mailcow_cc_role'] != "admin") {
|
2018-08-13 23:20:40 +02:00
|
|
|
$_SESSION['return'][] = array(
|
2018-06-23 23:50:22 +02:00
|
|
|
'type' => 'danger',
|
2018-08-03 20:31:33 +02:00
|
|
|
'log' => array(__FUNCTION__, $_action, $_data_log),
|
|
|
|
'msg' => 'access_denied'
|
2018-06-23 23:50:22 +02:00
|
|
|
);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
$ids = (array)$_data['id'];
|
|
|
|
foreach ($ids as $id) {
|
|
|
|
try {
|
|
|
|
$stmt = $pdo->prepare("DELETE FROM `settingsmap` WHERE `id`= :id");
|
|
|
|
$stmt->execute(array(':id' => $id));
|
|
|
|
}
|
|
|
|
catch (PDOException $e) {
|
2018-08-13 23:20:40 +02:00
|
|
|
$_SESSION['return'][] = array(
|
2018-06-23 23:50:22 +02:00
|
|
|
'type' => 'danger',
|
2018-08-03 20:31:33 +02:00
|
|
|
'log' => array(__FUNCTION__, $_action, $_data_log),
|
|
|
|
'msg' => array('mysql_error', $e)
|
2018-06-23 23:50:22 +02:00
|
|
|
);
|
|
|
|
return false;
|
|
|
|
}
|
2018-08-13 23:20:40 +02:00
|
|
|
$_SESSION['return'][] = array(
|
|
|
|
'type' => 'success',
|
|
|
|
'log' => array(__FUNCTION__, $_action, $_data_log),
|
|
|
|
'msg' => array('settings_map_removed', htmlspecialchars($id))
|
|
|
|
);
|
2018-06-23 23:50:22 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'get':
|
|
|
|
if ($_SESSION['mailcow_cc_role'] != "admin") {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
$settingsmaps = array();
|
2018-08-13 23:20:40 +02:00
|
|
|
$stmt = $pdo->query("SELECT `id`, `desc`, `active` FROM `settingsmap`");
|
|
|
|
$settingsmaps = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
2018-06-23 23:50:22 +02:00
|
|
|
return $settingsmaps;
|
|
|
|
break;
|
|
|
|
case 'details':
|
|
|
|
if ($_SESSION['mailcow_cc_role'] != "admin" || !isset($_data)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
$settingsmapdata = array();
|
2018-08-13 23:20:40 +02:00
|
|
|
$stmt = $pdo->prepare("SELECT `id`,
|
|
|
|
`desc`,
|
|
|
|
`content`,
|
|
|
|
`active` AS `active_int`,
|
|
|
|
CASE `active` WHEN 1 THEN '".$lang['mailbox']['yes']."' ELSE '".$lang['mailbox']['no']."' END AS `active`
|
|
|
|
FROM `settingsmap`
|
|
|
|
WHERE `id` = :id");
|
|
|
|
$stmt->execute(array(':id' => $_data));
|
|
|
|
$settingsmapdata = $stmt->fetch(PDO::FETCH_ASSOC);
|
2018-06-23 23:50:22 +02:00
|
|
|
return $settingsmapdata;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|