forked from howest-wsde/owaes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass.reports.php
158 lines (139 loc) · 5.07 KB
/
class.reports.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
<?php
class reports {
private $arReports = NULL;
public function reports() {
}
public function getList() {
if (is_null($this->arReports)) {
$arReports = array();
$oDB = new database();
$oDB->execute("select * from tblAbuse order by id desc; ");
while ($oDB->nextRecord()) {
$oReport = new report();
$oReport->loadRecord($oDB->record());
$arReports[] = $oReport;
}
$this->arReports = $arReports;
}
return $this->arReports;
}
public function __toArray() {
return $this->getList();
}
}
class report {
private $iID = 0;
private $iReporter = NULL;
private $iCreated = NULL;
private $iUser = NULL;
private $iMarket = NULL;
private $strReason = NULL;
private $arData = NULL;
public function report($strReason = NULL) {
if (!is_null($strReason)) $this->reason($strReason);
$this->iCreated = owaestime();
$this->reporter(me());
}
public function data($strKey = NULL, $strValue = NULL) {
if (is_null($this->arData)) $this->arData = array();
if (!is_null($strKey)) {
if (!is_null($strValue)) $this->arData[$strKey] = $strValue;
return isset($this->arData[$strKey]) ? $this->arData[$strKey] : FALSE;
} else {
return $this->arData;
}
}
public function user($iUser = NULL) {
if (!is_null($iUser)) $this->iUser = $iUser;
return $this->iUser;
}
public function timestamp() {
return $this->iCreated;
}
public function market($iMarket = NULL) {
if (!is_null($iMarket)) $this->iMarket = $iMarket;
return $this->iMarket;
}
public function reason($strReason = NULL) {
if (!is_null($strReason)) $this->strReason = $strReason;
return $this->strReason;
}
public function reporter($iReporter = NULL) {
if (!is_null($iReporter)) $this->iReporter = $iReporter;
return $this->iReporter;
}
public function loadRecord($oRecord) {
$this->iID = $oRecord["id"];
$this->iReporter = $oRecord["reporter"];
$this->strReason = $oRecord["reason"];
$this->iUser = $oRecord["user"];
$this->iMarket = $oRecord["market"];
$this->iCreated = $oRecord["created"];
$this->arData = json_decode($oRecord["data"], TRUE);
}
public function update() {
$arVelden = array(
"created" => $this->iCreated,
);
if (!is_null($this->iReporter)) $arVelden["reporter"] = $this->iReporter;
if (!is_null($this->iUser)) $arVelden["user"] = $this->iUser;
if (!is_null($this->strReason)) $arVelden["reason"] = $this->strReason;
if (!is_null($this->iMarket)) $arVelden["market"] = $this->iMarket;
if (!is_null($this->iCreated)) $arVelden["created"] = $this->iCreated;
if (!is_null($this->arData)) $arVelden["data"] = json_encode($this->arData);
$oDB = new database();
if ($this->iID == 0) {
$arFields = array();
$arValues = array();
foreach ($arVelden as $strField=>$strValue) {
$arFields[] = $strField;
$arValues[] = "'" . $oDB->escape($strValue) . "'";
}
$oDB->sql("insert into tblAbuse (" . implode(",", $arFields) . ") values (" . implode(",", $arValues) . "); ");
$oDB->execute();
$this->iID = $oDB->lastInsertID();
$iUser = (is_null($this->user())||$this->user()==0) ? ((is_null($this->market())||$this->market()==0) ? 0 : owaesitem($this->market())->author()->id()) : $this->user(); // bron van alle onheil
if ($iUser != 0){
foreach (user($iUser)->groups() as $oGroup){
$oMessage = new message();
$oMessage->sender(0);
$oMessage->receiver($iUser);
$oMessage->body("Er werd misbruik gemeld over onderstaande: ");
if (!is_null($this->market())) $oMessage->data("market", $this->market());
$oMessage->data("user", $iUser);
$oMessage->data("info", $this->reason());
$oMessage->data("reporter", me());
$oMessage->update();
}
}
$arAdmins = new userlist();
$arAdmins->filter("admin");
foreach ($arAdmins->getList() as $oAdmin) {
$oMessage = new message();
$oMessage->sender(0);
$oMessage->receiver($oAdmin->id());
$oMessage->body("Er werd misbruik gemeld over onderstaande ");
if (!is_null($this->market())) $oMessage->data("market", $this->market());
$oMessage->data("user", $iUser);
$oMessage->data("info", $this->reason());
$oMessage->data("reporter", me());
$oMessage->update();
}
$oMessage = new message();
$oMessage->sender(0);
$oMessage->receiver($iUser);
$oMessage->body("Onderstaand misbruik werd doorgestuurd");
if (!is_null($this->market())) $oMessage->data("market", $this->market());
if (!is_null($this->user())) $oMessage->data("user", $this->user());
$oMessage->data("info", $this->reason());
$oMessage->update();
} else {
$arUpdates = array();
foreach ($arVelden as $strField=>$strValue) {
$arUpdates[] = $strField . " = '" . $oDB->escape($strValue) . "'";
}
$oDB->sql("update tblAbuse set " . implode(",", $arUpdates) . " where id = " . $this->iID . ";");
$oDB->execute();
}
}
}