-
Notifications
You must be signed in to change notification settings - Fork 1
/
manage.php
307 lines (295 loc) · 11.1 KB
/
manage.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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
<?php
/*
作業上傳系統獨立精簡版 v1
CopyRight(C) 程式設計 Coding [email protected] 20120216-0228
版權宣告:本程式遵從GNUv3規範 http://www.gnu.org/licenses/gpl.html
作業管理程式
*/
include "includes/init.php";
include "includes/manage.class.php";
$obj = new Manage_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
if( !isset($_SESSION['priv'])) $_SESSION['priv'] = $obj->GetNoLoginPrivArr();
$view->assign('obj', $obj);
if( $f=="AccManage")$view->assign('f', "AccManage");
else $view->assign('f', "HW");
if( empty($_SESSION['email'])){ $view->display('LoginPage.mtpl'); exit; }
switch($f){
case "AccManage":
$view->display('AccManage.mtpl');
break;
case "AddAccount":
$sup = $_POST['superpasswd'];
if( $sup !== SUPER_PASSWD ){ $IsOk =-12; $msg="超級密碼錯誤! Err-12"; }
else{
$arr= array(
'email' => $_POST['email'],
'shadow' => md5($_POST['email']),
'passwd' => md5($_POST['passwd']),
'usID' => mysql_real_escape_string($_POST["usID"]),
'cname' => mysql_real_escape_string($_POST["cname"]),
"regDT" => date("Y-n-d H:i:s")
);
$IsOk =$obj->ProcAdmAddMember( $arr );
$msg="伺服器狀態異常,新增失敗! Err{$IsOk}";
}
if( $IsOk >0 ) $msg="會員新增成功";
elseif( $IsOk =-4 ) $msg="帳號已經存在";
$msg .= $obj->JS_CntDn( SITE_URL. "manage.php?f=AccManage" , 4000);
$view->assign('msg', $msg);
$view->display('Message.mtpl');
break;
case "ChangeHomework":
if( !isset($_POST['stp'])){ $view->display('AddHwPage.mtpl'); break; }
$stp= (int)$_POST['stp'];
$c= empty($_POST['c'])?"":$_POST['c'];
$rank=(int)$_POST["rank"];
if($rank>99)$rank=99;elseif($rank<0)$rank=0;
$arr=array(
"hwTitle"=> mysql_real_escape_string(trim($_POST["hwTitle"])),
"hwO"=> mysql_real_escape_string(trim($_POST["hwO"])),
"email"=> $_SESSION['email'],
"passwd"=> mysql_real_escape_string($_POST["passwd"]),
"classID"=> mysql_real_escape_string($_POST["classID"]),
"fromDT" => empty( $_POST["from"])?"": $_POST["from"],
"dueDT" => empty($_POST["to"])?"": $_POST["to"],
"remark" => addslashes($_POST["remark"]),
"closed" => (int)$_POST["closed"],
"display" => (int)$_POST["display"],
"upPasswd" => (int)$_POST["upPasswd"],
"rank" =>$rank,
"cDT" => date("Y-n-d H:i:s")
);
if($stp==3){ $IsOk =$obj->ProcAddHw( $arr );
if( $IsOk <=0 )$msg="伺服器狀態異常,寫入終止! Err{$IsOk}";
else $msg="新增作業成功";
}elseif($stp==5){
$arr['hID']= (int)$_POST["hID"];
$IsOk =$obj->ProcModHw( $arr );
if( $IsOk <=0 )$msg="伺服器狀態異常,寫入終止! Err{$IsOk}";
else $msg="修改作業成功";
}
$msg .= $obj->JS_CntDn( SITE_URL . "manage.php?f=Homework&c={$c}" , 4000);
$view->assign('msg', $msg);
$view->display('Message.mtpl');
break;
case "ChangeHwFilePWD": //變更學生上傳檔案之存取密碼
$wt=2000;
if(isset($_POST['passwd']) and trim($_POST['passwd'])<>""){
$sn = (int)$obj->LongDecode($_POST['c']);
$IsOk =$obj->ProcChangeUpHwAttr($sn, "modPasswd", trim($_POST['passwd']));
if( $IsOk <=0 )$msg="伺服器狀態異常,寫入終止! Err{$IsOk}";
else $msg="重設密碼成功";
} else {
$wt=5000;
$msg = "未輸入新密碼";
}
$msg .= $obj->JS_CntDn( $_SESSION['currURL'] , $wt);
$view->assign('msg', $msg);
$view->display('Message.mtpl');
break;
case "DelHw":
$wt=5000;
if( isset($_GET['c'])){
$sn = (int)$obj->LongDecode($_GET['c']);
include "includes/homework.class.php";
$obj2 = new Homework_class();
$obj2->DB= $DB;
$obj2->SetSession($_SESSION);
$IsOk =$obj2->ProcDelOneUploadHw( $sn );
unset( $obj2);
if( $IsOk>0 ) { $msg ="檔案刪除成功 <br />"; $wt=2000; }
else $msg = "檔案刪除失敗 Err{$IsOk}";
}
else $msg = "錯誤的操作 Err-11";
$msg .= $obj->JS_CntDn( $_SESSION['currURL'] , $wt);
$view->assign('msg', $msg);
$view->display('Message.mtpl');
break;
case "DelAccount":
$wt=1000;
$sup = $_POST['superpasswd'];
if( $sup !== SUPER_PASSWD ){ $IsOk =-12; $msg="超級密碼錯誤! Err-12"; }
else{
$IsOk =$obj->ProcDelMember( $_POST['email'] );
if( $IsOk <=0 ){$msg="伺服器狀態異常,寫入終止! Err{$IsOk}"; $wt=3000;}
else $msg="會員刪除成功";
}
$msg .= $obj->JS_CntDn( SITE_URL. "manage.php?f=AccManage", $wt, false);
$view->assign('msg', $msg);
$view->display('Message.mtpl');
break;
case "FindUpHwPasswd": //查詢學生作業檔案密碼
$thePasswd="";
if(isset($_POST['c']) and trim($_POST['c'])<>""){
$sn = (int)$obj->LongDecode($_POST['c']);
$sql="select `modPasswd` from `hwUpload` where `sn`='".$sn."'";
$thePasswd=$obj->DB->GetOne($sql);
}
echo $thePasswd;
break;
case "Homework":
if( empty($_POST['c']) && empty($_GET['c'])){
$tbl=array(
"pg"=>1,
"kw"=> empty($_POST["kw"])?"": trim(addslashes($_POST["kw"])),
"s" => empty( $_POST["s"])?"": $_POST["s"],
"from" => empty( $_POST["from"])?"": $_POST["from"],
"to" => empty($_POST["to"])?"": $_POST["to"],
);
}else{
$c =empty($_POST['c'])? $_GET['c']:$_POST['c'];
$tbl= $obj->Decrypt_c2Arr( $c );
if(! isset($tbl['pg']))$tbl['pg']=1;
}
if(! empty($tbl['s'])){ //_kw=1,_date=1,_state=1,state=0
$s= $tbl['s'];
$srr = explode(",",$s);
foreach($srr as $it){
preg_match('/(\w+)=(\w+)/', $it, $match);
$k= $match[1];
$v= $match[2];
$tbl[$k]=$v;
}
}
if(isset($tbl['stp'])) $stp= (int)$tbl['stp'];
else $stp= empty($_POST['stp'])?(empty($_GET['stp'])?0:(int)$_GET['stp']):(int)$_POST['stp'];
$tbl['odr']= empty($_GET['odr'])?(empty($tbl['odr'])?0:$tbl['odr']):(int)$_GET['odr']; //default no orderby
$obj->SetCurrParam($tbl);
unset($tbl['stp']); //clear
$c= $obj->Encrypt_Arr2c($tbl);
$view->assign('c', $c);
switch($stp){
case 2: //Modi
$sn= $tbl['sn'];
$view->assign('hID', $sn);
$view->display('ModHwPage.mtpl');
break;
case 3: //Save Modi
break;
case 4: //close
$sn= $tbl['sn'];
$IsOk = $obj->ProcChangeHwAttr($sn, "closed");
if( $IsOk <=0 )$msg="伺服器狀態異常,寫入終止! Err{$IsOk}";
else $msg="修改作業屬性[有效]成功";
$msg .= $obj->JS_CntDn( SITE_URL ."manage.php?f=Homework&c={$c}" , 2000);
$view->assign('msg', $msg);
$view->display('Message.mtpl');
break;
case 5: //display
$sn= $tbl['sn'];
$IsOk = $obj->ProcChangeHwAttr($sn, "display");
if( $IsOk <=0 )$msg="伺服器狀態異常,寫入終止! Err{$IsOk}";
else $msg="修改作業屬性[展示]成功";
$msg .= $obj->JS_CntDn( SITE_URL ."manage.php?f=Homework&c={$c}" , 2000);
$view->assign('msg', $msg);
$view->display('Message.mtpl');
break;
case 6: //delete
$sn= $tbl['sn'];
$IsOk = $obj->ProcDelHw($sn);
if( $IsOk <=0 )$msg="伺服器狀態異常,寫入終止! Err{$IsOk}";
else $msg="刪除作業成功,刪除目錄:". HWPREFIX. $sn;
$msg .= $obj->JS_CntDn( SITE_URL ."manage.php?f=Homework&c={$c}", 4000);
$view->assign('msg', $msg);
$view->display('Message.mtpl');
break;
case 7: //hw Manage
$_SESSION['currURL']= $_SERVER['REQUEST_URI'];
$sn= $tbl['sn'];
$view->assign('hID', $sn);
$view->display('ManageUpHw.mtpl');
break;
case 9: //Dl hw
$sn= $tbl['sn'];
$wt=4000;
$targetDir = HWPREFIX. $sn;
$IsOk =$obj-> CreateDirectory(UPLOAD_TEMP_DIR);
if( $IsOk == -1 )$msg="存在但不是目錄,新增目錄失敗! Err{$IsOk}". $obj->JS_CntDn( $_SESSION['currURL'] , $wt);
elseif( $IsOk == -2 ) $msg="新增目錄失敗! Err{$IsOk}". $obj->JS_CntDn( $_SESSION['currURL'] , $wt);
elseif ( !system('command -v zip')) {
$msg= "系統無zip命令,請安裝zip套件 Err-3。<br/>安裝範例: yum install zip";
}
else{
// $tmpPath = UPLOAD_TEMP_DIR. "$targetDir.zip";
$currPath= UPLOAD_DIR. $targetDir;
$cmd = "cd ". UPLOAD_TEMP_DIR. "; rm -f {$targetDir}.zip; zip -rjq {$targetDir}.zip $currPath/*";
system( $cmd );
sleep(1);
$msg="<h3>檔名{$targetDir}.zip,請 [<a href='". SITE_URL. UPDIR . TEMP_PATH . $targetDir .".zip'>點選此處下載</a>] </h3>檔案資訊:<div style='text-align:left;'>";
$arr= $obj-> GetUploadHwList($sn);
foreach($arr as $it){
$msg .= "{$it['fileName']} ,{$it['size']}bytes ,擁有人{$it['cname']} ,原檔名{$it['oFileName']} ,備註{$it['remark']}<br/>";
}
$msg .="</div>";
}
$view->assign('msg', $msg);
$view->display('Message.mtpl');
break;
default:
$_SESSION['currURL']= $_SERVER['REQUEST_URI'];
$view->display('HwManage.mtpl');
break;
}
break;
case "MngUpHw": //AJAX
$opr= isset($_POST['opr'])?$_POST['opr']:"";
$snc = isset($_POST['sn'])?$_POST['sn']:"";
if( empty($opr) || empty($snc)){ print "參數錯誤Err-10"; break; }
$row = $obj->Decrypt_c2Arr( $snc );
if($row['sn'] <= 0){ print "參數錯誤Err-11"; break; }
$sn =$row['sn'];
switch($opr){
case "ex": //exhibition
$IsOk = $obj->ProcChangeUpHwAttr($sn, "display");
if( $IsOk <=0 )$msg="伺服器狀態異常,寫入終止! Err{$IsOk}";
else $msg="1";
print $msg;
break;
case "p": //passed
$IsOk = $obj->ProcChangeUpHwAttr($sn, "passed");
if( $IsOk <=0 )$msg="伺服器狀態異常,寫入終止! Err{$IsOk}";
else{
$obj->UpdatePassedCnt( $sn, $row['p'] );
$msg="2";
}
print $msg;
break;
default:
print "參數錯誤Err-12";
break;
}
break;
case "SaveUpHwScore":
$wt=5000;
$z= $_POST['z'];
$h= $_POST['h'];
$IsOk = $obj->UpdateUpHwScore($z,$h);
if( $IsOk == -1 )$msg="沒有資料,動作無效! Err{$IsOk}";
if( $IsOk <=0 )$msg="伺服器狀態異常,寫入終止! Err{$IsOk}";
else {$msg="儲存作業成績成功"; $wt=2000;}
$msg .= $obj->JS_CntDn( $_SESSION['currURL'] , $wt);
$view->assign('msg', $msg);
$view->display('Message.mtpl');
break;
case "SaveOneHwScore":
$IsOk = $obj->UpdateOneHwScore($_POST);
if( $IsOk == -1 )$msg="沒有資料,動作無效! Err{$IsOk}";
if( $IsOk <=0 )$msg="伺服器狀態異常,寫入終止! Err{$IsOk}";
else {$msg="儲存作業成績成功"; $wt=2000;}
print $msg;
break;
default:
$msg = "". $obj->JS_CntDn( SITE_URL, 0);
$view->assign('msg', $msg);
$view->display('Message.mtpl');
break;
}
?>