<?php
  
$webdoc["page_title"].=" - Change your password";

/** zadani, pro jakeho uzivatele je tento soubor k dispozici
 *  soubor je k dispozici take vsem uzivatelum, kteri maji vyssi person_role
 * DA - 1
 * DE - 2
 * TA - 3
 * TE - 4
 * TT - 5    
*/ 
$person_role = 5;
if (!auth($person_role)) 
{
  $webdoc["message"][]=database_get_message("no_permission");
  $template->template_assign("no_display",true);
  return; 
}

/** ------------------------------------------------------
 *  ZACATEK vlastniho PHP kodu
    ------------------------------------------------------ */ 

if (isset($_SESSION["$webdoc[main_table]_edit_auth"])) // jestlize je sem presmerovano z editace hesla, zobraz hlasku
{
  unset($_SESSION["$webdoc[main_table]_edit_auth"]);
  $webdoc["message"][]=database_get_message("change_pass");  
}

if (isset($_POST["button"])) // prevedeni zadaneho jmena a hesla z formulare 
{
  $record["person_id"]=$_POST["person_id"];
  $record["pass"]=$_POST["pass"];
  $record["pass_again"]=$_POST["pass_again"];
  
  $filled_ok=true;
  if ($record["pass"]=="")
  {
    $webdoc["message"]["form_error"][]=database_get_message("filled_pass");
    $filled_ok=false;
  }
  if ($record["pass_again"]=="")
  {
    $webdoc["message"]["form_error"][]=database_get_message("filled_pass_again");
    $filled_ok=false;
  }
  
  if ($record["pass"]<>$record["pass_again"]) // test, zda se shoduji zadana hesla
  {  
    $pass_ok=false;
    $webdoc["message"]["form_error"][]=database_get_message("pass_not_match");
    
  }
  else
  { 
    $pass_ok=true;  
  }
  
  if ($filled_ok && $pass_ok) // pokud jsou vsechny podminky splneny, prida noveho uzivatele do Person
  {
    database_change_userpass_auth($record);  
  }
  
}
    
/** ------------------------------------------------------
 *  KONEC vlastniho PHP kodu
    ------------------------------------------------------ */ 

 
?>
