","]]]]>",$content);
}
function getTestFileIn($pid, $testfile,$OJ_DATA) {
if ($testfile != "")
return file_get_contents ( "$OJ_DATA/$pid/" . $testfile . ".in" );
else
return "";
}
function getTestFileOut($pid, $testfile,$OJ_DATA) {
if ($testfile != "")
return file_get_contents ( );
else
return "";
}
function printTestCases($pid,$OJ_DATA){
if(strstr($OJ_DATA,"saestor:")) {
// echo "$pid";
$store = new SaeStorage();
$ret = $store->getList("data", "$pid",100,0 );
foreach($ret as $file) {
// echo "$file";
if(!strstr($file,"sae-dir-tag")){
$pinfo = pathinfo ( $file );
if (isset($pinfo ['extension'])
&&$pinfo ['extension'] == "in"
&& $pinfo ['basename'] != "sample.in") {
$f = basename ( $pinfo ['basename'], "." . $pinfo ['extension'] );
$outfile="$pid/" . $f . ".out";
$infile="$pid/" . $f . ".in";
if( $store->fileExists ("data",$infile)){
echo "read ("data",$infile))."]]>\n";
}if($store->fileExists ("data",$outfile)){
echo "read ("data",$outfile))."]]>\n";
}
// break;
}
}
}
}else{
$ret = "";
$pdir = opendir ( "$OJ_DATA/$pid/" );
while ( $file = readdir ( $pdir ) ) {
$pinfo = pathinfo ( $file );
if (isset($pinfo ['extension'])
&&$pinfo ['extension'] == "in"
&& $pinfo ['basename'] != "sample.in") {
$ret = basename ( $pinfo ['basename'], "." . $pinfo ['extension'] );
$outfile="$OJ_DATA/$pid/" . $ret . ".out";
$infile="$OJ_DATA/$pid/" . $ret . ".in";
if(file_exists($infile)){
echo "\n";
}if(file_exists($outfile)){
echo "\n";
}
// break;
}
}
closedir ( $pdir );
return $ret;
}
}
class Solution{
var $language="";
var $source_code="";
}
function getSolution($pid,$lang){
$ret=new Solution();
$language_name=$GLOBALS['language_name'];
$sql = "select `solution_id`,`language` from solution where problem_id=? and result=4 and language=? limit 1";
// echo $sql;
$result = pdo_query($sql,$pid, $lang) ;
if($result&&$row = $result[0] ){
$solution_id=$row[0];
$ret->language=$language_name[$row[1]];
$sql = "select source from source_code where solution_id=?";
$result = pdo_query( $sql,$solution_id ) ;
if($row = $result[0] ){
$ret->source_code=$row['source'];
}
}
return $ret;
}
function fixurl($img_url){
$img_url= html_entity_decode( $img_url,ENT_QUOTES,"UTF-8");
if (substr($img_url,0,4)!="http"){
if(substr($img_url,0,1)=="/"){
$ret='http://'.$_SERVER['HTTP_HOST'].':'.$_SERVER["SERVER_PORT"].$img_url;
}else{
$path= dirname($_SERVER['PHP_SELF']);
$ret='http://'.$_SERVER['HTTP_HOST'].':'.$_SERVER["SERVER_PORT"].$path."/../".$img_url;
}
}else{
$ret=$img_url;
}
return $ret;
}
function image_base64_encode($img_url){
$img_url=fixurl($img_url);
if (substr($img_url,0,4)!="http") return false;
$handle = @fopen($img_url, "rb");
if($handle){
$contents = stream_get_contents($handle);
$encoded_img= base64_encode($contents);
fclose($handle);
return $encoded_img;
}else
return false;
}
function getImages($content){
preg_match_all("<[iI][mM][gG][^<>]+[sS][rR][cC]=\"?([^ \"\>]+)/?>",$content,$images);
return $images;
}
function fixImageURL(&$html,&$did){
$images=getImages($html);
$imgs=array_unique($images[1]);
foreach($imgs as $img){
$html=str_replace($img,fixurl($img),$html);
//print_r($did);
if(!in_array($img,$did)){
$base64=image_base64_encode($img);
if($base64){
echo "
";
}
array_push($did,$img);
}
}
}
if (! isset ( $_SESSION[$OJ_NAME.'_'.'administrator'] )) {
echo "";
echo "Please Login First!";
exit ( 1 );
}
if (isset($_POST ['do'])||isset($_GET['cid'])) {
if(isset($_POST ['in'])&&strlen($_POST ['in'])>0){
require_once("../include/check_post_key.php");
$in= $_POST ['in'] ;
$ins=explode(",",$in);
$in="";
foreach($ins as $pid){
$pid=intval($pid);
if($in)$in.=",";
$in.=$pid;
}
$sql = "select * from problem where problem_id in($in)";
$result = pdo_query( $sql );
$filename="-$in";
}else if (isset($_GET['cid'])){
require_once("../include/check_get_key.php");
$cid=intval( $_GET['cid'] );
$sql= "select title from contest where contest_id=?";
$result = pdo_query( $sql,$cid );
$row = $result[0];
$filename='-'.$row['title'];
$sql = "select * from problem where problem_id in(select problem_id from contest_problem where contest_id=?)";
$result = pdo_query( $sql ,$cid);
}else{
require_once("../include/check_post_key.php");
$start = intval ( $_POST ['start'] );
$end = intval ( $_POST ['end'] );
$sql = "select * from problem where problem_id>=? and problem_id<=? order by problem_id ";
$result = pdo_query( $sql,$start ,$end);
$filename="-$start-$end";
}
//echo $sql;
if (isset($_POST ['submit'])&&$_POST ['submit'] == "Export")
header ( 'Content-Type: text/xml' );
else {
header ( "content-type: application/file" );
header ( "content-disposition: attachment; filename=\"fps-".$_SESSION[$OJ_NAME.'_'.'user_id'].$filename.".xml\"" );
}
echo "";
?>
-
]]>
]]>
]]>
]]>
]]>
]]>
]]>
]]>
]]>
language){?>
source_code)?>]]>
";
if (file_exists($append_file)){?>
< language="">]]>>
";
}
elseif(file_exists( $filecc )){
echo "";
}
}
?>
";
}
?>