<?php
function rev_h($v) { return htmlspecialchars((string)$v, ENT_QUOTES, 'UTF-8'); }
function rev_t($key, $fallback) {
    if (function_exists('ec_t')) return ec_t($key, $fallback);
    if (function_exists('t')) return t($key, $fallback);
    return $fallback;
}
function rev_status($v) {
    return function_exists('ec_review_status_t')
        ? ec_review_status_t($v)
        : (string)$v;
}

if (!function_exists('ad_h')) {
    function ad_h($v) {
        return rev_h($v);
    }
}

/*
|--------------------------------------------------------------------------
| LANGUAGE MODE
|--------------------------------------------------------------------------
*/

$lang =
    $_SESSION['lang']
    ?? 'ar';

$isArabic =
    $lang === 'ar';

$dir =
    $isArabic
        ? 'rtl'
        : 'ltr';

$assignments = $assignments ?? [];
$stats = $stats ?? [];


?>

<style>

.meta-chip{
padding:10px 18px;
border-radius:999px;
font-weight:700;
display:inline-flex;
align-items:center;
gap:8px;
}

</style>

<div class="container-fluid">
    
<div
class="card border-0 shadow-sm mb-4 overflow-hidden"
style="
border-radius:28px;
background:
linear-gradient(
135deg,
#0f172a,
#1d4ed8
);
color:#fff;
"
>

<div class="card-body p-5 position-relative">

<div
style="
position:absolute;
top:-60px;
right:-60px;
width:220px;
height:220px;
background:rgba(255,255,255,.08);
border-radius:50%;
"
></div>

<div class="position-relative z-2">

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

<div>

<div class="opacity-75 mb-2">

<?= $isArabic
? 'مساحة المحكّم'
: 'Reviewer Workspace' ?>

</div>

<h2 class="fw-bold mb-3">

<?= rev_h(
$_SESSION['conference_short_name']
?? 'Conference'
) ?>

</h2>

<div class="opacity-75 fs-5">

<?= $isArabic
? 'إدارة عمليات التحكيم العلمي'
: 'Scientific Review Management Portal' ?>

</div>

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

<div class="meta-chip text-dark bg-white">

<i class="fa fa-list-check"></i>

<?= (int)($stats['total'] ?? 0) ?>

<?= $isArabic
? 'تكليف'
: 'Assignments' ?>

</div>

<div class="meta-chip text-dark bg-white">

<i class="fa fa-hourglass-half"></i>

<?= (int)($stats['assigned'] ?? 0) ?>

<?= $isArabic
? 'قيد الانتظار'
: 'Pending' ?>

</div>

<div class="meta-chip text-dark bg-white">

<i class="fa fa-circle-check"></i>

<?= (int)($stats['completed'] ?? 0) ?>

<?= $isArabic
? 'مكتمل'
: 'Completed' ?>

</div>

</div>

</div>

<div class="d-flex flex-column gap-2">

<a
class="btn btn-light btn-lg rounded-pill fw-bold"
href="/easychair/reviewer/assignments"
>

<i class="fa fa-clipboard-check"></i>

<?= $isArabic
? 'إدارة التكليفات'
: 'Manage Assignments' ?>

</a>

<a
class="btn btn-outline-light rounded-pill fw-bold"
href="/easychair/reviewer/history"
>

<?= $isArabic
? 'سجل التحكيم'
: 'Review History' ?>

</a>

</div>

</div>

</div>

</div>

</div>

<?php

$today =
    date('Y-m-d');

$overdueCount = 0;

foreach (($assignments ?? []) as $a) {

    if (
        !empty($a['due_date'])
        &&
        ($a['status'] ?? '') !== 'completed'
        &&
        $a['due_date'] < $today
    ) {
        $overdueCount++;
    }
}

?>    

<div class="row g-3 mb-4">
        <?php

$cards = [

[
'reviewer.dashboard.total_assignments',
'Total Assignments',
(int)($stats['total'] ?? 0),
'fa-list-check'
],

[
'reviewer.dashboard.pending_assignments',
'Pending Assignments',
(int)($stats['assigned'] ?? 0),
'fa-hourglass-half'
],

[
'reviewer.dashboard.completed_reviews',
'Completed Reviews',
(int)($stats['completed'] ?? 0),
'fa-circle-check'
],

[
'reviewer.dashboard.late_reviews',
'Late Reviews',
$overdueCount,
'fa-triangle-exclamation'
],

];        

        foreach ($cards as $c):
        ?>
            <div class="col-lg-3 col-md-6">
                <div class="card border-0 shadow-sm h-100" style="border-radius:20px;">
                    <div class="card-body p-4 d-flex justify-content-between align-items-center">
                        <div>
                            <div class="text-muted small fw-bold"><?= rev_h(rev_t($c[0],$c[1])) ?></div>
                            <div class="fs-2 fw-black fw-bold"><?= (int)$c[2] ?></div>
                        </div>
                        <div class="rounded-circle d-flex align-items-center justify-content-center" style="width:52px;height:52px;background:#eef2ff;color:#1d4ed8;">
                            <i class="fa <?= rev_h($c[3]) ?>"></i>
                        </div>
                    </div>
                </div>
            </div>
        <?php endforeach; ?>


    </div>

<?php if ($overdueCount > 0): ?>

<div
class="alert alert-danger border-0 shadow-sm mb-4"
style="border-radius:18px;"
>

<i class="fa fa-triangle-exclamation"></i>

<?= $isArabic
? "لديك {$overdueCount} مراجعة متأخرة."
: "You have {$overdueCount} overdue reviews." ?>

</div>

<?php endif; ?>

<?php if ((int)($stats['assigned'] ?? 0) > 0): ?>

<div
class="alert alert-warning border-0 shadow-sm mb-4"
style="border-radius:18px;"
>

<i class="fa fa-hourglass-half"></i>

<?= $isArabic
? 'هناك مراجعات بانتظار الإكمال.'
: 'Pending reviews require completion.' ?>

</div>

<?php endif; ?>
    
<?php

$acceptedRows =
array_filter(
    $assignments,
    fn($x)=>
    strtolower($x['status'] ?? '') === 'accepted'
);

$completedRows =
array_filter(
    $assignments,
    fn($x)=>
    strtolower($x['status'] ?? '') === 'completed'
);

$pendingRows =
array_filter(
    $assignments,
    fn($x)=>
    in_array(
        strtolower($x['status'] ?? ''),
        ['assigned','accepted','overdue'],
        true
    )
);

?>

<div class="row g-4 mb-4">

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

<div class="card border-0 shadow-sm h-100" style="border-radius:24px;">
<div class="card-body">

<h5 class="fw-bold mb-4">
<i class="fa fa-radar"></i>
<?= $isArabic ? 'رادار المواعيد' : 'Deadline Radar' ?>
</h5>

<?php if (count($pendingRows)): ?>

<?php foreach (array_slice($pendingRows,0,5) as $r): ?>

<div class="border rounded-4 p-3 mb-3">

<div class="fw-bold">
<?= rev_h(($r['title'] ?? '') ?: ('Submission #' . ($r['submission_id'] ?? ''))) ?>
</div>

<div class="small text-muted">
<?= $isArabic ? 'الحالة' : 'Status' ?>:
<?= rev_h(rev_status($r['status'] ?? 'assigned')) ?>
</div>

<div class="small text-muted">
<?= $isArabic ? 'الموعد' : 'Due' ?>:
<?= rev_h($r['due_date'] ?? '-') ?>
</div>

<a
class="btn btn-sm btn-primary rounded-pill mt-2"
href="/easychair/reviewer/review?assignment_id=<?= (int)$r['id'] ?>"
>
<?= $isArabic ? 'فتح المراجعة' : 'Open Review' ?>
</a>

</div>

<?php endforeach; ?>

<?php else: ?>

<div class="text-muted py-4">
<?= $isArabic ? 'لا توجد مراجعات معلقة.' : 'No pending reviews.' ?>
</div>

<?php endif; ?>

</div>
</div>

</div>

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

<div class="card border-0 shadow-sm h-100" style="border-radius:24px;">
<div class="card-body">

<h5 class="fw-bold mb-4">
<i class="fa fa-chart-pie"></i>
<?= $isArabic ? 'توزيع الحالات' : 'Status Distribution' ?>
</h5>

<?php

$statusMap = [
    'assigned'  => $stats['assigned'] ?? 0,
    'accepted'  => $stats['accepted'] ?? 0,
    'completed' => $stats['completed'] ?? 0,
    'overdue'   => $stats['overdue'] ?? 0,
];

?>

<?php foreach ($statusMap as $label => $value): ?>

<div class="mb-3">

<div class="d-flex justify-content-between small fw-bold mb-1">
<span><?= rev_h(rev_status($label)) ?></span>
<span><?= (int)$value ?></span>
</div>

<div class="progress" style="height:9px;border-radius:999px;">
<div
class="progress-bar"
style="width:<?= max(0,min(100,((int)($stats['total'] ?? 0) > 0 ? ((int)$value / (int)$stats['total']) * 100 : 0))) ?>%"
></div>
</div>

</div>

<?php endforeach; ?>

<?php if (!empty($stats['avg_score'])): ?>

<div class="alert alert-info border-0 mt-4 mb-0" style="border-radius:18px;">
<i class="fa fa-star"></i>
<?= $isArabic ? 'متوسط التقييمات المقدمة' : 'Average submitted score' ?>:
<strong><?= rev_h($stats['avg_score']) ?></strong>
</div>

<?php endif; ?>

</div>
</div>

</div>

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

<div class="card border-0 shadow-sm h-100" style="border-radius:24px;">
<div class="card-body">

<h5 class="fw-bold mb-4">
<i class="fa fa-circle-check"></i>
<?= $isArabic ? 'مراجعات جاهزة للإكمال' : 'Ready to Complete' ?>
</h5>

<?php if (count($acceptedRows)): ?>

<?php foreach (array_slice($acceptedRows,0,5) as $r): ?>

<div class="border rounded-4 p-3 mb-3">

<div class="fw-bold">
<?= rev_h(($r['title'] ?? '') ?: ('Submission #' . ($r['submission_id'] ?? ''))) ?>
</div>

<div class="small text-muted mb-2">
<?= $isArabic ? 'الجولة' : 'Round' ?> #<?= (int)($r['current_round_no'] ?? 1) ?>
</div>

<a
class="btn btn-sm btn-success rounded-pill"
href="/easychair/reviewer/review?assignment_id=<?= (int)$r['id'] ?>"
>
<?= $isArabic ? 'إكمال التحكيم' : 'Complete Review' ?>
</a>

</div>

<?php endforeach; ?>

<?php else: ?>

<div class="text-muted py-4">
<?= $isArabic ? 'لا توجد مراجعات مقبولة تنتظر الإكمال.' : 'No accepted reviews waiting for completion.' ?>
</div>

<?php endif; ?>

</div>
</div>

</div>

</div>


<div class="card border-0 shadow-sm" style="border-radius:22px;">
        <div class="card-body p-4">
            <div class="d-flex justify-content-between align-items-center flex-wrap gap-2 mb-3">
                <h5 class="fw-bold mb-0"><?= rev_h(rev_t('reviewer.assignments.title','Review Assignments')) ?></h5>
                <a class="btn btn-primary rounded-pill" href="/easychair/reviewer/assignments">
                    <?= rev_h(rev_t('action.view','View')) ?>
                </a>
            </div>

            <div class="table-responsive">
                <table class="table table-bordered align-middle">
                    <thead class="table-dark">
                    <tr>
                        <th><?= rev_h(rev_t('reviewer.assignment.submission_no','Submission No.')) ?></th>
                        <th><?= rev_h(rev_t('reviewer.assignment.paper_title','Paper Title')) ?></th>
                        <th><?= rev_h(rev_t('reviewer.assignment.review_status','Review Status')) ?></th>
                        <th><?= rev_h(rev_t('reviewer.assignment.deadline','Deadline')) ?></th>
                        <th><?= rev_h(rev_t('submission.actions','Actions')) ?></th>
                    </tr>
                    </thead>
                    <tbody>
                    <?php foreach (array_slice($assignments, 0, 10) as $a): ?>
                        <tr>

                            <td>
    #<?= (int)($a['submission_id'] ?? 0) ?>
</td>

                            <td>
                                <div class="fw-bold mb-1">

<?= rev_h(
($a['title'] ?? '')
?: ($a['title_ar'] ?? '')
) ?>

</div>

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

<span class="badge bg-primary">

<?= $isArabic
? 'جولة'
: 'Round' ?>

#<?= (int)(
$a['current_round_no']
?? 1
) ?>

</span>

<?php if (($a['status'] ?? '') === 'completed'): ?>

<span class="badge bg-success">

<?= $isArabic
? 'مكتمل'
: 'Completed' ?>

</span>

<?php endif; ?>

</div>
                            </td>
                            <td style="min-width:180px;">

<?php

$status =
    strtolower(
        (string)(
            $a['status']
            ?? ''
        )
    );

$progress = match ($status) {

    'assigned' => 25,

    'accepted' => 45,

    'completed' => 100,

    'overdue' => 15,

    default => 20
};

?>

<div class="fw-bold mb-1">

<?= rev_h(
rev_status(
$a['status']
?? 'assigned'
)
) ?>

</div>

<div class="progress" style="height:8px;border-radius:999px;">

<div
class="progress-bar"
style="width:<?= $progress ?>%"
></div>

</div>

<div class="small text-muted mt-1">

<?= $progress ?>%

</div>

</td>
                            <td><?= rev_h($a['due_date'] ?? '') ?></td>
                            <td>
			<?php if (($a['status'] ?? '') !== 'completed'): ?>

<a
href="/easychair/reviewer/review?assignment_id=<?= (int)$a['id'] ?>"
class="btn btn-primary btn-sm"
>
Review
</a>

<?php else: ?>

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

<?php endif; ?>

                            </td>
                        </tr>
                    <?php endforeach; ?>

                    <?php if (!$assignments): ?>
                        <tr>
                            <td colspan="5" class="text-center text-muted py-4">
                                <?= rev_h(rev_t('reviewer.assignments.no_assignments','No review assignments found.')) ?>
                            </td>
                        </tr>
                    <?php endif; ?>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>









<!-- PACK 679 -->

<?php

$rvItems=
$assignments
??
$reviews
??
[];

$rvAssigned=count($rvItems);

$rvDone=0;

$rvPending=0;

foreach($rvItems as $r){

$st=
strtolower(
(string)(
$r['status']
??
''
));

if(
in_array(
$st,
['completed','submitted'],
true
)
){
$rvDone++;
}

if(
in_array(
$st,
['assigned','under_review'],
true
)
){
$rvPending++;
}

}

$rvHealth=
$rvAssigned
?
round(
($rvDone/$rvAssigned)*100
)
:
0;

?>

<div class="card shadow-sm border-0 rounded-4 mb-4">

<div class="card-body">

<h4 class="mb-4">

<?= $isArabic
?
'لوحة عمليات المراجع'
:
'Reviewer Operations Dashboard'
?>

</h4>

<div class="row g-3">

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

<div class="border rounded-4 p-4 text-center">

<div class="display-6">

<?= $rvAssigned ?>

</div>

Assignments

</div>

</div>

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

<div class="border rounded-4 p-4 text-center">

<div class="display-6">

<?= $rvDone ?>

</div>

Completed

</div>

</div>

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

<div class="border rounded-4 p-4 text-center">

<div class="display-6">

<?= $rvPending ?>

</div>

Active

</div>

</div>

</div>

</div>

</div>

<!-- END PACK 679 -->


<!-- PACK 680 -->

<?php

$rv=
$assignments
??
$reviews
??
[];

$queue=[];

$completed=0;

$reviewing=0;

$revision=0;

foreach($rv as $r){

$status=
strtolower(
(string)(
$r['status']
??
''
));

$title=
$r['title']
??
$r['submission_title']
??
(
$isArabic
?
'بدون عنوان'
:
'Untitled'
);

if(
in_array(
$status,
[
'completed',
'submitted'
],
true
)
){
$completed++;
}

if(
$status==='under_review'
){
$reviewing++;
}

if(
$status==='revision_required'
){
$revision++;
}

$queue[]=[

'title'=>$title,

'step'=>
match(
$status
){

'assigned'=>
(
$isArabic
?
'ابدأ المراجعة'
:
'Start Review'
),

'under_review'=>
(
$isArabic
?
'حل التعارضات'
:
'Resolve Findings'
),

'submitted'=>
(
$isArabic
?
'بانتظار القرار'
:
'Await Decision'
),

'completed'=>
(
$isArabic
?
'تم الإنجاز'
:
'Completed'
),

default=>
(
$isArabic
?
'متابعة'
:
'Track'
)

}

];

}

$total=
max(
1,
count(
$rv
)
);

$confidence=
round(
(
$completed
/
$total
)
*
100
);

$consensus=
max(
0,
100-
(
$revision
*
8
)
);

$engine=
round(
(
$confidence
+
$consensus
+
(
$reviewing
*
5
)
)
/
3
);

$engine=
min(
100,
$engine
);

?>

<div class="card shadow-sm border-0 rounded-4 mb-4">

<div class="card-body">

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

<div>

<h4>

<?= $isArabic
?
'ذكاء القرار'
:
'Decision Intelligence'
?>

</h4>

<div class="text-muted">

<?= $isArabic
?
'التوافق ومحرك التوصية'
:
'Consensus and recommendation engine'
?>

</div>

</div>

<div class="display-5 fw-bold text-success">

<?= $engine ?>%

</div>

</div>

<div class="row g-3">

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

<div class="border rounded-4 p-4 text-center">

<div class="display-6">

<?= $confidence ?>

</div>

Confidence

</div>

</div>

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

<div class="border rounded-4 p-4 text-center">

<div class="display-6">

<?= $consensus ?>

</div>

Consensus

</div>

</div>

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

<div class="border rounded-4 p-4 text-center">

<div class="display-6">

<?= $reviewing ?>

</div>

Active

</div>

</div>

</div>

<hr>

<?php foreach(
array_slice(
$queue,
0,
8
)
as $row
): ?>

<div class="mb-3">

<div class="fw-bold">

<?= htmlspecialchars(
(string)$row['title']
) ?>

</div>

<div class="small text-muted">

<?= htmlspecialchars(
(string)$row['step']
) ?>

</div>

</div>

<?php endforeach; ?>

</div>

</div>

<!-- END PACK 680 -->


<!-- PACK 681 -->

<?php

$items=
$assignments
??
$reviews
??
[];

$queue=[];

$done=0;

$active=0;

$revision=0;

$decision=0;

foreach($items as $r){

$status=
strtolower(
(string)(
$r['status']
??
''
));

$title=
$r['title']
??
$r['submission_title']
??
(
$isArabic
?
'بدون عنوان'
:
'Untitled'
);

if(
in_array(
$status,
[
'completed',
'submitted'
],
true
)
){
$done++;
}

if(
in_array(
$status,
[
'assigned',
'under_review'
],
true
)
){
$active++;
}

if(
$status==='revision_required'
){
$revision++;
}

if(
$status==='completed'
){
$decision++;
}

$queue[]=[

'title'=>$title,

'step'=>
match(
$status
){

'assigned'=>
(
$isArabic
?
'بناء الأدلة'
:
'Build Evidence'
),

'under_review'=>
(
$isArabic
?
'تعميق التقييم'
:
'Deep Review'
),

'submitted'=>
(
$isArabic
?
'القرار النهائي'
:
'Final Verdict'
),

'completed'=>
(
$isArabic
?
'تم الإغلاق'
:
'Closed'
),

default=>
(
$isArabic
?
'متابعة'
:
'Track'
)

}

];

}

$total=
max(
1,
count(
$items
)
);

$throughput=
round(
(
$done
/
$total
)
*
100
);

$health=
max(
0,
100-
(
$revision
*
10
)
);

$verdict=
round(
(
$throughput
+
$health
+
(
$decision
*
5
)
)
/
3
);

$verdict=
min(
100,
$verdict
);

?>

<div class="card shadow-sm border-0 rounded-4 mb-4">

<div class="card-body">

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

<div>

<h4>

<?= $isArabic
?
'مساحة القرار النهائي'
:
'Final Verdict Workspace'
?>

</h4>

<div class="text-muted">

<?= $isArabic
?
'تحليلات الإنجاز ومخطط الأدلة'
:
'Evidence graph and throughput analytics'
?>

</div>

</div>

<div class="display-5 fw-bold text-primary">

<?= $verdict ?>%

</div>

</div>

<div class="row g-3">

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

<div class="border rounded-4 p-4 text-center">

<div class="display-6">

<?= $done ?>

</div>

Completed

</div>

</div>

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

<div class="border rounded-4 p-4 text-center">

<div class="display-6">

<?= $active ?>

</div>

Active

</div>

</div>

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

<div class="border rounded-4 p-4 text-center">

<div class="display-6">

<?= $health ?>

</div>

Health

</div>

</div>

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

<div class="border rounded-4 p-4 text-center">

<div class="display-6">

<?= $verdict ?>

</div>

Verdict

</div>

</div>

</div>

<hr>

<?php foreach(
array_slice(
$queue,
0,
8
)
as $row
): ?>

<div class="mb-3">

<div class="fw-bold">

<?= htmlspecialchars(
(string)$row['title']
) ?>

</div>

<div class="small text-muted">

<?= htmlspecialchars(
(string)$row['step']
) ?>

</div>

</div>

<?php endforeach; ?>

</div>

</div>

<!-- END PACK 681 -->


<!-- PACK 682 -->

<?php

$items=
$assignments
??
$reviews
??
[];

$queue=[];

$round1=0;

$round2=0;

$completed=0;

$revisions=0;

foreach($items as $r){

$status=
strtolower(
(string)(
$r['status']
??
''
));

$title=
$r['title']
??
$r['submission_title']
??
(
$isArabic
?
'بدون عنوان'
:
'Untitled'
);

if(
in_array(
$status,
[
'assigned',
'under_review'
],
true
)
){
$round1++;
}

if(
in_array(
$status,
[
'submitted',
'completed'
],
true
)
){
$round2++;
}

if(
in_array(
$status,
[
'completed',
'submitted'
],
true
)
){
$completed++;
}

if(
$status==='revision_required'
){
$revisions++;
}

$queue[]=[

'title'=>$title,

'next'=>
match(
$status
){

'assigned'=>
(
$isArabic
?
'بدء الجولة الأولى'
:
'Start Round One'
),

'under_review'=>
(
$isArabic
?
'المعايرة'
:
'Calibrate Review'
),

'submitted'=>
(
$isArabic
?
'التوصية النهائية'
:
'Finalize Recommendation'
),

'completed'=>
(
$isArabic
?
'إغلاق المهمة'
:
'Close Assignment'
),

'revision_required'=>
(
$isArabic
?
'إعادة التحقق'
:
'Recheck Revision'
),

default=>
(
$isArabic
?
'متابعة'
:
'Track'
)

}

];

}

$total=
max(
1,
count(
$items
)
);

$calibration=
round(
(
$completed
/
$total
)
*
100
);

$excellence=
max(
0,
100-
(
$revisions
*
8
)
);

$intelligence=
round(
(
$calibration
+
$excellence
+
(
$round2
*
5
)
)
/
3
);

$intelligence=
min(
100,
$intelligence
);

?>

<div class="card shadow-sm border-0 rounded-4 mb-4">

<div class="card-body">

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

<div>

<h4>

<?= $isArabic
?
'مركز تميز المراجعة'
:
'Review Excellence Center'
?>

</h4>

<div class="text-muted">

<?= $isArabic
?
'المعايرة والتوصيات متعددة الجولات'
:
'Multi-round calibration and recommendation intelligence'
?>

</div>

</div>

<div class="display-5 fw-bold text-success">

<?= $intelligence ?>%

</div>

</div>

<div class="row g-3">

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

<div class="border rounded-4 p-4 text-center">

<div class="display-6">

<?= $round1 ?>

</div>

Round 1

</div>

</div>

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

<div class="border rounded-4 p-4 text-center">

<div class="display-6">

<?= $round2 ?>

</div>

Round 2

</div>

</div>

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

<div class="border rounded-4 p-4 text-center">

<div class="display-6">

<?= $calibration ?>

</div>

Calibration

</div>

</div>

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

<div class="border rounded-4 p-4 text-center">

<div class="display-6">

<?= $excellence ?>

</div>

Excellence

</div>

</div>

</div>

<hr>

<?php foreach(
array_slice(
$queue,
0,
8
)
as $row
): ?>

<div class="mb-3">

<div class="fw-bold">

<?= htmlspecialchars(
(string)$row['title']
) ?>

</div>

<div class="small text-muted">

<?= htmlspecialchars(
(string)$row['next']
) ?>

</div>

</div>

<?php endforeach; ?>

</div>

</div>

<!-- END PACK 682 -->


<!-- PACK 683 -->

<?php

$rows=
$assignments
??
$reviews
??
[];

$timeline=[];

$reviewed=0;

$waiting=0;

$revision=0;

$closed=0;

foreach($rows as $r){

$status=
strtolower(
(string)(
$r['status']
??
''
));

$title=
$r['title']
??
$r['submission_title']
??
(
$isArabic
?
'بدون عنوان'
:
'Untitled'
);

if(
in_array(
$status,
[
'under_review',
'submitted'
],
true
)
){
$reviewed++;
}

if(
$status==='assigned'
){
$waiting++;
}

if(
$status==='revision_required'
){
$revision++;
}

if(
$status==='completed'
){
$closed++;
}

$timeline[]=[

'title'=>$title,

'label'=>
match(
$status
){

'assigned'=>
(
$isArabic
?
'بانتظار البدء'
:
'Await Start'
),

'under_review'=>
(
$isArabic
?
'تجميع الأدلة'
:
'Collect Evidence'
),

'submitted'=>
(
$isArabic
?
'توليد التوصية'
:
'Generate Recommendation'
),

'completed'=>
(
$isArabic
?
'تم الإغلاق'
:
'Closed'
),

'revision_required'=>
(
$isArabic
?
'مراجعة جديدة'
:
'New Revision'
),

default=>
(
$isArabic
?
'متابعة'
:
'Track'
)

}

];

}

$total=
max(
1,
count(
$rows
)
);

$consensus=
round(
(
(
$reviewed
+
$closed
)
/
$total
)
*
100
);

$reliability=
max(
0,

100-
(
$revision
*
8
)

);

$timelineScore=
round(
(
$closed
/
$total
)
*
100
);

$engine=
round(
(
$consensus
+
$reliability
+
$timelineScore
)
/
3
);

$engine=
min(
100,
$engine
);

?>

<div class="card shadow-sm border-0 rounded-4 mb-4">

<div class="card-body">

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

<div>

<h4>

<?= $isArabic
?
'محرك التوافق'
:
'Consensus Engine'
?>

</h4>

<div class="text-muted">

<?= $isArabic
?
'الخط الزمني ومصفوفة الاعتمادية'
:
'Evidence timeline and reliability matrix'
?>

</div>

</div>

<div class="display-5 fw-bold text-primary">

<?= $engine ?>%

</div>

</div>

<div class="row g-3">

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

<div class="border rounded-4 p-4 text-center">

<div class="display-6">

<?= $consensus ?>

</div>

Consensus

</div>

</div>

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

<div class="border rounded-4 p-4 text-center">

<div class="display-6">

<?= $reliability ?>

</div>

Reliability

</div>

</div>

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

<div class="border rounded-4 p-4 text-center">

<div class="display-6">

<?= $timelineScore ?>

</div>

Timeline

</div>

</div>

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

<div class="border rounded-4 p-4 text-center">

<div class="display-6">

<?= $closed ?>

</div>

Closed

</div>

</div>

</div>

<hr>

<?php foreach(
array_slice(
$timeline,
0,
8
)
as $row
): ?>

<div class="mb-3">

<div class="fw-bold">

<?= htmlspecialchars(
(string)$row['title']
) ?>

</div>

<div class="small text-muted">

<?= htmlspecialchars(
(string)$row['label']
) ?>

</div>

</div>

<?php endforeach; ?>

</div>

</div>

<!-- END PACK 683 -->


<!-- PACK 684 -->

<?php

$items=
$assignments
??
$reviews
??
[];

$queue=[];

$assigned=0;

$review=0;

$submitted=0;

$closed=0;

$revision=0;

foreach($items as $r){

$status=
strtolower(
(string)(
$r['status']
??
''
));

$title=
$r['title']
??
$r['submission_title']
??
(
$isArabic
?
'بدون عنوان'
:
'Untitled'
);

switch($status){

case 'assigned':
$assigned++;
break;

case 'under_review':
$review++;
break;

case 'submitted':
$submitted++;
break;

case 'completed':
$closed++;
break;

case 'revision_required':
$revision++;
break;

}

$confidence=
match(
$status
){

'assigned'=>25,

'under_review'=>55,

'submitted'=>80,

'completed'=>100,

'revision_required'=>70,

default=>20

};

$queue[]=[

'title'=>$title,

'step'=>
match(
$status
){

'assigned'=>
(
$isArabic
?
'بدء التقييم'
:
'Start Evaluation'
),

'under_review'=>
(
$isArabic
?
'معايرة المراجعة'
:
'Calibrate Review'
),

'submitted'=>
(
$isArabic
?
'التوصية النهائية'
:
'Final Recommendation'
),

'completed'=>
(
$isArabic
?
'إغلاق المهمة'
:
'Close Assignment'
),

'revision_required'=>
(
$isArabic
?
'إعادة التحقق'
:
'Recheck Revision'
),

default=>
(
$isArabic
?
'متابعة'
:
'Track'
)

},

'confidence'=>$confidence

];

}

$total=
max(
1,
count(
$items
)
);

$adaptive=
round(
(
(
$submitted
+
(
$closed
*
2
)
)
/
$total
)
*
100
);

$calibration=
max(
0,

100-
(
$revision
*
8
)

);

$hub=
round(
(
$adaptive
+
$calibration
+
(
$review
*
5
)
)
/
3
);

$hub=
min(
100,
$hub
);

?>

<div class="card shadow-sm border-0 rounded-4 mb-4">

<div class="card-body">

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

<div>

<h4>

<?= $isArabic
?
'مركز الثقة'
:
'Decision Confidence Hub'
?>

</h4>

<div class="text-muted">

<?= $isArabic
?
'المعايرة والذكاء التكيفي'
:
'Adaptive intelligence and cross-review calibration'
?>

</div>

</div>

<div class="display-5 fw-bold text-success">

<?= $hub ?>%

</div>

</div>

<div class="row g-3">

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

<div class="border rounded-4 p-4 text-center">

<div class="display-6">

<?= $adaptive ?>

</div>

Adaptive

</div>

</div>

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

<div class="border rounded-4 p-4 text-center">

<div class="display-6">

<?= $calibration ?>

</div>

Calibration

</div>

</div>

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

<div class="border rounded-4 p-4 text-center">

<div class="display-6">

<?= $closed ?>

</div>

Completed

</div>

</div>

</div>

<hr>

<?php foreach(
array_slice(
$queue,
0,
8
)
as $row
): ?>

<div class="mb-3">

<div class="fw-bold">

<?= htmlspecialchars(
(string)$row['title']
) ?>

</div>

<div class="small text-muted">

<?= htmlspecialchars(
(string)$row['step']
) ?>

•

<?= (int)$row['confidence'] ?>%

</div>

</div>

<?php endforeach; ?>

</div>

</div>

<!-- END PACK 684 -->











