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

  /*===================================================
    DeleteUser()
  ===================================================*/

  function DeleteUser() {

    // vars global configuration
    global $dbConn, $admin_template_path;

    // vars url & form
    global $num_rows;

    // vars messages
    global $msg;

    // vars template
    global $message, $back;
    
    $tpl = new Template();

    $i=1;
    while($i<=$num_rows){
      $var = "chkbox_$i";
      $id = $GLOBALS["$var"];

      if(!empty($id)) {
        $username = $id;
        $users_obj = new clsUsers;
        $users_obj->table_name = "idx_users";
        $delete_result = $users_obj->Delete($id);

        if($delete_result==0) {
          $message .= $msg["20191"];
    
          // delete favorites
          $query = "select * from idx_favorites where username='$username'";
          $result = $dbConn->Execute($query);
          
          $query = "delete from idx_favorites_detail where 0!= 0 ";
          while (!$result->EOF) {
            $fid = $result->Fields("favorite_id");
            $query .= "or favorite_id = '$fid'";
            $result->MoveNext();
          }
          $result = $dbConn->Execute($query);				  
          
          $query = "delete from idx_favorites where username='$username'";
          $result = $dbConn->Execute($query);				
          
          // delete editor
          $query = "delete from idx_editor where username='$username'";
          $result = $dbConn->Execute($query);						
      
        }
    
        $tpl->assign('username', $username);
        $message = $tpl->fetch('var:' . $message);
      }
      $i++;
    }
    
    if(empty($message)) $message = $msg["20192"];
    
    $back = "<a href=$back>Back</a>";

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


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

  include "../application.php";

  RunPreFilter(__FILE__);

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

  RunPostFilter(__FILE__);

?>