/**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = CallMeMessages::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'product_id' => $this->product_id, 'reg_date' => $this->reg_date]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'tel', $this->tel])->andFilterWhere(['like', 'email', $this->email])->andFilterWhere(['like', 'inn', $this->inn])->andFilterWhere(['like', 'city', $this->city])->andFilterWhere(['like', 'comment', $this->comment]);
     return $dataProvider;
 }
 public function actionAdd_call_me_message($name, $email, $tel, $product_id, $inn, $gorod, $comment)
 {
     $mail = EmailTo::findOne(['id' => 1]);
     $functions = new Functions();
     $tovar = Products::findOne(['id' => $product_id]);
     $model = new CallMeMessages();
     $model->name = $name;
     $model->email = empty($email) ? '' : $email;
     $model->tel = $tel;
     $model->product_id = $product_id;
     $model->inn = $inn;
     $model->city = $gorod;
     $model->comment = $comment;
     if ($model->save()) {
         $to = $mail->email_to;
         $subject = "Новый запрос договора поставки";
         $message = '
             <html>
                 <head>
                     <title>Поступила новая заявка на запрос договора поставки!</title>
                 </head>
                 <body>
                     <p>Только что поступила новая заявка на запрос договора поставки!</p>
                     <p>Имя:' . $name . '</p>
                     <p>Телефон:' . (empty($tel) ? 'не указано' : $tel) . '</p>
                     <p>Email:' . (empty($email) ? 'не указано' : $email) . '</p>
                     <p>ИНН:' . (empty($inn) ? 'не указано' : $inn) . '</p>
                     <p>Город:' . (empty($gorod) ? 'не указано' : $gorod) . '</p>
                     <p>Комментарий:' . (empty($comment) ? 'не указано' : $comment) . '</p>
                     <p>Товар:<a href="' . $functions->get_tovar_url($product_id) . '">' . $tovar->name . '</a></p>
                 </body>
             </html>';
         $headers = "Content-type: text/html; charset=windows-utf-8 \r\n";
         $headers .= "From: TEST\r\n";
         $headers .= "Bcc:TEST1\r\n";
         mail($to, $subject, $message, $headers);
         return 'success';
     }
     return false;
 }
 /**
  * Finds the CallMeMessages model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return CallMeMessages the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = CallMeMessages::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }