Esempio n. 1
0
 /**
  * method onSave()
  * Executed whenever the user clicks at the save button
  */
 function onSave()
 {
     try {
         // open a transaction with database 'changeman'
         TTransaction::open('changeman');
         // get the form data into an active record Note
         $object = $this->form->getData('Note');
         $logged = Member::newFromLogin(TSession::getValue('login'));
         $object->id_user = $logged->id;
         $object->register_date = date('Y-m-d');
         $object->register_time = date('H:i');
         // form validation
         $this->form->validate();
         // stores the object
         $object->store();
         $issue = new Issue($object->id_issue);
         $project = new Project($issue->id_project);
         $member = new Member($issue->id_user);
         // who has opened the issue
         // read email configuration file
         $ini = parse_ini_file('app/config/email.ini');
         $members = $project->getMembers(array('MEMBER', 'MANAGER'));
         $members = array_merge($members, array($member));
         // merge the logged user
         $mail_template = file_get_contents('app/resources/note.html');
         $mail_template = str_replace('{DESCRIPTION}', $issue->description, $mail_template);
         $mail_template = str_replace('{OPENER}', $member->name . ' ' . $issue->register_date . ' ' . $issue->issue_time, $mail_template);
         $mail_template = str_replace('{NOTE}', $object->note, $mail_template);
         $mail_template = str_replace('{MEMBER}', $logged->name . ' ' . $object->register_date . ' ' . $object->register_time, $mail_template);
         $mail = new TMail();
         $mail->setFrom($ini['from'], $ini['name']);
         $mail->setSubject(_t('Note') . ' #' . $issue->id . ': ' . $issue->title);
         $mail->setHtmlBody($mail_template);
         foreach ($members as $member) {
             $emails = explode(',', $member->email);
             foreach ($emails as $email) {
                 $mail->addAddress(trim($email), $member->name);
                 // echo "{$email}, {$member-> name} <br>";
             }
         }
         $mail->SetUseSmtp();
         $mail->SetSmtpHost($ini['host'], $ini['port']);
         $mail->SetSmtpUser($ini['user'], $ini['pass']);
         $mail->setReplyTo($ini['repl']);
         $mail->send();
         // fill the form with the active record data
         $this->form->setData($object);
         // close the transaction
         TTransaction::close();
         // shows the success message
         new TMessage('info', TAdiantiCoreTranslator::translate('Record saved'));
         // reload the listing
     } catch (Exception $e) {
         // shows the exception error message
         new TMessage('error', '<b>Error</b> ' . $e->getMessage());
         // undo all pending operations
         TTransaction::rollback();
     }
 }
 public function onEnviaEmail()
 {
     try {
         TTransaction::open('atividade');
         $object = $this->form->getData('Ticket');
         $vars['tipo_origens'] = $object->tipo_origens;
         $vars['codigo_cadastro_origem'] = $object->codigo_cadastro_origem;
         $vars['solicitante_id'] = $object->solicitante_id;
         $this->onChangeOrigem($vars);
         $this->onChangeTipoOrigem($vars);
         $this->onSetarValoresCombo($vars);
         $status = $object->status_ticket->nome;
         $solicitante = new Pessoa($object->solicitante_id);
         $cliente = $solicitante->pessoa_nome;
         $email1 = $solicitante->email1;
         $empresa = $solicitante->origem_nome;
         $responsavel = new Pessoa($object->responsavel_id);
         $colaborador = $responsavel->pessoa_nome;
         $email2 = $responsavel->email1;
         $table = new TTable();
         $table->border = 0;
         $table1 = new TTable();
         $table1->border = 1;
         $table2 = new TTable();
         $table2->border = 1;
         $table3 = new TTable();
         $table3->border = 1;
         $table4 = new TTable();
         $table4->border = 1;
         $imagem = new TImage('app/images/tecbiz.jpg');
         $imagem->height = 63;
         $imagem->width = 96;
         $row = $table->addRow();
         $cell = $row->addCell($imagem);
         $cell->style = 'width: 100px;';
         $cell = $row->addCell("Prezado <br /> {$cliente} do(a) {$empresa} <br /> Foi registrado um ticket com sua solicitação conforme os dados a seguir:");
         $cell->style = 'width: 700px;';
         $row = $table->addRow();
         $row->addCell('<span style="color: DarkOliveGreen;"><b><u>Inicial:</b></u></span>');
         $row = $table1->addRow();
         $cell = $row->addCell('<b>No. Ticket:</b>');
         $cell->style = 'width: 200px;';
         $cell = $row->addCell($object->id);
         $cell->style = 'width: 600px;';
         $row = $table1->addRow();
         $row->addCell('<b>Título Ticket:</b>');
         $row->addCell($object->titulo);
         $row = $table1->addRow();
         $row->addCell('<b>Data/Hora:</b>');
         $row->addCell(date('d/m/Y H:i'));
         $row = $table1->addRow();
         $row->addCell('<b>Status:</b>');
         $row->addCell($status);
         $row = $table1->addRow();
         $row->addCell('<b>Solicitante:</b>');
         $row->addCell($cliente);
         $row = $table1->addRow();
         $row->addCell('<b>Colaborador TecBiz:</b>');
         $row->addCell($colaborador);
         $row = $table->addRow();
         $cell = $row->addCell($table1);
         $cell->colspan = 2;
         $row = $table->addRow();
         $row->addCell('<span style="color: DarkOliveGreen;"><b><u>Solicitação:</b></u></span>');
         $row = $table2->addRow();
         $cell = $row->addCell('<b>Descrição:</b>');
         $cell->style = 'width: 200px;';
         $cell = $row->addCell($object->solicitacao_descricao);
         $cell->style = 'width: 520px;';
         $cell = $row->addCell($object->data_cadastro);
         $cell->style = 'width: 80px;';
         $row = $table->addRow();
         $cell = $row->addCell($table2);
         $cell->colspan = 2;
         $row = $table->addRow();
         $row->addCell('<span style="color: DarkOliveGreen;"><b><u>Orçamento:</b></u></span>');
         $row = $table3->addRow();
         $cell = $row->addCell('<b>Horas orçadas:</b>');
         $cell->style = 'width: 200px;';
         $cell = $row->addCell($object->orcamento_horas);
         $cell->style = 'width: 600px;';
         $row = $table3->addRow();
         $row->addCell('<b>Valor Hora:</b>');
         $row->addCell('R$ ' . $object->orcamento_valor_hora);
         $row = $table3->addRow();
         $row->addCell('<b>Valor Total:</b>');
         $row->addCell('R$ ' . $object->valor_total);
         $row = $table3->addRow();
         $row->addCell('<b>Forma de pagamento:</b>');
         $row->addCell($object->forma_pagamento);
         $row = $table3->addRow();
         $row = $table->addRow();
         $cell = $row->addCell($table3);
         $cell->colspan = 2;
         $row = $table4->addRow();
         $cell = $row->addCell('<span style="color: red;"><b>Importante:</b></span> Para dar seguimento a esta solicitação será necessário a aprovação da descrição e orçamento deste Ticket');
         $cell->style = 'width: 800px;';
         $row = $table->addRow();
         $cell = $row->addCell($table4);
         $cell->colspan = 2;
         TTransaction::close();
         $ini = parse_ini_file('app/config/email.ini');
         $mail = new TMail();
         $mail->setFrom($ini['from'], $ini['name']);
         $mail->setSubject('TecBiz criou um ticket para voce');
         $mail->setHtmlBody($table);
         $mail->addAddress($email1);
         $mail->addCC($email2);
         $mail->addBCC('*****@*****.**');
         // Se tiver anexo
         if (isset($target_file)) {
             $mail->addAttach($target_file);
         }
         $mail->SetUseSmtp();
         $mail->SetSmtpHost($ini['host'], $ini['port']);
         $mail->SetSmtpUser($ini['user'], $ini['pass']);
         $mail->setReplyTo($ini['repl']);
         $mail->send();
         new TMessage('info', 'Email enviado com sucesso');
     } catch (Exception $e) {
         new TMessage('error', $e->getMessage());
     }
     $this->form->setData($object);
 }
Esempio n. 3
0
 /**
  * method onSave()
  * Executed whenever the user clicks at the save button
  */
 function onSave()
 {
     try {
         // open a transaction with database 'changeman'
         TTransaction::open('changeman');
         // get the form data into an active record Release
         $object = $this->form->getData('Release');
         $sendmail = $object->sendmail == 'Y';
         unset($object->sendmail);
         // form validation
         $this->form->validate();
         // stores the object
         $object->store();
         if ($sendmail) {
             // read email configuration file
             $ini = parse_ini_file('app/config/email.ini');
             $project = new Project($object->id_project);
             $members = $project->getMembers();
             foreach ($members as $member) {
                 $emails = explode(',', $member->email);
                 foreach ($emails as $email) {
                     $mail = new TMail();
                     $mail->setFrom($ini['from'], $ini['name']);
                     $mail->setSubject(_t('Release') . ': ' . $object->name);
                     $mail->setHtmlBody($object->description);
                     $mail->addAddress(trim($email), $member->name);
                     $mail->SetUseSmtp();
                     $mail->SetSmtpHost($ini['host'], $ini['port']);
                     $mail->SetSmtpUser($ini['user'], $ini['pass']);
                     $mail->setReplyTo($ini['repl']);
                     $mail->send();
                     echo "{$email}, {$member->name}<br>";
                 }
             }
         }
         // fill the form with the active record data
         $this->form->setData($object);
         // close the transaction
         TTransaction::close();
         // shows the success message
         new TMessage('info', TAdiantiCoreTranslator::translate('Record saved'));
         // reload the listing
     } catch (Exception $e) {
         // shows the exception error message
         new TMessage('error', '<b>Error</b> ' . $e->getMessage());
         // undo all pending operations
         TTransaction::rollback();
     }
 }
 /**
  * method onSave()
  * Executed whenever the user clicks at the save button
  */
 function onSave()
 {
     try {
         // open a transaction with database 'changeman'
         TTransaction::open('changeman');
         // get the form data into an active record Issue
         $object = $this->form->getData('Issue');
         $member = Member::newFromLogin(TSession::getValue('login'));
         // standard values
         $object->id_user = $member->id;
         $object->id_status = 1;
         // NEW
         // form validation
         $this->form->validate();
         // stores the object
         $object->store();
         // have attachments
         if ($object->file) {
             $target_folder = 'attach/' . $object->id;
             $target_file = $target_folder . '/' . $object->file;
             @mkdir($target_folder);
             rename('tmp/' . $object->file, $target_file);
         }
         $project = new Project($object->id_project);
         // read email configuration file
         $ini = parse_ini_file('app/config/email.ini');
         $members = $project->getMembers(array('MEMBER', 'MANAGER'));
         $members = array_merge($members, array($member));
         // merge the logged user
         $mail_template = file_get_contents('app/resources/ticket_open.html');
         $mail_template = str_replace('{DESCRIPTION}', $object->description, $mail_template);
         $mail_template = str_replace('{OPENER}', $member->name . ' ' . $object->register_date . ' ' . $object->issue_time, $mail_template);
         $mail = new TMail();
         $mail->setFrom($ini['from'], $ini['name']);
         $mail->setSubject(_t('Issue') . ' #' . $object->id . ': ' . $object->title . ' (' . $object->status . ')');
         $mail->setHtmlBody($mail_template);
         foreach ($members as $member) {
             $emails = explode(',', $member->email);
             foreach ($emails as $email) {
                 $mail->addAddress(trim($email), $member->name);
                 // echo "{$email}, {$member-> name} <br>";
             }
         }
         if (isset($target_file)) {
             $mail->addAttach($target_file);
         }
         $mail->SetUseSmtp();
         $mail->SetSmtpHost($ini['host'], $ini['port']);
         $mail->SetSmtpUser($ini['user'], $ini['pass']);
         $mail->setReplyTo($ini['repl']);
         $mail->send();
         // fill the form with the active record data
         $this->form->setData($object);
         // close the transaction
         TTransaction::close();
         // shows the success message
         new TMessage('info', TAdiantiCoreTranslator::translate('Record saved'));
         // reload the listing
     } catch (Exception $e) {
         // shows the exception error message
         new TMessage('error', '<b>Error</b> ' . $e->getMessage() . '<br>' . _t('Try again'));
         // undo all pending operations
         TTransaction::rollback();
     }
 }