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

<meta>
  <description>reines Such-Template für Suchen über die Digibib (nur bis Version Digibib 6)</description>
  <variable name="location"><description>Such-Ort (siehe digibib-Dokumentation)</description></variable>
  <variable name="view"><description>Such-View (siehe digibib-Dokumentation)</description></variable>
  <variable name="searchid"><description>Sigel der Bücherei (siehe digibib-Dokumentation)</description></variable>
</meta>

<action id="connect">
  <s>request := x"https://www.digibib.net/jumpto?D_SUBSERVICE=CUSTOMIZE&LOCATION={$location}", 
     i := 1, 
     datasend := false()</s>
  <!-- follow links till we reach the login page -->
  <loop test="$i <= 50 and exists($request)">  
    <page url="{$request}"/>
    <pattern><t:switch prioritized="true">
      <div class="uic-error" t:condition="$datasend">
        <span class="requestError">The benutzername or passwort is invalid<t:s>vl:raise-login(.)</t:s></span>
      </div>
      <div class="uic-error" t:condition="$datasend">
        <span class="requestError">{vl:raise(.)}</span>
      </div>
      <div class="object-error" t:condition="$datasend">{vl:raise(.)}</div>
    
      <table class="datarows">{$request := (), $accountUrl := $url (:we have reached our destination:)}</table>
      <a t:condition="contains(@href, '/intro/account') and not($datasend)">{$request}</a>
      <form>{  
        let $action := @action return
        if (contains($action, "session/logout")) then ($request := (), $accountUrl := $url)
        else
        $request := form(.,
          if (contains($action, "selectIdp")) then 
            let $t := if ($type ge 1) then $type else 1 return (.//button)[$t]
          else if (contains($action, "samllogin")) then 
            ({"signin.username": $username, "signin.password": $password}, (datasend := true())[0])
          else if (contains($action, "HandleAuthorizeResponse")) then 
            (.//input[@type="submit" and not(contains(@name, "decline"))])[1]
          else ())
      }</form>
      <script t:condition="contains(., 'INITIAL_STATE')">
      {request := 
       let $type := if ($type ge 1) then $type else 1
       let $initialstate := parse-json(parse-json( extract(., "JSON.parse *\((.*)\);", 1) ))
       let $postUrl := $initialstate?postUrl
       return 
       if ($postUrl) then {"url": $postUrl, 
                           "method": "POST", 
                           "post": x"acsURL={uri-encode($postUrl)}{$amp}SAMLResponse={uri-encode($initialstate?postBody)}"}
       else
       let $contextInstId := $initialstate?contextInstId
       let $identityString := $initialstate?institutionIdpList?($type)?idpIdentity?identityString
       let $encoded := uri-encode(replace($identityString, " ", "||"))
       return            {"url": "https://authn.sd02.worldcat.org/wayf/metaauth-ui/cmnd/wayf/selectIdp", 
                          "method": "POST", 
                          "post": x"contextInstId={$contextInstId}{$amp}encodedIdpIdentity={$encoded}"}
      
      }
      </script>
      <!-- not used: -->
      <a>{$request}</a>
      <meta http-equiv="refresh">{$request}</meta>    
    </t:switch></pattern>
    <s>$i := $i + 1</s>
  </loop>
  <if test="$i > 50">
  <s>vl:raise-internal("Zuviele Weiterleitungen beim Login. ")</s>
  </if>
</action>

<action id="update-all">
  <page url="{$accountUrl}" test="$url ne $accountUrl"/>
  <pattern href="list"/>
</action>

<action id="renew-list">
  <loop var="book" list="$renew-books">
    <page url="{$book._renewUrl}"> </page>
  </loop>
  <call action="update-all"/>
</action>

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

<action id="search">
<!--  <page url="http://www.digibib.net/opensearch?S.SEARCH_SBDUE=on&S.SEARCH_SBAA=on&VIEW=HBZ:OeffBibInNRW&QUERY_alAL={searchTerms}&LOCATION=HBZ&

http://www.digibib.net/opensearch?S.SEARCH_SBDUE=on&S.SEARCH_SBAA=on&VIEW=HBZ:OeffBibInNRW&QUERY_azTI=test&LOCATION=HBZ&

-->
  <page url="http://www.digibib.net/opensearch" templateFile="search">
    <post name="LOCATION" value="{$location[1]}"/>
    <post name="VIEW" value="{$view[1]}"/>

    <post name="QUERY_azTI" value="{$book.title}"/>  
    <post name="QUERY_bzAU" value="{$book.author}"/>
    <post name="QUERY_fzIB" value="{$book.isbn}"/>
    <post name="QUERY_gzIS" value="{$book.issn}"/>
    <post name="QUERY_hzYR" value="{$book.year}"/>
    <post name="QUERY_ezKY" value="{$book.keywords}"/>
    <post name="QUERY_OazTI" value="AND"/>
    <post name="QUERY_ObzAU" value="AND"/>
    <post name="QUERY_OfzIB" value="AND"/>
    <post name="QUERY_OgzIS" value="AND"/>
    <post name="QUERY_OhzYR" value="AND"/>
    <post name="QUERY_OezKY" value="AND"/>
    
    <post name="COUNT" value="50"/>
    <post name="GWTIMEOUT" value="90"/>
    
    <post value="{join($searchid ! x'{.}=on', $amp)}"/>
    
  </page>  
  
 <!-- <page url="http://www.digibib.net/{$url}" templateFile="search"/> -->
  
<!--  <page url="http://www.digibib.net/Digibib?SID={$sid}&LOCATION={$location}&SERVICE=METASEARCH&SUBSERVICE=GETLIST&PREVREQID={$reqid}&STREAMING=TRUE&VIEW={$view}&FORMAT=List&START=1&COUNT=100&METAID={$metaid}" templateFile="search"/>-->
  
<!--  <page url="http://abderos.hbz-nrw.de/Digibib?SERVICE=METASEARCH&amp;SUBSERVICE=GETLIST&amp;{$metaid}&amp;FORMAT=List&amp;URLENCODING=TRUE&amp;START=1&amp;COUNT=200&amp;SID={$sid}&amp;LOCATION={$location}&amp;{$sreqid}&amp;{$reqid}&amp;{$olreqid}&amp;STREAMING=on" templateFile="search"/>
-->  

</action>

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


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


</actions>

 <!--<input type="hidden" name="VIEW"        value="DUEBIB:Lokale_Bibliotheken" />"/><input type="hidden" name="LOCATION"    value="DUEBIB
      QUERY_czCO = körperschaft, QUERY_0czCO
      QUERY_dzPB = verlag, QUERY_0dzPB
      
     " http://abderos.hbz-nrw.de/Digibib?SERVICE=METASEARCH&amp;SUBSERVICE=GETLIST&amp;METAID=4782&amp;FORMAT=List&amp;URLENCODING=TRUE&amp;START=1&amp;COUNT=10&amp;SID=RHEA:1906707980&amp;LOCATION=362&amp;SREQID=RHEA:38292267&amp;REQID=RHEA:38292267&amp;OLREQID=RHEA:38292267&amp;STREAMING=off"/>-->
