_idItem) { $this->_idItem = abs(crc32(__CLASS__)); } return $this; } protected function _getMailData(array $data) { $mailData = array( 'name' => htmlspecialchars($data['name']), 'company' => htmlspecialchars($data['company']), 'email' => htmlspecialchars($data['email']), 'phone' => htmlspecialchars($data['phone']), 'comments' => nl2br(htmlspecialchars($data['comments'])), 'link' => Qs_SiteMap::findFirst(null, array('type' => 'Form_Contact_Admin_'), null, 'url') . '?action=view&id=' . $data['id'], ); if ($this->getConfig('contactReasonEnabled', true)) { $reasons = $this->_getDataObj()->getDContactReason4Select(); $mailData['reason'] = Qs_Array::get($reasons, $data['idReason']); } return $mailData; } protected function _addThankYouMessage(array &$item) { $item['isThankYouMessage'] = $this->getShowThankYou(); if ($item['isThankYouMessage']) { $item['thankYouMessage'] = $this->_getThankYouMessage(); $contactAnchor = BASE_URL . '/' . CURRENT_PAGE . '#contact-form-thanks'; $this->_doc->addInlineScript( 'goToContactHeader', 'function goToContactHeader() {document.location.replace("' . $contactAnchor . '");}'); $this->_doc->addInitFunction('goToContactHeader'); } return $this; } protected function _addFormItem(Qs_Form $form) { $item['tpl'] = $this->getTemplate('text.tpl'); $item['header'] = $this->getConfig('formHeader'); $item['text'] = $form->render(); $this->_addThankYouMessage($item); $this->_addItem($item); return $this; } protected function _getThankYouMessage() { $fullAlias = CURRENT_PAGE_FINAL . '/' . $this->_thanksPageAlias; $page = Qs_SiteMap::findFirst(array('fullAlias' => $fullAlias)); $htmlBlock = null; foreach ($page['items'] as $item) { if ($item['type'] == 'HtmlBlock_') { $htmlBlock = $item; break; } } $content = ''; if (!empty($htmlBlock)) { $htmlBlockView = new App_HtmlBlock_View($htmlBlock); $data = $htmlBlockView->getData(array('' => 1)); if (is_array($data) && array_key_exists('content', $data)) { $content = $data['content']; } } return $content; } protected function _postInsert() { $data = $this->_getDataObj()->clearData()->getData(); $this->_sendAdminNotification($data); $this->setShowThankYou(); return $this; } public function setShowThankYou() { $session = $this->_getSession(); $session->contactBlockAdminNotification = true; $session->setExpirationHops(1, 'contactBlockAdminNotification'); return $this; } /** * @return Qs_Session_Namespace */ protected function _getSession() { if (null === $this->_session) { $this->_session = new Qs_Session_Namespace(get_class($this), true); } return $this->_session; } public function getShowThankYou() { $session = $this->_getSession(); return (bool) $session->contactBlockAdminNotification; } protected function _setBackMessage($msg = null) { return true; } protected function _getNewForm(array $options = array()) { $options['hasReason'] = $this->_getDataObj()->hasReason(); $options['reasons'] = $this->_getDataObj()->getDContactReason4Select(); return parent::_getNewForm($options); } public function getSideBlockItem(array $blockData = array()) { $item = array(); $this->_initAction(); if ('insert' == $this->_action) { $this->exec(); } else { $form = $this->_getNewForm(); $form->setDefaults(); $item = array('tpl' => $this->getTemplate('text.tpl'), 'text' => $form->render(), 'isSideBlock' => true); $this->_addThankYouMessage($item); } return $item; } }