Blame view

common/models/Emails.php 5.35 KB
da8366ac   Administrator   upload project
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
  <?php
  
  namespace common\models;
  
  use Yii;
  
  /**
   * This is the model class for table "w_emails".
   *
   * @property integer $id
   * @property string $code
   * @property string $name
   * @property string $value
   * @property string $to_email
   * @property string $from_email
   * @property string $from_name
   * @property integer $done
   * @property string $who_comment
   */
  class Emails extends \yii\db\ActiveRecord
  {
      /**
       * @inheritdoc
       */
      public static function tableName()
      {
          return 'w_emails';
      }
  
      /**
       * @inheritdoc
       */
      public function rules()
      {
          return [
              [['code', 'name', 'value'], 'required'],
              [['value'], 'string'],
              [['done'], 'integer'],
              [['code', 'name'], 'string', 'max' => 254],
              [['to_email', 'from_email', 'from_name'], 'string', 'max' => 200],
              [['who_comment'], 'string', 'max' => 50],
              [['code'], 'unique']
          ];
      }
  
      /**
       * @inheritdoc
       */
      public function attributeLabels()
      {
          return [
              'id' => 'ID',
              'code' => 'Code',
              'name' => 'Name',
              'value' => 'Value',
              'to_email' => 'To Email',
              'from_email' => 'From Email',
              'from_name' => 'From Name',
              'done' => 'Done',
              'who_comment' => 'Who Comment',
          ];
      }
b77421d2   Administrator   VItaliy 26.11.2015
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
  
  
      public static function header() {
  
  
          $office = Offices::findOne(1);
  
  
          $phones = explode(";",$office['phones']);
  
          $output = "<div style='width:100%; border-bottom: 2px solid #7389b4; font-family: Helvetica-Light;'>
  				<div style='float:left'>
  					<img src='http://".$_SERVER['HTTP_HOST']."/storage/media/files/settings/inside-placeholder-logo2.png' />
  				</div>
  				<div style='float:right'>
  					<div>
  						<div style='width:220px;'>";
          foreach ($phones as &$el) {
              $output .= "
  				<div style='float:left; height: 7px;'>
  					<img src='http://".$_SERVER['HTTP_HOST']."/storage/media-templates/img/phone.png' />
  				</div>
  				<div style='text-align:right; color:#7389b4'>
  					".$el."
  				</div>
  				<div style='clear:both'>&nbsp;</div>";
          }
          $output .= "				<div style='float:left; height: 7px;'>
  								<img src='http://".$_SERVER['HTTP_HOST']."/storage/media-templates/img/address.png' />
  							</div>
  							<div style='text-align:right'>".$office['address']."</div>
  							<div style='clear:both'>&nbsp;</div>
  							<div style='float:left; height: 7px;'>
  								<img src='http://".$_SERVER['HTTP_HOST']."/storage/media-templates/img/email.png' />
  							</div>
  							<div style='text-align:right'>".$office['email']."</div>
  							<div style='clear:both'>&nbsp;</div>
  						</div>
  					</div>
  					<div style='clear:both'>&nbsp;</div>
  				</div>
  				<div style='clear:both'>&nbsp;</div>
  			</div>";
  
          return $output;
      }
  
      public static function get($code,$vars,$to = '',$from = '',$from_name = '',$captcha=false)
      {
          $model = new Emails();
          $data = $model->findOne(['code'=>$code]);
  
          //$letter = $data['value'];
          $subject = $data['name'];
          if ($data['value'] == '') {
              return false;
          }
          if ($from == '') {
              $from = $data['from_email'];
          }
          if ($from_name == '') {
              $from_name = $data['from_name'];
          }
          /*if ($to == '') {
              $to = $data['to_email'];
          }*/
          if ($data['to_email'] != '') {
              $to = $data['to_email'];
          }
  
          $letter = Emails::header().$data['value'];
  
  
          if ($code == 'cart_client') {
              $subject = "Заказ №".$vars['order_numer']." - ".date("d.m.Y").", ".date("H:i");
          }
          else if ($code == 'cart_manager') {
              $subject = $vars['name']." (№".$vars['order_numer'].") - ".date("d.m.Y").", ".date("H:i");
          }
  
          foreach ($vars as $kk=>$vv) {
              $str = '{'.$kk.'}';
              $letter = str_replace($str,$vv,$letter);
          }
  
          $letter = str_replace(array("../../../"),"http://".$_SERVER['SERVER_NAME']."/",$letter);
  
          $mail = new \PHPMailer();
c4db9709   Administrator   VItaliy 27.11.2015
151
          $mail->CharSet = "UTF-8";
b77421d2   Administrator   VItaliy 26.11.2015
152
          $mail->From     = $from;
c4db9709   Administrator   VItaliy 27.11.2015
153
154
          $mail->FromName =$from_name;
          $mail->Subject  =$subject;
b77421d2   Administrator   VItaliy 26.11.2015
155
156
157
158
          $mail->MsgHTML($letter);
          $fp = fopen("Emails_log.txt","w");
          fwrite($fp, $letter);
          fclose($fp);
c4db9709   Administrator   VItaliy 27.11.2015
159
160
161
162
163
164
165
166
167
168
169
          $mail->AddAddress($to);
  //        $splitEmails = explode(",",$to);
  //        if (count($splitEmails)>1){
  //            foreach ($splitEmails as $sEmail){
  //                $mail->AddAddress($sEmail);
  //
  //            }
  //
  //        } else {
  //            $mail->AddAddress($to);
  //        }
b77421d2   Administrator   VItaliy 26.11.2015
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
  
          if ($captcha){
              if (md5($vars['code'])==$_SESSION['captcha_keystring']) {
                  if ($mail->Send()){
                      $mail->ClearAddresses();
                      $_SESSION['sendC'] = 1;
                      return true;
                  }
                  else
                      return false;
              }
              else {
                  $_SESSION['error_data'] = $vars;
                  $_SESSION['sendC'] = 2;
                  return false;
              }
          }
          else {
              if ($mail->Send()){
                  $mail->ClearAddresses();
                  $_SESSION['sendC'] = 1;
                  return true;
              }
              else
                  return false;
          }
      }
da8366ac   Administrator   upload project
197
  }