"y") { exit; } //アクション格納 $actiondata = dbselect("action_name,action_cd","`action`","action_cd ='".$_GET["cd"]."'",-1,-1); //顧客種別 $typedata = dbselect("type_name,customer_type_id","`customer_type`","customer_type_id ='".$_GET["type"]."'",-1,-1); //ファイル名 $strcsvtitle = Sjis(date("Y-m-d_").$_GET["type"]."_".$_GET["cd"]."_".$_GET["day"]."_".$typedata[0][0]."_".$actiondata[0][0].".csv"); //顧客種別 $strsqlwhere = " AND customer_type_id = '".$_GET["type"]."' "; //経過日 $strsqlwhere .= " AND customer_action_day = '".$_GET["day"]."' "; //並び if ($_GET["kind"] <> "call") { //DMリスト $strsqlorder = " ORDER BY address1,postcode,customerid"; } else { //CALLリスト $strsqlorder = " ORDER BY buy_last desc,customerid"; } //LOG用SQL $strsqlx = "INSERT INTO customer_handle_dl( `customerid`, `handle_kbn`, `handle_date`, `customer_type_id`, `action_cd`, `customer_action_day`, `creater`, `createdate`) SELECT `customerid`, 1, curdate(), '".$_GET["type"]."', '".$_GET["cd"]."', '".$_GET["day"]."', '".$userdata["tid"]."', now() FROM customer WHERE customer_action_flg <= 1 ".$strsqlwhere.$strsqlorder; $result=@mysql_query($strsqlx,$my_con); //抽出用SQL $strsql = "SELECT customerid,postcode,ken.kenname,concat(address2,ifnull(address3,''),' ',ifnull(address4,'')) as ad,concat(ifnull(custname1,''),' ',ifnull(custname2,'')) as name FROM customer INNER JOIN ken on(customer.address1 = ken.kenid) WHERE customer_action_flg <= 1 ".$strsqlwhere.$strsqlorder; //ダウンロード header("Content-type:application/octet-stream"); header("Content-Disposition:attachment;filename=$strcsvtitle"); header("Connection: close"); ob_end_clean(); echo Sjis("\"郵便番号\",\"都道府県\",\"住所\",\"氏名\",\"顧客ID\",\"印刷用ID\"\r\n"); #データ取得 $result=@mysql_query($strsql,$my_con); while ($data = mysql_fetch_array($result)) { echo Sprint($data["postcode"]); echo Sprint($data["kenname"]); echo Sprint($data["ad"]); echo Sprint($data["name"]." 様"); echo Sprint($data["customerid"]); echo "100".mb_substr($data["customerid"],4,4); echo "\r\n"; } if ($_GET["kind"] <> "call") { // アウトバウンドコール以外であれば、顧客アクションフラグを更新 0から1へ $strsql = "UPDATE customer SET customer_action_flg = 1,updater = '".$userdata["tid"]."' WHERE customer_action_flg = 0 ".$strsqlwhere; $result=@mysql_query($strsql,$my_con); mysql_sql_log($strsql,mysql_affected_rows(),$_SERVER['SCRIPT_NAME'].":".__LINE__); } myclose(); Function Sprint($str) { if($str == "0" ) { echo "\"0\","; } else { echo "\"".Sjis($str)."\","; } } ?>