Exemplo n.º 1
0
 public function onSendMail($sender, $param)
 {
     $mailer = new TMailer();
     $mailer->setObject($this->object->SafeText);
     $mailer->setBody($this->Body->Text);
     $recipient = array();
     if ($this->send_groups->getChecked()) {
         $indices = $this->groups->SelectedIndices;
         $result = '';
         foreach ($indices as $index) {
             $item = $this->groups->Items[$index];
             $cmd = $this->db->createCommand("SELECT u.id, email1, email2  FROM hr_user AS u LEFT JOIN hr_user_group_attribution AS uga ON uga.id_user=u.id  WHERE uga.id_group=" . $item->Value);
             $query = $cmd->query();
             $data = $query->readAll();
             foreach ($data as $d) {
                 if ($d['email1'] != '') {
                     $recipient[$d['id']] = $d['email1'];
                 } elseif ($d['email2'] != '') {
                     $recipient[$d['id']] = $d['email2'];
                 }
             }
         }
     }
     if ($this->send_users->getChecked()) {
         $indices = $this->users->SelectedIndices;
         $result = '';
         foreach ($indices as $index) {
             $item = $this->users->Items[$index];
             $cmd = $this->db->createCommand("SELECT email1, email2  FROM hr_user WHERE id=" . $item->Value);
             $query = $cmd->query();
             $data = $query->read();
             if ($data['email1'] != '') {
                 $recipient[$item->Value] = $data['email1'];
             } elseif ($data['email2'] != '') {
                 $recipient[$item->Value] = $data['email2'];
             }
         }
     }
     foreach ($recipient as $r) {
         $mailer->addRecipient($r);
     }
     if ($this->attachment->HasFile) {
         $this->attachment->saveAs('.' . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR . $this->attachment->FileName);
         $mailer->addAttachment('.' . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR . $this->attachment->FileName, $this->attachment->FileName);
     }
     $res = $mailer->sendHtmlMail($this->mailing->getChecked());
     if ($this->attachment->HasFile) {
         unlink('.' . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR . $this->attachment->FileName);
     }
     if ($res) {
         $pBack = array('okMsg' => Prado::localize('The mail was delivered successfully'));
         $this->Response->redirect($this->Service->constructUrl('components.easymailing.easymailing', $pBack));
     } else {
         $pBack = array('koMsg' => Prado::localize('The mail was not delivered successfully'));
         $this->Response->redirect($this->Service->constructUrl('components.easymailing.easymailing', $pBack));
     }
 }