/** * Adding Crm Contact and link it with crm company if possible * * @param Array $arrFormData form data's * @param int $userAccountId * @param int $frontendLanguage * @global <object> $objDatabase * @global int $_LANGID * */ function setContactPersonProfile($arrFormData = array(), $userAccountId = 0, $frontendLanguage) { global $objDatabase, $_LANGID; $this->contact = new \Cx\Modules\Crm\Model\Entity\CrmContact(); if (!empty($userAccountId)) { $userExists = $objDatabase->Execute("SELECT id FROM `" . DBPREFIX . "module_{$this->moduleNameLC}_contacts` WHERE user_account = {$userAccountId}"); if ($userExists && $userExists->RecordCount()) { $id = (int) $userExists->fields['id']; $this->contact->load($id); $this->contact->customerName = !empty($arrFormData['firstname'][0]) ? contrexx_input2raw($arrFormData['firstname'][0]) : ''; $this->contact->family_name = !empty($arrFormData['lastname'][0]) ? contrexx_input2raw($arrFormData['lastname'][0]) : ''; $this->contact->contact_language = !empty($frontendLanguage) ? (int) $frontendLanguage : $_LANGID; $this->contact->contact_gender = !empty($arrFormData['gender'][0]) ? $arrFormData['gender'][0] == 'gender_female' ? 1 : ($arrFormData['gender'][0] == 'gender_male' ? 2 : '') : ''; $this->contact->contactType = 2; $this->contact->datasource = 2; $this->contact->account_id = $userAccountId; //set profile picture if (!empty($arrFormData['picture'][0])) { $picture = $arrFormData['picture'][0]; $cx = \Cx\Core\Core\Controller\Cx::instanciate(); if (!file_exists($cx->getWebsiteImagesCrmProfilePath() . '/' . $picture)) { $file = $cx->getWebsiteImagesAccessProfilePath() . '/'; $newFile = $cx->getWebsiteImagesCrmProfilePath() . '/'; if (copy($file . $picture, $newFile . $picture)) { if ($this->createThumbnailOfPicture($picture)) { $this->contact->profile_picture = $picture; } } } } else { $this->contact->profile_picture = 'profile_person_big.png'; } // save current setting values, so we can switch back to them after we got our used settings out of database $prevSection = \Cx\Core\Setting\Controller\Setting::getCurrentSection(); $prevGroup = \Cx\Core\Setting\Controller\Setting::getCurrentGroup(); $prevEngine = \Cx\Core\Setting\Controller\Setting::getCurrentEngine(); \Cx\Core\Setting\Controller\Setting::init('Crm', 'config'); if ($arrFormData["company"][0] != "") { $crmCompany = new \Cx\Modules\Crm\Model\Entity\CrmContact(); if ($this->contact->contact_customer != 0) { $crmCompany->load($this->contact->contact_customer); } $crmCompany->customerName = $arrFormData["company"][0]; $crmCompany->contactType = 1; $customerType = $arrFormData[\Cx\Core\Setting\Controller\Setting::getValue('user_profile_attribute_customer_type', 'Crm')][0]; if ($customerType !== false) { $crmCompany->customerType = $customerType; } $companySize = $arrFormData[\Cx\Core\Setting\Controller\Setting::getValue('user_profile_attribute_company_size', 'Crm')][0]; if ($companySize !== false) { $crmCompany->companySize = $companySize; } $industryType = $arrFormData[\Cx\Core\Setting\Controller\Setting::getValue('user_profile_attribute_industry_type', 'Crm')][0]; if ($industryType !== false) { $crmCompany->industryType = $industryType; } if (isset($arrFormData["phone_office"])) { $crmCompany->phone = $arrFormData["phone_office"]; } // store/update the company profile $crmCompany->save(); // setting & storing the primary email address must be done after // the company has been saved for the case where the company is // being added as a new object without having an ID yet if (empty($crmCompany->email)) { $crmCompany->email = $this->contact->email; $crmCompany->storeEMail(); } $this->contact->contact_customer = $crmCompany->id; } if ($this->contact->save()) { // insert website if (!empty($arrFormData['website'][0])) { $webExists = $objDatabase->SelectLimit("SELECT 1 FROM `" . DBPREFIX . "module_{$this->moduleNameLC}_customer_contact_websites` WHERE is_primary = '1' AND contact_id = '{$this->contact->id}'"); $fields = array('url' => $arrFormData['website'][0], 'url_profile' => '1', 'is_primary' => '1', 'contact_id' => $this->contact->id); if ($webExists) { $query = \SQL::update("module_{$this->moduleNameLC}_customer_contact_websites", $fields, array('escape' => true)) . " WHERE is_primary = '1' AND `contact_id` = {$this->contact->id}"; } else { $query = \SQL::insert("module_{$this->moduleNameLC}_customer_contact_websites", $fields, array('escape' => true)); } $db = $objDatabase->Execute($query); } //insert address if (!empty($arrFormData['address'][0]) || !empty($arrFormData['city'][0]) || !empty($arrFormData['zip'][0]) || !empty($arrFormData['country'][0])) { $addressExists = $objDatabase->SelectLimit("SELECT 1 FROM `" . DBPREFIX . "module_{$this->moduleNameLC}_customer_contact_address` WHERE is_primary = '1' AND contact_id = '{$this->contact->id}'"); $country = \Cx\Core\Country\Controller\Country::getById($arrFormData['country'][0]); if ($addressExists && $addressExists->RecordCount()) { $query = "UPDATE `" . DBPREFIX . "module_{$this->moduleNameLC}_customer_contact_address` SET\n address = '" . contrexx_input2db($arrFormData['address'][0]) . "',\n city = '" . contrexx_input2db($arrFormData['city'][0]) . "',\n zip = '" . contrexx_input2db($arrFormData['zip'][0]) . "',\n country = '" . $country['name'] . "',\n Address_Type = '2'\n WHERE is_primary = '1' AND contact_id = '{$this->contact->id}'"; } else { $query = "INSERT INTO `" . DBPREFIX . "module_{$this->moduleNameLC}_customer_contact_address` SET\n address = '" . contrexx_input2db($arrFormData['address'][0]) . "',\n city = '" . contrexx_input2db($arrFormData['city'][0]) . "',\n state = '" . contrexx_input2db($arrFormData['city'][0]) . "',\n zip = '" . contrexx_input2db($arrFormData['zip'][0]) . "',\n country = '" . $country['name'] . "',\n Address_Type = '2',\n is_primary = '1',\n contact_id = '{$this->contact->id}'"; } $objDatabase->Execute($query); } // insert Phone $contactPhone = array(); if (!empty($arrFormData['phone_office'][0])) { $phoneExists = $objDatabase->SelectLimit("SELECT 1 FROM `" . DBPREFIX . "module_{$this->moduleNameLC}_customer_contact_phone` WHERE is_primary = '1' AND contact_id = '{$this->contact->id}'"); $fields = array('phone' => $arrFormData['phone_office'][0], 'phone_type' => '1', 'is_primary' => '1', 'contact_id' => $this->contact->id); if ($phoneExists && $phoneExists->RecordCount()) { $query = \SQL::update("module_{$this->moduleNameLC}_customer_contact_phone", $fields, array('escape' => true)) . " WHERE is_primary = '1' AND `contact_id` = {$this->contact->id}"; } else { $query = \SQL::insert("module_{$this->moduleNameLC}_customer_contact_phone", $fields, array('escape' => true)); } $objDatabase->Execute($query); } } \Cx\Core\Setting\Controller\Setting::init($prevSection, $prevGroup, $prevEngine); } } }
function modifyEntry() { global $_ARRAYLANG, $_CORELANG, $objDatabase, $_LANGID; \JS::activate('cx'); \JS::activate('jqueryui'); $this->_objTpl->loadTemplateFile('module_' . $this->moduleNameLC . '_modify_entry.html', true, true); $this->pageTitle = $_ARRAYLANG['TXT_MEDIADIR_ENTRIES']; //get seting values parent::getSettings(); $intEntryDourationAlways = ''; $intEntryDourationPeriod = ''; $intEntryDourationShowPeriod = 'none'; $intEntryDourationEnd = 0; $intEntryDourationStart = 0; $strOnSubmit = ''; if (!empty($_GET['id'])) { \Permission::checkAccess(MediaDirectoryAccessIDs::ModifyEntry, 'static'); $pageTitle = $_ARRAYLANG['TXT_MEDIADIR_ENTRY'] . " " . $_ARRAYLANG['TXT_MEDIADIR_EDIT']; $intEntryId = intval($_GET['id']); } else { \Permission::checkAccess(MediaDirectoryAccessIDs::AddEntry, 'static'); $pageTitle = $_ARRAYLANG['TXT_MEDIADIR_ENTRY'] . " " . $_ARRAYLANG['TXT_MEDIADIR_ADD']; $intEntryId = null; } //count forms $objForms = new MediaDirectoryForm(null, $this->moduleName); $arrActiveForms = array(); foreach ($objForms->arrForms as $intFormId => $arrForm) { if ($arrForm['formActive'] == 1) { $arrActiveForms[] = $intFormId; } } $intCountForms = count($arrActiveForms); if ($intCountForms > 0) { if (intval($intEntryId) == 0 && (empty($_POST['selectedFormId']) && empty($_POST['formId'])) && $intCountForms > 1) { $intFormId = null; //get form selector $objForms->listForms($this->_objTpl, 2, $intFormId); //parse blocks $this->_objTpl->hideBlock($this->moduleNameLC . 'EntryStatus'); $this->_objTpl->hideBlock($this->moduleNameLC . 'InputfieldList'); $this->_objTpl->hideBlock($this->moduleNameLC . 'SpezfieldList'); } else { //save entry data if (isset($_POST['submitEntryModfyForm']) && !empty($_POST['formId'])) { $objEntry = new MediaDirectoryEntry($this->moduleName); $intEntryId = intval($_POST['entryId']); $intEntryId = $objEntry->saveEntry($_POST, $intEntryId); if (!empty($_POST['entryId'])) { if ($intEntryId) { $this->strOkMessage = $_ARRAYLANG['TXT_MEDIADIR_ENTRY'] . ' ' . $_ARRAYLANG['TXT_MEDIADIR_SUCCESSFULLY_EDITED']; } else { $intEntryId = intval($_POST['entryId']); $this->strErrMessage = $_ARRAYLANG['TXT_MEDIADIR_ENTRY'] . ' ' . $_ARRAYLANG['TXT_MEDIADIR_CORRUPT_EDITED']; } } else { if ($intEntryId) { $this->strOkMessage = $_ARRAYLANG['TXT_MEDIADIR_ENTRY'] . ' ' . $_ARRAYLANG['TXT_MEDIADIR_SUCCESSFULLY_ADDED']; } else { $this->strErrMessage = $_ARRAYLANG['TXT_MEDIADIR_ENTRY'] . ' ' . $_ARRAYLANG['TXT_MEDIADIR_CORRUPT_ADDED']; } } } //get form id if (intval($intEntryId) != 0) { //get entry data $objEntry = new MediaDirectoryEntry($this->moduleName); $objEntry->getEntries($intEntryId, null, null, null, null, false, false); if (empty($objEntry->arrEntries)) { $objEntry->getEntries($intEntryId, null, null, null, null, true, false); } $intFormId = $objEntry->arrEntries[$intEntryId]['entryFormId']; } else { //set form id if ($intCountForms == 1) { $intFormId = intval($arrActiveForms[0]); } else { $intFormId = intval($_POST['selectedFormId']); } if (!empty($_POST['formId'])) { $intFormId = intval($_POST['formId']); } } //get inputfield object $objInputfields = new MediaDirectoryInputfield($intFormId, false, null, $this->moduleName); //list inputfields $objInputfields->listInputfields($this->_objTpl, 2, $intEntryId); //get translation status date if ($this->arrSettings['settingsTranslationStatus'] == 1) { $ownerRowClass = "row1"; foreach ($this->arrFrontendLanguages as $key => $arrLang) { $strLangStatus = ''; if ($intEntryId != 0) { if (in_array($arrLang['id'], $objEntry->arrEntries[$intEntryId]['entryTranslationStatus'])) { $strLangStatus = 'checked="checked"'; } } $this->_objTpl->setVariable(array('TXT_' . $this->moduleLangVar . '_TRANSLATION_LANG_NAME' => htmlspecialchars($arrLang['name'], ENT_QUOTES, CONTREXX_CHARSET), $this->moduleLangVar . '_TRANSLATION_LANG_ID' => intval($arrLang['id']), $this->moduleLangVar . '_TRANSLATION_LANG_STATUS' => $strLangStatus)); $this->_objTpl->parse($this->moduleNameLC . 'TranslationLangList'); } $this->_objTpl->parse($this->moduleNameLC . 'TranslationStatus'); } else { $ownerRowClass = "row2"; $this->_objTpl->hideBlock($this->moduleNameLC . 'TranslationStatus'); } //get user data $objFWUser = \FWUser::getFWUserObject(); $addedBy = isset($objEntry) ? $objEntry->arrEntries[$intEntryId]['entryAddedBy'] : ''; if (!empty($addedBy) && ($objUser = $objFWUser->objUser->getUser($addedBy))) { $userId = $objUser->getId(); } else { $userId = $objFWUser->objUser->getId(); } $this->_objTpl->setVariable(array('TXT_' . $this->moduleLangVar . '_OWNER' => $_ARRAYLANG['TXT_MEDIADIR_OWNER'], $this->moduleLangVar . '_OWNER_ROW' => $ownerRowClass, $this->moduleLangVar . '_OWNER_ID' => $userId)); \FWUser::getUserLiveSearch(); if ($intEntryId != 0) { $intEntryDourationStart = 1; $intEntryDourationEnd = 2; //parse contact data $objUser = $objFWUser->objUser; $intUserId = intval($objUser->getId()); $strUserMail = '<a href="mailto:' . contrexx_raw2xhtml($objUser->getEmail()) . '">' . contrexx_raw2xhtml($objUser->getEmail()) . '</a>'; $intUserLang = intval($objUser->getFrontendLanguage()); if ($objUser = $objUser->getUser($id = $intUserId)) { //get lang foreach ($this->arrFrontendLanguages as $intKey => $arrLang) { if ($arrLang['id'] == $intUserLang) { $strUserLang = $arrLang['name']; } } //get country $arrCountry = \Cx\Core\Country\Controller\Country::getById(intval($objUser->getProfileAttribute('country'))); $strCountry = $arrCountry['name']; //get title $objTitle = $objDatabase->Execute("SELECT `title` FROM " . DBPREFIX . "access_user_title WHERE id = '" . intval($objUser->getProfileAttribute('title')) . "' LIMIT 1"); $strTitle = $objTitle->fields['title']; $this->_objTpl->setVariable(array('TXT_' . $this->moduleLangVar . '_CONTACT_DATA' => "Kontaktangaben", $this->moduleLangVar . '_CONTACT_ATTRIBUT_TITLE' => contrexx_raw2xhtml($strTitle), $this->moduleLangVar . '_CONTACT_ATTRIBUT_FIRSTNAME' => contrexx_raw2xhtml($objUser->getProfileAttribute('firstname')), $this->moduleLangVar . '_CONTACT_ATTRIBUT_LASTNAME' => contrexx_raw2xhtml($objUser->getProfileAttribute('lastname')), $this->moduleLangVar . '_CONTACT_ATTRIBUT_COMPANY' => contrexx_raw2xhtml($objUser->getProfileAttribute('company')), $this->moduleLangVar . '_CONTACT_ATTRIBUT_ADRESS' => contrexx_raw2xhtml($objUser->getProfileAttribute('address')), $this->moduleLangVar . '_CONTACT_ATTRIBUT_CITY' => contrexx_raw2xhtml($objUser->getProfileAttribute('city')), $this->moduleLangVar . '_CONTACT_ATTRIBUT_ZIP' => contrexx_raw2xhtml($objUser->getProfileAttribute('zip')), $this->moduleLangVar . '_CONTACT_ATTRIBUT_COUNTRY' => contrexx_raw2xhtml($strCountry), $this->moduleLangVar . '_CONTACT_ATTRIBUT_PHONE' => contrexx_raw2xhtml($objUser->getProfileAttribute('phone_office')), $this->moduleLangVar . '_CONTACT_ATTRIBUT_FAX' => contrexx_raw2xhtml($objUser->getProfileAttribute('phone_fax')), $this->moduleLangVar . '_CONTACT_ATTRIBUT_WEBSITE' => '<a href="' . contrexx_raw2xhtml($objUser->getProfileAttribute('website')) . '" target="_blank">' . contrexx_raw2xhtml($objUser->getProfileAttribute('website')) . '</a>', $this->moduleLangVar . '_CONTACT_ATTRIBUT_MAIL' => $strUserMail, $this->moduleLangVar . '_CONTACT_ATTRIBUT_LANG' => $strUserLang)); } $this->_objTpl->parse($this->moduleNameLC . 'ContactData'); } else { $intEntryDourationStart = 1; $intEntryDourationEnd = 2; $this->_objTpl->hideBlock($this->moduleNameLC . 'ContactData'); } //get display duration data switch ($this->arrSettings['settingsEntryDisplaydurationValueType']) { case 1: $intDiffDay = $this->arrSettings['settingsEntryDisplaydurationValue']; $intDiffMonth = 0; $intDiffYear = 0; break; case 2: $intDiffDay = 0; $intDiffMonth = $this->arrSettings['settingsEntryDisplaydurationValue']; $intDiffYear = 0; break; case 3: $intDiffDay = 0; $intDiffMonth = 0; $intDiffYear = $this->arrSettings['settingsEntryDisplaydurationValue']; break; } if ($intEntryId != 0) { if (intval($objEntry->arrEntries[$intEntryId]['entryDurationType']) == 1) { $intEntryDourationAlways = 'selected="selected"'; $intEntryDourationStart = date("d.m.Y", mktime()); $intEntryDourationEnd = date("d.m.Y", mktime(0, 0, 0, date("m") + $intDiffMonth, date("d") + $intDiffDay, date("Y") + $intDiffYear)); } else { $intEntryDourationPeriod = 'selected="selected"'; $intEntryDourationShowPeriod = 'inline'; $intEntryDourationStart = date("d.m.Y", $objEntry->arrEntries[$intEntryId]['entryDurationStart']); $intEntryDourationEnd = date("d.m.Y", $objEntry->arrEntries[$intEntryId]['entryDurationEnd']); } if (intval($objEntry->arrEntries[$intEntryId]['entryDurationNotification']) == 1) { $this->_objTpl->setVariable(array($this->moduleLangVar . '_DISPLAYDURATION_RESET_NOTIFICATION_STATUS' => '<br /><input type="checkbox" name="durationResetNotification" value="1" /> ' . $_ARRAYLANG['TXT_MEDIADIR_DISPLAYDURATION_RESET_NOTIFICATION_STATUS'])); } } else { if (intval($this->arrSettings['settingsEntryDisplaydurationType']) == 1) { $intEntryDourationAlways = 'selected="selected"'; } else { $intEntryDourationPeriod = 'selected="selected"'; $intEntryDourationShowPeriod = 'inline'; } $intEntryDourationStart = date("d.m.Y", mktime()); $intEntryDourationEnd = date("d.m.Y", mktime(0, 0, 0, date("m") + $intDiffMonth, date("d") + $intDiffDay, date("Y") + $intDiffYear)); } //parse spez fields $this->_objTpl->touchBlock($this->moduleNameLC . 'SpezfieldList'); //generate javascript parent::setJavascript($this->getSelectorJavascript()); parent::setJavascript($objInputfields->getInputfieldJavascript()); //get form onsubmit $strOnSubmit = parent::getFormOnSubmit($objInputfields->arrJavascriptFormOnSubmit); $this->_objTpl->setVariable(array($this->moduleLangVar . '_ENTRY_STATUS' => $intEntryId && intval($objEntry->arrEntries[$intEntryId]['entryActive']) ? 'checked="checked"' : '', $this->moduleLangVar . '_MEDIABROWSER_BUTTON' => $this->getMediaBrowserButton($_ARRAYLANG['TXT_BROWSE'], array('type' => 'button', 'id' => 'mediabrowser_button', 'style' => 'display:none;')))); //parse blocks $this->_objTpl->hideBlock($this->moduleNameLC . 'FormList'); } //parse global variables $this->_objTpl->setGlobalVariable(array('TXT_' . $this->moduleLangVar . '_PAGE_TITLE' => $pageTitle, $this->moduleLangVar . '_ENTRY_ID' => $intEntryId, $this->moduleLangVar . '_FORM_ID' => $intFormId, 'TXT_' . $this->moduleLangVar . '_SUBMIT' => $_ARRAYLANG['TXT_' . $this->moduleLangVar . '_SUBMIT'], $this->moduleLangVar . '_JAVASCRIPT' => $this->getJavascript(), $this->moduleLangVar . '_FORM_ONSUBMIT' => $strOnSubmit, 'TXT_' . $this->moduleLangVar . '_PLEASE_CHECK_INPUT' => $_ARRAYLANG['TXT_MEDIADIR_PLEASE_CHECK_INPUT'], $this->moduleLangVar . '_DEFAULT_LANG_ID' => $_LANGID, 'TXT_' . $this->moduleLangVar . '_SPEZ_FIELDS' => $_ARRAYLANG['TXT_MEDIADIR_SPEZ_FIELDS'], 'TXT_' . $this->moduleLangVar . '_DISPLAYDURATION' => $_ARRAYLANG['TXT_MEDIADIR_DISPLAYDURATION'], 'TXT_' . $this->moduleLangVar . '_DISPLAYDURATION_ALWAYS' => $_ARRAYLANG['TXT_MEDIADIR_DISPLAYDURATION_ALWAYS'], 'TXT_' . $this->moduleLangVar . '_DISPLAYDURATION_PERIOD' => $_ARRAYLANG['TXT_MEDIADIR_DISPLAYDURATION_PERIOD'], 'TXT_' . $this->moduleLangVar . '_DISPLAYDURATION_FROM' => $_CORELANG['TXT_FROM'], 'TXT_' . $this->moduleLangVar . '_DISPLAYDURATION_TO' => $_CORELANG['TXT_TO'], $this->moduleLangVar . '_DISPLAYDURATION_START' => $intEntryDourationStart, $this->moduleLangVar . '_DISPLAYDURATION_END' => $intEntryDourationEnd, $this->moduleLangVar . '_DISPLAYDURATION_SELECT_ALWAYS' => $intEntryDourationAlways, $this->moduleLangVar . '_DISPLAYDURATION_SELECT_PERIOD' => $intEntryDourationPeriod, $this->moduleLangVar . '_DISPLAYDURATION_SHOW_PERIOD' => $intEntryDourationShowPeriod, 'TXT_' . $this->moduleLangVar . '_TRANSLATION_STATUS' => $_ARRAYLANG['TXT_MEDIADIR_TRANSLATION_STATUS'], 'TXT_' . $this->moduleLangVar . '_ENTRY_STATUS' => $_ARRAYLANG['TXT_MEDIADIR_ACTIVE'])); } else { \Cx\Core\Csrf\Controller\Csrf::header("Location: index.php?cmd=" . $this->moduleName . "&act=settings&tpl=forms"); exit; } }