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

  /*===================================================
    MakeActive()
  ===================================================*/

  function MakeActive() {

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

    // vars messages
    global $msg;

    // vars template
    global $message, $back;
    
    $lines = file($base_path . "application.php");
    
    $i = 0;
    $count_lines = @count($lines);
    while ($i < $count_lines) {
      $s = chop(ltrim($lines[$i]));
      if(substr($s,0,13)=='$active_theme') {
        // change
        $arr       = explode('=',$lines[$i]);
        $arr[1]    = " '{$theme}';\r\n";
        $lines[$i] = implode('=',$arr);
      }
      $i++;
    }
    
    // write again
    $content = implode("",$lines);
    $fp = fopen($base_path . "application.php", "w+");
    fwrite($fp,$content);
    fclose($fp);
    
    // clear all compiled templates
    $handle = opendir($base_path . "templates_c");
    while (FALSE !== ($filename = readdir($handle))) {
      if ($filename != "." && $filename != ".." && $filename != "dummy.txt" && $filename[0] != '.') {
        @unlink($base_path . "templates_c/" .$filename);
      }
    }
    closedir($handle);

    $message = $msg["20423"];
    $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");
  MakeActive();
  DisplayTemplate($admin_template_path . "footer.html");

  RunPostFilter(__FILE__);

?>