#include "common_tool.h" #include "clog.h" #include "cgi.h" #include "input.h" #include "wrenchboard_api.h" //#include "interswitch_sendmoney.h" #include "safestring.h" #include "cfg.h" #include #include "pgsql_wrapper.h" #include "pgsql.h" //char confirmation[20] = ""; //Confirmation(payment_id, confirmation, sizeof (confirmation)); void GenerateConfirmationSeed( char * number, int sz, int seed ); void GenerateConfirmation( char * number, int sz ) { GenerateConfirmationSeed(number,sz,1); } void GenerateConfirmationSeed( char * number, int sz, int seed ) { char chars[] = "WRB01234WRB56789WRB"; int n = sizeof(chars); int i; /* time_t t; time( &t ); pid_t pid = getpid(); srand(t+pid); */ srand((unsigned int)time((time_t *)NULL)); for ( i=0; i<10 && i1 && k==i) { number[i] = chars[n-k]; } else { number[i] = chars[ (int) ( (n-1.0)*rand()/(RAND_MAX+1.0)) ]; } } number[i] = 0; } void Confirmation( unsigned long payment_id, char * number, int sz ) { SQLINTEGER rows; char confirmation[11]; // Lock table to prevent generation of two identical confirmation numbers pgsql_exec("BEGIN; LOCK TABLE members_payments;" ); int i = 0; do { GenerateConfirmationSeed( confirmation, sizeof(confirmation), i++ ); //st.CloseCursor(); rows = 0; const PGresult *res = pgsql_query("SELECT id FROM members_payments WHERE confirmation='%s'", confirmation ); if (res!=NULL ) { rows = pgsql_num_rows(res); } } while ( rows>0 && i<100 ); pgsql_exec("UPDATE members_payments SET confirmation='%s', dt_confirmed=now() WHERE id=%lu", confirmation, payment_id ); pgsql_exec("COMMIT" ); // Unlock table 'data' strsafecpy( number, confirmation, sz ); } void GetOfferCode( unsigned long offer_id, char * number, int sz ) { SQLINTEGER rows; char offer_code[14]; // Lock table to prevent generation of two identical confirmation numbers pgsql_exec("BEGIN; LOCK TABLE members_jobs_offer;" ); int i = 0; do { GenerateConfirmationSeed( offer_code, sizeof(offer_code), i++ ); //st.CloseCursor(); rows = 0; const PGresult *res = pgsql_query("SELECT id FROM members_jobs_offer WHERE offer_code='%s'", offer_code ); if (res!=NULL ) { rows = pgsql_num_rows(res); } } while ( rows>0 && i<100 ); pgsql_exec("UPDATE members_jobs_offer SET offer_code='%s' WHERE id=%lu", offer_code, offer_id ); pgsql_exec("COMMIT" ); // Unlock table 'data' strsafecpy( number, offer_code, sz ); }