function get() { $graph = array($this); $sql = "INSERT INTO reports \n\t\t\t(txntype, from_brand, to_brand, amount, max_id, max_updated, keyword, status)\n\t\t\tSELECT txntype, \n\t\t\t\tf.brand_id AS from_brand, \n\t\t\t\tt.brand_id AS to_brand, \n\t\t\t\tSUM(r.amount) AS amount, \n\t\t\t\tMAX(record_id) AS max_id,\n\t\t\t\tMAX(r.updated) AS max_updated,\n\t\t\t\tp.keyword AS keyword,\n\t\t\t\tr.status AS status\n\t\t\tFROM records r\n\t\t\tINNER JOIN accounts f ON f.account_id = r.from_acct\n\t\t\tINNER JOIN accounts t ON t.account_id = r.to_acct\n\t\t\tLEFT JOIN promos p ON p.promo_id = r.promo_id\n\t\t\tWHERE record_id > (SELECT COALESCE(MAX(max_id),0) AS max_id FROM reports)\n\t\t\t\tAND (status < 0 OR status > 6) \n\t\t\t\tAND txntype IN ('np','pn') \n\t\t\tGROUP BY txntype, from_brand, to_brand, keyword"; $numInserted = DBquery::set($sql); //$this->sql = $sql; $this->numInserted = $success; return $graph; }
function updateTally($tally_id, $issued, $intrause, $inflow, $outflow, $num_members, $member_hours) { if (!$issued) { $issued = 0; } if (!$intrause) { $intrause = 0; } if (!$inflow) { $inflow = 0; } if (!$outflow) { $outflow = 0; } $sql = "UPDATE tallies SET updated=NOW(), issued={$issued}, intrause={$intrause}, inflow={$inflow}, outflow={$outflow}, num_members={$num_members}, member_hours={$member_hours}\n\t\t\tWHERE tally_id={$tally_id}"; return DBquery::set($sql); }
function get() { $graph = array($this); $brands = "SELECT brand_id\n\t\t\tFROM accounts a\n\t\t\tINNER JOIN (\n\t\t\t\tSELECT from_acct, MAX(created) AS created\n\t\t\t\tFROM records\n\t\t\t\tWHERE txntype='np'\n\t\t\t\tGROUP BY from_acct\n\t\t\t) r ON a.account_id = r.from_acct AND TIMESTAMPDIFF(HOUR,r.created,NOW()) > 168"; $sql = "SELECT brand_id, SUM(by_all_limit*amount) AS weeklyBudget\n\t\t\tFROM promos p \n\t\t\tINNER JOIN relays r ON p.relay_id = r.relay_id\n\t\t\tWHERE p.brand_id IN ({$brands})\n\t\t\tGROUP BY brand_id"; $rows = DBquery::get($sql); foreach ($rows as $r) { $sql = "CALL budgetRevExp({$r['brand_id']})"; $b = DBquery::get($sql)[0]; $b['weeklyBudget'] = $r['weeklyBudget']; $b['plannedAdd'] = min($r['weeklyBudget'] - $b['revBal'], $r['weeklyBudget'] - $b['expBal']); if ($b['plannedAdd']) { $sql = "INSERT INTO records (txntype,from_acct, to_acct, amount, note, status) VALUES ('np', {$b['revAcct']}, {$b['expAcct']}, {$b['plannedAdd']}, 'auto-add', 0);"; $b['sql'] = $sql; $b['numInserted'] = DBquery::set($sql); } $graph[] = $b; } return $graph; }
function trackReversal($rev_record_id) { $sql = "INSERT INTO reversals (orig_record_id, rev_record_id, adjusted_amt, txntype, created)\n\t\tVALUES ({$this->orig_record_id}, {$rev_record_id}, {$this->adjusted_amt}, '{$this->txnType}', NOW())"; $rowCount = DBquery::set($sql); if (!$rowCount) { Error::http(500, "Error: insert query failed."); } $id = DBquery::$conn->lastInsertId(); //echo " id=$id "; return $id; }
function resetSimMember() { $sql = "UPDATE members m \n\t\tJOIN brands b USING (brand_id)\n\t\tSET m.ended=NOW() \n\t\tWHERE member_id=? AND b.type_system='sim'"; DBquery::set($sql, array($this->member_id)); }
function setPassword($row) { if (!$row) { Error::http(40, "There is no user found to verify against the submitted code, email='{$this->email}'."); } if ($time > $row['ver_expires']) { Error::http(403, "The verification code has expired. Please use the form again to request a new verificaion code to be send to your email."); } if ($this->ver_code != $row['ver_code']) { Error::http(403, 'The submitted verification code does not match the one on record.'); } $pwd = password_hash($this->pwd, PASSWORD_BCRYPT); $sql = "UPDATE users SET password=? WHERE user_id=?"; DBquery::set($sql, array($pwd, $row['user_id'])); $this->okToSet = array("otk", "user_id", "login_provider"); $this->addKeyVal('user_id', $this->user_id); $this->addKeyVal('otk', mt_rand(1, 99999999)); $this->addKeyVal('login_provider', 'gp'); $this->update(array("token_id" => $this->token_id, "otk" => Requester::$otk, "token_val" => '0')); return array($this); }
function verifyBals() { if (1 * $this->verifier->from_holder['balance'] < $this->amount) { if ($this->record_id) { $sql = "UPDATE records SET status=-1 WHERE record_id={$this->record_id}"; DBquery::set($sql); } return "Account #{$this->from_acct} has insufficient balance. "; } }
<?php header('content-type: text/plain'); set_time_limit(0); error_reporting(error_reporting() & ~E_NOTICE); chdir("../"); include "utils/Utils.php"; include "config-public.php"; if (!isset($_GET['db'])) { Error::http(400, "Please specify a db='name' value in the URL query parameter."); } $targets = explode(",", $_GET['db']); $targets = array_intersect($targets, array_keys($dbs)); if (!$targets) { Error::http(403, "The db name value(s) did not match any of the {$dbs} keys in config file."); } DBquery::init($dbs, $targets); foreach ($targets as $alias) { DBquery::select_db($alias); if (!file_exists("tools/data_{$alias}.sql")) { Error::http(403, "Data file not found for db alias='{$alias}'."); } DBquery::set(file_get_contents("tools/db_schema.sql")); DBquery::set(file_get_contents("tools/data_{$alias}.sql")); }
function transact(&$from, &$to) { if ($from['brand_id'] == $to['brand_id']) { return; } if (!$from['expBal'] or !$to['revBal']) { return; } if (!$this->rating[$from['brand_id']] or !$this->rating[$to['brand_id']]) { return; } if ($from['expBal'] == 1 or $to['revBal'] == 1) { $amount = 1; } else { $amount = min(20, mt_rand(1, max(2, round(min($from['expBal'] / 4, $to['revBal'] / 4))))); } //round($to['expBal']))); if ($amount > $from['expBal'] or $amount > $to['revBal']) { return; } $fromAcct = $from['expAcct']; $toAcct = $to['revAcct']; $sql = "INSERT INTO records (txntype,from_acct,from_user,to_acct,to_user,amount,note,ref_id,status,created,updated) \n\t\t\tVALUES ('pn',{$fromAcct},0,{$toAcct},0,{$amount},'sim',{$this->weekNum},0,{$this->sqldate},{$this->sqldate})"; $from['outflow'] = $sql; DBquery::set($sql); $from['record_id'] = DBquery::$conn->lastInsertId(); $status = $this->advise($from, $to); if ($status == 7) { DBquery::get("CALL approveRecord(" . $from['record_id'] . ")"); $from['expBal'] += -1 * $amount; $to['revBal'] += -1 * $amount; if ($this->currWeek != $this->weekNum) { $sql = "UPDATE records SET status=?, updated={$this->sqldate} WHERE record_id=?"; DBquery::set($sql, array($status, $from['record_id'])); } } else { $sql = "UPDATE records SET status=?, updated={$this->sqldate} WHERE record_id=?"; DBquery::set($sql, array($status, $from['record_id'])); } }
function adjustQty() { if (!isset($this->qty) or $this->qty < 1) { return; } $sql = "UPDATE promos SET qty = qty-1 WHERE promo_id=? AND qty>0"; $mssg = DBquery::set($sql, array($this->relay_id)); }
function update($arr = array()) { if ($arr) { $this->setFilters($arr); } if (!$this->filterCond or !$this->filterValArr) { Error::http(403, "A filter key=value is required when updating {$this->table} information."); } if ($bannedSet = array_diff($this->keyArr, $this->okToSet)) { Error::http(403, "These parameters may not be set by the user: "******"."); } $keyValStr = implode(",", $this->keyMarkerArr); $valArr = array_merge($this->valArr, $this->filterValArr); $sql = "UPDATE {$this->table} SET {$keyValStr}, updated=NOW() WHERE {$this->filterCond}"; //exit(json_encode($sql .'... '. json_encode($valArr))); $rowCount = DBquery::set($sql, $valArr); //if (!$rowCount) Error::http(500, "Affected rows=0."); }