<?xml version="1.0" encoding="UTF-8"?>
<actions>


<meta>
  <description>Template für das Libero-System, version 5.4</description>
  <variable name="baseurl"><description>Serveraddresse (inklusive Protokoll)</description></variable>
  <variable name="loginBaseurl" default=""><description>Serveraddresse für Kontozugriff(inklusive Protokoll)</description></variable>
</meta>

<action id="connect">
  <s>$baseurl := get("loginBaseurl", $baseurl),
     $update-page := ()</s>
</action>

<action id="internal-connect">
  <page url="{$baseurl}WebOpac.cls" templateFile="start"/>
  <page url="{$baseurl}WebOpac.cls?VERSION=2&amp;ACTION=MEMBERSERV&amp;RSN=0&amp;DATA={$data}&amp;TOKEN={$token}&amp;Z=1&amp;NewBreadCrumb=1&amp;{$loginToken}">
    <template>
      <t:switch prioritized="true">
        <form><input name="usernum"/><t:s>update-page := form(., {"usernum": $username, "password": $password, "btnlogin": "LOGIN"})</t:s></form>
        <fieldset t:condition="@id=('issued_items', 'reserved_items_flds')">{$update-page := $url}</fieldset>
      </t:switch></template>
  </page>
</action>

<action id="update-all">
  <if test="not($update-page)"><call action="internal-connect"/></if>
  <s>$new-update-page := (), $session-lost := false()</s>
  <page url="{$update-page}" templateFile="update"/>  
  <page test="$wrong-update-page" url="{$update-page}" templateFile="update"/>  
  <s>$update-page := $new-update-page</s> <!-- Pattern assigns to $new-update-page instead $update-page as some libraries might not have that link. todo: check all libs, and remove $new-update-page if possible-->
  <if test="$session-lost">
    <call action="internal-connect"/>
    <page url="{$update-page}" templateFile="update"/>
    <page test="$wrong-update-page" url="{$update-page}" templateFile="update"/>  
  </if>
</action>

<action id="renew-list">
  <s>$update-page := (),
     $book-list := string-join(for $book in $renew-books return x"{$book.extendid}=1", "&amp;")
  </s>
  <page url="{$baseurl}WebOpac.cls">
    <post name="MGWCHD" value="0"/>
    <post name="TOKEN" value="{$token}"/>
    <post name="TOKENX" value="{$tokenx}"/>
    <post name="DATA" value="{$data}"/>
    <post name="usercode" value=""/>
    <post name="VERSION" value="{$version}"/>
    <post name="ACTION" value="MEMSLFISS"/>
    <post name="bno" value="{$username}"/>
    <post name="mid" value="{$mid}"/>
    <post value="{$book-list}"/>
<!--    <post name="SubmitIssued" value="Senden"/>-->
    <template><body><a t:condition="contains(@href, 'MEMSTAT')">{$update-page := @href}</a>?</body></template>
  </page>
  <call action="update-all"/>
</action>

<action id="cancel-list">
  <s>$update-page := (), 
     $book-list := string-join(for $book in $cancel-books return $book.cancelId, "&amp;"),
     $f := $cancelForm, 
     $f.post := concat($f.post, "&amp;", $book-list)
   </s>
  <page url="{$f}">
  <template>
    <b>Löschen der Benutzervormerkung wird bearbeitet</b>
    <b>Transaktion verarbeitet</b>
  </template>
  </page>
</action>

<action id="search-connect">
  <page url="{$baseurl}WebOpac.cls">
  <template>
    <t:switch-prioritized>
      <a t:condition="contains(@href, 'WebOpac.cls')">Erweiterte Suche<t:s>search:=@href</t:s></a>
      <title>LIBERO WebOPAC Erweiterte Suche<t:s>search:=$url</t:s></title>
      <font>Server ist zurzeit nicht verfügbar<t:s>vl:raise(.)</t:s></font>
    </t:switch-prioritized>
  </template> <!-- condition is for dresden which has a link "erweiterte suche in der Hilfe" -->
  </page>

  <s>search-keys := {"author": "kb", "title": "k", "free": "ku", "keywords": "kj", "isbn": "i"},
     search-select-map := {"LIMLOC": "libraryBranch", "LIMCOL": "category", "LIMGMD": "mediaType", "PREFER": "sort", "LIMLNG": "language"},
     search-select-map-reverse := map:merge(jn:keys($search-select-map)!{$search-select-map(.):.}) 
  </s>

  <page url="{$search}">
  <template><form>
    {search-form := form(.),
     search-params := (  "title", "author", "free", "keywords", "year", "isbn",
       .//select/(
       let $name := @name
       return
         if ($name = "USE_1") then ( .//option[starts-with(., "Schlag")]/(search-keys.keywords := @value) )[0]
         else let $mapped := $search-select-map($name) where $mapped 
              return {"name": $mapped, "options": .//option}
     ))
    }
  </form></template>
  </page>
</action>


<action id="search">  
  <s>
     i := 1, 
     f := $search-form,
     f.post := uri-combine($f.post, (
       if (boolean($book.year)) then 
         if (contains($book.year, "-")) then 
           {"YEARFROM": normalize-space(substring-before($book.year, "-")), "YEARTO": normalize-space(substring-after($book.year, "-"))} 
         else 
           {"YEARFROM": $book.year, "YEARTO": $book.year} 
       else (),
       for $key in jn:keys($book) return if (boolean($book($key)) and exists($search-keys($key))) then (
         {x"TERM_{$i}": $book($key), x"USE_{$i}": $search-keys($key)},
         (i := $i + 1)[2]
       ) else if ($search-select-map-reverse($key)) then 
         { $search-select-map-reverse($key): $book($key) }
       else ()
    )
     )
  </s>
  <page url="{$f}" templateFile="searchList"/>
  
</action>

<action id="search-next-page">
  <page url="{$next-page}" templateFile="searchList"/>
</action>

<action id="search-details">
  <page url="{$book._detail-url}" templateFile="searchDetails"/>
</action>

<action id="order-single"> 
  <s>$order := if ($book._order-url) then $book._order-url
               else if ($holding._order-id and get("order-form")) then
                 request-combine(get("order-form"), {$holding._order-id: 1})
               else ()
   </s>
  <page url="{$order}"/>
  <if test="//form//input[@name='usernum' and not(@type = 'hidden')]">
    <s>f := form(//form[.//input[@name='usernum']], {"usernum": $username, "password": $password})</s>
    <page url="{$f}"/>
  </if>
  <pattern href="orderConfirm"/>
  <if test="count($issuePoints) le 1">
    <s>$choose-result := ""</s>
    <call action="internal-order-choosen"/>
  </if>
</action>


<action id="internal-order-choosen"> 
  <if test="$choose-result instance of xs:string">
    <if test="count($issuePoints) > 1">
      <s>confirm.post := uri-combine($confirm.post, {$order-branch-name: $choose-result})</s>
    </if>
    <page url="{$confirm}"/>
    <pattern href="orderComplete"/>
    <s>$book.statusId := "ordered"</s>
  </if>
</action>


<action id="catalogue">
  <variable name="url" value="{$baseurl}WebOpac.cls"/>
</action>


</actions>
