<?php require_once __DIR__.'/admin_tool_helper.php'; if($_SERVER['REQUEST_METHOD']==='POST'){foreach($_POST['rules']??[] as $id=>$r){db()->prepare("UPDATE prop_firm_rules SET firm_name=?,max_daily_drawdown=?,max_total_drawdown=?,max_risk_per_trade=?,news_trading_allowed=?,weekend_holding_allowed=?,is_active=?,notes=? WHERE id=?")->execute([trim($r['firm_name']??''),(float)($r['max_daily_drawdown']??0),(float)($r['max_total_drawdown']??0),(float)($r['max_risk_per_trade']??0),!empty($r['news_trading_allowed'])?1:0,!empty($r['weekend_holding_allowed'])?1:0,!empty($r['is_active'])?1:0,trim($r['notes']??''),(int)$id]);}} $rows=db()->query("SELECT * FROM prop_firm_rules ORDER BY firm_name")->fetchAll(PDO::FETCH_ASSOC)?:[]; admin_layout_header('Prop Firm Rules'); ?><form method="post" class="bg-white rounded-2xl border shadow-sm p-6 overflow-x-auto"><table class="min-w-full text-sm"><thead><tr class="text-left text-slate-500"><th class="p-2">Firm</th><th class="p-2">Daily DD</th><th class="p-2">Total DD</th><th class="p-2">Risk/Trade</th><th class="p-2">News</th><th class="p-2">Weekend</th><th class="p-2">Active</th><th class="p-2">Notes</th></tr></thead><tbody><?php foreach($rows as $r):?><tr class="border-t"><?php foreach(['firm_name','max_daily_drawdown','max_total_drawdown','max_risk_per_trade'] as $c):?><td class="p-2"><input name="rules[<?=e($r['id'])?>][<?=$c?>]" value="<?=e($r[$c])?>" class="rounded border px-2 py-1"></td><?php endforeach; foreach(['news_trading_allowed','weekend_holding_allowed','is_active'] as $c):?><td class="p-2"><input type="checkbox" name="rules[<?=e($r['id'])?>][<?=$c?>]" value="1" <?=$r[$c]?'checked':''?>></td><?php endforeach; ?><td class="p-2"><input name="rules[<?=e($r['id'])?>][notes]" value="<?=e($r['notes'])?>" class="rounded border px-2 py-1"></td></tr><?php endforeach;?></tbody></table><button class="mt-6 px-6 py-3 rounded-xl bg-blue-600 text-white font-bold">Save Rules</button></form><?php admin_layout_footer(); ?>