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 = '

+7 (495) 972-07-73

+7 (495) 972-07-76

+7 (499) 166-62-43

+7 (499) 166-62-48

прайс-лист товаров

posuda-sklad.ru
'; } function getHeadDataWL(){ return $head = '

прайс-лист товаров

'; } function getFooterData(){ return $footer = ' '; } function getContent($result){ $html = ''; $count = count($result); for($i=0; $i<$count; $i++){ if($result[$i][0]=='parent_category'){ $html .='
'; $html .= '

'.$result[$i][1].'

'; for($s=$i+1; $s<$count; ++$s){ if($result[$s][0] == 'sub_category'){ $html .='

'.$result[$s][1].'

'; for($d=$s+1; $d<$count; $d++){ if($result[$d][0]=='item'){ $html .= '

'.$result[$d][1].'

'.$result[$d][2].' р.

'; } else { $s = $d-1; break; } } $html .= '
'; } else { $i=$s-1; break; } } $html .= '
'; } } return $html; } function getContentWL($result){ $html = ''; $count = count($result); for($i=0; $i<$count; $i++){ if($result[$i][0]=='parent_category'){ $html .='
'; $html .= '

'.$result[$i][1].'

'; for($s=$i+1; $s<$count; ++$s){ if($result[$s][0] == 'sub_category'){ $html .='

'.$result[$s][1].'

'; for($d=$s+1; $d<$count; $d++){ if($result[$d][0]=='item'){ $html .= '

'.$result[$d][1].'

'; } else { $s = $d-1; break; } } $html .= '
'; } else { $i=$s-1; break; } } $html .= '
'; } } return $html; } }