<?php

include_once("config.php");

if ($_POST['ChangePinButton'] or $_POST['PinCancelButton'])
{
$changepin=$_POST['ChangePinButton'];
$changecancel=$_POST['PinCancelButton'];
}
$ispasswordok=1;
$errmsg="";

if ($_POST['NewPin'])
{
/*for mobile*/
   
   $newpin=$_POST['NewPin'];
   if (strlen($newpin)<4)
   {	
     $ispasswordok=0;
     $errmsg="Password less 4 character Minimum";
   }
   if ($_POST['NewPin2'])
   {
     $newpin2=$_POST['NewPin2']; 
     if (strcmp($newpin,$newpin2)<>0)  
     {
       $ispasswordok=0;
      $errmsg="Passwords do not match";
       
     }  
   }
   if ($_POST['ChangePinbutton']==false)
   {
	$changepin="Ok";
	$changecancel="";
   }
}  

if ($webportal_use_agreement==true)
{
   if ($ispasswordok==1)
   {
	if ($_GET['AgreeButton'] or $_GET['DisAgreeButton'])
	{
		$agreebutton=$_GET['AgreeButton'];
		$disagreebutton=$_GET['DisAgreeButton'];
	}

	if ($_POST['AgreeButton'] or $_POST['DisAgreeButton'])
	{
   		$agreebutton=$_POST['AgreeButton'];
 		$disagreebutton=$_POST['DisAgreeButton'];
   	}

    
	if ($disagreebutton=="Disagree" or $changecancel=="Cancel")
	{

/*      $vlogout = $root_path . "/logout.php";*/
        $vlogout= "$prefix_http://$website_address";
  	  header("Location: $vlogout");
	} else
	{  
		$template = new pharmacies_page("template_pharmacies.html",$agreebutton,$changepin,$newpin);
		if ($template->agreed==0) 
		{
		$template = new agreement_page("template_agreement.html");

		} else 
		{
		if ($template->passwordchange==0 && $webportal_initial_password_change==true)
			{
				$template = new changepin_page("template_changepin.html");
	
			}

		if ($template->passwordchange==2 && $webportal_initial_password_change==true)
			{
			 $_SESSION["pin"] = $template->resetpin;

			}
		
		}


	}

    } else  /* else to is password ok */
      {
	$template = new changepin_page("template_changepin.html");
	if ($ispasswordok==0) {
	  $template->error =$errmsg;
	}

      }
    	
} else
{

/********************/
/*Agreement Disabled*/
/********************/
  $agreebutton="";
  $template = new pharmacies_page("template_pharmacies.html",$agreebutton,$changepin,$newpin);
if ($changecancel=="Cancel") 
{
      $vlogout = $root_path . "logout.php";
  	  header("Location: $vlogout");
 
} else  
{	
  
 if ($template->passwordchange==0 && $webportal_initial_password_change==true)
  {
	$template = new changepin_page("template_changepin.html");

	
  } 

  if ($template->passwordchange==2 && $webportal_initial_password_change==true)
	{
        $_SESSION["pin"] = $template->resetpin;

	}
	
}




 
}
$template->show();

?>