-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadmin.php
146 lines (137 loc) · 4.39 KB
/
admin.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
<?php
include_once ('db.php');
class plugins_stripe_admin extends plugins_stripe_db
{
/**
* @var backend_model_template $template
* @var backend_model_data $data
* @var component_core_message $message
* @var backend_controller_plugins $plugins
* @var backend_model_language $modelLanguage
* @var component_collections_language $collectionLanguage
*/
protected backend_model_template $template;
protected backend_model_data $data;
protected component_core_message $message;
protected backend_controller_plugins $plugins;
protected backend_model_language $modelLanguage;
protected component_collections_language $collectionLanguage;
/**
* @var string $action
* @var string $tabs
* @var string $type
*/
public string
$action,
$controller,
$apikey,
$endpointkey;
/**
* constructeur
*/
public function __construct(backend_model_template $t = null) {
$this->template = $t instanceof backend_model_template ? $t : new backend_model_template();
$this->plugins = new backend_controller_plugins();
$formClean = new form_inputEscape();
$this->message = new component_core_message($this->template);
$this->data = new backend_model_data($this);
// Global
if (http_request::isGet('action')) {
$this->action = $formClean->simpleClean($_GET['action']);
} elseif (http_request::isPost('action')) {
$this->action = $formClean->simpleClean($_POST['action']);
}
// POST
if (http_request::isPost('apikey')) {
$this->apikey = $formClean->simpleClean($_POST['apikey']);
}
if (http_request::isPost('endpointkey')) {
$this->endpointkey = $formClean->simpleClean($_POST['endpointkey']);
}
}
/**
* Method to override the name of the plugin in the admin menu
* @return string
*/
public function getExtensionName()
{
return $this->template->getConfigVars('stripe_plugin');
}
// --- Database actions
/**
* Assign data to the defined variable or return the data
* @param string $type
* @param string|int|null $id
* @param ?string $context
* @param string|bool $assign
* @return mixed
*/
private function getItems(string $type, $id = null, ?string $context = null, $assign = true) {
return $this->data->getItems($type, $id, $context, $assign);
}
/**
* Update data
* @param string $type
* @param array $params
*/
private function upd(string $type, array $params) {
switch ($type) {
case 'config':
parent::update($type, $params);
break;
}
}
/**
* Insert data
* @param string $type
* @param array $params
*/
private function add(string $type, array $params) {
switch ($type) {
case 'config':
parent::insert($type, $params);
break;
}
}
private function save(){
$setData = $this->getItems('root',NULL,'one',false);
if($setData['id_stripe']){
$this->upd(
'config',
[
'apikey' => $this->apikey,
'endpointkey' => $this->endpointkey,
'id' => $setData['id_stripe']
]
);
}else{
$this->add(
'config',
[
'apikey' => $this->apikey,
'endpointkey' => $this->endpointkey
]
);
}
$this->message->json_post_response(true, 'update');
}
/**
* Execute plugin
*/
public function run()
{
if (http_request::isRequest('action')) $this->action = form_inputEscape::simpleClean($_REQUEST['action']);
if(http_request::isGet('controller')) $this->controller = form_inputEscape::simpleClean($_GET['controller']);
if(http_request::isMethod('POST') && isset($this->action)) {
switch ($this->action) {
case 'edit':
$this->save();
break;
}
}else{
$data = $this->getItems('root',NULL,'one',false);
$this->template->assign('stripe', $data);
$this->template->display('index.tpl');
}
}
}