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

  /*===================================================
    SelectFile()
  ===================================================*/

  function SelectFile() {

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

    // vars url & form

    // vars messages
    global $msg;

    // vars template
    global $lang_name;

    // get language

    $handle=opendir($base_path . "lang");
    while ($file = readdir($handle)) {
      if($file[0]==".") { }
      else $lang[] = $file;
    }
    closedir($handle);

    sort($lang);

    $lang_sel = "<select name=lang_name>\n";
    $lang_sel .= "<option></option>\n";
    $i = 0;
    $count_lang = @count($lang);
    while ($i < $count_lang) {
      $lang_name = $lang[$i];
      $lang_sel .= "<option value='$lang_name'>$lang_name</option>\n";
      $i++;
    }
    $lang_sel .= "</select>";
    $lang_name = $lang_sel;

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


  /*===================================================
    ShowFormModifyTemplate()
  ===================================================*/

  function ShowFormModifyTemplate() {

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

    // vars url & form
    global $theme_name, $lang_name, $file_name;

    // vars messages

    // vars template
    global $file_content;

    $file_name = $lang_name;
    $file = $base_path . "lang/" . $file_name;
    $file_content = chop(file_get_contents($file));
    $file_content = htmlspecialchars($file_content);

    DisplayTemplate($admin_template_path . "lang_modify_form.html", "\$file_name,\$file_content");
  }


  /*===================================================
    ProcessFormModifyTemplate()
  ===================================================*/

  function ProcessFormModifyTemplate() {

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

    // vars url & form
    global $theme_name, $file_name, $file_content;

    // vars messages
    global $msg;

    // vars template
    global $message;

    $file = $base_path . "lang/" . $file_name;

    $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)) {
    SelectFile();
  }
  elseif ($pflag == 'show_form') {
    ShowFormModifyTemplate();
  }
  elseif ($pflag == 'modify') {
    ProcessFormModifyTemplate();
  }
  DisplayTemplate($admin_template_path . "footer.html");

  RunPostFilter(__FILE__);

?>