This repository has been archived by the owner on Sep 18, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vpanel.inc.php
77 lines (65 loc) · 2.59 KB
/
vpanel.inc.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
<?php
class VPanel {
private $apiurl;
private $sessionid;
private $authhash;
function __construct($apiurl) {
$this->apiurl = $apiurl;
}
function startSession($user, $apikey) {
$req1 = json_decode(file_get_contents($this->apiurl . 'api/startsession.php?username=' . urlencode($user)));
$this->sessionid = $req1->sessionid;
$this->apikey = $apikey;
$this->authhash = hash_hmac("md5", $req1->challenge, $this->apikey);
}
private function callApi($api, $data) {
$data["sessionid"] = $this->sessionid;
$data["authhash"] = $this->authhash;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $this->apiurl . 'api/' . $api);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, build_curl_array($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$ret = curl_exec($ch);
if (curl_getinfo($ch, CURLINFO_HTTP_CODE) != 200) {
throw new Exception('Verwaltungs-API liefert Fehlercode ' . curl_getinfo($ch, CURLINFO_HTTP_CODE) . ' - ' . $ret);
}
$data = json_decode($ret);
if (isset($data->result->failed)) {
throw new Exception('Verwaltungs-API liefert Fehlercode ' . $data->result->failed);
}
$this->authhash = hash_hmac("md5", $data->challenge, $this->apikey);
return $data->result;
}
function uploadDocument($dokumenttemplateid, $filename, $data = array()) {
$data["dokumenttemplateid"] = $dokumenttemplateid;
$data["file"] = "@" . $filename . ";type=application/pdf";
$this->callApi('createdokument.php', $data);
return true;
}
function getMitglied($mitgliedid) {
return $this->callApi('mitglied.php', array("mitgliedid" => $mitgliedid))->mitglied;
}
function modifyMitglied($mitgliedid, $changes) {
return $this->callApi('modifymitglied.php', array("mitgliedid" => $mitgliedid, "changes" => $changes));
}
function addMitgliedBeitragBuchung($mitgliedid, $beitragid, $timestamp, $gliederungid, $vermerk, $hoehe, $mailtemplateid = null) {
$query = array("sessionid" => $this->sessionid, "authhash" => $this->authhash, "mitgliedid" => $mitgliedid, "beitragid" => $beitragid, "timestamp" => $timestamp, "gliederungid" => $gliederungid, "vermerk" => $vermerk, "hoehe" => $hoehe);
if ($mailtemplateid !== null) {
$query["mailtemplateid"] = $mailtemplateid;
}
return $this->callApi('mitgliedbeitragbuchen.php', $query);
}
}
function build_curl_array($arr, $prefix = "", &$inarray = array()) {
foreach ($arr as $k => $v) {
$k = ($prefix == "" ? $k : $prefix . "[" . urlencode($k) . "]");
if (is_array($v)) {
build_curl_array($v, $k, $inarray);
} else {
$inarray[$k] = $v;
}
}
return $inarray;
}