<?php

/* PACK707_INLINE_TOGGLE */

try{

if(
isset($_GET['toggle_block'])
){

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

$id=
(int)
$_GET['toggle_block'];

$mode=
$_GET['mode']
??
'enabled';

$field=
(
$mode==='required'
)

?

'is_required'

:

'is_enabled';

$sql=

"

UPDATE
review_form_blocks

SET

{$field}=

CASE

WHEN {$field}=1

THEN 0

ELSE 1

END

WHERE id=?

";

$s=
$db->prepare(
$sql
);

$s->execute(
[
$id
]
);

echo
"<script>

location.href='/easychair/admin/review-form';

</script>";

exit;

}

}catch(
Exception $e
){}

?>


<?php
$title = "Review Form Criteria";
?>

<div class="card">
    <div class="card-header d-flex justify-content-between">
        <h3>Review Form Criteria</h3>


<a
    href="/easychair/admin/review-form/import-default"
    class="btn btn-warning rounded-pill fw-bold">

    <i class="fa fa-download"></i>
    <?= t('review.import_default', 'Import Default Review Form') ?>

</a>


        <a href="/easychair/admin/review-form/create"
           class="btn btn-primary">
            Add Criterion
        </a>
    </div>

    <div class="card-body">

        <table class="table table-bordered table-striped">

            <thead>
                <tr>
                    <th>#</th>
                    <th>Arabic Label</th>
                    <th>English Label</th>
                    <th>Max Score</th>
                    <th>Weight</th>
                    <th>Status</th>
                    <th width="220">Actions</th>
                </tr>
            </thead>

            <tbody>

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

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

<tr>

<td>
<?= (int)$c['id'] ?>
</td>

<td>
<?= htmlspecialchars($c['title_ar'] ?? '') ?>
</td>

<td>
<?= htmlspecialchars($c['title_en'] ?? '') ?>
</td>

<td>
<?= htmlspecialchars($c['max_score'] ?? '') ?>
</td>

<td>
<?= htmlspecialchars($c['weight'] ?? '') ?>
</td>

<td>

<?php if (($c['is_active'] ?? 1) == 1): ?>

<span class="badge bg-success">
Active
</span>

<?php else: ?>

<span class="badge bg-secondary">
Inactive
</span>

<?php endif; ?>

</td>

<td>

<a href="/easychair/admin/review-form/edit?id=<?= (int)$c['id'] ?>"
   class="btn btn-sm btn-warning">
Edit
</a>

<a href="/easychair/admin/review-form/toggle?id=<?= $c['id'] ?>"
   class="btn btn-sm btn-info">
Toggle
</a>

<a href="/easychair/admin/review-form/delete?id=<?= (int)$c['id'] ?>"
   class="btn btn-sm btn-danger"
   onclick="return confirm('Delete this criterion?');">
Delete
</a>

</td>

</tr>

<?php endforeach; ?>

<?php else: ?>

<tr>
<td colspan="7" class="text-center">
No criteria found
</td>
</tr>

<?php endif; ?>

            </tbody>

        </table>

    </div>
</div>


<!-- PACK706_REVIEW_BUILDER -->

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

<div class="card">

<div class="card-body">

<h4>

Review Form Builder

</h4>

<table class="table">

<tr>

<th>Block</th>

<th>Enabled</th>

<th>Required</th>

</tr>

<?php foreach($blocks as $b): ?>

<tr>

<td>

<?=htmlspecialchars(
$b['label_en']
)?>

</td>

<td>

<?=

$b['is_enabled']

?

'✓'

:

'✕

'?>

</td>

<td>

<?=

$b['is_required']

?

'*'

:

''

?>

</td>

</tr>

<?php endforeach; ?>

</table>

</div>

</div>

<?php endif; ?>



<!-- PACK706B_UI -->

<?php if(isset($builderBlocks)): ?>

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

<div class="card-body">

<h3>

Review Form Builder

</h3>

<div class="text-muted mb-3">

SuperAdmin controls reviewer blocks

</div>

<table
class="
table
table-striped
"
>

<thead>

<tr>

<th>#</th>

<th>Block</th>

<th>Enabled</th>

<th>Required</th>

</tr>

</thead>

<tbody>

<?php foreach($builderBlocks as $i=>$b): ?>

<tr>

<td>

<?= $i+1 ?>

</td>

<td>

<?= htmlspecialchars(
$b['label_en']
??
$b['block_key']
) ?>

</td>

<td>

<?=

!empty(
$b['is_enabled']
)

?

'<span class="badge bg-success">ON</span>'

:

'<span class="badge bg-danger">OFF</span>'

?>

</td>

<td>

<?=

!empty(
$b['is_required']
)

?

'<span class="badge bg-warning">*</span>'

:

''

?>

</td>

</tr>

<?php endforeach; ?>

</tbody>

</table>

</div>

</div>

<?php endif; ?>

<!-- END PACK706B_UI -->



<!-- PACK706_REAL_VIEW -->

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

<div class="card mt-4">

<div class="card-header">

<h4>

Review Form Builder

</h4>

</div>

<div class="card-body">

<table class="table">

<thead>

<tr>

<th>

Block

</th>

<th>

Enabled

</th>

<th>

Required

</th>

</tr>

</thead>

<tbody>

<?php foreach($blocks as $b): ?>

<tr>

<td>

<?=htmlspecialchars(
$b['label_en']
)?>

</td>

<td>

<a
href="
/easychair/admin/review-form
?toggle_block=<?= (int)$b['id'] ?>
&mode=enabled
"
class="
btn
btn-sm
<?= !empty($b['is_enabled'])?'btn-success':'btn-secondary' ?>
"
>

<?= !empty($b['is_enabled'])?'ON':'OFF' ?>

</a>

</td>

<td>

<a
href="
/easychair/admin/review-form
?toggle_block=<?= (int)$b['id'] ?>
&mode=required
"
class="
btn
btn-sm
<?= !empty($b['is_required'])?'btn-warning':'btn-outline-warning' ?>
"
>

<?= !empty($b['is_required'])?'*':'-' ?>

</a>

</td>

</tr>

<?php endforeach; ?>

</tbody>

</table>

</div>

</div>

<?php endif; ?>

