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

  /*===================================================
    ShowFormAddTemplate()
  ===================================================*/

  function ShowFormAddTemplate() {

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

    // vars url & form
    global $theme;

    // vars messages

    // vars template
    global $file_content;

    $file2 = $theme_path . $theme . "/custom_page_template.html";
    $file_content = chop(file_get_contents($file2));
    $file_content = htmlspecialchars($file_content);

    DisplayTemplate($admin_template_path . "template_add_custom_form.html",
      "\$theme,\$file_content");
  }


  /*===================================================
    ProcessFormAddTemplate()
  ===================================================*/

  function ProcessFormAddTemplate() {

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

    // vars url & form
    global $theme, $file, $file_content, $submit;

    // vars messages
    global $msg;

    // vars template
    global $message;
    
    $file = $theme_path . $theme . "/" . $file;

    $content = revers_htmlspecialchars($file_content);
    $content = stripslashes($content);
    $content = str_replace("\r","",$content);

    $fp = fopen($file, 'w+');
    fwrite($fp,$content);

    $message = $msg["20421"];

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


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

  include "../application.php";

  RunPreFilter(__FILE__);

  DisplayTemplate($admin_template_path . "header.html");
  if (empty($pflag)) {
    ShowFormAddTemplate();
  }
  elseif ($pflag == 'modify') {
    ProcessFormAddTemplate();
  }
  DisplayTemplate($admin_template_path . "footer.html");

  RunPostFilter(__FILE__);

?>