<?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)
 *
 */

  /*===================================================
    ShowFormConfigInvoice()
  ===================================================*/

  function ShowFormConfigInvoice() {

    // vars global configuration
    global $dbConn, $admin_template_path;

    // vars url & form

    // vars messages

    // vars template
    global $company, $contact, $address, $phone, $email, $currency_symbol,
             $currency_code, $ps;

    $query = "select * from idx_invoice_config";
    $result = $dbConn->Execute($query);

    $company = $result->Fields('company');
    $contact = $result->Fields('contact');
    $address = $result->Fields('address');
    $phone = $result->Fields('phone');
    $email = $result->Fields('email');
    $currency_symbol = $result->Fields('currency_symbol');
    $currency_code = $result->Fields('currency_code');

    // display payment
    $ps = GetPaymentSystems('raw');

    DisplayTemplate($admin_template_path . "inv_config_form.html",
      "\$company,\$contact,\$address,\$phone,\$email,\$currency_symbol,".
      "\$currency_code,\$ps");
  }


  /*===================================================
    ProcessFormConfigInvoice()
  ===================================================*/

  function ProcessFormConfigInvoice() {

    // vars global configuration
    global $dbConn, $admin_template_path;

    // vars url & form
    global $company, $contact, $address, $phone, $email, $currency_symbol,
             $currency_code;

    // vars messages
    global $msg;

    // vars template
    global $message, $back;

    // verify input

    if(empty($company)) $error_msg = $msg['20466'];
    elseif(empty($contact)) $error_msg = $msg['20467'];
    elseif(empty($email)) $error_msg = $msg["20154"];
    elseif(!IsEmailAddress($email)) $error_msg = $msg["20155"];
    elseif(empty($address)) $error_msg = $msg['20468'];
    elseif(empty($currency_symbol)) $error_msg = $msg['20469'];
    elseif(empty($currency_code)) $error_msg = $msg['20470'];

    if(empty($error_msg)) {
      // create invoice
      $query = "update idx_invoice_config set
        company = '$company',
        contact = '$contact',
        address = '$address',
        phone = '$phone',
        email = '$email',
        currency_symbol = '$currency_symbol',
        currency_code = '$currency_code'
      ";
      $result = $dbConn->Execute($query);
      $message = $msg['20487'];
    }
    else {
      $message = $error_msg;
    }

    $back = "<a href=inv_config.php>Back</a>";

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


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

  include "../application.php";

  RunPreFilter(__FILE__);

  DisplayTemplate($admin_template_path . "header.html");
  if (empty($pflag)) {
    ShowFormConfigInvoice();
  }
  elseif ($pflag == 'config') {
    ProcessFormConfigInvoice();
  }
  DisplayTemplate($admin_template_path . "footer.html");

  RunPostFilter(__FILE__);

?>