179 lines
6.4 KiB
PHP
179 lines
6.4 KiB
PHP
<?php
|
||
// CSRF token kontrolü
|
||
if (!isset($_POST['_token']) && !isset($_GET['_token'])) {
|
||
echo json_encode(['status' => 'error', 'message' => 'CSRF token gerekli']);
|
||
exit;
|
||
}
|
||
|
||
// Güncelleme işlemi
|
||
if (isset($_GET['update']) || isset($_POST['update'])) {
|
||
$tableName = $_POST['table'] ?? $_GET['table'] ?? '';
|
||
$id = $_POST['id'] ?? $_GET['id'] ?? '';
|
||
$columnName = $_POST['column'] ?? $_GET['column'] ?? '';
|
||
$newValue = $_POST['value'] ?? $_GET['value'] ?? '';
|
||
|
||
if (empty($tableName) || empty($id) || empty($columnName)) {
|
||
echo json_encode(['status' => 'error', 'message' => 'Missing parameters']);
|
||
exit;
|
||
}
|
||
|
||
try {
|
||
// Veritabanı güncelleme
|
||
$result = db($tableName)->where('id', $id)->update([$columnName => $newValue]);
|
||
|
||
if ($result) {
|
||
echo json_encode(['status' => 'success', 'message' => 'Update successful']);
|
||
} else {
|
||
echo json_encode(['status' => 'error', 'message' => 'Update failed']);
|
||
}
|
||
} catch (Exception $e) {
|
||
echo json_encode(['status' => 'error', 'message' => 'Database error: ' . $e->getMessage()]);
|
||
}
|
||
exit;
|
||
}
|
||
|
||
// Görüntüleme işlemi
|
||
$tableName = $_GET['table'] ?? '';
|
||
$id = $_GET['id'] ?? '';
|
||
$columnName = $_GET['column'] ?? '';
|
||
|
||
if (empty($tableName) || empty($id) || empty($columnName)) {
|
||
echo '<div class="alert alert-danger">Missing parameters: table=' . htmlspecialchars($tableName) . ', id=' . htmlspecialchars($id) . ', column=' . htmlspecialchars($columnName) . '</div>';
|
||
exit;
|
||
}
|
||
|
||
// Get current data
|
||
$currentData = db($tableName)->where('id', $id)->first();
|
||
$currentValue = $currentData->{$columnName} ?? '';
|
||
|
||
// Get column information
|
||
?>
|
||
|
||
<div class="modal-header">
|
||
<h5 class="modal-title">Edit {{ e2($columnName) }}</h5>
|
||
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
||
<span aria-hidden="true">×</span>
|
||
</button>
|
||
</div>
|
||
|
||
<div class="modal-body">
|
||
<form id="longTextEditForm">
|
||
<input type="hidden" name="_token" value="{{ csrf_token() }}">
|
||
<input type="hidden" name="table" value="{{ $tableName }}">
|
||
<input type="hidden" name="id" value="{{ $id }}">
|
||
<input type="hidden" name="column" value="{{ $columnName }}">
|
||
<input type="hidden" name="update" value="1">
|
||
|
||
<div class="form-group">
|
||
<label for="longTextValue">{{ e2($columnName) }}</label>
|
||
<textarea
|
||
class="form-control"
|
||
id="longTextValue"
|
||
name="value"
|
||
rows="10"
|
||
style="min-height: 200px;"
|
||
placeholder="Enter {{ e2($columnName) }}..."
|
||
>{{ $currentValue }}</textarea>
|
||
</div>
|
||
</form>
|
||
</div>
|
||
<div class="text-center">
|
||
<button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
|
||
<button type="button" class="btn btn-primary" onclick="saveLongText()">Save</button>
|
||
</div>
|
||
<script>
|
||
$(".modal-footer").hide();
|
||
|
||
function saveLongText() {
|
||
var formData = new FormData(document.getElementById('longTextEditForm'));
|
||
$.ajax({
|
||
url: '{{ url("admin-ajax/long-text-edit") }}',
|
||
type: 'POST',
|
||
data: formData,
|
||
processData: false,
|
||
contentType: false,
|
||
success: function(response) {
|
||
try {
|
||
var result = JSON.parse(response);
|
||
if (result.status === 'success') {
|
||
// Successful update
|
||
Swal.fire({
|
||
icon: 'success',
|
||
title: 'Success',
|
||
text: result.message,
|
||
timer: 2000,
|
||
showConfirmButton: false
|
||
});
|
||
|
||
// Close modal
|
||
$('#modal-popin').modal('hide');
|
||
|
||
// Refresh DataGrid - safe approach
|
||
try {
|
||
// Check if dataGrid element exists
|
||
if ($("#dataGrid").length > 0) {
|
||
// Try to get DevExtreme instance and refresh
|
||
var gridElement = $("#dataGrid");
|
||
if (gridElement.hasClass("dx-datagrid")) {
|
||
// Element is already a DevExtreme DataGrid
|
||
gridElement.dxDataGrid("refresh");
|
||
} else {
|
||
// Try to get instance and refresh
|
||
var instance = gridElement.dxDataGrid("instance");
|
||
if (instance && typeof instance.refresh === 'function') {
|
||
instance.refresh();
|
||
} else {
|
||
// Fallback: reload page
|
||
location.reload();
|
||
}
|
||
}
|
||
} else {
|
||
// DataGrid not found, reload page
|
||
location.reload();
|
||
}
|
||
} catch (error) {
|
||
console.log("DataGrid refresh error:", error);
|
||
// Final fallback: reload page
|
||
location.reload();
|
||
}
|
||
} else {
|
||
Swal.fire({
|
||
icon: 'error',
|
||
title: 'Error',
|
||
text: result.message
|
||
});
|
||
}
|
||
} catch (e) {
|
||
Swal.fire({
|
||
icon: 'error',
|
||
title: 'Error',
|
||
text: 'Error processing response'
|
||
});
|
||
}
|
||
},
|
||
error: function(xhr, status, error) {
|
||
Swal.fire({
|
||
icon: 'error',
|
||
title: 'Error',
|
||
text: 'Error during update: ' + error
|
||
});
|
||
}
|
||
});
|
||
}
|
||
|
||
// Textarea auto-resize
|
||
$(document).ready(function() {
|
||
var textarea = document.getElementById('longTextValue');
|
||
textarea.addEventListener('input', function() {
|
||
this.style.height = 'auto';
|
||
this.style.height = Math.max(200, this.scrollHeight) + 'px';
|
||
});
|
||
|
||
// Save with Enter key (Ctrl+Enter)
|
||
textarea.addEventListener('keydown', function(e) {
|
||
if (e.ctrlKey && e.key === 'Enter') {
|
||
saveLongText();
|
||
}
|
||
});
|
||
});
|
||
</script>
|