forked from QuantaCenter/grab
/
grab.php
63 lines (63 loc) · 1.7 KB
/
grab.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
<?php
header("Content-type: text/html; charset=gb2312");
include ("Course.class.php");
switch($_GET['action']){
case 'login':
login();
break;
case 'choose':
choose();
break;
case 'grab':
grab();
break;
}
function login(){//登录
$grab = new Course($_POST['username']);
$username = $_POST['username'];
$password = $_POST['password'];
$url = "http://jw.gdufs.edu.cn/pkmslogin.form";
$field = array('username'=>$username,'password'=>$password,'login-form-type'=>'pwd');
if($grab->login($url,$field)){
$res = my_iconv($grab->loginResult());
echo json_encode($res);
}
else{
echo 0;
}
}
function choose(){//查看课程列表
$grab = new Course($_POST['username']);
$url = "http://jw.gdufs.edu.cn/".$_POST['type']."&xh=".$_POST['username']."&xm=".urlencode($_POST['name']);
$res = my_iconv($grab->showCourse($url));
echo json_encode($res);
}
function grab(){//提交表单
$grab = new Course($_POST['username']);
$url = "http://jw.gdufs.edu.cn/".$_POST['type']."&xh=".$_POST['username']."&xm=".urlencode($_POST['name']);
$course = explode(",", $_POST['course']);
$input = $_POST['input'];
$tempReg = "/=>|&/";
$arr = preg_split($tempReg, $input);
$from = array();
for($i=0;$i<count($arr);$i+=2){
$form[$arr[$i]] = $arr[$i+1];
}
$form['ddl_ywyl'] = "";//有无余量
$form['ddl_kcgs'] = "";//课程归属
$form['ddl_sksj'] = "";//上课时间
$form['ddl_xqbs'] = 2;//1:北校区,2:南校区
$form['Button1'] = "提交";
for($i=0;$i<count($course);$i++){
$form[$course[$i]] = "on";
}
$res = my_iconv($grab->submitForm($url,$form));
echo json_encode($res);
}
function my_iconv($data){
foreach ($data as $key=>$value) {
$data[$key] = iconv("GB2312", "UTF-8", $value);
}
return $data;
}
?>