gitea init

This commit is contained in:
skryper
2025-10-08 21:28:30 +04:00
commit d4651a423d
2518 changed files with 522832 additions and 0 deletions
@@ -0,0 +1,25 @@
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
require_once __DIR__ . '/../../../includes/init.php';
require_once __DIR__ . '/../models/marketingmodels.php';
MarketingModel::setDb($pdo);
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$clientIds = $_POST['clients'] ?? [];
$subject = trim($_POST['subject'] ?? '');
$message = trim($_POST['message'] ?? '');
if (!empty($clientIds) && $subject && $message) {
$success = MarketingModel::sendBroadcast($clientIds, $subject, $message);
header("Location: dashboard.php?module=marketing&action=broadcast&sent=1");
exit;
}
}
// მხოლოდ GET მოთხოვნის დროს ჩაიტვირთოს ფორმა
require_once __DIR__ . '/../views/broadcast.php';
@@ -0,0 +1,12 @@
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
require_once __DIR__ . '/../../../includes/init.php';
require_once __DIR__ . '/../models/marketingmodels.php';
MarketingModel::setDb($pdo);
$emailLogs = MarketingModel::getEmailLogs();
require_once __DIR__ . '/../views/email_logs.php';
@@ -0,0 +1,109 @@
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require_once __DIR__ . '/../../../libs/phpmailer/src/PHPMailer.php';
require_once __DIR__ . '/../../../libs/phpmailer/src/SMTP.php';
require_once __DIR__ . '/../../../libs/phpmailer/src/Exception.php';
class MarketingModel
{
protected static $db;
public static function setDb($pdo)
{
self::$db = $pdo;
}
/**
* SMTP კონფიგურაციის მიღება ბაზიდან
*/
private static function getSmtpConfig()
{
$stmt = self::$db->query("SELECT setting_key, setting_value FROM smtp_settings");
$settings = $stmt->fetchAll(PDO::FETCH_KEY_PAIR);
// Default ღირებულებები თუ ბაზაში არ არის
return array_merge([
'smtp_host' => 'localhost',
'smtp_port' => '587',
'smtp_secure' => 'tls',
'smtp_auth' => '1',
'smtp_username' => '',
'smtp_password' => '',
'smtp_from_email' => 'noreply@example.com',
'smtp_from_name' => 'Website',
'smtp_debug' => '0'
], $settings);
}
public static function sendBroadcast($clientIds, $subject, $message)
{
$stmt = self::$db->prepare(
"SELECT id, email, first_name, last_name
FROM clients
WHERE id IN (" . implode(',', array_fill(0, count($clientIds), '?')) . ")"
);
$stmt->execute($clientIds);
$clients = $stmt->fetchAll();
// SMTP კონფიგურაციის მიღება ბაზიდან
$smtpConfig = self::getSmtpConfig();
foreach ($clients as $client) {
$mail = new PHPMailer(true);
try {
$mail->isSMTP();
$mail->Host = $smtpConfig['smtp_host'];
$mail->SMTPAuth = (bool)$smtpConfig['smtp_auth'];
$mail->Username = $smtpConfig['smtp_username'];
$mail->Password = $smtpConfig['smtp_password'];
$mail->SMTPSecure = $smtpConfig['smtp_secure'];
$mail->Port = (int)$smtpConfig['smtp_port'];
$mail->SMTPDebug = (int)$smtpConfig['smtp_debug'];
$mail->Debugoutput = 'error_log';
$mail->setFrom($smtpConfig['smtp_from_email'], $smtpConfig['smtp_from_name']);
$mail->addAddress($client['email'], $client['first_name'] . ' ' . $client['last_name']);
$mail->CharSet = 'UTF-8';
$mail->isHTML(true);
$mail->Subject = $subject;
$mail->Body = nl2br(htmlspecialchars($message));
if ($mail->send()) {
$log = self::$db->prepare(
"INSERT INTO email_logs (client_id, subject, message, sent_at) VALUES (?, ?, ?, NOW())"
);
$log->execute([$client['id'], $subject, $message]);
} else {
error_log("გაგზავნის შეცდომა: " . $mail->ErrorInfo);
}
} catch (Exception $e) {
error_log("PHPMailer გამონაკლისი: " . $mail->ErrorInfo);
}
}
return true;
}
public static function getAllClients()
{
$stmt = self::$db->query("SELECT id, first_name, last_name, email FROM clients ORDER BY first_name");
return $stmt->fetchAll();
}
public static function getEmailLogs()
{
$stmt = self::$db->query("SELECT email_logs.*, clients.first_name, clients.last_name FROM email_logs
JOIN clients ON email_logs.client_id = clients.id
ORDER BY sent_at DESC");
return $stmt->fetchAll();
}
}
@@ -0,0 +1,57 @@
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
require_once __DIR__ . '/../../../includes/init.php';
require_once __DIR__ . '/../../../../vendor/autoload.php';
use App\Config;
$success = isset($_GET['sent']) && $_GET['sent'] == 1;
// კლიენტების წამოღება
MarketingModel::setDb($pdo);
$clients = MarketingModel::getAllClients();
?>
<?php require_once Config::includePath('head.php'); ?>
<?php require_once Config::includePath('navbar.php'); ?>
<?php require_once Config::includePath('pageheader.php'); ?>
<?php require_once Config::includePath('pagebodystart.php'); ?>
<div class="container-xl mt-4">
<h2>ელ.ფოსტის გაგზავნა კლიენტებზე</h2>
<?php if ($success): ?>
<div class="alert alert-success">შეტყობინება წარმატებით გაიგზავნა!</div>
<?php endif; ?>
<form action="dashboard.php?module=marketing&action=broadcast" method="POST">
<div class="mb-3">
<label class="form-label">აირჩიე კლიენტები</label><br>
<?php foreach ($clients as $client): ?>
<div class="form-check form-check-inline">
<input class="form-check-input" type="checkbox" name="clients[]" value="<?= $client['id'] ?>">
<label class="form-check-label"> <?= htmlspecialchars($client['first_name'] . ' ' . $client['last_name']) ?> </label>
</div>
<?php endforeach; ?>
</div>
<div class="mb-3">
<label class="form-label">თემა</label>
<input type="text" name="subject" class="form-control" required>
</div>
<div class="mb-3">
<label class="form-label">შეტყობინება</label>
<textarea name="message" class="form-control" rows="5" required></textarea>
</div>
<button type="submit" class="btn btn-primary">გაგზავნა</button>
</form>
</div>
<?php require_once Config::includePath('footer.php'); ?>
@@ -0,0 +1,42 @@
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
require_once __DIR__ . '/../../../includes/init.php';
require_once __DIR__ . '/../../../../vendor/autoload.php';
use App\Config;
?>
<?php require_once App\Config::includePath('head.php'); ?>
<?php require_once App\Config::includePath('navbar.php'); ?>
<?php require_once App\Config::includePath('pageheader.php'); ?>
<?php require_once App\Config::includePath('pagebodystart.php'); ?>
<div class="container-xl mt-4">
<h2>ელ.ფოსტის გაგზავნის ისტორია</h2>
<table class="table table-bordered">
<thead>
<tr>
<th>კლიენტი</th>
<th>თემა</th>
<th>შეტყობინება</th>
<th>გაგზავნის დრო</th>
</tr>
</thead>
<tbody>
<?php foreach ($emailLogs as $log): ?>
<tr>
<td><?= htmlspecialchars($log['first_name'] . ' ' . $log['last_name']) ?></td>
<td><?= htmlspecialchars($log['subject']) ?></td>
<td><?= nl2br(htmlspecialchars($log['message'])) ?></td>
<td><?= htmlspecialchars($log['sent_at']) ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<?php require_once App\Config::includePath('footer.php'); ?>