Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
config.gs
85 changes: 85 additions & 0 deletions contact/contact.gs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
function doPost(e) {
var response = {};

try {
// parameterを取得
var param = e.parameter;

// ファイルID
var FILE_ID = "xxxxxxxxxxxxxxxxxxxx";

// リストネーム
var LIST_NAME = "contact";

// spreadsheetを開く
var sheet = SpreadsheetApp.openById(FILE_ID).getSheetByName(LIST_NAME);

// 今の日付取得
var now = Utilities.formatDate(new Date(), 'Asia/Tokyo', 'yyyy/MM/dd HH:mm:ss');


// sheetに情報を追加
sheet.appendRow([param.name, param.affiliation, param.affiliation_kosen, param.affiliation_group, param.mail, param.inquiry, param.content, now]);

informContact(param, now);

response["success"] = "true";
response["message"] = "";
}
catch (error) {
response["success"] = "false";
var error_message = {};
error_message["name"] = error.name;
error_message["resource"] = error.fileName + "(Line " + error.lineNumber + ")";
error_message["message"] = error.message;
error_message["stack"] = error.stack;
response["message"] = error_message;
errorMail(response);
}

var output = ContentService.createTextOutput();
output.setMimeType(ContentService.MimeType.JSON);
output.setContent(JSON.stringify(response));

return output;
}


// お問い合わせメール通知
function informContact(param, now){
var values = SpreadsheetApp.openById('xxxxxxxxxxxxxxxxx').getSheets()[0].getDataRange().getValues();
var address = [];
for (var i = 1; i < values.length; i++) {
address.push(values[i][0]);
}
address.push(param.mail);
var subject = '奈良高専吹奏楽部 | お問い合わせ';
var body = HtmlService.createTemplateFromFile("message_mail");
body.param = param;
body.now = now;
console.log(param);
Logger.log(param);
sendMail(param.mail, subject, body.evaluate().getContent(), address.join(","));
}

// メール送信
function sendMail(to, subject, mail_body, bcc){
GmailApp.sendEmail(
to,
subject,
'',
{
bcc: bcc,
name: '奈良高専吹奏楽部',
htmlBody: mail_body
}
);

}

// エラーメール送信
function errorMail(response){
var mailaddress = '[email protected]';
sendMail(mailaddress, 'error - contact', JSON.stringify(response), '');
}

38 changes: 38 additions & 0 deletions contact/message_mail.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<base target=”_top”>
</head>
<body>
<?= param.name ?> 様 <br><br>

<p>
お問い合わせありがとうございます.ご返信には1週間ほどかかる場合がございます.<br>
2週間以上経過しても返信がない場合,お手数をおかけしますが再度お問い合わせをしていただくか,
<strong>[email protected]</strong> までご連絡頂くようよろしくお願いいたします.
</p>
<br>

<h2>お問い合わせ内容</h2>

<h3>お名前</h3>
<p> <?= param.name ?> </p>

<h3>所属・団体名</h3>
<p> <?= param.affiliation ?> &emsp; <?= param.affiliation_kosen ?> &emsp; <?= param.affiliation_group ?></p>

<h3>メールアドレス</h3>
<p> <?= param.mail ?> </p>

<h3>お問い合わせ内容</h3>
<p> <?= param.inquiry ?> &emsp; <?= param.content ?> </p>

<br>
受付日:<?= now ?>
<br><br><br>
<p>
&copy; 2020- <a href="https://nitncwind.org/">奈良高専吹奏楽部</a>
</p>
</body>
</html>
52 changes: 52 additions & 0 deletions csv_cast.gs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// get処理
function doGet(e) {
// parameter取得
var params = e.parameter;

// パラメーター keyからファイルIDを取得
var file_id = convertP2f(params.key);

// 0(存在しない)ときは文字列返す
if (file_id == '0') {
return ContentService.createTextOutput().setMimeType(ContentService.MimeType.TEXT).setContent("404");
}

// CSVデータを取得
var csvData = convertSp2Csv(file_id);
var out = ContentService.createTextOutput().setMimeType(ContentService.MimeType.TEXT).setContent(csvData);
Logger.log(csvData);
return out;
}

// スプレッドシートをcsvに変換
function convertSp2Csv(file_id) {
var values = SpreadsheetApp.openById(file_id).getSheets()[0].getDataRange().getValues();
var data = [];
for (var i = 0; i < values.length; i++) {
data.push(values[i].join(","));
}
Logger.log(data.join("\r\n"));
return data.join("\r\n");
}

// Convert params to file
function convertP2f(key) {
switch(key) {
case 'about':
return ABOUT_CSV_ID;
case 'concerts':
return CONCERTS_CSV_ID;
case 'winds':
return WINDS_CSV_ID;
case 'ensemble':
return ENSEMBLE_CSV_ID;
case 'link':
return LINK_CSV_ID;
case 'contact':
return CONTACT_CSV_ID;
case 'news':
return NEWS_CSV_ID;
default:
return '0';
}
}