function download_csv_file($gc) { $crlf = "\r\n"; $rank = fdiv_set_rank_array(); $file_str = ""; unset($line); if($_GET["company_no"]){$company_no_f = $_GET["company_no"];} else{$company_no_f = 0;} $line[] = csv_item_edit("都道府県コード"); $line[] = csv_item_edit("都道府県名"); $line[] = csv_item_edit("市区町村コード"); $line[] = csv_item_edit("市区町村名"); $line[] = csv_item_edit("ランク"); $sql = "SELECT SQL_CALC_FOUND_ROWS"; $sql.= " company_no,"; $sql.= " company_nm "; $sql.= "FROM"; $sql.= " m_company "; if($company_no_f > 0){ $sql.= "WHERE"; $sql.= " company_no='".$company_no_f."' "; } if($company_no_f == 0){ $sql.= "WHERE keisai_flg='1' "; $sql.= "ORDER BY"; $sql.= " company_no"; } $rs = $gc->db->query($sql); $ccnt = 0; while ($rs->eof==false) { $company_no_arr[$ccnt] = $rs->fields["company_no"]; $company_nm = $rs->fields["company_nm"]; $line[] = csv_item_edit("会社コード"); $line[] = csv_item_edit($company_nm); $ccnt++; $rs->move_next(); } $rs->free_result(); $file_str.= implode(",", $line).$crlf; $sql = "SELECT SQL_CALC_FOUND_ROWS"; $sql.= " t.todoufuken_no,"; $sql.= " t.todoufuken_nm,"; $sql.= " s.shikucyouson_no,"; $sql.= " s.shikucyouson_nm,"; $sql.= " s.rank_no"; for ($i=0; $i<$ccnt; $i++) { $sql.= ", cad".$i.".shikucyouson_kingaku as csk_".$i." "; } $sql.= "FROM"; $sql.= " m_shikucyouson s "; $sql.= "INNER JOIN"; $sql.= " m_todoufuken t "; $sql.= "ON"; $sql.= " s.todoufuken_no = t.todoufuken_no "; for ($i=0; $i<$ccnt; $i++) { $sql.= "left JOIN"; $sql.= " (select company_no,shikucyouson_no,shikucyouson_kingaku from m_company_area where company_no=".$company_no_arr[$i].") cad".$i; $sql.= " ON "; $sql.= " cad".$i.".shikucyouson_no = s.shikucyouson_no "; } $sql.= "WHERE s.rank_no > 0 "; $sql.= "ORDER BY"; $sql.= " t.todoufuken_no, s.shikucyouson_no"; $rs = $gc->db->query($sql); $row_count = $gc->db->get_row_count(); $i = 0; while ($rs->eof==false) { unset($line); $todoufuken_no = $rs->fields["todoufuken_no"]; $todoufuken_nm = $rs->fields["todoufuken_nm"]; $shikucyouson_no = $rs->fields["shikucyouson_no"]; $shikucyouson_nm = $rs->fields["shikucyouson_nm"]; $company_no = $rs->fields["company_no"]; $company_nm = $rs->fields["company_nm"]; $rank_no = $rs->fields["rank_no"]; // $shikucyouson_kingaku = $rs->fields["shikucyouson_kingaku"]; $line[] = csv_item_edit($todoufuken_no); $line[] = csv_item_edit($todoufuken_nm); $line[] = csv_item_edit($shikucyouson_no); $line[] = csv_item_edit($shikucyouson_nm); $line[] = csv_item_edit($rank[$rank_no]); for ($i=0; $i<$ccnt; $i++) { $line[] = csv_item_edit($company_no_arr[$i]); if($rs->fields["csk_".$i] == ""){ $line[] = csv_item_edit("0"); }else{ $line[] = csv_item_edit($rs->fields["csk_".$i]); } } $file_str.= implode(",", $line).$crlf; $rs->move_next(); $i++; } $rs->free_result(); $file_str = mb_convert_encoding($file_str, "sjis-win", C_ENCODING); $file_length = strlen($file_str); $file_name = "company_area"; if($company_no_f > 0){$file_name .= "_".$company_no_f;} header("Content-Disposition: attachment; filename=".$file_name.".csv"); header("Content-Length:".$file_length); header("Content-Type: application/octet-stream"); echo $file_str; return true; }
function out_data($gc,$file_str) { $sql =" SELECT"; $sql.=" l.property_no"; $sql.=" , l.property_nm"; $sql.=" , l.todoufuken_no"; $sql.=" , l.todoufuken_nm"; $sql.=" , l.shikucyouson_no"; $sql.=" , l.shikucyouson_nm"; $sql.=" , l.town_nm"; $sql.=" , l.address"; $sql.=" , l.comment"; $sql.=" , r.railroad"; $sql.=" , r.station"; $sql.=" , d.rent"; $sql.=" , d.unit_price"; $sql.=" , d.tijyokaisu"; $sql.=" , d.tikakaisu"; $sql.=" , k.name as kouzou "; $sql.=" FROM propertylist l "; $sql.=" LEFT JOIN ( "; $sql.=" SELECT"; $sql.=" property_no"; $sql.=" , avg(rent) as rent"; $sql.=" , avg(unit_price) as unit_price"; $sql.=" , max(tijyokaisu) as tijyokaisu"; $sql.=" , max(tikakaisu) as tikakaisu "; $sql.=" FROM propertydetail "; $sql.=" GROUP BY property_no ) d "; $sql.=" ON d.property_no = l.property_no "; $sql.=" LEFT JOIN ( "; $sql.=" SELECT"; $sql.=" no"; $sql.=" ,d.property_no"; $sql.=" , railroad"; $sql.=" , station"; $sql.=" , kouzou"; $sql.=" FROM propertydetail d"; $sql.=" INNER JOIN"; $sql.=" ("; $sql.=" SELECT min(no) as detail_no, property_no"; $sql.=" FROM propertydetail "; $sql.=" GROUP BY property_no"; $sql.=" ORDER BY property_no"; $sql.=" ) a"; $sql.=" ON a.detail_no = d.no"; $sql.=" ) r "; $sql.=" ON r.property_no = l.property_no "; $sql.=" LEFT JOIN m_kouzou k "; $sql.=" ON k.no = r.kouzou "; if($_GET["shikucyouson_no"] > 0){ $sql.=" WHERE l.shikucyouson_no = ".$_GET["shikucyouson_no"]; } $sql.=" ORDER BY l.todoufuken_no , l.shikucyouson_no, l.town_nm"; $rs = $gc->db->query($sql); $file_str=$file_str."都道府県名,所在地名1,所在地名2,所在地名3,建物名,沿線略称(1),駅名(1),平均賃料,平均㎡単価,建物構造,地上階層,地下階層,コメント,\r\n"; $i = 0; while ($rs->eof==false) { $property_nm = csv_item_edit($rs->fields["property_nm"]); $todoufuken_nm = csv_item_edit($rs->fields["todoufuken_nm"]); $shikucyouson_nm = csv_item_edit($rs->fields["shikucyouson_nm"]); $town_nm = csv_item_edit($rs->fields["town_nm"]); $address = csv_item_edit("A".$rs->fields["address"]); $comment = csv_item_edit($rs->fields["comment"]); $railroad = csv_item_edit($rs->fields["railroad"]); $station = csv_item_edit($rs->fields["station"]); $kouzou = csv_item_edit($rs->fields["kouzou"]); $tijyokaisu= csv_item_edit($rs->fields["tijyokaisu"]); $tikakaisu = csv_item_edit($rs->fields["tikakaisu"]); $rent = csv_item_edit($rs->fields["rent"]); $unit_price = csv_item_edit($rs->fields["unit_price"]); $file_str=$file_str.$todoufuken_nm.",".$shikucyouson_nm.",".$town_nm.",".$address.",".$property_nm.",". $railroad.",".$station.",".$rent.",".$unit_price.",".$kouzou.",".$tijyokaisu.",".$tikakaisu.",".$comment."\r\n"; $rs->move_next(); } $rs->free_result(); return $file_str; }
function download_csv($gc) { $crlf = "\r\n"; $arr_todoufuken = fsel_get_arr_todoufuken($gc); $arr_purpose_arr = fdiv_set_purpose_array(); $arr_buken_sbt = fdiv_set_buken_sbt_array(); $arr_madori = fdiv_set_madori_array(); $arr_meigi = fdiv_set_meigi_array(); $arr_genjyou = fdiv_set_genjyou_array(); $arr_rank = fdiv_set_rank_array(); $file_str = ""; unset($line); $line[] = csv_item_edit("案件番号"); $line[] = csv_item_edit("申込日時"); $line[] = csv_item_edit("ご利用目的"); $line[] = csv_item_edit("希望のサービス"); $line[] = csv_item_edit("物件種別"); $line[] = csv_item_edit("物件所在地"); $line[] = csv_item_edit("町名・番地"); $line[] = csv_item_edit("建物名・部屋番号"); $line[] = csv_item_edit("築年数"); $line[] = csv_item_edit("面積"); $line[] = csv_item_edit("間取り"); $line[] = csv_item_edit("名義"); $line[] = csv_item_edit("現況"); $line[] = csv_item_edit("お名前"); $line[] = csv_item_edit("フリガナ"); $line[] = csv_item_edit("電話番号"); $line[] = csv_item_edit("メールアドレス"); $line[] = csv_item_edit("お住まい"); $line[] = csv_item_edit("町名・番地"); $line[] = csv_item_edit("建物名・部屋番号"); $line[] = csv_item_edit("ご要望・ご質問など"); $line[] = csv_item_edit("ランク"); // $line[] = csv_item_edit("手数料"); $file_str.= implode(",", $line).$crlf; ///////////////////////////////////////////////////////////// $sql = "SELECT SQL_CALC_FOUND_ROWS"; $sql.= " itm.item_no,"; $sql.= " itm.anken_no,"; $sql.= " itm.relocation_flg,"; $sql.= " itm.chintai_flg,"; $sql.= " itm.sublease_flg,"; $sql.= " itm.purpose_flg,"; $sql.= " itm.buken_sbt,"; $sql.= " itm.buken_shikucyouson_no,"; $sql.= " itm.buken_banchi,"; $sql.= " itm.buken_tatemono,"; $sql.= " itm.chikunensu,"; $sql.= " itm.menseki,"; $sql.= " itm.input_val,"; $sql.= " itm.input_kbn,"; $sql.= " itm.land_val,"; $sql.= " itm.madori_no,"; $sql.= " itm.meigi_no,"; $sql.= " itm.genjyou_no,"; $sql.= " itm.room_cnt,"; $sql.= " itm.fudousan_flg,"; $sql.= " itm.fudousan_nm,"; $sql.= " itm.bikou,"; $sql.= " itm.lname,"; $sql.= " itm.fname,"; $sql.= " itm.lname_kn,"; $sql.= " itm.fname_kn,"; $sql.= " itm.tel,"; $sql.= " itm.e_mail,"; $sql.= " itm.sumai_flg,"; $sql.= " itm.sumai_shikucyouson_no,"; $sql.= " itm.sumai_banchi,"; $sql.= " itm.sumai_tatemono,"; $sql.= " itm.moushikomibi,"; $sql.= " itm.rank_no,"; $sql.= " itm.tesuryou,"; $sql.= " itm.mukou_flg,"; $sql.= " itc.c_mukou_flg,"; $sql.= " itc.company_no,"; $sql.= " ad1.todoufuken_no AS buken_todoufuken_no,"; $sql.= " ad1.shikucyouson_nm AS buken_shikucyouson_nm,"; $sql.= " ad2.todoufuken_no AS sumai_todoufuken_no,"; $sql.= " ad2.shikucyouson_nm AS sumai_shikucyouson_nm,"; $sql.= " mco.company_no,"; $sql.= " mco.company_nm "; $sql.= "FROM"; $sql.= " t_item itm "; $sql.= "INNER JOIN"; $sql.= " t_item_company itc "; $sql.= "ON"; $sql.= " itm.item_no = itc.item_no "; $sql.= "INNER JOIN"; $sql.= " m_company mco "; $sql.= "ON"; $sql.= " itc.company_no = mco.company_no "; $sql.= "LEFT JOIN"; $sql.= " m_shikucyouson ad1 "; $sql.= "ON"; $sql.= " itm.buken_shikucyouson_no = ad1.shikucyouson_no "; $sql.= "LEFT JOIN"; $sql.= " m_shikucyouson ad2 "; $sql.= "ON"; $sql.= " itm.sumai_shikucyouson_no = ad2.shikucyouson_no "; $sql.= "WHERE itc.c_mukou_flg = 0 and itc.company_no=".$gc->login_company_no." "; $sql.= "ORDER BY"; $sql.= " itm.moushikomibi DESC, mco.company_no"; $rs = $gc->db->query($sql); $row_count = $gc->db->get_row_count(); $i = 0; $wk_item_no = ""; $arr_company_nm = array(); while ($rs->eof==false) { $item_no = $rs->fields["item_no"]; if($item_no != $wk_item_no){ $wk_item_no = $item_no; if( $i > 0 ){ unset($line); $line[] = csv_item_edit($anken_no); $line[] = csv_item_edit($moushikomibi); $line[] = csv_item_edit($purpose_str); $line[] = csv_item_edit($kibou_str); $line[] = csv_item_edit($buken_sbt_nm); $line[] = csv_item_edit($buken_todoufuken_nm.$buken_shikucyouson_nm); $line[] = csv_item_edit($buken_banchi); $line[] = csv_item_edit($buken_tatemono); $line[] = csv_item_edit($chikunensu); $line[] = csv_item_edit($menseki); $line[] = csv_item_edit($madori_nm); $line[] = csv_item_edit($meigi_nm); $line[] = csv_item_edit($genjyou_nm); $line[] = csv_item_edit($lname.$fname); $line[] = csv_item_edit($lname_kn.$fname_kn); $line[] = csv_item_edit($tel); $line[] = csv_item_edit($e_mail); $line[] = csv_item_edit($sumai_todoufuken_nm.$sumai_shikucyouson_nm); $line[] = csv_item_edit($sumai_banchi); $line[] = csv_item_edit($sumai_tatemono); $line[] = csv_item_edit($bikou); $line[] = csv_item_edit($rank_nm); // $line[] = csv_item_edit($tesuryou); $file_str.= implode(",", $line).$crlf; $arr_company_nm = array(); } // -------------------------------------------------------------------- $anken_no = $rs->fields["anken_no"]; $relocation_flg = $rs->fields["relocation_flg"]; $chintai_flg = $rs->fields["chintai_flg"]; $sublease_flg = $rs->fields["sublease_flg"]; $purpose_flg = $rs->fields["purpose_flg"]; $buken_sbt = $rs->fields["buken_sbt"]; $buken_shikucyouson_no = $rs->fields["buken_shikucyouson_no"]; $buken_banchi = $rs->fields["buken_banchi"]; $buken_tatemono = $rs->fields["buken_tatemono"]; $chikunensu = $rs->fields["chikunensu"]; $menseki = $rs->fields["menseki"]; $input_val = $rs->fields["input_val"]; $input_kbn = $rs->fields["input_kbn"]; $land_val = $rs->fields["land_val"]; $madori_no = $rs->fields["madori_no"]; $meigi_no = $rs->fields["meigi_no"]; $genjyou_no = $rs->fields["genjyou_no"]; $room_cnt = $rs->fields["room_cnt"]; $fudousan_flg = $rs->fields["fudousan_flg"]; $fudousan_nm = $rs->fields["fudousan_nm"]; $bikou = $rs->fields["bikou"]; $lname = $rs->fields["lname"]; $fname = $rs->fields["fname"]; $lname_kn = $rs->fields["lname_kn"]; $fname_kn = $rs->fields["fname_kn"]; $tel = $rs->fields["tel"]; $e_mail = $rs->fields["e_mail"]; $sumai_flg = $rs->fields["sumai_flg"]; $sumai_shikucyouson_no = $rs->fields["sumai_shikucyouson_no"]; $sumai_banchi = $rs->fields["sumai_banchi"]; $sumai_tatemono = $rs->fields["sumai_tatemono"]; $moushikomibi = $rs->fields["moushikomibi"]; $rank_no = $rs->fields["rank_no"]; $tesuryou = $rs->fields["tesuryou"]; $mukou_flg = $rs->fields["mukou_flg"]; $purpose_str = $arr_purpose_arr[$purpose_flg]; $arr_work = array(); if($chintai_flg == 1){ $arr_work[] = "賃貸募集・賃貸管理"; } if($sublease_flg == 1) { $arr_work[] = "サブリース"; } if($relocation_flg == 1) { $arr_work[] = "リロケーション"; } $kibou_str = implode(" ", $arr_work); $buken_sbt_nm = $arr_buken_sbt[$buken_sbt]; $madori_nm = $arr_madori[$madori_no]; $meigi_nm = $arr_meigi[$meigi_no]; $genjyou_nm = $arr_genjyou[$genjyou_no]; if($room_cnt > 0){ $genjyou_nm = $genjyou_nm." 空き部屋数 ".$room_cnt; } $buken_todoufuken_no = $rs->fields["buken_todoufuken_no"]; $buken_todoufuken_nm = $arr_todoufuken[$buken_todoufuken_no]; $buken_shikucyouson_nm = $rs->fields["buken_shikucyouson_nm"]; $sumai_todoufuken_no = $rs->fields["sumai_todoufuken_no"]; $sumai_todoufuken_nm = $arr_todoufuken[$sumai_todoufuken_no]; $sumai_shikucyouson_nm = $rs->fields["sumai_shikucyouson_nm"]; $rank_nm = $arr_rank[$rank_no]; $mukou_str = "有効"; if($mukou_flg==1){ $mukou_str = "無効"; } } $arr_company_nm[] = $rs->fields["company_nm"]; $rs->move_next(); $i++; } $rs->free_result(); // ---------------------------------------------------------------- unset($line); $line[] = csv_item_edit($anken_no); $line[] = csv_item_edit($moushikomibi); $line[] = csv_item_edit($purpose_str); $line[] = csv_item_edit($kibou_str); $line[] = csv_item_edit($buken_sbt_nm); $line[] = csv_item_edit($buken_todoufuken_nm.$buken_shikucyouson_nm); $line[] = csv_item_edit($buken_banchi); $line[] = csv_item_edit($buken_tatemono); $line[] = csv_item_edit($chikunensu); $line[] = csv_item_edit($menseki); $line[] = csv_item_edit($madori_nm); $line[] = csv_item_edit($meigi_nm); $line[] = csv_item_edit($genjyou_nm); $line[] = csv_item_edit($lname.$fname); $line[] = csv_item_edit($lname_kn.$fname_kn); $line[] = csv_item_edit($tel); $line[] = csv_item_edit($e_mail); $line[] = csv_item_edit($sumai_todoufuken_nm.$sumai_shikucyouson_nm); $line[] = csv_item_edit($sumai_banchi); $line[] = csv_item_edit($sumai_tatemono); $line[] = csv_item_edit($bikou); $line[] = csv_item_edit($rank_nm); // $line[] = csv_item_edit($tesuryou); $file_str.= implode(",", $line).$crlf; // ---------------------------------------------------------------- $file_str = mb_convert_encoding($file_str, "sjis-win", C_ENCODING); $file_length = strlen($file_str); $file_name = "案件.csv"; $agent = $_SERVER['HTTP_USER_AGENT']; if(strstr($agent, "MSIE")){ $file_name = urlencode($file_name); } header("Content-Disposition: attachment; filename=".$file_name); header("Content-Length:".$file_length); header("Content-Type: application/octet-stream"); echo $file_str; return true; }
function download_csv_file2($gc) { $crlf = "\r\n"; $arr_todoufuken = fsel_get_arr_todoufuken($gc); $rank = fdiv_set_rank_array(); $file_str = ""; unset($line); $line[] = csv_item_edit("案件番号"); $line[] = csv_item_edit("申込日"); $line[] = csv_item_edit("種別"); $line[] = csv_item_edit("延床面積(平米)"); $line[] = csv_item_edit("ランク"); $line[] = csv_item_edit("都道府県"); $line[] = csv_item_edit("市区町村"); $line[] = csv_item_edit("有効"); $line[] = csv_item_edit("無効"); $line[] = csv_item_edit("手数料"); $file_str.= implode(",", $line).$crlf; ///////////////////////////////////////////////////////////// $gc->mbif = $_GET["mbif"]; $y = substr($gc->mbif, 0, 4); $m = substr($gc->mbif, 4, 2); $d = substr($gc->mbif, 6, 4); if(!@checkdate($m, $d, $y)){ $gc->mbif = date("Ym01", time()); } $gc->mbit = $_GET["mbit"]; $y = substr($gc->mbit, 0, 4); $m = substr($gc->mbit, 4, 2); $d = substr($gc->mbit, 6, 4); if(!@checkdate($m, $d, $y)){ $gc->mbit = date("Ymt", time()); } $gc->company_no = $_GET["company_no"]; if(!is_numeric($gc->company_no)){ $gc->company_no = 0; } $gc->company_nm = fdb_get_name($gc, "m_company", "company_nm", "company_no", $gc->company_no); $arr_todoufuken = fsel_get_arr_todoufuken($gc); $arr_buken_sbt = fdiv_set_buken_sbt_array(); $arr_rank = fdiv_set_rank_array(); $sql = sql_text_create_d_csv($gc); $sql.= " p.item_no"; $rs = $gc->db->query($sql); $row_count = $gc->db->get_row_count(); $i = 0; while ($rs->eof==false) { unset($line); $item_no = $rs->fields["item_no"]; $anken_no = $rs->fields["anken_no"]; $buken_sbt = $rs->fields["buken_sbt"]; $menseki = $rs->fields["menseki"]; $purpose_flg = $rs->fields["purpose_flg"]; $rank_no = get_rank_d($rs); // $rank_no = $rs->fields["rank_no"]; $todoufuken_no = $rs->fields["todoufuken_no"]; $buken_shikucyouson_no = $rs->fields["buken_shikucyouson_no"]; $shikucyouson_nm = $rs->fields["shikucyouson_nm"]; $mukou_flg = $rs->fields["mukou_flg"]; $m_cnt = $rs->fields["m_cnt"]; $y_cnt = $rs->fields["y_cnt"]; $tesuryou = get_tesuryo_d($rs); // $tesuryou = $rs->fields["tesuryou"]; $moushikomibi = $rs->fields["moushikomibi"]; $moushikomi_d = substr($moushikomibi, 0, 4)."/".substr($moushikomibi, 5, 2)."/".substr($moushikomibi, 8, 2); $todoufuken_nm = $arr_todoufuken[$todoufuken_no]; $buken_sbt_nm = $arr_buken_sbt[$buken_sbt]; if($rank_no != "L"){ $rank_nm = $arr_rank[$rank_no]; }else{ $rank_nm = "L"; } /* if($purpose_flg == 1){ $rank_nm = "L"; } */ $line[] = csv_item_edit($anken_no); $line[] = csv_item_edit($moushikomi_d); $line[] = csv_item_edit($buken_sbt_nm); $line[] = csv_item_edit($menseki); $line[] = csv_item_edit($rank_nm); $line[] = csv_item_edit($todoufuken_nm); $line[] = csv_item_edit($shikucyouson_nm); $line[] = csv_item_edit($y_cnt); $line[] = csv_item_edit($m_cnt); // $line[] = csv_item_edit($mukou_flg==1?"無効":"有効"); $line[] = csv_item_edit( ( $mukou_flg==1?"0":$tesuryou ) ); // $line[] = csv_item_edit( ( $mukou_flg==1?"0":number_format($tesuryou) ) ); $file_str.= implode(",", $line).$crlf; $rs->move_next(); $i++; } $rs->free_result(); $file_str = mb_convert_encoding($file_str, "sjis-win", C_ENCODING); $file_length = strlen($file_str); $file_name = $gc->company_nm."(".substr($gc->mbif, 0, 4)."年".substr($gc->mbif, 4, 2)."月".substr($gc->mbif, 6, 2)."日から".substr($gc->mbit, 0, 4)."年".substr($gc->mbit, 4, 2)."月".substr($gc->mbit, 6, 2).").csv"; $agent = $_SERVER['HTTP_USER_AGENT']; if(strstr($agent, "MSIE")){ $file_name = urlencode($file_name); } header("Content-Disposition: attachment; filename=".$file_name); header("Content-Length:".$file_length); header("Content-Type: application/octet-stream"); echo $file_str; return true; }
function download_csv_file($gc) { $crlf = "\r\n"; $rank = fdiv_set_rank_array(); $file_str = ""; unset($line); if($_GET["company_no"]){$company_no_f = $_GET["company_no"];} else{$company_no_f = 0;} $line[] = csv_item_edit("都道府県コード"); $line[] = csv_item_edit("都道府県名"); $line[] = csv_item_edit("市区町村コード"); $line[] = csv_item_edit("市区町村名"); $line[] = csv_item_edit("ランク"); $sql = "SELECT SQL_CALC_FOUND_ROWS"; $sql.= " company_no,"; $sql.= " company_nm "; $sql.= "FROM"; $sql.= " m_company "; if($company_no_f > 0){ $sql.= "WHERE"; $sql.= " company_no='".$company_no_f."' "; } if($company_no_f == 0){//★★★ 抽出条件注意 ★★★ ★★★ 抽出条件注意 ★★★ ★★★ 抽出条件注意 ★★★ $sql.= "WHERE keisai_flg='1' OR company_no=9 "; $sql.= "ORDER BY"; $sql.= " company_no"; } $rs = $gc->db->query($sql); $ccnt = 0; while ($rs->eof==false) { $company_no_arr[$ccnt] = $rs->fields["company_no"]; $company_nm = $rs->fields["company_nm"]; $line[] = csv_item_edit($company_nm."(件数)"); $line[] = csv_item_edit($company_nm."(手数料)"); $ccnt++; $rs->move_next(); } $rs->free_result(); $line[] = csv_item_edit("合計(件数)"); $line[] = csv_item_edit("合計(手数料)"); $file_str.= implode(",", $line).$crlf; $sql = "SELECT SQL_CALC_FOUND_ROWS"; $sql.= " t.todoufuken_no,"; $sql.= " t.todoufuken_nm,"; $sql.= " s.shikucyouson_no,"; $sql.= " s.shikucyouson_nm,"; $sql.= " s.rank_no"; for ($i=0; $i<$ccnt; $i++) { $sql.= ", cad".$i.".com_count as cmc_".$i." "; $sql.= ", cad".$i.".shikucyouson_kingaku as csk_".$i." "; } $sql.= "FROM"; $sql.= " m_shikucyouson s "; $sql.= "INNER JOIN"; $sql.= " m_todoufuken t "; $sql.= "ON"; $sql.= " s.todoufuken_no = t.todoufuken_no "; for ($i=0; $i<$ccnt; $i++) { $sql.= "left JOIN"; $sql.= " ("; $sql.= " SELECT"; $sql.= " ic.company_no,"; $sql.= " im.buken_shikucyouson_no AS shikucyouson_no,"; $sql.= " COUNT(ic.company_no) AS com_count,"; $sql.= " SUM(it.tesuryou) AS shikucyouson_kingaku"; $sql.= " FROM"; $sql.= " t_item im"; $sql.= " INNER JOIN"; $sql.= " t_item_company ic"; $sql.= " ON"; $sql.= " im.item_no = ic.item_no"; $sql.= " INNER JOIN"; $sql.= " t_tesuryou it"; $sql.= " ON"; $sql.= " ic.item_no = it.item_no AND"; $sql.= " ic.company_no = it.company_no"; $sql.= " WHERE"; $sql.= " im.mukou_flg = 0 AND"; $sql.= " ic.c_mukou_flg = 0 AND";//★★★ 抽出条件注意 ★★★ ★★★ 抽出条件注意 ★★★ ★★★ 抽出条件注意 ★★★ $sql.= " im.moushikomibi BETWEEN '2015-10-01 00:00:00' AND '2015-11-08 23:59:59' AND"; $sql.= " ic.company_no = ".$company_no_arr[$i]; $sql.= " GROUP BY"; $sql.= " ic.company_no,"; $sql.= " im.buken_shikucyouson_no"; $sql.= " ) cad".$i; $sql.= " ON "; $sql.= " cad".$i.".shikucyouson_no = s.shikucyouson_no "; } $sql.= "WHERE s.rank_no > 0 "; $sql.= "ORDER BY"; $sql.= " t.todoufuken_no, s.shikucyouson_no"; $rs = $gc->db->query($sql); $row_count = $gc->db->get_row_count(); $i = 0; while ($rs->eof==false) { unset($line); $todoufuken_no = $rs->fields["todoufuken_no"]; $todoufuken_nm = $rs->fields["todoufuken_nm"]; $shikucyouson_no = $rs->fields["shikucyouson_no"]; $shikucyouson_nm = $rs->fields["shikucyouson_nm"]; $company_no = $rs->fields["company_no"]; $company_nm = $rs->fields["company_nm"]; $rank_no = $rs->fields["rank_no"]; // $shikucyouson_kingaku = $rs->fields["shikucyouson_kingaku"]; $cmc_kei = 0; $csk_kei = 0; $line[] = csv_item_edit($todoufuken_no); $line[] = csv_item_edit($todoufuken_nm); $line[] = csv_item_edit($shikucyouson_no); $line[] = csv_item_edit($shikucyouson_nm); $line[] = csv_item_edit($rank[$rank_no]); for ($i=0; $i<$ccnt; $i++) { if($rs->fields["csk_".$i] == ""){ $line[] = csv_item_edit("0"); $line[] = csv_item_edit("0"); }else{ $line[] = csv_item_edit($rs->fields["cmc_".$i]); $line[] = csv_item_edit($rs->fields["csk_".$i]); $cmc_kei += $rs->fields["cmc_".$i]; $csk_kei += $rs->fields["csk_".$i]; } } $line[] = csv_item_edit($cmc_kei); $line[] = csv_item_edit($csk_kei); $file_str.= implode(",", $line).$crlf; $rs->move_next(); $i++; } $rs->free_result(); $file_str = mb_convert_encoding($file_str, "sjis-win", C_ENCODING); $file_length = strlen($file_str); $file_name = "company_area_tesuryou"; if($company_no_f > 0){$file_name .= "_".$company_no_f;} header("Content-Disposition: attachment; filename=".$file_name.".csv"); header("Content-Length:".$file_length); header("Content-Type: application/octet-stream"); echo $file_str; return true; }
function download_csv_file($gc) { $crlf = "\r\n"; $rank = fdiv_set_rank_array(); $file_str = ""; unset($line); $line[] = csv_item_edit("都道府県コード"); $line[] = csv_item_edit("都道府県名"); $line[] = csv_item_edit("市区町村コード"); $line[] = csv_item_edit("市区町村名"); $line[] = csv_item_edit("市区町村名カナ"); $line[] = csv_item_edit("ランク"); $file_str.= implode(",", $line).$crlf; $sql = "SELECT SQL_CALC_FOUND_ROWS"; $sql.= " t.todoufuken_no,"; $sql.= " t.todoufuken_nm,"; $sql.= " s.shikucyouson_no,"; $sql.= " s.shikucyouson_nm,"; $sql.= " s.shikucyouson_kn,"; $sql.= " s.rank_no "; $sql.= "FROM"; $sql.= " m_todoufuken t "; $sql.= "INNER JOIN"; $sql.= " m_shikucyouson s "; $sql.= "ON"; $sql.= " s.todoufuken_no = t.todoufuken_no "; $sql.= "ORDER BY"; $sql.= " t.todoufuken_no, s.shikucyouson_no"; $rs = $gc->db->query($sql); $row_count = $gc->db->get_row_count(); $i = 0; while ($rs->eof==false) { unset($line); $todoufuken_no = $rs->fields["todoufuken_no"]; $todoufuken_nm = $rs->fields["todoufuken_nm"]; $shikucyouson_no = $rs->fields["shikucyouson_no"]; $shikucyouson_nm = $rs->fields["shikucyouson_nm"]; $shikucyouson_kn = $rs->fields["shikucyouson_kn"]; $rank_no = $rs->fields["rank_no"]; $line[] = csv_item_edit($todoufuken_no); $line[] = csv_item_edit($todoufuken_nm); $line[] = csv_item_edit($shikucyouson_no); $line[] = csv_item_edit($shikucyouson_nm); $line[] = csv_item_edit($shikucyouson_kn); $line[] = csv_item_edit($rank[$rank_no]); $file_str.= implode(",", $line).$crlf; $rs->move_next(); $i++; } $rs->free_result(); $file_str = mb_convert_encoding($file_str, "sjis-win", C_ENCODING); $file_length = strlen($file_str); header("Content-Disposition: attachment; filename=area.csv"); header("Content-Length:".$file_length); header("Content-Type: application/octet-stream"); echo $file_str; return true; }