src/Controller/RootController.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  4. use Symfony\Component\HttpFoundation\Response;
  5. use Symfony\Component\Routing\Annotation\Route;
  6. use Symfony\Component\HttpFoundation\Request;
  7. class RootController extends AbstractController
  8. {
  9.     /**
  10.      * @Route("/", name="root")
  11.      */
  12.     public function index(): Response
  13.     {
  14.         return $this->render('index.html.twig', [
  15.             'controller_name' => 'RootController',
  16.         ]);
  17.     }
  18.     /**
  19.      * @Route("/test", name="test page")
  20.      */
  21.     public function test(): Response
  22.     {
  23.         return $this->render('test.html.twig', [
  24.             'controller_name' => 'RootController',
  25.         ]);
  26.     }
  27.     /**
  28.      * @Route("/print_execute_kit_barcode", name="print_execute_kit_barcode")
  29.      */
  30.     public function print_execute_kit_barcode(Request $request): Response
  31.     {
  32.         $response = new Response();
  33.         $response->headers->set('Content-Type''application/json');
  34.         $response->headers->set('Access-Control-Allow-Origin''*');
  35.         $response->headers->set('Access-Control-Allow-Methods''POST, GET, PUT, DELETE, PATCH, OPTIONS');
  36.         $json_text $request->get("jsondata");
  37.         $json json_decode($json_text);
  38.         //var_dump($json);
  39.         
  40.         $base_path "/var/www/animalline/resource/";
  41.         //$base_path = "../resource/";
  42.         $print_title $json->title;
  43.         
  44.         $fname date("YmdHis");
  45.         
  46.         $csv_filename $base_path."csv/".$fname.".csv";
  47.         
  48.         $datas $json->datas;
  49.         //Create!Form:環境変数の設定(通常は環境に設定)
  50.         $cfInstDir  "/var/ps";
  51.         $path getenv("PATH");
  52.         $path $path.':'.$cfInstDir."/bin";
  53.         putenv ('CREATE_LANG='."UTF8");
  54.         putenv ('PATH='.$path);
  55.         putenv ("CDIR_PRINTST=".$cfInstDir);
  56.         putenv ('LD_LIBRARY_PATH='.$cfInstDir."/bin");
  57.         //Create!Form:実行ファイルの設定 
  58.         // 作業ディレクトリ 
  59.         $cfworkdir $base_path."printform/DNAKitSend/"
  60.         // スタイルファイル
  61.         $stylefile "DNAKit001.sty";
  62.         // 出力ファイル名 ( ディレクトリに書き込み権限必要 )
  63.         $outputfile $cfworkdir.$fname.".ccd"
  64.         $fp fopen($csv_filename,"w+");
  65.         $field_names = ["main_image","url_qr","pet_code","pet_barcode","pet_barcode_text","pet_code_02","set_no"];
  66.         fputcsv($fp,$field_names);
  67.         foreach($datas as $data){
  68.             $fields = [$cfworkdir."image/main.tif","https://animalline.jp/breeder/member/pets/new/".$data->barcode,$data->barcode,$data->barcode,$data->barcode,$data->barcode,$data->setno];
  69.             fputcsv($fp,$fields);
  70.         }
  71.         fclose($fp);
  72.         //Create!Form PrintStage実行
  73.         //実行コマンドライン(ランタイムガイド参照)
  74.         $execmd "cprintst -D".$cfworkdir." -s".$stylefile." -o".$outputfile." ".$csv_filename." 2>&1";
  75.         $cfret  0;
  76.         $sysret "";
  77.         //実行(ランタイムガイド参照)
  78.         //$sysret = system($execmd , $cfret);
  79.         $sysret exec($execmd$out$cfret);
  80.         
  81.         if($cfret!=0){
  82.             //Create!Form実行エラー
  83.             print("Error:".$cfret.PHP_EOL);
  84.             print("Command:".$execmd.PHP_EOL);
  85.         }else{
  86.             // 正常系
  87.         }
  88.         $response->setContent(json_encode([
  89.             'output' => $fname,
  90.             'ccdType' => 2,
  91.             'print_title' => $print_title,
  92.         ]));
  93.         return  $response;
  94.     }
  95.     /**
  96.      * @Route("/print_execute_kit_sheet", name="print_execute_kit_sheet")
  97.      */
  98.     public function print_execute_kit_sheet(Request $request): Response
  99.     {
  100.         $response = new Response();
  101.         $response->headers->set('Content-Type''application/json');
  102.         $response->headers->set('Access-Control-Allow-Origin''*');
  103.         $response->headers->set('Access-Control-Allow-Methods''POST, GET, PUT, DELETE, PATCH, OPTIONS');
  104.         $json_text $request->get("jsondata");
  105.         $json json_decode($json_text);
  106.         //var_dump($json);
  107.         
  108.         $base_path "/var/www/animalline/resource/";
  109.         //$base_path = "../resource/";
  110.         
  111.         $fname date("YmdHis");
  112.         
  113.         $csv_filename $base_path."csv/".$fname.".csv";
  114.         //Create!Form:環境変数の設定(通常は環境に設定)
  115.         $cfInstDir  "/var/ps";
  116.         $path getenv("PATH");
  117.         $path $path.':'.$cfInstDir."/bin";
  118.         putenv ('CREATE_LANG='."UTF8");
  119.         putenv ('PATH='.$path);
  120.         putenv ("CDIR_PRINTST=".$cfInstDir);
  121.         putenv ('LD_LIBRARY_PATH='.$cfInstDir."/bin");
  122.         //Create!Form:実行ファイルの設定 
  123.         // 作業ディレクトリ 
  124.         $cfworkdir $base_path."printform/DNAKitPaper/"
  125.         // スタイルファイル
  126.         $stylefile "DNAPaper001.sty";
  127.         // 出力ファイル名 ( ディレクトリに書き込み権限必要 )
  128.         $outputfile $cfworkdir.$fname.".ccd"
  129.         $fp fopen($csv_filename,"w+");
  130.         $field_names = [
  131.             mb_convert_encoding("postal""SJIS"),
  132.             mb_convert_encoding("logo""SJIS"),
  133.             mb_convert_encoding("post_code""SJIS"),
  134.             mb_convert_encoding("address01""SJIS"),
  135.             mb_convert_encoding("address02""SJIS"),
  136.             mb_convert_encoding("name""SJIS"),
  137.             mb_convert_encoding("set_no""SJIS"),
  138.             mb_convert_encoding("page02""SJIS")
  139.         ];
  140.         fputcsv($fp,$field_names);
  141.         $fields = [
  142.             mb_convert_encoding($cfworkdir."image/postal.tif""SJIS"),
  143.             mb_convert_encoding($cfworkdir."image/logo.tif""SJIS"),
  144.             mb_convert_encoding($json->post_code"SJIS"),
  145.             mb_convert_encoding($json->address01"SJIS"),
  146.             mb_convert_encoding($json->address02"SJIS"),
  147.             mb_convert_encoding($json->name." 様""SJIS"),
  148.             mb_convert_encoding($json->setno"SJIS"),
  149.             mb_convert_encoding($cfworkdir."image/page02.tif""SJIS"),
  150.         ];
  151.         fputcsv($fp,$fields);
  152.         fclose($fp);
  153.         //Create!Form PrintStage実行
  154.         //実行コマンドライン(ランタイムガイド参照)
  155.         $execmd "cprintst -D".$cfworkdir." -s".$stylefile." -o".$outputfile." ".$csv_filename." 2>&1";
  156.         $cfret  0;
  157.         $sysret "";
  158.         //実行(ランタイムガイド参照)
  159.         //$sysret = system($execmd , $cfret);
  160.         $sysret exec($execmd$out$cfret);
  161.         
  162.         if($cfret!=0){
  163.             //Create!Form実行エラー
  164.             print("Error:".$cfret.PHP_EOL);
  165.             print("Command:".$execmd.PHP_EOL);
  166.         }else{
  167.             // 正常系
  168.         }
  169.        
  170.         $response->setContent(json_encode([
  171.             'output' => $fname,
  172.             'ccdType' => 2,
  173.         ]));
  174.         return  $response;
  175.     }
  176.     /**
  177.      * @Route("/get_ccd/{sheetname}/{fileid}", name="get_ccd")
  178.      */
  179.     public function get_ccd(Request $request$sheetname,$fileid) {
  180.         $response = new Response();
  181.         $response->headers->set('Content-Type'' application/octet-stream');
  182.         $response->headers->set('Content-Disposition'' attachment; filename=tmp.ccd');
  183.         $response->headers->set('ontent-Transfer-Encoding'' binary');
  184.         $filedata file_get_contents('/var/www/animalline/resource/printform/'.$sheetname.'/'.$fileid.'.ccd');
  185.         $response->setContent($filedata);
  186.         return  $response;
  187.     }
  188.     /**
  189.      * @Route("/print_execute_kit_barcode_buy", name="print_execute_kit_barcode_buy")
  190.      */
  191.     public function print_execute_kit_barcodeBuy(Request $request): Response
  192.     {
  193.         $response = new Response();
  194.         $response->headers->set('Content-Type''application/json');
  195.         $response->headers->set('Access-Control-Allow-Origin''*');
  196.         $response->headers->set('Access-Control-Allow-Methods''POST, GET, PUT, DELETE, PATCH, OPTIONS');
  197.         $json_text $request->get("jsondata");
  198.         $json json_decode($json_text);
  199.         //var_dump($json);
  200.         
  201.         $base_path "/var/www/animalline/resource/";
  202.         //$base_path = "../resource/";
  203.         $print_title $json->title;
  204.         
  205.         $fname date("YmdHis");
  206.         
  207.         $csv_filename $base_path."csv/".$fname.".csv";
  208.         
  209.         $datas $json->datas;
  210.         //Create!Form:環境変数の設定(通常は環境に設定)
  211.         $cfInstDir  "/var/ps";
  212.         $path getenv("PATH");
  213.         $path $path.':'.$cfInstDir."/bin";
  214.         putenv ('CREATE_LANG='."UTF8");
  215.         putenv ('PATH='.$path);
  216.         putenv ("CDIR_PRINTST=".$cfInstDir);
  217.         putenv ('LD_LIBRARY_PATH='.$cfInstDir."/bin");
  218.         //Create!Form:実行ファイルの設定 
  219.         // 作業ディレクトリ 
  220.         $cfworkdir $base_path."printform/DNAKitSendBuy/"
  221.         // スタイルファイル
  222.         $stylefile "DNAKit001.sty";
  223.         // 出力ファイル名 ( ディレクトリに書き込み権限必要 )
  224.         $outputfile $cfworkdir.$fname.".ccd"
  225.         $fp fopen($csv_filename,"w+");
  226.         $field_names = ["main_image","url_qr","pet_code","pet_barcode","pet_barcode_text","pet_code_02","set_no"];
  227.         fputcsv($fp,$field_names);
  228.         foreach($datas as $data){
  229.             $fields = [$cfworkdir."image/main.tif","https://animalline.jp/d".$data->barcode,$data->barcode,$data->barcode,$data->barcode,$data->barcode,$data->setno];
  230.             fputcsv($fp,$fields);
  231.         }
  232.         fclose($fp);
  233.         //Create!Form PrintStage実行
  234.         //実行コマンドライン(ランタイムガイド参照)
  235.         $execmd "cprintst -D".$cfworkdir." -s".$stylefile." -o".$outputfile." ".$csv_filename." 2>&1";
  236.         $cfret  0;
  237.         $sysret "";
  238.         //実行(ランタイムガイド参照)
  239.         //$sysret = system($execmd , $cfret);
  240.         $sysret exec($execmd$out$cfret);
  241.         
  242.         if($cfret!=0){
  243.             //Create!Form実行エラー
  244.             print("Error:".$cfret.PHP_EOL);
  245.             print("Command:".$execmd.PHP_EOL);
  246.         }else{
  247.             // 正常系
  248.         }
  249.         $response->setContent(json_encode([
  250.             'output' => $fname,
  251.             'ccdType' => 2,
  252.             'print_title' => $print_title,
  253.         ]));
  254.         return  $response;
  255.     }
  256.     /**
  257.      * @Route("/print_execute_kit_sheet_buy", name="print_execute_kit_sheet_buy")
  258.      */
  259.     public function print_execute_kit_sheetBuy(Request $request): Response
  260.     {
  261.         $response = new Response();
  262.         $response->headers->set('Content-Type''application/json');
  263.         $response->headers->set('Access-Control-Allow-Origin''*');
  264.         $response->headers->set('Access-Control-Allow-Methods''POST, GET, PUT, DELETE, PATCH, OPTIONS');
  265.         $json_text $request->get("jsondata");
  266.         $json json_decode($json_text);
  267.         //var_dump($json);
  268.         
  269.         $base_path "/var/www/animalline/resource/";
  270.         //$base_path = "../resource/";
  271.         
  272.         $fname date("YmdHis");
  273.         
  274.         $csv_filename $base_path."csv/".$fname.".csv";
  275.         //Create!Form:環境変数の設定(通常は環境に設定)
  276.         $cfInstDir  "/var/ps";
  277.         $path getenv("PATH");
  278.         $path $path.':'.$cfInstDir."/bin";
  279.         putenv ('CREATE_LANG='."UTF8");
  280.         putenv ('PATH='.$path);
  281.         putenv ("CDIR_PRINTST=".$cfInstDir);
  282.         putenv ('LD_LIBRARY_PATH='.$cfInstDir."/bin");
  283.         //Create!Form:実行ファイルの設定 
  284.         // 作業ディレクトリ 
  285.         $cfworkdir $base_path."printform/DNAKitPaperBuy/"
  286.         // スタイルファイル
  287.         $stylefile "DNAPaper001.sty";
  288.         // 出力ファイル名 ( ディレクトリに書き込み権限必要 )
  289.         $outputfile $cfworkdir.$fname.".ccd"
  290.         $fp fopen($csv_filename,"w+");
  291.         $field_names = [
  292.             mb_convert_encoding("postal""SJIS"),
  293.             mb_convert_encoding("logo""SJIS"),
  294.             mb_convert_encoding("post_code""SJIS"),
  295.             mb_convert_encoding("address01""SJIS"),
  296.             mb_convert_encoding("address02""SJIS"),
  297.             mb_convert_encoding("name""SJIS"),
  298.             mb_convert_encoding("set_no""SJIS"),
  299.             mb_convert_encoding("page02""SJIS")
  300.         ];
  301.         fputcsv($fp,$field_names);
  302.         $fields = [
  303.             mb_convert_encoding($cfworkdir."image/postal.tif""SJIS"),
  304.             mb_convert_encoding($cfworkdir."image/logo.tif""SJIS"),
  305.             mb_convert_encoding($json->post_code"SJIS"),
  306.             mb_convert_encoding($json->address01"SJIS"),
  307.             mb_convert_encoding($json->address02"SJIS"),
  308.             mb_convert_encoding($json->name." 様""SJIS"),
  309.             mb_convert_encoding($json->setno"SJIS"),
  310.             mb_convert_encoding($cfworkdir."image/page02.tif""SJIS"),
  311.         ];
  312.         fputcsv($fp,$fields);
  313.         fclose($fp);
  314.         //Create!Form PrintStage実行
  315.         //実行コマンドライン(ランタイムガイド参照)
  316.         $execmd "cprintst -D".$cfworkdir." -s".$stylefile." -o".$outputfile." ".$csv_filename." 2>&1";
  317.         $cfret  0;
  318.         $sysret "";
  319.         //実行(ランタイムガイド参照)
  320.         //$sysret = system($execmd , $cfret);
  321.         $sysret exec($execmd$out$cfret);
  322.         
  323.         if($cfret!=0){
  324.             //Create!Form実行エラー
  325.             print("Error:".$cfret.PHP_EOL);
  326.             print("Command:".$execmd.PHP_EOL);
  327.         }else{
  328.             // 正常系
  329.         }
  330.        
  331.         $response->setContent(json_encode([
  332.             'output' => $fname,
  333.             'ccdType' => 2,
  334.         ]));
  335.         return  $response;
  336.     }
  337. }