| 1: | <?php
|
| 2: | namespace Opencart\Admin\Controller\Extension\Opencart\Module;
|
| 3: | |
| 4: | |
| 5: | |
| 6: | |
| 7: |
|
| 8: | class HTML extends \Opencart\System\Engine\Controller {
|
| 9: | |
| 10: | |
| 11: | |
| 12: | |
| 13: |
|
| 14: | public function index(): void {
|
| 15: | $this->load->language('extension/opencart/module/html');
|
| 16: |
|
| 17: | $this->document->setTitle($this->language->get('heading_title'));
|
| 18: |
|
| 19: | $this->document->addScript('view/javascript/ckeditor/ckeditor.js');
|
| 20: | $this->document->addScript('view/javascript/ckeditor/adapters/jquery.js');
|
| 21: |
|
| 22: | $data['breadcrumbs'] = [];
|
| 23: |
|
| 24: | $data['breadcrumbs'][] = [
|
| 25: | 'text' => $this->language->get('text_home'),
|
| 26: | 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
|
| 27: | ];
|
| 28: |
|
| 29: | $data['breadcrumbs'][] = [
|
| 30: | 'text' => $this->language->get('text_extension'),
|
| 31: | 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module')
|
| 32: | ];
|
| 33: |
|
| 34: | if (!isset($this->request->get['module_id'])) {
|
| 35: | $data['breadcrumbs'][] = [
|
| 36: | 'text' => $this->language->get('heading_title'),
|
| 37: | 'href' => $this->url->link('extension/opencart/module/html', 'user_token=' . $this->session->data['user_token'])
|
| 38: | ];
|
| 39: | } else {
|
| 40: | $data['breadcrumbs'][] = [
|
| 41: | 'text' => $this->language->get('heading_title'),
|
| 42: | 'href' => $this->url->link('extension/opencart/module/html', 'user_token=' . $this->session->data['user_token'] . '&module_id=' . $this->request->get['module_id'])
|
| 43: | ];
|
| 44: | }
|
| 45: |
|
| 46: | if (!isset($this->request->get['module_id'])) {
|
| 47: | $data['save'] = $this->url->link('extension/opencart/module/html.save', 'user_token=' . $this->session->data['user_token']);
|
| 48: | } else {
|
| 49: | $data['save'] = $this->url->link('extension/opencart/module/html.save', 'user_token=' . $this->session->data['user_token'] . '&module_id=' . $this->request->get['module_id']);
|
| 50: | }
|
| 51: |
|
| 52: | $data['back'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module');
|
| 53: |
|
| 54: | if (isset($this->request->get['module_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) {
|
| 55: | $this->load->model('setting/module');
|
| 56: |
|
| 57: | $module_info = $this->model_setting_module->getModule($this->request->get['module_id']);
|
| 58: | }
|
| 59: |
|
| 60: | if (isset($module_info['name'])) {
|
| 61: | $data['name'] = $module_info['name'];
|
| 62: | } else {
|
| 63: | $data['name'] = '';
|
| 64: | }
|
| 65: |
|
| 66: | if (isset($module_info['module_description'])) {
|
| 67: | $data['module_description'] = $module_info['module_description'];
|
| 68: | } else {
|
| 69: | $data['module_description'] = [];
|
| 70: | }
|
| 71: |
|
| 72: | $this->load->model('localisation/language');
|
| 73: |
|
| 74: | $data['languages'] = $this->model_localisation_language->getLanguages();
|
| 75: |
|
| 76: | if (isset($module_info['status'])) {
|
| 77: | $data['status'] = $module_info['status'];
|
| 78: | } else {
|
| 79: | $data['status'] = '';
|
| 80: | }
|
| 81: |
|
| 82: | if (isset($this->request->get['module_id'])) {
|
| 83: | $data['module_id'] = (int)$this->request->get['module_id'];
|
| 84: | } else {
|
| 85: | $data['module_id'] = 0;
|
| 86: | }
|
| 87: |
|
| 88: | $data['header'] = $this->load->controller('common/header');
|
| 89: | $data['column_left'] = $this->load->controller('common/column_left');
|
| 90: | $data['footer'] = $this->load->controller('common/footer');
|
| 91: |
|
| 92: | $this->response->setOutput($this->load->view('extension/opencart/module/html', $data));
|
| 93: | }
|
| 94: |
|
| 95: | |
| 96: | |
| 97: | |
| 98: | |
| 99: |
|
| 100: | public function save(): void {
|
| 101: | $this->load->language('extension/opencart/module/html');
|
| 102: |
|
| 103: | $json = [];
|
| 104: |
|
| 105: | if (!$this->user->hasPermission('modify', 'extension/opencart/module/html')) {
|
| 106: | $json['error']['warning'] = $this->language->get('error_permission');
|
| 107: | }
|
| 108: |
|
| 109: | if ((oc_strlen($this->request->post['name']) < 3) || (oc_strlen($this->request->post['name']) > 64)) {
|
| 110: | $json['error']['name'] = $this->language->get('error_name');
|
| 111: | }
|
| 112: |
|
| 113: | if (!$json) {
|
| 114: | $this->load->model('setting/module');
|
| 115: |
|
| 116: | if (!$this->request->post['module_id']) {
|
| 117: | $json['module_id'] = $this->model_setting_module->addModule('opencart.html', $this->request->post);
|
| 118: | } else {
|
| 119: | $this->model_setting_module->editModule($this->request->post['module_id'], $this->request->post);
|
| 120: | }
|
| 121: |
|
| 122: | $json['success'] = $this->language->get('text_success');
|
| 123: | }
|
| 124: |
|
| 125: | $this->response->addHeader('Content-Type: application/json');
|
| 126: | $this->response->setOutput(json_encode($json));
|
| 127: | }
|
| 128: | }
|
| 129: | |