forked from naaber/php-ruhmatoo-projekt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
edit.class.php
67 lines (49 loc) · 2.13 KB
/
edit.class.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
<?php
require_once("functions.php");
class Edit {
//private- klassi sees
private $connection;
//klassi loomisel (new User)
function __construct($mysqli){
$this->connection = $mysqli;
}
function getPacketData($id){
$mysqli = new mysqli($GLOBALS["servername"], $GLOBALS["server_username"], $GLOBALS["server_password"], $GLOBALS["database"]);
$stmt = $mysqli->prepare("SELECT arrival, departure, fromc, comment, office_id FROM post_import WHERE deleted IS NULL AND packet_id = ?");
$stmt->bind_param("i", $id);
$stmt->bind_result($arrival, $departure, $fromc, $comment, $office_id);
$stmt->execute();
$packet_array = array();
while($stmt->fetch()){
$packet = new StdClass();
$packet->arrival = $arrival;
$packet->departure = $departure;
$packet->fromc = $fromc;
$packet->comment = $comment;
$packet->office_id = $office_id;
array_push($packet_array, $packet);
}
$stmt->close();
return $packet_array;
}
function updatePacket($office, $arrival, $departure, $fromc, $comment, $office_id, $packet_id){
$offices = array("peakontor", "kopli", "kristiine", "lasna", "mustamae", "nomme", "oismae", "pirita");
if (!in_array($office, $offices)) {
die("Ära üritagi häkkida");
}
if($office == "peakontor"){
$mysqli = new mysqli($GLOBALS["servername"], $GLOBALS["server_username"], $GLOBALS["server_password"], $GLOBALS["database"]);
$stmt = $mysqli->prepare("UPDATE post_import SET arrival=?, departure=?, fromc=?, comment=?, office_id=? WHERE packet_id = ? AND deleted IS NULL");
$stmt->bind_param("iissii", $arrival, $departure, $fromc, $comment, $office_id, $packet_id);
$stmt->execute();
$stmt->close();
}else{
$mysqli = new mysqli($GLOBALS["servername"], $GLOBALS["server_username"], $GLOBALS["server_password"], $GLOBALS["database"]);
$stmt = $mysqli->prepare("UPDATE ".$office." SET arrival=?, departure=?, comment=? WHERE packet_id = ? AND deleted IS NULL");
$stmt->bind_param("iisi", $arrival, $departure, $comment, $packet_id);
$stmt->execute();
$stmt->close();
}
}
}
?>