File: /home/retile.ru/public_html/admin/controller/extension/module/attachmanager.php
<?php
class ControllerExtensionModuleAttachManager extends Controller {
private $error = array();
public function index() {
$this->load->language('extension/module/attachmanager');
$this->document->setTitle($this->language->get('heading_title1'));
$this->load->model('setting/setting');
$this->load->model('setting/module');
if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
$this->request->post['attachmanager']['filetype'] = strtolower($this->request->post['attachmanager']['filetype']);
$this->model_setting_setting->editSetting('attachmanager', $this->request->post);
if(isset($this->request->post['attachmanager_status'])){
$module_attachmanager_status = $this->request->post['attachmanager_status'];
}else{
$module_attachmanager_status = "0";
}
$this->model_setting_setting->editSetting('module_', array('module_attachmanager_status' => $module_attachmanager_status), $this->request->post);
$this->session->data['success'] = $this->language->get('text_success');
$this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true));
}
if (isset($this->request->post['attachmanager'])) {
$data['attachmanager'] = $this->request->post['attachmanager'];
} else {
$data['attachmanager'] = $this->config->get('attachmanager');
}
if (isset($this->error['warning'])) {
$data['error_warning'] = $this->error['warning'];
} else {
$data['error_warning'] = '';
}
if (isset($this->session->data['success'])) {
$data['success'] = $this->session->data['success'];
unset($this->session->data['success']);
} else {
$data['success'] = '';
}
if (isset($this->request->post['attachmanager_status'])) {
$data['attachmanager_status'] = $this->request->post['attachmanager_status'];
} else {
$data['attachmanager_status'] = $this->config->get('attachmanager_status');
}
$data['breadcrumbs'] = array();
$data['breadcrumbs'][] = array(
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true)
);
$data['breadcrumbs'][] = array(
'text' => $this->language->get('text_extension'),
'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true)
);
if (!isset($this->request->get['module_id'])) {
$data['breadcrumbs'][] = array(
'text' => $this->language->get('heading_title'),
'href' => $this->url->link('extension/module/attachmanager', 'user_token=' . $this->session->data['user_token'], true)
);
} else {
$data['breadcrumbs'][] = array(
'text' => $this->language->get('heading_title'),
'href' => $this->url->link('extension/module/attachmanager', 'user_token=' . $this->session->data['user_token'] . '&module_id=' . $this->request->get['module_id'], true)
);
}
if (!isset($this->request->get['module_id'])) {
$data['action'] = $this->url->link('extension/module/attachmanager', 'user_token=' . $this->session->data['user_token'], true);
} else {
$data['action'] = $this->url->link('extension/module/attachmanager', 'user_token=' . $this->session->data['user_token'] . '&module_id=' . $this->request->get['module_id'], true);
}
$data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true);
if (isset($this->request->get['module_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) {
$module_info = $this->model_setting_module->getModule($this->request->get['module_id']);
}
$data['user_token'] = $this->session->data['user_token'];
$this->load->model('localisation/language');
$data['languages'] = $this->model_localisation_language->getLanguages();
$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/module/attachmanager', $data));
}
public function integrateproduct() {
$output = array();
$output['tab_title'] = null;
$output['tab_content'] = null;
if ($this->config->get('attachmanager_status')) {
$this->load->model('tool/image');
$this->document->addScript('view/javascript/attachmanager.js');
$this->load->language('extension/module/attachmanager');
$data['text_attach_file_product_thumb'] = $this->language->get('text_attach_file_product_thumb');
$data['text_attach_file_product_name'] = $this->language->get('text_attach_file_product_name');
$data['text_attach_file_product_count'] = $this->language->get('text_attach_file_product_count');
$data['text_attach_file_product_login'] = $this->language->get('text_attach_file_product_login');
$data['button_add_attach_file_product'] = $this->language->get('button_add_attach_file_product');
$data['button_add_attach_exten_link'] = $this->language->get('button_add_attach_exten_link');
$data['tab_attach_internal'] = $this->language->get('tab_attach_internal');
$data['tab_attach_external'] = $this->language->get('tab_attach_external');
$data['text_attach_extend_link_name'] = $this->language->get('text_attach_extend_link_name');
$data['text_attach_extend_link_download'] = $this->language->get('text_attach_extend_link_download');
$data['button_config_attachments'] = $this->language->get('button_config_attachments');
$data['button_remove'] = $this->language->get('button_remove');
$attach_info = $this->config->get('attachmanager');
$data['attach_info_config'] = $attach_info;
$filetype = explode(',', $attach_info['filetype']);
$data['no_image'] = $this->model_tool_image->resize('no_image.png', 100, 100);
$data['exten_links'] = array();
$data['user_token'] = $this->session->data['user_token'];
if (isset($this->request->post['exten_link'])) {
$data['exten_links'] = $this->request->post['exten_link'];
} elseif (isset($this->request->get['product_id'])) {
$data['exten_links'] = $this->model_catalog_product->getLinkdownload($this->request->get['product_id']);
}
if (isset($this->request->post['product_attach'])) {
$product_attachs = $this->request->post['product_attach'];
} elseif (isset($this->request->get['product_id'])) {
$product_attachs = $this->model_catalog_product->getProductattachmanager($this->request->get['product_id']);
$data['exten_links'] = $this->model_catalog_product->getLinkdownload($this->request->get['product_id']);
} else {
$product_attachs = array();
}
$data['product_attachs'] = array();
$mmos_images_type = array('jpg', 'jpeg', 'gif', 'png');
foreach ($product_attachs as $product_attach) {
if (file_exists(DIR_IMAGE . '' . $product_attach['filename'])) {
$exten = strtolower(substr($product_attach['filename'], strrpos($product_attach['filename'], '.') + 1));
if (in_array($exten, $filetype)) {
if (in_array($exten, $mmos_images_type)) {
$thumb = $this->model_tool_image->resize($product_attach['filename'], 100, 100);
} else {
$thumb = $this->model_tool_image->resize('attached_icon/' . $exten . '.png', 100, 100);
}
} else {
$thumb = $this->model_tool_image->resize('attached_icon/default.png', 100, 100);
}
if (empty($product_attach['login_required'])) {
$product_attach['login_required'] = '';
}
if (empty($product_attach['download'])) {
$product_attach['download'] = '';
}
$data['product_attachs'][] = array(
'thumb' => $thumb,
'filename' => $product_attach['filename'],
'mask' => $product_attach['mask'],
'ext' => $exten,
'login_required' => $product_attach['login_required'],
'download' => $product_attach['download']
);
}
}
$output['tab_title'] = html_entity_decode($attach_info['tab_name'][$this->config->get('config_language_id')]);
$output['tab_content'] = $this->load->view('extension/module/attachmanager_include', $data);
}
return $output;
}
private function validate() {
if (!$this->user->hasPermission('modify', 'extension/module/attachmanager')) {
$this->error['warning'] = $this->language->get('error_permission');
}
return !$this->error;
}
public function uninstall() {
if ($this->user->hasPermission('modify', 'extension/extension/module')) {
$this->load->model('setting/setting');
$this->load->model('catalog/attachmanager');
$this->model_setting_setting->deleteSetting('attachmanager');
$this->model_catalog_attachmanager->uninstall();
}
}
public function install() {
if ($this->user->hasPermission('modify', 'extension/extension/module')) {
// add user permission
$this->load->model('catalog/attachmanager');
$this->load->model('setting/setting');
$this->load->model('localisation/language');
$this->model_catalog_attachmanager->install();
$typefile = 'dat,7z,arj,audio,avi,bat,bin,bmp,dll,doc,document,file,gif,hlp,htm,html,image,iso,jar,jpeg,jpg,mov,mp3,mpeg,pdf,png,ppt,psd,rar,rpm,software,swf,tar,tif,tiff,txt,video,wav,wma,wmv,xls,zip';
$languages = $this->model_localisation_language->getLanguages();
$name_document = array();
foreach ($languages as $language) {
$name_document[$language['language_id']] = "<i class='fa fa-download'></i> Файлы";
}
$initial = array(
'attachmanager' => array(
'status' => 0,
'extendlink' => 0,
'show_download' => 1,
'name_download' => 1,
'maxfilesize' => 80,
'filetype' => $typefile,
'tab_name' => $name_document
)
);
$this->model_setting_setting->editSetting('attachmanager', $initial);
$this->load->model('user/user_group');
$this->model_user_user_group->addPermission($this->user->getGroupId(), 'access', 'common/attachmanager');
$this->model_user_user_group->addPermission($this->user->getGroupId(), 'modify', 'common/attachmanager');
}
}
}
?>