예제 #1
0
 /**
  * handle Ajax call for sending a report on a post
  */
 public function actionSendReport()
 {
     $json = array();
     if (isset(\Yii::$app->request->post()['BbiiMessage'])) {
         $model = new BbiiMessage();
         $model->load(\Yii::$app->request->post()['BbiiMessage']);
         $model->subject = Yii::t('BbiiModule.bbii', 'Post reported: ') . BbiiPost::find($model->post_id)->subject;
         $model->sendto = 0;
         $model->sendfrom = \Yii::$app->user->identity->id;
         $model->outbox = 0;
         $model->type = 2;
         if ($model->save()) {
             $json['success'] = 'yes';
             $json['message'] = Yii::t('BbiiModule.bbii', 'Thank you for your report.');
         } else {
             $json['success'] = 'no';
             $json['message'] = Yii::t('BbiiModule.bbii', 'Could not register your report.');
         }
     }
     echo json_encode($json);
     \Yii::$app->end();
 }
예제 #2
0
 public function actionSendmail()
 {
     $model = new MailForm();
     // $model->unsetAttributes();
     if (isset(\Yii::$app->request->post()['MailForm'])) {
         $model->load(\Yii::$app->request->post()['MailForm']);
         if (empty($model->member_id)) {
             $model->member_id = -1;
             // All members
         }
         if ($model->validate()) {
             $members = $model->member_id >= 0 ? BbiiMember::find()->where(['group_id' => $model->member_id])->all() : BbiiMember::findAll();
             if (isset(\Yii::$app->request->post()['email'])) {
                 // e-mails
                 $name = $this->context->module->forumTitle;
                 $name = ' = ?UTF-8?B?' . base64_encode($name) . '? = ';
                 $from = BbiiSetting::find()->find()->contact_email;
                 $subject = ' = ?UTF-8?B?' . base64_encode($model->subject) . '? = ';
                 $headers = "From: {$name} <{$from}>\r\n" . "Reply-To: {$from}\r\n" . "MIME-Version: 1.0\r\n" . "Content-type: text/html; charset = UTF-8";
                 $users = array();
                 $class = new $this->module->userClass();
                 foreach ($members as $member) {
                     $sendto = $member->member_name . " <{$to}>";
                     $to = $user->getAttribute($this->module->userMailColumn);
                     $user = $class::find()->where([$this->module->userIdColumn => $member->id])->all();
                     mail($sendto, $subject, $model->body, $headers);
                     $users[] = $member->member_name;
                 }
                 // $model->unsetAttributes();
                 \Yii::$app->session->addFlash('success', Yii::t('BbiiModule.bbii', 'You have sent an e-mail to the following users: ') . implode(', ', $users));
             } else {
                 // private messages
                 $users = array();
                 foreach ($members as $member) {
                     $message = new BbiiMessage();
                     $message->sendfrom = \Yii::$app->user->identity->id;
                     $message->sendto = $member->id;
                     $message->subject = $model->subject;
                     $message->content = $model->body;
                     $message->outbox = 0;
                     if ($message->save()) {
                         $users[] = $member->member_name;
                     }
                 }
                 // $model->unsetAttributes();
                 \Yii::$app->session->addFlash('success', Yii::t('BbiiModule.bbii', 'You have sent a private message to the following users: ') . implode(', ', $users));
             }
         }
     }
     return $this->render('sendmail', array('model' => $model));
 }