-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsap_model.php
More file actions
46 lines (39 loc) · 1.29 KB
/
sap_model.php
File metadata and controls
46 lines (39 loc) · 1.29 KB
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
<?php
// no direct access
defined('EMONCMS_EXEC') or die('Restricted access');
class Sap
{
private $mysqli;
public function __construct($mysqli)
{
$this->mysqli = $mysqli;
}
public function save($userid, $docid, $data)
{
$userid = (int) $userid;
$docid = (int) $docid;
$data = preg_replace('/[^\w\s-.",:{}\[\]]/','',$data);
$data = json_decode($data);
$data = json_encode($data);
$data = $this->mysqli->real_escape_string($data);
$result = $this->mysqli->query("SELECT `docid` FROM sap WHERE `userid` = '$userid' AND `docid` = '$docid'");
$row = $result->fetch_object();
if (!$row)
{
$this->mysqli->query("INSERT INTO sap (`userid`, `docid`, `data`) VALUES ('$userid','$docid','$data')");
}
else
{
$this->mysqli->query("UPDATE sap SET `data` = '$data' WHERE `userid` = '$userid' AND `docid` = '$docid'");
}
}
public function get($userid,$docid)
{
$userid = (int) $userid;
$docid = (int) $docid;
$result = $this->mysqli->query("SELECT `data` FROM sap WHERE `userid` = '$userid' AND `docid` = '$docid'");
$row = $result->fetch_array();
if ($row) return $row['data']; else return '0';
}
}
?>