0)||
(isset($OJ_ON_SITE_CONTEST_ID)&&$OJ_ON_SITE_CONTEST_ID>0)||
(isset($OJ_SHARE_CODE)&&!$OJ_SHARE_CODE)
){
$view_errors= "代码分享功能当前不可用!";
require("template/".$OJ_TEMPLATE."/error.php");
exit (0);
}
// 删除某一个分享的代码
if(isset($_POST['delete'])) {
$sid = $_POST['delete'];
header('Content-Type:application/json');
if (!isset($_SESSION[$OJ_NAME.'_'.'user_id'])){
echo '{
"status": "error",
"msg": "请先登录!"
}';
}else {
if(!checkCodeOwner($sid, $user_id)){
echo '{
"status": "error",
"msg": "您没有权限删除!"
}';
}else {
deleteShareCodeBySid($sid, $user_id);
echo '{
"status": "success",
"msg": "删除成功!"
}';
}
}
exit(0);
}
// 查看分享的代码
if(isset($_GET['sid'])){
// share_id
$sid = intval($_GET['sid']);
$share_info = getShareCodeBySid($OJ_MEMCACHE,$sid);
// 代码不存在
if(count($share_info)==0){
$view_errors= "该代码不存在!";
require("template/".$OJ_TEMPLATE."/error.php");
}else {
//echo array_column($share_info,"user_id")[0] ;
$sid = array_column($share_info,"share_id")[0];
$author = array_column($share_info,"user_id")[0];
$title = array_column($share_info,"title")[0];
$language = array_column($share_info,"language")[0];
$share_time = array_column($share_info,"share_time")[0];
$view_src = array_column($share_info,"share_code")[0];
if($author==$user_id){
$readOnly = false;
$isOwner = true;
}else {
$readOnly = true;
}
require("template/" . $OJ_TEMPLATE . "/sharecodepage.php");
}
exit(0);
}
// 存储提交代码,包括新提交以及修改提交
if(isset($_POST['code'])) {
if (!isset($_SESSION[$OJ_NAME.'_'.'user_id'])){
$view_errors= "$MSG_Login";
require("template/".$OJ_TEMPLATE."/error.php");
}else {
header('Content-Type:application/json');
$vcode = $_POST['vcode'];
if($_SESSION[$OJ_NAME.'_'."vcode"]==null||$vcode!= $_SESSION[$OJ_NAME.'_'."vcode"]||$vcode==""||$vcode==null){
$_SESSION[$OJ_NAME.'_'."vcode"]=null;
echo '{
"status": "error",
"msg": "验证码错误"
}';
}else {
if(isset($_POST['sid'])) {
$sid = $_POST['sid'];
}
$title = $_POST['title'];
$code = $_POST['code'];
$language = $_POST['language'];
try {
if(isset($_POST['sid'])) {
$new_id = updateShareCodeBySid($sid,$title, $code, $language, $user_id);
}else {
$new_id = saveShareCode($title,$code, $language, $user_id);
}
}catch (Exception $e) {
echo '{
"status": "error",
"msg": "系统繁忙"
}';
exit(0);
}
echo '{
"status": "success",
"msg": "添加成功!",
"data": {
"sid":'.$new_id.'
}
}';
}
}
exit(0);
}
// 请求未带参数,直接进入代码提交页面
if (empty($_GET)) {
if (!isset($_SESSION[$OJ_NAME.'_'.'user_id'])){
$view_errors= "$MSG_Login";
require("template/".$OJ_TEMPLATE."/error.php");
}else {
$readOnly = false;
require("template/" . $OJ_TEMPLATE . "/sharecodepage.php");
}
exit(0);
}
// json 请求时
if (isset($_GET['type'])&&$_GET['type']=='json') {
header('Content-Type:application/json');
if(isset($_GET['list'])&&$_GET['list']=='submit'){
$subList = getSubmitByCid($OJ_MEMCACHE,$cid);
$problemMap = getProblemMapByCid($OJ_MEMCACHE,$cid);
$arr = array();
for($i=0;$i