mirror of
https://github.com/getnamingo/registry.git
synced 2025-05-15 09:07:00 +02:00
Promotion page is now active
This commit is contained in:
parent
a7bd8fc5fd
commit
d172717f0a
3 changed files with 113 additions and 15 deletions
|
@ -899,5 +899,83 @@ class SystemController extends Controller
|
|||
'currentUri' => $uri
|
||||
]);
|
||||
}
|
||||
|
||||
public function managePromo(Request $request, Response $response)
|
||||
{
|
||||
if ($_SESSION["auth_roles"] != 0) {
|
||||
return $response->withHeader('Location', '/dashboard')->withStatus(302);
|
||||
}
|
||||
|
||||
if ($request->getMethod() === 'POST') {
|
||||
// Retrieve POST data
|
||||
$data = $request->getParsedBody();
|
||||
$db = $this->container->get('db');
|
||||
|
||||
$sData = array();
|
||||
|
||||
$sData['tldid'] = filter_var($data['tldid'], FILTER_SANITIZE_NUMBER_INT);
|
||||
$sData['extension'] = substr(trim($data['extension']), 0, 10);
|
||||
$sData['promotionName'] = substr(trim($data['promotionName']), 0, 255);
|
||||
$sData['promotionStart'] = date('Y-m-d', strtotime($data['promotionStart']));
|
||||
$sData['promotionEnd'] = date('Y-m-d', strtotime($data['promotionEnd']));
|
||||
$sData['discountType'] = in_array($data['discountType'], ['percentage', 'amount']) ? $data['discountType'] : 'percentage';
|
||||
$sData['discountValue'] = filter_var($data['discountValue'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
|
||||
$sData['max_count'] = ($data['max_count'] === "") ? null : filter_var($data['max_count'], FILTER_SANITIZE_NUMBER_INT);
|
||||
$sData['promotionConditions'] = substr(trim($data['promotionConditions']), 0, 1000);
|
||||
$sData['promotionDescription'] = substr(trim($data['promotionDescription']), 0, 1000);
|
||||
|
||||
try {
|
||||
$discount_percentage = NULL;
|
||||
$discount_amount = NULL;
|
||||
|
||||
// Determine which column to populate based on discountType
|
||||
if ($sData['discountType'] == 'percentage') {
|
||||
// Ensure the percentage value is within a valid range (0 to 100)
|
||||
$discount_percentage = min(100, max(0, floatval($sData['discountValue'])));
|
||||
} elseif ($sData['discountType'] == 'amount') {
|
||||
// Ensure the amount is a valid positive number
|
||||
$discount_amount = max(0, floatval($sData['discountValue']));
|
||||
}
|
||||
|
||||
$currentDateTime = new \DateTime();
|
||||
$crdate = $currentDateTime->format('Y-m-d H:i:s.v'); // Current timestamp
|
||||
|
||||
$db->beginTransaction();
|
||||
|
||||
$db->insert(
|
||||
'promotion_pricing',
|
||||
[
|
||||
'tld_id' => $sData['tldid'],
|
||||
'promo_name' => $sData['promotionName'],
|
||||
'start_date' => $sData['promotionStart'],
|
||||
'end_date' => $sData['promotionEnd'],
|
||||
'discount_percentage' => $discount_percentage,
|
||||
'discount_amount' => $discount_amount,
|
||||
'description' => $sData['promotionDescription'],
|
||||
'conditions' => $sData['promotionConditions'],
|
||||
'promo_type' => 'full',
|
||||
'status' => 'active',
|
||||
'max_count' => $sData['max_count'],
|
||||
'created_by' => $_SESSION['auth_user_id'],
|
||||
'created_at' => $crdate
|
||||
]
|
||||
);
|
||||
|
||||
$db->commit();
|
||||
|
||||
$this->container->get('flash')->addMessage('success', 'Promotion updates for the ' . $sData['extension'] . ' TLD have been successfully applied');
|
||||
return $response->withHeader('Location', '/registry/tlds')->withStatus(302);
|
||||
} catch (Exception $e) {
|
||||
$db->rollBack();
|
||||
$this->container->get('flash')->addMessage('error', 'Database failure: ' . $e->getMessage());
|
||||
return $response->withHeader('Location', '/registry/tld/'.$sData['extension'])->withStatus(302);
|
||||
}
|
||||
|
||||
} else {
|
||||
// Redirect to the tlds view
|
||||
return $response->withHeader('Location', '/registry/tlds')->withStatus(302);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -228,33 +228,52 @@
|
|||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<h5 class="card-subtitle mt-3 mb-3">Create New Promotion</h5>
|
||||
<h4 class="card-subtitle mt-3 mb-3">Create New Promotion</h4>
|
||||
<form action="/registry/promotions" method="post">
|
||||
{{ csrf.field | raw }}
|
||||
<input type="hidden" name="tld" value="{{ tld.tld }}">
|
||||
<input type="hidden" name="tldid" value="{{ tld.id }}"><input type="hidden" name="extension" value="{{ tld.tld }}">
|
||||
<div class="mb-3">
|
||||
<label for="promotionName" class="form-label">Promotion Name</label>
|
||||
<input type="text" class="form-control" id="promotionName" name="promotionName" placeholder="Enter promotion name">
|
||||
<label for="promotionName" class="form-label required">Promotion Name</label>
|
||||
<input type="text" class="form-control" id="promotionName" name="promotionName" placeholder="Enter promotion name" required>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-sm-6 col-md-6">
|
||||
<div class="mb-3">
|
||||
<label for="promotionStart" class="form-label required">Promotion Start Date</label>
|
||||
<input type="date" class="form-control" placeholder="e.g., 01/01/2023" id="promotionStart" name="promotionStart" required>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-sm-6 col-md-6">
|
||||
<div class="mb-3">
|
||||
<label for="promotionEnd" class="form-label">Promotion End Date</label>
|
||||
<input type="date" class="form-control" placeholder="e.g., 01/01/2023" id="promotionEnd" name="promotionEnd">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="promotionDescription" class="form-label">Description</label>
|
||||
<textarea class="form-control" id="promotionDescription" name="promotionDescription" rows="3" placeholder="Enter description"></textarea>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="promotionPeriod" class="form-label">Promotion Period</label>
|
||||
<input type="text" class="form-control" id="promotionPeriod" name="promotionPeriod" placeholder="e.g., 01/01/2023 - 31/12/2023">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="discountType" class="form-label">Discount Type</label>
|
||||
<select class="form-select" id="discountType" name="discountType">
|
||||
<label for="discountType" class="form-label required">Discount Type</label>
|
||||
<select class="form-select" id="discountType" name="discountType" required>
|
||||
<option value="percentage">Percentage</option>
|
||||
<option value="fixed">Fixed Amount</option>
|
||||
<option value="free">Free Domains</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="discountValue" class="form-label">Discount Value</label>
|
||||
<input type="text" class="form-control" id="discountValue" name="discountValue" placeholder="Enter discount value">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="max_count" class="form-label">Maximum Discounted Items</label>
|
||||
<input type="text" class="form-control" id="max_count" name="max_count">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="promotionConditions" class="form-label">Conditions</label>
|
||||
<textarea class="form-control" id="promotionConditions" name="promotionConditions" rows="3" placeholder="Enter conditions"></textarea>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="promotionDescription" class="form-label">Description</label>
|
||||
<textarea class="form-control" id="promotionDescription" name="promotionDescription" rows="3" placeholder="Enter description"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-footer">
|
||||
<div class="row align-items-center">
|
||||
|
|
|
@ -97,7 +97,8 @@ $app->group('', function ($route) {
|
|||
$route->map(['GET', 'POST'], '/registry/tld/{tld}', SystemController::class . ':manageTld')->setName('manageTld');
|
||||
$route->get('/registry/tlds', SystemController::class .':listTlds')->setName('listTlds');
|
||||
$route->map(['GET', 'POST'], '/registry/reserved', SystemController::class .':manageReserved')->setName('manageReserved');
|
||||
|
||||
$route->post('/registry/promotions', SystemController::class . ':managePromo')->setName('managePromo');
|
||||
|
||||
$route->get('/support', SupportController::class .':view')->setName('ticketview');
|
||||
$route->map(['GET', 'POST'], '/support/new', SupportController::class .':newticket')->setName('newticket');
|
||||
$route->get('/ticket/{ticket}', SupportController::class . ':viewTicket')->setName('viewTicket');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue