-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsample_mixed.php
164 lines (151 loc) · 4.48 KB
/
sample_mixed.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
<html>
<head>
<style>
body {
background: #333;
}
a, pre {
color: #ccc;
}
strong {
color: #fff;
font-weight: normal;
}
</style>
</head>
<body>
<pre>
<?php
require_once 'vendor/autoload.php';
require_once 'ClisClient.php';
require_once 'WinjClient.php';
function sortArrayByKey(&$array, $sortKey, $sortType = SORT_ASC)
{
$sort_array = [];
foreach ($array as $key => $row) {
if (!isset($row[$sortKey]) or is_null($row[$sortKey])) {
$sort_array[$key] = $key * 0.01; //元の順番を保つ小細工
} else {
$sort_array[$key] = $row[$sortKey];
}
}
array_multisort($sort_array, $sortType, $array);
unset($sort_array);
}
function fixDateFormat($str)
{
if (preg_match("/(\d+)年(\d+)月(\d+)日/", $str, $m)) {
$str = $m[1] . "/" . sprintf("%02d", $m[2]) . "/" . sprintf("%02d", $m[3]);
}
return $str;
}
//世田谷
$client = new ClisClient("https://libweb.city.setagaya.tokyo.jp/idcheck.shtml", [
"UID" => "********",
"PASS" => "********",
], "form.loginform");
$seta_bor = $client->getBorrowing();
$seta_res = $client->getReservation();
sortArrayByKey($seta_res, "order");
//千代田
$client = new WinjClient("https://opc.library.chiyoda.tokyo.jp/winj/opac/login.do?dispatch=/opac/mylibrary.do&every=1", [
"txt_usercd" => "********",
"txt_password" => "********"
], "form[name='LoginForm']");
$chiyo_bor = $client->getBorrowing("返却期限:");
$chiyo_res = $client->getReservation();
sortArrayByKey($chiyo_res, "order");
//渋谷
$client = new WinjClient("https://www.lib-shibuya.tokyo.jp/winj/opac/login.do?lang=ja&dispatch=/opac/mylibrary.do&every=1", [
"txt_usercd" => "********",
"txt_password" => "********"
], "form[name='LoginForm']");
$shibu_bor = $client->getBorrowing("返却予定日:");
$shibu_res = $client->getReservation();
sortArrayByKey($shibu_res, "order");
if (count($seta_bor) >= 1) {
echo "世田谷\n";
foreach ($seta_bor as $item) {
$extend = ($item["extend"] === "可能") ? " : 延長可" : "";
echo " " . fixDateFormat($item["expiration"]) . "まで : " . $item["title"] . $extend . "\n";
}
}
if (count($chiyo_bor) >= 1) {
echo "千代田\n";
foreach ($chiyo_bor as $item) {
$extend = $item["extendable"] ? " : 延長可" : "";
echo " " . $item["expiration"] . "まで : " . $item["title"] . $extend . "\n";
}
}
if (count($shibu_bor) >= 1) {
echo "渋谷\n";
foreach ($shibu_bor as $item) {
$extend = $item["extendable"] ? " : 延長可" : "";
echo " " . $item["expiration"] . "まで : " . $item["title"] . $extend . "\n";
}
}
echo "\n";
if (count($seta_res) >= 1) {
echo "世田谷\n";
foreach ($seta_res as $item) {
if ($item["status"] === "受取可") {
echo "<strong>";
}
echo " " . $item["status"];
if ((int)$item["order"] >= 1) {
echo " : " . sprintf("%3d", $item["order"]) . "位";
}
if (strlen($item["expiration"]) > 0) {
echo " : " . fixDateFormat($item["expiration"]) . "まで";
}
echo " : " . $item["title"];
if ($item["status"] === "受取可") {
echo "</strong>";
}
echo "\n";
}
}
if (count($chiyo_res) >= 1) {
echo "千代田\n";
foreach ($chiyo_res as $item) {
if ($item["status"] === "受取可") {
echo "<strong>";
}
echo " " . $item["status"];
if (isset($item["order"])) {
echo " : " . sprintf("%3d", $item["order"]) . "位";
}
if (isset($item["expiration"])) {
echo " : " . $item["expiration"] . "まで";
}
echo " : " . $item["title"];
if ($item["status"] === "受取可") {
echo "</strong>";
}
echo "\n";
}
}
if (count($shibu_res) >= 1) {
echo "渋谷\n";
foreach ($shibu_res as $item) {
if ($item["status"] === "受取可") {
echo "<strong>";
}
echo " " . $item["status"];
if (isset($item["order"])) {
echo " : " . sprintf("%3d", $item["order"]) . "位";
}
if (isset($item["expiration"])) {
echo " : " . $item["expiration"] . "まで";
}
echo " : " . $item["title"];
if ($item["status"] === "受取可") {
echo "</strong>";
}
echo "\n";
}
}
?>
</pre>
</body>
</html>