prepare("SELECT id FROM affiliates WHERE affiliate_code = ?"); $checkStmt->execute([$affiliate_code]); } while ($checkStmt->fetch()); // Insert affiliate $stmt = $pdo->prepare(" INSERT INTO affiliates (affiliate_code, type, company_name, incharge_name, state, postal_code, place_name, mobile, email, url, signup_reward, created_by, status, created_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 'active', NOW()) "); $stmt->execute([ $affiliate_code, $type, $company_name, $incharge_name, $state, $postal_code, $place_name, $mobile, $email, $url, $signup_reward, $_SESSION['admin_id'] ]); $affiliate_id = $pdo->lastInsertId(); // Handle file uploads if (!empty($_FILES['attachments']['name'][0])) { $upload_dir = 'uploads/affiliates/'; if (!file_exists($upload_dir)) { mkdir($upload_dir, 0755, true); } $allowed_types = ['application/pdf', 'image/jpeg', 'image/jpg', 'image/png', 'image/gif']; $max_files = 10; $max_size = 5 * 1024 * 1024; // 5MB for ($i = 0; $i < min(count($_FILES['attachments']['name']), $max_files); $i++) { if ($_FILES['attachments']['error'][$i] === UPLOAD_ERR_OK) { $file_type = $_FILES['attachments']['type'][$i]; $file_size = $_FILES['attachments']['size'][$i]; if (in_array($file_type, $allowed_types) && $file_size <= $max_size) { $file_name = $_FILES['attachments']['name'][$i]; $file_tmp = $_FILES['attachments']['tmp_name'][$i]; // Generate unique filename $extension = pathinfo($file_name, PATHINFO_EXTENSION); $unique_name = $affiliate_code . '_' . time() . '_' . $i . '.' . $extension; $file_path = $upload_dir . $unique_name; if (move_uploaded_file($file_tmp, $file_path)) { $attachStmt = $pdo->prepare(" INSERT INTO affiliate_attachments (affiliate_id, file_name, file_path, file_type, file_size, uploaded_at) VALUES (?, ?, ?, ?, ?, NOW()) "); $attachStmt->execute([ $affiliate_id, $file_name, $file_path, $file_type, $file_size ]); } } } } } logActivity($_SESSION['admin_id'], 'create_affiliate', "Created affiliate: $affiliate_code", 'affiliate', $affiliate_id); header('Location: supply.php?success=created&code=' . $affiliate_code); exit; } catch (Exception $e) { $error = 'An error occurred. Please try again.'; error_log("Create affiliate error: " . $e->getMessage()); } } } include 'includes/header.php'; ?>
⚠️

📁 Click to upload or drag and drop files here

PDF, JPG, PNG, GIF (Max 10 files, 5MB each) Upload GST Certificate, PAN Card, Cancelled Cheque, Business Registration, etc.
Cancel