parent
f20e24f589
commit
b299b0e085
|
@ -26,9 +26,12 @@ function user_settings() {
|
||||||
$selected_language = $user['Sprache'];
|
$selected_language = $user['Sprache'];
|
||||||
|
|
||||||
$selected_angel_types_source = sql_select("SELECT * FROM `UserAngelTypes` WHERE `user_id`=" . sql_escape($user['UID']));
|
$selected_angel_types_source = sql_select("SELECT * FROM `UserAngelTypes` WHERE `user_id`=" . sql_escape($user['UID']));
|
||||||
|
$selected_angel_types_source_ids = array();
|
||||||
$selected_angel_types = array();
|
$selected_angel_types = array();
|
||||||
foreach ($selected_angel_types_source as $selected_angel_type)
|
foreach ($selected_angel_types_source as $selected_angel_type) {
|
||||||
$selected_angel_types[] = $selected_angel_type['angeltype_id'];
|
$selected_angel_types[] = $selected_angel_type['angeltype_id'];
|
||||||
|
$selected_angel_types_source_ids[] = $selected_angel_type['angeltype_id'];
|
||||||
|
}
|
||||||
|
|
||||||
$angel_types_source = sql_select("SELECT * FROM `AngelTypes` ORDER BY `name`");
|
$angel_types_source = sql_select("SELECT * FROM `AngelTypes` ORDER BY `name`");
|
||||||
$angel_types = array();
|
$angel_types = array();
|
||||||
|
@ -115,20 +118,35 @@ function user_settings() {
|
||||||
WHERE `UID`=" . sql_escape($user['UID']));
|
WHERE `UID`=" . sql_escape($user['UID']));
|
||||||
|
|
||||||
// Assign angel-types
|
// Assign angel-types
|
||||||
$user_angel_type_info = array();
|
|
||||||
$deleted_angel_types = array_diff(array_keys($angel_types), $selected_angel_types);
|
|
||||||
if (count($deleted_angel_types) > 0)
|
|
||||||
sql_query("DELETE FROM `UserAngelTypes` WHERE `user_id`='" . sql_escape($user['UID']) . "' AND `angeltype_id` IN (" . implode(",", $deleted_angel_types) . ")");
|
|
||||||
foreach ($angel_types_source as $angel_type)
|
|
||||||
if (in_array($angel_type['id'], $selected_angel_types))
|
|
||||||
$user_angel_type_info[] = $angel_type['name'];
|
|
||||||
|
|
||||||
foreach ($selected_angel_types as $selected_angel_type_id) {
|
$deleted_angel_type_names = array();
|
||||||
if (sql_num_query("SELECT * FROM `UserAngelTypes` WHERE `user_id`=" . sql_escape($user['UID']) . " AND `angeltype_id`=" . sql_escape($selected_angel_type_id) . " LIMIT 1") == 0)
|
$added_angel_type_names = array();
|
||||||
sql_query("INSERT INTO `UserAngelTypes` SET `user_id`=" . sql_escape($user['UID']) . ", `angeltype_id`=" . sql_escape($selected_angel_type_id));
|
|
||||||
|
foreach($selected_angel_types_source as $source_angel_type) {
|
||||||
|
if (!in_array($source_angel_type["angeltype_id"], $selected_angel_types)) {
|
||||||
|
$deleted_angel_type_names[] = $angel_types[$source_angel_type["angeltype_id"]];
|
||||||
|
sql_query("DELETE FROM `UserAngelTypes` WHERE `user_id`='" . sql_escape($user['UID']) . "' AND `angeltype_id` = ". sql_escape($source_angel_type["angeltype_id"]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach($selected_angel_types as $selected_angel_type) {
|
||||||
|
if (!in_array($selected_angel_type, $selected_angel_types_source_ids)) {
|
||||||
|
$added_angel_type_names[] = $angel_types[$selected_angel_type];
|
||||||
|
sql_query("INSERT INTO `UserAngelTypes` SET `user_id`=" . sql_escape($user['UID']) . ", `angeltype_id`=" . sql_escape($selected_angel_type));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(count($deleted_angel_type_names) > 0 || count($added_angel_type_names) > 0) {
|
||||||
|
$log_message = "User changed his own Angel Types. ";
|
||||||
|
if(count($deleted_angel_type_names) > 0) {
|
||||||
|
$log_message .= "Removed: " . implode(", ", $deleted_angel_type_names) . " ";
|
||||||
|
}
|
||||||
|
if(count($added_angel_type_names) > 0) {
|
||||||
|
$log_message .= "Added: " . implode(", ", $added_angel_type_names);
|
||||||
|
}
|
||||||
|
engelsystem_log($log_message);
|
||||||
}
|
}
|
||||||
|
|
||||||
engelsystem_log("Own angel types set to: " . join(", ", $user_angel_type_info));
|
|
||||||
success(_("Settings saved."));
|
success(_("Settings saved."));
|
||||||
redirect(page_link_to('user_settings'));
|
redirect(page_link_to('user_settings'));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue