<?php
require_once GTFWConfiguration::GetValue( 'application', 'docroot') .'module/validasi/business/AppValidasi.class.php';

class ProcessValidasi{
	var $_POST;
	var $Obj;
	var $pageView;
	var $cssDone = "notebox-done";
	var $cssFail = "notebox-warning";
	var $return;
	var $decId;
	var $encId;

   function __construct() {
		$this->Obj = new AppValidasi();
		$this->_POST = $_POST->AsArray();
		$this->decId = Dispatcher::Instance()->Decrypt($_REQUEST['dataId']);
		$this->encId = Dispatcher::Instance()->Encrypt($this->decId);
		$this->pageView = Dispatcher::Instance()->GetUrl('validasi', 'validasi', 'view', 'html');
	}
	
   function RandomPassword() {
      $new_password = '';
      $i = 0;
      for ($i=0; $i<6; $i++)
      {
         $number = rand(1, 9);
         settype($number, "string");
         $new_password = $new_password . $number;
      }
      return $new_password;
   }

   function AddPassword(){
      $new_password = $this->RandomPassword();
      $addPassword = $this->Obj->DoAddPassword($new_password,$this->decId);
      if($addPassword===true){
         Messenger::Instance()->Send('validasi', 'validasi', 'view', 'html', array($this->_POST,'Pembuatan Password Berhasil Dilakukan', $this->cssDone),Messenger::NextRequest);
      }else{
         Messenger::Instance()->Send('validasi', 'validasi', 'view', 'html', array($this->_POST,'Pembuatan Password Gagal Dilakukan', $this->cssFail),Messenger::NextRequest);
      }
      return $this->pageView;
   }
   
   function ResetPassword(){
      $new_password = $this->RandomPassword();
      $resetPassword = $this->Obj->DoAddPassword($new_password,$this->decId);
      if($resetPassword===true){
         Messenger::Instance()->Send('validasi', 'validasi', 'view', 'html', array($this->_POST,'Reset Password Berhasil Dilakukan', $this->cssDone),Messenger::NextRequest);
      }else{
         Messenger::Instance()->Send('validasi', 'validasi', 'view', 'html', array($this->_POST,'Reset Gagal Dilakukan', $this->cssFail),Messenger::NextRequest);
      }
      return $this->pageView;
   }
}
?>