Massal upload
This commit is contained in:
parent
b610ad13d6
commit
649064caeb
@ -87,7 +87,7 @@ class AdminController extends Controller {
|
||||
$version = $_POST['version'];
|
||||
$image_url = $_POST['image_url'];
|
||||
$download_url = $_POST['download_url'];
|
||||
$category_id = $_POST['category_id'] ?? null;
|
||||
$category_id = !empty($_POST['category_id']) ? $_POST['category_id'] : null;
|
||||
$status = $_POST['status'] ?? 'published';
|
||||
$is_vip = isset($_POST['is_vip']) ? 1 : 0;
|
||||
|
||||
@ -100,6 +100,66 @@ class AdminController extends Controller {
|
||||
$this->redirect('/admin/apks');
|
||||
}
|
||||
|
||||
public function massUploadForm() {
|
||||
$this->checkAuth();
|
||||
$db = db_pdo();
|
||||
$categories = $db->query("SELECT * FROM categories")->fetchAll();
|
||||
$this->view('admin/apks/mass_upload', ['categories' => $categories]);
|
||||
}
|
||||
|
||||
public function massUpload() {
|
||||
$this->checkAuth();
|
||||
$titles = $_POST['titles'] ?? [];
|
||||
$versions = $_POST['versions'] ?? [];
|
||||
$download_urls = $_POST['download_urls'] ?? [];
|
||||
$category_id = !empty($_POST['category_id']) ? $_POST['category_id'] : null;
|
||||
$status = $_POST['status'] ?? 'published';
|
||||
|
||||
$db = db_pdo();
|
||||
$stmt = $db->prepare("INSERT INTO apks (title, slug, description, version, icon_path, download_url, category_id, status, is_vip, display_order) VALUES (?, ?, ?, ?, ?, ?, ?, ?, 0, 0)");
|
||||
|
||||
foreach ($titles as $index => $title) {
|
||||
if (empty($title)) continue;
|
||||
$slug = $this->slugify($title);
|
||||
$version = $versions[$index] ?? '';
|
||||
$download_url = $download_urls[$index] ?? '';
|
||||
$description = $title; // Default description to title for mass upload
|
||||
|
||||
$icon_path = $this->handleMassUploadFile('icon_files', $index, true);
|
||||
|
||||
$stmt->execute([$title, $slug, $description, $version, $icon_path, $download_url, $category_id, $status]);
|
||||
}
|
||||
|
||||
$this->redirect('/admin/apks');
|
||||
}
|
||||
|
||||
private function handleMassUploadFile($field, $index, $compress = false) {
|
||||
if (!isset($_FILES[$field]['name'][$index]) || $_FILES[$field]['error'][$index] !== UPLOAD_ERR_OK) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$uploadDir = 'assets/uploads/icons/';
|
||||
if (!is_dir($uploadDir)) {
|
||||
mkdir($uploadDir, 0775, true);
|
||||
}
|
||||
|
||||
$ext = pathinfo($_FILES[$field]['name'][$index], PATHINFO_EXTENSION);
|
||||
$fileName = uniqid() . '.' . $ext;
|
||||
$targetPath = $uploadDir . $fileName;
|
||||
|
||||
if ($compress) {
|
||||
if (compress_image($_FILES[$field]['tmp_name'][$index], $targetPath, 75)) {
|
||||
return $targetPath;
|
||||
}
|
||||
} else {
|
||||
if (move_uploaded_file($_FILES[$field]['tmp_name'][$index], $targetPath)) {
|
||||
return $targetPath;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function editApkForm($params) {
|
||||
$this->checkAuth();
|
||||
$apkService = new ApkService();
|
||||
@ -116,7 +176,7 @@ class AdminController extends Controller {
|
||||
$version = $_POST['version'];
|
||||
$image_url = $_POST['image_url'];
|
||||
$download_url = $_POST['download_url'];
|
||||
$category_id = $_POST['category_id'] ?? null;
|
||||
$category_id = !empty($_POST['category_id']) ? $_POST['category_id'] : null;
|
||||
$status = $_POST['status'];
|
||||
$is_vip = isset($_POST['is_vip']) ? 1 : 0;
|
||||
|
||||
@ -284,4 +344,4 @@ class AdminController extends Controller {
|
||||
$text = strtolower($text);
|
||||
return empty($text) ? 'n-a' : $text;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BIN
assets/uploads/icons/699e4457a8386.jpg
Normal file
BIN
assets/uploads/icons/699e4457a8386.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 24 KiB |
BIN
assets/uploads/icons/699e46a5c9940.jpg
Normal file
BIN
assets/uploads/icons/699e46a5c9940.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 6.4 KiB |
BIN
assets/uploads/icons/699e46a5cb3a2.jpg
Normal file
BIN
assets/uploads/icons/699e46a5cb3a2.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 6.4 KiB |
@ -74,6 +74,8 @@ $router->post('/admin/settings', 'AdminController@saveSettings');
|
||||
|
||||
// Admin APKs
|
||||
$router->get('/admin/apks', 'AdminController@apks');
|
||||
$router->get('/admin/apks/mass-upload', 'AdminController@massUploadForm');
|
||||
$router->post('/admin/apks/mass-upload', 'AdminController@massUpload');
|
||||
$router->get('/admin/apks/add', 'AdminController@addApkForm');
|
||||
$router->post('/admin/apks/add', 'AdminController@addApk');
|
||||
$router->get('/admin/apks/edit/:id', 'AdminController@editApkForm');
|
||||
|
||||
96
views/admin/apks/mass_upload.php
Normal file
96
views/admin/apks/mass_upload.php
Normal file
@ -0,0 +1,96 @@
|
||||
<?php include __DIR__ . '/../header.php'; ?>
|
||||
|
||||
<div class="container py-4">
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-md-12">
|
||||
<div class="card shadow-lg border-0 rounded-4">
|
||||
<div class="card-header bg-white py-3 d-flex justify-content-between align-items-center">
|
||||
<h5 class="m-0 fw-bold">Mass Upload APKs</h5>
|
||||
<button type="button" class="btn btn-outline-primary btn-sm fw-bold" id="add-row">
|
||||
<i class="fas fa-plus me-1"></i> Add Row
|
||||
</button>
|
||||
</div>
|
||||
<div class="card-body p-4">
|
||||
<form action="/admin/apks/mass-upload" method="POST" enctype="multipart/form-data">
|
||||
<div class="row mb-3">
|
||||
<div class="col-md-6">
|
||||
<label for="category_id" class="form-label fw-medium">Common Category</label>
|
||||
<select class="form-select" id="category_id" name="category_id">
|
||||
<option value="">Uncategorized</option>
|
||||
<?php foreach ($categories as $cat): ?>
|
||||
<option value="<?php echo $cat['id']; ?>"><?php echo htmlspecialchars($cat['name']); ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<label for="status" class="form-label fw-medium">Common Status</label>
|
||||
<select class="form-select" id="status" name="status">
|
||||
<option value="published">Published</option>
|
||||
<option value="draft">Draft</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="table-responsive">
|
||||
<table class="table table-bordered align-middle" id="mass-upload-table">
|
||||
<thead class="table-light">
|
||||
<tr>
|
||||
<th style="width: 25%;">Title</th>
|
||||
<th style="width: 15%;">Version</th>
|
||||
<th style="width: 25%;">Icon File</th>
|
||||
<th style="width: 30%;">Download URL</th>
|
||||
<th style="width: 5%;"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td><input type="text" name="titles[]" class="form-control" required></td>
|
||||
<td><input type="text" name="versions[]" class="form-control" placeholder="1.0.0"></td>
|
||||
<td><input type="file" name="icon_files[]" class="form-control" accept="image/*"></td>
|
||||
<td><input type="url" name="download_urls[]" class="form-control" required placeholder="https://..."></td>
|
||||
<td><button type="button" class="btn btn-outline-danger btn-sm remove-row"><i class="fas fa-times"></i></button></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div class="d-grid gap-2 d-md-flex justify-content-md-end border-top pt-4 mt-3">
|
||||
<a href="/admin/apks" class="btn btn-light px-4 fw-bold">Cancel</a>
|
||||
<button type="submit" class="btn btn-primary px-5 fw-bold"><i class="fas fa-upload me-2"></i>Start Mass Upload</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
const tableBody = document.querySelector('#mass-upload-table tbody');
|
||||
const addRowBtn = document.querySelector('#add-row');
|
||||
|
||||
addRowBtn.addEventListener('click', function() {
|
||||
const newRow = document.createElement('tr');
|
||||
newRow.innerHTML = `
|
||||
<td><input type="text" name="titles[]" class="form-control" required></td>
|
||||
<td><input type="text" name="versions[]" class="form-control" placeholder="1.0.0"></td>
|
||||
<td><input type="file" name="icon_files[]" class="form-control" accept="image/*"></td>
|
||||
<td><input type="url" name="download_urls[]" class="form-control" required placeholder="https://..."></td>
|
||||
<td><button type="button" class="btn btn-outline-danger btn-sm remove-row"><i class="fas fa-times"></i></button></td>
|
||||
`;
|
||||
tableBody.appendChild(newRow);
|
||||
});
|
||||
|
||||
tableBody.addEventListener('click', function(e) {
|
||||
if (e.target.classList.contains('remove-row') || e.target.parentElement.classList.contains('remove-row')) {
|
||||
const row = e.target.closest('tr');
|
||||
if (tableBody.querySelectorAll('tr').length > 1) {
|
||||
row.remove();
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
<?php include __DIR__ . '/../footer.php'; ?>
|
||||
@ -59,6 +59,9 @@
|
||||
<li class="nav-item">
|
||||
<a class="nav-link px-3" href="/admin/apks"><i class="fas fa-mobile-alt me-1"></i> APKs</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link px-3" href="/admin/apks/mass-upload"><i class="fas fa-cloud-upload-alt me-1"></i> Mass Upload</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link px-3" href="/admin/categories"><i class="fas fa-list me-1"></i> <?php echo __('categories'); ?></a>
|
||||
</li>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user