namespace app\controllers;
+use Yii;
+use yii\data\ActiveDataProvider;
use yii_app\records\MarketplaceFlowwowEmails;
use yii_app\records\MarketplaceFlowwowEmailsSearch;
use yii\web\Controller;
]);
}
+ public function actionDecodeBodies()
+ {
+ if (Yii::$app->request->isPost) {
+ $emails = MarketplaceFlowwowEmails::find()->all();
+ foreach ($emails as $email) {
+ $decoded = quoted_printable_decode($email->body);
+ if ($email->body !== $decoded) {
+ $email->body = $decoded;
+ $email->save(false, ['body']);
+ }
+ }
+ Yii::$app->session->setFlash('success', 'Декодирование завершено');
+ return $this->refresh();
+ }
+
+ $dataProvider = new ActiveDataProvider([
+ 'query' => MarketplaceFlowwowEmails::find()->orderBy(['id' => SORT_DESC]),
+ 'pagination' => ['pageSize' => 20],
+ ]);
+
+ return $this->render('decode-bodies', [
+ 'dataProvider' => $dataProvider,
+ ]);
+ }
+
+
+ public function actionViewBody($id)
+ {
+ $model = MarketplaceFlowwowEmails::findOne($id);
+ if (!$model) {
+ throw new NotFoundHttpException('Письмо не найдено');
+ }
+
+ $decodedBody = quoted_printable_decode($model->body);
+
+ return $this->render('view-body', [
+ 'model' => $model,
+ 'body' => $decodedBody,
+ ]);
+ }
+
/**
* Creates a new MarketplaceFlowwowEmails model.
* If creation is successful, the browser will be redirected to the 'view' page.
'from' => $from,
'to' => $to,
'date' => $date,
- 'body' => $htmlMessage,
+ 'body' => quoted_printable_decode($htmlMessage),
];
$output = MarketplaceService::processMessage($message);
--- /dev/null
+<?php
+
+use yii\helpers\Html;
+use yii\grid\GridView;
+
+/** @var $dataProvider yii\data\ActiveDataProvider */
+
+$this->title = 'Декодирование писем Flowwow';
+$this->params['breadcrumbs'][] = $this->title;
+?>
+<div class="marketplace-flowwow-emails-decode p-4">
+ <h1><?= Html::encode($this->title) ?></h1>
+
+ <?php if (Yii::$app->session->hasFlash('success')): ?>
+ <div class="alert alert-success"><?= Yii::$app->session->getFlash('success') ?></div>
+ <?php endif; ?>
+
+ <p>
+ <?= Html::a('Назад к письмам', ['/marketplace-flowwow-emails/index'], ['class' => 'btn btn-primary my-4']) ?>
+ <?= Html::beginForm(['decode-bodies'], 'post') ?>
+ <?= Html::submitButton('Декодировать все письма', ['class' => 'btn btn-primary', 'data-confirm' => 'Вы уверены? Будет перезаписано тело писем!']) ?>
+ <?= Html::endForm() ?>
+ </p>
+
+ <h3>Последние письма:</h3>
+ <?= GridView::widget([
+ 'dataProvider' => $dataProvider,
+ 'columns' => [
+ 'id',
+ 'subject',
+ 'from',
+ 'to',
+ 'date',
+ [
+ 'label' => 'Действия',
+ 'format' => 'raw',
+ 'value' => function($model) {
+ return Html::a('Просмотр', ['view-body', 'id' => $model->id], ['target' => '_blank', 'class' => 'btn btn-xs btn-success']);
+ }
+ ],
+ ],
+ ]) ?>
+</div>
<div class="marketplace-flowwow-emails-index p-4">
<?= Html::a('к Заказам', ['/marketplace-orders/index'], ['class' => 'btn btn-primary my-4']) ?>
- <h1><?= Html::encode($this->title) ?></h1>
+ <?= Html::a('Декодировать', ['/marketplace-flowwow-emails/decode-bodies'], ['class' => 'btn btn-primary my-4']) ?>
+ <h1><?= Html::encode($this->title) ?></h1>
'from',
'to',
'date',
- //'body:ntext',
+ [
+ 'label' => 'Просмотр письма',
+ 'format' => 'raw',
+ 'value' => function($model) {
+ return Html::a('Просмотр', ['view-body', 'id' => $model->id], ['target' => '_blank', 'class' => 'btn btn-xs btn-success']);
+ }
+ ],
'created_at',
[
'template' => '{view}',
--- /dev/null
+<?php
+
+use yii\helpers\Html;
+
+/** @var $model app\models\MarketplaceFlowwowEmails */
+/** @var $body string */
+
+$this->title = 'Просмотр тела письма: ' . $model->subject;
+$this->params['breadcrumbs'][] = ['label' => 'Декодирование писем', 'url' => ['decode-bodies']];
+$this->params['breadcrumbs'][] = $this->title;
+
+?>
+<div class="marketplace-flowwow-emails-view-body p-4">
+ <h1><?= Html::encode($this->title) ?></h1>
+ <div>
+ <?= Html::a('Назад', ['decode-bodies'], ['class' => 'btn btn-primary']) ?>
+ </div>
+ <hr>
+ <iframe srcdoc="<?= htmlspecialchars($body) ?>" width="100%" height="800" frameborder="0" style="background:#fff"></iframe>
+
+</div>