/
class.Customize.php
118 lines (107 loc) · 3.09 KB
/
class.Customize.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
<?php
require_once($PATH_classes . '/class.DBconn.php');
/**
* customisation settings
*
* @author Alexander Rein <a.rein@be-clever-ag.de>, beclever werbeagentur AG <support@be-clever-ag.de>
* @copyright (c) 2016, Alexander Rein
*/
class Customize {
private $db = NULL;
public $error_msg = "";
public function __construct() {
$this->db = new DBconn();
if (!empty($this->db->error)) {
$this->error_msg = $this->db->error;
}
}
/**
*
* @param array $settings
* @return bool
*/
public function set_settings($settings) {
$update = array();
$values = array();
foreach ($settings as $key => $value) {
$values[$key]['key'] = $key;
$values[$key]['value'] = $value;
$this->db->addParams("s", $values[$key]['key']);
$this->db->addParams("s", $values[$key]['value']);
$update[] = "(?,?)";
}
$sql = "INSERT INTO customisation (title,value) VALUES " . implode(",", $update) . " ON DUPLICATE KEY UPDATE value=VALUES(value)";
if ($this->db->query($sql) === FALSE) {
$this->error_msg = $this->db->error;
return FALSE;
}
return TRUE;
}
/**
*
* @param string $key
* @param string $value
* @return bool
*/
public function set_option($key, $value) {
return $this->set_settings([$key => $value]);
}
/**
*
* @param string $key
* @return array
*/
public function get_settings($key = NULL) {
$sql = "SELECT * FROM customisation";
if (!empty($key)) {
$this->db->addParams("s", $key);
$sql .= " WHERE title = ?";
}
if ($this->db->query($sql) === FALSE) {
$this->error_msg = $this->db->error;
return FALSE;
} else {
if (!empty($key)) {
$return = $this->db->fetch_array_assoc();
return $return['value'];
} else {
return $this->db->fetch_all_array();
}
}
}
/**
*
* @param UPLOAD_ERR code $code
* @return string
*/
public static function uploadMessage($code)
{
switch ($code) {
case UPLOAD_ERR_INI_SIZE:
$message = "The uploaded file exceeds the upload_max_filesize directive in php.ini";
break;
case UPLOAD_ERR_FORM_SIZE:
$message = "The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form";
break;
case UPLOAD_ERR_PARTIAL:
$message = "The uploaded file was only partially uploaded";
break;
case UPLOAD_ERR_NO_FILE:
$message = "No file was uploaded";
break;
case UPLOAD_ERR_NO_TMP_DIR:
$message = "Missing a temporary folder";
break;
case UPLOAD_ERR_CANT_WRITE:
$message = "Failed to write file to disk";
break;
case UPLOAD_ERR_EXTENSION:
$message = "File upload stopped by extension";
break;
default:
$message = "Unknown upload error";
break;
}
return $message;
}
}