<?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, $theme;

    // vars url & form

    // vars messages
    global $msg;

    // vars template
    global $files_setting, $files_css, $files_msg, $files_pages, $files_child,
           $files_cp, $files_cp_child, $files_block, $files_email, $files_custom;
    
    include "template_data.php";

    foreach($tpl_file_setting as $k => $file) {
      $files_setting .= "<a href=template_modify_file.php?theme={$theme}&file={$file}
                      title='Edit' alt='Edit'>
                      <img src=../admin_tpl/images/doc_edit.gif border=0></a>&nbsp;{$file}<br>\n";
    }

    foreach($tpl_file_css as $k => $file) {
      $files_css .= "<a href=template_modify_file.php?theme={$theme}&file={$file}
                      title='Edit' alt='Edit'>
                      <img src=../admin_tpl/images/doc_edit.gif border=0></a>&nbsp;{$file}<br>\n";
    }

    foreach($tpl_file_msg as $k => $file) {
      $files_msg .= "<a href=template_modify_file.php?theme={$theme}&file={$file}
                      title='Edit' alt='Edit'>
                      <img src=../admin_tpl/images/doc_edit.gif border=0></a>&nbsp;{$file}<br>\n";
    }

    foreach($tpl_file_pages as $k => $file) {
      $files_pages .= "<a href=template_modify_file.php?theme={$theme}&file={$file}
                      title='Edit' alt='Edit'>
                      <img src=../admin_tpl/images/doc_edit.gif border=0></a>&nbsp;{$file}<br>\n";
    }
    
    foreach($tpl_file_child as $k => $file) {
      $files_child .= "<a href=template_modify_file.php?theme={$theme}&file={$file}
                      title='Edit' alt='Edit'>
                      <img src=../admin_tpl/images/doc_edit.gif border=0></a>&nbsp;{$file}<br>\n";
    }

    foreach($tpl_file_cp as $k => $file) {
      $file = 'cp/'.$file;
      $files_cp .= "<a href=template_modify_file.php?theme={$theme}&file={$file}
                      title='Edit' alt='Edit'>
                      <img src=../admin_tpl/images/doc_edit.gif border=0></a>&nbsp;{$file}<br>\n";
    }
    
    foreach($tpl_file_cp_child as $k => $file) {
      $file = 'cp/'.$file;
      $files_cp_child .= "<a href=template_modify_file.php?theme={$theme}&file={$file}
                      title='Edit' alt='Edit'>
                      <img src=../admin_tpl/images/doc_edit.gif border=0></a>&nbsp;{$file}<br>\n";
    }


    $theme_path = $theme_path . $theme. "/";
    
    $handle=opendir($theme_path . "/blocks/");
    while ($file = readdir($handle)) {
      if($file[0]==".") { }
      else $files[] = 'blocks/'."$file";
    }
    @sort($files);
    closedir($handle);
    
    foreach($files as $k => $file) {
      $files_block .= "<a href=template_modify_file.php?theme={$theme}&file={$file}
                      title='Edit' alt='Edit'>
                      <img src=../admin_tpl/images/doc_edit.gif border=0></a>&nbsp;{$file}<br>\n";
    }

    unset($files);

    $handle=opendir($theme_path . "/mail/");
    while ($file = readdir($handle)) {
      if($file[0]==".") { }
      else $files[] = 'mail/'."$file";
    }
    @sort($files);
    closedir($handle);

    foreach($files as $k => $file) {
      $files_email .= "<a href=template_modify_file.php?theme={$theme}&file={$file}
                      title='Edit' alt='Edit'>
                      <img src=../admin_tpl/images/doc_edit.gif border=0></a>&nbsp;{$file}<br>\n";
    }

    unset($files);

    $handle=opendir($theme_path);
    while ($file = readdir($handle)) {
      if($file[0]==".") { }
      elseif($file=="blocks") { }
      elseif($file=="cp") { }
      elseif($file=="images") { }
      elseif($file=="mail") { }
      elseif($file=="rss") { }
      else $files[] = "$file";
    }
    closedir($handle);
    
    $predefine_files = array_merge($tpl_file_setting,
                                   $tpl_file_css,
                                   $tpl_file_msg,
                                   $tpl_file_pages,
                                   $tpl_file_child,
                                   $exclude_files
                                   );

    $tpl_file_custom = array_diff($files, $predefine_files);

    foreach($tpl_file_custom as $k => $file) {
      $files_custom .= "<a href=template_modify_file.php?theme={$theme}&file={$file}
                      title='Edit' alt='Edit'>
                      <img src=../admin_tpl/images/doc_edit.gif border=0></a>
                      <a href=\"#\"
                      onclick=\"if(confirm('Are you sure want to delete this file?'))
                      MM_goToURL('self','template_delete_file.php?theme={$theme}&file={$file}');return document.MM_returnValue\"
                      title=\"Delete\" alt=\"Delete\">
                      <img src=../admin_tpl/images/doc_delete2.gif border=0></a>&nbsp;{$file}<br>\n";
    }
    
    $files_custom .= "<a href=template_add_custom.php?theme={$theme}
                      title='Add' alt='Add'>
                      <img src=../admin_tpl/images/doc_add.gif border=0></a>
                      <a href=template_add_custom.php?theme={$theme}
                      title='Add' alt='Add'>Add new custom template</a><br>\n";


    DisplayTemplate($admin_template_path . "template_select.html",
      "\$files_custom,\$theme,\$files_setting,\$files_css,\$files_msg,\$files_pages,\$files_child,\$files_cp,\$files_cp_child,\$files_block,\$files_email");
  }


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

  include "../application.php";

  RunPreFilter(__FILE__);

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

  RunPostFilter(__FILE__);

?>