<?php 
class ControllerToolBatch extends Controller { 
	private $error = array();
	
	public function index() {		
		$this->load->language('tool/batch');

		$this->document->title = $this->language->get('heading_title');
		
		if ($this->request->server['REQUEST_METHOD'] == 'POST' && $this->validate()) {
			if (is_uploaded_file($this->request->files['import']['tmp_name'])) {
				$file = $this->request->files['import']['tmp_name'];
				$zip = new ZipArchive();
				$rs = $zip->open($file);
				if($rs){
//					$fd=explode(".",basename($filepath));
					$zip->extractTo(DIR_IMAGE.'data/');
					$zip->close();
					$this->session->data['success'] = $this->language->get('text_success');
				}
			} 
			
			
		}

		$this->data['heading_title'] = $this->language->get('heading_title');
		
		$this->data['text_select_all'] = $this->language->get('text_select_all');
		$this->data['text_unselect_all'] = $this->language->get('text_unselect_all');
		
		$this->data['entry_upload_file'] = $this->language->get('entry_upload_file');
		
		 
		$this->data['button_upload'] = $this->language->get('button_upload');
		
		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->document->breadcrumbs = array();

   		$this->document->breadcrumbs[] = array(
       		'href'      => HTTPS_SERVER . 'index.php?route=common/home&token=' . $this->session->data['token'],
       		'text'      => $this->language->get('text_home'),
      		'separator' => FALSE
   		);

   		$this->document->breadcrumbs[] = array(
       		'href'      => HTTPS_SERVER . 'index.php?route=tool/batch&token=' . $this->session->data['token'],
       		'text'      => $this->language->get('heading_title'),
      		'separator' => ' :: '
   		);
		
		$this->data['upload'] = HTTPS_SERVER . 'index.php?route=tool/batch&token=' . $this->session->data['token'];

	


		
		$this->template = 'tool/batch.tpl';
		$this->children = array(
			'common/header',	
			'common/footer'	
		);
		
		$this->response->setOutput($this->render(TRUE), $this->config->get('config_compression'));
	}
	
	
	private function validate() {
		if (!$this->user->hasPermission('modify', 'tool/batch')) {
			$this->error['warning'] = $this->language->get('error_permission');
		}
		
		if (!$this->error) {
			return TRUE;
		} else {
			return FALSE;
		}		
	}
}
?>