Current Path : /var/www/alh/admin/controller/tool/ |
Current File : /var/www/alh/admin/controller/tool/export.php |
<?php class ControllerToolExport extends Controller { private $error = array(); public function index() { $this->load->language('tool/export'); $this->document->setTitle($this->language->get('heading_title')); $this->load->model('tool/export'); if (($this->request->server['REQUEST_METHOD'] == 'POST') && ($this->validate())) { if ((isset( $this->request->files['upload'] )) && (is_uploaded_file($this->request->files['upload']['tmp_name']))) { $file = $this->request->files['upload']['tmp_name']; if ($this->model_tool_export->upload($file)===TRUE) { $this->session->data['success'] = $this->language->get('text_success'); $this->redirect($this->url->link('tool/export', 'token=' . $this->session->data['token'], 'SSL')); } else { $this->error['warning'] = $this->language->get('error_upload'); } } } if (!empty($this->session->data['export_error']['errstr'])) { $this->error['warning'] = $this->session->data['export_error']['errstr']; if (!empty($this->session->data['export_nochange'])) { $this->error['warning'] .= '<br />'.$this->language->get( 'text_nochange' ); } $this->error['warning'] .= '<br />'.$this->language->get( 'text_log_details' ); } unset($this->session->data['export_error']); unset($this->session->data['export_nochange']); $this->data['heading_title'] = $this->language->get('heading_title'); $this->data['entry_restore'] = $this->language->get('entry_restore'); $this->data['entry_description'] = $this->language->get('entry_description'); $this->data['button_import'] = $this->language->get('button_import'); $this->data['button_export'] = $this->language->get('button_export'); $this->data['tab_general'] = $this->language->get('tab_general'); $this->data['error_select_file'] = $this->language->get('error_select_file'); $this->data['error_post_max_size'] = str_replace( '%1', ini_get('post_max_size'), $this->language->get('error_post_max_size') ); $this->data['error_upload_max_filesize'] = str_replace( '%1', ini_get('upload_max_filesize'), $this->language->get('error_upload_max_filesize') ); if (isset($this->error['warning'])) { $this->data['error_warning'] = $this->error['warning']; } else { $this->data['error_warning'] = ''; } if (isset($this->session->data['success'])) { $this->data['success'] = $this->session->data['success']; unset($this->session->data['success']); } else { $this->data['success'] = ''; } $this->data['breadcrumbs'] = array(); $this->data['breadcrumbs'][] = array( 'text' => $this->language->get('text_home'), 'href' => $this->url->link('common/home', 'token=' . $this->session->data['token'], 'SSL'), 'separator' => FALSE ); $this->data['breadcrumbs'][] = array( 'text' => $this->language->get('heading_title'), 'href' => $this->url->link('tool/export', 'token=' . $this->session->data['token'], 'SSL'), 'separator' => ' :: ' ); $this->data['action'] = $this->url->link('tool/export', 'token=' . $this->session->data['token'], 'SSL'); $this->data['export'] = $this->url->link('tool/export/download', 'token=' . $this->session->data['token'], 'SSL'); $this->data['post_max_size'] = $this->return_bytes( ini_get('post_max_size') ); $this->data['upload_max_filesize'] = $this->return_bytes( ini_get('upload_max_filesize') ); $this->template = 'tool/export.tpl'; $this->children = array( 'common/header', 'common/footer', ); $this->response->setOutput($this->render()); } function return_bytes($val) { $val = trim($val); switch (strtolower(substr($val, -1))) { case 'm': $val = (int)substr($val, 0, -1) * 1048576; break; case 'k': $val = (int)substr($val, 0, -1) * 1024; break; case 'g': $val = (int)substr($val, 0, -1) * 1073741824; break; case 'b': switch (strtolower(substr($val, -2, 1))) { case 'm': $val = (int)substr($val, 0, -2) * 1048576; break; case 'k': $val = (int)substr($val, 0, -2) * 1024; break; case 'g': $val = (int)substr($val, 0, -2) * 1073741824; break; default : break; } break; default: break; } return $val; } public function download() { if ($this->validate()) { // send the categories, products and options as a spreadsheet file $this->load->model('tool/export'); $this->model_tool_export->download(); $this->redirect( $this->url->link( 'tool/export', 'token='.$this->request->get['token'], 'SSL' ) ); } else { // return a permission error page return $this->forward('error/permission'); } } private function validate() { if (!$this->user->hasPermission('modify', 'tool/export')) { $this->error['warning'] = $this->language->get('error_permission'); } if (!$this->error) { return TRUE; } else { return FALSE; } } } ?>