function update_link_payment($pid, $data, $success, $raw) { global $db, $tables; $pdata = $db->GetRow("SELECT * FROM `{$tables['payment']['name']}` WHERE `ID` = " . $db->qstr($pid)); if (!$pdata['ID']) { return false; } $pdata['NAME'] = $data['name']; $pdata['EMAIL'] = $data['email']; $pdata['PAYED_TOTAL'] = (int) $data['total']; $pdata['PAYED_QUANTITY'] = (double) $data['quantity']; $pdata['CONFIRMED'] = $success ? 1 : 0; $pdata['CONFIRM_DATE'] = gmdate('Y-m-d H:i:s'); $pdate['RAW_LOG'] = $raw; if ((double) $pdata['PAYED_TOTAL'] < (double) $pdata['TOTAL']) { $pdata['CONFIRMED'] = -1; } db_replace('payment', $pdata, 'ID'); $ldata = $db->GetRow("SELECT * FROM `{$tables['link']['name']}` WHERE `ID` = " . $db->qstr($pdata['LINK_ID'])); send_payment_notifications($pdata, $ldata); //Take no action if link not found if (!$ldata['ID']) { return false; } $ldata['EXPIRY_DATE'] = ''; if ($pdata['CONFIRMED'] != 1 || (double) $pdata['PAYED_TOTAL'] < (double) $pdata['TOTAL']) { $ldata['PAYED'] = 0; } else { $ldata['PAYED'] = $pdata['ID']; if (PAY_AUTO_ACCEPT) { $ldata['STATUS'] = 2; $exp_date = calculate_expiry_date(time(), $pdata['QUANTITY'], $pdata['UM']); if ($exp_date != 0) { $ldata['EXPIRY_DATE'] = gmdate('Y-m-d H:i:s', $exp_date); } } } db_replace('link', $ldata, 'ID'); }
$tpl->assign('ENABLE_REWRITE', ENABLE_REWRITE); if ($_REQUEST['action']) { list($action, $id, $val) = explode(':', $_REQUEST['action']); } $tpl->assign('stats', array(0 => _L('Inactive'), 1 => _L('Pending'), 2 => _L('Active'))); switch ($action) { case 'S': //Set Status $error = false; if (PAY_ENABLE && $val == 2) { $sql = "SELECT `ID`, `PAYED`, `STATUS`, `EXPIRY_DATE` FROM `{$tables['link']['name']}` WHERE `ID` = " . $db->qstr($id); $data = $db->GetRow($sql); if ($data['PAYED'] > 0) { $sql = "SELECT `ID`, `QUANTITY`, `UM` FROM `{$tables['payment']['name']}` WHERE `ID` = " . $db->qstr($data['PAYED']); $pdata = $db->GetRow($sql); $exp_date = calculate_expiry_date(time(), $pdata['QUANTITY'], $pdata['UM']); if ($exp_date != 0 && $data['EXPIRY_DATE'] == '') { $data['EXPIRY_DATE'] = gmdate('Y-m-d H:i:s', $exp_date); } } $data['STATUS'] = 2; if (db_replace('link', $data, 'ID') > 0) { send_status_notifications($id); } else { $tpl->assign('sql_error', $db->ErrorMsg()); $error = true; } } else { if ($db->Execute("UPDATE `{$tables['link']['name']}` SET `STATUS` = " . $db->qstr($val) . " WHERE `ID` = " . $db->qstr($id))) { send_status_notifications($id); } else {