/** * Shows the form for entering the e-mail address * * After a valid address has been posted back, creates a new password * and sends it to the Customer. * Fails if changing or sending the password fails, and when the * form isn't posted (i.e. on first loading the page). * Returns true only after the new password has been sent successfully. * @return boolean True on success, false otherwise */ static function view_sendpass() { global $_ARRAYLANG; while (isset($_POST['shopEmail'])) { $email = contrexx_input2raw($_POST['shopEmail']); $password = \User::make_password(); if (!Customer::updatePassword($email, $password)) { \Message::error($_ARRAYLANG['TXT_SHOP_UNABLE_SET_NEW_PASSWORD']); break; } if (!self::sendLogin($email, $password)) { \Message::error($_ARRAYLANG['TXT_SHOP_UNABLE_TO_SEND_EMAIL']); break; } return \Message::ok($_ARRAYLANG['TXT_SHOP_ACCOUNT_DETAILS_SENT_SUCCESSFULLY']); } self::$objTemplate->setGlobalVariable($_ARRAYLANG); self::$objTemplate->touchBlock('shop_sendpass'); return false; }
/** * Returns a unique Coupon code with eight characters * @return string The Coupon code * @see User::make_password() */ static function getNewCode() { $code = null; while (true) { $code = \User::make_password(8, false); if (!self::codeExists($code)) { break; } } return $code; }
/** * add or edit contact * * @global array $_ARRAYLANG * @global object $objDatabase * @return true */ function _modifyContact() { global $_ARRAYLANG, $objDatabase, $objJs, $objResult, $_LANGID, $_CORELANG; \JS::activate('cx'); \JS::activate("jquery"); \JS::activate("jqueryui"); $objFWUser = \FWUser::getFWUserObject(); \FWUser::getUserLiveSearch(array('minLength' => 3, 'canCancel' => true, 'canClear' => true)); \JS::registerJS("modules/Crm/View/Script/main.js"); \JS::registerJS("modules/Crm/View/Script/contact.js"); \JS::registerCSS("modules/Crm/View/Style/main.css"); \JS::registerCSS("modules/Crm/View/Style/contact.css"); \JS::registerCSS("lib/javascript/chosen/chosen.css"); \JS::registerJS("lib/javascript/chosen/chosen.jquery.js"); $cxjs = \ContrexxJavascript::getInstance(); $cxjs->setVariable('TXT_CRM_MANDATORY_FIELDS_NOT_FILLED_OUT', $_ARRAYLANG['TXT_CRM_MANDATORY_FIELDS_NOT_FILLED_OUT'], 'modifyContact'); $mes = isset($_REQUEST['mes']) ? base64_decode($_REQUEST['mes']) : ''; if (!empty($mes)) { switch ($mes) { case "customerupdated": $this->_strOkMessage = $_ARRAYLANG['TXT_CRM_CUSTOMER_DETAILS_UPDATED_SUCCESSFULLY']; break; case "customeradded": $this->_strOkMessage = $_ARRAYLANG['TXT_CRM_CUSTOMER_ADDED_SUCCESSFULLY']; break; case "contactupdated": $this->_strOkMessage = $_ARRAYLANG['TXT_CRM_CUSTOMER_CONTACT_UPDATED_SUCCESSFULLY']; break; case "contactadded": $this->_strOkMessage = $_ARRAYLANG['TXT_CRM_CUSTOMER_CONTACT_ADDED_SUCCESSFULLY']; break; } } $settings = $this->getSettings(); $_GET['type'] = isset($_GET['type']) ? $_GET['type'] : 'customer'; $redirect = isset($_REQUEST['redirect']) ? $_REQUEST['redirect'] : base64_decode('&act=customers'); $this->_pageTitle = isset($_REQUEST['id']) ? $_ARRAYLANG["TXT_CRM_EDIT_" . strtoupper($_GET['type'])] : $_ARRAYLANG["TXT_CRM_ADD_" . strtoupper($_GET['type'])]; $this->_objTpl->loadTemplateFile('module_' . $this->moduleNameLC . '_customer_modify.html'); $this->_objTpl->setGlobalVariable("MODULE_NAME", $this->moduleName); $id = isset($_REQUEST['id']) ? intval($_REQUEST['id']) : 0; $this->contact = new \Cx\Modules\Crm\Model\Entity\CrmContact(); !empty($id) ? $this->contact->id = $id : ''; $contactType = isset($_GET['type']) && $_GET['type'] == 'contact' ? 2 : 1; //person $this->contact->family_name = isset($_POST['family_name']) ? contrexx_input2raw($_POST['family_name']) : ''; $this->contact->contact_role = isset($_POST['contact_role']) ? contrexx_input2raw($_POST['contact_role']) : ''; $this->contact->contact_language = isset($_POST['contact_language']) ? (int) $_POST['contact_language'] : (empty($id) ? $_LANGID : 0); $this->contact->contact_customer = isset($_POST['company']) ? (int) $_POST['company'] : (isset($_GET['custId']) ? (int) $_GET['custId'] : 0); $this->contact->contactType = $contactType; $this->contact->companySize = isset($_POST['companySize']) ? contrexx_input2raw($_POST['companySize']) : 0; $this->contact->contact_gender = isset($_POST['contact_gender']) ? (int) $_POST['contact_gender'] : 0; $this->contact->emailDelivery = empty($_POST) || isset($_POST['emailDelivery']) ? 1 : 0; $accountUserID = isset($_POST['contactId']) ? intVal($_POST['contactId']) : 0; $accountUserEmail = isset($_POST['contact_email']) ? contrexx_input2raw($_POST['contact_email']) : ''; $accountUserPassword = isset($_POST['contact_password']) ? contrexx_input2raw($_POST['contact_password']) : ''; $sendLoginDetails = isset($_POST['send_account_notification']); $this->contact->account_id = 0; // customer $tpl = isset($_REQUEST['tpl']) ? contrexx_input2db($_REQUEST['tpl']) : ''; if (isset($_GET['design']) && $_GET['design'] == 'custom') { $this->_objTpl->setVariable(array('PM_REMOVE_BACKGROUND_STYLE' => $this->pmRemoveStylesAddcustomer(), 'PM_AJAX_SAVE_FROM_SHADOWBOX_JAVASCRIPT' => $objJs->pmAjaxformSubmitForShadowbox($tpl))); } $defaultTypeId = $objDatabase->getOne('SELECT `id` FROM ' . DBPREFIX . 'module_' . $this->moduleNameLC . '_customer_types WHERE `default` = 1'); $this->contact->customerId = isset($_POST['customerId']) ? contrexx_input2raw($_POST['customerId']) : ''; $this->contact->customerType = isset($_POST['customer_type']) ? (int) $_POST['customer_type'] : (empty($id) ? $defaultTypeId : ''); $this->contact->customerName = isset($_POST['companyName']) ? contrexx_input2raw($_POST['companyName']) : ''; $this->contact->addedUser = $objFWUser->objUser->getId(); $this->contact->currency = isset($_POST['currency']) ? (int) $_POST['currency'] : ''; $this->contact->datasource = 1; $customerContacts = isset($_POST['companyContacts']) ? array_map('intval', (array) $_POST['companyContacts']) : array(); $assignedMembersShip = isset($_POST['assigned_memberships']) ? array_map('intval', (array) $_POST['assigned_memberships']) : array(); $this->contact->notes = isset($_POST['notes']) ? contrexx_input2raw($_POST['notes']) : ''; $this->contact->industryType = isset($_POST['industryType']) ? (int) $_POST['industryType'] : 0; $this->contact->user_name = isset($_POST['contact_username']) ? contrexx_input2raw($_POST['contact_username']) : ''; if (isset($_POST['save_contact']) || isset($_POST['save_add_new_contact'])) { $msg = ''; switch (true) { case $contactType == 1 && !empty($id): $msg = "customerupdated"; break; case $contactType == 2 && !empty($id): $msg = "contactupdated"; break; case $contactType == 1: $msg = "customeradded"; break; case $contactType == 2: $msg = "contactadded"; break; default: break; } $result = $this->parseContacts($_POST); // unset customer type, customerId the contact have customer if ($this->contact->contactType == 2 && $this->contact->contact_customer != 0) { $this->contact->customerType = 0; $this->contact->currency = 0; $this->contact->customerId = ''; } $accountMandatory = !empty($accountUserEmail) ? false : !$settings['user_account_mantatory']; if (!$settings['create_user_account'] || $contactType == 1 || !empty($accountUserEmail) && $this->addUser($accountUserEmail, $accountUserPassword, $sendLoginDetails, $result, $accountUserID) || $accountMandatory) { $this->contact->save(); $this->updateCustomerMemberships((array) $assignedMembersShip, $this->contact->id); if ($contactType == 2) { // For contact //$this->save } else { $this->updateCustomerContacts((array) $customerContacts, $this->contact->id); } // insert Emails $objDatabase->Execute("DELETE FROM `" . DBPREFIX . "module_{$this->moduleNameLC}_customer_contact_emails` WHERE `contact_id` = {$this->contact->id}"); $query = "INSERT INTO `" . DBPREFIX . "module_{$this->moduleNameLC}_customer_contact_emails` (email, email_type, is_primary, contact_id) VALUES "; $values = array(); foreach ($result['contactemail'] as $value) { if (!empty($value['value'])) { $values[] = "('" . contrexx_input2db($value['value']) . "', '" . (int) $value['type'] . "', '" . (int) $value['primary'] . "', '" . $this->contact->id . "')"; } } if (is_array($values) && !empty($values)) { $query .= implode(",", $values); $objDatabase->Execute($query); } // insert Phone $objDatabase->Execute("DELETE FROM `" . DBPREFIX . "module_{$this->moduleNameLC}_customer_contact_phone` WHERE `contact_id` = {$this->contact->id}"); $query = "INSERT INTO `" . DBPREFIX . "module_{$this->moduleNameLC}_customer_contact_phone` (phone, phone_type, is_primary, contact_id) VALUES "; $values = array(); foreach ($result['contactphone'] as $value) { if (!empty($value['value'])) { $values[] = "('" . contrexx_input2db($value['value']) . "', '" . (int) $value['type'] . "', '" . (int) $value['primary'] . "', '" . $this->contact->id . "')"; } } if (is_array($values) && !empty($values)) { $query .= implode(",", $values); $objDatabase->Execute($query); } // insert Website $assignedWebsites = array(); foreach ($result['contactwebsite'] as $value) { if (!empty($value['value'])) { $fields = array('url' => contrexx_input2raw($value['value']), 'url_profile' => (int) $value['profile'], 'is_primary' => $value['primary'], 'contact_id' => $this->contact->id); if (!empty($value['id'])) { array_push($assignedWebsites, $value['id']); $query = \SQL::update("module_{$this->moduleNameLC}_customer_contact_websites", $fields, array('escape' => true)) . " WHERE `id` = {$value['id']} AND `contact_id` = {$this->contact->id}"; $objDatabase->Execute($query); } else { $query = \SQL::insert("module_{$this->moduleNameLC}_customer_contact_websites", $fields, array('escape' => true)); $db = $objDatabase->Execute($query); if ($db) { array_push($assignedWebsites, $objDatabase->INSERT_ID()); } } } } $whereWebId = !empty($assignedWebsites) ? " AND `id` NOT IN (" . implode(',', $assignedWebsites) . ")" : ""; $objDatabase->Execute("DELETE FROM `" . DBPREFIX . "module_{$this->moduleNameLC}_customer_contact_websites` WHERE `contact_id` = {$this->contact->id} {$whereWebId}"); // insert social networks $assignedSocialNetwork = array(); foreach ($result['contactsocial'] as $value) { if (!empty($value['value'])) { $fields = array('id' => array('val' => !empty($value['id']) ? (int) $value['id'] : null, 'omitEmpty' => true), 'url' => contrexx_input2raw($value['value']), 'url_profile' => (int) $value['profile'], 'is_primary' => $value['primary'], 'contact_id' => $this->contact->id); if (!empty($value['id'])) { array_push($assignedSocialNetwork, $value['id']); $query = \SQL::update("module_{$this->moduleNameLC}_customer_contact_social_network", $fields, array('escape' => true)) . " WHERE `id` = {$value['id']} AND `contact_id` = {$this->contact->id}"; $objDatabase->Execute($query); } else { $query = \SQL::insert("module_{$this->moduleNameLC}_customer_contact_social_network", $fields, array('escape' => true)); $db = $objDatabase->Execute($query); if ($db) { array_push($assignedSocialNetwork, $objDatabase->INSERT_ID()); } } } } $whereWebId = !empty($assignedSocialNetwork) ? " AND `id` NOT IN (" . implode(',', $assignedSocialNetwork) . ")" : ""; $objDatabase->Execute("DELETE FROM `" . DBPREFIX . "module_{$this->moduleNameLC}_customer_contact_social_network` WHERE `contact_id` = {$this->contact->id} {$whereWebId}"); // insert address $objDatabase->Execute("DELETE FROM `" . DBPREFIX . "module_{$this->moduleNameLC}_customer_contact_address` WHERE `contact_id` = {$this->contact->id}"); $query = "INSERT INTO `" . DBPREFIX . "module_{$this->moduleNameLC}_customer_contact_address` (address, city, state, zip, country, Address_Type, is_primary, contact_id) VALUES "; $values = array(); foreach ($result['contactAddress'] as $value) { if (!empty($value['address']) || !empty($value['city']) || !empty($value['state']) || !empty($value['zip']) || !empty($value['country'])) { $values[] = "('" . contrexx_input2db($value['address']) . "', '" . contrexx_input2db($value['city']) . "', '" . contrexx_input2db($value['state']) . "', '" . contrexx_input2db($value['zip']) . "', '" . contrexx_input2db($value['country']) . "', '" . intval($value['type']) . "', '" . intval($value['primary']) . "', '" . $this->contact->id . "')"; } } if (is_array($values) && !empty($values)) { $query .= implode(",", $values); $objDatabase->Execute($query); } $ChckCount = 0; if (!empty($id)) { $contactId = $this->contact->contact_customer; } if ($this->contact->contactType == 2) { $contactId = $this->contact->contact_customer; } $customerId = $this->contact->id; $customerName = $this->contact->customerName; // notify the staff's $this->notifyStaffOnContactAccModification($this->contact->id, $this->contact->customerName, $this->contact->family_name, $this->contact->contact_gender); // ajax request if (isset($_GET['design']) && $_GET['design'] == 'custom') { $returnString = array('errChk' => $ChckCount, 'customerId' => $customerId, 'customerName' => $customerName, 'contactId' => $contactId, 'msg' => $msg); echo json_encode($returnString); exit; } if (isset($_POST['save_add_new_contact'])) { $contactTypeUrl = $contactType == 2 ? '&type=contact' : ''; \Cx\Core\Csrf\Controller\Csrf::header("Location:./index.php?cmd=" . $this->moduleName . "&act=customers&tpl=managecontact&mes=" . base64_encode($msg) . $contactTypeUrl); exit; } \Cx\Core\Csrf\Controller\Csrf::header("Location:./index.php?cmd=" . $this->moduleName . "&act=customers&mes=" . base64_encode($msg) . base64_decode($redirect)); exit; } elseif (empty($accountUserEmail)) { $this->_strErrMessage = $_ARRAYLANG['TXT_CRM_EMAIL_EMPTY']; } } elseif ($this->contact->load($id)) { if ($contactType == 1) { $objContact = $objDatabase->Execute("SELECT `id` FROM `" . DBPREFIX . "module_{$this->moduleNameLC}_contacts` WHERE `contact_customer` = {$this->contact->id}"); if ($objContact) { while (!$objContact->EOF) { $customerContacts[] = (int) $objContact->fields['id']; $objContact->MoveNext(); } } } $objMemberShips = $objDatabase->Execute("SELECT `membership_id` FROM `" . DBPREFIX . "module_{$this->moduleNameLC}_customer_membership` WHERE `contact_id` = {$this->contact->id}"); if ($objMemberShips) { while (!$objMemberShips->EOF) { $assignedMembersShip[] = (int) $objMemberShips->fields['membership_id']; $objMemberShips->Movenext(); } } // Get emails and phones $objEmails = $objDatabase->Execute("SELECT * FROM `" . DBPREFIX . "module_{$this->moduleNameLC}_customer_contact_emails` WHERE contact_id = {$this->contact->id} ORDER BY id ASC"); if ($objEmails) { while (!$objEmails->EOF) { $result['contactemail'][] = array("type" => $objEmails->fields['email_type'], "primary" => $objEmails->fields['is_primary'], "value" => $objEmails->fields['email']); $objEmails->MoveNext(); } } $objPhone = $objDatabase->Execute("SELECT * FROM `" . DBPREFIX . "module_{$this->moduleNameLC}_customer_contact_phone` WHERE contact_id = {$this->contact->id} ORDER BY id ASC"); if ($objPhone) { while (!$objPhone->EOF) { $result['contactphone'][] = array("type" => $objPhone->fields['phone_type'], "primary" => $objPhone->fields['is_primary'], "value" => $objPhone->fields['phone']); $objPhone->MoveNext(); } } $objWebsite = $objDatabase->Execute("SELECT * FROM `" . DBPREFIX . "module_{$this->moduleNameLC}_customer_contact_websites` WHERE contact_id = {$this->contact->id} ORDER BY id ASC"); if ($objWebsite) { while (!$objWebsite->EOF) { $result['contactwebsite'][] = array("id" => $objWebsite->fields['id'], "profile" => $objWebsite->fields['url_profile'], "primary" => $objWebsite->fields['is_primary'], "value" => $objWebsite->fields['url']); $objWebsite->MoveNext(); } } $objSocial = $objDatabase->Execute("SELECT * FROM `" . DBPREFIX . "module_{$this->moduleNameLC}_customer_contact_social_network` WHERE contact_id = {$this->contact->id} ORDER BY id ASC"); if ($objSocial) { while (!$objSocial->EOF) { $result['contactsocial'][] = array("id" => $objSocial->fields['id'], "profile" => $objSocial->fields['url_profile'], "primary" => $objSocial->fields['is_primary'], "value" => $objSocial->fields['url']); $objSocial->MoveNext(); } } $objAddress = $objDatabase->Execute("SELECT * FROM `" . DBPREFIX . "module_{$this->moduleNameLC}_customer_contact_address` WHERE contact_id = {$this->contact->id} ORDER BY id ASC"); if ($objAddress) { while (!$objAddress->EOF) { $result['contactAddress'][] = array("address" => $objAddress->fields['address'], "city" => $objAddress->fields['city'], "state" => $objAddress->fields['state'], "zip" => $objAddress->fields['zip'], "country" => $objAddress->fields['country'], "type" => $objAddress->fields['Address_Type'], "primary" => $objAddress->fields['is_primary']); $objAddress->MoveNext(); } } } // reset the email and phone fields if (empty($result['contactemail'])) { $result['contactemail'][] = array("type" => $contactType == 1 ? 1 : 0, "primary" => 1, "value" => ""); } if (empty($result['contactphone'])) { $result['contactphone'][] = array("type" => 1, "primary" => 1, "value" => ""); } if (empty($result['contactwebsite'])) { $result['contactwebsite'][] = array("id" => 0, "profile" => $contactType == 1 ? 3 : 1, "primary" => 1, "value" => ""); } if (empty($result['contactsocial'])) { $result['contactsocial'][] = array("id" => 0, "profile" => 4, "primary" => 1, "value" => ""); } if (empty($result['contactAddress'])) { $result['contactAddress'][] = array("address" => '', "city" => '', "state" => '', "zip" => "", "country" => "", "type" => 2, "primary" => 1); } if (!empty($result['contactemail'])) { $Count = 1; //$showEmail = false; $showEmail = true; foreach ($result['contactemail'] as $email) { if (!empty($email['value']) && !$showEmail) { $showEmail = true; } $this->_objTpl->setVariable(array('CRM_CONTACT_EMAIL_NAME' => "contactemail_{$Count}_{$email['type']}_{$email['primary']}", 'CRM_CONTACT_EMAIL' => contrexx_raw2xhtml($email['value']), 'CRM_EMAIL_OPTION' => $_ARRAYLANG[$this->emailOptions[$email['type']]], 'CRM_CONTACT_EMAIL_PRIMARY' => $email['primary'] ? "primary_field" : "not_primary_field")); $block = $contactType == 1 ? "customerEmailContainer" : "contactEmailContainer"; $this->_objTpl->parse($block); $Count++; } } if (!empty($result['contactphone'])) { foreach ($result['contactphone'] as $phone) { $this->_objTpl->setVariable(array('CRM_CONTACT_PHONE_NAME' => "contactphone_{$Count}_{$phone['type']}_{$phone['primary']}", 'CRM_CONTACT_PHONE' => contrexx_raw2xhtml($phone['value']), 'CRM_PHONE_OPTION' => $_ARRAYLANG[$this->phoneOptions[$phone['type']]], 'CRM_CONTACT_PHONE_PRIMARY' => $phone['primary'] ? "primary_field" : "not_primary_field")); $block = $contactType == 1 ? "customerPhoneContainer" : "contactPhoneContainer"; $this->_objTpl->parse($block); $Count++; } } if (!empty($result['contactwebsite'])) { foreach ($result['contactwebsite'] as $website) { $this->_objTpl->setVariable(array('CRM_CONTACT_WEBSITE_NAME' => "contactwebsite_{$Count}_{$website['profile']}_{$website['primary']}", 'CRM_CONTACT_WEBSITE' => contrexx_raw2xhtml(html_entity_decode($website['value'], ENT_QUOTES, CONTREXX_CHARSET)), 'CRM_WEBSITE_PROFILE' => !empty($this->websiteProfileOptions[$website['profile']]) ? $_ARRAYLANG[$this->websiteProfileOptions[$website['profile']]] : '', 'CRM_WEBSITE_OPTION' => $website['type'] != '' && !empty($this->websiteOptions[$website['type']]) ? $_ARRAYLANG[$this->websiteOptions[$website['type']]] : '', 'CRM_CONTACT_WEB_ID_NAME' => "website_{$Count}", 'CRM_CONTACT_WEB_ID' => (int) $website['id'], 'CRM_CONTACT_WEBSITE_PRIMARY' => $website['primary'] ? "primary_field" : "not_primary_field")); $block = $contactType == 1 ? "customerwebsiteContainer" : "contactwebsiteContainer"; $this->_objTpl->parse($block); $Count++; } } if (!empty($result['contactsocial'])) { foreach ($result['contactsocial'] as $social) { $this->_objTpl->setVariable(array('CRM_CONTACT_SOCIAL_NAME' => "contactsocial_{$Count}_{$social['profile']}_{$social['primary']}", 'CRM_CONTACT_SOCIAL' => contrexx_raw2xhtml(html_entity_decode($social['value'], ENT_QUOTES, CONTREXX_CHARSET)), 'CRM_SOCIAL_PROFILE' => $_ARRAYLANG[$this->socialProfileOptions[$social['profile']]], 'CRM_CONTACT_SOCIAL_ID_NAME' => "social_{$Count}", 'CRM_CONTACT_SOCIAL_ID' => (int) $social['id'], 'CRM_CONTACT_SOCIAL_PRIMARY' => $social['primary'] ? "primary_field" : "not_primary_field")); $block = $contactType == 1 ? "customerSocialLinkContainer" : "contactSocialLinkContainer"; $this->_objTpl->parse($block); $Count++; } } if (!empty($result['contactAddress'])) { $showAddress = false; foreach ($result['contactAddress'] as $address) { if (!empty($address['address']) && !$showAddress) { $showAddress = true; } $primary = $address['primary'] ? 1 : 0; $this->_objTpl->setVariable(array('CRM_CONTACT_ADDRESS_NAME' => "contactAddress_{$Count}_1_{$primary}", 'CRM_CONTACT_ADDRESS_VALUE' => contrexx_raw2xhtml($address['address']), 'CRM_CONTACT_CITY_NAME' => "contactAddress_{$Count}_2_{$primary}", 'CRM_CONTACT_CITY_VALUE' => contrexx_raw2xhtml($address['city']), 'CRM_CONTACT_STATE_NAME' => "contactAddress_{$Count}_3_{$primary}", 'CRM_CONTACT_STATE_VALUE' => contrexx_raw2xhtml($address['state']), 'CRM_CONTACT_ZIP_NAME' => "contactAddress_{$Count}_4_{$primary}", 'CRM_CONTACT_ZIP_VALUE' => contrexx_raw2xhtml($address['zip']), 'CRM_CONTACT_COUNTRY_NAME' => "contactAddress_{$Count}_5_{$primary}", 'CRM_CONTACT_COUNTRY_VALUE' => $this->getContactAddressCountry($this->_objTpl, $address['country'], $contactType == 1 ? "customerCrmCountry" : 'crmCountry'), 'CRM_CONTACT_ADDR_TYPE_NAME' => "contactAddress_{$Count}_6_{$primary}", 'CRM_CONTACT_ADDR_TYPE_VALUE' => $this->getContactAddrTypeCountry($this->_objTpl, $address['type'], $contactType == 1 ? "customerAddressType" : 'addressType'), 'CRM_CONTACT_ADDRESS_PRIMARY' => $primary ? "primary_field_address" : "not_primary_field_address")); $block = $contactType == 1 ? "customerAddressContainer" : "contactAddressContainer"; $this->_objTpl->parse($block); $Count++; } } $this->getContactAddressCountry($this->_objTpl, '', $contactType == 1 ? "customerAdditionalcrmCountry" : 'additionalcrmCountry'); $this->getContactAddrTypeCountry($this->_objTpl, 2, $contactType == 1 ? "customerAdditionaladdressType" : 'additionaladdressType'); // special fields for contacts $objResult = $objDatabase->Execute('SELECT id,name,lang FROM ' . DBPREFIX . 'languages'); while (!$objResult->EOF) { $this->_objTpl->setVariable(array('TXT_LANG_ID' => (int) $objResult->fields['id'], 'TXT_LANG_NAME' => contrexx_raw2xhtml($objResult->fields['name']), 'TXT_LANG_SELECT' => $objResult->fields['id'] == $this->contact->contact_language ? "selected=selected" : "")); $langBlock = $contactType == 2 ? "showAddtionalContactLanguages" : "ContactLanguages"; $this->_objTpl->parse($langBlock); $objResult->MoveNext(); } // special fields for customer if ($contactType == 1) { $this->getCustomerTypeDropDown($this->_objTpl, $this->contact->customerType, 'customerTypes', array('is_hide' => false)); // Customer Types // Parse the contacts if (!empty($customerContacts)) { $objContacts = $objDatabase->Execute("SELECT `id`, `customer_name`, `contact_familyname` FROM `" . DBPREFIX . "module_{$this->moduleNameLC}_contacts` WHERE `id` IN (" . implode(',', $customerContacts) . ")"); if ($objContacts) { $row = "row2"; while (!$objContacts->EOF) { $this->_objTpl->setVariable(array('CRM_CONTACT_ID' => $objContacts->fields['id'], 'CRM_CONTACT_NAME' => contrexx_raw2xhtml($objContacts->fields['contact_familyname'] . " " . $objContacts->fields['customer_name']), 'ROW_CLASS' => $row = $row == 'row2' ? "row1" : "row2")); $this->_objTpl->parse("customerContacts"); $objContacts->MoveNext(); } } } $this->_objTpl->setVariable('CRM_CONTACTS_HEADER_CLASS', !empty($customerContacts) ? 'header-collapse' : 'header-expand'); // parse currency $this->getCustomerCurrencyDropDown($this->_objTpl, $this->contact->currency, "currency"); // parse companysize $this->getCompanySizeDropDown($this->_objTpl, $this->contact->companySize, "companySize"); } else { $this->getCustomerTypeDropDown($this->_objTpl, $this->contact->customerType, "contactCustomerTypes", array('is_hide' => false)); // Customer Types $this->getCustomerCurrencyDropDown($this->_objTpl, $this->contact->currency, "contactCurrency"); // currency } $memberships = array_keys($this->getMemberships()); $membershipBlock = $contactType == 1 ? "assignedGroup" : "contactMembership"; $this->getMembershipDropdown($this->_objTpl, $memberships, $membershipBlock, $assignedMembersShip); if (!empty($this->contact->account_id)) { $objUser = $objFWUser->objUser->getUser($this->contact->account_id); if ($objUser) { $accountName = contrexx_raw2xhtml(\FWUser::getParsedUserTitle($objUser)); } } else { $objUser = false; } $this->_objTpl->setVariable(array('CRM_ADDRESS_HEADER_CLASS' => $showAddress ? 'header-collapse' : 'header-expand', 'CRM_ADDRESS_BLOCK_DISPLAY' => $showAddress ? 'table-row-group' : 'none', 'CRM_DESCRIPTION_HEADER_CLASS' => !empty($this->contact->notes) ? 'header-collapse' : 'header-expand', 'CRM_DESCRIPTION_BLOCK_DISPLAY' => !empty($this->contact->notes) ? 'table-row-group' : 'none', 'CRM_MEMBERSHIP_HEADER_CLASS' => !empty($assignedMembersShip) ? 'header-collapse' : 'header-expand', 'CRM_MEMBERSHIP_BLOCK_DISPLAY' => !empty($assignedMembersShip) ? 'table-row-group' : 'none')); $this->_objTpl->setGlobalVariable(array('TXT_CON_FAMILY' => contrexx_raw2xhtml($this->contact->family_name), 'TXT_CON_ROLE' => contrexx_raw2xhtml($this->contact->contact_role), 'CRM_INPUT_COUNT' => $Count, 'CRM_CONTACT_COMPANY_ID' => (int) $this->contact->contact_customer, 'CRM_CONTACT_COMPANY' => $this->contact->contact_customer != null ? contrexx_raw2xhtml($objDatabase->getOne("SELECT `customer_name` FROM `" . DBPREFIX . "module_{$this->moduleNameLC}_contacts` WHERE id = {$this->contact->contact_customer} ")) : '', 'CRM_CONTACT_NOTES' => contrexx_raw2xhtml($this->contact->notes), 'CRM_INDUSTRY_DROPDOWN' => $this->listIndustryTypes($this->_objTpl, 2, $this->contact->industryType), 'CRM_CUSTOMERID' => contrexx_input2xhtml($this->contact->customerId), 'CRM_COMPANY_NAME' => contrexx_input2xhtml($this->contact->customerName), 'CRM_CONTACT_ID' => $this->contact->id != null ? $this->contact->id : 0, 'CRM_CONTACT_USER_ID' => $this->contact->account_id != null ? $this->contact->account_id : 0, 'CRM_CONTACT_USERNAME' => $objUser ? contrexx_raw2xhtml($objUser->getEmail()) : '', 'CRM_CONTACT_ACCOUNT_USERNAME' => $objUser ? $accountName : ' ', 'CRM_CONTACT_SHOW_PASSWORD' => "style='display: none;'", 'CRM_CONTACT_RANDOM_PASSWORD' => \User::make_password(), 'CRM_GENDER_FEMALE_SELECTED' => $this->contact->contact_gender == 1 ? 'selected' : '', 'CRM_GENDER_MALE_SELECTED' => $this->contact->contact_gender == 2 ? 'selected' : '', 'CRM_CONTACT_TYPE' => $contactType == 1 ? 'company' : 'contact', 'CRM_ACCOUNT_MANTORY' => $settings['create_user_account'] && $settings['user_account_mantatory'] ? '<font color="red">*</font>' : '', 'CRM_ACCOUNT_MANTORY_CLASS' => $settings['create_user_account'] && $settings['user_account_mantatory'] ? 'mantatory' : '', 'CRM_EMAIL_DELIVERY' => $this->contact->emailDelivery ? 'checked="checked"' : '', 'TXT_CRM_EMPLOYEE' => $_ARRAYLANG['TXT_CRM_EMPLOYEE'], 'TXT_CRM_CITY' => $_ARRAYLANG['TXT_CRM_TITLE_CITY'], 'TXT_CRM_STATE' => $_ARRAYLANG['TXT_CRM_STATE'], 'TXT_CRM_ZIP_CODE' => $_ARRAYLANG['TXT_CRM_ZIP_CODE'], 'TXT_CRM_EDITCUSTOMERCONTACT_TITLE' => isset($_REQUEST['id']) ? $_ARRAYLANG["TXT_CRM_EDIT_" . strtoupper($_GET['type'])] : $_ARRAYLANG["TXT_CRM_ADD_" . strtoupper($_GET['type'])], 'TXT_CRM_INDUSTRY_TYPE' => $_ARRAYLANG['TXT_CRM_INDUSTRY_TYPE'], 'TXT_CRM_DATASOURCE' => $_ARRAYLANG['TXT_CRM_DATASOURCE'], 'TXT_CRM_OPTION' => $_ARRAYLANG['TXT_CRM_WORK'], 'TXT_CRM_EMAIL_DEFAULT_OPTION' => $contactType == 1 ? $_ARRAYLANG['TXT_CRM_HOME'] : $_ARRAYLANG['TXT_CRM_WORK'], 'TXT_CRM_PROFILE_OPTION' => $contactType == 1 ? $_ARRAYLANG['TXT_CRM_BUSINESS1'] : $_ARRAYLANG['TXT_CRM_WORK'], 'TXT_CRM_SOCIAL_PROFILE_OPTION' => $_ARRAYLANG['TXT_CRM_FACEBOOK'], 'TXT_CRM_NAME' => $_ARRAYLANG['TXT_CRM_NAME'], 'TXT_CRM_EMAIL' => $_ARRAYLANG['TXT_CRM_EMAIL'], 'TXT_CRM_PHONE' => $_ARRAYLANG['TXT_CRM_PHONE'], 'TXT_CRM_TITLE_LANGUAGE' => $_ARRAYLANG['TXT_CRM_TITLE_LANGUAGE'], 'TXT_CRM_ROLE' => $_ARRAYLANG['TXT_CRM_ROLE'], 'TXT_CRM_FAMILY_NAME' => $_ARRAYLANG['TXT_CRM_FAMILY_NAME'], 'TXT_CRM_TITLE_SELECT_LANGUAGE' => $_ARRAYLANG['TXT_CRM_TITLE_SELECT_LANGUAGE'], 'TXT_CRM_HOME' => $_ARRAYLANG['TXT_CRM_HOME'], 'TXT_CRM_WORK' => $_ARRAYLANG['TXT_CRM_WORK'], 'TXT_CRM_BUSINESS1' => $_ARRAYLANG['TXT_CRM_BUSINESS1'], 'TXT_CRM_BUSINESS2' => $_ARRAYLANG['TXT_CRM_BUSINESS2'], 'TXT_CRM_BUSINESS3' => $_ARRAYLANG['TXT_CRM_BUSINESS3'], 'TXT_CRM_PRIVATE' => $_ARRAYLANG['TXT_CRM_PRIVATE'], 'TXT_CRM_OTHERS' => $_ARRAYLANG['TXT_CRM_OTHERS'], 'TXT_CRM_MOBILE' => $_ARRAYLANG['TXT_CRM_MOBILE'], 'TXT_CRM_FAX' => $_ARRAYLANG['TXT_CRM_FAX'], 'TXT_CRM_DIRECT' => $_ARRAYLANG['TXT_CRM_DIRECT'], 'TXT_CRM_DESCRIPTION' => $_ARRAYLANG['TXT_CRM_DESCRIPTION'], 'TXT_COMPANY_NAME' => $_ARRAYLANG['TXT_CRM_TITLE_COMPANY_NAME'], 'TXT_CRM_WEBSITE_SOCIAL_NETWORK' => $_ARRAYLANG['TXT_CRM_WEBSITE_SOCIAL_NETWORK'], 'TXT_CRM_WEBSITE' => $_ARRAYLANG['TXT_CRM_WEBSITE'], 'TXT_CRM_SKYPE' => $_ARRAYLANG['TXT_CRM_SKYPE'], 'TXT_CRM_TWITTER' => $_ARRAYLANG['TXT_CRM_TWITTER'], 'TXT_CRM_LINKEDIN' => $_ARRAYLANG['TXT_CRM_LINKEDIN'], 'TXT_CRM_FACEBOOK' => $_ARRAYLANG['TXT_CRM_FACEBOOK'], 'TXT_CRM_LIVEJOURNAL' => $_ARRAYLANG['TXT_CRM_LIVEJOURNAL'], 'TXT_CRM_MYSPACE' => $_ARRAYLANG['TXT_CRM_MYSPACE'], 'TXT_CRM_GMAIL' => $_ARRAYLANG['TXT_CRM_GMAIL'], 'TXT_CRM_BLOGGER' => $_ARRAYLANG['TXT_CRM_BLOGGER'], 'TXT_CRM_YAHOO' => $_ARRAYLANG['TXT_CRM_YAHOO'], 'TXT_CRM_MSN' => $_ARRAYLANG['TXT_CRM_MSN'], 'TXT_CRM_ICQ' => $_ARRAYLANG['TXT_CRM_ICQ'], 'TXT_CRM_JABBER' => $_ARRAYLANG['TXT_CRM_JABBER'], 'TXT_CRM_AIM' => $_ARRAYLANG['TXT_CRM_AIM'], 'TXT_CRM_GOOGLE_PLUS' => $_ARRAYLANG['TXT_CRM_GOOGLE_PLUS'], 'TXT_CRM_XING' => $_ARRAYLANG['TXT_CRM_XING'], 'TXT_CRM_ADDRESS' => $_ARRAYLANG['TXT_CRM_TITLE_ADDRESS'], 'TXT_CRM_SELECT_COUNTRY' => $_ARRAYLANG['TXT_CRM_SELECT_COUNTRY'], 'TXT_CRM_OVERVIEW' => $_ARRAYLANG['TXT_CRM_OVERVIEW'], 'TXT_CRM_ARE_YOU_SURE_DELETE_ENTRIES' => $_ARRAYLANG['TXT_CRM_ARE_YOU_SURE_DELETE_ENTRIES'], 'TXT_CRM_ARE_YOU_SURE_DELETE_SELECTED_ENTRIES' => $_ARRAYLANG['TXT_CRM_ARE_YOU_SURE_DELETE_SELECTED_ENTRIES'], 'TXT_CRM_ACCOUNT_EMAIL' => $_ARRAYLANG['TXT_CRM_ACCOUNT_EMAIL'], 'TXT_CRM_ACCOUNT_PASSWORD' => $_ARRAYLANG['TXT_CRM_ACCOUNT_PASSWORD'], 'TXT_CRM_SEND_LOGIN_DETAILS' => $_ARRAYLANG['TXT_CRM_SEND_LOGIN_DETAILS'], 'TXT_CRM_CHOOSE_MEMBERSHIPS' => $_ARRAYLANG['TXT_CRM_CHOOSE_MEMBERSHIPS'], 'TXT_CRM_EMAIL_DELIVERY' => $_ARRAYLANG['TXT_CRM_EMAIL_DELIVERY'], 'TXT_CRM_COMPANY_NAME' => $_ARRAYLANG['TXT_CRM_TITLE_COMPANY_NAME'], 'TXT_CRM_CUSTOMERTYPE' => $_ARRAYLANG['TXT_CRM_TITLE_CUSTOMERTYPE'], 'TXT_CRM_SOCIAL_NETWORK' => $_ARRAYLANG['TXT_CRM_SOCIAL_NETWORK'], 'TXT_CRM_GENDER' => $_ARRAYLANG['TXT_CRM_GENDER'], 'TXT_CRM_NOT_SPECIFIED' => $_ARRAYLANG['TXT_CRM_NOT_SPECIFIED'], 'TXT_CRM_GENDER_MALE' => $_ARRAYLANG['TXT_CRM_GENDER_MALE'], 'TXT_CRM_GENDER_FEMALE' => $_ARRAYLANG['TXT_CRM_GENDER_FEMALE'], 'TXT_CRM_CUSTOMERID' => $_ARRAYLANG['TXT_CRM_TITLE_CUSTOMERID'], 'TXT_CRM_CURRENCY' => $_ARRAYLANG['TXT_CRM_TITLE_CURRENCY'], 'TXT_CRM_COMPANY_SIZE' => $_ARRAYLANG['TXT_CRM_COMPANY_SIZE'], 'TXT_CRM_PLEASE_SELECT' => $_ARRAYLANG['TXT_CRM_PLEASE_SELECT'], 'TXT_CRM_GENERAL_INFORMATION' => $_ARRAYLANG['TXT_CRM_GENERAL_INFORMATION'], 'TXT_CRM_PROFILE_INFORMATION' => $_ARRAYLANG['TXT_CRM_PROFILE_INFORMATION'], 'TXT_CRM_ALL_PERSONS' => $_ARRAYLANG['TXT_CRM_ALL_PERSONS'], 'TXT_CRM_ADD_CONTACT' => $_ARRAYLANG['TXT_CRM_ADD_OR_LINK_CONTACT'], 'TXT_CRM_ENTER_WEBSITE' => $_ARRAYLANG['TXT_CRM_ENTER_WEBSITE'], 'TXT_CRM_WEBSITE_NAME' => $_ARRAYLANG['TXT_CRM_WEBSITE_NAME'], 'TXT_CRM_FUNCTIONS' => $_ARRAYLANG['TXT_CRM_FUNCTIONS'], 'TXT_CRM_SELECT_FROM_CONTACTS' => $_ARRAYLANG['TXT_CRM_SELECT_FROM_CONTACTS'], 'TXT_CRM_NO_MATCHES' => $_ARRAYLANG['TXT_CRM_NO_MATCHES'], 'TXT_CRM_ADD_NEW' => $_ARRAYLANG['TXT_CRM_ADD_NEW'], 'TXT_CANCEL' => $_ARRAYLANG['TXT_CANCEL'], 'TXT_CRM_WEBSITE' => $_ARRAYLANG['TXT_CRM_WEBSITE'], 'TXT_CRM_ADD_WEBSITE' => $_ARRAYLANG['TXT_CRM_ADD_WEBSITE'], 'TXT_CRM_PLEASE_SELECT' => $_ARRAYLANG['TXT_CRM_PLEASE_SELECT'], 'TXT_CRM_WEBSITES' => $_ARRAYLANG['TXT_CRM_WEBSITES'], 'BTN_SAVE' => $_ARRAYLANG['TXT_CRM_SAVE'], 'TXT_CRM_ADD_NEW_CUSTOMER' => $_ARRAYLANG['TXT_CRM_ADD_NEW_CUSTOMER'], 'TXT_CRM_ADD_NEW_CONTACT' => $_ARRAYLANG['TXT_CRM_ADD_NEW_CONTACT'], 'TXT_CRM_PROFILE' => $_ARRAYLANG['TXT_CRM_PROFILE'], 'TXT_CRM_ACCOUNT' => $_ARRAYLANG['TXT_CRM_ACCOUNT'], 'TXT_CORE_SEARCH_USER' => $_ARRAYLANG['TXT_CORE_SEARCH_USER'], 'TXT_CRM_ADVANCED_OPTIONS' => $_ARRAYLANG['TXT_CRM_ADVANCED_OPTIONS'], 'TXT_CRM_MEMBERSHIP' => $_ARRAYLANG['TXT_CRM_MEMBERSHIP'], 'TXT_CRM_ADD_NEW_ACCOUNT' => $_ARRAYLANG['TXT_CRM_ADD_NEW_ACCOUNT'], 'TXT_CRM_FIND_CONTACT_BY_NAME' => $_ARRAYLANG['TXT_CRM_FIND_CONTACT_BY_NAME'], 'TXT_CRM_FIND_COMPANY_BY_NAME' => $_ARRAYLANG['TXT_CRM_FIND_COMPANY_BY_NAME'], 'TXT_CRM_SAVE_CONTACT' => $contactType == 2 ? $_ARRAYLANG['TXT_CRM_SAVE_PERSON'] : $_ARRAYLANG['TXT_CRM_SAVE_COMPANY'], 'TXT_CRM_SAVE_AND_ADD_NEW_CONTACT' => $contactType == 2 ? $_ARRAYLANG['TXT_CRM_SAVE_AND_ADD_NEW_PERSON'] : $_ARRAYLANG['TXT_CRM_SAVE_AND_ADD_NEW_COMPANY'], 'TXT_CRM_SELECT_CUSTOMER_WATERMARK' => $this->contact->customerName == null ? 'crm-watermark' : '', 'COMPANY_MENU_ACTIVE' => $contactType == 1 ? 'active' : '', 'CONTACT_MENU_ACTIVE' => $contactType == 2 ? 'active' : '', 'CRM_REDIRECT_LINK' => $redirect)); if ($contactType == 2) { // If contact type eq to `contact` if ($settings['create_user_account']) { $this->_objTpl->touchBlock("contactUserName"); $this->_objTpl->touchBlock("contactPassword"); $this->_objTpl->touchBlock("show-account-details"); $this->_objTpl->touchBlock("contactSendNotification"); } else { $this->_objTpl->hideBlock("contactUserName"); $this->_objTpl->hideBlock("contactPassword"); $this->_objTpl->hideBlock("show-account-details"); $this->_objTpl->touchBlock("emptyContactUserName"); $this->_objTpl->touchBlock("emptyContactPassword"); } $this->_objTpl->parse("contactBlock"); $this->_objTpl->hideBlock("customerBlock"); $this->_objTpl->hideBlock("customerAdditionalBlock"); $this->_objTpl->touchBlock("contactWebsiteOptions"); $this->_objTpl->hideBlock("companyWebsiteOptions"); } else { $this->_objTpl->parse("customerBlock"); $this->_objTpl->parse("customerAdditionalBlock"); $this->_objTpl->hideBlock("contactBlock"); $this->_objTpl->touchBlock("companyWebsiteOptions"); $this->_objTpl->hideBlock("contactWebsiteOptions"); } }
/** * Returns an array with all placeholders and their values to be * replaced in any shop mailtemplate for the given order ID. * * You only have to set the 'substitution' index value of your MailTemplate * array to the array returned. * Customer data is not included here. See {@see Customer::getSubstitutionArray()}. * Note that this method is now mostly independent of the current session. * The language of the mail template is determined by the browser * language range stored with the order. * @access private * @static * @param integer $order_id The order ID * @param boolean $create_accounts If true, creates User accounts * and Coupon codes. Defaults to true * @return array The array with placeholders as keys * and values from the order on success, * false otherwise */ static function getSubstitutionArray($order_id, $create_accounts = true) { global $_ARRAYLANG; /* $_ARRAYLANG['TXT_SHOP_URI_FOR_DOWNLOAD'].":\r\n". 'http://'.$_SERVER['SERVER_NAME']. "/index.php?section=download\r\n"; */ $objOrder = Order::getById($order_id); if (!$objOrder) { // Order not found return false; } $lang_id = $objOrder->lang_id(); if (!intval($lang_id)) { $lang_id = \FWLanguage::getLangIdByIso639_1($lang_id); } $status = $objOrder->status(); $customer_id = $objOrder->customer_id(); $customer = Customer::getById($customer_id); $payment_id = $objOrder->payment_id(); $shipment_id = $objOrder->shipment_id(); $arrSubstitution = array('CUSTOMER_COUNTRY_ID' => $objOrder->billing_country_id(), 'LANG_ID' => $lang_id, 'NOW' => date(ASCMS_DATE_FORMAT_DATETIME), 'TODAY' => date(ASCMS_DATE_FORMAT_DATE), 'ORDER_ID' => $order_id, 'ORDER_ID_CUSTOM' => ShopLibrary::getCustomOrderId($order_id), 'ORDER_DATE' => date(ASCMS_DATE_FORMAT_DATE, strtotime($objOrder->date_time())), 'ORDER_TIME' => date(ASCMS_DATE_FORMAT_TIME, strtotime($objOrder->date_time())), 'ORDER_STATUS_ID' => $status, 'ORDER_STATUS' => $_ARRAYLANG['TXT_SHOP_ORDER_STATUS_' . $status], 'MODIFIED' => date(ASCMS_DATE_FORMAT_DATETIME, strtotime($objOrder->modified_on())), 'REMARKS' => $objOrder->note(), 'ORDER_SUM' => sprintf('% 9.2f', $objOrder->sum()), 'CURRENCY' => Currency::getCodeById($objOrder->currency_id())); $arrSubstitution += $customer->getSubstitutionArray(); if ($shipment_id) { $arrSubstitution += array('SHIPMENT' => array(0 => array('SHIPMENT_NAME' => sprintf('%-40s', Shipment::getShipperName($shipment_id)), 'SHIPMENT_PRICE' => sprintf('% 9.2f', $objOrder->shipment_amount()))), 'SHIPPING_ADDRESS' => array(0 => array('SHIPPING_COMPANY' => $objOrder->company(), 'SHIPPING_TITLE' => $_ARRAYLANG['TXT_SHOP_' . strtoupper($objOrder->gender())], 'SHIPPING_FIRSTNAME' => $objOrder->firstname(), 'SHIPPING_LASTNAME' => $objOrder->lastname(), 'SHIPPING_ADDRESS' => $objOrder->address(), 'SHIPPING_ZIP' => $objOrder->zip(), 'SHIPPING_CITY' => $objOrder->city(), 'SHIPPING_COUNTRY_ID' => $objOrder->country_id(), 'SHIPPING_COUNTRY' => \Cx\Core\Country\Controller\Country::getNameById($objOrder->country_id()), 'SHIPPING_PHONE' => $objOrder->phone()))); } if ($payment_id) { $arrSubstitution += array('PAYMENT' => array(0 => array('PAYMENT_NAME' => sprintf('%-40s', Payment::getNameById($payment_id)), 'PAYMENT_PRICE' => sprintf('% 9.2f', $objOrder->payment_amount())))); } $arrItems = $objOrder->getItems(); if (!$arrItems) { \Message::warning($_ARRAYLANG['TXT_SHOP_ORDER_WARNING_NO_ITEM']); } // Deduct Coupon discounts, either from each Product price, or // from the items total. Mind that the Coupon has already been // stored with the Order, but not redeemed yet. This is done // in this method, but only if $create_accounts is true. $coupon_code = NULL; $coupon_amount = 0; $objCoupon = Coupon::getByOrderId($order_id); if ($objCoupon) { $coupon_code = $objCoupon->code(); } $orderItemCount = 0; $total_item_price = 0; // Suppress Coupon messages (see Coupon::available()) \Message::save(); foreach ($arrItems as $item) { $product_id = $item['product_id']; $objProduct = Product::getById($product_id); if (!$objProduct) { //die("Product ID $product_id not found"); continue; } //DBG::log("Orders::getSubstitutionArray(): Item: Product ID $product_id"); $product_name = substr($item['name'], 0, 40); $item_price = $item['price']; $quantity = $item['quantity']; // TODO: Add individual VAT rates for Products // $orderItemVatPercent = $objResultItem->fields['vat_percent']; // Decrease the Product stock count, // applies to "real", shipped goods only $objProduct->decreaseStock($quantity); $product_code = $objProduct->code(); // Pick the order items attributes $str_options = ''; // Any attributes? if ($item['attributes']) { $str_options = ' '; // '['; $attribute_name_previous = ''; foreach ($item['attributes'] as $attribute_name => $arrAttribute) { //DBG::log("Attribute /$attribute_name/ => ".var_export($arrAttribute, true)); // NOTE: The option price is optional and may be left out foreach ($arrAttribute as $arrOption) { $option_name = $arrOption['name']; $option_price = $arrOption['price']; $item_price += $option_price; // Recognize the names of uploaded files, // verify their presence and use the original name $option_name_stripped = ShopLibrary::stripUniqidFromFilename($option_name); $path = Order::UPLOAD_FOLDER . $option_name; if ($option_name != $option_name_stripped && \File::exists($path)) { $option_name = $option_name_stripped; } if ($attribute_name != $attribute_name_previous) { if ($attribute_name_previous) { $str_options .= '; '; } $str_options .= $attribute_name . ': ' . $option_name; $attribute_name_previous = $attribute_name; } else { $str_options .= ', ' . $option_name; } // TODO: Add proper formatting with sprintf() and language entries if ($option_price != 0) { $str_options .= ' ' . Currency::formatPrice($option_price) . ' ' . Currency::getActiveCurrencyCode(); } } } // $str_options .= ']'; } // Product details $arrProduct = array('PRODUCT_ID' => $product_id, 'PRODUCT_CODE' => $product_code, 'PRODUCT_QUANTITY' => $quantity, 'PRODUCT_TITLE' => $product_name, 'PRODUCT_OPTIONS' => $str_options, 'PRODUCT_ITEM_PRICE' => sprintf('% 9.2f', $item_price), 'PRODUCT_TOTAL_PRICE' => sprintf('% 9.2f', $item_price * $quantity)); //DBG::log("Orders::getSubstitutionArray($order_id, $create_accounts): Adding article: ".var_export($arrProduct, true)); $orderItemCount += $quantity; $total_item_price += $item_price * $quantity; if ($create_accounts) { // Add an account for every single instance of every Product for ($instance = 1; $instance <= $quantity; ++$instance) { $validity = 0; // Default to unlimited validity // In case there are protected downloads in the cart, // collect the group IDs $arrUsergroupId = array(); if ($objProduct->distribution() == 'download') { $usergroupIds = $objProduct->usergroup_ids(); if ($usergroupIds != '') { $arrUsergroupId = explode(',', $usergroupIds); $validity = $objProduct->weight(); } } // create an account that belongs to all collected // user groups, if any. if (count($arrUsergroupId) > 0) { // The login names are created separately for // each product instance $username = self::usernamePrefix . "_{$order_id}_{$product_id}_{$instance}"; $userEmail = $username . '-' . $arrSubstitution['CUSTOMER_EMAIL']; $userpass = \User::make_password(); $objUser = new \User(); $objUser->setUsername($username); $objUser->setPassword($userpass); $objUser->setEmail($userEmail); $objUser->setAdminStatus(false); $objUser->setActiveStatus(true); $objUser->setGroups($arrUsergroupId); $objUser->setValidityTimePeriod($validity); $objUser->setFrontendLanguage(FRONTEND_LANG_ID); $objUser->setBackendLanguage(FRONTEND_LANG_ID); $objUser->setProfile(array('firstname' => array(0 => $arrSubstitution['CUSTOMER_FIRSTNAME']), 'lastname' => array(0 => $arrSubstitution['CUSTOMER_LASTNAME']), 'company' => array(0 => $arrSubstitution['CUSTOMER_COMPANY']), 'address' => array(0 => $arrSubstitution['CUSTOMER_ADDRESS']), 'zip' => array(0 => $arrSubstitution['CUSTOMER_ZIP']), 'city' => array(0 => $arrSubstitution['CUSTOMER_CITY']), 'country' => array(0 => $arrSubstitution['CUSTOMER_COUNTRY_ID']), 'phone_office' => array(0 => $arrSubstitution['CUSTOMER_PHONE']), 'phone_fax' => array(0 => $arrSubstitution['CUSTOMER_FAX']))); if (!$objUser->store()) { \Message::error(implode('<br />', $objUser->getErrorMsg())); return false; } if (empty($arrProduct['USER_DATA'])) { $arrProduct['USER_DATA'] = array(); } $arrProduct['USER_DATA'][] = array('USER_NAME' => $username, 'USER_PASS' => $userpass); } //echo("Instance $instance"); if ($objProduct->distribution() == 'coupon') { if (empty($arrProduct['COUPON_DATA'])) { $arrProduct['COUPON_DATA'] = array(); } //DBG::log("Orders::getSubstitutionArray(): Getting code"); $code = Coupon::getNewCode(); //DBG::log("Orders::getSubstitutionArray(): Got code: $code, calling Coupon::addCode($code, 0, 0, 0, $item_price)"); Coupon::storeCode($code, 0, 0, 0, $item_price, 0, 0, 10000000000.0, true); $arrProduct['COUPON_DATA'][] = array('COUPON_CODE' => $code); } } // Redeem the *product* Coupon, if possible for the Product if ($coupon_code) { $objCoupon = Coupon::available($coupon_code, $item_price * $quantity, $customer_id, $product_id, $payment_id); if ($objCoupon) { $coupon_code = NULL; $coupon_amount = $objCoupon->getDiscountAmount($item_price, $customer_id); if ($create_accounts) { $objCoupon->redeem($order_id, $customer_id, $item_price * $quantity); } } //\DBG::log("Orders::getSubstitutionArray(): Got Product Coupon $coupon_code"); } } if (empty($arrSubstitution['ORDER_ITEM'])) { $arrSubstitution['ORDER_ITEM'] = array(); } $arrSubstitution['ORDER_ITEM'][] = $arrProduct; } $arrSubstitution['ORDER_ITEM_SUM'] = sprintf('% 9.2f', $total_item_price); $arrSubstitution['ORDER_ITEM_COUNT'] = sprintf('% 4u', $orderItemCount); // Redeem the *global* Coupon, if possible for the Order if ($coupon_code) { $objCoupon = Coupon::available($coupon_code, $total_item_price, $customer_id, null, $payment_id); if ($objCoupon) { $coupon_amount = $objCoupon->getDiscountAmount($total_item_price, $customer_id); if ($create_accounts) { $objCoupon->redeem($order_id, $customer_id, $total_item_price); } } } \Message::restore(); // Fill in the Coupon block with proper discount and amount if ($objCoupon) { $coupon_code = $objCoupon->code(); //\DBG::log("Orders::getSubstitutionArray(): Coupon $coupon_code, amount $coupon_amount"); } if ($coupon_amount) { //\DBG::log("Orders::getSubstitutionArray(): Got Order Coupon $coupon_code"); $arrSubstitution['DISCOUNT_COUPON'][] = array('DISCOUNT_COUPON_CODE' => sprintf('%-40s', $coupon_code), 'DISCOUNT_COUPON_AMOUNT' => sprintf('% 9.2f', -$coupon_amount)); } else { //\DBG::log("Orders::getSubstitutionArray(): No Coupon for Order ID $order_id"); } Products::deactivate_soldout(); if (Vat::isEnabled()) { //DBG::log("Orders::getSubstitutionArray(): VAT amount: ".$objOrder->vat_amount()); $arrSubstitution['VAT'] = array(0 => array('VAT_TEXT' => sprintf('%-40s', Vat::isIncluded() ? $_ARRAYLANG['TXT_SHOP_VAT_PREFIX_INCL'] : $_ARRAYLANG['TXT_SHOP_VAT_PREFIX_EXCL']), 'VAT_PRICE' => $objOrder->vat_amount())); } return $arrSubstitution; }
/** * Store a customer * * Sets a Message according to the outcome. * Note that failure to send the e-mail with login data is not * considered an error and will only produce a warning. * @return integer The Customer ID on success, null otherwise * @author Reto Kohli <*****@*****.**> */ static function storeCustomerFromPost() { global $_ARRAYLANG; $username = trim(strip_tags(contrexx_input2raw($_POST['username']))); $password = trim(strip_tags(contrexx_input2raw($_POST['password']))); $company = trim(strip_tags(contrexx_input2raw($_POST['company']))); $gender = trim(strip_tags(contrexx_input2raw($_POST['gender']))); $firstname = trim(strip_tags(contrexx_input2raw($_POST['firstname']))); $lastname = trim(strip_tags(contrexx_input2raw($_POST['lastname']))); $address = trim(strip_tags(contrexx_input2raw($_POST['address']))); $city = trim(strip_tags(contrexx_input2raw($_POST['city']))); $zip = trim(strip_tags(contrexx_input2raw($_POST['zip']))); $country_id = intval($_POST['country_id']); $phone = trim(strip_tags(contrexx_input2raw($_POST['phone']))); $fax = trim(strip_tags(contrexx_input2raw($_POST['fax']))); $email = trim(strip_tags(contrexx_input2raw($_POST['email']))); $companynote = trim(strip_tags(contrexx_input2raw($_POST['companynote']))); $customer_active = intval($_POST['active']); $is_reseller = intval($_POST['customer_type']); $customer_group_id = intval($_POST['customer_group_id']); // $registerdate = trim(strip_tags(contrexx_input2raw($_POST['registerdate']))); $lang_id = isset($_POST['customer_lang_id']) ? intval($_POST['customer_lang_id']) : FRONTEND_LANG_ID; $customer_id = intval($_REQUEST['customer_id']); $objCustomer = Customer::getById($customer_id); if (!$objCustomer) { $objCustomer = new Customer(); } $objCustomer->gender($gender); $objCustomer->company($company); $objCustomer->firstname($firstname); $objCustomer->lastname($lastname); $objCustomer->address($address); $objCustomer->city($city); $objCustomer->zip($zip); $objCustomer->country_id($country_id); $objCustomer->phone($phone); $objCustomer->fax($fax); $objCustomer->email($email); $objCustomer->companynote($companynote); $objCustomer->active($customer_active); $objCustomer->is_reseller($is_reseller); // Set automatically: $objCustomer->setRegisterDate($registerdate); $objCustomer->group_id($customer_group_id); $objCustomer->username($username); if (isset($_POST['sendlogindata']) && $password == '') { $password = \User::make_password(); } if ($password != '') { $objCustomer->password($password); } $objCustomer->setFrontendLanguage($lang_id); if (!$objCustomer->store()) { foreach ($objCustomer->error_msg as $message) { \Message::error($message); } return null; } \Message::ok($_ARRAYLANG['TXT_DATA_RECORD_UPDATED_SUCCESSFUL']); if (isset($_POST['sendlogindata'])) { // TODO: Use a common sendLogin() method $lang_id = $objCustomer->getFrontendLanguage(); $arrSubs = $objCustomer->getSubstitutionArray(); $arrSubs['CUSTOMER_LOGIN'] = array(0 => array('CUSTOMER_USERNAME' => $username, 'CUSTOMER_PASSWORD' => $password)); //DBG::log("Subs: ".var_export($arrSubs, true)); // Select template for sending login data $arrMailTemplate = array('key' => 'customer_login', 'section' => 'Shop', 'lang_id' => $lang_id, 'to' => $email, 'substitution' => $arrSubs); if (!\Cx\Core\MailTemplate\Controller\MailTemplate::send($arrMailTemplate)) { \Message::warning($_ARRAYLANG['TXT_MESSAGE_SEND_ERROR']); return $objCustomer->id(); } \Message::ok(sprintf($_ARRAYLANG['TXT_EMAIL_SEND_SUCCESSFULLY'], $email)); } return $objCustomer->id(); }