0) {
$msg_error = WEB_cell_login . " " . $login . " " . $msg_exists . "!";
} else {
$new = ['login' => $login];
// Определение OU
if ($rou > 0) {
$new['ou_id'] = $rou;
} else {
$rou = 3;
$ou_exists = get_record_sql($db_link, "SELECT id FROM ou WHERE id = ?", [$rou]);
if (empty($ou_exists)) {
$new['ou_id'] = $default_user_ou_id; // по умолчанию
} else {
$new['ou_id'] = $rou;
}
}
// Наследование настроек от OU
$ou_info = get_record_sql($db_link, "SELECT * FROM ou WHERE id = ?", [$new['ou_id']]);
if (!empty($ou_info)) {
$new['enabled'] = isset($ou_info['enabled']) ? (int)$ou_info['enabled'] : 0;
$new['queue_id'] = isset($ou_info['queue_id']) ? (int)$ou_info['queue_id'] : 0;
$new['filter_group_id'] = isset($ou_info['filter_group_id']) ? (int)$ou_info['filter_group_id'] : 0;
} else {
// Если OU не найден — значения по умолчанию
$new['enabled'] = 0;
$new['queue_id'] = 0;
$new['filter_group_id'] = 0;
}
$lid = insert_record($db_link, "user_list", $new);
if (!empty($lid)) {
header("Location: edituser.php?id=$lid");
exit;
}
}
}
header("Location: " . $_SERVER["REQUEST_URI"]);
exit;
}
?>
$msg_error
\n";
}
?>
0) {
$search_pattern = '%' . $f_search . '%';
$conditions[] = "(login LIKE ? OR description LIKE ?)";
$params[] = $search_pattern;
$params[] = $search_pattern;
}
// Защита от пустого WHERE
if (!empty($conditions)) {
$whereClause = ' WHERE ' . implode(' AND ', $conditions);
} else {
$whereClause = '';
}
// === 2. Безопасная сортировка (БЕЛЫЙ СПИСОК!) ===
$allowed_sort_fields = ['id', 'login', 'description' ];
$allowed_order = ['ASC', 'DESC'];
$sort_field = in_array($sort_field, $allowed_sort_fields, true) ? $sort_field : 'id';
$order = in_array(strtoupper($order), $allowed_order, true) ? strtoupper($order) : 'ASC';
// === 3. Подсчёт записей ===
$countSQL = "SELECT COUNT(*) FROM user_list $whereClause";
$count_records = (int)get_single_field($db_link, $countSQL, $params);
// === 4. Пагинация ===
$total = ceil($count_records / $displayed);
$page = max(1, min($page, $total));
$start = ($page - 1) * $displayed;
print_navigation($page_url, $page, $displayed, $count_records, $total);
// === 5. Запрос данных ===
$limit = (int)$displayed;
$offset = (int)$start;
$dataParams = array_merge($params, [$limit, $offset]);
$sSQL = "
SELECT *
FROM user_list U
$whereClause
ORDER BY $sort_field $order
LIMIT ? OFFSET ?
";
$users = get_records_sql($db_link, $sSQL, $dataParams);
?>