<?xml version="1.0" encoding="UTF-8"?>
<!--
 -
 -  $Id$
 -
 -  This file is part of the OpenLink Software Virtuoso Open-Source (VOS)
 -  project.
 -
 -  Copyright (C) 1998-2018 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="search"
        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">
  <v:method name="sortColumn" arglist="in titleName varchar, in columnName varchar">
    <![CDATA[
      declare altStr, directionStr, imageStr varchar;

      if (self.v_order = columnName and self.v_direction = 'desc') {
        directionStr := 'Ascending';
        imageStr := '&nbsp;<img src="image/d.gif" border="0" alt="Down"/>';
      } else if (self.v_order = columnName and self.v_direction = 'asc') {
        directionStr := 'Descending';
        imageStr := '&nbsp;<img src="image/u.gif" border="0" alt="Up"/>';
      } else {
        directionStr := 'Ascending';
        imageStr := '&nbsp;&nbsp;';
      }
      altStr := sprintf('Sort Rows on %s in %s Order', titleName, directionStr);
      http(sprintf('<a href="#" onClick="javascript: myPost(''F1'', ''sortColumn'', ''%s''); return false;" alt="%s" title="%s">%s%s</a>', columnName, altStr, altStr, titleName, imageStr));
    ]]>
  </v:method>

  <v:method name="sortChange" arglist="in columnName varchar">
    <![CDATA[
      if (columnName = '')
        return;
      self.ds.vc_reset();
      if (self.v_order = columnName) {
        self.v_direction := either(equ(self.v_direction, 'asc'), 'desc', 'asc');
      } else {
        self.v_direction := 'asc';
      }
      self.v_order := columnName;
    ]]>
  </v:method>

  <v:method name="linkClass" arglist="inout flag any">
    <![CDATA[
      if (self.account_rights <> 'W')
        return 'unread';
      return either(equ(flag, 1), 'read', 'unread');
    ]]>
  </v:method>

  <v:method name="update_params" arglist="">
    <![CDATA[
      declare params any;
      params := self.vc_page.vc_event.ve_params;

      self.v_mode := get_keyword('mode', params, self.v_mode);
      if (self.v_mode = 'opensearch')
        self.v_step := 1;

      self.v_keywords := trim(get_keyword('a_keywords', params, get_keyword('s_keywords', params, get_keyword('q', params, ''))));
      self.v_expression := trim(get_keyword('f_expression', params, get_keyword('type', params, self.v_expression)));
      self.v_conversation := self.f_conversation.ufl_selected;
      self.v_tags := trim(get_keyword('f_tags', params, get_keyword('tags', params, self.v_tags)));
      if (get_keyword('tag', params, '') <> '')
      {
        if (is_empty_or_null(self.v_tags))
          self.v_tags := '';
        self.v_tags := concat(self.v_tags, ', ', get_keyword('tag', params));
        self.v_tags := ENEWS.WA.tags2vector(self.v_tags);
        self.v_tags := ENEWS.WA.tags2unique(self.v_tags);
        self.v_tags := ENEWS.WA.vector2tags(self.v_tags);
      }
      self.v_read := trim(get_keyword('f_read', params, get_keyword('read', params, self.v_read)));
      self.v_flag := trim(get_keyword('f_flag', params, get_keyword('flag', params, self.v_flag)));
      self.v_after := trim(get_keyword('f_after', params, get_keyword('after', params, self.v_after)));
      self.v_before := trim(get_keyword('f_before', params, get_keyword('before', params, self.v_before)));

      self.v_type := trim(get_keyword('f_type', params, get_keyword('type', params, self.v_type)));
      self.v_max := trim(get_keyword('f_max', params, get_keyword('max', params, self.v_max)));
      self.v_order := trim(get_keyword('f_order', params, get_keyword('order', params, self.v_order)));
      self.v_direction := trim(get_keyword('f_direction', params, get_keyword('direction', params, self.v_direction)));

      self.v_group := self.f_group.ufl_selected;
      self.v_cloud := self.f_cloud.ufl_selected;

      self.sortChange (get_keyword ('sortColumn', params, ''));
    ]]>
  </v:method>

  <v:method name="enable_it" arglist="in what varchar, in flag int">
    <![CDATA[
      if (self.f_type.ufl_value = what)
        return flag;
      if (self.v_expression is null and self.f_type.ufl_value is null and self.v_type = what)
        return flag;
      return case when flag then 0 else 1 end;
    ]]>
  </v:method>

  <v:method name="do_search" arglist="inout e vspx_event">
    <![CDATA[
      declare tmp any;

      declare exit handler for SQLSTATE '*' {
        if (__SQL_STATE = 'TEST') {
          self.vc_error_message := ENEWS.WA.test_clear(__SQL_MESSAGE);
       		self.vc_is_valid := 0;
    		  return;
    		}
        resignal;
      };

      self.update_params();

      ENEWS.WA.test(self.v_keywords, vector('name', 'Keywords', 'class', 'free-text'));
      if (self.v_mode not in ('simple', 'opensearch'))
      {
        if (self.v_type = 'text')
          ENEWS.WA.test(self.v_expression, vector('name', 'Expression', 'class', 'free-text-expression'));
        ENEWS.WA.test(self.v_tags, vector('name', 'Tags', 'class', 'tags'));
        ENEWS.WA.test(self.v_after, vector('name', 'Date after', 'class', 'date2', 'type', 'date'));
        ENEWS.WA.test(self.v_before, vector('name', 'Date before', 'class', 'date2', 'type', 'date'));
        ENEWS.WA.test(self.v_max, vector('name', 'Max Records', 'class', 'integer', 'type', 'integer', 'minValue', 1, 'maxValue', 1000));
      }

      declare data varchar;

      ENEWS.WA.xml_set('keywords', data, self.v_keywords);
      if (self.v_mode not in ('simple', 'opensearch'))
      {
        ENEWS.WA.xml_set('expression', data, self.v_expression);
        ENEWS.WA.xml_set('conversation', data, self.v_conversation);
        ENEWS.WA.xml_set('tags', data, self.v_tags);
        ENEWS.WA.xml_set('read', data, self.v_read);
        ENEWS.WA.xml_set('flag', data, self.v_flag);
        ENEWS.WA.xml_set('afterDate', data, self.v_after);
        ENEWS.WA.xml_set('beforeDate', data, self.v_before);
      }

      self.ds_data := vector ();
      self.ds_tags := vector ();
      if (length(xpath_eval('//entry', data, 0)) = 0)
      {
        if (e.ve_is_post or (self.v_mode in ('simple', 'opensearch')))
        {
          self.vc_error_message := 'Empty search criteria.';
          self.vc_is_valid := 0;
        }
        return;
      }

      declare sql, state, msg, meta, result any;

      sql := ENEWS.WA.sfolder_sql(self.domain_id, self.account_id, self.account_rights, data, self.v_type, self.v_max);
      if (self.v_group = 0)
      {
        sql := concat(sql, 'order by ', self.v_order, ' ', self.v_direction);
      } else {
        sql := concat(sql, 'order by EFD_TITLE, ', self.v_order, ' ', self.v_direction);
      }

      state := '00000';
      exec(sql, state, msg, vector(), 0, meta, result);
      if (state = '00000')
      {
        self.ds_data := result;

        if (self.f_cloud.ufl_selected = 1)
        {
          declare N, minCnt, maxCnt integer;
          declare tag_object, tags, tags_dict any;

          tags_dict := dict_new();
          for (N := 0; N < length(self.ds_data); N := N + 1)
          {
            tags := ENEWS.WA.tags_account_item_select(self.domain_id, self.account_id, self.ds_data[N][0]);
            tags := split_and_decode (tags, 0, '\0\0,');
            foreach (any tag in tags) do
            {
              tag_object := dict_get(tags_dict, lcase(tag), vector(lcase(tag), 0));
              tag_object[1] := tag_object[1] + 1;
              dict_put(tags_dict, lcase(tag), tag_object);
            }
          }
          maxCnt := 1;
          minCnt := 1000000;
          for (select p.* from ENEWS.WA.tagsDictionary2rs(p0)(tag varchar, cnt integer) p where p0 = tags_dict order by tag) do
          {
            self.ds_tags := vector_concat(self.ds_tags, vector(vector(tag, cnt)));
            if (cnt > maxCnt)
              maxCnt := cnt;
            if (cnt < minCnt)
              minCnt := cnt;
          }
          self.ds_tags := vector_concat(vector(vector('__max', maxCnt)), self.ds_tags);
          self.ds_tags := vector_concat(vector(vector('__min', minCnt)), self.ds_tags);
        }
      }
	    self.ds.vc_data_bind (e);
    ]]>
  </v:method>
  <v:method name="do_url" arglist="in mode varchar, in prefix varchar">
    <![CDATA[
      declare tmp varchar;

      tmp := '';
      if (not is_empty_or_null(self.v_keywords))
        tmp := concat(tmp, sprintf('&%skeywords=%U', prefix, self.v_keywords));
      if (not is_empty_or_null(self.v_expression))
        tmp := concat(tmp, sprintf('&%sexpression=%U', prefix, self.v_expression));
      if (not is_empty_or_null(self.v_tags))
        tmp := concat(tmp, sprintf('&%stags=%U', prefix, self.v_tags));
      if (not is_empty_or_null(self.v_read))
        tmp := concat(tmp, sprintf('&%sread=%U', prefix, self.v_read));
      if (not is_empty_or_null(self.v_flag))
        tmp := concat(tmp, sprintf('&%sflag=%U', prefix, self.v_flag));
      if (not is_empty_or_null(self.v_after))
        tmp := concat(tmp, sprintf('&%safter=%U', prefix, self.v_after));
      if (not is_empty_or_null(self.v_before))
        tmp := concat(tmp, sprintf('&%sbefore=%U', prefix, self.v_before));
      if (mode = 'export')
      {
        if (not is_empty_or_null(self.v_type) and self.v_type <> 'text')
          tmp := concat(tmp, sprintf('&%stype=%U', prefix, self.v_type));
        if (not is_empty_or_null(self.v_max) and self.v_max <> '100')
          tmp := concat(tmp, sprintf('&%smax=%U', prefix, self.v_max));
        if (not is_empty_or_null(self.v_order) and self.v_order <> 'EFI_PUBLISH_DATE')
          tmp := concat(tmp, sprintf('&%sorder=%U', prefix, self.v_order));
        if (not is_empty_or_null(self.v_direction) and self.v_direction <> 'desc')
          tmp := concat(tmp, sprintf('&%sdirection=%U', prefix, self.v_direction));
      }

      return tmp;
    ]]>
  </v:method>

  <v:on-init>
    <![CDATA[
      if (self.ds_data is null)
      {
        self.ds_data := vector ();
        self.ds_meta := vector ();
        self.ds_tags := vector ();
      }
    ]]>
  </v:on-init>
  <v:after-data-bind>
    <![CDATA[
      if (not e.ve_is_post or (get_keyword ('sortColumn', e.ve_params, '') <> '') or (self.v_mode in ('simple', 'opensearch') and isnull (e.ve_button)) or (get_keyword ('tag', e.ve_params, '') <> ''))
      {
        self.do_search (e);
      }
    ]]>
  </v:after-data-bind>
  <vm:pagetitle>Search results</vm:pagetitle>
  <vm:pagewrapper>
    <vm:header>
      Search results
    </vm:header>
    <vm:variables>
      <v:variable name="v_tabNo" param-name="tabNo" type="varchar" default="1"/>
      <v:variable name="v_mode" type="varchar" default="'simple'"/>
      <v:variable name="v_step" param-name="step" type="integer" default="0"/>

      <v:variable name="v_keywords" type="varchar" default="''" param-name="q"/>
      <v:variable name="v_expression" type="varchar" default="''"/>
      <v:variable name="v_conversation" type="integer" default="0"/>
      <v:variable name="v_tags" type="varchar" default="''"/>
      <v:variable name="v_read" type="varchar" default="''"/>
      <v:variable name="v_flag" type="varchar" default="''"/>
      <v:variable name="v_after" type="varchar" default="''"/>
      <v:variable name="v_before" type="varchar" default="''"/>

      <v:variable name="v_type" type="varchar" default="'text'"/>
      <v:variable name="v_output" type="varchar" default="'html'"/>
      <v:variable name="v_max" type="varchar" default="'100'"/>
      <v:variable name="v_order" type="varchar" default="'EFI_PUBLISH_DATE'" />
      <v:variable name="v_direction" type="varchar" default="'desc'" />
      <v:variable name="v_group" type="integer" default="0" />
      <v:variable name="v_cloud" type="integer" default="0" />

      <v:variable name="ds_data" type="any" default="null"/>
      <v:variable name="ds_meta" type="any" default="null"/>
      <v:variable name="ds_tags" type="any" default="null"/>

      <v:variable name="v_groupName" type="varchar" default="''" />
    </vm:variables>
    <vm:pagebody>
      <v:before-data-bind>
        <![CDATA[
          self.update_params();
        ]]>
      </v:before-data-bind>
      <v:on-post>
        <![CDATA[
          declare tmp vspx_control;

          tmp := self.example.vc_find_control(self.f_type.ufl_value||'_help');
          self.example.tb_active := tmp;
          if (e.ve_button = control)
          {
            self.a_keywords.ufl_value := '';
            self.f_expression.ufl_value := '';
            self.ds_data := vector ();
            self.ds_tags := vector ();
            self.vc_data_bind (e);
          }
        ]]>
      </v:on-post>
      <?vsp 
        declare sparqlUrl, graphIri any;
        
        sparqlUrl := 'http://' || SIOC..get_cname () || '/sparql';
        graphIri := SIOC..get_graph ();
        http(sprintf('<input type="hidden" id="sparqlUrl" name="sparqlUrl" value="%s?default-graph-uri=%U&query=%U&format=%U"/>', sparqlUrl, graphIri, 'DESCRIBE <_RDF_>', 'application/sparql-results+xml')); 
      ?>
      <v:text name="tabNo" xhtml_id="tabNo" type="hidden" value="--self.v_tabNo"/>
      <v:text name="step" xhtml_id="step" type="hidden" value="1"/>
      <v:template name="st1" type="simple" enabled="-- case when (self.v_step and self.vc_is_valid) then 1 else 0 end;">
        <div class="form-header">
          <i><?V initcap(self.v_mode) ?> search found <?V length (self.ds_data) ?> feed(s) in last search</i>
        </div>
      </v:template>
      <v:template name="st2" type="simple">
        <v:before-render>
          <![CDATA[
            control.vc_enabled := case when (length (self.ds_data) and self.vc_is_valid = 1) then 1 else 0 end;
          ]]>
        </v:before-render>
        <div style="padding-bottom: 5px;">
          <?vsp
            self.update_params();
            http(sprintf('<a href="export.vspx?output=rss%s" class="gems"><img src="image/rss-icon-16.gif" border="0" title="RSS 2.0" alt="RSS 2.0"/> RSS</a>&nbsp;&nbsp;', self.do_url('export', '')));
            if (ENEWS.WA.settings_atomVersion (self.settings) = '1.0')
            {
              http(sprintf('<a href="export.vspx?output=atom10%s" class="gems"><img src="image/blue-icon-16.gif" border="0" title="Atom 1.0" alt="Atom 1.0"/> Atom</a>&nbsp;&nbsp;', self.do_url('export', '')));
    			  } else {
              http(sprintf('<a href="export.vspx?output=atom03%s" class="gems"><img src="image/blue-icon-16.gif" border="0" title="Atom 0.3" alt="Atom 0.3"/> Atom</a>&nbsp;&nbsp;', self.do_url('export', '')));
    			  }
            http(sprintf('<a href="export.vspx?output=rdf%s" class="gems"><img src="image/rdf-icon-16.gif" border="0" title="RDF 1.0" alt="RDF 1.0"/> RDF</a>&nbsp;&nbsp;', self.do_url('export', '')));
            http(sprintf('<a href="export.vspx?output=xbel%s" class="gems"><img src="image/blue-icon-16.gif" border="0" title="XBEL" alt="XBEL"/> XBEL</a>&nbsp;&nbsp;', self.do_url('export', '')));
    			?>
        </div>
      </v:template>
      <table cellspacing="0" cellpadding="0" width="100%" >
        <tr>
          <v:template name="st3" type="simple" enabled="-- case when (self.v_step and self.vc_is_valid) then 1 else 0 end;" >
            <td valign="top" style="border: solid #935000; border-width: 1px 1px 1px 1px;">
              <v:data-set name="ds" data="--self.ds_data" meta="--self.ds_meta" nrows="0" scrollable="1">
                <v:before-data-bind>
                  <![CDATA[
                    control.ds_nrows := ENEWS.WA.settings_rows (self.settings);
                  ]]>
                </v:before-data-bind>
                <v:template name="ds_header" type="simple" name-to-remove="table" set-to-remove="bottom">
                  <table id="search" class="FM_grid" style="border-width: 0px 0px 0px 0px;" cellspacing="0">
                    <thead class="sortHeader">
                      <tr>
                        <th width="1%" class="image">
                          <img src="image/flag.gif" border="0"/>
                        </th>
                        <th width="1%" style="border-width: 0px 0px 1px 0px;">
                          <img src="image/c.gif" border="0"/>
                        </th>
                        <th>
                          <?vsp self.sortColumn('Headline', 'EFI_TITLE'); ?>
                        </th>
                        <th>
                          <?vsp self.sortColumn('Author', 'EFI_AUTHOR'); ?>
                        </th>
                        <v:template type="simple" enabled="-- case when (self.v_group = 0) then 1 else 0 end;">
                          <th>
                            <?vsp self.sortColumn('Feed', 'EFD_TITLE'); ?>
                          </th>
                        </v:template>
                        <th>
                          <?vsp self.sortColumn('Date', 'EFI_PUBLISH_DATE'); ?>
                        </th>
                      </tr>
                    </thead>
                  </table>
                </v:template>

                <v:template name="ds_repeat" type="repeat" name-to-remove="" set-to-remove="">

                  <v:template name="ds_empty" type="if-not-exists" name-to-remove="table" set-to-remove="both">
                    <table>
                      <tr align="center">
                        <td colspan="5">No matches found in OFM DataSpace</td>
                      </tr>
                    </table>
                  </v:template>

                  <v:template name="ds_browse" type="browse" name-to-remove="table" set-to-remove="both">
                    <table>
                      <v:template type="simple" enabled="-- case when (self.v_group = 0) then 0 else 1 end;">
                        <?vsp
                          if (is_empty_or_null(self.v_groupName) or (self.v_groupName <> (control.vc_parent as vspx_row_template).te_rowset[8])) {
                        ?>
                        <tr>
                          <td align="center">
                            <img src="image/docs_16.gif" border="0"/>
                          </td>
                          <td colspan="3">
                            <v:url
                              value="--((control.vc_parent).vc_parent as vspx_row_template).te_rowset[8]"
                              format="%s"
      		                    url="--concat(sprintf('channels_update.vspx?id=%d', ((control.vc_parent).vc_parent as vspx_row_template).te_rowset[6]))"/>
                          </td>
                        </tr>
                        <?vsp
                          }
                          self.v_groupName := (control.vc_parent as vspx_row_template).te_rowset[8];
                        ?>
                      </v:template>
                      <tr>
                        <td align="center">
                          <?vsp
                            if (control.te_rowset[10] = 1)
                              http('<img src="image/flag.gif" border="0"/>');
                          ?>
                        </td>
                        <td>
                          <img src="image/html.png" border="0" alt="folder" width="16"/>
                        </td>
                        <td>
                          <?vsp
                            declare url, class, appIri, title varchar;
                            
                            title := (control as vspx_row_template).te_rowset[1];
                            url := (control as vspx_row_template).te_rowset[4];
                            class := self.linkClass((control as vspx_row_template).te_rowset[9]);
                            appIri := SIOC..feed_item_iri ((control as vspx_row_template).te_rowset[6], (control as vspx_row_template).te_rowset[0]);  
                            http (sprintf ('<a id="s_item_%d" href="%s" target="_blank" class="%s %s" about="%U" title="%s">%s</a>', (control as vspx_row_template).te_rowset[0], url, class, 'app', appIri, ENEWS.WA.utf2wide(title), title));
                          ?>  
                          <v:template type="simple" enabled="-- case when ((self.v_type = 'text') and is_empty_or_null(self.v_keywords) and is_empty_or_null(self.v_expression)) then 0 else 1 end">
                            <br /><i style="padding-left: 20px;"><v:label value="--ENEWS.WA.feed_excerpt(((control.vc_parent).vc_parent as vspx_row_template).te_rowset[0], self.v_keywords, self.v_expression)" format="%s"/></i>
                          </v:template>
                        </td>
                        <td>
                          <v:label value="--(control.vc_parent as vspx_row_template).te_rowset[2]" format="%s"/>
                        </td>
                        <v:template type="simple" enabled="-- case when (self.v_group = 0) then 1 else 0 end;">
                          <td>
                            <?vsp
                              declare url, appIri, title varchar;
                              
                              title := (control.vc_parent as vspx_row_template).te_rowset[8];
                              url := sprintf('channels_update.vspx?id=%d&sid=%s&realm=%s', (control.vc_parent as vspx_row_template).te_rowset[6], self.sid, self.realm);
                              appIri := SIOC..feed_iri ((control.vc_parent as vspx_row_template).te_rowset[6]);  
                              http (sprintf ('<a id="s_feed_%d" href="%s" class="%s" about="%U" title="%s">%s</a>', (control.vc_parent as vspx_row_template).te_rowset[6], url, 'app', appIri, ENEWS.WA.utf2wide(title), title));
                            ?>  
                          </td>
                        </v:template>
                        <td align="right" nowrap="nowrap">
                          <v:label value="--ENEWS.WA.dt_value((control.vc_parent as vspx_row_template).te_rowset[3])" format="%s"/>
                        </td>
                      </tr>
                    </table>
                  </v:template>

                </v:template>

                <v:template name="ds_footer" type="simple" name-to-remove="table" set-to-remove="top">
                  <table>
                    <tr>
                      <td align="center" colspan="6">
                        <vm:ds-navigation data-set="ds"/>
                      </td>
                    </tr>
                  </table>
                </v:template>

              </v:data-set>
              <script type="text/javascript">
                <![CDATA[
                  coloriseTable('search');
                ]]>
              </script>
            </td>
          </v:template>
          <v:template type="simple" enabled="-- case when (self.v_cloud and self.v_step and self.vc_is_valid) then 1 else 0 end;">
            <td width="20%" valign="top" style="border: solid #935000;  border-width: 1px 1px 1px 0px;">
              <div style="margin-left:3px; margin-top:3px;">
                <?vsp
                  declare N, tLength, tMax, tMin integer;
                  declare tStyle varchar;

                  tLength := length(self.ds_tags);
                  if (tLength > 2)
                  {
                    tMin := self.ds_tags[0][1];
                    tMax := self.ds_tags[1][1];
                    for (N := 2; N < tLength; N := N + 1)
                    {
                      tStyle := ODS.WA.tag_style(self.ds_tags[N][1], tMin, tMax);
                      http (sprintf ('<a id="t_tag_%s" name="pt_tag_%s" href="javascript: myTags(\'%s\');" class="%s" about="%U"><span style="%s">%s</span></a> ', self.ds_tags[N][0], self.ds_tags[N][0], self.ds_tags[N][0], 'app', SIOC..addressbook_tag_iri (self.account_id, self.ds_tags[N][0]), tStyle, self.ds_tags[N][0]));
                  }
                  } else {
                    http ('no tags');
                  }
                ?>
              </div>
            </td>
          </v:template>
        </tr>
      </table>
      <br />
      <v:template type="simple" enabled="--case when self.v_mode in ('simple', 'opensearch') then 0 else 1 end">
        <div id="s" class="c1">
      		<div class="tabs">
            &nbsp;<vm:tabCaption tab="s" tabsCount="2" tabNo="0" caption="Criteria" />
            &nbsp;<vm:tabCaption tab="s" tabsCount="2" tabNo="1" caption="Options" />
          </div>
      		<div class="contents">
            <div id="s_content_0" class="tabContent">
              <table class="form-body" cellspacing="0">
                <tr>
                  <th>
                    <v:label for="f_type" value="Expression Type" />
                  </th>
                  <td>
                    <v:select-list name="f_type" value="" auto-submit="1">
                      <v:item name="Text" value="text"/>
                      <v:item name="XPath" value="xpath"/>
                      <v:item name="XQuery" value="xquery"/>
                    </v:select-list>
                  </td>
                </tr>
                <vm:if test="self.v_type = 'text'">
                  <tr>
                    <th>
                      <v:label for="" value="Space delimited keyword list" />
                    </th>
                    <td>
                      <v:text name="a_keywords" value="--self.v_keywords" fmt-function="ENEWS.WA.utf2wide" xhtml_class="textbox" xhtml_size="70%"/>
                    </td>
                  </tr>
                </vm:if>
                <tr>
                  <th>
                    <v:label for="f_expression" value="--case when (self.v_type = 'text') then 'or expression' else case when (self.v_type = 'xpath') then 'XPath Expression' else 'XQuery Expression' end end;" />
                  </th>
                  <td>
                    <v:tab name="example" initial-active="text_help">
                      <v:template name="xpath_help" type="simple">
                        <v:select-list name="xp" xhtml_onchange="javascript: document.F1.f_expression.value = this.value">
                          <v:item value="" name="* select an example *"/>
                          <v:item value="//p[a]" name="paragraph with link(s)"/>
                          <v:item value="//p[contains(.,\'Virtuoso\')]" name="about Virtuoso"/>
                          <v:item value="//a[@href]/@href" name="link targets"/>
                          <v:item value="//a/text()" name="link titles"/>
                          <v:item value="//a[@name or @id]" name="link references"/>
                          <v:item value="//b" name="text in bold"/>
                          <v:item value="//i" name="text in italic"/>
                          <v:item value="//p[b or i or u or s or small or big]/*" name="formatting"/>
                          <v:item value="//p[b or i or u or s or small or big]/ancestor::*" name="section with formatting"/>
                          <v:item value="//*[@class]" name="css formatted sections"/>
                          <v:item value="//table[.//tr/td]" name="tables"/>
                          <v:item value="//img[@src]" name="images"/>
                          <v:item value="//p[img[@src]]" name="sections with images"/>
                          <v:item value="//p[a/@href[contains(.,\'.xml\')]]" name="about XML"/>
                        </v:select-list>
                        <br/>
                      </v:template>
                      <v:template name="xquery_help" type="simple">
                        <v:select-list name="xq" xhtml_onchange="javascript: document.F1.f_expression.value = this.value">
                          <v:item value="" name="* select an example *"/>
                          <v:item value="for $i in node()//table return $i" name="all tables"/>
                          <v:item value="for $t in node()//table return <ul> {for $i in $t//tr return <li>{$i/td/text()}</li> }</ul>" name="table to list"/>
                          <v:item value="for $i in node()//a return <p>{ string($i/@href) }</p>" name="list of links"/>
                          <v:item value="for $i in node() return <p>{ .//text() }</p>" name="text nodes"/>
                          <v:item value="for $i in node()//p[contains(.,\'Virtuoso\')] return <p>{ string($i) }</p>" name="about Virtuoso"/>
                        </v:select-list>
                        <br/>
                      </v:template>
                    </v:tab>
                    <v:textarea name="f_expression" value="--self.v_expression" fmt-function="ENEWS.WA.utf2wide" xhtml_rows="2" xhtml_cols="70"/>
                  </td>
                </tr>
                <vm:if test="ENEWS.WA.conversation_enable(self.domain_id)">
                  <tr>
                    <tr>
                      <th width="30%">&nbsp;</th>
                      <td>
                				<v:check-box name="f_conversation" xhtml_id="f_conversation" value="1" initial-checked="--self.v_conversation" xhtml_title="Search in conversations" />
                				<vm:label for="f_conversation" value="Search in conversations" />
                      </td>
                    </tr>
                  </tr>
                </vm:if>
                <vm:if test="self.account_rights <> 'W'">
                <tr>
                  <th>
                      <v:label for="f_tags" value="Tags" />
                  </th>
                  <td>
                      <v:text name="f_tags" value="--self.v_tags" fmt-function="ENEWS.WA.utf2wide" xhtml_class="textbox" xhtml_size="70%"/>
                  </td>
                </tr>
                <tr>
                  <th>
                    <v:label for="f_read" value="Show marked"/>
                  </th>
                  <td>
                    <v:select-list name="f_read" value="--self.v_read">
                      <v:item name="all" value=""/>
                      <v:item name="read" value="r+"/>
                      <v:item name="unread" value="r-"/>
                    </v:select-list>
                  </td>
                </tr>
                <tr>
                  <th>
                    <v:label for="f_flag" value="Show flagged"/>
                  </th>
                  <td>
                    <v:select-list name="f_flag" value="--self.v_flag">
                      <v:item name="all" value=""/>
                      <v:item name="flagged" value="f+"/>
                      <v:item name="unflagged" value="f-"/>
                    </v:select-list>
                  </td>
                </tr>
                </vm:if>
                <tr>
                  <th>
                    <v:label for="f_after" value="Date after"/>
                  </th>
                  <td>
                    <v:text name="f_after" xhtml_id="f_after" null-value="--''" value="--self.v_after" xhtml_onclick="javascript: datePopup (\'f_after\');" xhtml_size="10" />
                    <a href="#" name="f_after_select" id="f_after_select" onclick="datePopup ('f_after'); return false;" class="noapp">
                      <img border="0" title="pick" alt="pick" src="image/pick_calendar.gif" />
                    </a>
                  </td>
                </tr>
                <tr>
                  <th>
                    <v:label for="f_before" value="Date before"/>
                  </th>
                  <td>
                    <v:text name="f_before" xhtml_id="f_before" null-value="--''" value="--self.v_before" xhtml_onclick="javascript: datePopup (\'f_before\');" xhtml_size="10" />
                    <a href="#" name="f_before_select" id="f_before_select" onclick="datePopup ('f_before'); return false;" class="noapp">
                      <img border="0" title="pick" alt="pick" src="image/pick_calendar.gif" />
                    </a>
                  </td>
                </tr>
              </table>
            </div>
            <div id="s_content_1" class="tabContent" style="display: none;">
              <table class="form-body" cellspacing="0">
                <tr>
                  <th>
                    <v:label for="f_max" value="Max Results" />
                  </th>
                  <td>
                    <v:text name="f_max" default_value="100" xhtml_size="5"/>
                  </td>
                </tr>
                <tr>
                  <th>
                    <v:label for="f_order" value="Order by" />
                  </th>
                  <td>
                    <v:select-list name="f_order" value="--self.v_order">
                      <v:item name="Headline" value="EFI_TITLE"/>
                      <v:item name="Author" value="EFI_AUTHOR"/>
                      <v:item name="Feed" value="EFD_TITLE"/>
                      <v:item name="Date" value="EFI_PUBLISH_DATE"/>
                    </v:select-list>
                  </td>
                </tr>
                <tr>
                  <th>
                    <v:label for="f_direction" value="Direction" />
                  </th>
                  <td>
                    <v:select-list name="f_direction" value="--self.v_direction">
                      <v:item name="Asc" value="asc"/>
                      <v:item name="Desc" value="desc"/>
                    </v:select-list>
                  </td>
                </tr>
                <tr>
                  <th/>
                  <td>
              			<v:check-box name="f_group" xhtml_id="f_group" value="1"/>
                    <vm:label for="f_group" value="Group by feed source"/>
                  </td>
                </tr>
                <tr>
                  <th/>
                  <td>
                    <v:check-box name="f_cloud" xhtml_id="f_cloud" value="1"/>
                    <vm:label for="f_cloud" value="Show tag cloud"/>
                  </td>
                </tr>
              </table>
            </div>
          </div>
        </div>
        <div class="form-footer">
          <v:button name="btn_search" action="simple" value="Search" xhtml_class="form-button">
            <v:on-post>
              <![CDATA[
                self.do_search (e);
                self.vc_data_bind(e);
              ]]>
            </v:on-post>
          </v:button>
          <v:button name="btn_save" action="simple" value="Save" enabled="--case when ((self.v_type = 'text') and (self.account_rights = 'W')) then 1 else 0 end" xhtml_class="form-button">
            <v:on-post>
              <![CDATA[
                self.update_params();
                self.vc_redirect(ENEWS.WA.utf2wide (ENEWS.WA.page_url (self.domain_id, 'sfolders.vspx') || '?mode=create&return=yes' || self.do_url('save', 'f_')));
              ]]>
            </v:on-post>
          </v:button>
          <v:button name="btn_cancel" action="simple" value="Cancel" xhtml_class="form-button">
            <v:on-post>
              <![CDATA[
                self.vc_redirect (ENEWS.WA.utf2wide (ENEWS.WA.page_url (self.domain_id, 'news.vspx')));
              ]]>
            </v:on-post>
          </v:button>
        </div>
      </v:template>
      <vm:if test="self.v_mode in ('simple', 'opensearch')">
        <div class="new-form-body">
          <table cellspacing="0">
            <tr>
              <td align="center">
                <b><v:label for="" value="Search" /></b>
                <v:text name="s_keywords" value="--self.v_keywords" fmt-function="ENEWS.WA.utf2wide" xhtml_onkeypress="return submitEnter(\'F1\', \'\', event)" xhtml_class="textbox" xhtml_size="70%"/>
                |
                <v:button action="simple" style="url" value="Advanced" xhtml_class="form-button">
                  <v:on-post>
                    <![CDATA[
                      self.vc_is_valid := 1;
                      self.v_step := 0;
                      self.v_mode := 'advanced';
                      self.ds_data := vector();
                      self.ds_tags := vector();
                      self.vc_data_bind(e);
                    ]]>
                  </v:on-post>
                </v:button>
                |
                <v:button action="simple" style="url" value="Cancel" xhtml_class="form-button">
                  <v:on-post>
                    <![CDATA[
                      self.vc_redirect (ENEWS.WA.utf2wide (ENEWS.WA.page_url (self.domain_id, 'news.vspx')));
                    ]]>
                  </v:on-post>
                </v:button>
              </td>
            </tr>
          </table>
        </div>
      </vm:if>
    </vm:pagebody>
  </vm:pagewrapper>
</v:page>
