Refre email as actions
This commit is contained in:
@@ -2110,6 +2110,7 @@ long WrenchSendReferLoadLink(CVars in, CVars &out) {
|
||||
long WrenchSendRefer(CVars in, CVars &out) {
|
||||
logfmt(logINFO, "long WrenchSendRefer(CVars in, CVars out)");
|
||||
long ret = PHP_API_BAD_PARAM;
|
||||
CVars ml;
|
||||
try {
|
||||
//out = in;
|
||||
out["status"] = "";
|
||||
@@ -2164,7 +2165,14 @@ long WrenchSendRefer(CVars in, CVars &out) {
|
||||
const PGresult *res4 = pgsql_query("UPDATE members_refer_friend SET sent=now() WHERE id=%lu", refer_id);
|
||||
in["refer_id"] = refer_id;
|
||||
in["refer_id"].set_valid(true);
|
||||
account_email(ACCOUNT_SEND_REFEREMAIL, in, out); // ALERT REFER EMAIL
|
||||
|
||||
ml["action"] = ACCOUNT_SEND_REFEREMAIL; ml["action"].set_valid( true );
|
||||
ml["topic"] = "ACCOUNT_SEND_REFEREMAIL"; ml["topic"].set_valid( true );
|
||||
ml["refer_id"] = refer_id; ml["refer_id"].set_valid( true );
|
||||
//ml["interest_id"] = in["interest_id"]; ml["interest_id"].set_valid( true );
|
||||
submit_cron_email(ml);
|
||||
|
||||
// account_email(ACCOUNT_SEND_REFEREMAIL, in, out); // ALERT REFER EMAIL
|
||||
out["status"] = "Refer message sent";
|
||||
ret = PHP_API_OK;
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ extern int mailsend(CVars in, CVars &out);
|
||||
long CronWelcomeAccountMail(CVars in);
|
||||
long CronAccountPendingMail(CVars in) ;
|
||||
long CronJobEmail(long mailtype, CVars in, CVars &out);
|
||||
|
||||
long CronAccountMail(CVars in);
|
||||
/*
|
||||
|
||||
CREATE TABLE email_message(
|
||||
@@ -35,47 +35,22 @@ CREATE TABLE email_message(
|
||||
ADD CONSTRAINT email_message_id_key UNIQUE (id);
|
||||
*/
|
||||
|
||||
long submit_cron_email(CVars in){
|
||||
return insert_db_record( DBS_VALID, "email_message", "email_message_id_seq", in );
|
||||
}
|
||||
long submit_cron_email(CVars in){
|
||||
return insert_db_record( DBS_VALID, "email_message", "email_message_id_seq", in );
|
||||
}
|
||||
|
||||
long CronSendMail(CVars in, CVars &out){
|
||||
logfmt(logINFO, " ***** CALL long CronSendMail(CVars in, CVars &out)");
|
||||
long CronSendMail(CVars in, CVars &out){
|
||||
logfmt(logINFO, " ***** CALL long CronSendMail(CVars in, CVars &out)");
|
||||
|
||||
|
||||
|
||||
char vname[30];
|
||||
long ret = PHP_API_BAD_PARAM;
|
||||
|
||||
try {
|
||||
out["total_record"] = "0";
|
||||
const PGresult *res;
|
||||
res = pgsql_query("SELECT *, member_id AS pending_id FROM email_message WHERE topic ='WRENCHBOARD_ACCOUNT_PENDING' AND status = 1 ORDER BY id ASC LIMIT 20");
|
||||
|
||||
if (res != NULL && pgsql_num_rows(res) > 0) {
|
||||
out["total_record"] = pgsql_num_rows(res);
|
||||
|
||||
for (int i = 0, n = pgsql_num_rows(res); i < n; i++) {
|
||||
map<const char*, const char*>f = pgsql_fetch_assoc(res, i);
|
||||
if (f.empty()) continue;
|
||||
CVars rec;
|
||||
map_to_cvars(f, rec);
|
||||
pgsql_query("UPDATE email_message SET status = 2 WHERE id = %lu ", rec["id"].Long()); // move the status so no retry
|
||||
CronAccountPendingMail(rec); // send the cron email
|
||||
pgsql_query("UPDATE email_message SET status = 5, completed = now() WHERE id = %lu ", rec["id"].Long()); // move the status so no retry
|
||||
}
|
||||
}
|
||||
ret = PHP_API_OK;
|
||||
out["status"] = "OK";
|
||||
} catch (bad_parameter) {
|
||||
logfmt(logINFO, "ERROR CALL long WRENCHBOARD_ACCOUNT_LOGIN(CVars in, CVars &out)");
|
||||
}
|
||||
|
||||
char vname[30];
|
||||
long ret = PHP_API_BAD_PARAM;
|
||||
|
||||
try {
|
||||
out["total_record"] = "0";
|
||||
const PGresult *res;
|
||||
res = pgsql_query("SELECT * FROM email_message WHERE topic ='WRENCHBOARD_ACCOUNT_LOGIN' AND status = 1 ORDER BY id ASC LIMIT 20");
|
||||
res = pgsql_query("SELECT *, member_id AS pending_id FROM email_message WHERE topic ='WRENCHBOARD_ACCOUNT_PENDING' AND status = 1 ORDER BY id ASC LIMIT 20");
|
||||
|
||||
if (res != NULL && pgsql_num_rows(res) > 0) {
|
||||
out["total_record"] = pgsql_num_rows(res);
|
||||
@@ -86,7 +61,7 @@ CREATE TABLE email_message(
|
||||
CVars rec;
|
||||
map_to_cvars(f, rec);
|
||||
pgsql_query("UPDATE email_message SET status = 2 WHERE id = %lu ", rec["id"].Long()); // move the status so no retry
|
||||
CronWelcomeAccountMail(rec); // send the cron email
|
||||
CronAccountPendingMail(rec); // send the cron email
|
||||
pgsql_query("UPDATE email_message SET status = 5, completed = now() WHERE id = %lu ", rec["id"].Long()); // move the status so no retry
|
||||
}
|
||||
}
|
||||
@@ -97,38 +72,86 @@ CREATE TABLE email_message(
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
out["total_record"] = "0";
|
||||
const PGresult *res;
|
||||
res = pgsql_query("SELECT * FROM email_message "
|
||||
" WHERE topic IN ('JOBS_INDIVIDUAL_OFFER_MAIL', 'JOBS_OFFER_INTEREST_MAIL', 'JOBS_GROUP_OFFER_PUBLIC', 'JOBS_MESSAGE_ADDED') "
|
||||
" AND status = 1 ORDER BY id ASC LIMIT 20");
|
||||
try {
|
||||
out["total_record"] = "0";
|
||||
const PGresult *res;
|
||||
res = pgsql_query("SELECT * FROM email_message WHERE topic ='WRENCHBOARD_ACCOUNT_LOGIN' AND status = 1 ORDER BY id ASC LIMIT 20");
|
||||
|
||||
if (res != NULL && pgsql_num_rows(res) > 0) {
|
||||
out["total_record"] = pgsql_num_rows(res);
|
||||
if (res != NULL && pgsql_num_rows(res) > 0) {
|
||||
out["total_record"] = pgsql_num_rows(res);
|
||||
|
||||
for (int i = 0, n = pgsql_num_rows(res); i < n; i++) {
|
||||
map<const char*, const char*>f = pgsql_fetch_assoc(res, i);
|
||||
if (f.empty()) continue;
|
||||
CVars rec;
|
||||
map_to_cvars(f, rec);
|
||||
pgsql_query("UPDATE email_message SET status = 2 WHERE id = %lu ", rec["id"].Long()); // move the status so no retry
|
||||
CronJobEmail(rec["action"].Long(), rec, out); // send the cron email
|
||||
pgsql_query("UPDATE email_message SET status = 5, completed = now() WHERE id = %lu ", rec["id"].Long()); // move the status so no retry
|
||||
}
|
||||
for (int i = 0, n = pgsql_num_rows(res); i < n; i++) {
|
||||
map<const char*, const char*>f = pgsql_fetch_assoc(res, i);
|
||||
if (f.empty()) continue;
|
||||
CVars rec;
|
||||
map_to_cvars(f, rec);
|
||||
pgsql_query("UPDATE email_message SET status = 2 WHERE id = %lu ", rec["id"].Long()); // move the status so no retry
|
||||
CronWelcomeAccountMail(rec); // send the cron email
|
||||
pgsql_query("UPDATE email_message SET status = 5, completed = now() WHERE id = %lu ", rec["id"].Long()); // move the status so no retry
|
||||
}
|
||||
ret = PHP_API_OK;
|
||||
out["status"] = "OK";
|
||||
} catch (bad_parameter) {
|
||||
logfmt(logINFO, "ERROR CALL long WRENCHBOARD_ACCOUNT_LOGIN(CVars in, CVars &out)");
|
||||
}
|
||||
|
||||
|
||||
|
||||
return 0;
|
||||
ret = PHP_API_OK;
|
||||
out["status"] = "OK";
|
||||
} catch (bad_parameter) {
|
||||
logfmt(logINFO, "ERROR CALL long WRENCHBOARD_ACCOUNT_LOGIN(CVars in, CVars &out)");
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
out["total_record"] = "0";
|
||||
const PGresult *res;
|
||||
res = pgsql_query("SELECT * FROM email_message "
|
||||
" WHERE topic IN ('JOBS_INDIVIDUAL_OFFER_MAIL', 'JOBS_OFFER_INTEREST_MAIL', 'JOBS_GROUP_OFFER_PUBLIC', 'JOBS_MESSAGE_ADDED') "
|
||||
" AND status = 1 ORDER BY id ASC LIMIT 20");
|
||||
|
||||
if (res != NULL && pgsql_num_rows(res) > 0) {
|
||||
out["total_record"] = pgsql_num_rows(res);
|
||||
|
||||
for (int i = 0, n = pgsql_num_rows(res); i < n; i++) {
|
||||
map<const char*, const char*>f = pgsql_fetch_assoc(res, i);
|
||||
if (f.empty()) continue;
|
||||
CVars rec;
|
||||
map_to_cvars(f, rec);
|
||||
pgsql_query("UPDATE email_message SET status = 2 WHERE id = %lu ", rec["id"].Long()); // move the status so no retry
|
||||
CronJobEmail(rec["action"].Long(), rec, out); // send the cron email
|
||||
pgsql_query("UPDATE email_message SET status = 5, completed = now() WHERE id = %lu ", rec["id"].Long()); // move the status so no retry
|
||||
}
|
||||
}
|
||||
ret = PHP_API_OK;
|
||||
out["status"] = "OK";
|
||||
} catch (bad_parameter) {
|
||||
logfmt(logINFO, "ERROR CALL long WRENCHBOARD_ACCOUNT_LOGIN(CVars in, CVars &out)");
|
||||
}
|
||||
|
||||
try {
|
||||
out["total_record"] = "0";
|
||||
const PGresult *res;
|
||||
res = pgsql_query("SELECT * FROM email_message WHERE topic IN ('ACCOUNT_SEND_REFEREMAIL' ) AND status = 1 ORDER BY id ASC LIMIT 20");
|
||||
|
||||
if (res != NULL && pgsql_num_rows(res) > 0) {
|
||||
out["total_record"] = pgsql_num_rows(res);
|
||||
|
||||
for (int i = 0, n = pgsql_num_rows(res); i < n; i++) {
|
||||
map<const char*, const char*>f = pgsql_fetch_assoc(res, i);
|
||||
if (f.empty()) continue;
|
||||
CVars rec;
|
||||
map_to_cvars(f, rec);
|
||||
pgsql_query("UPDATE email_message SET status = 2 WHERE id = %lu ", rec["id"].Long()); // move the status so no retry
|
||||
CronAccountMail(rec); // send the cron email
|
||||
pgsql_query("UPDATE email_message SET status = 5, completed = now() WHERE id = %lu ", rec["id"].Long()); // move the status so no retry
|
||||
}
|
||||
}
|
||||
ret = PHP_API_OK;
|
||||
out["status"] = "OK";
|
||||
} catch (bad_parameter) {
|
||||
logfmt(logINFO, "ERROR CALL long CronAccountMail(CVars in,)");
|
||||
}
|
||||
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
long CronAccountPendingMail(CVars in) //TESTED
|
||||
{
|
||||
REQ_LONG(in, "pending_id", 1, -1);
|
||||
@@ -157,28 +180,25 @@ long CronAccountPendingMail(CVars in) //TESTED
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
long CronWelcomeAccountMail(CVars in) // TESTED
|
||||
{
|
||||
REQ_LONG(in, "member_id", 1, -1);
|
||||
CVars x;
|
||||
CVars out;
|
||||
CVars ml;
|
||||
C_CGI_Form form("", "");
|
||||
form.LetStr("main_site_url", "https://www.wrenchboard.com/");
|
||||
out["server_name"] = CfgReadChar("system.server_name");
|
||||
form.LetStr("server_name", out["server_name"].c_str());
|
||||
form.LetStr("site_name", "WrenchBoard");
|
||||
|
||||
long CronWelcomeAccountMail(CVars in) // TESTED
|
||||
{
|
||||
REQ_LONG(in, "member_id", 1, -1);
|
||||
CVars x;
|
||||
CVars out;
|
||||
CVars ml;
|
||||
C_CGI_Form form("", "");
|
||||
form.LetStr("main_site_url", "https://www.wrenchboard.com/");
|
||||
out["server_name"] = CfgReadChar("system.server_name");
|
||||
form.LetStr("server_name", out["server_name"].c_str());
|
||||
form.LetStr("site_name", "WrenchBoard");
|
||||
|
||||
if (load_db_record(x, "SELECT *,to_char(now(), 'yyyy') AS YYYY FROM members WHERE id = %lu ", in["member_id"].Long())) {
|
||||
vars2form(x, form);
|
||||
form.LetStr("email", x["email"].c_str());
|
||||
form.Email("ACCOUNT/member_welcome.mailfile");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
if (load_db_record(x, "SELECT *,to_char(now(), 'yyyy') AS YYYY FROM members WHERE id = %lu ", in["member_id"].Long())) {
|
||||
vars2form(x, form);
|
||||
form.LetStr("email", x["email"].c_str());
|
||||
form.Email("ACCOUNT/member_welcome.mailfile");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
long CronJobEmail(long mailtype, CVars in, CVars &out) {
|
||||
logfmt(logINFO, "job_email()");
|
||||
CVars x, y, z, ml;
|
||||
@@ -517,6 +537,50 @@ long CronJobEmail(long mailtype, CVars in, CVars &out) {
|
||||
break;
|
||||
|
||||
}
|
||||
logfmt(logINFO, "/job_email()");
|
||||
logfmt(logINFO, "/CronJobEmail()");
|
||||
return 0;
|
||||
}
|
||||
|
||||
long CronAccountMail(CVars in){
|
||||
logfmt(logINFO, "CronAccountMail()");
|
||||
CVars x, y, z, ml;
|
||||
C_CGI_Form form("", "");
|
||||
int c=0;
|
||||
CGIList * inv_list = new CGIList(&form, "inv_items");
|
||||
char listing_items[1024];
|
||||
const PGresult *res;
|
||||
|
||||
// char * server_name; // = getenv("SERVER_NAME");
|
||||
out["server_name"] = CfgReadChar("system.server_name");
|
||||
//sprintf(server_name, "%s", out["server_name"].c_str());
|
||||
form.LetStr("server_name", out["server_name"].c_str());
|
||||
|
||||
form.LetStr("site_name", "WrenchBoard");
|
||||
form.LetStr("site_trade_name", "Connecting Opportunities");
|
||||
|
||||
CVars yr;
|
||||
load_db_record(yr, "SELECT to_char(now(), 'yyyy') AS YYYY");
|
||||
vars2form(yr, form);
|
||||
|
||||
switch (mailtype) {
|
||||
|
||||
case ACCOUNT_SEND_REFEREMAIL:
|
||||
REQ_LONG(in, "refer_id", 1, -1);
|
||||
if (load_db_record(x, "SELECT r.*,m.firstname AS send_firstname,m.lastname AS send_lastname,"
|
||||
" date_part('year',now()) AS yyyy "
|
||||
" FROM members_refer_friend r "
|
||||
" LEFT JOIN members m ON m.id = r.member_id "
|
||||
" WHERE r.id = %lu ", in["refer_id"].Long())) {
|
||||
vars2form(x, form);
|
||||
form.LetStr("email", x["email"].c_str());
|
||||
form.Email("ACCOUNT/member_refer_individual.mailfile");
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
logfmt(logINFO, "/CronJobEmail()");
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user