<?php

/**
 *
 * INDEXU
 * Copyright(C), Nicecoder, 2000-2006, All Rights Reserved.
 *
 * INDEXU(tm) is protected by Indonesia and International copyright laws.
 * Unauthorized use or distribution of INDEXU(tm) is strictly prohibited,
 * violators will be prosecuted. To obtain a license for using INDEXU(tm),
 * please register at Nicecoder home page at http://www.nicecoder.com
 *
 * Author:
 *    Dody Rachmat Wicaksono (dody@nicecoder.com)
 *    M. Zuber (zubby@nicecoder.com)
 *
 */

  /*===================================================
    SendInvoice()
  ===================================================*/

  function SendInvoice() {

    // vars global configuration
    global $dbConn, $admin_template_path, $site_url, $theme_path, $active_theme;

    // vars url & form
    global $id;

    // vars messages
    global $msg;

    // vars template
    global $message, $invoice_id, $email;

    $invoice_id = $id;

    $theme_path = $theme_path . $active_theme;

    // get config
    $query = "select * from idx_invoice_config";
    $result = $dbConn->execute($query);
    $company = $result->Fields('company');
    $company_email = $result->Fields('email');

    // get email
    $query = "select email from idx_invoice where invoice_id = '$id'";
    $result = $dbConn->execute($query);
    $email = $result->Fields('email');


    // send email
    $body = EvalTemplate($theme_path . "/mail/inv_ask_payment.mail",
        "\$invoice_id,\$site_url");
    $subject = "$company, Invoice #$invoice_id";
    mail("$email",$subject,$body,
          "From: $company_email\nX-Mailer: INDEXU_X-Mailer/1.0");

    $message = $msg['20483'];

    DisplayTemplate($admin_template_path . "message.html", "\$message");
  }


  /*===================================================
    main
  ===================================================*/

  include "../application.php";
  
  RunPreFilter(__FILE__);

  DisplayTemplate($admin_template_path . "header.html");
  SendInvoice();
  DisplayTemplate($admin_template_path . "footer.html");

  RunPostFilter(__FILE__);

?>