language->load('module/showroom'); $this->data['heading_title'] = $this->language->get('heading_title'); $print = (isset($_GET['print']) && $_GET['print'] == 1) ? true : false; $this->load->model('catalog/showroom'); # if (isset($_SESSION['customer_id']) && (int)$_SESSION['customer_id'] > 0){ $this->setShowroomId(); $this->data['showroom_data'] = $this->model_catalog_showroom->load($this->getShowroomId()); $this->data['showroom_data']['path_to_showroom_image'] = $this->getPathToShowroomImage(); $template = ($print == true) ? 'print_showroom' : 'showroom'; # } # else{ # $template = 'no_showroom'; #} $this->data['breadcrumbs'] = array(); $this->data['breadcrumbs'][] = array( 'text' => $this->language->get('text_home'), 'href' => $this->url->link('common/home'), 'separator' => false ); $this->data['breadcrumbs'][] = array( 'text' => $this->language->get('text_showroom'), 'href' => $this->url->link('modules/showroom'), 'separator' => '>>' ); # var_dump($template); if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/module/showroom.tpl')) { $this->template = $this->config->get('config_template') . '/template/module/'.$template.'.tpl'; } else { $this->template = 'default/template/module/'.$template.'.tpl'; } $this->children = array( 'common/column_left', 'common/column_right', 'common/content_top', 'common/content_bottom', 'common/footer', 'common/header' ); # var_dump($_SESSION); $this->response->setOutput($this->render()); } function setShowroomId(){ $this->load->model('catalog/showroom'); if (isset($_SESSION['customer_id']) && (int)$_SESSION['customer_id'] > 0){ $showroom_id = $this->model_catalog_showroom->getShowroomIdByCustomerId($_SESSION['customer_id']); } else{ $showroom_id = $this->model_catalog_showroom->getShowroomIdBySessionId(); } $_SESSION['showroom_id'] = $showroom_id; return $showroom_id; } function getShowroomId(){ $showroom_id = (isset($_SESSION['showroom_id'])) ? $_SESSION['showroom_id'] : null; return $showroom_id; } function addProductToShowroom(){ $this->setShowroomId(); $this->load->model('catalog/showroom'); $quantity = (isset($_POST['quantity'])) ? (int)$_POST['quantity'] : 1; var_dump($this->getShowroomId()); for($i = 1; $i <= $quantity; $i++){ $this->model_catalog_showroom->addProduct($this->getShowroomId(), $_POST); } if (isset($_POST['ajax']) && $_POST['ajax'] == true){ } else{ header('location:index.php?route=module/showroom'); } exit; } function add(){ $this->load->model('catalog/showroom'); echo json_encode($this->model_catalog_showroom->addProduct($this->getShowroomId(), $_POST)); exit; } function delete(){ $this->load->model('catalog/showroom'); $this->model_catalog_showroom->deleteProduct($this->getShowroomId(), $_POST['showroom_products_id']); } function load(){ $this->load->model('catalog/showroom'); echo json_encode($this->model_catalog_showroom->loadContent($this->getShowroomId())); die(); } function save(){ $this->load->model('catalog/showroom'); echo json_encode($this->model_catalog_showroom->save($this->getShowroomId(), $_POST['json'])); # var_dump($_POST); die(); } function saveProduct(){ $this->load->model('catalog/showroom'); echo json_encode($this->model_catalog_showroom->saveProduct($this->getShowroomId(), $_POST)); die(); } function saveZoom(){ $this->load->model('catalog/showroom'); echo json_encode($this->model_catalog_showroom->saveZoom($this->getShowroomId(), $_POST['zoom'])); die(); } function saveBackground(){ $this->load->model('catalog/showroom'); echo json_encode($this->model_catalog_showroom->saveBackground($this->getShowroomId(), $_POST['background'])); die(); } function saveBackgroundPosition(){ $this->load->model('catalog/showroom'); echo json_encode($this->model_catalog_showroom->saveBackgroundPosition($this->getShowroomId(), $_POST['x'], $_POST['y'])); die(); } function saveBackgroundScale(){ $this->load->model('catalog/showroom'); echo json_encode($this->model_catalog_showroom->saveBackgroundScale($this->getShowroomId(), $_POST['scale'])); die(); } function getMirroredImage(){ $file = explode('image/',$_GET['file']); $src = 'image/'.$file[1]; if (is_file($src)){ $b = $this->mirrorImage($src); header('Content-Disposition: Attachment;filename=image.png'); header('Content-type: image/png'); imagepng($b ); } else { die('ende'); } } function mirrorImage($src){ if (is_file($src)){ $i = imagecreatefrompng($src); $img_x=imagesx($i); $img_y=imagesy($i); $b = imagecreatetruecolor($img_x, $img_y); imagesavealpha($b, true); $trans_color = imagecolorallocatealpha($b, 255, 255, 255, 127); imagefill($b, 0, 0, $trans_color); imagecopyresampled($b, $i, -1, 0, $img_x, 0, $img_x, $img_y, -$img_x, $img_y); return $b; } else { die('ende'); } } function uploadBackground(){ $data = (isset($_GET['qqfile'])) ? $this->ajaxUpload() : $this->standardUpload(); if (is_file($data['src'])){ ini_set("max_execution_time", "240"); $this->load->model('catalog/showroom'); DEFINE('THUMBNAIL_IMAGE_MAX_WIDTH', 1400); DEFINE('THUMBNAIL_IMAGE_MAX_HEIGHT', 850); $this->generate_image_thumbnail($data['src'], $data['src']); $image = getimagesize($data['src']); $width = $image[0]; $height = $image[1]; $format = ($width > $height) ? 'L' : 'P'; $showroom_width = $this->model_catalog_showroom->getShowroomWidth(); $showroom_height = $this->model_catalog_showroom->getShowroomHeight(); if ($format == 'P'){ $scale = $height * 100 / $showroom_height; } else{ $scale = $width * 100 / $showroom_width; } $scale = ($scale > 100) ? 1 / $scale * 100 : 1; $new_width = round($width * $scale); $new_height = round($height * $scale); $x = ( $new_width < $showroom_width) ? ($showroom_width - $new_width) / 2: 0; $y = ( $new_height < $showroom_height) ? ($showroom_height - $new_height) / 2: 0; $data = array( 'src' => $data['src'], 'x' => round($x), 'y' => round($y), 'width' => $width, 'height' => $height, 'scale' => round($scale,2), 'format' => $format ); $this->model_catalog_showroom->saveBackground($this->getShowroomId(), $data); } echo json_encode($data); die(); } function ajaxUpload( ){ $ret = false; $input = fopen("php://input", "r"); $qqfile = $_GET['qqfile']; $ar = explode('.', $qqfile); $ext = end( $ar ); $path = 'image/data/showroom/backgrounds/' . sprintf('%08s', $this->getShowroomId()).'.'.strtolower($ext); $target = fopen($path, "w"); if( $target ){ $bytes_copied = stream_copy_to_stream($input, $target); if( $bytes_copied > 0 ) { $ret = array(); $ret['src'] = $path; } fclose($target); fclose($input); } else { $ret['error'] = 'Fehler beim Upload'; } return $ret; } function standardUpload( ){ $ret = false; $input = fopen("php://input", "r"); $qqfile = $_FILES['qqfile']; $ar = explode('.', $_FILES['qqfile']['name']); $ext = current(array_reverse( $ar )); $path = 'image/data/showroom/backgrounds/' . sprintf('%08s', $this->getShowroomId()).'.'.strtolower($ext); if( copy($_FILES['qqfile']['tmp_name'], $path)){ $ret = array(); $ret['src'] = $path; } else { $ret['error'] = 'Fehler beim Upload'; } return $ret; } function generate_image_thumbnail($source_image_path, $thumbnail_image_path) { list($source_image_width, $source_image_height, $source_image_type) = getimagesize($source_image_path); switch ($source_image_type) { case IMAGETYPE_GIF: $source_gd_image = imagecreatefromgif($source_image_path); break; case IMAGETYPE_JPEG: $source_gd_image = imagecreatefromjpeg($source_image_path); break; case IMAGETYPE_PNG: $source_gd_image = imagecreatefrompng($source_image_path); break; } if ($source_gd_image === false) { return false; } $source_aspect_ratio = $source_image_width / $source_image_height; $thumbnail_aspect_ratio = THUMBNAIL_IMAGE_MAX_WIDTH / THUMBNAIL_IMAGE_MAX_HEIGHT; if ($source_image_width <= THUMBNAIL_IMAGE_MAX_WIDTH && $source_image_height <= THUMBNAIL_IMAGE_MAX_HEIGHT) { $thumbnail_image_width = $source_image_width; $thumbnail_image_height = $source_image_height; } elseif ($thumbnail_aspect_ratio > $source_aspect_ratio) { $thumbnail_image_width = (int) (THUMBNAIL_IMAGE_MAX_HEIGHT * $source_aspect_ratio); $thumbnail_image_height = THUMBNAIL_IMAGE_MAX_HEIGHT; } else { $thumbnail_image_width = THUMBNAIL_IMAGE_MAX_WIDTH; $thumbnail_image_height = (int) (THUMBNAIL_IMAGE_MAX_WIDTH / $source_aspect_ratio); } $thumbnail_gd_image = imagecreatetruecolor($thumbnail_image_width, $thumbnail_image_height); imagecopyresampled($thumbnail_gd_image, $source_gd_image, 0, 0, 0, 0, $thumbnail_image_width, $thumbnail_image_height, $source_image_width, $source_image_height); imagejpeg($thumbnail_gd_image, $thumbnail_image_path, 90); imagedestroy($source_gd_image); imagedestroy($thumbnail_gd_image); return true; } function saveShowroomImage(){ $result = array(); $this->load->model('catalog/showroom'); $showroom_data = $this->model_catalog_showroom->load($this->getShowroomId()); $showroom_image = @imagecreatefrompng('image/data/showroom/showroom_background.png'); $showroom_width = $this->model_catalog_showroom->getShowroomWidth(); $showroom_height = $this->model_catalog_showroom->getShowroomHeight(); // Background if (!empty($showroom_data['background'])){ extract($showroom_data['background']); $src_ar = explode('?', $src); $path = $src_ar[0]; $dst_x = $x; $dst_y = $y; $src_x = 0; $src_y = 0; $src_w = $showroom_width; $src_h = $showroom_height; $dst_width = round($scale * $width ); $dst_height = round($scale * $height ); $background_image = @imagecreatefromjpeg($path); imagecopyresized($showroom_image , $background_image, $dst_x , $dst_y , $src_x , $src_y, $dst_width, $dst_height, $width, $height ); } // Products foreach($showroom_data['products'] as $product){ extract($product); $dst_x = $x; $dst_y = $y + 32; $src_x = 0; $src_y = 0; $src_w = $showroom_width; $src_h = $showroom_height; $product_image_scale = ($y + 100) / 600 * $image_scale * $showroom_data['zoom']; $dst_width = round($width * $product_image_scale); $dst_height = round($height * $product_image_scale); /* echo $image_scale.'
'; echo $showroom_data['zoom'].'
'; echo $product_image_scale.'
'; echo $dst_width.'
'; echo $dst_height.'
'; echo $width.'
'; echo $height.'
'; echo "($dst_x , $dst_y , $src_x , $src_y, $dst_width, $dst_height, $width, $height )";*/ if ($mirrored){ $product_image = $this->mirrorImage($src); } else{ $product_image = @imagecreatefrompng($src); } imagecopyresized($showroom_image , $product_image, $dst_x , $dst_y , $src_x , $src_y, $dst_width, $dst_height, $width, $height ); imagedestroy($product_image); } $path = $this->getPathToShowroomImage(); // Remove old image if (is_file($path)){ unlink($path); } // Save new image imagepng($showroom_image, $path); if (is_file($path)){ $result['success'] = true; } echo json_encode($result); exit; } function saveShowroomImage1(){ $data = $_POST['data']; //removing the "data:image/png;base64," part $uri = substr($data,strpos($data,",")+1); // put the data to a file $path = $this->getPathToShowroomImage(); file_put_contents($path, base64_decode($uri)); } function downloadShowroomImage(){ $path = $this->getPathToShowroomImage(); if (is_file($path)){ $filesize = filesize($path); $filename = 'zimmermann_showroom.png'; header('Content-type: image/png'); header('Content-length: ' . $filesize); header('Content-Disposition: attachment;filename="' . $filename); header('X-Pad: avoid browser bug'); header('Cache-Control: no-cache'); header("Content-Transfer-Encoding: binary"); readfile($path); exit; } } private function getPathToShowroomImage(){ $path = 'image/data/showroom/images/' . sprintf('%08s', $this->getShowroomId()).'.png'; return $path; } function countProducts(){ $this->load->model('catalog/showroom'); $result = array(); $result['products_count'] = $this->model_catalog_showroom->countProducts($this->getShowroomId()); echo json_encode($result); # var_dump($_POST); die(); } public function checkForShowroom(){ $this->load->model('catalog/showroom'); $this->setShowroomId(); echo json_encode($this->model_catalog_showroom->checkForShowroom($_POST['products_id'], $this->getShowroomId())); die(); } public function phpinfo(){ #phpinfo(); die(); } } ?>