<?xml version="1.0" encoding="UTF-8"?>
<!--
 -
 -  $Id: news.vspx,v 1.21.2.5 2012/03/08 10:46:17 source Exp $
 -
 -  This file is part of the OpenLink Software Virtuoso Open-Source (VOS)
 -  project.
 -
 -  Copyright (C) 1998-2012 OpenLink Software
 -
 -  This project is free software; you can redistribute it and/or modify it
 -  under the terms of the GNU General Public License as published by the
 -  Free Software Foundation; only version 2 of the License, dated June 1991.
 -
 -  This program is distributed in the hope that it will be useful, but
 -  WITHOUT ANY WARRANTY; without even the implied warranty of
 -  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 -  General Public License for more details.
 -
 -  You should have received a copy of the GNU General Public License along
 -  with this program; if not, write to the Free Software Foundation, Inc.,
 -  51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
 -
-->
<v:page name="feed_reader_page" decor="template/template.vspx" style="template/template.xsl" fast-render="1" button-anchors="1" xmlns:v="http://www.openlinksw.com/vspx/" xmlns:vm="http://www.openlinksw.com/vspx/macro" doctype="-//W3C//DTD XHTML 1.0 Transitional//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  <vm:pagetitle>Read news</vm:pagetitle>
  <vm:pagewrapper>
    <vm:header>
      Read news
    </vm:header>
    <vm:variables>
      <v:variable name="fTab" type="varchar" default="'feeds'"/>
      <v:variable name="fNode" type="varchar" default="''"/>
      <v:variable name="fNodePath" type="varchar" default="''"/>
      <v:variable name="fNodeItem" type="varchar" default="''"/>
    </vm:variables>
    <vm:pagebody>
      <v:before-data-bind>
    <![CDATA[
          declare N, node_type, node_id any;
          declare tmp, params any;

          params := self.vc_page.vc_event.ve_params;
          tmp := lcase (get_keyword ('tag',  params, ''));
          if (tmp <> '')
      {
        self.fTab := 'tags';
            self.fNode := 't#' || tmp;
            self.fNodePath := self.fNode;
            self.fNodeItem := '';
            goto _validate;
      }
          tmp := cast (get_keyword ('link', params, '0') as integer);
          if (tmp)
      {
        self.fTab := 'feeds';
        if (self.domain_id > 0)
        {
              self.fNode := 'c#' || cast (coalesce ((select TOP 1 EFD_ID from ENEWS.WA.FEED_DOMAIN, ENEWS.WA.FEED_ITEM where EFD_DOMAIN_ID = self.domain_id and EFD_FEED_ID = EFI_FEED_ID and EFI_ID = tmp), '') as varchar);
        } else {
              self.fNode := 'c#' || cast (coalesce ((select EFI_FEED_ID from ENEWS.WA.FEED_ITEM where EFI_ID = tmp), '') as varchar);
        }
            self.fNodePath := ENEWS.WA.enews_path (self.domain_id, self.fNode);
            self.fNodeItem := cast (tmp as varchar);
            goto _validate;
      }
          tmp := cast (get_keyword ('feed', params, '0') as integer);
          if (tmp)
      {
        self.fTab := 'feed';
            self.fNode := 'c#' || cast (tmp as varchar);
            self.fNodePath := ENEWS.WA.enews_path (self.domain_id, self.fNode);
            goto _validate;
      }
          tmp := get_keyword('node', params, '');
          if (tmp <> '')
      {
            self.fNode := tmp;
            self.fNodePath := ENEWS.WA.enews_path (self.domain_id, self.fNode);
            goto _validate;
  	  }
          goto _exit;

        _validate:;
      node_id := ENEWS.WA.node_id(self.fNode);
      node_type := ENEWS.WA.node_type(self.fNode);

      if (self.fNode in ('r#0', 'r#1', 'f#-1', 's#-1', 'w#-1'))
            goto _exit;

          if (node_type = 't')
            goto _exit;

      if ((node_type = 'f') and (node_id <> -1) and (exists (select 1 from ENEWS.WA.FOLDER where EFO_ID = node_id)))
            goto _exit;

      if ((node_type = 'c') and (self.domain_id < 0) and (exists (select 1 from ENEWS.WA.FEED where EF_ID = node_id)))
            goto _exit;

          if ((node_type = 'c') and (self.domain_id > 0) and (exists (select 1 from ENEWS.WA.FEED_DOMAIN where EFD_DOMAIN_ID = self.domain_id and EFD_ID = node_id)))
            goto _exit;

          if ((node_type = 's') and (exists (select 1 from ENEWS.WA.SFOLDER where ESFO_DOMAIN_ID = self.domain_id and ESFO_ID = node_id)))
            goto _exit;

          if ((node_type = 'b') and (exists (select 1 from ENEWS.WA.BLOG, ENEWS.WA.WEBLOG where EW_DOMAIN_ID = self.domain_id and EB_ID = node_id and EB_WEBLOG_ID = EW_ID)))
            goto _exit;

          for (select TOP 1 EFD_ID, EFD_TITLE, ENEWS.WA.folder_path (EFD_DOMAIN_ID, EFD_FOLDER_ID) EFD_PATH from ENEWS.WA.FEED_DOMAIN where EFD_DOMAIN_ID = self.domain_id order by EFD_PATH, EFD_TITLE) do
      {
        self.fNode := ENEWS.WA.make_node ('c', EFD_ID);
            self.fNodePath := ENEWS.WA.enews_path (self.domain_id, self.fNode);
            self.fNodeItem := '';
            goto _exit;
      }

          for (select TOP 1 EB_ID, EW_ID from ENEWS.WA.BLOG, ENEWS.WA.WEBLOG where EW_DOMAIN_ID = self.domain_id and EB_WEBLOG_ID = EW_ID order by EW_NAME, EB_NAME) do
      {
        self.fNode := ENEWS.WA.make_node ('b', EB_ID);
            self.fNodePath := ENEWS.WA.enews_path (self.domain_id, self.fNode);
            self.fNodeItem := '';
            goto _exit;
      }

      self.fNode := ENEWS.WA.make_node('f', -1);
          self.fNodePath := ENEWS.WA.make_path ('', 'f', -1);
          self.fNodeItem := '';

        _exit:;
          self.fTab := case when (ENEWS.WA.node_type (self.fNode) = 't') then 'tags' else 'feeds' end;
        ]]>
      </v:before-data-bind>
      <?vsp 
        http (sprintf ('<input type="hidden" id="sparqlUrl" name="sparqlUrl" value="%s" />', ENEWS.WA.sparql_url ()));
        http (sprintf ('<input type="hidden" id="node" name="node" value="%s" />', self.fNode));
        http (sprintf ('<input type="hidden" id="nodePath" name="nodePath" value="%V" />', self.fNodePath));
        http (sprintf ('<input type="hidden" id="nodeItem" name="nodeItem" value="%V" />', self.fNodeItem));
      ?>
      <vm:if test="self.domain_id > 0">
        <div class="tabs">
          <div style="float: left;">
            <div id="feeds_button" class="tab <?V case when self.fTab = 'feeds' then 'activeTab2' else 'tab2' end ?>" onclick="javascript: Feeds.toggleLeftPane('feeds');">Feeds</div>
            <div id="tags_button" class="tab <?V case when self.fTab = 'tags' then 'activeTab2' else 'tab2' end ?>" onclick="javascript: Feeds.toggleLeftPane('tags');">Tags</div>
        </div>
          <vm:if test="ENEWS.WA.settings_favourites (self.settings)">
          <div style="float: right;">
            <div>
              <span class="tab">Favourites</span>
            </div>
          </div>
          </vm:if>
          <br style="clear: both;"/>
        </div>
      </vm:if>

      <div id="pane_main" class="pane_main">
        <div id="pane_left" style="<?V case when ENEWS.WA.settings_favourites(self.settings) then 'width: 20.3%;' else '' end ?>">
          <div id="pane_left_feeds">...</div>
          <div id="pane_left_tags">...</div>
                </div>
        <div id="pane_right" style="<?V case when ENEWS.WA.settings_favourites(self.settings) then 'width: 59.3%;' else '' end ?>">
          <div id="pane_right_top">
        </div>
          <div id="pane_right_bottom">
          </div>
        </div>
        <vm:if test="ENEWS.WA.settings_favourites (self.settings)">
          <div id="pane_right2">
          </div>
        </vm:if>
      </div>
    </vm:pagebody>
  </vm:pagewrapper>
</v:page>
