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

<meta>
  <description>Biber Bibdia, angepasst für das System der Stabi Berlin.</description>
</meta>


<action id="connect">
</action>

<action id="update-all">
  <s>vl:delete-current-books()</s>
  <page url="https://ausleihe.staatsbibliothek-berlin.de/opac/user.S?LANG=de&FUNC=medk&DUM1=&BENUTZER={uri-encode($username)}&PASS={uri-encode(xs:string(string-to-base64Binary($password)))}" templateFile="update"/>
  <page url="https://ausleihe.staatsbibliothek-berlin.de/opac/user.S?LANG=de&FUNC=vorm&DUM1=&BENUTZER={uri-encode($username)}&PASS={uri-encode(xs:string(string-to-base64Binary($password)))}" templateFile="update"/>
  <page url="https://ausleihe.staatsbibliothek-berlin.de/opac/user.S?LANG=de&FUNC=best&DUM1=&BENUTZER={uri-encode($username)}&PASS={uri-encode(xs:string(string-to-base64Binary($password)))}" templateFile="update"/>
<!--  <error templateFile="loginError"/>-->
</action>


<action id="update-single">
  <if test="$book.title eq ''">
     <try>
      <page url="http://stabikat.de:8080/DB=1/CMD?ACT=SRCHA&IKT=54&SRT=YOP&TRM={uri-encode($book.id)}" templateFile="../pica/searchDetails"/>
    
      <page test="($book.title eq '') and contains($book.id, '-')"   
          url="http://stabikat.de:8080/DB=1/CMD?ACT=SRCHA&IKT=54&SRT=YOP&TRM={uri-encode($book.shortId)}" 
          templateFile="../pica/searchDetails"/>
      
      <catch errors="*"></catch>
     </try>
  </if>
</action>


<action id="renew-list">
  <variable name="book-list">string-join(for $book in $renew-books return x"{uri-encode($book._internalId)}=YES", "&amp;")</variable> 

  <page url="https://ausleihe.staatsbibliothek-berlin.de/opac/verl.S" templateFile="simpleCheck">
    <post name="LANG" value="de"/>
    <post name="FUNC" value="verl"/>
    <post name="BENUTZER" value="{$username}"/>
    <post name="PASS" value="{xs:string(string-to-base64Binary($password))}"/>
    <post value="{$book-list}"/>
  </page>
  <call action="update-all"/>
</action>

<action id="cancel-list">
  <loop var="func" list="$cancel-books?_func">
    <variable name="book-list">string-join(for $book in $cancel-books[$func eq ?_func] return x"{uri-encode($book._internalId)}=YES", "&amp;")</variable> 
  
    <page url="https://ausleihe.staatsbibliothek-berlin.de/opac/{$func}.S">
      <post name="LANG" value="de"/>
      <post name="FUNC" value="{$func}"/>
      <post name="BENUTZER" value="{$username}"/>
      <post name="PASS" value="{xs:string(string-to-base64Binary($password))}"/>
      <post value="{$book-list}"/>
    </page>
  </loop>
  <call action="update-all"/>
</action>


<!-- compare pica template. 
Changes:
    x before all search options
     -->
<action id="search">
  <variable name="searchOptions">
  encode-for-uri( string-join(
    (if ($book.title)    then concat("xtit ", $book.title)    else (),
     if ($book.author)   then concat("xprs ", $book.author)   else (),
     if ($book.isbn)     then concat("xisb ", $book.isbn)     else (),
     if ($book.year)     then concat("xjah ", $book.year)     else (),
     if ($book.keywords) then concat("xslw ", $book.keywords) else ()), " UND "))
  </variable>


  <page url="http://stabikat.de/DB=1/SET=2/TTL=1/CMD?ACT=SRCHA&IKT=1016&SRT=RLV&TRM={$searchOptions}" templateFile="../pica/searchList"></page>
  
  <page test="$singleResult" url="http://stabikat.de/DB=1/SET=2/TTL=1/CMD?ACT=SRCHA&IKT=1016&SRT=RLV&TRM={$searchOptions}" templateFile="../pica/searchDetails"></page>

  <variable name="search-next-page-available">$nextPage</variable>
</action>

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

  <variable name="search-next-page-available">$nextPage</variable>
</action>

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

</actions>
