示例#1
0
 /**
  * @param array $result
  *
  * @return array of customer records
  */
 public function getCustomers($result)
 {
     $customersMdl = new CustomerModel();
     $customers = $customersMdl->get();
     $contacts = $customersMdl->getContacts();
     if (is_array($customers)) {
         $cdata = [];
         foreach ($customers as $customer) {
             $customer['contacts'] = [];
             $cdata[$customer['id']] = $customer;
         }
         // add custoner contacts
         foreach ($contacts as $contact) {
             if (isset($cdata[$contact['customerid']])) {
                 $cdata[$contact['customerid']]['contacts'][$contact['id']] = $contact;
             }
         }
         $result['data'] = $cdata;
     } else {
         $result['error'] = $customersMdl->errorInfo;
     }
     return $result;
 }
示例#2
0
 /**
  * Send password reset email to customer
  * @param $result
  * @return mixed
  */
 public function sendResetEmail($result)
 {
     // validate input
     if (!is_numeric($this->data->id)) {
         $result['error'] = "A valid id must be supplied";
         return $result;
     }
     // get customer details
     $custMdl = new CustomerModel();
     $customer = $custMdl->get($this->data->id)[0];
     if (strpos($customer['email'], '@') === -1) {
         $result['error'] = "The customer does not have a valid email";
         return $result;
     }
     // generate url
     $token = WposAdminUtilities::getToken();
     $link = "https://" . $_SERVER['SERVER_NAME'] . "/myaccount/resetpassword.php?token=" . $token;
     // set token
     if ($custMdl->setAuthToken($this->data->id, $token) === false) {
         $result['error'] = "Could not set auth token: " . $custMdl->errorInfo;
     }
     // send reset email
     $linkhtml = '<a href="' . $link . '">' . $link . '</a>';
     $mailer = new WposMail();
     if (($mres = $mailer->sendPredefinedMessage($customer['email'], 'reset_email', ['name' => $customer['name'], 'link' => $linkhtml])) !== true) {
         $result['error'] = $mres;
     }
     return $result;
 }
 /**
  * Generate invoice html
  * @return string
  */
 private function generateInvoiceHtml()
 {
     // copy invoice data, set tax values
     /** @noinspection PhpUnusedLocalVariableInspection */
     $invoice = $this->trans;
     $taxMdl = new TaxItemsModel();
     $taxdata = $taxMdl->get();
     $taxes = [];
     foreach ($taxdata as $value) {
         $taxes[$value['id']] = (object) $value;
     }
     // Get general settings
     $config = new WposAdminSettings();
     $settings = $config->getSettingsObject("general");
     $settings->payinst = $config->getSettingsObject("invoice")->payinst;
     // Get customer record
     $custMdl = new CustomerModel();
     /** @noinspection PhpUnusedLocalVariableInspection */
     $customer = (object) $custMdl->get($this->trans->custid)[0];
     $utils = new WposAdminUtilities();
     $utils->setCurrencyFormat($settings->currencyformat);
     // start output buffer and capture template output
     ob_start();
     include $_SERVER['DOCUMENT_ROOT'] . "/docs/templates/invoice.php";
     $html = ob_get_contents();
     ob_end_clean();
     return $html;
 }
 /**
  * Send password reset to the given user
  * @param $result
  * @return mixed
  */
 public function sendResetPasswordEmail($result)
 {
     // validate input + additional validation
     $jsonval = new JsonValidate($this->data, '{"email":"@","captcha":""}');
     if (($errors = $jsonval->validate()) !== true) {
         $result['error'] = $errors;
         return $result;
     }
     // validate captcha
     require $_SERVER['DOCUMENT_ROOT'] . $_SERVER['APP_ROOT'] . 'assets/secureimage/securimage.php';
     $img = new Securimage();
     // if the code checked is correct, it is destroyed to prevent re-use
     if ($img->check($this->data->captcha) == false) {
         $result['error'] = "Incorrect security code entered";
         return $result;
     }
     // check for account
     $custMdl = new CustomerModel();
     $customers = $custMdl->get(null, $this->data->email);
     if (empty($customers)) {
         $result['error'] = "There is no account with the specified email address.";
         return $result;
     }
     // run normal email password reset routine from admin functions
     $data = new stdClass();
     $data->id = $customers[0]['id'];
     $wAdminCust = new WposAdminCustomers($data);
     $result = $wAdminCust->sendResetEmail($result);
     return $result;
 }