<?php
$lane=getenv('MR3_LANE');$root=getenv('MR3_ROOT');$path=parse_url($_SERVER['REQUEST_URI'],PHP_URL_PATH);$parts=explode('/',trim((string)$path,'/'));$module=$parts[1]??'';$action=$parts[2]??'';
if(!($path==='/__poc_boundary'||(($parts[0]??'')==='p'&&in_array($module,['gradeEstimation','judgmentRank'],true)&&in_array($action,['add','update','delete','info','lists'],true)&&$_SERVER['REQUEST_METHOD']==='POST'))){http_response_code(403);exit;}
$_SERVER['PATH_INFO']=$path;require $root.'/env.php';if(!function_exists('json')){function json($data=[],$code=200,array $header=[],$options=[]){return \think\Response::create($data,'json',$code,$header,$options);}}
require $root.'/external_stubs.php';define('APP_PATH',__DIR__.'/source/application/');define('RUNTIME_PATH',__DIR__.'/runtime/');require $root.'/thinkphp/base.php';\think\App::initCommon();\think\Log::init(['type'=>'File','path'=>__DIR__.'/runtime/safe-log/','level'=>['no_raw_application_log']]);\think\Config::set(['type'=>'File','path'=>__DIR__.'/cache/','prefix'=>'GRADE10_'],'cache');\think\Config::set('redis',[]);$database=require $root.'/application/database.php';\think\Config::set($database,'database');\think\Db::clear();
if($path==='/__poc_boundary'){header('Content-Type: application/json');echo json_encode(['allowlist'=>'owned-grade-archives-only','external_stubs'=>class_exists(\app\common\Serve::class,false),'original_debug'=>$database['debug']??null]);exit;}
$params=\think\Request::instance()->post();$lease=json_decode((string)file_get_contents(__DIR__.'/private-lease.json'),true);$own=is_file(__DIR__.'/private-own.json')?json_decode(file_get_contents(__DIR__.'/private-own.json'),true):[];
if(in_array($action,['add','update'],true)&&(($params['staff_uuid']??'')!==$lease['staff']['uuid']||strpos((string)($params[$module==='gradeEstimation'?'declare_achievement':'demo']??''),'CDXGR10')!==0)){http_response_code(403);exit;}
if($action==='lists'&&isset($params['staff_uuid'])&&$params['staff_uuid']!==$lease['staff']['uuid']){http_response_code(403);exit;}
if(in_array($action,['update','delete','info'],true)&&isset($params['uuid'])&&$params['uuid']!=='00000000-0000-0000-0000-000000000811'&&$params['uuid']!==($own[$module]['uuid']??null)){http_response_code(403);exit;}
\think\App::run()->send();
