<?php
declare(strict_types=1);

$dir = '/var/www/html/easychair/app/controllers';
$files = glob($dir.'/*.php') ?: [];

$sensitive = [
  'organizations','org_users',
  'conferences','submissions','tracks','review_assignments','reviews','decisions',
  'committees','conference_chairs','conference_sessions','proceedings',
  'email_queue','email_templates',
  'dictionary','custom_fields','audit_logs',
  'jobs','job_queue','jobs_queue','job_runs','jobs_runs'
];

echo "=== Isolation Scanner (Pack205.2) ===\n";
foreach($files as $f){
  $txt = file_get_contents($f);
  $base = basename($f);

  // Owner controllers intentionally global
  if (stripos($base,'Owner')!==false) continue;

  $hits = [];
  foreach($sensitive as $t){
    if (preg_match('/\bFROM\s+'.preg_quote($t,'/').'\b/i', $txt)) {
      $ok = (stripos($txt,'org_id')!==false) || (preg_match('/\bJOIN\s+conferences\b/i',$txt)) || (preg_match('/\borg_users\b/i',$txt));
      if(!$ok) $hits[] = $t;
    }
  }

  if(!empty($hits)){
    echo "- ".$base." => POSSIBLE GLOBAL access: ".implode(', ', array_unique($hits))."\n";
  }
}
echo "=== Done ===\n";
