/** CSV: @mod: reference to current StripeGate module object @account_id: index of account to process, or array of such indices, or FALSE if @record_id is provided @record_id: index of record to process, or array of such indices, or FALSE to process @account_id, default=FALSE @fp: handle of open file, if writing data to disk, or FALSE if constructing in memory, default = FALSE @$sep: field-separator in output data, assumed single-byte ASCII, default = ',' Constructs a CSV string for specified/all records belonging to @account_id, and returns the string or writes it progressively to the file associated with @fp (which must be opened and closed upstream) To avoid field-corruption, existing separators in headings or data are converted to something else, generally like &#...; (except when the separator is '&', '#' or ';', those become %...%) Returns: TRUE/string, or FALSE on error */ private function CSV(&$mod, $account_id = FALSE, $record_id = FALSE, $fp = FALSE, $sep = ',') { global $db; $pref = cms_db_prefix(); $adata = $db->GetAssoc('SELECT account_id,name,currency,amountformat FROM ' . $pref . 'module_sgt_account'); if (!$adata) { return FALSE; } if ($account_id) { if (is_array($account_id)) { $sql = 'SELECT record_id FROM ' . $pref . 'module_sgt_record WHERE account_id IN(' . implode('?,', count($account_id) - 1) . '?) ORDER BY account_id,recorded'; $all = $db->GetCol($sql, $account_id); } else { $sql = 'SELECT record_id FROM ' . $pref . 'module_sgt_record WHERE account_id=? ORDER BY recorded'; $all = $db->GetCol($sql, array($account_id)); } } elseif ($record_id) { if (is_array($record_id)) { $all = $record_id; } else { $all = array($record_id); } } else { return FALSE; } foreach ($adata as $id => &$row) { $row['symbol'] = StripeGate\Utils::GetSymbol($row['currency']); } unset($row); if ($fp && ini_get('mbstring.internal_encoding') !== FALSE) { //send to file, and conversion is possible $config = cmsms()->GetConfig(); if (!empty($config['default_encoding'])) { $defchars = trim($config['default_encoding']); } else { $defchars = 'UTF-8'; } $expchars = $mod->GetPreference('export_file_encoding', 'ISO-8859-1'); $convert = strcasecmp($expchars, $defchars) != 0; } else { $convert = FALSE; } $sep2 = $sep != ' ' ? ' ' : ','; switch ($sep) { case '&': $r = '%38%'; break; case '#': $r = '%35%'; break; case ';': $r = '%59%'; break; default: $r = '&#' . ord($sep) . ';'; break; } $strip = $mod->GetPreference('strip_on_export', FALSE); //header line $outstr = implode($sep, array('account', 'amount', 'recorded', 'stripe identifier', 'paywhat', 'payfor')); $outstr .= PHP_EOL; if ($all) { $sql = 'SELECT * FROM ' . $pref . 'module_sgt_record WHERE record_id IN(' . implode(',', $all) . ')'; $all = $db->GetArray($sql); //data lines(s) foreach ($all as &$row) { unset($row['record_id']); $aid = (int) $row['account_id']; unset($row['account_id']); $fv = $adata[$aid]['name']; if ($strip) { $fv = strip_tags($fv); } $fv = str_replace($sep, $r, $fv); $outstr .= preg_replace('/[\\n\\t\\r]/', $sep2, $fv); foreach ($row as $fn => $fv) { switch ($fn) { case 'amount': $outstr .= $sep . StripeGate\Utils::GetPublicAmount($fv, $adata[$aid]['amountformat'], $adata[$aid]['symbol']); break; case 'recorded': $outstr .= $sep . date('Y-m-d H:i:s', $fv); break; default: if ($strip) { $fv = strip_tags($fv); } $fv = str_replace($sep, $r, $fv); $outstr .= $sep . preg_replace('/[\\n\\t\\r]/', $sep2, $fv); } } $outstr .= PHP_EOL; if ($fp) { if ($convert) { $conv = mb_convert_encoding($outstr, $expchars, $defchars); fwrite($fp, $conv); unset($conv); } else { fwrite($fp, $outstr); } $outstr = ''; } } unset($row); if ($fp) { return TRUE; } else { return $outstr; } //encoding conversion upstream } else { //no data, produce just a header line if ($fp) { if ($convert) { $conv = mb_convert_encoding($outstr, $expchars, $defchars); fwrite($fp, $conv); unset($conv); } else { fwrite($fp, $outstr); } return TRUE; } return $outstr; //encoding conversion upstream } }
//missing-value errors $err1 = $this->Lang('err_nonum'); $err2 = $this->Lang('err_nocvc'); $err3 = $this->Lang('err_nomonth'); $err4 = $this->Lang('err_noyear'); $err5 = $this->Lang('err_noamount'); $err6 = $this->Lang('err_nowho'); $err7 = $this->Lang('err_nopurpose'); //bad-value errors $err12 = $this->Lang('err_badnum'); $err13 = $this->Lang('err_badmonth'); $yr = date('Y'); $cent = substr($yr, 0, 2); $err14 = $this->Lang('err_badyear', $yr); $rawmin = preg_replace('/\\D/', '', $row['minpay']); $min = StripeGate\Utils::GetPublicAmount($rawmin, $row['amountformat'], $symbol); $err15 = $this->Lang('err_toosmall', $min); if (preg_match('/^(.*)?(S)(\\W+)?(\\d*)$/', $row['amountformat'], $matches)) { $sep = $matches[1] ? $symbol : $matches[3]; $places = strlen($matches[4]); } else { //defaults like US$ $sep = '.'; $places = 2; } $jsfuncs = array(); $jsloads = array(); $jsincs = array(); $baseurl = $this->GetModuleURLPath(); $jsfuncs[] = <<<EOS function lock_inputs() {
//]]> </script> EOS; $tplvars['cssscript'] = $t; } //button label $symbol = StripeGate\Utils::GetSymbol($row['currency']); if (strpos($params['amount'], $symbol) !== FALSE) { $t = $symbol; } else { $t = ''; } //cope with optional currency symbol in amount $amount = StripeGate\Utils::GetPrivateAmount($params['amount'], $row['amountformat'], $t); $public = StripeGate\Utils::GetPublicAmount($amount, $row['amountformat'], $symbol); $tplvars['submit'] = $this->Lang('pay', $public); /* NB CMSMS top interpreter (index.php) includes undocumented response to a parameter 'showtemplate' == 'false' (NO prefix, NOT any other flavour of FALSE) instead of that, the backend ajax processor clears all output buffers before reporting NB maybe faster to provide a returnid to index.php, instead of forcing it to interpret the default */ //ajax-parameters : mimic API link-creators $myname = $this->GetName(); $ajaxfirst = "mact={$myname},cntnt01,payprocess,0&cntnt01stg_account={$row['account_id']}&cntnt01stg_amount={$amount}&cntnt01stg_token="; $defaulterr = $this->Lang('err_pay'); $jsincs[] = <<<EOS <script src="https://checkout.stripe.com/checkout.js"></script> EOS; $jsloads[] = <<<EOS var handler = StripeCheckout.configure({