This repository has been archived by the owner on Feb 8, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhomework.php
executable file
·229 lines (220 loc) · 8.76 KB
/
homework.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
<?php
/*
作业上传系统独立精简版 v1
原始版本作者:CopyRight(C) 程式设计 Coding axer@tc.edu.tw 20120216-0314
修改版本作者:CopyRight(C) 老周部落
版权宣告:本程式遵从GNUv3规范 http://www.gnu.org/licenses/gpl.html
使用者作业管理程式
*/
include "includes/init.php";
include "includes/homework.class.php";
$obj = new Homework_class();
$obj->DB= $DB;
$obj->f = $f;
$obj->SetSession($_SESSION);
// $obj->InitAllCatArr();
//For index only
$view->caching = 0;
//$view->compile_check = true;
//$view->cache_lifetime = 10800; //3 hours
$view->assign('obj', $obj);
$view->assign('f', "HW");
switch($f){
case "ChkCanUpload": //AJAX
$hID = (int)$_POST['sn'];
$upPasswd= isset( $_POST['p'])?$_POST['p']:"";
print $IsOk= $obj->CheckCanUpload($hID, $upPasswd);
break;
case "DlHwIframe":
$sn = (int)$obj->LongDecode($_GET['c']);
$obj->SendFile2Browser($sn);
break;
case "DoMyHw":
$wt=5000;
$sn = (int)$obj->LongDecode($_POST['c']);
$crypt = md5($_POST['passwd']);
$IsOk= $obj->CheckHwPasswd($sn, $crypt);
if($IsOk <0){
$msg="密码错误,无法操作 Err{$IsOk}";
$msg .= $obj->JS_CntDn( "{$_SESSION['currURL']}" , $wt);
$view->assign('msg', $msg);
$view->display('Message.mtpl');
break;
}
switch($_POST['o']){
case 'd':
$IsOk =$obj->ProcDelOneUploadHw( $sn );
if( $IsOk>0 ) { $msg ="档案删除成功 <br />"; $wt=2000; }
else $msg = "档案删除失败 Err{$IsOk}";
break;
case 'dl':
$view->assign('sn', $sn);
$view->assign('c', $_POST['c']);
$view->display('HwDownloadPage.mtpl');
exit; //中止
break;
case 'm':
$view->assign('sn', $sn);
$view->display('HwModPage.mtpl');
exit; //中止
break;
default:
$msg="不明的操作错误Err-11";
break;
}
$msg .= $obj->JS_CntDn( "{$_SESSION['currURL']}" , $wt);
$view->assign('msg', $msg);
$view->display('Message.mtpl');
break;
case "ModMyHw":
$sn = (int)$obj->LongDecode($_POST['snc']);
$arr= array();
$row = $obj-> GetOneUploadHw($sn);
//判断作业编号是否正确
if(!isset($row['hID']) || $row['hID']<= 0){
$msg="错误的作业编号Err-12";
$msg .= $obj->JS_CntDn( "{$_SESSION['currURL']}" , 5000);
$view->assign('msg', $msg);
$view->display('Message.mtpl');
break;
}
//判断作业是否在可上传状态
$ret = $obj-> GetOneHw($row['hID']);
if ($ret['canUpload'] == 0){
$msg="档案修改失败,非上传时间Err-3";
$msg .= $obj->JS_CntDn( "{$_SESSION['currURL']}" , 5000);
$view->assign('msg', $msg);
$view->display('Message.mtpl');
break;
}
//从POST请求中获取学号、姓名
$cid = mysqli_real_escape_string($obj->DB->_connectionID, trim( $_POST['cid'] ));//学号
$cname = mysqli_real_escape_string($obj->DB->_connectionID, trim( $_POST['cname'] ));//姓名
if(!$obj-> CheckCidByRegex($cid, $row['hID'])){
$msg="您输入的学号不符合管理员在后台设置的正则表达式,请重新输入!";
$msg .= $obj->JS_CntDn( "{$_SESSION['currURL']}" , 5000);
$view->assign('msg', $msg);
$view->display('Message.mtpl');
break;
}
if($_FILES['MyFile']['size']>0){ // 有上传新档
//通过数据库获取作业标题,并将其传送给ProcUpFiles, 作业标准化命名需求
$title = $obj-> GetHwTitle($row['hID']);
$imgDir = HWPREFIX ."{$row['hID']}/"; //ex: 2008DecMedia/
if(empty($obj->GetHwFolderNameFormat($row['hID']))) {
$foldername = '';
} else {
$foldername = $obj->GetHwFolderNameFormat($row['hID']) . "/"; //ex: xx00/
}
if(empty($obj->GetHwFileNameFormat($row['hID']))) {
$filename = "\$title-\$cid-\$cname.\$ext";
} else {
$filename = $obj->GetHwFileNameFormat($row['hID']);
}
$IsOk= $obj->ProcUpFiles($_FILES['MyFile'], $imgDir, $rrr, $title, $cid, $cname, $foldername, $filename);
if( $IsOk >0){ $arr= $rrr; }
else $msg="档案上传失败 Err{$IsOk}";
} else {
$hwcheck = $obj-> GetOneUploadHw($sn);
if ($hwcheck['cid'] != $cid || $hwcheck['cname'] != $cname){
$msg="如需修改学号及姓名,请重新上传文档!";
$msg .= $obj->JS_CntDn( "{$_SESSION['currURL']}" , 5000);
$view->assign('msg', $msg);
$view->display('Message.mtpl');
break;
} else {
$IsOk = 1;//无上传文件直接标记为成功
}
}
$arr['sn']= $sn;
$arr['modPasswd']= $_POST['passwd'];
$arr['remark']= mysqli_real_escape_string($obj->DB->_connectionID, trim( $_POST['remark'] ));
$arr['cid']= mysqli_real_escape_string($obj->DB->_connectionID, trim( $_POST['cid'] ));//学号
$arr['cname']= mysqli_real_escape_string($obj->DB->_connectionID, trim( $_POST['cname'] ));//姓名
$arr['uDT']=time();
if( !$row)$msg = "修改失败,参数错误 Err-13";
else {
if( $IsOk>0 ){ $IsOk =$obj->ProcModMyHw ( $arr ); }//文件上传成功再修改数据库
if( $IsOk>0 ){ $msg ="档案修改成功 <br />"; }
else $msg = "档案修改失败 Err{$IsOk}";
}
$msg .= $obj->JS_CntDn( SITE_URL ."?f=HwDetail&c={$obj->LongEncode($row['hID'])}" , 5000);
$view->assign('msg', $msg);
$view->display('Message.mtpl');
break;
case "UploadHw":
$hID = (int)$_POST['hID'];
$upPasswd= isset( $_POST['upPasswd'])?$_POST['upPasswd']:"";
$IsOk= $obj->CheckCanUpload($hID, $upPasswd);
if( $IsOk <=0){
if($IsOk ==-3) $msg ="档案上传失败,非上传时间 Err{$IsOk}";
elseif($IsOk ==-4) $msg ="档案上传失败,上传密码错误 Err{$IsOk}";
else $msg= "档案上传失败 Err{$IsOk}";
$msg .= $obj->JS_CntDn( SITE_URL . "?f=HwDetail&c={$obj->LongEncode($hID)}" , 5000);
$view->assign('msg', $msg);
$view->display('Message.mtpl');
break;
}
//从POST请求中获取学号、姓名,通过数据库获取作业标题,并将其传送给ProcUpFiles, 作业标准化命名需求
$cid = mysqli_real_escape_string($obj->DB->_connectionID, trim( $_POST['cid'] ));//学号
$cname = mysqli_real_escape_string($obj->DB->_connectionID, trim( $_POST['cname'] ));//姓名
$title = $obj-> GetHwTitle($hID);
if(!$obj-> CheckCidByRegex($cid, $hID)){
$msg="您输入的学号不符合管理员在后台设置的正则表达式,请重新输入!";
$msg .= $obj->JS_CntDn( "{$_SESSION['currURL']}" , 5000);
$view->assign('msg', $msg);
$view->display('Message.mtpl');
break;
}
if($obj-> CheckUploadStatusByCid($cid, $hID)){
$msg="本学号已经上传过作业,请使用编辑功能或删除后重新上传!";
$msg .= $obj->JS_CntDn( "{$_SESSION['currURL']}" , 5000);
$view->assign('msg', $msg);
$view->display('Message.mtpl');
break;
}
$imgDir = HWPREFIX .$hID. "/"; //ex: xx00/
if(empty($obj->GetHwFolderNameFormat($hID))) {
$foldername = '';
} else {
$foldername = $obj->GetHwFolderNameFormat($hID) . "/"; //ex: xx00/
}
if(empty($obj->GetHwFileNameFormat($hID))) {
$filename = "\$title-\$cid-\$cname.\$ext";
} else {
$filename = $obj->GetHwFileNameFormat($hID);
}
$IsOk= $obj->ProcUpFiles($_FILES['MyFile'], $imgDir, $rrr, $title, $cid, $cname, $foldername, $filename);
$msg="";
if( $IsOk >0){
$arr=$rrr;
$arr['hID']=$hID;
$arr['modPasswd']= $_POST['passwd'];
$arr['remark']= mysqli_real_escape_string($obj->DB->_connectionID, trim( $_POST['remark'] ));
$arr['cid']= mysqli_real_escape_string($obj->DB->_connectionID, trim( $_POST['cid'] ));
$arr['cname']= mysqli_real_escape_string($obj->DB->_connectionID, trim( $_POST['cname'] ));
$arr['cDT']=time();
$arr['uDT']=$arr['cDT']; //第一次上传时,更新时间与新增时间相同
$IsOk =$obj->ProcAddHwUpload( $arr );
if( $IsOk>0 ) $msg .="档案上传储存成功 <br />";
else $msg .= "档案上传储存失败 Err{$IsOk}";
}else{
if($IsOk ==-1) $msg ="档案传输错误 Err{$IsOk}";
elseif($IsOk ==-4) $msg ="档案类型不被允许 Err{$IsOk}";
else $msg= "目录建立失败,请检查目录权限是否可供写入 Err{$IsOk}";
}
$msg .= $obj->JS_CntDn( SITE_URL . "?f=HwDetail&c={$obj->LongEncode($hID)}" , 3000);
$view->assign('msg', $msg);
$view->display('Message.mtpl');
break;
case "View":
$sn = (int)$obj->LongDecode($_GET['c']);
$IsOk= $obj->SendFile2Browser($sn);
break;
default:
$msg = "连结错误操作,一秒后导至首页{$f}". $obj->JS_CntDn( SITE_URL ,10000);
$view->assign('msg', $msg);
$view->display('Message.mtpl');
break;
}
?>