290 lines
11 KiB
C++
290 lines
11 KiB
C++
// Account management toosl
|
|
#include "clog.h"
|
|
#include "cgi.h"
|
|
#include "input.h"
|
|
#include "wrenchboard_api.h"
|
|
#include "contract.h"
|
|
#include "email.h"
|
|
#include "payments.h"
|
|
#include "safestring.h"
|
|
#include <string>
|
|
#include "pgsql.h"
|
|
#include "pgsql_wrapper.h"
|
|
#include "cfg.h"
|
|
#include <curl/curl.h>
|
|
|
|
|
|
|
|
long contract_calls(CVars in, CVars &out)
|
|
{
|
|
logfmt( logINFO, "contract_calls()" );
|
|
out["result"] = "YES I GET TO BACK END";
|
|
long action = REQ_LONG( in, "action", 0, -1);
|
|
switch( action )
|
|
{
|
|
case WRENCHBOARD_CONTRACT_MESSAGE:
|
|
return WrenchContractMessage( in, out);
|
|
break;
|
|
|
|
case WRENCHBOARD_CONTRACT_STATUS:
|
|
return WrenchContractStatus( in, out);
|
|
break;
|
|
|
|
}
|
|
logfmt( logINFO, "/contract_calls()" );
|
|
return 0;
|
|
}
|
|
|
|
|
|
long WrenchContractStatus( CVars in, CVars &out )
|
|
{
|
|
long ret = 0;
|
|
logfmt( logINFO, "WrenchContractStatus()" );
|
|
REQ_LONG( in, "member_id", 1, -1 );
|
|
REQ_STRING (in, "job_contract", 7, 25, "(.*)");
|
|
REQ_LONG( in, "job_id", 1, -1 );
|
|
long job_action = REQ_LONG( in, "job_action", 1, -1 );
|
|
out["result"] = "Yes i go to this back end";
|
|
long extension = 0;
|
|
|
|
in["contract_id"] = in["job_id"]; in["contract_id"].set_valid( true ); // the email system uses contract_id
|
|
|
|
switch( job_action )
|
|
{
|
|
case CONTRACT_NOTIFY_COMPLETE:
|
|
ret = load_db_record( out, "SELECT * FROM members_jobs_contract WHERE status IN (1,2) AND contract='%s' AND id=%lu AND client_id =%lu",in["job_contract"].c_str(),in["job_id"].Long(),in["member_id"].Long() );
|
|
logfmt( logINFO, "~~~~ ~~~~~ WrenchContractStatus() ret 1 = %lu",ret );
|
|
if (ret)
|
|
{
|
|
pgsql_exec("UPDATE members_jobs_contract SET status = %lu,updated=now() WHERE id = %lu",CONTRACT_NOTIFY_COMPLETE, in["job_id"].Long() );
|
|
|
|
if ( load_db_record( out, "SELECT * FROM members_jobs_contract WHERE status = %lu AND id=%lu AND client_id =%lu",CONTRACT_NOTIFY_COMPLETE,in["job_id"].Long(),in["member_id"].Long() ) )
|
|
{
|
|
project_email(CONTRACT_NOTIFY_COMPLETE, in, out);
|
|
out["result"] = "We have notify the task owner of your completion. Expect a response soon";
|
|
}
|
|
}
|
|
break;
|
|
|
|
case CONTRACT_REQUEST_CANCEL:
|
|
ret = load_db_record( out, "SELECT * FROM members_jobs_contract WHERE status IN (1,2) AND contract='%s' AND id=%lu AND client_id =%lu",in["job_contract"].c_str(),in["job_id"].Long(),in["member_id"].Long() );
|
|
logfmt( logINFO, "~~~~ ~~~~~ WrenchContractStatus() ret 1 = %lu",ret );
|
|
if (ret)
|
|
{
|
|
pgsql_exec("UPDATE members_jobs_contract SET status = %lu,updated=now() WHERE id = %lu",CONTRACT_REQUEST_CANCEL, in["job_id"].Long() );
|
|
|
|
if ( load_db_record( out, "SELECT * FROM members_jobs_contract WHERE status = %lu AND id=%lu AND client_id =%lu",CONTRACT_REQUEST_CANCEL,in["job_id"].Long(),in["member_id"].Long() ) )
|
|
{
|
|
project_email(CONTRACT_REQUEST_CANCEL, in, out);
|
|
out["result"] = "We have notify the task owner of your request for cancellation.";
|
|
}
|
|
}
|
|
break;
|
|
|
|
case CONTRACT_ACCEPT_COMPLETE:
|
|
|
|
ret = load_db_record( out, "SELECT * FROM members_jobs_contract WHERE status = %lu AND contract='%s' AND id=%lu AND member_id =%lu",CONTRACT_NOTIFY_COMPLETE,in["job_contract"].c_str(),in["job_id"].Long(),in["member_id"].Long() );
|
|
logfmt( logINFO, "~~~~ ~~~~~ WrenchContractStatus() ret 1 = %lu",ret );
|
|
if (ret)
|
|
{
|
|
pgsql_exec("UPDATE members_jobs_contract SET status = %lu,updated=now() WHERE id = %lu",CONTRACT_ACCEPT_COMPLETE, in["job_id"].Long() );
|
|
// make sure the update was done
|
|
if ( load_db_record( out, "SELECT * FROM members_jobs_contract WHERE status = %lu AND id=%lu AND member_id =%lu",CONTRACT_ACCEPT_COMPLETE,in["job_id"].Long(),in["member_id"].Long() ) )
|
|
{
|
|
//let us do the accounting parts here now
|
|
CVars y;
|
|
y["member_id"] = in["member_id"]; // note we are actually paying the client_id
|
|
y["contract_id"] = in["job_id"];
|
|
y["code"] = "COPAY";
|
|
y["dir"] = DIR_TARGET;
|
|
if ( WrenchContractPayment(y,out) == PHP_CREATED_OK )
|
|
{ // if you reserve pauments
|
|
//char offer_code[15] = "";
|
|
//GetOfferCode(offer_id, offer_code, sizeof (offer_code)); // this stamp the offer code directly in that call
|
|
pgsql_exec("UPDATE members_jobs_contract SET updated = now(),payment_date=now() WHERE id = %lu",out["job_id"].Long());
|
|
}
|
|
else
|
|
{
|
|
|
|
}
|
|
//----------------------------------------
|
|
|
|
project_email(CONTRACT_ACCEPT_COMPLETE, in, out); //USES in["contract_id"]
|
|
out["result"] = "This task is now complete. We have notified all parties accordingly";
|
|
}
|
|
}
|
|
break;
|
|
case CONTRACT_REJECT_COMPLETE:
|
|
|
|
ret = load_db_record( out, "SELECT * FROM members_jobs_contract WHERE status = %lu AND contract='%s' AND id=%lu AND member_id =%lu",CONTRACT_NOTIFY_COMPLETE,in["job_contract"].c_str(),in["job_id"].Long(),in["member_id"].Long() );
|
|
logfmt( logINFO, "~~~~ ~~~~~ WrenchContractStatus() ret 1 = %lu",ret );
|
|
if (ret)
|
|
{
|
|
pgsql_exec("UPDATE members_jobs_contract SET status = %lu,updated=now() WHERE id = %lu",CONTRACT_REJECT_COMPLETE, in["job_id"].Long() );
|
|
// make sure the update was done
|
|
if ( load_db_record( out, "SELECT * FROM members_jobs_contract WHERE status = %lu AND id=%lu AND member_id =%lu",CONTRACT_REJECT_COMPLETE,in["job_id"].Long(),in["member_id"].Long() ) )
|
|
{
|
|
project_email(CONTRACT_REJECT_COMPLETE, in, out);
|
|
out["result"] = "You have rejected that this task is complete. We have notified all parties accordingly";
|
|
}
|
|
}
|
|
break;
|
|
|
|
case CONTRACT_EXTEND_TIMELINE:
|
|
out["result"] = "CONTRACT_EXTEND_TIMELINE";
|
|
extension = REQ_LONG( in, "extension", 1, -1 );
|
|
|
|
ret = load_db_record( out, "SELECT * FROM members_jobs_contract WHERE status IN (1,2) AND contract='%s' AND id=%lu AND member_id =%lu AND delivery_date < now()",in["job_contract"].c_str(),in["job_id"].Long(),in["member_id"].Long() );
|
|
logfmt( logINFO, "~~~~ ~~~~~ WrenchContractStatus() ret 1 = %lu",ret );
|
|
if (ret)
|
|
{
|
|
pgsql_exec("UPDATE members_jobs_contract SET due_remind = NULL, delivery_date = now() +'%lu days' WHERE status IN (1,2) AND id = %lu AND contract='%s'",extension, in["job_id"].Long() ,in["job_contract"].c_str());
|
|
// make sure the update was done
|
|
if ( load_db_record( out, "SELECT * FROM members_jobs_contract WHERE id=%lu AND member_id =%lu AND delivery_date > now()",in["job_id"].Long(),in["member_id"].Long() ) )
|
|
{
|
|
project_email(CONTRACT_EXTEND_TIMELINE, in, out);
|
|
out["result"] = "We have extended the timeline as requested";
|
|
}
|
|
}
|
|
break;
|
|
|
|
case CONTRACT_CANCEL_CONTRACT:
|
|
out["result"] = "CONTRACT_CANCEL_CONTRACT";
|
|
|
|
ret = load_db_record( out, "SELECT * FROM members_jobs_contract WHERE status IN (1,2) AND delivery_date < now() AND contract='%s' AND id=%lu AND member_id =%lu",in["job_contract"].c_str(),in["job_id"].Long(),in["member_id"].Long() );
|
|
if (ret)
|
|
{
|
|
pgsql_exec("UPDATE members_jobs_contract SET status = %lu,updated=now() WHERE id = %lu",CONTRACT_CANCEL_CONTRACT, in["job_id"].Long() );
|
|
// make sure the update was done
|
|
if ( load_db_record( out, "SELECT * FROM members_jobs_contract WHERE status = %lu AND id=%lu AND member_id =%lu",CONTRACT_CANCEL_CONTRACT,in["job_id"].Long(),in["member_id"].Long() ) )
|
|
{
|
|
//let us do the accounting parts here now
|
|
CVars y;
|
|
y["member_id"] = in["member_id"]; // note we are actually paying the client_id
|
|
y["contract_id"] = in["job_id"];
|
|
y["code"] = "COCNL";
|
|
y["dir"] = DIR_TARGET;
|
|
y["job_status"] = CONTRACT_CANCEL_CONTRACT;
|
|
if ( WrenchCanceContractPayment(y,out) == PHP_CREATED_OK )
|
|
{ // if you reserve pauments
|
|
//char offer_code[15] = "";
|
|
//GetOfferCode(offer_id, offer_code, sizeof (offer_code)); // this stamp the offer code directly in that call
|
|
pgsql_exec("UPDATE members_jobs_contract SET updated = now(),payment_date=now() WHERE id = %lu",out["job_id"].Long());
|
|
}
|
|
else
|
|
{
|
|
|
|
}
|
|
//----------------------------------------
|
|
|
|
project_email(CONTRACT_CANCEL_CONTRACT, in, out); //USES in["contract_id"]
|
|
out["result"] = "This task is now complete. We have notified all parties accordingly";
|
|
}
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
}
|
|
|
|
|
|
//$mysql = "SELECT * FROM members_jobs_contract WHERE contract ='" . $data['job_contract'] . "' AND id =" . $data['job_id'];
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
Array ( [member_id] => 3 [proc] => ACCEPTCMP [job_id] => 13 [job_contract] => 7BW9B9R8BB [job_action] => 5 )
|
|
|
|
#define CONTRACT_NOTIFY_COMPLETE 4
|
|
#define CONTRACT_REQUEST_CANCEL 3
|
|
#define CONTRACT_ACCEPT_COMPLETE 5
|
|
#define CONTRACT_REJECT_COMPLETE 1
|
|
*/
|
|
logfmt( logINFO, "/WrenchContractStatus()" );
|
|
return 0;
|
|
}
|
|
|
|
long WrenchContractMessage( CVars in, CVars &out )
|
|
{
|
|
out["message_sent"] = "0";
|
|
/*
|
|
--- // note thet we did not refrenece members table - this is to ensure that the system can insert items too into the disucssion
|
|
CREATE TABLE jobs_contract_message (
|
|
id SERIAL,
|
|
member_id INT,
|
|
contract VARCHAR(25) REFERENCES members_jobs_contract(contract),
|
|
msg_type VARCHAR(5) NOT NULL,
|
|
message TEXT,
|
|
status INT DEFAULT 1,
|
|
created timestamp without time zone DEFAULT now()
|
|
);
|
|
|
|
$msgArray = array();
|
|
$msgArray['message'] = trim($this->input->post('jobmessage'));
|
|
$msgArray['contract'] = $this->input->post('contractId');
|
|
$msgArray['msg_type'] = 'TEXT';
|
|
$msgArray['member_id'] = $_SESSION['member_id']; // = $ret->email;
|
|
*/
|
|
long ret = PHP_API_BAD_PARAM;
|
|
logfmt( logINFO, "WrenchContractMessage()" );
|
|
ULONG message_id = 0;
|
|
|
|
REQ_LONG( in, "member_id", 1, -1 );
|
|
REQ_STRING (in, "contract", 10, 25, "(.*)");
|
|
REQ_STRING (in, "msg_type", 1, 5, "(.*)");
|
|
REQ_STRING (in, "message", 1, 1299, "(.*)");
|
|
|
|
const char * loc = getenv("REMOTE_ADDR");
|
|
in["loc"] = loc; in["loc"].set_valid(true);
|
|
CVars x;
|
|
x["member_id"] = in["member_id"]; x["member_id"].set_valid( true );
|
|
x["contract"] = in["contract"]; x["contract"].set_valid( true );
|
|
x["msg_type"] = in["msg_type"]; x["msg_type"].set_valid( true );
|
|
x["message"] = in["message"]; x["message"].set_valid( true );
|
|
|
|
message_id = insert_db_record( DBS_VALID, "jobs_contract_message", "jobs_contract_message_id_seq", x );
|
|
|
|
if (message_id) {
|
|
ret = PHP_CREATED_OK;
|
|
x["message_id"] = message_id; x["message_id"].set_valid( true );
|
|
job_email(JOBS_MESSAGE_ADDED,x,out);
|
|
load_db_record( out, "SELECT *,id AS message_id FROM jobs_contract_message WHERE id = %lu ", message_id );
|
|
out["status"] = "Message Sent";
|
|
out["message_sent"] = "200";
|
|
} else {
|
|
out["status"] = "Unable to send message";
|
|
}
|
|
|
|
logfmt( logINFO, "/WrenchContractMessage()" );
|
|
return ret;
|
|
}
|
|
|
|
|
|
long WrenchEditJobs33( CVars in, CVars &out )
|
|
{
|
|
long ret = PHP_API_BAD_PARAM;
|
|
logfmt( logINFO, "LoginWrenchBoardAccount()" );
|
|
REQ_STRING (in, "username", 5, 49, "(.*)");
|
|
REQ_STRING (in, "password", 5, 49, "(.*)");
|
|
REQ_STRING (in, "sessionid", 4, 40, "(.*)");
|
|
OPTIONAL( in, "loc" ) REQ_STRING (in, "loc", 3, 15, "(.*)");
|
|
|
|
const char * loc = getenv("REMOTE_ADDR");
|
|
in["loc"] = loc; in["loc"].set_valid(true);
|
|
|
|
ret = load_db_record( out, "SELECT *,id AS member_id FROM members WHERE status=1 AND LOWER(username)=LOWER('%s') AND password= md5('%s')", in["username"].c_str(), in["password"].c_str() );
|
|
if (ret) {
|
|
|
|
} else {
|
|
out["status"] = "Invalid username and/or password";
|
|
}
|
|
|
|
|
|
logfmt( logINFO, "/LoginWrenchBoardAccount()" );
|
|
return ret;
|
|
}
|
|
|
|
//******************************************************************************
|