IframsController.php 11.3 KB
<?php
namespace controllers;

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

class IframsController extends \Phalcon\Mvc\Controller
{
    function indexAction(){
        die('hello');
    }

    function pdfPriceAction(){
        $this->view->disableLevel(\Phalcon\Mvc\View::LEVEL_MAIN_LAYOUT);
        if( $this->request->isPost() )
        {
            $sourceFileName = 'http://www.posuda-sklad.ru/products_seo.csv';
            $origFileName = 'products_seo.csv';
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, $sourceFileName);
            curl_setopt($ch, CURLOPT_TIMEOUT, 300);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

            $st = curl_exec($ch);
            $fd = fopen($origFileName, "w");
            fwrite($fd, $st);
            fclose($fd);

            curl_close($ch);
            $result = $this->ServiceExcel->getCSV_CharsetClean('products_seo.csv');

            $type = $this->request->getPost('type');
            if(is_array($result)){
                if($type == 'pdf_1'){
                    $this->createNewPriceList($result);
                }else if($type == 'pdf_2'){
                    $this->createNewPriceListWL($result);
                }

            } else {
                die('файл с данными не получен');
            }


            $cd = 'cd www/seo/www-backend';
            exec($cd);
            $comand = 'wkhtmltopdf --margin-bottom 0 --margin-top 0 --margin-left 0 --margin-right 0 "http://storage.seo.dev.artwebua.com.ua/posuda_price_list/" catalog.pdf';
            exec($comand);
            sleep(2);
            exec('chmod 664 catalog.pdf');


            $file_dir = '/home/dev/www/seo/www-backend';

            if (file_exists("$file_dir/catalog.pdf")) {
                header('Content-type: application/pdf');
                header('Content-Disposition: attachment; filename="catalog.pdf"');
                readfile("/home/dev/www/seo/www-backend/catalog.pdf");
                unlink("$file_dir/catalog.pdf");
                die();
            }
        }

    }


    function createNewPriceList($result) {


            $route = STORAGE_PATH.'posuda_price_list/index.html';
            $body = $this->getHeadData();
            $body .= $this->getContent($result);
            $body .= $this->getFooterData();

            $fd = @fopen($route, "w");
            fwrite($fd, $body);
            @fclose($fd);

    }

    function createNewPriceListWL($result) {


        $route = STORAGE_PATH.'posuda_price_list/index.html';
        $body = $this->getHeadDataWL();
        $body .= $this->getContentWL($result);

        $fd = @fopen($route, "w");
        fwrite($fd, $body);
        @fclose($fd);

    }

    function getHeadData(){
        return $head = '<!DOCTYPE html>
        <html>
        <head lang="en">
            <meta charset="UTF-8">
            <link href="style.css" rel="stylesheet">
            <title></title>
            <style>

            </style>
        </head>
        <body>
        <div class="main-block" id="head-block">
            <div class="logo"></div>
            <div class="content">
                <div class="contacts">
                    <div class="first-phone-block">
                        <p>+7 (495) <span>972-07-73</span></p>
                        <p>+7 (495) <span>972-07-76</span></p>
                    </div>
                    <div class="second-phone-block">
                        <p>+7 (499) <span>166-62-43</span></p>
                        <p>+7 (499) <span>166-62-48</span></p>
                    </div>
                    <a class="email" href="mail@posuda-sklad.ru">mail@posuda-sklad.ru</a>
                </div>
                <p class="title">
                   прайс-лист товаров
                </p>
                <a class="site-link" href="posuda-sklad.ru">posuda-sklad.ru</a>
            </div>
            <div class="bottom-image"></div>
        </div>
';
    }



    function getHeadDataWL(){
        return $head = '<!DOCTYPE html>
        <html>
        <head lang="en">
            <meta charset="UTF-8">
            <link href="style.css" rel="stylesheet">
            <title></title>
            <style>

            </style>
        </head>
        <body>
        <div class="main-block" id="head-block">
            <div class="content">

                <p class="title" style="margin-top: 0; padding-top: 250px">
                   прайс-лист товаров
                </p>

            </div>
            <div class="bottom-image"></div>
        </div>
';
    }

    function getFooterData(){
        return $footer = '
                <div class="main-block footer-block-main" id="bottom-block">
                    <div class="logo">
                        <div class="contacts">
                            <div class="first-phone-block">
                                <p>+7 (495) <span>972-07-73</span></p>
                                <p>+7 (495) <span>972-07-76</span></p>
                            </div>
                            <div class="second-phone-block">
                                <p>+7 (499) <span>166-62-43</span></p>
                                <p>+7 (499) <span>166-62-48</span></p>
                            </div>
                            <a class="email" href="mail@posuda-sklad.ru">mail@posuda-sklad.ru</a>
                        </div>
                    </div>
                    <div class="content">
                        <p class="title">
                            прайс-лист товаров
                        </p>
                        <a class="site-link" href="posuda-sklad.ru">posuda-sklad.ru</a>
                    </div>
                    <div class="contacts">
                        <div class="first-phone-block">
                            <p>+7 (495) <span>972-07-73</span></p>
                            <p>+7 (495) <span>972-07-76</span></p>
                        </div>
                        <div class="second-phone-block">
                            <p>+7 (499) <span>166-62-43</span></p>
                            <p>+7 (499) <span>166-62-48</span></p>
                        </div>
                        <a class="email" href="mail@posuda-sklad.ru">mail@posuda-sklad.ru</a>
                        <p class="address">
                            105187, Москва, 1-я ул. Измайловского зверинца, д.19а (ст. метро "Партизанская")
                            Территория НИПТИ "Стройиндустрия". Две остановки от метро автобусом 7 или 131.
                            Заезд со 2-й ул. Измайловского зверинца, заводские корпуса сиреневого цвета.
                        </p>
                        <p class="time-table">
                            Будние дни с 9:00 до 17:00 без обеда.
                        </p>
                        <p class="coordinates">
                            Координаты для GPS навигатора:<br>
                            Долгота: N55°46.718\' (C 55.778635°), Широта: E37°44.792\' (B 37.746529°)
                        </p>
                    </div>
                    <div class="map">

                    </div>
                </div>
        </body>
        </html>';
    }

    function getContent($result){
        $html = '';
        $count = count($result);
        for($i=0; $i<$count; $i++){
            if($result[$i][0]=='parent_category'){
                $html .='
                <div class="main-block price-list" id="content-block">
                    <div class="logo">
                        <div class="contacts">
                            <div class="first-phone-block">
                                <p>+7 (495) <span>972-07-73</span></p>
                                <p>+7 (495) <span>972-07-76</span></p>
                            </div>
                            <div class="second-phone-block">
                                <p>+7 (499) <span>166-62-43</span></p>
                                <p>+7 (499) <span>166-62-48</span></p>
                            </div>
                            <a class="email" href="mail@posuda-sklad.ru">mail@posuda-sklad.ru</a>
                        </div>
                    </div>
                    <div class="content">';
                $html .= '<h1>'.$result[$i][1].'</h1>';
                for($s=$i+1; $s<$count; ++$s){
                    if($result[$s][0] == 'sub_category'){

                        $html .='<div class="table">
                        <h2>'.$result[$s][1].'</h2>
                        <div class="table-body">';
                        for($d=$s+1; $d<$count; $d++){
                            if($result[$d][0]=='item'){
                                $html .= '<div class="row">
                                    <img src='.(!empty($result[$d][3]) ? "http://www.posuda-sklad.ru/uploadedfiles/".$result[$d][3] : "image/images.jpg").'>
                                    <p class="name">'.$result[$d][1].'</p>
                                    <p class="price">'.$result[$d][2].' р.</p>
                                 </div>';
                            } else {
                                $s = $d-1;
                                break;
                            }
                        }
                        $html .= '</div></div>';
                    } else {
                        $i=$s-1;
                        break;
                    }

                }
                $html .= '</div></div>';
            }
        }

        return $html;

    }


    function getContentWL($result){
        $html = '';
        $count = count($result);
        for($i=0; $i<$count; $i++){
            if($result[$i][0]=='parent_category'){
                $html .='
                <div class="main-block price-list" id="content-block">
                    <div class="content">';
                $html .= '<h1>'.$result[$i][1].'</h1>';
                for($s=$i+1; $s<$count; ++$s){
                    if($result[$s][0] == 'sub_category'){

                        $html .='<div class="table">
                        <h2>'.$result[$s][1].'</h2>
                        <div class="table-body">';
                        for($d=$s+1; $d<$count; $d++){
                            if($result[$d][0]=='item'){
                                $html .= '<div class="row">
                                    <img src='.(!empty($result[$d][3]) ? "http://www.posuda-sklad.ru/uploadedfiles/".$result[$d][3] : "image/images.jpg").'>
                                    <p class="name">'.$result[$d][1].'</p>
                                    <p class="price"></p>
                                 </div>';
                            } else {
                                $s = $d-1;
                                break;
                            }
                        }
                        $html .= '</div></div>';
                    } else {
                        $i=$s-1;
                        break;
                    }

                }
                $html .= '</div></div>';
            }
        }

        return $html;

    }


}