<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\Request;
class RootController extends AbstractController
{
/**
* @Route("/", name="root")
*/
public function index(): Response
{
return $this->render('index.html.twig', [
'controller_name' => 'RootController',
]);
}
/**
* @Route("/test", name="test page")
*/
public function test(): Response
{
return $this->render('test.html.twig', [
'controller_name' => 'RootController',
]);
}
/**
* @Route("/print_execute_kit_barcode", name="print_execute_kit_barcode")
*/
public function print_execute_kit_barcode(Request $request): Response
{
$response = new Response();
$response->headers->set('Content-Type', 'application/json');
$response->headers->set('Access-Control-Allow-Origin', '*');
$response->headers->set('Access-Control-Allow-Methods', 'POST, GET, PUT, DELETE, PATCH, OPTIONS');
$json_text = $request->get("jsondata");
$json = json_decode($json_text);
//var_dump($json);
$base_path = "/var/www/animalline/resource/";
//$base_path = "../resource/";
$print_title = $json->title;
$fname = date("YmdHis");
$csv_filename = $base_path."csv/".$fname.".csv";
$datas = $json->datas;
//Create!Form:環境変数の設定(通常は環境に設定)
$cfInstDir = "/var/ps";
$path = getenv("PATH");
$path = $path.':'.$cfInstDir."/bin";
putenv ('CREATE_LANG='."UTF8");
putenv ('PATH='.$path);
putenv ("CDIR_PRINTST=".$cfInstDir);
putenv ('LD_LIBRARY_PATH='.$cfInstDir."/bin");
//Create!Form:実行ファイルの設定
// 作業ディレクトリ
$cfworkdir = $base_path."printform/DNAKitSend/";
// スタイルファイル
$stylefile = "DNAKit001.sty";
// 出力ファイル名 ( ディレクトリに書き込み権限必要 )
$outputfile = $cfworkdir.$fname.".ccd";
$fp = fopen($csv_filename,"w+");
$field_names = ["main_image","url_qr","pet_code","pet_barcode","pet_barcode_text","pet_code_02","set_no"];
fputcsv($fp,$field_names);
foreach($datas as $data){
$fields = [$cfworkdir."image/main.tif","https://animalline.jp/breeder/member/pets/new/".$data->barcode,$data->barcode,$data->barcode,$data->barcode,$data->barcode,$data->setno];
fputcsv($fp,$fields);
}
fclose($fp);
//Create!Form PrintStage実行
//実行コマンドライン(ランタイムガイド参照)
$execmd = "cprintst -D".$cfworkdir." -s".$stylefile." -o".$outputfile." ".$csv_filename." 2>&1";
$cfret = 0;
$sysret = "";
//実行(ランタイムガイド参照)
//$sysret = system($execmd , $cfret);
$sysret = exec($execmd, $out, $cfret);
if($cfret!=0){
//Create!Form実行エラー
print("Error:".$cfret.PHP_EOL);
print("Command:".$execmd.PHP_EOL);
}else{
// 正常系
}
$response->setContent(json_encode([
'output' => $fname,
'ccdType' => 2,
'print_title' => $print_title,
]));
return $response;
}
/**
* @Route("/print_execute_kit_sheet", name="print_execute_kit_sheet")
*/
public function print_execute_kit_sheet(Request $request): Response
{
$response = new Response();
$response->headers->set('Content-Type', 'application/json');
$response->headers->set('Access-Control-Allow-Origin', '*');
$response->headers->set('Access-Control-Allow-Methods', 'POST, GET, PUT, DELETE, PATCH, OPTIONS');
$json_text = $request->get("jsondata");
$json = json_decode($json_text);
//var_dump($json);
$base_path = "/var/www/animalline/resource/";
//$base_path = "../resource/";
$fname = date("YmdHis");
$csv_filename = $base_path."csv/".$fname.".csv";
//Create!Form:環境変数の設定(通常は環境に設定)
$cfInstDir = "/var/ps";
$path = getenv("PATH");
$path = $path.':'.$cfInstDir."/bin";
putenv ('CREATE_LANG='."UTF8");
putenv ('PATH='.$path);
putenv ("CDIR_PRINTST=".$cfInstDir);
putenv ('LD_LIBRARY_PATH='.$cfInstDir."/bin");
//Create!Form:実行ファイルの設定
// 作業ディレクトリ
$cfworkdir = $base_path."printform/DNAKitPaper/";
// スタイルファイル
$stylefile = "DNAPaper001.sty";
// 出力ファイル名 ( ディレクトリに書き込み権限必要 )
$outputfile = $cfworkdir.$fname.".ccd";
$fp = fopen($csv_filename,"w+");
$field_names = [
mb_convert_encoding("postal", "SJIS"),
mb_convert_encoding("logo", "SJIS"),
mb_convert_encoding("post_code", "SJIS"),
mb_convert_encoding("address01", "SJIS"),
mb_convert_encoding("address02", "SJIS"),
mb_convert_encoding("name", "SJIS"),
mb_convert_encoding("set_no", "SJIS"),
mb_convert_encoding("page02", "SJIS")
];
fputcsv($fp,$field_names);
$fields = [
mb_convert_encoding($cfworkdir."image/postal.tif", "SJIS"),
mb_convert_encoding($cfworkdir."image/logo.tif", "SJIS"),
mb_convert_encoding($json->post_code, "SJIS"),
mb_convert_encoding($json->address01, "SJIS"),
mb_convert_encoding($json->address02, "SJIS"),
mb_convert_encoding($json->name." 様", "SJIS"),
mb_convert_encoding($json->setno, "SJIS"),
mb_convert_encoding($cfworkdir."image/page02.tif", "SJIS"),
];
fputcsv($fp,$fields);
fclose($fp);
//Create!Form PrintStage実行
//実行コマンドライン(ランタイムガイド参照)
$execmd = "cprintst -D".$cfworkdir." -s".$stylefile." -o".$outputfile." ".$csv_filename." 2>&1";
$cfret = 0;
$sysret = "";
//実行(ランタイムガイド参照)
//$sysret = system($execmd , $cfret);
$sysret = exec($execmd, $out, $cfret);
if($cfret!=0){
//Create!Form実行エラー
print("Error:".$cfret.PHP_EOL);
print("Command:".$execmd.PHP_EOL);
}else{
// 正常系
}
$response->setContent(json_encode([
'output' => $fname,
'ccdType' => 2,
]));
return $response;
}
/**
* @Route("/get_ccd/{sheetname}/{fileid}", name="get_ccd")
*/
public function get_ccd(Request $request, $sheetname,$fileid) {
$response = new Response();
$response->headers->set('Content-Type', ' application/octet-stream');
$response->headers->set('Content-Disposition', ' attachment; filename=tmp.ccd');
$response->headers->set('ontent-Transfer-Encoding', ' binary');
$filedata = file_get_contents('/var/www/animalline/resource/printform/'.$sheetname.'/'.$fileid.'.ccd');
$response->setContent($filedata);
return $response;
}
/**
* @Route("/print_execute_kit_barcode_buy", name="print_execute_kit_barcode_buy")
*/
public function print_execute_kit_barcodeBuy(Request $request): Response
{
$response = new Response();
$response->headers->set('Content-Type', 'application/json');
$response->headers->set('Access-Control-Allow-Origin', '*');
$response->headers->set('Access-Control-Allow-Methods', 'POST, GET, PUT, DELETE, PATCH, OPTIONS');
$json_text = $request->get("jsondata");
$json = json_decode($json_text);
//var_dump($json);
$base_path = "/var/www/animalline/resource/";
//$base_path = "../resource/";
$print_title = $json->title;
$fname = date("YmdHis");
$csv_filename = $base_path."csv/".$fname.".csv";
$datas = $json->datas;
//Create!Form:環境変数の設定(通常は環境に設定)
$cfInstDir = "/var/ps";
$path = getenv("PATH");
$path = $path.':'.$cfInstDir."/bin";
putenv ('CREATE_LANG='."UTF8");
putenv ('PATH='.$path);
putenv ("CDIR_PRINTST=".$cfInstDir);
putenv ('LD_LIBRARY_PATH='.$cfInstDir."/bin");
//Create!Form:実行ファイルの設定
// 作業ディレクトリ
$cfworkdir = $base_path."printform/DNAKitSendBuy/";
// スタイルファイル
$stylefile = "DNAKit001.sty";
// 出力ファイル名 ( ディレクトリに書き込み権限必要 )
$outputfile = $cfworkdir.$fname.".ccd";
$fp = fopen($csv_filename,"w+");
$field_names = ["main_image","url_qr","pet_code","pet_barcode","pet_barcode_text","pet_code_02","set_no"];
fputcsv($fp,$field_names);
foreach($datas as $data){
$fields = [$cfworkdir."image/main.tif","https://animalline.jp/d".$data->barcode,$data->barcode,$data->barcode,$data->barcode,$data->barcode,$data->setno];
fputcsv($fp,$fields);
}
fclose($fp);
//Create!Form PrintStage実行
//実行コマンドライン(ランタイムガイド参照)
$execmd = "cprintst -D".$cfworkdir." -s".$stylefile." -o".$outputfile." ".$csv_filename." 2>&1";
$cfret = 0;
$sysret = "";
//実行(ランタイムガイド参照)
//$sysret = system($execmd , $cfret);
$sysret = exec($execmd, $out, $cfret);
if($cfret!=0){
//Create!Form実行エラー
print("Error:".$cfret.PHP_EOL);
print("Command:".$execmd.PHP_EOL);
}else{
// 正常系
}
$response->setContent(json_encode([
'output' => $fname,
'ccdType' => 2,
'print_title' => $print_title,
]));
return $response;
}
/**
* @Route("/print_execute_kit_sheet_buy", name="print_execute_kit_sheet_buy")
*/
public function print_execute_kit_sheetBuy(Request $request): Response
{
$response = new Response();
$response->headers->set('Content-Type', 'application/json');
$response->headers->set('Access-Control-Allow-Origin', '*');
$response->headers->set('Access-Control-Allow-Methods', 'POST, GET, PUT, DELETE, PATCH, OPTIONS');
$json_text = $request->get("jsondata");
$json = json_decode($json_text);
//var_dump($json);
$base_path = "/var/www/animalline/resource/";
//$base_path = "../resource/";
$fname = date("YmdHis");
$csv_filename = $base_path."csv/".$fname.".csv";
//Create!Form:環境変数の設定(通常は環境に設定)
$cfInstDir = "/var/ps";
$path = getenv("PATH");
$path = $path.':'.$cfInstDir."/bin";
putenv ('CREATE_LANG='."UTF8");
putenv ('PATH='.$path);
putenv ("CDIR_PRINTST=".$cfInstDir);
putenv ('LD_LIBRARY_PATH='.$cfInstDir."/bin");
//Create!Form:実行ファイルの設定
// 作業ディレクトリ
$cfworkdir = $base_path."printform/DNAKitPaperBuy/";
// スタイルファイル
$stylefile = "DNAPaper001.sty";
// 出力ファイル名 ( ディレクトリに書き込み権限必要 )
$outputfile = $cfworkdir.$fname.".ccd";
$fp = fopen($csv_filename,"w+");
$field_names = [
mb_convert_encoding("postal", "SJIS"),
mb_convert_encoding("logo", "SJIS"),
mb_convert_encoding("post_code", "SJIS"),
mb_convert_encoding("address01", "SJIS"),
mb_convert_encoding("address02", "SJIS"),
mb_convert_encoding("name", "SJIS"),
mb_convert_encoding("set_no", "SJIS"),
mb_convert_encoding("page02", "SJIS")
];
fputcsv($fp,$field_names);
$fields = [
mb_convert_encoding($cfworkdir."image/postal.tif", "SJIS"),
mb_convert_encoding($cfworkdir."image/logo.tif", "SJIS"),
mb_convert_encoding($json->post_code, "SJIS"),
mb_convert_encoding($json->address01, "SJIS"),
mb_convert_encoding($json->address02, "SJIS"),
mb_convert_encoding($json->name." 様", "SJIS"),
mb_convert_encoding($json->setno, "SJIS"),
mb_convert_encoding($cfworkdir."image/page02.tif", "SJIS"),
];
fputcsv($fp,$fields);
fclose($fp);
//Create!Form PrintStage実行
//実行コマンドライン(ランタイムガイド参照)
$execmd = "cprintst -D".$cfworkdir." -s".$stylefile." -o".$outputfile." ".$csv_filename." 2>&1";
$cfret = 0;
$sysret = "";
//実行(ランタイムガイド参照)
//$sysret = system($execmd , $cfret);
$sysret = exec($execmd, $out, $cfret);
if($cfret!=0){
//Create!Form実行エラー
print("Error:".$cfret.PHP_EOL);
print("Command:".$execmd.PHP_EOL);
}else{
// 正常系
}
$response->setContent(json_encode([
'output' => $fname,
'ccdType' => 2,
]));
return $response;
}
}