public static function uploadTestdata($judger, $data_config) { $prob_name = $data_config['name']; $testdata_path = MDL_Config::getInstance()->getVar('judger_testdata') . $prob_name . '/'; $dest_path = $judger->getConfig()->getTestdataPath() . $prob_name . '/'; if (!file_exists($dest_path) || !is_dir($dest_path)) { if (@mkdir($dest_path) === false) { throw new MDL_Exception_Judge_Share(MDL_Exception_Judge_Share::TESTDATA_UPLOAD); } chmod($dest_path, 0755); } unset($data_config['id']); unset($data_config['title']); $xml = BFL_XML::Array2XML($data_config); if (file_put_contents($dest_path . "config.xml", $xml) === false) { throw new MDL_Exception_Judge_Share(MDL_Exception_Judge_Share::TESTDATA_UPLOAD); } if ($testdata_path == $dest_path) { return; } if ($data_config['checker']['type'] == 'custom') { //Upload checker $checker_source = $data_config['checker']['custom']['source']; $checker_file = $testdata_path . $checker_source; $this->copy_file($dest_path . $checker_source, $checker_file); } //Upload testdatas foreach ($data_config['case'] as $item) { foreach (array('input', 'output') as $key) { $testdata_file = $testdata_path . $item[$key]; $this->copy_file($dest_path . $item[$key], $testdata_file); } } }
public static function getLoginedUserInformation() { $acl = MDL_ACL::getInstance(); $user_id = $acl->getUser()->getID(); if ($user_id != 0) { try { $user = MDL_User_Detail::getUser($user_id); BFL_Register::setVar('personal', $user); if (isset($user['identity'])) { $acl->setIdentity($user['identity']); } if (isset($user['preference'])) { $preference = BFL_XML::XML2Array($user['preference']); BFL_Register::setVar('user_preference', $preference); } } catch (MDL_Exception_User $e) { if ($e->testDesc(MDL_Exception_User::FIELD_USER, MDL_Exception_User::INVALID_USER_ID)) { $acl->resetSession(); $acl->initialize(SESSION_PREFIX, 'guest'); } else { throw $e; } } } }
protected function decodeConfig($config_string) { $rs = BFL_XML::XML2Array($config_string); if (!isset($rs['problems'][0])) { $rs['problems'] = array($rs['problems']); } return $rs; }
public function __construct($judger_config = '') { if ($judger_config != '') { $this->config = BFL_XML::XML2Array($judger_config); } else { $this->config = array('url' => '', 'public_key' => '', 'upload' => 'ftp'); } }
public function __construct($record_meta) { if (isset($record_meta->result)) { $result = $record_meta->result; $result = BFL_XML::XML2Array($result); } else { $result = array(); } $this->result = $result; }
/** * edit * @param array $data_config * @return void */ public static function edit($data_config) { $prob_id = $data_config['id']; $data_config = self::format($data_config); $data_config['version'] = time(); $data_config = BFL_XML::Array2XML($data_config); $prob_meta = new MDL_Problem_Meta($prob_id); $prob_meta->setVar('data_config', $data_config); $prob_meta->setVar('verified', 0); }
function writeExecutorConfigFile($program, $time_limit, $memory_limit, $output_limit, $openfile) { $prob_config = array('program' => $program, 'file' => $openfile); if ($time_limit != 0) { $prob_config['time_limit'] = $time_limit; } if ($memory_limit != 0) { $prob_config['memory_limit'] = $memory_limit; } if ($output_limit != 0) { $prob_config['output_limit'] = $output_limit; } $xml = BFL_XML::Array2XML($prob_config); file_put_contents("prob.xml", $xml); }
function getTestdataVersion($prob_name) { $path = Config::getInstance()->getVar('path'); $testdata_path = $path['testdata'] . $prob_name . '/'; $rs['version'] = 0; $rs['hash_code'] = ''; if (file_exists($testdata_path . 'config.xml')) { $xml = file_get_contents($testdata_path . 'config.xml'); $data_config = BFL_XML::XML2Array($xml); if (!isset($data_config['version']) || $data_config['version'] == 0) { $rs['version'] = 0; } else { $rs['version'] = $data_config['version']; } if ($data_config['checker']['type'] == 'custom') { if (!file_exists($testdata_path . $data_config['checker']['name'])) { $rs['version'] = -1; } } $hash_code = ''; if ($data_config['checker']['type'] == 'custom') { $checker_file = $testdata_path . $data_config['checker']['custom']['source']; if (file_exists($checker_file)) { $hash_code .= sha1_file($checker_file, true); } } foreach ($data_config['case'] as $item) { $input_file = $testdata_path . $item['input']; $output_file = $testdata_path . $item['output']; if (file_exists($input_file)) { $hash_code .= sha1_file($input_file, true); } if (file_exists($output_file)) { $hash_code .= sha1_file($output_file, true); } } $hash_code = sha1($hash_code); $rs['hash_code'] = $hash_code; } return $rs; }
public static function uploadTestdata($judger, $data_config) { $prob_name = $data_config['name']; $testdata_path = MDL_Config::getInstance()->getVar('judger_testdata') . $prob_name . '/'; $temp_file = tempnam(sys_get_temp_dir(), 'Vakuum'); unset($data_config['id']); unset($data_config['title']); $xml = BFL_XML::Array2XML($data_config); file_put_contents($temp_file, $xml); $pftp = self::connect($judger); if (ftp_chdir($pftp, $judger->getConfig()->getTestdataPath()) === false) { throw new MDL_Exception_Judge_FTP(MDL_Exception_Judge_FTP::TESTDATA_UPLOAD); } if (@ftp_chdir($pftp, $prob_name) === false) { ftp_mkdir($pftp, $prob_name); ftp_chmod($pftp, 0755, $prob_name); ftp_chdir($pftp, $prob_name); } //Upload config.xml if (ftp_put($pftp, 'config.xml', $temp_file, FTP_BINARY) === false) { throw new MDL_Exception_Judge_FTP(MDL_Exception_Judge_FTP::TESTDATA_UPLOAD); } if ($data_config['checker']['type'] == 'custom') { //Upload checker $checker_source = $data_config['checker']['custom']['source']; $checker_file = $testdata_path . $checker_source; if (ftp_put($pftp, $checker_source, $checker_file, FTP_BINARY) === false) { throw new MDL_Exception_Judge_FTP(MDL_Exception_Judge_FTP::TESTDATA_UPLOAD); } } //Upload testdatas foreach ($data_config['case'] as $item) { foreach (array('input', 'output') as $key) { $testdata_file = $testdata_path . $item[$key]; if (ftp_put($pftp, $item[$key], $testdata_file, FTP_BINARY) === false) { throw new MDL_Exception_Judge_FTP(MDL_Exception_Judge_FTP::TESTDATA_UPLOAD); } } } ftp_close($pftp); }
/** * Ger Problem * @param string $sql_where * @param string $param * @return array Problem */ private static function getProblemAbstract($sql_where, $param) { $db = BFL_Database::getInstance(); $stmt = $db->factory('select * from ' . DB_TABLE_PROB . ' ' . $sql_where); $stmt->bindParam(':param', $param); $stmt->execute(); $rs = $stmt->fetch(); if (empty($rs)) { throw new MDL_Exception_Problem(MDL_Exception_Problem::NOTFOUND); } $problem = $rs; $prob_id = $problem['prob_id']; $prob_meta = new MDL_Problem_Meta($prob_id); $rs = $prob_meta->getAll(); $problem = array_merge($problem, $rs); $problem['data_config'] = BFL_XML::XML2Array($problem['data_config']); if (!isset($problem['data_config']['case'][0])) { $problem['data_config']['case'] = array($problem['data_config']['case']); } return $problem; }
public function getInfo() { if ($this->prob_info == NULL) { $problem = $this->getProblemMeta()->getAll(); $problem['data_config'] = BFL_XML::XML2Array($problem['data_config']); if (!isset($problem['data_config']['case'][0])) { $problem['data_config']['case'] = array($problem['data_config']['case']); } $this->prob_info = $problem; } return $this->prob_info; }
protected function __construct() { $xml = file_get_contents("config.xml"); $this->config = BFL_XML::XML2Array($xml); }
protected static function encodeConfig($config) { return BFL_XML::Array2XML($config); }
public function ACT_dodispatch() { if (isset($_POST['ajax'])) { $ajax = true; } //TODO: add non-ajax support if (!isset($_POST['prob_id']) || !isset($_POST['judger_id'])) { die('interface error'); } $prob_id = $_POST['prob_id']; $judger_id = $_POST['judger_id']; $prob_names = MDL_Problem_Show::getProblemName($prob_id); $data_config = MDL_Problem_Data::getDataConfig($prob_id, $prob_names['prob_name'], $prob_names['prob_title']); $verify_result = MDL_Problem_Dispatch::verify($data_config); if ($verify_result['overall'] != '') { die('problem not verified'); } $rs = MDL_Problem_Dispatch::transmitTestdata($judger_id, $data_config); if ($rs['version'] == $data_config['version'] && $rs['hash_code'] == $verify_result['hash_code']) { $result['overall'] = ""; if ($data_config['checker']['type'] == 'custom' && $data_config['checker']['custom']['language'] != '') { if (!isset($rs['checker_compile']) || $rs['checker_compile'] != 1) { $result['overall'] = "checker_compile"; } } } else { $result['overall'] = "verify"; } echo BFL_XML::Array2XML($result); }
public static function recordExecute($info) { $newCase = $info; unset($newCase['record_id']); $record_meta = new MDL_Record_Meta($info['record_id']); if ($record_meta->getVar('status') == self::STATUS_STOPPED) { return; } if (isset($record_meta->result)) { $result = $record_meta->result; $result = BFL_XML::XML2Array($result); } else { $result = array(); } if (isset($result['execute']['case'])) { if (!isset($result['execute']['case'][0])) { $result['execute']['case'] = array($result['execute']['case']); } $result['execute']['case'][] = $newCase; } else { $result['execute']['case'] = $newCase; } $result = BFL_XML::Array2XML($result); $record_meta->setVar('result', $result); $record_meta->setVar('result_text', $info['case_id']); $record_meta->setVar('status', self::STATUS_RUNNING); }