Ejemplo n.º 1
0
 /**
  * Method to send the email
  * @param $idinvoice -- INT
  * @param $idcontact -- INT
  * @param $iduser -- INT
  * @param $recurrent -- Boolean
  */
 function sendInvoiceByEmail($idinvoice, $idcontact, $iduser, $recurrent = false)
 {
     $do_contact = new Contact();
     $do_user_rel = new UserRelations();
     $this->getId($idinvoice);
     if ($recurrent === true) {
         $this->sessionPersistent("do_invoice", "index.php", OFUZ_TTL);
     }
     $do_contact->getId($idcontact);
     $contact_name = $do_contact->firstname . ' ' . $do_contact->lastname;
     $do_contact_email = $do_contact->getChildContactEmail();
     $contact_email = $do_contact_email->getDefaultEmail();
     $do_user_detail = new User();
     $do_user_detail->getId($iduser);
     if ($contact_email) {
         $total_due = $this->amt_due;
         $total_due = $this->viewAmount($total_due);
         if ($recurrent) {
             $do_rec_invoice = new RecurrentInvoice();
             $idrec = $do_rec_invoice->checkIfInvoiceIsInRecurrent($idinvoice);
             if ($idrec) {
                 $email_template = new EmailTemplate("ofuz_send_recurrent_invoice");
                 $do_rec_invoice->getId($idrec);
                 $next_due_date = $do_rec_invoice->nextdate;
                 $recurrence = $do_rec_invoice->recurrence;
                 $recurrence_type = $do_rec_invoice->recurrence_type;
             } else {
                 $email_template = new EmailTemplate("ofuz_send_invoice");
             }
         } else {
             $email_template = new EmailTemplate("ofuz_send_invoice");
         }
         if ($this->status == 'Quote') {
             $email_template = new EmailTemplate("ofuz_send_quote");
         }
         $email_template->setSenderName($do_user_detail->getFullName());
         $email_template->setSenderEmail($do_user_detail->email);
         $signature = $do_user_detail->company . '<br />' . $do_user_detail->getFullName();
         $description = $this->description;
         $invoice_url = $GLOBALS['cfg_ofuz_site_https_base'] . 'inv/' . $do_user_rel->encrypt($idinvoice) . '/' . $do_user_rel->encrypt($idcontact);
         $email_data = array('name' => $contact_name, 'sender' => $do_user_detail->getFullName(), 'company' => $do_user_detail->company, 'description' => $description, 'invoice_url' => $invoice_url, 'num' => $this->num, 'signature' => $signature, 'amount' => $total_due, 'recurrence' => $recurrence, 'recurrence_type' => $recurrence_type, 'next_due_date' => $next_due_date);
         $emailer = new Radria_Emailer();
         $emailer->setEmailTemplate($email_template);
         $emailer->mergeArray($email_data);
         $emailer->addTo($contact_email);
         //attachment starts
         // Some bug in the PDF part it does not send the correct PDF as it says due amt is 0. Happens for the cron to send recurrent inv
         //echo '<br />Calling Method generatePDFInvoice().....<br />';
         // This is fixed
         $this->generatePDFInvoice($invoice_url);
         $fpdf_file_name = $this->getEncryptedFileName("pdf");
         $pdfFilePath = "invoice_pdf/{$fpdf_file_name}";
         $pdfFile = file_get_contents($pdfFilePath);
         $at = $emailer->createAttachment($pdfFile);
         $at->type = 'image/pdf';
         $at->disposition = Zend_Mime::DISPOSITION_INLINE;
         $at->encoding = Zend_Mime::ENCODING_BASE64;
         $at->filename = $fpdf_file_name;
         //attachment ends
         $emailer->send();
         if ($this->status == 'New') {
             $this->status = 'Sent';
             $this->update();
         }
         if ($recurrent) {
             $q = new sqlQuery($this->getDbCon());
             $q->query("update invoice set status = 'Sent' where idinvoice = " . $idinvoice . " Limit 1");
             $q->free();
         }
         $_SESSION['in_page_message'] = "client_invoice_sent";
         $_SESSION['in_page_message_data']['contact_email'] = $contact_email;
     } else {
         $_SESSION['in_page_message'] = "invoice_client_email_not_found";
     }
     $do_user_detail->free();
 }
Ejemplo n.º 2
0
    $fh = fopen($file_path, 'w') or die("can't open file");
    fwrite($fh, $vcard);
    fclose($fh);
    $do_template = new EmailTemplate();
    $do_template->setSenderName("Ofuz.net");
    $do_template->setSenderEmail("*****@*****.**");
    $do_template->setSubject("Contact ::" . $_SESSION['do_contact']->lastname . " " . $_SESSION['do_contact']->firstname);
    //$do_template->setMessage("You have received a contact");
    $do_template->bodytext = "You have received a contact";
    $do_template->bodyhtml = nl2br($do_template->bodytext);
    $emailer = new Radria_Emailer();
    $emailer->setEmailTemplate($do_template);
    $emailer->mergeArray($email_data);
    $emailer->addTo($email_mbl);
    $vcf_file = file_get_contents($file_path);
    $at = $emailer->createAttachment($vcf_file);
    $at->type = 'text/x-vcard';
    //$at->disposition = Zend_Mime::DISPOSITION_INLINE;
    $at->encoding = Zend_Mime::ENCODING_BASE64;
    $at->filename = $file_name . '.vcf';
    try {
        $emailer->send();
        echo _('<b>Contact is sent.</b>');
        echo '<br /><a href="/profile/' . $_SESSION['public_profile_name'] . '">' . _('Go Back') . '</a>';
    } catch (Exception $e) {
        echo _('<b>Error Sending Email, Please try again.</b>');
        echo '<br />';
        echo '<br /><a href="/profile/' . $_SESSION['public_profile_name'] . '">' . _('Go Back') . '</a>';
    }
} else {
    header("Content-type: text/x-vcard");