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

  /*===================================================
    ShowFormCreateMessage()
  ===================================================*/

  function ShowFormCreateMessage() {

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

    // vars url & form
    global $cat;

    // vars messages
    global $msg;

    // vars template
    global $webmaster_fields;

    $links_obj             = new clsLink;
    $links_obj->table_name = "idx_link";
    $fields = $links_obj->GetFields();
    $webmaster_fields = array();
    while (list($k, $v) = @each($fields)) {
      $webmaster_fields[] = "&lt;%$v%&gt;";
    }
    $webmaster_fields = implode(", ", $webmaster_fields);

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


  /*===================================================
    ProcessFormCreateMessage()
  ===================================================*/

  function ProcessFormCreateMessage() {

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

    // vars url & form
    global $subject, $body;

    // vars messages
    global $msg;

    // vars template
    global $message;

    // verify input

    if(empty($subject)) $error_msg = $msg["20271"];
    elseif(empty($body)) $error_msg = $msg["20272"];

    if(empty($error_msg)) {

      $ml_obj = new clsMailingList;
        $ml_obj->table_name = "idx_mailing_list";
      $ml_obj->message_table_name = "idx_message";
      $ml_obj->CreateMessage($subject,$body);

      $message = $msg["20281"];
    }
    else $message = $error_msg;

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


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

  include "../application.php";

  RunPreFilter(__FILE__);

  DisplayTemplate($admin_template_path . "header.html");
  if (empty($pflag)) {
    ShowFormCreateMessage();
  }
  elseif ($pflag == 'create') {
    ProcessFormCreateMessage();
  }
  DisplayTemplate($admin_template_path . "footer.html");

  RunPostFilter(__FILE__);

?>