Skip to content

Commit

Permalink
Added option to manage custom registrar pricing #129
Browse files Browse the repository at this point in the history
  • Loading branch information
getpinga committed Jul 29, 2024
1 parent a2d8f53 commit d751220
Show file tree
Hide file tree
Showing 4 changed files with 188 additions and 1 deletion.
55 changes: 55 additions & 0 deletions cp/app/Controllers/RegistrarsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -1167,5 +1167,60 @@ function fetchFirstMatchingResult($pdo, $sql, $params) {
return $response->withHeader('Location', '/dashboard')->withStatus(302);
}
}

public function updateCustomPricing(Request $request, Response $response, $args)
{
if ($_SESSION["auth_roles"] != 0) {
return $response->withHeader('Location', '/dashboard')->withStatus(302);
}
//TODO
if ($request->getMethod() === 'POST') {
// Retrieve POST data
$data = $request->getParsedBody();
$db = $this->container->get('db');

var_dump ($data);die();
}

$db = $this->container->get('db');
// Get the current URI
$uri = $request->getUri()->getPath();

if ($args) {
$args = trim($args);

$registrar = $db->selectRow('SELECT id,clid,name FROM registrar WHERE clid = ?',
[ $args ]);
$tlds = $db->select('SELECT id, tld FROM domain_tld');

$result = [];

foreach ($tlds as $tld) {
$createPrices = $db->selectRow('SELECT * FROM domain_price WHERE tldid = ? AND (registrar_id = ? OR registrar_id IS NULL) AND command = ? ORDER BY registrar_id DESC LIMIT 1', [$tld['id'], $registrar['id'], 'create']);
$renewPrices = $db->selectRow('SELECT * FROM domain_price WHERE tldid = ? AND (registrar_id = ? OR registrar_id IS NULL) AND command = ? ORDER BY registrar_id DESC LIMIT 1', [$tld['id'], $registrar['id'], 'renew']);
$transferPrices = $db->selectRow('SELECT * FROM domain_price WHERE tldid = ? AND (registrar_id = ? OR registrar_id IS NULL) AND command = ? ORDER BY registrar_id DESC LIMIT 1', [$tld['id'], $registrar['id'], 'transfer']);
$tld_restore = $db->selectRow('SELECT * FROM domain_restore_price WHERE tldid = ? AND (registrar_id = ? OR registrar_id IS NULL) ORDER BY registrar_id DESC LIMIT 1', [$tld['id'], $registrar['id']]);

$result[] = [
'tld' => $tld['tld'],
'createPrices' => ($createPrices && $createPrices['registrar_id'] === $registrar['id']) ? $createPrices : null,
'renewPrices' => ($renewPrices && $renewPrices['registrar_id'] === $registrar['id']) ? $renewPrices : null,
'transferPrices' => ($transferPrices && $transferPrices['registrar_id'] === $registrar['id']) ? $transferPrices : null,
'tld_restore' => ($tld_restore && $tld_restore['registrar_id'] === $registrar['id']) ? $tld_restore : null,
];
}

return view($response, 'admin/registrars/customPricing.twig', [
'tlds' => $result,
'name' => $registrar['name'],
'clid' => $registrar['clid'],
'currentUri' => $uri,
]);

} else {
// Redirect to the registrars view
return $response->withHeader('Location', '/registrars')->withStatus(302);
}
}

}
131 changes: 131 additions & 0 deletions cp/resources/views/admin/registrars/customPricing.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
{% extends "layouts/app.twig" %}

{% block title %}{{ __('Manage Custom Pricing') }}{% endblock %}

{% block content %}
<div class="page-wrapper">
<!-- Page header -->
<div class="page-header d-print-none">
<div class="container-xl">
<div class="row g-2 align-items-center">
<div class="col">
<!-- Page pre-title -->
<div class="page-pretitle">
{{ __('Overview') }}
</div>
<h2 class="page-title">
{{ __('Manage Custom Pricing') }}
</h2>
</div>
</div>
</div>
</div>
<!-- Page body -->
<div class="page-body">
<div class="container-xl">
<div class="col-12">
{% include 'partials/flash.twig' %}
<form action="/registrar/pricing/{{ clid }}" method="post">
{{ csrf.field | raw }}
<div class="card mb-3">
<div class="card-header">
<h3 class="card-title">{{ __('Registrar') }} {{ name }}</h3>
<div class="card-actions">
<!--<button type="submit" class="btn btn-primary">
<svg xmlns="http://www.w3.org/2000/svg" class="icon" width="24" height="24" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M7 7h-1a2 2 0 0 0 -2 2v9a2 2 0 0 0 2 2h9a2 2 0 0 0 2 -2v-1" /><path d="M20.385 6.585a2.1 2.1 0 0 0 -2.97 -2.97l-8.415 8.385v3h3l8.385 -8.415z" /><path d="M16 5l3 3" /></svg>
{{ __('Update Prices') }}
</button>-->
</div>
</div>
<div class="card-body">
<div class="alert alert-info" role="alert">
{{ __('Custom registrar pricing can currently be viewed in this panel but must be managed directly via the database.') }}
</div>
<div class="table-responsive">
<table class="table table-vcenter table-bordered">
<thead>
<tr>
<th>{{ __('TLD') }} / {{ __('Command') }}</th>
<th>{{ __('Create') }}</th>
<th>{{ __('Renew') }}</th>
<th>{{ __('Transfer') }}</th>
<th>{{ __('Restore Price') }}</th>
</tr>
</thead>
<tbody>
{% for tld in tlds %}
<tr>
<td>{{ tld.tld }}</td>
{% if tld.createPrices or tld.renewPrices or tld.transferPrices or tld.tld_restore %}
<td>
{% if tld.createPrices %}
{% for year in [12, 24, 36, 48, 60, 72, 84, 96, 108, 120] %}
<div class="row mb-2">
<div class="col-auto">
<label class="form-label">{{ year/12 }} Year{{ year > 12 ? 's' : '' }}</label>
</div>
<div class="col">
<input type="text" class="form-control" name="create_{{ tld.tld }}_{{ year }}" value="{{ attribute(tld.createPrices, 'm' ~ year) | default('N/A') }}">
</div>
</div>
{% endfor %}
{% else %}
N/A
{% endif %}
</td>
<td>
{% if tld.renewPrices %}
{% for year in [12, 24, 36, 48, 60, 72, 84, 96, 108, 120] %}
<div class="row mb-2">
<div class="col-auto">
<label class="form-label">{{ year/12 }} Year{{ year > 12 ? 's' : '' }}</label>
</div>
<div class="col">
<input type="text" class="form-control" name="renew_{{ tld.tld }}_{{ year }}" value="{{ attribute(tld.renewPrices, 'm' ~ year) | default('N/A') }}">
</div>
</div>
{% endfor %}
{% else %}
N/A
{% endif %}
</td>
<td>
{% if tld.transferPrices %}
{% for year in [12, 24, 36, 48, 60, 72, 84, 96, 108, 120] %}
<div class="row mb-2">
<div class="col-auto">
<label class="form-label">{{ year/12 }} Year{{ year > 12 ? 's' : '' }}</label>
</div>
<div class="col">
<input type="text" class="form-control" name="transfer_{{ tld.tld }}_{{ year }}" value="{{ attribute(tld.transferPrices, 'm' ~ year) | default('N/A') }}">
</div>
</div>
{% endfor %}
{% else %}
N/A
{% endif %}
</td>
<td>
{% if tld.tld_restore %}
<input type="text" class="form-control" name="restore_{{ tld.tld }}" value="{{ tld.tld_restore.price | default('N/A') }}">
{% else %}
N/A
{% endif %}
</td>
{% else %}
<td colspan="4">{{ __('Registrar does not have custom prices for') }} {{ tld.tld }}</td>
{% endif %}
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
{% include 'partials/footer.twig' %}
</div>
{% endblock %}
2 changes: 1 addition & 1 deletion cp/resources/views/partials/js-registrars.twig
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
function actionsFormatter(cell, formatterParams, onRendered) {
return `
<a class="btn btn-outline-primary btn-icon update-btn" href="/registrar/update/${cell.getRow().getData().clid}"><svg xmlns="http://www.w3.org/2000/svg" class="icon" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M7 7h-1a2 2 0 0 0 -2 2v9a2 2 0 0 0 2 2h9a2 2 0 0 0 2 -2v-1"></path><path d="M20.385 6.585a2.1 2.1 0 0 0 -2.97 -2.97l-8.415 8.385v3h3l8.385 -8.415z"></path><path d="M16 5l3 3"></path></svg></a>
<a class="btn btn-outline-primary btn-icon update-btn" href="/registrar/update/${cell.getRow().getData().clid}" title="{{ __('Manage Registrar') }}"><svg xmlns="http://www.w3.org/2000/svg" class="icon" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M7 7h-1a2 2 0 0 0 -2 2v9a2 2 0 0 0 2 2h9a2 2 0 0 0 2 -2v-1"></path><path d="M20.385 6.585a2.1 2.1 0 0 0 -2.97 -2.97l-8.415 8.385v3h3l8.385 -8.415z"></path><path d="M16 5l3 3"></path></svg></a> <a class="btn btn-outline-secondary btn-icon update-btn" href="/registrar/pricing/${cell.getRow().getData().clid}" title="{{ __('Manage Custom Pricing') }}"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M5 21v-16a2 2 0 0 1 2 -2h10a2 2 0 0 1 2 2v16l-3 -2l-2 2l-2 -2l-2 2l-2 -2l-3 2" /><path d="M14 8h-2.5a1.5 1.5 0 0 0 0 3h1a1.5 1.5 0 0 1 0 3h-2.5m2 0v1.5m0 -9v1.5" /></svg></a>
`;
}
Expand Down
1 change: 1 addition & 0 deletions cp/routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
$route->map(['GET', 'POST'], '/registrar/create', RegistrarsController::class . ':create')->setName('registrarcreate');
$route->get('/registrar/view/{registrar}', RegistrarsController::class . ':viewRegistrar')->setName('viewRegistrar');
$route->get('/registrar/update/{registrar}', RegistrarsController::class . ':updateRegistrar')->setName('updateRegistrar');
$route->map(['GET', 'POST'], '/registrar/pricing/{registrar}', RegistrarsController::class . ':updateCustomPricing')->setName('updateCustomPricing');
$route->post('/registrar/update', RegistrarsController::class . ':updateRegistrarProcess')->setName('updateRegistrarProcess');
$route->get('/registrar', RegistrarsController::class .':registrar')->setName('registrar');
$route->map(['GET', 'POST'], '/registrar/edit', RegistrarsController::class .':editRegistrar')->setName('editRegistrar');
Expand Down

0 comments on commit d751220

Please sign in to comment.