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

  /*===================================================
    MakeDuplicate()
  ===================================================*/

  function MakeDuplicate() {

    // vars url & form
    global $admin_template_path, $theme, $theme_path, $base_path;

    // vars messages
    global $msg;

    // vars template
    global $message, $back;
    

    // get all files


    $loc     = "{$theme_path}{$theme}";
    $loc_dup = "{$theme_path}{$theme}_copy";

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

    $handle = opendir($loc.'/blocks/');
    while ($file = readdir($handle)) {
      if($file[0]==".") { }
      else {
        $files[]      = "$loc/blocks/$file";
        $files_path[] = "{$loc_dup}/blocks/$file";
      }
    }
    closedir($handle);

    $handle = opendir($loc.'/cp/');
    while ($file = readdir($handle)) {
      if($file[0]==".") { }
      else {
        $files[]      = "$loc/cp/$file";
        $files_path[] = "{$loc_dup}/cp/$file";
      }
    }
    closedir($handle);

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

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

    $handle = opendir($loc.'/images/');
    while ($file = readdir($handle)) {
      if($file[0]==".") { }
      else {
        $files[]      = "$loc/images/$file";
        $files_path[] = "{$loc_dup}/images/$file";
      }
    }
    closedir($handle);

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

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

    $handle = opendir($loc.'/images/pr');
    while ($file = readdir($handle)) {
      if($file[0]==".") { }
      else {
        $files[]      = "$loc/images/pr/$file";
        $files_path[] = "{$loc_dup}/images/pr/$file";
      }
    }
    closedir($handle);
    
    // make directory
    @mkdir($loc_dup);
    @mkdir($loc_dup.'/blocks');
    @mkdir($loc_dup.'/cp');
    @mkdir($loc_dup.'/mail');
    @mkdir($loc_dup.'/rss');
    @mkdir($loc_dup.'/images');
    @mkdir($loc_dup.'/images/review');
    @mkdir($loc_dup.'/images/rating');
    @mkdir($loc_dup.'/images/pr');

    // chmod 777 directories
    @chmod($loc_dup, 0777);
    @chmod($loc_dup.'/blocks', 0777);
    @chmod($loc_dup.'/cp', 0777);
    @chmod($loc_dup.'/mail', 0777);
    @chmod($loc_dup.'/rss', 0777);
    @chmod($loc_dup.'/images', 0777);
    @chmod($loc_dup.'/images/review', 0777);
    @chmod($loc_dup.'/images/rating', 0777);
    @chmod($loc_dup.'/images/pr', 0777);

    // copy files

    $i = 0;
    $count_files = @count($files);
    while ($i < $count_files) {
      @copy($files[$i],$files_path[$i]);
      @chmod($files_path[$i], 0777);
      $i++;
    }

    $message = $msg["20426"];

    $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");
  MakeDuplicate();
  DisplayTemplate($admin_template_path . "footer.html");

  RunPostFilter(__FILE__);

?>