$child) writeCSVFromArray($res, $child, $dem, $bTypeUTF8); fwrite($res, "\r\n"); } else { if(!bTypeUTF8) $value = mb_convert_encoding($value, 'UTF-16LE', 'UTF-8'); fwrite($res, $value.$dem); } } // CSVファイル書き出し function writeCSVFileOutput($res, $csvdata) { $bTypeUTF8 = true; if($bTypeUTF8) fwrite($res, pack("C*",0xef, 0xbb, 0xbf)); // UTF-8用BOMヘッダ else fwrite($res, pack("C*",0xff,0xfe)); // UTF-16LE用BOMヘッダ // writeCSVFromArray($res, $csvdata, "\t", $bTypeUTF8); foreach($csvdata as $key => $value) { if(!$bTypeUTF8) $value = mb_convert_encoding($value, 'UTF-16LE', 'UTF-8'); // 文字コード変換 UTF-8 -> UTF-16LE fputcsv($res, $value); } } ini_set('memory_limit', -1); set_time_limit(0); $dbobj = new CMyDBWrapper(); $tournament_teamsInsert = array( "status_id" => 4 ); $tournament_id = $_GET["id"]; $tournament = get_tournament4tournament_id($tournament_id); $sex = implode(" / ", unserialize($tournament['sex'])); $shipping_postnum1 = unserialize($tournament['shipping_postnum1']); $shipping_postnum2 = unserialize($tournament['shipping_postnum2']); $shipping_address = unserialize($tournament['shipping_address']); $shipping_to = unserialize($tournament['shipping_to']); $shipping_num = unserialize($tournament['shipping_num']); if($shipping_postnum1){ $csv['0'] = array("配送先郵便番号1", "配送先郵便番号2", "配送先住所", "配送先宛名", "配送部数"); foreach($shipping_postnum1 as $key => $value){ $csv[$key+1] = array($shipping_postnum1[$key], $shipping_postnum2[$key], $shipping_address[$key], $shipping_to[$key], $shipping_num[$key]); } $file_address_name = "address.csv"; $csv_address_file = CSV_DIR."/".$file_address_name; $res = fopen($csv_address_file, 'wb'); writeCSVFileOutput($res, $csv); // fputcsv($res,pack('C*',0xFE,0xFF)); // fwrite($res, "/xEF/xBB/xBF"); // foreach($csv as $key => $value){ // //mb_convert_variables('SJIS-win', 'UTF-8', $value); // //$value = mb_convert_encoding($value, 'UTF-16LE', 'utf-8'); // fputcsv($res, $value); // } fclose($res); unset($csv); } $teams = get_team_list4tournament_id($tournament['organizer_id'], $tournament_id); $csv['0'] = array("チーム名", "女or男", "支部名", "監督姓", "監督名", "コーチ姓", "コーチ名", "マネージャー姓", "マネージャー名", "主将姓", "主将名"); for($i = 1;$i<=14;$i++){ array_push($csv['0'], $i."背番号", $i."姓", $i."名", $i."学年", $i."身長"); } array_push($csv['0'], "@img", "チーム紹介"); foreach($teams as $key => $value){ //監督 $directer = get_staff_list4position_id($value['team_id'], 1, $tournament_id); //コーチ1データ $coach1 = get_staff_list4position_id($value['team_id'], 2, $tournament_id); //コーチ2データ $coach2 = get_staff_list4position_id($value['team_id'], 3, $tournament_id); //トレーナーデータ $trainer = get_staff_list4position_id($value['team_id'], 4, $tournament_id); //マネージャ $manager = get_staff_list4position_id($value['team_id'], 5, $tournament_id); //部長データ $chief = get_staff_list4position_id($value['team_id'], 6, $tournament_id); //連絡・申込責任者データ $person = get_staff_list4position_id($value['team_id'], 7, $tournament_id); //帯同員データ $along = get_staff_list4position_id($value['team_id'], 8, $tournament_id); //キャプテンデータ $captain = get_staff_list4position_id($value['team_id'], 9, $tournament_id); //キャプテン背番号 $captain_uniform_number = get_player_uniform_number4position_id($value['team_id'], $tournament_id, 9); //選手データ $players = get_player_list4team_id($value['team_id'], $tournament_id); $players_count = count($players); $csv[$key+1] = array($value['team_name'], $value['sex_name'], $value['block_name'], $directer['0']['staff_lastname'], $directer['0']['staff_firstname'], $coach1['0']['staff_lastname'], $coach1['0']['staff_firstname'], $manager['0']['staff_lastname'], $manager['0']['staff_firstname'], $captain['0']['staff_lastname'], $captain['0']['staff_firstname']); foreach($players as $pKey => $player){ $school_year = mb_convert_kana($player['school_year'], "n", "utf-8"); $school_year = preg_replace('/[^0-9]/', '', $school_year); array_push($csv[$key+1], $player['uniform_number'], $player['player_lastname'], $player['player_firstname'], $school_year, $player['tall']); } if($players_count < 14){ for($i = $players_count;$i<=13;$i++){ array_push($csv[$key+1], "", "", "", "", ""); } } $file_name = "team-".$tournament_id."-".$value['login_id'].".psd"; $img_name = "team-".$tournament_id."-".$value['login_id'].".png"; array_push($csv[$key+1], $file_name, $value['tournament_comment']); //$ret = $dbobj->updateTable("tournament_teams", $tournament_teamsInsert, array("tournament_teams_id" => $value['tournament_teams_id'])); $img_list[] = $img_name; } $file_name = "print.csv"; $csv_file = CSV_DIR."/".$file_name; $res = fopen($csv_file, 'wb'); writeCSVFileOutput($res, $csv); //fputcsv($res,pack('C*',0xFE,0xBB,0xBF)); //fwrite($res, "/xEF/xBB/xBF"); // foreach($csv as $key => $value){ // //mb_convert_variables('SJIS-win', 'UTF-8', $value); // //$value = mb_convert_encoding($value, 'UTF-16LE', 'utf-8'); // fputcsv($res, $value); // } fclose($res); $buy_num['0'] = array("チーム名", "参加会場", "購入部数"); foreach($teams as $key => $value){ $buy_num[] = array($value['team_name'], $value['venue'], $value['buy_num']); } $buy_num_name = "buy_num.csv"; $buy_num_file = CSV_DIR."/".$buy_num_name; $res = fopen($buy_num_file, 'wb'); writeCSVFileOutput($res, $buy_num); // fputcsv($res,pack('C*',0xFE,0xFF)); // fwrite($res, "/xEF/xBB/xBF"); // foreach($buy_num as $key => $value){ // //mb_convert_variables('SJIS-win', 'UTF-8', $value); // //$value = mb_convert_encoding($value, 'UTF-16LE', 'utf-8'); // fputcsv($res, $value); // } fclose($res); $zip_name = "print.zip"; $zip_path = ZIP_DIR."/print.zip"; $zip = new ZipArchive(); // ZIPファイルをオープン $res = $zip->open($zip_path, ZipArchive::CREATE); // zipファイルのオープンに成功した場合 if($res === true){ $zip->addEmptyDir("img"); // 圧縮するファイルを指定する $zip->addFile($csv_file, $file_name); $zip->addFile($csv_address_file, $file_address_name); $zip->addFile($buy_num_file, $buy_num_name); $zip->addFile(PDF_DIR."pamphlet".$tournament['organizer_id']."-".$tournament_id.".pdf", "pamphlet".$tournament['organizer_id']."-".$tournament_id.".pdf"); foreach($img_list as $key => $value){ $zip->addFile(IMAGE_DIR.'/'.$value, "img/".$value); } // ZIPファイルをクローズ $zip->close(); } header("Content-Type: application/octet-stream"); header("Content-Disposition: attachment; filename=".$zip_name); header("Content-Transfer-Encoding: binary"); header("Content-Length: " . filesize($zip_path)); readfile($zip_path); unlink($zip_path); unlink($csv_file); unlink($csv_address_file); unlink($buy_num_file); set_time_limit(86400); ini_set('memory_limit', "256M"); ?>