/** * Send new password to defined E-Mail. */ protected function send() { if ($crumbComponent = $this->document->componentManager->getBlockByName('breadCrumbs')) { $crumbComponent->addCrumb(); } if ($component = $this->document->componentManager->getBlockByName('textBlockRestorePassword')) { $component->disable(); } if (!isset($_POST['u_name'])) { $message = $this->translate('ERR_NO_U_NAME'); } else { $uName = $_POST['u_name']; if (!($UID = $this->dbh->getScalar('user_users', 'u_id', array('u_name' => $uName)))) { $message = $this->translate('ERR_NO_U_NAME'); } else { $password = User::generatePassword(); $this->dbh->modify(QAL::UPDATE, 'user_users', array('u_password' => password_hash($password, PASSWORD_DEFAULT)), array('u_id' => $UID)); $user = new User($UID); $template = new MailTemplate('user_restore_password', ['user_login' => $uName, 'user_name' => $user->getValue('u_fullname'), 'user_password' => $password, 'site_url' => E()->getSiteManager()->getCurrentSite()->base, 'site_name' => $this->translate('TXT_SITE_NAME')]); $mailer = new Mail(); $mailer->setFrom($this->getConfigValue('mail.from'))->setSubject($template->getSubject())->setText($template->getBody())->setHtmlText($template->getHTMLBody())->addTo($uName); $message = $this->translate('MSG_PASSWORD_SENT'); try { $mailer->send(); } catch (\Exception $e) { $message = $e->getMessage(); } } } $this->prepare(); $messageField = new Field('restore_password_result'); $messageField->setData($message); $this->getData()->addField($messageField); }
/** * Send feedback. * It stores the access to database, sends message to the user and administrator. */ protected function send() { if (!isset($_POST[$this->getTableName()])) { E()->getResponse()->redirectToCurrentSection(); } try { $data[$this->getTableName()] = $_POST[$this->getTableName()]; if (!$this->document->getUser()->isAuthenticated() && !$this->getParam('noCaptcha')) { $this->checkCaptcha(); } if ($result = $this->saveData($data)) { $data = $data[$this->getTableName()]; $senderEmail = ''; if (isset($data['feed_email'])) { $senderEmail = $data['feed_email']; } else { $data['feed_email'] = $this->translate('TXT_NO_EMAIL_ENTERED'); } $this->dbh->modify(QAL::UPDATE, $this->getTableName(), array('feed_date' => date('Y-m-d H:i:s')), array($this->getPK() => $result)); if ($senderEmail) { $template = new MailTemplate('feedback_form', $data); $mailer = new Mail(); $mailer->setFrom($this->getConfigValue('mail.from'))->setSubject($template->getSubject())->setText($template->getBody())->setHtmlText($template->getHTMLBody())->addTo($senderEmail, $senderEmail)->send(); } try { $template = new MailTemplate('feedback_form_admin', $data); $mailer = new Mail(); $recipientID = false; if (isset($data['rcp_id']) && intval($data['rcp_id'])) { $recipientID = $data['rcp_id']; } $mailer->setFrom($this->getConfigValue('mail.from'))->setSubject($template->getSubject())->setText($template->getBody())->setHtmlText($template->getHTMLBody())->addTo($this->getRecipientEmail($recipientID))->send(); } catch (\Exception $e) { } } $this->prepare(); if ($this->getParam('textBlock') && ($textBlock = $this->document->componentManager->getBlockByName($this->getParam('textBlock')))) { $textBlock->disable(); } $this->response->redirectToCurrentSection('success/'); } catch (Exception $e) { $this->failure($e->getMessage(), $data[$this->getTableName()]); } }
/** * Save data. * * @throws SystemException */ protected function saveData() { $password = $_POST[$this->getTableName()]['u_password'] = User::generatePassword(); try { $result = $this->user->create($_POST[$this->getTableName()]); $template = new MailTemplate('user_registration', ['user_login' => $this->user->getValue('u_name'), 'user_name' => $this->user->getValue('u_fullname'), 'user_password' => $password, 'site_url' => E()->getSiteManager()->getCurrentSite()->base, 'site_name' => $this->translate('TXT_SITE_NAME')]); $mailer = new Mail(); $mailer->setFrom($this->getConfigValue('mail.from')); $mailer->setSubject($template->getSubject()); $mailer->setText($template->getBody()); $mailer->setHtmlText($template->getHTMLBody()); $mailer->addTo($this->user->getValue('u_name')); $mailer->send(); } catch (\Exception $error) { throw new SystemException($error->getMessage(), SystemException::ERR_WARNING); } }
protected function processSubscription($subscription) { $this->log(sprintf('Processing subscription id=%s "%s"', $subscription['id'], $subscription['name'])); $now = new \DateTime(); $last_sent = new \DateTime(empty($subscription['sent_date']) ? '2000-01-01 00:00:00' : $subscription['sent_date']); $desired = clone $last_sent; switch ($subscription['period']) { case 'hourly': $desired->add(new \DateInterval('PT1H')); break; case 'daily': $desired->add(new \DateInterval('PT24H')); break; case 'weekly': $desired->add(new \DateInterval('PT168H')); break; case 'monthly': $desired->add(new \DateInterval('PT5040H')); break; } if ($desired > $now) { $this->log(sprintf('Processing is not required due to last sent date %s and %s period', $last_sent->format('Y-m-d H:i:s'), $subscription['period'])); } else { $this->log(sprintf('Processing is required due to last sent date %s and %s period', $last_sent->format('Y-m-d H:i:s'), $subscription['period'])); $subscribers = $this->getSubscribers($subscription['id']); if (empty($subscribers)) { $this->log('No subscribers found'); } else { $this->log(sprintf('Found %s subscribers', count($subscribers))); try { $source = MailSourceFactory::getByName($subscription['type']); $source->setLang($this->getDefaultLanguage()); $since_date = new \DateTime($subscription['sent_date'] ? $subscription['sent_date'] : '2000-00-00 00:00:00'); $items = $source->getItemsSinceDate($since_date); $this->log(sprintf('Found %s items in subscription', count($items))); foreach ($subscribers as $email => $name) { $this->log(sprintf('Sending %s mail to %s (%s)', $subscription['type'], $email, $name)); $mail = new Mail(); $subscriber = ['user_email' => $email, 'user_name' => $name]; $mail->setDebugMode(E()->getConfigValue('site.debug'))->setSubject($source->getSubject($subscriber))->setText($source->getBody($subscriber, $items))->setHtmlText($source->getHTMLBody($subscriber, $items))->setFrom(E()->getConfigValue('mail.from'))->addTo($email, $name)->send(); } $last_sent = new \DateTime(); $this->dbh->modify(QAL::UPDATE, 'mail_subscriptions', array('subscription_sent_date' => $last_sent->format('Y-m-d H:i:s')), array('subscription_id' => $subscription['id'])); } catch (\Exception $e) { $this->log('Error processing subscription: ' . (string) $e); } } } }
/** * Send. */ protected function send() { $postTableName = str_replace('.', '_', $this->getTableName()); if (!isset($_POST[$postTableName])) { E()->getResponse()->redirectToCurrentSection(); } try { $data[$this->getTableName()] = $_POST[$postTableName]; if (!$this->document->getUser()->isAuthenticated() && !$this->getParam('noCaptcha')) { $this->checkCaptcha(); } if ($result = $this->saveData($data)) { $data = $data[$this->getTableName()]; //Unset pk_id field, because we don't need it in body of message to send $data['pk_id'] = $result; foreach ($data as $key => $value) { $data[$key] = ['translation' => $this->translate('FIELD_' . $key), 'value' => $value]; if ($fd = $this->saver->getDataDescription()->getFieldDescriptionByName($key)) { if ($fd->getType() == FieldDescription::FIELD_TYPE_MULTI && is_array($keyInfo = $fd->getPropertyValue('key'))) { $m2mTableName = $keyInfo['tableName']; $m2mPKName = $keyInfo['fieldName']; //Если существует таблица связанная if ($this->dbh->tableExists($m2mTableName)) { $tableInfo = $this->dbh->getColumnsInfo($m2mTableName); unset($tableInfo[$m2mPKName]); $m2mValueFieldInfo = current($tableInfo); if (isset($m2mValueFieldInfo['key']) && is_array($m2mValueFieldInfo)) { list($values, , ) = $this->dbh->getForeignKeyData($m2mValueFieldInfo['key']['tableName'], $m2mValueFieldInfo['key']['fieldName'], E()->getLanguage()->getCurrent(), [$m2mValueFieldInfo['key']['tableName'] . '.' . $m2mValueFieldInfo['key']['fieldName'] => $value]); if (is_array($values)) { $data[$key]['value'] = implode(',', array_map(function ($row) { return $row['fk_name']; }, $values)); } } } } } } try { $mailer = new Mail(); //Get subject $subject = $this->dbh->getScalar('frm_forms_translation', 'form_name', ['form_id' => $this->formID, 'lang_id' => E()->getLanguage()->getCurrent()]); $subject = $this->translate('TXT_EMAIL_FROM_FORM') . ' ' . $subject; //Create text to send. The last one will contain: translations of variables and variables. $body = ''; // if (!($url = $this->getConfigValue('site.media'))) $url = E()->getSiteManager()->getCurrentSite()->base; foreach ($data as $fieldname => $value) { $type = $this->getDataDescription()->getFieldDescriptionByName($fieldname)->getType(); if ($type == FieldDescription::FIELD_TYPE_FILE) { $val = $url . $value['value']; } elseif ($type == FieldDescription::FIELD_TYPE_BOOL) { $val = $this->translate((int) $value['value'] === 0 ? 'TXT_NO' : 'TXT_YES'); } else { $val = $value['value']; } $body .= '<strong>' . $value['translation'] . '</strong>: ' . $val . '<br>'; } $mailer->setFrom($this->getConfigValue('mail.from'))->setSubject($subject)->setText(strip_tags($body))->setHtmlText($body)->addTo(($recp = $this->getRecipientEmail()) ? $recp : $this->getConfigValue('mail.manager'))->send(); } catch (\Exception $e) { } } //$this->prepare(); $this->response->redirectToCurrentSection('send/success/'); } catch (\Exception $e) { $this->failure($e->getMessage(), $data); } }