| Server IP : 188.114.96.3 / Your IP : 216.73.216.143 Web Server : Apache System : Linux sv058.home.net.pl 6.8.2 husak_dirty_pages_fix #1 SMP PREEMPT_DYNAMIC Tue Apr 2 22:06:51 CEST 2024 x86_64 User : ( 3194769) PHP Version : 8.5.12 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : OFF Directory : /polana/admin/ |
Upload File : |
<?php
declare(strict_types=1);
require_once dirname(__DIR__).'/includes/functions.php';
require_admin_role();
require_once dirname(__DIR__).'/includes/polana_v15_menu_queue.php';
$all=p15_active_menu_ids();$id=(int)($_POST['menu_id']??$_GET['menu_id']??array_key_first($all)??0);
if(!isset($all[$id]) && $all)$id=(int)array_key_first($all);
$lang=(string)($_POST['lang']??$_GET['lang']??'all');if(!in_array($lang,['all','en','de','es'],true))$lang='all';
$error='';$notice='';
if(($_SERVER['REQUEST_METHOD']??'')==='POST'){
verify_csrf();
try{
if(!isset($all[$id]))throw new RuntimeException('Nieprawidłowa aktywna karta');
$ids=$_POST['ids']??[];
if(!is_array($ids))throw new RuntimeException('Nieprawidłowy wybór');
$ids=array_values(array_unique(array_filter(array_map('intval',$ids),static fn($x)=>$x>0)));
if(count($ids)>150)throw new RuntimeException('Limit 150 pozycji');
if(!$ids)throw new RuntimeException('Zaznacz przynajmniej jedno tłumaczenie');
$select=db()->prepare("SELECT j.* FROM tklm_v9_jobs j
LEFT JOIN menu_categories c ON j.entity='menu_categories' AND c.id=j.entity_id
LEFT JOIN menu_items i ON j.entity='menu_items' AND i.id=j.entity_id
WHERE j.id=? AND j.status='review' AND
((j.entity='menu_categories' AND c.menu_id=? AND c.active=1) OR
(j.entity='menu_items' AND i.category_id IN (SELECT id FROM menu_categories WHERE menu_id=? AND active=1) AND i.active=1 AND i.available=1))");
$save=db()->prepare("UPDATE tklm_v9_jobs SET translated_text=? WHERE id=? AND status='review'");
$ok=0;$bad=[];
foreach($ids as $jid){
try{
$select->execute([$jid,$id,$id]);$job=$select->fetch(PDO::FETCH_ASSOC);
if(!$job || ($lang!=='all' && $job['lang']!==$lang))throw new RuntimeException('Pozycja nie należy do tego filtra');
$candidate=trim((string)(($_POST['value']??[])[$jid]??''));
$limit=$job['field']==='name'?($job['entity']==='menu_categories'?150:255):($job['field']==='allergens'?500:20000);
if($candidate==='' || mb_strlen($candidate,'UTF-8')>$limit)throw new RuntimeException('Puste lub zbyt długie tłumaczenie');
$save->execute([$candidate,$jid]);
v9_approve($jid);$ok++;
}catch(Throwable $e){$bad[]=$jid.': '.$e->getMessage();}
}
$notice='Zatwierdzono: '.$ok.'; błędy: '.count($bad).($bad?' ('.implode('; ',array_slice($bad,0,4)).')':'');
}catch(Throwable $e){$error=$e->getMessage();}
}
$jobs=[];
if($id){
$sql="SELECT j.* FROM tklm_v9_jobs j
LEFT JOIN menu_categories c ON j.entity='menu_categories' AND c.id=j.entity_id
LEFT JOIN menu_items i ON j.entity='menu_items' AND i.id=j.entity_id
WHERE j.status='review'
AND ((j.entity='menu_categories' AND c.menu_id=? AND c.active=1) OR
(j.entity='menu_items' AND i.category_id IN (SELECT id FROM menu_categories WHERE menu_id=? AND active=1) AND i.active=1 AND i.available=1))";
$args=[$id,$id];if($lang!=='all'){$sql.=' AND j.lang=?';$args[]=$lang;}
$sql.=' ORDER BY FIELD(j.lang,\'en\',\'de\',\'es\'),j.id LIMIT 150';
$q=db()->prepare($sql);$q->execute($args);$jobs=$q->fetchAll(PDO::FETCH_ASSOC);
}
render_admin_header('Polana V15 — Zatwierdź menu');
?>
<main style="max-width:1150px;margin:25px auto;padding:16px">
<h1>Weryfikacja tłumaczeń aktualnej karty</h1>
<p>Popraw teksty, zaznacz wybrane, zatwierdź zbiorczo. Tłumaczenia starszych kart nie są pokazywane.</p>
<?php if($error):?><p style="color:#a22"><?=e($error)?></p><?php endif;?>
<?php if($notice):?><p style="color:#175e28"><?=e($notice)?></p><?php endif;?>
<form method="get">
<label>Karta <select name="menu_id" onchange="this.form.submit()">
<?php foreach($all as $key=>$m):?><option value="<?=$key?>" <?=$key===$id?'selected':''?>><?=e(strtoupper((string)$m['menu_type']).' — '.$m['name'])?></option><?php endforeach; ?></select></label>
<label>Język <select name="lang" onchange="this.form.submit()">
<?php foreach(['all'=>'Wszystkie','en'=>'EN','de'=>'DE','es'=>'ES'] as $code=>$label):?><option value="<?=$code?>" <?=$lang===$code?'selected':''?>><?=e($label)?></option><?php endforeach;?></select></label>
</form>
<p><a href="/admin/polana-v15-menu.php?menu_id=<?=$id?>">Wróć do tłumaczenia menu</a></p>
<?php if($jobs):?>
<form method="post" id="p15-approve-form">
<?=csrf_field()?><input type="hidden" name="menu_id" value="<?=$id?>"><input type="hidden" name="lang" value="<?=e($lang)?>">
<div style="position:sticky;top:0;background:#fff;padding:12px;z-index:3;border:1px solid #ddd;border-radius:9px;display:flex;flex-wrap:wrap;gap:15px;align-items:center">
<label><input type="checkbox" id="p15-select-all"> Wybierz wszystkie na stronie</label>
<span id="p15-count">0 wybranych</span>
<button type="submit" onclick="return confirm('Zatwierdzić wybrane tłumaczenia po sprawdzeniu?')">Zapisz poprawki i zatwierdź</button>
</div>
<?php foreach($jobs as $job):?>
<section style="background:white;border:1px solid #ddd;border-radius:10px;padding:16px;margin:12px 0">
<label><input type="checkbox" class="p15-check" name="ids[]" value="<?=(int)$job['id']?>">
<strong><?=e(strtoupper($job['lang']).' · '.$job['entity'].' #'.$job['entity_id'].' · '.$job['field'])?></strong></label>
<p><strong>Źródło PL:</strong> <?=nl2br(e($job['source_text']))?></p>
<?php if(function_exists('p14_missing_terms') && ($missing=p14_missing_terms((string)$job['source_text'],(string)$job['translated_text']))):?>
<p style="color:#a60">Możliwa zmiana nazwy własnej: <?=e(implode(', ',$missing))?></p>
<?php endif; ?>
<label>Tłumaczenie (możesz poprawić):
<textarea name="value[<?=(int)$job['id']?>]" style="display:block;width:100%;min-height:75px;padding:10px" rows="3"><?=e($job['translated_text'])?></textarea></label>
</section>
<?php endforeach;?></form>
<script>(()=>{const all=document.querySelector('#p15-select-all'),items=[...document.querySelectorAll('.p15-check')],label=document.querySelector('#p15-count');function update(){const n=items.filter(x=>x.checked).length;label.textContent=n+' wybranych';all.checked=n===items.length;all.indeterminate=n>0&&n<items.length;}all.onchange=()=>{items.forEach(x=>x.checked=all.checked);update()};items.forEach(x=>x.onchange=update);update()})();</script>
<?php else:?><p>Nie ma tłumaczeń oczekujących na zatwierdzenie dla tej karty i języka.</p><?php endif;?>
</main>
<?php render_admin_footer(); ?>