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

  /*===================================================
    DeleteFile()
  ===================================================*/

  function DeleteFile() {

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

    // vars url & form
    global $theme;

    // vars messages
    global $msg;

    // vars template
    global $message, $back;
    
    // check if it is currenly active
    
    if ($active_theme == $theme) {
      $message = $msg["20425"];
      DisplayTemplate($admin_template_path . "message.html", "\$message");
      RunPostFilter(__FILE__);
    }


    // get file list
    
    $theme_path = $theme_path . $theme. "/";
    
    $handle=opendir($theme_path);
    while ($file = readdir($handle)) {
      if($file[0]==".") { }
      else $files[] = $file;
    }
    closedir($handle);
    
    $handle=opendir($theme_path . "/blocks/");
    while ($file = readdir($handle)) {
      if($file[0]==".") { }
      else $files[] = "blocks/" . $file;
    }
    closedir($handle);
    
    $handle=opendir($theme_path . "/cp/");
    while ($file = readdir($handle)) {
      if($file[0]==".") { }
      else $files[] = "cp/" . $file;
    }
    closedir($handle);

    $handle=opendir($theme_path . "/images/");
    while ($file = readdir($handle)) {
      if($file[0]==".") { }
      else $files[] = "images/" . $file;
    }
    closedir($handle);
    
    $handle=opendir($theme_path . "/images/rating/");
    while ($file = readdir($handle)) {
      if($file[0]==".") { }
      else $files[] = "images/rating/" . $file;
    }
    closedir($handle);
    
    $handle=opendir($theme_path . "/images/review/");
    while ($file = readdir($handle)) {
      if($file[0]==".") { }
      else $files[] = "images/review/" . $file;
    }
    closedir($handle);

    $handle=opendir($theme_path . "/images/pr/");
    while ($file = readdir($handle)) {
      if($file[0]==".") { }
      else $files[] = "images/pr/" . $file;
    }
    closedir($handle);

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

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

    foreach($files as $k => $file) {
      // delete all
      @unlink($theme_path . $file);
    }
    
    // delete directory
    @rmdir($theme_path . "blocks");
    @rmdir($theme_path . "cp");
    @rmdir($theme_path . "mail");
    @rmdir($theme_path . "rss");
    @rmdir($theme_path . "images/review");
    @rmdir($theme_path . "images/rating");
    @rmdir($theme_path . "images/pr");
    @rmdir($theme_path . "images");
    @rmdir($theme_path);


    $message = $msg["20424"];

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

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


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

  include "../application.php";

  RunPreFilter(__FILE__);

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

  RunPostFilter(__FILE__);

?>