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

  /*===================================================
    ShowFormChangePassword()
  ===================================================*/

  function ShowFormChangePassword() {

    // vars global configuration
    global $admin_template_path;

    // vars url & form

    // vars messages

    // vars template
   
    DisplayTemplate($admin_template_path . "app_change_pwd_form.html");
  }


  /*===================================================
    ProcessFormChangePassword()
  ===================================================*/

  function ProcessFormChangePassword() {

    // vars global configuration
    global $admin_template_path;

    // vars url & form
    global $present_pwd, $new_pwd, $new_pwd2;

    // vars messages
    global $msg;
    
    // vars template
    global $message;
    
    // verify input
    
    if(empty($present_pwd)) $error_msg = $msg["20391"];
    elseif(empty($new_pwd)) $error_msg = $msg["20392"];
    elseif(empty($new_pwd2)) $error_msg = $msg["20393"];
    elseif($new_pwd2 != $new_pwd) $error_msg = $msg["20394"];

    if(empty($error_msg)) {
      $users_obj = new clsUsers;
      $users_obj->table_name = "idx_users";
      $change_result = $users_obj->ChangePassword($_COOKIE['COOKIE_USERNAME'], $present_pwd, $new_pwd);
      if ($change_result == 0) {
        $back_url = urlencode("admin/app_change_pwd.php?pflag=ok");
        Redirect("../login.php?f=1&b=$back_url&u=$_COOKIE[COOKIE_USERNAME]&p=$new_pwd&pflag=login");
      }
      else {
        // failed
        $error_msg = $msg["20401"];
      }
    }
    $message = $error_msg;
    DisplayTemplate($admin_template_path . "header.html");
    DisplayTemplate($admin_template_path . "message.html","\$message");
  }


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

  include "../application.php";
  
  RunPreFilter(__FILE__);

  if (empty($pflag)) {
    DisplayTemplate($admin_template_path . "header.html");
    ShowFormChangePassword();
  }
  elseif ($pflag == 'change') {
    ProcessFormChangePassword();
  }
  elseif ($pflag == 'ok') {
    $message = $msg["20402"];
    DisplayTemplate($admin_template_path . "header.html");
    DisplayTemplate($admin_template_path . "message.html","\$message");
  }  

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

  RunPostFilter(__FILE__);

?>