<?php

$webdoc["page_title"].=" - List";

$person_role = 5;
if (!auth($person_role)) 
{
  $webdoc["message"][]=database_get_message("no_permission");
  $template->template_assign("no_display",true);
  return;
}

if ($webdoc["main_table"]=="test" || $webdoc["main_table"]=="test_run")
{
  if (isset($_SESSION["$webdoc[main_table]_record_saved"])) //oznameni o uspesnem ulozeni po presmerovani na editaci
  {
    unset($_SESSION["$webdoc[main_table]_record_saved"]);
    $webdoc["message"][]=database_get_message("record_saved");
  }

  $webdoc["test_id"]=$_REQUEST["test_id"];
}

kernel_get_url($filter,$columns,$pages,$sort); //precte url a podle toho nastavi filter. pokud v url nastaveni filtru neni, precte cookies a pokud v cookies neco je, presmeruje na odpovidajici url

$webdoc["url"]=kernel_create_columns_url($columns).kernel_create_filter_url($filter); //url pro vypis stranek a prispevku na stranku. Parametry stranky budou nastaveny zvlast pro kazdy odkaz
$url_pages=kernel_create_pages_url($pages); //url pro ostatni odkazy (vcetne aktualni stranky)
$url_sort=kernel_create_sort_url($sort); //url pro razeni

$pages["url"]=$webdoc["url"].$url_sort;
$sort2["url"]=$webdoc["url"].$url_pages;

$webdoc["url"].=$url_pages.$url_sort;

$template->template_assign("filter",$filter); //prirazeni filtru do sablony jiz zde, aby se do skrytych poli nevkladaly nasledujici upravy data
//upraveni data
$filter["created_from2"]=kernel_date_control($filter["created_from"]);
$filter["created_to2"]=kernel_date_control($filter["created_to"]);
$filter["approved_from2"]=kernel_date_control($filter["approved_from"]);
$filter["approved_to2"]=kernel_date_control($filter["approved_to"]);
if ($webdoc["main_table"]=="test")
{
  $filter["terminate_from2"]=kernel_date_control($filter["terminate_from"]);
  $filter["terminate_to2"]=kernel_date_control($filter["terminate_to"]);
  $terminate=(!$filter["created_from2"] || !$filter["created_to2"]); //doplneni nasledujici podminky if. pokud neni main_table test, je vzdy false
}
else $terminate=false;

//kontrola spravnosti data u filtru. pokud nektery z parametru neprosel, presmeruje se zpet na filtr, kde se zobrazi chybova hlaska
if (!$filter["created_from2"] || !$filter["created_to2"] || !$filter["approved_from2"] || !$filter["approved_to2"] || $terminate)
{
  $webdoc["url"]="./?subpage1=$_GET[subpage1]&subpage2=filter$webdoc[url]&button_filtrate=1"; //vytvoreni nove url z hodnot filtru
  header("location: $webdoc[url]"); //presmerovani na filter.php
  echo database_get_message("continue")." <a href=\"$webdoc[url]\">".database_get_message("here")."</a>."; //zobrazeni hlasky "pokracovat zde", pokud selze presmerovani
  exit;
}

if (isset($_GET["test_id"])) $webdoc["test_id"]=(int)$_GET["test_id"];

$list=database_get_list($rows,$pages["records_total"],$pages,$sort,$columns,$filter); //vrati seznam pozadavku

if (!$list) unset($list);

kernel_create_pages($pages); //dopocitani dalsich promennych stranky pro sablonu
kernel_create_sort($sort,$sort2,$columns); //dopocitani dalsich promennych pro razeni zaznamu

if (count($list)==0) $webdoc["message"][]=database_get_message("list_empty");

switch ($webdoc["main_table"])
{
  case "requirement": $columns_array=array("name","description","comments","category","parent","created","creator","approved","approver","active","is_product_specific"); break;
  case "product": $columns_array=array("name","description","comments","category","parent","created","creator","approved","approver"); break;
  case "test": $columns_array=array("name","created","creator","approved","approver","acceptance_criteria","comments","terminate","terminator"); break;
  case "test_run": $columns_array=array("name","created","creator","approved","approver","tested","tester","sw_rev","hw_rev","setup","result","duration","description"); break;
}

foreach ($columns as $name => $value) //nastaveni poli pro funkci view_result
{
  if (in_array($name,$columns_array)) switch ($name)
  {
    case "name": $title[]="Name"; $values[]=$name; break;
    case "description": $title[]="Description"; $values[]=$name; break;
    case "category": $title[]="Category"; $values[]=$name; break;
    case "parent": $title[]="Parent"; $values[]=$name; break;
    case "created": $title[]="Created"; $values[]=$name; break;
    case "creator": $title[]="Creator"; $values[]=$name; break;
    case "approved": $title[]="Approved"; $values[]=$name; break;
    case "approver": $title[]="Approver"; $values[]=$name; break;
    case "tested": $title[]="Tested"; $values[]=$name; break;
    case "tester": $title[]="Tester"; $values[]=$name; break;
    case "active": $title[]="Active"; $values[]=$name; break;
    case "is_product_specific": $title[]="Is product specific"; $values[]=$name; break;
    case "acceptance_criteria": $title[]="Acceptance criteria"; $values[]=$name; break;
    case "sw_rev": $title[]="SW Rev"; $values[]=$name; break;
    case "hw_rev": $title[]="HW Rev"; $values[]=$name; break;
    case "setup": $title[]="Setup"; $values[]=$name; break;
    case "result": $title[]="Result"; $values[]=$name; break;
    case "duration": $title[]="Duration"; $values[]=$name; break;
    case "comments": $title[]="Comments"; $values[]=$name; break;
    case "terminate": $title[]="Terminated"; $values[]=$name; break;
    case "terminator": $title[]="Terminator"; $values[]=$name; break;
  }
}
if (isset($columns["actions"])) $title[]="Actions";

$template->template_assign("title",$title);
$template->template_assign("values",$values);

switch ($webdoc["main_table"])
{
  case "test":
    $template->template_assign("actions",array("View"=>"view","Edit"=>"edit","History"=>"history"));
    $template->template_assign("role",array("5","4","5"));
    $template->template_assign("parametr", array("test_id","sequence_id"));    
  break;
  case "test_run":
    $template->template_assign("actions",array("View"=>"view","Edit"=>"edit","Copy"=>"copy"));
    $template->template_assign("role",array("5","5","5"));
    $template->template_assign("parametr", array("test_run_id")); 
  break;
  default:
    $template->template_assign("actions",array("View"=>"view","Edit"=>"edit","History"=>"history","Copy"=>"copy","Files"=>"files","Approving"=>"approving"));
    $template->template_assign("role",array("5","1","5","1","2","2"));
    $template->template_assign("parametr", array("sequence_id"));
}

$template->template_assign("list",$list);
$template->template_assign("url",$webdoc["url"]); //url pro odkazy
$template->template_assign("columns_count",count($title)); //pocet sloupcu 
$template->template_assign("pages",$pages); //nastaveni hodnot stranky ve formulari
$template->template_assign("sort",$sort); //nastaveni hodnot razeni ve formulari
$template->template_assign("sort2",$sort2); //nastaveni hodnot razeni ve formulari
$template->template_assign("columns",$columns); //nastaveni hodnot sloupcu ve formulari
//filter prirazen do sablony vyse

$filter_text=database_get_filter($filter);
$template->template_assign("filter_text",$filter_text);
?>
