Exemplo n.º 1
0
 /**
  * Creates a new TbEmail model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new TbEmail();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Exemplo n.º 2
0
 public function actionTreeCreateEmail($ids = "")
 {
     if (!Yii::$app->user->can("admin")) {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
     $this->layout = "admin";
     $model = new TbEmail();
     $model->email_from = User::findIdentity(Yii::$app->user->id)->email;
     if ($ids != null || $ids != "") {
         $this->user_selected = explode(',', $ids);
         foreach (explode(',', $ids) as $id) {
             if (strpos($id, '_O') !== false) {
                 //id nay da show cac children
                 $id = substr($id, 0, -2);
                 $this->user_show_children[] = $id;
             }
             $this->getChildrenString($id);
         }
         $model->email_to = implode(",", $this->user_find_email);
     }
     if ($model->load(Yii::$app->request->post())) {
         $mails_to = explode(",", $model->email_to);
         $email_error = $this->sendEmail($model->email_from, $mails_to, $model->email_subject, $model->email_message);
         if (count($email_error) == 0) {
             Yii::$app->session->setFlash('success', 'The sending email is success.');
             $model->status = 1;
         } else {
             Yii::$app->session->setFlash('error', 'The sending email is error width ' . implode(',', $email_error));
             $model->status = 0;
         }
         $model->save();
         return $this->redirect(['email-view', 'id' => $model->id]);
     } else {
         return $this->render('email_create', ['model' => $model]);
     }
 }