784 lines
28 KiB
C++
784 lines
28 KiB
C++
// Account management toosl
|
|
#include "clog.h"
|
|
#include "cgi.h"
|
|
#include "input.h"
|
|
#include "wrenchboard_api.h"
|
|
#include "account_mngt.h"
|
|
#include "email.h"
|
|
#include "safestring.h"
|
|
#include <string>
|
|
#include "pgsql.h"
|
|
#include "pgsql_wrapper.h"
|
|
#include "cfg.h"
|
|
#include <curl/curl.h>
|
|
#include "payments.h"
|
|
#include "account.h"
|
|
|
|
|
|
|
|
long WrenchReturnMemberBankAccount(CVars in, CVars &out) {
|
|
logfmt(logINFO, "WrenchReturnMemberBankAccount()");
|
|
char vname[30];
|
|
long ret = PHP_API_BAD_PARAM;
|
|
|
|
try {
|
|
long limit = REQ_LONG(in, "limit", 1, -1);
|
|
long member_id = REQ_LONG(in, "member_id", 1, -1);
|
|
REQ_LONG(in, "page", 1, -1);
|
|
|
|
out["total_record"] = "0";
|
|
|
|
const PGresult *res;
|
|
|
|
res = pgsql_query("SELECT b.id bank_id,b.firstname||' '||b.lastname||' '||b.account_no||' '||k.name AS recipient,b.account_no,b.added "
|
|
"FROM sendmoney_recipient b "
|
|
"LEFT JOIN bank_entity_codes k ON k.code=b.bank_code "
|
|
"WHERE b.member_id = %lu AND b.status=1 LIMIT %lu", in["member_id"].Long(),limit);
|
|
|
|
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);
|
|
|
|
snprintf(vname, sizeof (vname), "bank_id_%05d", i);
|
|
out[vname] = rec["bank_id"];
|
|
|
|
snprintf(vname, sizeof (vname), "recipient_%05d", i);
|
|
out[vname] = rec["recipient"];
|
|
|
|
snprintf(vname, sizeof (vname), "account_no_%05d", i);
|
|
out[vname] = rec["account_no"];
|
|
|
|
snprintf(vname, sizeof (vname), "added_%05d", i);
|
|
out[vname] = rec["added"];
|
|
|
|
|
|
}
|
|
}
|
|
ret = PHP_API_OK;
|
|
out["status"] = "OK";
|
|
} catch (bad_parameter) {
|
|
logfmt(logINFO, "ERROR CALL long WrenchReturnMemberBankAccount(CVars in, CVars &out)");
|
|
}
|
|
logfmt(logINFO, "/WrenchReturnMemberBankAccount()");
|
|
return ret;
|
|
}
|
|
|
|
|
|
|
|
|
|
long WrenchReturnMemberPaymentHx(CVars in, CVars &out) {
|
|
logfmt(logINFO, "WrenchReturnMemberPaymentHx()");
|
|
char vname[30];
|
|
long ret = PHP_API_BAD_PARAM;
|
|
|
|
try {
|
|
long limit = REQ_LONG(in, "limit", 1, -1);
|
|
long member_id = REQ_LONG(in, "member_id", 1, -1);
|
|
REQ_LONG(in, "page", 1, -1);
|
|
|
|
out["total_record"] = "0";
|
|
|
|
const PGresult *res;
|
|
|
|
res = pgsql_query("SELECT m.added::date AS trx_date,m.terminatingamount*0.01 AS amount,m.fee*0.01 as fee, m.id AS trx_id,"
|
|
" r.firstname||' '||r.lastname||'<br><b>Acc:</b>'||r.account_no||'-'||b.name AS recipient,mp.confirmation,"
|
|
" CASE WHEN m.status=1 THEN 'Pending' WHEN m.status=3 THEN 'Cancelled' WHEN m.status=5 THEN 'Completed' ELSE '' END AS status "
|
|
" FROM money_transfer m "
|
|
" LEFT JOIN sendmoney_recipient r ON r.id = m.recipientid "
|
|
" LEFT JOIN bank_entity_codes b ON b.code = r.bank_code "
|
|
" LEFT JOIN members_payments mp ON mp.what_sendmoney = m.id "
|
|
" WHERE m.member_id =%lu AND mp.confirmation IS NOT NULL ORDER BY m.id DESC LIMIT %lu", in["member_id"].Long(),limit);
|
|
|
|
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);
|
|
|
|
snprintf(vname, sizeof (vname), "trx_date_%05d", i);
|
|
out[vname] = rec["trx_date"];
|
|
|
|
snprintf(vname, sizeof (vname), "amount_%05d", i);
|
|
out[vname] = rec["amount"];
|
|
|
|
snprintf(vname, sizeof (vname), "fee_%05d", i);
|
|
out[vname] = rec["fee"];
|
|
|
|
snprintf(vname, sizeof (vname), "recipient_%05d", i);
|
|
out[vname] = rec["recipient"];
|
|
|
|
snprintf(vname, sizeof (vname), "confirmation_%05d", i);
|
|
out[vname] = rec["confirmation"];
|
|
|
|
snprintf(vname, sizeof (vname), "status_%05d", i);
|
|
out[vname] = rec["status"];
|
|
|
|
snprintf(vname, sizeof (vname), "trx_id_%05d", i);
|
|
out[vname] = rec["trx_id"];
|
|
|
|
}
|
|
}
|
|
ret = PHP_API_OK;
|
|
out["status"] = "OK";
|
|
} catch (bad_parameter) {
|
|
logfmt(logINFO, "ERROR CALL long WrenchReturnMemberPaymentHxcd .."
|
|
"(CVars in, CVars &out)");
|
|
}
|
|
logfmt(logINFO, "/WrenchReturnMemberPaymentHx()");
|
|
return ret;
|
|
}
|
|
|
|
|
|
|
|
long WrenchMemberJobsOffers(CVars in, CVars &out) {
|
|
logfmt(logINFO, "WrenchMemberJobsOffers()******************** @@ ");
|
|
char vname[30];
|
|
long ret = PHP_API_BAD_PARAM;
|
|
|
|
try {
|
|
long limit = REQ_LONG(in, "limit", 1, -1);
|
|
long member_id = REQ_LONG(in, "member_id", 1, -1);
|
|
REQ_LONG(in, "page", 1, -1);
|
|
|
|
out["total_record"] = "0";
|
|
|
|
const PGresult *res;
|
|
|
|
|
|
|
|
res = pgsql_query("SELECT jo.added::date,mj.title, mj.description AS description, jo.job_description,mj.price, mj.timeline_days "
|
|
"FROM members_jobs_offer jo LEFT JOIN members_jobs mj ON mj.id = jo.job_id "
|
|
"WHERE jo.expire > now() AND jo.status = 1 "
|
|
"AND jo.client_id = %lu LIMIT %lu ", in["member_id"].Long(), in["limit"].Long());
|
|
|
|
|
|
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);
|
|
|
|
snprintf(vname, sizeof (vname), "title_%05d", i);
|
|
out[vname] = rec["title"];
|
|
|
|
snprintf(vname, sizeof (vname), "project_%05d", i);
|
|
out[vname] = rec["project"];
|
|
|
|
snprintf(vname, sizeof (vname), "description_%05d", i);
|
|
out[vname] = rec["description"];
|
|
|
|
snprintf(vname, sizeof (vname), "status_description_%05d", i);
|
|
out[vname] = rec["status_description"];
|
|
|
|
snprintf(vname, sizeof (vname), "delivery_date_%05d", i);
|
|
out[vname] = rec["delivery_date"];
|
|
|
|
snprintf(vname, sizeof (vname), "status_description_%05d", i);
|
|
out[vname] = rec["status_description"];
|
|
|
|
snprintf(vname, sizeof (vname), "timeline_days_%05d", i);
|
|
out[vname] = rec["timeline_days"];
|
|
|
|
snprintf(vname, sizeof (vname), "contract_%05d", i);
|
|
out[vname] = rec["contract"];
|
|
|
|
snprintf(vname, sizeof (vname), "job_description_%05d", i);
|
|
out[vname] = rec["job_description"];
|
|
|
|
snprintf(vname, sizeof (vname), "price_%05d", i);
|
|
out[vname] = rec["price"];
|
|
|
|
snprintf(vname, sizeof (vname), "job_id_%05d", i);
|
|
out[vname] = rec["job_id"];
|
|
|
|
snprintf(vname, sizeof (vname), "contract_id_%05d", i);
|
|
out[vname] = rec["contract_id"];
|
|
}
|
|
}
|
|
ret = PHP_API_OK;
|
|
out["status"] = "OK";
|
|
} catch (bad_parameter) {
|
|
logfmt(logINFO, "ERROR CALL long WrenchMemberJobsOffers(CVars in, CVars &out)");
|
|
}
|
|
logfmt(logINFO, "/WrenchMemberJobsOffers()");
|
|
return ret;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
long WrenchMemberActiveJobs(CVars in, CVars &out) {
|
|
logfmt(logINFO, "WrenchMemberActiveJobs()");
|
|
char vname[30];
|
|
long ret = PHP_API_BAD_PARAM;
|
|
|
|
try {
|
|
long limit = REQ_LONG(in, "limit", 1, -1);
|
|
long member_id = REQ_LONG(in, "member_id", 1, -1);
|
|
REQ_LONG(in, "page", 1, -1);
|
|
|
|
out["total_record"] = "0";
|
|
|
|
const PGresult *res;
|
|
|
|
|
|
res = pgsql_query("SELECT mc.id AS contract_id, mc.job_id AS job_id, mc.price, mc.timeline_days,mc.contract, "
|
|
" mj.title, mj.description AS description,mc.job_detail AS job_description, "
|
|
" (CASE WHEN mc.status=4 THEN 'Review' "
|
|
" WHEN mc.status = 1 AND mc.delivery_date > now() THEN 'Active' "
|
|
" WHEN mc.status = 1 AND mc.delivery_date <now() THEN 'Past Due' "
|
|
" ELSE 'Others' END) AS status_description,mc.delivery_date "
|
|
" FROM members_jobs_contract mc LEFT JOIN members_jobs mj ON mj.id = mc.job_id LEFT JOIN members m ON m.id=mc.client_id "
|
|
" WHERE mc.member_id = %lu AND mc.status IN (1,2,4) OR mc.client_id =%lu AND mc.status IN (1,2,4) ", in["member_id"].Long(), in["member_id"].Long());
|
|
|
|
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);
|
|
|
|
snprintf(vname, sizeof (vname), "title_%05d", i);
|
|
out[vname] = rec["title"];
|
|
|
|
snprintf(vname, sizeof (vname), "project_%05d", i);
|
|
out[vname] = rec["project"];
|
|
|
|
snprintf(vname, sizeof (vname), "description_%05d", i);
|
|
out[vname] = rec["description"];
|
|
|
|
snprintf(vname, sizeof (vname), "status_description_%05d", i);
|
|
out[vname] = rec["status_description"];
|
|
|
|
snprintf(vname, sizeof (vname), "delivery_date_%05d", i);
|
|
out[vname] = rec["delivery_date"];
|
|
|
|
snprintf(vname, sizeof (vname), "status_description_%05d", i);
|
|
out[vname] = rec["status_description"];
|
|
|
|
snprintf(vname, sizeof (vname), "timeline_days_%05d", i);
|
|
out[vname] = rec["timeline_days"];
|
|
|
|
snprintf(vname, sizeof (vname), "contract_%05d", i);
|
|
out[vname] = rec["contract"];
|
|
|
|
snprintf(vname, sizeof (vname), "job_description_%05d", i);
|
|
out[vname] = rec["job_description"];
|
|
|
|
snprintf(vname, sizeof (vname), "price_%05d", i);
|
|
out[vname] = rec["price"];
|
|
|
|
snprintf(vname, sizeof (vname), "job_id_%05d", i);
|
|
out[vname] = rec["job_id"];
|
|
|
|
snprintf(vname, sizeof (vname), "contract_id_%05d", i);
|
|
out[vname] = rec["contract_id"];
|
|
}
|
|
}
|
|
ret = PHP_API_OK;
|
|
out["status"] = "OK";
|
|
} catch (bad_parameter) {
|
|
logfmt(logINFO, "ERROR CALL long WrenchMemberActiveJobs(CVars in, CVars &out)");
|
|
}
|
|
logfmt(logINFO, "/WrenchMemberActiveJobs()");
|
|
return ret;
|
|
|
|
|
|
|
|
}
|
|
|
|
long WrenchReturnMemberMessages(CVars in, CVars &out) {
|
|
logfmt(logINFO, "WrenchReturnMemberMessages()");
|
|
char vname[60];
|
|
char vname_memo[60];
|
|
long ret = PHP_API_BAD_PARAM;
|
|
long msg_id = 0;
|
|
|
|
try {
|
|
long limit = REQ_LONG(in, "limit", 1, -1);
|
|
long member_id = REQ_LONG(in, "member_id", 1, -1);
|
|
REQ_LONG(in, "page", 1, -1);
|
|
OPTIONAL(in, "recent") REQ_LONG(in, "recent", 1, -1);
|
|
|
|
// this section ;limit recent or not recent
|
|
if ( in["recent"].Long() == 1 ){
|
|
snprintf(vname, sizeof (vname), " AND now() < mm.added + '96 hours' ");
|
|
}
|
|
else
|
|
{snprintf(vname, sizeof (vname), " ");
|
|
}
|
|
|
|
// This section focus the message based on memo
|
|
OPTIONAL(in, "msg_id") REQ_LONG(in, "msg_id", 1, -1);
|
|
if( in["msg_id"].Long() > 0 ){
|
|
REQ_STRING(in, "uid", 10, 100, "(.*)");
|
|
load_db_record(out, "SELECT TRIM(memo) AS memo FROM members_messages WHERE LOWER(uid::text)= LOWER('%s')", in["uid"].c_str());
|
|
if ( out["memo"] != "" ){
|
|
snprintf(vname_memo, sizeof (vname_memo), " AND LOWER(TRIM(mm.memo)) = LOWER('%s') ",out["memo"].c_str() );
|
|
}else{
|
|
snprintf(vname_memo, sizeof (vname_memo), "");
|
|
}
|
|
}else{
|
|
snprintf(vname_memo, sizeof (vname_memo), ""); // clean it up
|
|
}
|
|
|
|
out["total_record"] = "0";
|
|
|
|
const PGresult *res;
|
|
/* res = pgsql_query("SELECT mm.added::date AS msg_date,mm.msg,mm.id AS msg_id ,mm.senders_id , mm.msg_type, mm.memo,ms.firstname AS msg_from "
|
|
"FROM members_messages mm LEFT JOIN members ms ON ms.id =mm.senders_id "
|
|
"WHERE mm.member_id = %lu "
|
|
" %s AND mm.reply IS NULL ORDER BY mm.id DESC LIMIT %lu", in["member_id"].Long(),vname, limit);
|
|
to_char(mm.added, 'Day Mon dd, yyyy HH:MI AM') AS expire2
|
|
|
|
*/
|
|
|
|
|
|
res = pgsql_query("SELECT to_char(mm.added, 'Day Mon dd, yyyy HH:MI AM') AS msg_date,mm.msg,mm.id AS msg_id ,mm.senders_id , mm.msg_type, "
|
|
" mm.memo,ms.firstname AS msg_from,mm.reply,mm.member_id,mm.uid,TRIM(mm.memo) AS memo FROM members_messages mm "
|
|
" LEFT JOIN members ms ON ms.id =mm.senders_id WHERE mm.senders_id = %lu %s %s"
|
|
" UNION "
|
|
" SELECT to_char(mm.added, 'Day Mon dd, yyyy HH:MI AM') AS msg_date,mm.msg,mm.id AS msg_id ,mm.senders_id , mm.msg_type, "
|
|
" mm.memo,ms.firstname AS msg_from,mm.reply,mm.member_id,mm.uid,TRIM(mm.memo) AS memo FROM members_messages mm "
|
|
" LEFT JOIN members ms ON ms.id =mm.senders_id WHERE mm.member_id = %lu %s %s"
|
|
" ORDER BY msg_id DESC LIMIT %lu", in["member_id"].Long(),vname,vname_memo, in["member_id"].Long(), vname,vname_memo, limit);
|
|
|
|
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);
|
|
|
|
snprintf(vname, sizeof (vname), "msg_id_%05d", i);
|
|
out[vname] = rec["msg_id"];
|
|
|
|
snprintf(vname, sizeof (vname), "msg_date_%05d", i);
|
|
out[vname] = rec["msg_date"];
|
|
|
|
snprintf(vname, sizeof (vname), "msg_%05d", i);
|
|
out[vname] = rec["msg"];
|
|
|
|
snprintf(vname, sizeof (vname), "msg_from_%05d", i);
|
|
if (rec["senders_id"] == in["member_id"] ){
|
|
out[vname] = "You";
|
|
}
|
|
else{
|
|
out[vname] = rec["msg_from"];
|
|
}
|
|
|
|
|
|
|
|
snprintf(vname, sizeof (vname), "senders_id_%05d", i);
|
|
out[vname] = rec["senders_id"];
|
|
|
|
snprintf(vname, sizeof (vname), "member_id_%05d", i);
|
|
out[vname] = rec["member_id"];
|
|
|
|
snprintf(vname, sizeof (vname), "reply_%05d", i);
|
|
out[vname] = rec["reply"];
|
|
|
|
snprintf(vname, sizeof (vname), "uid_%05d", i);
|
|
out[vname] = rec["uid"];
|
|
|
|
snprintf(vname, sizeof (vname), "memo_%05d", i);
|
|
out[vname] = rec["memo"];
|
|
|
|
snprintf(vname, sizeof (vname), "message_mode_%05d", i);
|
|
if (rec["senders_id"] == in["member_id"] ){
|
|
out[vname] = "sender";
|
|
}
|
|
else{
|
|
out[vname] = "recipient";
|
|
}
|
|
}
|
|
}
|
|
ret = PHP_API_OK;
|
|
out["status"] = "OK";
|
|
} catch (bad_parameter) {
|
|
logfmt(logINFO, "ERROR CALL long WrenchReturnMemberMessages(CVars in, CVars &out)");
|
|
}
|
|
logfmt(logINFO, "/WrenchReturnMemberMessages()");
|
|
return ret;
|
|
}
|
|
|
|
|
|
/* This return the list of jobs on the home page of the apps*/
|
|
long WrenchReturnJobList(CVars in, CVars &out) {
|
|
logfmt(logINFO, "WrenchReturnJobList()");
|
|
char vname[30];
|
|
long ret = PHP_API_BAD_PARAM;
|
|
|
|
try {
|
|
long limit = REQ_LONG(in, "limit", 1, -1);
|
|
REQ_LONG(in, "page", 1, -1);
|
|
|
|
out["total_record"] = "0";
|
|
|
|
const PGresult *res;
|
|
|
|
res = pgsql_query("SELECT j.title,j.description,m.id AS job_id,m.expire,m.job_description,j.price, "
|
|
"m.offer_code,j.timeline_days, to_char(m.expire, 'Dy Mon dd, yyyy HH:MI AM') AS expire2,"
|
|
"m.uid AS offer_uid,j.uid AS job_uid,m.added::date AS offer_added,j.country AS job_country "
|
|
"FROM members_jobs_offer m "
|
|
"LEFT JOIN members_jobs j ON j.id=m.job_id "
|
|
"WHERE m.status = 1 AND m.client_id=0 "
|
|
"AND m.expire IS NOT NULL "
|
|
"AND m.public_view = 1 AND m.expire> now() "
|
|
"ORDER BY m.expire DESC LIMIT %lu", in["limit"].Long());
|
|
|
|
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);
|
|
|
|
snprintf(vname, sizeof (vname), "title_%05d", i);
|
|
out[vname] = rec["title"];
|
|
|
|
snprintf(vname, sizeof (vname), "description_%05d", i);
|
|
out[vname] = rec["description"];
|
|
|
|
snprintf(vname, sizeof (vname), "job_description_%05d", i);
|
|
out[vname] = rec["job_description"];
|
|
|
|
snprintf(vname, sizeof (vname), "expire_%05d", i);
|
|
out[vname] = rec["expire2"];
|
|
|
|
snprintf(vname, sizeof (vname), "price_%05d", i);
|
|
out[vname] = rec["price"];
|
|
|
|
snprintf(vname, sizeof (vname), "offer_code_%05d", i);
|
|
out[vname] = rec["offer_code"];
|
|
|
|
snprintf(vname, sizeof (vname), "timeline_days_%05d", i);
|
|
out[vname] = rec["timeline_days"];
|
|
|
|
snprintf(vname, sizeof (vname), "id_%05d", i);
|
|
out[vname] = rec["job_id"];
|
|
|
|
snprintf(vname, sizeof (vname), "offer_uid_%05d", i);
|
|
out[vname] = rec["offer_uid"];
|
|
|
|
snprintf(vname, sizeof (vname), "job_uid_%05d", i);
|
|
out[vname] = rec["job_uid"];
|
|
|
|
snprintf(vname, sizeof (vname), "offer_added_%05d", i);
|
|
out[vname] = rec["offer_added"];
|
|
|
|
snprintf(vname, sizeof (vname), "job_country_%05d", i);
|
|
out[vname] = rec["job_country"];
|
|
|
|
}
|
|
}
|
|
/*
|
|
wrenchboard=> SELECT count(mo.id),mj.offer_code FROM members_offer_interest mo
|
|
LEFT JOIN members_jobs_offer mj ON mj.id= mo.offer_id WHERE mj.expire > now() GROUP BY mj.offer_code
|
|
wrenchboard-> ;
|
|
count | offer_code
|
|
-------+------------
|
|
3 | 1B7R3134W0
|
|
3 | 66WW5B9B45
|
|
3 | Y1X0983WTP
|
|
(3 rows)
|
|
*/
|
|
|
|
const PGresult *res2;
|
|
|
|
res2 = pgsql_query("SELECT count(mo.id) AS interest_count,mj.offer_code FROM members_offer_interest mo "
|
|
" LEFT JOIN members_jobs_offer mj ON mj.id= mo.offer_id "
|
|
" WHERE mj.expire > now() GROUP BY mj.offer_code");
|
|
|
|
if (res2 != NULL && pgsql_num_rows(res2) > 0) {
|
|
out["total_interest_record"] = pgsql_num_rows(res2);
|
|
|
|
for (int ii = 0, n = pgsql_num_rows(res2); ii < n; ii++) {
|
|
map<const char*, const char*>f2 = pgsql_fetch_assoc(res2, ii);
|
|
if (f2.empty()) continue;
|
|
CVars rec2;
|
|
map_to_cvars(f2, rec2);
|
|
|
|
snprintf(vname, sizeof (vname), "interest_count_%s", rec2["offer_code"].c_str());
|
|
out[vname] = rec2["interest_count"];
|
|
}
|
|
}
|
|
|
|
|
|
ret = PHP_API_OK;
|
|
out["status"] = "OK";
|
|
} catch (bad_parameter) {
|
|
logfmt(logINFO, "ERROR CALL long WrenchReturnJobList(CVars in, CVars &out)");
|
|
}
|
|
logfmt(logINFO, "/WrenchReturnJobList()");
|
|
return ret;
|
|
}
|
|
|
|
|
|
|
|
|
|
long CreateMobileWrenchBoardAccount(CVars in, CVars &out) {
|
|
long ret = PHP_API_BAD_PARAM;
|
|
|
|
try {
|
|
|
|
REQ_STRING(in, "username", 5, 49, "(.*)");
|
|
REQ_STRING(in, "firstname", 2, 49, "(.*)");
|
|
REQ_STRING(in, "lastname", 2, 49, "(.*)");
|
|
REQ_STRING(in, "email", 5, 49, "(.*)");
|
|
OPTIONAL(in, "phone") REQ_STRING(in, "phone", 3, 15, "(.*)");
|
|
OPTIONAL(in, "loc") REQ_STRING(in, "loc", 3, 15, "(.*)");
|
|
long news = REQ_LONG(in, "news", 1, -1);
|
|
long terms = REQ_LONG(in, "terms", 1, -1);
|
|
REQ_STRING(in, "password", 5, 25, "(.*)");
|
|
OPTIONAL(in, "country") REQ_STRING(in, "country", 1, 3, "(.*)");
|
|
//const char * loc = getenv('REMOTE_ADDR');
|
|
//in["loc"] = loc;
|
|
OPTIONAL(in, "mobile") REQ_STRING(in, "mobile", 3, 15, "(.*)");
|
|
|
|
// in["news"] = "1";
|
|
//in["news"].set_valid( true );
|
|
|
|
|
|
ret = CreateWrenchBoardAccountPending(in, out);
|
|
} catch (bad_parameter) {
|
|
out["status"] = "ERROR";
|
|
}
|
|
|
|
return ret;
|
|
}
|
|
|
|
long CompleteMobileAccountCreation(CVars in, CVars &out){
|
|
long ret = PHP_API_BAD_PARAM;
|
|
CVars x;
|
|
x["password"] = in["password"]; x["password"].set_valid( true );
|
|
x["sessionid"] = "IINITIAL_SESSION_DUMMY"; x["sessionid"].set_valid( true );
|
|
x["username"] = in["username"]; x["username"].set_valid( true );
|
|
x["login_mode"]= "100"; x["login_mode"].set_valid( true );
|
|
|
|
if ( CreateWrenchBoardAccount(in, out) > 0 )
|
|
{
|
|
ret = LoginWrenchBoardAccount(x, out);
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
long CreateWrenchBoardAccount(CVars in, CVars &out) {
|
|
logfmt(logINFO, "CreateWrenchBoardAccount()");
|
|
long ret = PHP_API_BAD_PARAM;
|
|
bool compt = false;
|
|
REQ_STRING(in, "verify_link", 2, 120, "(.*)");
|
|
REQ_STRING (in, "password", 3, 15, "(.*)");
|
|
REQ_STRING(in, "username", 5, 49, "(.*)");
|
|
OPTIONAL(in, "loc") REQ_STRING(in, "loc", 3, 15, "(.*)");
|
|
CVars x;
|
|
//const char * loc = getenv('REMOTE_ADDR');
|
|
//in["loc"] = loc;
|
|
try {
|
|
long lonkF = load_db_record(out, "SELECT *,id AS pending_id FROM members_pending WHERE verify_link ='%s' AND password =md5('%s') AND username ='%s' AND status= 1 AND expire > now() LIMIT 1", in["verify_link"].c_str(), in["password"].c_str(), in["username"].c_str());
|
|
if (lonkF) {
|
|
if (out["pending_id"].Long() > 0 ){
|
|
out["status"] = "prepare to create account";
|
|
|
|
x["username"] = out["username"];
|
|
x["username"].set_valid(true);
|
|
x["firstname"] = out["firstname"];
|
|
x["firstname"].set_valid(true);
|
|
x["lastname"] = out["lastname"];
|
|
x["lastname"].set_valid(true);
|
|
x["email"] = out["email"];
|
|
x["email"].set_valid(true);
|
|
x["phone"] = out["phone"];
|
|
x["phone"].set_valid(true);
|
|
x["loc"] = out["loc"];
|
|
x["loc"].set_valid(true);
|
|
x["country"] = out["country"];
|
|
x["country"].set_valid(true);
|
|
x["password"] = out["password"];
|
|
x["password"].set_valid(true);
|
|
ret = insert_db_record(DBS_VALID, "members", "members_id_seq", x);
|
|
compt = true;
|
|
}
|
|
else{
|
|
out["status"] = "Invalid Link & Password Combination";
|
|
ret = PHP_API_BAD_PARAM;
|
|
}
|
|
|
|
|
|
if (ret > 0 && compt==true) {
|
|
out["member_id"] = ret;
|
|
out["member_id"].set_valid(true);
|
|
x["member_id"] = ret;
|
|
x["member_id"].set_valid(true);
|
|
x["pending_id"] = out["pending_id"];
|
|
x["pending_id"].set_valid(true);
|
|
|
|
CVars u;
|
|
load_db_record(u,"SELECT code AS currency FROM currency WHERE country = '%s'", x["country"].c_str() );
|
|
logfmt(logINFO, " The Currency code = %s", u["currency"].c_str());
|
|
out["wallet_id"] = CheckWallet( x["member_id"].Long() , u);
|
|
logfmt(logINFO, " The wallet_id = %lu", out["wallet_id"].Long());
|
|
|
|
CVars vw;
|
|
// vw["currency"] = "NAIRA"; // this will become a variable based on the country
|
|
// vw["currency"].set_valid( true );
|
|
// out["wallet_id"] = CheckWallet(out["member_id"].Long(),vw); // initial wallet
|
|
|
|
// - password already set pgsql_query("UPDATE members SET password = md5('%s') WHERE id = %lu",in["pass1"].c_str(),ret);
|
|
pgsql_query("UPDATE members_pending SET status = 5 WHERE id = %lu", out["pending_id"].Long());
|
|
pgsql_query("UPDATE members_refer_friend SET status = 5 WHERE status = 1 AND email = '%s'", x["email"].c_str());
|
|
WelcomeAccountMail(x);
|
|
SignupCompletedAlertMailfile(x);
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch (bad_parameter) {
|
|
out["status"] = "ERROR";
|
|
}
|
|
|
|
logfmt(logINFO, "/CreateWrenchBoardAccount()");
|
|
return ret;
|
|
}
|
|
|
|
long CreateWrenchBoardAccountPending(CVars in, CVars &out) {
|
|
long ret = PHP_API_BAD_PARAM;
|
|
out = in;
|
|
|
|
/*
|
|
CREATE TABLE members_pending (
|
|
id SERIAL,
|
|
username VARCHAR(50) UNIQUE NOT NULL,
|
|
firstname VARCHAR(50),
|
|
lastname VARCHAR(50),
|
|
email VARCHAR(50),
|
|
phone VARCHAR(25),
|
|
password VARCHAR(100),
|
|
status integer DEFAULT 1,
|
|
added timestamp without time zone DEFAULT now(),
|
|
verify_link VARCHAR(100),
|
|
terms integer DEFAULT 0,
|
|
news integer DEFAULT 0,
|
|
expire timestamp without time zone DEFAULT now() +'30 days'
|
|
);
|
|
ALTER TABLE ONLY members_pending
|
|
ADD CONSTRAINT members_pending_id_key UNIQUE (id);
|
|
*/
|
|
|
|
if ( load_db_record(out, "SELECT id FROM members_pending WHERE LOWER(username)=LOWER('%s')",in["username"].c_str()) > 0 ){
|
|
out["password"]="REMOVED";
|
|
out["acc"]="DULPICATE";
|
|
return -1;
|
|
}
|
|
if ( load_db_record(out, "SELECT uid FROM members WHERE LOWER(username)=LOWER('%s')",in["username"].c_str())> 0 ){
|
|
out["password"]="REMOVED";
|
|
out["acc"]="DULPICATE";
|
|
return -1;
|
|
}
|
|
|
|
REQ_STRING(in, "username", 5, 49, "(.*)");
|
|
REQ_STRING(in, "firstname", 2, 49, "(.*)");
|
|
REQ_STRING(in, "lastname", 2, 49, "(.*)");
|
|
REQ_STRING(in, "email", 5, 49, "(.*)");
|
|
OPTIONAL(in, "phone") REQ_STRING(in, "phone", 3, 15, "(.*)");
|
|
OPTIONAL(in, "loc") REQ_STRING(in, "loc", 3, 15, "(.*)");
|
|
long news = REQ_LONG(in, "news", 1, -1);
|
|
long terms = REQ_LONG(in, "terms", 1, -1);
|
|
REQ_STRING(in, "password", 5, 25, "(.*)");
|
|
OPTIONAL(in, "country") REQ_STRING(in, "country", 1, 3, "(.*)");
|
|
//const char * loc = getenv('REMOTE_ADDR');
|
|
//in["loc"] = loc;
|
|
OPTIONAL(in, "mobile") REQ_STRING(in, "mobile", 3, 15, "(.*)");
|
|
|
|
int r1, r2, r3,signup_random;
|
|
char verify_link[100];
|
|
srand(time(NULL));
|
|
r1 = abs(rand()*100);
|
|
srand(time(NULL));
|
|
r2 = abs(rand() * r1);
|
|
srand(time(NULL));
|
|
r3 = abs(rand() * r2);
|
|
srand(time(NULL));
|
|
|
|
|
|
signup_random = abs(rand()*0.009);
|
|
|
|
|
|
sprintf(verify_link, "WRENCHB-%09lu-%08lu-%08lu", r1, r2, r3);
|
|
|
|
|
|
CVars x;
|
|
x["username"] = in["username"];
|
|
x["username"].set_valid(true);
|
|
x["firstname"] = in["firstname"];
|
|
x["firstname"].set_valid(true);
|
|
x["lastname"] = in["lastname"];
|
|
x["lastname"].set_valid(true);
|
|
x["email"] = in["email"];
|
|
x["email"].set_valid(true);
|
|
x["phone"] = in["phone"];
|
|
x["phone"].set_valid(true);
|
|
x["country"] = in["country"];
|
|
x["country"].set_valid(true);
|
|
|
|
if (in["loc"].length() > 0) x["loc"] = in["loc"];
|
|
x["loc"].set_valid(true);
|
|
x["verify_link"] = verify_link;
|
|
x["verify_link"].set_valid(true);
|
|
|
|
x["news"] = in["news"];
|
|
x["news"].set_valid(true);
|
|
x["terms"] = in["terms"];
|
|
x["terms"].set_valid(true);
|
|
|
|
ret = insert_db_record(DBS_VALID, "members_pending", "members_pending_id_seq", x);
|
|
|
|
if (ret > 0) {
|
|
pgsql_query("UPDATE members_pending SET password = md5('%s'),signup_random=%lu WHERE id = %lu", in["password"].c_str(),signup_random/1000, ret);
|
|
pgsql_query("UPDATE members_refer_friend SET status = 5 WHERE status = 1 AND email = '%s'", x["email"].c_str());
|
|
|
|
load_db_record(out, "SELECT *,id AS pending_id FROM members_pending WHERE id=%lu LIMIT 1", ret);
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ret > 0) {
|
|
out["pending_id"] = ret;
|
|
out["pending_id"].set_valid(true);
|
|
x["pending_id"] = ret;
|
|
x["pending_id"].set_valid(true);
|
|
|
|
if (in["mobile"] != "" && in["mobile"] == "MOBILE") {
|
|
//ALTER TABLE members_pending ADD signup_random INT;
|
|
x["mobile_email"] = "100"; x["mobile_email"].set_valid( true );
|
|
AccountPendingMail(x);
|
|
} else {
|
|
AccountPendingMail(x);
|
|
}
|
|
SignupPendingAlertMailfile(x);
|
|
}
|
|
|
|
return ret;
|
|
}
|
|
//******************************************************************************
|