<?php
/* PACK839_ACTIVE_TEMPLATE_LOADER */
if(!isset($templates)){
    $templates=[];
    try{
        $db=\App\Core\Database::getInstance();
        $cid=(int)($_SESSION["conference_id"] ?? $_SESSION["current_conference_id"] ?? 0);
        if($cid>0){
            $st=$db->prepare("SELECT * FROM conference_email_templates WHERE conference_id=? ORDER BY is_active DESC, template_key ASC");
            $st->execute([$cid]);
            $templates=$st->fetchAll(PDO::FETCH_ASSOC) ?: [];
        }
    }catch(Throwable $e){
        $templates=[];
    }
}
?>

<?php

function etp_h($v){
return htmlspecialchars((string)$v,ENT_QUOTES,'UTF-8');
}

$templates=$templates??[];
$conference=$conference??[];

$success=$_SESSION['flash_success']??'';
$error=$_SESSION['flash_error']??'';

unset(
$_SESSION['flash_success'],
$_SESSION['flash_error']
);

$db=\App\Core\Database::getInstance();

$confs=
$db
->query("
SELECT
id,
short_name
FROM conferences
ORDER BY id
")
->fetchAll(PDO::FETCH_ASSOC);

?>

<div class="container-fluid py-3">

<div
class="
card
border-0
shadow-sm
mb-4
"
style="
border-radius:28px;
background:
linear-gradient(
135deg,
#07112d,
#1d4ed8
);

color:#fff;
">

<div class="card-body p-4">

<div
class="
d-flex
justify-content-between
align-items-center
flex-wrap
">

<div>

<h3 class="fw-bold">

<i
class="
fa
fa-envelope-open-text
">

</i>

Conference
<?php echo ec_h(ec_t('admin.email_templates.title','Email Templates')); ?>

</h3>

<div class="opacity-75">

Manage conference email templates professionally

</div>

</div>

<div>

<span
class="
badge
bg-light
text-dark
">

<?= etp_h(
($conference['short_name']??'')
.
' / #'
.
($conference['id']??'')
) ?>

</span>

<span
class="
badge
bg-warning
text-dark
">

Org
#
<?= (int)(
$conference['org_id']
??0
) ?>

</span>

</div>

</div>

<div
class="
mt-4
p-4
"
style="
background:
rgba(
255,
255,
255,
.10
);

border-radius:24px;
">

<h5>

<i
class="
fa
fa-copy
">

</i>

Clone Templates

</h5>

<form
method="post"
action="/easychair/admin/email-templates/clone">

<div
class="
row
g-3
align-items-end
">

<div class="col-md-4">

<label>

Source

</label>

<select
required
name="source_conference_id"
class="
form-select
rounded-pill
">

<option value="">
Select source
</option>

<?php foreach($confs as $c): ?>

<option
value="<?= $c['id'] ?>">

#<?= $c['id'] ?>

—

<?= etp_h(
$c['short_name']
) ?>

</option>

<?php endforeach; ?>

</select>

</div>

<div class="col-md-4">

<label>

Target

</label>

<select
required
name="target_conference_id"
class="
form-select
rounded-pill
">

<option value="">
Select target
</option>

<?php foreach($confs as $c): ?>

<option
value="<?= $c['id'] ?>">

#<?= $c['id'] ?>

—

<?= etp_h(
$c['short_name']
) ?>

</option>

<?php endforeach; ?>

</select>

</div>

<div class="col-md-2">

<div class="form-check">

<input
type="checkbox"
name="overwrite"
value="1">

Overwrite

</div>

<div class="form-check">

<input
checked
type="checkbox"
name="activate"
value="1">

Activate

</div>

</div>

<div class="col-md-2">

<button
class="
btn
btn-light
w-100
rounded-pill
">

Clone

</button>

</div>

</div>

</form>

</div>

</div>

</div>

<?php if ($success): ?>
<div class="alert alert-success"><?= etp_h($success) ?></div>
<?php endif; ?>

<?php if ($error): ?>
<div class="alert alert-danger"><?= etp_h($error) ?></div>
<?php endif; ?>

<div class="alert alert-info">
Available placeholders:
<code>{author_name}</code>
<code>{reviewer_name}</code>
<code>{submission_no}</code>
<code>{conference_title}</code>
</div>



<?php /* PACK838 */ ?>

<?php if(!empty($templates)): ?>

<div
class="card mt-4"
style="
border-radius:26px;
padding:30px;
">

<h2>

Active Email Templates

</h2>

<div
style="
display:grid;
grid-template-columns:
repeat(
auto-fill,
minmax(
430px,
1fr
)
);
gap:20px;
"
>

<?php foreach($templates as $t): ?>

<div
style="
border:
<?= !empty($t['is_active'])
?'2px solid #10b981'
:'1px solid #e5e7eb'
?>;

padding:22px;

border-radius:18px;

background:
<?= !empty($t['is_active'])
?'linear-gradient(135deg,#f0fff7,#ffffff)'
:'#fff'
?>
"
>

<div
style="
display:flex;
justify-content:space-between;
"
>

<h4>

<?= htmlspecialchars(
$t['template_key']
??'-'
) ?>

</h4>

<span
class="
badge
<?= !empty($t['is_active'])
?'bg-success'
:'bg-secondary'
?>
"
>

<?= !empty($t['is_active'])
?'ACTIVE'
:'INACTIVE'
?>

</span>

</div>

<div>

<b>
Subject
</b>

<br>

<?= htmlspecialchars(
$t['subject_en']
??''
) ?>

</div>

<hr>

<div
style="
max-height:180px;
overflow:auto;
"
>

<?= nl2br(
htmlspecialchars(
strip_tags(
$t['body_en']
??''
)
)
) ?>

</div>

</div>

<?php endforeach; ?>

</div>

</div>

<?php else: ?>

<div
class="alert alert-warning mt-4"
>

No templates found for this conference.

</div>

<?php endif; ?>


<?php /* PACK840_TEMPLATE_GRID */ ?>

<hr class="my-5">

<div class="card-glass p-4">

<div class="d-flex justify-content-between mb-4">

<h2>
Email Templates
</h2>

<a
href="/easychair/admin/email-templates/store"
class="btn btn-success"
>

+ New Template

</a>

</div>

<?php if(!empty($templates)): ?>

<div class="row">

<?php foreach($templates as $t): ?>

<div class="col-md-6 mb-4">

<div
class="card shadow"
style="
border-radius:24px;
border:
<?= !empty($t['is_active'])
?'2px solid #16a34a'
:'1px solid #ddd'
?>
"
>

<div class="card-body">

<div class="d-flex justify-content-between">

<h4>

<?=e($t['template_key'])?>

</h4>

<span
class="
badge
<?= !empty($t['is_active'])
?'bg-success'
:'bg-secondary'
?>
"
>

<?= !empty($t['is_active'])
?'ACTIVE'
:'INACTIVE'
?>

</span>

</div>

<div class="mt-3">

<b>Subject</b>

<br>

<?=e(
$t['subject_en']
??''
)?>

</div>

<hr>

<div
style="
max-height:180px;
overflow:auto;
"
>

<?=nl2br(
e(
strip_tags(
$t['body_en']
??''
)
)
)?>

</div>

<div
class="
mt-4
d-flex
gap-2
flex-wrap
"
>

<a
class="btn btn-primary"

href="/easychair/admin/email-templates/edit?id=<?=$t['id']?>"

>

Edit

</a>

<a
class="btn btn-warning"

href="/easychair/admin/email-templates/duplicate?id=<?=$t['id']?>"

>

Duplicate

</a>

<a
class="btn btn-danger"

onclick="
return confirm(
'Delete template?'
)
"

href="/easychair/admin/email-templates/delete?id=<?=$t['id']?>"

>

Delete

</a>

</div>

</div>

</div>

</div>

<?php endforeach; ?>

</div>

<?php else: ?>

<div
class="
alert
alert-warning
"
>

No templates configured for this conference.

</div>

<?php endif; ?>

</div>

