<?php
class ControllerExtensionOpenbay extends Controller {
private $error = array();
public function install() {
$this->load->language('extension/openbay');
$this->load->model('extension/extension');
if (!$this->user->hasPermission('modify', 'extension/openbay')) {
$this->session->data['error'] = $this->language->get('error_permission');
$this->response->redirect($this->url->link('extension/openbay', 'token=' . $this->session->data['token'], true));
} else {
$this->model_extension_extension->install('openbay', $this->request->get['extension']);
$this->session->data['success'] = $this->language->get('text_install_success');
$this->load->model('user/user_group');
$this->model_user_user_group->addPermission($this->user->getGroupId(), 'access', 'extension/openbay/' . $this->request->get['extension']);
$this->model_user_user_group->addPermission($this->user->getGroupId(), 'modify', 'extension/openbay/' . $this->request->get['extension']);
require_once(DIR_APPLICATION . 'controller/extension/openbay/' . $this->request->get['extension'] . '.php');
$class = 'ControllerExtensionOpenbay' . str_replace('_', '', $this->request->get['extension']);
$class = new $class($this->registry);
if (method_exists($class, 'install')) {
$class->install();
}
$this->response->redirect($this->url->link('extension/openbay', 'token=' . $this->session->data['token'], true));
}
}
public function uninstall() {
$this->load->language('extension/openbay');
$this->load->model('extension/extension');
if (!$this->user->hasPermission('modify', 'extension/openbay')) {
$this->session->data['error'] = $this->language->get('error_permission');
$this->response->redirect($this->url->link('extension/openbay', 'token=' . $this->session->data['token'], true));
} else {
$this->session->data['success'] = $this->language->get('text_uninstall_success');
require_once(DIR_APPLICATION . 'controller/extension/openbay/' . $this->request->get['extension'] . '.php');
$this->load->model('extension/extension');
$this->load->model('setting/setting');
$this->model_extension_extension->uninstall('openbay', $this->request->get['extension']);
$this->model_setting_setting->deleteSetting($this->request->get['extension']);
$class = 'ControllerExtensionOpenbay' . str_replace('_', '', $this->request->get['extension']);
$class = new $class($this->registry);
if (method_exists($class, 'uninstall')) {
$class->uninstall();
}
$this->response->redirect($this->url->link('extension/openbay', 'token=' . $this->session->data['token'], true));
}
}
public function index() {
$this->load->model('extension/openbay/openbay');
$this->load->model('extension/extension');
$this->load->model('setting/setting');
$this->load->model('extension/openbay/version');
$this->load->language('extension/openbay');
$data = $this->language->all();
$this->document->setTitle($this->language->get('heading_title'));
$this->document->addScript('view/javascript/openbay/js/faq.js');
$data['breadcrumbs'] = array();
$data['breadcrumbs'][] = array(
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/dashboard', 'token=' . $this->session->data['token'], true),
);
$data['breadcrumbs'][] = array(
'text' => $this->language->get('heading_title'),
'href' => $this->url->link('extension/openbay', 'token=' . $this->session->data['token'], true),
);
$data['manage_link'] = $this->url->link('extension/openbay/manage', 'token=' . $this->session->data['token'], true);
$data['product_link'] = $this->url->link('extension/openbay/items', 'token=' . $this->session->data['token'], true);
$data['order_link'] = $this->url->link('extension/openbay/orderlist', 'token=' . $this->session->data['token'], true);
$data['success'] = '';
if (isset($this->session->data['success'])) {
$data['success'] = $this->session->data['success'];
unset($this->session->data['success']);
}
$data['error'] = $this->model_extension_openbay_openbay->requirementTest();
if (isset($this->session->data['error'])) {
$data['error'][] = $this->session->data['error'];
unset($this->session->data['error']);
}
$extensions = $this->model_extension_extension->getInstalled('openbay');
foreach ($extensions as $key => $value) {
if (!file_exists(DIR_APPLICATION . 'controller/extension/openbay/' . $value . '.php')) {
$this->model_extension_extension->uninstall('openbay', $value);
unset($extensions[$key]);
}
}
$data['extensions'] = array();
$markets = array('ebay', 'etsy', 'amazon', 'amazonus', 'fba');
foreach ($markets as $market) {
$extension = basename($market, '.php');
$this->load->language('extension/openbay/' . $extension);
$data['extensions'][] = array(
'name' => $this->language->get('heading_title'),
'edit' => $this->url->link('extension/openbay/' . $extension . '', 'token=' . $this->session->data['token'], true),
'status' => ($this->config->get('openbay_' . $extension . '_status') || $this->config->get($extension . '_status')) ? $this->language->get('text_enabled') : $this->language->get('text_disabled'),
'install' => $this->url->link('extension/openbay/install', 'token=' . $this->session->data['token'] . '&extension=' . $extension, true),
'uninstall' => $this->url->link('extension/openbay/uninstall', 'token=' . $this->session->data['token'] . '&extension=' . $extension, true),
'installed' => in_array($extension, $extensions),
'code' => $extension
);
}
$settings = $this->model_setting_setting->getSetting('openbay');
if (isset($settings['openbay_version'])) {
$data['openbay_version'] = $settings['openbay_version'];
} else {
$data['openbay_version'] = $this->model_extension_openbay_version->version();
$settings['openbay_version'] = $this->model_extension_openbay_version->version();
$this->model_setting_setting->editSetting('openbay', $settings);
}
$data['token'] = $this->session->data['token'];
$data['header'] = $this->load->controller('common/header');
$data['column_left'] = $this->load->controller('common/column_left');
$data['footer'] = $this->load->controller('common/footer');
$this->response->setOutput($this->load->view('extension/openbay', $data));
}
public function manage() {
$this->load->model('setting/setting');
$this->load->language('extension/openbay');
$data = $this->language->all();
$this->document->setTitle($this->language->get('text_manage'));
$this->document->addScript('view/javascript/openbay/js/faq.js');
$data['breadcrumbs'] = array();
$data['breadcrumbs'][] = array(
'href' => $this->url->link('common/dashboard', 'token=' . $this->session->data['token'], true),
'text' => $this->language->get('text_home'),
);
$data['breadcrumbs'][] = array(
'href' => $this->url->link('extension/openbay', 'token=' . $this->session->data['token'], true),
'text' => $this->language->get('heading_title'),
);
$data['breadcrumbs'][] = array(
'href' => $this->url->link('extension/openbay/manage', 'token=' . $this->session->data['token'], true),
'text' => $this->language->get('text_manage'),
);
if ($this->request->server['REQUEST_METHOD'] == 'POST') {
$this->model_setting_setting->editSetting('openbay', $this->request->post);
$this->session->data['success'] = $this->language->get('text_success');
$this->response->redirect($this->url->link('extension/openbay', 'token=' . $this->session->data['token'], true));
}
if (isset($this->request->post['openbay_version'])) {
$data['openbay_version'] = $this->request->post['openbay_version'];
} else {
$settings = $this->model_setting_setting->getSetting('openbay');
if (isset($s