Added launch phase management in cp; allocation tokens in db

This commit is contained in:
Pinga 2023-12-18 08:16:39 +02:00
parent b20a44ecb0
commit 34fe2a866f
6 changed files with 221 additions and 10 deletions

View file

@ -783,6 +783,8 @@ class SystemController extends Controller
$premium_categories = $db->select('SELECT * FROM premium_domain_categories');
$promotions = $db->select('SELECT * FROM promotion_pricing WHERE tld_id = ?',
[ $tld['id'] ]);
$launch_phases = $db->select('SELECT * FROM launch_phases WHERE tld_id = ?',
[ $tld['id'] ]);
// Mapping of regex patterns to script names
$regexToScriptName = [
@ -812,6 +814,7 @@ class SystemController extends Controller
'premium_pricing' => $premium_pricing,
'premium_categories' => $premium_categories,
'promotions' => $promotions,
'launch_phases' => $launch_phases,
'currentUri' => $uri
]);
} else {
@ -989,5 +992,77 @@ class SystemController extends Controller
}
}
public function managePhases(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['phaseName'] = substr(trim($data['phaseName']), 0, 255);
$sData['phaseType'] = substr(trim($data['phaseType']), 0, 255);
$sData['phaseDescription'] = substr(trim($data['phaseDescription']), 0, 1000);
$sData['phaseStart'] = date('Y-m-d', strtotime($data['phaseStart']));
$sData['phaseEnd'] = date('Y-m-d', strtotime($data['phaseEnd']));
try {
$currentDateTime = new \DateTime();
$update = $currentDateTime->format('Y-m-d H:i:s.v'); // Current timestamp
$db->beginTransaction();
$existingPhaseType = $db->selectValue(
'SELECT COUNT(*) FROM launch_phases WHERE tld_id = ? AND phase_type = ?',
[
$sData['tldid'],
$sData['phaseType']
]
);
if ($existingPhaseType > 0) {
// phase_type already exists for the tldid
$db->rollBack();
$this->container->get('flash')->addMessage('error', 'The phase type already exists for this TLD.');
return $response->withHeader('Location', '/registry/tld/'.$sData['extension'])->withStatus(302);
}
$db->insert(
'launch_phases',
[
'tld_id' => $sData['tldid'],
'phase_name' => $sData['phaseName'],
'phase_type' => $sData['phaseType'],
'phase_description' => $sData['phaseDescription'],
'start_date' => $sData['phaseStart'],
'end_date' => $sData['phaseEnd'],
'lastupdate' => $update
]
);
$db->commit();
$this->container->get('flash')->addMessage('success', 'Launch phase 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);
}
}
}

View file

@ -191,7 +191,7 @@
</div>
</form>
<div class="card">
<div class="card mb-3">
<div class="card-header">
<h5 class="card-title">Manage Promotions</h5>
</div>
@ -284,6 +284,88 @@
</form>
</div>
</div>
<div class="card">
<div class="card-header">
<h5 class="card-title">Manage Launch Phases</h5>
</div>
<div class="card-body">
<div class="table-responsive mb-3">
<table class="table">
<thead>
<tr>
<th>ID</th>
<th>Phase Type</th>
<th>Phase Name</th>
<th>Phase Description</th>
<th>Start Date</th>
<th>End Date</th>
</tr>
</thead>
<tbody>
{% for phase in launch_phases %}
<tr>
<td>{{ phase.id }}</td>
<td>{{ phase.phase_type }}</td>
<td>{{ phase.phase_name }}</td>
<td>{{ phase.phase_description }}</td>
<td>{{ phase.start_date }}</td>
<td>{{ phase.end_date }}</td>
</tr>
{% else %}
<tr>
<td colspan="6">No launch phases found.</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
<h4 class="card-subtitle mt-3 mb-3">Create New Phase</h4>
<form action="/registry/phases" method="post">
{{ csrf.field | raw }}
<input type="hidden" name="tldid" value="{{ tld.id }}"><input type="hidden" name="extension" value="{{ tld.tld }}">
<div class="mb-3">
<label for="phaseType" class="form-label required">Phase Type</label>
<select class="form-select" id="phaseType" name="phaseType" required>
<option value="sunrise">Sunrise</option>
<option value="landrush">Landrush</option>
<option value="claims">Claims</option>
<option value="open">Open</option>
<option value="custom">Custom</option>
</select>
</div>
<div class="mb-3">
<label for="phaseName" class="form-label required">Phase Name</label>
<input type="text" class="form-control" id="phaseName" name="phaseName" placeholder="Enter phase name" required>
</div>
<div class="mb-3">
<label for="phaseDescription" class="form-label required">Phase Description</label>
<textarea class="form-control" id="phaseDescription" name="phaseDescription" rows="3" placeholder="Enter phase description" required></textarea>
</div>
<div class="row">
<div class="col-sm-6 col-md-6">
<div class="mb-3">
<label for="phaseStart" class="form-label required">Phase Start Date</label>
<input type="date" class="form-control" placeholder="e.g., 01/01/2023" id="phaseStart" name="phaseStart" required>
</div>
</div>
<div class="col-sm-6 col-md-6">
<div class="mb-3">
<label for="phaseEnd" class="form-label">Phase End Date</label>
<input type="date" class="form-control" placeholder="e.g., 01/01/2023" id="phaseEnd" name="phaseEnd">
</div>
</div>
</div>
</div>
<div class="card-footer">
<div class="row align-items-center">
<div class="col-auto">
<button type="submit" class="btn btn-primary">Update Phases</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>

View file

@ -101,6 +101,7 @@ $app->group('', function ($route) {
$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->post('/registry/phases', SystemController::class . ':managePhases')->setName('managePhases');
$route->get('/support', SupportController::class .':view')->setName('ticketview');
$route->map(['GET', 'POST'], '/support/new', SupportController::class .':newticket')->setName('newticket');