<?php

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

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

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

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

$conferenceTitle =
    $conference['title_ar']
    ?? $conference['title_en']
    ?? 'Conference';

?>

<style>

.submit-hero{
background:
linear-gradient(
135deg,
#0f172a,
#1d4ed8
);
border-radius:28px;
overflow:hidden;
position:relative;
color:#fff;
}

.submit-hero::before{
content:'';
position:absolute;
inset:0;
background:
radial-gradient(
circle at top right,
rgba(255,255,255,.18),
transparent 40%
);
}

.submit-card{
border:0;
border-radius:24px;
box-shadow:
0 10px 30px rgba(15,23,42,.08);
overflow:hidden;
}

.track-card{
border:2px solid #e2e8f0;
border-radius:18px;
padding:18px;
cursor:pointer;
transition:.25s;
height:100%;
}

.track-card:hover{
border-color:#2563eb;
transform:translateY(-3px);
}

.track-card.active{
border-color:#2563eb;
background:#eff6ff;
}

.upload-zone{
border:2px dashed #cbd5e1;
border-radius:24px;
padding:40px;
text-align:center;
background:#f8fafc;
transition:.25s;
}

.upload-zone:hover{
border-color:#2563eb;
background:#eff6ff;
}

.step-badge{
width:42px;
height:42px;
border-radius:50%;
display:flex;
align-items:center;
justify-content:center;
font-weight:bold;
background:#2563eb;
color:#fff;
}

.meta-chip{
padding:10px 18px;
border-radius:999px;
background:#fff;
font-weight:600;
display:inline-flex;
align-items:center;
gap:8px;
box-shadow:0 4px 15px rgba(15,23,42,.08);
}

</style>

<div class="container py-4" dir="<?= $dir ?>">

<div class="submit-hero p-5 mb-4">

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

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

<div>

<span class="badge bg-light text-dark px-3 py-2 mb-3">

<?= $isArabic
? 'بوابة إرسال الأبحاث'
: 'Paper Submission Portal' ?>

</span>

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

<?= esub_h($conferenceTitle) ?>

</h1>

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

<?= $isArabic
? 'نظام إرسال وتحكيم الأبحاث العلمية'
: 'Enterprise Research Submission Workflow' ?>

</div>

</div>

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

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

<i class="fa fa-layer-group"></i>

<?= count($tracks ?? []) ?>

<?= $isArabic
? 'مسار'
: 'Tracks' ?>

</div>

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

<i class="fa fa-file"></i>

PDF

</div>

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

<i class="fa fa-language"></i>

<?= $isArabic
? 'متعدد اللغات'
: 'Multilingual' ?>

</div>

</div>

</div>

</div>

</div>

<form
method="post"
action="/easychair/author/submit/store"
enctype="multipart/form-data"
>

<input
type="hidden"
name="conference_id"
value="<?= (int)$conference_id ?>"
>

<div class="submit-card mb-4">

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

<div class="d-flex align-items-center gap-3 mb-4">

<div class="step-badge">
1
</div>

<div>

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

<?= $isArabic
? 'بيانات البحث'
: 'Paper Information' ?>

</h4>

<div class="text-muted">

<?= $isArabic
? 'أدخل عنوان وملخص البحث'
: 'Provide title and abstract' ?>

</div>

</div>

</div>

<div class="row g-4">

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

<label class="form-label fw-bold">

<?= $isArabic
? 'عنوان البحث'
: 'Paper Title' ?>

</label>

<input
type="text"
name="title"
class="form-control form-control-lg"
required
>

</div>

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

<label class="form-label fw-bold">

<?= $isArabic
? 'العنوان بالعربية'
: 'Arabic Title' ?>

</label>

<input
type="text"
name="title_ar"
class="form-control form-control-lg"
>

</div>

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

<label class="form-label fw-bold">

<?= $isArabic
? 'الملخص'
: 'Abstract' ?>

</label>

<textarea
name="abstract"
rows="7"
class="form-control"
required
></textarea>

</div>

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

<label class="form-label fw-bold">

<?= $isArabic
? 'الملخص بالعربية'
: 'Arabic Abstract' ?>

</label>

<textarea
name="abstract_ar"
rows="7"
class="form-control"
></textarea>

</div>

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

<label class="form-label fw-bold">

<?= $isArabic
? 'الكلمات المفتاحية'
: 'Keywords' ?>

</label>

<input
type="text"
name="keywords_en"
class="form-control"
placeholder="AI, NLP, Security..."
>

</div>

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

<label class="form-label fw-bold">

<?= $isArabic
? 'الكلمات المفتاحية بالعربية'
: 'Arabic Keywords' ?>

</label>

<input
type="text"
name="keywords_ar"
class="form-control"
>

</div>

</div>

</div>

</div>

<div class="submit-card mb-4">

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

<div class="d-flex align-items-center gap-3 mb-4">

<div class="step-badge">
2
</div>

<div>

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

<?= $isArabic
? 'المسارات العلمية'
: 'Conference Tracks' ?>

</h4>

<div class="text-muted">

<?= $isArabic
? 'اختر المسار المناسب'
: 'Select the most suitable track' ?>

</div>

</div>

</div>

<div class="row g-3">

<?php foreach (($tracks ?? []) as $t): ?>

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

<label class="track-card d-block">

<input
type="radio"
name="track_id"
value="<?= (int)$t['id'] ?>"
class="d-none track-radio"
required
>

<div class="fw-bold fs-5 mb-2">

<?= esub_h(
$isArabic
? ($t['name_ar'] ?? '')
: ($t['name_en'] ?? '')
) ?>

</div>

<div class="text-muted small">

<?= esub_h(
$isArabic
? ($t['description_ar'] ?? '')
: ($t['description_en'] ?? '')
) ?>

</div>

</label>

</div>

<?php endforeach; ?>

</div>

</div>

</div>

<div class="submit-card mb-4">

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

<div class="d-flex align-items-center gap-3 mb-4">

<div class="step-badge">
3
</div>

<div>

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

<?= $isArabic
? 'رفع البحث'
: 'Upload Manuscript' ?>

</h4>

<div class="text-muted">

<?= $isArabic
? 'ارفع ملف البحث بصيغة PDF أو Word'
: 'Upload manuscript PDF or Word file' ?>

</div>

</div>

</div>

<div class="upload-zone">

<i class="fa fa-cloud-upload-alt fa-4x mb-3 text-primary"></i>

<h5 class="fw-bold">

<?= $isArabic
? 'اسحب الملف هنا أو اختر ملفاً'
: 'Drag file here or choose file' ?>

</h5>

<input
type="file"
name="file"
class="form-control mt-4"
required
>

</div>

</div>

</div>

<div class="submit-card mb-4">

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

<div class="d-flex align-items-center gap-3 mb-4">

<div class="step-badge">
4
</div>

<div>

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

<?= $isArabic
? 'المؤلفون المشاركون'
: 'Co-Authors' ?>

</h4>

<div class="text-muted">

<?= $isArabic
? 'إضافة المؤلفين المشاركين'
: 'Add co-authors if available' ?>

</div>

</div>

</div>

<div id="coauthors">

<div class="row g-3 coauthor-row mb-3">

<div class="col-md-3">
<input
name="coauthor_name[]"
class="form-control"
placeholder="Full Name"
>
</div>

<div class="col-md-3">
<input
name="coauthor_email[]"
class="form-control"
placeholder="Email"
>
</div>

<div class="col-md-4">
<input
name="coauthor_affiliation[]"
class="form-control"
placeholder="Affiliation"
>
</div>

<div class="col-md-2">
<input
name="coauthor_country[]"
class="form-control"
placeholder="Country"
>
</div>

</div>

</div>

<button
type="button"
class="btn btn-outline-primary"
onclick="addCoauthor()"
>

<i class="fa fa-plus"></i>

<?= $isArabic
? 'إضافة مؤلف'
: 'Add Co-Author' ?>

</button>

</div>

</div>

<div class="submit-card">

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

<div class="form-check mb-4">

<input
class="form-check-input"
type="checkbox"
required
id="confirmSubmission"
>

<label
class="form-check-label"
for="confirmSubmission"
>

<?= $isArabic
? 'أتعهد بأن البحث أصيل وغير مقدم لمؤتمر آخر'
: 'I confirm the submission is original and not submitted elsewhere' ?>

</label>

</div>

<button
class="btn btn-primary btn-lg px-5"
>

<i class="fa fa-paper-plane"></i>

<?= $isArabic
? 'إرسال البحث'
: 'Submit Paper' ?>

</button>

</div>

</div>

</form>

</div>

<script>

document.querySelectorAll('.track-card')
.forEach(card => {

card.addEventListener('click', () => {

document
.querySelectorAll('.track-card')
.forEach(c => c.classList.remove('active'));

card.classList.add('active');

card
.querySelector('.track-radio')
.checked = true;

});

});

function addCoauthor(){

const row =
document
.querySelector('.coauthor-row')
.cloneNode(true);

row.querySelectorAll('input')
.forEach(i => i.value = '');

document
.getElementById('coauthors')
.appendChild(row);

}

</script>

<style>

.author-row{
position:relative;
padding:16px;
border:1px solid #dbeafe;
border-radius:18px;
margin-bottom:14px;
background:#fff;
}

.author-actions{
display:flex;
gap:8px;
justify-content:flex-end;
}

.dropzone-enh{
border:2px dashed #3b82f6!important;
border-radius:24px!important;
cursor:pointer;
transition:.25s;
}

.dropzone-enh.drag{
background:#eff6ff;
transform:scale(1.01);
}

.country-select{
min-width:220px;
}

</style>

<script>

(function(){

const countries=[
["JO","Jordan","الأردن"],
["SA","Saudi Arabia","السعودية"],
["AE","United Arab Emirates","الإمارات"],
["EG","Egypt","مصر"],
["IQ","Iraq","العراق"],
["SY","Syria","سوريا"],
["LB","Lebanon","لبنان"],
["PS","Palestine","فلسطين"],
["QA","Qatar","قطر"],
["KW","Kuwait","الكويت"],
["BH","Bahrain","البحرين"],
["OM","Oman","عُمان"],
["US","United States","الولايات المتحدة"],
["GB","United Kingdom","المملكة المتحدة"],
["DE","Germany","ألمانيا"],
["FR","France","فرنسا"],
["CN","China","الصين"],
["JP","Japan","اليابان"]
];

function buildCountry(el){

if(el.dataset.countryReady)return;

el.dataset.countryReady=1;

const val=
el.value
||
'Jordan';

const d=
document.createElement(
'datalist'
);

d.id=
'countries_global';

if(
!document.getElementById(
d.id
)
){

countries.forEach(c=>{

let o=
document.createElement(
'option'
);

o.value=
c[1];

o.label=
c[2];

d.appendChild(
o
);

});

document.body.appendChild(
d
);

}

el.setAttribute(
'list',
'countries_global'
);

el.value=
val;

}

document
.querySelectorAll(
'input[placeholder="Country"]'
)
.forEach(
buildCountry
);

window.addCoauthorOld=
window.addCoauthor
||
function(){};

window.addCoauthor=
function(){

window.addCoauthorOld();

setTimeout(function(){

document
.querySelectorAll(
'input[placeholder="Country"]'
)
.forEach(
buildCountry
);

decorateAuthors();

},100);

};

function decorateAuthors(){

document
.querySelectorAll(
'input[name="coauthor_name[]"]'
)
.forEach(function(name,i){

let row=
name.closest(
'.row'
);

if(
!row
||
row.dataset.ready
)return;

row.dataset.ready=1;

row.classList.add(
'author-row'
);

let corr=
document.createElement(
'label'
);

corr.innerHTML=
`
<input
type="radio"
name="corresponding_author"
value="${i}"
${i===0?'checked':''}>
Corresponding
`;

let del=
document.createElement(
'button'
);

del.type=
'button';

del.className=
'btn btn-sm btn-outline-danger';

del.innerHTML=
'Delete';

del.onclick=
()=>row.remove();

let wrap=
document.createElement(
'div'
);

wrap.className=
'author-actions';

wrap.appendChild(
corr
);

wrap.appendChild(
del
);

row.appendChild(
wrap
);

});

}

decorateAuthors();

const file=
document.querySelector(
'input[type=file]'
);

if(file){

let box=
file.closest(
'div'
);

if(box){

box.classList.add(
'dropzone-enh'
);

box.addEventListener(
'dragover',
e=>{

e.preventDefault();

box.classList.add(
'drag'
);

}
);

box.addEventListener(
'dragleave',
()=>{

box.classList.remove(
'drag'
);

}
);

box.addEventListener(
'drop',
e=>{

e.preventDefault();

box.classList.remove(
'drag'
);

file.files=
e.dataTransfer.files;

});

}

}

})();

</script>


<style>

.ec-corresponding-pill{

display:inline-flex;

align-items:center;

gap:8px;

padding:8px 16px;

border-radius:999px;

background:#eff6ff;

border:1px solid #3b82f6;

color:#1d4ed8;

font-weight:700;

cursor:pointer;

margin-top:10px;

}

.ec-corresponding-pill.active{

background:#1d4ed8;

color:#fff;

}

.country-wrap{

position:relative;

}

.country-wrap select{

border-radius:14px;

}

</style>

<script>

(function(){

const countries=[

"Jordan|الأردن",
"Saudi Arabia|السعودية",
"United Arab Emirates|الإمارات",
"Qatar|قطر",
"Kuwait|الكويت",
"Oman|عمان",
"Bahrain|البحرين",
"Iraq|العراق",
"Syria|سوريا",
"Lebanon|لبنان",
"Palestine|فلسطين",
"Egypt|مصر",
"United States|الولايات المتحدة",
"United Kingdom|بريطانيا",
"Germany|ألمانيا",
"France|فرنسا",
"China|الصين",
"Japan|اليابان"

];

function upgradeCountries(){

document
.querySelectorAll(
'input[placeholder="Country"]'
)
.forEach(function(inp){

if(
inp.dataset.done
)return;

inp.dataset.done=1;

let val=
inp.value
||
'Jordan';

let wrap=
document.createElement(
'div'
);

wrap.className=
'country-wrap';

let sel=
document.createElement(
'select'
);

sel.name=
inp.name;

sel.className=
'form-select';

countries.forEach(c=>{

let p=
c.split('|');

let o=
document.createElement(
'option'
);

o.value=
p[0];

o.text=
p[0]
+
' — '
+
p[1];

if(
p[0]===val
)
o.selected=true;

sel.appendChild(
o
);

});

sel.onchange=
()=>{

inp.value=
sel.value;

};

inp.parentNode.insertBefore(
wrap,
inp
);

wrap.appendChild(
sel);

inp.type=
'hidden';

});

}

function setupCorresponding(){

document
.querySelectorAll(
'.author-row'
)
.forEach(function(r,i){

if(
r.querySelector(
'.ec-corresponding-pill'
)
)
return;

let h=
document.createElement(
'div'
);

h.className=
'ec-corresponding-pill';

h.innerHTML=
'✉ Corresponding Author';

if(i===0){

h.classList.add(
'active'
);

}

let hidden=
document.createElement(
'input'
);

hidden.type=
'hidden';

hidden.name=
'is_corresponding[]';

hidden.value=
i===0
?1
:0;

h.onclick=
function(){

document
.querySelectorAll(
'.ec-corresponding-pill'
)
.forEach(
x=>
x.classList.remove(
'active'
)
);

document
.querySelectorAll(
'input[name="is_corresponding[]"]'
)
.forEach(
x=>
x.value=0
);

h.classList.add(
'active'
);

hidden.value=1;

};

r.appendChild(
h
);

r.appendChild(
hidden
);

});

}

function boot(){

upgradeCountries();

setupCorresponding();

}

boot();

window.addEventListener(
'click',
function(){

setTimeout(
boot,
120
);

}
);

})();

</script>


<script>

(function(){

function setSubmitterCorresponding(){

let rows=
document.querySelectorAll(
'.author-row'
);

if(
!rows.length
)return;

rows.forEach(
r=>{

let old=
r.querySelector(
'input[name="is_corresponding[]"]'
);

if(old)
old.remove();

}

);

rows.forEach(
r=>{

let old=
r.querySelector(
'.ec-corresponding-pill'
);

if(old)
old.remove();

}

);

rows.forEach(
function(
row,
idx
){

let hidden=
document.createElement(
'input'
);

hidden.type=
'hidden';

hidden.name=
'is_corresponding[]';

hidden.value=
idx===0
?1
:0;

row.appendChild(
hidden
);

let pill=
document.createElement(
'div'
);

pill.className=
'ec-corresponding-pill';

if(
idx===0
){

pill.classList.add(
'active'
);

pill.innerHTML=
'✓ Corresponding Author';

}
else{

pill.innerHTML=
'Set Corresponding';

}

pill.onclick=
function(){

document
.querySelectorAll(
'.ec-corresponding-pill'
)
.forEach(
x=>{

x.classList.remove(
'active'
);

x.innerHTML=
'Set Corresponding';

}
);

document
.querySelectorAll(
'input[name="is_corresponding[]"]'
)
.forEach(
x=>
x.value=0
);

pill.classList.add(
'active'
);

pill.innerHTML=
'✓ Corresponding Author';

hidden.value=1;

};

row.appendChild(
pill
);

}

);

}

setTimeout(
setSubmitterCorresponding,
300
);

window.addEventListener(
'click',
function(){

setTimeout(
setSubmitterCorresponding,
150
);

}
);

})();

</script>


<style>

.author-row{
display:none;
}

.author-row.open{
display:flex!important;
}

.ec-corresponding-pill{
display:none!important;
}

.country-select{
border-radius:14px!important;
}

</style>

<script>

(function(){

/*
submitter:
implicit corresponding author
*/

window.__submitterCorresponding=true;

/*
hide initial author rows
*/

function hideInitial(){

document
.querySelectorAll(
'.author-row'
)
.forEach(
r=>{

if(
!r.dataset.manual
){

r.classList.remove(
'open'
);

}

}
);

}

hideInitial();

/*
hook add author
*/

window.oldAddAuthor=
window.addCoauthor
||
function(){};

window.addCoauthor=
function(){

window.oldAddAuthor();

setTimeout(function(){

let rows=
document.querySelectorAll(
'.author-row'
);

let last=
rows[
rows.length-1
];

if(last){

last.dataset.manual=1;

last.classList.add(
'open'
);

}

buildCountries();

},150);

};

/*
full countries
*/

const countries=`Jordan
Afghanistan
Albania
Algeria
Andorra
Angola
Antigua and Barbuda
Argentina
Armenia
Australia
Austria
Azerbaijan
Bahamas
Bahrain
Bangladesh
Barbados
Belarus
Belgium
Belize
Benin
Bhutan
Bolivia
Bosnia and Herzegovina
Botswana
Brazil
Brunei
Bulgaria
Burkina Faso
Burundi
Cabo Verde
Cambodia
Cameroon
Canada
Central African Republic
Chad
Chile
China
Colombia
Comoros
Congo
Costa Rica
Croatia
Cuba
Cyprus
Czech Republic
Denmark
Djibouti
Dominican Republic
Ecuador
Egypt
El Salvador
Estonia
Ethiopia
Finland
France
Germany
Greece
Hungary
Iceland
India
Indonesia
Iran
Iraq
Ireland
Italy
Japan
Jordan
Kazakhstan
Kenya
Kuwait
Lebanon
Libya
Malaysia
Morocco
Netherlands
New Zealand
Norway
Oman
Pakistan
Palestine State
Philippines
Poland
Portugal
Qatar
Romania
Russia
Saudi Arabia
Singapore
South Africa
South Korea
Spain
Sri Lanka
Sudan
Sweden
Switzerland
Syria
Thailand
Tunisia
Turkey
Ukraine
United Arab Emirates
United Kingdom
United States of America
Uruguay
Uzbekistan
Vietnam
Yemen
Zambia
Zimbabwe`
.split('\n');

function buildCountries(){

document
.querySelectorAll(
'select[name*="country"]'
)
.forEach(
function(sel){

if(
sel.dataset.full
)
return;

sel.dataset.full=1;

sel.innerHTML='';

countries.forEach(
function(c){

let o=
document.createElement(
'option'
);

o.value=c;

o.text=c;

if(
c==='Jordan'
){

o.selected=true;

}

sel.appendChild(
o
);

});

sel.classList.add(
'country-select'
);

sel.setAttribute(
'data-live-search',
'true'
);

}

);

}

setTimeout(
buildCountries,
300
);

})();

</script>

