public function get_add_payid_handler() { global $FANNIE_PLUGIN_SETTINGS, $FANNIE_OP_DB, $FANNIE_TRANS_DB, $FANNIE_ROOT; $ret = array(); $dbc = FannieDB::get($FANNIE_OP_DB); $model = new CustdataModel($dbc); $model->CardNo($this->add); if (count($model->find()) == 0) { $ret['error'] = 'Mem# ' . $this->add . ' does not exist!'; } else { $model->personNum(1); $model->load(); $ret['name'] = $model->LastName() . ', ' . $model->FirstName(); $dbc = FannieDB::get($FANNIE_TRANS_DB); $model = new ArLiveBalanceModel($dbc); $model->card_no($this->add); $balance = 0; if ($model->load()) { $balance = $model->balance(); } $ret['balance'] = $balance; $dbc = FannieDB::get($FANNIE_PLUGIN_SETTINGS['StaffArPayrollDB']); $model = new StaffArAccountsModel($dbc); $model->card_no($this->add); $model->nextPayment(0); $model->payrollIdentifier($this->payid); $model->save(); } echo json_encode($ret); return false; }
function updateCustomerAllLanes($cardno) { global $sql; deleteCustomerAllLanes($cardno); $model = new CustdataModel($sql); $model->CardNo($cardno); foreach ($model->find('personNum') as $obj) { $obj->pushToLanes(); } redoCard($cardno); }
public function preprocess() { global $FANNIE_OP_DB, $FANNIE_PLUGIN_LIST, $FANNIE_PLUGIN_SETTINGS; if (!isset($FANNIE_PLUGIN_LIST) || !in_array('CoopCred', $FANNIE_PLUGIN_LIST)) { $this->errors[] = "The Coop Cred plugin is not enabled."; return False; } if (array_key_exists('CoopCredDatabase', $FANNIE_PLUGIN_SETTINGS) && $FANNIE_PLUGIN_SETTINGS['CoopCredDatabase'] != "") { $dbc = FannieDB::get($FANNIE_PLUGIN_SETTINGS['CoopCredDatabase']); } else { $this->errors[] = "The Coop Cred database is not assigned in the " . "Coop Cred plugin configuration."; return False; } $this->cardNo = (int) FormLib::get('memNum', 0); $this->programID = (int) FormLib::get('programID', 0); $ccpModel = new CCredProgramsModel($dbc); $ccpModel->programID($this->programID); $prog = array_pop($ccpModel->find()); if ($prog != null) { $this->programName = $prog->programName(); $this->programBankID = $prog->bankID(); } else { $this->errors[] = "Error: Program ID {$this->programID} is not known."; return False; } $dbc = FannieDB::get($FANNIE_OP_DB); $cdModel = new CustdataModel($dbc); $cdModel->CardNo($this->cardNo); $cdModel->personNum(1); $mem = array_pop($cdModel->find()); if ($mem != null) { $this->memberFullName = $mem->FirstName() . " " . $mem->LastName(); } else { $noop = 1; $this->errors[] = "Error: Member {$this->cardNo} is not known."; return False; } /* 25Mar2015 Under bootstrap the non-sortable format doesn't really work. */ $this->sortable = True; return parent::preprocess(); }
function get_id_first_last_handler() { global $FANNIE_OP_DB; $dbc = FannieDB::get($FANNIE_OP_DB); if (empty($this->id) && empty($this->last)) { return True; } // invalid search if (!empty($this->id)) { $custdata = new CustdataModel($dbc); $custdata->CardNo($this->id); $custdata->Type('PC'); if (count($custdata->find()) > 0) { header('Location: GumMainPage.php?id=' . $this->id); return False; } $cards = new MemberCardsModel($dbc); $cards->upc(str_pad($this->id, 13, '0', STR_PAD_LEFT)); foreach ($cards->find() as $obj) { header('Location: GumMainPage.php?id=' . $obj->card_no()); return False; } } else { $q = $dbc->prepare_statement('SELECT CardNo, LastName, FirstName FROM custdata WHERE LastName LIKE ? AND FirstName LIKE ? AND Type = \'PC\' ORDER BY LastName,FirstName,CardNo'); $r = $dbc->exec_statement($q, array($this->last . '%', $this->first . '%')); $this->__models['custdata'] = array(); while ($w = $dbc->fetch_row($r)) { $this->__models['custdata'][] = $w; } if (count($this->__models['custdata']) == 1) { header('Location: GumMainPage.php?id=' . $this->__models['custdata'][0]['CardNo']); return False; } } return true; }
function process_file($linedata) { global $FANNIE_OP_DB, $FANNIE_TRANS_DB; $EMP_NO = $this->config->get('EMP_NO'); $LANE_NO = $this->config->get('REGISTER_NO'); $OFFSET_DEPT = $this->config->get('MISC_DEPT'); $card_no = $this->get_column_index('card_no'); $classA = $this->get_column_index('classA'); $classB = $this->get_column_index('classB'); $note = $this->get_column_index('note'); $dbc = FannieDB::get($FANNIE_OP_DB); $dtrans_table = $FANNIE_TRANS_DB . $dbc->sep() . 'dtransactions'; $prep = $dbc->prepare('SELECT MAX(trans_no) as tn FROM ' . $dtrans_table . ' WHERE emp_no=? AND register_no=?'); $result = $dbc->execute($prep, array($EMP_NO, $LANE_NO)); $trans = 1; if ($dbc->num_rows($result) > 0) { $row = $dbc->fetch_row($result); if ($row['tn'] != '') { $trans = $row['tn'] + 1; } } foreach ($linedata as $data) { if (!isset($data[$card_no])) { continue; } elseif (!is_numeric($data[$card_no])) { continue; } $cn = trim($data[$card_no]); $a_amt = trim($data[$classA], '$ '); $b_amt = trim($data[$classB], '$ '); $offset_amt = $a_amt + $b_amt; if ($offset_amt == 0) { continue; } $now = date('Y-m-d H:i:s'); $custdata = new CustdataModel($dbc); $custdata->CardNo($cn); $custdata->personNum(1); $custdata->load(); $meminfo = new MeminfoModel($dbc); $meminfo->card_no($cn); $meminfo->load(); $susp = new SuspensionsModel($dbc); $susp->cardno($cn); $susp->load(); $susp->type('T'); $susp->memtype1($custdata->memType()); $susp->memtype2($custdata->Type()); $susp->suspDate($now); $susp->discount($custdata->Discount()); $susp->chargelimit($custdata->ChargeLimit()); $susp->mailflag($meminfo->ads_OK()); $susp->reasoncode(64); $susp->save(); $suspHistory = new SuspensionHistoryModel($dbc); $suspHistory->username('abandon-import'); $suspHistory->postdate($now); $suspHistory->cardno($cn); $suspHistory->reasoncode(64); $suspHistory->save(); $meminfo->ads_OK(0); $meminfo->save(); $custdata->reset(); $custdata->CardNo($cn); foreach ($custdata->find() as $obj) { $obj->Type('TERM'); $obj->memType(0); $obj->Discount(0); $obj->ChargeLimit(0); $obj->MemDiscountLimit(0); $obj->save(); } if (isset($data[$note]) && !empty($data[$note])) { $memNote = new MemberNotesModel($dbc); $memNote->cardno($cn); $memNote->note($data[$note]); $memNote->stamp($now); $memNote->username('abandon-import'); $memNote->save(); } $trans_id = 1; if ($a_amt > 0) { $record = DTrans::$DEFAULTS; $record['register_no'] = $LANE_NO; $record['emp_no'] = $EMP_NO; $record['trans_no'] = $trans; $record['upc'] = $a_amt . 'DP992'; $record['description'] = 'Class A Equity'; $record['trans_type'] = 'D'; $record['department'] = 992; $record['unitPrice'] = -1 * $a_amt; $record['total'] = -1 * $a_amt; $record['regPrice'] = -1 * $a_amt; $record['card_no'] = $cn; $record['trans_id'] = $trans_id; $trans_id++; $info = DTrans::parameterize($record, 'datetime', $dbc->now()); $prep = $dbc->prepare("INSERT INTO {$dtrans_table} ({$info['columnString']}) VALUES ({$info['valueString']})"); $dbc->execute($prep, $info['arguments']); } if ($b_amt > 0) { $record = DTrans::$DEFAULTS; $record['register_no'] = $LANE_NO; $record['emp_no'] = $EMP_NO; $record['trans_no'] = $trans; $record['upc'] = $a_amt . 'DP991'; $record['description'] = 'Class B Equity'; $record['trans_type'] = 'D'; $record['department'] = 991; $record['unitPrice'] = -1 * $b_amt; $record['total'] = -1 * $b_amt; $record['regPrice'] = -1 * $b_amt; $record['card_no'] = $cn; $record['trans_id'] = $trans_id; $trans_id++; $info = DTrans::parameterize($record, 'datetime', $dbc->now()); $prep = $dbc->prepare("INSERT INTO {$dtrans_table} ({$info['columnString']}) VALUES ({$info['valueString']})"); $dbc->execute($prep, $info['arguments']); } $record = DTrans::$DEFAULTS; $record['register_no'] = $LANE_NO; $record['emp_no'] = $EMP_NO; $record['trans_no'] = $trans; $record['upc'] = $offset_amt . 'DP' . $OFFSET_DEPT; $record['description'] = 'Abandon Equity'; $record['trans_type'] = 'D'; $record['department'] = $OFFSET_DEPT; $record['unitPrice'] = $offset_amt; $record['total'] = $offset_amt; $record['regPrice'] = $offset_amt; $record['card_no'] = $cn; $record['trans_id'] = $trans_id; $trans_id++; $info = DTrans::parameterize($record, 'datetime', $dbc->now()); $prep = $dbc->prepare("INSERT INTO {$dtrans_table} ({$info['columnString']}) VALUES ({$info['valueString']})"); $dbc->execute($prep, $info['arguments']); $record = DTrans::$DEFAULTS; $record['register_no'] = $LANE_NO; $record['emp_no'] = $EMP_NO; $record['trans_no'] = $trans; $record['upc'] = '0'; $record['description'] = '63350'; $record['trans_type'] = 'C'; $record['trans_subtype'] = 'CM'; $record['card_no'] = $cn; $record['trans_id'] = $trans_id; $info = DTrans::parameterize($record, 'datetime', $dbc->now()); $prep = $dbc->prepare("INSERT INTO {$dtrans_table} ({$info['columnString']}) VALUES ({$info['valueString']})"); $dbc->execute($prep, $info['arguments']); $trans++; } return true; }
/** Update older tables. */ private static function postCustdata($dbc, $id, $json) { $config = \FannieConfig::factory(); $ret = array('errors' => 0, 'error-msg' => ''); /** save dates if provided **/ if (isset($json['startDate']) || isset($json['endDate'])) { $dates = new \MemDatesModel($dbc); $dates->start_date($json['startDate']); $dates->end_date($json['endDate']); $dates->card_no($id); if (!$dates->save()) { $ret['errors']++; $ret['error-msg'] .= 'ErrDates '; } } /** save UPC if provided **/ if (isset($json['idCardUPC'])) { $cards = new \MemberCardsModel($dbc); $cards->card_no($id); if ($json['idCardUPC'] != '') { $cards->upc(\BarcodeLib::padUPC($json['idCardUPC'])); } else { $cards->upc(''); } if (!$cards->save()) { $ret['errors']++; } } /** save contact method if provided **/ if (isset($json['contactMethod'])) { $contact = new \MemContactModel($dbc); $contact->card_no($id); if (isset($json['contactAllowed']) && !$json['contactAllowed']) { $contact->pref(0); } elseif ($json['contactMethod'] == 'email') { $contact->pref(2); } elseif ($json['contactMethod'] == 'both') { $contact->pref(3); } else { $contact->pref(1); } if (!$contact->save()) { $ret['errors']++; $ret['error-msg'] .= 'ErrUPC '; } } /** Custdata and meminfo are messier. Start with account-level settings. */ $custdata = new \CustdataModel($dbc); $custdata->CardNo($id); $custdata_changed = false; $meminfo = new \MeminfoModel($dbc); $meminfo->card_no($id); if (isset($json['addressFirstLine'])) { $street = $json['addressFirstLine']; if (isset($json['addressSecondLine'])) { $street .= "\n" . $json['addressSecondLine']; } $meminfo->street($street); } if (isset($json['city'])) { $meminfo->city($json['city']); } if (isset($json['state'])) { $meminfo->state($json['state']); } if (isset($json['zip'])) { $meminfo->zip($json['zip']); } if (isset($json['contactAllowed'])) { $meminfo->ads_OK($json['contactAllowed']); } if (isset($json['activeStatus']) && $json['activeStatus'] != '') { $custdata->Type($json['activeStatus']); $custdata_changed = true; } elseif (isset($json['memberStatus'])) { $custdata->Type($json['memberStatus']); $custdata_changed = true; } if (isset($json['customerTypeID'])) { $custdata->memType($json['customerTypeID']); $custdata_changed = true; } if (isset($json['chargeLimit'])) { $custdata->ChargeLimit($json['chargeLimit']); $custdata->MemDiscountLimit($json['chargeLimit']); $custdata_changed = true; } if (isset($json['chargeBalance'])) { $custdata->Balance($json['chargeBalance']); $custdata_changed = true; } /** Now loop through per-person settings. Assign the primary account holder's email address and phone number to the global meminfo, but save the other settings using a different per-person custdata instance */ if (isset($json['customers']) && is_array($json['customers']) && count($json['customers']) > 0) { $personNum = 2; foreach ($json['customers'] as $c_json) { if (!isset($c_json['accountHolder'])) { $ret['errors']++; $ret['error-msg'] .= 'ErrAcctHolder '; continue; } $loopCD = new \CustdataModel($dbc); $loopCD->CardNo($id); $loopCD_changed = false; if ($c_json['accountHolder']) { $loopCD->personNum(1); if (isset($c_json['phone'])) { $meminfo->phone($c_json['phone']); } if (isset($c_json['altPhone'])) { $meminfo->email_2($c_json['altPhone']); } if (isset($c_json['email'])) { $meminfo->email_1($c_json['email']); } } elseif (isset($c_json['firstName']) && isset($c_json['lastName']) && $c_json['firstName'] == '' && $c_json['lastName'] == '') { // blank name fields on non-account holder mean // the customer was removed from the account continue; } else { $loopCD->personNum($personNum); $personNum++; } if (isset($c_json['firstName'])) { $loopCD->FirstName($c_json['firstName']); $loopCD_changed = true; } if (isset($c_json['lastName'])) { $loopCD->LastName($c_json['lastName']); $loopCD_changed = true; } if (isset($c_json['chargeAllowed'])) { $loopCD->ChargeOk($c_json['chargeAllowed']); $loopCD_changed = true; } if (isset($c_json['checksAllowed'])) { $loopCD->WriteChecks($c_json['checksAllowed']); $loopCD_changed = true; } if (isset($c_json['staff'])) { $loopCD->staff($c_json['staff']); $loopCD_changed = true; } if (isset($c_json['discount'])) { $loopCD->Discount($c_json['discount']); $loopCD_changed = true; } if (isset($c_json['lowIncomeBenefits'])) { $loopCD->SSI($c_json['lowIncomeBenefits']); $loopCD_changed = true; } if ($loopCD_changed && !$loopCD->save()) { $ret['errors']++; $ret['error-msg'] .= 'ErrPerson '; } } $cleanP = $dbc->prepare('DELETE FROM custdata WHERE CardNo=? AND personNum>=?'); $cleanR = $dbc->execute($cleanP, array($id, $personNum)); } if (!$meminfo->save()) { $ret['errors']++; $ret['error-msg'] .= 'ErrMeminfo '; } /** Finally, apply account-level settings to all custdata records for the account. */ if ($custdata_changed) { $allCD = new \CustdataModel($dbc); $allCD->CardNo($id); foreach ($allCD->find() as $c) { $custdata->personNum($c->personNum()); if (!$custdata->save()) { $ret['errors']++; $ret['error-msg'] .= 'ErrGlobal '; } } } self::setBlueLines($id); // in classic mode sync changes back to the new table if present if ($config->get('CUST_SCHEMA') != 1 && $dbc->tableExists('CustomerAccounts')) { self::postAccount($dbc, $id, $json); } $ret['account'] = self::get($id); return $ret; }
protected function post_id_handler() { global $FANNIE_OP_DB, $FANNIE_TRANS_DB; $this->card_no = $this->id; if ($this->auth_mode == 'None') { return $this->unknownRequestHandler(); } $dbc = FannieDB::get($FANNIE_OP_DB); $note = FormLib::get_form_value('notetext'); $hash = FormLib::get_form_value('_notetext'); if (base64_decode($hash) != $note) { $noteP = $dbc->prepare_statement('INSERT INTO memberNotes (cardno, note, stamp, username) VALUES (?, ?, ' . $dbc->now() . ', ?)'); $noteR = $dbc->exec_statement($noteP, array($this->card_no, str_replace("\n", '<br />', $note), $this->current_user)); } $json = array('cardNo' => $this->id, 'customers' => array()); $account_holder = array('accountHolder' => 1); $account_holder['firstName'] = FormLib::get('FirstName'); $account_holder['lastName'] = FormLib::get('LastName'); $account_holder['customerID'] = FormLib::get('customerID'); $json['addressFirstLine'] = FormLib::get('address1'); $json['addressSecondLine'] = FormLib::get('address2'); $json['city'] = FormLib::get('city'); $json['state'] = FormLib::get('state'); $json['zip'] = FormLib::get('zip'); $account_holder['phone'] = FormLib::get('phone'); $account_holder['altPhone'] = FormLib::get('phone2'); $account_holder['email'] = FormLib::get('email'); $json['contactAllowed'] = FormLib::get('mailflag', 0); $upc = FormLib::get_form_value('upc', false); if ($upc !== false) { if ($upc != '') { $json['idCardUPC'] = BarcodeLib::padUPC($upc); } else { $json['idCardUPC'] = ''; } } if ($this->auth_mode == 'Full') { $json['customerTypeID'] = FormLib::get('memType'); $json['chargeLimit'] = FormLib::get('chargelimit'); $default = new MemtypeModel($dbc); $default->memtype($json['customerTypeID']); $default->load(); $account_holder['discount'] = $default->discount(); $account_holder['staff'] = $default->staff(); $account_holder['chargeAllowed'] = $json['chargeLimit'] == 0 ? 0 : 1; $account_holder['lowIncomeBenefits'] = $default->ssi(); $start = FormLib::get('start_date', ''); /** Interface hides 1900-01-01 dates from the end-user but that's not identical to 0000-00-00. A blank submission should preserve that 1900-01-01 date. */ if ($start == '' && FormLib::get('nonBlankStart') != '') { $start = FormLib::get('nonBlankStart'); } $json['startDate'] = $start; $json['endDate'] = FormLib::get('end_date'); } else { // get account defaults for additional names if needed $account = \COREPOS\Fannie\API\member\MemberREST::get($this->card_no); foreach ($account['customers'] as $c) { if ($c['accountHolder']) { $account_holder['discount'] = $c['discount']; $account_holder['staff'] = $c['staff']; $account_holder['lowIncomeBenefits'] = $c['lowIncomeBenefits']; $account_holder['chargeAllowed'] = $c['chargeAllowed']; } } } $json['customers'][] = $account_holder; $names = array('first' => FormLib::get_form_value('fn'), 'last' => FormLib::get_form_value('ln')); $fn = FormLib::get_form_value('fn'); $ln = FormLib::get_form_value('ln'); $hhID = FormLib::get('hhID'); for ($i = 0; $i < count($fn); $i++) { $set = array('first' => isset($fn[$i]) ? $fn[$i] : '', 'last' => isset($ln[$i]) ? $ln[$i] : '', 'id' => isset($hhID[$i]) ? $hhID[$i] : ''); $json['customers'][] = array('customerID' => $hhID[$i], 'accountHolder' => 0, 'firstName' => $set['first'], 'lastName' => $set['last'], 'discount' => $account_holder['discount'], 'staff' => $account_holder['staff'], 'lowIncomeBenefits' => $account_holder['lowIncomeBenefits'], 'chargeAllowed' => $account_holder['chargeAllowed']); } $resp = \COREPOS\Fannie\API\member\MemberREST::post($this->card_no, $json); $custdata = new CustdataModel($dbc); $custdata->CardNo($this->card_no); foreach ($custdata->find() as $c) { $c->pushToLanes(); } $cards = new MemberCardsModel($dbc); $cards->card_no($this->card_no); $cards->load(); $cards->pushToLanes(); header('Location: PIMemberPage.php?id=' . $this->card_no); return false; }
function post_id_handler() { global $FANNIE_OP_DB; if (!FannieAuth::validateUserQuiet('editmembers') && !FannieAuth::validateUserQuiet('editmembers_csc')) { return $this->unknown_request_handler(); } $dbc = FannieDB::get($FANNIE_OP_DB); $status = FormLib::get_form_value('status', 'INACT'); $codes = FormLib::get_form_value('reasoncodes', array()); $code = 0; foreach ($codes as $selected_code) { $code = $code | (int) $selected_code; } $cas_model = new CustomerAccountSuspensionsModel($dbc); $cas_model->card_no($this->id); $current_id = 0; $account = \COREPOS\Fannie\API\member\MemberREST::get($this->id); if ($code == 0) { // reactivate account // add history/log record, restore settings, delete suspensions record $history = new SuspensionHistoryModel($dbc); $history->username($this->current_user); $history->cardno($this->id); $history->reasoncode(-1); $history->post('Account reactivated'); $history->postdate(date('Y-m-d H:i:s')); $history->save(); $cas_model->reasonCode(0); $cas_model->suspensionTypeID(0); $cas_model->active(0); $cas_model->username($this->current_user); $cas_model->tdate(date('Y-m-d H:i:s')); $cas_model->save(); if (isset($this->__models['suspended'])) { $json = array('cardNo' => $this->id, 'activeStatus' => '', 'memberStatus' => $this->__models['suspended']->memtype2(), 'customerTypeID' => $this->__models['suspended']->memtype1(), 'chargeLimit' => $this->__models['suspended']->chargelimit(), 'contactAllowed' => $this->__models['suspended']->mailflag(), 'customers' => array()); foreach ($account['customers'] as $c) { $c['discount'] = $this->__models['suspended']->discount(); $c['chargeAllowed'] = 1; $json['customers'][] = $c; } \COREPOS\Fannie\API\member\MemberREST::post($this->id, $json); $cust = new CustdataModel($dbc); $cust->CardNo($this->id); foreach ($cust->find() as $obj) { $obj->pushToLanes(); } $this->__models['suspended']->delete(); } } elseif (isset($this->__models['suspended'])) { // account already suspended // add history/log record, update suspended record $m_status = 0; if ($status == 'TERM') { $this->__models['suspended']->type('T'); $m_status = 2; } else { $this->__models['suspended']->type('I'); $m_status = 1; } $this->__models['suspended']->reasoncode($code); $this->__models['suspended']->suspDate(date('Y-m-d H:i:s')); $this->__models['suspended']->save(); $history = new SuspensionHistoryModel($dbc); $history->username($this->current_user); $history->cardno($this->id); $history->reasoncode($code); $history->postdate(date('Y-m-d H:i:s')); $history->save(); $changed = false; $cas_model->active(1); // find most recent active record $current = $cas_model->find('tdate', true); foreach ($current as $obj) { if ($obj->reasonCode() != $code || $obj->suspensionTypeID() != $m_status) { $changed = true; } $cas_model->savedType($obj->savedType()); $cas_model->savedMemType($obj->savedMemType()); $cas_model->savedDiscount($obj->savedDiscount()); $cas_model->savedChargeLimit($obj->savedChargeLimit()); $cas_model->savedMailFlag($obj->savedMailFlag()); // copy "saved" values from current active // suspension record. should only be one break; } // only add a record if something changed. // count($current) of zero means there is no // record. once the migration to the new data // structure is complete, that check won't // be necessary if ($changed || count($current) == 0) { $cas_model->reasonCode($code); $cas_model->username($this->current_user); $cas_model->tdate(date('Y-m-d H:i:s')); $cas_model->suspensionTypeID($m_status); $current_id = $cas_model->save(); } $json = array('cardNo' => $this->id, 'activeStatus' => $status); \COREPOS\Fannie\API\member\MemberREST::post($this->id, $json); } else { // suspend active account // create suspensions and log/history records // set custdata & meminfo to inactive $discount = 0; foreach ($account['customers'] as $c) { if ($c['accountHolder']) { $discount = $c['discount']; break; } } $susp = new SuspensionsModel($dbc); $susp->cardno($this->id); $susp->type($status == 'TERM' ? 'T' : 'I'); $susp->memtype1($account['customerTypeID']); $susp->memtype2($account['memberStatus']); $susp->suspDate(date('Y-m-d H:i:s')); $susp->reason(''); $susp->mailflag($account['contactAllowed']); $susp->discount($discount); $susp->chargelimit($account['chargeLimit']); $susp->reasoncode($code); $susp->save(); $cas_model->savedType($account['memberStatus']); $cas_model->savedMemType($account['customerTypeID']); $cas_model->savedDiscount($discount); $cas_model->savedChargeLimit($account['chargeLimit']); $cas_model->savedMailFlag($account['contactAllowed']); $cas_model->suspensionTypeID($status == 'TERM' ? 2 : 1); $cas_model->tdate(date('Y-m-d H:i:s')); $cas_model->username($this->current_user); $cas_model->reasonCode($code); $cas_model->active(1); $current_id = $cas_model->save(); $history = new SuspensionHistoryModel($dbc); $history->username($this->current_user); $history->cardno($this->id); $history->reasoncode($code); $history->postdate(date('Y-m-d H:i:s')); $history->save(); $json = array('cardNo' => $this->id, 'chargeLimit' => 0, 'activeStatus' => $status, 'customerTypeID' => 0, 'contactAllowed' => 0, 'customers' => array()); foreach ($account['customers'] as $c) { $c['discount'] = 0; $json['customers'][] = $c; } \COREPOS\Fannie\API\member\MemberREST::post($this->id, $json); } // only one CustomerAccountSuspensions record should be active if ($current_id != 0) { $cas_model->reset(); $cas_model->card_no($this->id); $cas_model->active(1); foreach ($cas_model->find() as $obj) { if ($obj->customerAccountSuspensionID() != $current_id) { $obj->active(0); $obj->save(); } } } header('Location: PIMemberPage.php?id=' . $this->id); return False; }
function preprocess() { global $FANNIE_COUNTRY, $FANNIE_MEMBER_MODULES, $FANNIE_OP_DB; $this->country = isset($FANNIE_COUNTRY) && !empty($FANNIE_COUNTRY) ? $FANNIE_COUNTRY : "US"; $this->memNum = FormLib::get_form_value('memNum', False); if ($this->memNum !== false) { $this->title .= $this->memNum; $this->header .= $this->memNum; /* start building prev/next links */ $list = FormLib::get_form_value('l'); list($prevLink, $nextLink) = self::memLinksPrevNext($this->memNum, $list); if (!empty($prevLink)) { $this->header .= ' ' . $prevLink; } if (!empty($nextLink)) { $this->header .= ' ' . $nextLink; } $this->header .= ' ' . '<a href="javascript:history.back();">Back</a>'; $this->header .= ' ' . '<a href="MemberSearchPage.php">Find</a>'; /* end building prev/next links */ /* form was submitted. save input. */ if (FormLib::get_form_value('saveBtn', False) !== False) { $whichBtn = FormLib::get_form_value('saveBtn'); /** get current account settings for reference **/ $account = \COREPOS\Fannie\API\member\MemberREST::get($this->memNum); \COREPOS\Fannie\API\member\MemberModule::setAccount($account); FannieAPI::listModules('MemberModule'); foreach ($FANNIE_MEMBER_MODULES as $mm) { if (class_exists($mm)) { $instance = new $mm(); $this->msgs .= $instance->saveFormData($this->memNum); } } $dbc = FannieDB::get($FANNIE_OP_DB); $custdata = new CustdataModel($dbc); $custdata->CardNo($this->memNum); $members = $custdata->find(); if (is_array($members)) { foreach ($members as $m) { $m->pushToLanes(); } } if (!empty($this->msgs)) { // implies: errors occurred // stay on this page $this->msgs .= '<hr />'; } else { // By default, go back to search page w/ review info. // If user clicked Save & Next and another match is // available, edit the next match $loc = 'MemberSearchPage.php?review=' . $this->memNum; if ($whichBtn == 'Save & Next' && !empty($next)) { $loc = 'MemberEditor.php?memNum=' . $next; } if (is_array($list)) { $loc .= array_reduce($list, function ($c, $i) { return $c . '&l[]=' . $i; }, ''); } header('Location: ' . $loc); return False; } } } else { // cannot operate without a member number // php sapi check makes page unit-testable if (php_sapi_name() !== 'cli') { header('Location: MemberSearchPage.php'); } return false; } return true; // preprocess() }
protected function get_orderID_customer_handler() { $dbc = $this->connection; $dbc->selectDB($this->config->get('OP_DB')); $TRANS = $this->config->get('TRANS_DB') . $dbc->sep(); $orderID = $this->orderID; try { $memNum = $this->form->memNum; } catch (Exception $ex) { $memNum = '0'; } $canEdit = FannieAuth::validateUserQuiet('ordering_edit'); if (empty($orderID)) { $orderID = $this->createEmptyOrder(); } $names = array(); $personNum = 1; $status_row = array('Type' => 'REG', 'status' => ''); $dbc->selectDB($this->config->get('TRANS_DB')); $orderModel = new SpecialOrdersModel($dbc); $orderModel->specialOrderID($orderID); $orderModel->load(); $dbc->selectDB($this->config->get('OP_DB')); // detect member UPC entry if ($memNum > 9999999) { $cards = new MemberCardsModel($dbc); $cards->upc(BarcodeLib::padUPC($memNum)); $memNum = ''; foreach ($cards->find() as $c) { $memNum = $c->card_no(); break; } } // look up member id if applicable if ($memNum === "0") { $findMem = $dbc->prepare("SELECT card_no,voided FROM {$TRANS}PendingSpecialOrder WHERE order_id=?"); $memR = $dbc->execute($findMem, array($orderID)); if ($dbc->numRows($memR) > 0) { $memW = $dbc->fetchRow($memR); $memNum = $memW['card_no']; $personNum = $memW['voided']; } } elseif ($memNum == "") { $prep = $dbc->prepare("UPDATE {$TRANS}PendingSpecialOrder SET card_no=?,voided=0\n WHERE order_id=?"); $dbc->execute($prep, array(0, $orderID)); } else { $prep = $dbc->prepare("UPDATE {$TRANS}PendingSpecialOrder SET card_no=?\n WHERE order_id=?"); $dbc->execute($prep, array($memNum, $orderID)); // clear contact fields if member number changed // so that defaults are reloaded from meminfo $dbc->selectDB($this->config->get('TRANS_DB')); $orderModel->street(''); $orderModel->phone(''); $orderModel->save(); $orderModel->specialOrderID($orderID); $orderModel->load(); $dbc->selectDB($this->config->get('OP_DB')); // look up personnum, correct if it hasn't been set $pendQ = $dbc->prepare_statement("SELECT voided FROM {$TRANS}PendingSpecialOrder\n WHERE order_id=?"); $personNum = $dbc->getValue($pendQ, array($orderID)); if ($personNum == 0) { $personNum = 1; $upP = $dbc->prepare_statement("UPDATE {$TRANS}PendingSpecialOrder SET voided=?\n WHERE order_id=?"); $upR = $dbc->exec_statement($upP, array($personNum, $orderID)); } } if ($memNum != 0) { $custdata = new CustdataModel($dbc); $custdata->CardNo($memNum); foreach ($custdata->find('personNum') as $c) { $names[$c->personNum()] = array($c->FirstName(), $c->LastName()); } // load member contact info into order // on first go so it can be edited separately $current_street = $orderModel->street(); $current_phone = $orderModel->phone(); if (empty($current_street) && empty($current_phone)) { $contactQ = $dbc->prepare_statement("SELECT street,city,state,zip,phone,email_1,email_2\n FROM meminfo WHERE card_no=?"); $contactR = $dbc->exec_statement($contactQ, array($memNum)); if ($dbc->num_rows($contactR) > 0) { $contact_row = $dbc->fetch_row($contactR); $dbc->selectDB($this->config->get('TRANS_DB')); $orderModel->street($contact_row['street']); $orderModel->city($contact_row['city']); $orderModel->state($contact_row['state']); $orderModel->zip($contact_row['zip']); $orderModel->phone($contact_row['phone']); $orderModel->altPhone($contact_row['email_2']); $orderModel->email($contact_row['email_1']); $orderModel->save(); $orderModel->specialOrderID($orderID); $orderModel->load(); $dbc->selectDB($this->config->get('OP_DB')); } } if ($custdata->load()) { $status_row['Type'] = $custdata->Type(); if ($status_row['Type'] == 'INACT') { $status_row['status'] = 'Inactive'; } elseif ($status_row['Type'] == 'INACT2') { $status_row['status'] = 'Inactive'; } elseif ($status_row['Type'] == 'TERM') { $status_row['status'] = 'Terminated'; } } } $prep = $dbc->prepare_statement("SELECT entry_date FROM {$TRANS}SpecialOrderHistory \n WHERE order_id=? AND entry_type='CONFIRMED'"); $confirm_date = $dbc->getValue($prep, array($orderID)); $callback = 2; $user = '******'; $orderDate = ""; $prep = $dbc->prepare_statement("SELECT datetime,numflag,mixMatch FROM \n {$TRANS}PendingSpecialOrder WHERE order_id=? AND trans_id=0"); $res = $dbc->exec_statement($prep, array($orderID)); if ($dbc->num_rows($res) > 0) { list($orderDate, $callback, $user) = $dbc->fetch_row($res); } $status = array(0 => "New, No Call", 3 => "New, Call", 1 => "Called/waiting", 2 => "Pending", 4 => "Placed", 5 => "Arrived"); $order_status = $orderModel->statusFlag(); $ret = ""; $ret .= sprintf('<input type="hidden" id="orderID" value="%d" />', $orderID); $ret .= '<div class="row form-inline"><div class="col-sm-4 text-left">'; $ret .= sprintf('<b>Owner Number</b>: <input type="text" size="6" id="memNum" value="%s" class="form-control price-field input-sm" />', $memNum == 0 ? '' : $memNum); $ret .= '<br />'; $ret .= '<b>Owner</b>: ' . ($status_row['Type'] == 'PC' ? 'Yes' : 'No'); $ret .= sprintf('<input type="hidden" id="isMember" value="%s" />', $status_row['Type']); $ret .= '<br />'; if (!empty($status_row['status'])) { $ret .= '<b>Account status</b>: ' . $status_row['status']; $ret .= '<br />'; } $ret .= '</div><div class="col-sm-4 text-center">'; if ($canEdit) { $ret .= '<b>Status</b>: '; $ret .= '<select id="orderStatus" class="form-control input-sm">'; foreach ($status as $k => $v) { $ret .= sprintf('<option %s value="%d">%s</option>', $k == $order_status ? 'selected' : '', $k, $v); } $ret .= '</select><p />'; } $ret .= '<b>Store</b>: '; $ret .= '<select id="orderStore" class="form-control input-sm">'; $ret .= '<option value="0">Choose...</option>'; $stores = new StoresModel($dbc); $ret .= $stores->toOptions($orderModel->storeID()); $ret .= '</select>'; $ret .= '</div><div class="col-sm-4 text-right">'; $ret .= "<a href=\"\" class=\"btn btn-default btn-sm done-btn\">Done</a>"; $username = FannieAuth::checkLogin(); $prints = array(); $cachepath = sys_get_temp_dir() . "/ordercache/"; if (file_exists("{$cachepath}{$username}.prints")) { $prints = unserialize(file_get_contents("{$cachepath}{$username}.prints")); } else { $fptr = fopen("{$cachepath}{$username}.prints", 'w'); fwrite($fptr, serialize($prints)); fclose($fptr); } $ret .= sprintf('<br />Queue tags <input type="checkbox" %s class="print-cb" />', isset($prints[$orderID]) ? 'checked' : '', $username, $orderID); $ret .= sprintf('<br /><a href="tagpdf.php?oids[]=%d" target="_tags%d">Print Now</a>', $orderID, $orderID); $ret .= '</div></div>'; $extra = ""; $extra .= '<div class="row"><div class="col-sm-6 text-left">'; $extra .= "<b>Taken by</b>: " . $user . "<br />"; $extra .= "<b>On</b>: " . date("M j, Y g:ia", strtotime($orderDate)) . "<br />"; $extra .= '</div><div class="col-sm-6 text-right form-inline">'; $extra .= '<b>Call to Confirm</b>: '; $extra .= '<select id="ctcselect" class="form-control input-sm">'; $extra .= '<option value="2"></option>'; if ($callback == 1) { $extra .= '<option value="1" selected>Yes</option>'; $extra .= '<option value="0">No</option>'; } else { if ($callback == 0) { $extra .= '<option value="1">Yes</option>'; $extra .= '<option value="0" selected>No</option>'; } else { $extra .= '<option value="1">Yes</option>'; $extra .= '<option value="0">No</option>'; } } $extra .= '</select><br />'; $extra .= '<span id="confDateSpan">' . (!empty($confirm_date) ? 'Confirmed ' . $confirm_date : 'Not confirmed') . "</span> "; $extra .= '<input type="checkbox" id="confirm-date" '; if (!empty($confirm_date)) { $extra .= "checked"; } $extra .= ' /><br />'; $extra .= "<a href=\"\" class=\"btn btn-default btn-sm done-btn\">Done</a>"; $extra .= '</div></div>'; $ret .= '<table class="table table-bordered">'; // names if (empty($names)) { $ret .= sprintf('<tr><th>First Name</th><td> <input type="text" id="t_firstName" name="fn" class="form-control input-sm conact-field" value="%s" /></td>', $orderModel->firstName()); $ret .= sprintf('<th>Last Name</th><td><input type="text" id="t_lastName" value="%s" name="ln" class="form-control input-sm contact-field" /></td>', $orderModel->lastName()); } else { $ret .= '<tr><th>Name</th><td colspan="2"><select id="s_personNum" class="form-control input-sm">'; foreach ($names as $p => $n) { $ret .= sprintf('<option value="%d" %s>%s %s</option>', $p, $p == $personNum ? 'selected' : '', $n[0], $n[1]); } $ret .= '</select></td>'; $ret .= '<td> </td>'; } $ret .= '<td colspan="4" class="form-inline">For Department: <select id="nDept" class="form-control input-sm contact-field" name="noteDept"> <option value="0">Choose...</option>'; $superQ = $dbc->prepare_statement("select superID,super_name from MasterSuperDepts\n where superID > 0\n group by superID,super_name\n order by super_name"); $superR = $dbc->exec_statement($superQ); while ($superW = $dbc->fetch_row($superR)) { $ret .= sprintf('<option value="%d" %s>%s</option>', $superW['superID'], $superW['superID'] == $orderModel->noteSuperID() ? 'selected' : '', $superW['super_name']); } $ret .= "</select></td></tr>"; // address $street = $orderModel->street(); $street2 = ''; if (strstr($street, "\n")) { list($street, $street2) = explode("\n", $street, 2); } $ret .= sprintf(' <tr> <th>Address</th> <td> <input type="text" id="t_addr1" value="%s" class="form-control input-sm contact-field" name="addr" /> </td> <th>E-mail</th> <td> <input type="text" id="t_email" value="%s" class="form-control input-sm contact-field" name="email" /> </td> <td rowspan="2" colspan="4"> <textarea id="nText" rows="5" cols="25" class="form-control input-sm contact-field" name="noteText" >%s</textarea> </td> </tr> <tr> <th>Addr (2)</th> <td> <input type="text" id="t_addr2" value="%s" class="form-control input-sm contact-field" name="addr2" /> </td> <th>City</th> <td> <input type="text" id="t_city" name="city" class="form-control input-sm contact-field" value="%s" size="10" /> </td> </tr> <tr> <th>Phone</th> <td> <input type="text" id="t_ph1" name="ph1" class="form-control input-sm contact-field" value="%s" /> </td> <th>Alt. Phone</th> <td> <input type="text" id="t_ph2" value="%s" name="ph2" class="form-control input-sm contact-field" /> </td> <th>State</th> <td> <input type="text" id="t_state" value="%s" size="2" class="form-control input-sm contact-field" name="state" /> </td> <th>Zip</th> <td> <input type="text" id="t_zip" value="%s" size="5" class="form-control input-sm contact-field" name="zip" /> </td> </tr>', $street, $orderModel->email(), $orderModel->notes(), $street2, $orderModel->city(), $orderModel->phone(), $orderModel->altPhone(), $orderModel->state(), $orderModel->zip()); $ret .= '</table>'; echo json_encode(array('customer' => $ret, 'footer' => $extra)); return false; }
public function run() { global $FANNIE_OP_DB, $FANNIE_PLUGIN_SETTINGS, $argv; $dbc = FannieDB::get($FANNIE_OP_DB); $custdata = new CustdataModel($dbc); $meminfo = new MeminfoModel($dbc); $APIKEY = 'a92f83d3e5f7fe52d4579e7902c6491d-us8'; $LISTID = '54100d18af'; $APIKEY = $FANNIE_PLUGIN_SETTINGS['MailChimpApiKey']; $LISTID = $FANNIE_PLUGIN_SETTINGS['MailChimpListID']; if (empty($APIKEY) || empty($LISTID)) { $this->cronMsg('Missing API key or List ID', FannieLogger::NOTICE); return false; } if (!class_exists('Mailchimp')) { $this->cronMsg('MailChimp library is not installed', FannieLogger::NOTICE); return false; } $mc = new MailChimpEx($APIKEY); if ($FANNIE_PLUGIN_SETTINGS['MailChimpMergeVarField'] != 1) { $vars = $mc->lists->mergeVars(array($LISTID)); $field_id = false; if ($vars['data']) { $current = array_pop($vars['data']); foreach ($current['merge_vars'] as $index => $info) { if ($info['tag'] == 'CARDNO') { $field_id = $info['id']; break; } } if ($field_id !== false) { echo 'Found member# field' . "\n"; } else { echo 'Adding member# field' . "\n"; $new = $mc->lists->mergeVarAdd($LISTID, 'CARDNO', 'Owner Number', array('field_type' => 'number', 'public' => false)); $field_id = $new['id']; } } if ($field_id === false) { $this->cronMsg('Error: could not locate / create owner number field!', FannieLogger::NOTICE); return false; } } // end create owner number field if needed $statuses = array('subscribed', 'unsubscribed', 'cleaned'); $cleans = array(); $memlist = ''; /** Examine all list members */ foreach ($statuses as $status) { $this->cronMsg('==== Checking ' . $status . ' emails ====', FannieLogger::INFO); $full_list = $mc->lists->export($LISTID, $status); $headers = array_shift($full_list); $columns = array(); foreach ($headers as $index => $name) { $columns[strtoupper($name)] = $index; } $line_count = 1; foreach ($full_list as $record) { /** Print progress meter in verbose mode */ if (isset($argv[2]) && ($argv[2] == '-v' || $argv[2] == '--verbose')) { printf("Processing %d/%d\r", $line_count, count($full_list)); } $line_count++; $card_no = $record[$columns['OWNER NUMBER']]; $email = $record[$columns['EMAIL ADDRESS']]; $fn = $record[$columns['FIRST NAME']]; $ln = $record[$columns['LAST NAME']]; $changed = isset($columns['LAST_CHANGED']) && isset($record[$columns['LAST_CHANGED']]) ? $record[$columns['LAST_CHANGED']] : 0; /** MailChimp has a POS member number tag **/ if (!empty($card_no)) { switch ($status) { /** If subscribed list member has been tagged with a POS member number, compare MailChimp fields to POS fields. If name disagrees, use POS value for both. If email disagrees, use MailChimp value for both. */ case 'subscribed': $memlist .= sprintf('%d,', $card_no); $custdata->reset(); $custdata->CardNo($card_no); $custdata->personNum(1); $custdata->load(); $update = array(); $meminfo->reset(); $meminfo->card_no($card_no); $meminfo->load(); if ($meminfo->email_1() != $email && strtotime($changed) > strtotime($meminfo->modified())) { $this->cronMsg(sprintf("MISMATCH: POS says %s, MailChimp says %s, Mailchimp is newer", $meminfo->email_1(), $email), FannieLogger::INFO); $meminfo->email_1($email); $meminfo->save(); } elseif ($meminfo->email_1() != $email) { $update['EMAIL'] = $meminfo->email_1(); $this->cronMsg(sprintf("MISMATCH: POS says %s, MailChimp says %s, POS is newer", $meminfo->email_1(), $email), FannieLogger::INFO); } if (strtoupper(trim($custdata->FirstName())) != strtoupper($fn)) { $this->cronMsg(sprintf("MISMATCH: POS says %s, MailChimp says %s", $custdata->FirstName(), $fn), FannieLogger::INFO); $update['FNAME'] = trim($custdata->FirstName()); } if (strtoupper(trim($custdata->LastName())) != strtoupper($ln)) { $this->cronMsg(sprintf("MISMATCH: POS says %s, MailChimp says %s", $custdata->LastName(), $ln), FannieLogger::INFO); $update['LNAME'] = trim($custdata->LastName()); } if (count($update) > 0) { $email_struct = array('euid' => $record[$columns['EUID']], 'leid' => $record[$columns['LEID']]); $this->cronMsg(sprintf("Updating name field(s) for member #%d", $card_no), FannieLogger::INFO); try { $mc->lists->updateMember($LISTID, $email_struct, $update, '', false); } catch (Exception $ex) { echo $ex; var_dump($update); } sleep(1); } break; /** Just track the number to avoid re-adding them to the list */ /** Just track the number to avoid re-adding them to the list */ case 'unsubscribed': $memlist .= sprintf('%d,', $card_no); break; /** Cleaned in MailChimp means the address isn't deliverable In this situation, remove the bad address from POS and delete the address from MailChimp. The member can be re-added when a correct email is entered into POS. */ /** Cleaned in MailChimp means the address isn't deliverable In this situation, remove the bad address from POS and delete the address from MailChimp. The member can be re-added when a correct email is entered into POS. */ case 'cleaned': $meminfo->reset(); $meminfo->card_no($card_no); $meminfo->email_1(''); $meminfo->save(); $this->cronMsg(sprintf('CLEANING Member %d, email %s', $card_no, $email), FannieLogger::INFO); $cleans[] = $record; break; } /** If list member is not tagged with a POS member number, try to locate them in POS by name and/or email address. If found, tag them in MailChimp with the POS member number. This whole situation only occurs if the initial list is imported without member numbers. */ } else { switch ($status) { // subscribed users can be updated easily case 'subscribed': $update = array(); $meminfo->reset(); $meminfo->email_1($email); $matches = $meminfo->find(); if (count($matches) == 1) { $update['CARDNO'] = $matches[0]->card_no(); } else { $custdata->reset(); $custdata->FirstName($fn); $custdata->LastName($ln); $custdata->personNum(1); $custdata->Type('PC'); $matches = $custdata->find(); if (count($matches) == 1) { $update['CARDNO'] = $matches[0]->CardNo(); } } if (isset($update['CARDNO'])) { $email_struct = array('email' => $email, 'euid' => $record[$columns['EUID']], 'leid' => $record[$columns['LEID']]); $this->cronMsg("Assigning member # to account " . $email, FannieLogger::INFO); $mc->lists->updateMember($LISTID, $email_struct, $update, '', false); sleep(1); $memlist .= sprintf('%d,', $update['CARDNO']); } break; /** Unsubscribed are currently ignored. The can't be updated as is. They could be deleted entirely via unsubscribe, resubscribed with an owner number, and then unsubscribed again. That's not currently implemented. It does check for the email address on the POS side to prevent re-adding it. */ /** Unsubscribed are currently ignored. The can't be updated as is. They could be deleted entirely via unsubscribe, resubscribed with an owner number, and then unsubscribed again. That's not currently implemented. It does check for the email address on the POS side to prevent re-adding it. */ case 'unsubscribed': $meminfo->reset(); $this->cronMsg('Checking unsubscribed ' . $email, FannieLogger::INFO); $meminfo->email_1($email); $matches = $meminfo->find(); foreach ($matches as $opted_out) { $memlist .= sprintf('%d,', $opted_out->card_no()); $this->cronMsg('Excluding member ' . $opted_out->card_no(), FannieLogger::INFO); } break; /** Cleaned are bad addresses. Delete them from POS database then from Mail Chimp. */ /** Cleaned are bad addresses. Delete them from POS database then from Mail Chimp. */ case 'cleaned': $meminfo->reset(); $meminfo->email_1($email); foreach ($meminfo->find() as $bad_address) { $bad_address->email_1(''); $bad_address->save(); $this->cronMsg(sprintf('CLEANING untagged member %d, email %s', $bad_address->card_no(), $email), FannieLogger::INFO); } $cleans[] = $record; break; } } } // foreach list member record } // foreach list status /** Removed bounced from the MailChimp list now that POS has been updated */ $removal_batch = array(); foreach ($cleans as $record) { if (empty($record[$columns['EMAIL ADDRESS']])) { continue; } $email_struct = array('email' => $record[$columns['EMAIL ADDRESS']], 'euid' => $record[$columns['EUID']], 'leid' => $record[$columns['LEID']]); $removal_batch[] = $email_struct; } if (count($removal_batch) > 0) { $this->cronMsg(sprintf('Removing %d addresses with status "cleaned"', count($removal_batch)), FannieLogger::INFO); $result = $mc->lists->batchUnsubscribe($LISTID, $removal_batch, true, false, false); } /** Finally, find new members and add them to MailChimp */ if ($memlist === '') { $memlist = '-1,'; } $memlist = substr($memlist, 0, strlen($memlist) - 1); $query = 'SELECT m.card_no, m.email_1, c.FirstName, c.LastName FROM meminfo AS m INNER JOIN custdata AS c ON c.CardNo=m.card_no AND c.personNum=1 WHERE c.Type = \'PC\' AND m.email_1 IS NOT NULL AND m.email_1 <> \'\' AND m.card_no NOT IN (' . $memlist . ')'; $result = $dbc->query($query); $add_batch = array(); while ($row = $dbc->fetch_row($result)) { if (!filter_var($row['email_1'], FILTER_VALIDATE_EMAIL)) { continue; } $new = array('email' => array('email' => $row['email_1']), 'email_type' => 'html', 'merge_vars' => array('FNAME' => $row['FirstName'], 'LNAME' => $row['LastName'], 'CARDNO' => $row['card_no'])); $add_batch[] = $new; } if (count($add_batch) > 0) { $this->cronMsg(sprintf('Adding %d new members', count($add_batch)), FannieLogger::INFO); $added = $mc->lists->batchSubscribe($LISTID, $add_batch, false, true); } return true; }