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

  /*===================================================
    ShowFormAddUser()
  ===================================================*/

  function ShowFormAddUser() {

    // vars global configuration
    global $admin_template_path;

    // vars url & form

    // vars messages

    // vars template

    DisplayTemplate($admin_template_path . "user_add_form.html");
  }


  /*===================================================
    ProcessFormAddUser()
  ===================================================*/

  function ProcessFormAddUser() {

    // vars global configuration
    global $admin_template_path;

    // vars url & form
    global $username, $password, $email;

    // vars messages
    global $msg;

    // vars template
    global $message, $back;

    // verify input

    if(empty($username)) $error_msg = $msg["20151"];
    elseif(strlen($username)<3) $error_msg = $msg["20152"];
    elseif(empty($password)) $error_msg = $msg["20153"];
    elseif(empty($email)) $error_msg = $msg["20154"];
    elseif(!IsEmailAddress($email)) $error_msg = $msg["20155"];
    elseif(!IsAlphanumeric($username)) $error_msg = $msg["20157"];
    
    if(empty($error_msg)) {

      // register user
      $users_obj = new clsUsers;
      
      $users_obj->table_name = "idx_users";
      $users_obj->enable_user_validation = false;
      $auth = new auth();
      $register = $users_obj->Register($username,$email,$auth->Convert($password), $password);

      if ($register == '1') {
        // already exist
        $message = $msg["20156"];
      }
      else {
        $users_obj->ChangeProfile("process_form",$username);

        // success
        $message = $msg["20161"];
        $back = "<a href=user_add.php>Back</a>";
      }

    }
    else $message = $error_msg;

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


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

  include "../application.php";

  RunPreFilter(__FILE__);

  DisplayTemplate($admin_template_path . "header.html");
  if (empty($pflag)) {
    ShowFormAddUser();
  }
  elseif ($pflag == 'add') {
    ProcessFormAddUser();
  }
  DisplayTemplate($admin_template_path . "footer.html");

  RunPostFilter(__FILE__);

?>